alexbosworth / ln-service

Node.js interface to LND
MIT License
318 stars 61 forks source link

Derive private key #127

Closed apotdevin closed 3 years ago

apotdevin commented 3 years ago

Hey, don't know if it's currently possible with the api but is there some way to derive a private key from your wallet with ln-service?

For example for ln-auth you need to derive a private key with the path m/138'/0 for the signing

alexbosworth commented 3 years ago

I'm not sure I would use my node real private keys with arbitrary protocols...

If you consider that a private key is simply a random number, it is possible to generate a new key for this: You can use diffieHellmanComputeSecret to compute such a random series of bytes, doing the diffie with your own public key

You can convert random entropy to a mnemonic seed https://github.com/bitcoinjs/bip39

And you can convert that HD seed to derived keys: https://github.com/bitcoinjs/bip32

apotdevin commented 3 years ago

Ah the diffieHellman.. might just work. I believe the only requirement is that the random series of bytes doesn't change when computed again, and think this is the case with this one, will indeed check this 👍

alexbosworth commented 3 years ago

Yes it will not change when computed again, although you might want to mess with the key family and index or use other methods to make sure you are separated off from something else that might use the same key for a different purpose

apotdevin commented 3 years ago

Awesome it worked perfectly 👍 Yeah for lnauth it suggests to use key family of 138

Tried with a v0.9.1 lnd node and it worked but for a v0.10.2 lnd node it gives:

 503,
  'UnexpetedErrorDerivingSharedKey',
  {
    err: Error: 1 CANCELLED: Received http2 header with status: 404

You know what could be the issue? Is version 0.10.2 not compatible with diffieHellmanComputeSecret?

alexbosworth commented 3 years ago

Awesome it worked perfectly 👍 Yeah for lnauth it suggests to use key family of 138

Tried with a v0.9.1 lnd node and it worked but for a v0.10.2 lnd node it gives:

 503,
  'UnexpetedErrorDerivingSharedKey',
  {
    err: Error: 1 CANCELLED: Received http2 header with status: 404

You know what could be the issue? Is version 0.10.2 not compatible with diffieHellmanComputeSecret?

Maybe the build flag wasn't present?

apotdevin commented 3 years ago

Might be, always have issues with that node. Will check, thanks for the help!