@btc-vision/transaction 1.7.25 → 1.7.27

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,805 +0,0 @@
1
- import { g as pe } from "./bip39.js";
2
- import { d as ye, b as X, e as ge, a as ve } from "./noble-hashes.js";
3
- import { d as W, e as _e } from "./vendors.js";
4
- import { r as oe } from "./scure-base.js";
5
- import { r as Z } from "./valibot.js";
6
- import { r as Ee, a as we } from "./btc-vision-post-quantum.js";
7
- var G = {}, D = {}, R = {}, $;
8
- function se() {
9
- if ($) return R;
10
- $ = 1, Object.defineProperty(R, "__esModule", { value: !0 }), R.hash160 = e, R.hash256 = w, R.hmacSHA512 = s;
11
- const i = /* @__PURE__ */ ge(), I = /* @__PURE__ */ ye(), g = /* @__PURE__ */ X(), _ = /* @__PURE__ */ ve();
12
- function e(r) {
13
- return (0, I.ripemd160)((0, g.sha256)(r));
14
- }
15
- function w(r) {
16
- return (0, g.sha256)(r);
17
- }
18
- function s(r, f) {
19
- return (0, i.hmac)(_.sha512, r, f);
20
- }
21
- return R;
22
- }
23
- var j = {}, ee;
24
- function Pe() {
25
- if (ee) return j;
26
- ee = 1;
27
- var i = j && j.__createBinding || (Object.create ? (function(r, f, E, u) {
28
- u === void 0 && (u = E);
29
- var p = Object.getOwnPropertyDescriptor(f, E);
30
- (!p || ("get" in p ? !f.__esModule : p.writable || p.configurable)) && (p = { enumerable: !0, get: function() {
31
- return f[E];
32
- } }), Object.defineProperty(r, u, p);
33
- }) : (function(r, f, E, u) {
34
- u === void 0 && (u = E), r[u] = f[E];
35
- })), I = j && j.__setModuleDefault || (Object.create ? (function(r, f) {
36
- Object.defineProperty(r, "default", { enumerable: !0, value: f });
37
- }) : function(r, f) {
38
- r.default = f;
39
- }), g = j && j.__importStar || /* @__PURE__ */ (function() {
40
- var r = function(f) {
41
- return r = Object.getOwnPropertyNames || function(E) {
42
- var u = [];
43
- for (var p in E) Object.prototype.hasOwnProperty.call(E, p) && (u[u.length] = p);
44
- return u;
45
- }, r(f);
46
- };
47
- return function(f) {
48
- if (f && f.__esModule) return f;
49
- var E = {};
50
- if (f != null) for (var u = r(f), p = 0; p < u.length; p++) u[p] !== "default" && i(E, f, u[p]);
51
- return I(E, f), E;
52
- };
53
- })();
54
- Object.defineProperty(j, "__esModule", { value: !0 }), j.testEcc = w;
55
- const _ = g(W), e = (r) => _.fromHex(r);
56
- function w(r) {
57
- if (s(r.isPoint(e("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))), s(!r.isPoint(e("030000000000000000000000000000000000000000000000000000000000000005"))), s(r.isPrivate(e("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))), s(r.isPrivate(e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))), s(!r.isPrivate(e("0000000000000000000000000000000000000000000000000000000000000000"))), s(!r.isPrivate(e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))), s(!r.isPrivate(e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))), s(_.compare(r.pointFromScalar(e("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af")), e("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99")) === 0), r.xOnlyPointAddTweak) {
58
- s(r.xOnlyPointAddTweak(e("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"), e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140")) === null);
59
- let f = r.xOnlyPointAddTweak(e("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"), e("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));
60
- s(_.compare(f.xOnlyPubkey, e("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf")) === 0 && f.parity === 1), f = r.xOnlyPointAddTweak(e("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"), e("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47"));
61
- }
62
- s(_.compare(r.pointAddScalar(e("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"), e("0000000000000000000000000000000000000000000000000000000000000003")), e("02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5")) === 0), s(_.compare(r.privateAdd(e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"), e("0000000000000000000000000000000000000000000000000000000000000002")), e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140")) === 0), r.privateNegate && (s(_.compare(r.privateNegate(e("0000000000000000000000000000000000000000000000000000000000000001")), e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140")) === 0), s(_.compare(r.privateNegate(e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e")), e("0000000000000000000000000000000000000000000000000000000000000003")) === 0), s(_.compare(r.privateNegate(e("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af")), e("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792")) === 0)), s(_.compare(r.sign(e("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"), e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140")), e("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5")) === 0), s(r.verify(e("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"), e("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"), e("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))), r.signSchnorr && s(_.compare(r.signSchnorr(e("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"), e("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"), e("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906")), e("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")) === 0), r.verifySchnorr && s(r.verifySchnorr(e("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"), e("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"), e("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")));
63
- }
64
- function s(r) {
65
- if (!r)
66
- throw new Error("ecc library invalid");
67
- }
68
- return j;
69
- }
70
- var A = {}, te;
71
- function de() {
72
- return te || (te = 1, (function(i) {
73
- var I = A && A.__createBinding || (Object.create ? (function(r, f, E, u) {
74
- u === void 0 && (u = E);
75
- var p = Object.getOwnPropertyDescriptor(f, E);
76
- (!p || ("get" in p ? !f.__esModule : p.writable || p.configurable)) && (p = { enumerable: !0, get: function() {
77
- return f[E];
78
- } }), Object.defineProperty(r, u, p);
79
- }) : (function(r, f, E, u) {
80
- u === void 0 && (u = E), r[u] = f[E];
81
- })), g = A && A.__setModuleDefault || (Object.create ? (function(r, f) {
82
- Object.defineProperty(r, "default", { enumerable: !0, value: f });
83
- }) : function(r, f) {
84
- r.default = f;
85
- }), _ = A && A.__importStar || /* @__PURE__ */ (function() {
86
- var r = function(f) {
87
- return r = Object.getOwnPropertyNames || function(E) {
88
- var u = [];
89
- for (var p in E) Object.prototype.hasOwnProperty.call(E, p) && (u[u.length] = p);
90
- return u;
91
- }, r(f);
92
- };
93
- return function(f) {
94
- if (f && f.__esModule) return f;
95
- var E = {};
96
- if (f != null) for (var u = r(f), p = 0; p < u.length; p++) u[p] !== "default" && I(E, f, u[p]);
97
- return g(E, f), E;
98
- };
99
- })();
100
- Object.defineProperty(i, "__esModule", { value: !0 }), i.Bip32PathSchema = i.NetworkSchema = i.Buffer33Bytes = i.Buffer256Bit = i.Uint31Schema = i.Uint32Schema = void 0;
101
- const e = _(/* @__PURE__ */ Z());
102
- i.Uint32Schema = e.pipe(e.number(), e.integer(), e.minValue(0), e.maxValue(4294967295)), i.Uint31Schema = e.pipe(e.number(), e.integer(), e.minValue(0), e.maxValue(2147483647));
103
- const w = e.pipe(e.number(), e.integer(), e.minValue(0), e.maxValue(255));
104
- i.Buffer256Bit = e.pipe(e.instance(Uint8Array), e.length(32)), i.Buffer33Bytes = e.pipe(e.instance(Uint8Array), e.length(33));
105
- const s = e.object({
106
- public: i.Uint32Schema,
107
- private: i.Uint32Schema
108
- });
109
- i.NetworkSchema = e.object({
110
- wif: w,
111
- bip32: s,
112
- messagePrefix: e.string(),
113
- bech32: e.string(),
114
- bech32Opnet: e.optional(e.string()),
115
- pubKeyHash: w,
116
- scriptHash: w
117
- }), i.Bip32PathSchema = e.pipe(e.string(), e.regex(/^(m\/)?(\d+'?\/)*\d+'?$/));
118
- })(A)), A;
119
- }
120
- var U = {}, re;
121
- function z() {
122
- return re || (re = 1, Object.defineProperty(U, "__esModule", { value: !0 }), U.REGTEST = U.TESTNET = U.BITCOIN = void 0, U.BITCOIN = {
123
- messagePrefix: `Bitcoin Signed Message:
124
- `,
125
- bech32: "bc",
126
- bip32: {
127
- public: 76067358,
128
- private: 76066276
129
- },
130
- pubKeyHash: 0,
131
- scriptHash: 5,
132
- wif: 128
133
- }, U.TESTNET = {
134
- messagePrefix: `Bitcoin Signed Message:
135
- `,
136
- bech32: "tb",
137
- bip32: {
138
- public: 70617039,
139
- private: 70615956
140
- },
141
- pubKeyHash: 111,
142
- scriptHash: 196,
143
- wif: 239
144
- }, U.REGTEST = {
145
- messagePrefix: `Bitcoin Signed Message:
146
- `,
147
- bech32: "bcrt",
148
- bip32: {
149
- public: 70617039,
150
- private: 70615956
151
- },
152
- pubKeyHash: 111,
153
- scriptHash: 196,
154
- wif: 239
155
- }), U;
156
- }
157
- var ie;
158
- function me() {
159
- if (ie) return D;
160
- ie = 1;
161
- var i = D && D.__createBinding || (Object.create ? (function(l, P, m, L) {
162
- L === void 0 && (L = m);
163
- var T = Object.getOwnPropertyDescriptor(P, m);
164
- (!T || ("get" in T ? !P.__esModule : T.writable || T.configurable)) && (T = { enumerable: !0, get: function() {
165
- return P[m];
166
- } }), Object.defineProperty(l, L, T);
167
- }) : (function(l, P, m, L) {
168
- L === void 0 && (L = m), l[L] = P[m];
169
- })), I = D && D.__setModuleDefault || (Object.create ? (function(l, P) {
170
- Object.defineProperty(l, "default", { enumerable: !0, value: P });
171
- }) : function(l, P) {
172
- l.default = P;
173
- }), g = D && D.__importStar || /* @__PURE__ */ (function() {
174
- var l = function(P) {
175
- return l = Object.getOwnPropertyNames || function(m) {
176
- var L = [];
177
- for (var T in m) Object.prototype.hasOwnProperty.call(m, T) && (L[L.length] = T);
178
- return L;
179
- }, l(P);
180
- };
181
- return function(P) {
182
- if (P && P.__esModule) return P;
183
- var m = {};
184
- if (P != null) for (var L = l(P), T = 0; T < L.length; T++) L[T] !== "default" && i(m, P, L[T]);
185
- return I(m, P), m;
186
- };
187
- })();
188
- Object.defineProperty(D, "__esModule", { value: !0 }), D.BIP32Factory = F;
189
- const _ = g(se()), e = Pe(), w = oe, s = /* @__PURE__ */ X(), r = g(/* @__PURE__ */ Z()), f = de(), E = g(_e()), u = g(W), p = z(), V = (0, w.base58check)(s.sha256), q = {
190
- encode: (l) => V.encode(l),
191
- decode: (l) => V.decode(l)
192
- };
193
- function F(l) {
194
- (0, e.testEcc)(l);
195
- const P = 2147483648;
196
- function m(c) {
197
- return c.length === 32 ? c : c.slice(1, 33);
198
- }
199
- class L {
200
- __D;
201
- __Q;
202
- lowR = !1;
203
- constructor(t, n) {
204
- this.__D = t, this.__Q = n;
205
- }
206
- get publicKey() {
207
- return this.__Q === void 0 && (this.__Q = l.pointFromScalar(this.__D, !0)), this.__Q;
208
- }
209
- get privateKey() {
210
- return this.__D;
211
- }
212
- sign(t, n) {
213
- if (!this.privateKey)
214
- throw new Error("Missing private key");
215
- if (n === void 0 && (n = this.lowR), n) {
216
- let o = l.sign(t, this.privateKey);
217
- const h = new Uint8Array(32);
218
- let v = 0;
219
- for (; o[0] > 127; )
220
- v++, u.writeUInt32(h, 0, v, "LE"), o = l.sign(t, this.privateKey, h);
221
- return o;
222
- } else
223
- return l.sign(t, this.privateKey);
224
- }
225
- signSchnorr(t) {
226
- if (!this.privateKey)
227
- throw new Error("Missing private key");
228
- if (!l.signSchnorr)
229
- throw new Error("signSchnorr not supported by ecc library");
230
- return l.signSchnorr(t, this.privateKey);
231
- }
232
- verify(t, n) {
233
- return l.verify(t, this.publicKey, n);
234
- }
235
- verifySchnorr(t, n) {
236
- if (!l.verifySchnorr)
237
- throw new Error("verifySchnorr not supported by ecc library");
238
- return l.verifySchnorr(t, this.publicKey.subarray(1, 33), n);
239
- }
240
- }
241
- class T extends L {
242
- chainCode;
243
- network;
244
- __DEPTH;
245
- __INDEX;
246
- __PARENT_FINGERPRINT;
247
- constructor(t, n, o, h, v = 0, O = 0, S = 0) {
248
- super(t, n), this.chainCode = o, this.network = h, this.__DEPTH = v, this.__INDEX = O, this.__PARENT_FINGERPRINT = S, r.parse(f.NetworkSchema, h);
249
- }
250
- get depth() {
251
- return this.__DEPTH;
252
- }
253
- get index() {
254
- return this.__INDEX;
255
- }
256
- get parentFingerprint() {
257
- return this.__PARENT_FINGERPRINT;
258
- }
259
- get identifier() {
260
- return _.hash160(this.publicKey);
261
- }
262
- get fingerprint() {
263
- return this.identifier.slice(0, 4);
264
- }
265
- get compressed() {
266
- return !0;
267
- }
268
- // Private === not neutered
269
- // Public === neutered
270
- isNeutered() {
271
- return this.__D === void 0;
272
- }
273
- neutered() {
274
- return b(this.publicKey, this.chainCode, this.network, this.depth, this.index, this.parentFingerprint);
275
- }
276
- toBase58() {
277
- const t = this.network, n = this.isNeutered() ? t.bip32.public : t.bip32.private, o = new Uint8Array(78);
278
- return u.writeUInt32(o, 0, n, "BE"), u.writeUInt8(o, 4, this.depth), u.writeUInt32(o, 5, this.parentFingerprint, "BE"), u.writeUInt32(o, 9, this.index, "BE"), o.set(this.chainCode, 13), this.isNeutered() ? o.set(this.publicKey, 45) : (u.writeUInt8(o, 45, 0), o.set(this.privateKey, 46)), q.encode(o);
279
- }
280
- toWIF() {
281
- if (!this.privateKey)
282
- throw new TypeError("Missing private key");
283
- return E.encode({
284
- version: this.network.wif,
285
- privateKey: this.privateKey,
286
- compressed: !0
287
- });
288
- }
289
- // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions
290
- derive(t) {
291
- r.parse(f.Uint32Schema, t);
292
- const n = t >= P, o = new Uint8Array(37);
293
- if (n) {
294
- if (this.isNeutered())
295
- throw new TypeError("Missing private key for hardened child key");
296
- o[0] = 0, o.set(this.privateKey, 1), u.writeUInt32(o, 33, t, "BE");
297
- } else
298
- o.set(this.publicKey, 0), u.writeUInt32(o, 33, t, "BE");
299
- const h = _.hmacSHA512(this.chainCode, o), v = h.slice(0, 32), O = h.slice(32);
300
- if (!l.isPrivate(v))
301
- return this.derive(t + 1);
302
- let S;
303
- if (this.isNeutered()) {
304
- const B = l.pointAddScalar(this.publicKey, v, !0);
305
- if (B === null)
306
- return this.derive(t + 1);
307
- S = b(B, O, this.network, this.depth + 1, t, u.readUInt32(this.fingerprint, 0, "BE"));
308
- } else {
309
- const B = l.privateAdd(this.privateKey, v);
310
- if (B == null)
311
- return this.derive(t + 1);
312
- S = y(B, O, this.network, this.depth + 1, t, u.readUInt32(this.fingerprint, 0, "BE"));
313
- }
314
- return S;
315
- }
316
- deriveHardened(t) {
317
- if (typeof r.parse(f.Uint31Schema, t) == "number")
318
- return this.derive(t + P);
319
- throw new TypeError("Expected UInt31, got " + t);
320
- }
321
- derivePath(t) {
322
- r.parse(f.Bip32PathSchema, t);
323
- let n = t.split("/");
324
- if (n[0] === "m") {
325
- if (this.parentFingerprint)
326
- throw new TypeError("Expected master, got child");
327
- n = n.slice(1);
328
- }
329
- return n.reduce((o, h) => {
330
- let v;
331
- return h.slice(-1) === "'" ? (v = parseInt(h.slice(0, -1), 10), o.deriveHardened(v)) : (v = parseInt(h, 10), o.derive(v));
332
- }, this);
333
- }
334
- tweak(t) {
335
- return this.privateKey ? this.tweakFromPrivateKey(t) : this.tweakFromPublicKey(t);
336
- }
337
- tweakFromPublicKey(t) {
338
- const n = m(this.publicKey);
339
- if (!l.xOnlyPointAddTweak)
340
- throw new Error("xOnlyPointAddTweak not supported by ecc library");
341
- const o = l.xOnlyPointAddTweak(n, t);
342
- if (!o || o.xOnlyPubkey === null)
343
- throw new Error("Cannot tweak public key!");
344
- const h = Uint8Array.from([
345
- o.parity === 0 ? 2 : 3
346
- ]), v = u.concat([
347
- h,
348
- o.xOnlyPubkey
349
- ]);
350
- return new L(void 0, v);
351
- }
352
- tweakFromPrivateKey(t) {
353
- const n = this.publicKey[0] === 3 || this.publicKey[0] === 4 && (this.publicKey[64] & 1) === 1, o = (() => {
354
- if (n) {
355
- if (l.privateNegate)
356
- return l.privateNegate(this.privateKey);
357
- throw new Error("privateNegate not supported by ecc library");
358
- } else return this.privateKey;
359
- })(), h = l.privateAdd(o, t);
360
- if (!h)
361
- throw new Error("Invalid tweaked private key!");
362
- return new L(h, void 0);
363
- }
364
- }
365
- function Q(c, t) {
366
- const n = q.decode(c);
367
- if (n.length !== 78)
368
- throw new TypeError("Invalid buffer length");
369
- t = t || p.BITCOIN;
370
- const o = u.readUInt32(n, 0, "BE");
371
- if (o !== t.bip32.private && o !== t.bip32.public)
372
- throw new TypeError("Invalid network version");
373
- const h = n[4], v = u.readUInt32(n, 5, "BE");
374
- if (h === 0 && v !== 0)
375
- throw new TypeError("Invalid parent fingerprint");
376
- const O = u.readUInt32(n, 9, "BE");
377
- if (h === 0 && O !== 0)
378
- throw new TypeError("Invalid index");
379
- const S = n.slice(13, 45);
380
- let B;
381
- if (o === t.bip32.private) {
382
- if (n[45] !== 0)
383
- throw new TypeError("Invalid private key");
384
- const C = n.slice(46, 78);
385
- B = y(C, S, t, h, O, v);
386
- } else {
387
- const C = n.slice(45, 78);
388
- B = b(C, S, t, h, O, v);
389
- }
390
- return B;
391
- }
392
- function H(c, t, n) {
393
- return y(c, t, n);
394
- }
395
- function y(c, t, n, o, h, v) {
396
- if (r.parse(f.Buffer256Bit, c), r.parse(f.Buffer256Bit, t), n = n || p.BITCOIN, !l.isPrivate(c))
397
- throw new TypeError("Private key not in range [1, n)");
398
- return new T(c, void 0, t, n, o, h, v);
399
- }
400
- function a(c, t, n) {
401
- return b(c, t, n);
402
- }
403
- function b(c, t, n, o, h, v) {
404
- if (r.parse(f.Buffer33Bytes, c), r.parse(f.Buffer256Bit, t), n = n || p.BITCOIN, !l.isPoint(c))
405
- throw new TypeError("Point is not on the curve");
406
- return new T(void 0, c, t, n, o, h, v);
407
- }
408
- function d(c, t) {
409
- if (r.parse(r.instance(Uint8Array), c), c.length < 16)
410
- throw new TypeError("Seed should be at least 128 bits");
411
- if (c.length > 64)
412
- throw new TypeError("Seed should be at most 512 bits");
413
- t = t || p.BITCOIN;
414
- const n = _.hmacSHA512(u.fromUtf8("Bitcoin seed"), c), o = n.slice(0, 32), h = n.slice(32);
415
- return H(o, h, t);
416
- }
417
- return {
418
- fromSeed: d,
419
- fromBase58: Q,
420
- fromPublicKey: a,
421
- fromPrivateKey: H
422
- };
423
- }
424
- return D;
425
- }
426
- var Y = {}, K = {}, N = {}, ne;
427
- function be() {
428
- if (ne) return N;
429
- ne = 1, Object.defineProperty(N, "__esModule", { value: !0 }), N.DEFAULT_SECURITY_LEVEL = N.MLDSASecurityLevel = void 0, N.getMLDSAConfig = e, N.findNetworkByVersion = w;
430
- const i = Ee, I = z();
431
- var g;
432
- (function(s) {
433
- s[s.LEVEL2 = 44] = "LEVEL2", s[s.LEVEL3 = 65] = "LEVEL3", s[s.LEVEL5 = 87] = "LEVEL5";
434
- })(g || (N.MLDSASecurityLevel = g = {}));
435
- const _ = {
436
- [g.LEVEL2]: {
437
- level: g.LEVEL2,
438
- privateKeySize: 2560,
439
- publicKeySize: 1312,
440
- signatureSize: 2420,
441
- algorithm: i.ml_dsa44
442
- },
443
- [g.LEVEL3]: {
444
- level: g.LEVEL3,
445
- privateKeySize: 4032,
446
- publicKeySize: 1952,
447
- signatureSize: 3309,
448
- algorithm: i.ml_dsa65
449
- },
450
- [g.LEVEL5]: {
451
- level: g.LEVEL5,
452
- privateKeySize: 4896,
453
- publicKeySize: 2592,
454
- signatureSize: 4627,
455
- algorithm: i.ml_dsa87
456
- }
457
- };
458
- N.DEFAULT_SECURITY_LEVEL = g.LEVEL2;
459
- function e(s, r) {
460
- const f = _[s];
461
- if (!f)
462
- throw new TypeError(`Invalid ML-DSA security level: ${s}. Must be MLDSASecurityLevel.LEVEL2 (44), LEVEL3 (65), or LEVEL5 (87)`);
463
- return {
464
- ...f,
465
- network: r
466
- };
467
- }
468
- function w(s) {
469
- const r = [I.BITCOIN, I.TESTNET, I.REGTEST];
470
- for (const f of r) {
471
- if (s === f.bip32.private)
472
- return { network: f, isPrivate: !0 };
473
- if (s === f.bip32.public)
474
- return { network: f, isPrivate: !1 };
475
- }
476
- return null;
477
- }
478
- return N;
479
- }
480
- var fe;
481
- function Se() {
482
- if (fe) return K;
483
- fe = 1;
484
- var i = K && K.__createBinding || (Object.create ? (function(y, a, b, d) {
485
- d === void 0 && (d = b);
486
- var c = Object.getOwnPropertyDescriptor(a, b);
487
- (!c || ("get" in c ? !a.__esModule : c.writable || c.configurable)) && (c = { enumerable: !0, get: function() {
488
- return a[b];
489
- } }), Object.defineProperty(y, d, c);
490
- }) : (function(y, a, b, d) {
491
- d === void 0 && (d = b), y[d] = a[b];
492
- })), I = K && K.__setModuleDefault || (Object.create ? (function(y, a) {
493
- Object.defineProperty(y, "default", { enumerable: !0, value: a });
494
- }) : function(y, a) {
495
- y.default = a;
496
- }), g = K && K.__importStar || /* @__PURE__ */ (function() {
497
- var y = function(a) {
498
- return y = Object.getOwnPropertyNames || function(b) {
499
- var d = [];
500
- for (var c in b) Object.prototype.hasOwnProperty.call(b, c) && (d[d.length] = c);
501
- return d;
502
- }, y(a);
503
- };
504
- return function(a) {
505
- if (a && a.__esModule) return a;
506
- var b = {};
507
- if (a != null) for (var d = y(a), c = 0; c < d.length; c++) d[c] !== "default" && i(b, a, d[c]);
508
- return I(b, a), b;
509
- };
510
- })();
511
- Object.defineProperty(K, "__esModule", { value: !0 }), K.QuantumBIP32Factory = void 0;
512
- const _ = we, e = g(se()), w = g(W), s = g(/* @__PURE__ */ Z()), r = de(), f = oe, E = /* @__PURE__ */ X(), u = be(), p = z(), V = (0, f.base58check)(E.sha256), q = {
513
- encode: (y) => V.encode(y),
514
- decode: (y) => V.decode(y)
515
- }, F = 32, l = 2147483648;
516
- class P {
517
- _privateKey;
518
- _publicKey;
519
- config;
520
- constructor(a, b, d) {
521
- this._privateKey = a, this._publicKey = b, this.config = d;
522
- }
523
- get publicKey() {
524
- if (!this._publicKey)
525
- throw new Error("Public key not available");
526
- return this._publicKey;
527
- }
528
- get privateKey() {
529
- return this._privateKey;
530
- }
531
- sign(a) {
532
- if (!this._privateKey)
533
- throw new Error("Missing private key");
534
- return this.config.algorithm.sign(a, this._privateKey, {
535
- extraEntropy: (0, _.randomBytes)(32)
536
- });
537
- }
538
- verify(a, b) {
539
- return this.config.algorithm.verify(b, a, this._publicKey);
540
- }
541
- }
542
- class m extends P {
543
- chainCode;
544
- _depth;
545
- _index;
546
- _parentFingerprint;
547
- constructor(a, b, d, c, t = 0, n = 0, o = 0) {
548
- super(a, b, c), this.chainCode = d, this._depth = t, this._index = n, this._parentFingerprint = o;
549
- }
550
- get depth() {
551
- return this._depth;
552
- }
553
- get index() {
554
- return this._index;
555
- }
556
- get parentFingerprint() {
557
- return this._parentFingerprint;
558
- }
559
- get identifier() {
560
- return e.hash160(this.publicKey);
561
- }
562
- get fingerprint() {
563
- return this.identifier.slice(0, 4);
564
- }
565
- get securityLevel() {
566
- return this.config.level;
567
- }
568
- get network() {
569
- return this.config.network;
570
- }
571
- isNeutered() {
572
- return this._privateKey === void 0;
573
- }
574
- neutered() {
575
- return new m(void 0, this.publicKey, this.chainCode, this.config, this.depth, this.index, this.parentFingerprint);
576
- }
577
- toBase58() {
578
- const a = this.isNeutered() ? this.config.network.bip32.public : this.config.network.bip32.private, b = !this.isNeutered(), c = 45 + (b ? this.config.privateKeySize : this.config.publicKeySize), t = new Uint8Array(c);
579
- let n = 0;
580
- return w.writeUInt32(t, n, a, "BE"), n += 4, w.writeUInt8(t, n, this.depth), n += 1, w.writeUInt32(t, n, this.parentFingerprint, "BE"), n += 4, w.writeUInt32(t, n, this.index, "BE"), n += 4, t.set(this.chainCode, n), n += 32, b ? t.set(this._privateKey, n) : t.set(this._publicKey, n), q.encode(t);
581
- }
582
- /**
583
- * Derive a child key using BIP32 HMAC chain for seed derivation,
584
- * then ML-DSA for key generation
585
- */
586
- derive(a) {
587
- if (s.parse(r.Uint32Schema, a), this.isNeutered())
588
- throw new TypeError("Cannot derive child keys without private key");
589
- const b = a >= l;
590
- let d;
591
- if (b) {
592
- const v = e.hash256(this._privateKey);
593
- d = new Uint8Array(37), d[0] = 0, d.set(v, 1), w.writeUInt32(d, 33, a, "BE");
594
- } else {
595
- const v = e.hash256(this._privateKey);
596
- d = new Uint8Array(36), d.set(v, 0), w.writeUInt32(d, 32, a, "BE");
597
- }
598
- const c = e.hmacSHA512(this.chainCode, d), t = c.slice(0, 32), n = c.slice(32), { secretKey: o, publicKey: h } = this.config.algorithm.keygen(t);
599
- return new m(o, h, n, this.config, this.depth + 1, a, w.readUInt32(this.fingerprint, 0, "BE"));
600
- }
601
- deriveHardened(a) {
602
- try {
603
- s.parse(r.Uint31Schema, a);
604
- } catch {
605
- throw new TypeError("Expected UInt31, got " + a);
606
- }
607
- return this.derive(a + l);
608
- }
609
- derivePath(a) {
610
- s.parse(r.Bip32PathSchema, a);
611
- let b = a.split("/");
612
- if (b[0] === "m") {
613
- if (this.parentFingerprint)
614
- throw new TypeError("Expected master, got child");
615
- b = b.slice(1);
616
- }
617
- return b.reduce((d, c) => {
618
- let t;
619
- return c.slice(-1) === "'" ? (t = parseInt(c.slice(0, -1), 10), d.deriveHardened(t)) : (t = parseInt(c, 10), d.derive(t));
620
- }, this);
621
- }
622
- }
623
- function L(y, a, b) {
624
- if (s.parse(s.instance(Uint8Array), y), y.length < 16)
625
- throw new TypeError("Seed should be at least 128 bits");
626
- if (y.length > 64)
627
- throw new TypeError("Seed should be at most 512 bits");
628
- const d = (0, u.getMLDSAConfig)(b || u.MLDSASecurityLevel.LEVEL2, a || p.BITCOIN), c = e.hmacSHA512(w.fromUtf8("Bitcoin seed"), y), t = c.slice(0, 32), n = c.slice(32), { secretKey: o, publicKey: h } = d.algorithm.keygen(t);
629
- return new m(
630
- o,
631
- h,
632
- n,
633
- // Chain code
634
- d,
635
- 0,
636
- // depth
637
- 0,
638
- // index
639
- 0
640
- );
641
- }
642
- function T(y) {
643
- const a = q.decode(y), b = w.readUInt32(a, 0, "BE"), d = (0, u.findNetworkByVersion)(b);
644
- if (!d)
645
- throw new TypeError("Unknown network version");
646
- const { network: c, isPrivate: t } = d, o = a.length - 45;
647
- let h;
648
- if (t)
649
- if (o === 2560)
650
- h = u.MLDSASecurityLevel.LEVEL2;
651
- else if (o === 4032)
652
- h = u.MLDSASecurityLevel.LEVEL3;
653
- else if (o === 4896)
654
- h = u.MLDSASecurityLevel.LEVEL5;
655
- else
656
- throw new TypeError(`Invalid private key size: ${o}`);
657
- else if (o === 1312)
658
- h = u.MLDSASecurityLevel.LEVEL2;
659
- else if (o === 1952)
660
- h = u.MLDSASecurityLevel.LEVEL3;
661
- else if (o === 2592)
662
- h = u.MLDSASecurityLevel.LEVEL5;
663
- else
664
- throw new TypeError(`Invalid public key size: ${o}`);
665
- const v = (0, u.getMLDSAConfig)(h, c), O = t ? 45 + v.privateKeySize : 45 + v.publicKeySize;
666
- if (a.length !== O)
667
- throw new TypeError(`Invalid buffer length: expected ${O}, got ${a.length}`);
668
- let S = 4;
669
- const B = a[S];
670
- S += 1;
671
- const C = w.readUInt32(a, S, "BE");
672
- if (B === 0 && C !== 0)
673
- throw new TypeError("Invalid parent fingerprint");
674
- S += 4;
675
- const x = w.readUInt32(a, S, "BE");
676
- if (B === 0 && x !== 0)
677
- throw new TypeError("Invalid index");
678
- S += 4;
679
- const J = a.slice(S, S + 32);
680
- if (S += 32, t) {
681
- const k = a.slice(S, S + v.privateKeySize), le = v.algorithm.getPublicKey(k);
682
- return new m(k, le, J, v, B, x, C);
683
- } else {
684
- const k = a.slice(S, S + v.publicKeySize);
685
- return new m(void 0, k, J, v, B, x, C);
686
- }
687
- }
688
- function Q(y, a, b, d) {
689
- const c = (0, u.getMLDSAConfig)(d || u.MLDSASecurityLevel.LEVEL2, b || p.BITCOIN);
690
- if (y.length !== c.publicKeySize)
691
- throw new TypeError(`Invalid public key length for ML-DSA-${d}: expected ${c.publicKeySize}, got ${y.length}`);
692
- if (a.length !== F)
693
- throw new TypeError(`Invalid chain code length: expected ${F}, got ${a.length}`);
694
- return new m(void 0, y, a, c, 0, 0, 0);
695
- }
696
- function H(y, a, b, d) {
697
- const c = (0, u.getMLDSAConfig)(d || u.MLDSASecurityLevel.LEVEL2, b || p.BITCOIN);
698
- if (y.length !== c.privateKeySize)
699
- throw new TypeError(`Invalid private key length for ML-DSA-${d}: expected ${c.privateKeySize}, got ${y.length}`);
700
- if (a.length !== F)
701
- throw new TypeError(`Invalid chain code length: expected ${F}, got ${a.length}`);
702
- const t = c.algorithm.getPublicKey(y);
703
- return new m(y, t, a, c, 0, 0, 0);
704
- }
705
- return K.QuantumBIP32Factory = {
706
- fromSeed: L,
707
- fromBase58: T,
708
- fromPublicKey: Q,
709
- fromPrivateKey: H
710
- }, K;
711
- }
712
- var M = {}, ae;
713
- function he() {
714
- if (ae) return M;
715
- ae = 1, Object.defineProperty(M, "__esModule", { value: !0 }), M.QuantumDerivationPath = M.DerivationPath = void 0, M.getQuantumPath = g, M.getBitcoinPath = _;
716
- var i;
717
- (function(e) {
718
- e.BIP44 = "m/44'/0'/0'/0/0", e.BIP49 = "m/49'/0'/0'/0/0", e.BIP84 = "m/84'/0'/0'/0/0", e.BIP86 = "m/86'/0'/0'/0/0", e.BIP360 = "m/360'/0'/0'/0/0";
719
- })(i || (M.DerivationPath = i = {}));
720
- var I;
721
- (function(e) {
722
- e.STANDARD = "m/360'/0'/0'/0/0", e.CHANGE = "m/360'/0'/0'/1/0", e.ACCOUNT_0_ADDRESS_0 = "m/360'/0'/0'/0/0", e.ACCOUNT_0_ADDRESS_1 = "m/360'/0'/0'/0/1", e.ACCOUNT_1_ADDRESS_0 = "m/360'/1'/0'/0/0";
723
- })(I || (M.QuantumDerivationPath = I = {}));
724
- function g(e = 0, w = 0, s = !1) {
725
- return `m/360'/${e}'/${s ? 1 : 0}'/${w}`;
726
- }
727
- function _(e, w = 0, s = 0, r = !1) {
728
- return `m/${e}'/0'/${w}'/${r ? 1 : 0}/${s}`;
729
- }
730
- return M;
731
- }
732
- var ce;
733
- function Ie() {
734
- return ce || (ce = 1, (function(i) {
735
- Object.defineProperty(i, "__esModule", { value: !0 }), i.getBitcoinPath = i.getQuantumPath = i.QuantumDerivationPath = i.DerivationPath = i.getMLDSAConfig = i.DEFAULT_SECURITY_LEVEL = i.MLDSASecurityLevel = i.QuantumBIP32Factory = void 0;
736
- var I = Se();
737
- Object.defineProperty(i, "QuantumBIP32Factory", { enumerable: !0, get: function() {
738
- return I.QuantumBIP32Factory;
739
- } });
740
- var g = be();
741
- Object.defineProperty(i, "MLDSASecurityLevel", { enumerable: !0, get: function() {
742
- return g.MLDSASecurityLevel;
743
- } }), Object.defineProperty(i, "DEFAULT_SECURITY_LEVEL", { enumerable: !0, get: function() {
744
- return g.DEFAULT_SECURITY_LEVEL;
745
- } }), Object.defineProperty(i, "getMLDSAConfig", { enumerable: !0, get: function() {
746
- return g.getMLDSAConfig;
747
- } });
748
- var _ = he();
749
- Object.defineProperty(i, "DerivationPath", { enumerable: !0, get: function() {
750
- return _.DerivationPath;
751
- } }), Object.defineProperty(i, "QuantumDerivationPath", { enumerable: !0, get: function() {
752
- return _.QuantumDerivationPath;
753
- } }), Object.defineProperty(i, "getQuantumPath", { enumerable: !0, get: function() {
754
- return _.getQuantumPath;
755
- } }), Object.defineProperty(i, "getBitcoinPath", { enumerable: !0, get: function() {
756
- return _.getBitcoinPath;
757
- } });
758
- })(Y)), Y;
759
- }
760
- var ue;
761
- function Le() {
762
- return ue || (ue = 1, (function(i) {
763
- Object.defineProperty(i, "__esModule", { value: !0 }), i.getBitcoinPath = i.getQuantumPath = i.QuantumDerivationPath = i.DerivationPath = i.getMLDSAConfig = i.DEFAULT_SECURITY_LEVEL = i.MLDSASecurityLevel = i.QuantumBIP32Factory = i.REGTEST = i.TESTNET = i.BITCOIN = i.BIP32Factory = i.default = void 0;
764
- var I = me();
765
- Object.defineProperty(i, "default", { enumerable: !0, get: function() {
766
- return I.BIP32Factory;
767
- } }), Object.defineProperty(i, "BIP32Factory", { enumerable: !0, get: function() {
768
- return I.BIP32Factory;
769
- } });
770
- var g = z();
771
- Object.defineProperty(i, "BITCOIN", { enumerable: !0, get: function() {
772
- return g.BITCOIN;
773
- } }), Object.defineProperty(i, "TESTNET", { enumerable: !0, get: function() {
774
- return g.TESTNET;
775
- } }), Object.defineProperty(i, "REGTEST", { enumerable: !0, get: function() {
776
- return g.REGTEST;
777
- } });
778
- var _ = Ie();
779
- Object.defineProperty(i, "QuantumBIP32Factory", { enumerable: !0, get: function() {
780
- return _.QuantumBIP32Factory;
781
- } }), Object.defineProperty(i, "MLDSASecurityLevel", { enumerable: !0, get: function() {
782
- return _.MLDSASecurityLevel;
783
- } }), Object.defineProperty(i, "DEFAULT_SECURITY_LEVEL", { enumerable: !0, get: function() {
784
- return _.DEFAULT_SECURITY_LEVEL;
785
- } }), Object.defineProperty(i, "getMLDSAConfig", { enumerable: !0, get: function() {
786
- return _.getMLDSAConfig;
787
- } });
788
- var e = he();
789
- Object.defineProperty(i, "DerivationPath", { enumerable: !0, get: function() {
790
- return e.DerivationPath;
791
- } }), Object.defineProperty(i, "QuantumDerivationPath", { enumerable: !0, get: function() {
792
- return e.QuantumDerivationPath;
793
- } }), Object.defineProperty(i, "getQuantumPath", { enumerable: !0, get: function() {
794
- return e.getQuantumPath;
795
- } }), Object.defineProperty(i, "getBitcoinPath", { enumerable: !0, get: function() {
796
- return e.getBitcoinPath;
797
- } });
798
- })(G)), G;
799
- }
800
- var Te = Le();
801
- const Ue = /* @__PURE__ */ pe(Te);
802
- export {
803
- Ue as b,
804
- Te as c
805
- };