getAlby / hub

Alby Hub - Your own lightning node connected to every app. Run anywhere. Become self-sovereign.
https://albyhub.com
Apache License 2.0
90 stars 18 forks source link

Sign message using an onchain key #162

Open bumi opened 7 months ago

rolznz commented 7 months ago

@bumi this is different from https://github.com/getAlby/hub/issues/185 right? should the issue be in progress?

bumi commented 7 months ago

getAlby/hub#185 is using the LN node's key. but not the key of an onchain wallet address.

rdmitr commented 7 months ago

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 🤔

rolznz commented 7 months ago

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.

rolznz commented 7 months ago

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

bumi commented 7 months ago

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.

bumi commented 7 months ago

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.

rolznz commented 4 months ago

Not prioritizing for now - this is more complicated than expected and not necessary