@qntx/wallet-chains 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bitcoin-sign.mjs +1 -1
- package/dist/bitcoin.d.mts +7 -6
- package/dist/bitcoin.mjs +45 -212
- package/dist/bitcoin.mjs.map +1 -1
- package/dist/evm-sign.mjs +1 -1
- package/dist/evm.d.mts +4 -5
- package/dist/evm.mjs +28 -3
- package/dist/evm.mjs.map +1 -1
- package/dist/{message-AfNel4WZ.mjs → message-DtIS0ZWB.mjs} +3 -3
- package/dist/{message-AfNel4WZ.mjs.map → message-DtIS0ZWB.mjs.map} +1 -1
- package/dist/solana-sign.mjs +1 -1
- package/dist/solana.d.mts +48 -4
- package/dist/solana.mjs +96 -5
- package/dist/solana.mjs.map +1 -1
- package/dist/{typed-data-D28VBOIm.mjs → typed-data-C6XANSQF.mjs} +4 -266
- package/dist/typed-data-C6XANSQF.mjs.map +1 -0
- package/package.json +5 -2
- package/dist/curve-BeDNVVGm.mjs +0 -2865
- package/dist/curve-BeDNVVGm.mjs.map +0 -1
- package/dist/ed25519-DUtI5nWr.mjs +0 -586
- package/dist/ed25519-DUtI5nWr.mjs.map +0 -1
- package/dist/secp256k1-D0CRzacO.mjs +0 -1384
- package/dist/secp256k1-D0CRzacO.mjs.map +0 -1
- package/dist/typed-data-D28VBOIm.mjs.map +0 -1
|
@@ -1,271 +1,9 @@
|
|
|
1
1
|
import { ChainError } from "./index.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
3
|
+
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
4
|
+
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
4
5
|
import * as Address from "ox/Address";
|
|
5
6
|
import * as TypedData from "ox/TypedData";
|
|
6
|
-
//#region ../../node_modules/.bun/@noble+hashes@2.4.0/node_modules/@noble/hashes/sha3.js
|
|
7
|
-
/**
|
|
8
|
-
* SHA3 (keccak) hash function, based on a new "Sponge function" design.
|
|
9
|
-
* Different from older hashes, the internal state is bigger than output size.
|
|
10
|
-
*
|
|
11
|
-
* Check out
|
|
12
|
-
* {@link https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf | FIPS-202},
|
|
13
|
-
* {@link https://keccak.team/keccak.html | Website}, and
|
|
14
|
-
* {@link https://crypto.stackexchange.com/q/15727 | the differences between
|
|
15
|
-
* SHA-3 and Keccak}.
|
|
16
|
-
*
|
|
17
|
-
* Check out `sha3-addons` module for cSHAKE, k12, and others.
|
|
18
|
-
* @module
|
|
19
|
-
*/
|
|
20
|
-
const _0n = BigInt(0);
|
|
21
|
-
const _1n = BigInt(1);
|
|
22
|
-
const _2n = BigInt(2);
|
|
23
|
-
const _7n = BigInt(7);
|
|
24
|
-
const _256n = BigInt(256);
|
|
25
|
-
const _0x71n = BigInt(113);
|
|
26
|
-
const SHA3_PI = [];
|
|
27
|
-
const SHA3_ROTL = [];
|
|
28
|
-
const _SHA3_IOTA = [];
|
|
29
|
-
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
30
|
-
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
31
|
-
SHA3_PI.push(2 * (5 * y + x));
|
|
32
|
-
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
33
|
-
let t = _0n;
|
|
34
|
-
for (let j = 0; j < 7; j++) {
|
|
35
|
-
R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
|
|
36
|
-
if (R & _2n) t ^= _1n << (_1n << BigInt(j)) - _1n;
|
|
37
|
-
}
|
|
38
|
-
_SHA3_IOTA.push(t);
|
|
39
|
-
}
|
|
40
|
-
const IOTAS = split(_SHA3_IOTA, true);
|
|
41
|
-
const SHA3_IOTA_H = IOTAS[0];
|
|
42
|
-
const SHA3_IOTA_L = IOTAS[1];
|
|
43
|
-
const rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
44
|
-
const rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
45
|
-
const rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
46
|
-
const rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
47
|
-
const rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
|
|
48
|
-
const rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
|
|
49
|
-
const B = /* @__PURE__ */ new Uint32Array(10);
|
|
50
|
-
/**
|
|
51
|
-
* `keccakf1600` internal permutation, additionally allows adjusting the round count.
|
|
52
|
-
* @param s - 5x5 Keccak state encoded as 25 lanes split into 50 uint32 words
|
|
53
|
-
* in this file's local little-endian lane-word order
|
|
54
|
-
* @param rounds - number of rounds to execute
|
|
55
|
-
* @throws On wrong argument types. {@link TypeError}
|
|
56
|
-
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
57
|
-
* @throws If `rounds` is outside the supported `1..24` range. {@link Error}
|
|
58
|
-
* @example
|
|
59
|
-
* Permute a Keccak state with the default 24 rounds.
|
|
60
|
-
* ```ts
|
|
61
|
-
* keccakP(new Uint32Array(50));
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
function keccakP(s, rounds = 24) {
|
|
65
|
-
if (!(s instanceof Uint32Array)) throw new TypeError("\"s\" expected Uint32Array(50), got type=" + typeof s);
|
|
66
|
-
if (s.length !== 50) throw new RangeError("\"s\" expected Uint32Array(50), got length=" + s.length);
|
|
67
|
-
anumber(rounds, "rounds");
|
|
68
|
-
if (rounds < 1 || rounds > 24) throw new Error("\"rounds\" expected integer 1..24");
|
|
69
|
-
for (let round = 24 - rounds; round < 24; round++) {
|
|
70
|
-
for (let x = 0; x < 10; x++) B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
71
|
-
for (let x = 0; x < 10; x += 2) {
|
|
72
|
-
const idx1 = (x + 8) % 10;
|
|
73
|
-
const idx0 = (x + 2) % 10;
|
|
74
|
-
const B0 = B[idx0];
|
|
75
|
-
const B1 = B[idx0 + 1];
|
|
76
|
-
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
77
|
-
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
78
|
-
for (let y = 0; y < 50; y += 10) {
|
|
79
|
-
s[x + y] ^= Th;
|
|
80
|
-
s[x + y + 1] ^= Tl;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
let curH = s[2];
|
|
84
|
-
let curL = s[3];
|
|
85
|
-
for (let t = 0; t < 24; t++) {
|
|
86
|
-
const shift = SHA3_ROTL[t];
|
|
87
|
-
const Th = rotlH(curH, curL, shift);
|
|
88
|
-
const Tl = rotlL(curH, curL, shift);
|
|
89
|
-
const PI = SHA3_PI[t];
|
|
90
|
-
curH = s[PI];
|
|
91
|
-
curL = s[PI + 1];
|
|
92
|
-
s[PI] = Th;
|
|
93
|
-
s[PI + 1] = Tl;
|
|
94
|
-
}
|
|
95
|
-
for (let y = 0; y < 50; y += 10) {
|
|
96
|
-
const b0 = s[y], b1 = s[y + 1], b2 = s[y + 2], b3 = s[y + 3];
|
|
97
|
-
s[y] ^= ~s[y + 2] & s[y + 4];
|
|
98
|
-
s[y + 1] ^= ~s[y + 3] & s[y + 5];
|
|
99
|
-
s[y + 2] ^= ~s[y + 4] & s[y + 6];
|
|
100
|
-
s[y + 3] ^= ~s[y + 5] & s[y + 7];
|
|
101
|
-
s[y + 4] ^= ~s[y + 6] & s[y + 8];
|
|
102
|
-
s[y + 5] ^= ~s[y + 7] & s[y + 9];
|
|
103
|
-
s[y + 6] ^= ~s[y + 8] & b0;
|
|
104
|
-
s[y + 7] ^= ~s[y + 9] & b1;
|
|
105
|
-
s[y + 8] ^= ~b0 & b2;
|
|
106
|
-
s[y + 9] ^= ~b1 & b3;
|
|
107
|
-
}
|
|
108
|
-
s[0] ^= SHA3_IOTA_H[round];
|
|
109
|
-
s[1] ^= SHA3_IOTA_L[round];
|
|
110
|
-
}
|
|
111
|
-
clean(B);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Keccak sponge function.
|
|
115
|
-
* @param blockLen - absorb/squeeze rate in bytes
|
|
116
|
-
* @param suffix - domain separation suffix byte
|
|
117
|
-
* @param outputLen - default digest length in bytes. This base sponge only
|
|
118
|
-
* requires a non-negative integer; wrappers that need positive output
|
|
119
|
-
* lengths must enforce that themselves.
|
|
120
|
-
* @param enableXOF - whether XOF output is allowed
|
|
121
|
-
* @param rounds - number of Keccak-f rounds
|
|
122
|
-
* @example
|
|
123
|
-
* Build a sponge state, absorb bytes, then finalize a digest.
|
|
124
|
-
* ```ts
|
|
125
|
-
* const hash = new Keccak(136, 0x06, 32);
|
|
126
|
-
* hash.update(new Uint8Array([1, 2, 3]));
|
|
127
|
-
* hash.digest();
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
var Keccak = class Keccak {
|
|
131
|
-
state;
|
|
132
|
-
pos = 0;
|
|
133
|
-
posOut = 0;
|
|
134
|
-
finished = false;
|
|
135
|
-
state32;
|
|
136
|
-
destroyed = false;
|
|
137
|
-
blockLen;
|
|
138
|
-
suffix;
|
|
139
|
-
outputLen;
|
|
140
|
-
canXOF;
|
|
141
|
-
enableXOF = false;
|
|
142
|
-
rounds;
|
|
143
|
-
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
144
|
-
anumber(blockLen, "blockLen");
|
|
145
|
-
anumber(suffix, "suffix");
|
|
146
|
-
anumber(rounds, "rounds");
|
|
147
|
-
abool(enableXOF, "enableXOF");
|
|
148
|
-
this.blockLen = blockLen;
|
|
149
|
-
this.suffix = suffix;
|
|
150
|
-
this.outputLen = outputLen;
|
|
151
|
-
this.enableXOF = enableXOF;
|
|
152
|
-
this.canXOF = enableXOF;
|
|
153
|
-
this.rounds = rounds;
|
|
154
|
-
anumber(outputLen, "outputLen");
|
|
155
|
-
if (!(0 < blockLen && blockLen < 200)) throw new Error("\"blockLen\" must be 1..199");
|
|
156
|
-
this.state = /* @__PURE__ */ new Uint8Array(200);
|
|
157
|
-
this.state32 = u32(this.state);
|
|
158
|
-
}
|
|
159
|
-
clone() {
|
|
160
|
-
return this._cloneInto();
|
|
161
|
-
}
|
|
162
|
-
keccak() {
|
|
163
|
-
swap32IfBE(this.state32);
|
|
164
|
-
keccakP(this.state32, this.rounds);
|
|
165
|
-
swap32IfBE(this.state32);
|
|
166
|
-
this.posOut = 0;
|
|
167
|
-
this.pos = 0;
|
|
168
|
-
}
|
|
169
|
-
update(data) {
|
|
170
|
-
aexists(this);
|
|
171
|
-
abytes(data);
|
|
172
|
-
const { blockLen, state, state32 } = this;
|
|
173
|
-
const len = data.length;
|
|
174
|
-
const canUseU32 = blockLen % 4 === 0 && data.byteOffset % 4 === 0;
|
|
175
|
-
const blockLen32 = blockLen / 4;
|
|
176
|
-
const data32 = canUseU32 && len >= blockLen ? u32(data) : void 0;
|
|
177
|
-
for (let pos = 0; pos < len;) {
|
|
178
|
-
if (data32 !== void 0 && this.pos === 0 && pos % 4 === 0 && len - pos >= blockLen) {
|
|
179
|
-
for (let i = 0, o = pos / 4; i < blockLen32; i++) state32[i] ^= data32[o + i];
|
|
180
|
-
pos += blockLen;
|
|
181
|
-
this.pos = blockLen;
|
|
182
|
-
this.keccak();
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
186
|
-
for (let i = 0; i < take; i++) state[this.pos++] ^= data[pos++];
|
|
187
|
-
if (this.pos === blockLen) this.keccak();
|
|
188
|
-
}
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
finish() {
|
|
192
|
-
if (this.finished) return;
|
|
193
|
-
this.finished = true;
|
|
194
|
-
const { state, suffix, pos, blockLen } = this;
|
|
195
|
-
state[pos] ^= suffix;
|
|
196
|
-
if ((suffix & 128) !== 0 && pos === blockLen - 1) this.keccak();
|
|
197
|
-
state[blockLen - 1] ^= 128;
|
|
198
|
-
this.keccak();
|
|
199
|
-
}
|
|
200
|
-
writeInto(out) {
|
|
201
|
-
aexists(this, false);
|
|
202
|
-
abytes(out);
|
|
203
|
-
this.finish();
|
|
204
|
-
const bufferOut = this.state;
|
|
205
|
-
const { blockLen } = this;
|
|
206
|
-
for (let pos = 0, len = out.length; pos < len;) {
|
|
207
|
-
if (this.posOut >= blockLen) this.keccak();
|
|
208
|
-
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
209
|
-
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
210
|
-
this.posOut += take;
|
|
211
|
-
pos += take;
|
|
212
|
-
}
|
|
213
|
-
return out;
|
|
214
|
-
}
|
|
215
|
-
xofInto(out) {
|
|
216
|
-
if (!this.enableXOF) throw new Error("XOF is not enabled");
|
|
217
|
-
return this.writeInto(out);
|
|
218
|
-
}
|
|
219
|
-
xof(bytes) {
|
|
220
|
-
anumber(bytes);
|
|
221
|
-
return this.xofInto(new Uint8Array(bytes));
|
|
222
|
-
}
|
|
223
|
-
digestInto(out) {
|
|
224
|
-
aoutput(out, this);
|
|
225
|
-
if (this.finished) throw new Error("digest() was already called");
|
|
226
|
-
this.writeInto(out.length === this.outputLen ? out : out.subarray(0, this.outputLen));
|
|
227
|
-
this.destroy();
|
|
228
|
-
}
|
|
229
|
-
digest() {
|
|
230
|
-
const out = new Uint8Array(this.outputLen);
|
|
231
|
-
this.digestInto(out);
|
|
232
|
-
return out;
|
|
233
|
-
}
|
|
234
|
-
destroy() {
|
|
235
|
-
this.destroyed = true;
|
|
236
|
-
clean(this.state);
|
|
237
|
-
}
|
|
238
|
-
_cloneInto(to) {
|
|
239
|
-
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
240
|
-
to ||= new Keccak(blockLen, suffix, outputLen, enableXOF, rounds);
|
|
241
|
-
to.blockLen = blockLen;
|
|
242
|
-
to.state32.set(this.state32);
|
|
243
|
-
to.pos = this.pos;
|
|
244
|
-
to.posOut = this.posOut;
|
|
245
|
-
to.finished = this.finished;
|
|
246
|
-
to.rounds = rounds;
|
|
247
|
-
to.suffix = suffix;
|
|
248
|
-
to.outputLen = outputLen;
|
|
249
|
-
to.enableXOF = enableXOF;
|
|
250
|
-
to.canXOF = this.canXOF;
|
|
251
|
-
to.destroyed = this.destroyed;
|
|
252
|
-
return to;
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
const genKeccak = (suffix, blockLen, outputLen, info = {}) => createHasher(() => new Keccak(blockLen, suffix, outputLen), info);
|
|
256
|
-
/**
|
|
257
|
-
* Keccak-256 hash function. Different from SHA3-256.
|
|
258
|
-
* @param msg - message bytes to hash
|
|
259
|
-
* @param opts - Reserved hash options.
|
|
260
|
-
* @returns Digest bytes.
|
|
261
|
-
* @example
|
|
262
|
-
* Hash a message with Keccak-256.
|
|
263
|
-
* ```ts
|
|
264
|
-
* keccak_256(new Uint8Array([97, 98, 99]));
|
|
265
|
-
* ```
|
|
266
|
-
*/
|
|
267
|
-
const keccak_256 = /* @__PURE__ */ genKeccak(1, 136, 32);
|
|
268
|
-
//#endregion
|
|
269
7
|
//#region src/evm/address.ts
|
|
270
8
|
/** EIP-55 checksummed address, e.g. `0x52908400098527886E0F7030069857D2E4169EE7`. */
|
|
271
9
|
const isEvmAddress = (value) => /^0x[0-9a-fA-F]{40}$/.test(value);
|
|
@@ -461,4 +199,4 @@ const typedDataWarnings = (parsed) => parsed.chainIdMismatch ? [{
|
|
|
461
199
|
//#endregion
|
|
462
200
|
export { isCanonicalHex as a, normalizeEvmTransaction as c, isEvmAddress as d, canonicalHex as i, checksumEvmAddress as l, typedDataWarnings as n, isRecord as o, assertHex as r, networkChainId as s, parseTypedData as t, evmAddressFromPublicKey as u };
|
|
463
201
|
|
|
464
|
-
//# sourceMappingURL=typed-data-
|
|
202
|
+
//# sourceMappingURL=typed-data-C6XANSQF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-data-C6XANSQF.mjs","names":[],"sources":["../src/evm/address.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 { ChainError } from \"../index.ts\";\nimport type { EvmTransaction, EvmAccessListEntry } from \"../index.ts\";\nimport { checksumEvmAddress, isEvmAddress } from \"./address.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\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 if (/^0x[0-9a-fA-F]+$/.test(value) || value === \"0x\") {\n return canonicalHex(BigInt(value === \"0x\" ? \"0x0\" : value));\n }\n throw new ChainError(\"invalid-quantity\", `${field} must be a 0x quantity`);\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. */\nexport const networkChainId = (network: string): number => {\n const match = /^eip155:(\\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} 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\",\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\") {\n throw new ChainError(\n \"unsupported\",\n `transaction type ${String(type)} is not supported (legacy, eip2930 and eip1559 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 return {\n type,\n ...base,\n accessList: accessList(tx[\"accessList\"]),\n maxFeePerGas: quantity(tx[\"maxFeePerGas\"], \"maxFeePerGas\"),\n maxPriorityFeePerGas: quantity(tx[\"maxPriorityFeePerGas\"], \"maxPriorityFeePerGas\"),\n };\n};\n","import * as TypedData from \"ox/TypedData\";\n\nimport { ChainError } from \"../index.ts\";\nimport type { IntentWarning } from \"../index.ts\";\nimport { isRecord, networkChainId } 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\nconst 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 = {\n readonly json: TypedDataInput;\n /**\n * True when `domain.chainId` disagrees with the request's network — the intent is still signable\n * but renders `opaque` with a warning.\n */\n readonly chainIdMismatch: boolean;\n};\n\n/** Parses the EIP-712 JSON source and validates its shape with ox. */\nexport const parseTypedData = (typedData: string, network: 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 try {\n TypedData.validate(json);\n } catch {\n throw new ChainError(\"invalid-typed-data\", \"typedData failed EIP-712 validation\");\n }\n const { chainId } = json.domain;\n const numeric =\n typeof chainId === \"number\"\n ? chainId\n : typeof chainId === \"string\"\n ? Number(chainId)\n : Number.NaN;\n return {\n json,\n chainIdMismatch: Number.isSafeInteger(numeric) && numeric !== networkChainId(network),\n };\n};\n\nexport const typedDataWarnings = (parsed: ParsedTypedData): ReadonlyArray<IntentWarning> =>\n parsed.chainIdMismatch\n ? [\n {\n kind: \"chain-id-mismatch\",\n message: \"typed-data domain.chainId does not match the request network\",\n },\n ]\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;;;;AC1BA,SAAgB,UAAU,OAAe,OAA+C;CACtF,IAAI,CAAC,0BAA0B,KAAK,KAAK,GACvC,MAAM,IAAI,WAAW,oBAAoB,GAAG,MAAM,2BAA2B;AAEjF;AAEA,MAAa,YAAY,UACvB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAErE,MAAM,gBAAgB;AAEtB,MAAa,kBAAkB,UAA2B,cAAc,KAAK,KAAK;AAElF,MAAa,gBAAgB,UAA0B,KAAK,MAAM,SAAS,EAAE;AAE7E,MAAM,eAAe,OAAgB,UAA0B;CAC7D,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ACN,SAAS;AACX,CACF,IACA,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qntx/wallet-chains",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "qntx/wallet chain semantics: SignRequest codecs, display decoding, verifiability and signing for EVM, Solana and Bitcoin",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": "QuantX <x@qntx.org>",
|
|
@@ -56,9 +56,12 @@
|
|
|
56
56
|
"test": "vp test && bun scripts/size-check.ts",
|
|
57
57
|
"typecheck": "tsc --noEmit",
|
|
58
58
|
"smoke:hermes": "bun scripts/hermes-smoke.ts",
|
|
59
|
-
"check:pkg": "vp pack && publint && attw --pack . --profile esm-only"
|
|
59
|
+
"check:pkg": "vp pack && bun ../../scripts/check-dist-deps.ts . && publint && attw --pack . --profile esm-only"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
+
"@noble/curves": "2.4.0",
|
|
63
|
+
"@noble/hashes": "2.4.0",
|
|
64
|
+
"@scure/base": "2.4.0",
|
|
62
65
|
"@scure/bip32": "2.4.0",
|
|
63
66
|
"@scure/btc-signer": "2.4.1",
|
|
64
67
|
"@solana/addresses": "8.5.0",
|