polkadot-labs / hdkd

A Polkadot minimalistic HDKD library
MIT License
4 stars 1 forks source link

generateMnemonic should return an array #104

Open ryanleecode opened 3 months ago

ryanleecode commented 3 months ago

This should return an array rather than string IMO. B/c you need to arbitrary assume the delimiter to split, where as if its an array i can easily reverse the operation with join.

https://github.com/polkadot-labs/hdkd/blob/fc5b52f9960c0ad8b0bb7397fff0ffe75b58907f/packages/hdkd-helpers/src/bip39.ts#L90

kratico commented 3 months ago

A mnemonic is a sentence so returning a string is fine. The definition of a sentence may be words separated/joined by spaces but I couldn't find the sentence definition in the spec, so this is ambiguous. Anyway, this is also consistent with mnemonicToEntropy and entropyToMnemonic types which was ported/adapted from https://github.com/bitcoinjs/bip39/blob/a7ecbfe2e60d0214ce17163d610cad9f7b23140c/ts_src/index.ts

Nevertheless, a few helper functions can be added to return/receive the mnemonic words as an array.