@coinbase/cdp-sdk
Version:
SDK for interacting with the Coinbase Developer Platform Wallet API
128 lines (117 loc) • 8.45 kB
JavaScript
import { cdpApiClient } from "../../cdpApiClient.js";
/**
* Creates a mandate denominated in `asset`. Optionally set `policy` to cap debits; if omitted, a Coinbase-configured monthly max applies. The response always includes the resolved `policy`.
Returns the mandate in `created` status with no `source`; it is not yet usable. Next step: have the customer approve it with **Get wallet approval options** then **Approve a mandate with a wallet**, which attaches the `source` and moves the mandate to `approval_succeeded`.
A mandate's terms can't be modified once created. To change them, cancel the mandate and create a new one.
* @summary Create a mandate
*/
export const createMandate = (createMandateRequest, options) => {
return cdpApiClient({
url: `/v2/mandates`,
method: "POST",
headers: { "Content-Type": "application/json" },
data: createMandateRequest,
}, options);
};
/**
* Returns a paginated list of mandates that the API key has permission to access. Filter by `address` (the funding `source`), `network`, and `status`.
* @summary List mandates
*/
export const listMandates = (params, options) => {
return cdpApiClient({ url: `/v2/mandates`, method: "GET", params }, options);
};
/**
* Retrieves a single mandate by its ID, including its current `status`, `policy`, and `source`.
* @summary Get a mandate
*/
export const getMandate = (mandateId, options) => {
return cdpApiClient({ url: `/v2/mandates/${mandateId}`, method: "GET" }, options);
};
/**
* Ends the mandate off-chain. `status` becomes `canceled`, `canceledAt` is set, and new authorizations are blocked immediately; authorizations already in progress are not affected. Cancel can be called from any status except a fully revoked one (`revokedAt` set); canceling an already canceled mandate is a no-op that returns the mandate unchanged.
Canceling does not touch the on-chain spending allowance, which may still be live afterward. The customer removes it separately with **Revoke a mandate with a wallet**; that later revocation sets `revokedAt` while `canceledAt` remains set.
* @summary Cancel a mandate
*/
export const cancelMandate = (mandateId, cancelMandateRequest, options) => {
return cdpApiClient({
url: `/v2/mandates/${mandateId}/cancel`,
method: "POST",
headers: { "Content-Type": "application/json" },
data: cancelMandateRequest,
}, options);
};
/**
* Returns all wallet revocations for the mandate, newest first. Each records an attempt to remove the spending allowance on-chain. A `succeeded` entry means the allowance has been removed.
* @summary List mandate revocations
*/
export const listMandateRevocations = (mandateId, params, options) => {
return cdpApiClient({ url: `/v2/mandates/${mandateId}/revocations`, method: "GET", params }, options);
};
/**
* Retrieves a single revocation by ID.
* @summary Get a mandate revocation
*/
export const getMandateRevocation = (mandateId, revocationId, options) => {
return cdpApiClient({ url: `/v2/mandates/${mandateId}/revocations/${revocationId}`, method: "GET" }, options);
};
/**
* **Customer-initiated.** Removes the mandate's spending allowance on-chain using the customer's signed payloads from **Get wallet revocation options**. The customer signs the payloads themselves, so this call is unauthenticated. The mandate must have an active allowance and no approval or revocation in flight.
Returns a `pending` revocation and moves the mandate to `revocation_pending`. When the network transaction confirms, `revokedAt` is set and `status` becomes `revocation_succeeded`; if it does not complete, `status` becomes `revocation_failed` and a new revocation can be submitted. Follow progress with **Get a mandate revocation** or the `acceptance.mandate.revocation_*` webhooks.
A canceled mandate can still be revoked: the revocation sets `revokedAt` while `canceledAt` remains set.
* @summary Revoke a mandate with a wallet
*/
export const revokeWalletMandate = (mandateId, walletRevocationRequest, options) => {
return cdpApiClient({
url: `/v2/mandates/${mandateId}/revocations/wallet`,
method: "POST",
headers: { "Content-Type": "application/json" },
data: walletRevocationRequest,
}, options);
};
/**
* Returns the payloads the customer must sign to remove the mandate's spending allowance on-chain. The mandate must have an active allowance (approval succeeded, not yet revoked) and no approval or revocation in flight. A canceled mandate can still be revoked while its allowance is live.
Present the payloads to the customer to sign, then call **Revoke a mandate with a wallet** with the signed payloads.
This is a stateless read operation and does not modify the mandate. The payloads embed fresh signing data on each call, so sign and submit the payloads from a single response rather than caching them.
* @summary Get wallet revocation options
*/
export const getWalletRevocationOptions = (mandateId, options) => {
return cdpApiClient({ url: `/v2/mandates/${mandateId}/revocations/wallet/options`, method: "GET" }, options);
};
/**
* Returns the approvals for a mandate, most recent first. Each approval is an attempt to attach a funding `source`; inspect them to see why a mandate is not yet `approval_succeeded`: a `pending` attempt is still in progress, a `failed` one carries an `error`.
* @summary List mandate approvals
*/
export const listMandateApprovals = (mandateId, params, options) => {
return cdpApiClient({ url: `/v2/mandates/${mandateId}/approvals`, method: "GET", params }, options);
};
/**
* Retrieves a single approval by its ID, including its current `status`, its `onchainTransactions` once submitted, and, when it failed, its `error`. Poll this after **Approve a mandate with a wallet** to follow a `pending` approval to `succeeded` or `failed`, or consume the mandate webhooks instead.
* @summary Get a mandate approval
*/
export const getMandateApproval = (mandateId, approvalId, options) => {
return cdpApiClient({ url: `/v2/mandates/${mandateId}/approvals/${approvalId}`, method: "GET" }, options);
};
/**
* **Customer-initiated.** Approves a mandate on a wallet source using the customer's signed payloads from **Get wallet approval options**. The customer signs the payloads themselves, so this call is unauthenticated. The mandate must be in `created` or `approval_failed` status, not expired, and have no approval or revocation in flight.
Returns a `pending` approval and moves the mandate to `approval_pending`. On success the mandate's `source` is set and `status` becomes `approval_succeeded`; it can then be used by **Authorize a payment session with a mandate**. On failure `status` becomes `approval_failed` and a new approval can be submitted. Follow progress with **Get a mandate approval** or the `acceptance.mandate.approval_*` webhooks.
* @summary Approve a mandate with a wallet
*/
export const approveWalletMandate = (mandateId, walletApprovalRequest, options) => {
return cdpApiClient({
url: `/v2/mandates/${mandateId}/approvals/wallet`,
method: "POST",
headers: { "Content-Type": "application/json" },
data: walletApprovalRequest,
}, options);
};
/**
* Returns the available wallet approval options for a mandate. The mandate must be in `created` or `approval_failed` status, not expired, and have no approval or revocation in flight.
Provide one or more customer wallet addresses as query parameters. Each option specifies the network, asset, and payloads the customer must sign to approve the mandate. Present the options to the customer and let them choose one, then call **Approve a mandate with a wallet** with the selected option and its signed payloads.
This is a stateless read operation and does not modify the mandate. The payloads embed fresh on-chain signing data such as a `nonce` and `deadline`, so sign and submit the payloads from a single response rather than caching them.
If a requested address has no eligible approval options, it appears in `ineligibleAddresses` with a `code` and `message` instead of being absent from `options`.
* @summary Get wallet approval options
*/
export const getWalletApprovalOptions = (mandateId, params, options) => {
return cdpApiClient({ url: `/v2/mandates/${mandateId}/approvals/wallet/options`, method: "GET", params }, options);
};
//# sourceMappingURL=mandates.js.map