feat(sdk): sign/encode/decode/verify invoice, receipt and tip frames #77

Merged
sirius merged 2 commits from wt/t_cd793d2c into main 2026-09-15 17:38:35 +00:00
Owner

The SDK could already send a payment (sendInvoice / sendTip), but it could not build or inspect a payment frame: pay::sign_* take the ed25519 identity secret and Node exposed only identity_pk(), so the signing half was unreachable from Kotlin.

This adds the signing surface to the node rather than exporting the key, then wraps it for Kotlin.

Core (src/node.rs)

Node::sign_invoice, Node::sign_receipt, Node::sign_tip sign with the node's own identity key and return the core frame struct. No method hands the secret out, and nothing crosses the FFI boundary except the signature.

pay_invoice and tip now call these instead of signing inline, so there is one signing path rather than two. Behaviour is unchanged: same key, same unix_now() timestamp, same frames.

SDK (crates/onionwire-sdk/src/lib.rs)

Backward compatible; nothing existing changed.

  • Records Invoice, Receipt, Tip mirroring src/pay.rs. sig is the raw 64-byte signature, not hex, so a frame re-encodes byte-for-byte.
  • Wire::sign_invoice / sign_receipt / sign_tip - async, WireError.Stopped after shutdown.
  • Free functions encode_invoice / encode_receipt / encode_tip, decode_invoice / decode_receipt / decode_tip (None for a foreign or truncated frame), verify_invoice / verify_receipt / verify_tip against the sender's pubkey hex (false for a bad key or an edited frame, never a panic).

Verification (this branch)

  • SDK: cargo test --locked in crates/onionwire-sdk - 27 passed, 0 failed (19 before; 8 new). cargo clippy --locked --all-targets -- -D warnings clean.
  • Root: cargo clippy --locked --all-targets -- -D warnings clean; cargo test --locked --lib 14 passed; cargo test --locked --test pay 11 passed.
  • Kotlin bindings generated for real from the built cdylib (uniffi-bindgen generate --library libonionwire_sdk.so --language kotlin); the new signatures are on card t_cd793d2c.

No wire-format change. Note the card's child tasks t_2eb62e1e / t_a9a28f76 duplicate already-merged PRs #65 / #66 and should be re-checked before apk-dev is dispatched onto them.

The SDK could already *send* a payment (`sendInvoice` / `sendTip`), but it could not build or inspect a payment **frame**: `pay::sign_*` take the ed25519 identity secret and `Node` exposed only `identity_pk()`, so the signing half was unreachable from Kotlin. This adds the signing surface to the node rather than exporting the key, then wraps it for Kotlin. ## Core (`src/node.rs`) `Node::sign_invoice`, `Node::sign_receipt`, `Node::sign_tip` sign with the node's own identity key and return the core frame struct. No method hands the secret out, and nothing crosses the FFI boundary except the signature. `pay_invoice` and `tip` now call these instead of signing inline, so there is one signing path rather than two. Behaviour is unchanged: same key, same `unix_now()` timestamp, same frames. ## SDK (`crates/onionwire-sdk/src/lib.rs`) Backward compatible; nothing existing changed. * Records `Invoice`, `Receipt`, `Tip` mirroring `src/pay.rs`. `sig` is the raw 64-byte signature, not hex, so a frame re-encodes byte-for-byte. * `Wire::sign_invoice` / `sign_receipt` / `sign_tip` - async, `WireError.Stopped` after shutdown. * Free functions `encode_invoice` / `encode_receipt` / `encode_tip`, `decode_invoice` / `decode_receipt` / `decode_tip` (`None` for a foreign or truncated frame), `verify_invoice` / `verify_receipt` / `verify_tip` against the sender's pubkey hex (`false` for a bad key or an edited frame, never a panic). ## Verification (this branch) * SDK: `cargo test --locked` in `crates/onionwire-sdk` - 27 passed, 0 failed (19 before; 8 new). `cargo clippy --locked --all-targets -- -D warnings` clean. * Root: `cargo clippy --locked --all-targets -- -D warnings` clean; `cargo test --locked --lib` 14 passed; `cargo test --locked --test pay` 11 passed. * Kotlin bindings generated for real from the built cdylib (`uniffi-bindgen generate --library libonionwire_sdk.so --language kotlin`); the new signatures are on card t_cd793d2c. No wire-format change. Note the card's child tasks `t_2eb62e1e` / `t_a9a28f76` duplicate already-merged PRs #65 / #66 and should be re-checked before apk-dev is dispatched onto them.
feat(sdk): sign/encode/decode/verify invoice, receipt and tip frames
All checks were successful
ci / test (pull_request) Successful in 4m24s
android-ci / android (pull_request) Successful in 8m53s
ci / sdk (pull_request) Successful in 1m17s
96d582153a
The SDK could already send an invoice or a tip through Node::pay_invoice /
Node::tip, but it could not touch the payment frames themselves: pay::sign_*
take the ed25519 identity secret and Node exposed only identity_pk(), so the
signing half lived nowhere the SDK could reach.

Add the signing surface to the node instead of exporting the key:

  * Node::sign_invoice / sign_receipt / sign_tip sign with the node's own
    identity key and return the core frame struct. The secret never leaves
    the process and there is no API that hands it out.
  * pay_invoice and tip now call those methods rather than signing inline, so
    there is one signing path, not two.

SDK (crates/onionwire-sdk), all backward compatible:

  * Records Invoice, Receipt, Tip mirroring src/pay.rs, sig as raw bytes so a
    frame re-encodes byte-for-byte.
  * Wire::sign_invoice / sign_receipt / sign_tip (async, over the node).
  * Free functions encode_invoice / encode_receipt / encode_tip,
    decode_invoice / decode_receipt / decode_tip (None on a foreign or
    truncated frame), verify_invoice / verify_receipt / verify_tip against
    the sender's pubkey hex (false on a bad key, never a panic).

Tests: 8 new SDK unit tests (record round-trips through the core encoders,
signer-key-only verification, tamper rejection, foreign/truncated frame,
typed Stopped error after shutdown). SDK 27 passed, 0 failed; SDK clippy
--all-targets -D warnings clean; root clippy --all-targets -D warnings
clean; root lib tests 14 passed; tests/pay.rs 11 passed.
Merge branch 'main' into wt/t_cd793d2c
All checks were successful
ci / test (pull_request) Successful in 3m51s
ci / sdk (pull_request) Successful in 57s
android-ci / android (pull_request) Successful in 8m33s
b1dd18a4a2
sirius merged commit 995f46013e into main 2026-09-15 17:38:35 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!77
No description provided.