Utilities and base libraries for use across polkadot-js for Polkadot and Substrate. Includes base libraries, crypto helpers and cross-environment helpers.
This has been PR-ed previously in https://github.com/polkadot-js/common/pull/1689 and there has been some discussion. However after giving it some thought, we could actually make this work.
part 1
We need a wordlist option passed to the bip39 functions, e.g. last param of wordlist: string[] = DEFAULT_WORDLIST -
For these treat the wordlist the same as onlyJs, i.e. when passed in we want to take the JS (non-WASM) route, i.e. it ties into the changes we made in bip39.ts. This looks something like !hasBigInt || (!wordlist && !onlyJs && isReady()) and the param passed on the JS-only path
We are pulling in the extra wordlists via https://github.com/polkadot-js/common/pull/1803
This has been PR-ed previously in https://github.com/polkadot-js/common/pull/1689 and there has been some discussion. However after giving it some thought, we could actually make this work.
part 1
wordlist
option passed to the bip39 functions, e.g. last param ofwordlist: string[] = DEFAULT_WORDLIST
-https://github.com/polkadot-js/common/blob/91a2eac220df188a5c339f2dcc6ca98e5896da0b/packages/util-crypto/src/mnemonic/bip39.ts#L53 https://github.com/polkadot-js/common/blob/91a2eac220df188a5c339f2dcc6ca98e5896da0b/packages/util-crypto/src/mnemonic/bip39.ts#L95
DEAFULT_WORDLIST
usage in these functions so bewordlist
instead.bip39.spec.ts
to ensure we are actually ok.part 2
Now the base generation is ok, but we may still use the wasm versions which doesn't have support for this. To get around it -
wordlist?: string[], onlyJs?: boolean
https://github.com/polkadot-js/common/blob/91a2eac220df188a5c339f2dcc6ca98e5896da0b/packages/util-crypto/src/mnemonic/validate.ts#L22-L23 https://github.com/polkadot-js/common/blob/91a2eac220df188a5c339f2dcc6ca98e5896da0b/packages/util-crypto/src/mnemonic/toMiniSecret.ts#L11 https://github.com/polkadot-js/common/blob/91a2eac220df188a5c339f2dcc6ca98e5896da0b/packages/util-crypto/src/mnemonic/toLegacySeed.ts#L27 https://github.com/polkadot-js/common/blob/91a2eac220df188a5c339f2dcc6ca98e5896da0b/packages/util-crypto/src/mnemonic/toEntropy.ts#L9 https://github.com/polkadot-js/common/blob/91a2eac220df188a5c339f2dcc6ca98e5896da0b/packages/util-crypto/src/mnemonic/generate.ts#L21
wordlist
the same asonlyJs
, i.e. when passed in we want to take the JS (non-WASM) route, i.e. it ties into the changes we made inbip39.ts
. This looks something like!hasBigInt || (!wordlist && !onlyJs && isReady())
and the param passed on the JS-only pathpart 3
Now we also need keyring support -
addFromMnemonic
,addFromUri
&createFromUri
in https://github.com/polkadot-js/common/blob/892004563faa65dcd81bf60cf8d2e5aba74ae9d4/packages/keyring/src/keyring.ts#L201-L223