@btc-vision/bitcoin 7.0.0-alpha.1 → 7.0.0-alpha.10

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 (290) hide show
  1. package/README.md +455 -155
  2. package/browser/address.d.ts +5 -1
  3. package/browser/address.d.ts.map +1 -1
  4. package/browser/branded.d.ts +3 -14
  5. package/browser/branded.d.ts.map +1 -1
  6. package/browser/chunks/psbt-parallel-BBFlkmiv.js +10717 -0
  7. package/browser/ecc/context.d.ts +22 -21
  8. package/browser/ecc/context.d.ts.map +1 -1
  9. package/browser/ecc/index.d.ts +1 -1
  10. package/browser/ecc/index.d.ts.map +1 -1
  11. package/browser/ecc/types.d.ts +10 -123
  12. package/browser/ecc/types.d.ts.map +1 -1
  13. package/browser/env.d.ts +13 -0
  14. package/browser/env.d.ts.map +1 -0
  15. package/browser/index.d.ts +6 -6
  16. package/browser/index.d.ts.map +1 -1
  17. package/browser/index.js +2602 -11786
  18. package/browser/io/hex.d.ts.map +1 -1
  19. package/browser/io/index.d.ts +0 -1
  20. package/browser/io/index.d.ts.map +1 -1
  21. package/browser/opcodes.d.ts +11 -0
  22. package/browser/opcodes.d.ts.map +1 -1
  23. package/browser/payments/p2tr.d.ts.map +1 -1
  24. package/browser/psbt/PsbtCache.d.ts +54 -0
  25. package/browser/psbt/PsbtCache.d.ts.map +1 -0
  26. package/browser/psbt/PsbtFinalizer.d.ts +21 -0
  27. package/browser/psbt/PsbtFinalizer.d.ts.map +1 -0
  28. package/browser/psbt/PsbtSigner.d.ts +32 -0
  29. package/browser/psbt/PsbtSigner.d.ts.map +1 -0
  30. package/browser/psbt/PsbtTransaction.d.ts +25 -0
  31. package/browser/psbt/PsbtTransaction.d.ts.map +1 -0
  32. package/browser/psbt/types.d.ts +4 -70
  33. package/browser/psbt/types.d.ts.map +1 -1
  34. package/browser/psbt/validation.d.ts +1 -1
  35. package/browser/psbt/validation.d.ts.map +1 -1
  36. package/browser/psbt.d.ts +26 -40
  37. package/browser/psbt.d.ts.map +1 -1
  38. package/browser/script.d.ts.map +1 -1
  39. package/browser/transaction.d.ts +4 -4
  40. package/browser/transaction.d.ts.map +1 -1
  41. package/browser/types.d.ts +5 -3
  42. package/browser/types.d.ts.map +1 -1
  43. package/browser/workers/WorkerSigningPool.d.ts +7 -0
  44. package/browser/workers/WorkerSigningPool.d.ts.map +1 -1
  45. package/browser/workers/WorkerSigningPool.node.d.ts +7 -0
  46. package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -1
  47. package/browser/workers/WorkerSigningPool.sequential.d.ts +67 -0
  48. package/browser/workers/WorkerSigningPool.sequential.d.ts.map +1 -0
  49. package/browser/workers/WorkerSigningPool.worklet.d.ts +64 -0
  50. package/browser/workers/WorkerSigningPool.worklet.d.ts.map +1 -0
  51. package/browser/workers/index.browser.d.ts +16 -0
  52. package/browser/workers/index.browser.d.ts.map +1 -0
  53. package/browser/workers/index.d.ts +4 -64
  54. package/browser/workers/index.d.ts.map +1 -1
  55. package/browser/workers/index.js +28 -0
  56. package/browser/workers/index.node.d.ts +17 -0
  57. package/browser/workers/index.node.d.ts.map +1 -0
  58. package/browser/workers/index.react-native.d.ts +28 -0
  59. package/browser/workers/index.react-native.d.ts.map +1 -0
  60. package/browser/workers/index.shared.d.ts +15 -0
  61. package/browser/workers/index.shared.d.ts.map +1 -0
  62. package/browser/workers/psbt-parallel.d.ts +2 -3
  63. package/browser/workers/psbt-parallel.d.ts.map +1 -1
  64. package/browser/workers/types.d.ts +17 -0
  65. package/browser/workers/types.d.ts.map +1 -1
  66. package/build/address.d.ts +5 -1
  67. package/build/address.d.ts.map +1 -1
  68. package/build/address.js +29 -17
  69. package/build/address.js.map +1 -1
  70. package/build/bech32utils.js.map +1 -1
  71. package/build/block.js.map +1 -1
  72. package/build/branded.d.ts +3 -14
  73. package/build/branded.d.ts.map +1 -1
  74. package/build/branded.js +0 -5
  75. package/build/branded.js.map +1 -1
  76. package/build/ecc/context.d.ts +22 -21
  77. package/build/ecc/context.d.ts.map +1 -1
  78. package/build/ecc/context.js +23 -95
  79. package/build/ecc/context.js.map +1 -1
  80. package/build/ecc/index.d.ts +1 -1
  81. package/build/ecc/index.d.ts.map +1 -1
  82. package/build/ecc/types.d.ts +7 -126
  83. package/build/ecc/types.d.ts.map +1 -1
  84. package/build/ecc/types.js +4 -1
  85. package/build/ecc/types.js.map +1 -1
  86. package/build/env.d.ts +13 -0
  87. package/build/env.d.ts.map +1 -0
  88. package/build/env.js +198 -0
  89. package/build/env.js.map +1 -0
  90. package/build/index.d.ts +7 -6
  91. package/build/index.d.ts.map +1 -1
  92. package/build/index.js +7 -5
  93. package/build/index.js.map +1 -1
  94. package/build/io/hex.d.ts.map +1 -1
  95. package/build/io/hex.js +2 -1
  96. package/build/io/hex.js.map +1 -1
  97. package/build/io/index.d.ts +0 -1
  98. package/build/io/index.d.ts.map +1 -1
  99. package/build/io/index.js +0 -2
  100. package/build/io/index.js.map +1 -1
  101. package/build/opcodes.d.ts +11 -0
  102. package/build/opcodes.d.ts.map +1 -1
  103. package/build/opcodes.js +19 -4
  104. package/build/opcodes.js.map +1 -1
  105. package/build/payments/bip341.js.map +1 -1
  106. package/build/payments/embed.js.map +1 -1
  107. package/build/payments/p2ms.js.map +1 -1
  108. package/build/payments/p2pk.js.map +1 -1
  109. package/build/payments/p2pkh.js.map +1 -1
  110. package/build/payments/p2sh.js.map +1 -1
  111. package/build/payments/p2tr.d.ts.map +1 -1
  112. package/build/payments/p2tr.js +2 -3
  113. package/build/payments/p2tr.js.map +1 -1
  114. package/build/payments/p2wpkh.js.map +1 -1
  115. package/build/payments/p2wsh.js.map +1 -1
  116. package/build/psbt/PsbtCache.d.ts +54 -0
  117. package/build/psbt/PsbtCache.d.ts.map +1 -0
  118. package/build/psbt/PsbtCache.js +249 -0
  119. package/build/psbt/PsbtCache.js.map +1 -0
  120. package/build/psbt/PsbtFinalizer.d.ts +21 -0
  121. package/build/psbt/PsbtFinalizer.d.ts.map +1 -0
  122. package/build/psbt/PsbtFinalizer.js +157 -0
  123. package/build/psbt/PsbtFinalizer.js.map +1 -0
  124. package/build/psbt/PsbtSigner.d.ts +32 -0
  125. package/build/psbt/PsbtSigner.d.ts.map +1 -0
  126. package/build/psbt/PsbtSigner.js +192 -0
  127. package/build/psbt/PsbtSigner.js.map +1 -0
  128. package/build/psbt/PsbtTransaction.d.ts +25 -0
  129. package/build/psbt/PsbtTransaction.d.ts.map +1 -0
  130. package/build/psbt/PsbtTransaction.js +61 -0
  131. package/build/psbt/PsbtTransaction.js.map +1 -0
  132. package/build/psbt/types.d.ts +4 -70
  133. package/build/psbt/types.d.ts.map +1 -1
  134. package/build/psbt/validation.d.ts +1 -1
  135. package/build/psbt/validation.d.ts.map +1 -1
  136. package/build/psbt.d.ts +26 -40
  137. package/build/psbt.d.ts.map +1 -1
  138. package/build/psbt.js +177 -799
  139. package/build/psbt.js.map +1 -1
  140. package/build/script.d.ts.map +1 -1
  141. package/build/script.js +2 -2
  142. package/build/script.js.map +1 -1
  143. package/build/transaction.d.ts +4 -4
  144. package/build/transaction.d.ts.map +1 -1
  145. package/build/transaction.js +5 -4
  146. package/build/transaction.js.map +1 -1
  147. package/build/tsconfig.build.tsbuildinfo +1 -1
  148. package/build/types.d.ts +5 -3
  149. package/build/types.d.ts.map +1 -1
  150. package/build/types.js +11 -16
  151. package/build/types.js.map +1 -1
  152. package/build/workers/WorkerSigningPool.d.ts +7 -0
  153. package/build/workers/WorkerSigningPool.d.ts.map +1 -1
  154. package/build/workers/WorkerSigningPool.js +12 -1
  155. package/build/workers/WorkerSigningPool.js.map +1 -1
  156. package/build/workers/WorkerSigningPool.node.d.ts +7 -0
  157. package/build/workers/WorkerSigningPool.node.d.ts.map +1 -1
  158. package/build/workers/WorkerSigningPool.node.js +37 -5
  159. package/build/workers/WorkerSigningPool.node.js.map +1 -1
  160. package/build/workers/WorkerSigningPool.sequential.d.ts +76 -0
  161. package/build/workers/WorkerSigningPool.sequential.d.ts.map +1 -0
  162. package/build/workers/WorkerSigningPool.sequential.js +160 -0
  163. package/build/workers/WorkerSigningPool.sequential.js.map +1 -0
  164. package/build/workers/WorkerSigningPool.worklet.d.ts +79 -0
  165. package/build/workers/WorkerSigningPool.worklet.d.ts.map +1 -0
  166. package/build/workers/WorkerSigningPool.worklet.js +390 -0
  167. package/build/workers/WorkerSigningPool.worklet.js.map +1 -0
  168. package/build/workers/index.browser.d.ts +24 -0
  169. package/build/workers/index.browser.d.ts.map +1 -0
  170. package/build/workers/index.browser.js +30 -0
  171. package/build/workers/index.browser.js.map +1 -0
  172. package/build/workers/index.d.ts +6 -18
  173. package/build/workers/index.d.ts.map +1 -1
  174. package/build/workers/index.js +12 -14
  175. package/build/workers/index.js.map +1 -1
  176. package/build/workers/index.node.d.ts +38 -0
  177. package/build/workers/index.node.d.ts.map +1 -0
  178. package/build/workers/index.node.js +45 -0
  179. package/build/workers/index.node.js.map +1 -0
  180. package/build/workers/index.react-native.d.ts +28 -0
  181. package/build/workers/index.react-native.d.ts.map +1 -0
  182. package/build/workers/index.react-native.js +67 -0
  183. package/build/workers/index.react-native.js.map +1 -0
  184. package/build/workers/index.shared.d.ts +15 -0
  185. package/build/workers/index.shared.d.ts.map +1 -0
  186. package/build/workers/index.shared.js +20 -0
  187. package/build/workers/index.shared.js.map +1 -0
  188. package/build/workers/psbt-parallel.d.ts +2 -3
  189. package/build/workers/psbt-parallel.d.ts.map +1 -1
  190. package/build/workers/psbt-parallel.js +4 -4
  191. package/build/workers/psbt-parallel.js.map +1 -1
  192. package/build/workers/types.d.ts +17 -0
  193. package/build/workers/types.d.ts.map +1 -1
  194. package/package.json +46 -8
  195. package/src/address.ts +41 -18
  196. package/src/bech32utils.ts +3 -3
  197. package/src/block.ts +2 -2
  198. package/src/branded.ts +15 -13
  199. package/src/ecc/context.ts +30 -133
  200. package/src/ecc/index.ts +2 -2
  201. package/src/ecc/types.ts +7 -138
  202. package/src/env.ts +239 -0
  203. package/src/index.ts +45 -9
  204. package/src/io/hex.ts +2 -1
  205. package/src/io/index.ts +0 -3
  206. package/src/opcodes.ts +21 -4
  207. package/src/payments/bip341.ts +3 -3
  208. package/src/payments/embed.ts +1 -1
  209. package/src/payments/p2ms.ts +2 -2
  210. package/src/payments/p2pk.ts +2 -2
  211. package/src/payments/p2pkh.ts +3 -3
  212. package/src/payments/p2sh.ts +4 -4
  213. package/src/payments/p2tr.ts +9 -9
  214. package/src/payments/p2wpkh.ts +5 -5
  215. package/src/payments/p2wsh.ts +2 -2
  216. package/src/psbt/PsbtCache.ts +325 -0
  217. package/src/psbt/PsbtFinalizer.ts +213 -0
  218. package/src/psbt/PsbtSigner.ts +302 -0
  219. package/src/psbt/PsbtTransaction.ts +82 -0
  220. package/src/psbt/types.ts +4 -86
  221. package/src/psbt/validation.ts +1 -1
  222. package/src/psbt.ts +349 -1198
  223. package/src/script.ts +2 -2
  224. package/src/transaction.ts +10 -9
  225. package/src/types.ts +18 -28
  226. package/src/workers/WorkerSigningPool.node.ts +41 -5
  227. package/src/workers/WorkerSigningPool.sequential.ts +191 -0
  228. package/src/workers/WorkerSigningPool.ts +14 -1
  229. package/src/workers/WorkerSigningPool.worklet.ts +522 -0
  230. package/src/workers/index.browser.ts +34 -0
  231. package/src/workers/index.node.ts +50 -0
  232. package/src/workers/index.react-native.ts +110 -0
  233. package/src/workers/index.shared.ts +58 -0
  234. package/src/workers/index.ts +14 -65
  235. package/src/workers/psbt-parallel.ts +7 -7
  236. package/src/workers/types.ts +21 -0
  237. package/test/address.spec.ts +2 -2
  238. package/test/bitcoin.core.spec.ts +5 -2
  239. package/test/browser/payments.spec.ts +151 -0
  240. package/test/browser/psbt.spec.ts +1510 -0
  241. package/test/browser/script.spec.ts +223 -0
  242. package/test/browser/setup.ts +13 -0
  243. package/test/browser/workers-signing.spec.ts +537 -0
  244. package/test/crypto.spec.ts +2 -2
  245. package/test/env.spec.ts +418 -0
  246. package/test/fixtures/core/base58_encode_decode.json +12 -48
  247. package/test/fixtures/core/base58_keys_invalid.json +50 -150
  248. package/test/fixtures/core/sighash.json +1 -3
  249. package/test/fixtures/core/tx_valid.json +133 -501
  250. package/test/fixtures/embed.json +3 -11
  251. package/test/fixtures/p2ms.json +21 -91
  252. package/test/fixtures/p2pk.json +5 -24
  253. package/test/fixtures/p2pkh.json +7 -36
  254. package/test/fixtures/p2sh.json +8 -54
  255. package/test/fixtures/p2tr.json +2 -6
  256. package/test/fixtures/p2wpkh.json +7 -36
  257. package/test/fixtures/p2wsh.json +14 -59
  258. package/test/fixtures/psbt.json +2 -6
  259. package/test/fixtures/script.json +12 -48
  260. package/test/integration/addresses.spec.ts +11 -5
  261. package/test/integration/bip32.spec.ts +1 -1
  262. package/test/integration/cltv.spec.ts +10 -6
  263. package/test/integration/csv.spec.ts +10 -9
  264. package/test/integration/payments.spec.ts +8 -4
  265. package/test/integration/taproot.spec.ts +26 -6
  266. package/test/integration/transactions.spec.ts +22 -8
  267. package/test/payments.spec.ts +1 -1
  268. package/test/payments.utils.ts +1 -1
  269. package/test/psbt.spec.ts +250 -64
  270. package/test/script_signature.spec.ts +1 -1
  271. package/test/transaction.spec.ts +18 -5
  272. package/test/tsconfig.json +6 -20
  273. package/test/workers-pool.spec.ts +65 -23
  274. package/test/workers-sequential.spec.ts +669 -0
  275. package/test/workers-signing.spec.ts +7 -3
  276. package/test/workers-worklet.spec.ts +500 -0
  277. package/test/workers.spec.ts +6 -7
  278. package/typedoc.json +11 -1
  279. package/vite.config.browser.ts +31 -6
  280. package/vitest.config.browser.ts +68 -0
  281. package/browser/ecpair.d.ts +0 -99
  282. package/browser/io/MemoryPool.d.ts +0 -220
  283. package/browser/io/MemoryPool.d.ts.map +0 -1
  284. package/build/io/MemoryPool.d.ts +0 -220
  285. package/build/io/MemoryPool.d.ts.map +0 -1
  286. package/build/io/MemoryPool.js +0 -309
  287. package/build/io/MemoryPool.js.map +0 -1
  288. package/src/ecpair.d.ts +0 -99
  289. package/src/io/MemoryPool.ts +0 -343
  290. package/test/taproot-cache.spec.ts +0 -694
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import './env.js';
1
2
  import type {
2
3
  PsbtInput as _PsbtInput,
3
4
  PsbtInputUpdate as _PsbtInputUpdate,
@@ -39,7 +40,41 @@ export * as script from './script.js';
39
40
  export { Block } from './block.js';
40
41
  /** @hidden */
41
42
  export * from './crypto.js';
42
- export * from './psbt.js';
43
+ export {
44
+ Psbt,
45
+ PsbtCache,
46
+ PsbtSigner,
47
+ PsbtFinalizer,
48
+ PsbtTransaction,
49
+ transactionFromBuffer,
50
+ getFinalScripts,
51
+ prepareFinalScripts,
52
+ } from './psbt.js';
53
+ export type {
54
+ TransactionInput,
55
+ PsbtTxInput,
56
+ TransactionOutput,
57
+ PsbtTxOutput,
58
+ ValidateSigFunction,
59
+ PsbtBaseExtended,
60
+ PsbtOptsOptional,
61
+ PsbtOpts,
62
+ PsbtInputExtended,
63
+ PsbtOutputExtended,
64
+ PsbtOutputExtendedScript,
65
+ HDSigner,
66
+ HDSignerAsync,
67
+ Signer,
68
+ SignerAsync,
69
+ TaprootHashCheckSigner,
70
+ PsbtCacheInterface,
71
+ TxCacheNumberKey,
72
+ ScriptType,
73
+ AllScriptType,
74
+ GetScriptReturn,
75
+ FinalScriptsFunc,
76
+ FinalTaprootScriptsFunc,
77
+ } from './psbt.js';
43
78
  /** @hidden */
44
79
  export { opcodes } from './opcodes.js';
45
80
  export { Transaction } from './transaction.js';
@@ -48,7 +83,7 @@ export type { TaprootHashCache } from './transaction.js';
48
83
  export type { Network } from './networks.js';
49
84
  /** @hidden */
50
85
  export { initEccLib, getEccLib, EccContext } from './ecc/context.js';
51
- export type { EccLib } from './ecc/types.js';
86
+ export type { CryptoBackend, EccLib } from './ecc/types.js';
52
87
  export { PaymentType } from './payments/index.js';
53
88
  export type {
54
89
  Payment,
@@ -108,8 +143,6 @@ export {
108
143
  xor,
109
144
  fromUtf8,
110
145
  toUtf8,
111
- MemoryPool,
112
- SimpleMemoryPool,
113
146
  varuint,
114
147
  } from './io/index.js';
115
148
  export * from './payments/bip341.js';
@@ -177,23 +210,26 @@ export const errors = {
177
210
  SignatureError,
178
211
  } as const;
179
212
 
180
- // Worker-based parallel signing
181
- export * as workers from './workers/index.js';
213
+ // Worker-based parallel signing (browser-safe shared exports only)
214
+ // For createSigningPool / detectRuntime, use '@btc-vision/bitcoin/workers' subpath export
215
+ // which routes to the correct platform-specific implementation.
182
216
  export {
183
217
  WorkerSigningPool,
184
218
  getSigningPool,
185
219
  SignatureType,
186
- createSigningPool,
187
220
  signPsbtParallel,
188
- } from './workers/index.js';
221
+ prepareSigningTasks,
222
+ applySignaturesToPsbt,
223
+ } from './workers/index.shared.js';
189
224
  export type {
190
225
  WorkerPoolConfig,
191
226
  SigningTask,
227
+ SigningPoolLike,
192
228
  ParallelSignerKeyPair,
193
229
  ParallelSigningResult,
194
230
  ParallelSignOptions,
195
231
  PsbtParallelKeyPair,
196
- } from './workers/index.js';
232
+ } from './workers/index.shared.js';
197
233
 
