@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,466 @@
1
+ import { c as hasHiddenCharacters, l as isEncodedBytes, s as displayExcerpt, t as ChainError } from "./src-CHB_z45M.mjs";
2
+ import { keccak_256 } from "@noble/hashes/sha3.js";
3
+ import { bytesToHex } from "@noble/hashes/utils.js";
4
+ import * as AbiFunction from "ox/AbiFunction";
5
+ import { secp256k1 } from "@noble/curves/secp256k1.js";
6
+ import * as Address from "ox/Address";
7
+ import * as AbiParameters from "ox/AbiParameters";
8
+ import * as Hex from "ox/Hex";
9
+ import * as TypedData from "ox/TypedData";
10
+ // src/evm/address.ts
11
+ /** EIP-55 checksummed address, e.g. `0x52908400098527886E0F7030069857D2E4169EE7`. */
12
+ const isEvmAddress = (value) => /^0x[0-9a-fA-F]{40}$/.test(value);
13
+ function checksumEvmAddress(address) {
14
+ if (!isEvmAddress(address)) throw new ChainError("invalid-address", "not an EVM address");
15
+ const checksummed = Address.checksum(address);
16
+ Address.assert(checksummed, { strict: true });
17
+ return checksummed;
18
+ }
19
+ /** `keccak256(pubkey)[12:]` — accepts a 33-byte compressed or 65-byte uncompressed secp256k1 key. */
20
+ function evmAddressFromPublicKey(pubkey) {
21
+ const uncompressed = pubkey.length === 65 && pubkey[0] === 4 ? pubkey : pubkey.length === 33 ? secp256k1.Point.fromBytes(pubkey).toBytes(false) : void 0;
22
+ if (uncompressed === void 0 || uncompressed[0] !== 4) throw new ChainError("invalid-address", "expected a compressed or uncompressed secp256k1 key");
23
+ return checksumEvmAddress(`0x${bytesToHex(keccak_256(uncompressed.subarray(1))).slice(-40)}`);
24
+ }
25
+ // src/evm/delegation.ts
26
+ /**
27
+ * MetaMask Delegation Framework EIP7702StatelessDeleGator v1.3.0 — deterministic CREATE2, the same
28
+ * address on every chain that supports it.
29
+ */
30
+ const EVM_DELEGATOR = {
31
+ address: "0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B",
32
+ name: "EIP7702StatelessDeleGator",
33
+ version: "1.3.0"
34
+ };
35
+ /** The EIP-7702 designator byte prefix: `0xef0100 ‖ address` marks a delegated account's code. */
36
+ const EVM_DELEGATION_PREFIX = "0xef0100";
37
+ /** ERC-7821 batch-default execution mode: `0x01` followed by 31 zero bytes. */
38
+ const EXECUTE_BATCH_MODE = "0x0100000000000000000000000000000000000000000000000000000000000000";
39
+ const EXECUTE = AbiFunction.from("function execute(bytes32 mode, bytes executionData)");
40
+ const EXECUTIONS = [{
41
+ type: "tuple[]",
42
+ components: [
43
+ {
44
+ name: "target",
45
+ type: "address"
46
+ },
47
+ {
48
+ name: "value",
49
+ type: "uint256"
50
+ },
51
+ {
52
+ name: "callData",
53
+ type: "bytes"
54
+ }
55
+ ]
56
+ }];
57
+ const hex = (v) => {
58
+ Hex.assert(v);
59
+ return v;
60
+ };
61
+ /** ERC-7821 batch-default self-call payload for `execute` on the delegator. */
62
+ const encodeBatchExecute = (calls) => AbiFunction.encodeData(EXECUTE, [EXECUTE_BATCH_MODE, AbiParameters.encode(EXECUTIONS, [calls.map((c) => ({
63
+ target: hex(checksumEvmAddress(c.to)),
64
+ value: c.value,
65
+ callData: hex(c.data)
66
+ }))])]);
67
+ const list = (v) => Array.isArray(v) ? v : [];
68
+ const isExecution = (e) => typeof e === "object" && e !== null && "target" in e && "value" in e && "callData" in e && typeof e.target === "string" && isEvmAddress(e.target) && typeof e.value === "bigint" && typeof e.callData === "string";
69
+ /** Decodes an `execute` call; undefined unless the encoding is canonical batch-default mode. */
70
+ const decodeBatchExecute = (data) => {
71
+ try {
72
+ const [mode, executionData] = list(AbiFunction.decodeData(EXECUTE, hex(data)));
73
+ if (mode !== "0x0100000000000000000000000000000000000000000000000000000000000000" || typeof executionData !== "string") return;
74
+ const decoded = AbiParameters.decode(EXECUTIONS, hex(executionData));
75
+ const [inner] = list(decoded);
76
+ const executions = [];
77
+ for (const e of list(inner)) {
78
+ if (!isExecution(e)) return;
79
+ executions.push({
80
+ to: checksumEvmAddress(e.target),
81
+ value: e.value,
82
+ data: e.callData
83
+ });
84
+ }
85
+ return encodeBatchExecute(executions).toLowerCase() === data.toLowerCase() ? executions : void 0;
86
+ } catch {
87
+ return;
88
+ }
89
+ };
90
+ // src/evm/transaction.ts
91
+ /** Validates a string is `0x`-hex and narrows it to the branded hex type. */
92
+ function assertHex(value, field) {
93
+ if (!/^0x(?:[0-9a-fA-F]{2})*$/.test(value)) throw new ChainError("invalid-quantity", `${field} must be 0x-prefixed bytes`);
94
+ }
95
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
96
+ const CANONICAL_HEX = /^0x(?:0|[1-9a-f][0-9a-f]*)$/;
97
+ const isCanonicalHex = (value) => CANONICAL_HEX.test(value);
98
+ const canonicalHex = (value) => `0x${value.toString(16)}`;
99
+ /** Parses a JSON-RPC quantity: `0x` and at least one hex digit — a bare `"0x"` is malformed. */
100
+ const quantityBigInt = (value, field) => {
101
+ if (typeof value !== "string" || !/^0x[0-9a-fA-F]+$/.test(value)) throw new ChainError("invalid-quantity", `${field} must be a 0x quantity`);
102
+ return BigInt(value);
103
+ };
104
+ const safeInteger = (value, field) => {
105
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw new ChainError("invalid-quantity", `${field} must be a non-negative safe integer`);
106
+ return value;
107
+ };
108
+ const quantity = (value, field) => {
109
+ if (typeof value !== "string") throw new ChainError("invalid-quantity", `${field} must be a 0x quantity string`);
110
+ if (CANONICAL_HEX.test(value)) return value;
111
+ return canonicalHex(quantityBigInt(value, field));
112
+ };
113
+ const hexBytes = (value, field) => {
114
+ if (typeof value !== "string" || !/^0x(?:[0-9a-fA-F]{2})*$/.test(value)) throw new ChainError("invalid-quantity", `${field} must be 0x-prefixed bytes`);
115
+ return value.toLowerCase();
116
+ };
117
+ const accessList = (value) => {
118
+ if (!Array.isArray(value)) throw new ChainError("invalid-request", "accessList must be an array");
119
+ return value.map((entry) => {
120
+ if (!isRecord(entry)) throw new ChainError("invalid-address", "accessList entries must be objects");
121
+ const keys = Object.keys(entry).sort();
122
+ if (keys.length !== 2 || keys[0] !== "address" || keys[1] !== "storageKeys") throw new ChainError("unknown-field", `accessList entry fields must be exactly address+storageKeys, got ${keys.join(",")}`);
123
+ const { address, storageKeys } = entry;
124
+ if (typeof address !== "string" || !isEvmAddress(address)) throw new ChainError("invalid-address", "accessList entry has an invalid address");
125
+ if (!Array.isArray(storageKeys)) throw new ChainError("invalid-quantity", "accessList storageKeys must be an array");
126
+ return {
127
+ address: checksumEvmAddress(address),
128
+ storageKeys: storageKeys.map((k) => {
129
+ if (typeof k !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(k)) throw new ChainError("invalid-quantity", "accessList storageKeys must be 32-byte hex strings");
130
+ return k.toLowerCase();
131
+ })
132
+ };
133
+ });
134
+ };
135
+ /** The EIP-155 part of a CAIP-2 `network` string, e.g. `eip155:1` → 1. Chain 0 does not exist. */
136
+ const networkChainId = (network) => {
137
+ const idPart = /^eip155:([1-9]\d*)$/.exec(network)?.[1];
138
+ if (idPart === void 0) throw new ChainError("chain-id-mismatch", `network is not an eip155 CAIP-2 id: ${network}`);
139
+ const id = Number(idPart);
140
+ if (!Number.isSafeInteger(id)) throw new ChainError("chain-id-mismatch", `chain id is not a safe integer: ${network}`);
141
+ return id;
142
+ };
143
+ const REQUIRED = {
144
+ base: [
145
+ "chainId",
146
+ "nonce",
147
+ "gas",
148
+ "value",
149
+ "data"
150
+ ],
151
+ gasPrice: ["gasPrice"],
152
+ accessList: ["accessList"],
153
+ eip1559: ["maxFeePerGas", "maxPriorityFeePerGas"]
154
+ };
155
+ const ALLOWED = {
156
+ base: [
157
+ "type",
158
+ "chainId",
159
+ "nonce",
160
+ "gas",
161
+ "value",
162
+ "data",
163
+ "to"
164
+ ],
165
+ legacy: ["gasPrice"],
166
+ eip2930: ["gasPrice", "accessList"],
167
+ eip1559: [
168
+ "accessList",
169
+ "maxFeePerGas",
170
+ "maxPriorityFeePerGas"
171
+ ],
172
+ eip7702: [
173
+ "accessList",
174
+ "maxFeePerGas",
175
+ "maxPriorityFeePerGas",
176
+ "authorization"
177
+ ]
178
+ };
179
+ const requireFields = (input, fields) => {
180
+ for (const field of fields) if (input[field] === void 0) throw new ChainError("invalid-request", `tx.${field} is required`);
181
+ };
182
+ const rejectUnknown = (input, type) => {
183
+ const allowed = /* @__PURE__ */ new Set([...ALLOWED.base, ...ALLOWED[type]]);
184
+ const unknown = Object.keys(input).filter((k) => !allowed.has(k));
185
+ if (unknown.length > 0) throw new ChainError("unknown-field", `tx has unknown fields for ${type}: ${unknown.sort().join(", ")}`);
186
+ };
187
+ /**
188
+ * Canonicalizes an EVM transaction: exact key sets per type, all required fields present, `0x`
189
+ * canonical quantities, EIP-55 addresses. Idempotent.
190
+ */
191
+ const normalizeEvmTransaction = (tx) => {
192
+ if (!isRecord(tx)) throw new ChainError("invalid-request", "tx must be an object");
193
+ const { type } = tx;
194
+ if (type !== "legacy" && type !== "eip2930" && type !== "eip1559" && type !== "eip7702") throw new ChainError("unsupported", `transaction type ${String(type)} is not supported (legacy, eip2930, eip1559 and eip7702 only)`);
195
+ rejectUnknown(tx, type);
196
+ requireFields(tx, REQUIRED.base);
197
+ const chainId = safeInteger(tx["chainId"], "chainId");
198
+ const nonce = safeInteger(tx["nonce"], "nonce");
199
+ const gas = quantity(tx["gas"], "gas");
200
+ const value = quantity(tx["value"], "value");
201
+ const data = hexBytes(tx["data"], "data");
202
+ const toRaw = tx["to"];
203
+ const to = toRaw === void 0 ? void 0 : typeof toRaw === "string" && isEvmAddress(toRaw) ? checksumEvmAddress(toRaw) : void 0;
204
+ if (toRaw !== void 0 && to === void 0) throw new ChainError("invalid-address", "to must be a valid EVM address");
205
+ const base = {
206
+ chainId,
207
+ nonce,
208
+ gas,
209
+ value,
210
+ data,
211
+ ...to === void 0 ? {} : { to }
212
+ };
213
+ if (type === "legacy") {
214
+ requireFields(tx, REQUIRED.gasPrice);
215
+ return {
216
+ type,
217
+ ...base,
218
+ gasPrice: quantity(tx["gasPrice"], "gasPrice")
219
+ };
220
+ }
221
+ if (type === "eip2930") {
222
+ requireFields(tx, [...REQUIRED.gasPrice, ...REQUIRED.accessList]);
223
+ return {
224
+ type,
225
+ ...base,
226
+ gasPrice: quantity(tx["gasPrice"], "gasPrice"),
227
+ accessList: accessList(tx["accessList"])
228
+ };
229
+ }
230
+ requireFields(tx, [...REQUIRED.accessList, ...REQUIRED.eip1559]);
231
+ const fees = {
232
+ maxFeePerGas: quantity(tx["maxFeePerGas"], "maxFeePerGas"),
233
+ maxPriorityFeePerGas: quantity(tx["maxPriorityFeePerGas"], "maxPriorityFeePerGas")
234
+ };
235
+ if (BigInt(fees.maxPriorityFeePerGas) > BigInt(fees.maxFeePerGas)) throw new ChainError("invalid-request", "maxPriorityFeePerGas exceeds maxFeePerGas");
236
+ const list = accessList(tx["accessList"]);
237
+ if (type === "eip1559") return {
238
+ type,
239
+ ...base,
240
+ accessList: list,
241
+ ...fees
242
+ };
243
+ if (to === void 0) throw new ChainError("invalid-request", "tx.to is required for eip7702");
244
+ if (chainId < 1) throw new ChainError("invalid-request", "eip7702 chainId 0 is a chain-universal authorization and is never signed");
245
+ const auth = tx["authorization"];
246
+ if (!isRecord(auth) || Object.keys(auth).length !== 1 || typeof auth["address"] !== "string") throw new ChainError("invalid-request", "tx.authorization must be an object with exactly address");
247
+ const authAddress = checksumEvmAddress(auth["address"]);
248
+ if (authAddress !== EVM_DELEGATOR.address && authAddress !== "0x0000000000000000000000000000000000000000") throw new ChainError("unsupported", "authorization address is not supported");
249
+ return {
250
+ type,
251
+ ...base,
252
+ to,
253
+ accessList: list,
254
+ ...fees,
255
+ authorization: { address: authAddress }
256
+ };
257
+ };
258
+ // src/evm/typed-data.ts
259
+ const isField = (value) => isRecord(value) && typeof value["name"] === "string" && typeof value["type"] === "string";
260
+ const isTypedDataInput = (value) => {
261
+ if (!isRecord(value)) return false;
262
+ const { types, primaryType, domain, message } = value;
263
+ if (!isRecord(types)) return false;
264
+ if (typeof primaryType !== "string" || primaryType === "") return false;
265
+ if (!isRecord(domain)) return false;
266
+ if (!isRecord(message)) return false;
267
+ return Object.values(types).every((fields) => Array.isArray(fields) && fields.every(isField));
268
+ };
269
+ const isTypedDataMessage = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
270
+ /**
271
+ * The EIP-712 domain separator and message struct hash of a parsed document — the same encoder
272
+ * `planEvmTypedData` signs (`keccak256(0x1901 | domain | message)` is the task digest). `message`
273
+ * is `undefined` when the primary type is `EIP712Domain` itself.
274
+ */
275
+ const typedDataHashes = (json) => {
276
+ const encoded = Hex.toBytes(TypedData.encode({
277
+ domain: json.domain,
278
+ types: json.types,
279
+ primaryType: json.primaryType,
280
+ message: json.message
281
+ }));
282
+ return {
283
+ domain: encoded.subarray(2, 34),
284
+ message: json.primaryType === "EIP712Domain" ? void 0 : encoded.subarray(34)
285
+ };
286
+ };
287
+ /** `value` is an array of message objects (empty allowed). */
288
+ const typedDataMessages = (value) => Array.isArray(value) && value.every(isTypedDataMessage) ? value : void 0;
289
+ /** The `Type field,Type field` signature of struct `name` in `types`. */
290
+ const typedDataSignature = (types, name) => types[name]?.map((field) => `${field.type} ${field.name}`).join(",");
291
+ /** Struct `name` has exactly `fields`, in order, no more. */
292
+ const sameFields = (types, name, fields) => typedDataSignature(types, name) === fields.join(",");
293
+ /** A hex `address` field value, checksummed; `undefined` when malformed. */
294
+ const typedDataAddress = (value) => typeof value === "string" && /^0x[0-9a-fA-F]{40}$/.test(value) ? checksumEvmAddress(value) : void 0;
295
+ /** A uint field value (safe-integer number, decimal or `0x` hex string) ≤ `max`. */
296
+ const typedDataUint = (value, max) => {
297
+ let parsed;
298
+ if (typeof value === "number" && Number.isSafeInteger(value)) parsed = BigInt(value);
299
+ else if (typeof value === "string" && /^(?:[0-9]+|0x[0-9a-fA-F]+)$/.test(value)) parsed = BigInt(value);
300
+ else return;
301
+ return parsed >= 0n && parsed <= max ? parsed : void 0;
302
+ };
303
+ /** The largest timestamp a permit/order expiry or a Safe field is allowed to carry. */
304
+ const MAX_UINT48 = 2n ** 48n - 1n;
305
+ const isHexBytes = (value) => typeof value === "string" && /^0x(?:[0-9a-fA-F]{2})*$/.test(value);
306
+ /** A `bytes` field value: `0x`-prefixed hex of even length. */
307
+ const typedDataBytes = (value) => isHexBytes(value) ? value : void 0;
308
+ /**
309
+ * Walks `value` along `type`: every struct-typed value must be an object carrying its fields, and
310
+ * struct/array nesting stays within MAX_TYPED_DATA_DEPTH — so a recursive type is bounded by its
311
+ * message and a missing nested struct fails here rather than inside the encoder.
312
+ */
313
+ const checkStructure = (types, type, value, depth) => {
314
+ const array = /^(.+)\[\d*\]$/.exec(type);
315
+ const struct = array === null ? types[type] : void 0;
316
+ if (array === null && struct === void 0) return;
317
+ if (depth >= 32) throw new ChainError("invalid-typed-data", "typedData nests too deeply");
318
+ if (array !== null) {
319
+ if (!Array.isArray(value)) throw new ChainError("invalid-typed-data", `typedData ${type} value is not an array`);
320
+ for (const item of value) checkStructure(types, array[1] ?? "", item, depth + 1);
321
+ return;
322
+ }
323
+ if (!isRecord(value)) throw new ChainError("invalid-typed-data", `typedData ${type} value is not an object`);
324
+ for (const field of struct ?? []) checkStructure(types, field.type, value[field.name], depth + 1);
325
+ };
326
+ /**
327
+ * Parses the EIP-712 JSON source and validates it with ox. `types.EIP712Domain` is required:
328
+ * without it ox derives the domain type from the domain object while MetaMask hashes an empty
329
+ * domain, so the same document would sign differently across wallets.
330
+ */
331
+ const parseTypedData = (typedData) => {
332
+ let json;
333
+ try {
334
+ json = JSON.parse(typedData);
335
+ } catch {
336
+ throw new ChainError("invalid-typed-data", "typedData is not valid JSON");
337
+ }
338
+ if (!isTypedDataInput(json)) throw new ChainError("invalid-typed-data", "typedData must be a JSON object with types, primaryType, domain and message");
339
+ if (json.types["EIP712Domain"] === void 0) throw new ChainError("invalid-typed-data", "typedData must declare types.EIP712Domain");
340
+ try {
341
+ TypedData.validate(json);
342
+ } catch {
343
+ throw new ChainError("invalid-typed-data", "typedData failed EIP-712 validation");
344
+ }
345
+ checkStructure(json.types, json.primaryType, json.message, 0);
346
+ const declared = new Set((json.types["EIP712Domain"] ?? []).map((field) => field.name));
347
+ const domain = Object.fromEntries(Object.entries(json.domain).filter(([key]) => declared.has(key)));
348
+ return { json: {
349
+ ...json,
350
+ domain
351
+ } };
352
+ };
353
+ /** Most leaves an unrecognised typed-data document may have and still be shown in full. */
354
+ const TYPED_FIELD_BUDGET = 16;
355
+ /** Longest path or value (in code points, after sanitising) one leaf line may show. */
356
+ const TYPED_FIELD_CODE_POINTS = 96;
357
+ const FIXED_BYTES = /^bytes(?:[1-9]|[12][0-9]|3[0-2])$/;
358
+ const INT_TYPE = /^u?int([0-9]*)$/;
359
+ /**
360
+ * The display value of one atomic leaf, or `undefined` when the value is not in a form that is
361
+ * shown exactly as it is encoded. Only the canonical forms every EIP-712 hasher agrees on are
362
+ * accepted — anything else aborts the whole expansion.
363
+ */
364
+ const leafValue = (type, value) => {
365
+ if (type === "address") return typedDataAddress(value);
366
+ if (type === "bool") return typeof value === "boolean" ? value ? "true" : "false" : void 0;
367
+ if (type === "string") {
368
+ if (typeof value !== "string") return;
369
+ const excerpt = displayExcerpt(value, 1, 96);
370
+ return excerpt.omitted === 0 ? excerpt.lines[0] ?? "" : void 0;
371
+ }
372
+ if (type === "bytes" || FIXED_BYTES.test(type)) return typeof value === "string" && /^0x([0-9a-fA-F]{2})*$/.test(value) && value.length <= 96 ? value.toLowerCase() : void 0;
373
+ const int = INT_TYPE.exec(type);
374
+ if (int !== null) {
375
+ const bits = int[1] === "" ? 256 : Number(int[1]);
376
+ if (bits % 8 !== 0 || bits < 8 || bits > 256) return;
377
+ const signed = !type.startsWith("u");
378
+ let parsed;
379
+ if (typeof value === "number" && Number.isSafeInteger(value)) parsed = BigInt(value);
380
+ else if (typeof value === "string" && ((signed ? /^-?[0-9]+$/ : /^[0-9]+$/).test(value) || /^0x[0-9a-fA-F]+$/.test(value))) parsed = BigInt(value);
381
+ else return;
382
+ const min = signed ? -(2n ** BigInt(bits - 1)) : 0n;
383
+ const max = signed ? 2n ** BigInt(bits - 1) - 1n : 2n ** BigInt(bits) - 1n;
384
+ return parsed >= min && parsed <= max ? parsed.toString(10) : void 0;
385
+ }
386
+ };
387
+ /**
388
+ * Whether the atomic leaf of `type` holding `value` is a commitment: `bytesN` always is — the
389
+ * signature commits to raw bytes the owner cannot read — as is a non-empty `bytes` or a `string`
390
+ * that is just an encoded-bytes rendering of ≥ 32 bytes. `"0x"` and an empty-array leaf ("[]")
391
+ * carry nothing and are not.
392
+ */
393
+ const isCommitmentLeaf = (type, value) => type === "bytes" && value !== "0x" || FIXED_BYTES.test(type) || type === "string" && typeof value === "string" && isEncodedBytes(value);
394
+ /**
395
+ * Every leaf of `message` under `primaryType`, in EIP-712 encoding order (each struct's fields in
396
+ * declaration order, arrays element by element), as display lines, and whether any leaf is a
397
+ * commitment; `undefined` when there are more than TYPED_FIELD_BUDGET leaves or any leaf cannot be
398
+ * shown exactly as it is encoded. `leaf` may override an atomic leaf's display — a string return is
399
+ * used verbatim (commitment flags still apply) and `undefined` falls back to the default rule,
400
+ * which aborts the expansion when it cannot show the leaf exactly.
401
+ */
402
+ const typedDataFields = (json, leaf) => {
403
+ const leaves = [];
404
+ let hasCommitment = false;
405
+ const push = (path, value, commits) => {
406
+ const excerpt = displayExcerpt(path, 1, 96);
407
+ if (excerpt.omitted !== 0) return false;
408
+ leaves.push({
409
+ path: excerpt.lines[0] ?? "",
410
+ value
411
+ });
412
+ hasCommitment = hasCommitment || commits;
413
+ return leaves.length <= 16;
414
+ };
415
+ const walk = (type, value, path) => {
416
+ const array = /^(.+)\[\d*\]$/.exec(type);
417
+ if (array !== null) {
418
+ if (!Array.isArray(value)) return false;
419
+ return value.length === 0 ? push(path, "[]", false) : value.every((item, index) => walk(array[1] ?? "", item, `${path}[${index}]`));
420
+ }
421
+ const struct = json.types[type];
422
+ if (struct !== void 0) return isTypedDataMessage(value) && struct.every((field) => walk(field.type, value[field.name], path === "" ? field.name : `${path}.${field.name}`));
423
+ const display = leaf?.(type, value) ?? leafValue(type, value);
424
+ return display !== void 0 && push(path, display, isCommitmentLeaf(type, value));
425
+ };
426
+ return walk(json.primaryType, json.message, "") ? {
427
+ fields: leaves,
428
+ hasCommitment
429
+ } : void 0;
430
+ };
431
+ /**
432
+ * Whether any `string` leaf of the document carries characters the text rule hides — domain fields
433
+ * under `types.EIP712Domain` (or the fields ox derives when it is not declared) and message fields
434
+ * under `primaryType`, walked through structs and arrays — or the type encoding's own strings do:
435
+ * `primaryType`, every key of `types`, and every field's `name` and `type` are hashed into the
436
+ * signature, so a deceptive code point there is blind for the same reason as hidden message bytes.
437
+ * All declared types are scanned, not only the ones the primary type reaches. A key the type does
438
+ * not declare is not signed and is ignored. Never throws: a branch it cannot walk counts as no
439
+ * hidden text — malformed documents are refused by the validator.
440
+ */
441
+ const typedDataHasHiddenText = (json) => {
442
+ const hidden = (type, value, depth) => {
443
+ if (depth >= 32) return false;
444
+ const array = /^(.+)\[\d*\]$/.exec(type);
445
+ if (array !== null) return Array.isArray(value) && value.some((item) => hidden(array[1] ?? "", item, depth + 1));
446
+ const struct = json.types[type];
447
+ if (struct !== void 0) return isRecord(value) && struct.some((field) => hidden(field.type, value[field.name], depth + 1));
448
+ return type === "string" && typeof value === "string" && hasHiddenCharacters(value);
449
+ };
450
+ const domainFields = json.types["EIP712Domain"] ?? TypedData.extractEip712DomainTypes(json.domain);
451
+ return hasHiddenCharacters(json.primaryType) || Object.entries(json.types).some(([name, struct]) => hasHiddenCharacters(name) || struct.some((field) => hasHiddenCharacters(field.name) || hasHiddenCharacters(field.type))) || domainFields.some((field) => hasHiddenCharacters(field.name) || hasHiddenCharacters(field.type)) || domainFields.some((field) => hidden(field.type, json.domain[field.name], 0)) || hidden(json.primaryType, json.message, 0);
452
+ };
453
+ /**
454
+ * `domain.chainId` as a number, when present: a safe non-negative integer given as a JSON number, a
455
+ * decimal string or a `0x` hex string.
456
+ */
457
+ const domainChainId = (domain) => {
458
+ const { chainId } = domain;
459
+ if (chainId === void 0) return;
460
+ const numeric = typeof chainId === "number" ? chainId : typeof chainId === "string" && /^(?:[0-9]+|0x[0-9a-fA-F]+)$/.test(chainId) ? Number(chainId) : NaN;
461
+ if (!Number.isSafeInteger(numeric) || numeric < 0) throw new ChainError("invalid-typed-data", "typed-data domain.chainId is malformed");
462
+ return numeric;
463
+ };
464
+ export { EVM_DELEGATION_PREFIX as C, checksumEvmAddress as D, encodeBatchExecute as E, evmAddressFromPublicKey as O, quantityBigInt as S, decodeBatchExecute as T, canonicalHex as _, isTypedDataInput as a, networkChainId as b, sameFields as c, typedDataFields as d, typedDataHasHiddenText as f, assertHex as g, typedDataUint as h, domainChainId as i, isEvmAddress as k, typedDataAddress as l, typedDataMessages as m, TYPED_FIELD_BUDGET as n, isTypedDataMessage as o, typedDataHashes as p, TYPED_FIELD_CODE_POINTS as r, parseTypedData as s, MAX_UINT48 as t, typedDataBytes as u, isCanonicalHex as v, EVM_DELEGATOR as w, normalizeEvmTransaction as x, isRecord as y };
465
+
466
+ //# sourceMappingURL=typed-data-DRtKULsH.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-data-DRtKULsH.mjs","names":[],"sources":["../src/evm/address.ts","../src/evm/delegation.ts","../src/evm/transaction.ts","../src/evm/typed-data.ts"],"sourcesContent":["import { secp256k1 } from \"@noble/curves/secp256k1.js\";\nimport { keccak_256 } from \"@noble/hashes/sha3.js\";\nimport { bytesToHex } from \"@noble/hashes/utils.js\";\nimport * as Address from \"ox/Address\";\n\nimport { ChainError } from \"../index.ts\";\n\n/** EIP-55 checksummed address, e.g. `0x52908400098527886E0F7030069857D2E4169EE7`. */\nexport const isEvmAddress = (value: string): boolean => /^0x[0-9a-fA-F]{40}$/.test(value);\n\nexport function checksumEvmAddress(address: string): string {\n if (!isEvmAddress(address)) {\n throw new ChainError(\"invalid-address\", \"not an EVM address\");\n }\n const checksummed = Address.checksum(address);\n Address.assert(checksummed, { strict: true });\n return checksummed;\n}\n\n/** `keccak256(pubkey)[12:]` — accepts a 33-byte compressed or 65-byte uncompressed secp256k1 key. */\nexport function evmAddressFromPublicKey(pubkey: Uint8Array): string {\n const uncompressed =\n pubkey.length === 65 && pubkey[0] === 4\n ? pubkey\n : pubkey.length === 33\n ? secp256k1.Point.fromBytes(pubkey).toBytes(false)\n : undefined;\n if (uncompressed === undefined || uncompressed[0] !== 4) {\n throw new ChainError(\"invalid-address\", \"expected a compressed or uncompressed secp256k1 key\");\n }\n return checksumEvmAddress(`0x${bytesToHex(keccak_256(uncompressed.subarray(1))).slice(-40)}`);\n}\n","import * as AbiFunction from \"ox/AbiFunction\";\nimport * as AbiParameters from \"ox/AbiParameters\";\nimport * as Hex from \"ox/Hex\";\n\nimport { checksumEvmAddress, isEvmAddress } from \"./address.ts\";\n\n/**\n * MetaMask Delegation Framework EIP7702StatelessDeleGator v1.3.0 — deterministic CREATE2, the same\n * address on every chain that supports it.\n */\nexport const EVM_DELEGATOR = {\n address: \"0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B\",\n name: \"EIP7702StatelessDeleGator\",\n version: \"1.3.0\",\n} as const;\n\n/** The EIP-7702 designator byte prefix: `0xef0100 ‖ address` marks a delegated account's code. */\nexport const EVM_DELEGATION_PREFIX = \"0xef0100\";\n\n/** ERC-7821 batch-default execution mode: `0x01` followed by 31 zero bytes. */\nexport const EXECUTE_BATCH_MODE =\n \"0x0100000000000000000000000000000000000000000000000000000000000000\";\n\nexport const EXECUTE: AbiFunction.AbiFunction = AbiFunction.from(\n \"function execute(bytes32 mode, bytes executionData)\",\n);\n\nconst EXECUTIONS = [\n {\n type: \"tuple[]\",\n components: [\n { name: \"target\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"callData\", type: \"bytes\" },\n ],\n },\n] as const;\n\nconst hex = (v: string): `0x${string}` => {\n Hex.assert(v);\n return v;\n};\n\n/** ERC-7821 batch-default self-call payload for `execute` on the delegator. */\nexport const encodeBatchExecute = (\n calls: ReadonlyArray<{ readonly to: string; readonly value: bigint; readonly data: string }>,\n): string =>\n AbiFunction.encodeData(EXECUTE, [\n EXECUTE_BATCH_MODE,\n AbiParameters.encode(EXECUTIONS, [\n calls.map((c) => ({\n target: hex(checksumEvmAddress(c.to)),\n value: c.value,\n callData: hex(c.data),\n })),\n ]),\n ]);\n\ntype Execution = { readonly to: string; readonly value: bigint; readonly data: string };\n\nconst list = (v: unknown): ReadonlyArray<unknown> => (Array.isArray(v) ? v : []);\n\nconst isExecution = (\n e: unknown,\n): e is { readonly target: string; readonly value: bigint; readonly callData: string } =>\n typeof e === \"object\" &&\n e !== null &&\n \"target\" in e &&\n \"value\" in e &&\n \"callData\" in e &&\n typeof e.target === \"string\" &&\n isEvmAddress(e.target) &&\n typeof e.value === \"bigint\" &&\n typeof e.callData === \"string\";\n\n/** Decodes an `execute` call; undefined unless the encoding is canonical batch-default mode. */\nexport const decodeBatchExecute = (data: string): ReadonlyArray<Execution> | undefined => {\n try {\n const args = list(AbiFunction.decodeData(EXECUTE, hex(data)));\n const [mode, executionData] = args;\n if (mode !== EXECUTE_BATCH_MODE || typeof executionData !== \"string\") {\n return undefined;\n }\n const decoded: unknown = AbiParameters.decode(EXECUTIONS, hex(executionData));\n const [inner] = list(decoded);\n const executions: Execution[] = [];\n for (const e of list(inner)) {\n if (!isExecution(e)) {\n return undefined;\n }\n executions.push({\n to: checksumEvmAddress(e.target),\n value: e.value,\n data: e.callData,\n });\n }\n /* Display must equal execution: accept only the canonical encoding the delegator's own\n * calldata decoder would read — a non-canonical payload (trailing bytes, aliased offsets)\n * can decode one way here and another on-chain. */\n return encodeBatchExecute(executions).toLowerCase() === data.toLowerCase()\n ? executions\n : undefined;\n } catch {\n return undefined;\n }\n};\n","import { ChainError } from \"../index.ts\";\nimport type { EvmTransaction, EvmAccessListEntry } from \"../index.ts\";\nimport { checksumEvmAddress, isEvmAddress } from \"./address.ts\";\nimport { EVM_DELEGATOR } from \"./delegation.ts\";\n\n/** Validates a string is `0x`-hex and narrows it to the branded hex type. */\nexport function assertHex(value: string, field: string): asserts value is `0x${string}` {\n if (!/^0x(?:[0-9a-fA-F]{2})*$/.test(value)) {\n throw new ChainError(\"invalid-quantity\", `${field} must be 0x-prefixed bytes`);\n }\n}\n\nexport const isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst CANONICAL_HEX = /^0x(?:0|[1-9a-f][0-9a-f]*)$/;\n\nexport const isCanonicalHex = (value: string): boolean => CANONICAL_HEX.test(value);\n\nexport const canonicalHex = (value: bigint): string => `0x${value.toString(16)}`;\n\n/** Parses a JSON-RPC quantity: `0x` and at least one hex digit — a bare `\"0x\"` is malformed. */\nexport const quantityBigInt = (value: unknown, field: string): bigint => {\n if (typeof value !== \"string\" || !/^0x[0-9a-fA-F]+$/.test(value)) {\n throw new ChainError(\"invalid-quantity\", `${field} must be a 0x quantity`);\n }\n return BigInt(value);\n};\n\nconst safeInteger = (value: unknown, field: string): number => {\n if (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) {\n throw new ChainError(\"invalid-quantity\", `${field} must be a non-negative safe integer`);\n }\n return value;\n};\n\nconst quantity = (value: unknown, field: string): string => {\n if (typeof value !== \"string\") {\n throw new ChainError(\"invalid-quantity\", `${field} must be a 0x quantity string`);\n }\n if (CANONICAL_HEX.test(value)) {\n return value;\n }\n return canonicalHex(quantityBigInt(value, field));\n};\n\nconst hexBytes = (value: unknown, field: string): string => {\n if (typeof value !== \"string\" || !/^0x(?:[0-9a-fA-F]{2})*$/.test(value)) {\n throw new ChainError(\"invalid-quantity\", `${field} must be 0x-prefixed bytes`);\n }\n return value.toLowerCase();\n};\n\nconst accessList = (value: unknown): ReadonlyArray<EvmAccessListEntry> => {\n if (!Array.isArray(value)) {\n throw new ChainError(\"invalid-request\", \"accessList must be an array\");\n }\n return value.map((entry): EvmAccessListEntry => {\n if (!isRecord(entry)) {\n throw new ChainError(\"invalid-address\", \"accessList entries must be objects\");\n }\n const keys = Object.keys(entry).sort();\n if (keys.length !== 2 || keys[0] !== \"address\" || keys[1] !== \"storageKeys\") {\n throw new ChainError(\n \"unknown-field\",\n `accessList entry fields must be exactly address+storageKeys, got ${keys.join(\",\")}`,\n );\n }\n const { address, storageKeys } = entry;\n if (typeof address !== \"string\" || !isEvmAddress(address)) {\n throw new ChainError(\"invalid-address\", \"accessList entry has an invalid address\");\n }\n if (!Array.isArray(storageKeys)) {\n throw new ChainError(\"invalid-quantity\", \"accessList storageKeys must be an array\");\n }\n return {\n address: checksumEvmAddress(address),\n storageKeys: storageKeys.map((k) => {\n if (typeof k !== \"string\" || !/^0x[0-9a-fA-F]{64}$/.test(k)) {\n throw new ChainError(\n \"invalid-quantity\",\n \"accessList storageKeys must be 32-byte hex strings\",\n );\n }\n return k.toLowerCase();\n }),\n };\n });\n};\n\n/** The EIP-155 part of a CAIP-2 `network` string, e.g. `eip155:1` → 1. Chain 0 does not exist. */\nexport const networkChainId = (network: string): number => {\n const match = /^eip155:([1-9]\\d*)$/.exec(network);\n const idPart = match?.[1];\n if (idPart === undefined) {\n throw new ChainError(\"chain-id-mismatch\", `network is not an eip155 CAIP-2 id: ${network}`);\n }\n const id = Number(idPart);\n if (!Number.isSafeInteger(id)) {\n throw new ChainError(\"chain-id-mismatch\", `chain id is not a safe integer: ${network}`);\n }\n return id;\n};\n\nconst REQUIRED = {\n base: [\"chainId\", \"nonce\", \"gas\", \"value\", \"data\"],\n gasPrice: [\"gasPrice\"],\n accessList: [\"accessList\"],\n eip1559: [\"maxFeePerGas\", \"maxPriorityFeePerGas\"],\n} as const;\n\nconst ALLOWED = {\n base: [\"type\", \"chainId\", \"nonce\", \"gas\", \"value\", \"data\", \"to\"],\n legacy: [\"gasPrice\"],\n eip2930: [\"gasPrice\", \"accessList\"],\n eip1559: [\"accessList\", \"maxFeePerGas\", \"maxPriorityFeePerGas\"],\n eip7702: [\"accessList\", \"maxFeePerGas\", \"maxPriorityFeePerGas\", \"authorization\"],\n} as const;\n\nconst requireFields = (input: Record<string, unknown>, fields: ReadonlyArray<string>): void => {\n for (const field of fields) {\n if (input[field] === undefined) {\n throw new ChainError(\"invalid-request\", `tx.${field} is required`);\n }\n }\n};\n\nconst rejectUnknown = (\n input: Record<string, unknown>,\n type: \"legacy\" | \"eip2930\" | \"eip1559\" | \"eip7702\",\n): void => {\n const allowed = new Set<string>([...ALLOWED.base, ...ALLOWED[type]]);\n const unknown = Object.keys(input).filter((k) => !allowed.has(k));\n if (unknown.length > 0) {\n throw new ChainError(\n \"unknown-field\",\n `tx has unknown fields for ${type}: ${unknown.sort().join(\", \")}`,\n );\n }\n};\n\n/**\n * Canonicalizes an EVM transaction: exact key sets per type, all required fields present, `0x`\n * canonical quantities, EIP-55 addresses. Idempotent.\n */\nexport const normalizeEvmTransaction = (tx: unknown): EvmTransaction => {\n if (!isRecord(tx)) {\n throw new ChainError(\"invalid-request\", \"tx must be an object\");\n }\n const { type } = tx;\n if (type !== \"legacy\" && type !== \"eip2930\" && type !== \"eip1559\" && type !== \"eip7702\") {\n throw new ChainError(\n \"unsupported\",\n `transaction type ${String(type)} is not supported (legacy, eip2930, eip1559 and eip7702 only)`,\n );\n }\n rejectUnknown(tx, type);\n requireFields(tx, REQUIRED.base);\n const chainId = safeInteger(tx[\"chainId\"], \"chainId\");\n const nonce = safeInteger(tx[\"nonce\"], \"nonce\");\n const gas = quantity(tx[\"gas\"], \"gas\");\n const value = quantity(tx[\"value\"], \"value\");\n const data = hexBytes(tx[\"data\"], \"data\");\n const toRaw = tx[\"to\"];\n const to =\n toRaw === undefined\n ? undefined\n : typeof toRaw === \"string\" && isEvmAddress(toRaw)\n ? checksumEvmAddress(toRaw)\n : undefined;\n if (toRaw !== undefined && to === undefined) {\n throw new ChainError(\"invalid-address\", \"to must be a valid EVM address\");\n }\n const base = { chainId, nonce, gas, value, data, ...(to === undefined ? {} : { to }) };\n if (type === \"legacy\") {\n requireFields(tx, REQUIRED.gasPrice);\n return { type, ...base, gasPrice: quantity(tx[\"gasPrice\"], \"gasPrice\") };\n }\n if (type === \"eip2930\") {\n requireFields(tx, [...REQUIRED.gasPrice, ...REQUIRED.accessList]);\n return {\n type,\n ...base,\n gasPrice: quantity(tx[\"gasPrice\"], \"gasPrice\"),\n accessList: accessList(tx[\"accessList\"]),\n };\n }\n requireFields(tx, [...REQUIRED.accessList, ...REQUIRED.eip1559]);\n const fees = {\n maxFeePerGas: quantity(tx[\"maxFeePerGas\"], \"maxFeePerGas\"),\n maxPriorityFeePerGas: quantity(tx[\"maxPriorityFeePerGas\"], \"maxPriorityFeePerGas\"),\n };\n if (BigInt(fees.maxPriorityFeePerGas) > BigInt(fees.maxFeePerGas)) {\n throw new ChainError(\"invalid-request\", \"maxPriorityFeePerGas exceeds maxFeePerGas\");\n }\n const list = accessList(tx[\"accessList\"]);\n if (type === \"eip1559\") {\n return { type, ...base, accessList: list, ...fees };\n }\n if (to === undefined) {\n throw new ChainError(\"invalid-request\", \"tx.to is required for eip7702\");\n }\n if (chainId < 1) {\n throw new ChainError(\n \"invalid-request\",\n \"eip7702 chainId 0 is a chain-universal authorization and is never signed\",\n );\n }\n const auth = tx[\"authorization\"];\n if (!isRecord(auth) || Object.keys(auth).length !== 1 || typeof auth[\"address\"] !== \"string\") {\n throw new ChainError(\n \"invalid-request\",\n \"tx.authorization must be an object with exactly address\",\n );\n }\n const authAddress = checksumEvmAddress(auth[\"address\"]);\n if (\n authAddress !== EVM_DELEGATOR.address &&\n authAddress !== \"0x0000000000000000000000000000000000000000\"\n ) {\n throw new ChainError(\"unsupported\", \"authorization address is not supported\");\n }\n return {\n type,\n ...base,\n to,\n accessList: list,\n ...fees,\n authorization: { address: authAddress },\n };\n};\n","import * as Hex from \"ox/Hex\";\nimport * as TypedData from \"ox/TypedData\";\n\nimport { displayExcerpt, hasHiddenCharacters, isEncodedBytes } from \"../display.ts\";\nimport { ChainError } from \"../index.ts\";\nimport type { TypedDataLeaf } from \"../index.ts\";\nimport { checksumEvmAddress } from \"./address.ts\";\nimport { isRecord } from \"./transaction.ts\";\n\ntype TypedDataField = {\n readonly name: string;\n readonly type: string;\n};\n\n/**\n * The subset of the EIP-712 document the wallet needs to see before handing it to ox's validator —\n * object with `types`, `primaryType`, `domain` and `message` of the right shapes.\n */\nexport type TypedDataInput = {\n readonly types: Record<string, ReadonlyArray<TypedDataField>>;\n readonly primaryType: string;\n readonly domain: Record<string, unknown>;\n readonly message: Record<string, unknown>;\n};\n\nconst isField = (value: unknown): value is TypedDataField =>\n isRecord(value) && typeof value[\"name\"] === \"string\" && typeof value[\"type\"] === \"string\";\n\nexport const isTypedDataInput = (value: unknown): value is TypedDataInput => {\n if (!isRecord(value)) {\n return false;\n }\n const { types, primaryType, domain, message } = value;\n if (!isRecord(types)) {\n return false;\n }\n if (typeof primaryType !== \"string\" || primaryType === \"\") {\n return false;\n }\n if (!isRecord(domain)) {\n return false;\n }\n if (!isRecord(message)) {\n return false;\n }\n return Object.values(types).every((fields) => Array.isArray(fields) && fields.every(isField));\n};\n\nexport type ParsedTypedData = { readonly json: TypedDataInput };\n\n/** A message object inside the document's `message`. */\nexport type TypedDataMessage = Readonly<Record<string, unknown>>;\n\nexport const isTypedDataMessage = (value: unknown): value is TypedDataMessage =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n/**\n * The EIP-712 domain separator and message struct hash of a parsed document — the same encoder\n * `planEvmTypedData` signs (`keccak256(0x1901 | domain | message)` is the task digest). `message`\n * is `undefined` when the primary type is `EIP712Domain` itself.\n */\nexport const typedDataHashes = (\n json: TypedDataInput,\n): { readonly domain: Uint8Array; readonly message: Uint8Array | undefined } => {\n // ox encodes `0x19 ‖ 0x01 ‖ domainSeparator ‖ hashStruct(message)`; the struct hash is absent\n // when the primary type is EIP712Domain itself.\n const encoded = Hex.toBytes(\n TypedData.encode({\n domain: json.domain,\n types: json.types,\n primaryType: json.primaryType,\n message: json.message,\n }),\n );\n return {\n domain: encoded.subarray(2, 34),\n message: json.primaryType === \"EIP712Domain\" ? undefined : encoded.subarray(34),\n };\n};\n\n/** `value` is an array of message objects (empty allowed). */\nexport const typedDataMessages = (value: unknown): ReadonlyArray<TypedDataMessage> | undefined =>\n Array.isArray(value) && value.every(isTypedDataMessage) ? value : undefined;\n\n/** The `Type field,Type field` signature of struct `name` in `types`. */\nexport const typedDataSignature = (\n types: TypedDataInput[\"types\"],\n name: string,\n): string | undefined => types[name]?.map((field) => `${field.type} ${field.name}`).join(\",\");\n\n/** Struct `name` has exactly `fields`, in order, no more. */\nexport const sameFields = (\n types: TypedDataInput[\"types\"],\n name: string,\n fields: ReadonlyArray<string>,\n): boolean => typedDataSignature(types, name) === fields.join(\",\");\n\n/** A hex `address` field value, checksummed; `undefined` when malformed. */\nexport const typedDataAddress = (value: unknown): string | undefined =>\n typeof value === \"string\" && /^0x[0-9a-fA-F]{40}$/.test(value)\n ? checksumEvmAddress(value)\n : undefined;\n\n/** A uint field value (safe-integer number, decimal or `0x` hex string) ≤ `max`. */\nexport const typedDataUint = (value: unknown, max: bigint): bigint | undefined => {\n let parsed: bigint;\n if (typeof value === \"number\" && Number.isSafeInteger(value)) {\n parsed = BigInt(value);\n } else if (typeof value === \"string\" && /^(?:[0-9]+|0x[0-9a-fA-F]+)$/.test(value)) {\n parsed = BigInt(value);\n } else {\n return undefined;\n }\n return parsed >= 0n && parsed <= max ? parsed : undefined;\n};\n\n/** The largest timestamp a permit/order expiry or a Safe field is allowed to carry. */\nexport const MAX_UINT48: bigint = 2n ** 48n - 1n;\n\nconst isHexBytes = (value: unknown): value is `0x${string}` =>\n typeof value === \"string\" && /^0x(?:[0-9a-fA-F]{2})*$/.test(value);\n\n/** A `bytes` field value: `0x`-prefixed hex of even length. */\nexport const typedDataBytes = (value: unknown): `0x${string}` | undefined =>\n isHexBytes(value) ? value : undefined;\n\n/** Struct nesting allowed in a message — real protocols (Seaport, Permit2, Safe) stay under 8. */\nexport const MAX_TYPED_DATA_DEPTH = 32;\n\n/**\n * Walks `value` along `type`: every struct-typed value must be an object carrying its fields, and\n * struct/array nesting stays within MAX_TYPED_DATA_DEPTH — so a recursive type is bounded by its\n * message and a missing nested struct fails here rather than inside the encoder.\n */\nconst checkStructure = (\n types: TypedDataInput[\"types\"],\n type: string,\n value: unknown,\n depth: number,\n): void => {\n const array = /^(.+)\\[\\d*\\]$/.exec(type);\n const struct = array === null ? types[type] : undefined;\n if (array === null && struct === undefined) {\n return;\n }\n if (depth >= MAX_TYPED_DATA_DEPTH) {\n throw new ChainError(\"invalid-typed-data\", \"typedData nests too deeply\");\n }\n if (array !== null) {\n if (!Array.isArray(value)) {\n throw new ChainError(\"invalid-typed-data\", `typedData ${type} value is not an array`);\n }\n for (const item of value) {\n checkStructure(types, array[1] ?? \"\", item, depth + 1);\n }\n return;\n }\n if (!isRecord(value)) {\n throw new ChainError(\"invalid-typed-data\", `typedData ${type} value is not an object`);\n }\n for (const field of struct ?? []) {\n checkStructure(types, field.type, value[field.name], depth + 1);\n }\n};\n\n/**\n * Parses the EIP-712 JSON source and validates it with ox. `types.EIP712Domain` is required:\n * without it ox derives the domain type from the domain object while MetaMask hashes an empty\n * domain, so the same document would sign differently across wallets.\n */\nexport const parseTypedData = (typedData: string): ParsedTypedData => {\n let json: unknown;\n try {\n json = JSON.parse(typedData);\n } catch {\n throw new ChainError(\"invalid-typed-data\", \"typedData is not valid JSON\");\n }\n if (!isTypedDataInput(json)) {\n throw new ChainError(\n \"invalid-typed-data\",\n \"typedData must be a JSON object with types, primaryType, domain and message\",\n );\n }\n if (json.types[\"EIP712Domain\"] === undefined) {\n throw new ChainError(\"invalid-typed-data\", \"typedData must declare types.EIP712Domain\");\n }\n try {\n TypedData.validate(json);\n } catch {\n throw new ChainError(\"invalid-typed-data\", \"typedData failed EIP-712 validation\");\n }\n checkStructure(json.types, json.primaryType, json.message, 0);\n /* Only the domain keys `types.EIP712Domain` declares are hashed — undeclared keys are\n dropped so nothing downstream (display, recognisers, the chain-id check, signing) can\n read a field the signature does not commit to. */\n const declared = new Set((json.types[\"EIP712Domain\"] ?? []).map((field) => field.name));\n const domain = Object.fromEntries(\n Object.entries(json.domain).filter(([key]) => declared.has(key)),\n );\n return { json: { ...json, domain } };\n};\n\n/** Most leaves an unrecognised typed-data document may have and still be shown in full. */\nexport const TYPED_FIELD_BUDGET = 16;\n\n/** Longest path or value (in code points, after sanitising) one leaf line may show. */\nexport const TYPED_FIELD_CODE_POINTS = 96;\n\nconst FIXED_BYTES = /^bytes(?:[1-9]|[12][0-9]|3[0-2])$/;\nconst INT_TYPE = /^u?int([0-9]*)$/;\n\n/**\n * The display value of one atomic leaf, or `undefined` when the value is not in a form that is\n * shown exactly as it is encoded. Only the canonical forms every EIP-712 hasher agrees on are\n * accepted — anything else aborts the whole expansion.\n */\nconst leafValue = (type: string, value: unknown): string | undefined => {\n if (type === \"address\") {\n return typedDataAddress(value);\n }\n if (type === \"bool\") {\n return typeof value === \"boolean\" ? (value ? \"true\" : \"false\") : undefined;\n }\n if (type === \"string\") {\n if (typeof value !== \"string\") {\n return undefined;\n }\n const excerpt = displayExcerpt(value, 1, TYPED_FIELD_CODE_POINTS);\n return excerpt.omitted === 0 ? (excerpt.lines[0] ?? \"\") : undefined;\n }\n if (type === \"bytes\" || FIXED_BYTES.test(type)) {\n return typeof value === \"string\" &&\n /^0x([0-9a-fA-F]{2})*$/.test(value) &&\n value.length <= TYPED_FIELD_CODE_POINTS\n ? value.toLowerCase()\n : undefined;\n }\n const int = INT_TYPE.exec(type);\n if (int !== null) {\n const bits = int[1] === \"\" ? 256 : Number(int[1]);\n if (bits % 8 !== 0 || bits < 8 || bits > 256) {\n return undefined;\n }\n const signed = !type.startsWith(\"u\");\n let parsed: bigint;\n if (typeof value === \"number\" && Number.isSafeInteger(value)) {\n parsed = BigInt(value);\n } else if (\n typeof value === \"string\" &&\n ((signed ? /^-?[0-9]+$/ : /^[0-9]+$/).test(value) || /^0x[0-9a-fA-F]+$/.test(value))\n ) {\n parsed = BigInt(value);\n } else {\n return undefined;\n }\n const min = signed ? -(2n ** BigInt(bits - 1)) : 0n;\n const max = signed ? 2n ** BigInt(bits - 1) - 1n : 2n ** BigInt(bits) - 1n;\n return parsed >= min && parsed <= max ? parsed.toString(10) : undefined;\n }\n return undefined;\n};\n\n/**\n * Whether the atomic leaf of `type` holding `value` is a commitment: `bytesN` always is — the\n * signature commits to raw bytes the owner cannot read — as is a non-empty `bytes` or a `string`\n * that is just an encoded-bytes rendering of ≥ 32 bytes. `\"0x\"` and an empty-array leaf (\"[]\")\n * carry nothing and are not.\n */\nconst isCommitmentLeaf = (type: string, value: unknown): boolean =>\n (type === \"bytes\" && value !== \"0x\") ||\n FIXED_BYTES.test(type) ||\n (type === \"string\" && typeof value === \"string\" && isEncodedBytes(value));\n\n/**\n * Every leaf of `message` under `primaryType`, in EIP-712 encoding order (each struct's fields in\n * declaration order, arrays element by element), as display lines, and whether any leaf is a\n * commitment; `undefined` when there are more than TYPED_FIELD_BUDGET leaves or any leaf cannot be\n * shown exactly as it is encoded. `leaf` may override an atomic leaf's display — a string return is\n * used verbatim (commitment flags still apply) and `undefined` falls back to the default rule,\n * which aborts the expansion when it cannot show the leaf exactly.\n */\nexport const typedDataFields = (\n json: TypedDataInput,\n leaf?: (type: string, value: unknown) => string | undefined,\n):\n | { readonly fields: ReadonlyArray<TypedDataLeaf>; readonly hasCommitment: boolean }\n | undefined => {\n const leaves: TypedDataLeaf[] = [];\n let hasCommitment = false;\n const push = (path: string, value: string, commits: boolean): boolean => {\n const excerpt = displayExcerpt(path, 1, TYPED_FIELD_CODE_POINTS);\n if (excerpt.omitted !== 0) {\n return false;\n }\n leaves.push({ path: excerpt.lines[0] ?? \"\", value });\n hasCommitment = hasCommitment || commits;\n return leaves.length <= TYPED_FIELD_BUDGET;\n };\n const walk = (type: string, value: unknown, path: string): boolean => {\n const array = /^(.+)\\[\\d*\\]$/.exec(type);\n if (array !== null) {\n if (!Array.isArray(value)) {\n return false;\n }\n return value.length === 0\n ? push(path, \"[]\", false)\n : value.every((item, index) => walk(array[1] ?? \"\", item, `${path}[${index}]`));\n }\n const struct = json.types[type];\n if (struct !== undefined) {\n return (\n isTypedDataMessage(value) &&\n struct.every((field) =>\n walk(field.type, value[field.name], path === \"\" ? field.name : `${path}.${field.name}`),\n )\n );\n }\n const display = leaf?.(type, value) ?? leafValue(type, value);\n return display !== undefined && push(path, display, isCommitmentLeaf(type, value));\n };\n return walk(json.primaryType, json.message, \"\") ? { fields: leaves, hasCommitment } : undefined;\n};\n\n/**\n * Whether any `string` leaf of the document carries characters the text rule hides — domain fields\n * under `types.EIP712Domain` (or the fields ox derives when it is not declared) and message fields\n * under `primaryType`, walked through structs and arrays — or the type encoding's own strings do:\n * `primaryType`, every key of `types`, and every field's `name` and `type` are hashed into the\n * signature, so a deceptive code point there is blind for the same reason as hidden message bytes.\n * All declared types are scanned, not only the ones the primary type reaches. A key the type does\n * not declare is not signed and is ignored. Never throws: a branch it cannot walk counts as no\n * hidden text — malformed documents are refused by the validator.\n */\nexport const typedDataHasHiddenText = (json: TypedDataInput): boolean => {\n const hidden = (type: string, value: unknown, depth: number): boolean => {\n if (depth >= MAX_TYPED_DATA_DEPTH) {\n return false;\n }\n const array = /^(.+)\\[\\d*\\]$/.exec(type);\n if (array !== null) {\n return Array.isArray(value) && value.some((item) => hidden(array[1] ?? \"\", item, depth + 1));\n }\n const struct = json.types[type];\n if (struct !== undefined) {\n return (\n isRecord(value) && struct.some((field) => hidden(field.type, value[field.name], depth + 1))\n );\n }\n return type === \"string\" && typeof value === \"string\" && hasHiddenCharacters(value);\n };\n const domainFields =\n json.types[\"EIP712Domain\"] ?? TypedData.extractEip712DomainTypes(json.domain);\n const namesHidden =\n hasHiddenCharacters(json.primaryType) ||\n Object.entries(json.types).some(\n ([name, struct]) =>\n hasHiddenCharacters(name) ||\n struct.some((field) => hasHiddenCharacters(field.name) || hasHiddenCharacters(field.type)),\n ) ||\n domainFields.some(\n (field) => hasHiddenCharacters(field.name) || hasHiddenCharacters(field.type),\n );\n return (\n namesHidden ||\n domainFields.some((field) => hidden(field.type, json.domain[field.name], 0)) ||\n hidden(json.primaryType, json.message, 0)\n );\n};\n\n/**\n * `domain.chainId` as a number, when present: a safe non-negative integer given as a JSON number, a\n * decimal string or a `0x` hex string.\n */\nexport const domainChainId = (domain: Record<string, unknown>): number | undefined => {\n const { chainId } = domain;\n if (chainId === undefined) {\n return undefined;\n }\n const numeric =\n typeof chainId === \"number\"\n ? chainId\n : typeof chainId === \"string\" && /^(?:[0-9]+|0x[0-9a-fA-F]+)$/.test(chainId)\n ? Number(chainId)\n : Number.NaN;\n if (!Number.isSafeInteger(numeric) || numeric < 0) {\n throw new ChainError(\"invalid-typed-data\", \"typed-data domain.chainId is malformed\");\n }\n return numeric;\n};\n"],"mappings":";;;;;;;;;;;AAQA,MAAa,gBAAgB,UAA2B,sBAAsB,KAAK,KAAK;AAExF,SAAgB,mBAAmB,SAAyB;CAC1D,IAAI,CAAC,aAAa,OAAO,GACvB,MAAM,IAAI,WAAW,mBAAmB,oBAAoB;CAE9D,MAAM,cAAc,QAAQ,SAAS,OAAO;CAC5C,QAAQ,OAAO,aAAa,EAAE,QAAQ,KAAK,CAAC;CAC5C,OAAO;AACT;;AAGA,SAAgB,wBAAwB,QAA4B;CAClE,MAAM,eACJ,OAAO,WAAW,MAAM,OAAO,OAAO,IAClC,SACA,OAAO,WAAW,KAChB,UAAU,MAAM,UAAU,MAAM,CAAC,CAAC,QAAQ,KAAK,IAC/C,KAAA;CACR,IAAI,iBAAiB,KAAA,KAAa,aAAa,OAAO,GACpD,MAAM,IAAI,WAAW,mBAAmB,qDAAqD;CAE/F,OAAO,mBAAmB,KAAK,WAAW,WAAW,aAAa,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG;AAC9F;;;;;;ACrBA,MAAa,gBAAgB;CAC3B,SAAS;CACT,MAAM;CACN,SAAS;AACX;;AAGA,MAAa,wBAAwB;;AAGrC,MAAa,qBACX;AAEF,MAAa,UAAmC,YAAY,KAC1D,qDACF;AAEA,MAAM,aAAa,CACjB;CACE,MAAM;CACN,YAAY;EACV;GAAE,MAAM;GAAU,MAAM;EAAU;EAClC;GAAE,MAAM;GAAS,MAAM;EAAU;EACjC;GAAE,MAAM;GAAY,MAAM;EAAQ;CACpC;AACF,CACF;AAEA,MAAM,OAAO,MAA6B;CACxC,IAAI,OAAO,CAAC;CACZ,OAAO;AACT;;AAGA,MAAa,sBACX,UAEA,YAAY,WAAW,SAAS,CAC9B,oBACA,cAAc,OAAO,YAAY,CAC/B,MAAM,KAAK,OAAO;CAChB,QAAQ,IAA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AS,CAAC;AAE5C;;;;;AAMA,MAAa,iBAAiB,WAAwD;CACpF,MAAM,EAAE,YAAY;CACpB,IAAI,YAAY,KAAA,GACd;CAEF,MAAM,UACJ,OAAO,YAAY,WACf,UACA,OAAO,YAAY,YAAY,8BAA8B,KAAK,OAAO,IACvE,OAAO,OAAO,IACd;CACR,IAAI,CAAC,OAAO,cAAc,OAAO,KAAK,UAAU,GAC9C,MAAM,IAAI,WAAW,sBAAsB,wCAAwC;CAErF,OAAO;AACT"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qntx/wallet-chains",
3
- "version": "0.12.0",
4
- "description": "qntx/wallet chain semantics: SignRequest codecs, display decoding, verifiability and signing for EVM, Solana and Bitcoin",
3
+ "version": "0.14.0",
4
+ "description": "qntx/wallet chain semantics: SignRequest codecs, display decoding, verifiability and signing for EVM, Solana, TRON and Bitcoin",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "author": "QuantX <x@qntx.org>",
7
7
  "repository": {
@@ -46,6 +46,18 @@
46
46
  "types": "./dist/bitcoin-sign.d.mts",
47
47
  "default": "./dist/bitcoin-sign.mjs"
48
48
  },
