@piprail/sdk 2.7.0 → 2.8.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/CHANGELOG.md +34 -0
- package/dist/{algorand-TMA62DN2.cjs → algorand-EKD34T4Q.cjs} +32 -32
- package/dist/{algorand-WB6PBJU4.js → algorand-WJL6VRXW.js} +1 -1
- package/dist/{aptos-JQMZNTMD.cjs → aptos-CVHLVMAF.cjs} +31 -31
- package/dist/{aptos-QAAXIUY3.js → aptos-WMPFEASY.js} +1 -1
- package/dist/{chunk-JG6KRAW6.cjs → chunk-VPENSVOI.cjs} +8 -0
- package/dist/{chunk-7XK22JSQ.js → chunk-W3HOMXOF.js} +8 -0
- package/dist/index.cjs +106 -101
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -11
- package/dist/{near-H5AQ253I.cjs → near-NYFMX2KA.cjs} +26 -26
- package/dist/{near-OTPQD6BI.js → near-QV4IOZNX.js} +1 -1
- package/dist/{solana-M3VOHCMO.cjs → solana-L342QCSV.cjs} +64 -33
- package/dist/{solana-3FMCWSEE.js → solana-Z34OWXMO.js} +33 -2
- package/dist/{stellar-U5NCRIOJ.js → stellar-PWC4LETJ.js} +1 -1
- package/dist/{stellar-FW6C6FBE.cjs → stellar-YEXRVR3W.cjs} +20 -20
- package/dist/{sui-47C2KEZI.cjs → sui-EFRSCDWN.cjs} +16 -16
- package/dist/{sui-Y53M4GUM.js → sui-VEOGHBYE.js} +1 -1
- package/dist/{ton-MMPKWT6N.cjs → ton-LZKJWYHV.cjs} +25 -21
- package/dist/{ton-5ZPT5PSP.js → ton-N7KSPSAR.js} +11 -7
- package/dist/{tron-JOT4STIG.cjs → tron-DQU4WTGQ.cjs} +24 -24
- package/dist/{tron-WYS4X2I5.js → tron-WKDUQVZR.js} +1 -1
- package/dist/{xrpl-2MZEOIFY.js → xrpl-6B4IYRWI.js} +1 -1
- package/dist/{xrpl-PECT4IMX.cjs → xrpl-K3U3SBF4.cjs} +20 -20
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,38 @@ All notable changes to `@piprail/sdk` are documented here. The format
|
|
|
4
4
|
follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the
|
|
5
5
|
versions follow [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [2.8.0] — 2026-06-19 — Solana exact SPL-Memo conformance · TON canonical CAIP-2 (`tvm:-239`) · Toncoin→Gram
|
|
8
|
+
|
|
9
|
+
- **chore(ton): native coin symbol `TON` → `GRAM` (Toncoin → Gram rebrand).** A TON community
|
|
10
|
+
governance vote renamed the native token *Toncoin → Gram* (ticker `TON` → `GRAM`), live 2026-06-15.
|
|
11
|
+
It's a token-only, presentation-layer rename — the blockchain is still **The Open Network (TON)**, the
|
|
12
|
+
CAIP-2 network id stays `tvm:-239`, and addresses/contracts/jettons are unchanged (no migration). The
|
|
13
|
+
SDK now surfaces the native coin's symbol as `GRAM` (a 402's `extra.symbol`, `describeAsset`, and
|
|
14
|
+
`estimateCost`'s `feeSymbol`); `chain: 'ton'` and `token: 'native'` select it exactly as before, and
|
|
15
|
+
USD₮ / other jettons are unaffected.
|
|
16
|
+
- **fix(ton): emit canonical CAIP-2 `tvm:-239` (was `ton:-239`)** — the chainagnostic CAIP-2 registry
|
|
17
|
+
has no `ton` namespace and the merged foundation TON exact scheme mandates the `tvm` namespace, so a
|
|
18
|
+
TON 402's `accepts[].network` (and slug resolution / receipts) now emit `tvm:-239`. This makes
|
|
19
|
+
PipRail's TON 402s matchable by discovery indexes and any standard x402 client/facilitator keying on
|
|
20
|
+
the canonical id. **Back-compat:** the legacy `ton:-239` id is still accepted on parse — an inbound or
|
|
21
|
+
foreign challenge using the old id normalizes to `tvm:-239` and routes/verifies unchanged. The
|
|
22
|
+
internal `ton:<address>|<nonce>` proof-locator prefix is unrelated and unchanged.
|
|
23
|
+
- **Solana `exact` SVM conformance — the buyer now emits the spec-required SPL-Memo.** The ratified
|
|
24
|
+
x402 SVM `exact` scheme (§1.2/§3.1) says clients **MUST** include a Memo instruction — `extra.memo`
|
|
25
|
+
verbatim when present, else a random ≥16-byte hex nonce for transaction uniqueness across concurrent
|
|
26
|
+
identical-parameter payments. PipRail's Solana exact buyer previously emitted none, so a seller that
|
|
27
|
+
set `extra.memo` (or a facilitator enforcing the uniqueness Memo) rejected the payment. The buyer now
|
|
28
|
+
appends one SPL-Memo as instruction `[3]`, keeping the exact-rail tx at **4** instructions (still
|
|
29
|
+
inside Path-1's 3-to-7 fast path; SPL-Memo is category-exempt, so it never trips the smart-wallet
|
|
30
|
+
allowlist or the fee-payer drain guard). An `extra.memo` over the 256-byte scheme cap is rejected
|
|
31
|
+
(`UnsupportedSchemeError`). This **changes the exact-rail's default emitted bytes** (a Memo is now
|
|
32
|
+
present) — a *required* conformance change, additive on the wire (old PipRail gates already tolerate
|
|
33
|
+
an inbound Memo). The `onchain-proof` default is byte-identical and untouched.
|
|
34
|
+
- **harden(units): validate `decimals` is a non-negative safe integer.** `parseUnits` / `floorUnits` /
|
|
35
|
+
`formatUnits` now reject a negative, fractional, or NaN `decimals` argument up front (instead of
|
|
36
|
+
silently corrupting the bigint math via `padStart` / `slice`) — defence against a malformed preset or
|
|
37
|
+
a bad caller arg. Existing valid calls are unaffected. Thanks to @samsamtrum (#25).
|
|
38
|
+
|
|
7
39
|
## [2.7.0] — 2026-06-19 — symmetric payment notifications (`onFailed`: both sides notified on success AND failure)
|
|
8
40
|
|
|
9
41
|
Additive and backward-compatible — defaults and the zero-config 402 stay byte-identical; omit the new
|
|
@@ -1433,6 +1465,8 @@ straight into your wallet. The API is small and self-contained.
|
|
|
1433
1465
|
to your wallet; PipRail never holds funds.
|
|
1434
1466
|
- `viem ^2.21` is a peer dependency. Node 20+ or a modern browser.
|
|
1435
1467
|
|
|
1468
|
+
[2.8.0]: https://www.npmjs.com/package/@piprail/sdk
|
|
1469
|
+
[2.7.0]: https://www.npmjs.com/package/@piprail/sdk
|
|
1436
1470
|
[2.6.0]: https://www.npmjs.com/package/@piprail/sdk
|
|
1437
1471
|
[2.5.0]: https://www.npmjs.com/package/@piprail/sdk
|
|
1438
1472
|
[2.4.0]: https://www.npmjs.com/package/@piprail/sdk
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkVPENSVOIcjs = require('./chunk-VPENSVOI.cjs');
|
|
14
14
|
|
|
15
15
|
// src/drivers/algorand/index.ts
|
|
16
16
|
var _algosdk = require('algosdk'); var _algosdk2 = _interopRequireDefault(_algosdk);
|
|
@@ -58,13 +58,13 @@ async function payAlgorand(params) {
|
|
|
58
58
|
} catch (err) {
|
|
59
59
|
const mapped = mapAlgorandError(err, accept.payTo);
|
|
60
60
|
if (mapped) throw mapped;
|
|
61
|
-
throw _nullishCoalesce(
|
|
61
|
+
throw _nullishCoalesce(_chunkVPENSVOIcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
function mapAlgorandError(err, payTo) {
|
|
65
65
|
const m = err instanceof Error ? err.message : String(err);
|
|
66
66
|
if (/must optin/i.test(m) || /missing from/i.test(m) && m.includes(payTo)) {
|
|
67
|
-
return new (0,
|
|
67
|
+
return new (0, _chunkVPENSVOIcjs.RecipientNotReadyError)(
|
|
68
68
|
`Algorand recipient ${payTo} hasn't opted into this asset \u2014 it must opt in (a 0-amount asset transfer to itself) before it can receive. (Algorand: ${firstLine(m)})`,
|
|
69
69
|
{ cause: err }
|
|
70
70
|
);
|
|
@@ -72,7 +72,7 @@ function mapAlgorandError(err, payTo) {
|
|
|
72
72
|
if (/overspend|below min|min(imum)? balance|tried to spend|balance \d+ below|asset \d+ missing from|insufficient|underflow/i.test(
|
|
73
73
|
m
|
|
74
74
|
)) {
|
|
75
|
-
return new (0,
|
|
75
|
+
return new (0, _chunkVPENSVOIcjs.InsufficientFundsError)(
|
|
76
76
|
`Algorand payment failed: the sender can't cover it \u2014 token balance, ALGO for fees, the 0.1-ALGO minimum balance, or a missing asset opt-in on the sender. (Algorand: ${firstLine(m)})`,
|
|
77
77
|
{ cause: err }
|
|
78
78
|
);
|
|
@@ -99,33 +99,33 @@ function isSet(addr) {
|
|
|
99
99
|
function randomNote() {
|
|
100
100
|
const g = globalThis.crypto;
|
|
101
101
|
if (!_optionalChain([g, 'optionalAccess', _ => _.getRandomValues])) {
|
|
102
|
-
throw new (0,
|
|
102
|
+
throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)("Algorand exact: no Web Crypto CSPRNG available to generate a unique note.");
|
|
103
103
|
}
|
|
104
104
|
return g.getRandomValues(new Uint8Array(32));
|
|
105
105
|
}
|
|
106
106
|
async function payExactAlgorand(input) {
|
|
107
107
|
const { suggestedParams, sk, sender, accept } = input;
|
|
108
108
|
if (accept.asset === "native") {
|
|
109
|
-
throw new (0,
|
|
109
|
+
throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)(
|
|
110
110
|
"Algorand exact is ASA-only (an asset transfer); native ALGO is not exact-payable. Pay via onchain-proof."
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
113
|
const feePayer = accept.extra.feePayer;
|
|
114
114
|
if (!feePayer) {
|
|
115
|
-
throw new (0,
|
|
115
|
+
throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)("Algorand exact rail must advertise extra.feePayer (the fee sponsor address).");
|
|
116
116
|
}
|
|
117
117
|
const assetId = parseAlgorandAssetId(accept.asset);
|
|
118
118
|
if (assetId === null) {
|
|
119
|
-
throw new (0,
|
|
119
|
+
throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)(`Algorand exact rail asset "${accept.asset}" must be a numeric ASA id.`);
|
|
120
120
|
}
|
|
121
121
|
if (!_algosdk2.default.isValidAddress(feePayer)) {
|
|
122
|
-
throw new (0,
|
|
122
|
+
throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)(`Algorand exact: extra.feePayer "${feePayer}" is not a valid Algorand address.`);
|
|
123
123
|
}
|
|
124
124
|
if (!_algosdk2.default.isValidAddress(accept.payTo)) {
|
|
125
|
-
throw new (0,
|
|
125
|
+
throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)(`Algorand exact: payTo "${accept.payTo}" is not a valid Algorand address.`);
|
|
126
126
|
}
|
|
127
127
|
if (feePayer === sender) {
|
|
128
|
-
throw new (0,
|
|
128
|
+
throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)(
|
|
129
129
|
"Algorand exact: the fee payer must differ from the payer \u2014 the buyer must pay ZERO ALGO (the sponsor pays the pooled fee)."
|
|
130
130
|
);
|
|
131
131
|
}
|
|
@@ -172,13 +172,13 @@ function decodeElement(bytes) {
|
|
|
172
172
|
async function verifyAndSettleExactAlgorand(input) {
|
|
173
173
|
const { client, feePayerSk, feePayerAddr, payload, accept } = input;
|
|
174
174
|
const railFeePayer = accept.extra.feePayer;
|
|
175
|
-
if (!railFeePayer) throw new (0,
|
|
175
|
+
if (!railFeePayer) throw new (0, _chunkVPENSVOIcjs.SettlementError)("Algorand exact: rail is missing extra.feePayer.");
|
|
176
176
|
if (railFeePayer !== feePayerAddr) {
|
|
177
|
-
throw new (0,
|
|
177
|
+
throw new (0, _chunkVPENSVOIcjs.SettlementError)("Algorand exact: the gate relayer address does not match the rail extra.feePayer \u2014 misconfigured rail.");
|
|
178
178
|
}
|
|
179
179
|
const assetId = parseAlgorandAssetId(accept.asset);
|
|
180
|
-
if (assetId === null) throw new (0,
|
|
181
|
-
if (!_algosdk2.default.isValidAddress(accept.payTo)) throw new (0,
|
|
180
|
+
if (assetId === null) throw new (0, _chunkVPENSVOIcjs.SettlementError)(`Algorand exact: rail asset "${accept.asset}" is not a numeric ASA id.`);
|
|
181
|
+
if (!_algosdk2.default.isValidAddress(accept.payTo)) throw new (0, _chunkVPENSVOIcjs.SettlementError)(`Algorand exact: rail payTo "${accept.payTo}" is invalid.`);
|
|
182
182
|
const { paymentIndex, paymentGroup } = payload;
|
|
183
183
|
if (paymentGroup.length !== GROUP_SIZE) {
|
|
184
184
|
return fail("signature_invalid", `Algorand exact expects a ${GROUP_SIZE}-transaction group (payment + fee), got ${paymentGroup.length}.`);
|
|
@@ -244,7 +244,7 @@ async function verifyAndSettleExactAlgorand(input) {
|
|
|
244
244
|
try {
|
|
245
245
|
feeSigned = fee.signTxn(feePayerSk);
|
|
246
246
|
} catch (err) {
|
|
247
|
-
throw new (0,
|
|
247
|
+
throw new (0, _chunkVPENSVOIcjs.SettlementError)(`Algorand exact settle: the gate could not sign the fee transaction (${shorten(err instanceof Error ? err.message : String(err))}).`, { cause: err });
|
|
248
248
|
}
|
|
249
249
|
const signedGroup = elements.map((el, i) => i === paymentIndex ? payElement.raw : feeSigned);
|
|
250
250
|
try {
|
|
@@ -266,7 +266,7 @@ async function verifyAndSettleExactAlgorand(input) {
|
|
|
266
266
|
if (/signature|sig|auth|malformed/i.test(m)) return fail("signature_invalid", `Settle rejected \u2014 bad signature: ${shorten(m)}.`);
|
|
267
267
|
if (/already in ledger|already committed|duplicate/i.test(m)) return fail("tx_already_used", `This payment was already settled: ${shorten(m)}.`);
|
|
268
268
|
if (/\bround\b|expired|lifetime|stale|validity/i.test(m)) return fail("payment_expired", `Settle rejected \u2014 validity window expired: ${shorten(m)}.`);
|
|
269
|
-
throw new (0,
|
|
269
|
+
throw new (0, _chunkVPENSVOIcjs.SettlementError)(
|
|
270
270
|
`Algorand exact settle: the group failed to submit (${shorten(m)}). The buyer's signed transaction is still valid \u2014 fund/fix the fee payer (${railFeePayer}) and the buyer can re-present it.`,
|
|
271
271
|
{ cause: err }
|
|
272
272
|
);
|
|
@@ -275,10 +275,10 @@ async function verifyAndSettleExactAlgorand(input) {
|
|
|
275
275
|
try {
|
|
276
276
|
round = await client.waitForConfirmation(buyerTxid);
|
|
277
277
|
} catch (err) {
|
|
278
|
-
throw new (0,
|
|
278
|
+
throw new (0, _chunkVPENSVOIcjs.SettlementError)(`Algorand exact settle: submitted ${buyerTxid} but confirmation read failed (${shorten(err instanceof Error ? err.message : String(err))}). It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`, { cause: err });
|
|
279
279
|
}
|
|
280
280
|
if (round === null) {
|
|
281
|
-
throw new (0,
|
|
281
|
+
throw new (0, _chunkVPENSVOIcjs.SettlementError)(`Algorand exact settle: submitted ${buyerTxid} but it did not confirm in time. It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`);
|
|
282
282
|
}
|
|
283
283
|
return {
|
|
284
284
|
ok: true,
|
|
@@ -373,13 +373,13 @@ function rpcFailed(nonce) {
|
|
|
373
373
|
|
|
374
374
|
function assertAlgorandWallet(wallet, network) {
|
|
375
375
|
if (typeof wallet !== "object" || wallet === null) {
|
|
376
|
-
throw new (0,
|
|
376
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
377
377
|
`chain ${network} is Algorand; wallet must be { key } (25-word mnemonic) or { account }.`
|
|
378
378
|
);
|
|
379
379
|
}
|
|
380
|
-
|
|
380
|
+
_chunkVPENSVOIcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Algorand");
|
|
381
381
|
if (!("key" in wallet) && !("account" in wallet)) {
|
|
382
|
-
throw new (0,
|
|
382
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
383
383
|
`chain ${network} is Algorand; wallet must be { key } (25-word mnemonic) or { account }.`
|
|
384
384
|
);
|
|
385
385
|
}
|
|
@@ -394,13 +394,13 @@ function resolveAlgorandWallet(config) {
|
|
|
394
394
|
const { addr, sk } = _algosdk2.default.mnemonicToSecretKey(config.key);
|
|
395
395
|
return { addr: addr.toString(), sk };
|
|
396
396
|
} catch (cause) {
|
|
397
|
-
throw new (0,
|
|
397
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
398
398
|
"Algorand wallet { key } is not a valid 25-word Algorand mnemonic.",
|
|
399
399
|
{ cause }
|
|
400
400
|
);
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
|
-
throw new (0,
|
|
403
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)("Algorand wallet needs { key } (25-word mnemonic) or { account }.");
|
|
404
404
|
}
|
|
405
405
|
|
|
406
406
|
// src/drivers/algorand/index.ts
|
|
@@ -471,16 +471,16 @@ function makeAlgorandNetwork(preset, algodUrl) {
|
|
|
471
471
|
const info = preset.tokens[token.toUpperCase()];
|
|
472
472
|
if (!info) {
|
|
473
473
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
474
|
-
throw new (0,
|
|
474
|
+
throw new (0, _chunkVPENSVOIcjs.UnknownTokenError)(
|
|
475
475
|
`token "${token}" isn't built in for Algorand (known: ${known}). Pass { assetId, decimals } for a custom ASA, or use 'native'.`
|
|
476
476
|
);
|
|
477
477
|
}
|
|
478
478
|
return { asset: algorandAssetId(info.assetId), decimals: info.decimals, symbol: info.symbol };
|
|
479
479
|
}
|
|
480
|
-
|
|
480
|
+
_chunkVPENSVOIcjs.rejectForeignToken.call(void 0, token, "algorand", network);
|
|
481
481
|
const t = token;
|
|
482
482
|
if (typeof t.assetId !== "number" || typeof t.decimals !== "number") {
|
|
483
|
-
throw new (0,
|
|
483
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
484
484
|
`chain ${network} is Algorand; a custom token must be { assetId, decimals }.`
|
|
485
485
|
);
|
|
486
486
|
}
|
|
@@ -501,12 +501,12 @@ function makeAlgorandNetwork(preset, algodUrl) {
|
|
|
501
501
|
},
|
|
502
502
|
assertValidPayTo(payTo) {
|
|
503
503
|
if (payTo.startsWith("0x")) {
|
|
504
|
-
throw new (0,
|
|
504
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
505
505
|
`chain ${network} is Algorand, but payTo "${payTo}" looks like an EVM address.`
|
|
506
506
|
);
|
|
507
507
|
}
|
|
508
508
|
if (!_algosdk2.default.isValidAddress(payTo)) {
|
|
509
|
-
throw new (0,
|
|
509
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
510
510
|
`chain ${network} is Algorand, but payTo "${payTo}" is not a valid Algorand address.`
|
|
511
511
|
);
|
|
512
512
|
}
|
|
@@ -523,14 +523,14 @@ function makeAlgorandNetwork(preset, algodUrl) {
|
|
|
523
523
|
const info = await _algosdk2.default.waitForConfirmation(algod, ref, 10);
|
|
524
524
|
return { height: String(_nullishCoalesce(info.confirmedRound, () => ( 0))) };
|
|
525
525
|
} catch (err) {
|
|
526
|
-
throw new (0,
|
|
526
|
+
throw new (0, _chunkVPENSVOIcjs.ConfirmationTimeoutError)(`Algorand tx ${ref} did not confirm in time.`, {
|
|
527
527
|
cause: err
|
|
528
528
|
});
|
|
529
529
|
}
|
|
530
530
|
},
|
|
531
531
|
async estimateCost(accept) {
|
|
532
532
|
if (accept.scheme === "exact") {
|
|
533
|
-
return
|
|
533
|
+
return _chunkVPENSVOIcjs.nativeCost.call(void 0, {
|
|
534
534
|
symbol: ALGO_SYMBOL,
|
|
535
535
|
decimals: ALGO_DECIMALS,
|
|
536
536
|
fee: 0n,
|
|
@@ -538,7 +538,7 @@ function makeAlgorandNetwork(preset, algodUrl) {
|
|
|
538
538
|
detail: "gasless \u2014 the fee payer (facilitator/relayer) pools the group fee; the buyer pays 0 ALGO"
|
|
539
539
|
});
|
|
540
540
|
}
|
|
541
|
-
return
|
|
541
|
+
return _chunkVPENSVOIcjs.nativeCost.call(void 0, {
|
|
542
542
|
symbol: ALGO_SYMBOL,
|
|
543
543
|
decimals: ALGO_DECIMALS,
|
|
544
544
|
fee: 1000n,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkVPENSVOIcjs = require('./chunk-VPENSVOI.cjs');
|
|
13
13
|
|
|
14
14
|
// src/drivers/aptos/index.ts
|
|
15
15
|
var _tssdk = require('@aptos-labs/ts-sdk');
|
|
@@ -58,14 +58,14 @@ async function payAptos(params) {
|
|
|
58
58
|
const res = await client.signSubmit({ signer, transaction });
|
|
59
59
|
return res.hash;
|
|
60
60
|
} catch (err) {
|
|
61
|
-
if (err instanceof
|
|
61
|
+
if (err instanceof _chunkVPENSVOIcjs.InsufficientFundsError) throw err;
|
|
62
62
|
if (isAptosAffordability(err)) {
|
|
63
|
-
throw new (0,
|
|
63
|
+
throw new (0, _chunkVPENSVOIcjs.InsufficientFundsError)(
|
|
64
64
|
err instanceof Error ? err.message : "Insufficient APT/token balance for the payment.",
|
|
65
65
|
{ cause: err }
|
|
66
66
|
);
|
|
67
67
|
}
|
|
68
|
-
throw _nullishCoalesce(
|
|
68
|
+
throw _nullishCoalesce(_chunkVPENSVOIcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
function isAptosAffordability(err) {
|
|
@@ -103,24 +103,24 @@ function parseAddr(addr) {
|
|
|
103
103
|
async function payExactAptos(input) {
|
|
104
104
|
const { client, sender, accept } = input;
|
|
105
105
|
if (accept.asset === "native") {
|
|
106
|
-
throw new (0,
|
|
106
|
+
throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)(
|
|
107
107
|
"Aptos exact is Fungible-Asset only (a primary_fungible_store transfer); native APT is not exact-payable. Pay via onchain-proof."
|
|
108
108
|
);
|
|
109
109
|
}
|
|
110
110
|
const feePayer = accept.extra.feePayer;
|
|
111
111
|
if (!feePayer) {
|
|
112
|
-
throw new (0,
|
|
112
|
+
throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)("Aptos exact rail must advertise extra.feePayer (the gas sponsor address).");
|
|
113
113
|
}
|
|
114
114
|
const feePayerAddr = parseAddr(feePayer);
|
|
115
|
-
if (!feePayerAddr) throw new (0,
|
|
115
|
+
if (!feePayerAddr) throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)(`Aptos exact: extra.feePayer "${feePayer}" is not a valid Aptos address.`);
|
|
116
116
|
const payToAddr = parseAddr(accept.payTo);
|
|
117
|
-
if (!payToAddr) throw new (0,
|
|
117
|
+
if (!payToAddr) throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)(`Aptos exact: payTo "${accept.payTo}" is not a valid Aptos address.`);
|
|
118
118
|
const metadataAddr = parseAddr(accept.asset);
|
|
119
|
-
if (!metadataAddr) throw new (0,
|
|
119
|
+
if (!metadataAddr) throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)(`Aptos exact: asset "${accept.asset}" is not a valid FA metadata address.`);
|
|
120
120
|
const senderAddr = parseAddr(sender);
|
|
121
|
-
if (!senderAddr) throw new (0,
|
|
121
|
+
if (!senderAddr) throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)(`Aptos exact: payer "${sender}" is not a valid Aptos address.`);
|
|
122
122
|
if (feePayerAddr.equals(senderAddr)) {
|
|
123
|
-
throw new (0,
|
|
123
|
+
throw new (0, _chunkVPENSVOIcjs.UnsupportedSchemeError)(
|
|
124
124
|
"Aptos exact: the fee payer must differ from the payer \u2014 the buyer must pay ZERO APT (the sponsor pays gas)."
|
|
125
125
|
);
|
|
126
126
|
}
|
|
@@ -158,16 +158,16 @@ function argBytes(arg) {
|
|
|
158
158
|
async function verifyAndSettleExactAptos(input) {
|
|
159
159
|
const { client, feePayerAddr, payload, accept } = input;
|
|
160
160
|
const railFeePayer = accept.extra.feePayer;
|
|
161
|
-
if (!railFeePayer) throw new (0,
|
|
161
|
+
if (!railFeePayer) throw new (0, _chunkVPENSVOIcjs.SettlementError)("Aptos exact: rail is missing extra.feePayer.");
|
|
162
162
|
if (railFeePayer !== feePayerAddr) {
|
|
163
|
-
throw new (0,
|
|
163
|
+
throw new (0, _chunkVPENSVOIcjs.SettlementError)("Aptos exact: the gate relayer address does not match the rail extra.feePayer \u2014 misconfigured rail.");
|
|
164
164
|
}
|
|
165
|
-
if (accept.asset === "native") throw new (0,
|
|
165
|
+
if (accept.asset === "native") throw new (0, _chunkVPENSVOIcjs.SettlementError)("Aptos exact: native APT is not exact-payable (misconfigured rail).");
|
|
166
166
|
const railFeePayerAddr = parseAddr(railFeePayer);
|
|
167
167
|
const railPayTo = parseAddr(accept.payTo);
|
|
168
168
|
const railMetadata = parseAddr(accept.asset);
|
|
169
169
|
if (!railFeePayerAddr || !railPayTo || !railMetadata) {
|
|
170
|
-
throw new (0,
|
|
170
|
+
throw new (0, _chunkVPENSVOIcjs.SettlementError)("Aptos exact: rail feePayer/payTo/asset is not a valid Aptos address (misconfigured rail).");
|
|
171
171
|
}
|
|
172
172
|
let tx;
|
|
173
173
|
let senderAuth;
|
|
@@ -241,7 +241,7 @@ async function verifyAndSettleExactAptos(input) {
|
|
|
241
241
|
try {
|
|
242
242
|
feePayerAuth = client.signAsFeePayer({ transaction: tx });
|
|
243
243
|
} catch (err) {
|
|
244
|
-
throw new (0,
|
|
244
|
+
throw new (0, _chunkVPENSVOIcjs.SettlementError)(`Aptos exact settle: the gate could not sign as fee payer (${shorten(err instanceof Error ? err.message : String(err))}).`, { cause: err });
|
|
245
245
|
}
|
|
246
246
|
if (senderAuth instanceof _tssdk.AccountAuthenticatorEd25519) {
|
|
247
247
|
try {
|
|
@@ -264,7 +264,7 @@ async function verifyAndSettleExactAptos(input) {
|
|
|
264
264
|
if (/signature|invalid.*auth|INVALID_SIGNATURE/i.test(m)) return fail("signature_invalid", `Settle rejected \u2014 bad signature: ${shorten(m)}.`);
|
|
265
265
|
if (/SEQUENCE_NUMBER_TOO_OLD|already.*(committed|ledger)|duplicate/i.test(m)) return fail("tx_already_used", `This payment was already settled: ${shorten(m)}.`);
|
|
266
266
|
if (/EXPIRED|expired|TOO_NEW/i.test(m)) return fail("payment_expired", `Settle rejected \u2014 expired/stale: ${shorten(m)}.`);
|
|
267
|
-
throw new (0,
|
|
267
|
+
throw new (0, _chunkVPENSVOIcjs.SettlementError)(
|
|
268
268
|
`Aptos exact settle: the transaction failed to submit (${shorten(m)}). The buyer's signed transaction is still valid \u2014 fund/fix the fee payer (${railFeePayer}) and the buyer can re-present it.`,
|
|
269
269
|
{ cause: err }
|
|
270
270
|
);
|
|
@@ -273,10 +273,10 @@ async function verifyAndSettleExactAptos(input) {
|
|
|
273
273
|
try {
|
|
274
274
|
confirmed = await client.waitForConfirmation(hash);
|
|
275
275
|
} catch (err) {
|
|
276
|
-
throw new (0,
|
|
276
|
+
throw new (0, _chunkVPENSVOIcjs.SettlementError)(`Aptos exact settle: submitted ${hash} but confirmation read failed (${shorten(err instanceof Error ? err.message : String(err))}). It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`, { cause: err });
|
|
277
277
|
}
|
|
278
278
|
if (confirmed === null) {
|
|
279
|
-
throw new (0,
|
|
279
|
+
throw new (0, _chunkVPENSVOIcjs.SettlementError)(`Aptos exact settle: submitted ${hash} but it did not confirm in time. It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`);
|
|
280
280
|
}
|
|
281
281
|
if (!confirmed.success) {
|
|
282
282
|
return fail("tx_reverted", `Settle tx ${hash} reverted on-chain (a post-simulate race).`);
|
|
@@ -371,13 +371,13 @@ function txNotFound(hash) {
|
|
|
371
371
|
|
|
372
372
|
function assertAptosWallet(wallet, network) {
|
|
373
373
|
if (typeof wallet !== "object" || wallet === null) {
|
|
374
|
-
throw new (0,
|
|
374
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
375
375
|
`chain ${network} is Aptos; wallet must be { key } (ed25519-priv-0x\u2026) or { account }.`
|
|
376
376
|
);
|
|
377
377
|
}
|
|
378
|
-
|
|
378
|
+
_chunkVPENSVOIcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Aptos");
|
|
379
379
|
if (!("key" in wallet) && !("account" in wallet)) {
|
|
380
|
-
throw new (0,
|
|
380
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
381
381
|
`chain ${network} is Aptos; wallet must be { key } (ed25519-priv-0x\u2026) or { account }.`
|
|
382
382
|
);
|
|
383
383
|
}
|
|
@@ -389,13 +389,13 @@ function resolveAptosAccount(config) {
|
|
|
389
389
|
try {
|
|
390
390
|
return _tssdk.Account.fromPrivateKey({ privateKey: new (0, _tssdk.Ed25519PrivateKey)(config.key) });
|
|
391
391
|
} catch (cause) {
|
|
392
|
-
throw new (0,
|
|
392
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
393
393
|
"Aptos wallet { key } is not a valid ed25519 secret (ed25519-priv-0x\u2026 or 0x\u2026 hex).",
|
|
394
394
|
{ cause }
|
|
395
395
|
);
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
|
-
throw new (0,
|
|
398
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)("Aptos wallet needs { key } (ed25519-priv-0x\u2026) or { account }.");
|
|
399
399
|
}
|
|
400
400
|
|
|
401
401
|
// src/drivers/aptos/index.ts
|
|
@@ -467,16 +467,16 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
467
467
|
const info = preset.tokens[token.toUpperCase()];
|
|
468
468
|
if (!info) {
|
|
469
469
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
470
|
-
throw new (0,
|
|
470
|
+
throw new (0, _chunkVPENSVOIcjs.UnknownTokenError)(
|
|
471
471
|
`token "${token}" isn't built in for Aptos (known: ${known}). Pass { metadata, decimals } for a custom Fungible Asset, or use 'native'.`
|
|
472
472
|
);
|
|
473
473
|
}
|
|
474
474
|
return { asset: info.metadata, decimals: info.decimals, symbol: info.symbol };
|
|
475
475
|
}
|
|
476
|
-
|
|
476
|
+
_chunkVPENSVOIcjs.rejectForeignToken.call(void 0, token, "aptos", network);
|
|
477
477
|
const t = token;
|
|
478
478
|
if (!t.metadata || typeof t.decimals !== "number") {
|
|
479
|
-
throw new (0,
|
|
479
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
480
480
|
`chain ${network} is Aptos; a custom token must be { metadata, decimals }.`
|
|
481
481
|
);
|
|
482
482
|
}
|
|
@@ -503,7 +503,7 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
503
503
|
valid = false;
|
|
504
504
|
}
|
|
505
505
|
if (!valid || evmLike) {
|
|
506
|
-
throw new (0,
|
|
506
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
507
507
|
`chain ${network} is Aptos, but payTo "${payTo}" is not a valid Aptos address (0x + 32 bytes).`
|
|
508
508
|
);
|
|
509
509
|
}
|
|
@@ -525,12 +525,12 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
525
525
|
const tx = await aptos.waitForTransaction({ transactionHash: ref });
|
|
526
526
|
return { height: String(_nullishCoalesce(tx.version, () => ( "0"))) };
|
|
527
527
|
} catch (err) {
|
|
528
|
-
throw new (0,
|
|
528
|
+
throw new (0, _chunkVPENSVOIcjs.ConfirmationTimeoutError)(`Aptos tx ${ref} did not finalize in time.`, { cause: err });
|
|
529
529
|
}
|
|
530
530
|
},
|
|
531
531
|
async estimateCost(accept) {
|
|
532
532
|
if (accept.scheme === "exact") {
|
|
533
|
-
return
|
|
533
|
+
return _chunkVPENSVOIcjs.nativeCost.call(void 0, {
|
|
534
534
|
symbol: APT_SYMBOL,
|
|
535
535
|
decimals: APT_DECIMALS,
|
|
536
536
|
fee: 0n,
|
|
@@ -538,7 +538,7 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
538
538
|
detail: "gasless \u2014 the fee payer (facilitator/relayer) sponsors gas; the buyer pays 0 APT"
|
|
539
539
|
});
|
|
540
540
|
}
|
|
541
|
-
return
|
|
541
|
+
return _chunkVPENSVOIcjs.nativeCost.call(void 0, {
|
|
542
542
|
symbol: APT_SYMBOL,
|
|
543
543
|
decimals: APT_DECIMALS,
|
|
544
544
|
fee: 100000n,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
nativeCost,
|
|
10
10
|
rejectForeignToken,
|
|
11
11
|
toInsufficientFundsError
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-W3HOMXOF.js";
|
|
13
13
|
|
|
14
14
|
// src/drivers/aptos/index.ts
|
|
15
15
|
import { Aptos, AptosConfig, Network, AccountAddress as AccountAddress2 } from "@aptos-labs/ts-sdk";
|
|
@@ -133,7 +133,13 @@ function rejectForeignToken(token, family, network) {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
// src/util/units.ts
|
|
136
|
+
function assertValidDecimals(decimals, fn) {
|
|
137
|
+
if (!Number.isSafeInteger(decimals) || decimals < 0) {
|
|
138
|
+
throw new Error(`${fn}: decimals must be a non-negative safe integer (got ${decimals}).`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
136
141
|
function parseUnits(value, decimals) {
|
|
142
|
+
assertValidDecimals(decimals, "parseUnits");
|
|
137
143
|
if (!/^\d+(\.\d+)?$/.test(value)) {
|
|
138
144
|
throw new Error(`parseUnits: "${value}" is not a non-negative decimal amount.`);
|
|
139
145
|
}
|
|
@@ -147,6 +153,7 @@ function parseUnits(value, decimals) {
|
|
|
147
153
|
return BigInt(whole + fracPadded);
|
|
148
154
|
}
|
|
149
155
|
function floorUnits(value, decimals) {
|
|
156
|
+
assertValidDecimals(decimals, "floorUnits");
|
|
150
157
|
if (!/^\d+(\.\d+)?$/.test(value)) {
|
|
151
158
|
throw new Error(`floorUnits: "${value}" is not a non-negative decimal amount.`);
|
|
152
159
|
}
|
|
@@ -155,6 +162,7 @@ function floorUnits(value, decimals) {
|
|
|
155
162
|
return BigInt(whole + fracTrunc);
|
|
156
163
|
}
|
|
157
164
|
function formatUnits(value, decimals) {
|
|
165
|
+
assertValidDecimals(decimals, "formatUnits");
|
|
158
166
|
const negative = value < 0n;
|
|
159
167
|
const digits = (negative ? -value : value).toString().padStart(decimals + 1, "0");
|
|
160
168
|
const whole = digits.slice(0, digits.length - decimals);
|
|
@@ -133,7 +133,13 @@ function rejectForeignToken(token, family, network) {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
// src/util/units.ts
|
|
136
|
+
function assertValidDecimals(decimals, fn) {
|
|
137
|
+
if (!Number.isSafeInteger(decimals) || decimals < 0) {
|
|
138
|
+
throw new Error(`${fn}: decimals must be a non-negative safe integer (got ${decimals}).`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
136
141
|
function parseUnits(value, decimals) {
|
|
142
|
+
assertValidDecimals(decimals, "parseUnits");
|
|
137
143
|
if (!/^\d+(\.\d+)?$/.test(value)) {
|
|
138
144
|
throw new Error(`parseUnits: "${value}" is not a non-negative decimal amount.`);
|
|
139
145
|
}
|
|
@@ -147,6 +153,7 @@ function parseUnits(value, decimals) {
|
|
|
147
153
|
return BigInt(whole + fracPadded);
|
|
148
154
|
}
|
|
149
155
|
function floorUnits(value, decimals) {
|
|
156
|
+
assertValidDecimals(decimals, "floorUnits");
|
|
150
157
|
if (!/^\d+(\.\d+)?$/.test(value)) {
|
|
151
158
|
throw new Error(`floorUnits: "${value}" is not a non-negative decimal amount.`);
|
|
152
159
|
}
|
|
@@ -155,6 +162,7 @@ function floorUnits(value, decimals) {
|
|
|
155
162
|
return BigInt(whole + fracTrunc);
|
|
156
163
|
}
|
|
157
164
|
function formatUnits(value, decimals) {
|
|
165
|
+
assertValidDecimals(decimals, "formatUnits");
|
|
158
166
|
const negative = value < 0n;
|
|
159
167
|
const digits = (negative ? -value : value).toString().padStart(decimals + 1, "0");
|
|
160
168
|
const whole = digits.slice(0, digits.length - decimals);
|