@atumlabs/mppx-atum-escrow 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,126 @@
1
+ import * as zod_v4_core from 'zod/v4/core';
2
+ import * as z from 'zod/mini';
3
+ import { Signer } from 'ethers';
4
+ import { S as SenderSigner, f as SenderSignerOptions, h as SolanaClusterUnixTimeReader } from './internal-CjcEyEsm.js';
5
+ export { A as AtumEscrowChallenge, a as AtumEscrowCredential, C as ChargeCredentialPayload, c as ChargeRequest, d as ChargeRequestSchema, e as CredentialPayloadSchema, I as INTENT, M as METHOD_NAME, P as PaymentRequest, g as atumEscrowChargeMethod } from './internal-CjcEyEsm.js';
6
+ import { Method } from 'mppx';
7
+
8
+ /** Configuration for the payer side of the method. */
9
+ interface AtumEscrowClientConfig {
10
+ /**
11
+ * How to sign the source-chain deposit authorization. Either a ready-made
12
+ * {@link SenderSigner}, or options selecting the built-in private-key or Turnkey
13
+ * provider ({@link SenderSignerOptions}), which are bound to the challenge's source
14
+ * chain automatically.
15
+ */
16
+ signer: SenderSigner | SenderSignerOptions;
17
+ /**
18
+ * The payer's source-chain account (the depositor). Its chain-native form must match
19
+ * the signing key; the server rejects a credential whose signature does not recover to it.
20
+ */
21
+ account: string;
22
+ /** Clock (epoch ms) used to derive absolute deadlines from the challenge budgets. Defaults to `Date.now`. */
23
+ now?: () => number;
24
+ /**
25
+ * Solana-only test seam: supplies the `issued_at` a Solana deposit is stamped with,
26
+ * keeping the build fully offline. Defaults to the client clock. Ignored for EVM/Tron.
27
+ */
28
+ solanaClockReader?: SolanaClusterUnixTimeReader;
29
+ }
30
+ /**
31
+ * Configure the payer side of the method.
32
+ *
33
+ * The returned method builds and signs an Atum payment request from an incoming
34
+ * challenge and serializes it into an MPP credential. The source-chain authorization is
35
+ * built through the payment-gateway client's request builder, so the same call handles
36
+ * EVM, Tron, and Solana sources.
37
+ *
38
+ * Idempotency: for EVM and Tron sources the deposit nonce (and the `request_id`) are
39
+ * derived deterministically from the challenge id, so even if a caller rebuilds the
40
+ * credential for the same challenge the escrow admits at most one deposit — the reused
41
+ * nonce reverts the second on-chain. This holds only when the merchant issues a stable,
42
+ * per-intent challenge id: set `opaque` to a per-payment identifier (e.g. an order id),
43
+ * reused on retry of that intent, and keep `expires` stable or absent per intent (both feed
44
+ * the challenge-id HMAC). Solana sources use a replay-window nonce rather than a
45
+ * deterministic one and rely on the gateway's content-keyed dedup (the request id, and
46
+ * thus the payment id, are still derived deterministically from the challenge id).
47
+ * Building once and resubmitting the identical bytes remains the simplest safe pattern.
48
+ *
49
+ * @param config - the payer's signer, source account, and options.
50
+ */
51
+ declare function registerClient(config: AtumEscrowClientConfig): Method.Client<{
52
+ readonly name: "atum-escrow";
53
+ readonly intent: "charge";
54
+ readonly schema: {
55
+ readonly request: z.ZodMiniObject<{
56
+ source: z.ZodMiniObject<{
57
+ network: z.ZodMiniString<string>;
58
+ asset: z.ZodMiniString<string>;
59
+ amount: z.ZodMiniString<string>;
60
+ }, zod_v4_core.$strip>;
61
+ extra: z.ZodMiniObject<{
62
+ destination: z.ZodMiniObject<{
63
+ network: z.ZodMiniString<string>;
64
+ asset: z.ZodMiniString<string>;
65
+ account: z.ZodMiniString<string>;
66
+ }, zod_v4_core.$strip>;
67
+ fulfillmentAmount: z.ZodMiniString<string>;
68
+ escrow: z.ZodMiniString<string>;
69
+ fulfillmentProxy: z.ZodMiniString<string>;
70
+ reserver: z.ZodMiniString<string>;
71
+ releaser: z.ZodMiniString<string>;
72
+ fulfillmentVerifierEndpoint: z.ZodMiniString<string>;
73
+ quoteDeadlineSeconds: z.ZodMiniNumber<number>;
74
+ fulfillmentDeadlineSeconds: z.ZodMiniNumber<number>;
75
+ permit2: z.ZodMiniOptional<z.ZodMiniString<string>>;
76
+ svmSignatureClusterId: z.ZodMiniOptional<z.ZodMiniString<string>>;
77
+ svmSignatureDomainVersion: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
78
+ }, zod_v4_core.$strip>;
79
+ }, zod_v4_core.$strip>;
80
+ readonly credential: {
81
+ readonly payload: z.ZodMiniObject<{
82
+ paymentRequest: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
83
+ }, zod_v4_core.$strip>;
84
+ };
85
+ };
86
+ }, undefined>;
87
+ /** Result of an {@link ensureSourceApproval} call. */
88
+ interface EnsureApprovalResult {
89
+ /** The existing allowance already covered the required amount; no transaction was sent. */
90
+ alreadySufficient: boolean;
91
+ /** The approval transaction hash, when one was sent. */
92
+ txHash?: string;
93
+ }
94
+ /**
95
+ * Ensure the payer has approved the token-transfer contract (Permit2) to move the source
96
+ * token, so the escrow deposit does not revert at settlement. Reads the current allowance
97
+ * and sends an approval only if it falls short.
98
+ *
99
+ * Applies to EVM and Tron sources (which use a Permit2-style allowance); Solana sources
100
+ * authorize the transfer in the signed deposit itself, so this is a no-op there.
101
+ *
102
+ * @param params.network - CAIP-2 source chain id.
103
+ * @param params.token - source token address.
104
+ * @param params.owner - the payer's account.
105
+ * @param params.signer - an ethers signer able to send the approval on `network`.
106
+ * @param params.spender - the contract to approve; defaults to the canonical EVM Permit2.
107
+ * Required for Tron (its Permit2 address is chain-specific).
108
+ * @param params.requiredAllowance - the minimum allowance this charge needs (pass the
109
+ * source cap, `challenge.request.source.amount`). When omitted, the function ensures an
110
+ * unlimited approval — a smaller leftover allowance is NOT treated as sufficient, so a
111
+ * later larger charge cannot slip through and revert on-chain.
112
+ *
113
+ * Not concurrency-safe: two overlapping calls for the same `(owner, token, spender)` may
114
+ * both read a short allowance and both send an approval. They target the same value, so
115
+ * this only wastes gas; serialize calls per token if that matters.
116
+ */
117
+ declare function ensureSourceApproval(params: {
118
+ network: string;
119
+ token: string;
120
+ owner: string;
121
+ signer: Signer;
122
+ spender?: string;
123
+ requiredAllowance?: bigint;
124
+ }): Promise<EnsureApprovalResult>;
125
+
126
+ export { type AtumEscrowClientConfig, type EnsureApprovalResult, SenderSigner, SenderSignerOptions, ensureSourceApproval, registerClient };
package/dist/client.js ADDED
@@ -0,0 +1,21 @@
1
+ import { createRequire as __atumCreateRequire } from 'module'; const require = __atumCreateRequire(import.meta.url);
2
+ import {
3
+ ensureSourceApproval,
4
+ registerClient
5
+ } from "./chunk-V2SJ747H.js";
6
+ import {
7
+ ChargeRequestSchema,
8
+ CredentialPayloadSchema,
9
+ INTENT,
10
+ METHOD_NAME,
11
+ atumEscrowChargeMethod
12
+ } from "./chunk-WWSNMK7N.js";
13
+ export {
14
+ ChargeRequestSchema,
15
+ CredentialPayloadSchema,
16
+ INTENT,
17
+ METHOD_NAME,
18
+ atumEscrowChargeMethod,
19
+ ensureSourceApproval,
20
+ registerClient
21
+ };
@@ -0,0 +1,81 @@
1
+ export { A as AtumEscrowChallenge, a as AtumEscrowCredential, b as AtumEscrowRequest, C as ChargeCredentialPayload, c as ChargeRequest, d as ChargeRequestSchema, e as CredentialPayloadSchema, I as INTENT, M as METHOD_NAME, P as PaymentRequest, S as SenderSigner, f as SenderSignerOptions, g as atumEscrowChargeMethod } from './internal-CjcEyEsm.js';
2
+ export { AtumEscrowClientConfig, EnsureApprovalResult, ensureSourceApproval, registerClient } from './client.js';
3
+ export { AtumEscrowCorridor, AtumEscrowReceipt, AtumEscrowServerConfig, AtumEscrowSource, ChainDefaultsSource, FulfillmentConfirmation, PaymentSubmitter, buildChargeRequest, corridorFromDefaults, registerServer, validateCorridor } from './server.js';
4
+ import 'zod/mini';
5
+ import 'mppx';
6
+ import 'zod/v4/core';
7
+ import 'ethers';
8
+
9
+ /**
10
+ * This file was automatically generated by json-schema-to-typescript.
11
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
12
+ * and run json-schema-to-typescript to regenerate this file.
13
+ */
14
+ /**
15
+ * The `extra.atum` object carried inside an atum-escrow x402 PaymentRequirements entry (accepts[]): the merchant's receive-side plus the contract/role addresses and deadline budgets. Scheme-specific data the standard x402 `extra` bag treats as opaque, so it is owned here and shared by all role mechanisms. Addresses are chain-general: an EVM `0x`-prefixed hex address, or a Tron/Solana base58 address, depending on the source/destination chain.
16
+ */
17
+ interface AtumEscrowExtra {
18
+ /**
19
+ * Where the merchant receives (CAIP-2 chain, token, account).
20
+ */
21
+ destination: {
22
+ /**
23
+ * CAIP-2 destination chain id (e.g. eip155:42161).
24
+ */
25
+ network: string;
26
+ /**
27
+ * Destination token address (EVM hex or base58).
28
+ */
29
+ asset: string;
30
+ /**
31
+ * Merchant receive account (EVM hex or base58).
32
+ */
33
+ account: string;
34
+ };
35
+ /**
36
+ * Exact amount the merchant receives, in atomic token units.
37
+ */
38
+ fulfillmentAmount: string;
39
+ /**
40
+ * Source-chain escrow contract (the x402 payTo).
41
+ */
42
+ escrow: string;
43
+ /**
44
+ * Destination-chain fulfillment proxy contract.
45
+ */
46
+ fulfillmentProxy: string;
47
+ /**
48
+ * Reserver role address (escrow deposit witness).
49
+ */
50
+ reserver: string;
51
+ /**
52
+ * Releaser role address (escrow deposit witness).
53
+ */
54
+ releaser: string;
55
+ /**
56
+ * Source-chain fulfillment-verifier endpoint the payment request carries. The verifier account and the quote selector are the releaser and reserver respectively, so only the endpoint is not otherwise present in this object.
57
+ */
58
+ fulfillmentVerifierEndpoint: string;
59
+ /**
60
+ * Recommended quote-deadline budget in seconds, relative to signing time.
61
+ */
62
+ quoteDeadlineSeconds: number;
63
+ /**
64
+ * Recommended fulfillment-deadline budget in seconds, relative to signing time.
65
+ */
66
+ fulfillmentDeadlineSeconds: number;
67
+ /**
68
+ * Tron-only: the Permit2 contract address the deposit authorization is signed against (the TIP-712 verifying contract). Present only when the source chain is Tron; on EVM the canonical Permit2 address is well-known, and Solana does not use Permit2.
69
+ */
70
+ permit2?: string;
71
+ /**
72
+ * Solana-only: cluster identifier used to domain-separate the deposit authorization. Present only when the source chain is Solana; omitted for EVM/Tron.
73
+ */
74
+ svmSignatureClusterId?: string;
75
+ /**
76
+ * Solana-only: signature domain version used to domain-separate the deposit authorization. Present only when the source chain is Solana; omitted for EVM/Tron.
77
+ */
78
+ svmSignatureDomainVersion?: number;
79
+ }
80
+
81
+ export type { AtumEscrowExtra };
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ import { createRequire as __atumCreateRequire } from 'module'; const require = __atumCreateRequire(import.meta.url);
2
+ import {
3
+ ensureSourceApproval,
4
+ registerClient
5
+ } from "./chunk-V2SJ747H.js";
6
+ import {
7
+ buildChargeRequest,
8
+ corridorFromDefaults,
9
+ registerServer,
10
+ validateCorridor
11
+ } from "./chunk-XDYCJ36Z.js";
12
+ import {
13
+ ChargeRequestSchema,
14
+ CredentialPayloadSchema,
15
+ INTENT,
16
+ METHOD_NAME,
17
+ atumEscrowChargeMethod
18
+ } from "./chunk-WWSNMK7N.js";
19
+ export {
20
+ ChargeRequestSchema,
21
+ CredentialPayloadSchema,
22
+ INTENT,
23
+ METHOD_NAME,
24
+ atumEscrowChargeMethod,
25
+ buildChargeRequest,
26
+ corridorFromDefaults,
27
+ ensureSourceApproval,
28
+ registerClient,
29
+ registerServer,
30
+ validateCorridor
31
+ };