Skip to content

Add Zig reference implementation#32

Closed
vincenzopalazzo wants to merge 2 commits into
rustyrussell:masterfrom
vincenzopalazzo:claude/modest-jackson
Closed

Add Zig reference implementation#32
vincenzopalazzo wants to merge 2 commits into
rustyrussell:masterfrom
vincenzopalazzo:claude/modest-jackson

Conversation

@vincenzopalazzo
Copy link
Copy Markdown
Contributor

Summary

  • Pure Zig BOLT12 offer decoder with zero external dependencies (uses only std.crypto.hash.sha2)
  • Ported from the TypeScript reference implementation (PR Pure TypeScript BOLT12 library (bolt12-utils) #30 / bolt12-utils)
  • Modules: bigsize, bech32, tlv, merkle, offer, bolt12 (high-level API)
  • 142 unit tests passing against the official offers-bolt-test.json test vectors
  • Includes example CLI decoder (zig build run -- <bolt12-string>)
  • Compatible with Zig 0.15

Test plan

  • zig build compiles without errors
  • zig build test passes all 142 tests
  • Test vectors from test-vectors/offers-bolt-test.json validated
  • Example decoder produces correct output for valid offers
  • Invalid offers are properly rejected

🤖 Generated with Claude Code

vincenzopalazzo and others added 2 commits April 3, 2026 12:08
Pure Zig implementation of the BOLT12 offer decoder with zero
dependencies beyond the standard library. Ported from the TypeScript
reference implementation (bolt12-utils).

Modules:
- bigsize: variable-length integer encoding per BOLT 1
- bech32: BOLT12 bech32 encoding/decoding (no checksum)
- tlv: TLV stream parsing with ascending order validation
- merkle: tagged hash merkle tree for offer_id computation
- offer: semantic validation of offer TLV fields
- bolt12: high-level decodeOffer API

Includes 142 unit tests and integration tests against the official
test vectors from offers-bolt-test.json.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Validate Zig implementation against all three official test suites:

- offers-test.json: 53 vectors (20 valid + 33 invalid offers)
- format-string-test.json: 12 vectors (bech32 format parsing, +
  continuation, case handling)
- signature-test.json: 3 vectors (merkle tree leaf/branch/root hashes)

Also fixes offer validation to perform full secp256k1 point-on-curve
checks using std.crypto.ecc.Secp256k1, matching the TypeScript
reference which uses @noble/curves.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vincenzopalazzo
Copy link
Copy Markdown
Contributor Author

this need more work I open the PR in the wrong repo

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