@gardenfi/utils 2.1.2-beta.4 → 2.1.2-beta.5
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/index103.cjs +1 -1
- package/dist/index103.js +3 -3
- package/dist/index104.cjs +1 -1
- package/dist/index104.js +2 -2
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +2 -2
- package/dist/index20.cjs +1 -1
- package/dist/index20.js +17 -18
- package/dist/index21.cjs +1 -16
- package/dist/index21.js +30 -112
- package/dist/index22.cjs +16 -1
- package/dist/index22.js +113 -30
- package/dist/index25.cjs +1 -1
- package/dist/index25.js +3 -3
- package/dist/index39.cjs +1 -1
- package/dist/index39.js +1 -1
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +22 -19
- package/dist/index41.cjs +1 -1
- package/dist/index41.js +1 -1
- package/dist/index42.cjs +1 -1
- package/dist/index42.js +4 -4
- package/dist/index46.cjs +1 -1
- package/dist/index46.js +1 -1
- package/dist/index56.cjs +1 -1
- package/dist/index56.js +2 -2
- package/dist/index71.cjs +1 -1
- package/dist/index71.js +1 -1
- package/dist/index73.cjs +1 -1
- package/dist/index73.js +8 -11
- package/dist/index74.cjs +1 -1
- package/dist/index74.js +40 -19
- package/dist/index75.cjs +1 -1
- package/dist/index75.js +34 -40
- package/dist/index76.cjs +1 -1
- package/dist/index76.js +69 -34
- package/dist/index77.cjs +1 -1
- package/dist/index77.js +109 -66
- package/dist/index78.cjs +1 -1
- package/dist/index78.js +62 -107
- package/dist/index79.cjs +1 -1
- package/dist/index79.js +2 -68
- package/dist/index80.cjs +1 -1
- package/dist/index80.js +17 -2
- package/dist/index81.cjs +1 -1
- package/dist/index81.js +220 -13
- package/dist/index82.cjs +1 -1
- package/dist/index82.js +220 -212
- package/dist/index83.cjs +1 -1
- package/dist/index83.js +37 -226
- package/dist/index84.cjs +1 -1
- package/dist/index84.js +104 -8
- package/dist/index85.cjs +1 -1
- package/dist/index85.js +17 -42
- package/dist/index86.cjs +1 -1
- package/dist/index86.js +74 -100
- package/dist/index87.cjs +1 -1
- package/dist/index87.js +15 -14
- package/dist/index88.cjs +1 -1
- package/dist/index88.js +10 -76
- package/dist/index89.cjs +1 -1
- package/dist/index89.js +38 -18
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +2 -2
- package/dist/index90.cjs +1 -1
- package/dist/index90.js +2 -13
- package/dist/index91.cjs +1 -1
- package/dist/index91.js +5 -39
- package/dist/index92.cjs +1 -1
- package/dist/index92.js +11 -5
- package/dist/index93.cjs +1 -1
- package/dist/index93.js +11 -10
- package/dist/index94.cjs +1 -1
- package/dist/index94.js +20 -2
- package/dist/index96.cjs +1 -1
- package/dist/index96.js +1 -1
- package/package.json +1 -1
package/dist/index82.js
CHANGED
|
@@ -1,226 +1,234 @@
|
|
|
1
|
-
import { numberToBytesLE as S, numberToBytesBE as x, bitMask as _, bytesToNumberLE as y, bytesToNumberBE as L, validateObject as M } from "./index83.js";
|
|
2
1
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
-
const d =
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
const d = /* @__PURE__ */ BigInt(0), y = /* @__PURE__ */ BigInt(1), I = /* @__PURE__ */ BigInt(2);
|
|
3
|
+
function h(t) {
|
|
4
|
+
return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
|
|
5
|
+
}
|
|
6
|
+
function b(t) {
|
|
7
|
+
if (!h(t))
|
|
8
|
+
throw new Error("Uint8Array expected");
|
|
9
|
+
}
|
|
10
|
+
function O(t, n) {
|
|
11
|
+
if (typeof n != "boolean")
|
|
12
|
+
throw new Error(t + " boolean expected, got " + n);
|
|
13
|
+
}
|
|
14
|
+
const T = /* @__PURE__ */ Array.from({ length: 256 }, (t, n) => n.toString(16).padStart(2, "0"));
|
|
15
|
+
function B(t) {
|
|
16
|
+
b(t);
|
|
17
|
+
let n = "";
|
|
18
|
+
for (let r = 0; r < t.length; r++)
|
|
19
|
+
n += T[t[r]];
|
|
20
|
+
return n;
|
|
21
|
+
}
|
|
22
|
+
function S(t) {
|
|
23
|
+
const n = t.toString(16);
|
|
24
|
+
return n.length & 1 ? "0" + n : n;
|
|
25
|
+
}
|
|
26
|
+
function U(t) {
|
|
27
|
+
if (typeof t != "string")
|
|
28
|
+
throw new Error("hex string expected, got " + typeof t);
|
|
29
|
+
return t === "" ? d : BigInt("0x" + t);
|
|
30
|
+
}
|
|
31
|
+
const s = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
32
|
+
function E(t) {
|
|
33
|
+
if (t >= s._0 && t <= s._9)
|
|
34
|
+
return t - s._0;
|
|
35
|
+
if (t >= s.A && t <= s.F)
|
|
36
|
+
return t - (s.A - 10);
|
|
37
|
+
if (t >= s.a && t <= s.f)
|
|
38
|
+
return t - (s.a - 10);
|
|
39
|
+
}
|
|
40
|
+
function m(t) {
|
|
41
|
+
if (typeof t != "string")
|
|
42
|
+
throw new Error("hex string expected, got " + typeof t);
|
|
43
|
+
const n = t.length, r = n / 2;
|
|
44
|
+
if (n % 2)
|
|
45
|
+
throw new Error("hex string expected, got unpadded hex of length " + n);
|
|
46
|
+
const e = new Uint8Array(r);
|
|
47
|
+
for (let o = 0, i = 0; o < r; o++, i += 2) {
|
|
48
|
+
const a = E(t.charCodeAt(i)), f = E(t.charCodeAt(i + 1));
|
|
49
|
+
if (a === void 0 || f === void 0) {
|
|
50
|
+
const c = t[i] + t[i + 1];
|
|
51
|
+
throw new Error('hex string expected, got non-hex character "' + c + '" at index ' + i);
|
|
52
|
+
}
|
|
53
|
+
e[o] = a * 16 + f;
|
|
54
|
+
}
|
|
18
55
|
return e;
|
|
19
56
|
}
|
|
20
|
-
function V(t
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
57
|
+
function V(t) {
|
|
58
|
+
return U(B(t));
|
|
59
|
+
}
|
|
60
|
+
function H(t) {
|
|
61
|
+
return b(t), U(B(Uint8Array.from(t).reverse()));
|
|
62
|
+
}
|
|
63
|
+
function v(t, n) {
|
|
64
|
+
return m(t.toString(16).padStart(n * 2, "0"));
|
|
65
|
+
}
|
|
66
|
+
function C(t, n) {
|
|
67
|
+
return v(t, n).reverse();
|
|
68
|
+
}
|
|
69
|
+
function M(t) {
|
|
70
|
+
return m(S(t));
|
|
71
|
+
}
|
|
72
|
+
function R(t, n, r) {
|
|
73
|
+
let e;
|
|
74
|
+
if (typeof n == "string")
|
|
75
|
+
try {
|
|
76
|
+
e = m(n);
|
|
77
|
+
} catch (i) {
|
|
78
|
+
throw new Error(t + " must be hex string or Uint8Array, cause: " + i);
|
|
79
|
+
}
|
|
80
|
+
else if (h(n))
|
|
81
|
+
e = Uint8Array.from(n);
|
|
82
|
+
else
|
|
83
|
+
throw new Error(t + " must be hex string or Uint8Array");
|
|
84
|
+
const o = e.length;
|
|
85
|
+
if (typeof r == "number" && o !== r)
|
|
86
|
+
throw new Error(t + " of length " + r + " expected, got " + o);
|
|
24
87
|
return e;
|
|
25
88
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
let r = g(t, i), e = i, s = d, u = c;
|
|
32
|
-
for (; r !== d; ) {
|
|
33
|
-
const o = e / r, n = e % r, l = s - u * o;
|
|
34
|
-
e = r, r = n, s = u, u = l;
|
|
89
|
+
function _(...t) {
|
|
90
|
+
let n = 0;
|
|
91
|
+
for (let e = 0; e < t.length; e++) {
|
|
92
|
+
const o = t[e];
|
|
93
|
+
b(o), n += o.length;
|
|
35
94
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
function j(t) {
|
|
41
|
-
const i = (t - c) / w;
|
|
42
|
-
let r, e, s;
|
|
43
|
-
for (r = t - c, e = 0; r % w === d; r /= w, e++)
|
|
44
|
-
;
|
|
45
|
-
for (s = w; s < t && Z(s, i, t) !== t - c; s++)
|
|
46
|
-
if (s > 1e3)
|
|
47
|
-
throw new Error("Cannot find square root: likely non-prime P");
|
|
48
|
-
if (e === 1) {
|
|
49
|
-
const f = (t + c) / b;
|
|
50
|
-
return function(n, l) {
|
|
51
|
-
const h = n.pow(l, f);
|
|
52
|
-
if (!n.eql(n.sqr(h), l))
|
|
53
|
-
throw new Error("Cannot find square root");
|
|
54
|
-
return h;
|
|
55
|
-
};
|
|
95
|
+
const r = new Uint8Array(n);
|
|
96
|
+
for (let e = 0, o = 0; e < t.length; e++) {
|
|
97
|
+
const i = t[e];
|
|
98
|
+
r.set(i, o), o += i.length;
|
|
56
99
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
for (let B = o.sqr(a); q < l && !o.eql(B, o.ONE); q++)
|
|
67
|
-
B = o.sqr(B);
|
|
68
|
-
const E = o.pow(h, c << BigInt(l - q - 1));
|
|
69
|
-
h = o.sqr(E), v = o.mul(v, E), a = o.mul(a, h), l = q;
|
|
70
|
-
}
|
|
71
|
-
return v;
|
|
72
|
-
};
|
|
100
|
+
return r;
|
|
101
|
+
}
|
|
102
|
+
function j(t, n) {
|
|
103
|
+
if (t.length !== n.length)
|
|
104
|
+
return !1;
|
|
105
|
+
let r = 0;
|
|
106
|
+
for (let e = 0; e < t.length; e++)
|
|
107
|
+
r |= t[e] ^ n[e];
|
|
108
|
+
return r === 0;
|
|
73
109
|
}
|
|
74
110
|
function z(t) {
|
|
75
|
-
if (t
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const A = [
|
|
96
|
-
"create",
|
|
97
|
-
"isValid",
|
|
98
|
-
"is0",
|
|
99
|
-
"neg",
|
|
100
|
-
"inv",
|
|
101
|
-
"sqrt",
|
|
102
|
-
"sqr",
|
|
103
|
-
"eql",
|
|
104
|
-
"add",
|
|
105
|
-
"sub",
|
|
106
|
-
"mul",
|
|
107
|
-
"pow",
|
|
108
|
-
"div",
|
|
109
|
-
"addN",
|
|
110
|
-
"subN",
|
|
111
|
-
"mulN",
|
|
112
|
-
"sqrN"
|
|
113
|
-
];
|
|
114
|
-
function Y(t) {
|
|
115
|
-
const i = {
|
|
116
|
-
ORDER: "bigint",
|
|
117
|
-
MASK: "bigint",
|
|
118
|
-
BYTES: "isSafeInteger",
|
|
119
|
-
BITS: "isSafeInteger"
|
|
120
|
-
}, r = A.reduce((e, s) => (e[s] = "function", e), i);
|
|
121
|
-
return M(t, r);
|
|
122
|
-
}
|
|
123
|
-
function k(t, i, r) {
|
|
124
|
-
if (r < d)
|
|
125
|
-
throw new Error("invalid exponent, negatives unsupported");
|
|
126
|
-
if (r === d)
|
|
127
|
-
return t.ONE;
|
|
128
|
-
if (r === c)
|
|
129
|
-
return i;
|
|
130
|
-
let e = t.ONE, s = i;
|
|
131
|
-
for (; r > d; )
|
|
132
|
-
r & c && (e = t.mul(e, s)), s = t.sqr(s), r >>= c;
|
|
133
|
-
return e;
|
|
111
|
+
if (typeof t != "string")
|
|
112
|
+
throw new Error("string expected");
|
|
113
|
+
return new Uint8Array(new TextEncoder().encode(t));
|
|
114
|
+
}
|
|
115
|
+
const w = (t) => typeof t == "bigint" && d <= t;
|
|
116
|
+
function N(t, n, r) {
|
|
117
|
+
return w(t) && w(n) && w(r) && n <= t && t < r;
|
|
118
|
+
}
|
|
119
|
+
function D(t, n, r, e) {
|
|
120
|
+
if (!N(n, r, e))
|
|
121
|
+
throw new Error("expected valid " + t + ": " + r + " <= n < " + e + ", got " + n);
|
|
122
|
+
}
|
|
123
|
+
function G(t) {
|
|
124
|
+
let n;
|
|
125
|
+
for (n = 0; t > d; t >>= y, n += 1)
|
|
126
|
+
;
|
|
127
|
+
return n;
|
|
128
|
+
}
|
|
129
|
+
function P(t, n) {
|
|
130
|
+
return t >> BigInt(n) & y;
|
|
134
131
|
}
|
|
135
|
-
function
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
function
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
throw new Error("
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (typeof n != "bigint")
|
|
161
|
-
throw new Error("invalid field element: expected bigint, got " + typeof n);
|
|
162
|
-
return d <= n && n < t;
|
|
163
|
-
},
|
|
164
|
-
is0: (n) => n === d,
|
|
165
|
-
isOdd: (n) => (n & c) === c,
|
|
166
|
-
neg: (n) => g(-n, t),
|
|
167
|
-
eql: (n, l) => n === l,
|
|
168
|
-
sqr: (n) => g(n * n, t),
|
|
169
|
-
add: (n, l) => g(n + l, t),
|
|
170
|
-
sub: (n, l) => g(n - l, t),
|
|
171
|
-
mul: (n, l) => g(n * l, t),
|
|
172
|
-
pow: (n, l) => k(o, n, l),
|
|
173
|
-
div: (n, l) => g(n * I(l, t), t),
|
|
174
|
-
// Same as above, but doesn't normalize
|
|
175
|
-
sqrN: (n) => n * n,
|
|
176
|
-
addN: (n, l) => n + l,
|
|
177
|
-
subN: (n, l) => n - l,
|
|
178
|
-
mulN: (n, l) => n * l,
|
|
179
|
-
inv: (n) => I(n, t),
|
|
180
|
-
sqrt: e.sqrt || ((n) => (f || (f = z(t)), f(o, n))),
|
|
181
|
-
invertBatch: (n) => H(o, n),
|
|
182
|
-
// TODO: do we really need constant cmov?
|
|
183
|
-
// We don't have const-time bigints anyway, so probably will be not very useful
|
|
184
|
-
cmov: (n, l, h) => h ? l : n,
|
|
185
|
-
toBytes: (n) => r ? S(n, u) : x(n, u),
|
|
186
|
-
fromBytes: (n) => {
|
|
187
|
-
if (n.length !== u)
|
|
188
|
-
throw new Error("Field.fromBytes: expected " + u + " bytes, got " + n.length);
|
|
189
|
-
return r ? y(n) : L(n);
|
|
132
|
+
function W(t, n, r) {
|
|
133
|
+
return t | (r ? y : d) << BigInt(n);
|
|
134
|
+
}
|
|
135
|
+
const q = (t) => (I << BigInt(t - 1)) - y, p = (t) => new Uint8Array(t), A = (t) => Uint8Array.from(t);
|
|
136
|
+
function J(t, n, r) {
|
|
137
|
+
if (typeof t != "number" || t < 2)
|
|
138
|
+
throw new Error("hashLen must be a number");
|
|
139
|
+
if (typeof n != "number" || n < 2)
|
|
140
|
+
throw new Error("qByteLen must be a number");
|
|
141
|
+
if (typeof r != "function")
|
|
142
|
+
throw new Error("hmacFn must be a function");
|
|
143
|
+
let e = p(t), o = p(t), i = 0;
|
|
144
|
+
const a = () => {
|
|
145
|
+
e.fill(1), o.fill(0), i = 0;
|
|
146
|
+
}, f = (...u) => r(o, e, ...u), c = (u = p()) => {
|
|
147
|
+
o = f(A([0]), u), e = f(), u.length !== 0 && (o = f(A([1]), u), e = f());
|
|
148
|
+
}, x = () => {
|
|
149
|
+
if (i++ >= 1e3)
|
|
150
|
+
throw new Error("drbg: tried 1000 values");
|
|
151
|
+
let u = 0;
|
|
152
|
+
const l = [];
|
|
153
|
+
for (; u < n; ) {
|
|
154
|
+
e = f();
|
|
155
|
+
const g = e.slice();
|
|
156
|
+
l.push(g), u += e.length;
|
|
190
157
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
158
|
+
return _(...l);
|
|
159
|
+
};
|
|
160
|
+
return (u, l) => {
|
|
161
|
+
a(), c(u);
|
|
162
|
+
let g;
|
|
163
|
+
for (; !(g = l(x())); )
|
|
164
|
+
c();
|
|
165
|
+
return a(), g;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const k = {
|
|
169
|
+
bigint: (t) => typeof t == "bigint",
|
|
170
|
+
function: (t) => typeof t == "function",
|
|
171
|
+
boolean: (t) => typeof t == "boolean",
|
|
172
|
+
string: (t) => typeof t == "string",
|
|
173
|
+
stringOrUint8Array: (t) => typeof t == "string" || h(t),
|
|
174
|
+
isSafeInteger: (t) => Number.isSafeInteger(t),
|
|
175
|
+
array: (t) => Array.isArray(t),
|
|
176
|
+
field: (t, n) => n.Fp.isValid(t),
|
|
177
|
+
hash: (t) => typeof t == "function" && Number.isSafeInteger(t.outputLen)
|
|
178
|
+
};
|
|
179
|
+
function K(t, n, r = {}) {
|
|
180
|
+
const e = (o, i, a) => {
|
|
181
|
+
const f = k[i];
|
|
182
|
+
if (typeof f != "function")
|
|
183
|
+
throw new Error("invalid validator function");
|
|
184
|
+
const c = t[o];
|
|
185
|
+
if (!(a && c === void 0) && !f(c, t))
|
|
186
|
+
throw new Error("param " + String(o) + " is invalid. Expected " + i + ", got " + c);
|
|
187
|
+
};
|
|
188
|
+
for (const [o, i] of Object.entries(n))
|
|
189
|
+
e(o, i, !1);
|
|
190
|
+
for (const [o, i] of Object.entries(r))
|
|
191
|
+
e(o, i, !0);
|
|
192
|
+
return t;
|
|
193
|
+
}
|
|
194
|
+
const Q = () => {
|
|
195
|
+
throw new Error("not implemented");
|
|
196
|
+
};
|
|
197
|
+
function X(t) {
|
|
198
|
+
const n = /* @__PURE__ */ new WeakMap();
|
|
199
|
+
return (r, ...e) => {
|
|
200
|
+
const o = n.get(r);
|
|
201
|
+
if (o !== void 0)
|
|
202
|
+
return o;
|
|
203
|
+
const i = t(r, ...e);
|
|
204
|
+
return n.set(r, i), i;
|
|
205
|
+
};
|
|
210
206
|
}
|
|
211
207
|
export {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
208
|
+
D as aInRange,
|
|
209
|
+
O as abool,
|
|
210
|
+
b as abytes,
|
|
211
|
+
P as bitGet,
|
|
212
|
+
G as bitLen,
|
|
213
|
+
q as bitMask,
|
|
214
|
+
W as bitSet,
|
|
215
|
+
B as bytesToHex,
|
|
216
|
+
V as bytesToNumberBE,
|
|
217
|
+
H as bytesToNumberLE,
|
|
218
|
+
_ as concatBytes,
|
|
219
|
+
J as createHmacDrbg,
|
|
220
|
+
R as ensureBytes,
|
|
221
|
+
j as equalBytes,
|
|
222
|
+
m as hexToBytes,
|
|
223
|
+
U as hexToNumber,
|
|
224
|
+
N as inRange,
|
|
225
|
+
h as isBytes,
|
|
226
|
+
X as memoized,
|
|
227
|
+
Q as notImplemented,
|
|
228
|
+
v as numberToBytesBE,
|
|
229
|
+
C as numberToBytesLE,
|
|
230
|
+
S as numberToHexUnpadded,
|
|
231
|
+
M as numberToVarBytesBE,
|
|
232
|
+
z as utf8ToBytes,
|
|
233
|
+
K as validateObject
|
|
226
234
|
};
|
package/dist/index83.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index48.cjs"),u=require("./index95.cjs"),f=require("./index38.cjs"),g=require("./index26.cjs");function c(n,e="hex"){const i=o(n),s=u.createCursor(new Uint8Array(i.length));return i.encode(s),e==="hex"?g.bytesToHex(s.bytes):s.bytes}function o(n){return Array.isArray(n)?p(n.map(e=>o(e))):y(n)}function p(n){const e=n.reduce((t,h)=>t+h.length,0),i=l(e);return{length:e<=55?1+e:1+i+e,encode(t){e<=55?t.pushByte(192+e):(t.pushByte(247+i),i===1?t.pushUint8(e):i===2?t.pushUint16(e):i===3?t.pushUint24(e):t.pushUint32(e));for(const{encode:h}of n)h(t)}}}function y(n){const e=typeof n=="string"?f.hexToBytes(n):n,i=l(e.length);return{length:e.length===1&&e[0]<128?1:e.length<=55?1+e.length:1+i+e.length,encode(t){e.length===1&&e[0]<128?t.pushBytes(e):e.length<=55?(t.pushByte(128+e.length),t.pushBytes(e)):(t.pushByte(183+i),i===1?t.pushUint8(e.length):i===2?t.pushUint16(e.length):i===3?t.pushUint24(e.length):t.pushUint32(e.length),t.pushBytes(e))}}}function l(n){if(n<2**8)return 1;if(n<2**16)return 2;if(n<2**24)return 3;if(n<2**32)return 4;throw new r.BaseError("Length is too large.")}exports.toRlp=c;
|