Skip to content

Commit 2212f31

Browse files
Revert "Set pbkdf2Encode rounds to default to 210,000 (#1983)" (#2007)
This reverts commit e5e6bdd.
1 parent 0478403 commit 2212f31

File tree

15 files changed

+43
-88
lines changed

15 files changed

+43
-88
lines changed

packages/keyring/src/index.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ describe('keypair', (): void => {
358358
});
359359

360360
it('creates with dev phrase with derivation path specified', (): void => {
361-
const pair = keyring.createFromUri(PHRASE, undefined, undefined, undefined, 2048);
361+
const pair = keyring.createFromUri(PHRASE);
362362

363363
expect(
364364
pair.address
@@ -367,20 +367,20 @@ describe('keypair', (): void => {
367367

368368
it('creates with dev phrase with derivation path specified - addFromUri', (): void => {
369369
expect(
370-
keyring.addFromUri(PHRASE, undefined, undefined, undefined, 2048).address
370+
keyring.addFromUri(PHRASE).address
371371
).toEqual(ETH_ADDRESS_ONE);
372372
});
373373

374374
it('creates with dev phrase with derivation path specified - addFromUri with type', (): void => {
375375
const keyringUntyped = new Keyring();
376376

377377
expect(
378-
keyringUntyped.addFromUri(PHRASE, {}, 'ethereum', undefined, 2048).address
378+
keyringUntyped.addFromUri(PHRASE, {}, 'ethereum').address
379379
).toEqual(ETH_ADDRESS_ONE);
380380
});
381381

382382
it('encodes a pair toJSON (and decodes)', (): void => {
383-
const pair = keyring.createFromUri(PHRASE, undefined, undefined, undefined, 2048);
383+
const pair = keyring.createFromUri(PHRASE);
384384
const json = pair.toJson('password');
385385

386386
expect(json.address).toEqual('0x0381351b1b46d2602b0992bb5d5531f9c1696b0812feb2534b6884adc47e2e1d8b'); // this is the public key (different from address for ethereum)
@@ -399,7 +399,7 @@ describe('keypair', (): void => {
399399
});
400400

401401
it('encodes a pair toJSON and back', (): void => {
402-
const pairOriginal = keyring.createFromUri(PHRASE, undefined, undefined, undefined, 2048);
402+
const pairOriginal = keyring.createFromUri(PHRASE);
403403
const json = pairOriginal.toJson('password');
404404
const pair = keyring.addFromJson(
405405
json

packages/keyring/src/keyring.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,10 @@ export class Keyring implements KeyringInstance {
152152
* @name addFromUri
153153
* @summary Creates an account via an suri
154154
* @description Extracts the phrase, path and password from a SURI format for specifying secret keys `<secret>/<soft-key>//<hard-key>///<password>` (the `///password` may be omitted, and `/<soft-key>` and `//<hard-key>` maybe repeated and mixed). The secret can be a hex string, mnemonic phrase or a string (to be padded)
155-
* @param _suri
156-
* @param meta
157-
* @param type The supported types of pairs. Either 'ed25519' | 'sr25519' | 'ecdsa' | 'ethereum'.
158-
* @param wordlist - Optional custom wordlist for mnemonic.
159-
* @param rounds - Optional: Number of PBKDF2 iterations to run (default: 210000 (when onlyJS = true) or 2048 (when onlyJS = false).
160-
*/
161-
public addFromUri (suri: string, meta: KeyringPair$Meta = {}, type: KeypairType = this.type, wordlist?: string[], rounds?: number): KeyringPair {
155+
*/
156+
public addFromUri (suri: string, meta: KeyringPair$Meta = {}, type: KeypairType = this.type, wordlist?: string[]): KeyringPair {
162157
return this.addPair(
163-
this.createFromUri(suri, meta, type, wordlist, rounds)
158+
this.createFromUri(suri, meta, type, wordlist)
164159
);
165160
}
166161

@@ -207,14 +202,8 @@ export class Keyring implements KeyringInstance {
207202
* @name createFromUri
208203
* @summary Creates a Keypair from an suri
209204
* @description This creates a pair from the suri, but does not add it to the keyring
210-
*
211-
* @param _suri
212-
* @param meta
213-
* @param type The supported types of pairs. Either 'ed25519' | 'sr25519' | 'ecdsa' | 'ethereum'.
214-
* @param wordlist - Optional custom wordlist for mnemonic.
215-
* @param rounds - Optional: Number of PBKDF2 iterations to run (default: 210000 (when onlyJS = true) or 2048 (when onlyJS = false).
216205
*/
217-
public createFromUri (_suri: string, meta: KeyringPair$Meta = {}, type: KeypairType = this.type, wordlist?: string[], rounds?: number): KeyringPair {
206+
public createFromUri (_suri: string, meta: KeyringPair$Meta = {}, type: KeypairType = this.type, wordlist?: string[]): KeyringPair {
218207
// here we only aut-add the dev phrase if we have a hard-derived path
219208
const suri = _suri.startsWith('//')
220209
? `${DEV_PHRASE}${_suri}`
@@ -230,8 +219,8 @@ export class Keyring implements KeyringInstance {
230219

231220
if ([12, 15, 18, 21, 24].includes(parts.length)) {
232221
seed = type === 'ethereum'
233-
? mnemonicToLegacySeed(phrase, '', false, 64, rounds)
234-
: mnemonicToMiniSecret(phrase, password, wordlist, false, rounds);
222+
? mnemonicToLegacySeed(phrase, '', false, 64)
223+
: mnemonicToMiniSecret(phrase, password, wordlist);
235224
} else {
236225
if (phrase.length > 32) {
237226
throw new Error('specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes');

packages/keyring/src/suri.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ describe('keyring.addFromUri', (): void => {
9898
describe(`${type}`, (): void => {
9999
tests.forEach(({ pk, ss, uri }): void => {
100100
it(`creates ${uri}`, (): void => {
101-
const pair = keyring.addFromUri(uri, {}, type as KeypairType, undefined, 2048);
101+
const pair = keyring.addFromUri(uri, {}, type as KeypairType);
102102

103103
expect(u8aToHex(pair.publicKey)).toEqual(pk);
104104
expect(pair.address).toEqual(ss);

packages/util-crypto/src/hd/ethereum/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ describe('hdEthereum', (): void => {
3939
]);
4040

4141
it('derives the right key pair from a mnemonic', (): void => {
42-
const key = hdEthereum(mnemonicToLegacySeed(PHRASE, '', false, 64, 2048));
42+
const key = hdEthereum(mnemonicToLegacySeed(PHRASE, '', false, 64));
4343

4444
expect(key.publicKey).toEqual(PUBLIC);
4545
expect(key.secretKey).toEqual(SECRET);
4646
});
4747

4848
it('derives the right key pair from a mnemonic and a derivation path', (): void => {
49-
const key = hdEthereum(mnemonicToLegacySeed(PHRASE, '', false, 64, 2048), derivationPath);
49+
const key = hdEthereum(mnemonicToLegacySeed(PHRASE, '', false, 64), derivationPath);
5050

5151
expect(key.publicKey).toEqual(PUBLICDERIVED);
5252
expect(key.secretKey).toEqual(SECRETDERIVED);

packages/util-crypto/src/hd/ledger/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('ledgerDerive', (): void => {
5454
tests.forEach(({ ed25519, index: [account, address], mnemonic }, index): void => {
5555
it(`derives a known ed25519 seed for ${network} (${index})`, (): void => {
5656
expect(u8aToHex(
57-
hdLedger(mnemonic, `m/44'/${slip44}'/${account}'/0'/${address}'`, 2048)
57+
hdLedger(mnemonic, `m/44'/${slip44}'/${account}'/0'/${address}'`)
5858
.secretKey
5959
.slice(0, 32)
6060
)).toEqual(ed25519);

packages/util-crypto/src/hd/ledger/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { HARDENED, hdValidatePath } from '../validatePath.js';
99
import { ledgerDerivePrivate } from './derivePrivate.js';
1010
import { ledgerMaster } from './master.js';
1111

12-
export function hdLedger (_mnemonic: string, path: string, rounds?: number): Keypair {
12+
export function hdLedger (_mnemonic: string, path: string): Keypair {
1313
const words = _mnemonic
1414
.split(' ')
1515
.map((s) => s.trim())
@@ -30,7 +30,7 @@ export function hdLedger (_mnemonic: string, path: string, rounds?: number): Key
3030
}
3131

3232
const parts = path.split('/').slice(1);
33-
let seed = ledgerMaster(mnemonic, password, rounds);
33+
let seed = ledgerMaster(mnemonic, password);
3434

3535
for (const p of parts) {
3636
const n = parseInt(p.replace(/'$/, ''), 10);

packages/util-crypto/src/hd/ledger/master.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const XPRV = '0x402b03cd9c8bed9ba9f9bd6cd9c315ce9fcc59c7c25d37c85a36096617e69d41
1313
describe('ledgerDerive', (): void => {
1414
it('derives a known master xprv', (): void => {
1515
expect(u8aToHex(
16-
ledgerMaster(MNEMONIC, undefined, 2048)
16+
ledgerMaster(MNEMONIC)
1717
)).toEqual(XPRV);
1818
});
1919
});

packages/util-crypto/src/hd/ledger/master.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,9 @@ import { mnemonicToSeedSync } from '../../mnemonic/bip39.js';
88

99
const ED25519_CRYPTO = 'ed25519 seed';
1010

11-
/**
12-
* Gets an xprv from a mnemonic
13-
*
14-
* @param mnemonic - The BIP-39 mnemonic phrase to derive the secret from.
15-
* @param password - Optional: password to secure the seed (default: empty string).
16-
* @param wordlist - Optional custom wordlist for mnemonic.
17-
* @param onlyJs - Optional: If `true`, forces use of the JavaScript implementation instead of WASM.
18-
* @param rounds - Optional: Number of PBKDF2 iterations to run (default: 210000).
19-
*/
20-
export function ledgerMaster (mnemonic: string, password?: string, rounds?: number): Uint8Array {
21-
const seed = mnemonicToSeedSync(mnemonic, password, rounds);
11+
// gets an xprv from a mnemonic
12+
export function ledgerMaster (mnemonic: string, password?: string): Uint8Array {
13+
const seed = mnemonicToSeedSync(mnemonic, password);
2214
const chainCode = hmacShaAsU8a(ED25519_CRYPTO, new Uint8Array([1, ...seed]), 256);
2315
let priv;
2416

packages/util-crypto/src/mnemonic/bip39.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,10 @@ function deriveChecksumBits (entropyBuffer: Uint8Array): string {
4747
).slice(0, (entropyBuffer.length * 8) / 32);
4848
}
4949

50-
/*
51-
* @param mnemonic - The BIP-39 mnemonic phrase to derive the secret from.
52-
* @param password - Optional: password to secure the seed (default: empty string).
53-
* @param rounds - Optional: Number of PBKDF2 iterations to run (default: 210000).
54-
*/
55-
export function mnemonicToSeedSync (mnemonic: string, password?: string, rounds?: number): Uint8Array {
50+
export function mnemonicToSeedSync (mnemonic: string, password?: string): Uint8Array {
5651
return pbkdf2Encode(
5752
stringToU8a(normalize(mnemonic)),
58-
stringToU8a(`mnemonic${normalize(password)}`),
59-
rounds
53+
stringToU8a(`mnemonic${normalize(password)}`)
6054
).password;
6155
}
6256

packages/util-crypto/src/mnemonic/toLegacySeed.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ describe('mnemonicToLegacySeed', (): void => {
2121
it(`generates Wasm & Js equivalents for password=${password || 'undefined'}`, (): void => {
2222
expect(
2323
u8aEq(
24-
mnemonicToLegacySeed(MNEMONIC, password, true, 32, 2048),
25-
mnemonicToLegacySeed(MNEMONIC, password, false, 32, 2048)
24+
mnemonicToLegacySeed(MNEMONIC, password, true),
25+
mnemonicToLegacySeed(MNEMONIC, password, false)
2626
)
2727
).toEqual(true);
2828
});
@@ -32,19 +32,19 @@ describe('mnemonicToLegacySeed', (): void => {
3232
describe(`onlyJs=${(onlyJs && 'true') || 'false'}`, (): void => {
3333
it('generates a valid 64bytes seed', (): void => {
3434
expect(
35-
u8aToHex(mnemonicToLegacySeed(MNEMONIC, undefined, onlyJs, 64, 2048))
35+
u8aToHex(mnemonicToLegacySeed(MNEMONIC, undefined, onlyJs, 64))
3636
).toEqual(SEED_64);
3737
});
3838

3939
it('generates a valid 32bytes seed', (): void => {
4040
expect(
41-
u8aToHex(mnemonicToLegacySeed(MNEMONIC, undefined, onlyJs, 32, 2048))
41+
u8aToHex(mnemonicToLegacySeed(MNEMONIC, undefined, onlyJs))
4242
).toEqual(SEED_32);
4343
});
4444

4545
it('fails with non-mnemonics', (): void => {
4646
expect(
47-
() => mnemonicToLegacySeed('foo bar baz', undefined, onlyJs, 32, 2048)
47+
() => mnemonicToLegacySeed('foo bar baz', undefined, onlyJs)
4848
).toThrow(/mnemonic specified/);
4949
});
5050
});

0 commit comments

Comments
 (0)