@catena/sdk 0.1.0 → 0.4.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.
- package/README.md +789 -358
- package/dist/{client-CHZMO00P.mjs → client-BSYVYJGm.mjs} +196 -21
- package/dist/{client-Cm2wNUuB.d.mts → client-B_Gi0aqH.d.mts} +270 -13
- package/dist/client.d.mts +2 -2
- package/dist/client.mjs +2 -2
- package/dist/movements.d.mts +139 -0
- package/dist/movements.mjs +334 -0
- package/dist/mpp.d.mts +42 -30
- package/dist/mpp.mjs +13 -14
- package/dist/{settlement-report-CT3EbtLL.mjs → settlement-report-DTxaAxE3.mjs} +22 -1
- package/dist/viem.d.mts +18 -18
- package/dist/viem.mjs +10 -15
- package/dist/x402.d.mts +21 -15
- package/dist/x402.mjs +8 -14
- package/package.json +9 -9
package/dist/viem.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as OnchainNetworkInput, X as X402PaymentRequirements, Y as X402Authorization, a as IntentSubmitError, n as CatenaClient, t as ApiError } from "./client-B_Gi0aqH.mjs";
|
|
2
2
|
import { X402ApprovalPendingError, X402PaymentError, X402SubmitInterruptedError } from "./x402.mjs";
|
|
3
3
|
import { LocalAccount } from "viem";
|
|
4
4
|
//#region src/viem.d.ts
|
|
@@ -8,7 +8,7 @@ import { LocalAccount } from "viem";
|
|
|
8
8
|
* `TransferWithAuthorization` typed data; `signMessage`, `signTransaction`,
|
|
9
9
|
* and raw-hash signing are structurally unavailable.
|
|
10
10
|
*/
|
|
11
|
-
declare class UnsupportedAccountCapabilityError extends Error {
|
|
11
|
+
export declare class UnsupportedAccountCapabilityError extends Error {
|
|
12
12
|
readonly capability: "signMessage" | "signTransaction";
|
|
13
13
|
constructor(capability: "signMessage" | "signTransaction");
|
|
14
14
|
}
|
|
@@ -16,12 +16,12 @@ declare class UnsupportedAccountCapabilityError extends Error {
|
|
|
16
16
|
* Machine-readable reason a typed-data payload was refused before any
|
|
17
17
|
* request was made. Branch on `reason`, not message prose.
|
|
18
18
|
*/
|
|
19
|
-
type UnsupportedTypedDataReason = "primary_type" | "types" | "network" | "asset" | "domain" | "message" | "nonce" | "from_mismatch" | "recipient" | "expired" | "window";
|
|
19
|
+
export type UnsupportedTypedDataReason = "primary_type" | "types" | "network" | "asset" | "domain" | "message" | "nonce" | "from_mismatch" | "recipient" | "expired" | "window";
|
|
20
20
|
/**
|
|
21
21
|
* The typed data is not something a Catena wallet can sign. Thrown
|
|
22
22
|
* client-side, before any intent exists; nothing was submitted or paid.
|
|
23
23
|
*/
|
|
24
|
-
declare class UnsupportedTypedDataError extends Error {
|
|
24
|
+
export declare class UnsupportedTypedDataError extends Error {
|
|
25
25
|
readonly reason: UnsupportedTypedDataReason;
|
|
26
26
|
constructor(reason: UnsupportedTypedDataReason, message: string);
|
|
27
27
|
}
|
|
@@ -30,7 +30,7 @@ declare class UnsupportedTypedDataError extends Error {
|
|
|
30
30
|
* wallet's own address. x402 authorizations can only be signed for a wallet
|
|
31
31
|
* account; pick an account whose deposit address source is `wallet`.
|
|
32
32
|
*/
|
|
33
|
-
declare class NotAWalletAccountError extends Error {
|
|
33
|
+
export declare class NotAWalletAccountError extends Error {
|
|
34
34
|
readonly accountId: string;
|
|
35
35
|
readonly source: string;
|
|
36
36
|
constructor(accountId: string, source: string);
|
|
@@ -39,7 +39,7 @@ declare class NotAWalletAccountError extends Error {
|
|
|
39
39
|
* Catena declined the payment (policy block or terminal failure). `reasons`
|
|
40
40
|
* carries the server's detail; the same struct will not succeed on retry.
|
|
41
41
|
*/
|
|
42
|
-
declare class X402PaymentDeclinedError extends X402PaymentError {
|
|
42
|
+
export declare class X402PaymentDeclinedError extends X402PaymentError {
|
|
43
43
|
readonly intentId: string;
|
|
44
44
|
constructor(intentId: string, reasons: readonly string[]);
|
|
45
45
|
}
|
|
@@ -50,7 +50,7 @@ declare class X402PaymentDeclinedError extends X402PaymentError {
|
|
|
50
50
|
* approved x402 payment resting in this state — it waits for the paid
|
|
51
51
|
* request to be re-run.
|
|
52
52
|
*/
|
|
53
|
-
declare class X402PaymentInFlightError extends X402PaymentError {
|
|
53
|
+
export declare class X402PaymentInFlightError extends X402PaymentError {
|
|
54
54
|
readonly intentId: string;
|
|
55
55
|
constructor(intentId: string, status: string);
|
|
56
56
|
}
|
|
@@ -61,7 +61,7 @@ declare class X402PaymentInFlightError extends X402PaymentError {
|
|
|
61
61
|
* return the same unusable value, so recovery here means reconciling the
|
|
62
62
|
* payment with the operator, not fetching the signature again.
|
|
63
63
|
*/
|
|
64
|
-
declare class X402PaymentSignatureUnusableError extends X402PaymentError {
|
|
64
|
+
export declare class X402PaymentSignatureUnusableError extends X402PaymentError {
|
|
65
65
|
readonly intentId: string;
|
|
66
66
|
constructor(intentId: string, message: string);
|
|
67
67
|
}
|
|
@@ -74,13 +74,13 @@ declare class X402PaymentSignatureUnusableError extends X402PaymentError {
|
|
|
74
74
|
* money has moved, so it belongs to the family a caller branches on before
|
|
75
75
|
* deciding whether to pay again. Reconcile with `getIntent(intentId)`.
|
|
76
76
|
*/
|
|
77
|
-
declare class SignatureVerificationFailedError extends X402PaymentError {
|
|
77
|
+
export declare class SignatureVerificationFailedError extends X402PaymentError {
|
|
78
78
|
readonly intentId: string;
|
|
79
79
|
readonly expectedAddress: string;
|
|
80
80
|
readonly recoveredAddress: string | undefined;
|
|
81
81
|
constructor(intentId: string, expectedAddress: string, recoveredAddress: string | undefined);
|
|
82
82
|
}
|
|
83
|
-
interface CatenaAccountOptions {
|
|
83
|
+
export interface CatenaAccountOptions {
|
|
84
84
|
/**
|
|
85
85
|
* The wallet account payments draw from. Its deposit address must resolve
|
|
86
86
|
* with source `wallet`.
|
|
@@ -102,16 +102,16 @@ interface CatenaAccountOptions {
|
|
|
102
102
|
* whose only working capability is `signTypedData` for x402 EIP-3009
|
|
103
103
|
* payment authorizations.
|
|
104
104
|
*/
|
|
105
|
-
type CatenaAccount = LocalAccount;
|
|
105
|
+
export type CatenaAccount = LocalAccount;
|
|
106
106
|
/**
|
|
107
107
|
* Present a Catena wallet as a viem `Account` for x402 client tooling.
|
|
108
108
|
*
|
|
109
109
|
* The returned account's `signTypedData` accepts exactly one shape — EIP-3009
|
|
110
|
-
* `TransferWithAuthorization` for
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
110
|
+
* `TransferWithAuthorization` for an EVM token, the payload x402 exact-scheme
|
|
111
|
+
* clients construct — and routes it through a Catena x402 intent. The server
|
|
112
|
+
* decides whether the network and token contract are supported before signing;
|
|
113
|
+
* the returned signature is verified against the caller's exact struct before
|
|
114
|
+
* it is returned. `signMessage` and `signTransaction` throw
|
|
115
115
|
* `UnsupportedAccountCapabilityError`; there is no raw-hash `sign`.
|
|
116
116
|
*
|
|
117
117
|
* Failure modes: `UnsupportedTypedDataError` (refused client-side, nothing
|
|
@@ -130,6 +130,6 @@ type CatenaAccount = LocalAccount;
|
|
|
130
130
|
* Requires the optional `viem` peer dependency; importing this module
|
|
131
131
|
* without viem installed fails with a module-not-found error naming it.
|
|
132
132
|
*/
|
|
133
|
-
declare function createCatenaAccount(client: CatenaClient, options: CatenaAccountOptions): Promise<CatenaAccount>;
|
|
133
|
+
export declare function createCatenaAccount(client: CatenaClient, options: CatenaAccountOptions): Promise<CatenaAccount>;
|
|
134
134
|
//#endregion
|
|
135
|
-
export { ApiError,
|
|
135
|
+
export { ApiError, IntentSubmitError, type OnchainNetworkInput, X402ApprovalPendingError, type X402Authorization, X402PaymentError, type X402PaymentRequirements, X402SubmitInterruptedError };
|
package/dist/viem.mjs
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as IntentSubmitError, t as ApiError, w as x402CredentialFromIntentData } from "./client-BSYVYJGm.mjs";
|
|
2
2
|
import { X402ApprovalPendingError, X402PaymentError, X402SubmitInterruptedError } from "./x402.mjs";
|
|
3
3
|
import * as v from "valibot";
|
|
4
4
|
import { getAddress, isAddress, isHex, recoverTypedDataAddress } from "viem";
|
|
5
5
|
import { toAccount } from "viem/accounts";
|
|
6
6
|
//#region src/viem.ts
|
|
7
|
-
const NETWORKS = {
|
|
8
|
-
"8453": {
|
|
9
|
-
network: "eip155:8453",
|
|
10
|
-
usdc: getAddress("0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913")
|
|
11
|
-
},
|
|
12
|
-
"84532": {
|
|
13
|
-
network: "eip155:84532",
|
|
14
|
-
usdc: getAddress("0x036CbD53842c5426634e7929541eC2318f3dCF7e")
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
7
|
const EIP712_DOMAIN_TYPE = [
|
|
18
8
|
{
|
|
19
9
|
name: "name",
|
|
@@ -185,6 +175,11 @@ const CANONICAL_DOMAIN_TYPE = encodeCanonicalTable(EIP712_DOMAIN_TYPE);
|
|
|
185
175
|
function isEvmAddress(value) {
|
|
186
176
|
return isAddress(value);
|
|
187
177
|
}
|
|
178
|
+
function evmNetwork(chainId) {
|
|
179
|
+
if (typeof chainId === "number" && !Number.isSafeInteger(chainId)) return;
|
|
180
|
+
const numeric = typeof chainId === "bigint" ? chainId : BigInt(chainId);
|
|
181
|
+
return numeric >= 1n && numeric <= BigInt(Number.MAX_SAFE_INTEGER) ? `eip155:${numeric}` : void 0;
|
|
182
|
+
}
|
|
188
183
|
async function createCatenaAccount(client, options) {
|
|
189
184
|
const deposit = await client.getAccountDepositAddress(options.accountId, {
|
|
190
185
|
network: options.network ?? "base",
|
|
@@ -211,9 +206,9 @@ async function signX402TypedData(client, args) {
|
|
|
211
206
|
const transferType = types["TransferWithAuthorization"];
|
|
212
207
|
if (encodeTypeTable(transferType) !== CANONICAL_TRANSFER_TYPE) throw new UnsupportedTypedDataError("types", "The TransferWithAuthorization type definition does not match EIP-3009");
|
|
213
208
|
if (domain.chainId === void 0) throw new UnsupportedTypedDataError("network", "The typed data names no chainId");
|
|
214
|
-
const
|
|
215
|
-
if (
|
|
216
|
-
if (domain.verifyingContract === void 0 || !isEvmAddress(domain.verifyingContract)
|
|
209
|
+
const network = evmNetwork(domain.chainId);
|
|
210
|
+
if (network === void 0) throw new UnsupportedTypedDataError("network", "The typed data chainId must be a positive safe integer");
|
|
211
|
+
if (domain.verifyingContract === void 0 || !isEvmAddress(domain.verifyingContract)) throw new UnsupportedTypedDataError("asset", "The verifying contract must be a 20-byte hex address, either all-lowercase or with a valid EIP-55 checksum");
|
|
217
212
|
if (!domain.name || !domain.version) throw new UnsupportedTypedDataError("domain", "The typed-data domain must carry the token's name and version");
|
|
218
213
|
const unsupportedDomainFields = Object.entries(domain).filter(([key, value]) => !CANONICAL_DOMAIN_FIELDS.has(key) && value !== void 0).map(([key]) => key);
|
|
219
214
|
if (unsupportedDomainFields.length > 0) throw new UnsupportedTypedDataError("domain", `The typed-data domain carries fields this account cannot sign over: ${unsupportedDomainFields.join(", ")}`);
|
|
@@ -240,7 +235,7 @@ async function signX402TypedData(client, args) {
|
|
|
240
235
|
};
|
|
241
236
|
const paymentRequirements = {
|
|
242
237
|
scheme: "exact",
|
|
243
|
-
network
|
|
238
|
+
network,
|
|
244
239
|
asset: getAddress(domain.verifyingContract),
|
|
245
240
|
amount: authorization.value,
|
|
246
241
|
payTo: message.to,
|
package/dist/x402.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { J as WalletCounterpartyRail, X as X402PaymentRequirements, Z as X402Resource, i as FetchLike, n as CatenaClient } from "./client-B_Gi0aqH.mjs";
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
//#region src/x402.d.ts
|
|
4
4
|
declare const paymentRequiredSchema: v.LooseObjectSchema<{
|
|
@@ -26,12 +26,12 @@ declare const paymentRequiredSchema: v.LooseObjectSchema<{
|
|
|
26
26
|
*/
|
|
27
27
|
readonly extensions: v.OptionalSchema<v.UnknownSchema, undefined>;
|
|
28
28
|
}, undefined>;
|
|
29
|
-
type X402PaymentRequired = v.InferOutput<typeof paymentRequiredSchema>;
|
|
29
|
+
export type X402PaymentRequired = v.InferOutput<typeof paymentRequiredSchema>;
|
|
30
30
|
/**
|
|
31
31
|
* Decode a 402 response's `PAYMENT-REQUIRED` challenge. Returns undefined for
|
|
32
32
|
* a 402 that carries no decodable v2 challenge (not an x402 endpoint).
|
|
33
33
|
*/
|
|
34
|
-
declare function decodePaymentRequired(response: Response): X402PaymentRequired | undefined;
|
|
34
|
+
export declare function decodePaymentRequired(response: Response): X402PaymentRequired | undefined;
|
|
35
35
|
/**
|
|
36
36
|
* Payment failure raised by this module; `reasons` carries the policy or
|
|
37
37
|
* decline detail when the server provided any, and subclasses mark the cases
|
|
@@ -41,7 +41,7 @@ declare function decodePaymentRequired(response: Response): X402PaymentRequired
|
|
|
41
41
|
* `TimeoutError` also propagates unchanged; no payment was authorized, so
|
|
42
42
|
* re-running cannot double-pay.
|
|
43
43
|
*/
|
|
44
|
-
declare class X402PaymentError extends Error {
|
|
44
|
+
export declare class X402PaymentError extends Error {
|
|
45
45
|
readonly reasons: readonly string[];
|
|
46
46
|
constructor(message: string, reasons?: readonly string[],
|
|
47
47
|
/**
|
|
@@ -60,7 +60,7 @@ declare class X402PaymentError extends Error {
|
|
|
60
60
|
* account on one of `requiredNetworks`, not to change policy. Consumers can
|
|
61
61
|
* name those networks (and, for a CLI, tell the user how to switch accounts).
|
|
62
62
|
*/
|
|
63
|
-
declare class X402NetworkMismatchError extends X402PaymentError {
|
|
63
|
+
export declare class X402NetworkMismatchError extends X402PaymentError {
|
|
64
64
|
readonly accountId: string;
|
|
65
65
|
readonly requiredNetworks: readonly string[];
|
|
66
66
|
constructor(accountId: string, requiredNetworks: readonly string[], reasons?: readonly string[]);
|
|
@@ -73,15 +73,21 @@ declare class X402NetworkMismatchError extends X402PaymentError {
|
|
|
73
73
|
* `network`, then a re-run. Consumers can name the recipient (and, for a CLI,
|
|
74
74
|
* print the exact counterparty-create command).
|
|
75
75
|
*/
|
|
76
|
-
declare class X402CounterpartyNotFoundError extends X402PaymentError {
|
|
76
|
+
export declare class X402CounterpartyNotFoundError extends X402PaymentError {
|
|
77
77
|
readonly payTo: string;
|
|
78
78
|
readonly network: string;
|
|
79
|
+
/**
|
|
80
|
+
* Server-resolved Catena rail that can be passed to a
|
|
81
|
+
* `create_counterparty` intent. Absent when the server sends no valid rail,
|
|
82
|
+
* or when the rail names a different recipient than the challenge.
|
|
83
|
+
*/
|
|
84
|
+
readonly requiredRail: WalletCounterpartyRail | undefined;
|
|
79
85
|
/**
|
|
80
86
|
* The challenge's advertised service name, when present — a suggested
|
|
81
87
|
* counterparty name.
|
|
82
88
|
*/
|
|
83
89
|
readonly serviceName: string | undefined;
|
|
84
|
-
constructor(payTo: string, network: string, serviceName?: string, reasons?: readonly string[]);
|
|
90
|
+
constructor(payTo: string, network: string, serviceName?: string, reasons?: readonly string[], requiredRail?: WalletCounterpartyRail);
|
|
85
91
|
}
|
|
86
92
|
/**
|
|
87
93
|
* The payment exceeded a policy limit and is parked for a human approval.
|
|
@@ -89,7 +95,7 @@ declare class X402CounterpartyNotFoundError extends X402PaymentError {
|
|
|
89
95
|
* same request (same endpoint, same price) consumes the approval and pays.
|
|
90
96
|
* `expiresAt` is when the pending approval self-expires.
|
|
91
97
|
*/
|
|
92
|
-
declare class X402ApprovalPendingError extends X402PaymentError {
|
|
98
|
+
export declare class X402ApprovalPendingError extends X402PaymentError {
|
|
93
99
|
readonly intentId: string;
|
|
94
100
|
readonly expiresAt: string | null;
|
|
95
101
|
constructor(intentId: string, reasons: readonly string[], expiresAt: string | null);
|
|
@@ -103,7 +109,7 @@ declare class X402ApprovalPendingError extends X402PaymentError {
|
|
|
103
109
|
* authorization is valid) — re-running the whole loop would mint a second
|
|
104
110
|
* payment.
|
|
105
111
|
*/
|
|
106
|
-
declare class X402RetryFailedError extends X402PaymentError {
|
|
112
|
+
export declare class X402RetryFailedError extends X402PaymentError {
|
|
107
113
|
readonly receipt: X402PaymentReceipt;
|
|
108
114
|
constructor(receipt: X402PaymentReceipt, cause: unknown);
|
|
109
115
|
}
|
|
@@ -117,12 +123,12 @@ declare class X402RetryFailedError extends X402PaymentError {
|
|
|
117
123
|
* processing, it is mid-settlement — keep polling. Pay again only once it is
|
|
118
124
|
* terminally blocked or failed.
|
|
119
125
|
*/
|
|
120
|
-
declare class X402SubmitInterruptedError extends X402PaymentError {
|
|
126
|
+
export declare class X402SubmitInterruptedError extends X402PaymentError {
|
|
121
127
|
readonly intentId: string;
|
|
122
128
|
readonly requirements: X402PaymentRequirements;
|
|
123
129
|
constructor(intentId: string, requirements: X402PaymentRequirements, cause: unknown);
|
|
124
130
|
}
|
|
125
|
-
interface X402PaymentReceipt {
|
|
131
|
+
export interface X402PaymentReceipt {
|
|
126
132
|
/**
|
|
127
133
|
* The Catena intent that settled the payment; pass to `getIntent`.
|
|
128
134
|
*/
|
|
@@ -151,7 +157,7 @@ interface X402PaymentReceipt {
|
|
|
151
157
|
* propagates unchanged; no payment was authorized, so re-running cannot
|
|
152
158
|
* double-pay.
|
|
153
159
|
*/
|
|
154
|
-
declare function payX402Challenge(client: CatenaClient, args: {
|
|
160
|
+
export declare function payX402Challenge(client: CatenaClient, args: {
|
|
155
161
|
accountId: string;
|
|
156
162
|
paymentRequired: X402PaymentRequired;
|
|
157
163
|
/**
|
|
@@ -170,7 +176,7 @@ declare function payX402Challenge(client: CatenaClient, args: {
|
|
|
170
176
|
*/
|
|
171
177
|
maxAtomicAmount?: bigint;
|
|
172
178
|
}): Promise<X402PaymentReceipt>;
|
|
173
|
-
interface X402FetchOptions {
|
|
179
|
+
export interface X402FetchOptions {
|
|
174
180
|
/**
|
|
175
181
|
* Source wallet account the payments draw from.
|
|
176
182
|
*/
|
|
@@ -201,6 +207,6 @@ interface X402FetchOptions {
|
|
|
201
207
|
* propagates unchanged; no payment was authorized, so re-running cannot
|
|
202
208
|
* double-pay.
|
|
203
209
|
*/
|
|
204
|
-
declare function wrapFetchWithX402Payment(client: CatenaClient, options: X402FetchOptions): FetchLike;
|
|
210
|
+
export declare function wrapFetchWithX402Payment(client: CatenaClient, options: X402FetchOptions): FetchLike;
|
|
205
211
|
//#endregion
|
|
206
|
-
export {
|
|
212
|
+
export type { WalletCounterpartyRail, X402PaymentRequirements, X402Resource };
|
package/dist/x402.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
1
|
+
import { D as extractRelayableOffer, E as x402ResourceSchema, O as extractRelayableReceipt, T as x402PaymentRequirementsSchema, n as IntentSubmitError, t as ApiError, w as x402CredentialFromIntentData } from "./client-BSYVYJGm.mjs";
|
|
2
|
+
import { a as isReplayableFetchRequest, i as fetchRetryHeaders, n as reportSettlementHint$1, o as requiredWalletRailFromDetails, r as paymentNetworkLabel, s as assertNever, t as EVM_TRANSACTION_HASH_PATTERN } from "./settlement-report-DTxaAxE3.mjs";
|
|
3
3
|
import * as v from "valibot";
|
|
4
4
|
//#region src/x402.ts
|
|
5
5
|
const PAYMENT_REQUIRED_HEADERS = ["PAYMENT-REQUIRED", "X-Payment-Required"];
|
|
@@ -25,14 +25,6 @@ const TRY_NEXT_REQUIREMENT_CODES = new Set([
|
|
|
25
25
|
X402_NETWORK_MISMATCH_CODE,
|
|
26
26
|
X402_COUNTERPARTY_RAIL_NOT_FOUND_CODE
|
|
27
27
|
]);
|
|
28
|
-
const NETWORK_LABELS = {
|
|
29
|
-
"eip155:8453": "Base",
|
|
30
|
-
"eip155:84532": "Base Sepolia"
|
|
31
|
-
};
|
|
32
|
-
function networkLabel(network) {
|
|
33
|
-
const label = Object.hasOwn(NETWORK_LABELS, network) ? NETWORK_LABELS[network] : void 0;
|
|
34
|
-
return label ? `${label} (${network})` : network;
|
|
35
|
-
}
|
|
36
28
|
function decodeBase64Json(value) {
|
|
37
29
|
const normalized = value.replaceAll("-", "+").replaceAll("_", "/");
|
|
38
30
|
const bytes = Uint8Array.from(atob(normalized), (char) => char.charCodeAt(0));
|
|
@@ -70,7 +62,7 @@ var X402NetworkMismatchError = class extends X402PaymentError {
|
|
|
70
62
|
accountId;
|
|
71
63
|
requiredNetworks;
|
|
72
64
|
constructor(accountId, requiredNetworks, reasons = []) {
|
|
73
|
-
super(`Account ${accountId} cannot fund this 402 challenge: it must be paid from a wallet account on ${requiredNetworks.map(
|
|
65
|
+
super(`Account ${accountId} cannot fund this 402 challenge: it must be paid from a wallet account on ${requiredNetworks.map(paymentNetworkLabel).join(" or ")}`, reasons, { appendReasonsToMessage: false });
|
|
74
66
|
this.name = "X402NetworkMismatchError";
|
|
75
67
|
this.accountId = accountId;
|
|
76
68
|
this.requiredNetworks = requiredNetworks;
|
|
@@ -79,13 +71,15 @@ var X402NetworkMismatchError = class extends X402PaymentError {
|
|
|
79
71
|
var X402CounterpartyNotFoundError = class extends X402PaymentError {
|
|
80
72
|
payTo;
|
|
81
73
|
network;
|
|
74
|
+
requiredRail;
|
|
82
75
|
serviceName;
|
|
83
|
-
constructor(payTo, network, serviceName, reasons = []) {
|
|
84
|
-
super(`This 402 pays ${payTo} on ${
|
|
76
|
+
constructor(payTo, network, serviceName, reasons = [], requiredRail) {
|
|
77
|
+
super(`This 402 pays ${payTo} on ${paymentNetworkLabel(network)}, which is not a saved counterparty wallet rail; add it as a counterparty before paying`, reasons, { appendReasonsToMessage: false });
|
|
85
78
|
this.name = "X402CounterpartyNotFoundError";
|
|
86
79
|
this.payTo = payTo;
|
|
87
80
|
this.network = network;
|
|
88
81
|
this.serviceName = serviceName;
|
|
82
|
+
this.requiredRail = requiredRail;
|
|
89
83
|
}
|
|
90
84
|
};
|
|
91
85
|
var X402ApprovalPendingError = class extends X402PaymentError {
|
|
@@ -158,7 +152,7 @@ async function payX402Challenge(client, args) {
|
|
|
158
152
|
...otherSkips
|
|
159
153
|
].map((skip) => skip.error.message))];
|
|
160
154
|
const unsaved = counterpartySkips.find((skip) => skip.error.status === 404 && EVM_ADDRESS.test(skip.requirement.payTo));
|
|
161
|
-
if (unsaved) throw new X402CounterpartyNotFoundError(unsaved.requirement.payTo, unsaved.requirement.network, resource?.serviceName, reasons);
|
|
155
|
+
if (unsaved) throw new X402CounterpartyNotFoundError(unsaved.requirement.payTo, unsaved.requirement.network, resource?.serviceName, reasons, requiredWalletRailFromDetails(unsaved.error.details, unsaved.requirement.payTo));
|
|
162
156
|
if (mismatchSkips.length > 0 && counterpartySkips.length === 0) throw new X402NetworkMismatchError(args.accountId, [...new Set(mismatchSkips.map((skip) => skip.requirement.network))], reasons);
|
|
163
157
|
throw new X402PaymentError("No requirement in the 402 challenge is payable from this account", reasons);
|
|
164
158
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@catena/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Typed client SDK for the Catena agent API",
|
|
5
5
|
"homepage": "https://catena.com/",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -34,18 +34,18 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@turnkey/api-key-stamper": "0.6.
|
|
37
|
+
"@turnkey/api-key-stamper": "0.6.14",
|
|
38
38
|
"valibot": "1.4.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"mppx": "0.9.
|
|
42
|
-
"publint": "0.3.
|
|
43
|
-
"tsdown": "0.
|
|
44
|
-
"viem": "2.
|
|
41
|
+
"mppx": "0.9.2",
|
|
42
|
+
"publint": "0.3.24",
|
|
43
|
+
"tsdown": "0.23.0",
|
|
44
|
+
"viem": "2.56.3"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"mppx": "0.9.0",
|
|
48
|
-
"viem": "^2.
|
|
47
|
+
"mppx": "^0.9.0",
|
|
48
|
+
"viem": "^2.24.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|
|
51
51
|
"mppx": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=20"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "d063f4fe2ff6940a73a547b7f11eb4d67f9b4748",
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|
|
64
64
|
"clean": "git clean -xdf dist node_modules/.cache",
|