@devlab.group/agent-commerce 2.0.0 → 2.2.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 +137 -56
- package/dist/ap2.d.ts +2 -2
- package/dist/ap2.js +4 -3
- package/dist/ap2.js.map +1 -1
- package/dist/{authorization-BpbWGGrf.d.ts → authorization-CMkIuAkO.d.ts} +1 -1
- package/dist/chunk-2CJNA7MS.js +8 -0
- package/dist/chunk-2CJNA7MS.js.map +1 -0
- package/dist/{chunk-CKJRITWY.js → chunk-5ZYXBCDX.js} +3 -3
- package/dist/{chunk-CKJRITWY.js.map → chunk-5ZYXBCDX.js.map} +1 -1
- package/dist/{chunk-3LUJHVKX.js → chunk-6Z2H53CG.js} +5 -4
- package/dist/chunk-6Z2H53CG.js.map +1 -0
- package/dist/{chunk-53WXXIPR.js → chunk-7ZMMXZ4G.js} +6 -10
- package/dist/chunk-7ZMMXZ4G.js.map +1 -0
- package/dist/{chunk-HOZA3IWP.js → chunk-ES3V6ECS.js} +16 -6
- package/dist/chunk-ES3V6ECS.js.map +1 -0
- package/dist/chunk-HNRDZLSN.js +1398 -0
- package/dist/chunk-HNRDZLSN.js.map +1 -0
- package/dist/{chunk-SYEGCNJZ.js → chunk-IEW7NSP2.js} +23 -5
- package/dist/chunk-IEW7NSP2.js.map +1 -0
- package/dist/chunk-KA2AX5FH.js +44 -0
- package/dist/chunk-KA2AX5FH.js.map +1 -0
- package/dist/chunk-Y4RE3XYF.js +581 -0
- package/dist/chunk-Y4RE3XYF.js.map +1 -0
- package/dist/cli/ap2-MBMQHFX4.js +678 -0
- package/dist/cli/ap2-MBMQHFX4.js.map +1 -0
- package/dist/cli/chunk-2ZZOGI5I.js +1352 -0
- package/dist/cli/chunk-2ZZOGI5I.js.map +1 -0
- package/dist/cli/chunk-3EQBCFZY.js +53 -0
- package/dist/cli/chunk-3EQBCFZY.js.map +1 -0
- package/dist/cli/chunk-3M6U7ILB.js +8 -0
- package/dist/cli/chunk-3M6U7ILB.js.map +1 -0
- package/dist/cli/chunk-3MGAJ5FX.js +70 -0
- package/dist/cli/chunk-3MGAJ5FX.js.map +1 -0
- package/dist/cli/chunk-5K4XEAZV.js +113 -0
- package/dist/cli/chunk-5K4XEAZV.js.map +1 -0
- package/dist/cli/chunk-7JNYFUT3.js +256 -0
- package/dist/cli/chunk-7JNYFUT3.js.map +1 -0
- package/dist/cli/chunk-AA3FIEAR.js +27 -0
- package/dist/cli/chunk-AA3FIEAR.js.map +1 -0
- package/dist/cli/chunk-FHCFR2GS.js +17 -0
- package/dist/cli/chunk-FHCFR2GS.js.map +1 -0
- package/dist/cli/chunk-FRMLWGSS.js +8 -0
- package/dist/cli/chunk-FRMLWGSS.js.map +1 -0
- package/dist/cli/chunk-KLX2YZDG.js +1400 -0
- package/dist/cli/chunk-KLX2YZDG.js.map +1 -0
- package/dist/cli/chunk-NSPPEF5M.js +334 -0
- package/dist/cli/chunk-NSPPEF5M.js.map +1 -0
- package/dist/cli/chunk-OSTCU6ZK.js +44 -0
- package/dist/cli/chunk-OSTCU6ZK.js.map +1 -0
- package/dist/cli/chunk-QQ3WY5L3.js +271 -0
- package/dist/cli/chunk-QQ3WY5L3.js.map +1 -0
- package/dist/cli/chunk-RWVPYAKC.js +1742 -0
- package/dist/cli/chunk-RWVPYAKC.js.map +1 -0
- package/dist/cli/chunk-SPAYKVUP.js +118 -0
- package/dist/cli/chunk-SPAYKVUP.js.map +1 -0
- package/dist/cli/chunk-SS3QFF5N.js +614 -0
- package/dist/cli/chunk-SS3QFF5N.js.map +1 -0
- package/dist/cli/chunk-TPC4EJLT.js +11 -0
- package/dist/cli/chunk-TPC4EJLT.js.map +1 -0
- package/dist/cli/config-4IBGVFSP.js +11 -0
- package/dist/cli/config-4IBGVFSP.js.map +1 -0
- package/dist/cli/index.js +822 -3392
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/mcp-CNWQ2MOE.js +559 -0
- package/dist/cli/mcp-CNWQ2MOE.js.map +1 -0
- package/dist/cli/near-5AY3HWYF.js +58 -0
- package/dist/cli/near-5AY3HWYF.js.map +1 -0
- package/dist/cli/provider-4BQDH56Y.js +396 -0
- package/dist/cli/provider-4BQDH56Y.js.map +1 -0
- package/dist/cli/run-5MB2D45X.js +7286 -0
- package/dist/cli/run-5MB2D45X.js.map +1 -0
- package/dist/cli/svm-3MMYFPC7.js +33 -0
- package/dist/cli/svm-3MMYFPC7.js.map +1 -0
- package/dist/cli/x402-NKR3WQDQ.js +96 -0
- package/dist/cli/x402-NKR3WQDQ.js.map +1 -0
- package/dist/{constants-BSBRlKRR.d.ts → constants-nackLItD.d.ts} +2 -1
- package/dist/index.d.ts +61 -40
- package/dist/index.js +2642 -2205
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +3 -3
- package/dist/mcp.js +15 -20
- package/dist/mcp.js.map +1 -1
- package/dist/mpp.d.ts +12 -5
- package/dist/mpp.js +69 -65
- package/dist/mpp.js.map +1 -1
- package/dist/near-D6C42VPE.js +58 -0
- package/dist/near-D6C42VPE.js.map +1 -0
- package/dist/networks-olfflCI_.d.ts +38 -0
- package/dist/{protocol-adapter-DonxfAwa.d.ts → protocol-adapter-CfxU8Z2T.d.ts} +2 -2
- package/dist/{runtime-CiYbgGpi.d.ts → runtime-7vLNYvmU.d.ts} +25 -3
- package/dist/svm-QEUAUNPQ.js +33 -0
- package/dist/svm-QEUAUNPQ.js.map +1 -0
- package/dist/x402.d.ts +76 -64
- package/dist/x402.js +13 -4
- package/dist/x402.js.map +1 -1
- package/package.json +22 -2
- package/dist/chunk-3LUJHVKX.js.map +0 -1
- package/dist/chunk-53WXXIPR.js.map +0 -1
- package/dist/chunk-HOZA3IWP.js.map +0 -1
- package/dist/chunk-RKBGCPCK.js +0 -733
- package/dist/chunk-RKBGCPCK.js.map +0 -1
- package/dist/chunk-SYEGCNJZ.js.map +0 -1
- package/dist/chunk-TWRUNWDR.js +0 -265
- package/dist/chunk-TWRUNWDR.js.map +0 -1
- package/dist/{payment-flow-DCS882tR.d.ts → guardrails-CX_jYXvZ.d.ts} +8 -8
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { computeSvmReplayKey } from './chunk-OSTCU6ZK.js';
|
|
2
|
+
import { isRecord } from './chunk-3M6U7ILB.js';
|
|
3
|
+
import { getAddressEncoder, getProgramDerivedAddress, address } from '@solana/kit';
|
|
4
|
+
import { transactionMessageHash, decodeTransactionFromPayload } from '@x402/svm';
|
|
5
|
+
|
|
6
|
+
var MAX_TRANSACTION_BASE64 = 1644;
|
|
7
|
+
var ASSOCIATED_TOKEN_PROGRAM = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
8
|
+
async function associatedTokenAccount(owner, mint, tokenProgram) {
|
|
9
|
+
const encoder = getAddressEncoder();
|
|
10
|
+
const [account] = await getProgramDerivedAddress({
|
|
11
|
+
programAddress: address(ASSOCIATED_TOKEN_PROGRAM),
|
|
12
|
+
seeds: [owner, tokenProgram, mint].map((key) => encoder.encode(address(key)))
|
|
13
|
+
});
|
|
14
|
+
return account;
|
|
15
|
+
}
|
|
16
|
+
function svmReplayKey(payload, network) {
|
|
17
|
+
if (!isRecord(payload)) return "invalid_exact_svm_payload_transaction";
|
|
18
|
+
const transaction = payload["transaction"];
|
|
19
|
+
if (typeof transaction !== "string" || transaction.length > MAX_TRANSACTION_BASE64) {
|
|
20
|
+
return "invalid_exact_svm_payload_transaction";
|
|
21
|
+
}
|
|
22
|
+
let messageHash;
|
|
23
|
+
try {
|
|
24
|
+
messageHash = transactionMessageHash(decodeTransactionFromPayload({ transaction }));
|
|
25
|
+
} catch {
|
|
26
|
+
return "invalid_exact_svm_payload_transaction_could_not_be_decoded";
|
|
27
|
+
}
|
|
28
|
+
return { replayKey: computeSvmReplayKey({ network, messageHash }) };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { associatedTokenAccount, svmReplayKey };
|
|
32
|
+
//# sourceMappingURL=svm-3MMYFPC7.js.map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payload inspection: bounded decoding and the replay identity.\n * The provider loads this module only for a Solana offer, so an EVM-only\n * deployment never imports `@x402/svm` or `@solana/kit`.\n *\n * The facilitator checks the transaction itself: the fee payer, signatures,\n * instruction layout, mint, recipient token account and amount, and a\n * simulation. Its smart-wallet path accepts layouts the gateway could not\n * parse, so the gateway does not read the transfer.\n */\nimport { address, getAddressEncoder, getProgramDerivedAddress } from '@solana/kit';\nimport { decodeTransactionFromPayload, transactionMessageHash } from '@x402/svm';\nimport { isRecord } from '../../core/is-record';\nimport { computeSvmReplayKey } from './replay-key';\n\n// A Solana transaction fits a 1232-byte packet, which is 1644 base64 characters\nconst MAX_TRANSACTION_BASE64 = 1644;\n\nconst ASSOCIATED_TOKEN_PROGRAM = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';\n\n/**\n * The associated token account of `owner` for `mint`, where the SDK client\n * sends a Solana `exact` payment. Its transaction cannot create the account.\n */\nexport async function associatedTokenAccount(\n owner: string,\n mint: string,\n tokenProgram: string,\n): Promise<string> {\n const encoder = getAddressEncoder();\n const [account] = await getProgramDerivedAddress({\n programAddress: address(ASSOCIATED_TOKEN_PROGRAM),\n seeds: [owner, tokenProgram, mint].map((key) => encoder.encode(address(key))),\n });\n return account;\n}\n\n/**\n * Returns the Solana `exact` replay key, or an SDK refusal reason for a\n * missing, oversized or undecodable transaction.\n */\nexport function svmReplayKey(payload: unknown, network: string): { replayKey: string } | string {\n if (!isRecord(payload)) return 'invalid_exact_svm_payload_transaction';\n const transaction = payload['transaction'];\n if (typeof transaction !== 'string' || transaction.length > MAX_TRANSACTION_BASE64) {\n return 'invalid_exact_svm_payload_transaction';\n }\n let messageHash: string;\n try {\n messageHash = transactionMessageHash(decodeTransactionFromPayload({ transaction }));\n } catch {\n return 'invalid_exact_svm_payload_transaction_could_not_be_decoded';\n }\n return { replayKey: computeSvmReplayKey({ network, messageHash }) };\n}\n"]}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { chainIdFromCaip2 } from './chunk-KLX2YZDG.js';
|
|
2
|
+
export { createX402PaymentProvider } from './chunk-KLX2YZDG.js';
|
|
3
|
+
import './chunk-NSPPEF5M.js';
|
|
4
|
+
export { SUPPORTED_NETWORK_IDS } from './chunk-7JNYFUT3.js';
|
|
5
|
+
import './chunk-OSTCU6ZK.js';
|
|
6
|
+
import './chunk-FRMLWGSS.js';
|
|
7
|
+
import { CommerceError } from './chunk-QQ3WY5L3.js';
|
|
8
|
+
import './chunk-3M6U7ILB.js';
|
|
9
|
+
import { PaymentRequirementsV2Schema } from '@x402/core/schemas';
|
|
10
|
+
import { getAddress, toHex } from 'viem';
|
|
11
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
12
|
+
|
|
13
|
+
var X402_VERSION = 2;
|
|
14
|
+
var TRANSFER_WITH_AUTHORIZATION_TYPES = {
|
|
15
|
+
TransferWithAuthorization: [
|
|
16
|
+
{ name: "from", type: "address" },
|
|
17
|
+
{ name: "to", type: "address" },
|
|
18
|
+
{ name: "value", type: "uint256" },
|
|
19
|
+
{ name: "validAfter", type: "uint256" },
|
|
20
|
+
{ name: "validBefore", type: "uint256" },
|
|
21
|
+
{ name: "nonce", type: "bytes32" }
|
|
22
|
+
]
|
|
23
|
+
};
|
|
24
|
+
async function createPaymentProof(options) {
|
|
25
|
+
const requirements = PaymentRequirementsV2Schema.parse(options.accepts);
|
|
26
|
+
const method = requirements.extra?.["assetTransferMethod"];
|
|
27
|
+
if (method !== void 0 && method !== "eip3009") {
|
|
28
|
+
throw new CommerceError(
|
|
29
|
+
"INPUT_INVALID",
|
|
30
|
+
`createPaymentProof: signs EIP-3009 only, and this offer uses "${String(method)}"; sign it with the SDK's x402Client`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (!requirements.extra || typeof requirements.extra["name"] !== "string" || typeof requirements.extra["version"] !== "string") {
|
|
34
|
+
throw new CommerceError(
|
|
35
|
+
"INPUT_INVALID",
|
|
36
|
+
"createPaymentProof: payment requirement is missing extra.name/extra.version, so the EIP-712 domain cannot be built"
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
const chainId = chainIdFromCaip2(requirements.network);
|
|
40
|
+
if (chainId === void 0) {
|
|
41
|
+
throw new CommerceError(
|
|
42
|
+
"INPUT_INVALID",
|
|
43
|
+
`createPaymentProof: network "${requirements.network}" is not a CAIP-2 eip155 identifier, so there is no chain id to sign against`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
const account = privateKeyToAccount(options.buyerPrivateKey);
|
|
47
|
+
const nonce = options.overrides?.nonce ?? randomNonce();
|
|
48
|
+
const nowSeconds = Math.floor(Date.now() / 1e3);
|
|
49
|
+
const validAfter = options.overrides?.validAfter ?? 0;
|
|
50
|
+
const validBefore = options.overrides?.validBefore ?? nowSeconds + requirements.maxTimeoutSeconds;
|
|
51
|
+
const to = getAddress(options.overrides?.payTo ?? requirements.payTo);
|
|
52
|
+
const value = BigInt(options.overrides?.value ?? requirements.amount);
|
|
53
|
+
const signature = await account.signTypedData({
|
|
54
|
+
domain: {
|
|
55
|
+
name: requirements.extra["name"],
|
|
56
|
+
version: requirements.extra["version"],
|
|
57
|
+
chainId,
|
|
58
|
+
verifyingContract: getAddress(requirements.asset)
|
|
59
|
+
},
|
|
60
|
+
types: TRANSFER_WITH_AUTHORIZATION_TYPES,
|
|
61
|
+
primaryType: "TransferWithAuthorization",
|
|
62
|
+
message: {
|
|
63
|
+
from: account.address,
|
|
64
|
+
to,
|
|
65
|
+
value,
|
|
66
|
+
validAfter: BigInt(validAfter),
|
|
67
|
+
validBefore: BigInt(validBefore),
|
|
68
|
+
nonce
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
const payload = {
|
|
72
|
+
x402Version: X402_VERSION,
|
|
73
|
+
accepted: requirements,
|
|
74
|
+
payload: {
|
|
75
|
+
signature,
|
|
76
|
+
authorization: {
|
|
77
|
+
from: account.address,
|
|
78
|
+
to,
|
|
79
|
+
value: value.toString(),
|
|
80
|
+
validAfter: validAfter.toString(),
|
|
81
|
+
validBefore: validBefore.toString(),
|
|
82
|
+
nonce
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return Buffer.from(JSON.stringify(payload), "utf8").toString("base64");
|
|
87
|
+
}
|
|
88
|
+
function randomNonce() {
|
|
89
|
+
const bytes = new Uint8Array(32);
|
|
90
|
+
crypto.getRandomValues(bytes);
|
|
91
|
+
return toHex(bytes);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { createPaymentProof };
|
|
95
|
+
//# sourceMappingURL=x402-NKR3WQDQ.js.map
|
|
96
|
+
//# sourceMappingURL=x402-NKR3WQDQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/payments/x402/client.ts"],"names":[],"mappings":";;;;;;;;;;;;AAkCA,IAAM,YAAA,GAAe,CAAA;AAErB,IAAM,iCAAA,GAAoC;AAAA,EACxC,yBAAA,EAA2B;AAAA,IACzB,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAU;AAAA,IAChC,EAAE,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,SAAA,EAAU;AAAA,IAC9B,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA,EAAU;AAAA,IACjC,EAAE,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,SAAA,EAAU;AAAA,IACtC,EAAE,IAAA,EAAM,aAAA,EAAe,IAAA,EAAM,SAAA,EAAU;AAAA,IACvC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA;AAAU;AAErC,CAAA;AAGA,eAAsB,mBAAmB,OAAA,EAAqD;AAC5F,EAAA,MAAM,YAAA,GAAe,2BAAA,CAA4B,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA;AACtE,EAAA,MAAM,MAAA,GAAS,YAAA,CAAa,KAAA,GAAQ,qBAAqB,CAAA;AACzD,EAAA,IAAI,MAAA,K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B","file":"x402-NKR3WQDQ.js","sourcesContent":["/**\n * Client-side payment helper: builds and EIP-712-signs an x402 v2 `exact`/EVM\n * authorization on the buyer's side. The demo buyer agent and the test suites\n * use it, and the `/x402` entry exports it. The gateway never calls it and\n * never holds a buyer key.\n *\n * It signs directly rather than through the SDK's `x402Client` because of\n * `overrides`: negative tests need deliberately wrong authorizations that a\n * conforming client will not produce. The x402 settlement E2E suite also\n * settles a payment built by `x402Client` itself to cover interoperability.\n */\n\nimport { PaymentRequirementsV2Schema } from '@x402/core/schemas';\nimport type { PaymentPayload, PaymentRequirements } from '@x402/core/types';\nimport { getAddress, toHex } from 'viem';\nimport { privateKeyToAccount } from 'viem/accounts';\nimport { CommerceError } from '../../core';\nimport { chainIdFromCaip2 } from './chain';\n\nexport interface CreatePaymentProofOptions {\n /** The buyer's private key. It signs locally and is never sent anywhere */\n readonly buyerPrivateKey: `0x${string}`;\n /** One entry from PaymentRequiredEnvelope.payment.accepts, verbatim */\n readonly accepts: Readonly<Record<string, unknown>>;\n /** For negative tests only: a wrong amount, recipient, nonce or validity window */\n readonly overrides?: {\n readonly value?: string;\n readonly payTo?: string;\n readonly nonce?: `0x${string}`;\n readonly validBefore?: number;\n readonly validAfter?: number;\n };\n}\n\nconst X402_VERSION = 2;\n\nconst TRANSFER_WITH_AUTHORIZATION_TYPES = {\n TransferWithAuthorization: [\n { name: 'from', type: 'address' },\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'validAfter', type: 'uint256' },\n { name: 'validBefore', type: 'uint256' },\n { name: 'nonce', type: 'bytes32' },\n ],\n} as const;\n\n/** Returns the base64 `PAYMENT-SIGNATURE` value to send back to the gateway */\nexport async function createPaymentProof(options: CreatePaymentProofOptions): Promise<string> {\n const requirements = PaymentRequirementsV2Schema.parse(options.accepts);\n const method = requirements.extra?.['assetTransferMethod'];\n if (method !== undefined && method !== 'eip3009') {\n throw new CommerceError(\n 'INPUT_INVALID',\n `createPaymentProof: signs EIP-3009 only, and this offer uses \"${String(method)}\"; sign it with the SDK's x402Client`,\n );\n }\n if (\n !requirements.extra ||\n typeof requirements.extra['name'] !== 'string' ||\n typeof requirements.extra['version'] !== 'string'\n ) {\n throw new CommerceError(\n 'INPUT_INVALID',\n 'createPaymentProof: payment requirement is missing extra.name/extra.version, so the EIP-712 domain cannot be built',\n );\n }\n\n const chainId = chainIdFromCaip2(requirements.network);\n if (chainId === undefined) {\n throw new CommerceError(\n 'INPUT_INVALID',\n `createPaymentProof: network \"${requirements.network}\" is not a CAIP-2 eip155 identifier, so there is no chain id to sign against`,\n );\n }\n\n const account = privateKeyToAccount(options.buyerPrivateKey);\n\n const nonce = options.overrides?.nonce ?? randomNonce();\n const nowSeconds = Math.floor(Date.now() / 1000);\n // 0, as in the SDK's own v2 client: nothing here wants the authorization\n // delayed\n const validAfter = options.overrides?.validAfter ?? 0;\n const validBefore = options.overrides?.validBefore ?? nowSeconds + requirements.maxTimeoutSeconds;\n const to = getAddress((options.overrides?.payTo ?? requirements.payTo) as `0x${string}`);\n const value = BigInt(options.overrides?.value ?? requirements.amount);\n\n const signature = await account.signTypedData({\n domain: {\n name: requirements.extra['name'],\n version: requirements.extra['version'],\n chainId,\n verifyingContract: getAddress(requirements.asset as `0x${string}`),\n },\n types: TRANSFER_WITH_AUTHORIZATION_TYPES,\n primaryType: 'TransferWithAuthorization',\n message: {\n from: account.address,\n to,\n value,\n validAfter: BigInt(validAfter),\n validBefore: BigInt(validBefore),\n nonce,\n },\n });\n\n // v2 echoes the chosen requirement back as `accepted` so a stateless\n // facilitator knows which offer was taken. The gateway verifies against its\n // own copy.\n const payload: PaymentPayload = {\n x402Version: X402_VERSION,\n accepted: requirements as PaymentRequirements,\n payload: {\n signature,\n authorization: {\n from: account.address,\n to,\n value: value.toString(),\n validAfter: validAfter.toString(),\n validBefore: validBefore.toString(),\n nonce,\n },\n },\n };\n\n return Buffer.from(JSON.stringify(payload), 'utf8').toString('base64');\n}\n\nfunction randomNonce(): `0x${string}` {\n const bytes = new Uint8Array(32);\n crypto.getRandomValues(bytes);\n return toHex(bytes);\n}\n"]}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Importing this metadata does not load `mppx`.
|
|
9
9
|
*/
|
|
10
|
+
|
|
10
11
|
/** Upstream specification repository the pinned drafts were read from */
|
|
11
12
|
declare const MPP_SPEC_REPOSITORY = "https://github.com/tempoxyz/mpp-specs";
|
|
12
13
|
/**
|
|
@@ -40,7 +41,7 @@ declare const MPP_PROFILE: {
|
|
|
40
41
|
readonly assetDecimals: 6;
|
|
41
42
|
};
|
|
42
43
|
/** Supported CAIP-2 networks; gateway config applies the x402 mainnet guardrails */
|
|
43
|
-
declare const MPP_NETWORKS: readonly ["eip155:84532", "eip155:8453"];
|
|
44
|
+
declare const MPP_NETWORKS: readonly ["eip155:31337", "eip155:84532", "eip155:8453"];
|
|
44
45
|
type MppNetwork = (typeof MPP_NETWORKS)[number];
|
|
45
46
|
/** Compact descriptor value naming the core draft, intent and method */
|
|
46
47
|
declare const MPP_SUPPORTED_SPEC: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { f as Ap2AuthorizationConfig } from './types-CVw6Sf46.js';
|
|
2
|
-
import { I as IsoTimestamp, D as DecimalAmount, P as PaymentMethodName, a as CommerceResource, b as PaymentSubmission, B as BackendHandler, A as AdapterDescriptor, c as AdapterHealth, R as ResourceRegistry, d as PaymentProvider, L as Logger, C as Clock, e as IdGenerator } from './runtime-
|
|
3
|
-
export { f as
|
|
4
|
-
import { M as MppNetwork } from './constants-
|
|
5
|
-
import { X as X402PaymentFlow, a as X402FacilitatorConfig } from './
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import { I as IsoTimestamp, D as DecimalAmount, P as PaymentMethodName, a as CommerceResource, b as PaymentSubmission, B as BackendHandler, A as AdapterDescriptor, c as AdapterHealth, R as ResourceRegistry, d as PaymentProvider, L as Logger, C as Clock, e as IdGenerator } from './runtime-7vLNYvmU.js';
|
|
3
|
+
export { f as AdapterHealthComponent, g as AuthorizationMethodName, h as BackendMethod, i as DEFAULT_BACKEND_TIMEOUT_MS, J as JsonSchema, N as NOOP_LOGGER, j as PAYMENT_METHOD_NAMES, k as PROTOCOL_NAMES, l as PaymentChallenge, m as PaymentContext, n as PaymentRequirement, o as PaymentResult, p as PaymentSettlementContext, q as PaymentVerificationContext, r as Pricing, s as ProtocolName, t as systemClock } from './runtime-7vLNYvmU.js';
|
|
4
|
+
import { M as MppNetwork } from './constants-nackLItD.js';
|
|
5
|
+
import { X as X402PaymentFlow, a as X402FacilitatorConfig } from './guardrails-CX_jYXvZ.js';
|
|
6
|
+
import { C as CustomNetworks } from './networks-olfflCI_.js';
|
|
7
|
+
import { a as AuthorizationRequirement, b as AuthorizationSubmission, A as AuthorizationProvider } from './authorization-CMkIuAkO.js';
|
|
8
|
+
export { c as AuthorizationFinalizeContext, d as AuthorizationRecord, e as AuthorizationVerification, f as AuthorizationVerificationContext } from './authorization-CMkIuAkO.js';
|
|
9
|
+
import { D as DeliveredOutcome, P as PaymentRequiredOutcome, C as CommerceEvent, a as PaymentAttempt, b as CommerceReceipt, E as ExecutionPipeline, c as ProtocolAdapter, H as HttpProtocolAdapter, A as AdapterHttpRoute, d as ProtocolAdapterContext } from './protocol-adapter-CfxU8Z2T.js';
|
|
10
|
+
export { e as COMMERCE_EVENT_TYPES, f as CanonicalRequest, g as CommerceEventType, h as EventSink, i as ExecutionOutcome, j as isHttpProtocolAdapter } from './protocol-adapter-CfxU8Z2T.js';
|
|
10
11
|
import { FastifyInstance } from 'fastify';
|
|
11
12
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
12
13
|
|
|
@@ -152,8 +153,14 @@ interface PaymentRequiredEnvelope {
|
|
|
152
153
|
readonly version: string;
|
|
153
154
|
readonly amount: DecimalAmount;
|
|
154
155
|
readonly currency: string;
|
|
155
|
-
|
|
156
|
+
/**
|
|
157
|
+
* @deprecated Read each offer's `payTo` in `accepts`. Absent when the
|
|
158
|
+
* challenge offers several destinations.
|
|
159
|
+
*/
|
|
160
|
+
readonly destination?: string;
|
|
161
|
+
/** @deprecated Read each offer's `network` in `accepts` */
|
|
156
162
|
readonly network?: string;
|
|
163
|
+
/** @deprecated Read each offer's `asset` in `accepts` */
|
|
157
164
|
readonly asset?: string;
|
|
158
165
|
readonly expiresAt?: IsoTimestamp;
|
|
159
166
|
/** Provider-native requirement objects, passed through verbatim */
|
|
@@ -305,6 +312,12 @@ interface PaymentAttemptReservation {
|
|
|
305
312
|
readonly currency: string;
|
|
306
313
|
readonly payer?: string;
|
|
307
314
|
readonly payee?: string;
|
|
315
|
+
/**
|
|
316
|
+
* Reclaim this `replayKey` if the same `provider` rejected it, which
|
|
317
|
+
* settled nothing. Set only for rails whose authorizations remain reusable
|
|
318
|
+
* until settled.
|
|
319
|
+
*/
|
|
320
|
+
readonly reclaimRejected?: boolean;
|
|
308
321
|
}
|
|
309
322
|
interface PaymentAttemptUpdate {
|
|
310
323
|
readonly replayKey: string;
|
|
@@ -325,6 +338,10 @@ interface ReceiptStore {
|
|
|
325
338
|
* `replayKey` is already reserved, throws `CommerceError('PAYMENT_REPLAYED')`
|
|
326
339
|
* with the existing attempt's `PaymentAttempt.status` in
|
|
327
340
|
* `details.attemptStatus` when available.
|
|
341
|
+
*
|
|
342
|
+
* With `reclaimRejected`, replace the same provider's `rejected` attempt,
|
|
343
|
+
* which settled nothing. Only one concurrent claim can replace it with the
|
|
344
|
+
* new reservation.
|
|
328
345
|
*/
|
|
329
346
|
reservePaymentAttempt(reservation: PaymentAttemptReservation): Promise<PaymentAttempt>;
|
|
330
347
|
updatePaymentAttempt(update: PaymentAttemptUpdate): Promise<void>;
|
|
@@ -381,25 +398,6 @@ declare const ACP_WELL_KNOWN_PATH = "/.well-known/acp.json";
|
|
|
381
398
|
declare const ACP_CHECKOUT_OPERATIONS: readonly ["createCheckoutSession", "updateCheckoutSession", "getCheckoutSession", "completeCheckoutSession", "cancelCheckoutSession"];
|
|
382
399
|
type AcpCheckoutOperation = (typeof ACP_CHECKOUT_OPERATIONS)[number];
|
|
383
400
|
|
|
384
|
-
/**
|
|
385
|
-
* `config.yaml` schema, validation and normalization into the canonical
|
|
386
|
-
* `GatewayConfig` (docs/contracts.md).
|
|
387
|
-
*
|
|
388
|
-
* 1. Zod validates shape: types, required fields, unknown keys. Numeric and
|
|
389
|
-
* boolean leaves accept their native type or a string, because env
|
|
390
|
-
* substitution produces strings. Zod transforms interact badly with
|
|
391
|
-
* `.strict()` inference, so coercion happens in plain TypeScript in step 2.
|
|
392
|
-
* 2. A business-rule pass coerces those leaves and checks what needs a
|
|
393
|
-
* specific message: cross-references, disabled protocols and payment
|
|
394
|
-
* methods, dynamic pricing, addresses, duplicate trust entries.
|
|
395
|
-
*
|
|
396
|
-
* Env substitution (`${VAR}` / `${VAR:-default}`) runs over the raw value
|
|
397
|
-
* before both steps, so numeric and boolean fields can be templated. The one
|
|
398
|
-
* exception is `version:`, checked before substitution: it decides whether this
|
|
399
|
-
* parser understands the document at all, so it cannot depend on the
|
|
400
|
-
* environment.
|
|
401
|
-
*/
|
|
402
|
-
|
|
403
401
|
/** Optional ACP discovery metadata. Absent fields are omitted from the document */
|
|
404
402
|
interface AcpDiscoveryConfig {
|
|
405
403
|
readonly documentationUrl?: string;
|
|
@@ -431,6 +429,20 @@ type AcpProtocolConfig = {
|
|
|
431
429
|
};
|
|
432
430
|
readonly discovery?: AcpDiscoveryConfig;
|
|
433
431
|
};
|
|
432
|
+
/** One resolved x402 option: where a payment settles and in which token */
|
|
433
|
+
interface X402OptionConfig {
|
|
434
|
+
readonly network: string;
|
|
435
|
+
/** This network's RPC: `payments.x402.networks.<id>.rpcUrl`, else `payments.x402.rpcUrl` */
|
|
436
|
+
readonly rpcUrl: string;
|
|
437
|
+
readonly asset: string;
|
|
438
|
+
/** EIP-712 domain of the token; always present for EIP-3009 */
|
|
439
|
+
readonly assetName?: string;
|
|
440
|
+
readonly assetVersion?: string;
|
|
441
|
+
readonly assetDecimals: number;
|
|
442
|
+
readonly payTo: string;
|
|
443
|
+
/** Absent for EIP-3009, the default */
|
|
444
|
+
readonly assetTransferMethod?: 'permit2';
|
|
445
|
+
}
|
|
434
446
|
interface GatewayConfig {
|
|
435
447
|
readonly version: 1;
|
|
436
448
|
readonly merchant: {
|
|
@@ -472,18 +484,35 @@ interface GatewayConfig {
|
|
|
472
484
|
readonly network: string;
|
|
473
485
|
readonly rpcUrl: string;
|
|
474
486
|
readonly asset: string;
|
|
475
|
-
|
|
476
|
-
readonly
|
|
487
|
+
/** Always present for EIP-3009; a Permit2 option may have none */
|
|
488
|
+
readonly assetName?: string;
|
|
489
|
+
readonly assetVersion?: string;
|
|
477
490
|
readonly assetDecimals: number;
|
|
478
491
|
readonly payTo: string;
|
|
492
|
+
/** Absent for EIP-3009, the default */
|
|
493
|
+
readonly assetTransferMethod?: 'permit2';
|
|
479
494
|
readonly maxTimeoutSeconds: number;
|
|
480
495
|
/** Defaults to `authorization`, the x402 default */
|
|
481
496
|
readonly paymentFlow?: X402PaymentFlow;
|
|
482
497
|
/** Resources whose `paymentFlow` overrides the rail's, by resource id */
|
|
483
498
|
readonly resourcePaymentFlows?: Readonly<Record<string, X402PaymentFlow>>;
|
|
499
|
+
/** Resources that set `mimeType`, by resource id; others declare `application/json` */
|
|
500
|
+
readonly resourceMimeTypes?: Readonly<Record<string, string>>;
|
|
484
501
|
readonly facilitator: X402FacilitatorConfig;
|
|
485
502
|
readonly allowMainnet?: boolean;
|
|
486
503
|
readonly allowUnauthenticatedFacilitator?: boolean;
|
|
504
|
+
/** EVM networks declared beside the built-in ones, by CAIP-2 id */
|
|
505
|
+
readonly networks?: CustomNetworks;
|
|
506
|
+
/**
|
|
507
|
+
* Resolved options in challenge order; fields above mirror the first.
|
|
508
|
+
* Omit for manually built single-option configs that skip `parseConfig`
|
|
509
|
+
*/
|
|
510
|
+
readonly options?: readonly X402OptionConfig[];
|
|
511
|
+
/**
|
|
512
|
+
* Resource `x402.accepts` overrides by id, replacing `options`.
|
|
513
|
+
* Absent when no resource overrides its offers.
|
|
514
|
+
*/
|
|
515
|
+
readonly resourceOptions?: Readonly<Record<string, readonly X402OptionConfig[]>>;
|
|
487
516
|
};
|
|
488
517
|
readonly mpp?: {
|
|
489
518
|
readonly enabled: boolean;
|
|
@@ -496,7 +525,7 @@ interface GatewayConfig {
|
|
|
496
525
|
readonly realm: string;
|
|
497
526
|
readonly challengeSecret: string;
|
|
498
527
|
readonly challengeTtlSeconds?: number;
|
|
499
|
-
/** Defaults to `
|
|
528
|
+
/** Defaults to `upfront`: settle before the backend call */
|
|
500
529
|
readonly paymentFlow?: X402PaymentFlow;
|
|
501
530
|
/** Resources whose `paymentFlow` overrides the rail's, by resource id */
|
|
502
531
|
readonly resourcePaymentFlows?: Readonly<Record<string, X402PaymentFlow>>;
|
|
@@ -510,6 +539,7 @@ interface GatewayConfig {
|
|
|
510
539
|
readonly ap2: Ap2AuthorizationConfig;
|
|
511
540
|
};
|
|
512
541
|
}
|
|
542
|
+
|
|
513
543
|
declare function parseConfig(raw: unknown, env: NodeJS.ProcessEnv): GatewayConfig;
|
|
514
544
|
|
|
515
545
|
interface LoadConfigOptions {
|
|
@@ -575,16 +605,7 @@ declare class A2aProtocolAdapter implements HttpProtocolAdapter {
|
|
|
575
605
|
handleHttp(req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
576
606
|
private dispatch;
|
|
577
607
|
private execute;
|
|
578
|
-
/**
|
|
579
|
-
* A message on a task waiting for an x402 extension payment, recognized by
|
|
580
|
-
* its `taskId` whether or not the header activated the extension again. Any
|
|
581
|
-
* other task id falls through to `parseInvocation`, which answers
|
|
582
|
-
* TaskNotFoundError.
|
|
583
|
-
*/
|
|
584
|
-
private resumePayment;
|
|
585
|
-
private payPending;
|
|
586
608
|
private taskIdentity;
|
|
587
|
-
private taskResult;
|
|
588
609
|
health(): Promise<AdapterHealth>;
|
|
589
610
|
stop(): Promise<void>;
|
|
590
611
|
private writeJson;
|