Open bumi opened 7 months ago
getAlby/hub#185 is using the LN node's key. but not the key of an onchain wallet address.
I seem to be stuck with this one. Do you have any examples of the relevant methods in any of the APIs? I'm not sure I even understand how to get the onchain wallet address 🤔
Here is how to sign using the wallet key (which won't work in this case): https://github.com/getAlby/ldk-node/blob/main/src/wallet.rs#L457
Here is how to get an address: https://github.com/getAlby/ldk-node/blob/main/src/wallet.rs#L188
It might also be helpful to look at BDK: https://docs.rs/bdk/latest/bdk/wallet/struct.Wallet.html#method.get_address (note: we would want the address index to still auto-increment using AddressIndex::New
)
I think we need to use the message_signing crate (what the LDK wallet uses) but instead of using the wallet node secret key, we need to derive a private key from the same derivation path as the generated onchain address (the AddressInfo has the index and the KeychainKind will be External).
I'm not sure the best way to do that (the most manual way I think would be to use the secp context: https://docs.rs/bdk/latest/bdk/wallet/struct.Wallet.html#method.secp_ctx but maybe there is a better way)
Does that help? you might need to dig in a bit further to see how the addresses are created and if you can somehow get the private key of the address.
Regarding how the derivation works, you can see the image here - each address will have its own derivation path (where the last item in the path is the address index): https://trezor.io/learn/a/what-is-bip32
I don't think we should derive the keys ourself. the LDK/BDK library should have an option to sign a message already. if it does not have that, then we should not do this now.
hmm, seems this is not supported so far? https://github.com/bitcoindevkit/bdk/issues/989
but there is: https://github.com/bitcoindevkit/bdk/pull/601/files
Maybe we can take a minute to look into this and see how easy it is to implement. but I worry that it's too complicated, so we leave it.
Not prioritizing for now - this is more complicated than expected and not necessary
@bumi this is different from https://github.com/getAlby/hub/issues/185 right? should the issue be in progress?