Author

Topic: Help bitcoin core (Read 45 times)

staff
Activity: 3458
Merit: 6793
Just writing some code
October 25, 2024, 12:37:00 PM
#6
As I said in my post, the seed itself is no longer stored in a descriptor wallet as it is used only once to generate the master private key.

When the descriptors are created, the master public key for the master private key is computed and that public key is encoded into the descriptor. The chaincode is not secret data, so it is included directly in the master public key in the descriptor.

The private key is then extracted from the master private key and stored separately by itself. The master private key is reconstructed as needed by using the master public key from a descriptor and replacing the public key with the stored private key.
newbie
Activity: 13
Merit: 5
October 24, 2024, 11:12:44 PM
#5
One way to do it is to find the xpub in the wallet and decode it to extract the chain code, but it seems weird that this is how its done in the update? or is it?
newbie
Activity: 13
Merit: 5
October 24, 2024, 10:06:27 PM
#4
The chaincode of the master private key is derived from a 256 bit seed following BIP 32: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#user-content-Master_key_generation

The seed itself is discarded once the master private key is computed as it is extraneous information that is never used once the master private key is produced.



It is unclear to me what problem you are actually trying to solve. None of what you described makes any sense, and it seems like this is an XY Problem. Please describe what it is you are trying to achieve, not what it is you think the way to the solution is.

hehe thanks, yes you are right - my explanation was not so good. Let me take it from the beginning, by explaining what it is that i am trying to do.

I have a Legacy wallet and i dump it with bitcoin cli. (dumpwallet "c:/path/to")

result;
# extended private masterkey: xprv9s21ZrQH143K39Uh6WDcTpGFfvhHrFvuELiMGfgcTmyDWyFwUEyM5bPDr1izEkdvPz8YoU4inik zq5FgqGqheZ9N1g8JY9ZYB5rQfDTvQy3
#
#...1000+ privkeys
# KzMmTGLuLCtGpgHNVPZiPmkY5r1dmrRh4JVMhsPAH7s9dXgvCNf8 2024-10-01T15:19:13Z hdseed=1 # addr=bc1qt25vctmf................... hdkeypath=m

The goal is to verify that i can recreate the extended private masterkey;
1. decode the WIF back to raw privkey: 5da81cba4308754d78458f31fcf8d656cfe545f88d3e20b61be65c30976881be
2. use the raw privkey as entrophy with hmac512, and generate an xpriv:
result;
# xpriv: xprv9s21ZrQH143K39Uh6WDcTpGFfvhHrFvuELiMGfgcTmyDWyFwUEyM5bPDr1izEkdvPz8YoU4inik zq5FgqGqheZ9N1g8JY9ZYB5rQfDTvQy3



//////////////////////////////////

Sorry for the mess, but as you can see, i was able to derive the xpriv from the legacy wallet - because the seed was stored as a priv key and then used as entropy. In descriptorwallets, i cant find the seed in the same way.

i run "listdescriptors true" and the xpriv is shown:
xprv9s21ZrQH143K2XZn9uKACsWBgS8XQEp4biHSmAHkJhzfxrRMrC8AetMqJ3fSb7kt6VUy7xq1nCW npxipqZ4osUVypWkf8hZPCrvS27xnZyQ

when i decode this xpriv, it is clear it was made with:
chain code: 2f1e6d9c24fce6e898a26f5c13256c605fdd02d807fb4090e92b59d830afc56c
priv::::::::: b7e80b043fb168604c965dcb680509423513b9daa6dd44d1ec132e9169e1d99e


So either i need to find both the chain code and the priv, or i need the seed that created the chaincode and priv.

I dump all key/values in the SQLite database, and i find this:

key:
1377616c6c657464657363726970746f726b657974fd7bafbfd88fda0f6f16e61d4cedd5671e0c1 ff97ee5dd8a5053bef4e58eb6210349a3cabb153821e449073100b11a595c4b684fc59adf6fa626 4138239350eab6
value:
d63081d30201010420b7e80b043fb168604c965dcb680509423513b9daa6dd44d1ec132e9169e1d99ea08185308182020101302c06072a8648ce3d0101022100fffffffffffffffffffffffffffffffff ffffffffffffffffffffffefffffc2f300604010004010704210279be667ef9dcbbac55a06295ce 870b07029bfcdb2dce28d959f2815b16f81798022100fffffffffffffffffffffffffffffffebaa edce6af48a03bbfd25e8cd0364141020101a1240322000349a3cabb153821e449073100b11a595c 4b684fc59adf6fa6264138239350eab66b7a19cc76de134e8bda6240f1305744143299881755702 ef104130f0a5badab


at byteoffset 10 to 42 in the value you see the privkey from the decoded xpriv, but where is the chain code? or better, where is the seed that created the priv and xpriv? I assume its there somewhere as bitcoin core was able to generate the xpriv??

hope its not too cluttery of a question..
staff
Activity: 3458
Merit: 6793
Just writing some code
October 24, 2024, 09:12:38 PM
#3
The chaincode of the master private key is derived from a 256 bit seed following BIP 32: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#user-content-Master_key_generation

The seed itself is discarded once the master private key is computed as it is extraneous information that is never used once the master private key is produced.



It is unclear to me what problem you are actually trying to solve. None of what you described makes any sense, and it seems like this is an XY Problem. Please describe what it is you are trying to achieve, not what it is you think the way to the solution is.
newbie
Activity: 13
Merit: 5
October 24, 2024, 06:08:01 PM
#2

I need help understanding the following keys in bitcoin core new descriptorwallets:

walletdescriptor
walletdescriptorkey
walletdescriptorcache
walletdescriptorlcache

They all have descriptorID, pubkeys, and walletdescriptorkey also has the privkey, but where is the chaincode for the xpriv, or how is it made, and if its from a seed, where is the seed stored?


I guess i could extract the chain code from the xpub keys that are visible, but is this how the descriptorwallets now do it??
newbie
Activity: 13
Merit: 5
October 24, 2024, 06:00:58 PM
#1
The new descriptorwallets is a tough one to wrap my head around.... I read alot of the source code but i couldnt locate the specifics. If anyone can answer, thank you very much, i am very frustrated.....

This is in regards to unencrypted wallets btw:
In the legacy wallets, the wallet stored key/values where the value contained raw private keys. by default, one of those priv keys was the seed used to derive the rest.

So,
In the new descriptorwallets, i used "listdescriptors true" to expose the xpriv.

I decoded the xpriv to find the chain code and master priv:
Chain Code: 93178c464f29bde405889bdae733bd05fcd7ad0711246734f9ec25031fe7cce8
Master Private Key: ac437aaabc98750d666d0afb00c40bb43d0872fa8e981e20519d1b769eb27062


The problem im facing is that i dont understand how bitcoin core got the chaincode in the descriptorwallets. Does it use the desc_id or something?

The reason i need to know this is that the only priv key my wallet holds is "ac437aaabc98750d666d0afb00c40bb43d0872fa8e981e20519d1b769eb27062", and i need to derive the xpriv to restore the wallet. So at first, when i found the key, value that (in previous legacy wallet) held the seed, it now holds the priv key:

ac437aaabc98750d666d0afb00c40bb43d0872fa8e981e20519d1b769eb27062

so where is the chain code? normally, the privkey and chain code would be derived at the same time, so i dont understand... Anyone?
Jump to: