@1money/protocol-ts-sdk 1.0.14

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 (65) hide show
  1. package/.claude/settings.local.json +14 -0
  2. package/CLAUDE.md +77 -0
  3. package/README.md +600 -0
  4. package/es/api/accounts/index.d.ts +20 -0
  5. package/es/api/accounts/types.d.ts +9 -0
  6. package/es/api/chain/index.d.ts +12 -0
  7. package/es/api/chain/types.d.ts +3 -0
  8. package/es/api/checkpoints/index.d.ts +26 -0
  9. package/es/api/checkpoints/types.d.ts +33 -0
  10. package/es/api/constants.d.ts +9 -0
  11. package/es/api/index.d.ts +31 -0
  12. package/es/api/index.js +593 -0
  13. package/es/api/state/index.d.ts +12 -0
  14. package/es/api/state/types.d.ts +7 -0
  15. package/es/api/tokens/index.d.ts +62 -0
  16. package/es/api/tokens/types.d.ts +130 -0
  17. package/es/api/transactions/index.d.ts +35 -0
  18. package/es/api/transactions/types.d.ts +25 -0
  19. package/es/api/types.d.ts +18 -0
  20. package/es/client/core.d.ts +109 -0
  21. package/es/client/index.d.ts +21 -0
  22. package/es/client/index.js +373 -0
  23. package/es/index.d.ts +20 -0
  24. package/es/index.js +1490 -0
  25. package/es/utils/address.d.ts +15 -0
  26. package/es/utils/index.d.ts +6 -0
  27. package/es/utils/index.js +841 -0
  28. package/es/utils/interface.d.ts +7 -0
  29. package/es/utils/safePromise.d.ts +4 -0
  30. package/es/utils/sign.d.ts +15 -0
  31. package/es/utils/txHash.d.ts +2 -0
  32. package/es/utils/typeof.d.ts +2 -0
  33. package/lib/api/accounts/index.d.ts +20 -0
  34. package/lib/api/accounts/types.d.ts +9 -0
  35. package/lib/api/chain/index.d.ts +12 -0
  36. package/lib/api/chain/types.d.ts +3 -0
  37. package/lib/api/checkpoints/index.d.ts +26 -0
  38. package/lib/api/checkpoints/types.d.ts +33 -0
  39. package/lib/api/constants.d.ts +9 -0
  40. package/lib/api/index.d.ts +31 -0
  41. package/lib/api/index.js +692 -0
  42. package/lib/api/state/index.d.ts +12 -0
  43. package/lib/api/state/types.d.ts +7 -0
  44. package/lib/api/tokens/index.d.ts +62 -0
  45. package/lib/api/tokens/types.d.ts +130 -0
  46. package/lib/api/transactions/index.d.ts +35 -0
  47. package/lib/api/transactions/types.d.ts +25 -0
  48. package/lib/api/types.d.ts +18 -0
  49. package/lib/client/core.d.ts +109 -0
  50. package/lib/client/index.d.ts +21 -0
  51. package/lib/client/index.js +434 -0
  52. package/lib/index.d.ts +20 -0
  53. package/lib/index.js +1591 -0
  54. package/lib/utils/address.d.ts +15 -0
  55. package/lib/utils/index.d.ts +6 -0
  56. package/lib/utils/index.js +937 -0
  57. package/lib/utils/interface.d.ts +7 -0
  58. package/lib/utils/safePromise.d.ts +4 -0
  59. package/lib/utils/sign.d.ts +15 -0
  60. package/lib/utils/txHash.d.ts +2 -0
  61. package/lib/utils/typeof.d.ts +2 -0
  62. package/package.json +111 -0
  63. package/public/favicon.ico +0 -0
  64. package/public/logo.png +0 -0
  65. package/umd/1money-protocol-ts-sdk.min.js +2 -0
