bdk-practice
bdk-practice copied to clipboard
Add xkey matching with PSBT::Input::bip32_derivation
Proposing a small update in the psbt-xpub
exercise.
It occurred to me that while iterating via Descriptor::for_each_key()
, we should also ensure that we are inserting the right keys into the global key map. If we happen to have a descriptor of many miniscript branches, and we need only one/or some of them to be included for that specific transaction, we should only add the related xpubs in the global map.
Iterating over all the keys will insert all of them, even if they aren't used in the final witness stack.
I made the check by doing a match()
of the xpub in descriptor and thge PSBT input's bip32_derivation
keymap. But this require secp context. So has extra overburden.. Is there any better way to do this??
Thanks @afilini for the look.. I have few more questions..
If, let's say, the creator of the PSBT didn't know about one xpub I don't think that's a good reason for not adding it, if we know it. It could be an argument for also adding the corresponding bip32 path, but that's out of scope for this exercise.
My thought behind this was, if we have a minscript with multiple execution branch, and we only used one branch to satisfy the witness script, this logic will then push all the keys associated with the full descriptor into the global map.. And for taproot cases, no. of execution branches can be very large too.. So makes sense to have some kinda gate over there, and not just push all the keys we can find from a descriptor??
Future proposal: It feels many other PSBT operations can be added in these exercise book.. That would be really helpful.. A lot is going on inside creation-signing-finializing, and if we can demo them like this in parts would be a good resource for devs.. Let me know if I can be of any help for that.. If we have a list I can try to pitch in short exercises like this..
Yes, what you described also makes sense, but it really depends on what one is trying to do specifically.
Ideally we would have options to tweak this, maybe we are the only "updater" and so we have to add everything ourselves, maybe we are just finishing up the work of somebody else.
My guess is that here we should just try to keep it simple, we are not building a full wallet after all
Yes that makes sense.. There would be many other logic like that to handle and its out of scope for the exercise.. But thought this one could be mentioned as a generic thing to do, especially in Taproot kinda env..
Maybe we can just add a note in this exercise like "Something you might wanna keep in mind while using for_each_key
" of descriptors"?? Its actually less of a problem if you do it over a single minscript key.. But then you have to know which minscript you wanna work with among all the execution paths..
Any more ideas you have on how we can expand the PSBT exercise?? Seems very useful for wallet developers.. If you have any mental lists let me know.. I would try to sketch out some exercises from them..