Fiber LogoFiber Docs
Pay to decrypt25 minute tutorial

Unlock Encrypted Data with a Fiber Payment

Run a Buyer and Seller as independent browser nodes, pay a real Testnet Invoice, and use the revealed payment preimage to decrypt the Seller's result.

InvoiceAES-GCMPayment preimage
1 Start two browser nodes

Keep Buyer and Seller identities separate

Buyer Node A and Seller Node C run locally with separate keys and stores. Browser nodes cannot accept inbound connections, so both connect to Bottle for routing; Bottle is infrastructure, not a third application role.

Buyer Node ABottle · route onlySeller Node C
app/pay-to-decrypt/page.tsx · lines 3–7
2 Encrypt the result

Generate a fresh key inside the browser

Seller Node C creates a random 256-bit key and 96-bit IV, then encrypts the result with authenticated AES-GCM. The ciphertext can be delivered before payment because it is unreadable without the key.

lib/crypto.ts · lines 1–11
3 Bind the key to an Invoice

Use the AES key as the payment preimage

Seller Node C creates a regular Invoice with payment_preimage: K and hash_algorithm: 'sha256'. Fiber places only sha256(K) in the Invoice and keeps K secret until settlement.

lib/invoice.ts · lines 3–16
4 Transfer the encrypted offer

Copy ciphertext and Invoice, never the key

The portable JSON contains the ciphertext, IV, payment hash, encoded Invoice, and a public Bottle→Seller last-hop hint. Copying it between the two panes makes the application boundary explicit without adding a coordination server.

lib/offer.ts · lines 1–22
5 Pay for the key

Wait for Fiber to return the preimage

Buyer Node A combines its direct channel to Bottle with the offer's Bottle→Seller last-hop hint. This builds one ordinary A → Bottle → C payment without waiting for gossip or asking Bottle to start a separate trampoline payment. Only a successful result exposes payment_preimage; failure leaves the ciphertext locked.

lib/payment.ts · lines 1–18
6 Decrypt locally

Import the revealed preimage as the AES key

Before payment, a trial decryption fails AES-GCM authentication. After payment, the exact preimage returned by Fiber authenticates and decrypts the original result in Buyer Node A's browser.

lib/crypto.ts · lines 14–21
7 Understand the guarantee

Payment proves key release, not result quality

This construction binds settlement to disclosure of a particular key. AES-GCM proves that the key matches the ciphertext, but it cannot prove that the Seller's plaintext is useful or truthful. Production markets still need reputation, previews, or dispute rules.

No application backend

Encryption, offer transfer, Invoice creation, payment polling, and decryption all run in the browser. The demo still uses public Fiber and CKB Testnet infrastructure.