getAlby / lightning-browser-extension

The Bitcoin Lightning Browser extension that connects to different wallet interfaces and brings deep lightning integration to the web
https://getalby.com
MIT License
530 stars 193 forks source link

[BUG] Galoy doesn't return preimage with WebLN #2946

Closed reneaaron closed 7 months ago

reneaaron commented 8 months ago

Describe the bug

Implement WebLN (return preimage for sendPayment calls)

https://github.com/getAlby/lightning-browser-extension/blob/master/src/extension/background-script/connectors/galoy.ts#L314

openoms commented 8 months ago

Looking into this, can extend the graphql call. The API can return the preimage when paying through LN, but doesn't do for intraledger:

mutation LnInvoicePaymentSend($input: LnInvoicePaymentInput!) {
  lnInvoicePaymentSend(input: $input) {
    errors {
      message
    }
    status
    transaction {
      settlementVia {
        ... on SettlementViaLn {
          preImage
        }
        ... on SettlementViaIntraLedger {
          counterPartyUsername
          counterPartyWalletId
        }
      }
    }
  }
}

would it be useful to return the username or just a note about intraledger settlement?

Testing paying a new account without username set is not returning anything so it must be a note about intraledger payment:

{
  "data": {
    "lnInvoicePaymentSend": {
      "errors": [],
      "status": "SUCCESS",
      "transaction": {
        "settlementVia": {
          "counterPartyUsername": null,
          "counterPartyWalletId": null
        }
      }
    }
  }
}

Example response on signet LN:

{
  "data": {
    "lnInvoicePaymentSend": {
      "errors": [],
      "status": "SUCCESS",
      "transaction": {
        "settlementVia": {
          "preImage": "b88173fa2326356c4f0f3399cc0c7e2eb6c1c8b75369c45b708c77fdb4799e15"
        }
      }
    }
  }
}
reneaaron commented 8 months ago

If the Galoy connector doesn't reliably return preimages for WebLN it will break quite some apps that follow the current WebLN spec and possibly would force them to handle those special cases (for intraledger payments) which is clearly not how WebLN is intended to work.

Why is it that you can't provide a preimage for intraledger payments? Do they never hit the node but just the DB?

openoms commented 8 months ago

The preImage could be returned for intraledger payments as well as the invoice is generated on the node (not knowing that it will be paid intraledger or over LN) and the paymentSecret is known. Will open an issue for discussion with the Galoy team.

eg.:

curl --request POST \
    --header 'content-type: application/json' \
    --header 'X-API-KEY: galoy_staging_xxxxxxxxxxxx' \
    --url 'https://api.staging.galoy.io/graphql' \
    --data '{"query":"mutation LnInvoiceCreate($input: LnInvoiceCreateInput!) {\n  lnInvoiceCreate(input: $input) {\n    invoice {\n      paymentHash\n      paymentRequest\n      createdAt\n      satoshis\n      paymentStatus\n      paymentSecret\n    }\n  }\n}","variables":{"input":{"amount":21,"walletId":"xxxxxxxxxx"}}}'
{
  "data": {
    "lnInvoiceCreate": {
      "invoice": {
        "paymentHash": "b1cf0faaf9fd7b15de77cf032d9ca7559612c8356c6b21a7c45402d65e9c4869",
        "paymentRequest": "lntbs210n1pjc9w42pp5k88sl2hel4a3thnheupjm8982ktp9jp4d34jrf7y2spdvh5ufp5sdqqcqzpuxqyz5vqsp5tr8c5ngy7s9ryvu9v3hx5tg26wfrx8kg42uhuqlleaavsc6qpp7s9qyyssq2tjznjeckf8j8mcpgezcyprat4yys3ac9fqf0g2uutkavt3qj5grqtha38lkxyvlncfwhfh88ssa895ur6a6a8h8390s6qm9tn34kdsqlwkhkj",
        "createdAt": 1703066283,
        "satoshis": 21,
        "paymentStatus": "PENDING",
        "paymentSecret": "58cf8a4d04f40a323385646e6a2d0ad392331ec8aab97e03ffcf7ac86340087d"
      }
    }
  }
}
bumi commented 8 months ago

that would be great! \o/

openoms commented 8 months ago

Until the preimage is returned for intraledger also can offer a partial improvement to return it for ln settlements at least: #2953