@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,230 @@
1
+ import * as zod_v4_core from 'zod/v4/core';
2
+ import * as z from 'zod/mini';
3
+ import { P as PaymentRequest, i as ChainDefaults, c as ChargeRequest } from './internal-CjcEyEsm.js';
4
+ export { A as AtumEscrowChallenge, a as AtumEscrowCredential, C as ChargeCredentialPayload, d as ChargeRequestSchema, e as CredentialPayloadSchema, I as INTENT, M as METHOD_NAME, g as atumEscrowChargeMethod } from './internal-CjcEyEsm.js';
5
+ import { Receipt, Method } from 'mppx';
6
+
7
+ /**
8
+ * This file was automatically generated by json-schema-to-typescript.
9
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
10
+ * and run json-schema-to-typescript to regenerate this file.
11
+ */
12
+ /**
13
+ * Confirmation details after a payment has been successfully delivered. Contains proof of delivery and transaction details for both source and destination chains.
14
+ */
15
+ interface FulfillmentConfirmation {
16
+ /**
17
+ * Unique identifier for this payment transaction. Use this to track the payment across all systems.
18
+ */
19
+ payment_id: string;
20
+ /**
21
+ * Your original request ID that was provided when creating the payment. Helps match confirmations to your internal systems.
22
+ */
23
+ request_id: string;
24
+ /**
25
+ * Timestamp when the fulfillment was completed
26
+ */
27
+ fulfillment_timestamp?: string;
28
+ /**
29
+ * The blockchain where funds were locked in escrow, using CAIP-2 format. CAIP-2 is a standard way to identify blockchains: {namespace}:{reference}. Examples: 'eip155:1' for Ethereum mainnet, 'eip155:42161' for Arbitrum, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' for Solana, 'tron:mainnet' for Tron
30
+ */
31
+ source_chain_id: string;
32
+ /**
33
+ * The blockchain where the payment was delivered, using CAIP-2 format. CAIP-2 is a standard way to identify blockchains: {namespace}:{reference}. Examples: 'eip155:1' for Ethereum mainnet, 'eip155:42161' for Arbitrum, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' for Solana, 'tron:mainnet' for Tron
34
+ */
35
+ destination_chain_id: string;
36
+ /**
37
+ * Transaction hash of the escrow reservation on the source chain
38
+ */
39
+ source_tx_hash: string;
40
+ /**
41
+ * Transaction hash of the fulfillment on the destination chain
42
+ */
43
+ destination_tx_hash: string;
44
+ /**
45
+ * Block number where the source transaction was confirmed
46
+ */
47
+ source_block_number?: number;
48
+ /**
49
+ * Block number where the destination transaction was confirmed
50
+ */
51
+ destination_block_number?: number;
52
+ }
53
+
54
+ /** One source chain/token the merchant accepts payment from. */
55
+ interface AtumEscrowSource {
56
+ /** CAIP-2 source chain id (e.g. `eip155:8453`, `tron:mainnet`, `solana:<genesis>`). */
57
+ network: string;
58
+ /**
59
+ * Source token addresses the payer may fund with on this network. All tokens on the
60
+ * same chain share the escrow/role/verifier fields below, so accepting several tokens on
61
+ * one chain is a single source with multiple `assets` — no need to duplicate the entry.
62
+ */
63
+ assets: string[];
64
+ /** Source-chain escrow contract; the payer's funds lock here. */
65
+ escrow: string;
66
+ /** Source-chain role address that witnesses the escrow deposit on reservation. */
67
+ reserver: string;
68
+ /** Source-chain role address that witnesses the escrow release on fulfillment. */
69
+ releaser: string;
70
+ /** Source-chain endpoint used to verify fulfillment. */
71
+ fulfillmentVerifierEndpoint: string;
72
+ /** Tron-only: the Permit2 contract the deposit is signed against. Defaults to the known address for the cluster when omitted. */
73
+ permit2?: string;
74
+ /** Solana-only: cluster id that domain-separates the deposit authorization. */
75
+ svmSignatureClusterId?: string;
76
+ /** Solana-only: signature domain version that domain-separates the deposit authorization. */
77
+ svmSignatureDomainVersion?: number;
78
+ }
79
+ /** Corridor configuration: what the merchant receives and which sources it accepts. */
80
+ interface AtumEscrowCorridor {
81
+ /** Where the merchant receives: CAIP-2 chain, token, and receive account. */
82
+ destination: {
83
+ network: string;
84
+ asset: string;
85
+ account: string;
86
+ };
87
+ /** Destination-chain fulfillment-proxy contract. */
88
+ fulfillmentProxy: string;
89
+ /** Markup over `fulfillmentAmount` to derive each source cap, in basis points (e.g. `300` = 3%). */
90
+ markupBps: number;
91
+ /** Quote-deadline budget in seconds, relative to signing time. */
92
+ quoteDeadlineSeconds: number;
93
+ /** Fulfillment-deadline budget in seconds, relative to signing time. */
94
+ fulfillmentDeadlineSeconds: number;
95
+ /** Accepted source options; selected per charge by `(network, asset)`. */
96
+ sources: AtumEscrowSource[];
97
+ }
98
+ /**
99
+ * Submits a signed payment request to the Atum Payment Gateway and resolves with the
100
+ * settlement result. Satisfied by an adapter over `@atum-labs/payment-gateway-client`.
101
+ */
102
+ interface PaymentSubmitter {
103
+ submit(request: PaymentRequest): Promise<{
104
+ payment_id?: string;
105
+ fulfillment_confirmation?: FulfillmentConfirmation;
106
+ }>;
107
+ }
108
+ /** Configuration for the merchant side of the method. */
109
+ interface AtumEscrowServerConfig {
110
+ /** The gateway settlement is submitted through. */
111
+ submitter: PaymentSubmitter;
112
+ /** Clock (epoch ms) used to validate deadline ordering and budgets. Defaults to `Date.now`. */
113
+ now?: () => number;
114
+ }
115
+ /**
116
+ * The receipt returned once a payment settles, extending the MPP receipt with the Atum
117
+ * settlement details. `reference` carries the destination-chain transaction hash, and
118
+ * `fulfillmentConfirmation` carries the full settlement confirmation (payment id,
119
+ * destination chain, request id, and transaction hashes).
120
+ */
121
+ type AtumEscrowReceipt = Receipt.Receipt & {
122
+ /** The full settlement confirmation. */
123
+ fulfillmentConfirmation: FulfillmentConfirmation;
124
+ };
125
+ /**
126
+ * Configure the merchant side of the method.
127
+ *
128
+ * The returned method verifies an incoming credential and settles it through the Atum
129
+ * Payment Gateway, resolving with an {@link AtumEscrowReceipt} once the payment
130
+ * completes. Verification throws if the credential is invalid or the payment does not
131
+ * settle. The inbound request is held open for the duration of settlement, so client
132
+ * and server timeouts must exceed the corridor's deadline budgets.
133
+ *
134
+ * The corridor is not part of the server configuration: verification trusts the
135
+ * HMAC-bound challenge (carried in `request`) as the source of truth for the payment
136
+ * terms, so one registration serves every corridor the merchant advertises.
137
+ *
138
+ * @param config - the gateway submitter and options.
139
+ */
140
+ declare function registerServer(config: AtumEscrowServerConfig): Method.Server<{
141
+ readonly name: "atum-escrow";
142
+ readonly intent: "charge";
143
+ readonly schema: {
144
+ readonly request: z.ZodMiniObject<{
145
+ source: z.ZodMiniObject<{
146
+ network: z.ZodMiniString<string>;
147
+ asset: z.ZodMiniString<string>;
148
+ amount: z.ZodMiniString<string>;
149
+ }, zod_v4_core.$strip>;
150
+ extra: z.ZodMiniObject<{
151
+ destination: z.ZodMiniObject<{
152
+ network: z.ZodMiniString<string>;
153
+ asset: z.ZodMiniString<string>;
154
+ account: z.ZodMiniString<string>;
155
+ }, zod_v4_core.$strip>;
156
+ fulfillmentAmount: z.ZodMiniString<string>;
157
+ escrow: z.ZodMiniString<string>;
158
+ fulfillmentProxy: z.ZodMiniString<string>;
159
+ reserver: z.ZodMiniString<string>;
160
+ releaser: z.ZodMiniString<string>;
161
+ fulfillmentVerifierEndpoint: z.ZodMiniString<string>;
162
+ quoteDeadlineSeconds: z.ZodMiniNumber<number>;
163
+ fulfillmentDeadlineSeconds: z.ZodMiniNumber<number>;
164
+ permit2: z.ZodMiniOptional<z.ZodMiniString<string>>;
165
+ svmSignatureClusterId: z.ZodMiniOptional<z.ZodMiniString<string>>;
166
+ svmSignatureDomainVersion: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
167
+ }, zod_v4_core.$strip>;
168
+ }, zod_v4_core.$strip>;
169
+ readonly credential: {
170
+ readonly payload: z.ZodMiniObject<{
171
+ paymentRequest: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
172
+ }, zod_v4_core.$strip>;
173
+ };
174
+ };
175
+ }, {}, undefined, {}, undefined>;
176
+ /**
177
+ * Validate a corridor's shape and per-source addresses. Run automatically by
178
+ * {@link buildChargeRequest}; call it directly to fail fast at merchant startup.
179
+ *
180
+ * @throws if the deadline budgets are non-positive or out of order, the markup is
181
+ * negative, there are no sources, or a source is missing a required field.
182
+ */
183
+ declare function validateCorridor(corridor: AtumEscrowCorridor): void;
184
+ /**
185
+ * Build the `charge` challenge request for a specific source option from a corridor. The
186
+ * merchant uses this to construct the 402 challenge; the source cap is
187
+ * `fulfillmentAmount + markup`, quoted in the source token. The corridor is validated
188
+ * first, so a misconfiguration fails here rather than at signing time.
189
+ *
190
+ * @param corridor - the corridor to serve.
191
+ * @param select - which configured source to fund from, by `(network, asset)`.
192
+ * @param fulfillmentAmount - exact amount the merchant receives, atomic units of the
193
+ * destination token. Set per charge so one registration serves any price.
194
+ * @throws if no source option matches `select`, or the corridor is invalid.
195
+ */
196
+ declare function buildChargeRequest(corridor: AtumEscrowCorridor, select: {
197
+ network: string;
198
+ asset: string;
199
+ }, fulfillmentAmount: string): ChargeRequest;
200
+ /** The minimal defaults source `corridorFromDefaults` needs; satisfied by the gateway client. */
201
+ interface ChainDefaultsSource {
202
+ fetchChainDefaults(chainId: string): Promise<ChainDefaults>;
203
+ }
204
+ /**
205
+ * Build a corridor by fetching the escrow/role/proxy addresses from the payment gateway's
206
+ * `/defaults` endpoint, so the merchant does not hand-author protocol addresses. Fetches
207
+ * the destination chain's fulfillment proxy and each source chain's escrow, reserver,
208
+ * releaser, verifier endpoint (and Solana domain fields) in parallel.
209
+ *
210
+ * @param defaults - a defaults source (e.g. a `PaymentGatewayClient`).
211
+ * @param params - the destination receive-side, the source chains and their accepted
212
+ * token `assets`, the markup, and the deadline budgets. One entry per source chain;
213
+ * list several tokens in `assets` to accept more than one on that chain.
214
+ */
215
+ declare function corridorFromDefaults(defaults: ChainDefaultsSource, params: {
216
+ destination: {
217
+ network: string;
218
+ asset: string;
219
+ account: string;
220
+ };
221
+ sources: Array<{
222
+ network: string;
223
+ assets: string[];
224
+ }>;
225
+ markupBps: number;
226
+ quoteDeadlineSeconds: number;
227
+ fulfillmentDeadlineSeconds: number;
228
+ }): Promise<AtumEscrowCorridor>;
229
+
230
+ export { type AtumEscrowCorridor, type AtumEscrowReceipt, type AtumEscrowServerConfig, type AtumEscrowSource, type ChainDefaultsSource, ChargeRequest, type FulfillmentConfirmation, PaymentRequest, type PaymentSubmitter, buildChargeRequest, corridorFromDefaults, registerServer, validateCorridor };
package/dist/server.js ADDED
@@ -0,0 +1,25 @@
1
+ import { createRequire as __atumCreateRequire } from 'module'; const require = __atumCreateRequire(import.meta.url);
2
+ import {
3
+ buildChargeRequest,
4
+ corridorFromDefaults,
5
+ registerServer,
6
+ validateCorridor
7
+ } from "./chunk-XDYCJ36Z.js";
8
+ import {
9
+ ChargeRequestSchema,
10
+ CredentialPayloadSchema,
11
+ INTENT,
12
+ METHOD_NAME,
13
+ atumEscrowChargeMethod
14
+ } from "./chunk-WWSNMK7N.js";
15
+ export {
16
+ ChargeRequestSchema,
17
+ CredentialPayloadSchema,
18
+ INTENT,
19
+ METHOD_NAME,
20
+ atumEscrowChargeMethod,
21
+ buildChargeRequest,
22
+ corridorFromDefaults,
23
+ registerServer,
24
+ validateCorridor
25
+ };
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "@atumlabs/mppx-atum-escrow",
3
+ "version": "0.1.0",
4
+ "description": "Atum cross-chain escrow payment method for the Machine Payments Protocol (MPP).",
5
+ "author": "Atum Labs, Inc.",
6
+ "license": "UNLICENSED",
7
+ "homepage": "https://github.com/Atum-Labs/protocol/tree/main/mppx-atum-escrow#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Atum-Labs/protocol.git",
11
+ "directory": "mppx-atum-escrow"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/Atum-Labs/protocol/issues"
15
+ },
16
+ "keywords": [
17
+ "atum",
18
+ "mpp",
19
+ "machine-payments-protocol",
20
+ "payment-method",
21
+ "cross-chain",
22
+ "stablecoin",
23
+ "escrow",
24
+ "permit2"
25
+ ],
26
+ "type": "module",
27
+ "engines": {
28
+ "node": ">=18"
29
+ },
30
+ "main": "dist/index.js",
31
+ "types": "dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "default": "./dist/index.js"
36
+ },
37
+ "./client": {
38
+ "types": "./dist/client.d.ts",
39
+ "default": "./dist/client.js"
40
+ },
41
+ "./server": {
42
+ "types": "./dist/server.d.ts",
43
+ "default": "./dist/server.js"
44
+ }
45
+ },
46
+ "files": [
47
+ "dist/**/*",
48
+ "README.md"
49
+ ],
50
+ "scripts": {
51
+ "prebuild:deps": "node -e \"const {existsSync}=require('fs');for(const p of ['../contracts/evm/escrow-encoding/typescript/tsconfig.json','../contracts/tvm/escrow-encoding/typescript/tsconfig.json','../contracts/svm/escrow-encoding/typescript/tsconfig.json','../schemas/apis/atum-escrow/v1/bindings/typescript/tsconfig.json','../schemas/apis/fulfillment-confirmation/v1/bindings/typescript/tsconfig.json']){if(!existsSync(p)){console.error('bundled sibling not found at '+p+'. Is this checked out inside the protocol monorepo?');process.exit(1)}}if(!existsSync('../payment-gateway-client/dist/index.js')){console.error('@atum-labs/payment-gateway-client is not built. Run its build first (pnpm --filter @atum-labs/payment-gateway-client build).');process.exit(1)}\"",
52
+ "build:deps": "tsc -p ../contracts/evm/escrow-encoding/typescript/tsconfig.json && tsc -p ../contracts/tvm/escrow-encoding/typescript/tsconfig.json && tsc -p ../contracts/svm/escrow-encoding/typescript/tsconfig.json && tsc -p ../schemas/apis/atum-escrow/v1/bindings/typescript/tsconfig.json && tsc -p ../schemas/apis/fulfillment-confirmation/v1/bindings/typescript/tsconfig.json",
53
+ "build": "pnpm run build:deps && tsup",
54
+ "typecheck": "pnpm run build:deps && tsc --noEmit",
55
+ "pretest": "pnpm run build:deps",
56
+ "test": "vitest run",
57
+ "clean": "rm -rf dist ../contracts/evm/escrow-encoding/typescript/dist ../contracts/tvm/escrow-encoding/typescript/dist ../contracts/svm/escrow-encoding/typescript/dist ../schemas/apis/atum-escrow/v1/bindings/typescript/dist ../schemas/apis/fulfillment-confirmation/v1/bindings/typescript/dist",
58
+ "check:publishable": "node scripts/check-publishable.mjs",
59
+ "prepare": "pnpm run build",
60
+ "prepublishOnly": "pnpm run build && pnpm run check:publishable"
61
+ },
62
+ "dependencies": {
63
+ "bs58": "^6.0.0",
64
+ "ethers": "^6.13.0",
65
+ "tweetnacl": "^1.0.3"
66
+ },
67
+ "peerDependencies": {
68
+ "mppx": ">=0.8.12 <0.9.0",
69
+ "zod": "^4.4.3"
70
+ },
71
+ "devDependencies": {
72
+ "@atum-labs/atum-escrow": "workspace:*",
73
+ "@atum-labs/evm-escrow-encoding": "workspace:*",
74
+ "@atum-labs/fulfillment-confirmation": "workspace:*",
75
+ "@atum-labs/payment-gateway-client": "workspace:*",
76
+ "@atum-labs/schema-declarations": "workspace:*",
77
+ "@atum-labs/solana-escrow-encoding": "workspace:*",
78
+ "@atum-labs/tvm-escrow-encoding": "workspace:*",
79
+ "@types/node": "^20.0.0",
80
+ "mppx": "^0.8.12",
81
+ "tsup": "^8.5.1",
82
+ "typescript": "^5.6.3",
83
+ "vitest": "^2.1.9",
84
+ "zod": "^4.4.3"
85
+ }
86
+ }