alexbosworth / ln-service

Node.js interface to LND
MIT License
319 stars 60 forks source link

parsePaymentRequest to sign back request with more tags #124

Closed nicolasburtey closed 4 years ago

nicolasburtey commented 4 years ago

If I run this:

  const {parsePaymentRequest, createUnsignedRequest} = require('invoices');
  const request_org = (await lnService.createInvoice({lnd, description: "abc"})).request
  const decoded = parsePaymentRequest({request: request_org});

I have the following issue: ExpectedPaymentDescriptionOrDescriptionHashForPayReq

I can add a description field to get the error away (but I believe memo are optional, not mandatory?)

If I run the full script, I'm running into this issue ExpectedValidSignatureForSignedPaymentRequest:

  const { lnd } = lnService.authenticatedLndGrpc(getAuth())
  const {parsePaymentRequest, createUnsignedRequest} = require('invoices');

  const request_org = (await lnService.createInvoice({lnd, description: "abc"})).request
  const decoded = parsePaymentRequest({request: request_org});

  const unsignedComponents = createUnsignedRequest(decoded);
  const hash = unsignedComponents.hash

  const {signature} = await lnService.signMessage({lnd, message: hash});
  const {request} = lnService.createSignedRequest({
    destination: decoded.destination,
    hrp: unsignedComponents.hrp,
    signature,
    tags: unsignedComponents.tags,
  });

Any idea what I'm doing wrong here?

alexbosworth commented 4 years ago

I guess that my encoding method does expect a description, but I can modify it to not require one

Can you show the code for signature? Does it work if you specify tokens in createSignedRequest?

nicolasburtey commented 4 years ago

I asked for clarification on lightning-rfc regarding the description part.

Can you show the code for signature?

Maybe I'm mistaken your question, but I'm using:

const {signature} = await lnService.signMessage({lnd, message: hash});

Does it work if you specify tokens in createSignedRequest?

createSignedRequest doesn't take token as an argument. it takes an array of tags + hrm (which contain the amount).

alexbosworth commented 4 years ago

I put up a fix for the empty description issue, can you try that out?

alexbosworth commented 4 years ago

Ok one thing I would try changing is instead of using signMessage, use signBytes

alexbosworth commented 4 years ago

Here is an example code you can follow: https://github.com/alexbosworth/ln-service/blob/master/test/signerrpc-integration/test_sign_bytes.js#L13

nicolasburtey commented 4 years ago

trying now. Seems SignBytes is not mentioned in the method in the readme. Don't know if this is intentional.

nicolasburtey commented 4 years ago

Is this in some ways the derivation path used by lnd to get the private key of the node (that correspond to the public key broadcasted publicly) ?

      key_family: 6,
      key_index: 0,
alexbosworth commented 4 years ago

trying now. Seems SignBytes is not mentioned in the method in the readme. Don't know if this is intentional.

You're right, it should be mentioned in the readme but it's not there

alexbosworth commented 4 years ago

Is this in some ways the derivation path used by lnd to get the private key of the node (that correspond to the public key broadcasted publicly) ?

      key_family: 6,
      key_index: 0,

That's the identity key, you can use getPublicKey to see the public key at family 6, index 0

alexbosworth commented 4 years ago

createSignedRequest doesn't take token as an argument. it takes an array of tags + hrm (which contain the amount).

You're right on this, I just saw it taking tokens in the test but that was superfluous

nicolasburtey commented 4 years ago

has time to made more tests. it's working. thanks!