@btc-vision/bitcoin 6.5.1 → 6.5.3

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 (103) hide show
  1. package/browser/chunks/crypto-0PweVewC.js +2033 -0
  2. package/browser/chunks/{payments-BE4vwHhV.js → payments-CgasufRS.js} +410 -408
  3. package/browser/chunks/psbt-BIwOrKer.js +4096 -0
  4. package/browser/chunks/{script-COWGdiOo.js → script-CROJPzz_.js} +96 -96
  5. package/browser/chunks/{transaction-BiXwH2v4.js → transaction-DchBu35N.js} +158 -147
  6. package/browser/chunks/{utils-BKmkTzNZ.js → utils-CO5kmxe9.js} +225 -223
  7. package/browser/crypto.d.ts +1 -1
  8. package/browser/hooks/HookedSigner.d.ts +1 -1
  9. package/browser/index.d.ts +23 -1
  10. package/browser/index.js +6 -6
  11. package/browser/payments/index.d.ts +2 -2
  12. package/browser/payments/lazy.d.ts +1 -1
  13. package/browser/psbt/bip371.d.ts +5 -1
  14. package/browser/psbt.d.ts +1 -1
  15. package/browser/typeforce.d.ts +38 -0
  16. package/browser/types.d.ts +22 -20
  17. package/build/address.js +2 -2
  18. package/build/bip66.js +2 -2
  19. package/build/block.js +2 -2
  20. package/build/crypto.d.ts +1 -1
  21. package/build/crypto.js +2 -3
  22. package/build/hooks/HookedSigner.d.ts +1 -1
  23. package/build/index.d.ts +23 -1
  24. package/build/payments/bip341.js +1 -1
  25. package/build/payments/index.d.ts +2 -2
  26. package/build/payments/lazy.d.ts +1 -1
  27. package/build/payments/p2op.js +3 -3
  28. package/build/payments/p2pk.js +1 -1
  29. package/build/payments/p2pkh.js +3 -3
  30. package/build/payments/p2sh.js +3 -3
  31. package/build/payments/p2tr.js +9 -5
  32. package/build/payments/p2wpkh.js +3 -3
  33. package/build/payments/p2wsh.js +2 -2
  34. package/build/psbt/bip371.d.ts +5 -1
  35. package/build/psbt/bip371.js +10 -7
  36. package/build/psbt/psbtutils.js +5 -4
  37. package/build/psbt.d.ts +1 -1
  38. package/build/psbt.js +78 -45
  39. package/build/script.js +2 -2
  40. package/build/script_signature.js +7 -7
  41. package/build/transaction.js +22 -10
  42. package/build/tsconfig.tsbuildinfo +1 -0
  43. package/build/types.d.ts +22 -20
  44. package/build/types.js +10 -9
  45. package/package.json +32 -57
  46. package/src/address.ts +2 -2
  47. package/src/bip66.ts +2 -2
  48. package/src/block.ts +8 -5
  49. package/src/crypto.ts +3 -4
  50. package/src/ecc_lib.ts +1 -1
  51. package/src/hooks/HookedSigner.ts +1 -1
  52. package/src/index.ts +34 -12
  53. package/src/payments/bip341.ts +1 -1
  54. package/src/payments/embed.ts +1 -2
  55. package/src/payments/index.ts +4 -4
  56. package/src/payments/lazy.ts +3 -3
  57. package/src/payments/p2op.ts +4 -3
  58. package/src/payments/p2pk.ts +1 -1
  59. package/src/payments/p2pkh.ts +3 -3
  60. package/src/payments/p2sh.ts +13 -5
  61. package/src/payments/p2tr.ts +8 -9
  62. package/src/payments/p2wpkh.ts +3 -3
  63. package/src/payments/p2wsh.ts +4 -4
  64. package/src/psbt/bip371.ts +22 -13
  65. package/src/psbt/psbtutils.ts +8 -5
  66. package/src/psbt.ts +127 -80
  67. package/src/script.ts +4 -4
  68. package/src/script_signature.ts +7 -7
  69. package/src/transaction.ts +31 -18
  70. package/src/typeforce.d.ts +38 -0
  71. package/src/types.ts +34 -29
  72. package/test/address.spec.ts +12 -4
  73. package/test/bitcoin.core.spec.ts +1 -1
  74. package/test/block.spec.ts +1 -1
  75. package/test/bufferutils.spec.ts +1 -1
  76. package/test/crypto.spec.ts +3 -2
  77. package/test/fixtures/address.json +1 -1
  78. package/test/integration/addresses.spec.ts +1 -1
  79. package/test/integration/bip32.spec.ts +2 -2
  80. package/test/integration/blocks.spec.ts +1 -1
  81. package/test/integration/cltv.spec.ts +3 -3
  82. package/test/integration/csv.spec.ts +3 -3
  83. package/test/integration/payments.spec.ts +1 -1
  84. package/test/integration/taproot.spec.ts +8 -7
  85. package/test/integration/transactions.spec.ts +2 -2
  86. package/test/payments.spec.ts +4 -3
  87. package/test/psbt.spec.ts +106 -74
  88. package/test/script.spec.ts +73 -7
  89. package/test/script_number.spec.ts +1 -1
  90. package/test/script_signature.spec.ts +1 -1
  91. package/test/transaction.spec.ts +1 -1
  92. package/test/tsconfig.json +1 -1
  93. package/test/types.spec.ts +1 -1
  94. package/vitest.config.ts +16 -0
  95. package/.babelrc +0 -13
  96. package/.mocharc.json +0 -13
  97. package/browser/chunks/crypto-C6FlKKmp.js +0 -2006
  98. package/browser/chunks/psbt-Dlosf9CT.js +0 -3853
  99. package/cjs/package.json +0 -3
  100. package/gulpfile.js +0 -42
  101. package/src/crypto/crypto-browser.js +0 -75
  102. package/test/ts-node-register.js +0 -7
  103. package/webpack.config.js +0 -79
