@btc-vision/bitcoin 7.0.0-alpha.0 → 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 +6 -2
- package/browser/address.d.ts.map +1 -1
- package/browser/block.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/crypto.d.ts +1 -1
- package/browser/ecc/context.d.ts +25 -24
- 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 +7 -7
- package/browser/index.d.ts.map +1 -1
- package/browser/index.js +2497 -11686
- package/browser/io/BinaryReader.d.ts +15 -15
- package/browser/io/BinaryReader.d.ts.map +1 -1
- package/browser/io/BinaryWriter.d.ts +17 -17
- package/browser/io/BinaryWriter.d.ts.map +1 -1
- 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/bip341.d.ts +1 -1
- package/browser/payments/bip341.d.ts.map +1 -1
- package/browser/payments/embed.d.ts +1 -1
- package/browser/payments/embed.d.ts.map +1 -1
- package/browser/payments/p2ms.d.ts.map +1 -1
- package/browser/payments/p2op.d.ts +1 -1
- package/browser/payments/p2op.d.ts.map +1 -1
- package/browser/payments/p2pk.d.ts +1 -1
- package/browser/payments/p2pk.d.ts.map +1 -1
- package/browser/payments/p2pkh.d.ts +1 -1
- package/browser/payments/p2pkh.d.ts.map +1 -1
- package/browser/payments/p2sh.d.ts.map +1 -1
- package/browser/payments/p2tr.d.ts +2 -2
- package/browser/payments/p2tr.d.ts.map +1 -1
- package/browser/payments/p2wpkh.d.ts +1 -1
- package/browser/payments/p2wpkh.d.ts.map +1 -1
- package/browser/payments/p2wsh.d.ts.map +1 -1
- package/browser/payments/types.d.ts +1 -1
- package/browser/payments/types.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/bip371.d.ts.map +1 -1
- package/browser/psbt/types.d.ts +5 -71
- 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 +24 -17
- package/browser/workers/WorkerSigningPool.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.node.d.ts +19 -12
- 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 +6 -2
- package/build/address.d.ts.map +1 -1
- package/build/address.js +32 -19
- package/build/address.js.map +1 -1
- package/build/bech32utils.js.map +1 -1
- package/build/block.d.ts.map +1 -1
- package/build/block.js +2 -4
- 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/crypto.d.ts +1 -1
- package/build/ecc/context.d.ts +25 -24
- package/build/ecc/context.d.ts.map +1 -1
- package/build/ecc/context.js +29 -101
- 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 +8 -7
- package/build/index.d.ts.map +1 -1
- package/build/index.js +9 -7
- package/build/index.js.map +1 -1
- package/build/io/BinaryReader.d.ts +15 -15
- package/build/io/BinaryReader.d.ts.map +1 -1
- package/build/io/BinaryReader.js +17 -17
- package/build/io/BinaryReader.js.map +1 -1
- package/build/io/BinaryWriter.d.ts +17 -17
- package/build/io/BinaryWriter.d.ts.map +1 -1
- package/build/io/BinaryWriter.js +39 -39
- package/build/io/BinaryWriter.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.d.ts +1 -2
- package/build/payments/bip341.d.ts.map +1 -1
- package/build/payments/bip341.js +1 -2
- package/build/payments/bip341.js.map +1 -1
- package/build/payments/embed.d.ts +1 -1
- package/build/payments/embed.d.ts.map +1 -1
- package/build/payments/embed.js +14 -14
- package/build/payments/embed.js.map +1 -1
- package/build/payments/p2ms.d.ts.map +1 -1
- package/build/payments/p2ms.js +21 -21
- package/build/payments/p2ms.js.map +1 -1
- package/build/payments/p2op.d.ts +1 -1
- package/build/payments/p2op.d.ts.map +1 -1
- package/build/payments/p2op.js +18 -18
- package/build/payments/p2op.js.map +1 -1
- package/build/payments/p2pk.d.ts +1 -1
- package/build/payments/p2pk.d.ts.map +1 -1
- package/build/payments/p2pk.js +17 -17
- package/build/payments/p2pk.js.map +1 -1
- package/build/payments/p2pkh.d.ts +1 -1
- package/build/payments/p2pkh.d.ts.map +1 -1
- package/build/payments/p2pkh.js +20 -20
- package/build/payments/p2pkh.js.map +1 -1
- package/build/payments/p2sh.d.ts.map +1 -1
- package/build/payments/p2sh.js +22 -20
- package/build/payments/p2sh.js.map +1 -1
- package/build/payments/p2tr.d.ts +2 -2
- package/build/payments/p2tr.d.ts.map +1 -1
- package/build/payments/p2tr.js +25 -26
- package/build/payments/p2tr.js.map +1 -1
- package/build/payments/p2wpkh.d.ts +1 -1
- package/build/payments/p2wpkh.d.ts.map +1 -1
- package/build/payments/p2wpkh.js +20 -20
- package/build/payments/p2wpkh.js.map +1 -1
- package/build/payments/p2wsh.d.ts.map +1 -1
- package/build/payments/p2wsh.js +22 -22
- package/build/payments/p2wsh.js.map +1 -1
- package/build/payments/types.d.ts +1 -1
- package/build/payments/types.d.ts.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/bip371.d.ts.map +1 -1
- package/build/psbt/bip371.js +6 -2
- package/build/psbt/bip371.js.map +1 -1
- package/build/psbt/psbtutils.js +1 -1
- package/build/psbt/psbtutils.js.map +1 -1
- package/build/psbt/types.d.ts +5 -71
- 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/validation.js +1 -1
- package/build/psbt/validation.js.map +1 -1
- package/build/psbt.d.ts +26 -40
- package/build/psbt.d.ts.map +1 -1
- package/build/psbt.js +180 -808
- package/build/psbt.js.map +1 -1
- package/build/script.d.ts.map +1 -1
- package/build/script.js +4 -4
- 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 +6 -5
- 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 +14 -25
- package/build/types.js.map +1 -1
- package/build/workers/WorkerSigningPool.d.ts +24 -17
- package/build/workers/WorkerSigningPool.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.js +36 -25
- package/build/workers/WorkerSigningPool.js.map +1 -1
- package/build/workers/WorkerSigningPool.node.d.ts +19 -12
- package/build/workers/WorkerSigningPool.node.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.node.js +60 -28
- 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/build/workers/types.js.map +1 -1
- package/package.json +48 -9
- package/src/address.ts +53 -21
- package/src/bech32utils.ts +3 -3
- package/src/block.ts +17 -10
- package/src/branded.ts +15 -13
- package/src/crypto.ts +1 -1
- package/src/ecc/context.ts +36 -136
- package/src/ecc/index.ts +2 -2
- package/src/ecc/types.ts +7 -145
- package/src/env.ts +239 -0
- package/src/index.ts +57 -22
- package/src/io/BinaryReader.ts +18 -18
- package/src/io/BinaryWriter.ts +43 -43
- 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 +5 -7
- package/src/payments/embed.ts +19 -19
- package/src/payments/p2ms.ts +34 -27
- package/src/payments/p2op.ts +22 -22
- package/src/payments/p2pk.ts +22 -22
- package/src/payments/p2pkh.ts +28 -28
- package/src/payments/p2sh.ts +33 -30
- package/src/payments/p2tr.ts +40 -40
- package/src/payments/p2wpkh.ts +30 -30
- package/src/payments/p2wsh.ts +29 -29
- package/src/payments/types.ts +1 -1
- 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/bip371.ts +7 -3
- package/src/psbt/psbtutils.ts +1 -1
- package/src/psbt/types.ts +5 -94
- package/src/psbt/validation.ts +5 -12
- package/src/psbt.ts +376 -1201
- package/src/script.ts +6 -9
- package/src/transaction.ts +19 -15
- package/src/types.ts +33 -45
- package/src/workers/WorkerSigningPool.node.ts +72 -36
- package/src/workers/WorkerSigningPool.sequential.ts +191 -0
- package/src/workers/WorkerSigningPool.ts +48 -39
- 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 +8 -13
- package/src/workers/types.ts +26 -1
- 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 +39 -0
- 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/payments/p2tr.ts
CHANGED
|
@@ -9,29 +9,29 @@
|
|
|
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
|
-
stacksEqual,
|
|
17
|
-
TAPLEAF_VERSION_MASK,
|
|
18
15
|
type Bytes32,
|
|
19
|
-
|
|
16
|
+
isXOnlyPublicKey,
|
|
20
17
|
type SchnorrSignature,
|
|
18
|
+
type Script,
|
|
19
|
+
stacksEqual,
|
|
20
|
+
TAPLEAF_VERSION_MASK,
|
|
21
21
|
type Taptree,
|
|
22
22
|
type XOnlyPublicKey,
|
|
23
23
|
} from '../types.js';
|
|
24
24
|
import {
|
|
25
25
|
findScriptPath,
|
|
26
|
+
type HashTree,
|
|
26
27
|
LEAF_VERSION_TAPSCRIPT,
|
|
27
28
|
rootHashFromPath,
|
|
28
29
|
tapleafHash,
|
|
29
30
|
toHashTree,
|
|
30
31
|
tweakKey,
|
|
31
|
-
type HashTree,
|
|
32
32
|
} from './bip341.js';
|
|
33
33
|
import { concat, equals } from '../io/index.js';
|
|
34
|
-
import {
|
|
34
|
+
import { type P2TRPayment, type PaymentOpts, PaymentType, type ScriptRedeem } from './types.js';
|
|
35
35
|
|
|
36
36
|
const OPS = bscript.opcodes;
|
|
37
37
|
const TAPROOT_WITNESS_VERSION = 0x01;
|
|
@@ -362,6 +362,28 @@ export class P2TR {
|
|
|
362
362
|
|
|
363
363
|
// Private helper methods
|
|
364
364
|
|
|
365
|
+
/**
|
|
366
|
+
* Converts to a plain P2TRPayment object for backwards compatibility.
|
|
367
|
+
*
|
|
368
|
+
* @returns A P2TRPayment object
|
|
369
|
+
*/
|
|
370
|
+
toPayment(): P2TRPayment {
|
|
371
|
+
return {
|
|
372
|
+
name: this.name,
|
|
373
|
+
network: this.network,
|
|
374
|
+
address: this.address,
|
|
375
|
+
pubkey: this.pubkey,
|
|
376
|
+
internalPubkey: this.internalPubkey,
|
|
377
|
+
hash: this.hash,
|
|
378
|
+
scriptTree: this.#inputScriptTree,
|
|
379
|
+
signature: this.signature,
|
|
380
|
+
output: this.output,
|
|
381
|
+
redeem: this.redeem,
|
|
382
|
+
redeemVersion: this.redeemVersion,
|
|
383
|
+
witness: this.witness,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
|
|
365
387
|
#getDecodedAddress(): { version: number; prefix: string; data: Uint8Array } | undefined {
|
|
366
388
|
if (!this.#decodedAddressComputed) {
|
|
367
389
|
if (this.#inputAddress) {
|
|
@@ -397,6 +419,8 @@ export class P2TR {
|
|
|
397
419
|
return this.#witnessWithoutAnnex;
|
|
398
420
|
}
|
|
399
421
|
|
|
422
|
+
// Private computation methods
|
|
423
|
+
|
|
400
424
|
#getHashTree(): HashTree | undefined {
|
|
401
425
|
if (!this.#hashTreeComputed) {
|
|
402
426
|
if (this.#inputScriptTree) {
|
|
@@ -409,8 +433,6 @@ export class P2TR {
|
|
|
409
433
|
return this.#hashTree;
|
|
410
434
|
}
|
|
411
435
|
|
|
412
|
-
// Private computation methods
|
|
413
|
-
|
|
414
436
|
#computeAddress(): string | undefined {
|
|
415
437
|
if (this.#inputAddress) {
|
|
416
438
|
return this.#inputAddress;
|
|
@@ -437,7 +459,7 @@ export class P2TR {
|
|
|
437
459
|
if (internalPk) {
|
|
438
460
|
const tweakedKey = tweakKey(internalPk, this.hash);
|
|
439
461
|
if (tweakedKey) {
|
|
440
|
-
return tweakedKey.x
|
|
462
|
+
return tweakedKey.x;
|
|
441
463
|
}
|
|
442
464
|
}
|
|
443
465
|
return undefined;
|
|
@@ -457,7 +479,7 @@ export class P2TR {
|
|
|
457
479
|
#computeHash(): Bytes32 | undefined {
|
|
458
480
|
const hashTree = this.#getHashTree();
|
|
459
481
|
if (hashTree) {
|
|
460
|
-
return hashTree.hash
|
|
482
|
+
return hashTree.hash;
|
|
461
483
|
}
|
|
462
484
|
|
|
463
485
|
const w = this.#getWitnessWithoutAnnex();
|
|
@@ -469,7 +491,7 @@ export class P2TR {
|
|
|
469
491
|
output: script,
|
|
470
492
|
version: leafVersion,
|
|
471
493
|
});
|
|
472
|
-
return rootHashFromPath(controlBlock, leafHash)
|
|
494
|
+
return rootHashFromPath(controlBlock, leafHash);
|
|
473
495
|
}
|
|
474
496
|
|
|
475
497
|
return undefined;
|
|
@@ -493,7 +515,7 @@ export class P2TR {
|
|
|
493
515
|
const pk = this.pubkey;
|
|
494
516
|
if (!pk) return undefined;
|
|
495
517
|
|
|
496
|
-
return bscript.compile([OPS.OP_1, pk])
|
|
518
|
+
return bscript.compile([OPS.OP_1, pk]);
|
|
497
519
|
}
|
|
498
520
|
|
|
499
521
|
#computeRedeem(): ScriptRedeem | undefined {
|
|
@@ -525,6 +547,8 @@ export class P2TR {
|
|
|
525
547
|
return LEAF_VERSION_TAPSCRIPT;
|
|
526
548
|
}
|
|
527
549
|
|
|
550
|
+
// Validation
|
|
551
|
+
|
|
528
552
|
#computeWitness(): Uint8Array[] | undefined {
|
|
529
553
|
if (this.#inputWitness) {
|
|
530
554
|
return this.#inputWitness;
|
|
@@ -558,8 +582,6 @@ export class P2TR {
|
|
|
558
582
|
return undefined;
|
|
559
583
|
}
|
|
560
584
|
|
|
561
|
-
// Validation
|
|
562
|
-
|
|
563
585
|
#validate(): void {
|
|
564
586
|
let pubkey: Uint8Array = new Uint8Array(0);
|
|
565
587
|
|
|
@@ -666,7 +688,7 @@ export class P2TR {
|
|
|
666
688
|
if (witness && witness.length > 0) {
|
|
667
689
|
if (witness.length === 1) {
|
|
668
690
|
// Key-path spending
|
|
669
|
-
if (this.#inputSignature && !equals(this.#inputSignature
|
|
691
|
+
if (this.#inputSignature && !equals(this.#inputSignature, witness[0]!)) {
|
|
670
692
|
throw new TypeError('Signature mismatch');
|
|
671
693
|
}
|
|
672
694
|
} else {
|
|
@@ -690,11 +712,11 @@ export class P2TR {
|
|
|
690
712
|
}
|
|
691
713
|
|
|
692
714
|
const internalPk = controlBlock.subarray(1, 33);
|
|
693
|
-
if (this.#inputInternalPubkey && !equals(this.#inputInternalPubkey
|
|
715
|
+
if (this.#inputInternalPubkey && !equals(this.#inputInternalPubkey, internalPk)) {
|
|
694
716
|
throw new TypeError('Internal pubkey mismatch');
|
|
695
717
|
}
|
|
696
718
|
|
|
697
|
-
if (!
|
|
719
|
+
if (!isXOnlyPublicKey(internalPk)) {
|
|
698
720
|
throw new TypeError('Invalid internalPubkey for p2tr witness');
|
|
699
721
|
}
|
|
700
722
|
|
|
@@ -707,7 +729,7 @@ export class P2TR {
|
|
|
707
729
|
});
|
|
708
730
|
const computedHash = rootHashFromPath(controlBlock, leafHash);
|
|
709
731
|
|
|
710
|
-
const outputKey = tweakKey(internalPk
|
|
732
|
+
const outputKey = tweakKey(internalPk, computedHash);
|
|
711
733
|
if (!outputKey) {
|
|
712
734
|
throw new TypeError('Invalid outputKey for p2tr witness');
|
|
713
735
|
}
|
|
@@ -722,28 +744,6 @@ export class P2TR {
|
|
|
722
744
|
}
|
|
723
745
|
}
|
|
724
746
|
}
|
|
725
|
-
|
|
726
|
-
/**
|
|
727
|
-
* Converts to a plain P2TRPayment object for backwards compatibility.
|
|
728
|
-
*
|
|
729
|
-
* @returns A P2TRPayment object
|
|
730
|
-
*/
|
|
731
|
-
toPayment(): P2TRPayment {
|
|
732
|
-
return {
|
|
733
|
-
name: this.name,
|
|
734
|
-
network: this.network,
|
|
735
|
-
address: this.address,
|
|
736
|
-
pubkey: this.pubkey,
|
|
737
|
-
internalPubkey: this.internalPubkey,
|
|
738
|
-
hash: this.hash,
|
|
739
|
-
scriptTree: this.#inputScriptTree,
|
|
740
|
-
signature: this.signature,
|
|
741
|
-
output: this.output,
|
|
742
|
-
redeem: this.redeem,
|
|
743
|
-
redeemVersion: this.redeemVersion,
|
|
744
|
-
witness: this.witness,
|
|
745
|
-
};
|
|
746
|
-
}
|
|
747
747
|
}
|
|
748
748
|
|
|
749
749
|
/**
|
package/src/payments/p2wpkh.ts
CHANGED
|
@@ -12,10 +12,10 @@ import { bech32 } from 'bech32';
|
|
|
12
12
|
import * as bcrypto from '../crypto.js';
|
|
13
13
|
import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
14
14
|
import * as bscript from '../script.js';
|
|
15
|
-
import { isPoint } from '../types.js';
|
|
16
15
|
import type { Bytes20, PublicKey, Script, Signature } from '../types.js';
|
|
16
|
+
import { isPoint } from '../types.js';
|
|
17
17
|
import { equals } from '../io/index.js';
|
|
18
|
-
import {
|
|
18
|
+
import { type P2WPKHPayment, type PaymentOpts, PaymentType } from './types.js';
|
|
19
19
|
|
|
20
20
|
const OPS = bscript.opcodes;
|
|
21
21
|
const EMPTY_BUFFER = new Uint8Array(0);
|
|
@@ -279,6 +279,27 @@ export class P2WPKH {
|
|
|
279
279
|
|
|
280
280
|
// Private helper methods
|
|
281
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Converts to a plain P2WPKHPayment object for backwards compatibility.
|
|
284
|
+
*
|
|
285
|
+
* @returns A P2WPKHPayment object
|
|
286
|
+
*/
|
|
287
|
+
toPayment(): P2WPKHPayment {
|
|
288
|
+
return {
|
|
289
|
+
name: this.name,
|
|
290
|
+
network: this.network,
|
|
291
|
+
address: this.address,
|
|
292
|
+
hash: this.hash,
|
|
293
|
+
pubkey: this.pubkey,
|
|
294
|
+
signature: this.signature,
|
|
295
|
+
output: this.output,
|
|
296
|
+
input: this.input,
|
|
297
|
+
witness: this.witness,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Private computation methods
|
|
302
|
+
|
|
282
303
|
#getDecodedAddress(): { version: number; prefix: string; data: Uint8Array } | undefined {
|
|
283
304
|
if (!this.#decodedAddressComputed) {
|
|
284
305
|
if (this.#inputAddress) {
|
|
@@ -296,8 +317,6 @@ export class P2WPKH {
|
|
|
296
317
|
return this.#decodedAddress;
|
|
297
318
|
}
|
|
298
319
|
|
|
299
|
-
// Private computation methods
|
|
300
|
-
|
|
301
320
|
#computeAddress(): string | undefined {
|
|
302
321
|
if (this.#inputAddress) {
|
|
303
322
|
return this.#inputAddress;
|
|
@@ -322,7 +341,7 @@ export class P2WPKH {
|
|
|
322
341
|
}
|
|
323
342
|
const pk = this.#inputPubkey ?? this.pubkey;
|
|
324
343
|
if (pk) {
|
|
325
|
-
return bcrypto.hash160(pk)
|
|
344
|
+
return bcrypto.hash160(pk);
|
|
326
345
|
}
|
|
327
346
|
return undefined;
|
|
328
347
|
}
|
|
@@ -354,7 +373,7 @@ export class P2WPKH {
|
|
|
354
373
|
const h = this.hash;
|
|
355
374
|
if (!h) return undefined;
|
|
356
375
|
|
|
357
|
-
return bscript.compile([OPS.OP_0, h])
|
|
376
|
+
return bscript.compile([OPS.OP_0, h]);
|
|
358
377
|
}
|
|
359
378
|
|
|
360
379
|
#computeInput(): Uint8Array | undefined {
|
|
@@ -364,6 +383,8 @@ export class P2WPKH {
|
|
|
364
383
|
return undefined;
|
|
365
384
|
}
|
|
366
385
|
|
|
386
|
+
// Validation
|
|
387
|
+
|
|
367
388
|
#computeWitness(): Uint8Array[] | undefined {
|
|
368
389
|
if (this.#inputWitness) {
|
|
369
390
|
return this.#inputWitness;
|
|
@@ -374,8 +395,6 @@ export class P2WPKH {
|
|
|
374
395
|
return [this.#inputSignature, this.#inputPubkey];
|
|
375
396
|
}
|
|
376
397
|
|
|
377
|
-
// Validation
|
|
378
|
-
|
|
379
398
|
#validate(): void {
|
|
380
399
|
let hash: Uint8Array = new Uint8Array(0);
|
|
381
400
|
|
|
@@ -438,14 +457,14 @@ export class P2WPKH {
|
|
|
438
457
|
if (!bscript.isCanonicalScriptSignature(this.#inputWitness[0]!)) {
|
|
439
458
|
throw new TypeError('Witness has invalid signature');
|
|
440
459
|
}
|
|
441
|
-
if (!isPoint(this.#inputWitness[1]!) || this.#inputWitness[1]
|
|
460
|
+
if (!isPoint(this.#inputWitness[1]!) || this.#inputWitness[1].length !== 33) {
|
|
442
461
|
throw new TypeError('Witness has invalid pubkey');
|
|
443
462
|
}
|
|
444
463
|
|
|
445
|
-
if (this.#inputSignature && !equals(this.#inputSignature
|
|
464
|
+
if (this.#inputSignature && !equals(this.#inputSignature, this.#inputWitness[0]!)) {
|
|
446
465
|
throw new TypeError('Signature mismatch');
|
|
447
466
|
}
|
|
448
|
-
if (this.#inputPubkey && !equals(this.#inputPubkey
|
|
467
|
+
if (this.#inputPubkey && !equals(this.#inputPubkey, this.#inputWitness[1])) {
|
|
449
468
|
throw new TypeError('Pubkey mismatch');
|
|
450
469
|
}
|
|
451
470
|
|
|
@@ -455,25 +474,6 @@ export class P2WPKH {
|
|
|
455
474
|
}
|
|
456
475
|
}
|
|
457
476
|
}
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* Converts to a plain P2WPKHPayment object for backwards compatibility.
|
|
461
|
-
*
|
|
462
|
-
* @returns A P2WPKHPayment object
|
|
463
|
-
*/
|
|
464
|
-
toPayment(): P2WPKHPayment {
|
|
465
|
-
return {
|
|
466
|
-
name: this.name,
|
|
467
|
-
network: this.network,
|
|
468
|
-
address: this.address,
|
|
469
|
-
hash: this.hash,
|
|
470
|
-
pubkey: this.pubkey,
|
|
471
|
-
signature: this.signature,
|
|
472
|
-
output: this.output,
|
|
473
|
-
input: this.input,
|
|
474
|
-
witness: this.witness,
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
477
|
}
|
|
478
478
|
|
|
479
479
|
/**
|
package/src/payments/p2wsh.ts
CHANGED
|
@@ -12,10 +12,10 @@ import { bech32 } from 'bech32';
|
|
|
12
12
|
import * as bcrypto from '../crypto.js';
|
|
13
13
|
import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
14
14
|
import * as bscript from '../script.js';
|
|
15
|
-
import { isPoint, stacksEqual, type StackElement } from '../types.js';
|
|
16
15
|
import type { Bytes32, Script } from '../types.js';
|
|
16
|
+
import { isPoint, type StackElement, stacksEqual } from '../types.js';
|
|
17
17
|
import { equals } from '../io/index.js';
|
|
18
|
-
import {
|
|
18
|
+
import { type P2WSHPayment, type PaymentOpts, PaymentType, type ScriptRedeem } from './types.js';
|
|
19
19
|
|
|
20
20
|
const OPS = bscript.opcodes;
|
|
21
21
|
const EMPTY_BUFFER = new Uint8Array(0);
|
|
@@ -278,6 +278,27 @@ export class P2WSH {
|
|
|
278
278
|
|
|
279
279
|
// Private helper methods
|
|
280
280
|
|
|
281
|
+
/**
|
|
282
|
+
* Converts to a plain P2WSHPayment object for backwards compatibility.
|
|
283
|
+
*
|
|
284
|
+
* @returns A P2WSHPayment object
|
|
285
|
+
*/
|
|
286
|
+
toPayment(): P2WSHPayment {
|
|
287
|
+
// Access witness first as it may modify redeem (transform input to witness)
|
|
288
|
+
const witness = this.witness;
|
|
289
|
+
const redeem = this.redeem;
|
|
290
|
+
return {
|
|
291
|
+
name: this.name,
|
|
292
|
+
network: this.network,
|
|
293
|
+
address: this.address,
|
|
294
|
+
hash: this.hash,
|
|
295
|
+
output: this.output,
|
|
296
|
+
input: this.input,
|
|
297
|
+
redeem,
|
|
298
|
+
witness,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
281
302
|
#getDecodedAddress(): { version: number; prefix: string; data: Uint8Array } | undefined {
|
|
282
303
|
if (!this.#decodedAddressComputed) {
|
|
283
304
|
if (this.#inputAddress) {
|
|
@@ -295,6 +316,8 @@ export class P2WSH {
|
|
|
295
316
|
return this.#decodedAddress;
|
|
296
317
|
}
|
|
297
318
|
|
|
319
|
+
// Private computation methods
|
|
320
|
+
|
|
298
321
|
#getRedeemChunks(): (Uint8Array | number)[] | undefined {
|
|
299
322
|
if (!this.#redeemChunksComputed) {
|
|
300
323
|
if (this.#inputRedeem?.input) {
|
|
@@ -305,8 +328,6 @@ export class P2WSH {
|
|
|
305
328
|
return this.#redeemChunks;
|
|
306
329
|
}
|
|
307
330
|
|
|
308
|
-
// Private computation methods
|
|
309
|
-
|
|
310
331
|
#computeAddress(): string | undefined {
|
|
311
332
|
if (this.#inputAddress) {
|
|
312
333
|
return this.#inputAddress;
|
|
@@ -331,7 +352,7 @@ export class P2WSH {
|
|
|
331
352
|
}
|
|
332
353
|
const r = this.redeem;
|
|
333
354
|
if (r && r.output) {
|
|
334
|
-
return bcrypto.sha256(r.output)
|
|
355
|
+
return bcrypto.sha256(r.output);
|
|
335
356
|
}
|
|
336
357
|
return undefined;
|
|
337
358
|
}
|
|
@@ -343,7 +364,7 @@ export class P2WSH {
|
|
|
343
364
|
const h = this.hash;
|
|
344
365
|
if (!h) return undefined;
|
|
345
366
|
|
|
346
|
-
return bscript.compile([OPS.OP_0, h])
|
|
367
|
+
return bscript.compile([OPS.OP_0, h]);
|
|
347
368
|
}
|
|
348
369
|
|
|
349
370
|
#computeInput(): Uint8Array | undefined {
|
|
@@ -367,6 +388,8 @@ export class P2WSH {
|
|
|
367
388
|
return undefined;
|
|
368
389
|
}
|
|
369
390
|
|
|
391
|
+
// Validation
|
|
392
|
+
|
|
370
393
|
#computeWitness(): Uint8Array[] | undefined {
|
|
371
394
|
if (this.#inputWitness) {
|
|
372
395
|
return this.#inputWitness;
|
|
@@ -394,8 +417,6 @@ export class P2WSH {
|
|
|
394
417
|
return undefined;
|
|
395
418
|
}
|
|
396
419
|
|
|
397
|
-
// Validation
|
|
398
|
-
|
|
399
420
|
#validate(): void {
|
|
400
421
|
let hash: Uint8Array = new Uint8Array(0);
|
|
401
422
|
|
|
@@ -518,27 +539,6 @@ export class P2WSH {
|
|
|
518
539
|
}
|
|
519
540
|
}
|
|
520
541
|
}
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* Converts to a plain P2WSHPayment object for backwards compatibility.
|
|
524
|
-
*
|
|
525
|
-
* @returns A P2WSHPayment object
|
|
526
|
-
*/
|
|
527
|
-
toPayment(): P2WSHPayment {
|
|
528
|
-
// Access witness first as it may modify redeem (transform input to witness)
|
|
529
|
-
const witness = this.witness;
|
|
530
|
-
const redeem = this.redeem;
|
|
531
|
-
return {
|
|
532
|
-
name: this.name,
|
|
533
|
-
network: this.network,
|
|
534
|
-
address: this.address,
|
|
535
|
-
hash: this.hash,
|
|
536
|
-
output: this.output,
|
|
537
|
-
input: this.input,
|
|
538
|
-
redeem,
|
|
539
|
-
witness,
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
542
|
}
|
|
543
543
|
|
|
544
544
|
/**
|