@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.
- package/README.md +455 -155
- package/browser/address.d.ts +5 -1
- package/browser/address.d.ts.map +1 -1
- package/browser/branded.d.ts +3 -14
- package/browser/branded.d.ts.map +1 -1
- package/browser/chunks/psbt-parallel-BBFlkmiv.js +10717 -0
- package/browser/ecc/context.d.ts +22 -21
- package/browser/ecc/context.d.ts.map +1 -1
- package/browser/ecc/index.d.ts +1 -1
- package/browser/ecc/index.d.ts.map +1 -1
- package/browser/ecc/types.d.ts +10 -123
- package/browser/ecc/types.d.ts.map +1 -1
- package/browser/env.d.ts +13 -0
- package/browser/env.d.ts.map +1 -0
- package/browser/index.d.ts +6 -6
- package/browser/index.d.ts.map +1 -1
- package/browser/index.js +2602 -11786
- package/browser/io/hex.d.ts.map +1 -1
- package/browser/io/index.d.ts +0 -1
- package/browser/io/index.d.ts.map +1 -1
- package/browser/opcodes.d.ts +11 -0
- package/browser/opcodes.d.ts.map +1 -1
- package/browser/payments/p2tr.d.ts.map +1 -1
- package/browser/psbt/PsbtCache.d.ts +54 -0
- package/browser/psbt/PsbtCache.d.ts.map +1 -0
- package/browser/psbt/PsbtFinalizer.d.ts +21 -0
- package/browser/psbt/PsbtFinalizer.d.ts.map +1 -0
- package/browser/psbt/PsbtSigner.d.ts +32 -0
- package/browser/psbt/PsbtSigner.d.ts.map +1 -0
- package/browser/psbt/PsbtTransaction.d.ts +25 -0
- package/browser/psbt/PsbtTransaction.d.ts.map +1 -0
- package/browser/psbt/types.d.ts +4 -70
- package/browser/psbt/types.d.ts.map +1 -1
- package/browser/psbt/validation.d.ts +1 -1
- package/browser/psbt/validation.d.ts.map +1 -1
- package/browser/psbt.d.ts +26 -40
- package/browser/psbt.d.ts.map +1 -1
- package/browser/script.d.ts.map +1 -1
- package/browser/transaction.d.ts +4 -4
- package/browser/transaction.d.ts.map +1 -1
- package/browser/types.d.ts +5 -3
- package/browser/types.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.d.ts +7 -0
- package/browser/workers/WorkerSigningPool.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.node.d.ts +7 -0
- package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.sequential.d.ts +67 -0
- package/browser/workers/WorkerSigningPool.sequential.d.ts.map +1 -0
- package/browser/workers/WorkerSigningPool.worklet.d.ts +64 -0
- package/browser/workers/WorkerSigningPool.worklet.d.ts.map +1 -0
- package/browser/workers/index.browser.d.ts +16 -0
- package/browser/workers/index.browser.d.ts.map +1 -0
- package/browser/workers/index.d.ts +4 -64
- package/browser/workers/index.d.ts.map +1 -1
- package/browser/workers/index.js +28 -0
- package/browser/workers/index.node.d.ts +17 -0
- package/browser/workers/index.node.d.ts.map +1 -0
- package/browser/workers/index.react-native.d.ts +28 -0
- package/browser/workers/index.react-native.d.ts.map +1 -0
- package/browser/workers/index.shared.d.ts +15 -0
- package/browser/workers/index.shared.d.ts.map +1 -0
- package/browser/workers/psbt-parallel.d.ts +2 -3
- package/browser/workers/psbt-parallel.d.ts.map +1 -1
- package/browser/workers/types.d.ts +17 -0
- package/browser/workers/types.d.ts.map +1 -1
- package/build/address.d.ts +5 -1
- package/build/address.d.ts.map +1 -1
- package/build/address.js +29 -17
- package/build/address.js.map +1 -1
- package/build/bech32utils.js.map +1 -1
- package/build/block.js.map +1 -1
- package/build/branded.d.ts +3 -14
- package/build/branded.d.ts.map +1 -1
- package/build/branded.js +0 -5
- package/build/branded.js.map +1 -1
- package/build/ecc/context.d.ts +22 -21
- package/build/ecc/context.d.ts.map +1 -1
- package/build/ecc/context.js +23 -95
- package/build/ecc/context.js.map +1 -1
- package/build/ecc/index.d.ts +1 -1
- package/build/ecc/index.d.ts.map +1 -1
- package/build/ecc/types.d.ts +7 -126
- package/build/ecc/types.d.ts.map +1 -1
- package/build/ecc/types.js +4 -1
- package/build/ecc/types.js.map +1 -1
- package/build/env.d.ts +13 -0
- package/build/env.d.ts.map +1 -0
- package/build/env.js +198 -0
- package/build/env.js.map +1 -0
- package/build/index.d.ts +7 -6
- package/build/index.d.ts.map +1 -1
- package/build/index.js +7 -5
- package/build/index.js.map +1 -1
- package/build/io/hex.d.ts.map +1 -1
- package/build/io/hex.js +2 -1
- package/build/io/hex.js.map +1 -1
- package/build/io/index.d.ts +0 -1
- package/build/io/index.d.ts.map +1 -1
- package/build/io/index.js +0 -2
- package/build/io/index.js.map +1 -1
- package/build/opcodes.d.ts +11 -0
- package/build/opcodes.d.ts.map +1 -1
- package/build/opcodes.js +19 -4
- package/build/opcodes.js.map +1 -1
- package/build/payments/bip341.js.map +1 -1
- package/build/payments/embed.js.map +1 -1
- package/build/payments/p2ms.js.map +1 -1
- package/build/payments/p2pk.js.map +1 -1
- package/build/payments/p2pkh.js.map +1 -1
- package/build/payments/p2sh.js.map +1 -1
- package/build/payments/p2tr.d.ts.map +1 -1
- package/build/payments/p2tr.js +2 -3
- package/build/payments/p2tr.js.map +1 -1
- package/build/payments/p2wpkh.js.map +1 -1
- package/build/payments/p2wsh.js.map +1 -1
- package/build/psbt/PsbtCache.d.ts +54 -0
- package/build/psbt/PsbtCache.d.ts.map +1 -0
- package/build/psbt/PsbtCache.js +249 -0
- package/build/psbt/PsbtCache.js.map +1 -0
- package/build/psbt/PsbtFinalizer.d.ts +21 -0
- package/build/psbt/PsbtFinalizer.d.ts.map +1 -0
- package/build/psbt/PsbtFinalizer.js +157 -0
- package/build/psbt/PsbtFinalizer.js.map +1 -0
- package/build/psbt/PsbtSigner.d.ts +32 -0
- package/build/psbt/PsbtSigner.d.ts.map +1 -0
- package/build/psbt/PsbtSigner.js +192 -0
- package/build/psbt/PsbtSigner.js.map +1 -0
- package/build/psbt/PsbtTransaction.d.ts +25 -0
- package/build/psbt/PsbtTransaction.d.ts.map +1 -0
- package/build/psbt/PsbtTransaction.js +61 -0
- package/build/psbt/PsbtTransaction.js.map +1 -0
- package/build/psbt/types.d.ts +4 -70
- package/build/psbt/types.d.ts.map +1 -1
- package/build/psbt/validation.d.ts +1 -1
- package/build/psbt/validation.d.ts.map +1 -1
- package/build/psbt.d.ts +26 -40
- package/build/psbt.d.ts.map +1 -1
- package/build/psbt.js +177 -799
- package/build/psbt.js.map +1 -1
- package/build/script.d.ts.map +1 -1
- package/build/script.js +2 -2
- package/build/script.js.map +1 -1
- package/build/transaction.d.ts +4 -4
- package/build/transaction.d.ts.map +1 -1
- package/build/transaction.js +5 -4
- package/build/transaction.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/types.d.ts +5 -3
- package/build/types.d.ts.map +1 -1
- package/build/types.js +11 -16
- package/build/types.js.map +1 -1
- package/build/workers/WorkerSigningPool.d.ts +7 -0
- package/build/workers/WorkerSigningPool.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.js +12 -1
- package/build/workers/WorkerSigningPool.js.map +1 -1
- package/build/workers/WorkerSigningPool.node.d.ts +7 -0
- package/build/workers/WorkerSigningPool.node.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.node.js +37 -5
- package/build/workers/WorkerSigningPool.node.js.map +1 -1
- package/build/workers/WorkerSigningPool.sequential.d.ts +76 -0
- package/build/workers/WorkerSigningPool.sequential.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.sequential.js +160 -0
- package/build/workers/WorkerSigningPool.sequential.js.map +1 -0
- package/build/workers/WorkerSigningPool.worklet.d.ts +79 -0
- package/build/workers/WorkerSigningPool.worklet.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.worklet.js +390 -0
- package/build/workers/WorkerSigningPool.worklet.js.map +1 -0
- package/build/workers/index.browser.d.ts +24 -0
- package/build/workers/index.browser.d.ts.map +1 -0
- package/build/workers/index.browser.js +30 -0
- package/build/workers/index.browser.js.map +1 -0
- package/build/workers/index.d.ts +6 -18
- package/build/workers/index.d.ts.map +1 -1
- package/build/workers/index.js +12 -14
- package/build/workers/index.js.map +1 -1
- package/build/workers/index.node.d.ts +38 -0
- package/build/workers/index.node.d.ts.map +1 -0
- package/build/workers/index.node.js +45 -0
- package/build/workers/index.node.js.map +1 -0
- package/build/workers/index.react-native.d.ts +28 -0
- package/build/workers/index.react-native.d.ts.map +1 -0
- package/build/workers/index.react-native.js +67 -0
- package/build/workers/index.react-native.js.map +1 -0
- package/build/workers/index.shared.d.ts +15 -0
- package/build/workers/index.shared.d.ts.map +1 -0
- package/build/workers/index.shared.js +20 -0
- package/build/workers/index.shared.js.map +1 -0
- package/build/workers/psbt-parallel.d.ts +2 -3
- package/build/workers/psbt-parallel.d.ts.map +1 -1
- package/build/workers/psbt-parallel.js +4 -4
- package/build/workers/psbt-parallel.js.map +1 -1
- package/build/workers/types.d.ts +17 -0
- package/build/workers/types.d.ts.map +1 -1
- package/package.json +46 -8
- package/src/address.ts +41 -18
- package/src/bech32utils.ts +3 -3
- package/src/block.ts +2 -2
- package/src/branded.ts +15 -13
- package/src/ecc/context.ts +30 -133
- package/src/ecc/index.ts +2 -2
- package/src/ecc/types.ts +7 -138
- package/src/env.ts +239 -0
- package/src/index.ts +45 -9
- package/src/io/hex.ts +2 -1
- package/src/io/index.ts +0 -3
- package/src/opcodes.ts +21 -4
- package/src/payments/bip341.ts +3 -3
- package/src/payments/embed.ts +1 -1
- package/src/payments/p2ms.ts +2 -2
- package/src/payments/p2pk.ts +2 -2
- package/src/payments/p2pkh.ts +3 -3
- package/src/payments/p2sh.ts +4 -4
- package/src/payments/p2tr.ts +9 -9
- package/src/payments/p2wpkh.ts +5 -5
- package/src/payments/p2wsh.ts +2 -2
- package/src/psbt/PsbtCache.ts +325 -0
- package/src/psbt/PsbtFinalizer.ts +213 -0
- package/src/psbt/PsbtSigner.ts +302 -0
- package/src/psbt/PsbtTransaction.ts +82 -0
- package/src/psbt/types.ts +4 -86
- package/src/psbt/validation.ts +1 -1
- package/src/psbt.ts +349 -1198
- package/src/script.ts +2 -2
- package/src/transaction.ts +10 -9
- package/src/types.ts +18 -28
- package/src/workers/WorkerSigningPool.node.ts +41 -5
- package/src/workers/WorkerSigningPool.sequential.ts +191 -0
- package/src/workers/WorkerSigningPool.ts +14 -1
- package/src/workers/WorkerSigningPool.worklet.ts +522 -0
- package/src/workers/index.browser.ts +34 -0
- package/src/workers/index.node.ts +50 -0
- package/src/workers/index.react-native.ts +110 -0
- package/src/workers/index.shared.ts +58 -0
- package/src/workers/index.ts +14 -65
- package/src/workers/psbt-parallel.ts +7 -7
- package/src/workers/types.ts +21 -0
- package/test/address.spec.ts +2 -2
- package/test/bitcoin.core.spec.ts +5 -2
- package/test/browser/payments.spec.ts +151 -0
- package/test/browser/psbt.spec.ts +1510 -0
- package/test/browser/script.spec.ts +223 -0
- package/test/browser/setup.ts +13 -0
- package/test/browser/workers-signing.spec.ts +537 -0
- package/test/crypto.spec.ts +2 -2
- package/test/env.spec.ts +418 -0
- package/test/fixtures/core/base58_encode_decode.json +12 -48
- package/test/fixtures/core/base58_keys_invalid.json +50 -150
- package/test/fixtures/core/sighash.json +1 -3
- package/test/fixtures/core/tx_valid.json +133 -501
- package/test/fixtures/embed.json +3 -11
- package/test/fixtures/p2ms.json +21 -91
- package/test/fixtures/p2pk.json +5 -24
- package/test/fixtures/p2pkh.json +7 -36
- package/test/fixtures/p2sh.json +8 -54
- package/test/fixtures/p2tr.json +2 -6
- package/test/fixtures/p2wpkh.json +7 -36
- package/test/fixtures/p2wsh.json +14 -59
- package/test/fixtures/psbt.json +2 -6
- package/test/fixtures/script.json +12 -48
- package/test/integration/addresses.spec.ts +11 -5
- package/test/integration/bip32.spec.ts +1 -1
- package/test/integration/cltv.spec.ts +10 -6
- package/test/integration/csv.spec.ts +10 -9
- package/test/integration/payments.spec.ts +8 -4
- package/test/integration/taproot.spec.ts +26 -6
- package/test/integration/transactions.spec.ts +22 -8
- package/test/payments.spec.ts +1 -1
- package/test/payments.utils.ts +1 -1
- package/test/psbt.spec.ts +250 -64
- package/test/script_signature.spec.ts +1 -1
- package/test/transaction.spec.ts +18 -5
- package/test/tsconfig.json +6 -20
- package/test/workers-pool.spec.ts +65 -23
- package/test/workers-sequential.spec.ts +669 -0
- package/test/workers-signing.spec.ts +7 -3
- package/test/workers-worklet.spec.ts +500 -0
- package/test/workers.spec.ts +6 -7
- package/typedoc.json +11 -1
- package/vite.config.browser.ts +31 -6
- package/vitest.config.browser.ts +68 -0
- package/browser/ecpair.d.ts +0 -99
- package/browser/io/MemoryPool.d.ts +0 -220
- package/browser/io/MemoryPool.d.ts.map +0 -1
- package/build/io/MemoryPool.d.ts +0 -220
- package/build/io/MemoryPool.d.ts.map +0 -1
- package/build/io/MemoryPool.js +0 -309
- package/build/io/MemoryPool.js.map +0 -1
- package/src/ecpair.d.ts +0 -99
- package/src/io/MemoryPool.ts +0 -343
- 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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
package/src/opcodes.ts
CHANGED
|
@@ -273,8 +273,25 @@ export const opcodes: Opcodes = {
|
|
|
273
273
|
OP_INVALIDOPCODE: 255,
|
|
274
274
|
};
|
|
275
275
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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();
|
package/src/payments/bip341.ts
CHANGED
|
@@ -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
|
-
)
|
|
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)
|
|
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]))
|
|
131
|
+
return bcrypto.taggedHash('TapBranch', concat([a, b]));
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
function serializeScript(s: Uint8Array): Uint8Array {
|
package/src/payments/embed.ts
CHANGED
|
@@ -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))
|
|
202
|
+
return bscript.compile(([OPS.OP_RETURN] as Stack).concat(this.#inputData));
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
#validate(): void {
|
package/src/payments/p2ms.ts
CHANGED
|
@@ -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
|
-
)
|
|
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))
|
|
390
|
+
return bscript.compile(([OPS.OP_0] as Stack).concat(this.#inputSignatures));
|
|
391
391
|
}
|
|
392
392
|
|
|
393
393
|
// Validation
|
package/src/payments/p2pk.ts
CHANGED
|
@@ -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])
|
|
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])
|
|
299
|
+
return bscript.compile([signature]);
|
|
300
300
|
}
|
|
301
301
|
return undefined;
|
|
302
302
|
}
|
package/src/payments/p2pkh.ts
CHANGED
|
@@ -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)
|
|
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
|
-
])
|
|
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])
|
|
444
|
+
return bscript.compile([this.#inputSignature, pubKey]);
|
|
445
445
|
}
|
|
446
446
|
|
|
447
447
|
// Validation
|
package/src/payments/p2sh.ts
CHANGED
|
@@ -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))
|
|
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)
|
|
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])
|
|
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
|
-
)
|
|
398
|
+
);
|
|
399
399
|
}
|
|
400
400
|
|
|
401
401
|
#computeRedeem(): ScriptRedeem | undefined {
|
package/src/payments/p2tr.ts
CHANGED
|
@@ -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
|
|
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
|
|
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)
|
|
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])
|
|
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
|
|
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
|
|
715
|
+
if (this.#inputInternalPubkey && !equals(this.#inputInternalPubkey, internalPk)) {
|
|
716
716
|
throw new TypeError('Internal pubkey mismatch');
|
|
717
717
|
}
|
|
718
718
|
|
|
719
|
-
if (!
|
|
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
|
|
732
|
+
const outputKey = tweakKey(internalPk, computedHash);
|
|
733
733
|
if (!outputKey) {
|
|
734
734
|
throw new TypeError('Invalid outputKey for p2tr witness');
|
|
735
735
|
}
|
package/src/payments/p2wpkh.ts
CHANGED
|
@@ -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)
|
|
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])
|
|
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]
|
|
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
|
|
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
|
|
467
|
+
if (this.#inputPubkey && !equals(this.#inputPubkey, this.#inputWitness[1])) {
|
|
468
468
|
throw new TypeError('Pubkey mismatch');
|
|
469
469
|
}
|
|
470
470
|
|
package/src/payments/p2wsh.ts
CHANGED
|
@@ -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)
|
|
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])
|
|
367
|
+
return bscript.compile([OPS.OP_0, h]);
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
#computeInput(): Uint8Array | undefined {
|