Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hdkey: save seed for use in multiple derivations #1365

Open
pro-wh opened this issue May 12, 2023 · 2 comments
Open

hdkey: save seed for use in multiple derivations #1365

pro-wh opened this issue May 12, 2023 · 2 comments
Labels
c:client-sdk/typescript Category: TypeScript client SDK

Comments

@pro-wh
Copy link
Contributor

pro-wh commented May 12, 2023

our wallet wants to derive several accounts at a time. it's more efficient to do the expensive part of stretching the mnemonic into a seed once and allow the library user to get multiple paths' keys from that seed.

const seed = await mnemonicToSeed(mnemonic, passphrase);
const key = HDKey.makeHDKey(ED25519_CURVE, seed);
return key.derivePath(`m/44'/474'/${index}'`).keypair;

Originally posted by @lukaw3d in oasisprotocol/wallet#1454 (comment)

@lukaw3d
Copy link
Member

lukaw3d commented May 15, 2023

Quick attempt at profiling m/44'/474'/0' ... m/44'/474'/47':

https://github.com/oasisprotocol/oasis-wallet-web/blob/8feb1357d44afc804f1a86b2a88c581152faf1a0/src/app/state/importaccounts/saga.ts#L70-L85

mnemonicToSeed: 841ms
makeHDKey: 183ms
derivePath: 519ms

@pro-wh pro-wh changed the title hdkey: save seed for use in multiple derivatoins hdkey: save seed for use in multiple derivations May 15, 2023
@pro-wh
Copy link
Contributor Author

pro-wh commented May 15, 2023

interesting, mnemonicToSeed from bip39 looks like it uses @noble sha512 in pbkdf2 https://github.com/bitcoinjs/bip39/blob/v3.1.0/src/index.js#L41 (c: 2048, whatever that parameter is)
derivePath calls derive, and derive calls makeHDKey, and the stuff outside makeHDKey doesn't look like it ought to take 300+ms
and makeHDKey uses js-sha512, if I were to count it out, three calls per path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c:client-sdk/typescript Category: TypeScript client SDK
Projects
None yet
Development

No branches or pull requests

2 participants