Skip to content

Add authenticated encryption, in-flight recovery, and Lightning withdrawal#5

Merged
nisfeb merged 1 commit into
masterfrom
feature/melt-withdraw
Mar 13, 2026
Merged

Add authenticated encryption, in-flight recovery, and Lightning withdrawal#5
nisfeb merged 1 commit into
masterfrom
feature/melt-withdraw

Conversation

@nisfeb
Copy link
Copy Markdown
Contributor

@nisfeb nisfeb commented Mar 13, 2026

Summary

  • Authenticated encryption: encrypt-then-MAC with HMAC-SHA256 — rejects tampered ciphertext before decrypting, random ephemeral keys via eny, mint URL inside encrypted payload
  • In-flight token recovery: tokens held in escrow 30 min after signing, NUT-03 swapped for fresh proofs if unused — prevents permanent loss from failed pushes
  • Lightning withdrawal: maintainers can withdraw received tokens to Lightning via NUT-05 melt, with per-mint wallet display in admin UI

Changes

Security (agent)

  • ecash-encrypt takes eny param, derives separate enc_key and mac_key from DH shared secret
  • HMAC-SHA256 over ciphertext (encrypt-then-MAC), included as ecash-mac field
  • ecash-decrypt verifies MAC first, returns ~ on failure
  • Token payload now {mint, tokens} JSON — mint URL protected by encryption
  • In-flight map with 30-min Behn timer, NUT-03 swap on expiry via verify-keys/verify-swap flow

Withdrawal (agent + UI)

  • State-8: adds pending-melts=(map @t pending-melt)
  • POST /vitriol/admin/withdraw: accepts mint + BOLT11 invoice
  • Iris melt handlers: quote → select proofs → execute → restore on failure
  • Admin UI: per-mint balance display with proof count, invoice input, withdraw button

Types

  • pending-melt: mint, step, invoice, proofs-used, quote-id, fee-reserve

Test plan

  • MAC verification rejects modified ciphertext
  • In-flight tokens return to wallet via NUT-03 swap after 30 min
  • Per-mint balances display correctly in maintainer admin
  • Withdraw to Lightning: quote + execute succeeds, proofs consumed
  • Failed melt restores proofs to wallet
  • State migration from 6/7 → 8 preserves existing data

🤖 Generated with Claude Code

… withdrawal

Security fixes:
- Encrypt-then-MAC: separate enc/mac keys from DH secret, HMAC-SHA256
  ciphertext authentication, reject tampered data before decrypting
- Random ephemeral keys via eny.bowl instead of deterministic derivation
- Mint URL inside encrypted payload, not as external unprotected field
- In-flight token recovery: tokens held in escrow for 30 min after
  signing, NUT-03 swapped for fresh proofs if unused (prevents loss
  from failed pushes)

Maintainer features:
- Per-mint wallet display showing balance and proof count per mint
- Lightning withdrawal (NUT-05 melt): enter BOLT11 invoice, agent
  quotes and executes melt, proofs restored on failure
- State-8 with pending-melts tracking quote and execute steps
- pending-melt type in sur/vitriol.hoon

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@nisfeb nisfeb merged commit a621db6 into master Mar 13, 2026
1 check passed
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