@qntx/wallet-chains 0.12.0 → 0.14.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.
Files changed (62) hide show
  1. package/README.md +13 -10
  2. package/dist/{account-ref-D2rW_qlI.mjs → account-ref-BFTeEyHt.mjs} +2 -2
  3. package/dist/{account-ref-D2rW_qlI.mjs.map → account-ref-BFTeEyHt.mjs.map} +1 -1
  4. package/dist/assemble-8GvNDony.mjs +405 -0
  5. package/dist/assemble-8GvNDony.mjs.map +1 -0
  6. package/dist/assemble-B3sO9Fvc.mjs +629 -0
  7. package/dist/assemble-B3sO9Fvc.mjs.map +1 -0
  8. package/dist/assemble-BdiPo0ZX.mjs +32 -0
  9. package/dist/assemble-BdiPo0ZX.mjs.map +1 -0
  10. package/dist/assets-sg2_Z3nZ.mjs +200 -0
  11. package/dist/assets-sg2_Z3nZ.mjs.map +1 -0
  12. package/dist/bitcoin-sign.d.mts +3 -0
  13. package/dist/bitcoin-sign.mjs +52 -18
  14. package/dist/bitcoin-sign.mjs.map +1 -1
  15. package/dist/bitcoin.d.mts +123 -7
  16. package/dist/bitcoin.mjs +162 -69
  17. package/dist/bitcoin.mjs.map +1 -1
  18. package/dist/evm-sign.d.mts +3 -1
  19. package/dist/evm-sign.mjs +25 -82
  20. package/dist/evm-sign.mjs.map +1 -1
  21. package/dist/evm.d.mts +252 -22
  22. package/dist/evm.mjs +2460 -448
  23. package/dist/evm.mjs.map +1 -1
  24. package/dist/families-BlgplKAJ.mjs +412 -0
  25. package/dist/families-BlgplKAJ.mjs.map +1 -0
  26. package/dist/index-CIRaHKpx.d.mts +941 -0
  27. package/dist/index.d.mts +2 -2
  28. package/dist/index.mjs +1 -1
  29. package/dist/networks.d.mts +29 -0
  30. package/dist/networks.mjs +245 -0
  31. package/dist/networks.mjs.map +1 -0
  32. package/dist/plan-wCnxHqRu.mjs +1311 -0
  33. package/dist/plan-wCnxHqRu.mjs.map +1 -0
  34. package/dist/solana-sign.d.mts +3 -0
  35. package/dist/solana-sign.mjs +23 -10
  36. package/dist/solana-sign.mjs.map +1 -1
  37. package/dist/solana.d.mts +136 -24
  38. package/dist/solana.mjs +1244 -63
  39. package/dist/solana.mjs.map +1 -1
  40. package/dist/src-CHB_z45M.mjs +387 -0
  41. package/dist/src-CHB_z45M.mjs.map +1 -0
  42. package/dist/tasks-7AFv3PQn.mjs +86 -0
  43. package/dist/tasks-7AFv3PQn.mjs.map +1 -0
  44. package/dist/token-call-DH22g8BL.mjs +914 -0
  45. package/dist/token-call-DH22g8BL.mjs.map +1 -0
  46. package/dist/tron-sign.d.mts +10 -0
  47. package/dist/tron-sign.mjs +36 -0
  48. package/dist/tron-sign.mjs.map +1 -0
  49. package/dist/tron.d.mts +328 -0
  50. package/dist/tron.mjs +1484 -0
  51. package/dist/tron.mjs.map +1 -0
  52. package/dist/typed-data-CE9h4U0F.d.mts +51 -0
  53. package/dist/typed-data-DRtKULsH.mjs +466 -0
  54. package/dist/typed-data-DRtKULsH.mjs.map +1 -0
  55. package/package.json +17 -10
  56. package/dist/index-DYwm4-Ec.d.mts +0 -256
  57. package/dist/message-ChhEZ0lx.mjs +0 -188
  58. package/dist/message-ChhEZ0lx.mjs.map +0 -1
  59. package/dist/src-8NZeEnrW.mjs +0 -67
  60. package/dist/src-8NZeEnrW.mjs.map +0 -1
  61. package/dist/typed-data-J5g2WemC.mjs +0 -227
  62. package/dist/typed-data-J5g2WemC.mjs.map +0 -1
