@coinbase/cdp-sdk
Version:
SDK for interacting with the Coinbase Developer Platform Wallet API
80 lines • 3.34 kB
TypeScript
import { SpendTracker } from "./spend-tracker.js";
import { type Address, type Amount, type Asset, type SpendControls } from "./types.js";
import type { x402Client } from "@x402/core/client";
import type { Network, PaymentPayload } from "@x402/core/types";
/** Default thresholds (as fractions of the cap) for `onApproachingLimit`. */
export declare const DEFAULT_APPROACHING_LIMIT_THRESHOLDS: readonly number[];
/**
* Hard ceiling on `PaymentRequirements.maxTimeoutSeconds`, independent of
* whatever value the resource server sends. `maxTimeoutSeconds` feeds
* directly into the EIP-3009 `validBefore` the wallet signs, so an
* unbounded server-supplied value could grant an authorization an
* arbitrarily long redemption window.
*/
export declare const MAX_PAYMENT_TIMEOUT_SECONDS = 3600;
/**
* Symbol-keyed property on a client that carries its settlement-aware confirm/rollback registry.
*/
export declare const SPEND_CONTROLS_REGISTRY: unique symbol;
/**
* Settlement-aware finalization handlers attached to a client by {@link applySpendControls}.
*/
export interface SpendControlsRegistry {
/**
* Mark a previously-created payment as settled on-chain.
*
* @param paymentPayload - The payment payload to confirm.
*/
confirm(paymentPayload: PaymentPayload): Promise<void>;
/**
* Undo a previously-recorded provisional spend entry.
*
* Only safe for a payload that was never transmitted — a sent authorization
* is independently redeemable and can't be safely un-counted. Not called by
* the SDK's own `onPaymentResponse` wiring; for callers with out-of-band
* knowledge that a specific payload was never sent.
*
* @param paymentPayload - The payment payload to roll back.
*/
rollback(paymentPayload: PaymentPayload): Promise<void>;
}
/**
* The active spend controls configuration after defaults are filled in.
*/
export type ResolvedSpendControls = Readonly<{
maxAmountPerPayment?: {
atomic: bigint;
asset?: string;
};
maxCumulativeSpend?: {
atomic: bigint;
asset?: string;
};
maxCumulativeSpendWindowMs?: number;
allowedNetworks: ReadonlySet<Network>;
allowedAssets: ReadonlySet<Asset>;
allowedPayees: ReadonlySet<Address>;
approachingLimitThresholds: ReadonlyArray<number>;
onApproachingLimit?: (spent: Amount, limit: Amount) => void;
tracker: SpendTracker;
}>;
/**
* Attach a {@link SpendControls} configuration to an `x402Client`.
*
* Can only be called once per client — a second call throws
* `SpendControlError` (`code: "already_applied"`).
*
* @param client - The client to attach controls to.
* @param controls - The spend controls configuration to apply.
* @returns A frozen snapshot of the resolved configuration.
*/
export declare function applySpendControls(client: x402Client, controls: SpendControls): ResolvedSpendControls;
/**
* Look up the settlement-aware {@link SpendControlsRegistry} attached to an
* `x402Client` by {@link applySpendControls}.
*
* @param client - The x402Client to look up the registry for.
* @returns The registry, or undefined if spend controls were not applied.
*/
export declare function getSpendControlsRegistry(client: x402Client): SpendControlsRegistry | undefined;
//# sourceMappingURL=apply.d.ts.map