@agent-score/commerce 2.2.0 → 2.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 +7 -7
- package/dist/challenge/index.d.mts +4 -4
- package/dist/challenge/index.d.ts +4 -4
- package/dist/challenge/index.js.map +1 -1
- package/dist/challenge/index.mjs.map +1 -1
- package/dist/{checkout-CfgxgPZL.d.ts → checkout-B-MIzYzW.d.ts} +8 -11
- package/dist/{checkout-CKQE2QpJ.d.mts → checkout-Bn7ZKIBD.d.mts} +8 -11
- package/dist/core.d.mts +4 -6
- package/dist/core.d.ts +4 -6
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +1 -1
- package/dist/core.mjs.map +1 -1
- package/dist/discovery/index.d.mts +10 -9
- package/dist/discovery/index.d.ts +10 -9
- package/dist/discovery/index.js +44 -6
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +44 -6
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/identity/express.js +13 -13
- package/dist/identity/express.js.map +1 -1
- package/dist/identity/express.mjs +13 -13
- package/dist/identity/express.mjs.map +1 -1
- package/dist/identity/fastify.js +13 -13
- package/dist/identity/fastify.js.map +1 -1
- package/dist/identity/fastify.mjs +13 -13
- package/dist/identity/fastify.mjs.map +1 -1
- package/dist/identity/hono.js +13 -13
- package/dist/identity/hono.js.map +1 -1
- package/dist/identity/hono.mjs +13 -13
- package/dist/identity/hono.mjs.map +1 -1
- package/dist/identity/nextjs.js +13 -13
- package/dist/identity/nextjs.js.map +1 -1
- package/dist/identity/nextjs.mjs +13 -13
- package/dist/identity/nextjs.mjs.map +1 -1
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/policy.mjs.map +1 -1
- package/dist/identity/web.js +13 -13
- package/dist/identity/web.js.map +1 -1
- package/dist/identity/web.mjs +13 -13
- package/dist/identity/web.mjs.map +1 -1
- package/dist/index.d.mts +12 -13
- package/dist/index.d.ts +12 -13
- package/dist/index.js +88 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -65
- package/dist/index.mjs.map +1 -1
- package/dist/{default_rails-C5gKZJMI.d.ts → network_kind-BIJM2peR.d.ts} +22 -8
- package/dist/{default_rails-XFCuRddA.d.mts → network_kind-C0EMkdzz.d.mts} +22 -8
- package/dist/payment/index.d.mts +16 -26
- package/dist/payment/index.d.ts +16 -26
- package/dist/payment/index.js +64 -57
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +64 -57
- package/dist/payment/index.mjs.map +1 -1
- package/dist/{pricing-uFGRNoGl.d.ts → pricing-CytRwhC2.d.ts} +1 -1
- package/dist/{pricing-dSI3ePmE.d.mts → pricing-KHDqMLd7.d.mts} +1 -1
- package/dist/{rail_spec-D6qzh3J0.d.mts → rail_spec-BFZmW9RN.d.mts} +28 -4
- package/dist/{rail_spec-D6qzh3J0.d.ts → rail_spec-BFZmW9RN.d.ts} +28 -4
- package/dist/stripe-multichain/index.d.mts +61 -18
- package/dist/stripe-multichain/index.d.ts +61 -18
- package/dist/stripe-multichain/index.js +82 -42
- package/dist/stripe-multichain/index.js.map +1 -1
- package/dist/stripe-multichain/index.mjs +81 -42
- package/dist/stripe-multichain/index.mjs.map +1 -1
- package/dist/{wwwauthenticate-D_FMnPgU.d.mts → wwwauthenticate-CVaGUMjU.d.mts} +8 -6
- package/dist/{wwwauthenticate-D_FMnPgU.d.ts → wwwauthenticate-CVaGUMjU.d.ts} +8 -6
- package/package.json +12 -11
package/dist/payment/index.mjs
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
+
// src/payment/amounts.ts
|
|
2
|
+
function usdToAtomic(usd, opts) {
|
|
3
|
+
const { decimals } = opts;
|
|
4
|
+
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
5
|
+
throw new RangeError(`decimals must be a non-negative integer, got ${decimals}`);
|
|
6
|
+
}
|
|
7
|
+
if (typeof usd === "number") {
|
|
8
|
+
if (!Number.isFinite(usd)) {
|
|
9
|
+
throw new RangeError(`usd must be finite, got ${usd}`);
|
|
10
|
+
}
|
|
11
|
+
if (usd < 0) {
|
|
12
|
+
throw new RangeError(`usd must be non-negative, got ${usd}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const s = (typeof usd === "number" ? usd.toString() : usd).trim();
|
|
16
|
+
if (s.startsWith("-")) {
|
|
17
|
+
throw new RangeError(`usd must be non-negative, got ${s}`);
|
|
18
|
+
}
|
|
19
|
+
if (s === "NaN" || s === "Infinity") {
|
|
20
|
+
throw new RangeError(`usd must be finite, got ${s}`);
|
|
21
|
+
}
|
|
22
|
+
const match = /^(\d*)(?:\.(\d*))?$/.exec(s);
|
|
23
|
+
if (!match || match[1] === "" && (match[2] === void 0 || match[2] === "")) {
|
|
24
|
+
throw new SyntaxError(`invalid usd value: ${JSON.stringify(usd)}`);
|
|
25
|
+
}
|
|
26
|
+
const intPart = match[1] || "0";
|
|
27
|
+
const fracPart = match[2] ?? "";
|
|
28
|
+
if (fracPart.length <= decimals) {
|
|
29
|
+
return BigInt(intPart + fracPart.padEnd(decimals, "0"));
|
|
30
|
+
}
|
|
31
|
+
const kept = fracPart.slice(0, decimals);
|
|
32
|
+
const roundDigit = fracPart[decimals];
|
|
33
|
+
let result = BigInt(intPart + kept);
|
|
34
|
+
if (roundDigit >= "5") {
|
|
35
|
+
result += 1n;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
function formatUsdCents(cents, decimals = 2) {
|
|
40
|
+
return (cents / 100).toFixed(decimals);
|
|
41
|
+
}
|
|
42
|
+
|
|
1
43
|
// src/payment/networks.ts
|
|
2
44
|
var networks = {
|
|
3
45
|
base: {
|
|
@@ -128,8 +170,7 @@ function buildPaymentRequestBlob({
|
|
|
128
170
|
const decimalsResolved = decimals ?? railDef?.decimals ?? 6;
|
|
129
171
|
const currencyResolved = currency ?? railDef?.currency ?? "usd";
|
|
130
172
|
const chainIdResolved = chainId ?? railDef?.chainId;
|
|
131
|
-
const
|
|
132
|
-
const amountRaw = BigInt(Math.round(amountNum * 10 ** decimalsResolved)).toString();
|
|
173
|
+
const amountRaw = usdToAtomic(amountUsd, { decimals: decimalsResolved }).toString();
|
|
133
174
|
const blob = { amount: amountRaw, currency: currencyResolved, decimals: decimalsResolved };
|
|
134
175
|
if (recipient) blob.recipient = recipient;
|
|
135
176
|
const methodDetails = {};
|
|
@@ -685,11 +726,13 @@ async function registerSolana(spec) {
|
|
|
685
726
|
"createMppxServer: SolanaMppRailSpec requires a string recipient (per-order factories not supported here)."
|
|
686
727
|
);
|
|
687
728
|
}
|
|
729
|
+
const ataCreationRequired = spec.ataCreationRequired !== false;
|
|
688
730
|
const baseMethod = solanaMpp.charge({
|
|
689
731
|
recipient: spec.recipient,
|
|
690
732
|
currency: spec.token ?? defaultMint,
|
|
691
733
|
decimals: spec.decimals ?? defaultDecimals,
|
|
692
734
|
network,
|
|
735
|
+
...ataCreationRequired ? { splits: [{ recipient: spec.recipient, amount: "0", ataCreationRequired: true }] } : {},
|
|
693
736
|
...spec.rpcUrl ? { rpcUrl: spec.rpcUrl } : {},
|
|
694
737
|
...spec.signer ? { signer: spec.signer } : {},
|
|
695
738
|
...spec.tokenProgram ? { tokenProgram: spec.tokenProgram } : {}
|
|
@@ -994,6 +1037,18 @@ async function extractSolanaSignerFromCredential(credential) {
|
|
|
994
1037
|
}
|
|
995
1038
|
}
|
|
996
1039
|
async function extractPaymentSigner(request, x402PaymentHeader) {
|
|
1040
|
+
if (x402PaymentHeader) {
|
|
1041
|
+
try {
|
|
1042
|
+
const decoded = atob(x402PaymentHeader);
|
|
1043
|
+
const parsed = JSON.parse(decoded);
|
|
1044
|
+
const from = parsed?.payload?.authorization?.from;
|
|
1045
|
+
if (typeof from === "string" && /^0x[0-9a-fA-F]{40}$/.test(from)) {
|
|
1046
|
+
return { address: from.toLowerCase(), network: "evm" };
|
|
1047
|
+
}
|
|
1048
|
+
} catch (err) {
|
|
1049
|
+
console.warn("[gate] x402 signer extraction failed:", err instanceof Error ? err.message : err);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
997
1052
|
const authHeader = request.headers.get("authorization");
|
|
998
1053
|
if (authHeader) {
|
|
999
1054
|
try {
|
|
@@ -1013,18 +1068,6 @@ async function extractPaymentSigner(request, x402PaymentHeader) {
|
|
|
1013
1068
|
console.warn("[gate] MPP signer extraction failed:", err instanceof Error ? err.message : err);
|
|
1014
1069
|
}
|
|
1015
1070
|
}
|
|
1016
|
-
if (x402PaymentHeader) {
|
|
1017
|
-
try {
|
|
1018
|
-
const decoded = atob(x402PaymentHeader);
|
|
1019
|
-
const parsed = JSON.parse(decoded);
|
|
1020
|
-
const from = parsed?.payload?.authorization?.from;
|
|
1021
|
-
if (typeof from === "string" && /^0x[0-9a-fA-F]{40}$/.test(from)) {
|
|
1022
|
-
return { address: from.toLowerCase(), network: "evm" };
|
|
1023
|
-
}
|
|
1024
|
-
} catch (err) {
|
|
1025
|
-
console.warn("[gate] x402 signer extraction failed:", err instanceof Error ? err.message : err);
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
1071
|
return null;
|
|
1029
1072
|
}
|
|
1030
1073
|
async function extractPaymentSignerFromAuth(authHeader, x402PaymentHeader) {
|
|
@@ -1056,48 +1099,6 @@ function settlementOverrideHeader(overrides) {
|
|
|
1056
1099
|
return { name: SETTLEMENT_OVERRIDES_HEADER, value: JSON.stringify(overrides) };
|
|
1057
1100
|
}
|
|
1058
1101
|
|
|
1059
|
-
// src/payment/amounts.ts
|
|
1060
|
-
function usdToAtomic(usd, opts) {
|
|
1061
|
-
const { decimals } = opts;
|
|
1062
|
-
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
1063
|
-
throw new RangeError(`decimals must be a non-negative integer, got ${decimals}`);
|
|
1064
|
-
}
|
|
1065
|
-
if (typeof usd === "number") {
|
|
1066
|
-
if (!Number.isFinite(usd)) {
|
|
1067
|
-
throw new RangeError(`usd must be finite, got ${usd}`);
|
|
1068
|
-
}
|
|
1069
|
-
if (usd < 0) {
|
|
1070
|
-
throw new RangeError(`usd must be non-negative, got ${usd}`);
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
const s = (typeof usd === "number" ? usd.toString() : usd).trim();
|
|
1074
|
-
if (s.startsWith("-")) {
|
|
1075
|
-
throw new RangeError(`usd must be non-negative, got ${s}`);
|
|
1076
|
-
}
|
|
1077
|
-
if (s === "NaN" || s === "Infinity") {
|
|
1078
|
-
throw new RangeError(`usd must be finite, got ${s}`);
|
|
1079
|
-
}
|
|
1080
|
-
const match = /^(\d*)(?:\.(\d*))?$/.exec(s);
|
|
1081
|
-
if (!match || match[1] === "" && (match[2] === void 0 || match[2] === "")) {
|
|
1082
|
-
throw new SyntaxError(`invalid usd value: ${JSON.stringify(usd)}`);
|
|
1083
|
-
}
|
|
1084
|
-
const intPart = match[1] || "0";
|
|
1085
|
-
const fracPart = match[2] ?? "";
|
|
1086
|
-
if (fracPart.length <= decimals) {
|
|
1087
|
-
return BigInt(intPart + fracPart.padEnd(decimals, "0"));
|
|
1088
|
-
}
|
|
1089
|
-
const kept = fracPart.slice(0, decimals);
|
|
1090
|
-
const roundDigit = fracPart[decimals];
|
|
1091
|
-
let result = BigInt(intPart + kept);
|
|
1092
|
-
if (roundDigit >= "5") {
|
|
1093
|
-
result += 1n;
|
|
1094
|
-
}
|
|
1095
|
-
return result;
|
|
1096
|
-
}
|
|
1097
|
-
function formatUsdCents(cents, decimals = 2) {
|
|
1098
|
-
return (cents / 100).toFixed(decimals);
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
1102
|
// src/payment/zero-settle.ts
|
|
1102
1103
|
var EVM_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
1103
1104
|
var SOLANA_BASE58_RE = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
@@ -1277,7 +1278,13 @@ function buildMppxComposeRails(opts) {
|
|
|
1277
1278
|
function buildDefaultCheckoutRails(opts) {
|
|
1278
1279
|
const out = {};
|
|
1279
1280
|
if (opts.tempo) {
|
|
1280
|
-
|
|
1281
|
+
const merged = { recipient: "", ...RAIL_SPEC_DEFAULTS.tempo, ...opts.tempo };
|
|
1282
|
+
if (merged.testnet) {
|
|
1283
|
+
if (opts.tempo.network === void 0) merged.network = "tempo-testnet";
|
|
1284
|
+
if (opts.tempo.chainId === void 0) merged.chainId = 42431;
|
|
1285
|
+
if (opts.tempo.token === void 0) merged.token = USDC.tempo.testnet.address;
|
|
1286
|
+
}
|
|
1287
|
+
out.tempo = merged;
|
|
1281
1288
|
}
|
|
1282
1289
|
if (opts.x402Base) {
|
|
1283
1290
|
const merged = { recipient: "", ...RAIL_SPEC_DEFAULTS.x402Base, ...opts.x402Base };
|