@@ -1,116 +1,115 @@
1
- import { t as C, f as g, B as c, h as E, b as M } from "./crypto-C6FlKKmp.js";
2
- import { g as ne, b as P, i as x, d as b, f as se, a as G } from "./psbt-Dlosf9CT.js";
3
- import { b as me, g as ce, h as ae, t, s as N, j as T, i as we, T as W } from "./utils-BKmkTzNZ.js";
4
- import { d as a, o as v, c as l, i as S, e as ie, f as ue, g as le } from "./script-COWGdiOo.js";
5
- const F = 192, ye = 128, be = (e) => "left" in e && "right" in e;
6
- function K(e, o) {
1
+ import { t as F, e as g, B as m, h as E, a as G } from "./crypto-0PweVewC.js";
2
+ import { g as K, b as P, i as x, d as b, f as se, a as X } from "./psbt-BIwOrKer.js";
3
+ import { b as ae, g as me, h as we, t as r, s as N, j as T, i as ce, T as W } from "./utils-CO5kmxe9.js";
4
+ import { d as w, o as v, c as y, i as S, e as ue, f as ie, g as ye } from "./script-CROJPzz_.js";
5
+ const M = 192, le = 128, be = (e) => "left" in e && "right" in e;
6
+ function L(e, o) {
7
7
  if (e.length < 33)
8
8
  throw new TypeError(
9
9
  `The control-block length is too small. Got ${e.length}, expected min 33.`
10
10
  );
11
11
  const p = (e.length - 33) / 32;
12
- let u = o;
12
+ let i = o;
13
13
  for (let s = 0; s < p; s++) {
14
- const i = e.slice(33 + 32 * s, 65 + 32 * s);
15
- u.compare(i) < 0 ? u = L(u, i) : u = L(i, u);
14
+ const u = e.subarray(33 + 32 * s, 65 + 32 * s);
15
+ i.compare(u) < 0 ? i = C(i, u) : i = C(u, i);
16
16
  }
17
- return u;
17
+ return i;
18
18
  }
19
19
  function A(e) {
20
- if (me(e)) return { hash: H(e) };
20
+ if (ae(e)) return { hash: H(e) };
21
21
  const o = [A(e[0]), A(e[1])];
22
- o.sort((s, i) => s.hash.compare(i.hash));
23
- const [p, u] = o;
22
+ o.sort((s, u) => s.hash.compare(u.hash));
23
+ const [p, i] = o;
24
24
  return {
25
- hash: L(p.hash, u.hash),
25
+ hash: C(p.hash, i.hash),
26
26
  left: p,
27
- right: u
27
+ right: i
28
28
  };
29
29
  }
30
30
  function q(e, o) {
31
31
  if (be(e)) {
32
32
  const p = q(e.left, o);
33
33
  if (p !== void 0) return [...p, e.right.hash];
34
- const u = q(e.right, o);
35
- if (u !== void 0) return [...u, e.left.hash];
34
+ const i = q(e.right, o);
35
+ if (i !== void 0) return [...i, e.left.hash];
36
36
  } else if (e.hash.equals(o))
37
37
  return [];
38
38
  }
39
39
  function H(e) {
40
- const o = e.version || F;
41
- return C(
40
+ const o = e.version || M;
41
+ return F(
42
42
  "TapLeaf",
43
43
  g.concat([g.from([o]), ge(e.output)])
44
44
  );
45
45
  }
46
46
  function oe(e, o) {
47
- return C("TapTweak", g.concat(o ? [e, o] : [e]));
47
+ return F("TapTweak", g.concat(o ? [e, o] : [e]));
48
48
  }
49
49
  function j(e, o) {
50
50
  if (!g.isBuffer(e) || e.length !== 32 || o && o.length !== 32) return null;
51
- const p = oe(e, o), u = ne().xOnlyPointAddTweak(e, p);
52
- return !u || u.xOnlyPubkey === null ? null : {
53
- parity: u.parity,
54
- x: g.from(u.xOnlyPubkey)
51
+ const p = oe(e, o), i = K().xOnlyPointAddTweak(e, p);
52
+ return !i || i.xOnlyPubkey === null ? null : {
53
+ parity: i.parity,
54
+ x: g.from(i.xOnlyPubkey)
55
55
  };
56
56
  }
57
- function L(e, o) {
58
- return C("TapBranch", g.concat([e, o]));
57
+ function C(e, o) {
58
+ return F("TapBranch", g.concat([e, o]));
59
59
  }
60
60
  function ge(e) {
61
- const o = ce(e.length), p = g.allocUnsafe(o);
62
- return ae(e.length, p), g.concat([p, e]);
61
+ const o = me(e.length), p = g.allocUnsafe(o);
62
+ return we(e.length, p), g.concat([p, e]);
63
63
  }
64
64
  function h(e, o, p) {
65
65
  Object.defineProperty(e, o, {
66
66
  configurable: !0,
67
67
  enumerable: !0,
68
68
  get() {
69
- const u = p.call(this);
70
- return this[o] = u, u;
69
+ const i = p.call(this);
70
+ return this[o] = i, i;
71
71
  },
72
- set(u) {
72
+ set(i) {
73
73
  Object.defineProperty(this, o, {
74
74
  configurable: !0,
75
75
  enumerable: !0,
76
- value: u,
76
+ value: i,
77
77
  writable: !0
78
78
  });
79
79
  }
80
80
  });
81
81
  }
82
- function y(e) {
82
+ function l(e) {
83
83
  let o;
84
84
  return () => (o !== void 0 || (o = e()), o);
85
85
  }
86
86
  const D = v;
87
87
  function ke(e, o) {
88
88
  if (!e.data && !e.output) throw new TypeError("Not enough data");
89
- o = Object.assign({ validate: !0 }, o || {}), t(
89
+ o = Object.assign({ validate: !0 }, o || {}), r(
90
90
  {
91
- network: t.maybe(t.Object),
92
- output: t.maybe(t.Buffer),
93
- data: t.maybe(t.arrayOf(t.Buffer))
91
+ network: r.maybe(r.Object),
92
+ output: r.maybe(r.Buffer),
93
+ data: r.maybe(r.arrayOf(r.Buffer))
94
94
  },
95
95
  e
96
96
  );
97
- const p = e.network || P, u = { name: k.Embed, network: p, data: [] };
98
- if (h(u, "output", () => {
97
+ const p = e.network || P, i = { name: k.Embed, network: p, data: [] };
98
+ if (h(i, "output", () => {
99
99
  if (e.data)
100
- return l([D.OP_RETURN].concat(e.data));
101
- }), h(u, "data", () => {
100
+ return y([D.OP_RETURN].concat(e.data));
101
+ }), h(i, "data", () => {
102
102
  if (!e.output) return;
103
- const s = a(e.output);
103
+ const s = w(e.output);
104
104
  if (s != null)
105
105
  return s.slice(1);
106
106
  }), o.validate && e.output) {
107
- const s = a(e.output);
107
+ const s = w(e.output);
108
108
  if (s[0] !== D.OP_RETURN) throw new TypeError("Output is invalid");
109
- if (!s.slice(1).every(t.Buffer)) throw new TypeError("Output is invalid");
110
- if (e.data && !N(e.data, u.data))
111
- throw new TypeError("Data mismatch");
109
+ if (!s.slice(1).every(r.Buffer)) throw new TypeError("Output is invalid");
110
+ if (e.data && !N(e.data, i.data)) throw new TypeError("Data mismatch");
112
111
  }
113
- return Object.assign(u, e);
112
+ return Object.assign(i, e);
114
113
  }
115
114
  const I = v, V = I.OP_RESERVED;
116
115
  function Ee(e, o) {
@@ -120,15 +119,15 @@ function Ee(e, o) {
120
119
  function p(f) {
121
120
  return S(f) || (o.allowIncomplete && f === I.OP_0) !== void 0;
122
121
  }
123
- t(
122
+ r(
124
123
  {
125
- network: t.maybe(t.Object),
126
- m: t.maybe(t.Number),
127
- n: t.maybe(t.Number),
128
- output: t.maybe(t.Buffer),
129
- pubkeys: t.maybe(t.arrayOf(T)),
130
- signatures: t.maybe(t.arrayOf(p)),
131
- input: t.maybe(t.Buffer)
124
+ network: r.maybe(r.Object),
125
+ m: r.maybe(r.Number),
126
+ n: r.maybe(r.Number),
127
+ output: r.maybe(r.Buffer),
128
+ pubkeys: r.maybe(r.arrayOf(T)),
129
+ signatures: r.maybe(r.arrayOf(p)),
130
+ input: r.maybe(r.Buffer)
132
131
  },
133
132
  e
134
133
  );
@@ -136,13 +135,13 @@ function Ee(e, o) {
136
135
  network: e.network || P,
137
136
  name: k.P2MS
138
137
  };
139
- let i = [], n = !1;
140
- function r(f) {
141
- n || (n = !0, i = a(f), s.m = i[0] - V, s.n = i[i.length - 2] - V, s.pubkeys = i.slice(1, -2));
138
+ let u = [], n = !1;
139
+ function t(f) {
140
+ n || (n = !0, u = w(f), s.m = u[0] - V, s.n = u[u.length - 2] - V, s.pubkeys = u.slice(1, -2));
142
141
  }
143
142
  if (h(s, "output", () => {
144
143
  if (e.m && s.n && e.pubkeys)
145
- return l(
144
+ return y(
146
145
  [].concat(
147
146
  V + e.m,
148
147
  e.pubkeys,
@@ -152,21 +151,21 @@ function Ee(e, o) {
152
151
  );
153
152
  }), h(s, "m", () => {
154
153
  if (s.output)
155
- return r(s.output), s.m;
154
+ return t(s.output), s.m;
156
155
  }), h(s, "n", () => {
157
156
  if (s.pubkeys)
158
157
  return s.pubkeys.length;
159
158
  }), h(s, "pubkeys", () => {
160
159
  if (e.output)
161
- return r(e.output), s.pubkeys;
160
+ return t(e.output), s.pubkeys;
162
161
  }), h(s, "signatures", () => {
163
162
  if (!e.input) return;
164
- const f = a(e.input);
163
+ const f = w(e.input);
165
164
  if (f != null)
166
165
  return f.slice(1);
167
166
  }), h(s, "input", () => {
168
167
  if (e.signatures)
169
- return l([I.OP_0].concat(e.signatures));
168
+ return y([I.OP_0].concat(e.signatures));
170
169
  }), h(s, "witness", () => {
171
170
  if (s.input)
172
171
  return [];
@@ -175,11 +174,11 @@ function Ee(e, o) {
175
174
  return `p2ms(${s.m} of ${s.n})`;
176
175
  }), o.validate) {
177
176
  if (e.output) {
178
- if (r(e.output), !t.Number(i[0])) throw new TypeError("Output is invalid");
179
- if (!t.Number(i[i.length - 2])) throw new TypeError("Output is invalid");
180
- if (i[i.length - 1] !== I.OP_CHECKMULTISIG)
177
+ if (t(e.output), !r.Number(u[0])) throw new TypeError("Output is invalid");
178
+ if (!r.Number(u[u.length - 2])) throw new TypeError("Output is invalid");
179
+ if (u[u.length - 1] !== I.OP_CHECKMULTISIG)
181
180
  throw new TypeError("Output is invalid");
182
- if (s.m <= 0 || s.n > 16 || s.m > s.n || s.n !== i.length - 3)
181
+ if (s.m <= 0 || s.n > 16 || s.m > s.n || s.n !== u.length - 3)
183
182
  throw new TypeError("Output is invalid");
184
183
  if (!s.pubkeys.every((f) => T(f))) throw new TypeError("Output is invalid");
185
184
  if (e.m !== void 0 && e.m !== s.m) throw new TypeError("m mismatch");
@@ -208,43 +207,43 @@ function Ee(e, o) {
208
207
  }
209
208
  return Object.assign(s, e);
210
209
  }
211
- const X = v;
210
+ const Q = v;
212
211
  function Te(e, o) {
213
212
  if (!e.input && !e.output && !e.pubkey && !e.input && !e.signature)
214
213
  throw new TypeError("Not enough data");
215
- o = Object.assign({ validate: !0 }, o || {}), t(
214
+ o = Object.assign({ validate: !0 }, o || {}), r(
216
215
  {
217
- network: t.maybe(t.Object),
218
- output: t.maybe(t.Buffer),
219
- pubkey: t.maybe(T),
220
- signature: t.maybe(S),
221
- input: t.maybe(t.Buffer)
216
+ network: r.maybe(r.Object),
217
+ output: r.maybe(r.Buffer),
218
+ pubkey: r.maybe(T),
219
+ signature: r.maybe(S),
220
+ input: r.maybe(r.Buffer)
222
221
  },
223
222
  e
224
223
  );
225
- const p = y(() => a(e.input)), u = e.network || P, s = {
224
+ const p = l(() => w(e.input)), i = e.network || P, s = {
226
225
  name: k.P2PK,
227
- network: u,
226
+ network: i,
228
227
  pubkey: void 0
229
228
  };
230
229
  if (h(s, "output", () => {
231
230
  if (e.pubkey)
232
- return l([e.pubkey, X.OP_CHECKSIG]);
231
+ return y([e.pubkey, Q.OP_CHECKSIG]);
233
232
  }), h(s, "pubkey", () => {
234
233
  if (e.output)
235
- return e.output.slice(1, -1);
234
+ return e.output.subarray(1, -1);
236
235
  }), h(s, "signature", () => {
237
236
  if (e.input)
238
237
  return p()[0];
239
238
  }), h(s, "input", () => {
240
239
  if (e.signature)
241
- return l([e.signature]);
240
+ return y([e.signature]);
242
241
  }), h(s, "witness", () => {
243
242
  if (s.input)
244
243
  return [];
245
244
  }), o.validate) {
246
245
  if (e.output) {
247
- if (e.output[e.output.length - 1] !== X.OP_CHECKSIG)
246
+ if (e.output[e.output.length - 1] !== Q.OP_CHECKSIG)
248
247
  throw new TypeError("Output is invalid");
249
248
  if (!T(s.pubkey)) throw new TypeError("Output pubkey is invalid");
250
249
  if (e.pubkey && !e.pubkey.equals(s.pubkey)) throw new TypeError("Pubkey mismatch");
@@ -263,114 +262,114 @@ const B = v;
263
262
  function Pe(e, o) {
264
263
  if (!e.address && !e.hash && !e.output && !e.redeem && !e.input)
265
264
  throw new TypeError("Not enough data");
266
- o = Object.assign({ validate: !0 }, o || {}), t(
265
+ o = Object.assign({ validate: !0 }, o || {}), r(
267
266
  {
268
- network: t.maybe(t.Object),
269
- address: t.maybe(t.String),
270
- hash: t.maybe(t.BufferN(20)),
271
- output: t.maybe(t.BufferN(23)),
272
- redeem: t.maybe({
273
- network: t.maybe(t.Object),
274
- output: t.maybe(t.Buffer),
275
- input: t.maybe(t.Buffer),
276
- witness: t.maybe(t.arrayOf(t.Buffer))
267
+ network: r.maybe(r.Object),
268
+ address: r.maybe(r.String),
269
+ hash: r.maybe(r.BufferN(20)),
270
+ output: r.maybe(r.BufferN(23)),
271
+ redeem: r.maybe({
272
+ network: r.maybe(r.Object),
273
+ output: r.maybe(r.Buffer),
274
+ input: r.maybe(r.Buffer),
275
+ witness: r.maybe(r.arrayOf(r.Buffer))
277
276
  }),
278
- input: t.maybe(t.Buffer),
279
- witness: t.maybe(t.arrayOf(t.Buffer))
277
+ input: r.maybe(r.Buffer),
278
+ witness: r.maybe(r.arrayOf(r.Buffer))
280
279
  },
281
280
  e
282
281
  );
283
282
  let p = e.network;
284
283
  p || (p = e.redeem && e.redeem.network || P);
285
- const u = {
284
+ const i = {
286
285
  network: p,
287
286
  name: k.P2SH
288
- }, s = y(() => {
289
- const r = c.from(x.decode(e.address)), f = r.readUInt8(0), d = r.slice(1);
287
+ }, s = l(() => {
288
+ const t = m.from(x.decode(e.address)), f = t.readUInt8(0), d = t.subarray(1);
290
289
  return { version: f, hash: d };
291
- }), i = y(() => a(e.input)), n = y(() => {
292
- const r = i(), f = r[r.length - 1];
290
+ }), u = l(() => w(e.input)), n = l(() => {
291
+ const t = u(), f = t[t.length - 1];
293
292
  return {
294
293
  network: p,
295
- output: f === B.OP_FALSE ? c.from([]) : f,
296
- input: l(r.slice(0, -1)),
294
+ output: f === B.OP_FALSE ? m.from([]) : f,
295
+ input: y(t.slice(0, -1)),
297
296
  witness: e.witness || []
298
297
  };
299
298
  });
300
- if (h(u, "address", () => {
301
- if (!u.hash) return;
302
- const r = c.allocUnsafe(21);
303
- return r.writeUInt8(u.network.scriptHash, 0), u.hash.copy(r, 1), x.encode(r);
304
- }), h(u, "hash", () => {
305
- if (e.output) return e.output.slice(2, 22);
299
+ if (h(i, "address", () => {
300
+ if (!i.hash) return;
301
+ const t = m.allocUnsafe(21);
302
+ return t.writeUInt8(i.network.scriptHash, 0), i.hash.copy(t, 1), x.encode(t);
303
+ }), h(i, "hash", () => {
304
+ if (e.output) return e.output.subarray(2, 22);
306
305
  if (e.address) return s().hash;
307
- if (u.redeem && u.redeem.output) return E(u.redeem.output);
308
- }), h(u, "output", () => {
309
- if (u.hash)
310
- return l([B.OP_HASH160, u.hash, B.OP_EQUAL]);
311
- }), h(u, "redeem", () => {
306
+ if (i.redeem && i.redeem.output) return E(i.redeem.output);
307
+ }), h(i, "output", () => {
308
+ if (i.hash)
309
+ return y([B.OP_HASH160, i.hash, B.OP_EQUAL]);
310
+ }), h(i, "redeem", () => {
312
311
  if (e.input)
313
312
  return n();
314
- }), h(u, "input", () => {
313
+ }), h(i, "input", () => {
315
314
  if (!(!e.redeem || !e.redeem.input || !e.redeem.output))
316
- return l(
317
- [].concat(a(e.redeem.input), e.redeem.output)
315
+ return y(
316
+ [].concat(w(e.redeem.input), e.redeem.output)
318
317
  );
319
- }), h(u, "witness", () => {
320
- if (u.redeem && u.redeem.witness) return u.redeem.witness;
321
- if (u.input) return [];
322
- }), h(u, "name", () => {
323
- const r = ["p2sh"];
324
- return u.redeem !== void 0 && u.redeem.name !== void 0 && r.push(u.redeem.name), r.join("-");
318
+ }), h(i, "witness", () => {
319
+ if (i.redeem && i.redeem.witness) return i.redeem.witness;
320
+ if (i.input) return [];
321
+ }), h(i, "name", () => {
322
+ const t = ["p2sh"];
323
+ return i.redeem !== void 0 && i.redeem.name !== void 0 && t.push(i.redeem.name), t.join("-");
325
324
  }), o.validate) {
326
- let r = c.from([]);
325
+ let t = m.from([]);
327
326
  if (e.address) {
328
327
  if (s().version !== p.scriptHash)
329
328
  throw new TypeError("Invalid version or Network mismatch");
330
329
  if (s().hash.length !== 20) throw new TypeError("Invalid address");
331
- r = s().hash;
330
+ t = s().hash;
332
331
  }
333
332
  if (e.hash) {
334
- if (r.length > 0 && !r.equals(e.hash)) throw new TypeError("Hash mismatch");
335
- r = e.hash;
333
+ if (t.length > 0 && !t.equals(e.hash)) throw new TypeError("Hash mismatch");
334
+ t = e.hash;
336
335
  }
337
336
  if (e.output) {
338
337
  if (e.output.length !== 23 || e.output[0] !== B.OP_HASH160 || e.output[1] !== 20 || e.output[22] !== B.OP_EQUAL)
339
338
  throw new TypeError("Output is invalid");
340
- const d = e.output.slice(2, 22);
341
- if (r.length > 0 && !r.equals(d)) throw new TypeError("Hash mismatch");
342
- r = d;
339
+ const d = e.output.subarray(2, 22);
340
+ if (t.length > 0 && !t.equals(d)) throw new TypeError("Hash mismatch");
341
+ t = d;
343
342
  }
344
343
  const f = (d) => {
345
344
  if (d.output) {
346
- const m = a(d.output);
347
- if (!m || m.length < 1)
345
+ const a = w(d.output);
346
+ if (!a || a.length < 1)
348
347
  throw new TypeError("Redeem.output too short");
349
348
  if (d.output.byteLength > 520)
350
349
  throw new TypeError("Redeem.output unspendable if larger than 520 bytes");
351
- if (ie(m) > 201)
350
+ if (ue(a) > 201)
352
351
  throw new TypeError(
353
352
  "Redeem.output unspendable with more than 201 non-push ops"
354
353
  );
355
- const w = E(d.output);
356
- if (r.length > 0 && !r.equals(w)) throw new TypeError("Hash mismatch");
357
- r = w;
354
+ const c = E(d.output);
355
+ if (t.length > 0 && !t.equals(c)) throw new TypeError("Hash mismatch");
356
+ t = c;
358
357
  }
359
358
  if (d.input) {
360
- const m = d.input.length > 0, w = d.witness && d.witness.length > 0;
361
- if (!m && !w) throw new TypeError("Empty input");
362
- if (m && w) throw new TypeError("Input and witness provided");
363
- if (m) {
364
- const _ = a(d.input);
365
- if (!ue(_))
359
+ const a = d.input.length > 0, c = d.witness && d.witness.length > 0;
360
+ if (!a && !c) throw new TypeError("Empty input");
361
+ if (a && c) throw new TypeError("Input and witness provided");
362
+ if (a) {
363
+ const _ = w(d.input);
364
+ if (!ie(_))
366
365
  throw new TypeError("Non push-only scriptSig");
367
366
  }
368
367
  }
369
368
  };
370
369
  if (e.input) {
371
- const d = i();
370
+ const d = u();
372
371
  if (!d || d.length < 1) throw new TypeError("Input too short");
373
- if (!c.isBuffer(n().output)) throw new TypeError("Input is invalid");
372
+ if (!m.isBuffer(n().output)) throw new TypeError("Input is invalid");
374
373
  f(n());
375
374
  }
376
375
  if (e.redeem) {
@@ -388,154 +387,156 @@ function Pe(e, o) {
388
387
  if (e.witness && e.redeem && e.redeem.witness && !N(e.redeem.witness, e.witness))
389
388
  throw new TypeError("Witness and redeem.witness mismatch");
390
389
  }
391
- return Object.assign(u, e);
390
+ return Object.assign(i, e);
392
391
  }
393
- const Q = v, Y = 1, ve = 80;
392
+ const Y = v, z = 1, ve = 80;
394
393
  function Oe(e, o) {
395
394
  if (!e.address && !e.output && !e.pubkey && !e.internalPubkey && !(e.witness && e.witness.length > 1))
396
395
  throw new TypeError("Not enough data");
397
- o = Object.assign({ validate: !0 }, o || {}), t(
396
+ o = Object.assign({ validate: !0 }, o || {}), r(
398
397
  {
399
- address: t.maybe(t.String),
400
- input: t.maybe(t.BufferN(0)),
401
- network: t.maybe(t.Object),
402
- output: t.maybe(t.BufferN(34)),
403
- internalPubkey: t.maybe(t.BufferN(32)),
404
- hash: t.maybe(t.BufferN(32)),
398
+ address: r.maybe(r.String),
399
+ input: r.maybe(r.BufferN(0)),
400
+ network: r.maybe(r.Object),
401
+ output: r.maybe(r.BufferN(34)),
402
+ internalPubkey: r.maybe(r.BufferN(32)),
403
+ hash: r.maybe(r.BufferN(32)),
405
404
  // merkle root hash, the tweak
406
- pubkey: t.maybe(t.BufferN(32)),
405
+ pubkey: r.maybe(r.BufferN(32)),
407
406
  // tweaked with `hash` from `internalPubkey`
408
- signature: t.maybe(t.anyOf(t.BufferN(64), t.BufferN(65))),
409
- witness: t.maybe(t.arrayOf(t.Buffer)),
410
- scriptTree: t.maybe(we),
411
- redeem: t.maybe({
412
- output: t.maybe(t.Buffer),
407
+ signature: r.maybe(r.anyOf(r.BufferN(64), r.BufferN(65))),
408
+ witness: r.maybe(r.arrayOf(r.Buffer)),
409
+ scriptTree: r.maybe(ce),
410
+ redeem: r.maybe({
411
+ output: r.maybe(r.Buffer),
413
412
  // tapleaf script
414
- redeemVersion: t.maybe(t.Number),
413
+ redeemVersion: r.maybe(r.Number),
415
414
  // tapleaf version
416
- witness: t.maybe(t.arrayOf(t.Buffer))
415
+ witness: r.maybe(r.arrayOf(r.Buffer))
417
416
  }),
418
- redeemVersion: t.maybe(t.Number)
417
+ redeemVersion: r.maybe(r.Number)
419
418
  },
420
419
  e
421
420
  );
422
- const p = y(() => se(e.address)), u = y(() => {
421
+ const p = l(() => se(e.address)), i = l(() => {
423
422
  if (!(!e.witness || !e.witness.length))
424
423
  return e.witness.length >= 2 && e.witness[e.witness.length - 1][0] === ve ? e.witness.slice(0, -1) : e.witness.slice();
425
- }), s = y(() => {
424
+ }), s = l(() => {
426
425
  if (e.scriptTree) return A(e.scriptTree);
427
426
  if (e.hash) return { hash: e.hash };
428
- }), i = e.network || P, n = {
427
+ }), u = e.network || P, n = {
429
428
  name: k.P2TR,
430
- network: i
429
+ network: u
431
430
  };
432
431
  if (h(n, "address", () => {
433
432
  if (!n.pubkey) return;
434
- const r = b.bech32m.toWords(n.pubkey);
435
- return r.unshift(Y), b.bech32m.encode(i.bech32, r);
433
+ const t = b.bech32m.toWords(n.pubkey);
434
+ return t.unshift(z), b.bech32m.encode(u.bech32, t);
436
435
  }), h(n, "hash", () => {
437
- const r = s();
438
- if (r) return r.hash;
439
- const f = u();
436
+ const t = s();
437
+ if (t) return t.hash;
438
+ const f = i();
440
439
  if (f && f.length > 1) {
441
- const d = f[f.length - 1], m = d[0] & W, w = f[f.length - 2], _ = H({
442
- output: w,
443
- version: m
440
+ const d = f[f.length - 1], a = d[0] & W, c = f[f.length - 2], _ = H({
441
+ output: c,
442
+ version: a
444
443
  });
445
- return K(d, _);
444
+ return L(d, _);
446
445
  }
447
446
  }), h(n, "output", () => {
448
447
  if (n.pubkey)
449
- return l([Q.OP_1, n.pubkey]);
450
- }), h(n, "redeemVersion", () => e.redeemVersion ? e.redeemVersion : e.redeem && e.redeem.redeemVersion !== void 0 && e.redeem.redeemVersion !== null ? e.redeem.redeemVersion : F), h(n, "redeem", () => {
451
- const r = u();
452
- if (!(!r || r.length < 2))
448
+ return y([Y.OP_1, n.pubkey]);
449
+ }), h(n, "redeemVersion", () => e.redeemVersion ? e.redeemVersion : e.redeem && e.redeem.redeemVersion !== void 0 && e.redeem.redeemVersion !== null ? e.redeem.redeemVersion : M), h(n, "redeem", () => {
450
+ const t = i();
451
+ if (!(!t || t.length < 2))
453
452
  return {
454
- output: r[r.length - 2],
455
- witness: r.slice(0, -2),
456
- redeemVersion: r[r.length - 1][0] & W
453
+ output: t[t.length - 2],
454
+ witness: t.slice(0, -2),
455
+ redeemVersion: t[t.length - 1][0] & W
457
456
  };
458
457
  }), h(n, "pubkey", () => {
459
458
  if (e.pubkey) return e.pubkey;
460
- if (e.output) return e.output.slice(2);
459
+ if (e.output) return e.output.subarray(2);
461
460
  if (e.address) return p().data;
462
461
  if (n.internalPubkey) {
463
- const r = j(n.internalPubkey, n.hash);
464
- if (r) return r.x;
462
+ const t = j(n.internalPubkey, n.hash);
463
+ if (t) return t.x;
465
464
  }
466
465
  }), h(n, "internalPubkey", () => {
467
466
  if (e.internalPubkey) return e.internalPubkey;
468
- const r = u();
469
- if (r && r.length > 1) return r[r.length - 1].slice(1, 33);
467
+ const t = i();
468
+ if (t && t.length > 1) return t[t.length - 1].subarray(1, 33);
470
469
  }), h(n, "signature", () => {
471
470
  if (e.signature) return e.signature;
472
- const r = u();
473
- if (!(!r || r.length !== 1))
474
- return r[0];
471
+ const t = i();
472
+ if (!(!t || t.length !== 1))
473
+ return t[0];
475
474
  }), h(n, "witness", () => {
476
475
  if (e.witness) return e.witness;
477
- const r = s();
478
- if (r && e.redeem && e.redeem.output && e.internalPubkey) {
476
+ const t = s();
477
+ if (t && e.redeem && e.redeem.output && e.internalPubkey) {
479
478
  const f = H({
480
479
  output: e.redeem.output,
481
480
  version: n.redeemVersion
482
- }), d = q(r, f);
481
+ }), d = q(t, f);
483
482
  if (!d) return;
484
- const m = j(e.internalPubkey, r.hash);
485
- if (!m) return;
486
- const w = g.concat(
487
- [g.from([n.redeemVersion | m.parity]), e.internalPubkey].concat(
483
+ const a = j(e.internalPubkey, t.hash);
484
+ if (!a) return;
485
+ const c = g.concat(
486
+ [g.from([n.redeemVersion | a.parity]), e.internalPubkey].concat(
488
487
  d
489
488
  )
490
489
  );
491
- return [e.redeem.output, w];
490
+ return [e.redeem.output, c];
492
491
  }
493
492
  if (e.signature) return [e.signature];
494
493
  }), o.validate) {
495
- let r = g.from([]);
494
+ let t = g.from([]);
496
495
  if (e.address) {
497
- if (i && i.bech32 !== p().prefix)
496
+ if (u && u.bech32 !== p().prefix)
498
497
  throw new TypeError("Invalid prefix or Network mismatch");
499
- if (p().version !== Y)
498
+ if (p().version !== z)
500
499
  throw new TypeError("Invalid address version");
501
500
  if (p().data.length !== 32) throw new TypeError("Invalid address data");
502
- r = p().data;
501
+ t = p().data;
503
502
  }
504
503
  if (e.pubkey) {
505
- if (r.length > 0 && !r.equals(e.pubkey))
504
+ if (t.length > 0 && !t.equals(e.pubkey))
506
505
  throw new TypeError("Pubkey mismatch");
507
- r = e.pubkey;
506
+ t = e.pubkey;
508
507
  }
509
508
  if (e.output) {
510
- if (e.output.length !== 34 || e.output[0] !== Q.OP_1 || e.output[1] !== 32)
509
+ if (e.output.length !== 34 || e.output[0] !== Y.OP_1 || e.output[1] !== 32)
511
510
  throw new TypeError("Output is invalid");
512
- if (r.length > 0 && !r.equals(e.output.slice(2)))
511
+ if (t.length > 0 && !t.equals(e.output.subarray(2)))
513
512
  throw new TypeError("Pubkey mismatch");
514
- r = e.output.slice(2);
513
+ t = e.output.subarray(2);
515
514
  }
516
515
  if (e.internalPubkey) {
517
- const m = j(e.internalPubkey, n.hash);
518
- if (r.length > 0 && !r.equals(m.x))
516
+ const a = j(e.internalPubkey, n.hash);
517
+ if (t.length > 0 && !t.equals(a.x))
519
518
  throw new TypeError("Pubkey mismatch");
520
- r = m.x;
519
+ t = a.x;
521
520
  }
521
+ if (t && t.length && !K().isXOnlyPoint(t))
522
+ throw new TypeError("Invalid pubkey for p2tr");
522
523
  const f = s();
523
524
  if (e.hash && f && !e.hash.equals(f.hash))
524
525
  throw new TypeError("Hash mismatch");
525
526
  if (e.redeem && e.redeem.output && f) {
526
- const m = H({
527
+ const a = H({
527
528
  output: e.redeem.output,
528
529
  version: n.redeemVersion
529
530
  });
530
- if (!q(f, m))
531
+ if (!q(f, a))
531
532
  throw new TypeError("Redeem script not in tree");
532
533
  }
533
- const d = u();
534
+ const d = i();
534
535
  if (e.redeem && n.redeem) {
535
536
  if (e.redeem.redeemVersion && e.redeem.redeemVersion !== n.redeem.redeemVersion)
536
537
  throw new TypeError("Redeem.redeemVersion and witness mismatch");
537
538
  if (e.redeem.output) {
538
- if (a(e.redeem.output).length === 0)
539
+ if (w(e.redeem.output).length === 0)
539
540
  throw new TypeError("Redeem.output is invalid");
540
541
  if (n.redeem.output && !e.redeem.output.equals(n.redeem.output))
541
542
  throw new TypeError("Redeem.output and witness mismatch");
@@ -548,75 +549,75 @@ function Oe(e, o) {
548
549
  if (e.signature && !e.signature.equals(d[0]))
549
550
  throw new TypeError("Signature mismatch");
550
551
  } else {
551
- const m = d[d.length - 1];
552
- if (m.length < 33)
552
+ const a = d[d.length - 1];
553
+ if (a.length < 33)
553
554
  throw new TypeError(
554
- `The control-block length is too small. Got ${m.length}, expected min 33.`
555
+ `The control-block length is too small. Got ${a.length}, expected min 33.`
555
556
  );
556
- if ((m.length - 33) % 32 !== 0)
557
+ if ((a.length - 33) % 32 !== 0)
557
558
  throw new TypeError(
558
- `The control-block length of ${m.length} is incorrect!`
559
+ `The control-block length of ${a.length} is incorrect!`
559
560
  );
560
- const w = (m.length - 33) / 32;
561
- if (w > 128)
562
- throw new TypeError(`The script path is too long. Got ${w}, expected max 128.`);
563
- const _ = m.slice(1, 33);
561
+ const c = (a.length - 33) / 32;
562
+ if (c > 128)
563
+ throw new TypeError(`The script path is too long. Got ${c}, expected max 128.`);
564
+ const _ = a.subarray(1, 33);
564
565
  if (e.internalPubkey && !e.internalPubkey.equals(_))
565
566
  throw new TypeError("Internal pubkey mismatch");
566
- if (!ne().isXOnlyPoint(_))
567
+ if (!K().isXOnlyPoint(_))
567
568
  throw new TypeError("Invalid internalPubkey for p2tr witness");
568
- const he = m[0] & W, pe = d[d.length - 2], fe = H({
569
+ const he = a[0] & W, pe = d[d.length - 2], fe = H({
569
570
  output: pe,
570
571
  version: he
571
- }), de = K(m, fe), U = j(_, de);
572
+ }), de = L(a, fe), U = j(_, de);
572
573
  if (!U)
573
574
  throw new TypeError("Invalid outputKey for p2tr witness");
574
- if (r.length && !r.equals(U.x))
575
+ if (t.length && !t.equals(U.x))
575
576
  throw new TypeError("Pubkey mismatch for p2tr witness");
576
- if (U.parity !== (m[0] & 1)) throw new Error("Incorrect parity");
577
+ if (U.parity !== (a[0] & 1)) throw new Error("Incorrect parity");
577
578
  }
578
579
  }
579
580
  return Object.assign(n, e);
580
581
  }
581
- const z = v, _e = c.alloc(0);
582
+ const Z = v, _e = m.alloc(0);
582
583
  function Se(e, o) {
583
584
  if (!e.address && !e.hash && !e.output && !e.pubkey && !e.witness)
584
585
  throw new TypeError("Not enough data");
585
- o = Object.assign({ validate: !0 }, o || {}), t(
586
+ o = Object.assign({ validate: !0 }, o || {}), r(
586
587
  {
587
- address: t.maybe(t.String),
588
- hash: t.maybe(t.BufferN(20)),
589
- input: t.maybe(t.BufferN(0)),
590
- network: t.maybe(t.Object),
591
- output: t.maybe(t.BufferN(22)),
592
- pubkey: t.maybe(T),
593
- signature: t.maybe(S),
594
- witness: t.maybe(t.arrayOf(t.Buffer))
588
+ address: r.maybe(r.String),
589
+ hash: r.maybe(r.BufferN(20)),
590
+ input: r.maybe(r.BufferN(0)),
591
+ network: r.maybe(r.Object),
592
+ output: r.maybe(r.BufferN(22)),
593
+ pubkey: r.maybe(T),
594
+ signature: r.maybe(S),
595
+ witness: r.maybe(r.arrayOf(r.Buffer))
595
596
  },
596
597
  e
597
598
  );
598
- const p = y(() => {
599
- const i = b.bech32.decode(e.address), n = i.words.shift(), r = b.bech32.fromWords(i.words);
599
+ const p = l(() => {
600
+ const u = b.bech32.decode(e.address), n = u.words.shift(), t = b.bech32.fromWords(u.words);
600
601
  return {
601
602
  version: n,
602
- prefix: i.prefix,
603
- data: c.from(r)
603
+ prefix: u.prefix,
604
+ data: m.from(t)
604
605
  };
605
- }), u = e.network || P, s = {
606
+ }), i = e.network || P, s = {
606
607
  name: k.P2WPKH,
607
- network: u
608
+ network: i
608
609
  };
609
610
  if (h(s, "address", () => {
610
611
  if (!s.hash) return;
611
- const i = b.bech32.toWords(s.hash);
612
- return i.unshift(0), b.bech32.encode(u.bech32, i);
612
+ const u = b.bech32.toWords(s.hash);
613
+ return u.unshift(0), b.bech32.encode(i.bech32, u);
613
614
  }), h(s, "hash", () => {
614
- if (e.output) return e.output.slice(2, 22);
615
+ if (e.output) return e.output.subarray(2, 22);
615
616
  if (e.address) return p().data;
616
617
  if (e.pubkey || s.pubkey) return E(e.pubkey || s.pubkey);
617
618
  }), h(s, "output", () => {
618
619
  if (s.hash)
619
- return l([z.OP_0, s.hash]);
620
+ return y([Z.OP_0, s.hash]);
620
621
  }), h(s, "pubkey", () => {
621
622
  if (e.pubkey) return e.pubkey;
622
623
  if (e.witness)
@@ -631,29 +632,29 @@ function Se(e, o) {
631
632
  if (e.pubkey && e.signature)
632
633
  return [e.signature, e.pubkey];
633
634
  }), o.validate) {
634
- let i = c.from([]);
635
+ let u = m.from([]);
635
636
  if (e.address) {
636
- if (u && u.bech32 !== p().prefix)
637
+ if (i && i.bech32 !== p().prefix)
637
638
  throw new TypeError("Invalid prefix or Network mismatch");
638
639
  if (p().version !== 0) throw new TypeError("Invalid address version");
639
640
  if (p().data.length !== 20) throw new TypeError("Invalid address data");
640
- i = p().data;
641
+ u = p().data;
641
642
  }
642
643
  if (e.hash) {
643
- if (i.length > 0 && !i.equals(e.hash)) throw new TypeError("Hash mismatch");
644
- i = e.hash;
644
+ if (u.length > 0 && !u.equals(e.hash)) throw new TypeError("Hash mismatch");
645
+ u = e.hash;
645
646
  }
646
647
  if (e.output) {
647
- if (e.output.length !== 22 || e.output[0] !== z.OP_0 || e.output[1] !== 20)
648
+ if (e.output.length !== 22 || e.output[0] !== Z.OP_0 || e.output[1] !== 20)
648
649
  throw new TypeError("Output is invalid");
649
- if (i.length > 0 && !i.equals(e.output.slice(2)))
650
+ if (u.length > 0 && !u.equals(e.output.subarray(2)))
650
651
  throw new TypeError("Hash mismatch");
651
- i = e.output.slice(2);
652
+ u = e.output.subarray(2);
652
653
  }
653
654
  if (e.pubkey) {
654
655
  const n = E(e.pubkey);
655
- if (i.length > 0 && !i.equals(n)) throw new TypeError("Hash mismatch");
656
- if (i = n, !T(e.pubkey) || e.pubkey.length !== 33)
656
+ if (u.length > 0 && !u.equals(n)) throw new TypeError("Hash mismatch");
657
+ if (u = n, !T(e.pubkey) || e.pubkey.length !== 33)
657
658
  throw new TypeError("Invalid pubkey for p2wpkh");
658
659
  }
659
660
  if (e.witness) {
@@ -666,82 +667,82 @@ function Se(e, o) {
666
667
  throw new TypeError("Signature mismatch");
667
668
  if (e.pubkey && !e.pubkey.equals(e.witness[1])) throw new TypeError("Pubkey mismatch");
668
669
  const n = E(e.witness[1]);
669
- if (i.length > 0 && !i.equals(n)) throw new TypeError("Hash mismatch");
670
+ if (u.length > 0 && !u.equals(n)) throw new TypeError("Hash mismatch");
670
671
  }
671
672
  }
672
673
  return Object.assign(s, e);
673
674
  }
674
- const Z = v, $ = c.alloc(0);
675
+ const J = v, $ = m.alloc(0);
675
676
  function R(e) {
676
- return !!(c.isBuffer(e) && e.length === 65 && e[0] === 4 && T(e));
677
+ return !!(m.isBuffer(e) && e.length === 65 && e[0] === 4 && T(e));
677
678
  }
678
679
  function Ie(e, o) {
679
680
  if (!e.address && !e.hash && !e.output && !e.redeem && !e.witness)
680
681
  throw new TypeError("Not enough data");
681
- o = Object.assign({ validate: !0 }, o || {}), t(
682
+ o = Object.assign({ validate: !0 }, o || {}), r(
682
683
  {
683
- network: t.maybe(t.Object),
684
- address: t.maybe(t.String),
685
- hash: t.maybe(t.BufferN(32)),
686
- output: t.maybe(t.BufferN(34)),
687
- redeem: t.maybe({
688
- input: t.maybe(t.Buffer),
689
- network: t.maybe(t.Object),
690
- output: t.maybe(t.Buffer),
691
- witness: t.maybe(t.arrayOf(t.Buffer))
684
+ network: r.maybe(r.Object),
685
+ address: r.maybe(r.String),
686
+ hash: r.maybe(r.BufferN(32)),
687
+ output: r.maybe(r.BufferN(34)),
688
+ redeem: r.maybe({
689
+ input: r.maybe(r.Buffer),
690
+ network: r.maybe(r.Object),
691
+ output: r.maybe(r.Buffer),
692
+ witness: r.maybe(r.arrayOf(r.Buffer))
692
693
  }),
693
- input: t.maybe(t.BufferN(0)),
694
- witness: t.maybe(t.arrayOf(t.Buffer))
694
+ input: r.maybe(r.BufferN(0)),
695
+ witness: r.maybe(r.arrayOf(r.Buffer))
695
696
  },
696
697
  e
697
698
  );
698
- const p = y(() => {
699
- const n = b.bech32.decode(e.address), r = n.words.shift(), f = b.bech32.fromWords(n.words);
699
+ const p = l(() => {
700
+ const n = b.bech32.decode(e.address), t = n.words.shift(), f = b.bech32.fromWords(n.words);
700
701
  return {
701
- version: r,
702
+ version: t,
702
703
  prefix: n.prefix,
703
- data: c.from(f)
704
+ data: m.from(f)
704
705
  };
705
- }), u = y(() => a(e.redeem.input));
706
+ }), i = l(() => w(e.redeem.input));
706
707
  let s = e.network;
707
708
  s || (s = e.redeem && e.redeem.network || P);
708
- const i = {
709
+ const u = {
709
710
  network: s,
710
711
  name: k.P2WSH
711
712
  };
712
- if (h(i, "address", () => {
713
- if (!i.hash) return;
714
- const n = b.bech32.toWords(i.hash);
713
+ if (h(u, "address", () => {
714
+ if (!u.hash) return;
715
+ const n = b.bech32.toWords(u.hash);
715
716
  return n.unshift(0), b.bech32.encode(s.bech32, n);
716
- }), h(i, "hash", () => {
717
- if (e.output) return e.output.slice(2);
717
+ }), h(u, "hash", () => {
718
+ if (e.output) return e.output.subarray(2);
718
719
  if (e.address) return p().data;
719
- if (i.redeem && i.redeem.output) return M(i.redeem.output);
720
- }), h(i, "output", () => {
721
- if (i.hash)
722
- return l([Z.OP_0, i.hash]);
723
- }), h(i, "redeem", () => {
720
+ if (u.redeem && u.redeem.output) return G(u.redeem.output);
721
+ }), h(u, "output", () => {
722
+ if (u.hash)
723
+ return y([J.OP_0, u.hash]);
724
+ }), h(u, "redeem", () => {
724
725
  if (e.witness)
725
726
  return {
726
727
  output: e.witness[e.witness.length - 1],
727
728
  input: $,
728
729
  witness: e.witness.slice(0, -1)
729
730
  };
730
- }), h(i, "input", () => {
731
- if (i.witness)
731
+ }), h(u, "input", () => {
732
+ if (u.witness)
732
733
  return $;
733
- }), h(i, "witness", () => {
734
+ }), h(u, "witness", () => {
734
735
  if (e.redeem && e.redeem.input && e.redeem.input.length > 0 && e.redeem.output && e.redeem.output.length > 0) {
735
- const n = le(u());
736
- return i.redeem = Object.assign({ witness: n }, e.redeem), i.redeem.input = $, [].concat(n, e.redeem.output);
736
+ const n = ye(i());
737
+ return u.redeem = Object.assign({ witness: n }, e.redeem), u.redeem.input = $, [].concat(n, e.redeem.output);
737
738
  }
738
739
  if (e.redeem && e.redeem.output && e.redeem.witness)
739
740
  return [].concat(e.redeem.witness, e.redeem.output);
740
- }), h(i, "name", () => {
741
+ }), h(u, "name", () => {
741
742
  const n = ["p2wsh"];
742
- return i.redeem !== void 0 && i.redeem.name !== void 0 && n.push(i.redeem.name), n.join("-");
743
+ return u.redeem !== void 0 && u.redeem.name !== void 0 && n.push(u.redeem.name), n.join("-");
743
744
  }), o.validate) {
744
- let n = c.from([]);
745
+ let n = m.from([]);
745
746
  if (e.address) {
746
747
  if (p().prefix !== s.bech32)
747
748
  throw new TypeError("Invalid prefix or Network mismatch");
@@ -754,11 +755,11 @@ function Ie(e, o) {
754
755
  n = e.hash;
755
756
  }
756
757
  if (e.output) {
757
- if (e.output.length !== 34 || e.output[0] !== Z.OP_0 || e.output[1] !== 32)
758
+ if (e.output.length !== 34 || e.output[0] !== J.OP_0 || e.output[1] !== 32)
758
759
  throw new TypeError("Output is invalid");
759
- const r = e.output.slice(2);
760
- if (n.length > 0 && !n.equals(r)) throw new TypeError("Hash mismatch");
761
- n = r;
760
+ const t = e.output.subarray(2);
761
+ if (n.length > 0 && !n.equals(t)) throw new TypeError("Hash mismatch");
762
+ n = t;
762
763
  }
763
764
  if (e.redeem) {
764
765
  if (e.redeem.network && e.redeem.network !== s)
@@ -766,48 +767,48 @@ function Ie(e, o) {
766
767
  if (e.redeem.input && e.redeem.input.length > 0 && e.redeem.witness && e.redeem.witness.length > 0)
767
768
  throw new TypeError("Ambiguous witness source");
768
769
  if (e.redeem.output) {
769
- const r = a(e.redeem.output);
770
- if (!r || r.length < 1)
770
+ const t = w(e.redeem.output);
771
+ if (!t || t.length < 1)
771
772
  throw new TypeError("Redeem.output is invalid");
772
773
  if (e.redeem.output.byteLength > 3600)
773
774
  throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");
774
- if (ie(r) > 201)
775
+ if (ue(t) > 201)
775
776
  throw new TypeError(
776
777
  "Redeem.output unspendable with more than 201 non-push ops"
777
778
  );
778
- const f = M(e.redeem.output);
779
+ const f = G(e.redeem.output);
779
780
  if (n.length > 0 && !n.equals(f)) throw new TypeError("Hash mismatch");
780
781
  n = f;
781
782
  }
782
- if (e.redeem.input && !ue(u()))
783
+ if (e.redeem.input && !ie(i()))
783
784
  throw new TypeError("Non push-only scriptSig");
784
785
  if (e.witness && e.redeem.witness && !N(e.witness, e.redeem.witness))
785
786
  throw new TypeError("Witness and redeem.witness mismatch");
786
- if (e.redeem.input && u().some(R) || e.redeem.output && (a(e.redeem.output) || []).some(R))
787
+ if (e.redeem.input && i().some(R) || e.redeem.output && (w(e.redeem.output) || []).some(R))
787
788
  throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey");
788
789
  }
789
790
  if (e.witness && e.witness.length > 0) {
790
- const r = e.witness[e.witness.length - 1];
791
- if (e.redeem && e.redeem.output && !e.redeem.output.equals(r))
791
+ const t = e.witness[e.witness.length - 1];
792
+ if (e.redeem && e.redeem.output && !e.redeem.output.equals(t))
792
793
  throw new TypeError("Witness and redeem.output mismatch");
793
- if (e.witness.some(R) || (a(r) || []).some(R))
794
+ if (e.witness.some(R) || (w(t) || []).some(R))
794
795
  throw new TypeError("Witness contains uncompressed pubkey");
795
796
  }
796
797
  }
797
- return Object.assign(i, e);
798
+ return Object.assign(u, e);
798
799
  }
799
- const J = v, ee = 16, te = 2, re = 40;
800
+ const ee = v, re = 16, te = 2, ne = 40;
800
801
  function He(e, o) {
801
802
  if (!e.address && !e.output && !e.program && (typeof e.deploymentVersion > "u" || !e.hash160))
802
803
  throw new TypeError("At least one of address, output or program must be provided");
803
- o = Object.assign({ validate: !0 }, o || {}), t(
804
+ o = Object.assign({ validate: !0 }, o || {}), r(
804
805
  {
805
- address: t.maybe(t.String),
806
- output: t.maybe(t.Buffer),
807
- program: t.maybe(t.Buffer),
808
- network: t.maybe(t.Object),
809
- deploymentVersion: t.maybe(t.Number),
810
- hash160: t.maybe(t.BufferN(20))
806
+ address: r.maybe(r.String),
807
+ output: r.maybe(r.Buffer),
808
+ program: r.maybe(r.Buffer),
809
+ network: r.maybe(r.Object),
810
+ deploymentVersion: r.maybe(r.Number),
811
+ hash160: r.maybe(r.BufferN(20))
811
812
  },
812
813
  e
813
814
  );
@@ -816,135 +817,136 @@ function He(e, o) {
816
817
  if (e.hash160.length !== 20) throw new TypeError("hash160 must be exactly 20 bytes");
817
818
  if (e.deploymentVersion < 0 || e.deploymentVersion > 255)
818
819
  throw new TypeError("deploymentVersion must fit in one byte");
819
- return c.concat([c.of(e.deploymentVersion), e.hash160]);
820
+ return m.concat([m.of(e.deploymentVersion), e.hash160]);
820
821
  }
821
- }, u = y(() => se(e.address)), s = e.network || P, i = {
822
+ }, i = l(() => se(e.address)), s = e.network || P, u = {
822
823
  name: k.P2OP,
823
824
  network: s,
824
825
  deploymentVersion: 0
825
826
  };
826
- if (h(i, "program", () => {
827
+ if (h(u, "program", () => {
827
828
  if (e.program) return e.program;
828
829
  const n = p();
829
830
  if (n) return n;
830
831
  if (e.output) {
831
- if (e.output[0] !== J.OP_16) throw new TypeError("Invalid P2OP script");
832
- let r = 1, f;
832
+ if (e.output[0] !== ee.OP_16) throw new TypeError("Invalid P2OP script");
833
+ let t = 1, f;
833
834
  if (e.output[1] < 76)
834
- f = e.output[1], r = 2;
835
+ f = e.output[1], t = 2;
835
836
  else if (e.output[1] === 76)
836
- f = e.output[2], r = 3;
837
+ f = e.output[2], t = 3;
837
838
  else
838
839
  throw new TypeError("Unsupported push opcode in P2OP script");
839
- return e.output.slice(r, r + f);
840
+ return e.output.subarray(t, t + f);
840
841
  }
841
842
  if (e.address)
842
- return u().data;
843
- }), h(i, "deploymentVersion", () => {
844
- if (i.program)
845
- return i.program[0];
846
- }), h(i, "hash160", () => {
847
- if (i.program)
848
- return i.program.slice(1);
849
- }), h(i, "output", () => {
850
- if (i.program)
851
- return l([J.OP_16, i.program]);
852
- }), h(i, "address", () => {
853
- if (!i.program) return;
843
+ return i().data;
844
+ }), h(u, "deploymentVersion", () => {
845
+ if (u.program)
846
+ return u.program[0];
847
+ }), h(u, "hash160", () => {
848
+ if (u.program)
849
+ return u.program.subarray(1);
850
+ }), h(u, "output", () => {
851
+ if (u.program)
852
+ return y([ee.OP_16, u.program]);
853
+ }), h(u, "address", () => {
854
+ if (!u.program) return;
854
855
  if (!s.bech32Opnet)
855
856
  throw new TypeError("Network does not support opnet");
856
- const n = b.bech32m.toWords(i.program);
857
- return n.unshift(ee), b.bech32m.encode(s.bech32Opnet, n);
857
+ const n = b.bech32m.toWords(u.program);
858
+ return n.unshift(re), b.bech32m.encode(s.bech32Opnet, n);
858
859
  }), o.validate) {
859
860
  let n = g.alloc(0);
860
861
  if (e.address) {
861
- const r = u();
862
- if (s.bech32Opnet !== r.prefix)
862
+ const t = i();
863
+ if (s.bech32Opnet !== t.prefix)
863
864
  throw new TypeError("Invalid prefix or network mismatch");
864
- if (r.version !== ee)
865
+ if (t.version !== re)
865
866
  throw new TypeError("Invalid witness version for p2op");
866
- if (r.data.length < te || r.data.length > re)
867
+ if (t.data.length < te || t.data.length > ne)
867
868
  throw new TypeError("Invalid witness program length");
868
- n = r.data;
869
+ n = t.data;
869
870
  }
870
871
  if (e.program) {
871
872
  if (n.length && !n.equals(e.program)) throw new TypeError("Program mismatch");
872
873
  n = e.program;
873
874
  }
874
875
  if (!n.length && e.deploymentVersion !== void 0 && e.hash160 && (n = p()), e.output) {
875
- const r = i.program;
876
- if (n.length && !n.equals(r))
876
+ const t = u.program;
877
+ if (n.length && !n.equals(t))
877
878
  throw new TypeError("Program mismatch (output vs other source)");
878
- n = r;
879
+ n = t;
879
880
  }
880
- if (n.length < te || n.length > re)
881
+ if (n.length < te || n.length > ne)
881
882
  throw new TypeError(`Witness program must be 2–40 bytes. Was ${n.length} bytes`);
882
883
  if (e.deploymentVersion !== void 0 && e.deploymentVersion !== n[0])
883
884
  throw new TypeError("deploymentVersion mismatch");
884
- if (e.hash160 && !e.hash160.equals(n.slice(1))) throw new TypeError("hash160 mismatch");
885
+ if (e.hash160 && !e.hash160.equals(n.subarray(1)))
886
+ throw new TypeError("hash160 mismatch");
885
887
  }
886
- return Object.assign(i, e);
888
+ return Object.assign(u, e);
887
889
  }
888
890
  const O = v;
889
891
  function Ne(e, o) {
890
892
  if (!e.address && !e.hash && !e.output && !e.pubkey && !e.input)
891
893
  throw new TypeError("Not enough data");
892
- o = Object.assign({ validate: !0 }, o || {}), t(
894
+ o = Object.assign({ validate: !0 }, o || {}), r(
893
895
  {
894
- network: t.maybe(t.Object),
895
- address: t.maybe(t.String),
896
- hash: t.maybe(t.BufferN(20)),
897
- output: t.maybe(t.BufferN(25)),
898
- pubkey: t.maybe(T),
899
- signature: t.maybe(S),
900
- input: t.maybe(t.Buffer)
896
+ network: r.maybe(r.Object),
897
+ address: r.maybe(r.String),
898
+ hash: r.maybe(r.BufferN(20)),
899
+ output: r.maybe(r.BufferN(25)),
900
+ pubkey: r.maybe(T),
901
+ signature: r.maybe(S),
902
+ input: r.maybe(r.Buffer)
901
903
  },
902
904
  e
903
905
  );
904
- const p = y(() => {
905
- const n = c.from(x.decode(e.address)), r = n.readUInt8(0), f = n.slice(1);
906
- return { version: r, hash: f };
907
- }), u = y(() => a(e.input)), s = e.network || P, i = {
906
+ const p = l(() => {
907
+ const n = m.from(x.decode(e.address)), t = n.readUInt8(0), f = n.subarray(1);
908
+ return { version: t, hash: f };
909
+ }), i = l(() => w(e.input)), s = e.network || P, u = {
908
910
  name: k.P2PKH,
909
911
  network: s,
910
912
  hash: void 0
911
913
  };
912
- if (h(i, "address", () => {
913
- if (!i.hash) return;
914
- const n = c.allocUnsafe(21);
915
- return n.writeUInt8(s.pubKeyHash, 0), i.hash.copy(n, 1), x.encode(n);
916
- }), h(i, "hash", () => {
917
- if (e.output) return e.output.slice(3, 23);
914
+ if (h(u, "address", () => {
915
+ if (!u.hash) return;
916
+ const n = m.allocUnsafe(21);
917
+ return n.writeUInt8(s.pubKeyHash, 0), u.hash.copy(n, 1), x.encode(n);
918
+ }), h(u, "hash", () => {
919
+ if (e.output) return e.output.subarray(3, 23);
918
920
  if (e.address) return p().hash;
919
- if (e.pubkey || i.pubkey) return E(e.pubkey || i.pubkey);
920
- }), h(i, "output", () => {
921
- if (i.hash)
922
- return l([
921
+ if (e.pubkey || u.pubkey) return E(e.pubkey || u.pubkey);
922
+ }), h(u, "output", () => {
923
+ if (u.hash)
924
+ return y([
923
925
  O.OP_DUP,
924
926
  O.OP_HASH160,
925
- i.hash,
927
+ u.hash,
926
928
  O.OP_EQUALVERIFY,
927
929
  O.OP_CHECKSIG
928
930
  ]);
929
- }), h(i, "pubkey", () => {
931
+ }), h(u, "pubkey", () => {
930
932
  if (e.input)
931
- return u()[1];
932
- }), h(i, "signature", () => {
933
+ return i()[1];
934
+ }), h(u, "signature", () => {
933
935
  if (e.input)
934
- return u()[0];
935
- }), h(i, "input", () => {
936
+ return i()[0];
937
+ }), h(u, "input", () => {
936
938
  if (!e.pubkey || !e.signature) return;
937
939
  let n = e.pubkey;
938
940
  if (e.useHybrid || e.useUncompressed) {
939
- const r = G(e.pubkey);
940
- r && (e.useUncompressed ? n = r.uncompressed : n = r.hybrid);
941
+ const t = X(e.pubkey);
942
+ t && (e.useUncompressed ? n = t.uncompressed : n = t.hybrid);
941
943
  }
942
- return l([e.signature, n]);
943
- }), h(i, "witness", () => {
944
- if (i.input)
944
+ return y([e.signature, n]);
945
+ }), h(u, "witness", () => {
946
+ if (u.input)
945
947
  return [];
946
948
  }), o.validate) {
947
- let n = c.from([]);
949
+ let n = m.from([]);
948
950
  if (e.address) {
949
951
  if (p().version !== s.pubKeyHash)
950
952
  throw new TypeError("Invalid version or Network mismatch");
@@ -960,50 +962,50 @@ function Ne(e, o) {
960
962
  if (e.output) {
961
963
  if (e.output.length !== 25 || e.output[0] !== O.OP_DUP || e.output[1] !== O.OP_HASH160 || e.output[2] !== 20 || e.output[23] !== O.OP_EQUALVERIFY || e.output[24] !== O.OP_CHECKSIG)
962
964
  throw new TypeError("Output is invalid");
963
- const r = e.output.slice(3, 23);
964
- if (n.length > 0 && !n.equals(r)) throw new TypeError("Hash mismatch");
965
- n = r;
965
+ const t = e.output.subarray(3, 23);
966
+ if (n.length > 0 && !n.equals(t)) throw new TypeError("Hash mismatch");
967
+ n = t;
966
968
  }
967
969
  if (e.pubkey) {
968
- const r = E(e.pubkey);
969
- let f = n.length > 0 && !n.equals(r);
970
+ const t = E(e.pubkey);
971
+ let f = n.length > 0 && !n.equals(t);
970
972
  if (f && (e.pubkey.length === 33 && (e.pubkey[0] === 2 || e.pubkey[0] === 3) || e.pubkey.length === 65 && e.pubkey[0] === 4)) {
971
- const d = G(e.pubkey);
973
+ const d = X(e.pubkey);
972
974
  if (d) {
973
- const m = E(d.uncompressed);
974
- if (n.equals(m))
975
+ const a = E(d.uncompressed);
976
+ if (n.equals(a))
975
977
  f = !1, e.useUncompressed = !0;
976
978
  else {
977
- const w = E(d.hybrid);
978
- f = !n.equals(w), f || (e.useHybrid = !0);
979
+ const c = E(d.hybrid);
980
+ f = !n.equals(c), f || (e.useHybrid = !0);
979
981
  }
980
982
  }
981
983
  }
982
984
  if (f)
983
985
  throw new TypeError("Hash mismatch");
984
- n = r;
986
+ n = t;
985
987
  }
986
988
  if (e.input) {
987
- const r = u();
988
- if (r.length !== 2) throw new TypeError("Input is invalid");
989
- if (!S(r[0]))
989
+ const t = i();
990
+ if (t.length !== 2) throw new TypeError("Input is invalid");
991
+ if (!S(t[0]))
990
992
  throw new TypeError("Input has invalid signature");
991
- if (!T(r[1])) throw new TypeError("Input has invalid pubkey");
992
- if (e.signature && !e.signature.equals(r[0]))
993
+ if (!T(t[1])) throw new TypeError("Input has invalid pubkey");
994
+ if (e.signature && !e.signature.equals(t[0]))
993
995
  throw new TypeError("Signature mismatch");
994
- if (e.pubkey && !e.pubkey.equals(r[1]))
996
+ if (e.pubkey && !e.pubkey.equals(t[1]))
995
997
  throw new TypeError("Pubkey mismatch");
996
- const f = E(r[1]);
998
+ const f = E(t[1]);
997
999
  if (n.length > 0 && !n.equals(f)) throw new TypeError("Hash mismatch (input)");
998
1000
  }
999
1001
  }
1000
- return Object.assign(i, e);
1002
+ return Object.assign(u, e);
1001
1003
  }
1002
1004
  var k = /* @__PURE__ */ ((e) => (e.P2PK = "p2pk", e.P2PKH = "p2pkh", e.P2SH = "p2sh", e.P2MS = "p2ms", e.P2WPKH = "p2wpkh", e.P2WSH = "p2wsh", e.P2TR = "p2tr", e.P2OP = "p2op", e.Embed = "embed", e.ScriptRedeem = "scriptRedeem", e))(k || {});
1003
1005
  const Re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1004
1006
  __proto__: null,
1005
- LEAF_VERSION_TAPSCRIPT: F,
1006
- MAX_TAPTREE_DEPTH: ye,
1007
+ LEAF_VERSION_TAPSCRIPT: M,
1008
+ MAX_TAPTREE_DEPTH: le,
1007
1009
  PaymentType: k,
1008
1010
  findScriptPath: q,
1009
1011
  p2data: ke,
@@ -1016,16 +1018,16 @@ const Re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1016
1018
  p2wpkh: Se,
1017
1019
  p2wsh: Ie,
1018
1020
  prop: h,
1019
- rootHashFromPath: K,
1021
+ rootHashFromPath: L,
1020
1022
  tapTweakHash: oe,
1021
1023
  tapleafHash: H,
1022
1024
  toHashTree: A,
1023
1025
  tweakKey: j,
1024
- value: y
1026
+ value: l
1025
1027
  }, Symbol.toStringTag, { value: "Module" }));
1026
1028
  export {
1027
- F as L,
1028
- ye as M,
1029
+ M as L,
1030
+ le as M,
1029
1031
  k as P,
1030
1032
  Pe as a,
1031
1033
  Se as b,
@@ -1040,6 +1042,6 @@ export {
1040
1042
  q as k,
1041
1043
  oe as l,
1042
1044
  Ne as p,
1043
- K as r,
1045
+ L as r,
1044
1046
  j as t
1045
1047
  };