@piprail/sdk 1.14.0 → 1.15.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 +30 -0
- package/ERRORS.md +15 -1
- package/README.md +38 -2
- package/STANDARDS.md +4 -2
- package/dist/{algorand-OIHGJN5S.cjs → algorand-EJ3S2V7E.cjs} +17 -17
- package/dist/{algorand-7EUZYL2Z.js → algorand-F3OYB534.js} +1 -1
- package/dist/{aptos-WDWZOU25.cjs → aptos-GJGIZHNI.cjs} +16 -16
- package/dist/{aptos-CDEYDDM5.js → aptos-SUXOVP7B.js} +1 -1
- package/dist/{chunk-H3A4KWLJ.js → chunk-ILPABTI2.js} +6 -0
- package/dist/{chunk-FTKVCP6K.cjs → chunk-PA6YD3HL.cjs} +17 -11
- package/dist/index.cjs +493 -115
- package/dist/index.d.cts +264 -12
- package/dist/index.d.ts +264 -12
- package/dist/index.js +403 -25
- package/dist/{near-DT6LRIKB.js → near-LM7S3WUD.js} +1 -1
- package/dist/{near-FUH3VAXT.cjs → near-ZJLZE26R.cjs} +19 -19
- package/dist/{solana-QUVXPKBZ.cjs → solana-MPPE6K24.cjs} +14 -14
- package/dist/{solana-3TRYD4QB.js → solana-WDKWWF33.js} +1 -1
- package/dist/{stellar-IK3UML6O.js → stellar-FIJPQZVW.js} +1 -1
- package/dist/{stellar-APZEBFAD.cjs → stellar-XHLLNHQP.cjs} +21 -21
- package/dist/{sui-L7BQNJWO.cjs → sui-6CVLEXLA.cjs} +17 -17
- package/dist/{sui-VSE63WQM.js → sui-B7AVN7NK.js} +1 -1
- package/dist/{ton-QHGQLJX2.js → ton-CHJ26BVA.js} +1 -1
- package/dist/{ton-5DLKKOFE.cjs → ton-RNEFN25G.cjs} +14 -14
- package/dist/{tron-2N2GA62O.js → tron-DD3JDROV.js} +1 -1
- package/dist/{tron-HHIT6WKY.cjs → tron-TKJHNFGM.cjs} +24 -24
- package/dist/{xrpl-2GZMDYW5.js → xrpl-GTUPP6SK.js} +1 -1
- package/dist/{xrpl-USEG4AHX.cjs → xrpl-XN2NBNGI.cjs} +21 -21
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,35 @@ 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
|
+
## [1.15.0] — 2026-06-10 — the trusted agent wallet (budget-bound, time-boxed, asks-first)
|
|
8
|
+
|
|
9
|
+
A minor, fully additive layer — defaults byte-identical, no new error code, protocol
|
|
10
|
+
layer stays viem-free.
|
|
11
|
+
|
|
12
|
+
### Added — a TIME dimension on `PaymentPolicy` (Mode A)
|
|
13
|
+
- Four opt-in fields make the spend leash a *clock* too: `ttlSeconds` / `expiresAt` (a
|
|
14
|
+
session deadline — past it EVERY pay is refused with `reasonCode:'SESSION_EXPIRED'`,
|
|
15
|
+
TERMINAL) and `windowTotal` + `windowSeconds` (an optional rolling rate-limit, per
|
|
16
|
+
`(network, asset)`). All default off → behaviour unchanged. A half-armed window
|
|
17
|
+
(`windowTotal` without `windowSeconds`) or an unsafe `ttlSeconds` throws at construction.
|
|
18
|
+
- `client.budget(): SessionBudget` and `PaymentPlan.session` surface the remaining money +
|
|
19
|
+
time leash so a headless agent can SEE it before paying. `client.remaining(): SpendRemaining[]`
|
|
20
|
+
gives the per-asset cap, ledger-scoped. All read-only, never throw, process-scoped (reset on restart).
|
|
21
|
+
- `PolicyDecision` gains a typed `code` (`PolicyDenyCode`); `PayBlocker` gains `OUTSIDE_WINDOW`.
|
|
22
|
+
|
|
23
|
+
### Added — agent ergonomics (the model-facing contract)
|
|
24
|
+
- `PaymentDeclinedError.reasonCode` (`'POLICY' | 'BUDGET' | 'OUTSIDE_WINDOW' | 'SESSION_EXPIRED'
|
|
25
|
+
| 'APPROVAL'`) — a typed discriminator so an agent branches on the cause (and spots a TERMINAL
|
|
26
|
+
decline) without parsing prose. No new `.code`.
|
|
27
|
+
- The `piprail_pay_request` tool now funnels EVERY `PipRailError` into a structured
|
|
28
|
+
`{ ok:false, code, reason, explain, ref?, reasonCode?, declined? }` — never an uncaught crash, so a
|
|
29
|
+
broadcast-but-unconfirmed timeout reaches the agent with its `.ref` and the never-re-pay rule.
|
|
30
|
+
- New pure exports: `summarizePlan` / `explainDecline` / `formatSpendReport` (NL renderers, wired into
|
|
31
|
+
the tool outputs), `classifyChallenge` + `ChallengeTriage` (scheme/chain triage), and
|
|
32
|
+
`PIPRAIL_AGENT_GUIDE` / `agentGuide` (the cross-tool contract).
|
|
33
|
+
- `paymentTools()` now returns **7** tools — the original 5, plus read-only `piprail_budget` and
|
|
34
|
+
`piprail_guide` appended last (the first five are byte-identical in name + order).
|
|
35
|
+
|
|
7
36
|
## [1.14.0] — 2026-06-10
|
|
8
37
|
|
|
9
38
|
### Added — pay the standard `exact` rail (opt-in, EVM + EIP-3009)
|
|
@@ -662,6 +691,7 @@ straight into your wallet. The API is small and self-contained.
|
|
|
662
691
|
to your wallet; PipRail never holds funds.
|
|
663
692
|
- `viem ^2.21` is a peer dependency. Node 20+ or a modern browser.
|
|
664
693
|
|
|
694
|
+
[1.15.0]: https://www.npmjs.com/package/@piprail/sdk
|
|
665
695
|
[1.14.0]: https://www.npmjs.com/package/@piprail/sdk
|
|
666
696
|
[1.13.1]: https://www.npmjs.com/package/@piprail/sdk
|
|
667
697
|
[1.13.0]: https://www.npmjs.com/package/@piprail/sdk
|
package/ERRORS.md
CHANGED
|
@@ -114,9 +114,23 @@ the code. A consumer building a custom client may branch on it.
|
|
|
114
114
|
`error — detail` (e.g. `… Last server rejection: amount_too_low — Paid 40000, required
|
|
115
115
|
500000.`), and a `payment-failed` event carrying the same reason.
|
|
116
116
|
- **Client refused to pay →** `PaymentDeclinedError` thrown *before* any on-chain send — the
|
|
117
|
-
quote exceeded the client's `policy
|
|
117
|
+
quote exceeded the client's `policy` (amount/total/chain/token/host, or the session's **time
|
|
118
|
+
envelope**), or an `onBeforePay` hook returned false. Nothing moved. It carries an optional typed
|
|
119
|
+
`reasonCode` (`'POLICY' | 'BUDGET' | 'OUTSIDE_WINDOW' | 'SESSION_EXPIRED' | 'APPROVAL'`) so an agent
|
|
120
|
+
branches on the cause — and recognises a **TERMINAL** `SESSION_EXPIRED` / `APPROVAL` it must not
|
|
121
|
+
retry — without parsing the message. The session TTL (`SESSION_EXPIRED`) and rolling window
|
|
122
|
+
(`OUTSIDE_WINDOW`) reuse this EXISTING `PaymentDeclinedError` (`.code` stays `'PAYMENT_DECLINED'`):
|
|
123
|
+
**no new error class, no new `VerifyErrorCode`** — only the closed `PayBlocker` union gains `OUTSIDE_WINDOW`.
|
|
118
124
|
- **Config / flow / wallet problem →** a thrown `PipRailError` with a stable `.code`.
|
|
119
125
|
|
|
126
|
+
> **The agent toolkit funnels all of this.** The `piprail_pay_request` tool catches **every**
|
|
127
|
+
> `PipRailError` and returns a structured `{ ok:false, code, reason, explain, ref?, reasonCode?,
|
|
128
|
+
> declined? }` instead of letting it crash the agent loop — so a broadcast-but-unconfirmed
|
|
129
|
+
> `PAYMENT_TIMEOUT`/`MAX_RETRIES_EXCEEDED`/`CONFIRMATION_TIMEOUT` reaches the model with its `.ref` and
|
|
130
|
+
> the never-re-pay rule (via `explainDecline`). Only a genuine non-`PipRailError` bug rethrows.
|
|
131
|
+
> The pure renderers (`render.ts`) and `classifyChallenge` (`classify.ts`) are viem-free protocol-layer
|
|
132
|
+
> modules; `render.ts`'s VALUE import of `errors.ts` is allowed (errors.ts is chain-agnostic).
|
|
133
|
+
|
|
120
134
|
Observability hooks never change control flow: the gate wraps `onPaid`, and the client routes
|
|
121
135
|
every event through a private `safeEmit()` that swallows handler throws — a logging bug can't
|
|
122
136
|
abort a payment.
|
package/README.md
CHANGED
|
@@ -148,17 +148,53 @@ For **every rail the 402 offers on your chain**, the plan reads **token balance
|
|
|
148
148
|
|
|
149
149
|
```ts
|
|
150
150
|
import { paymentTools } from '@piprail/sdk'
|
|
151
|
-
const tools = paymentTools(client)
|
|
151
|
+
const tools = paymentTools(client)
|
|
152
|
+
// → [piprail_discover, piprail_quote_payment, piprail_plan_payment,
|
|
153
|
+
// piprail_pay_request, piprail_register, piprail_budget, piprail_guide]
|
|
152
154
|
```
|
|
153
155
|
|
|
154
156
|
Each descriptor also carries advisory **`annotations`** (MCP-style `ToolAnnotations` — `title`,
|
|
155
|
-
`readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`): the
|
|
157
|
+
`readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`): the reads are flagged
|
|
156
158
|
**read-only**, `piprail_pay_request` is flagged **value-moving** (the one tool that spends), and
|
|
157
159
|
`piprail_register` is non-destructive — so an MCP client can render the right consent. They're hints,
|
|
158
160
|
not the boundary; the spend policy is. `@piprail/mcp` advertises them on the wire.
|
|
159
161
|
|
|
160
162
|
See [`examples/agent-tools.mjs`](../examples/agent-tools.mjs) for MCP / AI-SDK wiring.
|
|
161
163
|
|
|
164
|
+
### A budget that's also a clock — the time envelope (Mode A)
|
|
165
|
+
|
|
166
|
+
The spend policy already caps *amount* and *total*; it can also bound *time*, so a headless agent
|
|
167
|
+
runs free **inside** a budget **and** time envelope and the policy *is* the consent — no per-pay ask.
|
|
168
|
+
All opt-in; omit them and behaviour is byte-identical.
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
const client = new PipRailClient({
|
|
172
|
+
chain: 'base', wallet,
|
|
173
|
+
policy: {
|
|
174
|
+
maxAmount: '0.10', maxTotal: '5.00', tokens: ['USDC'],
|
|
175
|
+
ttlSeconds: 3600, // the whole session expires in 1h — then EVERY pay is refused
|
|
176
|
+
windowTotal: '1.00', windowSeconds: 600, // …and ≤ $1 of USDC in any rolling 10-minute window
|
|
177
|
+
},
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
client.budget() // → { session: { expiresAt, secondsRemaining }, byAsset: [...] } — read the leash before paying
|
|
181
|
+
client.remaining() // → per-(network,asset) remaining cap (ledger-scoped)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
A pay past the deadline throws `PaymentDeclinedError` with **`reasonCode: 'SESSION_EXPIRED'`** (TERMINAL
|
|
185
|
+
— don't retry); a window breach is `'OUTSIDE_WINDOW'`. The window needs **both** `windowTotal` and
|
|
186
|
+
`windowSeconds` (one alone throws at construction — a leash can't be half-armed). State is in-memory and
|
|
187
|
+
**resets on restart** (the session *is* the process); durable limits are the caller's pluggable concern.
|
|
188
|
+
|
|
189
|
+
### Legible to the model — the decline contract + the guide
|
|
190
|
+
|
|
191
|
+
`piprail_pay_request` funnels **every** failure into a structured `{ ok:false, code, reason, explain,
|
|
192
|
+
ref?, reasonCode?, declined? }` — never an uncaught crash — so a broadcast-but-unconfirmed timeout
|
|
193
|
+
reaches the agent with its `.ref` and the **never-re-pay** rule, not a double-spend. Pure helpers make
|
|
194
|
+
the rest legible: `summarizePlan` / `explainDecline` / `formatSpendReport` (one-line English),
|
|
195
|
+
`classifyChallenge` (wrong-chain vs unpayable-scheme), and `PIPRAIL_AGENT_GUIDE` (the whole contract,
|
|
196
|
+
distilled for an LLM). `piprail_budget` lets the agent self-check its leash; `piprail_guide` returns the contract.
|
|
197
|
+
|
|
162
198
|
## Be discoverable — find and be found ($0, no backend)
|
|
163
199
|
|
|
164
200
|
A 402 endpoint is payable, but nobody can *find* it. PipRail closes that gap by building on the
|
package/STANDARDS.md
CHANGED
|
@@ -109,8 +109,10 @@ npm test # full Vitest suite
|
|
|
109
109
|
npm run build # tsup build succeeds
|
|
110
110
|
# lazy-chunk invariant — the EVM bundle pulls in no non-EVM chain lib:
|
|
111
111
|
grep -E "from ?['\"]@(solana|ton|stellar)" dist/index.js # → expect NO matches
|
|
112
|
-
# viem-free protocol layer — the chain-agnostic core never imports a chain SDK
|
|
113
|
-
|
|
112
|
+
# viem-free protocol layer — the chain-agnostic core never imports a chain SDK
|
|
113
|
+
# (includes the pure agent-ergonomics modules render/classify/agentGuide; render.ts's
|
|
114
|
+
# VALUE import of errors.ts is allowed — errors.ts is chain-agnostic, the grep targets viem):
|
|
115
|
+
grep -lE "from ['\"]viem" src/client.ts src/x402.ts src/policy.ts src/ledger.ts src/server.ts src/agent.ts src/render.ts src/classify.ts src/agentGuide.ts # → expect NO matches
|
|
114
116
|
```
|
|
115
117
|
|
|
116
118
|
`prepublishOnly` runs build + test + both typechecks. Never ship with any of these red.
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkPA6YD3HLcjs = require('./chunk-PA6YD3HL.cjs');
|
|
11
11
|
|
|
12
12
|
// src/drivers/algorand/index.ts
|
|
13
13
|
var _algosdk = require('algosdk'); var _algosdk2 = _interopRequireDefault(_algosdk);
|
|
@@ -55,13 +55,13 @@ async function payAlgorand(params) {
|
|
|
55
55
|
} catch (err) {
|
|
56
56
|
const mapped = mapAlgorandError(err, accept.payTo);
|
|
57
57
|
if (mapped) throw mapped;
|
|
58
|
-
throw _nullishCoalesce(
|
|
58
|
+
throw _nullishCoalesce(_chunkPA6YD3HLcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
function mapAlgorandError(err, payTo) {
|
|
62
62
|
const m = err instanceof Error ? err.message : String(err);
|
|
63
63
|
if (/must optin/i.test(m) || /missing from/i.test(m) && m.includes(payTo)) {
|
|
64
|
-
return new (0,
|
|
64
|
+
return new (0, _chunkPA6YD3HLcjs.RecipientNotReadyError)(
|
|
65
65
|
`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)})`,
|
|
66
66
|
{ cause: err }
|
|
67
67
|
);
|
|
@@ -69,7 +69,7 @@ function mapAlgorandError(err, payTo) {
|
|
|
69
69
|
if (/overspend|below min|min(imum)? balance|tried to spend|balance \d+ below|asset \d+ missing from|insufficient|underflow/i.test(
|
|
70
70
|
m
|
|
71
71
|
)) {
|
|
72
|
-
return new (0,
|
|
72
|
+
return new (0, _chunkPA6YD3HLcjs.InsufficientFundsError)(
|
|
73
73
|
`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)})`,
|
|
74
74
|
{ cause: err }
|
|
75
75
|
);
|
|
@@ -157,22 +157,22 @@ function rpcFailed(nonce) {
|
|
|
157
157
|
|
|
158
158
|
function assertAlgorandWallet(wallet, network) {
|
|
159
159
|
if (typeof wallet !== "object" || wallet === null) {
|
|
160
|
-
throw new (0,
|
|
160
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
161
161
|
`chain ${network} is Algorand; wallet must be { mnemonic } (25 words) or { account }.`
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
164
|
if ("privateKey" in wallet || "walletClient" in wallet) {
|
|
165
|
-
throw new (0,
|
|
165
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
166
166
|
`chain ${network} is Algorand; an EVM/Aptos wallet can't be used \u2014 pass { mnemonic } (25 words) or { account }.`
|
|
167
167
|
);
|
|
168
168
|
}
|
|
169
169
|
if ("secretKey" in wallet || "signer" in wallet || "secret" in wallet || "keypair" in wallet || "keyPair" in wallet || "seed" in wallet || "accountId" in wallet) {
|
|
170
|
-
throw new (0,
|
|
170
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
171
171
|
`chain ${network} is Algorand; that looks like another family's wallet \u2014 pass { mnemonic } (25 words) or { account }.`
|
|
172
172
|
);
|
|
173
173
|
}
|
|
174
174
|
if (!("mnemonic" in wallet) && !("account" in wallet)) {
|
|
175
|
-
throw new (0,
|
|
175
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
176
176
|
`chain ${network} is Algorand; wallet must be { mnemonic } (25 words) or { account }.`
|
|
177
177
|
);
|
|
178
178
|
}
|
|
@@ -187,13 +187,13 @@ function resolveAlgorandWallet(config) {
|
|
|
187
187
|
const { addr, sk } = _algosdk2.default.mnemonicToSecretKey(config.mnemonic);
|
|
188
188
|
return { addr: addr.toString(), sk };
|
|
189
189
|
} catch (cause) {
|
|
190
|
-
throw new (0,
|
|
190
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
191
191
|
"Algorand wallet { mnemonic } is not a valid 25-word Algorand mnemonic.",
|
|
192
192
|
{ cause }
|
|
193
193
|
);
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
throw new (0,
|
|
196
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)("Algorand wallet needs { mnemonic } (25 words) or { account }.");
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
// src/drivers/algorand/index.ts
|
|
@@ -248,16 +248,16 @@ function makeAlgorandNetwork(preset, algodUrl) {
|
|
|
248
248
|
const info = preset.tokens[token.toUpperCase()];
|
|
249
249
|
if (!info) {
|
|
250
250
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
251
|
-
throw new (0,
|
|
251
|
+
throw new (0, _chunkPA6YD3HLcjs.UnknownTokenError)(
|
|
252
252
|
`token "${token}" isn't built in for Algorand (known: ${known}). Pass { assetId, decimals } for a custom ASA, or use 'native'.`
|
|
253
253
|
);
|
|
254
254
|
}
|
|
255
255
|
return { asset: algorandAssetId(info.assetId), decimals: info.decimals, symbol: info.symbol };
|
|
256
256
|
}
|
|
257
|
-
|
|
257
|
+
_chunkPA6YD3HLcjs.rejectForeignToken.call(void 0, token, "algorand", network);
|
|
258
258
|
const t = token;
|
|
259
259
|
if (typeof t.assetId !== "number" || typeof t.decimals !== "number") {
|
|
260
|
-
throw new (0,
|
|
260
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
261
261
|
`chain ${network} is Algorand; a custom token must be { assetId, decimals }.`
|
|
262
262
|
);
|
|
263
263
|
}
|
|
@@ -278,12 +278,12 @@ function makeAlgorandNetwork(preset, algodUrl) {
|
|
|
278
278
|
},
|
|
279
279
|
assertValidPayTo(payTo) {
|
|
280
280
|
if (payTo.startsWith("0x")) {
|
|
281
|
-
throw new (0,
|
|
281
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
282
282
|
`chain ${network} is Algorand, but payTo "${payTo}" looks like an EVM address.`
|
|
283
283
|
);
|
|
284
284
|
}
|
|
285
285
|
if (!_algosdk2.default.isValidAddress(payTo)) {
|
|
286
|
-
throw new (0,
|
|
286
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
287
287
|
`chain ${network} is Algorand, but payTo "${payTo}" is not a valid Algorand address.`
|
|
288
288
|
);
|
|
289
289
|
}
|
|
@@ -300,13 +300,13 @@ function makeAlgorandNetwork(preset, algodUrl) {
|
|
|
300
300
|
const info = await _algosdk2.default.waitForConfirmation(algod, ref, 10);
|
|
301
301
|
return { height: String(_nullishCoalesce(info.confirmedRound, () => ( 0))) };
|
|
302
302
|
} catch (err) {
|
|
303
|
-
throw new (0,
|
|
303
|
+
throw new (0, _chunkPA6YD3HLcjs.ConfirmationTimeoutError)(`Algorand tx ${ref} did not confirm in time.`, {
|
|
304
304
|
cause: err
|
|
305
305
|
});
|
|
306
306
|
}
|
|
307
307
|
},
|
|
308
308
|
async estimateCost() {
|
|
309
|
-
return
|
|
309
|
+
return _chunkPA6YD3HLcjs.nativeCost.call(void 0, {
|
|
310
310
|
symbol: ALGO_SYMBOL,
|
|
311
311
|
decimals: ALGO_DECIMALS,
|
|
312
312
|
fee: 1000n,
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkPA6YD3HLcjs = require('./chunk-PA6YD3HL.cjs');
|
|
10
10
|
|
|
11
11
|
// src/drivers/aptos/index.ts
|
|
12
12
|
var _tssdk = require('@aptos-labs/ts-sdk');
|
|
@@ -55,14 +55,14 @@ async function payAptos(params) {
|
|
|
55
55
|
const res = await client.signSubmit({ signer, transaction });
|
|
56
56
|
return res.hash;
|
|
57
57
|
} catch (err) {
|
|
58
|
-
if (err instanceof
|
|
58
|
+
if (err instanceof _chunkPA6YD3HLcjs.InsufficientFundsError) throw err;
|
|
59
59
|
if (isAptosAffordability(err)) {
|
|
60
|
-
throw new (0,
|
|
60
|
+
throw new (0, _chunkPA6YD3HLcjs.InsufficientFundsError)(
|
|
61
61
|
err instanceof Error ? err.message : "Insufficient APT/token balance for the payment.",
|
|
62
62
|
{ cause: err }
|
|
63
63
|
);
|
|
64
64
|
}
|
|
65
|
-
throw _nullishCoalesce(
|
|
65
|
+
throw _nullishCoalesce(_chunkPA6YD3HLcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
function isAptosAffordability(err) {
|
|
@@ -146,22 +146,22 @@ function txNotFound(hash) {
|
|
|
146
146
|
|
|
147
147
|
function assertAptosWallet(wallet, network) {
|
|
148
148
|
if (typeof wallet !== "object" || wallet === null) {
|
|
149
|
-
throw new (0,
|
|
149
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
150
150
|
`chain ${network} is Aptos; wallet must be { privateKey } (ed25519-priv-0x\u2026) or { account }.`
|
|
151
151
|
);
|
|
152
152
|
}
|
|
153
153
|
if ("walletClient" in wallet) {
|
|
154
|
-
throw new (0,
|
|
154
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
155
155
|
`chain ${network} is Aptos; a viem { walletClient } can't be used \u2014 pass { privateKey } (ed25519-priv-0x\u2026) or { account }.`
|
|
156
156
|
);
|
|
157
157
|
}
|
|
158
158
|
if ("secretKey" in wallet || "signer" in wallet || "mnemonic" in wallet || "keypair" in wallet || "keyPair" in wallet || "secret" in wallet || "seed" in wallet || "accountId" in wallet) {
|
|
159
|
-
throw new (0,
|
|
159
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
160
160
|
`chain ${network} is Aptos; that looks like another family's wallet \u2014 pass { privateKey } (ed25519-priv-0x\u2026) or { account }.`
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
163
|
if (!("privateKey" in wallet) && !("account" in wallet)) {
|
|
164
|
-
throw new (0,
|
|
164
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
165
165
|
`chain ${network} is Aptos; wallet must be { privateKey } (ed25519-priv-0x\u2026) or { account }.`
|
|
166
166
|
);
|
|
167
167
|
}
|
|
@@ -173,13 +173,13 @@ function resolveAptosAccount(config) {
|
|
|
173
173
|
try {
|
|
174
174
|
return _tssdk.Account.fromPrivateKey({ privateKey: new (0, _tssdk.Ed25519PrivateKey)(config.privateKey) });
|
|
175
175
|
} catch (cause) {
|
|
176
|
-
throw new (0,
|
|
176
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
177
177
|
"Aptos wallet { privateKey } is not a valid ed25519 secret (ed25519-priv-0x\u2026 or 0x\u2026 hex).",
|
|
178
178
|
{ cause }
|
|
179
179
|
);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
throw new (0,
|
|
182
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)("Aptos wallet needs { privateKey } (ed25519-priv-0x\u2026) or { account }.");
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
// src/drivers/aptos/index.ts
|
|
@@ -251,16 +251,16 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
251
251
|
const info = preset.tokens[token.toUpperCase()];
|
|
252
252
|
if (!info) {
|
|
253
253
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
254
|
-
throw new (0,
|
|
254
|
+
throw new (0, _chunkPA6YD3HLcjs.UnknownTokenError)(
|
|
255
255
|
`token "${token}" isn't built in for Aptos (known: ${known}). Pass { metadata, decimals } for a custom Fungible Asset, or use 'native'.`
|
|
256
256
|
);
|
|
257
257
|
}
|
|
258
258
|
return { asset: info.metadata, decimals: info.decimals, symbol: info.symbol };
|
|
259
259
|
}
|
|
260
|
-
|
|
260
|
+
_chunkPA6YD3HLcjs.rejectForeignToken.call(void 0, token, "aptos", network);
|
|
261
261
|
const t = token;
|
|
262
262
|
if (!t.metadata || typeof t.decimals !== "number") {
|
|
263
|
-
throw new (0,
|
|
263
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
264
264
|
`chain ${network} is Aptos; a custom token must be { metadata, decimals }.`
|
|
265
265
|
);
|
|
266
266
|
}
|
|
@@ -287,7 +287,7 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
287
287
|
valid = false;
|
|
288
288
|
}
|
|
289
289
|
if (!valid || evmLike) {
|
|
290
|
-
throw new (0,
|
|
290
|
+
throw new (0, _chunkPA6YD3HLcjs.WrongFamilyError)(
|
|
291
291
|
`chain ${network} is Aptos, but payTo "${payTo}" is not a valid Aptos address (0x + 32 bytes).`
|
|
292
292
|
);
|
|
293
293
|
}
|
|
@@ -309,11 +309,11 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
309
309
|
const tx = await aptos.waitForTransaction({ transactionHash: ref });
|
|
310
310
|
return { height: String(_nullishCoalesce(tx.version, () => ( "0"))) };
|
|
311
311
|
} catch (err) {
|
|
312
|
-
throw new (0,
|
|
312
|
+
throw new (0, _chunkPA6YD3HLcjs.ConfirmationTimeoutError)(`Aptos tx ${ref} did not finalize in time.`, { cause: err });
|
|
313
313
|
}
|
|
314
314
|
},
|
|
315
315
|
async estimateCost() {
|
|
316
|
-
return
|
|
316
|
+
return _chunkPA6YD3HLcjs.nativeCost.call(void 0, {
|
|
317
317
|
symbol: APT_SYMBOL,
|
|
318
318
|
decimals: APT_DECIMALS,
|
|
319
319
|
fee: 100000n,
|
|
@@ -53,6 +53,12 @@ var MaxRetriesExceededError = class extends PipRailError {
|
|
|
53
53
|
};
|
|
54
54
|
var PaymentDeclinedError = class extends PipRailError {
|
|
55
55
|
code = "PAYMENT_DECLINED";
|
|
56
|
+
/** Why it was declined, as a typed enum (a hint; `.code` is the reliable channel). */
|
|
57
|
+
reasonCode;
|
|
58
|
+
constructor(message, options) {
|
|
59
|
+
super(message, options);
|
|
60
|
+
this.reasonCode = options?.reasonCode;
|
|
61
|
+
}
|
|
56
62
|
};
|
|
57
63
|
var ConfirmationTimeoutError = class extends PipRailError {
|
|
58
64
|
code = "CONFIRMATION_TIMEOUT";
|
|
@@ -51,37 +51,43 @@ var MaxRetriesExceededError = (_class5 = class extends PipRailError {
|
|
|
51
51
|
this.ref = _optionalChain([options, 'optionalAccess', _2 => _2.ref]);
|
|
52
52
|
}
|
|
53
53
|
}, _class5);
|
|
54
|
-
var PaymentDeclinedError = (_class6 = class extends PipRailError {
|
|
54
|
+
var PaymentDeclinedError = (_class6 = class extends PipRailError {
|
|
55
55
|
__init6() {this.code = "PAYMENT_DECLINED"}
|
|
56
|
+
/** Why it was declined, as a typed enum (a hint; `.code` is the reliable channel). */
|
|
57
|
+
|
|
58
|
+
constructor(message, options) {
|
|
59
|
+
super(message, options);_class6.prototype.__init6.call(this);;
|
|
60
|
+
this.reasonCode = _optionalChain([options, 'optionalAccess', _3 => _3.reasonCode]);
|
|
61
|
+
}
|
|
56
62
|
}, _class6);
|
|
57
|
-
var ConfirmationTimeoutError = (_class7 = class extends PipRailError {constructor(...
|
|
63
|
+
var ConfirmationTimeoutError = (_class7 = class extends PipRailError {constructor(...args4) { super(...args4); _class7.prototype.__init7.call(this); }
|
|
58
64
|
__init7() {this.code = "CONFIRMATION_TIMEOUT"}
|
|
59
65
|
}, _class7);
|
|
60
|
-
var SettlementError = (_class8 = class extends PipRailError {constructor(...
|
|
66
|
+
var SettlementError = (_class8 = class extends PipRailError {constructor(...args5) { super(...args5); _class8.prototype.__init8.call(this); }
|
|
61
67
|
__init8() {this.code = "SETTLEMENT_FAILED"}
|
|
62
68
|
}, _class8);
|
|
63
|
-
var InvalidEnvelopeError = (_class9 = class extends PipRailError {constructor(...
|
|
69
|
+
var InvalidEnvelopeError = (_class9 = class extends PipRailError {constructor(...args6) { super(...args6); _class9.prototype.__init9.call(this); }
|
|
64
70
|
__init9() {this.code = "INVALID_ENVELOPE"}
|
|
65
71
|
}, _class9);
|
|
66
|
-
var NoCompatibleAcceptError = (_class10 = class extends PipRailError {constructor(...
|
|
72
|
+
var NoCompatibleAcceptError = (_class10 = class extends PipRailError {constructor(...args7) { super(...args7); _class10.prototype.__init10.call(this); }
|
|
67
73
|
__init10() {this.code = "NO_COMPATIBLE_ACCEPT"}
|
|
68
74
|
}, _class10);
|
|
69
|
-
var UnsupportedSchemeError = (_class11 = class extends PipRailError {constructor(...
|
|
75
|
+
var UnsupportedSchemeError = (_class11 = class extends PipRailError {constructor(...args8) { super(...args8); _class11.prototype.__init11.call(this); }
|
|
70
76
|
__init11() {this.code = "UNSUPPORTED_SCHEME"}
|
|
71
77
|
}, _class11);
|
|
72
|
-
var NonReplayableBodyError = (_class12 = class extends PipRailError {constructor(...
|
|
78
|
+
var NonReplayableBodyError = (_class12 = class extends PipRailError {constructor(...args9) { super(...args9); _class12.prototype.__init12.call(this); }
|
|
73
79
|
__init12() {this.code = "NON_REPLAYABLE_BODY"}
|
|
74
80
|
}, _class12);
|
|
75
|
-
var WrongFamilyError = (_class13 = class extends PipRailError {constructor(...
|
|
81
|
+
var WrongFamilyError = (_class13 = class extends PipRailError {constructor(...args10) { super(...args10); _class13.prototype.__init13.call(this); }
|
|
76
82
|
__init13() {this.code = "WRONG_FAMILY"}
|
|
77
83
|
}, _class13);
|
|
78
|
-
var UnknownTokenError = (_class14 = class extends PipRailError {constructor(...
|
|
84
|
+
var UnknownTokenError = (_class14 = class extends PipRailError {constructor(...args11) { super(...args11); _class14.prototype.__init14.call(this); }
|
|
79
85
|
__init14() {this.code = "UNKNOWN_TOKEN"}
|
|
80
86
|
}, _class14);
|
|
81
|
-
var MissingDriverError = (_class15 = class extends PipRailError {constructor(...
|
|
87
|
+
var MissingDriverError = (_class15 = class extends PipRailError {constructor(...args12) { super(...args12); _class15.prototype.__init15.call(this); }
|
|
82
88
|
__init15() {this.code = "MISSING_DRIVER"}
|
|
83
89
|
}, _class15);
|
|
84
|
-
var UnsupportedNetworkError = (_class16 = class extends PipRailError {constructor(...
|
|
90
|
+
var UnsupportedNetworkError = (_class16 = class extends PipRailError {constructor(...args13) { super(...args13); _class16.prototype.__init16.call(this); }
|
|
85
91
|
__init16() {this.code = "UNSUPPORTED_NETWORK"}
|
|
86
92
|
}, _class16);
|
|
87
93
|
|