49
+ "./tron/sign": {
50
+ "types": "./dist/tron-sign.d.mts",
51
+ "default": "./dist/tron-sign.mjs"
52
+ },
53
+ "./tron": {
54
+ "types": "./dist/tron.d.mts",
55
+ "default": "./dist/tron.mjs"
56
+ },
57
+ "./networks": {
58
+ "types": "./dist/networks.d.mts",
59
+ "default": "./dist/networks.mjs"
60
+ },
49
61
  "./package.json": "./package.json"
50
62
  },
51
63
  "publishConfig": {
@@ -55,9 +67,10 @@
55
67
  "build": "vp pack",
56
68
  "test": "vp test && bun scripts/size-check.ts",
57
69
  "test:coverage": "vp test --coverage",
70
+ "fuzz": "vp test fuzz --testTimeout 1800000",
58
71
  "typecheck": "tsc --noEmit",
59
72
  "smoke:hermes": "bun scripts/hermes-smoke.ts",
60
- "check:pkg": "vp pack && bun ../../scripts/check-dist-deps.ts . && publint && attw --pack . --profile esm-only"
73
+ "check:pkg": "vp pack && bun ../../scripts/check-dist-deps.ts . && bun ../../scripts/check-api.ts . && publint && attw --pack . --profile esm-only"
61
74
  },
62
75
  "dependencies": {
63
76
  "@noble/curves": "2.4.0",
@@ -69,6 +82,7 @@
69
82
  "@solana/addresses": "8.5.0",
70
83
  "@solana/codecs": "8.5.0",
71
84
  "@solana/transaction-messages": "8.5.0",
85
+ "@solana/transactions": "8.5.0",
72
86
  "ox": "1.8.12"
73
87
  },
74
88
  "devDependencies": {
@@ -92,13 +106,6 @@
92
106
  "viem": "2.57.12",
93
107
  "vite-plus": "1.4.0"
94
108
  },
95
- "devEngines": {
96
- "packageManager": {
97
- "name": "bun",
98
- "version": "1.4.0",
99
- "onFail": "ignore"
100
- }
101
- },
102
109
  "engines": {
103
110
  "node": ">=20.19.0"
104
111
  }