@agent-score/commerce 2.3.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 +6 -6
- 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-ChyOi7aU.d.ts → checkout-B-MIzYzW.d.ts} +8 -11
- package/dist/{checkout-Ceo1_rVJ.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 +86 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -65
- package/dist/index.mjs.map +1 -1
- package/dist/{default_rails-DtR_E9N9.d.ts → network_kind-BIJM2peR.d.ts} +22 -8
- package/dist/{default_rails-K25PtWrL.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 +62 -57
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +62 -57
- package/dist/payment/index.mjs.map +1 -1
- package/dist/{pricing-B3-aKxSz.d.ts → pricing-CytRwhC2.d.ts} +1 -1
- package/dist/{pricing-BReyZiqN.d.mts → pricing-KHDqMLd7.d.mts} +1 -1
- package/dist/{rail_spec-B1239jPp.d.mts → rail_spec-BFZmW9RN.d.mts} +3 -4
- package/dist/{rail_spec-B1239jPp.d.ts → rail_spec-BFZmW9RN.d.ts} +3 -4
- package/dist/stripe-multichain/index.d.mts +2 -9
- package/dist/stripe-multichain/index.d.ts +2 -9
- package/dist/stripe-multichain/index.js.map +1 -1
- 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 +9 -8
package/dist/discovery/index.mjs
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
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
|
+
|
|
1
40
|
// src/payment/networks.ts
|
|
2
41
|
var networks = {
|
|
3
42
|
base: {
|
|
@@ -121,8 +160,7 @@ function buildPaymentRequestBlob({
|
|
|
121
160
|
const decimalsResolved = decimals ?? railDef?.decimals ?? 6;
|
|
122
161
|
const currencyResolved = currency ?? railDef?.currency ?? "usd";
|
|
123
162
|
const chainIdResolved = chainId ?? railDef?.chainId;
|
|
124
|
-
const
|
|
125
|
-
const amountRaw = BigInt(Math.round(amountNum * 10 ** decimalsResolved)).toString();
|
|
163
|
+
const amountRaw = usdToAtomic(amountUsd, { decimals: decimalsResolved }).toString();
|
|
126
164
|
const blob = { amount: amountRaw, currency: currencyResolved, decimals: decimalsResolved };
|
|
127
165
|
if (recipient) blob.recipient = recipient;
|
|
128
166
|
const methodDetails = {};
|
|
@@ -1428,19 +1466,19 @@ function stableStringify(value) {
|
|
|
1428
1466
|
}
|
|
1429
1467
|
if (!Number.isInteger(value)) {
|
|
1430
1468
|
throw new Error(
|
|
1431
|
-
`UCP profile canonicalization rejects non-integer Number ${value}. Use a decimal string (e.g. "9.99") for monetary or fractional fields
|
|
1469
|
+
`UCP profile canonicalization rejects non-integer Number ${value}. Use a decimal string (e.g. "9.99") for monetary or fractional fields so the signed canonical bytes stay stable for any verifier.`
|
|
1432
1470
|
);
|
|
1433
1471
|
}
|
|
1434
1472
|
if (!Number.isSafeInteger(value)) {
|
|
1435
1473
|
throw new Error(
|
|
1436
|
-
`stableStringify: integer ${value} exceeds Number.MAX_SAFE_INTEGER. For values >2^53, use a decimal string to
|
|
1474
|
+
`stableStringify: integer ${value} exceeds Number.MAX_SAFE_INTEGER. For values >2^53, use a decimal string to keep the signed bytes stable across implementations.`
|
|
1437
1475
|
);
|
|
1438
1476
|
}
|
|
1439
1477
|
}
|
|
1440
1478
|
if (typeof value === "string") {
|
|
1441
1479
|
if (value.includes("\u2028") || value.includes("\u2029")) {
|
|
1442
1480
|
throw new Error(
|
|
1443
|
-
"stableStringify: strings containing U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR) are not allowed;
|
|
1481
|
+
"stableStringify: strings containing U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR) are not allowed; stable canonical bytes require neither be present (some JSON encoders escape them, others emit them raw)."
|
|
1444
1482
|
);
|
|
1445
1483
|
}
|
|
1446
1484
|
return JSON.stringify(value);
|
|
@@ -1460,7 +1498,7 @@ function stableStringify(value) {
|
|
|
1460
1498
|
for (const k of keys) {
|
|
1461
1499
|
if (k.includes("\u2028") || k.includes("\u2029")) {
|
|
1462
1500
|
throw new Error(
|
|
1463
|
-
"stableStringify: object keys containing U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR) are not allowed;
|
|
1501
|
+
"stableStringify: object keys containing U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR) are not allowed; stable canonical bytes require neither be present (some JSON encoders escape them, others emit them raw)."
|
|
1464
1502
|
);
|
|
1465
1503
|
}
|
|
1466
1504
|
}
|