@@ -0,0 +1,629 @@
1
+ import { t as ChainError } from "./src-CHB_z45M.mjs";
2
+ import { r as lookupEvmToken, t as EVM_NATIVE_ASSET } from "./assets-sg2_Z3nZ.mjs";
3
+ import { D as checksumEvmAddress, b as networkChainId, g as assertHex$1, s as parseTypedData } from "./typed-data-DRtKULsH.mjs";
4
+ import { a as signaturesOf, n as acceptEcdsa } from "./tasks-7AFv3PQn.mjs";
5
+ import { keccak_256 } from "@noble/hashes/sha3.js";
6
+ import { bytesToHex, hexToBytes, utf8ToBytes } from "@noble/hashes/utils.js";
7
+ import * as AbiFunction from "ox/AbiFunction";
8
+ import * as Hex from "ox/Hex";
9
+ import * as TypedData from "ox/TypedData";
10
+ import * as Authorization from "ox/Authorization";
11
+ import * as PersonalMessage from "ox/PersonalMessage";
12
+ import * as Signature from "ox/Signature";
13
+ import * as TxEnvelopeEip1559 from "ox/TxEnvelopeEip1559";
14
+ import * as TxEnvelopeEip2930 from "ox/TxEnvelopeEip2930";
15
+ import * as TxEnvelopeEip7702 from "ox/TxEnvelopeEip7702";
16
+ import * as TxEnvelopeLegacy from "ox/TxEnvelopeLegacy";
17
+ // src/evm/fiat24.ts
18
+ /**
19
+ * The Fiat24 contracts (SR Saphirstein AG) the decoder recognises by address — Arbitrum One only.
20
+ * The pinned proxies come from the issuer's own list
21
+ * (https://docs.fiat24.com/developer/integration-guide/part-1-smart-contracts.md) re-read on chain
22
+ * at block 526439604: EIP-1967 implementation slots, symbol()/decimals() — Sourcify full matches,
23
+ * solc 0.8.18.
24
+ */
25
+ const FIAT24_CHAIN = 42161;
26
+ /** The ERC-721 "Fiat24 Account" — each token id is a client account. */
27
+ const FIAT24_ACCOUNT = "0x133CAEecA096cA54889db71956c7f75862Ead7A0";
28
+ /** The FX/top-up contract (Fiat24CryptoDeposit). */
29
+ const FIAT24_DEPOSIT = "0x4582f67698843Dfb6A9F195C0dDee05B0A8C973F";
30
+ /** The card-authorisation contract (Fiat24CardAuthorizationMarqeta). */
31
+ const FIAT24_CARD = "0xe2e3B88B9893e18D0867c08f9cA93f8aB5935b14";
32
+ /**
33
+ * The F24 utility token `mintByClient` burns at the issuer-set account price (Fiat24Account.sol:96
34
+ * `f24.burnFrom(msg.sender, fiat24PriceList.getPrice(_tokenId))`; the deposit contract's `f24()`
35
+ * getter returns this address on chain; Sourcify exact match —
36
+ * https://sourcify.dev/server/v2/contract/42161/0x22043fDdF353308B4F2e7dA2e5284E4D087449e1).
37
+ */
38
+ const F24_BURN = {
39
+ asset: "0x22043fDdF353308B4F2e7dA2e5284E4D087449e1",
40
+ symbol: "F24",
41
+ decimals: 2
42
+ };
43
+ /**
44
+ * The four cash tokens, keyed by lowercase address; each carries its checksummed form. All four
45
+ * share the one Fiat24Token.sol source and `decimals()` is the constant 2 (Fiat24Token.sol:256-258;
46
+ * issuer list above).
47
+ */
48
+ const FIAT24_TOKENS = {
49
+ "0xbe00f3db78688d9704bcb4e0a827aea3a9cc0d62": {
50
+ address: "0xbE00f3db78688d9704BCb4e0a827aea3a9Cc0D62",
51
+ symbol: "USD24"
52
+ },
53
+ "0x2c5d06f591d0d8cd43ac232c2b654475a142c7da": {
54
+ address: "0x2c5d06f591D0d8cd43Ac232c2B654475a142c7DA",
55
+ symbol: "EUR24"
56
+ },
57
+ "0xd41f1f0cf89fd239ca4c1f8e8ada46345c86b0a4": {
58
+ address: "0xd41F1f0cf89fD239ca4c1F8E8ADA46345c86b0a4",
59
+ symbol: "CHF24"
60
+ },
61
+ "0x7288ac74d211735374a23707d1518dcbbc0144fd": {
62
+ address: "0x7288Ac74d211735374A23707D1518DCbbc0144fd",
63
+ symbol: "CNH24"
64
+ }
65
+ };
66
+ const isInternalAccount = (account) => account.toString(10).startsWith("9");
67
+ const TRANSFER_BY_ACCOUNT_ID = AbiFunction.from("function transferByAccountId(uint256 accountId, uint256 amount)");
68
+ const CLIENT_PAYOUT = AbiFunction.from("function clientPayout(uint256 amount, string contactId)");
69
+ const CLIENT_PAYOUT_REF = AbiFunction.from("function clientPayoutRef(uint256 amount, string contactId, uint256 purposeId, string ref)");
70
+ const MONEY_EXCHANGE_EXACT_IN = AbiFunction.from("function moneyExchangeExactIn(address input, address output, uint256 amount)");
71
+ const MONEY_EXCHANGE_EXACT_OUT = AbiFunction.from("function moneyExchangeExactOut(address input, address output, uint256 amount)");
72
+ const DEPOSIT_TOKEN_VIA_USDC = AbiFunction.from("function depositTokenViaUsdc(address input, address output, uint256 amount)");
73
+ const DEPOSIT_ETH = AbiFunction.from("function depositETH(address output) payable");
74
+ const DEPOSIT_TOKEN_VIA_ETH = AbiFunction.from("function depositTokenViaEth(address input, address output, uint256 amount)");
75
+ const MINT_BY_CLIENT = AbiFunction.from("function mintByClient(uint256 tokenId)");
76
+ const MINT_BY_CLIENT_WITH_ETH = AbiFunction.from("function mintByClientWithETH(uint256 tokenId) payable");
77
+ const ACCOUNT_TRANSFER_FROM = AbiFunction.from("function transferFrom(address from, address to, uint256 tokenId)");
78
+ const ACCOUNT_SAFE_TRANSFER = AbiFunction.from("function safeTransferFrom(address from, address to, uint256 tokenId)");
79
+ const ACCOUNT_SAFE_TRANSFER_DATA = AbiFunction.from("function safeTransferFrom(address from, address to, uint256 tokenId, bytes data)");
80
+ const FIAT24_SELECTORS = new Set([
81
+ TRANSFER_BY_ACCOUNT_ID,
82
+ CLIENT_PAYOUT,
83
+ CLIENT_PAYOUT_REF,
84
+ MONEY_EXCHANGE_EXACT_IN,
85
+ MONEY_EXCHANGE_EXACT_OUT,
86
+ DEPOSIT_TOKEN_VIA_USDC,
87
+ DEPOSIT_ETH,
88
+ DEPOSIT_TOKEN_VIA_ETH,
89
+ MINT_BY_CLIENT,
90
+ MINT_BY_CLIENT_WITH_ETH
91
+ ].map((fn) => AbiFunction.getSelector(fn)));
92
+ const ERC20_SELECTORS = new Set([
93
+ "function transfer(address to, uint256 amount)",
94
+ "function approve(address spender, uint256 amount)",
95
+ "function increaseAllowance(address spender, uint256 amount)",
96
+ "function decreaseAllowance(address spender, uint256 amount)",
97
+ "function transferFrom(address from, address to, uint256 amount)"
98
+ ].map((signature) => AbiFunction.getSelector(signature)));
99
+ const FIAT24_CONTRACTS = new Set([
100
+ FIAT24_ACCOUNT,
101
+ FIAT24_DEPOSIT,
102
+ FIAT24_CARD,
103
+ ...Object.keys(FIAT24_TOKENS)
104
+ ].map((a) => a.toLowerCase()));
105
+ /** `to` is one of the seven pinned Fiat24 proxies on Arbitrum One. */
106
+ const isFiat24Contract = (chainId, to) => chainId === 42161 && FIAT24_CONTRACTS.has(to.toLowerCase());
107
+ /** `data` starts with a Fiat24-specific selector (any callee, any chain). */
108
+ const hasFiat24Selector = (data) => FIAT24_SELECTORS.has(data.slice(0, 10).toLowerCase());
109
+ /** The spender's role when it is a Fiat24 contract on Arbitrum One. */
110
+ const fiat24Spender = (chainId, spender) => {
111
+ if (chainId !== 42161) return;
112
+ const address = spender.toLowerCase();
113
+ return address === "0xe2e3B88B9893e18D0867c08f9cA93f8aB5935b14".toLowerCase() ? "card" : address === "0x4582f67698843Dfb6A9F195C0dDee05B0A8C973F".toLowerCase() ? "deposit" : void 0;
114
+ };
115
+ /** Canonical-encoding decode like `tryCall` in decode.ts — undefined on any mismatch. */
116
+ const tryCall = (fn, data) => {
117
+ const selector = AbiFunction.getSelector(fn);
118
+ if (!data.toLowerCase().startsWith(selector)) return;
119
+ try {
120
+ assertHex$1(data, "data");
121
+ const args = AbiFunction.decodeData(fn, data);
122
+ if (!Array.isArray(args)) return;
123
+ return AbiFunction.encodeData(fn, args).toLowerCase() === data.toLowerCase() ? args : void 0;
124
+ } catch {
125
+ return;
126
+ }
127
+ };
128
+ const argUint = (args, index) => {
129
+ const value = args[index];
130
+ if (typeof value !== "bigint") throw new ChainError("invalid-request", "decoded argument is not a uint256");
131
+ return value;
132
+ };
133
+ const argAddress = (args, index) => {
134
+ const value = args[index];
135
+ if (typeof value !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(value)) throw new ChainError("invalid-request", "decoded argument is not an address");
136
+ return checksumEvmAddress(value);
137
+ };
138
+ const argString = (args, index) => {
139
+ const value = args[index];
140
+ if (typeof value !== "string") throw new ChainError("invalid-request", "decoded argument is not a string");
141
+ return value;
142
+ };
143
+ const runCases = (cases, call) => {
144
+ for (const c of cases) {
145
+ const args = tryCall(c.fn, call.data);
146
+ if (args === void 0) continue;
147
+ if (c.payable === true ? call.value === 0n : call.value > 0n) return "claimed";
148
+ const decoded = c.run(args, call);
149
+ return decoded === "claimed" ? "claimed" : { decoded };
150
+ }
151
+ };
152
+ const tokenAmount = (token, amount, chainId, table) => {
153
+ const known = lookupEvmToken(table, chainId, token);
154
+ return {
155
+ asset: token,
156
+ amount: amount.toString(10),
157
+ ...known === void 0 ? {} : {
158
+ symbol: known.symbol,
159
+ decimals: known.decimals
160
+ }
161
+ };
162
+ };
163
+ /** The cash-token row for an address argument, or undefined for any other token. */
164
+ const cashToken = (address) => FIAT24_TOKENS[address.toLowerCase()];
165
+ const fiat24Token = (token) => ({
166
+ asset: token.address,
167
+ symbol: token.symbol,
168
+ decimals: 2
169
+ });
170
+ /** Verified outflow of a cash-token amount; `fiat24` names the account or payee the bytes carry. */
171
+ const cashFlow = (token, amount, chainId, table, fiat24) => ({
172
+ to: token.address,
173
+ amount: tokenAmount(token.address, amount, chainId, table),
174
+ verified: true,
175
+ fiat24
176
+ });
177
+ const ethFlow = (to, value) => ({
178
+ to,
179
+ amount: {
180
+ asset: EVM_NATIVE_ASSET,
181
+ amount: value.toString(10)
182
+ },
183
+ verified: true
184
+ });
185
+ /** A top-up input paid to the deposit contract — verified only when the token table knows it. */
186
+ const topUpFlow = (input, amount, chainId, table) => ({
187
+ to: FIAT24_DEPOSIT,
188
+ amount: tokenAmount(input, amount, chainId, table),
189
+ verified: lookupEvmToken(table, chainId, input) !== void 0
190
+ });
191
+ const payout = (token, args, action, chainId, table) => {
192
+ const contactId = argString(args, 1);
193
+ return {
194
+ summary: "payout",
195
+ outflows: [cashFlow(token, argUint(args, 0), chainId, table, { payee: contactId })],
196
+ warnings: [{
197
+ kind: "fiat24-payee-offchain",
198
+ message: ""
199
+ }],
200
+ fiat24: action(contactId)
201
+ };
202
+ };
203
+ /** Both exchange sides need two different cash tokens — anything else is a near miss. */
204
+ const exchangePair = (args) => {
205
+ const input = cashToken(argAddress(args, 0));
206
+ const output = cashToken(argAddress(args, 1));
207
+ return input === void 0 || output === void 0 || input.address === output.address ? void 0 : {
208
+ input,
209
+ output
210
+ };
211
+ };
212
+ const exchangeIn = (args, chainId, table) => {
213
+ const pair = exchangePair(args);
214
+ if (pair === void 0) return "claimed";
215
+ return {
216
+ summary: "swap",
217
+ outflows: [{
218
+ to: FIAT24_DEPOSIT,
219
+ amount: tokenAmount(pair.input.address, argUint(args, 2), chainId, table),
220
+ verified: true
221
+ }],
222
+ warnings: [{
223
+ kind: "fiat24-issuer-rate",
224
+ message: ""
225
+ }],
226
+ fiat24: {
227
+ kind: "exchange",
228
+ side: "exact-in",
229
+ receive: fiat24Token(pair.output)
230
+ }
231
+ };
232
+ };
233
+ const exchangeOut = (args, chainId, table) => {
234
+ const pair = exchangePair(args);
235
+ if (pair === void 0) return "claimed";
236
+ return {
237
+ summary: "swap",
238
+ outflows: [],
239
+ warnings: [{
240
+ kind: "fiat24-issuer-rate",
241
+ message: ""
242
+ }, {
243
+ kind: "fiat24-exact-out-unbounded",
244
+ message: ""
245
+ }],
246
+ fiat24: {
247
+ kind: "exchange",
248
+ side: "exact-out",
249
+ pay: fiat24Token(pair.input),
250
+ receive: tokenAmount(pair.output.address, argUint(args, 2), chainId, table)
251
+ }
252
+ };
253
+ };
254
+ /** A top-up's shared shape: pay in, receive a cash token at a rate the transaction cannot bound. */
255
+ const topUp = (outflows, output, swapsInTx) => ({
256
+ summary: "swap",
257
+ outflows,
258
+ warnings: [{
259
+ kind: "fiat24-issuer-rate",
260
+ message: ""
261
+ }, ...swapsInTx ? [{
262
+ kind: "fiat24-swap-quote",
263
+ message: ""
264
+ }] : []],
265
+ fiat24: {
266
+ kind: "top-up",
267
+ receive: fiat24Token(output)
268
+ }
269
+ });
270
+ const topUpToken = (args, swapsInTx, chainId, table) => {
271
+ const input = argAddress(args, 0);
272
+ const output = cashToken(argAddress(args, 1));
273
+ if (output === void 0) return "claimed";
274
+ return topUp([topUpFlow(input, argUint(args, 2), chainId, table)], output, swapsInTx(input));
275
+ };
276
+ /** Minting an account permanently links the address to the identity Fiat24 verifies. */
277
+ const openAccount = (id, outflows, burn) => ({
278
+ summary: "contract-call",
279
+ outflows,
280
+ warnings: [{
281
+ kind: "fiat24-account-link",
282
+ message: ""
283
+ }, ...burn === void 0 ? [] : [{
284
+ kind: "fiat24-account-burn",
285
+ message: ""
286
+ }]],
287
+ fiat24: {
288
+ kind: "open-account",
289
+ account: id.toString(10),
290
+ ...burn === void 0 ? {} : { burn }
291
+ }
292
+ });
293
+ const moveAccount = (args) => {
294
+ const to = argAddress(args, 1);
295
+ const id = argUint(args, 2);
296
+ return {
297
+ summary: "transfer",
298
+ outflows: [{
299
+ to,
300
+ amount: {
301
+ asset: FIAT24_ACCOUNT,
302
+ amount: "1",
303
+ tokenId: id.toString(10)
304
+ },
305
+ verified: false
306
+ }],
307
+ warnings: [{
308
+ kind: "fiat24-account-move",
309
+ level: "danger",
310
+ message: `#${id.toString(10)} → ${to}`
311
+ }]
312
+ };
313
+ };
314
+ const decodeFiat24Token = (token, call, chainId, table) => {
315
+ const hit = runCases([
316
+ {
317
+ fn: TRANSFER_BY_ACCOUNT_ID,
318
+ run: (args) => {
319
+ const account = argUint(args, 0);
320
+ return {
321
+ summary: "transfer",
322
+ outflows: [cashFlow(token, argUint(args, 1), chainId, table, { account: account.toString(10) })],
323
+ warnings: isInternalAccount(account) ? [{
324
+ kind: "fiat24-internal-account",
325
+ message: account.toString(10)
326
+ }] : []
327
+ };
328
+ }
329
+ },
330
+ {
331
+ fn: CLIENT_PAYOUT,
332
+ run: (args) => payout(token, args, (contactId) => ({
333
+ kind: "payout",
334
+ contactId
335
+ }), chainId, table)
336
+ },
337
+ {
338
+ fn: CLIENT_PAYOUT_REF,
339
+ run: (args) => payout(token, args, (contactId) => ({
340
+ kind: "payout",
341
+ contactId,
342
+ purposeId: argUint(args, 2).toString(10),
343
+ ref: argString(args, 3)
344
+ }), chainId, table)
345
+ }
346
+ ], call);
347
+ if (hit !== void 0) return hit;
348
+ const selector = call.data.slice(0, 10).toLowerCase();
349
+ return ERC20_SELECTORS.has(selector) && call.value === 0n ? void 0 : "claimed";
350
+ };
351
+ const decodeFiat24Deposit = (call, chainId, table) => runCases([
352
+ {
353
+ fn: MONEY_EXCHANGE_EXACT_IN,
354
+ run: (args) => exchangeIn(args, chainId, table)
355
+ },
356
+ {
357
+ fn: MONEY_EXCHANGE_EXACT_OUT,
358
+ run: (args) => exchangeOut(args, chainId, table)
359
+ },
360
+ {
361
+ fn: DEPOSIT_TOKEN_VIA_USDC,
362
+ run: (args) => topUpToken(args, (input) => input.toLowerCase() !== "0xaf88d065e77c8cC2239327C5EDb3A432268e5831".toLowerCase(), chainId, table)
363
+ },
364
+ {
365
+ fn: DEPOSIT_ETH,
366
+ payable: true,
367
+ run: (args, call) => {
368
+ const output = cashToken(argAddress(args, 0));
369
+ return output === void 0 ? "claimed" : topUp([ethFlow("0x4582f67698843Dfb6A9F195C0dDee05B0A8C973F", call.value)], output, true);
370
+ }
371
+ },
372
+ {
373
+ fn: DEPOSIT_TOKEN_VIA_ETH,
374
+ run: (args) => topUpToken(args, () => true, chainId, table)
375
+ }
376
+ ], call) ?? "claimed";
377
+ const decodeFiat24Account = (call) => runCases([
378
+ {
379
+ fn: MINT_BY_CLIENT,
380
+ run: (args) => openAccount(argUint(args, 0), [], F24_BURN)
381
+ },
382
+ {
383
+ fn: MINT_BY_CLIENT_WITH_ETH,
384
+ payable: true,
385
+ run: (args, call) => openAccount(argUint(args, 0), [ethFlow("0x133CAEecA096cA54889db71956c7f75862Ead7A0", call.value)])
386
+ },
387
+ {
388
+ fn: ACCOUNT_SAFE_TRANSFER_DATA,
389
+ run: moveAccount
390
+ },
391
+ {
392
+ fn: ACCOUNT_SAFE_TRANSFER,
393
+ run: moveAccount
394
+ },
395
+ {
396
+ fn: ACCOUNT_TRANSFER_FROM,
397
+ run: moveAccount
398
+ }
399
+ ], call) ?? "claimed";
400
+ /**
401
+ * Decodes a call to a Fiat24 contract: `{ decoded }` for the calls the rules table describes,
402
+ * `"claimed"` for every other call into one of the seven pinned proxies (the Fiat24 family's
403
+ * near-miss reason applies), `undefined` when the call is not Fiat24's — a cash token's ERC-20
404
+ * selectors, or a callee Fiat24 does not own.
405
+ *
406
+ * Only `depositETH` and `mintByClientWithETH` are payable; a positive value on any other function
407
+ * is a near miss.
408
+ */
409
+ const decodeFiat24 = (chainId, call, table) => {
410
+ if (chainId !== 42161 || call.to === void 0) return;
411
+ const to = call.to.toLowerCase();
412
+ const token = FIAT24_TOKENS[to];
413
+ if (token !== void 0) return decodeFiat24Token(token, call, chainId, table);
414
+ if (to === "0x4582f67698843Dfb6A9F195C0dDee05B0A8C973F".toLowerCase()) return decodeFiat24Deposit(call, chainId, table);
415
+ if (to === "0x133CAEecA096cA54889db71956c7f75862Ead7A0".toLowerCase()) return decodeFiat24Account(call);
416
+ return FIAT24_CONTRACTS.has(to) ? "claimed" : void 0;
417
+ };
418
+ const sessionLabel = (chainId, tokenId, deadline) => `fiat24-session-v1:${chainId}:${tokenId}:${deadline};`;
419
+ /** The exact personal-message text a `evm.fiat24-session` request signs. */
420
+ const fiat24SessionMessage = (chainId, tokenId, deadline) => {
421
+ return `I agree to access my profile. ${`0x${bytesToHex(keccak_256(utf8ToBytes(sessionLabel(chainId, tokenId, deadline) + deadline)))}`}`;
422
+ };
423
+ // src/evm/envelope.ts
424
+ /**
425
+ * The unsigned EIP-2718 envelope of a normalized transaction — one construction shared by the
426
+ * kernel's signer and by the host's round-trip check, which re-serializes it with the returned
427
+ * signature to prove the kernel signed exactly the requested transaction.
428
+ */
429
+ /** Validates a string is `0x`-hex and narrows it for ox's branded type. */
430
+ function assertHex(value, field) {
431
+ if (!/^0x(?:[0-9a-fA-F]{2})*$/.test(value)) throw new ChainError("invalid-quantity", `${field} must be 0x-prefixed bytes`);
432
+ }
433
+ const hex = (value, field) => {
434
+ assertHex(value, field);
435
+ return value;
436
+ };
437
+ const accessEntry = (entry) => ({
438
+ address: hex(entry.address, "accessList.address"),
439
+ storageKeys: entry.storageKeys.map((k) => hex(k, "accessList.storageKeys"))
440
+ });
441
+ /** The EIP-7702 authorization an `eip7702` transaction carries: the account's next-but-one nonce. */
442
+ const evmAuthorization = (tx) => ({
443
+ chainId: tx.chainId,
444
+ address: hex(tx.authorization.address, "authorization.address"),
445
+ nonce: BigInt(tx.nonce + 1)
446
+ });
447
+ const baseEnvelope = (tx) => ({
448
+ chainId: tx.chainId,
449
+ to: tx.to === void 0 ? void 0 : hex(tx.to, "to"),
450
+ data: hex(tx.data, "data"),
451
+ value: BigInt(tx.value),
452
+ nonce: BigInt(tx.nonce),
453
+ gas: BigInt(tx.gas)
454
+ });
455
+ /**
456
+ * The envelope of `tx`. An `eip7702` transaction embeds its signed authorization, so the caller
457
+ * passes the signature over `evmAuthorization(tx)`.
458
+ */
459
+ const evmEnvelope = (tx, authorization) => {
460
+ const base = baseEnvelope(tx);
461
+ if (tx.type === "legacy") {
462
+ const envelope = {
463
+ ...base,
464
+ type: "legacy",
465
+ gasPrice: BigInt(tx.gasPrice)
466
+ };
467
+ return {
468
+ payload: TxEnvelopeLegacy.getSignPayload(envelope),
469
+ serialize: (signature) => TxEnvelopeLegacy.serialize(envelope, { signature })
470
+ };
471
+ }
472
+ if (tx.type === "eip2930") {
473
+ const envelope = {
474
+ ...base,
475
+ type: "eip2930",
476
+ gasPrice: BigInt(tx.gasPrice),
477
+ accessList: tx.accessList.map(accessEntry)
478
+ };
479
+ return {
480
+ payload: TxEnvelopeEip2930.getSignPayload(envelope),
481
+ serialize: (signature) => TxEnvelopeEip2930.serialize(envelope, { signature })
482
+ };
483
+ }
484
+ if (tx.type === "eip7702") {
485
+ if (authorization === void 0) throw new ChainError("invalid-request", "an eip7702 envelope needs its signed authorization");
486
+ const envelope = {
487
+ ...base,
488
+ type: "eip7702",
489
+ to: hex(tx.to, "to"),
490
+ accessList: tx.accessList.map(accessEntry),
491
+ maxFeePerGas: BigInt(tx.maxFeePerGas),
492
+ maxPriorityFeePerGas: BigInt(tx.maxPriorityFeePerGas),
493
+ authorizationList: [{
494
+ ...evmAuthorization(tx),
495
+ r: authorization.r,
496
+ s: authorization.s,
497
+ yParity: authorization.yParity
498
+ }]
499
+ };
500
+ return {
501
+ payload: TxEnvelopeEip7702.getSignPayload(envelope),
502
+ serialize: (signature) => TxEnvelopeEip7702.serialize(envelope, { signature })
503
+ };
504
+ }
505
+ const envelope = {
506
+ ...base,
507
+ type: "eip1559",
508
+ accessList: tx.accessList.map(accessEntry),
509
+ maxFeePerGas: BigInt(tx.maxFeePerGas),
510
+ maxPriorityFeePerGas: BigInt(tx.maxPriorityFeePerGas)
511
+ };
512
+ return {
513
+ payload: TxEnvelopeEip1559.getSignPayload(envelope),
514
+ serialize: (signature) => TxEnvelopeEip1559.serialize(envelope, { signature })
515
+ };
516
+ };
517
+ /**
518
+ * The unsigned signing preimage of `tx`: the EIP-155 / EIP-2718 serialization whose keccak256 is
519
+ * `evmEnvelope(tx).payload`. An `eip7702` transaction has no unsigned preimage — its payload is the
520
+ * authorization's, produced by `evmAuthorization(tx)`.
521
+ */
522
+ const evmSigningPreimage = (tx) => {
523
+ const base = baseEnvelope(tx);
524
+ if (tx.type === "legacy") return hexToBytes(TxEnvelopeLegacy.serialize({
525
+ ...base,
526
+ type: "legacy",
527
+ gasPrice: BigInt(tx.gasPrice)
528
+ }).slice(2));
529
+ if (tx.type === "eip2930") return hexToBytes(TxEnvelopeEip2930.serialize({
530
+ ...base,
531
+ type: "eip2930",
532
+ gasPrice: BigInt(tx.gasPrice),
533
+ accessList: tx.accessList.map(accessEntry)
534
+ }).slice(2));
535
+ if (tx.type === "eip7702") throw new ChainError("invalid-request", "an eip7702 transaction has no unsigned preimage");
536
+ return hexToBytes(TxEnvelopeEip1559.serialize({
537
+ ...base,
538
+ type: "eip1559",
539
+ accessList: tx.accessList.map(accessEntry),
540
+ maxFeePerGas: BigInt(tx.maxFeePerGas),
541
+ maxPriorityFeePerGas: BigInt(tx.maxPriorityFeePerGas)
542
+ }).slice(2));
543
+ };
544
+ // src/evm/plan.ts
545
+ /**
546
+ * /evm/plan — the serialisable signing plan of a normalized request: the digests each signing
547
+ * backend must sign, and the transaction an EIP-7702 signature later re-enters. No key material.
548
+ */
549
+ const ecdsa = (digest, key) => ({
550
+ scheme: "ecdsa-secp256k1",
551
+ path: key.path,
552
+ publicKey: key.publicKey,
553
+ digest
554
+ });
555
+ const personalDigest = (message) => Hex.toBytes(PersonalMessage.getSignPayload(Hex.fromBytes(message)));
556
+ /**
557
+ * The transaction plan. For `eip7702` the task covers the authorization digest; `assembleEvm` then
558
+ * returns a stage-2 plan whose task is the envelope digest of the authorized transaction.
559
+ */
560
+ const planEvmTransaction = (tx, key) => ({
561
+ kind: "evm.transaction",
562
+ tx,
563
+ tasks: [ecdsa(Hex.toBytes(tx.type === "eip7702" ? Authorization.getSignPayload(evmAuthorization(tx)) : evmEnvelope(tx).payload), key)]
564
+ });
565
+ const planEvmPersonalMessage = (message, key) => ({
566
+ kind: "evm.personal-message",
567
+ tasks: [ecdsa(personalDigest(message), key)]
568
+ });
569
+ const planEvmTypedData = (typedData, key) => {
570
+ const { json } = parseTypedData(typedData);
571
+ let payload;
572
+ try {
573
+ payload = TypedData.getSignPayload(json);
574
+ } catch {
575
+ throw new ChainError("invalid-typed-data", "typedData failed to encode");
576
+ }
577
+ return {
578
+ kind: "evm.typed-data",
579
+ tasks: [ecdsa(Hex.toBytes(payload), key)]
580
+ };
581
+ };
582
+ /** The plan of a normalized request; the task keeps the request kind so the kernel can wrap it. */
583
+ const planEvm = (request, key) => {
584
+ if (request.kind === "evm.transaction") return planEvmTransaction(request.tx, key);
585
+ if (request.kind === "evm.personal-message") return planEvmPersonalMessage(request.message, key);
586
+ if (request.kind === "evm.fiat24-session") return {
587
+ kind: "evm.fiat24-session",
588
+ tasks: [ecdsa(personalDigest(utf8ToBytes(fiat24SessionMessage(networkChainId(request.network), request.tokenId, request.deadline))), key)]
589
+ };
590
+ return planEvmTypedData(request.typedData, key);
591
+ };
592
+ // src/evm/assemble.ts
593
+ /**
594
+ * /evm/assemble — turn verified signature material into the wire artefact: the serialized signed
595
+ * envelope for a transaction, the 65-byte `r‖s‖v` (v = 27 + yParity) for messages. An `eip7702`
596
+ * transaction without its authorization returns the stage-2 plan instead.
597
+ */
598
+ const oxSignature = (accepted) => Signature.from({
599
+ r: Hex.fromNumber(accepted.r),
600
+ s: Hex.fromNumber(accepted.s),
601
+ yParity: accepted.yParity
602
+ });
603
+ const assembleEvm = (plan, signatures) => {
604
+ signaturesOf(plan.tasks, signatures);
605
+ const signature = oxSignature(acceptEcdsa(plan.tasks[0], signatures[0] ?? /* @__PURE__ */ new Uint8Array()));
606
+ if (plan.kind !== "evm.transaction") return {
607
+ kind: "signed",
608
+ artefact: Signature.toBytes(signature)
609
+ };
610
+ if (plan.tx.type === "eip7702" && plan.authorization === void 0) return {
611
+ kind: "next",
612
+ plan: {
613
+ ...plan,
614
+ authorization: Signature.toBytes(signature),
615
+ tasks: [{
616
+ ...plan.tasks[0],
617
+ digest: Hex.toBytes(evmEnvelope(plan.tx, signature).payload)
618
+ }]
619
+ }
620
+ };
621
+ const envelope = evmEnvelope(plan.tx, plan.authorization === void 0 ? void 0 : Signature.fromBytes(plan.authorization));
622
+ return {
623
+ kind: "signed",
624
+ artefact: Hex.toBytes(envelope.serialize(signature))
625
+ };
626
+ };
627
+ export { planEvmTypedData as a, evmSigningPreimage as c, fiat24SessionMessage as d, fiat24Spender as f, planEvmTransaction as i, FIAT24_CHAIN as l, isFiat24Contract as m, planEvm as n, evmAuthorization as o, hasFiat24Selector as p, planEvmPersonalMessage as r, evmEnvelope as s, assembleEvm as t, decodeFiat24 as u };
628
+
629
+ //# sourceMappingURL=assemble-B3sO9Fvc.mjs.map