Allow for WASM-as-available mnemonicToBip39 call (#669)

This commit is contained in:
Jaco Greeff
2020-08-25 21:16:22 +02:00
committed by GitHub
parent 83fdd11c59
commit e5dd55e419
5 changed files with 25 additions and 12 deletions
+4
View File
@@ -1,5 +1,9 @@
# CHANGELOG
## 3.4.0-beta.x
- Allow for WASM-as-available `mnemonicToBip39` call
## 3.3.1 Aug 24, 2020
- Add `addressRaw` to Keyring interface (if address encoding is different to publicKey)
+1 -1
View File
@@ -27,7 +27,7 @@
"dependencies": {
"@babel/runtime": "^7.11.2",
"@polkadot/util": "3.3.1",
"@polkadot/wasm-crypto": "^1.3.1",
"@polkadot/wasm-crypto": "^1.4.0-beta.6",
"base-x": "^3.0.8",
"bip39": "^3.0.2",
"blakejs": "^1.1.0",
@@ -3,6 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { u8aToHex } from '@polkadot/util';
import { waitReady } from '@polkadot/wasm-crypto';
import { mnemonicToBip39 } from './';
@@ -14,4 +15,14 @@ describe('mnemonicToBip39Seed', (): void => {
)
).toEqual('0x3c121e20de068083b49c2315697fb59a2d9e8643c24e5ea7628132c58969a027');
});
it('generates the seed via WASM', async (): Promise<void> => {
await waitReady();
expect(
u8aToHex(
mnemonicToBip39('seed sock milk update focus rotate barely fade car face mechanic mercy')
)
).toEqual('0x3c121e20de068083b49c2315697fb59a2d9e8643c24e5ea7628132c58969a027');
});
});
+4 -6
View File
@@ -5,7 +5,7 @@
import { mnemonicToSeedSync } from 'bip39';
import { bufferToU8a } from '@polkadot/util';
// import { bip39ToSeed, isReady } from '@polkadot/wasm-crypto';
import { bip39ToSeed, isReady } from '@polkadot/wasm-crypto';
/**
* @name toSeed
@@ -25,9 +25,7 @@ import { bufferToU8a } from '@polkadot/util';
* ```
*/
export default function toBip39 (mnemonic: string, password = ''): Uint8Array {
// FIXMe Re-add when we have support in the WASM libs again
// return isReady()
// ? bip39ToSeed(mnemonic, password)
return bufferToU8a(mnemonicToSeedSync(mnemonic, password)).subarray(0, 32);
return isReady()
? bip39ToSeed(mnemonic, password)
: bufferToU8a(mnemonicToSeedSync(mnemonic, password)).subarray(0, 32);
}
+5 -5
View File
@@ -2849,7 +2849,7 @@ __metadata:
dependencies:
"@babel/runtime": ^7.11.2
"@polkadot/util": 3.3.1
"@polkadot/wasm-crypto": ^1.3.1
"@polkadot/wasm-crypto": ^1.4.0-beta.6
"@types/bn.js": ^4.11.6
"@types/elliptic": ^6.4.12
"@types/pbkdf2": ^3.1.0
@@ -2881,12 +2881,12 @@ __metadata:
languageName: unknown
linkType: soft
"@polkadot/wasm-crypto@npm:^1.3.1":
version: 1.3.1
resolution: "@polkadot/wasm-crypto@npm:1.3.1"
"@polkadot/wasm-crypto@npm:^1.4.0-beta.6":
version: 1.4.0-beta.6
resolution: "@polkadot/wasm-crypto@npm:1.4.0-beta.6"
peerDependencies:
"@polkadot/util": "*"
checksum: 033a434ccfd882737fd3952c4a587e4eb0220730dca9397a16255336a40e58f6102a8c0baee8d5e0aa5c6b240357e1bacd67705da6d52938df4fbd7fc4827fce
checksum: 910e95665b2dd276b554ca3f7021bc810f4276d2191318cfb0a1103a90596a0d94c6872dfea922ebb4f368f50a2391d62c14a1465b2babbcfc4606c90ec9bd42
languageName: node
linkType: hard