Skip to content

fix(js): reject empty offer_description TLV (BOLT12)#35

Open
vincenzopalazzo wants to merge 1 commit into
rustyrussell:masterfrom
vincenzopalazzo:fix/reject-empty-offer-description
Open

fix(js): reject empty offer_description TLV (BOLT12)#35
vincenzopalazzo wants to merge 1 commit into
rustyrussell:masterfrom
vincenzopalazzo:fix/reject-empty-offer-description

Conversation

@vincenzopalazzo

Copy link
Copy Markdown
Collaborator

Summary

Aligns validateOffer() with BOLT12 offer encoding:

  • When offer_amount is set, writers MUST set offer_description to a complete description.
  • Readers MUST NOT respond when offer_amount is set and offer_description is not set.

A type-10 TLV with zero-length payload is not “descriptionless” — writers should omit the TLV entirely (as in minimal amount-less offers).

Changes

  • js/src/offer.ts: reject Invalid: empty offer_description when TLV 10 has length 0; only count non-empty descriptions for the amount/description semantic check.
  • js/src/fields.ts: do not surface description for empty TLV 10 payloads.
  • test-vectors/offers-bolt-test.json: add invalid vector (fixed amount + empty description).

Testing

cd js && npm test
# offers-test.ts: 54/54 pass (includes new vector)

Context

Decoded a real-world offer that had offer_amount + offer_description with length 0; it previously passed validation incorrectly.

BOLT12 treats descriptionless offers as omitting type 10 entirely.
A zero-length offer_description must not satisfy the requirement
that fixed-amount offers include a complete description.

- validateOffer: error on empty offer_description
- extractOfferFields: omit description when TLV payload is empty
- test vector: amount + empty description offer is invalid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant