@piprail/sdk 1.25.0 → 2.0.1
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 +50 -0
- package/README.md +4 -4
- package/dist/{algorand-677ILBQS.js → algorand-GSFVZTBF.js} +10 -18
- package/dist/{algorand-ZJ53VCTN.cjs → algorand-HZS43N4P.cjs} +23 -31
- package/dist/{aptos-3TSKTI4D.js → aptos-RIL56C7L.js} +10 -18
- package/dist/{aptos-XIIHPAOO.cjs → aptos-TRCCJRZA.cjs} +22 -30
- package/dist/{chunk-L6WQRHEZ.js → chunk-7XK22JSQ.js} +14 -1
- package/dist/{chunk-U35MG4TF.cjs → chunk-JG6KRAW6.cjs} +15 -2
- package/dist/index.cjs +282 -197
- package/dist/index.d.cts +40 -32
- package/dist/index.d.ts +40 -32
- package/dist/index.js +176 -91
- package/dist/{near-MG256A3E.cjs → near-DI2I3MAV.cjs} +24 -32
- package/dist/{near-TWA4PYOD.js → near-MTYBCUYM.js} +10 -18
- package/dist/{solana-KWNRY5NR.js → solana-E4MD6JJ6.js} +20 -12
- package/dist/{solana-UEMHFQH5.cjs → solana-TLHL2KNY.cjs} +46 -38
- package/dist/{stellar-SCRRPCEA.cjs → stellar-FW6C6FBE.cjs} +28 -38
- package/dist/{stellar-YB7JXKK4.js → stellar-U5NCRIOJ.js} +12 -22
- package/dist/{sui-LFT65OGU.cjs → sui-47C2KEZI.cjs} +23 -31
- package/dist/{sui-IODKU2MA.js → sui-Y53M4GUM.js} +10 -18
- package/dist/{ton-QN5GTOCS.js → ton-5ZPT5PSP.js} +20 -13
- package/dist/{ton-RAYJFKJC.cjs → ton-MMPKWT6N.cjs} +30 -23
- package/dist/{tron-KX4VWS7V.cjs → tron-JOT4STIG.cjs} +33 -38
- package/dist/{tron-QSNCDYRB.js → tron-WYS4X2I5.js} +14 -19
- package/dist/{xrpl-ECHK3GIX.js → xrpl-2MZEOIFY.js} +11 -19
- package/dist/{xrpl-GXUFDXHU.cjs → xrpl-PECT4IMX.cjs} +27 -35
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,54 @@ 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.0.1] — 2026-06-15 — clearer typed errors (robustness; no API change)
|
|
8
|
+
|
|
9
|
+
A patch release hardening error reporting at every wrong-input boundary — found by a
|
|
10
|
+
repo-wide adversarial fuzzing pass. **No behaviour change for correct input**, no API change;
|
|
11
|
+
every fix turns a raw/cryptic library error into a typed `PipRailError` per [`ERRORS.md`](ERRORS.md).
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- **Wallet `{ key }` validation is now uniform + typed.** A malformed or wrong-family key throws a
|
|
16
|
+
clear `WrongFamilyError` instead of leaking a library error:
|
|
17
|
+
- **EVM** — a non-`0x…`/short/garbage key (e.g. a base58 secret, or one missing `0x`) →
|
|
18
|
+
`WrongFamilyError` (was viem's raw `invalid private key, expected hex or 32 bytes`).
|
|
19
|
+
- **Solana** — a `0x…` EVM key or non-base58 secret → `WrongFamilyError` (was `Non-base58 character`).
|
|
20
|
+
- **TON** — an invalid/typo'd mnemonic → `WrongFamilyError` at use (was a silent **wrong-wallet**
|
|
21
|
+
derivation that only failed later as an opaque network error); now validated via `mnemonicValidate`.
|
|
22
|
+
- **A malformed 402 challenge yields a typed `InvalidEnvelopeError`, never a raw `TypeError`.** An
|
|
23
|
+
`accepts[]` entry missing its `extra` block (on an unrecognised token), or a non-string `amount`,
|
|
24
|
+
is now rejected cleanly across `quote` / `estimateCost` / `planPayment` / `canAfford` / `fetch`
|
|
25
|
+
(a recognised token still prices gracefully from the SDK's own decimals).
|
|
26
|
+
- **Read-only agent tools funnel expected errors into a structured result.** `piprail_quote_payment`,
|
|
27
|
+
`piprail_plan_payment`, `piprail_discover`, `piprail_register`, and `piprail_budget` now return
|
|
28
|
+
`{ ok:false, code, reason, explain }` for a typed SDK error (e.g. `WALLET_REQUIRED` on a read-only
|
|
29
|
+
client) — mirroring `piprail_pay_request` — instead of an opaque error; a genuine non-SDK error is
|
|
30
|
+
still re-thrown.
|
|
31
|
+
- **A no-gas wallet's settlement failure maps to `InsufficientFundsError`.** viem's gas-estimation
|
|
32
|
+
shortfall phrasing (`gas required exceeds allowance`) is now classified as `INSUFFICIENT_FUNDS`
|
|
33
|
+
(was a raw multi-line viem dump); an ERC-20 `insufficient allowance` (approve) is deliberately NOT
|
|
34
|
+
mis-classified.
|
|
35
|
+
|
|
36
|
+
## [2.0.0] — 2026-06-15 — one wallet field: `key` (BREAKING)
|
|
37
|
+
|
|
38
|
+
### Changed — the wallet secret is a single `key` field on every chain (BREAKING)
|
|
39
|
+
|
|
40
|
+
- **`WalletInput` is unified.** Every chain now takes `wallet: { key }` — the chain's secret as a
|
|
41
|
+
string. NEAR also keeps `accountId`: `{ accountId, key }`. The per-chain secret field names
|
|
42
|
+
(`privateKey` · `secretKey` · `seed` · `secret` · `mnemonic`) are **removed**.
|
|
43
|
+
- **Migration** — rename the field; the *value* is unchanged:
|
|
44
|
+
`{ privateKey } → { key }`, `{ secretKey } → { key }`, `{ seed } → { key }`,
|
|
45
|
+
`{ secret } → { key }`, `{ mnemonic } → { key }`, `{ accountId, privateKey } → { accountId, key }`.
|
|
46
|
+
Passing a pre-2.0 field name throws a `WrongFamilyError` whose message names the exact `{ key }` fix.
|
|
47
|
+
- **Bring-your-own native signer objects are unchanged** — EVM `{ walletClient }`, Solana `{ signer }`,
|
|
48
|
+
TON `{ keyPair }`, Stellar/Sui `{ keypair }`, XRPL `{ wallet }`, Aptos/Algorand `{ account }`.
|
|
49
|
+
- **Why** — one obvious shape across every chain, the whole point of "name a chain, add a wallet."
|
|
50
|
+
See [Wallets by family](https://docs.piprail.com/making-payments/wallets-by-family/).
|
|
51
|
+
|
|
52
|
+
Nothing else changed: the protocol, drivers, schemes, discovery, spend policy, and every other API
|
|
53
|
+
are identical. Live-verified across 11 mainnet chains with the new `{ key }` shape.
|
|
54
|
+
|
|
7
55
|
## [1.25.0] — 2026-06-15 — more keyless facilitators (live-verified)
|
|
8
56
|
|
|
9
57
|
### Added — `KNOWN_FACILITATORS` grows beyond PayAI
|
|
@@ -1083,6 +1131,8 @@ straight into your wallet. The API is small and self-contained.
|
|
|
1083
1131
|
to your wallet; PipRail never holds funds.
|
|
1084
1132
|
- `viem ^2.21` is a peer dependency. Node 20+ or a modern browser.
|
|
1085
1133
|
|
|
1134
|
+
[2.0.1]: https://www.npmjs.com/package/@piprail/sdk
|
|
1135
|
+
[2.0.0]: https://www.npmjs.com/package/@piprail/sdk
|
|
1086
1136
|
[1.25.0]: https://www.npmjs.com/package/@piprail/sdk
|
|
1087
1137
|
[1.24.0]: https://www.npmjs.com/package/@piprail/sdk
|
|
1088
1138
|
[1.15.1]: https://www.npmjs.com/package/@piprail/sdk
|
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ That route now costs **0.05 USDC on Base**, paid straight to your wallet. One pa
|
|
|
31
31
|
```ts
|
|
32
32
|
import { PipRailClient } from '@piprail/sdk'
|
|
33
33
|
|
|
34
|
-
const client = new PipRailClient({ chain: 'base', wallet: {
|
|
34
|
+
const client = new PipRailClient({ chain: 'base', wallet: { key: process.env.AGENT_KEY } })
|
|
35
35
|
|
|
36
36
|
const res = await client.fetch('https://api.example.com/report') // hits the 402, pays it, retries with proof
|
|
37
37
|
```
|
|
@@ -49,9 +49,9 @@ import { MultiChainPayer } from '@piprail/sdk'
|
|
|
49
49
|
|
|
50
50
|
const payer = MultiChainPayer.fromWallets({
|
|
51
51
|
wallets: {
|
|
52
|
-
base: {
|
|
53
|
-
solana: {
|
|
54
|
-
xrpl: {
|
|
52
|
+
base: { key: process.env.EVM_KEY }, // one EVM key works on every EVM chain
|
|
53
|
+
solana: { key: process.env.SOLANA_KEY },
|
|
54
|
+
xrpl: { key: process.env.XRPL_SEED },
|
|
55
55
|
},
|
|
56
56
|
policy: { maxAmount: '1.00', maxTotal: '10.00', tokens: ['USDC', 'USDT'] }, // one budget, every chain
|
|
57
57
|
})
|
|
@@ -4,10 +4,11 @@ import {
|
|
|
4
4
|
RecipientNotReadyError,
|
|
5
5
|
UnknownTokenError,
|
|
6
6
|
WrongFamilyError,
|
|
7
|
+
assertNoLegacyWalletKey,
|
|
7
8
|
nativeCost,
|
|
8
9
|
rejectForeignToken,
|
|
9
10
|
toInsufficientFundsError
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-7XK22JSQ.js";
|
|
11
12
|
|
|
12
13
|
// src/drivers/algorand/index.ts
|
|
13
14
|
import algosdk2 from "algosdk";
|
|
@@ -158,22 +159,13 @@ import algosdk from "algosdk";
|
|
|
158
159
|
function assertAlgorandWallet(wallet, network) {
|
|
159
160
|
if (typeof wallet !== "object" || wallet === null) {
|
|
160
161
|
throw new WrongFamilyError(
|
|
161
|
-
`chain ${network} is Algorand; wallet must be {
|
|
162
|
+
`chain ${network} is Algorand; wallet must be { key } (25-word mnemonic) or { account }.`
|
|
162
163
|
);
|
|
163
164
|
}
|
|
164
|
-
|
|
165
|
+
assertNoLegacyWalletKey(wallet, "Algorand");
|
|
166
|
+
if (!("key" in wallet) && !("account" in wallet)) {
|
|
165
167
|
throw new WrongFamilyError(
|
|
166
|
-
`chain ${network} is Algorand;
|
|
167
|
-
);
|
|
168
|
-
}
|
|
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 WrongFamilyError(
|
|
171
|
-
`chain ${network} is Algorand; that looks like another family's wallet \u2014 pass { mnemonic } (25 words) or { account }.`
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
if (!("mnemonic" in wallet) && !("account" in wallet)) {
|
|
175
|
-
throw new WrongFamilyError(
|
|
176
|
-
`chain ${network} is Algorand; wallet must be { mnemonic } (25 words) or { account }.`
|
|
168
|
+
`chain ${network} is Algorand; wallet must be { key } (25-word mnemonic) or { account }.`
|
|
177
169
|
);
|
|
178
170
|
}
|
|
179
171
|
return wallet;
|
|
@@ -182,18 +174,18 @@ function resolveAlgorandWallet(config) {
|
|
|
182
174
|
if (config.account) {
|
|
183
175
|
return { addr: String(config.account.addr), sk: config.account.sk };
|
|
184
176
|
}
|
|
185
|
-
if (config.
|
|
177
|
+
if (config.key != null) {
|
|
186
178
|
try {
|
|
187
|
-
const { addr, sk } = algosdk.mnemonicToSecretKey(config.
|
|
179
|
+
const { addr, sk } = algosdk.mnemonicToSecretKey(config.key);
|
|
188
180
|
return { addr: addr.toString(), sk };
|
|
189
181
|
} catch (cause) {
|
|
190
182
|
throw new WrongFamilyError(
|
|
191
|
-
"Algorand wallet {
|
|
183
|
+
"Algorand wallet { key } is not a valid 25-word Algorand mnemonic.",
|
|
192
184
|
{ cause }
|
|
193
185
|
);
|
|
194
186
|
}
|
|
195
187
|
}
|
|
196
|
-
throw new WrongFamilyError("Algorand wallet needs {
|
|
188
|
+
throw new WrongFamilyError("Algorand wallet needs { key } (25-word mnemonic) or { account }.");
|
|
197
189
|
}
|
|
198
190
|
|
|
199
191
|
// src/drivers/algorand/index.ts
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
var _chunkJG6KRAW6cjs = require('./chunk-JG6KRAW6.cjs');
|
|
11
12
|
|
|
12
13
|
// src/drivers/algorand/index.ts
|
|
13
14
|
var _algosdk = require('algosdk'); var _algosdk2 = _interopRequireDefault(_algosdk);
|
|
@@ -55,13 +56,13 @@ async function payAlgorand(params) {
|
|
|
55
56
|
} catch (err) {
|
|
56
57
|
const mapped = mapAlgorandError(err, accept.payTo);
|
|
57
58
|
if (mapped) throw mapped;
|
|
58
|
-
throw _nullishCoalesce(
|
|
59
|
+
throw _nullishCoalesce(_chunkJG6KRAW6cjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
function mapAlgorandError(err, payTo) {
|
|
62
63
|
const m = err instanceof Error ? err.message : String(err);
|
|
63
64
|
if (/must optin/i.test(m) || /missing from/i.test(m) && m.includes(payTo)) {
|
|
64
|
-
return new (0,
|
|
65
|
+
return new (0, _chunkJG6KRAW6cjs.RecipientNotReadyError)(
|
|
65
66
|
`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
67
|
{ cause: err }
|
|
67
68
|
);
|
|
@@ -69,7 +70,7 @@ function mapAlgorandError(err, payTo) {
|
|
|
69
70
|
if (/overspend|below min|min(imum)? balance|tried to spend|balance \d+ below|asset \d+ missing from|insufficient|underflow/i.test(
|
|
70
71
|
m
|
|
71
72
|
)) {
|
|
72
|
-
return new (0,
|
|
73
|
+
return new (0, _chunkJG6KRAW6cjs.InsufficientFundsError)(
|
|
73
74
|
`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
75
|
{ cause: err }
|
|
75
76
|
);
|
|
@@ -157,23 +158,14 @@ function rpcFailed(nonce) {
|
|
|
157
158
|
|
|
158
159
|
function assertAlgorandWallet(wallet, network) {
|
|
159
160
|
if (typeof wallet !== "object" || wallet === null) {
|
|
160
|
-
throw new (0,
|
|
161
|
-
`chain ${network} is Algorand; wallet must be {
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
if ("privateKey" in wallet || "walletClient" in wallet) {
|
|
165
|
-
throw new (0, _chunkU35MG4TFcjs.WrongFamilyError)(
|
|
166
|
-
`chain ${network} is Algorand; an EVM/Aptos wallet can't be used \u2014 pass { mnemonic } (25 words) or { account }.`
|
|
167
|
-
);
|
|
168
|
-
}
|
|
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, _chunkU35MG4TFcjs.WrongFamilyError)(
|
|
171
|
-
`chain ${network} is Algorand; that looks like another family's wallet \u2014 pass { mnemonic } (25 words) or { account }.`
|
|
161
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
162
|
+
`chain ${network} is Algorand; wallet must be { key } (25-word mnemonic) or { account }.`
|
|
172
163
|
);
|
|
173
164
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
165
|
+
_chunkJG6KRAW6cjs.assertNoLegacyWalletKey.call(void 0, wallet, "Algorand");
|
|
166
|
+
if (!("key" in wallet) && !("account" in wallet)) {
|
|
167
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
168
|
+
`chain ${network} is Algorand; wallet must be { key } (25-word mnemonic) or { account }.`
|
|
177
169
|
);
|
|
178
170
|
}
|
|
179
171
|
return wallet;
|
|
@@ -182,18 +174,18 @@ function resolveAlgorandWallet(config) {
|
|
|
182
174
|
if (config.account) {
|
|
183
175
|
return { addr: String(config.account.addr), sk: config.account.sk };
|
|
184
176
|
}
|
|
185
|
-
if (config.
|
|
177
|
+
if (config.key != null) {
|
|
186
178
|
try {
|
|
187
|
-
const { addr, sk } = _algosdk2.default.mnemonicToSecretKey(config.
|
|
179
|
+
const { addr, sk } = _algosdk2.default.mnemonicToSecretKey(config.key);
|
|
188
180
|
return { addr: addr.toString(), sk };
|
|
189
181
|
} catch (cause) {
|
|
190
|
-
throw new (0,
|
|
191
|
-
"Algorand wallet {
|
|
182
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
183
|
+
"Algorand wallet { key } is not a valid 25-word Algorand mnemonic.",
|
|
192
184
|
{ cause }
|
|
193
185
|
);
|
|
194
186
|
}
|
|
195
187
|
}
|
|
196
|
-
throw new (0,
|
|
188
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)("Algorand wallet needs { key } (25-word mnemonic) or { account }.");
|
|
197
189
|
}
|
|
198
190
|
|
|
199
191
|
// src/drivers/algorand/index.ts
|
|
@@ -248,16 +240,16 @@ function makeAlgorandNetwork(preset, algodUrl) {
|
|
|
248
240
|
const info = preset.tokens[token.toUpperCase()];
|
|
249
241
|
if (!info) {
|
|
250
242
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
251
|
-
throw new (0,
|
|
243
|
+
throw new (0, _chunkJG6KRAW6cjs.UnknownTokenError)(
|
|
252
244
|
`token "${token}" isn't built in for Algorand (known: ${known}). Pass { assetId, decimals } for a custom ASA, or use 'native'.`
|
|
253
245
|
);
|
|
254
246
|
}
|
|
255
247
|
return { asset: algorandAssetId(info.assetId), decimals: info.decimals, symbol: info.symbol };
|
|
256
248
|
}
|
|
257
|
-
|
|
249
|
+
_chunkJG6KRAW6cjs.rejectForeignToken.call(void 0, token, "algorand", network);
|
|
258
250
|
const t = token;
|
|
259
251
|
if (typeof t.assetId !== "number" || typeof t.decimals !== "number") {
|
|
260
|
-
throw new (0,
|
|
252
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
261
253
|
`chain ${network} is Algorand; a custom token must be { assetId, decimals }.`
|
|
262
254
|
);
|
|
263
255
|
}
|
|
@@ -278,12 +270,12 @@ function makeAlgorandNetwork(preset, algodUrl) {
|
|
|
278
270
|
},
|
|
279
271
|
assertValidPayTo(payTo) {
|
|
280
272
|
if (payTo.startsWith("0x")) {
|
|
281
|
-
throw new (0,
|
|
273
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
282
274
|
`chain ${network} is Algorand, but payTo "${payTo}" looks like an EVM address.`
|
|
283
275
|
);
|
|
284
276
|
}
|
|
285
277
|
if (!_algosdk2.default.isValidAddress(payTo)) {
|
|
286
|
-
throw new (0,
|
|
278
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
287
279
|
`chain ${network} is Algorand, but payTo "${payTo}" is not a valid Algorand address.`
|
|
288
280
|
);
|
|
289
281
|
}
|
|
@@ -300,13 +292,13 @@ function makeAlgorandNetwork(preset, algodUrl) {
|
|
|
300
292
|
const info = await _algosdk2.default.waitForConfirmation(algod, ref, 10);
|
|
301
293
|
return { height: String(_nullishCoalesce(info.confirmedRound, () => ( 0))) };
|
|
302
294
|
} catch (err) {
|
|
303
|
-
throw new (0,
|
|
295
|
+
throw new (0, _chunkJG6KRAW6cjs.ConfirmationTimeoutError)(`Algorand tx ${ref} did not confirm in time.`, {
|
|
304
296
|
cause: err
|
|
305
297
|
});
|
|
306
298
|
}
|
|
307
299
|
},
|
|
308
300
|
async estimateCost() {
|
|
309
|
-
return
|
|
301
|
+
return _chunkJG6KRAW6cjs.nativeCost.call(void 0, {
|
|
310
302
|
symbol: ALGO_SYMBOL,
|
|
311
303
|
decimals: ALGO_DECIMALS,
|
|
312
304
|
fee: 1000n,
|
|
@@ -3,10 +3,11 @@ import {
|
|
|
3
3
|
InsufficientFundsError,
|
|
4
4
|
UnknownTokenError,
|
|
5
5
|
WrongFamilyError,
|
|
6
|
+
assertNoLegacyWalletKey,
|
|
6
7
|
nativeCost,
|
|
7
8
|
rejectForeignToken,
|
|
8
9
|
toInsufficientFundsError
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-7XK22JSQ.js";
|
|
10
11
|
|
|
11
12
|
// src/drivers/aptos/index.ts
|
|
12
13
|
import { Aptos, AptosConfig, Network, AccountAddress } from "@aptos-labs/ts-sdk";
|
|
@@ -147,39 +148,30 @@ import { Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
|
|
|
147
148
|
function assertAptosWallet(wallet, network) {
|
|
148
149
|
if (typeof wallet !== "object" || wallet === null) {
|
|
149
150
|
throw new WrongFamilyError(
|
|
150
|
-
`chain ${network} is Aptos; wallet must be {
|
|
151
|
+
`chain ${network} is Aptos; wallet must be { key } (ed25519-priv-0x\u2026) or { account }.`
|
|
151
152
|
);
|
|
152
153
|
}
|
|
153
|
-
|
|
154
|
+
assertNoLegacyWalletKey(wallet, "Aptos");
|
|
155
|
+
if (!("key" in wallet) && !("account" in wallet)) {
|
|
154
156
|
throw new WrongFamilyError(
|
|
155
|
-
`chain ${network} is Aptos;
|
|
156
|
-
);
|
|
157
|
-
}
|
|
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 WrongFamilyError(
|
|
160
|
-
`chain ${network} is Aptos; that looks like another family's wallet \u2014 pass { privateKey } (ed25519-priv-0x\u2026) or { account }.`
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
if (!("privateKey" in wallet) && !("account" in wallet)) {
|
|
164
|
-
throw new WrongFamilyError(
|
|
165
|
-
`chain ${network} is Aptos; wallet must be { privateKey } (ed25519-priv-0x\u2026) or { account }.`
|
|
157
|
+
`chain ${network} is Aptos; wallet must be { key } (ed25519-priv-0x\u2026) or { account }.`
|
|
166
158
|
);
|
|
167
159
|
}
|
|
168
160
|
return wallet;
|
|
169
161
|
}
|
|
170
162
|
function resolveAptosAccount(config) {
|
|
171
163
|
if (config.account) return config.account;
|
|
172
|
-
if (config.
|
|
164
|
+
if (config.key != null) {
|
|
173
165
|
try {
|
|
174
|
-
return Account.fromPrivateKey({ privateKey: new Ed25519PrivateKey(config.
|
|
166
|
+
return Account.fromPrivateKey({ privateKey: new Ed25519PrivateKey(config.key) });
|
|
175
167
|
} catch (cause) {
|
|
176
168
|
throw new WrongFamilyError(
|
|
177
|
-
"Aptos wallet {
|
|
169
|
+
"Aptos wallet { key } is not a valid ed25519 secret (ed25519-priv-0x\u2026 or 0x\u2026 hex).",
|
|
178
170
|
{ cause }
|
|
179
171
|
);
|
|
180
172
|
}
|
|
181
173
|
}
|
|
182
|
-
throw new WrongFamilyError("Aptos wallet needs {
|
|
174
|
+
throw new WrongFamilyError("Aptos wallet needs { key } (ed25519-priv-0x\u2026) or { account }.");
|
|
183
175
|
}
|
|
184
176
|
|
|
185
177
|
// src/drivers/aptos/index.ts
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
var _chunkJG6KRAW6cjs = require('./chunk-JG6KRAW6.cjs');
|
|
10
11
|
|
|
11
12
|
// src/drivers/aptos/index.ts
|
|
12
13
|
var _tssdk = require('@aptos-labs/ts-sdk');
|
|
@@ -55,14 +56,14 @@ async function payAptos(params) {
|
|
|
55
56
|
const res = await client.signSubmit({ signer, transaction });
|
|
56
57
|
return res.hash;
|
|
57
58
|
} catch (err) {
|
|
58
|
-
if (err instanceof
|
|
59
|
+
if (err instanceof _chunkJG6KRAW6cjs.InsufficientFundsError) throw err;
|
|
59
60
|
if (isAptosAffordability(err)) {
|
|
60
|
-
throw new (0,
|
|
61
|
+
throw new (0, _chunkJG6KRAW6cjs.InsufficientFundsError)(
|
|
61
62
|
err instanceof Error ? err.message : "Insufficient APT/token balance for the payment.",
|
|
62
63
|
{ cause: err }
|
|
63
64
|
);
|
|
64
65
|
}
|
|
65
|
-
throw _nullishCoalesce(
|
|
66
|
+
throw _nullishCoalesce(_chunkJG6KRAW6cjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
function isAptosAffordability(err) {
|
|
@@ -146,40 +147,31 @@ function txNotFound(hash) {
|
|
|
146
147
|
|
|
147
148
|
function assertAptosWallet(wallet, network) {
|
|
148
149
|
if (typeof wallet !== "object" || wallet === null) {
|
|
149
|
-
throw new (0,
|
|
150
|
-
`chain ${network} is Aptos; wallet must be {
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
if ("walletClient" in wallet) {
|
|
154
|
-
throw new (0, _chunkU35MG4TFcjs.WrongFamilyError)(
|
|
155
|
-
`chain ${network} is Aptos; a viem { walletClient } can't be used \u2014 pass { privateKey } (ed25519-priv-0x\u2026) or { account }.`
|
|
156
|
-
);
|
|
157
|
-
}
|
|
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, _chunkU35MG4TFcjs.WrongFamilyError)(
|
|
160
|
-
`chain ${network} is Aptos; that looks like another family's wallet \u2014 pass { privateKey } (ed25519-priv-0x\u2026) or { account }.`
|
|
150
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
151
|
+
`chain ${network} is Aptos; wallet must be { key } (ed25519-priv-0x\u2026) or { account }.`
|
|
161
152
|
);
|
|
162
153
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
154
|
+
_chunkJG6KRAW6cjs.assertNoLegacyWalletKey.call(void 0, wallet, "Aptos");
|
|
155
|
+
if (!("key" in wallet) && !("account" in wallet)) {
|
|
156
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
157
|
+
`chain ${network} is Aptos; wallet must be { key } (ed25519-priv-0x\u2026) or { account }.`
|
|
166
158
|
);
|
|
167
159
|
}
|
|
168
160
|
return wallet;
|
|
169
161
|
}
|
|
170
162
|
function resolveAptosAccount(config) {
|
|
171
163
|
if (config.account) return config.account;
|
|
172
|
-
if (config.
|
|
164
|
+
if (config.key != null) {
|
|
173
165
|
try {
|
|
174
|
-
return _tssdk.Account.fromPrivateKey({ privateKey: new (0, _tssdk.Ed25519PrivateKey)(config.
|
|
166
|
+
return _tssdk.Account.fromPrivateKey({ privateKey: new (0, _tssdk.Ed25519PrivateKey)(config.key) });
|
|
175
167
|
} catch (cause) {
|
|
176
|
-
throw new (0,
|
|
177
|
-
"Aptos wallet {
|
|
168
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
169
|
+
"Aptos wallet { key } is not a valid ed25519 secret (ed25519-priv-0x\u2026 or 0x\u2026 hex).",
|
|
178
170
|
{ cause }
|
|
179
171
|
);
|
|
180
172
|
}
|
|
181
173
|
}
|
|
182
|
-
throw new (0,
|
|
174
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)("Aptos wallet needs { key } (ed25519-priv-0x\u2026) or { account }.");
|
|
183
175
|
}
|
|
184
176
|
|
|
185
177
|
// src/drivers/aptos/index.ts
|
|
@@ -251,16 +243,16 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
251
243
|
const info = preset.tokens[token.toUpperCase()];
|
|
252
244
|
if (!info) {
|
|
253
245
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
254
|
-
throw new (0,
|
|
246
|
+
throw new (0, _chunkJG6KRAW6cjs.UnknownTokenError)(
|
|
255
247
|
`token "${token}" isn't built in for Aptos (known: ${known}). Pass { metadata, decimals } for a custom Fungible Asset, or use 'native'.`
|
|
256
248
|
);
|
|
257
249
|
}
|
|
258
250
|
return { asset: info.metadata, decimals: info.decimals, symbol: info.symbol };
|
|
259
251
|
}
|
|
260
|
-
|
|
252
|
+
_chunkJG6KRAW6cjs.rejectForeignToken.call(void 0, token, "aptos", network);
|
|
261
253
|
const t = token;
|
|
262
254
|
if (!t.metadata || typeof t.decimals !== "number") {
|
|
263
|
-
throw new (0,
|
|
255
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
264
256
|
`chain ${network} is Aptos; a custom token must be { metadata, decimals }.`
|
|
265
257
|
);
|
|
266
258
|
}
|
|
@@ -287,7 +279,7 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
287
279
|
valid = false;
|
|
288
280
|
}
|
|
289
281
|
if (!valid || evmLike) {
|
|
290
|
-
throw new (0,
|
|
282
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
291
283
|
`chain ${network} is Aptos, but payTo "${payTo}" is not a valid Aptos address (0x + 32 bytes).`
|
|
292
284
|
);
|
|
293
285
|
}
|
|
@@ -309,11 +301,11 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
309
301
|
const tx = await aptos.waitForTransaction({ transactionHash: ref });
|
|
310
302
|
return { height: String(_nullishCoalesce(tx.version, () => ( "0"))) };
|
|
311
303
|
} catch (err) {
|
|
312
|
-
throw new (0,
|
|
304
|
+
throw new (0, _chunkJG6KRAW6cjs.ConfirmationTimeoutError)(`Aptos tx ${ref} did not finalize in time.`, { cause: err });
|
|
313
305
|
}
|
|
314
306
|
},
|
|
315
307
|
async estimateCost() {
|
|
316
|
-
return
|
|
308
|
+
return _chunkJG6KRAW6cjs.nativeCost.call(void 0, {
|
|
317
309
|
symbol: APT_SYMBOL,
|
|
318
310
|
decimals: APT_DECIMALS,
|
|
319
311
|
fee: 100000n,
|
|
@@ -13,7 +13,7 @@ var RecipientNotReadyError = class extends PipRailError {
|
|
|
13
13
|
};
|
|
14
14
|
function toInsufficientFundsError(err) {
|
|
15
15
|
const message = err instanceof Error ? err.message : String(err);
|
|
16
|
-
if (/insufficient (funds|balance|lamports|fee)|not enough|exceeds (the )?balance|underfunded|low[_ ]?reserve|debit the account/i.test(
|
|
16
|
+
if (/insufficient (funds|balance|lamports|fee)|not enough|exceeds (the )?balance|underfunded|low[_ ]?reserve|debit the account|gas required exceeds (the )?allowance/i.test(
|
|
17
17
|
message
|
|
18
18
|
)) {
|
|
19
19
|
return new InsufficientFundsError(
|
|
@@ -174,6 +174,18 @@ function nativeCost(opts) {
|
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
// src/drivers/wallet-migrate.ts
|
|
178
|
+
var LEGACY_WALLET_FIELDS = ["privateKey", "secretKey", "seed", "secret", "mnemonic"];
|
|
179
|
+
function assertNoLegacyWalletKey(wallet, family) {
|
|
180
|
+
for (const f of LEGACY_WALLET_FIELDS) {
|
|
181
|
+
if (f in wallet) {
|
|
182
|
+
throw new WrongFamilyError(
|
|
183
|
+
`${family} wallet: PipRail v2 unified the wallet secret to a single field \u2014 replace { ${f} } with { key }` + (family === "NEAR" ? " ({ accountId, key })" : "") + "."
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
177
189
|
export {
|
|
178
190
|
PipRailError,
|
|
179
191
|
InsufficientFundsError,
|
|
@@ -194,6 +206,7 @@ export {
|
|
|
194
206
|
UnknownTokenError,
|
|
195
207
|
MissingDriverError,
|
|
196
208
|
UnsupportedNetworkError,
|
|
209
|
+
assertNoLegacyWalletKey,
|
|
197
210
|
rejectForeignToken,
|
|
198
211
|
parseUnits,
|
|
199
212
|
floorUnits,
|
|
@@ -13,7 +13,7 @@ var RecipientNotReadyError = (_class2 = class extends PipRailError {constructor(
|
|
|
13
13
|
}, _class2);
|
|
14
14
|
function toInsufficientFundsError(err) {
|
|
15
15
|
const message = err instanceof Error ? err.message : String(err);
|
|
16
|
-
if (/insufficient (funds|balance|lamports|fee)|not enough|exceeds (the )?balance|underfunded|low[_ ]?reserve|debit the account/i.test(
|
|
16
|
+
if (/insufficient (funds|balance|lamports|fee)|not enough|exceeds (the )?balance|underfunded|low[_ ]?reserve|debit the account|gas required exceeds (the )?allowance/i.test(
|
|
17
17
|
message
|
|
18
18
|
)) {
|
|
19
19
|
return new InsufficientFundsError(
|
|
@@ -174,6 +174,19 @@ function nativeCost(opts) {
|
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
// src/drivers/wallet-migrate.ts
|
|
178
|
+
var LEGACY_WALLET_FIELDS = ["privateKey", "secretKey", "seed", "secret", "mnemonic"];
|
|
179
|
+
function assertNoLegacyWalletKey(wallet, family) {
|
|
180
|
+
for (const f of LEGACY_WALLET_FIELDS) {
|
|
181
|
+
if (f in wallet) {
|
|
182
|
+
throw new WrongFamilyError(
|
|
183
|
+
`${family} wallet: PipRail v2 unified the wallet secret to a single field \u2014 replace { ${f} } with { key }` + (family === "NEAR" ? " ({ accountId, key })" : "") + "."
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
|
|
177
190
|
|
|
178
191
|
|
|
179
192
|
|
|
@@ -199,4 +212,4 @@ function nativeCost(opts) {
|
|
|
199
212
|
|
|
200
213
|
|
|
201
214
|
|
|
202
|
-
exports.PipRailError = PipRailError; exports.InsufficientFundsError = InsufficientFundsError; exports.RecipientNotReadyError = RecipientNotReadyError; exports.toInsufficientFundsError = toInsufficientFundsError; exports.WrongChainError = WrongChainError; exports.PaymentTimeoutError = PaymentTimeoutError; exports.MaxRetriesExceededError = MaxRetriesExceededError; exports.PaymentDeclinedError = PaymentDeclinedError; exports.ConfirmationTimeoutError = ConfirmationTimeoutError; exports.SettlementError = SettlementError; exports.InvalidEnvelopeError = InvalidEnvelopeError; exports.NoCompatibleAcceptError = NoCompatibleAcceptError; exports.UnsupportedSchemeError = UnsupportedSchemeError; exports.NonReplayableBodyError = NonReplayableBodyError; exports.WalletRequiredError = WalletRequiredError; exports.WrongFamilyError = WrongFamilyError; exports.UnknownTokenError = UnknownTokenError; exports.MissingDriverError = MissingDriverError; exports.UnsupportedNetworkError = UnsupportedNetworkError; exports.rejectForeignToken = rejectForeignToken; exports.parseUnits = parseUnits; exports.floorUnits = floorUnits; exports.formatUnits = formatUnits; exports.nativeCost = nativeCost;
|
|
215
|
+
exports.PipRailError = PipRailError; exports.InsufficientFundsError = InsufficientFundsError; exports.RecipientNotReadyError = RecipientNotReadyError; exports.toInsufficientFundsError = toInsufficientFundsError; exports.WrongChainError = WrongChainError; exports.PaymentTimeoutError = PaymentTimeoutError; exports.MaxRetriesExceededError = MaxRetriesExceededError; exports.PaymentDeclinedError = PaymentDeclinedError; exports.ConfirmationTimeoutError = ConfirmationTimeoutError; exports.SettlementError = SettlementError; exports.InvalidEnvelopeError = InvalidEnvelopeError; exports.NoCompatibleAcceptError = NoCompatibleAcceptError; exports.UnsupportedSchemeError = UnsupportedSchemeError; exports.NonReplayableBodyError = NonReplayableBodyError; exports.WalletRequiredError = WalletRequiredError; exports.WrongFamilyError = WrongFamilyError; exports.UnknownTokenError = UnknownTokenError; exports.MissingDriverError = MissingDriverError; exports.UnsupportedNetworkError = UnsupportedNetworkError; exports.assertNoLegacyWalletKey = assertNoLegacyWalletKey; exports.rejectForeignToken = rejectForeignToken; exports.parseUnits = parseUnits; exports.floorUnits = floorUnits; exports.formatUnits = formatUnits; exports.nativeCost = nativeCost;
|