Skip to content

Verify & fix invoice description_hash == sha256(metadata) (LUD-06) #29

Description

@Chemaclass

Context

For LNURL-pay (LUD-06), the bolt11 invoice's description_hash must equal sha256(metadata) where metadata is the exact UTF-8 string returned in the pay params metadata field. Wallets that verify this will reject a mismatched invoice.

  • src/Invoice/Domain/BackendInvoice/LnbitsBackendInvoice.php — sends to LNbits:
    'unhashed_description' => bin2hex($metadata),
    'description_hash'     => hash('sha256', $metadata),
  • src/Invoice/Application/InvoiceGenerator.php — builds metadata via LnurlPayMetadata and passes it to requestInvoice().
  • src/Shared/Value/LnurlPayMetadata.php — the metadata string builder.

Goal

Verify and, if needed, fix that the invoice returned to the wallet carries description_hash == sha256(metadata) using the same metadata string advertised in the pay params — so real wallets accept the invoice.

Scope / Tasks

  • Confirm what LNbits does when both unhashed_description and description_hash are supplied — determine whether they can conflict and which one LNbits honors. Send only what's needed (likely just unhashed_description, letting LNbits hash it, OR just the correct description_hash), backed by the LNbits API docs.
  • Confirm bin2hex($metadata) is the encoding LNbits expects for unhashed_description (hex of the raw metadata bytes) and that the resulting invoice's description_hash matches sha256(metadata).
  • If a mismatch is possible, fix the payload so the advertised metadata and the invoice's description_hash always agree.
  • Add a regression test asserting the payload sent to HttpApiInterface encodes the metadata such that description_hash == sha256(metadata) (stub the HTTP layer and assert on the request body).

Implementation notes

  • The pay-params metadata and the invoice metadata must be byte-identical — both already flow from LnurlPayMetadata; keep it that way.
  • Back any claim about LNbits behavior with the LNbits API docs or a real response sample (do not assume) — see repo convention on evidence-backed external-API claims.

Acceptance criteria

  • Documented confirmation (docs/sample) of the correct LNbits payload for description-hash LNURL invoices.
  • Test asserts the sent body yields description_hash == sha256(metadata).
  • composer test-all green.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions