-
Notifications
You must be signed in to change notification settings - Fork 809
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
Derivation Path of known outputs is incorrect #484
Comments
Hi @christsim I'm looking into this... could you please tell me exactly how you're using the |
Hi @pinheadmz, So just a few notes first. I'm using Then I create a watchOnly wallet and load the xpub account key into it (derived from the masterKey offline). When I want to send a transaction, I call Then on an offline pc, I first derive the xprv account key from the masterKey. Then to get the private key which matches the inputs of the unsigned transaction, I call, Here is my signing code (simplified): var derivedXprv = xprvAccountKey.derivePath(path);
var ring = bcoin.WalletKey.fromPrivate(derivedXprv.privateKey, true);
mtx.sign(ring); Hope that clears it up? Regards, |
I'm sorry Chris, how are you getting And also have you tried just asking the wallet to sign the tx automatically? I think if you have derived enough addresses on the offline computer it should recognize it has the keys and sign. There are also methods to return a private key given its address. But in general I think I see what you mean. The |
I'm pretty much deriving it the same way as this https://iancoleman.io/bip39/. I'm then giving the Bcoin will then derive addresses based on
So obviously the watchOnly wallet can't sign the transactions. I don't generate addresses on the offline wallet so it can't find the matching private key by itself. I'm currently signing the transaction this like, as disussed above: var derivedXprv = xprvAccountKey.derivePath(path);
var ring = bcoin.WalletKey.fromPrivate(derivedXprv.privateKey, true);
mtx.sign(ring); However I have to manipulate the path to get the transactioned sigend. |
OK I figured this out.. So if your tx is saying an address path is this:
Then from the wallet xprv master key, the REAL derivation path is actually this (BTC testnet):
...and I've verified this on the bip39 website. The bug is in how the tx object reports the derivation path on wallet transactions, and I'll look into fixing that today :-) |
The PR for this is still open at #502 was this closed as it's not an issue? Seems like there is still an outstanding bug, not having reproduced the issue myself yet. |
Not sure why I closed. Sorry about that. |
Hi All.
When calling
wallet.getTX(hash)
the outputs that belong to our wallets have a path included to help you derive that address of the private key again. However, as you can see below, the derivation path is not correct:derivation:"m/0'/1/2"
but should be:
derivation:"m/1/2"
And therefore you cannot regenerate the correct private key for that input. The hardened account should not be included in the path as it's already included in the base xpub/xprv account key.
Steps to reproduce:
accountKey.derivePath(path.derivation)
Regards,
Chris
The text was updated successfully, but these errors were encountered: