@catena/sdk 0.0.0-bootstrap.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ import { t as InvalidKeyError } from "./keypair-BjMJtI3-.mjs";
2
+ import { A as IntentResult, B as Policy, C as COUNTERPARTY_RULE_MODES, D as ExtensibleString, E as Counterparty, F as OnchainNetworkInput, G as X402Resource, H as SendMethod, I as POLICY_CAPABILITIES, J as X402SignedReceipt, K as AppInfo, L as POLICY_OVERRIDE_CAPABILITIES, M as MppChallenge, N as MppResource, O as INTENT_ACTION_TYPES, P as OnchainAssetInput, R as POLICY_RULE_ACTIONS, S as COUNTERPARTY_ACTIONS, T as CounterpartiesResponse, U as X402Authorization, V as SEND_METHODS, W as X402PaymentRequirements, _ as AccountDepositAddressResponse, a as IntentSubmitError, b as AccountsResponse, c as ACCOUNT_AGGREGATION_SCOPES, d as ACCOUNT_TRANSACTION_MOVEMENT_STATUSES, f as ACCOUNT_TRANSACTION_STATUSES, g as AccountDepositAddressParams, h as AccountBalanceResponse, i as FetchLike, j as MppAction, k as IntentAction, l as ACCOUNT_DEPOSIT_ADDRESS_SOURCES, m as ACTOR_AGGREGATION_SCOPES, n as CatenaClient, o as TimeoutError, p as ACCOUNT_TRANSACTION_TYPES, q as X402SignedOffer, r as CatenaClientOptions, s as createCatenaClient, t as ApiError, u as ACCOUNT_TRANSACTION_METHODS, v as AccountTransactionsParams, w as CounterpartiesParams, x as Agent, y as AccountTransactionsResponse, z as POLICY_RULE_TYPES } from "./client-Cm2wNUuB.mjs";
3
+ export { ACCOUNT_AGGREGATION_SCOPES, ACCOUNT_DEPOSIT_ADDRESS_SOURCES, ACCOUNT_TRANSACTION_METHODS, ACCOUNT_TRANSACTION_MOVEMENT_STATUSES, ACCOUNT_TRANSACTION_STATUSES, ACCOUNT_TRANSACTION_TYPES, ACTOR_AGGREGATION_SCOPES, type AccountBalanceResponse, type AccountDepositAddressParams, type AccountDepositAddressResponse, type AccountTransactionsParams, type AccountTransactionsResponse, type AccountsResponse, type Agent, ApiError, type AppInfo, COUNTERPARTY_ACTIONS, COUNTERPARTY_RULE_MODES, type CatenaClient, CatenaClientOptions, type CounterpartiesParams, type CounterpartiesResponse, type Counterparty, type ExtensibleString, FetchLike, INTENT_ACTION_TYPES, type IntentAction, type IntentResult, IntentSubmitError, InvalidKeyError, type MppAction, type MppChallenge, type MppResource, type OnchainAssetInput, type OnchainNetworkInput, POLICY_CAPABILITIES, POLICY_OVERRIDE_CAPABILITIES, POLICY_RULE_ACTIONS, POLICY_RULE_TYPES, type Policy, SEND_METHODS, type SendMethod, TimeoutError, type X402Authorization, type X402PaymentRequirements, type X402Resource, type X402SignedOffer, type X402SignedReceipt, createCatenaClient };
@@ -0,0 +1,3 @@
1
+ import { InvalidKeyError } from "./keypair.mjs";
2
+ import { _ as POLICY_RULE_ACTIONS, a as ACCOUNT_AGGREGATION_SCOPES, c as ACCOUNT_TRANSACTION_MOVEMENT_STATUSES, d as ACTOR_AGGREGATION_SCOPES, f as COUNTERPARTY_ACTIONS, g as POLICY_OVERRIDE_CAPABILITIES, h as POLICY_CAPABILITIES, i as createCatenaClient, l as ACCOUNT_TRANSACTION_STATUSES, m as INTENT_ACTION_TYPES, n as IntentSubmitError, o as ACCOUNT_DEPOSIT_ADDRESS_SOURCES, p as COUNTERPARTY_RULE_MODES, r as TimeoutError, s as ACCOUNT_TRANSACTION_METHODS, t as ApiError, u as ACCOUNT_TRANSACTION_TYPES, v as POLICY_RULE_TYPES, y as SEND_METHODS } from "./client-CHZMO00P.mjs";
3
+ export { ACCOUNT_AGGREGATION_SCOPES, ACCOUNT_DEPOSIT_ADDRESS_SOURCES, ACCOUNT_TRANSACTION_METHODS, ACCOUNT_TRANSACTION_MOVEMENT_STATUSES, ACCOUNT_TRANSACTION_STATUSES, ACCOUNT_TRANSACTION_TYPES, ACTOR_AGGREGATION_SCOPES, ApiError, COUNTERPARTY_ACTIONS, COUNTERPARTY_RULE_MODES, INTENT_ACTION_TYPES, IntentSubmitError, InvalidKeyError, POLICY_CAPABILITIES, POLICY_OVERRIDE_CAPABILITIES, POLICY_RULE_ACTIONS, POLICY_RULE_TYPES, SEND_METHODS, TimeoutError, createCatenaClient };
@@ -0,0 +1,35 @@
1
+ //#region src/keypair.d.ts
2
+ interface P256Keypair {
3
+ algorithm: "p256";
4
+ privateKeyHex: string;
5
+ publicKeyHex: string;
6
+ }
7
+ /**
8
+ * The supplied value is not a usable P-256 key.
9
+ */
10
+ declare class InvalidKeyError extends Error {
11
+ constructor(message: string);
12
+ }
13
+ /**
14
+ * Generate a fresh agent credential. Feed `privateKeyHex` to
15
+ * `createCatenaClient`; the public half (or its thumbprint) is what gets
16
+ * registered with Catena when the agent is linked. The SDK never persists
17
+ * keys — storage is the caller's responsibility.
18
+ */
19
+ declare function generateP256Keypair(): P256Keypair;
20
+ /**
21
+ * Derive the full keypair from the private scalar alone, so a corrupt key
22
+ * throws at construction instead of surfacing as bank-side invalid_signature
23
+ * 401s — and a mismatched pair cannot exist at all.
24
+ */
25
+ declare function p256KeypairFromPrivateKeyHex(privateKeyHex: string): P256Keypair;
26
+ declare function p256PointFromCompressedHex(publicKeyHex: string): Buffer | null;
27
+ /**
28
+ * RFC 7638 JWK thumbprint of a P-256 public key — the stable id the API
29
+ * knows a linked credential by. Throws {@link InvalidKeyError} when the
30
+ * input is not a valid P-256 point.
31
+ */
32
+ declare function computeP256PublicKeyThumbprint(publicKeyHex: string): string;
33
+ declare function p256PublicKeyThumbprintFromPoint(point: Buffer): string;
34
+ //#endregion
35
+ export { p256KeypairFromPrivateKeyHex as a, generateP256Keypair as i, P256Keypair as n, p256PointFromCompressedHex as o, computeP256PublicKeyThumbprint as r, p256PublicKeyThumbprintFromPoint as s, InvalidKeyError as t };
@@ -0,0 +1,2 @@
1
+ import { a as p256KeypairFromPrivateKeyHex, i as generateP256Keypair, n as P256Keypair, o as p256PointFromCompressedHex, r as computeP256PublicKeyThumbprint, s as p256PublicKeyThumbprintFromPoint, t as InvalidKeyError } from "./keypair-BjMJtI3-.mjs";
2
+ export { InvalidKeyError, P256Keypair, computeP256PublicKeyThumbprint, generateP256Keypair, p256KeypairFromPrivateKeyHex, p256PointFromCompressedHex, p256PublicKeyThumbprintFromPoint };
@@ -0,0 +1,50 @@
1
+ import { ECDH, createECDH, createHash } from "node:crypto";
2
+ //#region src/keypair.ts
3
+ var InvalidKeyError = class extends Error {
4
+ constructor(message) {
5
+ super(message);
6
+ this.name = "InvalidKeyError";
7
+ }
8
+ };
9
+ function generateP256Keypair() {
10
+ const ecdh = createECDH("prime256v1");
11
+ ecdh.generateKeys();
12
+ return p256KeypairFromPrivateKeyHex(ecdh.getPrivateKey().toString("hex").padStart(64, "0"));
13
+ }
14
+ const PRIVATE_KEY_HEX = /^[0-9a-f]{64}$/i;
15
+ function p256KeypairFromPrivateKeyHex(privateKeyHex) {
16
+ if (!PRIVATE_KEY_HEX.test(privateKeyHex)) throw new InvalidKeyError("P-256 private key must be 64 hex characters");
17
+ const normalized = privateKeyHex.toLowerCase();
18
+ const ecdh = createECDH("prime256v1");
19
+ try {
20
+ ecdh.setPrivateKey(Buffer.from(normalized, "hex"));
21
+ } catch {
22
+ throw new InvalidKeyError("value is not a valid P-256 private key (scalar out of range)");
23
+ }
24
+ return {
25
+ algorithm: "p256",
26
+ privateKeyHex: normalized,
27
+ publicKeyHex: ecdh.getPublicKey("hex", "compressed")
28
+ };
29
+ }
30
+ function p256PointFromCompressedHex(publicKeyHex) {
31
+ try {
32
+ const uncompressed = ECDH.convertKey(publicKeyHex, "prime256v1", "hex", "hex", "uncompressed");
33
+ const point = Buffer.isBuffer(uncompressed) ? uncompressed : Buffer.from(uncompressed, "hex");
34
+ return point.length === 65 ? point : null;
35
+ } catch {
36
+ return null;
37
+ }
38
+ }
39
+ function computeP256PublicKeyThumbprint(publicKeyHex) {
40
+ const point = p256PointFromCompressedHex(publicKeyHex);
41
+ if (point === null) throw new InvalidKeyError("value is not a valid P-256 public key");
42
+ return p256PublicKeyThumbprintFromPoint(point);
43
+ }
44
+ function p256PublicKeyThumbprintFromPoint(point) {
45
+ const x = point.subarray(1, 33).toString("base64url");
46
+ const y = point.subarray(33, 65).toString("base64url");
47
+ return createHash("sha256").update(`{"crv":"P-256","kty":"EC","x":"${x}","y":"${y}"}`, "utf8").digest("base64url");
48
+ }
49
+ //#endregion
50
+ export { InvalidKeyError, computeP256PublicKeyThumbprint, generateP256Keypair, p256KeypairFromPrivateKeyHex, p256PointFromCompressedHex, p256PublicKeyThumbprintFromPoint };
package/dist/mpp.d.mts ADDED
@@ -0,0 +1,315 @@
1
+ import { A as IntentResult, i as FetchLike, n as CatenaClient } from "./client-Cm2wNUuB.mjs";
2
+ import { Method, z } from "mppx";
3
+ //#region src/mpp.d.ts
4
+ declare const evmCharge: {
5
+ readonly name: "evm";
6
+ readonly intent: "charge";
7
+ readonly schema: {
8
+ credential: {
9
+ payload: z.ZodMiniObject<{
10
+ type: z.ZodMiniLiteral<"authorization">;
11
+ from: z.ZodMiniString<string>;
12
+ to: z.ZodMiniString<string>;
13
+ value: z.ZodMiniString<string>;
14
+ validAfter: z.ZodMiniString<string>;
15
+ validBefore: z.ZodMiniString<string>;
16
+ nonce: z.ZodMiniString<string>;
17
+ signature: z.ZodMiniString<string>;
18
+ }, z.core.$strip>;
19
+ };
20
+ request: z.ZodMiniObject<{
21
+ amount: z.ZodMiniString<string>;
22
+ currency: z.ZodMiniString<string>;
23
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
24
+ externalId: z.ZodMiniOptional<z.ZodMiniString<string>>;
25
+ recipient: z.ZodMiniString<string>;
26
+ methodDetails: z.ZodMiniObject<{
27
+ chainId: z.ZodMiniNumber<number>;
28
+ credentialTypes: z.ZodMiniArray<z.ZodMiniLiteral<"authorization">>;
29
+ decimals: z.ZodMiniLiteral<6>;
30
+ permit2Address: z.ZodMiniOptional<z.ZodMiniString<string>>;
31
+ splits: z.ZodMiniOptional<z.ZodMiniNever>;
32
+ }, z.core.$strip>;
33
+ }, z.core.$strip>;
34
+ };
35
+ };
36
+ declare const usdcCharge: {
37
+ readonly name: "usdc";
38
+ readonly intent: "charge";
39
+ readonly schema: {
40
+ credential: {
41
+ payload: z.ZodMiniObject<{
42
+ type: z.ZodMiniLiteral<"authorization">;
43
+ from: z.ZodMiniString<string>;
44
+ to: z.ZodMiniString<string>;
45
+ value: z.ZodMiniString<string>;
46
+ validAfter: z.ZodMiniString<string>;
47
+ validBefore: z.ZodMiniString<string>;
48
+ nonce: z.ZodMiniString<string>;
49
+ signature: z.ZodMiniString<string>;
50
+ }, z.core.$strip>;
51
+ };
52
+ request: z.ZodMiniObject<{
53
+ amount: z.ZodMiniString<string>;
54
+ currency: z.ZodMiniString<string>;
55
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
56
+ externalId: z.ZodMiniOptional<z.ZodMiniString<string>>;
57
+ recipient: z.ZodMiniString<string>;
58
+ methodDetails: z.ZodMiniObject<{
59
+ type: z.ZodMiniLiteral<"evm">;
60
+ evm: z.ZodMiniObject<{
61
+ chainId: z.ZodMiniNumber<number>;
62
+ credentialTypes: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniLiteral<"authorization">>>;
63
+ decimals: z.ZodMiniLiteral<6>;
64
+ permit2Address: z.ZodMiniOptional<z.ZodMiniString<string>>;
65
+ splits: z.ZodMiniOptional<z.ZodMiniNever>;
66
+ }, z.core.$strip>;
67
+ }, z.core.$strip>;
68
+ }, z.core.$strip>;
69
+ };
70
+ };
71
+ /**
72
+ * Parameters shared by both Catena MPP charge methods.
73
+ */
74
+ interface CatenaMppParameters {
75
+ /**
76
+ * A linked Catena SDK client used to submit the payment intent.
77
+ */
78
+ readonly client: CatenaClient;
79
+ /**
80
+ * Catena account whose wallet will authorize the charge.
81
+ */
82
+ readonly accountId: string;
83
+ /**
84
+ * Price ceiling in atomic USDC units (6 decimals). Challenges asking for
85
+ * more are refused before any intent is created.
86
+ */
87
+ readonly maxAtomicAmount?: bigint;
88
+ }
89
+ /**
90
+ * Catena-backed `evm/charge` mppx client method.
91
+ */
92
+ type CatenaEvmChargeMethod = Method.Client<typeof evmCharge>;
93
+ /**
94
+ * Catena-backed `usdc/charge` mppx client method.
95
+ */
96
+ type CatenaUsdcChargeMethod = Method.Client<typeof usdcCharge>;
97
+ /**
98
+ * Both Catena methods registered by the factory.
99
+ */
100
+ type CatenaMppMethods = readonly [CatenaEvmChargeMethod, CatenaUsdcChargeMethod];
101
+ /**
102
+ * Callable Catena MPP factory, with the conventional charge alias.
103
+ */
104
+ interface CatenaMppFactory {
105
+ (parameters: CatenaMppParameters): CatenaMppMethods;
106
+ charge(parameters: CatenaMppParameters): CatenaMppMethods;
107
+ }
108
+ /**
109
+ * Status of a Catena MPP intent that did not yield a usable credential.
110
+ */
111
+ type MppPaymentStatus = IntentResult["status"];
112
+ /**
113
+ * A Catena MPP intent completed without a usable credential or stopped in a
114
+ * non-completed state. Inspect `status` to choose a recovery path and
115
+ * `intentId` to reconcile the payment with `client.getIntent(intentId)`.
116
+ */
117
+ declare class MppPaymentError extends Error {
118
+ readonly intentId: string;
119
+ readonly status: MppPaymentStatus;
120
+ readonly reasons: readonly string[];
121
+ readonly expiresAt: string | null;
122
+ constructor(message: string, details: {
123
+ readonly intentId: string;
124
+ readonly status: MppPaymentStatus;
125
+ readonly reasons: readonly string[];
126
+ readonly expiresAt: string | null;
127
+ });
128
+ }
129
+ /**
130
+ * Credential-free record of an MPP payment completed by the managed fetch
131
+ * wrapper.
132
+ */
133
+ interface MppPaymentReceipt {
134
+ /**
135
+ * Catena intent that completed the payment.
136
+ */
137
+ readonly intentId: string;
138
+ /**
139
+ * Validated MPP method selected from the seller's challenge.
140
+ */
141
+ readonly method: "evm" | "usdc";
142
+ /**
143
+ * Paid amount in atomic USDC units (6 decimals).
144
+ */
145
+ readonly atomicAmount: string;
146
+ /**
147
+ * CAIP-2 network on which the payment was authorized.
148
+ */
149
+ readonly network: "eip155:8453" | "eip155:84532";
150
+ /**
151
+ * EVM address that received the payment authorization.
152
+ */
153
+ readonly recipient: string;
154
+ /**
155
+ * Canonical final URL of the resource that was paid.
156
+ */
157
+ readonly resourceUrl: string;
158
+ }
159
+ /**
160
+ * Base error for managed MPP negotiation failures. `intentId` is present only
161
+ * after Catena created an intent; `reasons` carries server recovery detail
162
+ * without exposing the payment credential.
163
+ */
164
+ declare class MppFetchPaymentError extends Error {
165
+ /**
166
+ * Catena intent to reconcile, when one was created.
167
+ */
168
+ readonly intentId: string | undefined;
169
+ /**
170
+ * Stable recovery detail returned by Catena.
171
+ */
172
+ readonly reasons: readonly string[];
173
+ constructor(message: string, details?: {
174
+ readonly intentId?: string;
175
+ readonly reasons?: readonly string[];
176
+ readonly cause?: unknown;
177
+ });
178
+ }
179
+ /**
180
+ * None of the offered MPP networks can be funded by the selected account.
181
+ */
182
+ declare class MppNetworkMismatchError extends MppFetchPaymentError {
183
+ /**
184
+ * Account that needs a wallet on one of the required networks.
185
+ */
186
+ readonly accountId: string;
187
+ /**
188
+ * Offered networks that Catena reported as mismatches.
189
+ */
190
+ readonly requiredNetworks: readonly ("eip155:8453" | "eip155:84532")[];
191
+ constructor(accountId: string, requiredNetworks: readonly ("eip155:8453" | "eip155:84532")[], reasons: readonly string[]);
192
+ }
193
+ /**
194
+ * The selected MPP recipient is not saved as a usable Catena counterparty
195
+ * rail.
196
+ */
197
+ declare class MppCounterpartyNotFoundError extends MppFetchPaymentError {
198
+ /**
199
+ * Recipient address that must be added.
200
+ */
201
+ readonly recipient: string;
202
+ /**
203
+ * Network on which the recipient was offered.
204
+ */
205
+ readonly network: "eip155:8453" | "eip155:84532";
206
+ constructor(recipient: string, network: "eip155:8453" | "eip155:84532", reasons: readonly string[]);
207
+ }
208
+ /**
209
+ * The MPP payment is parked for human approval. Retry the original request
210
+ * after approval so a fresh challenge can consume the grant.
211
+ */
212
+ declare class MppApprovalPendingError extends MppFetchPaymentError {
213
+ /**
214
+ * Time at which the pending approval expires, when supplied by Catena.
215
+ */
216
+ readonly expiresAt: string | null;
217
+ constructor(intentId: string, reasons: readonly string[], expiresAt: string | null);
218
+ }
219
+ /**
220
+ * Catena terminally blocked or failed the selected MPP payment.
221
+ */
222
+ declare class MppPaymentDeclinedError extends MppFetchPaymentError {
223
+ /**
224
+ * Terminal intent disposition.
225
+ */
226
+ readonly status: "blocked" | "failed";
227
+ constructor(intentId: string, status: "blocked" | "failed", reasons: readonly string[]);
228
+ }
229
+ /**
230
+ * Submission failed where Catena may already have acted. Reconcile the intent
231
+ * before authorizing another payment.
232
+ */
233
+ declare class MppSubmitInterruptedError extends MppFetchPaymentError {
234
+ /**
235
+ * Validated MPP method whose submission became ambiguous.
236
+ */
237
+ readonly method: "evm" | "usdc";
238
+ /**
239
+ * Potentially paid amount in atomic USDC units.
240
+ */
241
+ readonly atomicAmount: string;
242
+ /**
243
+ * Network on which submission may have occurred.
244
+ */
245
+ readonly network: "eip155:8453" | "eip155:84532";
246
+ /**
247
+ * Recipient whose payment may have been submitted.
248
+ */
249
+ readonly recipient: string;
250
+ /**
251
+ * Canonical resource URL bound to the ambiguous intent.
252
+ */
253
+ readonly resourceUrl: string;
254
+ constructor(intentId: string, terms: {
255
+ readonly method: "evm" | "usdc";
256
+ readonly atomicAmount: string;
257
+ readonly network: "eip155:8453" | "eip155:84532";
258
+ readonly recipient: string;
259
+ }, resourceUrl: string, cause: unknown);
260
+ }
261
+ /**
262
+ * Payment completed but `onPayment` or the single paid retry failed. The
263
+ * credential-free receipt identifies the settled intent for reconciliation.
264
+ */
265
+ declare class MppRetryFailedError extends MppFetchPaymentError {
266
+ /**
267
+ * Completed payment that must not be paid a second time.
268
+ */
269
+ readonly receipt: MppPaymentReceipt;
270
+ constructor(receipt: MppPaymentReceipt, cause: unknown);
271
+ }
272
+ /**
273
+ * Options for the managed MPP fetch wrapper.
274
+ */
275
+ interface MppFetchOptions {
276
+ /**
277
+ * Catena account whose wallet authorizes payments.
278
+ */
279
+ readonly accountId: string;
280
+ /**
281
+ * Custom fetch transport, defaulting to `globalThis.fetch`.
282
+ */
283
+ readonly baseFetch?: FetchLike;
284
+ /**
285
+ * Maximum acceptable price in atomic USDC units (6 decimals).
286
+ */
287
+ readonly maxAtomicAmount?: bigint;
288
+ /**
289
+ * Called once after payment completes and before the paid retry. The receipt
290
+ * deliberately excludes the MPP credential.
291
+ */
292
+ readonly onPayment?: (receipt: MppPaymentReceipt) => void | Promise<void>;
293
+ }
294
+ /**
295
+ * Create Catena-backed mppx charge methods for native USDC on Base and Base
296
+ * Sepolia. Pass the returned tuple directly in `Mppx.create({ methods: [...]
297
+ * })`.
298
+ */
299
+ declare const catena: CatenaMppFactory;
300
+ /**
301
+ * Wrap `fetch` with one managed MPP payment attempt. Ordinary responses and
302
+ * 402s without a decodable MPP challenge pass through unchanged. For a
303
+ * supported challenge, the wrapper binds the payment to the final same-origin
304
+ * resource URL, submits one Catena intent at a time, calls `onPayment`, and
305
+ * retries the original request exactly once through the configured Fetch
306
+ * transport with Mppx's credential transport.
307
+ *
308
+ * Stream and consumed `Request` bodies are rejected before payment because
309
+ * they cannot be replayed safely. Once an intent completes, continuation
310
+ * failures throw `MppRetryFailedError`; do not run the payment loop again
311
+ * without first reconciling that receipt's intent.
312
+ */
313
+ declare function wrapFetchWithMppPayment(client: CatenaClient, options: MppFetchOptions): FetchLike;
314
+ //#endregion
315
+ export { CatenaEvmChargeMethod, CatenaMppFactory, CatenaMppMethods, CatenaMppParameters, CatenaUsdcChargeMethod, MppApprovalPendingError, MppCounterpartyNotFoundError, MppFetchOptions, MppFetchPaymentError, MppNetworkMismatchError, MppPaymentDeclinedError, MppPaymentError, MppPaymentReceipt, MppPaymentStatus, MppRetryFailedError, MppSubmitInterruptedError, catena, wrapFetchWithMppPayment };