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,40 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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
|
|
3
|
+
exports.MuSig2TaprootInput = exports.TaprootInput = exports.PublicKeyHashInput = exports.PublicKeyInput = exports.MultisigScriptHashInput = exports.MultisigInput = exports.Input = void 0;
|
|
4
|
+
const preconditions_1 = require("../util/preconditions");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const bufferwriter_1 = require("../encoding/bufferwriter");
|
|
7
|
+
const buffer_1 = require("../util/buffer");
|
|
8
|
+
const js_1 = require("../util/js");
|
|
9
|
+
const script_1 = require("../script");
|
|
10
|
+
const opcode_1 = require("../opcode");
|
|
11
|
+
const crypto_1 = require("../crypto");
|
|
12
|
+
const output_1 = require("./output");
|
|
13
|
+
const musig2_1 = require("../crypto/musig2");
|
|
14
|
+
const signature_1 = require("../crypto/signature");
|
|
15
|
+
const signature_2 = require("./signature");
|
|
16
|
+
const sighash_1 = require("./sighash");
|
|
17
|
+
const taproot_1 = require("../script/taproot");
|
|
18
|
+
const NULL_INDEX = 0xffffffff;
|
|
19
|
+
const NULL_HASH = buffer_1.BufferUtil.alloc(32);
|
|
19
20
|
class Input {
|
|
20
21
|
static MAXINT = 0xffffffff;
|
|
21
22
|
static DEFAULT_SEQNUMBER = 0xffffffff;
|
|
22
23
|
static DEFAULT_LOCKTIME_SEQNUMBER = 0xfffffffe;
|
|
23
24
|
static DEFAULT_RBF_SEQNUMBER = 0xfffffffd;
|
|
24
|
-
static
|
|
25
|
-
static
|
|
26
|
-
static SEQUENCE_LOCKTIME_MASK =
|
|
25
|
+
static SEQUENCE_LOCKTIME_DISABLE_FLAG = 1 << 31;
|
|
26
|
+
static SEQUENCE_LOCKTIME_TYPE_FLAG = 1 << 22;
|
|
27
|
+
static SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
|
|
27
28
|
static SEQUENCE_LOCKTIME_GRANULARITY = 512;
|
|
28
29
|
static SEQUENCE_BLOCKDIFF_LIMIT = 0xffff;
|
|
29
|
-
static PublicKey;
|
|
30
|
-
static PublicKeyHash;
|
|
31
|
-
static Multisig;
|
|
32
|
-
static MultisigScriptHash;
|
|
33
|
-
static Taproot;
|
|
34
|
-
static MuSigTaproot;
|
|
35
|
-
static P2PKH;
|
|
36
|
-
static P2SH;
|
|
37
|
-
static P2TR;
|
|
38
30
|
prevTxId;
|
|
39
31
|
outputIndex;
|
|
40
32
|
sequenceNumber;
|
|
@@ -50,20 +42,20 @@ class Input {
|
|
|
50
42
|
return new Input(params);
|
|
51
43
|
}
|
|
52
44
|
static fromObject(obj) {
|
|
53
|
-
|
|
45
|
+
preconditions_1.Preconditions.checkArgument(typeof obj === 'object' && obj !== null, 'Must provide an object');
|
|
54
46
|
const input = new Input();
|
|
55
47
|
return input._fromObject(obj);
|
|
56
48
|
}
|
|
57
49
|
_fromObject(params) {
|
|
58
50
|
let prevTxId;
|
|
59
|
-
if (typeof params.prevTxId === 'string' &&
|
|
60
|
-
prevTxId =
|
|
51
|
+
if (typeof params.prevTxId === 'string' && js_1.JSUtil.isHexa(params.prevTxId)) {
|
|
52
|
+
prevTxId = buffer_1.BufferUtil.from(params.prevTxId, 'hex');
|
|
61
53
|
}
|
|
62
|
-
else if (
|
|
54
|
+
else if (buffer_1.BufferUtil.isBuffer(params.prevTxId)) {
|
|
63
55
|
prevTxId = params.prevTxId;
|
|
64
56
|
}
|
|
65
57
|
else {
|
|
66
|
-
prevTxId =
|
|
58
|
+
prevTxId = buffer_1.BufferUtil.alloc(0);
|
|
67
59
|
}
|
|
68
60
|
this.output = params.output;
|
|
69
61
|
this.prevTxId = prevTxId;
|
|
@@ -73,7 +65,7 @@ class Input {
|
|
|
73
65
|
? params.sequenceNumber
|
|
74
66
|
: Input.DEFAULT_SEQNUMBER;
|
|
75
67
|
if (params.scriptBuffer === undefined && params.script === undefined) {
|
|
76
|
-
throw new
|
|
68
|
+
throw new errors_1.BitcoreError.Transaction.Input.MissingScript();
|
|
77
69
|
}
|
|
78
70
|
this.setScript(params.scriptBuffer || params.script);
|
|
79
71
|
return this;
|
|
@@ -83,7 +75,7 @@ class Input {
|
|
|
83
75
|
return null;
|
|
84
76
|
}
|
|
85
77
|
if (!this._script) {
|
|
86
|
-
this._script = new
|
|
78
|
+
this._script = new script_1.Script(this._scriptBuffer);
|
|
87
79
|
this._script._isInput = true;
|
|
88
80
|
}
|
|
89
81
|
return this._script;
|
|
@@ -93,26 +85,26 @@ class Input {
|
|
|
93
85
|
}
|
|
94
86
|
setScript(script) {
|
|
95
87
|
this._script = undefined;
|
|
96
|
-
if (script instanceof
|
|
88
|
+
if (script instanceof script_1.Script) {
|
|
97
89
|
this._script = script;
|
|
98
90
|
this._scriptBuffer = script.toBuffer();
|
|
99
91
|
}
|
|
100
92
|
else if (script === null) {
|
|
101
|
-
this._script =
|
|
93
|
+
this._script = script_1.Script.empty();
|
|
102
94
|
this._scriptBuffer = this._script.toBuffer();
|
|
103
95
|
}
|
|
104
|
-
else if (
|
|
96
|
+
else if (buffer_1.BufferUtil.isBuffer(script)) {
|
|
105
97
|
this._scriptBuffer = script;
|
|
106
|
-
this._script =
|
|
98
|
+
this._script = script_1.Script.fromBuffer(script);
|
|
107
99
|
}
|
|
108
100
|
else if (typeof script === 'string') {
|
|
109
|
-
if (
|
|
110
|
-
this._scriptBuffer =
|
|
111
|
-
this._script =
|
|
101
|
+
if (js_1.JSUtil.isHexa(script)) {
|
|
102
|
+
this._scriptBuffer = buffer_1.BufferUtil.from(script, 'hex');
|
|
103
|
+
this._script = script_1.Script.fromBuffer(this._scriptBuffer);
|
|
112
104
|
}
|
|
113
105
|
else {
|
|
114
|
-
this._scriptBuffer =
|
|
115
|
-
this._script =
|
|
106
|
+
this._scriptBuffer = buffer_1.BufferUtil.from(script, 'utf8');
|
|
107
|
+
this._script = script_1.Script.fromBuffer(this._scriptBuffer);
|
|
116
108
|
}
|
|
117
109
|
}
|
|
118
110
|
else {
|
|
@@ -121,12 +113,10 @@ class Input {
|
|
|
121
113
|
return this;
|
|
122
114
|
}
|
|
123
115
|
isNull() {
|
|
124
|
-
return
|
|
125
|
-
'0000000000000000000000000000000000000000000000000000000000000000' &&
|
|
126
|
-
this.outputIndex === 0xffffffff);
|
|
116
|
+
return this.prevTxId === NULL_HASH && this.outputIndex === NULL_INDEX;
|
|
127
117
|
}
|
|
128
118
|
isFinal() {
|
|
129
|
-
return this.sequenceNumber !==
|
|
119
|
+
return this.sequenceNumber !== Input.DEFAULT_SEQNUMBER;
|
|
130
120
|
}
|
|
131
121
|
hasSequence() {
|
|
132
122
|
return this.sequenceNumber !== Input.DEFAULT_SEQNUMBER;
|
|
@@ -163,7 +153,7 @@ class Input {
|
|
|
163
153
|
}
|
|
164
154
|
toObject() {
|
|
165
155
|
const obj = {
|
|
166
|
-
prevTxId:
|
|
156
|
+
prevTxId: buffer_1.BufferUtil.from(this.prevTxId).toString('hex'),
|
|
167
157
|
outputIndex: this.outputIndex,
|
|
168
158
|
sequenceNumber: this.sequenceNumber,
|
|
169
159
|
script: this._scriptBuffer.toString('hex'),
|
|
@@ -179,7 +169,9 @@ class Input {
|
|
|
179
169
|
}
|
|
180
170
|
return obj;
|
|
181
171
|
}
|
|
182
|
-
toJSON
|
|
172
|
+
toJSON() {
|
|
173
|
+
return this.toObject();
|
|
174
|
+
}
|
|
183
175
|
static fromBufferReader(br) {
|
|
184
176
|
const input = new Input();
|
|
185
177
|
input.prevTxId = br.readReverse(32);
|
|
@@ -189,7 +181,7 @@ class Input {
|
|
|
189
181
|
return input;
|
|
190
182
|
}
|
|
191
183
|
toBuffer() {
|
|
192
|
-
const bw = new
|
|
184
|
+
const bw = new bufferwriter_1.BufferWriter();
|
|
193
185
|
bw.writeReverse(this.prevTxId);
|
|
194
186
|
bw.writeUInt32LE(this.outputIndex);
|
|
195
187
|
bw.writeVarLengthBuffer(this._scriptBuffer);
|
|
@@ -198,7 +190,7 @@ class Input {
|
|
|
198
190
|
}
|
|
199
191
|
toBufferWriter(writer) {
|
|
200
192
|
if (!writer) {
|
|
201
|
-
writer = new
|
|
193
|
+
writer = new bufferwriter_1.BufferWriter();
|
|
202
194
|
}
|
|
203
195
|
writer.writeReverse(this.prevTxId);
|
|
204
196
|
writer.writeUInt32LE(this.outputIndex);
|
|
@@ -211,7 +203,7 @@ class Input {
|
|
|
211
203
|
getSize() {
|
|
212
204
|
return (32 +
|
|
213
205
|
4 +
|
|
214
|
-
|
|
206
|
+
bufferwriter_1.BufferWriter.varintBufNum(this._scriptBuffer.length).length +
|
|
215
207
|
this._scriptBuffer.length +
|
|
216
208
|
4);
|
|
217
209
|
}
|
|
@@ -221,32 +213,32 @@ class Input {
|
|
|
221
213
|
}
|
|
222
214
|
return (this.prevTxId.length === 32 &&
|
|
223
215
|
this.outputIndex >= 0 &&
|
|
224
|
-
this.outputIndex <=
|
|
216
|
+
this.outputIndex <= NULL_INDEX &&
|
|
225
217
|
this._scriptBuffer.length > 0);
|
|
226
218
|
}
|
|
227
219
|
clone() {
|
|
228
220
|
return new Input({
|
|
229
|
-
prevTxId:
|
|
221
|
+
prevTxId: buffer_1.BufferUtil.from(this.prevTxId),
|
|
230
222
|
outputIndex: this.outputIndex,
|
|
231
223
|
sequenceNumber: this.sequenceNumber,
|
|
232
|
-
scriptBuffer:
|
|
224
|
+
scriptBuffer: buffer_1.BufferUtil.from(this._scriptBuffer),
|
|
233
225
|
output: this.output,
|
|
234
226
|
});
|
|
235
227
|
}
|
|
236
228
|
getSignatures(transaction, privateKey, index, sigtype, hashData, signingMethod) {
|
|
237
|
-
|
|
238
|
-
sigtype = sigtype ||
|
|
229
|
+
preconditions_1.Preconditions.checkState(this.output instanceof output_1.Output, 'Output is required');
|
|
230
|
+
sigtype = sigtype || signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_FORKID;
|
|
239
231
|
const publicKey = privateKey.publicKey;
|
|
240
232
|
if (this.output.script.isPublicKeyHashOut()) {
|
|
241
|
-
const addressHash = hashData ||
|
|
242
|
-
if (
|
|
233
|
+
const addressHash = hashData || crypto_1.Hash.sha256ripemd160(publicKey.toBuffer());
|
|
234
|
+
if (buffer_1.BufferUtil.equals(addressHash, this.output.script.getPublicKeyHash())) {
|
|
243
235
|
return [
|
|
244
|
-
new
|
|
236
|
+
new signature_2.TransactionSignature({
|
|
245
237
|
publicKey: publicKey,
|
|
246
238
|
prevTxId: this.prevTxId,
|
|
247
239
|
outputIndex: this.outputIndex,
|
|
248
240
|
inputIndex: index,
|
|
249
|
-
signature: (0,
|
|
241
|
+
signature: (0, sighash_1.sign)(transaction, privateKey, sigtype, index, this.output.script, new crypto_1.BN(this.output.satoshis.toString()), undefined, signingMethod),
|
|
250
242
|
sigtype: sigtype,
|
|
251
243
|
}),
|
|
252
244
|
];
|
|
@@ -256,12 +248,12 @@ class Input {
|
|
|
256
248
|
if (publicKey.toString() ===
|
|
257
249
|
this.output.script.getPublicKey().toString('hex')) {
|
|
258
250
|
return [
|
|
259
|
-
new
|
|
251
|
+
new signature_2.TransactionSignature({
|
|
260
252
|
publicKey: publicKey,
|
|
261
253
|
prevTxId: this.prevTxId,
|
|
262
254
|
outputIndex: this.outputIndex,
|
|
263
255
|
inputIndex: index,
|
|
264
|
-
signature: (0,
|
|
256
|
+
signature: (0, sighash_1.sign)(transaction, privateKey, sigtype, index, this.output.script, new crypto_1.BN(this.output.satoshis.toString()), undefined, signingMethod),
|
|
265
257
|
sigtype: sigtype,
|
|
266
258
|
}),
|
|
267
259
|
];
|
|
@@ -273,20 +265,20 @@ class Input {
|
|
|
273
265
|
throw new Error('Input#isFullySigned');
|
|
274
266
|
}
|
|
275
267
|
addSignature(transaction, signature, signingMethod) {
|
|
276
|
-
|
|
268
|
+
preconditions_1.Preconditions.checkState(this.isValidSignature(transaction, signature, signingMethod), 'Signature is invalid');
|
|
277
269
|
if (this.output?.script.isPublicKeyHashOut()) {
|
|
278
|
-
const script = new
|
|
270
|
+
const script = new script_1.Script();
|
|
279
271
|
script.add(signature.signature.toTxFormat(signingMethod));
|
|
280
272
|
script.add(signature.publicKey.toBuffer());
|
|
281
273
|
this.setScript(script);
|
|
282
274
|
}
|
|
283
275
|
else if (this.output?.script.isPublicKeyOut()) {
|
|
284
|
-
const script = new
|
|
276
|
+
const script = new script_1.Script();
|
|
285
277
|
script.add(signature.signature.toTxFormat(signingMethod));
|
|
286
278
|
this.setScript(script);
|
|
287
279
|
}
|
|
288
280
|
else {
|
|
289
|
-
const script = new
|
|
281
|
+
const script = new script_1.Script();
|
|
290
282
|
script.add(signature.signature.toTxFormat(signingMethod));
|
|
291
283
|
if (signature.publicKey) {
|
|
292
284
|
script.add(signature.publicKey.toBuffer());
|
|
@@ -299,10 +291,10 @@ class Input {
|
|
|
299
291
|
throw new Error('Input#clearSignatures');
|
|
300
292
|
}
|
|
301
293
|
isValidSignature(transaction, signature, signingMethod) {
|
|
302
|
-
return (0,
|
|
294
|
+
return (0, sighash_1.verify)(transaction, signature.signature, signature.publicKey, signature.inputIndex, this.output.script, new crypto_1.BN(this.output.satoshis.toString()), undefined, signingMethod);
|
|
303
295
|
}
|
|
304
296
|
lockForSeconds(seconds) {
|
|
305
|
-
|
|
297
|
+
preconditions_1.Preconditions.checkArgument(typeof seconds === 'number', 'seconds must be a number');
|
|
306
298
|
if (seconds < 0 ||
|
|
307
299
|
seconds >=
|
|
308
300
|
Input.SEQUENCE_LOCKTIME_GRANULARITY * Input.SEQUENCE_LOCKTIME_MASK) {
|
|
@@ -313,7 +305,7 @@ class Input {
|
|
|
313
305
|
return this;
|
|
314
306
|
}
|
|
315
307
|
lockUntilBlockHeight(heightDiff) {
|
|
316
|
-
|
|
308
|
+
preconditions_1.Preconditions.checkArgument(typeof heightDiff === 'number', 'heightDiff must be a number');
|
|
317
309
|
if (heightDiff < 0 || heightDiff >= Input.SEQUENCE_BLOCKDIFF_LIMIT) {
|
|
318
310
|
throw new Error('Block height out of range');
|
|
319
311
|
}
|
|
@@ -373,7 +365,7 @@ class MultisigInput extends Input {
|
|
|
373
365
|
else {
|
|
374
366
|
this.publicKeys = pubkeys.sort((a, b) => a.toString().localeCompare(b.toString()));
|
|
375
367
|
}
|
|
376
|
-
|
|
368
|
+
preconditions_1.Preconditions.checkState(script_1.Script.buildMultisigOut(this.publicKeys, threshold).equals(this.output.script), "Provided public keys don't match to the provided output script");
|
|
377
369
|
this.publicKeyIndex = {};
|
|
378
370
|
this.publicKeys.forEach((publicKey, index) => {
|
|
379
371
|
this.publicKeyIndex[publicKey.toString()] = index;
|
|
@@ -397,7 +389,7 @@ class MultisigInput extends Input {
|
|
|
397
389
|
if (!signature) {
|
|
398
390
|
return undefined;
|
|
399
391
|
}
|
|
400
|
-
return new
|
|
392
|
+
return new signature_2.TransactionSignature(signature);
|
|
401
393
|
});
|
|
402
394
|
}
|
|
403
395
|
_serializeSignatures() {
|
|
@@ -409,17 +401,17 @@ class MultisigInput extends Input {
|
|
|
409
401
|
});
|
|
410
402
|
}
|
|
411
403
|
getSignatures(transaction, privateKey, index, sigtype, hashData, signingMethod) {
|
|
412
|
-
|
|
413
|
-
sigtype = sigtype ||
|
|
404
|
+
preconditions_1.Preconditions.checkState(this.output instanceof output_1.Output, 'Output is required');
|
|
405
|
+
sigtype = sigtype || signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_FORKID;
|
|
414
406
|
const results = [];
|
|
415
407
|
this.publicKeys.forEach(publicKey => {
|
|
416
408
|
if (publicKey.toString() === privateKey.publicKey.toString()) {
|
|
417
|
-
results.push(new
|
|
409
|
+
results.push(new signature_2.TransactionSignature({
|
|
418
410
|
publicKey: privateKey.publicKey,
|
|
419
411
|
prevTxId: this.prevTxId,
|
|
420
412
|
outputIndex: this.outputIndex,
|
|
421
413
|
inputIndex: index,
|
|
422
|
-
signature: (0,
|
|
414
|
+
signature: (0, sighash_1.sign)(transaction, privateKey, sigtype, index, this.output.script, new crypto_1.BN(this.output.satoshis.toString()), undefined, signingMethod),
|
|
423
415
|
sigtype: sigtype,
|
|
424
416
|
}));
|
|
425
417
|
}
|
|
@@ -427,17 +419,17 @@ class MultisigInput extends Input {
|
|
|
427
419
|
return results;
|
|
428
420
|
}
|
|
429
421
|
addSignature(transaction, signature, signingMethod) {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
422
|
+
preconditions_1.Preconditions.checkState(!this.isFullySigned(), 'All needed signatures have already been added');
|
|
423
|
+
preconditions_1.Preconditions.checkArgument(this.publicKeyIndex[signature.publicKey.toString()] !== undefined, 'Signature has no matching public key');
|
|
424
|
+
preconditions_1.Preconditions.checkState(this.isValidSignature(transaction, signature, signingMethod), 'Invalid signature');
|
|
433
425
|
this.signatures[this.publicKeyIndex[signature.publicKey.toString()]] =
|
|
434
426
|
signature;
|
|
435
427
|
this._updateScript(signingMethod);
|
|
436
428
|
return this;
|
|
437
429
|
}
|
|
438
430
|
_updateScript(signingMethod) {
|
|
439
|
-
const script = new
|
|
440
|
-
script.add(
|
|
431
|
+
const script = new script_1.Script();
|
|
432
|
+
script.add(opcode_1.Opcode.OP_0);
|
|
441
433
|
const signatures = this._createSignatures(signingMethod);
|
|
442
434
|
for (const sig of signatures) {
|
|
443
435
|
script.add(sig);
|
|
@@ -449,9 +441,9 @@ class MultisigInput extends Input {
|
|
|
449
441
|
return this.signatures
|
|
450
442
|
.filter(signature => signature !== undefined)
|
|
451
443
|
.map(signature => {
|
|
452
|
-
return
|
|
444
|
+
return buffer_1.BufferUtil.concat([
|
|
453
445
|
signature.signature.toDER(signingMethod),
|
|
454
|
-
|
|
446
|
+
buffer_1.BufferUtil.from([signature.sigtype]),
|
|
455
447
|
]);
|
|
456
448
|
});
|
|
457
449
|
}
|
|
@@ -475,7 +467,7 @@ class MultisigInput extends Input {
|
|
|
475
467
|
});
|
|
476
468
|
}
|
|
477
469
|
isValidSignature(transaction, signature, signingMethod) {
|
|
478
|
-
return (0,
|
|
470
|
+
return (0, sighash_1.verify)(transaction, signature.signature, signature.publicKey, signature.inputIndex, this.output.script, new crypto_1.BN(this.output.satoshis.toString()), undefined, signingMethod);
|
|
479
471
|
}
|
|
480
472
|
normalizeSignatures(transaction, input, inputIndex, signatures, publicKeys, signingMethod) {
|
|
481
473
|
return publicKeys
|
|
@@ -485,16 +477,16 @@ class MultisigInput extends Input {
|
|
|
485
477
|
if (signatureMatch) {
|
|
486
478
|
return true;
|
|
487
479
|
}
|
|
488
|
-
const signature = new
|
|
489
|
-
signature:
|
|
480
|
+
const signature = new signature_2.TransactionSignature({
|
|
481
|
+
signature: signature_1.Signature.fromTxFormat(signatureBuffer),
|
|
490
482
|
publicKey: pubKey,
|
|
491
483
|
prevTxId: input.prevTxId,
|
|
492
484
|
outputIndex: input.outputIndex,
|
|
493
485
|
inputIndex: inputIndex,
|
|
494
|
-
sigtype:
|
|
486
|
+
sigtype: signature_1.Signature.SIGHASH_ALL,
|
|
495
487
|
});
|
|
496
488
|
signature.signature.nhashtype = signature.sigtype;
|
|
497
|
-
const isMatch = (0,
|
|
489
|
+
const isMatch = (0, sighash_1.verify)(transaction, signature.signature, signature.publicKey, signature.inputIndex, input.output.script, new crypto_1.BN(input.output.satoshis.toString()), undefined, signingMethod);
|
|
498
490
|
if (isMatch) {
|
|
499
491
|
signatureMatch = signature;
|
|
500
492
|
return false;
|
|
@@ -541,8 +533,8 @@ class MultisigScriptHashInput extends Input {
|
|
|
541
533
|
else {
|
|
542
534
|
this.publicKeys = pubkeys.sort((a, b) => a.toString().localeCompare(b.toString()));
|
|
543
535
|
}
|
|
544
|
-
this.redeemScript =
|
|
545
|
-
|
|
536
|
+
this.redeemScript = script_1.Script.buildMultisigOut(this.publicKeys, threshold, opts);
|
|
537
|
+
preconditions_1.Preconditions.checkState(script_1.Script.buildScriptHashOut(this.redeemScript).equals(this.output.script), "Provided public keys don't hash to the provided output");
|
|
546
538
|
this.publicKeyIndex = {};
|
|
547
539
|
this.publicKeys.forEach((publicKey, index) => {
|
|
548
540
|
this.publicKeyIndex[publicKey.toString()] = index;
|
|
@@ -567,7 +559,7 @@ class MultisigScriptHashInput extends Input {
|
|
|
567
559
|
if (!signature) {
|
|
568
560
|
return undefined;
|
|
569
561
|
}
|
|
570
|
-
return new
|
|
562
|
+
return new signature_2.TransactionSignature(signature);
|
|
571
563
|
});
|
|
572
564
|
}
|
|
573
565
|
_serializeSignatures() {
|
|
@@ -579,17 +571,17 @@ class MultisigScriptHashInput extends Input {
|
|
|
579
571
|
});
|
|
580
572
|
}
|
|
581
573
|
getSignatures(transaction, privateKey, index, sigtype, hashData, signingMethod) {
|
|
582
|
-
|
|
583
|
-
sigtype = sigtype ||
|
|
574
|
+
preconditions_1.Preconditions.checkState(this.output instanceof output_1.Output, 'Output is required');
|
|
575
|
+
sigtype = sigtype || signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_FORKID;
|
|
584
576
|
const results = [];
|
|
585
577
|
this.publicKeys.forEach(publicKey => {
|
|
586
578
|
if (publicKey.toString() === privateKey.publicKey.toString()) {
|
|
587
|
-
results.push(new
|
|
579
|
+
results.push(new signature_2.TransactionSignature({
|
|
588
580
|
publicKey: privateKey.publicKey,
|
|
589
581
|
prevTxId: this.prevTxId,
|
|
590
582
|
outputIndex: this.outputIndex,
|
|
591
583
|
inputIndex: index,
|
|
592
|
-
signature: (0,
|
|
584
|
+
signature: (0, sighash_1.sign)(transaction, privateKey, sigtype, index, this.redeemScript, new crypto_1.BN(this.output.satoshis.toString()), undefined, signingMethod),
|
|
593
585
|
sigtype: sigtype,
|
|
594
586
|
}));
|
|
595
587
|
}
|
|
@@ -597,9 +589,9 @@ class MultisigScriptHashInput extends Input {
|
|
|
597
589
|
return results;
|
|
598
590
|
}
|
|
599
591
|
addSignature(transaction, signature, signingMethod) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
592
|
+
preconditions_1.Preconditions.checkState(!this.isFullySigned(), 'All needed signatures have already been added');
|
|
593
|
+
preconditions_1.Preconditions.checkArgument(this.publicKeyIndex[signature.publicKey.toString()] !== undefined, 'Signature has no matching public key');
|
|
594
|
+
preconditions_1.Preconditions.checkState(this.isValidSignature(transaction, signature, signingMethod), 'Invalid signature');
|
|
603
595
|
this.signatures[this.publicKeyIndex[signature.publicKey.toString()]] =
|
|
604
596
|
signature;
|
|
605
597
|
this.checkBitsField[this.publicKeyIndex[signature.publicKey.toString()]] =
|
|
@@ -608,8 +600,8 @@ class MultisigScriptHashInput extends Input {
|
|
|
608
600
|
return this;
|
|
609
601
|
}
|
|
610
602
|
_updateScript(signingMethod, checkBitsField) {
|
|
611
|
-
const script = new
|
|
612
|
-
script.add(
|
|
603
|
+
const script = new script_1.Script();
|
|
604
|
+
script.add(opcode_1.Opcode.OP_0);
|
|
613
605
|
const signatures = this._createSignatures(signingMethod);
|
|
614
606
|
for (const sig of signatures) {
|
|
615
607
|
script.add(sig);
|
|
@@ -622,9 +614,9 @@ class MultisigScriptHashInput extends Input {
|
|
|
622
614
|
return this.signatures
|
|
623
615
|
.filter(signature => signature !== undefined)
|
|
624
616
|
.map(signature => {
|
|
625
|
-
return
|
|
617
|
+
return buffer_1.BufferUtil.concat([
|
|
626
618
|
signature.signature.toDER(signingMethod),
|
|
627
|
-
|
|
619
|
+
buffer_1.BufferUtil.from([signature.sigtype]),
|
|
628
620
|
]);
|
|
629
621
|
});
|
|
630
622
|
}
|
|
@@ -649,7 +641,7 @@ class MultisigScriptHashInput extends Input {
|
|
|
649
641
|
}
|
|
650
642
|
isValidSignature(transaction, signature, signingMethod) {
|
|
651
643
|
signingMethod = signingMethod || 'ecdsa';
|
|
652
|
-
return (0,
|
|
644
|
+
return (0, sighash_1.verify)(transaction, signature.signature, signature.publicKey, signature.inputIndex, this.redeemScript, new crypto_1.BN(this.output.satoshis.toString()), undefined, signingMethod);
|
|
653
645
|
}
|
|
654
646
|
normalizeSignatures(transaction, input, inputIndex, signatures, publicKeys, signingMethod) {
|
|
655
647
|
return [];
|
|
@@ -664,18 +656,18 @@ exports.MultisigScriptHashInput = MultisigScriptHashInput;
|
|
|
664
656
|
class PublicKeyInput extends Input {
|
|
665
657
|
static SCRIPT_MAX_SIZE = 73;
|
|
666
658
|
getSignatures(transaction, privateKey, index, sigtype, hashData, signingMethod) {
|
|
667
|
-
|
|
668
|
-
sigtype = sigtype ||
|
|
659
|
+
preconditions_1.Preconditions.checkState(this.output instanceof output_1.Output, 'Output is required');
|
|
660
|
+
sigtype = sigtype || signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_FORKID;
|
|
669
661
|
const publicKey = privateKey.publicKey;
|
|
670
662
|
if (publicKey.toString() ===
|
|
671
663
|
this.output.script.getPublicKey().toString('hex')) {
|
|
672
664
|
return [
|
|
673
|
-
new
|
|
665
|
+
new signature_2.TransactionSignature({
|
|
674
666
|
publicKey: publicKey,
|
|
675
667
|
prevTxId: this.prevTxId,
|
|
676
668
|
outputIndex: this.outputIndex,
|
|
677
669
|
inputIndex: index,
|
|
678
|
-
signature: (0,
|
|
670
|
+
signature: (0, sighash_1.sign)(transaction, privateKey, sigtype, index, this.output.script, new crypto_1.BN(this.output.satoshis.toString()), undefined, signingMethod),
|
|
679
671
|
sigtype: sigtype,
|
|
680
672
|
}),
|
|
681
673
|
];
|
|
@@ -683,14 +675,14 @@ class PublicKeyInput extends Input {
|
|
|
683
675
|
return [];
|
|
684
676
|
}
|
|
685
677
|
addSignature(transaction, signature, signingMethod) {
|
|
686
|
-
|
|
687
|
-
const script = new
|
|
678
|
+
preconditions_1.Preconditions.checkState(this.isValidSignature(transaction, signature, signingMethod), 'Signature is invalid');
|
|
679
|
+
const script = new script_1.Script();
|
|
688
680
|
script.add(signature.signature.toTxFormat(signingMethod));
|
|
689
681
|
this.setScript(script);
|
|
690
682
|
return this;
|
|
691
683
|
}
|
|
692
684
|
clearSignatures() {
|
|
693
|
-
this.setScript(new
|
|
685
|
+
this.setScript(new script_1.Script());
|
|
694
686
|
return this;
|
|
695
687
|
}
|
|
696
688
|
isFullySigned() {
|
|
@@ -704,17 +696,17 @@ exports.PublicKeyInput = PublicKeyInput;
|
|
|
704
696
|
class PublicKeyHashInput extends Input {
|
|
705
697
|
static SCRIPT_MAX_SIZE = 73 + 34;
|
|
706
698
|
getSignatures(transaction, privateKey, index, sigtype, hashData, signingMethod) {
|
|
707
|
-
|
|
708
|
-
hashData = hashData ||
|
|
709
|
-
sigtype = sigtype ||
|
|
710
|
-
if (
|
|
699
|
+
preconditions_1.Preconditions.checkState(this.output instanceof output_1.Output, 'Output is required');
|
|
700
|
+
hashData = hashData || crypto_1.Hash.sha256ripemd160(privateKey.publicKey.toBuffer());
|
|
701
|
+
sigtype = sigtype || signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_FORKID;
|
|
702
|
+
if (buffer_1.BufferUtil.equals(hashData, this.output.script.getPublicKeyHash())) {
|
|
711
703
|
return [
|
|
712
|
-
new
|
|
704
|
+
new signature_2.TransactionSignature({
|
|
713
705
|
publicKey: privateKey.publicKey,
|
|
714
706
|
prevTxId: this.prevTxId,
|
|
715
707
|
outputIndex: this.outputIndex,
|
|
716
708
|
inputIndex: index,
|
|
717
|
-
signature: (0,
|
|
709
|
+
signature: (0, sighash_1.sign)(transaction, privateKey, sigtype, index, this.output.script, new crypto_1.BN(this.output.satoshis.toString()), undefined, signingMethod),
|
|
718
710
|
sigtype: sigtype,
|
|
719
711
|
}),
|
|
720
712
|
];
|
|
@@ -722,15 +714,15 @@ class PublicKeyHashInput extends Input {
|
|
|
722
714
|
return [];
|
|
723
715
|
}
|
|
724
716
|
addSignature(transaction, signature, signingMethod) {
|
|
725
|
-
|
|
726
|
-
const script = new
|
|
717
|
+
preconditions_1.Preconditions.checkState(this.isValidSignature(transaction, signature, signingMethod), 'Signature is invalid');
|
|
718
|
+
const script = new script_1.Script();
|
|
727
719
|
script.add(signature.signature.toTxFormat(signingMethod));
|
|
728
720
|
script.add(signature.publicKey.toBuffer());
|
|
729
721
|
this.setScript(script);
|
|
730
722
|
return this;
|
|
731
723
|
}
|
|
732
724
|
clearSignatures() {
|
|
733
|
-
this.setScript(new
|
|
725
|
+
this.setScript(new script_1.Script());
|
|
734
726
|
return this;
|
|
735
727
|
}
|
|
736
728
|
isFullySigned() {
|
|
@@ -748,29 +740,27 @@ class TaprootInput extends Input {
|
|
|
748
740
|
tapScript;
|
|
749
741
|
constructor(params) {
|
|
750
742
|
super(params);
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
this.tapScript = params.tapScript;
|
|
756
|
-
}
|
|
743
|
+
this.internalPubKey = params.internalPubKey;
|
|
744
|
+
this.merkleRoot = params.merkleRoot;
|
|
745
|
+
this.controlBlock = params.controlBlock;
|
|
746
|
+
this.tapScript = params.tapScript;
|
|
757
747
|
}
|
|
758
748
|
hasScriptTree() {
|
|
759
749
|
if (!this.merkleRoot || this.merkleRoot.length !== 32) {
|
|
760
750
|
return false;
|
|
761
751
|
}
|
|
762
|
-
return !this.merkleRoot.equals(
|
|
752
|
+
return !this.merkleRoot.equals(buffer_1.BufferUtil.alloc(32));
|
|
763
753
|
}
|
|
764
754
|
isKeyPathOnly() {
|
|
765
755
|
return !this.hasScriptTree();
|
|
766
756
|
}
|
|
767
757
|
getSignatures(transaction, privateKey, index, sigtype, hashData, signingMethod) {
|
|
768
|
-
|
|
769
|
-
|
|
758
|
+
preconditions_1.Preconditions.checkState(this.output instanceof output_1.Output, 'Output is required');
|
|
759
|
+
preconditions_1.Preconditions.checkState(this.output.script.isTaprootOut(), 'Output must be Pay-To-Taproot');
|
|
770
760
|
const isKeyPath = this.isKeyPathOnly();
|
|
771
761
|
if (isKeyPath) {
|
|
772
|
-
sigtype = sigtype ||
|
|
773
|
-
if ((sigtype & 0x60) !==
|
|
762
|
+
sigtype = sigtype || taproot_1.TAPROOT_SIGHASH_TYPE;
|
|
763
|
+
if ((sigtype & 0x60) !== signature_1.Signature.SIGHASH_LOTUS) {
|
|
774
764
|
throw new Error('Taproot key spend signatures must use "SIGHASH_ALL | SIGHASH_LOTUS" (0x61)');
|
|
775
765
|
}
|
|
776
766
|
signingMethod = signingMethod || 'schnorr';
|
|
@@ -780,17 +770,17 @@ class TaprootInput extends Input {
|
|
|
780
770
|
return this._getKeyPathSignatures(transaction, privateKey, index, sigtype, signingMethod);
|
|
781
771
|
}
|
|
782
772
|
else {
|
|
783
|
-
sigtype = sigtype ||
|
|
773
|
+
sigtype = sigtype || signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_FORKID;
|
|
784
774
|
signingMethod = signingMethod || 'schnorr';
|
|
785
775
|
return this._getScriptPathSignatures(transaction, privateKey, index, sigtype, signingMethod);
|
|
786
776
|
}
|
|
787
777
|
}
|
|
788
778
|
_getKeyPathSignatures(transaction, privateKey, index, sigtype, signingMethod) {
|
|
789
|
-
const merkleRoot = this.merkleRoot ||
|
|
790
|
-
const tweakedPrivateKey = (0,
|
|
791
|
-
const signature = (0,
|
|
779
|
+
const merkleRoot = this.merkleRoot || buffer_1.BufferUtil.alloc(32);
|
|
780
|
+
const tweakedPrivateKey = (0, taproot_1.tweakPrivateKey)(privateKey, merkleRoot);
|
|
781
|
+
const signature = (0, sighash_1.sign)(transaction, tweakedPrivateKey, sigtype, index, this.output.script, new crypto_1.BN(this.output.satoshis.toString()), undefined, signingMethod);
|
|
792
782
|
return [
|
|
793
|
-
new
|
|
783
|
+
new signature_2.TransactionSignature({
|
|
794
784
|
publicKey: tweakedPrivateKey.publicKey,
|
|
795
785
|
prevTxId: this.prevTxId,
|
|
796
786
|
outputIndex: this.outputIndex,
|
|
@@ -801,9 +791,9 @@ class TaprootInput extends Input {
|
|
|
801
791
|
];
|
|
802
792
|
}
|
|
803
793
|
_getScriptPathSignatures(transaction, privateKey, index, sigtype, signingMethod) {
|
|
804
|
-
const signature = (0,
|
|
794
|
+
const signature = (0, sighash_1.sign)(transaction, privateKey, sigtype, index, this.tapScript || this.output.script, new crypto_1.BN(this.output.satoshis.toString()), undefined, signingMethod);
|
|
805
795
|
return [
|
|
806
|
-
new
|
|
796
|
+
new signature_2.TransactionSignature({
|
|
807
797
|
publicKey: privateKey.publicKey,
|
|
808
798
|
prevTxId: this.prevTxId,
|
|
809
799
|
outputIndex: this.outputIndex,
|
|
@@ -814,8 +804,8 @@ class TaprootInput extends Input {
|
|
|
814
804
|
];
|
|
815
805
|
}
|
|
816
806
|
addSignature(transaction, signature, signingMethod) {
|
|
817
|
-
|
|
818
|
-
const script = new
|
|
807
|
+
preconditions_1.Preconditions.checkState(this.isValidSignature(transaction, signature, signingMethod), 'Signature is invalid');
|
|
808
|
+
const script = new script_1.Script();
|
|
819
809
|
if (this.isKeyPathOnly()) {
|
|
820
810
|
script.add(signature.signature.toTxFormat('schnorr'));
|
|
821
811
|
}
|
|
@@ -836,15 +826,15 @@ class TaprootInput extends Input {
|
|
|
836
826
|
return this;
|
|
837
827
|
}
|
|
838
828
|
isValidSignature(transaction, signature, signingMethod) {
|
|
839
|
-
|
|
829
|
+
preconditions_1.Preconditions.checkState(this.output instanceof output_1.Output, 'Output is required');
|
|
840
830
|
signingMethod = signingMethod || 'schnorr';
|
|
841
831
|
if (signingMethod !== 'schnorr') {
|
|
842
832
|
return false;
|
|
843
833
|
}
|
|
844
|
-
return transaction.verifySignature(signature.signature, signature.publicKey, signature.inputIndex, this.output.script, new
|
|
834
|
+
return transaction.verifySignature(signature.signature, signature.publicKey, signature.inputIndex, this.output.script, new crypto_1.BN(this.output.satoshis), undefined, signingMethod);
|
|
845
835
|
}
|
|
846
836
|
clearSignatures() {
|
|
847
|
-
this.setScript(new
|
|
837
|
+
this.setScript(new script_1.Script());
|
|
848
838
|
return this;
|
|
849
839
|
}
|
|
850
840
|
isFullySigned() {
|
|
@@ -855,7 +845,7 @@ class TaprootInput extends Input {
|
|
|
855
845
|
}
|
|
856
846
|
}
|
|
857
847
|
exports.TaprootInput = TaprootInput;
|
|
858
|
-
class
|
|
848
|
+
class MuSig2TaprootInput extends TaprootInput {
|
|
859
849
|
keyAggContext;
|
|
860
850
|
publicNonces;
|
|
861
851
|
aggregatedNonce;
|
|
@@ -863,14 +853,12 @@ class MuSigTaprootInput extends TaprootInput {
|
|
|
863
853
|
mySignerIndex;
|
|
864
854
|
constructor(params) {
|
|
865
855
|
super(params);
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
this.partialSignatures = new Map();
|
|
871
|
-
}
|
|
856
|
+
this.keyAggContext = params.keyAggContext;
|
|
857
|
+
this.mySignerIndex = params.mySignerIndex;
|
|
858
|
+
this.publicNonces = new Map();
|
|
859
|
+
this.partialSignatures = new Map();
|
|
872
860
|
}
|
|
873
|
-
|
|
861
|
+
initMuSig2Session(keyAggContext, mySignerIndex) {
|
|
874
862
|
this.keyAggContext = keyAggContext;
|
|
875
863
|
this.mySignerIndex = mySignerIndex;
|
|
876
864
|
this.publicNonces = new Map();
|
|
@@ -903,7 +891,7 @@ class MuSigTaprootInput extends TaprootInput {
|
|
|
903
891
|
}
|
|
904
892
|
noncesArray.push(nonce);
|
|
905
893
|
}
|
|
906
|
-
this.aggregatedNonce = (0,
|
|
894
|
+
this.aggregatedNonce = (0, musig2_1.muSig2NonceAgg)(noncesArray);
|
|
907
895
|
return this;
|
|
908
896
|
}
|
|
909
897
|
addPartialSignature(signerIndex, partialSig) {
|
|
@@ -920,14 +908,14 @@ class MuSigTaprootInput extends TaprootInput {
|
|
|
920
908
|
const numSigners = this.keyAggContext.pubkeys.length;
|
|
921
909
|
return this.partialSignatures.size === numSigners;
|
|
922
910
|
}
|
|
923
|
-
|
|
911
|
+
finalizeMuSig2Signature(transaction, message) {
|
|
924
912
|
if (!this.hasAllPartialSignatures()) {
|
|
925
913
|
throw new Error('Not all partial signatures received');
|
|
926
914
|
}
|
|
927
915
|
if (!this.aggregatedNonce) {
|
|
928
916
|
throw new Error('Nonces must be aggregated first');
|
|
929
917
|
}
|
|
930
|
-
const commitment = (0,
|
|
918
|
+
const commitment = (0, taproot_1.extractTaprootCommitment)(this.output.script);
|
|
931
919
|
const partialSigsArray = [];
|
|
932
920
|
for (let i = 0; i < this.keyAggContext.pubkeys.length; i++) {
|
|
933
921
|
const partialSig = this.partialSignatures.get(i);
|
|
@@ -936,8 +924,8 @@ class MuSigTaprootInput extends TaprootInput {
|
|
|
936
924
|
}
|
|
937
925
|
partialSigsArray.push(partialSig);
|
|
938
926
|
}
|
|
939
|
-
const finalSignature = (0,
|
|
940
|
-
const script = new
|
|
927
|
+
const finalSignature = (0, musig2_1.muSig2SigAgg)(partialSigsArray, this.aggregatedNonce, message, commitment);
|
|
928
|
+
const script = new script_1.Script();
|
|
941
929
|
script.add(finalSignature.toTxFormat('schnorr'));
|
|
942
930
|
this.setScript(script);
|
|
943
931
|
return this;
|
|
@@ -949,13 +937,4 @@ class MuSigTaprootInput extends TaprootInput {
|
|
|
949
937
|
this.script.chunks.length > 0));
|
|
950
938
|
}
|
|
951
939
|
}
|
|
952
|
-
exports.
|
|
953
|
-
Input.PublicKey = PublicKeyInput;
|
|
954
|
-
Input.PublicKeyHash = PublicKeyHashInput;
|
|
955
|
-
Input.Multisig = MultisigInput;
|
|
956
|
-
Input.MultisigScriptHash = MultisigScriptHashInput;
|
|
957
|
-
Input.Taproot = TaprootInput;
|
|
958
|
-
Input.MuSigTaproot = MuSigTaprootInput;
|
|
959
|
-
Input.P2PKH = PublicKeyHashInput;
|
|
960
|
-
Input.P2SH = MultisigScriptHashInput;
|
|
961
|
-
Input.P2TR = TaprootInput;
|
|
940
|
+
exports.MuSig2TaprootInput = MuSig2TaprootInput;
|