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,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ScriptTypes = exports.Script = void 0;
|
|
4
|
-
exports.toAddress = toAddress;
|
|
5
|
-
exports.empty = empty;
|
|
6
4
|
const preconditions_js_1 = require("./util/preconditions.js");
|
|
7
5
|
const bufferreader_js_1 = require("./encoding/bufferreader.js");
|
|
8
6
|
const bufferwriter_js_1 = require("./encoding/bufferwriter.js");
|
|
@@ -13,13 +11,17 @@ const address_js_1 = require("./address.js");
|
|
|
13
11
|
const errors_js_1 = require("./errors.js");
|
|
14
12
|
const buffer_js_1 = require("./util/buffer.js");
|
|
15
13
|
const signature_js_1 = require("./crypto/signature.js");
|
|
16
|
-
const chunk_js_1 = require("./chunk.js");
|
|
17
|
-
const taproot_js_1 = require("./taproot.js");
|
|
14
|
+
const chunk_js_1 = require("./script/chunk.js");
|
|
15
|
+
const taproot_js_1 = require("./script/taproot.js");
|
|
18
16
|
class Script {
|
|
19
17
|
chunks;
|
|
20
18
|
_network;
|
|
21
19
|
constructor(from) {
|
|
22
|
-
if (
|
|
20
|
+
if (!from) {
|
|
21
|
+
this.chunks = [];
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (buffer_js_1.BufferUtil.isBuffer(from)) {
|
|
23
25
|
return Script.fromBuffer(from);
|
|
24
26
|
}
|
|
25
27
|
else if (from instanceof address_js_1.Address) {
|
|
@@ -31,14 +33,9 @@ class Script {
|
|
|
31
33
|
else if (typeof from === 'string') {
|
|
32
34
|
return Script.fromString(from);
|
|
33
35
|
}
|
|
34
|
-
else if (typeof from === 'object' &&
|
|
35
|
-
from !== null &&
|
|
36
|
-
Array.isArray(from.chunks)) {
|
|
36
|
+
else if (typeof from === 'object' && Array.isArray(from.chunks)) {
|
|
37
37
|
this.set(from);
|
|
38
38
|
}
|
|
39
|
-
else {
|
|
40
|
-
this.chunks = [];
|
|
41
|
-
}
|
|
42
39
|
}
|
|
43
40
|
set(obj) {
|
|
44
41
|
preconditions_js_1.Preconditions.checkArgument(typeof obj === 'object', 'obj', 'Must be an object');
|
|
@@ -47,18 +44,25 @@ class Script {
|
|
|
47
44
|
this._network = obj._network;
|
|
48
45
|
return this;
|
|
49
46
|
}
|
|
47
|
+
static empty() {
|
|
48
|
+
return new Script();
|
|
49
|
+
}
|
|
50
50
|
static fromBuffer(buffer) {
|
|
51
|
-
const script =
|
|
51
|
+
const script = Script.empty();
|
|
52
52
|
script.chunks = [];
|
|
53
53
|
const br = new bufferreader_js_1.BufferReader(buffer);
|
|
54
54
|
while (!br.finished()) {
|
|
55
55
|
try {
|
|
56
56
|
const opcodenum = br.readUInt8();
|
|
57
57
|
let len, buf;
|
|
58
|
-
if (opcodenum
|
|
58
|
+
if (opcodenum >= 0 && opcodenum < opcode_js_1.Opcode.OP_PUSHDATA1) {
|
|
59
59
|
len = opcodenum;
|
|
60
|
+
buf = br.read(len);
|
|
61
|
+
if (buf.length !== len) {
|
|
62
|
+
throw new errors_js_1.BitcoreError.Script.InvalidBuffer(`Push data length mismatch: expected ${len}, got ${buf.length}`);
|
|
63
|
+
}
|
|
60
64
|
script.chunks.push(new chunk_js_1.Chunk({
|
|
61
|
-
buf:
|
|
65
|
+
buf: buf,
|
|
62
66
|
len: len,
|
|
63
67
|
opcodenum: opcodenum,
|
|
64
68
|
}));
|
|
@@ -66,6 +70,9 @@ class Script {
|
|
|
66
70
|
else if (opcodenum === opcode_js_1.Opcode.OP_PUSHDATA1) {
|
|
67
71
|
len = br.readUInt8();
|
|
68
72
|
buf = br.read(len);
|
|
73
|
+
if (buf.length !== len) {
|
|
74
|
+
throw new errors_js_1.BitcoreError.Script.InvalidBuffer(`OP_PUSHDATA1 length mismatch: expected ${len}, got ${buf.length}`);
|
|
75
|
+
}
|
|
69
76
|
script.chunks.push(new chunk_js_1.Chunk({
|
|
70
77
|
buf: buf,
|
|
71
78
|
len: len,
|
|
@@ -75,6 +82,9 @@ class Script {
|
|
|
75
82
|
else if (opcodenum === opcode_js_1.Opcode.OP_PUSHDATA2) {
|
|
76
83
|
len = br.readUInt16LE();
|
|
77
84
|
buf = br.read(len);
|
|
85
|
+
if (buf.length !== len) {
|
|
86
|
+
throw new errors_js_1.BitcoreError.Script.InvalidBuffer(`OP_PUSHDATA2 length mismatch: expected ${len}, got ${buf.length}`);
|
|
87
|
+
}
|
|
78
88
|
script.chunks.push(new chunk_js_1.Chunk({
|
|
79
89
|
buf: buf,
|
|
80
90
|
len: len,
|
|
@@ -84,6 +94,9 @@ class Script {
|
|
|
84
94
|
else if (opcodenum === opcode_js_1.Opcode.OP_PUSHDATA4) {
|
|
85
95
|
len = br.readUInt32LE();
|
|
86
96
|
buf = br.read(len);
|
|
97
|
+
if (buf.length !== len) {
|
|
98
|
+
throw new errors_js_1.BitcoreError.Script.InvalidBuffer(`OP_PUSHDATA4 length mismatch: expected ${len}, got ${buf.length}`);
|
|
99
|
+
}
|
|
87
100
|
script.chunks.push(new chunk_js_1.Chunk({
|
|
88
101
|
buf: buf,
|
|
89
102
|
len: len,
|
|
@@ -111,7 +124,7 @@ class Script {
|
|
|
111
124
|
if (!/^[0-9a-f]*$/.test(cleanStr)) {
|
|
112
125
|
throw new errors_js_1.BitcoreError.Script.InvalidScriptString(str);
|
|
113
126
|
}
|
|
114
|
-
const buffer =
|
|
127
|
+
const buffer = buffer_js_1.BufferUtil.from(cleanStr, 'hex');
|
|
115
128
|
return Script.fromBuffer(buffer);
|
|
116
129
|
}
|
|
117
130
|
static fromASM(str) {
|
|
@@ -124,7 +137,7 @@ class Script {
|
|
|
124
137
|
const opcode = new opcode_js_1.Opcode(token);
|
|
125
138
|
const opcodenum = opcode.num;
|
|
126
139
|
if (opcodenum === undefined) {
|
|
127
|
-
const buf =
|
|
140
|
+
const buf = buffer_js_1.BufferUtil.from(tokens[i], 'hex');
|
|
128
141
|
let opcodenum;
|
|
129
142
|
const len = buf.length;
|
|
130
143
|
if (len >= 0 && len < opcode_js_1.Opcode.OP_PUSHDATA1) {
|
|
@@ -159,14 +172,14 @@ class Script {
|
|
|
159
172
|
return script;
|
|
160
173
|
}
|
|
161
174
|
static fromHex(str) {
|
|
162
|
-
return new Script(
|
|
175
|
+
return new Script(buffer_js_1.BufferUtil.from(str, 'hex'));
|
|
163
176
|
}
|
|
164
177
|
static fromAddress(address) {
|
|
165
178
|
if (typeof address === 'string') {
|
|
166
179
|
address = address_js_1.Address.fromString(address);
|
|
167
180
|
}
|
|
168
181
|
if (address.isPayToTaproot()) {
|
|
169
|
-
return Script.
|
|
182
|
+
return Script.buildTaprootOut(address.hashBuffer);
|
|
170
183
|
}
|
|
171
184
|
else if (address.isPayToScriptHash()) {
|
|
172
185
|
return Script.buildScriptHashOut(address);
|
|
@@ -176,6 +189,55 @@ class Script {
|
|
|
176
189
|
}
|
|
177
190
|
throw new errors_js_1.BitcoreError.Script.UnrecognizedAddress(address);
|
|
178
191
|
}
|
|
192
|
+
static fromPayload(scriptType, payload) {
|
|
193
|
+
const buf = typeof payload === 'string' ? buffer_js_1.BufferUtil.from(payload, 'hex') : payload;
|
|
194
|
+
switch (scriptType) {
|
|
195
|
+
case 'p2pk': {
|
|
196
|
+
if (buf.length !== 33 && buf.length !== 65) {
|
|
197
|
+
throw new Error(`Invalid p2pk payload length: expected 33 (compressed) or 65 (uncompressed), got ${buf.length}`);
|
|
198
|
+
}
|
|
199
|
+
return Script.buildPublicKeyOut(new publickey_js_1.PublicKey(buf));
|
|
200
|
+
}
|
|
201
|
+
case 'p2pkh': {
|
|
202
|
+
if (buf.length !== 20) {
|
|
203
|
+
throw new Error(`Invalid p2pkh payload length: expected 20, got ${buf.length}`);
|
|
204
|
+
}
|
|
205
|
+
const p2pkhScript = new Script();
|
|
206
|
+
p2pkhScript.chunks = [];
|
|
207
|
+
p2pkhScript
|
|
208
|
+
.add(opcode_js_1.Opcode.OP_DUP)
|
|
209
|
+
.add(opcode_js_1.Opcode.OP_HASH160)
|
|
210
|
+
.add(buf)
|
|
211
|
+
.add(opcode_js_1.Opcode.OP_EQUALVERIFY)
|
|
212
|
+
.add(opcode_js_1.Opcode.OP_CHECKSIG);
|
|
213
|
+
return p2pkhScript;
|
|
214
|
+
}
|
|
215
|
+
case 'p2sh': {
|
|
216
|
+
if (buf.length !== 20) {
|
|
217
|
+
throw new Error(`Invalid p2sh payload length: expected 20, got ${buf.length}`);
|
|
218
|
+
}
|
|
219
|
+
const p2shScript = new Script();
|
|
220
|
+
p2shScript.add(opcode_js_1.Opcode.OP_HASH160).add(buf).add(opcode_js_1.Opcode.OP_EQUAL);
|
|
221
|
+
return p2shScript;
|
|
222
|
+
}
|
|
223
|
+
case 'p2tr-commitment': {
|
|
224
|
+
if (buf.length !== 33) {
|
|
225
|
+
throw new Error(`Invalid p2tr-commitment payload length: expected 33, got ${buf.length}`);
|
|
226
|
+
}
|
|
227
|
+
return Script.buildTaprootOut(buf);
|
|
228
|
+
}
|
|
229
|
+
case 'p2tr-state': {
|
|
230
|
+
throw new Error('Cannot reconstruct full script from p2tr-state payload alone; ' +
|
|
231
|
+
'the commitment is required. Use p2tr-commitment payload instead.');
|
|
232
|
+
}
|
|
233
|
+
case 'other': {
|
|
234
|
+
return Script.fromBuffer(buf);
|
|
235
|
+
}
|
|
236
|
+
default: {
|
|
237
|
+
throw new Error(`Unknown script type: ${scriptType}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
179
241
|
static buildMultisigOut(publicKeys, threshold, opts = {}) {
|
|
180
242
|
preconditions_js_1.Preconditions.checkArgument(threshold <= publicKeys.length, 'threshold', 'Number of required signatures must be less than or equal to the number of public keys');
|
|
181
243
|
const script = new Script();
|
|
@@ -318,13 +380,6 @@ class Script {
|
|
|
318
380
|
script.add((opts.cachedMultisig || Script.buildMultisigOut(pubkeys, threshold, opts)).toBuffer());
|
|
319
381
|
return script;
|
|
320
382
|
}
|
|
321
|
-
static buildWitnessMultisigOutFromScript(script) {
|
|
322
|
-
const scriptHash = hash_js_1.Hash.sha256(script.toBuffer());
|
|
323
|
-
const witnessScript = new Script();
|
|
324
|
-
witnessScript.add(opcode_js_1.Opcode.OP_0);
|
|
325
|
-
witnessScript.add(scriptHash);
|
|
326
|
-
return witnessScript;
|
|
327
|
-
}
|
|
328
383
|
static buildPublicKeyOut(pubkey) {
|
|
329
384
|
const script = new Script();
|
|
330
385
|
script.add(pubkey.toBuffer());
|
|
@@ -335,10 +390,10 @@ class Script {
|
|
|
335
390
|
let buffer;
|
|
336
391
|
if (typeof data === 'string') {
|
|
337
392
|
if (encoding === 'hex') {
|
|
338
|
-
buffer =
|
|
393
|
+
buffer = buffer_js_1.BufferUtil.from(data, 'hex');
|
|
339
394
|
}
|
|
340
395
|
else {
|
|
341
|
-
buffer =
|
|
396
|
+
buffer = buffer_js_1.BufferUtil.from(data, 'utf8');
|
|
342
397
|
}
|
|
343
398
|
}
|
|
344
399
|
else {
|
|
@@ -394,10 +449,10 @@ class Script {
|
|
|
394
449
|
script.add(publicKey.toBuffer());
|
|
395
450
|
return script;
|
|
396
451
|
}
|
|
397
|
-
static
|
|
452
|
+
static buildTaprootOut(commitment, state) {
|
|
398
453
|
preconditions_js_1.Preconditions.checkArgument(commitment !== undefined, 'commitment', 'Must be defined');
|
|
399
454
|
const commitmentBuf = commitment instanceof publickey_js_1.PublicKey ? commitment.toBuffer() : commitment;
|
|
400
|
-
if (commitmentBuf.length !==
|
|
455
|
+
if (commitmentBuf.length !== taproot_js_1.PUBKEY_COMPRESSED_SIZE) {
|
|
401
456
|
throw new Error('Taproot commitment must be 33-byte compressed public key');
|
|
402
457
|
}
|
|
403
458
|
if (state && state.length !== 32) {
|
|
@@ -418,7 +473,7 @@ class Script {
|
|
|
418
473
|
opcodenum: chunk.num,
|
|
419
474
|
}));
|
|
420
475
|
}
|
|
421
|
-
else if (
|
|
476
|
+
else if (buffer_js_1.BufferUtil.isBuffer(chunk)) {
|
|
422
477
|
const chunkObj = {
|
|
423
478
|
buf: chunk,
|
|
424
479
|
len: chunk.length,
|
|
@@ -448,6 +503,17 @@ class Script {
|
|
|
448
503
|
}
|
|
449
504
|
return this;
|
|
450
505
|
}
|
|
506
|
+
addTaprootState(state) {
|
|
507
|
+
if (state.length !== 32) {
|
|
508
|
+
throw new Error('Taproot state must be exactly 32 bytes');
|
|
509
|
+
}
|
|
510
|
+
if (this.chunks[3]) {
|
|
511
|
+
this.chunks[3].buf = state;
|
|
512
|
+
return this;
|
|
513
|
+
}
|
|
514
|
+
this.add(state);
|
|
515
|
+
return this;
|
|
516
|
+
}
|
|
451
517
|
toBuffer() {
|
|
452
518
|
const bw = new bufferwriter_js_1.BufferWriter();
|
|
453
519
|
for (const chunk of this.chunks) {
|
|
@@ -470,18 +536,6 @@ class Script {
|
|
|
470
536
|
toString() {
|
|
471
537
|
return this.toBuffer().toString('hex');
|
|
472
538
|
}
|
|
473
|
-
toP2PKH() {
|
|
474
|
-
if (!this.isPayToPublicKeyHash()) {
|
|
475
|
-
throw new Error('Script is not a P2PKH address');
|
|
476
|
-
}
|
|
477
|
-
return this.chunks[2].buf.toString('hex');
|
|
478
|
-
}
|
|
479
|
-
toP2SH() {
|
|
480
|
-
if (!this.isPayToScriptHash()) {
|
|
481
|
-
throw new Error('Script is not a P2SH address');
|
|
482
|
-
}
|
|
483
|
-
return this.chunks[1].buf.toString('hex');
|
|
484
|
-
}
|
|
485
539
|
toASM() {
|
|
486
540
|
let str = '';
|
|
487
541
|
for (let i = 0; i < this.chunks.length; i++) {
|
|
@@ -560,53 +614,37 @@ class Script {
|
|
|
560
614
|
}
|
|
561
615
|
return str;
|
|
562
616
|
}
|
|
563
|
-
|
|
617
|
+
isPublicKeyHashOut() {
|
|
564
618
|
return (this.chunks.length === 5 &&
|
|
565
619
|
this.chunks[0].opcodenum === opcode_js_1.Opcode.OP_DUP &&
|
|
566
620
|
this.chunks[1].opcodenum === opcode_js_1.Opcode.OP_HASH160 &&
|
|
567
621
|
this.chunks[2].opcodenum === 20 &&
|
|
568
|
-
this.chunks[2].buf
|
|
569
|
-
this.chunks[3].opcodenum === opcode_js_1.Opcode.OP_EQUALVERIFY &&
|
|
570
|
-
this.chunks[4].opcodenum === opcode_js_1.Opcode.OP_CHECKSIG);
|
|
571
|
-
}
|
|
572
|
-
isPublicKeyHashOut() {
|
|
573
|
-
return !!(this.chunks.length === 5 &&
|
|
574
|
-
this.chunks[0].opcodenum === opcode_js_1.Opcode.OP_DUP &&
|
|
575
|
-
this.chunks[1].opcodenum === opcode_js_1.Opcode.OP_HASH160 &&
|
|
576
|
-
this.chunks[2].buf &&
|
|
577
|
-
this.chunks[2].buf.length === 20 &&
|
|
622
|
+
this.chunks[2].buf?.length === 20 &&
|
|
578
623
|
this.chunks[3].opcodenum === opcode_js_1.Opcode.OP_EQUALVERIFY &&
|
|
579
624
|
this.chunks[4].opcodenum === opcode_js_1.Opcode.OP_CHECKSIG);
|
|
580
625
|
}
|
|
581
|
-
|
|
626
|
+
isScriptHashOut() {
|
|
582
627
|
return (this.chunks.length === 3 &&
|
|
583
628
|
this.chunks[0].opcodenum === opcode_js_1.Opcode.OP_HASH160 &&
|
|
584
629
|
this.chunks[1].opcodenum === 20 &&
|
|
585
|
-
this.chunks[1].buf
|
|
630
|
+
this.chunks[1].buf?.length === 20 &&
|
|
586
631
|
this.chunks[2].opcodenum === opcode_js_1.Opcode.OP_EQUAL);
|
|
587
632
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
buf[0] === opcode_js_1.Opcode.OP_HASH160 &&
|
|
592
|
-
buf[1] === 0x14 &&
|
|
593
|
-
buf[buf.length - 1] === opcode_js_1.Opcode.OP_EQUAL);
|
|
594
|
-
}
|
|
595
|
-
isPayToTaproot() {
|
|
596
|
-
const buf = this.toBuffer();
|
|
597
|
-
if (buf.length < taproot_js_1.TAPROOT_SIZE_WITHOUT_STATE ||
|
|
598
|
-
buf[0] !== opcode_js_1.Opcode.OP_SCRIPTTYPE ||
|
|
599
|
-
buf[1] !== opcode_js_1.Opcode.OP_1 ||
|
|
600
|
-
buf[2] !== 33) {
|
|
633
|
+
isTaprootOut() {
|
|
634
|
+
if (this.chunks[0].opcodenum !== opcode_js_1.Opcode.OP_SCRIPTTYPE ||
|
|
635
|
+
this.chunks[1].opcodenum !== opcode_js_1.Opcode.OP_1) {
|
|
601
636
|
return false;
|
|
602
637
|
}
|
|
603
|
-
if (
|
|
604
|
-
return
|
|
638
|
+
if (this.chunks.length === 3) {
|
|
639
|
+
return (this.chunks[2].opcodenum === 33 && this.chunks[2].buf?.length === 33);
|
|
605
640
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
641
|
+
if (this.chunks.length === 4) {
|
|
642
|
+
return (this.chunks[2].opcodenum === 33 &&
|
|
643
|
+
this.chunks[2].buf?.length === 33 &&
|
|
644
|
+
this.chunks[3].opcodenum === 32 &&
|
|
645
|
+
this.chunks[3].buf?.length === 32);
|
|
646
|
+
}
|
|
647
|
+
return false;
|
|
610
648
|
}
|
|
611
649
|
isTaprootIn() {
|
|
612
650
|
if (this.chunks.length === 0) {
|
|
@@ -637,20 +675,45 @@ class Script {
|
|
|
637
675
|
getData() {
|
|
638
676
|
if (this.isScriptHashOut()) {
|
|
639
677
|
if (this.chunks[1] === undefined) {
|
|
640
|
-
return
|
|
678
|
+
return buffer_js_1.BufferUtil.alloc(0);
|
|
641
679
|
}
|
|
642
680
|
else {
|
|
643
|
-
return
|
|
681
|
+
return buffer_js_1.BufferUtil.from(this.chunks[1].buf);
|
|
644
682
|
}
|
|
645
683
|
}
|
|
646
684
|
if (this.isPublicKeyHashOut()) {
|
|
647
|
-
return
|
|
685
|
+
return buffer_js_1.BufferUtil.from(this.chunks[2].buf);
|
|
648
686
|
}
|
|
649
|
-
if (this.
|
|
650
|
-
return
|
|
687
|
+
if (this.isTaprootOut()) {
|
|
688
|
+
return buffer_js_1.BufferUtil.from(this.chunks[2].buf);
|
|
651
689
|
}
|
|
652
690
|
throw new Error('Unrecognized script type to get data from');
|
|
653
691
|
}
|
|
692
|
+
getPayload() {
|
|
693
|
+
let type;
|
|
694
|
+
let payload;
|
|
695
|
+
if (this.isPublicKeyOut()) {
|
|
696
|
+
type = 'p2pk';
|
|
697
|
+
payload = buffer_js_1.BufferUtil.from(this.chunks[0].buf);
|
|
698
|
+
}
|
|
699
|
+
else if (this.isPublicKeyHashOut()) {
|
|
700
|
+
type = 'p2pkh';
|
|
701
|
+
payload = buffer_js_1.BufferUtil.from(this.chunks[2].buf);
|
|
702
|
+
}
|
|
703
|
+
else if (this.isScriptHashOut()) {
|
|
704
|
+
type = 'p2sh';
|
|
705
|
+
payload = buffer_js_1.BufferUtil.from(this.chunks[1].buf);
|
|
706
|
+
}
|
|
707
|
+
else if (this.isTaprootOut()) {
|
|
708
|
+
type = this.chunks.length === 4 ? 'p2tr-state' : 'p2tr-commitment';
|
|
709
|
+
payload = buffer_js_1.BufferUtil.from(this.chunks[2].buf);
|
|
710
|
+
}
|
|
711
|
+
else {
|
|
712
|
+
type = 'other';
|
|
713
|
+
payload = this.toBuffer();
|
|
714
|
+
}
|
|
715
|
+
return { type, payload, payloadHex: payload.toString('hex') };
|
|
716
|
+
}
|
|
654
717
|
getAddressInfo() {
|
|
655
718
|
if (this._isInput) {
|
|
656
719
|
return this._getInputAddressInfo();
|
|
@@ -668,7 +731,7 @@ class Script {
|
|
|
668
731
|
}
|
|
669
732
|
_getOutputAddressInfo() {
|
|
670
733
|
const info = {};
|
|
671
|
-
if (this.
|
|
734
|
+
if (this.isTaprootOut()) {
|
|
672
735
|
const buf = this.toBuffer();
|
|
673
736
|
info.hashBuffer = buf.slice(3, 36);
|
|
674
737
|
info.type = address_js_1.Address.PayToTaproot;
|
|
@@ -708,7 +771,7 @@ class Script {
|
|
|
708
771
|
}
|
|
709
772
|
if (info instanceof address_js_1.Address) {
|
|
710
773
|
if (network) {
|
|
711
|
-
if (this.
|
|
774
|
+
if (this.isTaprootOut()) {
|
|
712
775
|
const buf = this.toBuffer();
|
|
713
776
|
const commitment = buf.slice(3, 36);
|
|
714
777
|
return address_js_1.Address.fromTaprootCommitment(commitment, network);
|
|
@@ -763,7 +826,16 @@ class Script {
|
|
|
763
826
|
}
|
|
764
827
|
isValid() {
|
|
765
828
|
try {
|
|
766
|
-
|
|
829
|
+
for (const chunk of this.chunks) {
|
|
830
|
+
if (chunk.opcodenum === undefined) {
|
|
831
|
+
return false;
|
|
832
|
+
}
|
|
833
|
+
if (chunk.buf &&
|
|
834
|
+
(chunk.len === undefined || chunk.len !== chunk.buf.length)) {
|
|
835
|
+
return false;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
return true;
|
|
767
839
|
}
|
|
768
840
|
catch (e) {
|
|
769
841
|
return false;
|
|
@@ -773,7 +845,7 @@ class Script {
|
|
|
773
845
|
const cloned = new Script();
|
|
774
846
|
cloned.chunks = this.chunks.map(chunk => new chunk_js_1.Chunk({
|
|
775
847
|
opcodenum: chunk.opcodenum,
|
|
776
|
-
buf: chunk.buf ?
|
|
848
|
+
buf: chunk.buf ? buffer_js_1.BufferUtil.from(chunk.buf) : undefined,
|
|
777
849
|
len: chunk.len,
|
|
778
850
|
}));
|
|
779
851
|
return cloned;
|
|
@@ -864,7 +936,7 @@ class Script {
|
|
|
864
936
|
return (this.chunks.length > 3 &&
|
|
865
937
|
this._isSmallIntOp(this.chunks[0].opcodenum) &&
|
|
866
938
|
this.chunks.slice(1, this.chunks.length - 2).every(function (obj) {
|
|
867
|
-
return obj.buf &&
|
|
939
|
+
return obj.buf && buffer_js_1.BufferUtil.isBuffer(obj.buf);
|
|
868
940
|
}) &&
|
|
869
941
|
this._isSmallIntOp(this.chunks[this.chunks.length - 2].opcodenum) &&
|
|
870
942
|
this.chunks[this.chunks.length - 1].opcodenum === opcode_js_1.Opcode.OP_CHECKMULTISIG);
|
|
@@ -876,7 +948,7 @@ class Script {
|
|
|
876
948
|
return (this.chunks.length >= 2 &&
|
|
877
949
|
this.chunks[0].opcodenum === 0 &&
|
|
878
950
|
this.chunks.slice(1, this.chunks.length).every(function (obj) {
|
|
879
|
-
return obj.buf &&
|
|
951
|
+
return (obj.buf && buffer_js_1.BufferUtil.isBuffer(obj.buf) && signature_js_1.Signature.isTxDER(obj.buf));
|
|
880
952
|
}));
|
|
881
953
|
}
|
|
882
954
|
isDataOut() {
|
|
@@ -946,11 +1018,8 @@ class Script {
|
|
|
946
1018
|
return this.classify() !== exports.ScriptTypes.UNKNOWN;
|
|
947
1019
|
}
|
|
948
1020
|
getType() {
|
|
949
|
-
if (this.
|
|
950
|
-
|
|
951
|
-
return buf.length === taproot_js_1.TAPROOT_SIZE_WITH_STATE
|
|
952
|
-
? 'p2tr-state'
|
|
953
|
-
: 'p2tr-commitment';
|
|
1021
|
+
if (this.isTaprootOut()) {
|
|
1022
|
+
return this.chunks.length === 4 ? 'p2tr-state' : 'p2tr-commitment';
|
|
954
1023
|
}
|
|
955
1024
|
else if (this.isPublicKeyOut()) {
|
|
956
1025
|
return 'p2pk';
|
|
@@ -973,11 +1042,11 @@ class Script {
|
|
|
973
1042
|
return false;
|
|
974
1043
|
}
|
|
975
1044
|
for (let i = 0; i < this.chunks.length; i++) {
|
|
976
|
-
if (
|
|
977
|
-
!
|
|
1045
|
+
if (buffer_js_1.BufferUtil.isBuffer(this.chunks[i].buf) &&
|
|
1046
|
+
!buffer_js_1.BufferUtil.isBuffer(script.chunks[i].buf)) {
|
|
978
1047
|
return false;
|
|
979
1048
|
}
|
|
980
|
-
if (
|
|
1049
|
+
if (buffer_js_1.BufferUtil.isBuffer(this.chunks[i].buf) &&
|
|
981
1050
|
!buffer_js_1.BufferUtil.equals(this.chunks[i].buf, script.chunks[i].buf)) {
|
|
982
1051
|
return false;
|
|
983
1052
|
}
|
|
@@ -997,7 +1066,7 @@ class Script {
|
|
|
997
1066
|
else if (obj instanceof opcode_js_1.Opcode) {
|
|
998
1067
|
this._addOpcode(obj, prepend);
|
|
999
1068
|
}
|
|
1000
|
-
else if (
|
|
1069
|
+
else if (buffer_js_1.BufferUtil.isBuffer(obj)) {
|
|
1001
1070
|
this._addBuffer(obj, prepend);
|
|
1002
1071
|
}
|
|
1003
1072
|
else if (obj instanceof Script) {
|
|
@@ -1139,13 +1208,3 @@ exports.ScriptTypes = {
|
|
|
1139
1208
|
MULTISIG_IN: 'Spend from multisig',
|
|
1140
1209
|
DATA_OUT: 'Data push',
|
|
1141
1210
|
};
|
|
1142
|
-
function toAddress(script, network) {
|
|
1143
|
-
const addr = script.toAddress(network);
|
|
1144
|
-
if (!addr || typeof addr === 'boolean') {
|
|
1145
|
-
throw new Error('Cannot convert script to address');
|
|
1146
|
-
}
|
|
1147
|
-
return addr;
|
|
1148
|
-
}
|
|
1149
|
-
function empty() {
|
|
1150
|
-
return new Script();
|
|
1151
|
-
}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.buildMuSig2TaprootKey = buildMuSig2TaprootKey;
|
|
4
|
+
exports.buildMuSig2TaprootKeyWithScripts = buildMuSig2TaprootKeyWithScripts;
|
|
5
5
|
exports.signTaprootKeyPathWithMuSig2 = signTaprootKeyPathWithMuSig2;
|
|
6
6
|
exports.verifyTaprootKeyPathMuSigPartial = verifyTaprootKeyPathMuSigPartial;
|
|
7
7
|
exports.isMuSigTaprootOutput = isMuSigTaprootOutput;
|
|
8
8
|
exports.createMuSigTaprootAddress = createMuSigTaprootAddress;
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const address_1 = require("../address");
|
|
10
|
+
const buffer_1 = require("../util/buffer");
|
|
11
|
+
const index_1 = require("../crypto/index");
|
|
12
|
+
const musig2_1 = require("../crypto/musig2");
|
|
13
|
+
const taproot_1 = require("../script/taproot");
|
|
14
|
+
function buildMuSig2TaprootKey(signerPubKeys) {
|
|
15
|
+
const keyAggContext = (0, musig2_1.muSig2KeyAgg)(signerPubKeys);
|
|
15
16
|
const aggregatedPubKey = keyAggContext.aggregatedPubKey;
|
|
16
|
-
const merkleRoot =
|
|
17
|
-
const tweak = (0,
|
|
18
|
-
const commitment = (0,
|
|
19
|
-
const script = (0,
|
|
17
|
+
const merkleRoot = buffer_1.BufferUtil.alloc(32);
|
|
18
|
+
const tweak = (0, taproot_1.calculateTapTweak)(aggregatedPubKey, merkleRoot);
|
|
19
|
+
const commitment = (0, taproot_1.tweakPublicKey)(aggregatedPubKey, merkleRoot);
|
|
20
|
+
const script = (0, taproot_1.buildKeyPathTaproot)(aggregatedPubKey);
|
|
20
21
|
return {
|
|
21
22
|
aggregatedPubKey,
|
|
22
23
|
commitment,
|
|
@@ -26,11 +27,11 @@ function buildMuSigTaprootKey(signerPubKeys, state) {
|
|
|
26
27
|
tweak,
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
|
-
function
|
|
30
|
-
const keyAggContext = (0,
|
|
30
|
+
function buildMuSig2TaprootKeyWithScripts(signerPubKeys, scriptTree, state) {
|
|
31
|
+
const keyAggContext = (0, musig2_1.muSig2KeyAgg)(signerPubKeys);
|
|
31
32
|
const aggregatedPubKey = keyAggContext.aggregatedPubKey;
|
|
32
|
-
const { script, commitment, merkleRoot, leaves } = (0,
|
|
33
|
-
const tweak = (0,
|
|
33
|
+
const { script, commitment, merkleRoot, leaves } = (0, taproot_1.buildScriptPathTaproot)(aggregatedPubKey, scriptTree, state);
|
|
34
|
+
const tweak = (0, taproot_1.calculateTapTweak)(aggregatedPubKey, merkleRoot);
|
|
34
35
|
return {
|
|
35
36
|
aggregatedPubKey,
|
|
36
37
|
commitment,
|
|
@@ -42,35 +43,39 @@ function buildMuSigTaprootKeyWithScripts(signerPubKeys, scriptTree, state) {
|
|
|
42
43
|
};
|
|
43
44
|
}
|
|
44
45
|
function signTaprootKeyPathWithMuSig2(secretNonce, privateKey, keyAggContext, signerIndex, aggregatedNonce, message, tweak) {
|
|
45
|
-
const n =
|
|
46
|
+
const n = index_1.Point.getN();
|
|
46
47
|
const commitment = keyAggContext.aggregatedPubKey.addScalar(tweak);
|
|
47
48
|
const modifiedKeyAggContext = {
|
|
48
49
|
...keyAggContext,
|
|
49
50
|
aggregatedPubKey: commitment,
|
|
50
51
|
};
|
|
51
|
-
const partialSig = (0,
|
|
52
|
+
const partialSig = (0, musig2_1.muSig2PartialSign)(secretNonce, privateKey, modifiedKeyAggContext, signerIndex, aggregatedNonce, message);
|
|
52
53
|
if (signerIndex === 0) {
|
|
53
54
|
const { R1, R2 } = aggregatedNonce;
|
|
54
|
-
const nonceCoefData =
|
|
55
|
+
const nonceCoefData = buffer_1.BufferUtil.concat([
|
|
55
56
|
commitment.toBuffer(),
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
index_1.Point.pointToCompressed(R1),
|
|
58
|
+
index_1.Point.pointToCompressed(R2),
|
|
58
59
|
message,
|
|
59
60
|
]);
|
|
60
|
-
const b =
|
|
61
|
+
const b = index_1.BN.fromBuffer((0, musig2_1.muSig2TaggedHash)(musig2_1.MUSIG2_TAG_NONCE_COEFF, nonceCoefData));
|
|
61
62
|
const R = R1.add(R2.mul(b));
|
|
62
|
-
const R_x = R.
|
|
63
|
-
const commitment_compressed =
|
|
64
|
-
const challengeData =
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
const R_x = R.x.toBuffer({ size: 32 });
|
|
64
|
+
const commitment_compressed = index_1.Point.pointToCompressed(commitment.point);
|
|
65
|
+
const challengeData = buffer_1.BufferUtil.concat([
|
|
66
|
+
R_x,
|
|
67
|
+
commitment_compressed,
|
|
68
|
+
message,
|
|
69
|
+
]);
|
|
70
|
+
const e = index_1.BN.fromBuffer(index_1.Hash.sha256(challengeData)).umod(n);
|
|
71
|
+
const tweakBN = index_1.BN.fromBuffer(tweak).umod(n);
|
|
67
72
|
const tweakTerm = e.mul(tweakBN).umod(n);
|
|
68
73
|
return partialSig.add(tweakTerm).umod(n);
|
|
69
74
|
}
|
|
70
75
|
return partialSig;
|
|
71
76
|
}
|
|
72
77
|
function verifyTaprootKeyPathMuSigPartial(partialSig, publicNonce, publicKey, keyAggContext, signerIndex, aggregatedNonce, message, tweak) {
|
|
73
|
-
const n =
|
|
78
|
+
const n = index_1.Point.getN();
|
|
74
79
|
const commitment = keyAggContext.aggregatedPubKey.addScalar(tweak);
|
|
75
80
|
const modifiedKeyAggContext = {
|
|
76
81
|
...keyAggContext,
|
|
@@ -79,28 +84,32 @@ function verifyTaprootKeyPathMuSigPartial(partialSig, publicNonce, publicKey, ke
|
|
|
79
84
|
let adjustedPartialSig = partialSig;
|
|
80
85
|
if (signerIndex === 0) {
|
|
81
86
|
const { R1, R2 } = aggregatedNonce;
|
|
82
|
-
const nonceCoefData =
|
|
87
|
+
const nonceCoefData = buffer_1.BufferUtil.concat([
|
|
83
88
|
commitment.toBuffer(),
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
index_1.Point.pointToCompressed(R1),
|
|
90
|
+
index_1.Point.pointToCompressed(R2),
|
|
86
91
|
message,
|
|
87
92
|
]);
|
|
88
|
-
const b =
|
|
93
|
+
const b = index_1.BN.fromBuffer((0, musig2_1.muSig2TaggedHash)(musig2_1.MUSIG2_TAG_NONCE_COEFF, nonceCoefData));
|
|
89
94
|
const R = R1.add(R2.mul(b));
|
|
90
|
-
const R_x = R.
|
|
91
|
-
const commitment_compressed =
|
|
92
|
-
const challengeData =
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
const R_x = R.x.toBuffer({ size: 32 });
|
|
96
|
+
const commitment_compressed = index_1.Point.pointToCompressed(commitment.point);
|
|
97
|
+
const challengeData = buffer_1.BufferUtil.concat([
|
|
98
|
+
R_x,
|
|
99
|
+
commitment_compressed,
|
|
100
|
+
message,
|
|
101
|
+
]);
|
|
102
|
+
const e = index_1.BN.fromBuffer(index_1.Hash.sha256(challengeData)).umod(n);
|
|
103
|
+
const tweakBN = index_1.BN.fromBuffer(tweak).umod(n);
|
|
95
104
|
const tweakTerm = e.mul(tweakBN).umod(n);
|
|
96
105
|
adjustedPartialSig = partialSig.sub(tweakTerm).umod(n);
|
|
97
106
|
}
|
|
98
|
-
return (0,
|
|
107
|
+
return (0, musig2_1.muSig2PartialSigVerify)(adjustedPartialSig, publicNonce, publicKey, modifiedKeyAggContext, signerIndex, aggregatedNonce, message);
|
|
99
108
|
}
|
|
100
109
|
function isMuSigTaprootOutput(script) {
|
|
101
|
-
return script.
|
|
110
|
+
return script.isTaprootOut();
|
|
102
111
|
}
|
|
103
|
-
function createMuSigTaprootAddress(signerPubKeys, network
|
|
112
|
+
function createMuSigTaprootAddress(signerPubKeys, network) {
|
|
104
113
|
if (signerPubKeys.length === 0) {
|
|
105
114
|
throw new Error('At least one signer public key is required');
|
|
106
115
|
}
|
|
@@ -109,8 +118,8 @@ function createMuSigTaprootAddress(signerPubKeys, network, state) {
|
|
|
109
118
|
if (mismatchedKeyIndex !== -1) {
|
|
110
119
|
throw new Error(`Public key network mismatch at index ${mismatchedKeyIndex}: expected '${inferredNetwork}', got '${signerPubKeys[mismatchedKeyIndex].network.name}'`);
|
|
111
120
|
}
|
|
112
|
-
const result =
|
|
113
|
-
const address =
|
|
121
|
+
const result = buildMuSig2TaprootKey(signerPubKeys);
|
|
122
|
+
const address = address_1.Address.fromTaprootCommitment(result.commitment, inferredNetwork);
|
|
114
123
|
return {
|
|
115
124
|
address,
|
|
116
125
|
script: result.script,
|