@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/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
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import * as bcrypto from '../crypto.js';
|
|
2
2
|
import { getEccLib } from '../ecc/context.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { alloc, compare, concat, equals, varuint } from '../io/index.js';
|
|
4
|
+
import type { Bytes32, Tapleaf, Taptree, XOnlyPublicKey } from '../types.js';
|
|
5
5
|
import { isTapleaf } from '../types.js';
|
|
6
|
-
import type { Tapleaf, Taptree } from '../types.js';
|
|
7
|
-
import type { Bytes32, XOnlyPublicKey } from '../types.js';
|
|
8
6
|
|
|
9
7
|
export const LEAF_VERSION_TAPSCRIPT = 0xc0;
|
|
10
8
|
export const MAX_TAPTREE_DEPTH = 128;
|
|
@@ -106,11 +104,11 @@ export function tapleafHash(leaf: Tapleaf): Bytes32 {
|
|
|
106
104
|
return bcrypto.taggedHash(
|
|
107
105
|
'TapLeaf',
|
|
108
106
|
concat([new Uint8Array([version]), serializeScript(leaf.output)]),
|
|
109
|
-
)
|
|
107
|
+
);
|
|
110
108
|
}
|
|
111
109
|
|
|
112
110
|
export function tapTweakHash(pubKey: XOnlyPublicKey, h: Bytes32 | undefined): Bytes32 {
|
|
113
|
-
return bcrypto.taggedHash('TapTweak', h ? concat([pubKey, h]) : pubKey)
|
|
111
|
+
return bcrypto.taggedHash('TapTweak', h ? concat([pubKey, h]) : pubKey);
|
|
114
112
|
}
|
|
115
113
|
|
|
116
114
|
export function tweakKey(pubKey: XOnlyPublicKey, h: Bytes32 | undefined): TweakedPublicKey | null {
|
|
@@ -130,7 +128,7 @@ export function tweakKey(pubKey: XOnlyPublicKey, h: Bytes32 | undefined): Tweake
|
|
|
130
128
|
}
|
|
131
129
|
|
|
132
130
|
function tapBranchHash(a: Uint8Array, b: Uint8Array): Bytes32 {
|
|
133
|
-
return bcrypto.taggedHash('TapBranch', concat([a, b]))
|
|
131
|
+
return bcrypto.taggedHash('TapBranch', concat([a, b]));
|
|
134
132
|
}
|
|
135
133
|
|
|
136
134
|
function serializeScript(s: Uint8Array): Uint8Array {
|
package/src/payments/embed.ts
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
11
11
|
import * as bscript from '../script.js';
|
|
12
|
-
import { stacksEqual, type Stack } from '../types.js';
|
|
13
12
|
import type { Script } from '../types.js';
|
|
14
|
-
import {
|
|
13
|
+
import { type Stack, stacksEqual } from '../types.js';
|
|
14
|
+
import { type EmbedPayment, type PaymentOpts, PaymentType } from './types.js';
|
|
15
15
|
|
|
16
16
|
const OPS = bscript.opcodes;
|
|
17
17
|
|
|
@@ -162,6 +162,20 @@ export class Embed {
|
|
|
162
162
|
|
|
163
163
|
// Private computation methods
|
|
164
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Converts to a plain EmbedPayment object for backwards compatibility.
|
|
167
|
+
*
|
|
168
|
+
* @returns An EmbedPayment object
|
|
169
|
+
*/
|
|
170
|
+
toPayment(): EmbedPayment {
|
|
171
|
+
return {
|
|
172
|
+
name: this.name,
|
|
173
|
+
network: this.network,
|
|
174
|
+
data: this.data,
|
|
175
|
+
output: this.output,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
165
179
|
#computeData(): Uint8Array[] | undefined {
|
|
166
180
|
if (this.#inputData) {
|
|
167
181
|
return this.#inputData;
|
|
@@ -176,6 +190,8 @@ export class Embed {
|
|
|
176
190
|
return undefined;
|
|
177
191
|
}
|
|
178
192
|
|
|
193
|
+
// Validation
|
|
194
|
+
|
|
179
195
|
#computeOutput(): Uint8Array | undefined {
|
|
180
196
|
if (this.#inputOutput) {
|
|
181
197
|
return this.#inputOutput;
|
|
@@ -183,11 +199,9 @@ export class Embed {
|
|
|
183
199
|
if (!this.#inputData) {
|
|
184
200
|
return undefined;
|
|
185
201
|
}
|
|
186
|
-
return bscript.compile(([OPS.OP_RETURN] as Stack).concat(this.#inputData))
|
|
202
|
+
return bscript.compile(([OPS.OP_RETURN] as Stack).concat(this.#inputData));
|
|
187
203
|
}
|
|
188
204
|
|
|
189
|
-
// Validation
|
|
190
|
-
|
|
191
205
|
#validate(): void {
|
|
192
206
|
if (this.#inputOutput) {
|
|
193
207
|
const chunks = bscript.decompile(this.#inputOutput);
|
|
@@ -206,20 +220,6 @@ export class Embed {
|
|
|
206
220
|
}
|
|
207
221
|
}
|
|
208
222
|
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Converts to a plain EmbedPayment object for backwards compatibility.
|
|
212
|
-
*
|
|
213
|
-
* @returns An EmbedPayment object
|
|
214
|
-
*/
|
|
215
|
-
toPayment(): EmbedPayment {
|
|
216
|
-
return {
|
|
217
|
-
name: this.name,
|
|
218
|
-
network: this.network,
|
|
219
|
-
data: this.data,
|
|
220
|
-
output: this.output,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
/**
|
package/src/payments/p2ms.ts
CHANGED
|
@@ -9,8 +9,15 @@
|
|
|
9
9
|
|
|
10
10
|
import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
11
11
|
import * as bscript from '../script.js';
|
|
12
|
-
import {
|
|
13
|
-
|
|
12
|
+
import {
|
|
13
|
+
isPoint,
|
|
14
|
+
type PublicKey,
|
|
15
|
+
type Script,
|
|
16
|
+
type Signature,
|
|
17
|
+
type Stack,
|
|
18
|
+
stacksEqual,
|
|
19
|
+
} from '../types.js';
|
|
20
|
+
import { type P2MSPayment, type PaymentOpts, PaymentType } from './types.js';
|
|
14
21
|
|
|
15
22
|
const OPS = bscript.opcodes;
|
|
16
23
|
const OP_INT_BASE = OPS.OP_RESERVED; // OP_1 - 1
|
|
@@ -274,6 +281,27 @@ export class P2MS {
|
|
|
274
281
|
|
|
275
282
|
// Private helper methods
|
|
276
283
|
|
|
284
|
+
/**
|
|
285
|
+
* Converts to a plain P2MSPayment object for backwards compatibility.
|
|
286
|
+
*
|
|
287
|
+
* @returns A P2MSPayment object
|
|
288
|
+
*/
|
|
289
|
+
toPayment(): P2MSPayment {
|
|
290
|
+
return {
|
|
291
|
+
name: this.name,
|
|
292
|
+
network: this.network,
|
|
293
|
+
m: this.m,
|
|
294
|
+
n: this.n,
|
|
295
|
+
pubkeys: this.pubkeys,
|
|
296
|
+
signatures: this.signatures,
|
|
297
|
+
output: this.output,
|
|
298
|
+
input: this.input,
|
|
299
|
+
witness: this.witness,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Private computation methods
|
|
304
|
+
|
|
277
305
|
#decode(output: Uint8Array | Stack): void {
|
|
278
306
|
if (this.#decoded) return;
|
|
279
307
|
this.#decoded = true;
|
|
@@ -286,8 +314,6 @@ export class P2MS {
|
|
|
286
314
|
this.#pubkeysComputed = true;
|
|
287
315
|
}
|
|
288
316
|
|
|
289
|
-
// Private computation methods
|
|
290
|
-
|
|
291
317
|
#computeM(): number | undefined {
|
|
292
318
|
if (this.#inputM !== undefined) {
|
|
293
319
|
return this.#inputM;
|
|
@@ -351,7 +377,7 @@ export class P2MS {
|
|
|
351
377
|
}
|
|
352
378
|
return bscript.compile(
|
|
353
379
|
([] as Stack).concat(OP_INT_BASE + m, pubkeys, OP_INT_BASE + n, OPS.OP_CHECKMULTISIG),
|
|
354
|
-
)
|
|
380
|
+
);
|
|
355
381
|
}
|
|
356
382
|
|
|
357
383
|
#computeInput(): Script | undefined {
|
|
@@ -361,9 +387,11 @@ export class P2MS {
|
|
|
361
387
|
if (!this.#inputSignatures) {
|
|
362
388
|
return undefined;
|
|
363
389
|
}
|
|
364
|
-
return bscript.compile(([OPS.OP_0] as Stack).concat(this.#inputSignatures))
|
|
390
|
+
return bscript.compile(([OPS.OP_0] as Stack).concat(this.#inputSignatures));
|
|
365
391
|
}
|
|
366
392
|
|
|
393
|
+
// Validation
|
|
394
|
+
|
|
367
395
|
#computeWitness(): Uint8Array[] | undefined {
|
|
368
396
|
if (this.input) {
|
|
369
397
|
return [];
|
|
@@ -371,8 +399,6 @@ export class P2MS {
|
|
|
371
399
|
return undefined;
|
|
372
400
|
}
|
|
373
401
|
|
|
374
|
-
// Validation
|
|
375
|
-
|
|
376
402
|
#isAcceptableSignature(x: Uint8Array | number): boolean {
|
|
377
403
|
return (
|
|
378
404
|
bscript.isCanonicalScriptSignature(x as Uint8Array) ||
|
|
@@ -465,25 +491,6 @@ export class P2MS {
|
|
|
465
491
|
}
|
|
466
492
|
}
|
|
467
493
|
}
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Converts to a plain P2MSPayment object for backwards compatibility.
|
|
471
|
-
*
|
|
472
|
-
* @returns A P2MSPayment object
|
|
473
|
-
*/
|
|
474
|
-
toPayment(): P2MSPayment {
|
|
475
|
-
return {
|
|
476
|
-
name: this.name,
|
|
477
|
-
network: this.network,
|
|
478
|
-
m: this.m,
|
|
479
|
-
n: this.n,
|
|
480
|
-
pubkeys: this.pubkeys,
|
|
481
|
-
signatures: this.signatures,
|
|
482
|
-
output: this.output,
|
|
483
|
-
input: this.input,
|
|
484
|
-
witness: this.witness,
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
494
|
}
|
|
488
495
|
|
|
489
496
|
/**
|
package/src/payments/p2op.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
|
13
13
|
import * as bscript from '../script.js';
|
|
14
14
|
import { alloc, concat, equals } from '../io/index.js';
|
|
15
15
|
import type { Bytes20, Script } from '../types.js';
|
|
16
|
-
import {
|
|
16
|
+
import { type P2OPPayment, type PaymentOpts, PaymentType } from './types.js';
|
|
17
17
|
|
|
18
18
|
const OPS = bscript.opcodes;
|
|
19
19
|
const P2OP_WITNESS_VERSION = 0x10;
|
|
@@ -241,6 +241,23 @@ export class P2OP {
|
|
|
241
241
|
|
|
242
242
|
// Private helper methods
|
|
243
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Converts to a plain P2OPPayment object for backwards compatibility.
|
|
246
|
+
*
|
|
247
|
+
* @returns A P2OPPayment object
|
|
248
|
+
*/
|
|
249
|
+
toPayment(): P2OPPayment {
|
|
250
|
+
return {
|
|
251
|
+
name: this.name,
|
|
252
|
+
network: this.network,
|
|
253
|
+
address: this.address,
|
|
254
|
+
program: this.program,
|
|
255
|
+
deploymentVersion: this.deploymentVersion,
|
|
256
|
+
hash160: this.hash160,
|
|
257
|
+
output: this.output as Script | undefined,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
244
261
|
#getDecodedAddress(): { version: number; prefix: string; data: Uint8Array } | undefined {
|
|
245
262
|
if (!this.#decodedAddressComputed) {
|
|
246
263
|
if (this.#inputAddress) {
|
|
@@ -258,6 +275,8 @@ export class P2OP {
|
|
|
258
275
|
return this.#decodedAddress;
|
|
259
276
|
}
|
|
260
277
|
|
|
278
|
+
// Private computation methods
|
|
279
|
+
|
|
261
280
|
#makeProgramFromParts(): Uint8Array | undefined {
|
|
262
281
|
if (
|
|
263
282
|
typeof this.#inputDeploymentVersion !== 'undefined' &&
|
|
@@ -274,8 +293,6 @@ export class P2OP {
|
|
|
274
293
|
return undefined;
|
|
275
294
|
}
|
|
276
295
|
|
|
277
|
-
// Private computation methods
|
|
278
|
-
|
|
279
296
|
#computeAddress(): string | undefined {
|
|
280
297
|
if (this.#inputAddress) {
|
|
281
298
|
return this.#inputAddress;
|
|
@@ -346,6 +363,8 @@ export class P2OP {
|
|
|
346
363
|
return prog.subarray(1) as Bytes20;
|
|
347
364
|
}
|
|
348
365
|
|
|
366
|
+
// Validation
|
|
367
|
+
|
|
349
368
|
#computeOutput(): Uint8Array | undefined {
|
|
350
369
|
if (this.#inputOutput) {
|
|
351
370
|
return this.#inputOutput;
|
|
@@ -356,8 +375,6 @@ export class P2OP {
|
|
|
356
375
|
return bscript.compile([OPS.OP_16, prog]);
|
|
357
376
|
}
|
|
358
377
|
|
|
359
|
-
// Validation
|
|
360
|
-
|
|
361
378
|
#validate(): void {
|
|
362
379
|
let prog: Uint8Array = alloc(0);
|
|
363
380
|
|
|
@@ -416,23 +433,6 @@ export class P2OP {
|
|
|
416
433
|
throw new TypeError('hash160 mismatch');
|
|
417
434
|
}
|
|
418
435
|
}
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Converts to a plain P2OPPayment object for backwards compatibility.
|
|
422
|
-
*
|
|
423
|
-
* @returns A P2OPPayment object
|
|
424
|
-
*/
|
|
425
|
-
toPayment(): P2OPPayment {
|
|
426
|
-
return {
|
|
427
|
-
name: this.name,
|
|
428
|
-
network: this.network,
|
|
429
|
-
address: this.address,
|
|
430
|
-
program: this.program,
|
|
431
|
-
deploymentVersion: this.deploymentVersion,
|
|
432
|
-
hash160: this.hash160,
|
|
433
|
-
output: this.output as Script | undefined,
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
436
|
}
|
|
437
437
|
|
|
438
438
|
/**
|
package/src/payments/p2pk.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
|
11
11
|
import * as bscript from '../script.js';
|
|
12
12
|
import { isPoint, type PublicKey, type Script, type Signature } from '../types.js';
|
|
13
13
|
import { equals } from '../io/index.js';
|
|
14
|
-
import {
|
|
14
|
+
import { type P2PKPayment, type PaymentOpts, PaymentType } from './types.js';
|
|
15
15
|
|
|
16
16
|
const OPS = bscript.opcodes;
|
|
17
17
|
|
|
@@ -238,6 +238,23 @@ export class P2PK {
|
|
|
238
238
|
|
|
239
239
|
// Private computation methods
|
|
240
240
|
|
|
241
|
+
/**
|
|
242
|
+
* Converts to a plain P2PKPayment object for backwards compatibility.
|
|
243
|
+
*
|
|
244
|
+
* @returns A P2PKPayment object
|
|
245
|
+
*/
|
|
246
|
+
toPayment(): P2PKPayment {
|
|
247
|
+
return {
|
|
248
|
+
name: this.name,
|
|
249
|
+
network: this.network,
|
|
250
|
+
pubkey: this.pubkey,
|
|
251
|
+
signature: this.signature,
|
|
252
|
+
output: this.output,
|
|
253
|
+
input: this.input,
|
|
254
|
+
witness: this.witness,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
241
258
|
#computePubkey(): PublicKey | undefined {
|
|
242
259
|
if (this.#inputPubkey) {
|
|
243
260
|
return this.#inputPubkey as PublicKey;
|
|
@@ -268,7 +285,7 @@ export class P2PK {
|
|
|
268
285
|
}
|
|
269
286
|
const pubkey = this.#inputPubkey;
|
|
270
287
|
if (pubkey) {
|
|
271
|
-
return bscript.compile([pubkey, OPS.OP_CHECKSIG])
|
|
288
|
+
return bscript.compile([pubkey, OPS.OP_CHECKSIG]);
|
|
272
289
|
}
|
|
273
290
|
return undefined;
|
|
274
291
|
}
|
|
@@ -279,11 +296,13 @@ export class P2PK {
|
|
|
279
296
|
}
|
|
280
297
|
const signature = this.#inputSignature;
|
|
281
298
|
if (signature) {
|
|
282
|
-
return bscript.compile([signature])
|
|
299
|
+
return bscript.compile([signature]);
|
|
283
300
|
}
|
|
284
301
|
return undefined;
|
|
285
302
|
}
|
|
286
303
|
|
|
304
|
+
// Validation
|
|
305
|
+
|
|
287
306
|
#computeWitness(): Uint8Array[] | undefined {
|
|
288
307
|
if (this.input) {
|
|
289
308
|
return [];
|
|
@@ -291,8 +310,6 @@ export class P2PK {
|
|
|
291
310
|
return undefined;
|
|
292
311
|
}
|
|
293
312
|
|
|
294
|
-
// Validation
|
|
295
|
-
|
|
296
313
|
#validate(): void {
|
|
297
314
|
if (this.#inputOutput) {
|
|
298
315
|
if (this.#inputOutput[this.#inputOutput.length - 1] !== OPS.OP_CHECKSIG) {
|
|
@@ -329,23 +346,6 @@ export class P2PK {
|
|
|
329
346
|
}
|
|
330
347
|
}
|
|
331
348
|
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Converts to a plain P2PKPayment object for backwards compatibility.
|
|
335
|
-
*
|
|
336
|
-
* @returns A P2PKPayment object
|
|
337
|
-
*/
|
|
338
|
-
toPayment(): P2PKPayment {
|
|
339
|
-
return {
|
|
340
|
-
name: this.name,
|
|
341
|
-
network: this.network,
|
|
342
|
-
pubkey: this.pubkey,
|
|
343
|
-
signature: this.signature,
|
|
344
|
-
output: this.output,
|
|
345
|
-
input: this.input,
|
|
346
|
-
witness: this.witness,
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
/**
|
package/src/payments/p2pkh.ts
CHANGED
|
@@ -13,9 +13,9 @@ import * as bcrypto from '../crypto.js';
|
|
|
13
13
|
import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
14
14
|
import { decompressPublicKey } from '../pubkey.js';
|
|
15
15
|
import * as bscript from '../script.js';
|
|
16
|
-
import {
|
|
16
|
+
import { type Bytes20, isPoint, type PublicKey, type Script, type Signature } from '../types.js';
|
|
17
17
|
import { alloc, equals } from '../io/index.js';
|
|
18
|
-
import {
|
|
18
|
+
import { type P2PKHPayment, type PaymentOpts, PaymentType } from './types.js';
|
|
19
19
|
|
|
20
20
|
const OPS = bscript.opcodes;
|
|
21
21
|
|
|
@@ -303,6 +303,25 @@ export class P2PKH {
|
|
|
303
303
|
|
|
304
304
|
// Private helper methods
|
|
305
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Converts to a plain P2PKHPayment object for backwards compatibility.
|
|
308
|
+
*
|
|
309
|
+
* @returns A P2PKHPayment object
|
|
310
|
+
*/
|
|
311
|
+
toPayment(): P2PKHPayment {
|
|
312
|
+
return {
|
|
313
|
+
name: this.name,
|
|
314
|
+
network: this.network,
|
|
315
|
+
address: this.address,
|
|
316
|
+
hash: this.hash,
|
|
317
|
+
pubkey: this.pubkey,
|
|
318
|
+
signature: this.signature,
|
|
319
|
+
output: this.output,
|
|
320
|
+
input: this.input,
|
|
321
|
+
witness: this.witness,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
306
325
|
#getDecodedAddress(): { version: number; hash: Uint8Array } | undefined {
|
|
307
326
|
if (!this.#decodedAddressComputed) {
|
|
308
327
|
if (this.#inputAddress) {
|
|
@@ -317,6 +336,8 @@ export class P2PKH {
|
|
|
317
336
|
return this.#decodedAddress;
|
|
318
337
|
}
|
|
319
338
|
|
|
339
|
+
// Private computation methods
|
|
340
|
+
|
|
320
341
|
#getInputChunks(): (Uint8Array | number)[] | undefined {
|
|
321
342
|
if (!this.#inputChunksComputed) {
|
|
322
343
|
if (this.#inputInput) {
|
|
@@ -327,8 +348,6 @@ export class P2PKH {
|
|
|
327
348
|
return this.#inputChunks;
|
|
328
349
|
}
|
|
329
350
|
|
|
330
|
-
// Private computation methods
|
|
331
|
-
|
|
332
351
|
#computeAddress(): string | undefined {
|
|
333
352
|
if (this.#inputAddress) {
|
|
334
353
|
return this.#inputAddress;
|
|
@@ -355,7 +374,7 @@ export class P2PKH {
|
|
|
355
374
|
// Use the pubkey getter to derive pubkey from input if available
|
|
356
375
|
const pk = this.pubkey;
|
|
357
376
|
if (pk) {
|
|
358
|
-
return bcrypto.hash160(pk)
|
|
377
|
+
return bcrypto.hash160(pk);
|
|
359
378
|
}
|
|
360
379
|
return undefined;
|
|
361
380
|
}
|
|
@@ -399,7 +418,7 @@ export class P2PKH {
|
|
|
399
418
|
h,
|
|
400
419
|
OPS.OP_EQUALVERIFY,
|
|
401
420
|
OPS.OP_CHECKSIG,
|
|
402
|
-
])
|
|
421
|
+
]);
|
|
403
422
|
}
|
|
404
423
|
|
|
405
424
|
#computeInput(): Script | undefined {
|
|
@@ -422,9 +441,11 @@ export class P2PKH {
|
|
|
422
441
|
}
|
|
423
442
|
}
|
|
424
443
|
|
|
425
|
-
return bscript.compile([this.#inputSignature, pubKey])
|
|
444
|
+
return bscript.compile([this.#inputSignature, pubKey]);
|
|
426
445
|
}
|
|
427
446
|
|
|
447
|
+
// Validation
|
|
448
|
+
|
|
428
449
|
#computeWitness(): Uint8Array[] | undefined {
|
|
429
450
|
if (this.input) {
|
|
430
451
|
return [];
|
|
@@ -432,8 +453,6 @@ export class P2PKH {
|
|
|
432
453
|
return undefined;
|
|
433
454
|
}
|
|
434
455
|
|
|
435
|
-
// Validation
|
|
436
|
-
|
|
437
456
|
#validate(): void {
|
|
438
457
|
let hash: Uint8Array = new Uint8Array(0);
|
|
439
458
|
|
|
@@ -540,25 +559,6 @@ export class P2PKH {
|
|
|
540
559
|
}
|
|
541
560
|
}
|
|
542
561
|
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Converts to a plain P2PKHPayment object for backwards compatibility.
|
|
546
|
-
*
|
|
547
|
-
* @returns A P2PKHPayment object
|
|
548
|
-
*/
|
|
549
|
-
toPayment(): P2PKHPayment {
|
|
550
|
-
return {
|
|
551
|
-
name: this.name,
|
|
552
|
-
network: this.network,
|
|
553
|
-
address: this.address,
|
|
554
|
-
hash: this.hash,
|
|
555
|
-
pubkey: this.pubkey,
|
|
556
|
-
signature: this.signature,
|
|
557
|
-
output: this.output,
|
|
558
|
-
input: this.input,
|
|
559
|
-
witness: this.witness,
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
562
|
}
|
|
563
563
|
|
|
564
564
|
/**
|
package/src/payments/p2sh.ts
CHANGED
|
@@ -12,13 +12,13 @@ import * as bs58check from 'bs58check';
|
|
|
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 {
|
|
15
|
+
import { type Bytes20, type Script, type Stack, stacksEqual } from '../types.js';
|
|
16
16
|
import { alloc, equals } from '../io/index.js';
|
|
17
17
|
import {
|
|
18
|
-
PaymentType,
|
|
19
18
|
type P2SHPayment,
|
|
20
19
|
type Payment,
|
|
21
20
|
type PaymentOpts,
|
|
21
|
+
PaymentType,
|
|
22
22
|
type ScriptRedeem,
|
|
23
23
|
} from './types.js';
|
|
24
24
|
|
|
@@ -282,6 +282,24 @@ export class P2SH {
|
|
|
282
282
|
|
|
283
283
|
// Private helper methods
|
|
284
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Converts to a plain P2SHPayment object for backwards compatibility.
|
|
287
|
+
*
|
|
288
|
+
* @returns A P2SHPayment object
|
|
289
|
+
*/
|
|
290
|
+
toPayment(): P2SHPayment {
|
|
291
|
+
return {
|
|
292
|
+
name: this.name,
|
|
293
|
+
network: this.network,
|
|
294
|
+
address: this.address,
|
|
295
|
+
hash: this.hash,
|
|
296
|
+
output: this.output,
|
|
297
|
+
input: this.input,
|
|
298
|
+
redeem: this.redeem,
|
|
299
|
+
witness: this.witness,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
285
303
|
#getDecodedAddress(): { version: number; hash: Uint8Array } | undefined {
|
|
286
304
|
if (!this.#decodedAddressComputed) {
|
|
287
305
|
if (this.#inputAddress) {
|
|
@@ -306,6 +324,8 @@ export class P2SH {
|
|
|
306
324
|
return this.#inputChunks;
|
|
307
325
|
}
|
|
308
326
|
|
|
327
|
+
// Private computation methods
|
|
328
|
+
|
|
309
329
|
#getDerivedRedeem(): ScriptRedeem | undefined {
|
|
310
330
|
if (!this.#derivedRedeemComputed) {
|
|
311
331
|
const chunks = this.#getInputChunks();
|
|
@@ -313,9 +333,10 @@ export class P2SH {
|
|
|
313
333
|
const lastChunk = chunks[chunks.length - 1];
|
|
314
334
|
this.#derivedRedeem = {
|
|
315
335
|
network: this.#network,
|
|
316
|
-
output:
|
|
317
|
-
|
|
318
|
-
|
|
336
|
+
output: (lastChunk === OPS.OP_FALSE
|
|
337
|
+
? new Uint8Array(0)
|
|
338
|
+
: (lastChunk as Uint8Array)) as Script,
|
|
339
|
+
input: bscript.compile(chunks.slice(0, -1)),
|
|
319
340
|
witness: this.#inputWitness || [],
|
|
320
341
|
};
|
|
321
342
|
}
|
|
@@ -324,8 +345,6 @@ export class P2SH {
|
|
|
324
345
|
return this.#derivedRedeem;
|
|
325
346
|
}
|
|
326
347
|
|
|
327
|
-
// Private computation methods
|
|
328
|
-
|
|
329
348
|
#computeAddress(): string | undefined {
|
|
330
349
|
if (this.#inputAddress) {
|
|
331
350
|
return this.#inputAddress;
|
|
@@ -351,7 +370,7 @@ export class P2SH {
|
|
|
351
370
|
}
|
|
352
371
|
const r = this.redeem;
|
|
353
372
|
if (r && r.output) {
|
|
354
|
-
return bcrypto.hash160(r.output)
|
|
373
|
+
return bcrypto.hash160(r.output);
|
|
355
374
|
}
|
|
356
375
|
return undefined;
|
|
357
376
|
}
|
|
@@ -363,7 +382,7 @@ export class P2SH {
|
|
|
363
382
|
const h = this.hash;
|
|
364
383
|
if (!h) return undefined;
|
|
365
384
|
|
|
366
|
-
return bscript.compile([OPS.OP_HASH160, h, OPS.OP_EQUAL])
|
|
385
|
+
return bscript.compile([OPS.OP_HASH160, h, OPS.OP_EQUAL]);
|
|
367
386
|
}
|
|
368
387
|
|
|
369
388
|
#computeInput(): Script | undefined {
|
|
@@ -374,7 +393,9 @@ export class P2SH {
|
|
|
374
393
|
if (!r || !r.input || !r.output) {
|
|
375
394
|
return undefined;
|
|
376
395
|
}
|
|
377
|
-
return bscript.compile(
|
|
396
|
+
return bscript.compile(
|
|
397
|
+
([] as Stack).concat(bscript.decompile(r.input) as Stack, r.output),
|
|
398
|
+
);
|
|
378
399
|
}
|
|
379
400
|
|
|
380
401
|
#computeRedeem(): ScriptRedeem | undefined {
|
|
@@ -387,6 +408,8 @@ export class P2SH {
|
|
|
387
408
|
return undefined;
|
|
388
409
|
}
|
|
389
410
|
|
|
411
|
+
// Validation
|
|
412
|
+
|
|
390
413
|
#computeWitness(): Uint8Array[] | undefined {
|
|
391
414
|
if (this.#inputWitness) {
|
|
392
415
|
return this.#inputWitness;
|
|
@@ -401,8 +424,6 @@ export class P2SH {
|
|
|
401
424
|
return undefined;
|
|
402
425
|
}
|
|
403
426
|
|
|
404
|
-
// Validation
|
|
405
|
-
|
|
406
427
|
#checkRedeem(redeem: Payment): void {
|
|
407
428
|
// Is the redeem output empty/invalid?
|
|
408
429
|
if (redeem.output) {
|
|
@@ -547,24 +568,6 @@ export class P2SH {
|
|
|
547
568
|
}
|
|
548
569
|
}
|
|
549
570
|
}
|
|
550
|
-
|
|
551
|
-
/**
|
|
552
|
-
* Converts to a plain P2SHPayment object for backwards compatibility.
|
|
553
|
-
*
|
|
554
|
-
* @returns A P2SHPayment object
|
|
555
|
-
*/
|
|
556
|
-
toPayment(): P2SHPayment {
|
|
557
|
-
return {
|
|
558
|
-
name: this.name,
|
|
559
|
-
network: this.network,
|
|
560
|
-
address: this.address,
|
|
561
|
-
hash: this.hash,
|
|
562
|
-
output: this.output,
|
|
563
|
-
input: this.input,
|
|
564
|
-
redeem: this.redeem,
|
|
565
|
-
witness: this.witness,
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
571
|
}
|
|
569
572
|
|
|
570
573
|
/**
|