xpi-ts 0.2.13 → 0.2.15
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/dist/cjs/lib/bitcore/address.js +75 -74
- package/dist/cjs/lib/bitcore/block/block.js +124 -126
- package/dist/cjs/lib/bitcore/block/blockheader.js +142 -208
- package/dist/cjs/lib/bitcore/block/index.js +3 -1
- package/dist/cjs/lib/bitcore/block/merkleblock.js +301 -0
- package/dist/cjs/lib/bitcore/crypto/bn.js +18 -22
- package/dist/cjs/lib/bitcore/crypto/ecdsa.js +50 -49
- package/dist/cjs/lib/bitcore/crypto/hash.js +25 -22
- package/dist/cjs/lib/bitcore/crypto/musig2.js +86 -92
- package/dist/cjs/lib/bitcore/crypto/point.js +42 -35
- package/dist/cjs/lib/bitcore/crypto/random.js +3 -2
- package/dist/cjs/lib/bitcore/crypto/schnorr.js +46 -55
- package/dist/cjs/lib/bitcore/crypto/signature.js +67 -55
- package/dist/cjs/lib/bitcore/crypto/sigtype.js +1 -1
- package/dist/cjs/lib/bitcore/encoding/base58.js +5 -4
- package/dist/cjs/lib/bitcore/encoding/base58check.js +14 -57
- package/dist/cjs/lib/bitcore/encoding/bufferreader.js +17 -17
- package/dist/cjs/lib/bitcore/encoding/bufferwriter.js +22 -26
- package/dist/cjs/lib/bitcore/encoding/varint.js +12 -11
- package/dist/cjs/lib/bitcore/errors.js +1 -0
- package/dist/cjs/lib/bitcore/hdprivatekey.js +74 -66
- package/dist/cjs/lib/bitcore/hdpublickey.js +96 -116
- package/dist/cjs/lib/bitcore/index.js +165 -172
- package/dist/cjs/lib/bitcore/message.js +36 -35
- package/dist/cjs/lib/bitcore/mnemonic/mnemonic.js +4 -3
- package/dist/cjs/lib/bitcore/mnemonic/pbkdf2.js +6 -5
- package/dist/cjs/lib/bitcore/mnemonic/words/french.js +2053 -0
- package/dist/cjs/lib/bitcore/mnemonic/words/index.js +2 -0
- package/dist/cjs/lib/bitcore/musig2/session.js +26 -25
- package/dist/cjs/lib/bitcore/musig2/signer.js +17 -16
- package/dist/cjs/lib/bitcore/networks.js +4 -3
- package/dist/cjs/lib/bitcore/opcode.js +11 -7
- package/dist/cjs/lib/bitcore/privatekey.js +42 -42
- package/dist/cjs/lib/bitcore/publickey.js +61 -57
- package/dist/cjs/lib/bitcore/script/interpreter/condition-stack.js +41 -0
- package/dist/cjs/lib/bitcore/script/interpreter/index.js +25 -0
- package/dist/cjs/lib/bitcore/script/interpreter/interpreter.js +1362 -0
- package/dist/cjs/lib/bitcore/script/interpreter/script-num.js +200 -0
- package/dist/cjs/lib/bitcore/script/interpreter/types.js +96 -0
- package/dist/cjs/lib/bitcore/{taproot.js → script/taproot.js} +107 -95
- package/dist/cjs/lib/bitcore/script.js +163 -104
- package/dist/cjs/lib/bitcore/taproot/musig2.js +51 -42
- package/dist/cjs/lib/bitcore/transaction/index.js +21 -21
- package/dist/cjs/lib/bitcore/transaction/input/multisig.js +10 -0
- package/dist/cjs/lib/bitcore/transaction/input/multisigscripthash.js +10 -0
- package/dist/cjs/lib/bitcore/transaction/input/publickey.js +10 -0
- package/dist/cjs/lib/bitcore/transaction/input/publickeyhash.js +10 -0
- package/dist/cjs/lib/bitcore/transaction/input/taproot.js +20 -0
- package/dist/cjs/lib/bitcore/transaction/input.js +145 -166
- package/dist/cjs/lib/bitcore/transaction/outpoint.js +89 -0
- package/dist/cjs/lib/bitcore/transaction/output.js +13 -8
- package/dist/cjs/lib/bitcore/transaction/sighash.js +96 -96
- package/dist/cjs/lib/bitcore/transaction/signature.js +39 -40
- package/dist/cjs/lib/bitcore/transaction/transaction.js +130 -118
- package/dist/cjs/lib/bitcore/transaction/unspentoutput.js +27 -23
- package/dist/cjs/lib/bitcore/util/bits.js +33 -0
- package/dist/cjs/lib/bitcore/util/buffer.js +29 -18
- package/dist/cjs/lib/bitcore/util/js.js +0 -3
- package/dist/cjs/lib/bitcore/util/merkle.js +53 -0
- package/dist/cjs/lib/bitcore/util/preconditions.js +8 -7
- package/dist/cjs/lib/bitcore/xaddress.js +27 -23
- package/dist/cjs/lib/{bitcore/taproot/nft.js → nft.js} +98 -29
- package/dist/cjs/lib/rank/index.js +28 -27
- package/dist/cjs/lib/rank/script.js +2 -1
- package/dist/cjs/lib/rank/transaction.js +2 -1
- package/dist/cjs/utils/string.js +6 -5
- package/dist/esm/lib/bitcore/address.js +42 -41
- package/dist/esm/lib/bitcore/block/block.js +126 -128
- package/dist/esm/lib/bitcore/block/blockheader.js +141 -207
- package/dist/esm/lib/bitcore/block/index.js +1 -0
- package/dist/esm/lib/bitcore/block/merkleblock.js +295 -0
- package/dist/esm/lib/bitcore/crypto/bn.js +18 -22
- package/dist/esm/lib/bitcore/crypto/ecdsa.js +25 -24
- package/dist/esm/lib/bitcore/crypto/hash.js +25 -22
- package/dist/esm/lib/bitcore/crypto/musig2.js +60 -66
- package/dist/esm/lib/bitcore/crypto/point.js +22 -15
- package/dist/esm/lib/bitcore/crypto/random.js +3 -2
- package/dist/esm/lib/bitcore/crypto/schnorr.js +35 -44
- package/dist/esm/lib/bitcore/crypto/signature.js +61 -49
- package/dist/esm/lib/bitcore/crypto/sigtype.js +1 -1
- package/dist/esm/lib/bitcore/encoding/base58.js +5 -4
- package/dist/esm/lib/bitcore/encoding/base58check.js +11 -57
- package/dist/esm/lib/bitcore/encoding/bufferreader.js +7 -7
- package/dist/esm/lib/bitcore/encoding/bufferwriter.js +18 -21
- package/dist/esm/lib/bitcore/encoding/varint.js +7 -6
- package/dist/esm/lib/bitcore/errors.js +1 -0
- package/dist/esm/lib/bitcore/hdprivatekey.js +47 -39
- package/dist/esm/lib/bitcore/hdpublickey.js +77 -97
- package/dist/esm/lib/bitcore/index.js +42 -45
- package/dist/esm/lib/bitcore/message.js +16 -15
- package/dist/esm/lib/bitcore/mnemonic/mnemonic.js +4 -3
- package/dist/esm/lib/bitcore/mnemonic/pbkdf2.js +5 -4
- package/dist/esm/lib/bitcore/mnemonic/words/french.js +2050 -0
- package/dist/esm/lib/bitcore/mnemonic/words/index.js +2 -0
- package/dist/esm/lib/bitcore/musig2/session.js +17 -16
- package/dist/esm/lib/bitcore/musig2/signer.js +19 -18
- package/dist/esm/lib/bitcore/networks.js +4 -3
- package/dist/esm/lib/bitcore/opcode.js +9 -5
- package/dist/esm/lib/bitcore/privatekey.js +25 -25
- package/dist/esm/lib/bitcore/publickey.js +46 -42
- package/dist/esm/lib/bitcore/script/interpreter/condition-stack.js +37 -0
- package/dist/esm/lib/bitcore/script/interpreter/index.js +4 -0
- package/dist/esm/lib/bitcore/script/interpreter/interpreter.js +1356 -0
- package/dist/esm/lib/bitcore/script/interpreter/script-num.js +195 -0
- package/dist/esm/lib/bitcore/script/interpreter/types.js +93 -0
- package/dist/esm/lib/bitcore/{taproot.js → script/taproot.js} +92 -81
- package/dist/esm/lib/bitcore/script.js +163 -102
- package/dist/esm/lib/bitcore/taproot/musig2.js +36 -27
- package/dist/esm/lib/bitcore/transaction/index.js +6 -6
- package/dist/esm/lib/bitcore/transaction/input/multisig.js +6 -0
- package/dist/esm/lib/bitcore/transaction/input/multisigscripthash.js +6 -0
- package/dist/esm/lib/bitcore/transaction/input/publickey.js +6 -0
- package/dist/esm/lib/bitcore/transaction/input/publickeyhash.js +6 -0
- package/dist/esm/lib/bitcore/transaction/input/taproot.js +16 -0
- package/dist/esm/lib/bitcore/transaction/input.js +55 -76
- package/dist/esm/lib/bitcore/transaction/outpoint.js +85 -0
- package/dist/esm/lib/bitcore/transaction/output.js +13 -8
- package/dist/esm/lib/bitcore/transaction/sighash.js +22 -22
- package/dist/esm/lib/bitcore/transaction/signature.js +16 -17
- package/dist/esm/lib/bitcore/transaction/transaction.js +58 -46
- package/dist/esm/lib/bitcore/transaction/unspentoutput.js +15 -11
- package/dist/esm/lib/bitcore/util/bits.js +27 -0
- package/dist/esm/lib/bitcore/util/buffer.js +20 -9
- package/dist/esm/lib/bitcore/util/js.js +0 -3
- package/dist/esm/lib/bitcore/util/merkle.js +47 -0
- package/dist/esm/lib/bitcore/util/preconditions.js +3 -2
- package/dist/esm/lib/bitcore/xaddress.js +16 -12
- package/dist/esm/lib/{bitcore/taproot/nft.js → nft.js} +97 -28
- package/dist/esm/lib/rank/index.js +15 -14
- package/dist/esm/lib/rank/script.js +1 -0
- package/dist/esm/lib/rank/transaction.js +1 -0
- package/dist/esm/utils/string.js +1 -0
- package/dist/types/lib/bitcore/address.d.ts +4 -3
- package/dist/types/lib/bitcore/address.d.ts.map +1 -1
- package/dist/types/lib/bitcore/block/block.d.ts +11 -19
- package/dist/types/lib/bitcore/block/block.d.ts.map +1 -1
- package/dist/types/lib/bitcore/block/blockheader.d.ts +30 -32
- package/dist/types/lib/bitcore/block/blockheader.d.ts.map +1 -1
- package/dist/types/lib/bitcore/block/index.d.ts +2 -0
- package/dist/types/lib/bitcore/block/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/block/merkleblock.d.ts +53 -0
- package/dist/types/lib/bitcore/block/merkleblock.d.ts.map +1 -0
- package/dist/types/lib/bitcore/crypto/bn.d.ts +2 -2
- package/dist/types/lib/bitcore/crypto/bn.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/ecdsa.d.ts +5 -4
- package/dist/types/lib/bitcore/crypto/ecdsa.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/hash.d.ts +3 -1
- package/dist/types/lib/bitcore/crypto/hash.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/musig2.d.ts +22 -30
- package/dist/types/lib/bitcore/crypto/musig2.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/point.d.ts +8 -3
- package/dist/types/lib/bitcore/crypto/point.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/random.d.ts +1 -0
- package/dist/types/lib/bitcore/crypto/random.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/schnorr.d.ts +5 -4
- package/dist/types/lib/bitcore/crypto/schnorr.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/signature.d.ts +4 -1
- package/dist/types/lib/bitcore/crypto/signature.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/sigtype.d.ts +1 -0
- package/dist/types/lib/bitcore/crypto/sigtype.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/base58.d.ts +1 -0
- package/dist/types/lib/bitcore/encoding/base58.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/base58check.d.ts +1 -2
- package/dist/types/lib/bitcore/encoding/base58check.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/bufferreader.d.ts +2 -1
- package/dist/types/lib/bitcore/encoding/bufferreader.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/bufferwriter.d.ts +2 -2
- package/dist/types/lib/bitcore/encoding/bufferwriter.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/varint.d.ts +3 -2
- package/dist/types/lib/bitcore/encoding/varint.d.ts.map +1 -1
- package/dist/types/lib/bitcore/errors.d.ts +3 -0
- package/dist/types/lib/bitcore/errors.d.ts.map +1 -1
- package/dist/types/lib/bitcore/hdprivatekey.d.ts +5 -4
- package/dist/types/lib/bitcore/hdprivatekey.d.ts.map +1 -1
- package/dist/types/lib/bitcore/hdpublickey.d.ts +4 -3
- package/dist/types/lib/bitcore/hdpublickey.d.ts.map +1 -1
- package/dist/types/lib/bitcore/index.d.ts +55 -60
- package/dist/types/lib/bitcore/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/message.d.ts +7 -4
- package/dist/types/lib/bitcore/message.d.ts.map +1 -1
- package/dist/types/lib/bitcore/mnemonic/mnemonic.d.ts +2 -0
- package/dist/types/lib/bitcore/mnemonic/mnemonic.d.ts.map +1 -1
- package/dist/types/lib/bitcore/mnemonic/pbkdf2.d.ts +1 -0
- package/dist/types/lib/bitcore/mnemonic/pbkdf2.d.ts.map +1 -1
- package/dist/types/lib/bitcore/mnemonic/words/french.d.ts +2 -0
- package/dist/types/lib/bitcore/mnemonic/words/french.d.ts.map +1 -0
- package/dist/types/lib/bitcore/mnemonic/words/index.d.ts +1 -0
- package/dist/types/lib/bitcore/mnemonic/words/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/musig2/session.d.ts +8 -7
- package/dist/types/lib/bitcore/musig2/session.d.ts.map +1 -1
- package/dist/types/lib/bitcore/musig2/signer.d.ts +10 -9
- package/dist/types/lib/bitcore/musig2/signer.d.ts.map +1 -1
- package/dist/types/lib/bitcore/networks.d.ts +1 -0
- package/dist/types/lib/bitcore/networks.d.ts.map +1 -1
- package/dist/types/lib/bitcore/opcode.d.ts +5 -0
- package/dist/types/lib/bitcore/opcode.d.ts.map +1 -1
- package/dist/types/lib/bitcore/privatekey.d.ts +5 -4
- package/dist/types/lib/bitcore/privatekey.d.ts.map +1 -1
- package/dist/types/lib/bitcore/publickey.d.ts +13 -6
- package/dist/types/lib/bitcore/publickey.d.ts.map +1 -1
- package/dist/types/lib/bitcore/{chunk.d.ts → script/chunk.d.ts} +1 -0
- package/dist/types/lib/bitcore/script/chunk.d.ts.map +1 -0
- package/dist/types/lib/bitcore/script/interpreter/condition-stack.d.ts +11 -0
- package/dist/types/lib/bitcore/script/interpreter/condition-stack.d.ts.map +1 -0
- package/dist/types/lib/bitcore/script/interpreter/index.d.ts +5 -0
- package/dist/types/lib/bitcore/script/interpreter/index.d.ts.map +1 -0
- package/dist/types/lib/bitcore/script/interpreter/interpreter.d.ts +21 -0
- package/dist/types/lib/bitcore/script/interpreter/interpreter.d.ts.map +1 -0
- package/dist/types/lib/bitcore/script/interpreter/script-num.d.ts +35 -0
- package/dist/types/lib/bitcore/script/interpreter/script-num.d.ts.map +1 -0
- package/dist/types/lib/bitcore/script/interpreter/types.d.ts +101 -0
- package/dist/types/lib/bitcore/script/interpreter/types.d.ts.map +1 -0
- package/dist/types/lib/bitcore/{taproot.d.ts → script/taproot.d.ts} +20 -7
- package/dist/types/lib/bitcore/script/taproot.d.ts.map +1 -0
- package/dist/types/lib/bitcore/script.d.ts +12 -11
- package/dist/types/lib/bitcore/script.d.ts.map +1 -1
- package/dist/types/lib/bitcore/taproot/musig2.d.ts +17 -16
- package/dist/types/lib/bitcore/taproot/musig2.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/index.d.ts +11 -11
- package/dist/types/lib/bitcore/transaction/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/input/multisig.d.ts +5 -0
- package/dist/types/lib/bitcore/transaction/input/multisig.d.ts.map +1 -0
- package/dist/types/lib/bitcore/transaction/input/multisigscripthash.d.ts +5 -0
- package/dist/types/lib/bitcore/transaction/input/multisigscripthash.d.ts.map +1 -0
- package/dist/types/lib/bitcore/transaction/input/publickey.d.ts +5 -0
- package/dist/types/lib/bitcore/transaction/input/publickey.d.ts.map +1 -0
- package/dist/types/lib/bitcore/transaction/input/publickeyhash.d.ts +6 -0
- package/dist/types/lib/bitcore/transaction/input/publickeyhash.d.ts.map +1 -0
- package/dist/types/lib/bitcore/transaction/input/taproot.d.ts +18 -0
- package/dist/types/lib/bitcore/transaction/input/taproot.d.ts.map +1 -0
- package/dist/types/lib/bitcore/transaction/input.d.ts +27 -35
- package/dist/types/lib/bitcore/transaction/input.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/outpoint.d.ts +32 -0
- package/dist/types/lib/bitcore/transaction/outpoint.d.ts.map +1 -0
- package/dist/types/lib/bitcore/transaction/output.d.ts +3 -1
- package/dist/types/lib/bitcore/transaction/output.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/sighash.d.ts +8 -7
- package/dist/types/lib/bitcore/transaction/sighash.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/signature.d.ts +3 -2
- package/dist/types/lib/bitcore/transaction/signature.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/transaction.d.ts +18 -15
- package/dist/types/lib/bitcore/transaction/transaction.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/unspentoutput.d.ts +9 -7
- package/dist/types/lib/bitcore/transaction/unspentoutput.d.ts.map +1 -1
- package/dist/types/lib/bitcore/unit.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/base32.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/bits.d.ts +5 -0
- package/dist/types/lib/bitcore/util/bits.d.ts.map +1 -0
- package/dist/types/lib/bitcore/util/buffer.d.ts +10 -2
- package/dist/types/lib/bitcore/util/buffer.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/js.d.ts +0 -1
- package/dist/types/lib/bitcore/util/js.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/merkle.d.ts +6 -0
- package/dist/types/lib/bitcore/util/merkle.d.ts.map +1 -0
- package/dist/types/lib/bitcore/util/preconditions.d.ts.map +1 -1
- package/dist/types/lib/bitcore/xaddress.d.ts +1 -0
- package/dist/types/lib/bitcore/xaddress.d.ts.map +1 -1
- package/dist/types/lib/{bitcore/taproot/nft.d.ts → nft.d.ts} +26 -12
- package/dist/types/lib/nft.d.ts.map +1 -0
- package/dist/types/lib/rank/index.d.ts +1 -0
- package/dist/types/lib/rank/index.d.ts.map +1 -1
- package/dist/types/lib/rank/script.d.ts +1 -0
- package/dist/types/lib/rank/script.d.ts.map +1 -1
- package/dist/types/lib/rank/transaction.d.ts +1 -0
- package/dist/types/lib/rank/transaction.d.ts.map +1 -1
- package/dist/types/utils/string.d.ts +1 -0
- package/dist/types/utils/string.d.ts.map +1 -1
- package/package.json +3 -2
- package/dist/cjs/lib/bitcore/script/interpreter.js +0 -1757
- package/dist/esm/lib/bitcore/script/interpreter.js +0 -1753
- package/dist/types/lib/bitcore/chunk.d.ts.map +0 -1
- package/dist/types/lib/bitcore/script/interpreter.d.ts +0 -101
- package/dist/types/lib/bitcore/script/interpreter.d.ts.map +0 -1
- package/dist/types/lib/bitcore/taproot/nft.d.ts.map +0 -1
- package/dist/types/lib/bitcore/taproot.d.ts.map +0 -1
- /package/dist/cjs/lib/bitcore/{chunk.js → script/chunk.js} +0 -0
- /package/dist/esm/lib/bitcore/{chunk.js → script/chunk.js} +0 -0
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Transaction = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
4
|
+
const preconditions_1 = require("../util/preconditions");
|
|
5
|
+
const js_1 = require("../util/js");
|
|
6
|
+
const bufferreader_1 = require("../encoding/bufferreader");
|
|
7
|
+
const bufferwriter_1 = require("../encoding/bufferwriter");
|
|
8
|
+
const hash_1 = require("../crypto/hash");
|
|
9
|
+
const signature_1 = require("../crypto/signature");
|
|
10
|
+
const sighash_1 = require("./sighash");
|
|
11
|
+
const errors_1 = require("../errors");
|
|
12
|
+
const address_1 = require("../address");
|
|
13
|
+
const unspentoutput_1 = require("./unspentoutput");
|
|
14
|
+
const input_1 = require("./input");
|
|
15
|
+
const output_1 = require("./output");
|
|
16
|
+
const script_1 = require("../script");
|
|
17
|
+
const privatekey_1 = require("../privatekey");
|
|
18
|
+
const bn_1 = require("../crypto/bn");
|
|
19
|
+
const sighash_2 = require("./sighash");
|
|
20
|
+
const interpreter_1 = require("../script/interpreter");
|
|
21
|
+
const util_1 = require("../util");
|
|
21
22
|
const CURRENT_VERSION = 2;
|
|
22
23
|
const DEFAULT_NLOCKTIME = 0;
|
|
23
24
|
const MAX_BLOCK_SIZE = 32_000_000;
|
|
@@ -29,7 +30,7 @@ const NLOCKTIME_MAX_VALUE = 4294967295;
|
|
|
29
30
|
const FEE_PER_KB = 1_000;
|
|
30
31
|
const CHANGE_OUTPUT_MAX_SIZE = 20 + 4 + 34 + 4;
|
|
31
32
|
const MAXIMUM_EXTRA_SIZE = 4 + 9 + 9 + 4;
|
|
32
|
-
const NULL_HASH =
|
|
33
|
+
const NULL_HASH = util_1.BufferUtil.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
|
|
33
34
|
class Transaction {
|
|
34
35
|
static DUST_AMOUNT = DUST_AMOUNT;
|
|
35
36
|
static FEE_SECURITY_MARGIN = FEE_SECURITY_MARGIN;
|
|
@@ -62,10 +63,10 @@ class Transaction {
|
|
|
62
63
|
if (serialized instanceof Transaction) {
|
|
63
64
|
return Transaction.shallowCopy(serialized);
|
|
64
65
|
}
|
|
65
|
-
else if (typeof serialized === 'string' &&
|
|
66
|
+
else if (typeof serialized === 'string' && js_1.JSUtil.isHexa(serialized)) {
|
|
66
67
|
this.fromString(serialized);
|
|
67
68
|
}
|
|
68
|
-
else if (
|
|
69
|
+
else if (util_1.BufferUtil.isBuffer(serialized)) {
|
|
69
70
|
this.fromBuffer(serialized);
|
|
70
71
|
}
|
|
71
72
|
else if (serialized && typeof serialized === 'object') {
|
|
@@ -97,22 +98,28 @@ class Transaction {
|
|
|
97
98
|
get hash() {
|
|
98
99
|
if (!this._hash) {
|
|
99
100
|
const hashBuffer = this._getHash();
|
|
100
|
-
const reader = new
|
|
101
|
+
const reader = new bufferreader_1.BufferReader(hashBuffer);
|
|
101
102
|
this._hash = reader.readReverse(32).toString('hex');
|
|
102
103
|
}
|
|
103
104
|
return this._hash;
|
|
104
105
|
}
|
|
106
|
+
get hashBuffer() {
|
|
107
|
+
return this._getHash();
|
|
108
|
+
}
|
|
105
109
|
get id() {
|
|
106
110
|
return this.txid;
|
|
107
111
|
}
|
|
108
112
|
get txid() {
|
|
109
113
|
if (!this._txid) {
|
|
110
114
|
const txidBuffer = this._getTxid();
|
|
111
|
-
const reader = new
|
|
115
|
+
const reader = new bufferreader_1.BufferReader(txidBuffer);
|
|
112
116
|
this._txid = reader.readReverse(32).toString('hex');
|
|
113
117
|
}
|
|
114
118
|
return this._txid;
|
|
115
119
|
}
|
|
120
|
+
get txidBuffer() {
|
|
121
|
+
return this._getTxid();
|
|
122
|
+
}
|
|
116
123
|
get inputAmount() {
|
|
117
124
|
return this._getInputAmount();
|
|
118
125
|
}
|
|
@@ -138,10 +145,10 @@ class Transaction {
|
|
|
138
145
|
this._version = version;
|
|
139
146
|
}
|
|
140
147
|
_getHash() {
|
|
141
|
-
return
|
|
148
|
+
return hash_1.Hash.sha256sha256(this.toBuffer());
|
|
142
149
|
}
|
|
143
150
|
_getTxid() {
|
|
144
|
-
const writer = new
|
|
151
|
+
const writer = new bufferwriter_1.BufferWriter();
|
|
145
152
|
writer.writeInt32LE(this.version);
|
|
146
153
|
const inputHashes = this._getTxInputHashes();
|
|
147
154
|
const outputHashes = this._getTxOutputHashes();
|
|
@@ -152,7 +159,7 @@ class Transaction {
|
|
|
152
159
|
writer.write(outputMerkleRootAndHeight.root);
|
|
153
160
|
writer.writeUInt8(outputMerkleRootAndHeight.height);
|
|
154
161
|
writer.writeUInt32LE(this.nLockTime);
|
|
155
|
-
return
|
|
162
|
+
return hash_1.Hash.sha256sha256(writer.toBuffer());
|
|
156
163
|
}
|
|
157
164
|
_getTxInputHashes() {
|
|
158
165
|
const hashes = [];
|
|
@@ -161,11 +168,11 @@ class Transaction {
|
|
|
161
168
|
}
|
|
162
169
|
for (let i = 0; i < this.inputs.length; i++) {
|
|
163
170
|
const input = this.inputs[i];
|
|
164
|
-
const writer = new
|
|
171
|
+
const writer = new bufferwriter_1.BufferWriter();
|
|
165
172
|
writer.writeReverse(input.prevTxId);
|
|
166
173
|
writer.writeUInt32LE(input.outputIndex);
|
|
167
174
|
writer.writeUInt32LE(Number(input.sequenceNumber));
|
|
168
|
-
const hash =
|
|
175
|
+
const hash = hash_1.Hash.sha256sha256(writer.toBuffer());
|
|
169
176
|
hashes.push(hash);
|
|
170
177
|
}
|
|
171
178
|
return hashes;
|
|
@@ -177,10 +184,10 @@ class Transaction {
|
|
|
177
184
|
}
|
|
178
185
|
for (let i = 0; i < this.outputs.length; i++) {
|
|
179
186
|
const output = this.outputs[i];
|
|
180
|
-
const writer = new
|
|
181
|
-
writer.writeUInt64LEBN(new
|
|
187
|
+
const writer = new bufferwriter_1.BufferWriter();
|
|
188
|
+
writer.writeUInt64LEBN(new bn_1.BN(output.satoshis));
|
|
182
189
|
writer.writeVarLengthBuffer(output.scriptBuffer);
|
|
183
|
-
const hash =
|
|
190
|
+
const hash = hash_1.Hash.sha256sha256(writer.toBuffer());
|
|
184
191
|
hashes.push(hash);
|
|
185
192
|
}
|
|
186
193
|
return hashes;
|
|
@@ -201,8 +208,8 @@ class Transaction {
|
|
|
201
208
|
size += 1;
|
|
202
209
|
}
|
|
203
210
|
for (let i = 0; i < size; i += 2) {
|
|
204
|
-
const buf =
|
|
205
|
-
hashes.push(
|
|
211
|
+
const buf = util_1.BufferUtil.concat([hashes[j + i], hashes[j + i + 1]]);
|
|
212
|
+
hashes.push(hash_1.Hash.sha256sha256(buf));
|
|
206
213
|
}
|
|
207
214
|
j += size;
|
|
208
215
|
}
|
|
@@ -268,7 +275,7 @@ class Transaction {
|
|
|
268
275
|
if (sigError)
|
|
269
276
|
return sigError;
|
|
270
277
|
if (this._hasInvalidSatoshis()) {
|
|
271
|
-
return new
|
|
278
|
+
return new errors_1.BitcoreError('Invalid satoshis in outputs');
|
|
272
279
|
}
|
|
273
280
|
return null;
|
|
274
281
|
}
|
|
@@ -278,7 +285,7 @@ class Transaction {
|
|
|
278
285
|
}
|
|
279
286
|
for (const output of this.outputs) {
|
|
280
287
|
if (output.satoshis < Transaction.DUST_AMOUNT && !output.isOpReturn()) {
|
|
281
|
-
return new
|
|
288
|
+
return new errors_1.BitcoreError('Dust outputs not allowed');
|
|
282
289
|
}
|
|
283
290
|
}
|
|
284
291
|
return null;
|
|
@@ -288,7 +295,7 @@ class Transaction {
|
|
|
288
295
|
return null;
|
|
289
296
|
}
|
|
290
297
|
if (!this.isFullySigned()) {
|
|
291
|
-
return new
|
|
298
|
+
return new errors_1.BitcoreError('Transaction is not fully signed');
|
|
292
299
|
}
|
|
293
300
|
return null;
|
|
294
301
|
}
|
|
@@ -309,12 +316,12 @@ class Transaction {
|
|
|
309
316
|
return true;
|
|
310
317
|
}
|
|
311
318
|
toBuffer() {
|
|
312
|
-
const writer = new
|
|
319
|
+
const writer = new bufferwriter_1.BufferWriter();
|
|
313
320
|
return this.toBufferWriter(writer).toBuffer();
|
|
314
321
|
}
|
|
315
322
|
toBufferWriter(writer) {
|
|
316
323
|
if (!writer) {
|
|
317
|
-
writer = new
|
|
324
|
+
writer = new bufferwriter_1.BufferWriter();
|
|
318
325
|
}
|
|
319
326
|
writer.writeInt32LE(this.version);
|
|
320
327
|
writer.writeVarintNum(this.inputs.length);
|
|
@@ -323,34 +330,34 @@ class Transaction {
|
|
|
323
330
|
}
|
|
324
331
|
writer.writeVarintNum(this.outputs.length);
|
|
325
332
|
for (const output of this.outputs) {
|
|
326
|
-
writer.writeUInt64LEBN(new
|
|
333
|
+
writer.writeUInt64LEBN(new bn_1.BN(output.satoshis));
|
|
327
334
|
writer.writeVarLengthBuffer(output.scriptBuffer);
|
|
328
335
|
}
|
|
329
336
|
writer.writeUInt32LE(this.nLockTime);
|
|
330
337
|
return writer;
|
|
331
338
|
}
|
|
332
339
|
fromBuffer(buffer) {
|
|
333
|
-
const reader = new
|
|
340
|
+
const reader = new bufferreader_1.BufferReader(buffer);
|
|
334
341
|
return this.fromBufferReader(reader);
|
|
335
342
|
}
|
|
336
343
|
fromBufferReader(reader) {
|
|
337
|
-
|
|
344
|
+
preconditions_1.Preconditions.checkArgument(!reader.finished(), 'No transaction data received');
|
|
338
345
|
this.version = reader.readInt32LE();
|
|
339
346
|
const sizeTxIns = reader.readVarintNum();
|
|
340
347
|
for (let i = 0; i < sizeTxIns; i++) {
|
|
341
|
-
const input =
|
|
348
|
+
const input = input_1.Input.fromBufferReader(reader);
|
|
342
349
|
this.inputs.push(input);
|
|
343
350
|
}
|
|
344
351
|
const sizeTxOuts = reader.readVarintNum();
|
|
345
352
|
for (let i = 0; i < sizeTxOuts; i++) {
|
|
346
|
-
const output =
|
|
353
|
+
const output = output_1.Output.fromBufferReader(reader);
|
|
347
354
|
this.outputs.push(output);
|
|
348
355
|
}
|
|
349
356
|
this.nLockTime = reader.readUInt32LE();
|
|
350
357
|
return this;
|
|
351
358
|
}
|
|
352
359
|
fromString(str) {
|
|
353
|
-
return this.fromBuffer(
|
|
360
|
+
return this.fromBuffer(util_1.BufferUtil.from(str, 'hex'));
|
|
354
361
|
}
|
|
355
362
|
toObject() {
|
|
356
363
|
const inputs = this.inputs.map(input => input.toObject());
|
|
@@ -377,7 +384,7 @@ class Transaction {
|
|
|
377
384
|
}
|
|
378
385
|
toJSON = this.toObject;
|
|
379
386
|
fromObject(arg) {
|
|
380
|
-
|
|
387
|
+
preconditions_1.Preconditions.checkArgument(typeof arg === 'object' && arg !== null, 'Must provide an object to deserialize a transaction');
|
|
381
388
|
let transaction;
|
|
382
389
|
if (arg instanceof Transaction) {
|
|
383
390
|
const obj = arg.toObject();
|
|
@@ -400,7 +407,7 @@ class Transaction {
|
|
|
400
407
|
this.nLockTime = transaction.nLockTime || DEFAULT_NLOCKTIME;
|
|
401
408
|
if (transaction.inputs) {
|
|
402
409
|
for (const inputData of transaction.inputs) {
|
|
403
|
-
const input = new
|
|
410
|
+
const input = new input_1.Input({
|
|
404
411
|
prevTxId: inputData.prevTxId,
|
|
405
412
|
outputIndex: inputData.outputIndex,
|
|
406
413
|
sequenceNumber: inputData.sequenceNumber,
|
|
@@ -413,7 +420,7 @@ class Transaction {
|
|
|
413
420
|
}
|
|
414
421
|
if (transaction.outputs) {
|
|
415
422
|
for (const outputData of transaction.outputs) {
|
|
416
|
-
const output = new
|
|
423
|
+
const output = new output_1.Output({
|
|
417
424
|
satoshis: outputData.satoshis,
|
|
418
425
|
script: outputData.script,
|
|
419
426
|
});
|
|
@@ -423,7 +430,7 @@ class Transaction {
|
|
|
423
430
|
if (transaction.changeScript) {
|
|
424
431
|
this._changeScript =
|
|
425
432
|
typeof transaction.changeScript === 'string'
|
|
426
|
-
?
|
|
433
|
+
? script_1.Script.fromString(transaction.changeScript)
|
|
427
434
|
: transaction.changeScript;
|
|
428
435
|
}
|
|
429
436
|
if (transaction.changeIndex !== undefined) {
|
|
@@ -465,7 +472,7 @@ class Transaction {
|
|
|
465
472
|
if (exists) {
|
|
466
473
|
return this;
|
|
467
474
|
}
|
|
468
|
-
const utxo = utxos instanceof
|
|
475
|
+
const utxo = utxos instanceof unspentoutput_1.UnspentOutput ? utxos : new unspentoutput_1.UnspentOutput(utxos);
|
|
469
476
|
if (pubkeys && threshold) {
|
|
470
477
|
this._fromMultisigUtxo(utxo, pubkeys, threshold, opts);
|
|
471
478
|
}
|
|
@@ -475,7 +482,7 @@ class Transaction {
|
|
|
475
482
|
return this;
|
|
476
483
|
}
|
|
477
484
|
change(address) {
|
|
478
|
-
this._changeScript =
|
|
485
|
+
this._changeScript = script_1.Script.fromAddress(address);
|
|
479
486
|
this._updateChangeOutput();
|
|
480
487
|
return this;
|
|
481
488
|
}
|
|
@@ -486,9 +493,9 @@ class Transaction {
|
|
|
486
493
|
}
|
|
487
494
|
return this;
|
|
488
495
|
}
|
|
489
|
-
|
|
490
|
-
this.addOutput(new
|
|
491
|
-
script:
|
|
496
|
+
preconditions_1.Preconditions.checkArgument(js_1.JSUtil.isNaturalNumber(amount), 'Amount is expected to be a positive integer');
|
|
497
|
+
this.addOutput(new output_1.Output({
|
|
498
|
+
script: script_1.Script.fromAddress(new address_1.Address(address)),
|
|
492
499
|
satoshis: amount,
|
|
493
500
|
}));
|
|
494
501
|
return this;
|
|
@@ -504,34 +511,34 @@ class Transaction {
|
|
|
504
511
|
return this;
|
|
505
512
|
}
|
|
506
513
|
signSchnorr(privateKey) {
|
|
507
|
-
return this.sign(privateKey,
|
|
514
|
+
return this.sign(privateKey, signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_LOTUS, 'schnorr');
|
|
508
515
|
}
|
|
509
516
|
getMuSig2Inputs() {
|
|
510
|
-
return this.inputs.filter(input => input instanceof
|
|
517
|
+
return this.inputs.filter(input => input instanceof input_1.MuSig2TaprootInput);
|
|
511
518
|
}
|
|
512
519
|
getMuSig2Sighash(inputIndex) {
|
|
513
520
|
const input = this.inputs[inputIndex];
|
|
514
|
-
if (!(input instanceof
|
|
515
|
-
throw new Error(`Input ${inputIndex} is not a
|
|
521
|
+
if (!(input instanceof input_1.MuSig2TaprootInput)) {
|
|
522
|
+
throw new Error(`Input ${inputIndex} is not a MuSig2TaprootInput`);
|
|
516
523
|
}
|
|
517
524
|
if (!input.output) {
|
|
518
525
|
throw new Error(`Input ${inputIndex} is missing output information`);
|
|
519
526
|
}
|
|
520
|
-
const sigtype =
|
|
521
|
-
return (0,
|
|
527
|
+
const sigtype = signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_LOTUS;
|
|
528
|
+
return (0, sighash_2.sighash)(this, sigtype, inputIndex, input.output.script, new bn_1.BN(input.output.satoshis));
|
|
522
529
|
}
|
|
523
530
|
addMuSig2Nonce(inputIndex, signerIndex, nonce) {
|
|
524
531
|
const input = this.inputs[inputIndex];
|
|
525
|
-
if (!(input instanceof
|
|
526
|
-
throw new Error(`Input ${inputIndex} is not a
|
|
532
|
+
if (!(input instanceof input_1.MuSig2TaprootInput)) {
|
|
533
|
+
throw new Error(`Input ${inputIndex} is not a MuSig2TaprootInput`);
|
|
527
534
|
}
|
|
528
535
|
input.addPublicNonce(signerIndex, nonce);
|
|
529
536
|
return this;
|
|
530
537
|
}
|
|
531
538
|
addMuSig2PartialSignature(inputIndex, signerIndex, partialSig) {
|
|
532
539
|
const input = this.inputs[inputIndex];
|
|
533
|
-
if (!(input instanceof
|
|
534
|
-
throw new Error(`Input ${inputIndex} is not a
|
|
540
|
+
if (!(input instanceof input_1.MuSig2TaprootInput)) {
|
|
541
|
+
throw new Error(`Input ${inputIndex} is not a MuSig2TaprootInput`);
|
|
535
542
|
}
|
|
536
543
|
input.addPartialSignature(signerIndex, partialSig);
|
|
537
544
|
return this;
|
|
@@ -540,36 +547,36 @@ class Transaction {
|
|
|
540
547
|
const musigInputs = this.getMuSig2Inputs();
|
|
541
548
|
for (let i = 0; i < this.inputs.length; i++) {
|
|
542
549
|
const input = this.inputs[i];
|
|
543
|
-
if (input instanceof
|
|
550
|
+
if (input instanceof input_1.MuSig2TaprootInput) {
|
|
544
551
|
if (!input.hasAllPartialSignatures()) {
|
|
545
552
|
throw new Error(`MuSig2 input ${i} is missing partial signatures. ` +
|
|
546
553
|
`Has ${input.partialSignatures?.size || 0} of ${input.keyAggContext?.pubkeys.length || 0}`);
|
|
547
554
|
}
|
|
548
555
|
const sighash = this.getMuSig2Sighash(i);
|
|
549
|
-
input.
|
|
556
|
+
input.finalizeMuSig2Signature(this, sighash);
|
|
550
557
|
}
|
|
551
558
|
}
|
|
552
559
|
return this;
|
|
553
560
|
}
|
|
554
561
|
getSignatures(privKey, sigtype, signingMethod) {
|
|
555
|
-
const privateKey = new
|
|
562
|
+
const privateKey = new privatekey_1.PrivateKey(privKey);
|
|
556
563
|
const results = [];
|
|
557
|
-
const hashData =
|
|
564
|
+
const hashData = hash_1.Hash.sha256ripemd160(privateKey.publicKey.toBuffer());
|
|
558
565
|
for (let index = 0; index < this.inputs.length; index++) {
|
|
559
566
|
const input = this.inputs[index];
|
|
560
567
|
let inputSigtype = sigtype;
|
|
561
568
|
if (!inputSigtype) {
|
|
562
|
-
if (input.output?.script.
|
|
569
|
+
if (input.output?.script.isTaprootOut()) {
|
|
563
570
|
const taprootInput = input;
|
|
564
571
|
if (taprootInput.hasScriptTree()) {
|
|
565
|
-
inputSigtype =
|
|
572
|
+
inputSigtype = signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_FORKID;
|
|
566
573
|
}
|
|
567
574
|
else {
|
|
568
|
-
inputSigtype =
|
|
575
|
+
inputSigtype = signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_LOTUS;
|
|
569
576
|
}
|
|
570
577
|
}
|
|
571
578
|
else {
|
|
572
|
-
inputSigtype =
|
|
579
|
+
inputSigtype = signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_FORKID;
|
|
573
580
|
}
|
|
574
581
|
}
|
|
575
582
|
const signatures = input.getSignatures(this, privateKey, index, inputSigtype, hashData, signingMethod);
|
|
@@ -588,10 +595,10 @@ class Transaction {
|
|
|
588
595
|
return input.isValidSignature(this, sig);
|
|
589
596
|
}
|
|
590
597
|
verifySignature(sig, pubkey, nin, subscript, satoshisBN, flags, signingMethod) {
|
|
591
|
-
return (0,
|
|
598
|
+
return (0, sighash_1.verify)(this, sig, pubkey, nin, subscript, satoshisBN, flags, signingMethod);
|
|
592
599
|
}
|
|
593
600
|
lockUntilDate(time) {
|
|
594
|
-
|
|
601
|
+
preconditions_1.Preconditions.checkArgument(!!time, 'time is required');
|
|
595
602
|
if (typeof time === 'number' &&
|
|
596
603
|
time < Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT) {
|
|
597
604
|
throw new Error('Lock time too early');
|
|
@@ -600,15 +607,15 @@ class Transaction {
|
|
|
600
607
|
time = time.getTime() / 1000;
|
|
601
608
|
}
|
|
602
609
|
for (let i = 0; i < this.inputs.length; i++) {
|
|
603
|
-
if (this.inputs[i].sequenceNumber ===
|
|
604
|
-
this.inputs[i].sequenceNumber =
|
|
610
|
+
if (this.inputs[i].sequenceNumber === input_1.Input.DEFAULT_SEQNUMBER) {
|
|
611
|
+
this.inputs[i].sequenceNumber = input_1.Input.DEFAULT_LOCKTIME_SEQNUMBER;
|
|
605
612
|
}
|
|
606
613
|
}
|
|
607
614
|
this.nLockTime = time;
|
|
608
615
|
return this;
|
|
609
616
|
}
|
|
610
617
|
lockUntilBlockHeight(height) {
|
|
611
|
-
|
|
618
|
+
preconditions_1.Preconditions.checkArgument(typeof height === 'number', 'height must be a number');
|
|
612
619
|
if (height >= Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT) {
|
|
613
620
|
throw new Error('Block height too high');
|
|
614
621
|
}
|
|
@@ -616,8 +623,8 @@ class Transaction {
|
|
|
616
623
|
throw new Error('NLockTime out of range');
|
|
617
624
|
}
|
|
618
625
|
for (let i = 0; i < this.inputs.length; i++) {
|
|
619
|
-
if (this.inputs[i].sequenceNumber ===
|
|
620
|
-
this.inputs[i].sequenceNumber =
|
|
626
|
+
if (this.inputs[i].sequenceNumber === input_1.Input.DEFAULT_SEQNUMBER) {
|
|
627
|
+
this.inputs[i].sequenceNumber = input_1.Input.DEFAULT_LOCKTIME_SEQNUMBER;
|
|
621
628
|
}
|
|
622
629
|
}
|
|
623
630
|
this.nLockTime = height;
|
|
@@ -636,8 +643,8 @@ class Transaction {
|
|
|
636
643
|
return this.inputs.every(input => !!input.output);
|
|
637
644
|
}
|
|
638
645
|
addData(value) {
|
|
639
|
-
this.addOutput(new
|
|
640
|
-
script:
|
|
646
|
+
this.addOutput(new output_1.Output({
|
|
647
|
+
script: script_1.Script.buildDataOut(value),
|
|
641
648
|
satoshis: 0,
|
|
642
649
|
}));
|
|
643
650
|
return this;
|
|
@@ -663,7 +670,7 @@ class Transaction {
|
|
|
663
670
|
x.i = i++;
|
|
664
671
|
});
|
|
665
672
|
copy.sort((first, second) => {
|
|
666
|
-
const prevTxIdCompare =
|
|
673
|
+
const prevTxIdCompare = util_1.BufferUtil.compare(first.prevTxId, second.prevTxId);
|
|
667
674
|
if (prevTxIdCompare !== 0)
|
|
668
675
|
return prevTxIdCompare;
|
|
669
676
|
const outputIndexCompare = first.outputIndex - second.outputIndex;
|
|
@@ -685,7 +692,7 @@ class Transaction {
|
|
|
685
692
|
const satoshisCompare = first.satoshis - second.satoshis;
|
|
686
693
|
if (satoshisCompare !== 0)
|
|
687
694
|
return satoshisCompare;
|
|
688
|
-
const scriptCompare =
|
|
695
|
+
const scriptCompare = util_1.BufferUtil.compare(first.scriptBuffer, second.scriptBuffer);
|
|
689
696
|
if (scriptCompare !== 0)
|
|
690
697
|
return scriptCompare;
|
|
691
698
|
return (first.i -
|
|
@@ -820,14 +827,11 @@ class Transaction {
|
|
|
820
827
|
try {
|
|
821
828
|
const verifyFlags = flags !== undefined
|
|
822
829
|
? flags
|
|
823
|
-
:
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
interpreter_js_1.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID |
|
|
829
|
-
interpreter_js_1.Interpreter.SCRIPT_ENABLE_SCHNORR_MULTISIG;
|
|
830
|
-
const interpreter = new interpreter_js_1.Interpreter();
|
|
830
|
+
: interpreter_1.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID |
|
|
831
|
+
interpreter_1.Interpreter.SCRIPT_VERIFY_CLEANSTACK |
|
|
832
|
+
interpreter_1.Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS |
|
|
833
|
+
interpreter_1.Interpreter.SCRIPT_VERIFY_INPUT_SIGCHECKS;
|
|
834
|
+
const interpreter = new interpreter_1.Interpreter();
|
|
831
835
|
const isValid = interpreter.verify(input.script, input.output.script, this, i, verifyFlags, BigInt(input.output.satoshis));
|
|
832
836
|
if (!isValid) {
|
|
833
837
|
return {
|
|
@@ -851,7 +855,7 @@ class Transaction {
|
|
|
851
855
|
this.inputs[0].outputIndex === 0xffffffff);
|
|
852
856
|
}
|
|
853
857
|
uncheckedAddInput(input) {
|
|
854
|
-
|
|
858
|
+
preconditions_1.Preconditions.checkArgument(input instanceof input_1.Input, 'input must be an Input');
|
|
855
859
|
this.inputs.push(input);
|
|
856
860
|
this._inputAmount = undefined;
|
|
857
861
|
this._updateChangeOutput();
|
|
@@ -861,7 +865,7 @@ class Transaction {
|
|
|
861
865
|
const isInvalidSorting = this.outputs.length !== newOutputs.length ||
|
|
862
866
|
this.outputs.some((output, index) => output !== newOutputs[index]);
|
|
863
867
|
if (isInvalidSorting) {
|
|
864
|
-
throw new
|
|
868
|
+
throw new errors_1.BitcoreError('Invalid sorting: outputs must contain the same elements');
|
|
865
869
|
}
|
|
866
870
|
if (this._changeIndex !== undefined) {
|
|
867
871
|
const changeOutput = this.outputs[this._changeIndex];
|
|
@@ -872,82 +876,90 @@ class Transaction {
|
|
|
872
876
|
}
|
|
873
877
|
_fromNonP2SH(utxo) {
|
|
874
878
|
let clazz;
|
|
875
|
-
const unspentOutput = new
|
|
876
|
-
if (unspentOutput.script.
|
|
879
|
+
const unspentOutput = new unspentoutput_1.UnspentOutput(utxo);
|
|
880
|
+
if (unspentOutput.script.isTaprootOut()) {
|
|
877
881
|
if (unspentOutput.keyAggContext &&
|
|
878
882
|
unspentOutput.mySignerIndex !== undefined) {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
883
|
+
if (!unspentOutput.internalPubKey || !unspentOutput.merkleRoot) {
|
|
884
|
+
throw new errors_1.BitcoreError('MuSig2 Taproot input requires internalPubKey and merkleRoot');
|
|
885
|
+
}
|
|
886
|
+
clazz = input_1.MuSig2TaprootInput;
|
|
887
|
+
const input = new input_1.MuSig2TaprootInput({
|
|
888
|
+
output: new output_1.Output({
|
|
882
889
|
script: unspentOutput.script,
|
|
883
890
|
satoshis: unspentOutput.satoshis,
|
|
884
891
|
}),
|
|
885
892
|
prevTxId: unspentOutput.txId,
|
|
886
893
|
outputIndex: unspentOutput.outputIndex,
|
|
887
|
-
script: new
|
|
894
|
+
script: new script_1.Script(),
|
|
888
895
|
keyAggContext: unspentOutput.keyAggContext,
|
|
889
896
|
mySignerIndex: unspentOutput.mySignerIndex,
|
|
897
|
+
internalPubKey: unspentOutput.internalPubKey,
|
|
898
|
+
merkleRoot: unspentOutput.merkleRoot,
|
|
890
899
|
});
|
|
891
900
|
this.addInput(input);
|
|
892
901
|
return;
|
|
893
902
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
903
|
+
if (!unspentOutput.internalPubKey) {
|
|
904
|
+
throw new errors_1.BitcoreError('Taproot input requires internalPubKey');
|
|
905
|
+
}
|
|
906
|
+
clazz = input_1.TaprootInput;
|
|
907
|
+
const taprootInput = new input_1.TaprootInput({
|
|
908
|
+
output: new output_1.Output({
|
|
897
909
|
script: unspentOutput.script,
|
|
898
910
|
satoshis: unspentOutput.satoshis,
|
|
899
911
|
}),
|
|
900
912
|
prevTxId: unspentOutput.txId,
|
|
901
913
|
outputIndex: unspentOutput.outputIndex,
|
|
902
|
-
script: new
|
|
914
|
+
script: new script_1.Script(),
|
|
903
915
|
internalPubKey: unspentOutput.internalPubKey,
|
|
904
|
-
merkleRoot: unspentOutput.merkleRoot ||
|
|
916
|
+
merkleRoot: unspentOutput.merkleRoot || util_1.BufferUtil.alloc(32),
|
|
905
917
|
});
|
|
906
918
|
this.addInput(taprootInput);
|
|
907
919
|
return;
|
|
908
920
|
}
|
|
909
|
-
else if (unspentOutput.script.
|
|
910
|
-
clazz =
|
|
921
|
+
else if (unspentOutput.script.isPublicKeyHashOut()) {
|
|
922
|
+
clazz = input_1.PublicKeyHashInput;
|
|
911
923
|
}
|
|
912
924
|
else if (unspentOutput.script.isPublicKeyOut()) {
|
|
913
|
-
clazz =
|
|
925
|
+
clazz = input_1.PublicKeyInput;
|
|
914
926
|
}
|
|
915
927
|
else {
|
|
916
|
-
clazz =
|
|
928
|
+
clazz = input_1.Input;
|
|
917
929
|
}
|
|
918
930
|
this.addInput(new clazz({
|
|
919
|
-
output: new
|
|
931
|
+
output: new output_1.Output({
|
|
920
932
|
script: unspentOutput.script,
|
|
921
933
|
satoshis: unspentOutput.satoshis,
|
|
922
934
|
}),
|
|
923
935
|
prevTxId: unspentOutput.txId,
|
|
924
936
|
outputIndex: unspentOutput.outputIndex,
|
|
925
|
-
script: new
|
|
937
|
+
script: new script_1.Script(),
|
|
926
938
|
}));
|
|
927
939
|
}
|
|
928
940
|
_fromMultisigUtxo(utxo, pubkeys, threshold, opts) {
|
|
929
|
-
|
|
930
|
-
const unspentOutput = new
|
|
941
|
+
preconditions_1.Preconditions.checkArgument(threshold <= pubkeys.length, 'Number of required signatures must be greater than the number of public keys');
|
|
942
|
+
const unspentOutput = new unspentoutput_1.UnspentOutput(utxo);
|
|
931
943
|
if (unspentOutput.script.isMultisigOut()) {
|
|
932
|
-
this.addInput(new
|
|
933
|
-
output: new
|
|
944
|
+
this.addInput(new input_1.MultisigInput(new input_1.Input({
|
|
945
|
+
output: new output_1.Output({
|
|
934
946
|
script: unspentOutput.script,
|
|
935
947
|
satoshis: unspentOutput.satoshis,
|
|
936
948
|
}),
|
|
937
949
|
prevTxId: unspentOutput.txId,
|
|
938
950
|
outputIndex: unspentOutput.outputIndex,
|
|
939
|
-
script: new
|
|
951
|
+
script: new script_1.Script(),
|
|
940
952
|
}), pubkeys, threshold, undefined, opts));
|
|
941
953
|
}
|
|
942
|
-
else if (unspentOutput.script.
|
|
943
|
-
this.addInput(new
|
|
944
|
-
output: new
|
|
954
|
+
else if (unspentOutput.script.isScriptHashOut()) {
|
|
955
|
+
this.addInput(new input_1.MultisigScriptHashInput(new input_1.Input({
|
|
956
|
+
output: new output_1.Output({
|
|
945
957
|
script: unspentOutput.script,
|
|
946
958
|
satoshis: unspentOutput.satoshis,
|
|
947
959
|
}),
|
|
948
960
|
prevTxId: unspentOutput.txId,
|
|
949
961
|
outputIndex: unspentOutput.outputIndex,
|
|
950
|
-
script: new
|
|
962
|
+
script: new script_1.Script(),
|
|
951
963
|
}), pubkeys, threshold, undefined, opts));
|
|
952
964
|
}
|
|
953
965
|
else {
|
|
@@ -967,7 +979,7 @@ class Transaction {
|
|
|
967
979
|
const changeAmount = available - fee;
|
|
968
980
|
if (changeAmount >= Transaction.DUST_AMOUNT) {
|
|
969
981
|
this._changeIndex = this.outputs.length;
|
|
970
|
-
this._addOutput(new
|
|
982
|
+
this._addOutput(new output_1.Output({
|
|
971
983
|
script: this._changeScript,
|
|
972
984
|
satoshis: changeAmount,
|
|
973
985
|
}));
|