paulmillr / scure-bip32

Secure, audited & minimal implementation of BIP32 hierarchical deterministic (HD) wallets.
https://paulmillr.com/noble/#scure
MIT License
65 stars 9 forks source link

Possible discrepancy with the cryptocoinjs hdkey lib #13

Closed jackson-dean closed 1 year ago

jackson-dean commented 1 year ago

This could be a problem with me and not the lib, but I seem to be getting unexpected results when incrementing the account number portion of the path. I have some code that looks like this:

    const mnemonic = formControls.mnemonic.value;
    const passphrase = formControls.passphrase.value;
    const accountNumber = Number(formControls.accountNumber.value);
    const masterSeed = mnemonicToSeedSync(mnemonic, passphrase);

    const keys = HDKey.fromMasterSeed(masterSeed).derive(`m/44'/0'/${accountNumber}'/0/0`);

When I use account number 0, I get the exact same public key that I get from the cryptocoin hdkey lib. However, if I use any other account number: 1, 2, 3, etc. I do not seem to be seeing the same public key that I get from the other lib. Any ideas where I might be going wrong?

paulmillr commented 1 year ago

We have extensive tests. If an output differs between implementations, you can add a failing test:

https://github.com/paulmillr/scure-bip32/blob/main/test/hdkey.test.ts

paulmillr commented 1 year ago

i've just compared 400k random seeds with index 2, it all matches.

jackson-dean commented 1 year ago

so weird, okay must be something I'm doing weird. thanks man, I will take a closer look at where I'm going wrong.

jackson-dean commented 1 year ago

fwiw, I finally found the issue and it is just some weird old code on our side. These libraries are awesome! The lord's work.