FFiber Offers
Documentation / Reference

SDK integration

The ESM SDK gives applications one consistent interface for protocol operations, resolver calls, readiness, Fiber RPC, topology analysis, route checks, and deliberate payment execution.

Packages and imports

The monorepo exposes the protocol and SDK packages with TypeScript declarations. Import only the layer your application needs.

import {
  createSignedOffer,
  decodeOffer,
  verifyOffer
} from "@fiber-offers/protocol";

import {
  createOffer,
  FiberOffersClient,
  FiberPaymentClient,
  FiberPaymentFlowClient,
  FiberRecurringPaymentScheduler,
  FiberTopologyClient
} from "@fiber-offers/sdk";
ClientUse it for
FiberOffersClientResolver offers, readiness, invoices, addresses, resolutions, webhooks, receipts, and reconciliation. For operators, also the offer switch and resolver keys.
FiberPaymentClientPayer-side Fiber send_payment, dry-runs, and payment status calls.
FiberPaymentFlowClientThe composed wallet path from readiness to invoice to route confidence to explicitly opted-in payment.
FiberTopologyClientMerchant and payer node pair inspection plus direct-channel diagnostics.
FiberRecurringPaymentSchedulerPayer-owned capped approvals, due-cycle execution, retries, and revocation.
JsonFileRecurringApprovalStorePrivate durable approval storage for Node payer services through @fiber-offers/sdk/node.

Durable recurring payments

import {
  FiberRecurringPaymentScheduler,
  JsonFileRecurringApprovalStore
} from "@fiber-offers/sdk/node";

const scheduler = new FiberRecurringPaymentScheduler({
  resolverClient: resolver,
  paymentFlow,
  store: new JsonFileRecurringApprovalStore(".fiber-offers/payer-approvals.json"),
  autoStart: true,
  retryDelayMs: 30000
});

await scheduler.approve(offerId);

The scheduler remains in the payer trust boundary. Browser wallets can use WebStorageRecurringApprovalStore; merchant resolvers never receive payer payment credentials.

Merchant offer registration

import { createOffer, FiberOffersClient } from "@fiber-offers/sdk";

const created = await createOffer({
  network: "testnet",
  resolver_url: "https://resolver.example",
  description: "Coffee checkout",
  assets: [{ asset_type: "ckb", symbol: "CKB" }],
  amount_min: "1000",
  amount_max: "1000"
}, { fiberRpcUrl: "http://127.0.0.1:8227" });

const resolver = new FiberOffersClient({
  resolverUrl: "https://resolver.example",
  apiKey: process.env.RESOLVER_API_KEY
});

const registered = await resolver.registerOffer(created.offer, {
  username: "coffee"
});

Keep created.offer_private_key_pem under merchant control. The resolver verifies that the signed node_id matches its configured Fiber node before registration and invoice minting. apiKey takes RESOLVER_API_KEY or a named key; a shop's backend needs only the manage scope.

Wallet readiness and invoice calls

const resolver = new FiberOffersClient({
  resolverUrl: "https://resolver.example"
});

const offer = await resolver.resolveFiberAddress("coffee@example.com");
const request = {
  amount: "1000",
  asset: { asset_type: "ckb", symbol: "CKB" }
};

const readiness = await resolver.checkPayment(offer.offer_id, request);
if (!readiness.ready) {
  throw new Error(readiness.summary);
}

const invoice = await resolver.requestInvoice(offer.offer_id, request, {
  idempotencyKey: "checkout-order-42"
});

Use the resolution ID returned by invoice creation when retrieving receipts, status, or reconciliation. Do not create a new idempotency key when retrying the same network request.

Operator helpers

const created = await resolver.createWebhook(offerId, {
  url: "https://merchant.example/webhooks/fiber",
  events: ["invoice.paid", "invoice.failed"]
});
storeSecret(created.signing_secret); // Returned only now.

const subscriptions = await resolver.getWebhooks(offerId);
await resolver.testWebhook(offerId, created.id);
await resolver.updateWebhook(offerId, created.id, { disabled: true });

const rotated = await resolver.rotateWebhookSecret(offerId, created.id);
storeSecret(rotated.signing_secret);

const events = await resolver.getWebhookEvents(offerId);
const delivery = await resolver.deliverWebhookEvents(offerId, {
  retryFailed: true
});

const updated = await resolver.syncResolutions(offerId, {
  includeTerminal: false
});

const csv = await resolver.getReconciliationCsv(offerId);

These calls need a resolver key when the resolver has one configured: reads need the read scope, and changes need manage. Treat them as merchant or operator tasks, not wallet-facing payment actions.

Offer switch and resolver keys

// Manage scope: switch an offer off, and back on.
await resolver.disableOffer(offerId, { reason: "Sold out" });
await resolver.enableOffer(offerId);

// Admin scope: named keys and browser sessions.
const { key, token } = await resolver.createApiKey({
  name: "shop backend",
  scope: "manage"
});
storeSecret(token); // Returned only now.

const { keys } = await resolver.listApiKeys();
await resolver.revokeApiKey(oldKey.id);
const { ended } = await resolver.endOperatorSessions();

// No scope needed: who the configured key is to the resolver.
const session = await resolver.getOperatorSession();
// { authenticated, scope, key: { id, name } }

disableOffer needs no signature from the offer's key, so it also stops an offer whose key is lost, and enableOffer undoes it. revokeOffer is signed by the offer's key and is permanent. Offers and offer list items carry operator_disabled, with who switched the offer off and why, when the client has a key. In getRecurrenceStatus, revoked is true only for a signed revocation, and disabled is true while the offer cannot be paid for either reason.

createApiKey takes name, scope ("read", "manage" or "admin") and an optional expires_at. The resolver keeps only a hash of the token. A revoked key stops working on every replica, along with the sessions opened with it. The types are OperatorScope, OperatorApiKey, CreateApiKeyInput, CreatedApiKey, OperatorSessionStatus, and OperatorDisabledRecord.

Topology and payer helpers

const topology = new FiberTopologyClient({
  merchant: "http://127.0.0.1:8227",
  payer: "http://127.0.0.1:8229"
});

const report = await topology.inspectPair();
const payer = new FiberPaymentClient({
  url: "http://127.0.0.1:8229"
});

const route = await payer.checkPaymentRoute(invoice.invoice, {
  maxFeeAmount: 100000,
  diagnostics: report.diagnostics
});

checkPaymentRoute performs a dry-run. Use sendPayment only after application confirmation logic has explicitly approved the payment.