@@ -0,0 +1,937 @@
1
+ 'use strict';var viem=require('viem'),rlp=require('@ethereumjs/rlp');/**
2
+ * Derives the token account address given the wallet address and mint address.
3
+ *
4
+ * Address is 20 byte, 160 bits. Let's say if we want to support 50 billion
5
+ * accounts on 1money. That's about 36 bits. There are 124 bits remaining. In
6
+ * other words, the collision probability is 1/2^124, which is very very low.
7
+ * So, we will be fine to just use the hash of the wallet address and mint
8
+ * address to derive the token account address.
9
+ *
10
+ * @param walletAddress - The wallet address (20 bytes)
11
+ * @param mintAddress - The mint address (20 bytes)
12
+ * @returns The derived token account address
13
+ */
14
+ function deriveTokenAddress(walletAddress, mintAddress) {
15
+ var walletBytes = walletAddress.startsWith('0x')
16
+ ? viem.hexToBytes(walletAddress)
17
+ : viem.stringToBytes(walletAddress);
18
+ var mintBytes = mintAddress.startsWith('0x')
19
+ ? viem.hexToBytes(mintAddress)
20
+ : viem.stringToBytes(mintAddress);
21
+ var combined = new Uint8Array(walletBytes.length + mintBytes.length);
22
+ combined.set(walletBytes, 0);
23
+ combined.set(mintBytes, walletBytes.length);
24
+ var hashHex = viem.keccak256(combined);
25
+ var hashBytes = viem.hexToBytes(hashHex);
26
+ var addressBytes = hashBytes.slice(12);
27
+ return viem.bytesToHex(addressBytes);
28
+ }/******************************************************************************
29
+ Copyright (c) Microsoft Corporation.
30
+
31
+ Permission to use, copy, modify, and/or distribute this software for any
32
+ purpose with or without fee is hereby granted.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
35
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
37
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
38
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
39
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
40
+ PERFORMANCE OF THIS SOFTWARE.
41
+ ***************************************************************************** */
42
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
43
+
44
+
45
+ function __awaiter(thisArg, _arguments, P, generator) {
46
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
47
+ return new (P || (P = Promise))(function (resolve, reject) {
48
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
49
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
50
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
51
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
52
+ });
53
+ }
54
+
55
+ function __generator(thisArg, body) {
56
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
57
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
58
+ function verb(n) { return function (v) { return step([n, v]); }; }
59
+ function step(op) {
60
+ if (f) throw new TypeError("Generator is already executing.");
61
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
62
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
63
+ if (y = 0, t) op = [op[0] & 2, t.value];
64
+ switch (op[0]) {
65
+ case 0: case 1: t = op; break;
66
+ case 4: _.label++; return { value: op[1], done: false };
67
+ case 5: _.label++; y = op[1]; op = [0]; continue;
68
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
69
+ default:
70
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
71
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
72
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
73
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
74
+ if (t[2]) _.ops.pop();
75
+ _.trys.pop(); continue;
76
+ }
77
+ op = body.call(thisArg, _);
78
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
79
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
80
+ }
81
+ }
82
+
83
+ function __spreadArray(to, from, pack) {
84
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
85
+ if (ar || !(i in from)) {
86
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
87
+ ar[i] = from[i];
88
+ }
89
+ }
90
+ return to.concat(ar || Array.prototype.slice.call(from));
91
+ }
92
+
93
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
94
+ var e = new Error(message);
95
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
96
+ };// concurrent
97
+ function safePromiseAll(arr) {
98
+ // @ts-expect-error
99
+ if (!arr || !arr.length)
100
+ return Promise.resolve([]);
101
+ return Promise.all(arr);
102
+ }
103
+ // serial
104
+ function safePromiseLine(arr) {
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ var res, i, _a, _b;
107
+ return __generator(this, function (_c) {
108
+ switch (_c.label) {
109
+ case 0:
110
+ if (!arr || !arr.length)
111
+ return [2 /*return*/, []];
112
+ res = [];
113
+ i = 0;
114
+ _c.label = 1;
115
+ case 1:
116
+ if (!(i < arr.length)) return [3 /*break*/, 6];
117
+ _c.label = 2;
118
+ case 2:
119
+ _c.trys.push([2, 4, , 5]);
120
+ _b = (_a = res).push;
121
+ return [4 /*yield*/, arr[i](i)];
122
+ case 3:
123
+ _b.apply(_a, [_c.sent()]);
124
+ return [3 /*break*/, 5];
125
+ case 4:
126
+ _c.sent();
127
+ return [3 /*break*/, 5];
128
+ case 5:
129
+ i++;
130
+ return [3 /*break*/, 1];
131
+ case 6: return [2 /*return*/, res];
132
+ }
133
+ });
134
+ });
135
+ }function _typeof(ele) {
136
+ if (typeof ele !== 'object')
137
+ return (typeof ele).toLowerCase();
138
+ var typeStr = Object.prototype.toString.call(ele);
139
+ return typeStr.slice(8, typeStr.length - 1).toLowerCase();
140
+ }/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
141
+ /**
142
+ * 4KB JS implementation of secp256k1 ECDSA / Schnorr signatures & ECDH.
143
+ * Compliant with RFC6979 & BIP340.
144
+ * @module
145
+ */
146
+ /**
147
+ * Curve params. secp256k1 is short weierstrass / koblitz curve. Equation is y² == x³ + ax + b.
148
+ * * P = `2n**256n-2n**32n-2n**977n` // field over which calculations are done
149
+ * * N = `2n**256n - 0x14551231950b75fc4402da1732fc9bebfn` // group order, amount of curve points
150
+ * * h = `1n` // cofactor
151
+ * * a = `0n` // equation param
152
+ * * b = `7n` // equation param
153
+ * * Gx, Gy are coordinates of Generator / base point
154
+ */
155
+ const secp256k1_CURVE = {
156
+ p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,
157
+ n: 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,
158
+ b: 7n,
159
+ Gx: 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,
160
+ Gy: 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,
161
+ };
162
+ const { p: P, n: N, Gx, Gy, b: _b } = secp256k1_CURVE;
163
+ const L = 32; // field / group byte length
164
+ const L2 = 64;
165
+ // Helpers and Precomputes sections are reused between libraries
166
+ // ## Helpers
167
+ // ----------
168
+ // error helper, messes-up stack trace
169
+ const err = (m = '') => {
170
+ throw new Error(m);
171
+ };
172
+ const isBig = (n) => typeof n === 'bigint'; // is big integer
173
+ const isStr = (s) => typeof s === 'string'; // is string
174
+ const isBytes = (a) => a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
175
+ /** assert is Uint8Array (of specific length) */
176
+ const abytes = (a, l) => !isBytes(a) || (typeof l === 'number' && l > 0 && a.length !== l)
177
+ ? err('Uint8Array expected')
178
+ : a;
179
+ /** create Uint8Array */
180
+ const u8n = (len) => new Uint8Array(len);
181
+ const u8fr = (buf) => Uint8Array.from(buf);
182
+ const padh = (n, pad) => n.toString(16).padStart(pad, '0');
183
+ const bytesToHex = (b) => Array.from(abytes(b))
184
+ .map((e) => padh(e, 2))
185
+ .join('');
186
+ const C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 }; // ASCII characters
187
+ const _ch = (ch) => {
188
+ if (ch >= C._0 && ch <= C._9)
189
+ return ch - C._0; // '2' => 50-48
190
+ if (ch >= C.A && ch <= C.F)
191
+ return ch - (C.A - 10); // 'B' => 66-(65-10)
192
+ if (ch >= C.a && ch <= C.f)
193
+ return ch - (C.a - 10); // 'b' => 98-(97-10)
194
+ return;
195
+ };
196
+ const hexToBytes = (hex) => {
197
+ const e = 'hex invalid';
198
+ if (!isStr(hex))
199
+ return err(e);
200
+ const hl = hex.length;
201
+ const al = hl / 2;
202
+ if (hl % 2)
203
+ return err(e);
204
+ const array = u8n(al);
205
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
206
+ // treat each char as ASCII
207
+ const n1 = _ch(hex.charCodeAt(hi)); // parse first char, multiply it by 16
208
+ const n2 = _ch(hex.charCodeAt(hi + 1)); // parse second char
209
+ if (n1 === undefined || n2 === undefined)
210
+ return err(e);
211
+ array[ai] = n1 * 16 + n2; // example: 'A9' => 10*16 + 9
212
+ }
213
+ return array;
214
+ };
215
+ /** normalize hex or ui8a to ui8a */
216
+ const toU8 = (a, len) => abytes(isStr(a) ? hexToBytes(a) : u8fr(abytes(a)), len);
217
+ const cr = () => globalThis?.crypto; // WebCrypto is available in all modern environments
218
+ const subtle = () => cr()?.subtle ?? err('crypto.subtle must be defined');
219
+ // prettier-ignore
220
+ const concatBytes = (...arrs) => {
221
+ const r = u8n(arrs.reduce((sum, a) => sum + abytes(a).length, 0)); // create u8a of summed length
222
+ let pad = 0; // walk through each array,
223
+ arrs.forEach(a => { r.set(a, pad); pad += a.length; }); // ensure they have proper type
224
+ return r;
225
+ };
226
+ /** WebCrypto OS-level CSPRNG (random number generator). Will throw when not available. */
227
+ const randomBytes = (len = L) => {
228
+ const c = cr();
229
+ return c.getRandomValues(u8n(len));
230
+ };
231
+ const big = BigInt;
232
+ const arange = (n, min, max, msg = 'bad number: out of range') => isBig(n) && min <= n && n < max ? n : err(msg);
233
+ /** modular division */
234
+ const M = (a, b = P) => {
235
+ const r = a % b;
236
+ return r >= 0n ? r : b + r;
237
+ };
238
+ const modN = (a) => M(a, N);
239
+ /** Modular inversion using eucledian GCD (non-CT). No negative exponent for now. */
240
+ // prettier-ignore
241
+ const invert = (num, md) => {
242
+ if (num === 0n || md <= 0n)
243
+ err('no inverse n=' + num + ' mod=' + md);
244
+ let a = M(num, md), b = md, x = 0n, u = 1n;
245
+ while (a !== 0n) {
246
+ const q = b / a, r = b % a;
247
+ const m = x - u * q;
248
+ b = a, a = r, x = u, u = m;
249
+ }
250
+ return b === 1n ? M(x, md) : err('no inverse'); // b is gcd at this point
251
+ };
252
+ const apoint = (p) => (p instanceof Point ? p : err('Point expected'));
253
+ // ## End of Helpers
254
+ // -----------------
255
+ /** secp256k1 formula. Koblitz curves are subclass of weierstrass curves with a=0, making it x³+b */
256
+ const koblitz = (x) => M(M(x * x) * x + _b);
257
+ /** assert is field element or 0 */
258
+ const afield0 = (n) => arange(n, 0n, P);
259
+ /** assert is field element */
260
+ const afield = (n) => arange(n, 1n, P);
261
+ /** assert is group elem */
262
+ const agroup = (n) => arange(n, 1n, N);
263
+ const isEven = (y) => (y & 1n) === 0n;
264
+ /** create Uint8Array of byte n */
265
+ const u8of = (n) => Uint8Array.of(n);
266
+ const getPrefix = (y) => u8of(isEven(y) ? 0x02 : 0x03);
267
+ /** lift_x from BIP340 calculates square root. Validates x, then validates root*root. */
268
+ const lift_x = (x) => {
269
+ // Let c = x³ + 7 mod p. Fail if x ≥ p. (also fail if x < 1)
270
+ const c = koblitz(afield(x));
271
+ // c = √y
272
+ // y = c^((p+1)/4) mod p
273
+ // This formula works for fields p = 3 mod 4 -- a special, fast case.
274
+ // Paper: "Square Roots from 1;24,51,10 to Dan Shanks".
275
+ let r = 1n;
276
+ for (let num = c, e = (P + 1n) / 4n; e > 0n; e >>= 1n) {
277
+ // powMod: modular exponentiation.
278
+ if (e & 1n)
279
+ r = (r * num) % P; // Uses exponentiation by squaring.
280
+ num = (num * num) % P; // Not constant-time.
281
+ }
282
+ return M(r * r) === c ? r : err('sqrt invalid'); // check if result is valid
283
+ };
284
+ /** Point in 3d xyz projective coordinates. 3d takes less inversions than 2d. */
285
+ class Point {
286
+ static BASE;
287
+ static ZERO;
288
+ px;
289
+ py;
290
+ pz;
291
+ constructor(px, py, pz) {
292
+ this.px = afield0(px);
293
+ this.py = afield(py); // y can't be 0 in Projective
294
+ this.pz = afield0(pz);
295
+ Object.freeze(this);
296
+ }
297
+ /** Convert Uint8Array or hex string to Point. */
298
+ static fromBytes(bytes) {
299
+ abytes(bytes);
300
+ let p = undefined;
301
+ // First byte is prefix, rest is data. There are 2 kinds: compressed & uncompressed:
302
+ // * [0x02 or 0x03][32-byte x coordinate]
303
+ // * [0x04] [32-byte x coordinate][32-byte y coordinate]
304
+ const head = bytes[0];
305
+ const tail = bytes.subarray(1);
306
+ const x = sliceBytesNumBE(tail, 0, L);
307
+ const len = bytes.length;
308
+ // Compressed 33-byte point, 0x02 or 0x03 prefix
309
+ if (len === L + 1 && [0x02, 0x03].includes(head)) {
310
+ // Equation is y² == x³ + ax + b. We calculate y from x.
311
+ // y = √y²; there are two solutions: y, -y. Determine proper solution based on prefix
312
+ let y = lift_x(x);
313
+ const evenY = isEven(y);
314
+ const evenH = isEven(big(head));
315
+ if (evenH !== evenY)
316
+ y = M(-y);
317
+ p = new Point(x, y, 1n);
318
+ }
319
+ // Uncompressed 65-byte point, 0x04 prefix
320
+ if (len === L2 + 1 && head === 0x04)
321
+ p = new Point(x, sliceBytesNumBE(tail, L, L2), 1n);
322
+ // Validate point
323
+ return p ? p.assertValidity() : err('bad point: not on curve');
324
+ }
325
+ /** Equality check: compare points P&Q. */
326
+ equals(other) {
327
+ const { px: X1, py: Y1, pz: Z1 } = this;
328
+ const { px: X2, py: Y2, pz: Z2 } = apoint(other); // checks class equality
329
+ const X1Z2 = M(X1 * Z2);
330
+ const X2Z1 = M(X2 * Z1);
331
+ const Y1Z2 = M(Y1 * Z2);
332
+ const Y2Z1 = M(Y2 * Z1);
333
+ return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
334
+ }
335
+ is0() {
336
+ return this.equals(I);
337
+ }
338
+ /** Flip point over y coordinate. */
339
+ negate() {
340
+ return new Point(this.px, M(-this.py), this.pz);
341
+ }
342
+ /** Point doubling: P+P, complete formula. */
343
+ double() {
344
+ return this.add(this);
345
+ }
346
+ /**
347
+ * Point addition: P+Q, complete, exception-free formula
348
+ * (Renes-Costello-Batina, algo 1 of [2015/1060](https://eprint.iacr.org/2015/1060)).
349
+ * Cost: `12M + 0S + 3*a + 3*b3 + 23add`.
350
+ */
351
+ // prettier-ignore
352
+ add(other) {
353
+ const { px: X1, py: Y1, pz: Z1 } = this;
354
+ const { px: X2, py: Y2, pz: Z2 } = apoint(other);
355
+ const a = 0n;
356
+ const b = _b;
357
+ let X3 = 0n, Y3 = 0n, Z3 = 0n;
358
+ const b3 = M(b * 3n);
359
+ let t0 = M(X1 * X2), t1 = M(Y1 * Y2), t2 = M(Z1 * Z2), t3 = M(X1 + Y1); // step 1
360
+ let t4 = M(X2 + Y2); // step 5
361
+ t3 = M(t3 * t4);
362
+ t4 = M(t0 + t1);
363
+ t3 = M(t3 - t4);
364
+ t4 = M(X1 + Z1);
365
+ let t5 = M(X2 + Z2); // step 10
366
+ t4 = M(t4 * t5);
367
+ t5 = M(t0 + t2);
368
+ t4 = M(t4 - t5);
369
+ t5 = M(Y1 + Z1);
370
+ X3 = M(Y2 + Z2); // step 15
371
+ t5 = M(t5 * X3);
372
+ X3 = M(t1 + t2);
373
+ t5 = M(t5 - X3);
374
+ Z3 = M(a * t4);
375
+ X3 = M(b3 * t2); // step 20
376
+ Z3 = M(X3 + Z3);
377
+ X3 = M(t1 - Z3);
378
+ Z3 = M(t1 + Z3);
379
+ Y3 = M(X3 * Z3);
380
+ t1 = M(t0 + t0); // step 25
381
+ t1 = M(t1 + t0);
382
+ t2 = M(a * t2);
383
+ t4 = M(b3 * t4);
384
+ t1 = M(t1 + t2);
385
+ t2 = M(t0 - t2); // step 30
386
+ t2 = M(a * t2);
387
+ t4 = M(t4 + t2);
388
+ t0 = M(t1 * t4);
389
+ Y3 = M(Y3 + t0);
390
+ t0 = M(t5 * t4); // step 35
391
+ X3 = M(t3 * X3);
392
+ X3 = M(X3 - t0);
393
+ t0 = M(t3 * t1);
394
+ Z3 = M(t5 * Z3);
395
+ Z3 = M(Z3 + t0); // step 40
396
+ return new Point(X3, Y3, Z3);
397
+ }
398
+ /**
399
+ * Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
400
+ * Uses {@link wNAF} for base point.
401
+ * Uses fake point to mitigate side-channel leakage.
402
+ * @param n scalar by which point is multiplied
403
+ * @param safe safe mode guards against timing attacks; unsafe mode is faster
404
+ */
405
+ multiply(n, safe = true) {
406
+ if (!safe && n === 0n)
407
+ return I;
408
+ agroup(n);
409
+ if (n === 1n)
410
+ return this;
411
+ if (this.equals(G))
412
+ return wNAF(n).p;
413
+ // init result point & fake point
414
+ let p = I;
415
+ let f = G;
416
+ for (let d = this; n > 0n; d = d.double(), n >>= 1n) {
417
+ // if bit is present, add to point
418
+ // if not present, add to fake, for timing safety
419
+ if (n & 1n)
420
+ p = p.add(d);
421
+ else if (safe)
422
+ f = f.add(d);
423
+ }
424
+ return p;
425
+ }
426
+ /** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
427
+ toAffine() {
428
+ const { px: x, py: y, pz: z } = this;
429
+ // fast-paths for ZERO point OR Z=1
430
+ if (this.equals(I))
431
+ return { x: 0n, y: 0n };
432
+ if (z === 1n)
433
+ return { x, y };
434
+ const iz = invert(z, P);
435
+ // (Z * Z^-1) must be 1, otherwise bad math
436
+ if (M(z * iz) !== 1n)
437
+ err('inverse invalid');
438
+ // x = X*Z^-1; y = Y*Z^-1
439
+ return { x: M(x * iz), y: M(y * iz) };
440
+ }
441
+ /** Checks if the point is valid and on-curve. */
442
+ assertValidity() {
443
+ const { x, y } = this.toAffine(); // convert to 2d xy affine point.
444
+ afield(x); // must be in range 1 <= x,y < P
445
+ afield(y);
446
+ // y² == x³ + ax + b, equation sides must be equal
447
+ return M(y * y) === koblitz(x) ? this : err('bad point: not on curve');
448
+ }
449
+ /** Converts point to 33/65-byte Uint8Array. */
450
+ toBytes(isCompressed = true) {
451
+ const { x, y } = this.assertValidity().toAffine();
452
+ const x32b = numTo32b(x);
453
+ if (isCompressed)
454
+ return concatBytes(getPrefix(y), x32b);
455
+ return concatBytes(u8of(0x04), x32b, numTo32b(y));
456
+ }
457
+ /** Create 3d xyz point from 2d xy. (0, 0) => (0, 1, 0), not (0, 0, 1) */
458
+ static fromAffine(ap) {
459
+ const { x, y } = ap;
460
+ return x === 0n && y === 0n ? I : new Point(x, y, 1n);
461
+ }
462
+ toHex(isCompressed) {
463
+ return bytesToHex(this.toBytes(isCompressed));
464
+ }
465
+ static fromPrivateKey(k) {
466
+ return G.multiply(toPrivScalar(k));
467
+ }
468
+ static fromHex(hex) {
469
+ return Point.fromBytes(toU8(hex));
470
+ }
471
+ get x() {
472
+ return this.toAffine().x;
473
+ }
474
+ get y() {
475
+ return this.toAffine().y;
476
+ }
477
+ toRawBytes(isCompressed) {
478
+ return this.toBytes(isCompressed);
479
+ }
480
+ }
481
+ /** Generator / base point */
482
+ const G = new Point(Gx, Gy, 1n);
483
+ /** Identity / zero point */
484
+ const I = new Point(0n, 1n, 0n);
485
+ // Static aliases
486
+ Point.BASE = G;
487
+ Point.ZERO = I;
488
+ /** `Q = u1⋅G + u2⋅R`. Verifies Q is not ZERO. Unsafe: non-CT. */
489
+ const doubleScalarMulUns = (R, u1, u2) => {
490
+ return G.multiply(u1, false).add(R.multiply(u2, false)).assertValidity();
491
+ };
492
+ const bytesToNumBE = (b) => big('0x' + (bytesToHex(b) || '0'));
493
+ const sliceBytesNumBE = (b, from, to) => bytesToNumBE(b.subarray(from, to));
494
+ const B256 = 2n ** 256n; // secp256k1 is weierstrass curve. Equation is x³ + ax + b.
495
+ /** Number to 32b. Must be 0 <= num < B256. validate, pad, to bytes. */
496
+ const numTo32b = (num) => hexToBytes(padh(arange(num, 0n, B256), L2));
497
+ /** Normalize private key to scalar (bigint). Verifies scalar is in range 1<s<N */
498
+ const toPrivScalar = (pr) => {
499
+ const num = isBig(pr) ? pr : bytesToNumBE(toU8(pr, L));
500
+ return arange(num, 1n, N, 'private key invalid 3');
501
+ };
502
+ /** For Signature malleability, validates sig.s is bigger than N/2. */
503
+ const highS = (n) => n > N >> 1n;
504
+ /** ECDSA Signature class. Supports only compact 64-byte representation, not DER. */
505
+ class Signature {
506
+ r;
507
+ s;
508
+ recovery;
509
+ constructor(r, s, recovery) {
510
+ this.r = agroup(r); // 1 <= r < N
511
+ this.s = agroup(s); // 1 <= s < N
512
+ if (recovery != null)
513
+ this.recovery = recovery;
514
+ Object.freeze(this);
515
+ }
516
+ /** Create signature from 64b compact (r || s) representation. */
517
+ static fromBytes(b) {
518
+ abytes(b, L2);
519
+ const r = sliceBytesNumBE(b, 0, L);
520
+ const s = sliceBytesNumBE(b, L, L2);
521
+ return new Signature(r, s);
522
+ }
523
+ toBytes() {
524
+ const { r, s } = this;
525
+ return concatBytes(numTo32b(r), numTo32b(s));
526
+ }
527
+ /** Copy signature, with newly added recovery bit. */
528
+ addRecoveryBit(bit) {
529
+ return new Signature(this.r, this.s, bit);
530
+ }
531
+ hasHighS() {
532
+ return highS(this.s);
533
+ }
534
+ toCompactRawBytes() {
535
+ return this.toBytes();
536
+ }
537
+ toCompactHex() {
538
+ return bytesToHex(this.toBytes());
539
+ }
540
+ recoverPublicKey(msg) {
541
+ return recoverPublicKey(this, msg);
542
+ }
543
+ static fromCompact(hex) {
544
+ return Signature.fromBytes(toU8(hex, L2));
545
+ }
546
+ assertValidity() {
547
+ return this;
548
+ }
549
+ normalizeS() {
550
+ const { r, s, recovery } = this;
551
+ return highS(s) ? new Signature(r, modN(-s), recovery) : this;
552
+ }
553
+ }
554
+ /**
555
+ * RFC6979: ensure ECDSA msg is X bytes, convert to BigInt.
556
+ * RFC suggests optional truncating via bits2octets.
557
+ * FIPS 186-4 4.6 suggests the leftmost min(nBitLen, outLen) bits,
558
+ * which matches bits2int. bits2int can produce res>N.
559
+ */
560
+ const bits2int = (bytes) => {
561
+ const delta = bytes.length * 8 - 256;
562
+ if (delta > 1024)
563
+ err('msg invalid'); // our CUSTOM check, "just-in-case": prohibit long inputs
564
+ const num = bytesToNumBE(bytes);
565
+ return delta > 0 ? num >> big(delta) : num;
566
+ };
567
+ /** int2octets can't be used; pads small msgs with 0: BAD for truncation as per RFC vectors */
568
+ const bits2int_modN = (bytes) => modN(bits2int(abytes(bytes)));
569
+ const signOpts = { lowS: true };
570
+ // RFC6979 signature generation, preparation step.
571
+ const prepSig = (msgh, priv, opts = signOpts) => {
572
+ if (['der', 'recovered', 'canonical'].some((k) => k in opts))
573
+ // legacy opts
574
+ err('option not supported');
575
+ let { lowS, extraEntropy } = opts; // generates low-s sigs by default
576
+ if (lowS == null)
577
+ lowS = true; // RFC6979 3.2: we skip step A
578
+ const i2o = numTo32b; // int to octets
579
+ const h1i = bits2int_modN(toU8(msgh)); // msg bigint
580
+ const h1o = i2o(h1i); // msg octets
581
+ const d = toPrivScalar(priv); // validate private key, convert to bigint
582
+ const seed = [i2o(d), h1o]; // Step D of RFC6979 3.2
583
+ /** RFC6979 3.6: additional k' (optional). See {@link ExtraEntropy}. */
584
+ // K = HMAC_K(V || 0x00 || int2octets(x) || bits2octets(h1) || k')
585
+ if (extraEntropy)
586
+ seed.push(extraEntropy === true ? randomBytes(L) : toU8(extraEntropy));
587
+ const m = h1i; // convert msg to bigint
588
+ // Converts signature params into point w r/s, checks result for validity.
589
+ // To transform k => Signature:
590
+ // q = k⋅G
591
+ // r = q.x mod n
592
+ // s = k^-1(m + rd) mod n
593
+ const k2sig = (kBytes) => {
594
+ // RFC 6979 Section 3.2, step 3: k = bits2int(T)
595
+ // Important: all mod() calls here must be done over N
596
+ const k = bits2int(kBytes);
597
+ if (!(1n <= k && k < N))
598
+ return; // Check 0 < k < CURVE.n
599
+ const q = G.multiply(k).toAffine(); // q = k⋅G
600
+ const r = modN(q.x); // r = q.x mod n
601
+ if (r === 0n)
602
+ return;
603
+ const ik = invert(k, N); // k^-1 mod n, NOT mod P
604
+ const s = modN(ik * modN(m + modN(d * r))); // s = k^-1(m + rd) mod n
605
+ if (s === 0n)
606
+ return;
607
+ let normS = s; // normalized S
608
+ let recovery = (q.x === r ? 0 : 2) | Number(q.y & 1n); // recovery bit (2 or 3, when q.x > n)
609
+ if (lowS && highS(s)) {
610
+ // if lowS was passed, ensure s is always
611
+ normS = modN(-s); // in the bottom half of CURVE.n
612
+ recovery ^= 1;
613
+ }
614
+ return new Signature(r, normS, recovery); // use normS, not s
615
+ };
616
+ return { seed: concatBytes(...seed), k2sig };
617
+ };
618
+ // HMAC-DRBG from NIST 800-90. Minimal, non-full-spec - used for RFC6979 signatures.
619
+ const hmacDrbg = (asynchronous) => {
620
+ let v = u8n(L); // Steps B, C of RFC6979 3.2: set hashLen
621
+ let k = u8n(L); // In our case, it's always equal to L
622
+ let i = 0; // Iterations counter, will throw when over max
623
+ const NULL = u8n(0);
624
+ const reset = () => {
625
+ v.fill(1);
626
+ k.fill(0);
627
+ i = 0;
628
+ };
629
+ const max = 1000;
630
+ const _e = 'drbg: tried 1000 values';
631
+ {
632
+ // asynchronous=true
633
+ // h = hmac(K || V || ...)
634
+ const h = (...b) => etc.hmacSha256Async(k, v, ...b);
635
+ const reseed = async (seed = NULL) => {
636
+ // HMAC-DRBG reseed() function. Steps D-G
637
+ k = await h(u8of(0x00), seed); // k = hmac(K || V || 0x00 || seed)
638
+ v = await h(); // v = hmac(K || V)
639
+ if (seed.length === 0)
640
+ return;
641
+ k = await h(u8of(0x01), seed); // k = hmac(K || V || 0x01 || seed)
642
+ v = await h(); // v = hmac(K || V)
643
+ };
644
+ // HMAC-DRBG generate() function
645
+ const gen = async () => {
646
+ if (i++ >= max)
647
+ err(_e);
648
+ v = await h(); // v = hmac(K || V)
649
+ return v; // this diverges from noble-curves: we don't allow arbitrary output len!
650
+ };
651
+ // Do not reuse returned fn for more than 1 sig:
652
+ // 1) it's slower (JIT screws up). 2. unsafe (async race conditions)
653
+ return async (seed, pred) => {
654
+ reset();
655
+ await reseed(seed); // Steps D-G
656
+ let res = undefined; // Step H: grind until k is in [1..n-1]
657
+ while (!(res = pred(await gen())))
658
+ await reseed(); // test predicate until it returns ok
659
+ reset();
660
+ return res;
661
+ };
662
+ }
663
+ };
664
+ /**
665
+ * Sign a msg hash using secp256k1. Async.
666
+ * Follows [SEC1](https://secg.org/sec1-v2.pdf) 4.1.2 & RFC6979.
667
+ * It's suggested to enable hedging ({@link ExtraEntropy}) to prevent fault attacks.
668
+ * @param msgh - message HASH, not message itself e.g. sha256(message)
669
+ * @param priv - private key
670
+ * @param opts - `lowS: true` prevents malleability, `extraEntropy: true` enables hedging
671
+ */
672
+ const signAsync = async (msgh, priv, opts = signOpts) => {
673
+ // Re-run drbg until k2sig returns ok
674
+ const { seed, k2sig } = prepSig(msgh, priv, opts);
675
+ const sig = await hmacDrbg()(seed, k2sig);
676
+ return sig;
677
+ };
678
+ /**
679
+ * ECDSA public key recovery. Requires msg hash and recovery id.
680
+ * Follows [SEC1](https://secg.org/sec1-v2.pdf) 4.1.6.
681
+ */
682
+ const recoverPublicKey = (sig, msgh) => {
683
+ const { r, s, recovery } = sig;
684
+ // 0 or 1 recovery id determines sign of "y" coordinate.
685
+ // 2 or 3 means q.x was >N.
686
+ if (![0, 1, 2, 3].includes(recovery))
687
+ err('recovery id invalid');
688
+ const h = bits2int_modN(toU8(msgh, L)); // Truncate hash
689
+ const radj = recovery === 2 || recovery === 3 ? r + N : r;
690
+ afield(radj); // ensure q.x is still a field element
691
+ const head = getPrefix(big(recovery)); // head is 0x02 or 0x03
692
+ const Rb = concatBytes(head, numTo32b(radj)); // concat head + r
693
+ const R = Point.fromBytes(Rb);
694
+ const ir = invert(radj, N); // r^-1
695
+ const u1 = modN(-h * ir); // -hr^-1
696
+ const u2 = modN(s * ir); // sr^-1
697
+ return doubleScalarMulUns(R, u1, u2); // (sr^-1)R-(hr^-1)G = -(hr^-1)G + (sr^-1)
698
+ };
699
+ // FIPS 186 B.4.1 compliant key generation produces private keys with modulo bias being neglible.
700
+ // takes >N+8 bytes, returns (hash mod n-1)+1
701
+ const hashToPrivateKey = (hash) => {
702
+ hash = toU8(hash);
703
+ if (hash.length < L + 8 || hash.length > 1024)
704
+ err('expected 40-1024b');
705
+ const num = M(bytesToNumBE(hash), N - 1n);
706
+ return numTo32b(num + 1n);
707
+ };
708
+ const _sha = 'SHA-256';
709
+ /** Math, hex, byte helpers. Not in `utils` because utils share API with noble-curves. */
710
+ const etc = {
711
+ hexToBytes: hexToBytes,
712
+ bytesToHex: bytesToHex,
713
+ concatBytes: concatBytes,
714
+ bytesToNumberBE: bytesToNumBE,
715
+ numberToBytesBE: numTo32b,
716
+ mod: M,
717
+ invert: invert, // math utilities
718
+ hmacSha256Async: async (key, ...msgs) => {
719
+ const s = subtle();
720
+ const name = 'HMAC';
721
+ const k = await s.importKey('raw', key, { name, hash: { name: _sha } }, false, ['sign']);
722
+ return u8n(await s.sign(name, k, concatBytes(...msgs)));
723
+ },
724
+ hmacSha256Sync: undefined, // For TypeScript. Actual logic is below
725
+ hashToPrivateKey: hashToPrivateKey,
726
+ randomBytes: randomBytes,
727
+ };
728
+ // ## Precomputes
729
+ // --------------
730
+ const W = 8; // W is window size
731
+ const scalarBits = 256;
732
+ const pwindows = Math.ceil(scalarBits / W) + 1; // 33 for W=8
733
+ const pwindowSize = 2 ** (W - 1); // 128 for W=8
734
+ const precompute = () => {
735
+ const points = [];
736
+ let p = G;
737
+ let b = p;
738
+ for (let w = 0; w < pwindows; w++) {
739
+ b = p;
740
+ points.push(b);
741
+ for (let i = 1; i < pwindowSize; i++) {
742
+ b = b.add(p);
743
+ points.push(b);
744
+ } // i=1, bc we skip 0
745
+ p = b.double();
746
+ }
747
+ return points;
748
+ };
749
+ let Gpows = undefined; // precomputes for base point G
750
+ // const-time negate
751
+ const ctneg = (cnd, p) => {
752
+ const n = p.negate();
753
+ return cnd ? n : p;
754
+ };
755
+ /**
756
+ * Precomputes give 12x faster getPublicKey(), 10x sign(), 2x verify() by
757
+ * caching multiples of G (base point). Cache is stored in 32MB of RAM.
758
+ * Any time `G.multiply` is done, precomputes are used.
759
+ * Not used for getSharedSecret, which instead multiplies random pubkey `P.multiply`.
760
+ *
761
+ * w-ary non-adjacent form (wNAF) precomputation method is 10% slower than windowed method,
762
+ * but takes 2x less RAM. RAM reduction is possible by utilizing `.subtract`.
763
+ *
764
+ * !! Precomputes can be disabled by commenting-out call of the wNAF() inside Point#multiply().
765
+ */
766
+ const wNAF = (n) => {
767
+ const comp = Gpows || (Gpows = precompute());
768
+ let p = I;
769
+ let f = G; // f must be G, or could become I in the end
770
+ const pow_2_w = 2 ** W; // 256 for W=8
771
+ const maxNum = pow_2_w; // 256 for W=8
772
+ const mask = big(pow_2_w - 1); // 255 for W=8 == mask 0b11111111
773
+ const shiftBy = big(W); // 8 for W=8
774
+ for (let w = 0; w < pwindows; w++) {
775
+ let wbits = Number(n & mask); // extract W bits.
776
+ n >>= shiftBy; // shift number by W bits.
777
+ if (wbits > pwindowSize) {
778
+ wbits -= maxNum;
779
+ n += 1n;
780
+ } // split if bits > max: +224 => 256-32
781
+ const off = w * pwindowSize;
782
+ const offF = off; // offsets, evaluate both
783
+ const offP = off + Math.abs(wbits) - 1;
784
+ const isEven = w % 2 !== 0; // conditions, evaluate both
785
+ const isNeg = wbits < 0;
786
+ if (wbits === 0) {
787
+ // off == I: can't add it. Adding random offF instead.
788
+ f = f.add(ctneg(isEven, comp[offF])); // bits are 0: add garbage to fake point
789
+ }
790
+ else {
791
+ p = p.add(ctneg(isNeg, comp[offP])); // bits are 1: add to result point
792
+ }
793
+ }
794
+ return { p, f }; // return both real and fake points for JIT
795
+ };/**
796
+ * RLP encode a payload into a digest
797
+ * @param payload Payload to encode
798
+ * @returns RLP encoded payload
799
+ */
800
+ function encodePayload(payload) {
801
+ if (_typeof(payload) === 'array') {
802
+ var formatted = payload.map(function (v) {
803
+ if (_typeof(v) === 'string') {
804
+ if (/^0x[0-9a-fA-F]+$/.test(v)) {
805
+ // hex-encoded data → raw bytes
806
+ return viem.hexToBytes(v);
807
+ }
808
+ else if (!isNaN(+v)) {
809
+ // number-like string → hex → bytes
810
+ return v === '0' ? new Uint8Array([]) : viem.hexToBytes(viem.numberToHex(+v));
811
+ }
812
+ else {
813
+ // plain string → UTF-8 bytes
814
+ return new TextEncoder().encode(v);
815
+ }
816
+ }
817
+ else if (_typeof(v) === 'number' || _typeof(v) === 'bigint') {
818
+ // produce minimal hex, then arrayify
819
+ return v === 0 || v === BigInt(0) ? new Uint8Array([]) : viem.hexToBytes(viem.numberToHex(v));
820
+ }
821
+ else if (_typeof(v) === 'boolean') {
822
+ return v ? Uint8Array.from([1]) : new Uint8Array([]);
823
+ }
824
+ else {
825
+ return v;
826
+ }
827
+ });
828
+ return rlp.encode(formatted);
829
+ }
830
+ if (_typeof(payload) === 'boolean') {
831
+ return rlp.encode(payload ? Uint8Array.from([1]) : new Uint8Array([]));
832
+ }
833
+ return rlp.encode(payload);
834
+ }
835
+ /**
836
+ * Sign a message using the provided private key
837
+ * @param payload Payload to sign
838
+ * @param privateKey Private key to sign with
839
+ * @returns Signature object with r, s, v components
840
+ */
841
+ function signMessage(payload, privateKey) {
842
+ return __awaiter(this, void 0, void 0, function () {
843
+ var encoded, digestHex, digest, privateKeyBytes, signature, compact, rBytes, sBytes;
844
+ return __generator(this, function (_a) {
845
+ switch (_a.label) {
846
+ case 0:
847
+ encoded = encodePayload(payload);
848
+ digestHex = viem.keccak256(encoded);
849
+ digest = viem.hexToBytes(digestHex);
850
+ privateKeyBytes = viem.hexToBytes(privateKey);
851
+ return [4 /*yield*/, signAsync(digest, privateKeyBytes, { lowS: true })];
852
+ case 1:
853
+ signature = _a.sent();
854
+ compact = signature.toCompactRawBytes();
855
+ rBytes = compact.subarray(0, 32);
856
+ sBytes = compact.subarray(32, 64);
857
+ return [2 /*return*/, {
858
+ r: viem.bytesToHex(rBytes),
859
+ s: viem.bytesToHex(sBytes),
860
+ v: signature.recovery,
861
+ }];
862
+ }
863
+ });
864
+ });
865
+ }
866
+ function toHex(value) {
867
+ var type = _typeof(value);
868
+ try {
869
+ switch (type) {
870
+ case 'boolean':
871
+ return viem.boolToHex(value);
872
+ case 'number':
873
+ case 'bigint':
874
+ return viem.numberToHex(value);
875
+ case 'string':
876
+ if (!isNaN(+value))
877
+ return viem.numberToHex(+value);
878
+ return viem.stringToHex(value);
879
+ case 'uint8array':
880
+ case 'uint16array':
881
+ case 'uint32array':
882
+ case 'int8array':
883
+ case 'int16array':
884
+ case 'int32array':
885
+ case 'arraybuffer':
886
+ return viem.bytesToHex(value);
887
+ case 'array':
888
+ if (value.length === 0)
889
+ return '0x';
890
+ else if (value.every(function (item) { return typeof item === 'number'; }))
891
+ return viem.bytesToHex(Uint8Array.from(value));
892
+ else
893
+ return viem.bytesToHex(viem.stringToBytes(JSON.stringify(value)));
894
+ default:
895
+ return viem.bytesToHex(viem.stringToBytes(JSON.stringify(value)));
896
+ }
897
+ }
898
+ catch (e) {
899
+ console.error('[1Money toHex]: ', e);
900
+ return '0x';
901
+ }
902
+ }function encodeRlpListHeader(length) {
903
+ if (length < 56) {
904
+ // Short list: single byte prefix
905
+ return Uint8Array.from([0xc0 + length]);
906
+ }
907
+ else {
908
+ // Long list: prefix 0xf7 + length of length + actual length bytes
909
+ var lenBytes = [];
910
+ var temp = length;
911
+ while (temp > 0) {
912
+ lenBytes.unshift(temp & 0xff);
913
+ temp >>= 8;
914
+ }
915
+ return Uint8Array.from(__spreadArray([0xf7 + lenBytes.length], lenBytes, true));
916
+ }
917
+ }
918
+ function calcTxHash(payload, signature) {
919
+ var pEncode = encodePayload(payload);
920
+ var vEncode = rlp.encode(typeof signature.v === 'boolean'
921
+ ? signature.v
922
+ ? Uint8Array.from([1])
923
+ : new Uint8Array([])
924
+ : BigInt(signature.v));
925
+ var rEncode = rlp.encode(viem.hexToBytes(signature.r));
926
+ var sEncode = rlp.encode(viem.hexToBytes(signature.s));
927
+ var vrsBytes = new Uint8Array(vEncode.length + rEncode.length + sEncode.length);
928
+ vrsBytes.set(vEncode, 0);
929
+ vrsBytes.set(rEncode, vEncode.length);
930
+ vrsBytes.set(sEncode, vEncode.length + rEncode.length);
931
+ var header = encodeRlpListHeader(pEncode.length + vrsBytes.length);
932
+ var encoded = new Uint8Array(header.length + pEncode.length + vrsBytes.length);
933
+ encoded.set(header, 0);
934
+ encoded.set(pEncode, header.length);
935
+ encoded.set(vrsBytes, header.length + pEncode.length);
936
+ return viem.keccak256(encoded);
937
+ }exports._typeof=_typeof;exports.calcTxHash=calcTxHash;exports.deriveTokenAddress=deriveTokenAddress;exports.encodePayload=encodePayload;exports.safePromiseAll=safePromiseAll;exports.safePromiseLine=safePromiseLine;exports.signMessage=signMessage;exports.toHex=toHex;