198
234
  const bitcoin = {
199
235
  networks,
package/src/io/hex.ts CHANGED
@@ -49,7 +49,8 @@ const HEX_TO_NIBBLE: readonly number[] = (() => {
49
49
  export function toHex(bytes: Uint8Array): string {
50
50
  let result = '';
51
51
  for (let i = 0; i < bytes.length; i++) {
52
- result += BYTE_TO_HEX[bytes[i]!];
52
+ const hex = BYTE_TO_HEX[bytes[i] as number];
53
+ result += hex as string;
53
54
  }
54
55
  return result;
55
56
  }
package/src/io/index.ts CHANGED
@@ -34,8 +34,5 @@ export {
34
34
  toUtf8,
35
35
  } from './utils.js';
36
36
 
37
- // Memory pools
38
- export { MemoryPool, SimpleMemoryPool } from './MemoryPool.js';
39
-
40
37
  // Re-export varuint for Bitcoin CompactSize encoding
41
38
  export { varuint };
package/src/opcodes.ts CHANGED
@@ -273,8 +273,25 @@ export const opcodes: Opcodes = {
273
273
  OP_INVALIDOPCODE: 255,
274
274
  };
275
275
 
276
- export const REVERSE_OPS: { [key: number]: string } = {};
277
- for (const op of Object.keys(opcodes)) {
278
- const code = opcodes[op as keyof Opcodes];
279
- REVERSE_OPS[code] = op;
276
+ let _reverseOps: { [key: number]: string } | undefined;
277
+
278
+ /**
279
+ * Returns the reverse mapping from opcode number to opcode name.
280
+ * Lazily computed on first call.
281
+ */
282
+ export function getReverseOps(): { [key: number]: string } {
283
+ if (!_reverseOps) {
284
+ _reverseOps = {};
285
+ for (const op of Object.keys(opcodes)) {
286
+ const code = opcodes[op as keyof Opcodes];
287
+ _reverseOps[code] = op;
288
+ }
289
+ }
290
+ return _reverseOps;
280
291
  }
292
+
293
+ /**
294
+ * @deprecated Use {@link getReverseOps}() for lazy initialization.
295
+ * This eagerly-initialized alias exists for backward compatibility.
296
+ */
297
+ export const REVERSE_OPS: { [key: number]: string } = getReverseOps();
@@ -104,11 +104,11 @@ export function tapleafHash(leaf: Tapleaf): Bytes32 {
104
104
  return bcrypto.taggedHash(
105
105
  'TapLeaf',
106
106
  concat([new Uint8Array([version]), serializeScript(leaf.output)]),
107
- ) as Bytes32;
107
+ );
108
108
  }
109
109
 
110
110
  export function tapTweakHash(pubKey: XOnlyPublicKey, h: Bytes32 | undefined): Bytes32 {
111
- return bcrypto.taggedHash('TapTweak', h ? concat([pubKey, h]) : pubKey) as Bytes32;
111
+ return bcrypto.taggedHash('TapTweak', h ? concat([pubKey, h]) : pubKey);
112
112
  }
113
113
 
114
114
  export function tweakKey(pubKey: XOnlyPublicKey, h: Bytes32 | undefined): TweakedPublicKey | null {
@@ -128,7 +128,7 @@ export function tweakKey(pubKey: XOnlyPublicKey, h: Bytes32 | undefined): Tweake
128
128
  }
129
129
 
130
130
  function tapBranchHash(a: Uint8Array, b: Uint8Array): Bytes32 {
131
- return bcrypto.taggedHash('TapBranch', concat([a, b])) as Bytes32;
131
+ return bcrypto.taggedHash('TapBranch', concat([a, b]));
132
132
  }
133
133
 
134
134
  function serializeScript(s: Uint8Array): Uint8Array {
@@ -199,7 +199,7 @@ export class Embed {
199
199
  if (!this.#inputData) {
200
200
  return undefined;
201
201
  }
202
- return bscript.compile(([OPS.OP_RETURN] as Stack).concat(this.#inputData)) as Script;
202
+ return bscript.compile(([OPS.OP_RETURN] as Stack).concat(this.#inputData));
203
203
  }
204
204
 
205
205
  #validate(): void {
@@ -377,7 +377,7 @@ export class P2MS {
377
377
  }
378
378
  return bscript.compile(
379
379
  ([] as Stack).concat(OP_INT_BASE + m, pubkeys, OP_INT_BASE + n, OPS.OP_CHECKMULTISIG),
380
- ) as Script;
380
+ );
381
381
  }
382
382
 
383
383
  #computeInput(): Script | undefined {
@@ -387,7 +387,7 @@ export class P2MS {
387
387
  if (!this.#inputSignatures) {
388
388
  return undefined;
389
389
  }
390
- return bscript.compile(([OPS.OP_0] as Stack).concat(this.#inputSignatures)) as Script;
390
+ return bscript.compile(([OPS.OP_0] as Stack).concat(this.#inputSignatures));
391
391
  }
392
392
 
393
393
  // Validation
@@ -285,7 +285,7 @@ export class P2PK {
285
285
  }
286
286
  const pubkey = this.#inputPubkey;
287
287
  if (pubkey) {
288
- return bscript.compile([pubkey, OPS.OP_CHECKSIG]) as Script;
288
+ return bscript.compile([pubkey, OPS.OP_CHECKSIG]);
289
289
  }
290
290
  return undefined;
291
291
  }
@@ -296,7 +296,7 @@ export class P2PK {
296
296
  }
297
297
  const signature = this.#inputSignature;
298
298
  if (signature) {
299
- return bscript.compile([signature]) as Script;
299
+ return bscript.compile([signature]);
300
300
  }
301
301
  return undefined;
302
302
  }
@@ -374,7 +374,7 @@ export class P2PKH {
374
374
  // Use the pubkey getter to derive pubkey from input if available
375
375
  const pk = this.pubkey;
376
376
  if (pk) {
377
- return bcrypto.hash160(pk) as Bytes20;
377
+ return bcrypto.hash160(pk);
378
378
  }
379
379
  return undefined;
380
380
  }
@@ -418,7 +418,7 @@ export class P2PKH {
418
418
  h,
419
419
  OPS.OP_EQUALVERIFY,
420
420
  OPS.OP_CHECKSIG,
421
- ]) as Script;
421
+ ]);
422
422
  }
423
423
 
424
424
  #computeInput(): Script | undefined {
@@ -441,7 +441,7 @@ export class P2PKH {
441
441
  }
442
442
  }
443
443
 
444
- return bscript.compile([this.#inputSignature, pubKey]) as Script;
444
+ return bscript.compile([this.#inputSignature, pubKey]);
445
445
  }
446
446
 
447
447
  // Validation
@@ -336,7 +336,7 @@ export class P2SH {
336
336
  output: (lastChunk === OPS.OP_FALSE
337
337
  ? new Uint8Array(0)
338
338
  : (lastChunk as Uint8Array)) as Script,
339
- input: bscript.compile(chunks.slice(0, -1)) as Script,
339
+ input: bscript.compile(chunks.slice(0, -1)),
340
340
  witness: this.#inputWitness || [],
341
341
  };
342
342
  }
@@ -370,7 +370,7 @@ export class P2SH {
370
370
  }
371
371
  const r = this.redeem;
372
372
  if (r && r.output) {
373
- return bcrypto.hash160(r.output) as Bytes20;
373
+ return bcrypto.hash160(r.output);
374
374
  }
375
375
  return undefined;
376
376
  }
@@ -382,7 +382,7 @@ export class P2SH {
382
382
  const h = this.hash;
383
383
  if (!h) return undefined;
384
384
 
385
- return bscript.compile([OPS.OP_HASH160, h, OPS.OP_EQUAL]) as Script;
385
+ return bscript.compile([OPS.OP_HASH160, h, OPS.OP_EQUAL]);
386
386
  }
387
387
 
388
388
  #computeInput(): Script | undefined {
@@ -395,7 +395,7 @@ export class P2SH {
395
395
  }
396
396
  return bscript.compile(
397
397
  ([] as Stack).concat(bscript.decompile(r.input) as Stack, r.output),
398
- ) as Script;
398
+ );
399
399
  }
400
400
 
401
401
  #computeRedeem(): ScriptRedeem | undefined {
@@ -9,11 +9,11 @@
9
9
 
10
10
  import { bech32m } from 'bech32';
11
11
  import { fromBech32 } from '../bech32utils.js';
12
- import { getEccLib } from '../ecc/context.js';
13
12
  import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
14
13
  import * as bscript from '../script.js';
15
14
  import {
16
15
  type Bytes32,
16
+ isXOnlyPublicKey,
17
17
  type SchnorrSignature,
18
18
  type Script,
19
19
  stacksEqual,
@@ -459,7 +459,7 @@ export class P2TR {
459
459
  if (internalPk) {
460
460
  const tweakedKey = tweakKey(internalPk, this.hash);
461
461
  if (tweakedKey) {
462
- return tweakedKey.x as XOnlyPublicKey;
462
+ return tweakedKey.x;
463
463
  }
464
464
  }
465
465
  return undefined;
@@ -479,7 +479,7 @@ export class P2TR {
479
479
  #computeHash(): Bytes32 | undefined {
480
480
  const hashTree = this.#getHashTree();
481
481
  if (hashTree) {
482
- return hashTree.hash as Bytes32;
482
+ return hashTree.hash;
483
483
  }
484
484
 
485
485
  const w = this.#getWitnessWithoutAnnex();
@@ -491,7 +491,7 @@ export class P2TR {
491
491
  output: script,
492
492
  version: leafVersion,
493
493
  });
494
- return rootHashFromPath(controlBlock, leafHash) as Bytes32;
494
+ return rootHashFromPath(controlBlock, leafHash);
495
495
  }
496
496
 
497
497
  return undefined;
@@ -515,7 +515,7 @@ export class P2TR {
515
515
  const pk = this.pubkey;
516
516
  if (!pk) return undefined;
517
517
 
518
- return bscript.compile([OPS.OP_1, pk]) as Script;
518
+ return bscript.compile([OPS.OP_1, pk]);
519
519
  }
520
520
 
521
521
  #computeRedeem(): ScriptRedeem | undefined {
@@ -688,7 +688,7 @@ export class P2TR {
688
688
  if (witness && witness.length > 0) {
689
689
  if (witness.length === 1) {
690
690
  // Key-path spending
691
- if (this.#inputSignature && !equals(this.#inputSignature!, witness[0]!)) {
691
+ if (this.#inputSignature && !equals(this.#inputSignature, witness[0]!)) {
692
692
  throw new TypeError('Signature mismatch');
693
693
  }
694
694
  } else {
@@ -712,11 +712,11 @@ export class P2TR {
712
712
  }
713
713
 
714
714
  const internalPk = controlBlock.subarray(1, 33);
715
- if (this.#inputInternalPubkey && !equals(this.#inputInternalPubkey!, internalPk)) {
715
+ if (this.#inputInternalPubkey && !equals(this.#inputInternalPubkey, internalPk)) {
716
716
  throw new TypeError('Internal pubkey mismatch');
717
717
  }
718
718
 
719
- if (!getEccLib().isXOnlyPoint(internalPk)) {
719
+ if (!isXOnlyPublicKey(internalPk)) {
720
720
  throw new TypeError('Invalid internalPubkey for p2tr witness');
721
721
  }
722
722
 
@@ -729,7 +729,7 @@ export class P2TR {
729
729
  });
730
730
  const computedHash = rootHashFromPath(controlBlock, leafHash);
731
731
 
732
- const outputKey = tweakKey(internalPk as XOnlyPublicKey, computedHash);
732
+ const outputKey = tweakKey(internalPk, computedHash);
733
733
  if (!outputKey) {
734
734
  throw new TypeError('Invalid outputKey for p2tr witness');
735
735
  }
@@ -341,7 +341,7 @@ export class P2WPKH {
341
341
  }
342
342
  const pk = this.#inputPubkey ?? this.pubkey;
343
343
  if (pk) {
344
- return bcrypto.hash160(pk) as Bytes20;
344
+ return bcrypto.hash160(pk);
345
345
  }
346
346
  return undefined;
347
347
  }
@@ -373,7 +373,7 @@ export class P2WPKH {
373
373
  const h = this.hash;
374
374
  if (!h) return undefined;
375
375
 
376
- return bscript.compile([OPS.OP_0, h]) as Script;
376
+ return bscript.compile([OPS.OP_0, h]);
377
377
  }
378
378
 
379
379
  #computeInput(): Uint8Array | undefined {
@@ -457,14 +457,14 @@ export class P2WPKH {
457
457
  if (!bscript.isCanonicalScriptSignature(this.#inputWitness[0]!)) {
458
458
  throw new TypeError('Witness has invalid signature');
459
459
  }
460
- if (!isPoint(this.#inputWitness[1]!) || this.#inputWitness[1]!.length !== 33) {
460
+ if (!isPoint(this.#inputWitness[1]!) || this.#inputWitness[1].length !== 33) {
461
461
  throw new TypeError('Witness has invalid pubkey');
462
462
  }
463
463
 
464
- if (this.#inputSignature && !equals(this.#inputSignature!, this.#inputWitness[0]!)) {
464
+ if (this.#inputSignature && !equals(this.#inputSignature, this.#inputWitness[0]!)) {
465
465
  throw new TypeError('Signature mismatch');
466
466
  }
467
- if (this.#inputPubkey && !equals(this.#inputPubkey!, this.#inputWitness[1]!)) {
467
+ if (this.#inputPubkey && !equals(this.#inputPubkey, this.#inputWitness[1])) {
468
468
  throw new TypeError('Pubkey mismatch');
469
469
  }
470
470
 
@@ -352,7 +352,7 @@ export class P2WSH {
352
352
  }
353
353
  const r = this.redeem;
354
354
  if (r && r.output) {
355
- return bcrypto.sha256(r.output) as Bytes32;
355
+ return bcrypto.sha256(r.output);
356
356
  }
357
357
  return undefined;
358
358
  }
@@ -364,7 +364,7 @@ export class P2WSH {
364
364
  const h = this.hash;
365
365
  if (!h) return undefined;
366
366
 
367
- return bscript.compile([OPS.OP_0, h]) as Script;
367
+ return bscript.compile([OPS.OP_0, h]);
368
368
  }
369
369
 
370
370
  #computeInput(): Uint8Array | undefined {