@btc-vision/transaction 1.7.25 → 1.7.26

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.
@@ -1,86 +0,0 @@
1
- import { C as M } from "./vendors.js";
2
- function a(h, e) {
3
- h = h.replace("#", "");
4
- const s = parseInt(h, 16), i = Math.round(2.55 * e), l = (s >> 16) + i, f = (s >> 8 & 255) + i, S = (s & 255) + i;
5
- return (16777216 + (l < 255 ? l < 1 ? 0 : l : 255) * 65536 + (f < 255 ? f < 1 ? 0 : f : 255) * 256 + (S < 255 ? S < 1 ? 0 : S : 255)).toString(16).slice(1);
6
- }
7
- var t = function(h, e, s, i) {
8
- if (s === "a" && !i) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof e == "function" ? h !== e || !i : !e.has(h)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return s === "m" ? i : s === "a" ? i.call(h) : i ? i.value : e.get(h);
11
- }, o, _, c, d, p, x, N, k, $, L, g, n, u, r, w, m, P;
12
- class R {
13
- constructor(e = new M()) {
14
- this.chalk = e, this.moduleName = "", this.logColor = "#00bfff", this.enableLogs = !0, this.hideLogs = !1, o.set(this, "#ff00ff"), _.set(this, a(t(this, o, "f"), 75)), c.set(this, "#9400d3"), d.set(this, a(t(this, c, "f"), 15)), p.set(this, a(t(this, d, "f"), 15)), x.set(this, "#7cfc00"), N.set(this, a(t(this, x, "f"), 15)), k.set(this, "#ffdead"), $.set(this, a(t(this, k, "f"), 15)), L.set(this, "#ff8c00"), g.set(this, a(t(this, L, "f"), 15)), n.set(this, "#ff4500"), u.set(this, a(t(this, n, "f"), 15)), r.set(this, "#ffffff"), w.set(this, a(t(this, r, "f"), 15)), m.set(this, "#8b0000"), P.set(this, a(t(this, m, "f"), 15)), this.prefix = "", this.moduleName = this.constructor.name;
15
- }
16
- setLogPrefix(e) {
17
- this.prefix = e;
18
- }
19
- getStartPrefix() {
20
- return this.prefix;
21
- }
22
- disable() {
23
- this.enableLogs = !1;
24
- }
25
- enable() {
26
- this.enableLogs = !0;
27
- }
28
- fancyLog(e, s, i, l, f) {
29
- this.enableLogs && console.log(this.chalk.hex(t(this, o, "f"))(`${this.getStartPrefix()}[${this.moduleName} INFO]: `) + this.chalk.hex(t(this, r, "f"))(e) + " " + this.chalk.hex(t(this, g, "f"))(s) + " " + this.chalk.hex(t(this, r, "f"))(i) + " " + this.chalk.hex(t(this, p, "f"))(l) + " " + this.chalk.hex(t(this, r, "f"))(f));
30
- }
31
- log(...e) {
32
- if (this.enableLogs && !this.hideLogs) {
33
- const s = a(this.logColor, 15);
34
- console.log(this.chalk.hex(this.logColor)(`${this.getStartPrefix()}[${this.moduleName} LOG]: `) + this.chalk.hex(s)(...e));
35
- }
36
- }
37
- lightOrangeLog(...e) {
38
- this.enableLogs && (this.hideLogs || console.log(this.chalk.hex(t(this, g, "f"))(`${this.getStartPrefix()}[${this.moduleName} LOG]: `) + this.chalk.hex(t(this, r, "f"))(...e)));
39
- }
40
- error(...e) {
41
- this.enableLogs && console.log(this.chalk.hex(t(this, n, "f"))(`${this.getStartPrefix()}[${this.moduleName} ERROR]: `) + this.chalk.hex(t(this, u, "f"))(...e));
42
- }
43
- warn(...e) {
44
- this.enableLogs && console.log(this.chalk.hex(t(this, L, "f"))(`${this.getStartPrefix()}[${this.moduleName} WARN]: `) + this.chalk.hex(t(this, g, "f"))(...e));
45
- }
46
- debug(...e) {
47
- this.enableLogs && (this.hideLogs || console.log(this.chalk.hex(t(this, k, "f"))(`${this.getStartPrefix()}[${this.moduleName} DEBUG]: `) + this.chalk.hex(t(this, $, "f"))(...e)));
48
- }
49
- success(...e) {
50
- this.enableLogs && (this.hideLogs || console.log(this.chalk.hex(t(this, x, "f"))(`${this.getStartPrefix()}[${this.moduleName} SUCCESS]: `) + this.chalk.hex(t(this, N, "f"))(...e)));
51
- }
52
- fail(...e) {
53
- this.enableLogs && (this.hideLogs || console.log(this.chalk.hex(t(this, n, "f"))(`${this.getStartPrefix()}[${this.moduleName} FAIL]: `) + this.chalk.hex(t(this, u, "f"))(...e)));
54
- }
55
- debugBright(...e) {
56
- this.enableLogs && (this.hideLogs || console.log(this.chalk.hex(t(this, c, "f"))(`${this.getStartPrefix()}[${this.moduleName} DEBUG]: `) + this.chalk.hex(t(this, d, "f"))(...e)));
57
- }
58
- important(...e) {
59
- this.enableLogs && console.log(this.chalk.hex(t(this, o, "f"))(`${this.getStartPrefix()}[${this.moduleName} IMPORTANT]: `) + this.chalk.hex(t(this, _, "f"))(...e));
60
- }
61
- panic(...e) {
62
- this.enableLogs && console.log(this.chalk.hex(t(this, m, "f"))(`${this.getStartPrefix()}[${this.moduleName} HELP PANIC]: `) + this.chalk.hex(t(this, P, "f"))(...e));
63
- }
64
- info(...e) {
65
- this.enableLogs && console.log(this.chalk.hex(t(this, o, "f"))(`${this.getStartPrefix()}[${this.moduleName} INFO]: `) + this.chalk.hex(t(this, r, "f"))(...e));
66
- }
67
- securityNotice(...e) {
68
- this.enableLogs && console.log(this.chalk.hex("#22d8e6")(`${this.getStartPrefix()}[${this.moduleName} SECURITY NOTICE]: `) + this.chalk.hex("#22e3e6")(...e));
69
- }
70
- traceLog(...e) {
71
- this.enableLogs && console.log(this.chalk.hex("#ffffff")(`${this.getStartPrefix()}[${this.moduleName} TRACE LOG]: `) + this.chalk.hex(t(this, w, "f"))(...e));
72
- }
73
- }
74
- o = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), N = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ new WeakMap(), L = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), n = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap(), r = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap();
75
- class O extends R {
76
- constructor() {
77
- super();
78
- }
79
- }
80
- var W;
81
- (function(h) {
82
- h[h.NONE = 0] = "NONE", h[h.ERROR = 1] = "ERROR", h[h.WARN = 2] = "WARN", h[h.INFO = 3] = "INFO", h[h.DEBUG = 4] = "DEBUG", h[h.TRACE = 5] = "TRACE", h[h.ALL = 6] = "ALL";
83
- })(W || (W = {}));
84
- export {
85
- O as L
86
- };
@@ -1,542 +0,0 @@
1
- import { a as Je } from "./bip39.js";
2
- import { F as qe, c as st, d as ct } from "./noble-curves.js";
3
- import { h as j, i as it, j as Pe, k as lt, l as ft, m as R } from "./noble-hashes.js";
4
- const Le = it;
5
- function Se(e, o) {
6
- if (e.length !== o.length)
7
- return !1;
8
- let n = 0;
9
- for (let l = 0; l < e.length; l++)
10
- n |= e[l] ^ o[l];
11
- return n === 0;
12
- }
13
- function dt(e) {
14
- return Uint8Array.from(e);
15
- }
16
- function je(e) {
17
- if (typeof e != "object" || e === null || lt(e))
18
- throw new Error("expected opts to be an object");
19
- }
20
- function Me(e) {
21
- je(e), e.context !== void 0 && j(e.context, void 0, "opts.context");
22
- }
23
- function me(e) {
24
- Me(e), e.extraEntropy !== !1 && e.extraEntropy !== void 0 && j(e.extraEntropy, void 0, "opts.extraEntropy");
25
- }
26
- function ue(e, ...o) {
27
- const n = (d) => typeof d == "number" ? d : d.bytesLen, l = o.reduce((d, g) => d + n(g), 0);
28
- return {
29
- bytesLen: l,
30
- encode: (d) => {
31
- const g = new Uint8Array(l);
32
- for (let h = 0, u = 0; h < o.length; h++) {
33
- const M = o[h], G = n(M), O = typeof M == "number" ? d[h] : M.encode(d[h]);
34
- j(O, G, e), g.set(O, u), typeof M != "number" && O.fill(0), u += G;
35
- }
36
- return g;
37
- },
38
- decode: (d) => {
39
- j(d, l, e);
40
- const g = [];
41
- for (const h of o) {
42
- const u = n(h), M = d.subarray(0, u);
43
- g.push(typeof h == "number" ? M : h.decode(M)), d = d.subarray(u);
44
- }
45
- return g;
46
- }
47
- };
48
- }
49
- function J(e, o) {
50
- const n = o * e.bytesLen;
51
- return {
52
- bytesLen: n,
53
- encode: (l) => {
54
- if (l.length !== o)
55
- throw new Error(`vecCoder.encode: wrong length=${l.length}. Expected: ${o}`);
56
- const d = new Uint8Array(n);
57
- for (let g = 0, h = 0; g < l.length; g++) {
58
- const u = e.encode(l[g]);
59
- d.set(u, h), u.fill(0), h += u.length;
60
- }
61
- return d;
62
- },
63
- decode: (l) => {
64
- j(l, n);
65
- const d = [];
66
- for (let g = 0; g < l.length; g += e.bytesLen)
67
- d.push(e.decode(l.subarray(g, g + e.bytesLen)));
68
- return d;
69
- }
70
- };
71
- }
72
- function D(...e) {
73
- for (const o of e)
74
- if (Array.isArray(o))
75
- for (const n of o)
76
- n.fill(0);
77
- else
78
- o.fill(0);
79
- }
80
- function _e(e) {
81
- return (1 << e) - 1;
82
- }
83
- const Oe = Uint8Array.of();
84
- function Be(e, o = Oe) {
85
- if (j(e), j(o), o.length > 255)
86
- throw new Error("context should be less than 255 bytes");
87
- return Pe(new Uint8Array([0, o.length]), o, e);
88
- }
89
- const at = /* @__PURE__ */ Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2]);
90
- function et(e, o = 0) {
91
- if (!e.oid || !Se(e.oid.subarray(0, 10), at))
92
- throw new Error("hash.oid is invalid: expected NIST hash");
93
- const n = e.outputLen * 8 / 2;
94
- if (o > n)
95
- throw new Error("Pre-hash security strength too low: " + n + ", required: " + o);
96
- }
97
- function ke(e, o, n = Oe) {
98
- if (j(o), j(n), n.length > 255)
99
- throw new Error("context should be less than 255 bytes");
100
- const l = e(o);
101
- return Pe(new Uint8Array([1, n.length]), n, e.oid, l);
102
- }
103
- const ut = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
104
- __proto__: null,
105
- EMPTY: Oe,
106
- abytes: j,
107
- checkHash: et,
108
- cleanBytes: D,
109
- concatBytes: Pe,
110
- copyBytes: dt,
111
- equalBytes: Se,
112
- getMask: _e,
113
- getMessage: Be,
114
- getMessagePrehash: ke,
115
- randomBytes: Le,
116
- splitCoder: ue,
117
- validateOpts: je,
118
- validateSigOpts: me,
119
- validateVerOpts: Me,
120
- vecCoder: J
121
- }, Symbol.toStringTag, { value: "Module" })), Lt = /* @__PURE__ */ Je(ut);
122
- const yt = (e) => {
123
- const { newPoly: o, N: n, Q: l, F: d, ROOT_OF_UNITY: g, brvBits: h } = e, u = (y, p = l) => {
124
- const B = y % p | 0;
125
- return (B >= 0 ? B | 0 : p + B | 0) | 0;
126
- }, M = (y, p = l) => {
127
- const B = u(y, p) | 0;
128
- return (B > p >> 1 ? B - p | 0 : B) | 0;
129
- };
130
- function G() {
131
- const y = o(n);
132
- for (let p = 0; p < n; p++) {
133
- const B = st(p, h), oe = BigInt(g) ** BigInt(B) % BigInt(l);
134
- y[p] = Number(oe) | 0;
135
- }
136
- return y;
137
- }
138
- const O = G(), Q = {
139
- add: (y, p) => u((y | 0) + (p | 0)) | 0,
140
- sub: (y, p) => u((y | 0) - (p | 0)) | 0,
141
- mul: (y, p) => u((y | 0) * (p | 0)) | 0,
142
- inv: (y) => {
143
- throw new Error("not implemented");
144
- }
145
- }, se = {
146
- N: n,
147
- roots: O,
148
- invertButterflies: !0,
149
- skipStages: 0,
150
- brp: !1
151
- }, ce = qe(Q, { dit: !1, ...se }), ne = qe(Q, { dit: !0, ...se });
152
- return { mod: u, smod: M, nttZetas: O, NTT: {
153
- encode: (y) => ce(y),
154
- decode: (y) => {
155
- ne(y);
156
- for (let p = 0; p < y.length; p++)
157
- y[p] = u(d * y[p]);
158
- return y;
159
- }
160
- }, bitsCoder: (y, p) => {
161
- const B = _e(y), oe = y * (n / 8);
162
- return {
163
- bytesLen: oe,
164
- encode: (V) => {
165
- const W = new Uint8Array(oe);
166
- for (let Y = 0, H = 0, k = 0, ie = 0; Y < V.length; Y++)
167
- for (H |= (p.encode(V[Y]) & B) << k, k += y; k >= 8; k -= 8, H >>= 8)
168
- W[ie++] = H & _e(k);
169
- return W;
170
- },
171
- decode: (V) => {
172
- const W = o(n);
173
- for (let Y = 0, H = 0, k = 0, ie = 0; Y < V.length; Y++)
174
- for (H |= V[Y] << k, k += 8; k >= y; k -= y, H >>= y)
175
- W[ie++] = p.decode(H & B);
176
- return W;
177
- }
178
- };
179
- } };
180
- }, tt = (e) => (o, n) => {
181
- n || (n = e.blockLen);
182
- const l = new Uint8Array(o.length + 2);
183
- l.set(o);
184
- const d = o.length, g = new Uint8Array(n);
185
- let h = e.create({}), u = 0, M = 0;
186
- return {
187
- stats: () => ({ calls: u, xofs: M }),
188
- get: (G, O) => (l[d + 0] = G, l[d + 1] = O, h.destroy(), h = e.create({}).update(l), u++, () => (M++, h.xofInto(g))),
189
- clean: () => {
190
- h.destroy(), D(g, l);
191
- }
192
- };
193
- }, Ue = /* @__PURE__ */ tt(ft), Re = /* @__PURE__ */ tt(R);
194
- function Ze(e) {
195
- je(e), e.externalMu !== void 0 && ct(e.externalMu, "opts.externalMu");
196
- }
197
- const b = 256, Z = 8380417, ht = 1753, gt = 8347681, te = 13, Ce = Math.floor((Z - 1) / 88) | 0, ve = Math.floor((Z - 1) / 32) | 0, Ee = {
198
- 2: { K: 4, L: 4, D: te, GAMMA1: 2 ** 17, GAMMA2: Ce, TAU: 39, ETA: 2, OMEGA: 80 },
199
- 3: { K: 6, L: 5, D: te, GAMMA1: 2 ** 19, GAMMA2: ve, TAU: 49, ETA: 4, OMEGA: 55 },
200
- 5: { K: 8, L: 7, D: te, GAMMA1: 2 ** 19, GAMMA2: ve, TAU: 60, ETA: 2, OMEGA: 75 }
201
- }, S = (e) => new Int32Array(e), { mod: ee, smod: we, NTT: x, bitsCoder: pt } = yt({
202
- N: b,
203
- Q: Z,
204
- F: gt,
205
- ROOT_OF_UNITY: ht,
206
- newPoly: S,
207
- brvBits: 8
208
- }), Qe = (e) => e, de = (e, o = Qe, n = Qe) => pt(e, {
209
- encode: (l) => o(n(l)),
210
- decode: (l) => n(o(l))
211
- }), z = (e, o) => {
212
- for (let n = 0; n < e.length; n++)
213
- e[n] = ee(e[n] + o[n]);
214
- return e;
215
- }, Ve = (e, o) => {
216
- for (let n = 0; n < e.length; n++)
217
- e[n] = ee(e[n] - o[n]);
218
- return e;
219
- }, At = (e) => {
220
- for (let o = 0; o < b; o++)
221
- e[o] <<= te;
222
- return e;
223
- }, ae = (e, o) => {
224
- for (let n = 0; n < b; n++)
225
- if (Math.abs(we(e[n])) >= o)
226
- return !0;
227
- return !1;
228
- }, q = (e, o) => {
229
- const n = S(b);
230
- for (let l = 0; l < e.length; l++)
231
- n[l] = ee(e[l] * o[l]);
232
- return n;
233
- };
234
- function Te(e) {
235
- const o = S(b);
236
- for (let n = 0; n < b; ) {
237
- const l = e();
238
- if (l.length % 3)
239
- throw new Error("RejNTTPoly: unaligned block");
240
- for (let d = 0; n < b && d <= l.length - 3; d += 3) {
241
- const g = (l[d + 0] | l[d + 1] << 8 | l[d + 2] << 16) & 8388607;
242
- g < Z && (o[n++] = g);
243
- }
244
- }
245
- return o;
246
- }
247
- function Ke(e) {
248
- const { K: o, L: n, GAMMA1: l, GAMMA2: d, TAU: g, ETA: h, OMEGA: u } = e, { CRH_BYTES: M, TR_BYTES: G, C_TILDE_BYTES: O, XOF128: Q, XOF256: se, securityLevel: ce } = e;
249
- if (![2, 4].includes(h))
250
- throw new Error("Wrong ETA");
251
- if (![1 << 17, 1 << 19].includes(l))
252
- throw new Error("Wrong GAMMA1");
253
- if (![Ce, ve].includes(d))
254
- throw new Error("Wrong GAMMA2");
255
- const ne = g * h, ye = (t) => {
256
- const c = ee(t), r = we(c, 2 * d) | 0;
257
- return c - r === Z - 1 ? { r1: 0, r0: r - 1 | 0 } : { r1: Math.floor((c - r) / (2 * d)) | 0, r0: r };
258
- }, Ge = (t) => ye(t).r1, y = (t) => ye(t).r0, p = (t, c) => t <= d || t > Z - d || t === Z - d && c === 0 ? 0 : 1, B = (t, c) => {
259
- const r = Math.floor((Z - 1) / (2 * d)), { r1: s, r0: f } = ye(c);
260
- return t === 1 ? f > 0 ? ee(s + 1, r) | 0 : ee(s - 1, r) | 0 : s | 0;
261
- }, oe = (t) => {
262
- const c = ee(t), r = we(c, 2 ** te) | 0;
263
- return { r1: Math.floor((c - r) / 2 ** te) | 0, r0: r };
264
- }, V = {
265
- bytesLen: u + o,
266
- encode: (t) => {
267
- if (t === !1)
268
- throw new Error("hint.encode: hint is false");
269
- const c = new Uint8Array(u + o);
270
- for (let r = 0, s = 0; r < o; r++) {
271
- for (let f = 0; f < b; f++)
272
- t[r][f] !== 0 && (c[s++] = f);
273
- c[u + r] = s;
274
- }
275
- return c;
276
- },
277
- decode: (t) => {
278
- const c = [];
279
- let r = 0;
280
- for (let s = 0; s < o; s++) {
281
- const f = S(b);
282
- if (t[u + s] < r || t[u + s] > u)
283
- return !1;
284
- for (let a = r; a < t[u + s]; a++) {
285
- if (a > r && t[a] <= t[a - 1])
286
- return !1;
287
- f[t[a]] = 1;
288
- }
289
- r = t[u + s], c.push(f);
290
- }
291
- for (let s = r; s < u; s++)
292
- if (t[s] !== 0)
293
- return !1;
294
- return c;
295
- }
296
- }, W = de(h === 2 ? 3 : 4, (t) => h - t, (t) => {
297
- if (!(-h <= t && t <= h))
298
- throw new Error(`malformed key s1/s3 ${t} outside of ETA range [${-h}, ${h}]`);
299
- return t;
300
- }), Y = de(13, (t) => (1 << te - 1) - t), H = de(10), k = de(l === 1 << 17 ? 18 : 20, (t) => we(l - t)), ie = de(d === Ce ? 6 : 4), Ie = J(ie, o), he = ue("publicKey", 32, J(H, o)), ge = ue("secretKey", 32, 32, G, J(W, n), J(W, o), J(Y, o)), pe = ue("signature", O, J(k, n), V), Ne = h === 2 ? (t) => t < 15 ? 2 - t % 5 : !1 : (t) => t < 9 ? 4 - t : !1;
301
- function Ye(t) {
302
- const c = S(b);
303
- for (let r = 0; r < b; ) {
304
- const s = t();
305
- for (let f = 0; r < b && f < s.length; f += 1) {
306
- const a = Ne(s[f] & 15), L = Ne(s[f] >> 4 & 15);
307
- a !== !1 && (c[r++] = a), r < b && L !== !1 && (c[r++] = L);
308
- }
309
- }
310
- return c;
311
- }
312
- const He = (t) => {
313
- const c = S(b), r = R.create({}).update(t), s = new Uint8Array(R.blockLen);
314
- r.xofInto(s);
315
- const f = s.slice(0, 8);
316
- for (let a = b - g, L = 8, C = 0, T = 0; a < b; a++) {
317
- let m = a + 1;
318
- for (; m > a; )
319
- m = s[L++], !(L < R.blockLen) && (r.xofInto(s), L = 0);
320
- c[a] = c[m], c[m] = 1 - ((f[C] >> T++ & 1) << 1), T >= 8 && (C++, T = 0);
321
- }
322
- return c;
323
- }, Fe = (t) => {
324
- const c = S(b), r = S(b);
325
- for (let s = 0; s < t.length; s++) {
326
- const { r0: f, r1: a } = oe(t[s]);
327
- c[s] = f, r[s] = a;
328
- }
329
- return { r0: c, r1: r };
330
- }, nt = (t, c) => {
331
- for (let r = 0; r < b; r++)
332
- t[r] = B(c[r], t[r]);
333
- return t;
334
- }, ot = (t, c) => {
335
- const r = S(b);
336
- let s = 0;
337
- for (let f = 0; f < b; f++) {
338
- const a = p(t[f], c[f]);
339
- r[f] = a, s += a;
340
- }
341
- return { v: r, cnt: s };
342
- }, $e = 32, De = ue("seed", 32, 64, 32), K = {
343
- info: { type: "internal-ml-dsa" },
344
- lengths: {
345
- secretKey: ge.bytesLen,
346
- publicKey: he.bytesLen,
347
- seed: 32,
348
- signature: pe.bytesLen,
349
- signRand: $e
350
- },
351
- keygen: (t) => {
352
- const c = new Uint8Array(34), r = t === void 0;
353
- r && (t = Le(32)), j(t, 32, "seed"), c.set(t), r && D(t), c[32] = o, c[33] = n;
354
- const [s, f, a] = De.decode(R(c, { dkLen: De.bytesLen })), L = se(f), C = [];
355
- for (let i = 0; i < n; i++)
356
- C.push(Ye(L.get(i & 255, i >> 8 & 255)));
357
- const T = [];
358
- for (let i = n; i < n + o; i++)
359
- T.push(Ye(L.get(i & 255, i >> 8 & 255)));
360
- const m = C.map((i) => x.encode(i.slice())), w = [], _ = [], F = Q(s), E = S(b);
361
- for (let i = 0; i < o; i++) {
362
- D(E);
363
- for (let P = 0; P < n; P++) {
364
- const N = Te(F.get(P, i));
365
- z(E, q(N, m[P]));
366
- }
367
- x.decode(E);
368
- const { r0: U, r1: v } = Fe(z(E, T[i]));
369
- w.push(U), _.push(v);
370
- }
371
- const I = he.encode([s, _]), $ = R(I, { dkLen: G }), re = ge.encode([s, a, $, C, T, w]);
372
- return F.clean(), L.clean(), D(s, f, a, C, T, m, E, w, _, $, c), { publicKey: I, secretKey: re };
373
- },
374
- getPublicKey: (t) => {
375
- const [c, r, s, f, a, L] = ge.decode(t), C = Q(c), T = f.map((_) => x.encode(_.slice())), m = [], w = S(b);
376
- for (let _ = 0; _ < o; _++) {
377
- w.fill(0);
378
- for (let E = 0; E < n; E++) {
379
- const I = Te(C.get(E, _));
380
- z(w, q(I, T[E]));
381
- }
382
- x.decode(w), z(w, a[_]);
383
- const { r1: F } = Fe(w);
384
- m.push(F);
385
- }
386
- return C.clean(), D(w, T, L, f, a), he.encode([c, m]);
387
- },
388
- // NOTE: random is optional.
389
- sign: (t, c, r = {}) => {
390
- me(r), Ze(r);
391
- let { extraEntropy: s, externalMu: f = !1 } = r;
392
- const [a, L, C, T, m, w] = ge.decode(c), _ = [], F = Q(a);
393
- for (let i = 0; i < o; i++) {
394
- const U = [];
395
- for (let v = 0; v < n; v++)
396
- U.push(Te(F.get(v, i)));
397
- _.push(U);
398
- }
399
- F.clean();
400
- for (let i = 0; i < n; i++)
401
- x.encode(T[i]);
402
- for (let i = 0; i < o; i++)
403
- x.encode(m[i]), x.encode(w[i]);
404
- const E = f ? t : R.create({ dkLen: M }).update(C).update(t).digest(), I = s === !1 ? new Uint8Array(32) : s === void 0 ? Le($e) : s;
405
- j(I, 32, "extraEntropy");
406
- const $ = R.create({ dkLen: M }).update(L).update(I).update(E).digest();
407
- j($, M);
408
- const re = se($, k.bytesLen);
409
- e: for (let i = 0; ; ) {
410
- const U = [];
411
- for (let A = 0; A < n; A++, i++)
412
- U.push(k.decode(re.get(i & 255, i >> 8)()));
413
- const v = U.map((A) => x.encode(A.slice())), P = [];
414
- for (let A = 0; A < o; A++) {
415
- const fe = S(b);
416
- for (let X = 0; X < n; X++)
417
- z(fe, q(_[A][X], v[X]));
418
- x.decode(fe), P.push(fe);
419
- }
420
- const N = P.map((A) => A.map(Ge)), le = R.create({ dkLen: O }).update(E).update(Ie.encode(N)).digest(), Ae = x.encode(He(le)), be = T.map((A) => q(A, Ae));
421
- for (let A = 0; A < n; A++)
422
- if (z(x.decode(be[A]), U[A]), ae(be[A], l - ne))
423
- continue e;
424
- let We = 0;
425
- const xe = [];
426
- for (let A = 0; A < o; A++) {
427
- const fe = x.decode(q(m[A], Ae)), X = Ve(P[A], fe).map(y);
428
- if (ae(X, d - ne))
429
- continue e;
430
- const Xe = x.decode(q(w[A], Ae));
431
- if (ae(Xe, d))
432
- continue e;
433
- z(X, Xe);
434
- const ze = ot(X, N[A]);
435
- xe.push(ze.v), We += ze.cnt;
436
- }
437
- if (We > u)
438
- continue;
439
- re.clean();
440
- const rt = pe.encode([le, be, xe]);
441
- return D(le, be, xe, Ae, N, P, v, U, $, E, T, m, w, ..._), rt;
442
- }
443
- throw new Error("Unreachable code path reached, report this error");
444
- },
445
- verify: (t, c, r, s = {}) => {
446
- Ze(s);
447
- const { externalMu: f = !1 } = s, [a, L] = he.decode(r), C = R(r, { dkLen: G });
448
- if (t.length !== pe.bytesLen)
449
- return !1;
450
- const [T, m, w] = pe.decode(t);
451
- if (w === !1)
452
- return !1;
453
- for (let i = 0; i < n; i++)
454
- if (ae(m[i], l - ne))
455
- return !1;
456
- const _ = f ? c : R.create({ dkLen: M }).update(C).update(c).digest(), F = x.encode(He(T)), E = m.map((i) => i.slice());
457
- for (let i = 0; i < n; i++)
458
- x.encode(E[i]);
459
- const I = [], $ = Q(a);
460
- for (let i = 0; i < o; i++) {
461
- const U = q(x.encode(At(L[i])), F), v = S(b);
462
- for (let N = 0; N < n; N++) {
463
- const le = Te($.get(N, i));
464
- z(v, q(le, E[N]));
465
- }
466
- const P = x.decode(Ve(v, U));
467
- I.push(nt(P, w[i]));
468
- }
469
- $.clean();
470
- const re = R.create({ dkLen: O }).update(_).update(Ie.encode(I)).digest();
471
- for (const i of w)
472
- if (!(i.reduce((v, P) => v + P, 0) <= u))
473
- return !1;
474
- for (const i of m)
475
- if (ae(i, l - ne))
476
- return !1;
477
- return Se(T, re);
478
- }
479
- };
480
- return {
481
- info: { type: "ml-dsa" },
482
- internal: K,
483
- securityLevel: ce,
484
- keygen: K.keygen,
485
- lengths: K.lengths,
486
- getPublicKey: K.getPublicKey,
487
- sign: (t, c, r = {}) => {
488
- me(r);
489
- const s = Be(t, r.context), f = K.sign(s, c, r);
490
- return D(s), f;
491
- },
492
- verify: (t, c, r, s = {}) => (Me(s), K.verify(t, Be(c, s.context), r)),
493
- prehash: (t) => (et(t, ce), {
494
- info: { type: "hashml-dsa" },
495
- securityLevel: ce,
496
- lengths: K.lengths,
497
- keygen: K.keygen,
498
- getPublicKey: K.getPublicKey,
499
- sign: (c, r, s = {}) => {
500
- me(s);
501
- const f = ke(t, c, s.context), a = K.sign(f, r, s);
502
- return D(f), a;
503
- },
504
- verify: (c, r, s, f = {}) => (Me(f), K.verify(c, ke(t, r, f.context), s))
505
- })
506
- };
507
- }
508
- const bt = /* @__PURE__ */ Ke({
509
- ...Ee[2],
510
- CRH_BYTES: 64,
511
- TR_BYTES: 64,
512
- C_TILDE_BYTES: 32,
513
- XOF128: Ue,
514
- XOF256: Re,
515
- securityLevel: 128
516
- }), Tt = /* @__PURE__ */ Ke({
517
- ...Ee[3],
518
- CRH_BYTES: 64,
519
- TR_BYTES: 64,
520
- C_TILDE_BYTES: 48,
521
- XOF128: Ue,
522
- XOF256: Re,
523
- securityLevel: 192
524
- }), mt = /* @__PURE__ */ Ke({
525
- ...Ee[5],
526
- CRH_BYTES: 64,
527
- TR_BYTES: 64,
528
- C_TILDE_BYTES: 64,
529
- XOF128: Ue,
530
- XOF256: Re,
531
- securityLevel: 256
532
- }), wt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
533
- __proto__: null,
534
- PARAMS: Ee,
535
- ml_dsa44: bt,
536
- ml_dsa65: Tt,
537
- ml_dsa87: mt
538
- }, Symbol.toStringTag, { value: "Module" })), _t = /* @__PURE__ */ Je(wt);
539
- export {
540
- Lt as a,
541
- _t as r
542
- };