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
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutPoint = exports.OUTPOINT_SIZE = void 0;
|
|
4
|
+
const bufferreader_js_1 = require("../encoding/bufferreader.js");
|
|
5
|
+
const bufferwriter_js_1 = require("../encoding/bufferwriter.js");
|
|
6
|
+
const buffer_js_1 = require("../util/buffer.js");
|
|
7
|
+
exports.OUTPOINT_SIZE = 36;
|
|
8
|
+
class OutPoint {
|
|
9
|
+
static NULL_INDEX = 0xffffffff;
|
|
10
|
+
_txid;
|
|
11
|
+
_n;
|
|
12
|
+
constructor(txid, n) {
|
|
13
|
+
if (txid === undefined) {
|
|
14
|
+
this._txid = buffer_js_1.BufferUtil.alloc(32, 0);
|
|
15
|
+
this._n = OutPoint.NULL_INDEX;
|
|
16
|
+
}
|
|
17
|
+
else if (buffer_js_1.BufferUtil.isBuffer(txid)) {
|
|
18
|
+
if (txid.length !== 32) {
|
|
19
|
+
throw new TypeError(`OutPoint txid buffer must be 32 bytes, got ${txid.length}`);
|
|
20
|
+
}
|
|
21
|
+
this._txid = buffer_js_1.BufferUtil.from(txid);
|
|
22
|
+
this._n = n !== undefined ? n >>> 0 : OutPoint.NULL_INDEX;
|
|
23
|
+
}
|
|
24
|
+
else if (typeof txid === 'string') {
|
|
25
|
+
if (txid.length !== 64) {
|
|
26
|
+
throw new TypeError(`OutPoint txid hex string must be 64 characters, got ${txid.length}`);
|
|
27
|
+
}
|
|
28
|
+
this._txid = buffer_js_1.BufferUtil.reverse(buffer_js_1.BufferUtil.from(txid, 'hex'));
|
|
29
|
+
this._n = n !== undefined ? n >>> 0 : OutPoint.NULL_INDEX;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new TypeError('OutPoint txid must be a Buffer or hex string');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
static fromObject(data) {
|
|
36
|
+
return new OutPoint(data.txid, data.outputIndex);
|
|
37
|
+
}
|
|
38
|
+
static fromBuffer(buf) {
|
|
39
|
+
const reader = new bufferreader_js_1.BufferReader(buf);
|
|
40
|
+
return OutPoint.fromBufferReader(reader);
|
|
41
|
+
}
|
|
42
|
+
static fromBufferReader(reader) {
|
|
43
|
+
const txidBuf = reader.read(32);
|
|
44
|
+
const n = reader.readUInt32LE();
|
|
45
|
+
const outpoint = new OutPoint();
|
|
46
|
+
outpoint._txid = txidBuf;
|
|
47
|
+
outpoint._n = n;
|
|
48
|
+
return outpoint;
|
|
49
|
+
}
|
|
50
|
+
isNull() {
|
|
51
|
+
return (this._n === OutPoint.NULL_INDEX && this._txid.every(byte => byte === 0));
|
|
52
|
+
}
|
|
53
|
+
getTxId() {
|
|
54
|
+
return buffer_js_1.BufferUtil.reverse(this._txid).toString('hex');
|
|
55
|
+
}
|
|
56
|
+
getTxIdBuffer() {
|
|
57
|
+
return buffer_js_1.BufferUtil.from(this._txid);
|
|
58
|
+
}
|
|
59
|
+
getN() {
|
|
60
|
+
return this._n;
|
|
61
|
+
}
|
|
62
|
+
toBuffer() {
|
|
63
|
+
const writer = new bufferwriter_js_1.BufferWriter();
|
|
64
|
+
this.toBufferWriter(writer);
|
|
65
|
+
return writer.toBuffer();
|
|
66
|
+
}
|
|
67
|
+
toBufferWriter(writer) {
|
|
68
|
+
writer.write(this._txid);
|
|
69
|
+
writer.writeUInt32LE(this._n);
|
|
70
|
+
return writer;
|
|
71
|
+
}
|
|
72
|
+
toObject() {
|
|
73
|
+
return {
|
|
74
|
+
txid: this.getTxId(),
|
|
75
|
+
outputIndex: this._n,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
toString() {
|
|
79
|
+
return `COutPoint(${this.getTxId().substring(0, 10)}, ${this._n})`;
|
|
80
|
+
}
|
|
81
|
+
equals(other) {
|
|
82
|
+
return this._txid.equals(other._txid) && this._n === other._n;
|
|
83
|
+
}
|
|
84
|
+
lessThan(other) {
|
|
85
|
+
const cmp = this._txid.compare(other._txid);
|
|
86
|
+
return cmp < 0 || (cmp === 0 && this._n < other._n);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.OutPoint = OutPoint;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Output = void 0;
|
|
4
|
+
const bn_js_1 = require("../crypto/bn.js");
|
|
4
5
|
const preconditions_js_1 = require("../util/preconditions.js");
|
|
5
6
|
const errors_js_1 = require("../errors.js");
|
|
6
7
|
const bufferwriter_js_1 = require("../encoding/bufferwriter.js");
|
|
8
|
+
const buffer_js_1 = require("../util/buffer.js");
|
|
7
9
|
const js_js_1 = require("../util/js.js");
|
|
8
10
|
const script_js_1 = require("../script.js");
|
|
9
|
-
const
|
|
11
|
+
const opcode_js_1 = require("../opcode.js");
|
|
10
12
|
const MAX_SAFE_INTEGER = 0x1fffffffffffff;
|
|
11
13
|
class Output {
|
|
12
14
|
satoshis;
|
|
@@ -22,7 +24,7 @@ class Output {
|
|
|
22
24
|
this.satoshis = 0;
|
|
23
25
|
this._satoshisBN = new bn_js_1.BN(0);
|
|
24
26
|
}
|
|
25
|
-
if (
|
|
27
|
+
if (buffer_js_1.BufferUtil.isBuffer(args.script)) {
|
|
26
28
|
this._scriptBuffer = args.script;
|
|
27
29
|
}
|
|
28
30
|
else if (args.scriptBuffer !== undefined) {
|
|
@@ -32,7 +34,7 @@ class Output {
|
|
|
32
34
|
this.setScript(args.script);
|
|
33
35
|
}
|
|
34
36
|
else {
|
|
35
|
-
this._scriptBuffer =
|
|
37
|
+
this._scriptBuffer = buffer_js_1.BufferUtil.alloc(0);
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
else {
|
|
@@ -111,7 +113,7 @@ class Output {
|
|
|
111
113
|
this._scriptBuffer = this._script.toBuffer();
|
|
112
114
|
this._script._isOutput = true;
|
|
113
115
|
}
|
|
114
|
-
else if (
|
|
116
|
+
else if (buffer_js_1.BufferUtil.isBuffer(script)) {
|
|
115
117
|
this.setScriptFromBuffer(script);
|
|
116
118
|
}
|
|
117
119
|
else {
|
|
@@ -153,7 +155,7 @@ class Output {
|
|
|
153
155
|
}
|
|
154
156
|
return !!(this._script &&
|
|
155
157
|
this._script.chunks.length > 0 &&
|
|
156
|
-
this._script.chunks[0].opcodenum ===
|
|
158
|
+
this._script.chunks[0].opcodenum === opcode_js_1.Opcode.OP_RETURN);
|
|
157
159
|
}
|
|
158
160
|
toObject() {
|
|
159
161
|
return {
|
|
@@ -181,7 +183,7 @@ class Output {
|
|
|
181
183
|
obj.script = br.read(size);
|
|
182
184
|
}
|
|
183
185
|
else {
|
|
184
|
-
obj.script =
|
|
186
|
+
obj.script = buffer_js_1.BufferUtil.from([]);
|
|
185
187
|
}
|
|
186
188
|
return new Output(obj);
|
|
187
189
|
}
|
|
@@ -217,10 +219,13 @@ class Output {
|
|
|
217
219
|
return new Output(data);
|
|
218
220
|
}
|
|
219
221
|
isPayToPublicKeyHash() {
|
|
220
|
-
return this.script.
|
|
222
|
+
return this.script.isPublicKeyHashOut();
|
|
221
223
|
}
|
|
222
224
|
isPayToScriptHash() {
|
|
223
|
-
return this.script.
|
|
225
|
+
return this.script.isScriptHashOut();
|
|
226
|
+
}
|
|
227
|
+
isPayToTaproot() {
|
|
228
|
+
return this.script.isTaprootOut();
|
|
224
229
|
}
|
|
225
230
|
getAddress() {
|
|
226
231
|
try {
|
|
@@ -4,26 +4,26 @@ exports.BITS_64_ON = exports.SIGHASH_SINGLE_BUG = exports.DEFAULT_SIGN_FLAGS = v
|
|
|
4
4
|
exports.sighash = sighash;
|
|
5
5
|
exports.sign = sign;
|
|
6
6
|
exports.verify = verify;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
7
|
+
const signature_1 = require("../crypto/signature");
|
|
8
|
+
const script_1 = require("../script");
|
|
9
|
+
const output_1 = require("./output");
|
|
10
|
+
const bufferreader_1 = require("../encoding/bufferreader");
|
|
11
|
+
const bufferwriter_1 = require("../encoding/bufferwriter");
|
|
12
|
+
const bn_1 = require("../crypto/bn");
|
|
13
|
+
const hash_1 = require("../crypto/hash");
|
|
14
|
+
const ecdsa_1 = require("../crypto/ecdsa");
|
|
15
|
+
const schnorr_1 = require("../crypto/schnorr");
|
|
16
|
+
const preconditions_1 = require("../util/preconditions");
|
|
17
|
+
const buffer_1 = require("../util/buffer");
|
|
18
|
+
const interpreter_1 = require("../script/interpreter");
|
|
19
|
+
const transaction_1 = require("./transaction");
|
|
20
|
+
const input_1 = require("./input");
|
|
21
21
|
const SIGHASH_SINGLE_BUG_CONST = '0000000000000000000000000000000000000000000000000000000000000001';
|
|
22
22
|
const BITS_64_ON_CONST = 'ffffffffffffffff';
|
|
23
|
-
const NULL_HASH =
|
|
24
|
-
const SIGHASH_ALGORITHM_MASK =
|
|
23
|
+
const NULL_HASH = buffer_1.BufferUtil.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
|
|
24
|
+
const SIGHASH_ALGORITHM_MASK = signature_1.Signature.SIGHASH_ALGORITHM_MASK;
|
|
25
25
|
const DEFAULT_SIGN_FLAGS_CONST = 1 << 16;
|
|
26
|
-
function
|
|
26
|
+
function getForkId() {
|
|
27
27
|
return 0;
|
|
28
28
|
}
|
|
29
29
|
function getMerkleRoot(hashes) {
|
|
@@ -38,8 +38,8 @@ function getMerkleRoot(hashes) {
|
|
|
38
38
|
for (let i = 0; i < currentHashes.length; i += 2) {
|
|
39
39
|
const left = currentHashes[i];
|
|
40
40
|
const right = i + 1 < currentHashes.length ? currentHashes[i + 1] : NULL_HASH;
|
|
41
|
-
const combined =
|
|
42
|
-
const pairHash =
|
|
41
|
+
const combined = buffer_1.BufferUtil.concat([left, right]);
|
|
42
|
+
const pairHash = hash_1.Hash.sha256sha256(combined);
|
|
43
43
|
newHashes.push(pairHash);
|
|
44
44
|
}
|
|
45
45
|
currentHashes = newHashes;
|
|
@@ -47,107 +47,107 @@ function getMerkleRoot(hashes) {
|
|
|
47
47
|
return { root: currentHashes[0], height };
|
|
48
48
|
}
|
|
49
49
|
function sighashForLotus(transaction, sighashType, inputNumber, spentOutputs, executedScriptHash, codeseparatorPos = 0xffffffff) {
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
preconditions_1.Preconditions.checkArgument(spentOutputs.length === transaction.inputs.length, 'Must provide spent output for each input');
|
|
51
|
+
preconditions_1.Preconditions.checkArgument(inputNumber < transaction.inputs.length, 'Input index out of range');
|
|
52
52
|
const baseType = sighashType & 0x03;
|
|
53
53
|
const unusedBits = sighashType & 0x1c;
|
|
54
54
|
if (baseType === 0 || unusedBits !== 0) {
|
|
55
55
|
throw new Error('Invalid sighash type for SIGHASH_LOTUS');
|
|
56
56
|
}
|
|
57
57
|
const input = transaction.inputs[inputNumber];
|
|
58
|
-
const writer = new
|
|
58
|
+
const writer = new bufferwriter_1.BufferWriter();
|
|
59
59
|
writer.writeUInt32LE(sighashType >>> 0);
|
|
60
60
|
const spendType = executedScriptHash ? 2 : 0;
|
|
61
|
-
const inputHashWriter = new
|
|
61
|
+
const inputHashWriter = new bufferwriter_1.BufferWriter();
|
|
62
62
|
inputHashWriter.writeUInt8(spendType);
|
|
63
63
|
inputHashWriter.writeReverse(input.prevTxId);
|
|
64
64
|
inputHashWriter.writeUInt32LE(input.outputIndex);
|
|
65
65
|
inputHashWriter.writeUInt32LE(input.sequenceNumber);
|
|
66
66
|
const spentOutput = spentOutputs[inputNumber];
|
|
67
|
-
inputHashWriter.writeUInt64LEBN(new
|
|
67
|
+
inputHashWriter.writeUInt64LEBN(new bn_1.BN(spentOutput.satoshis));
|
|
68
68
|
inputHashWriter.writeVarLengthBuffer(spentOutput.scriptBuffer);
|
|
69
|
-
const inputHash =
|
|
69
|
+
const inputHash = hash_1.Hash.sha256sha256(inputHashWriter.toBuffer());
|
|
70
70
|
writer.write(inputHash);
|
|
71
71
|
if (executedScriptHash) {
|
|
72
|
-
|
|
72
|
+
preconditions_1.Preconditions.checkArgument(executedScriptHash.length === 32, 'executed_script_hash must be 32 bytes');
|
|
73
73
|
writer.writeUInt32LE(codeseparatorPos);
|
|
74
74
|
writer.write(executedScriptHash);
|
|
75
75
|
}
|
|
76
|
-
if (!(sighashType &
|
|
76
|
+
if (!(sighashType & signature_1.Signature.SIGHASH_ANYONECANPAY)) {
|
|
77
77
|
writer.writeUInt32LE(inputNumber);
|
|
78
78
|
const spentOutputHashes = spentOutputs.map(output => {
|
|
79
|
-
const w = new
|
|
80
|
-
w.writeUInt64LEBN(new
|
|
79
|
+
const w = new bufferwriter_1.BufferWriter();
|
|
80
|
+
w.writeUInt64LEBN(new bn_1.BN(output.satoshis));
|
|
81
81
|
w.writeVarLengthBuffer(output.scriptBuffer);
|
|
82
|
-
return
|
|
82
|
+
return hash_1.Hash.sha256sha256(w.toBuffer());
|
|
83
83
|
});
|
|
84
84
|
const spentOutputsMerkle = getMerkleRoot(spentOutputHashes);
|
|
85
85
|
writer.write(spentOutputsMerkle.root);
|
|
86
86
|
const totalInputAmount = spentOutputs.reduce((sum, output) => sum + output.satoshis, 0);
|
|
87
|
-
writer.writeUInt64LEBN(new
|
|
87
|
+
writer.writeUInt64LEBN(new bn_1.BN(totalInputAmount));
|
|
88
88
|
}
|
|
89
|
-
if (baseType ===
|
|
89
|
+
if (baseType === signature_1.Signature.SIGHASH_ALL) {
|
|
90
90
|
const totalOutputAmount = transaction.outputs.reduce((sum, output) => sum + output.satoshis, 0);
|
|
91
|
-
writer.writeUInt64LEBN(new
|
|
91
|
+
writer.writeUInt64LEBN(new bn_1.BN(totalOutputAmount));
|
|
92
92
|
}
|
|
93
93
|
writer.writeUInt32LE(transaction.version || 2);
|
|
94
|
-
if (!(sighashType &
|
|
94
|
+
if (!(sighashType & signature_1.Signature.SIGHASH_ANYONECANPAY)) {
|
|
95
95
|
const inputHashes = transaction.inputs.map(inp => {
|
|
96
|
-
const w = new
|
|
96
|
+
const w = new bufferwriter_1.BufferWriter();
|
|
97
97
|
w.writeReverse(inp.prevTxId);
|
|
98
98
|
w.writeUInt32LE(inp.outputIndex);
|
|
99
99
|
w.writeUInt32LE(inp.sequenceNumber);
|
|
100
|
-
return
|
|
100
|
+
return hash_1.Hash.sha256sha256(w.toBuffer());
|
|
101
101
|
});
|
|
102
102
|
const inputsMerkle = getMerkleRoot(inputHashes);
|
|
103
103
|
writer.write(inputsMerkle.root);
|
|
104
104
|
writer.writeUInt8(inputsMerkle.height);
|
|
105
105
|
}
|
|
106
|
-
if (baseType ===
|
|
106
|
+
if (baseType === signature_1.Signature.SIGHASH_SINGLE) {
|
|
107
107
|
if (inputNumber >= transaction.outputs.length) {
|
|
108
108
|
throw new Error('SIGHASH_SINGLE: no corresponding output for input');
|
|
109
109
|
}
|
|
110
|
-
const w = new
|
|
110
|
+
const w = new bufferwriter_1.BufferWriter();
|
|
111
111
|
transaction.outputs[inputNumber].toBufferWriter(w);
|
|
112
|
-
const outputHash =
|
|
112
|
+
const outputHash = hash_1.Hash.sha256sha256(w.toBuffer());
|
|
113
113
|
writer.write(outputHash);
|
|
114
114
|
}
|
|
115
|
-
if (baseType ===
|
|
115
|
+
if (baseType === signature_1.Signature.SIGHASH_ALL) {
|
|
116
116
|
const outputHashes = transaction.outputs.map(output => {
|
|
117
|
-
const w = new
|
|
117
|
+
const w = new bufferwriter_1.BufferWriter();
|
|
118
118
|
output.toBufferWriter(w);
|
|
119
|
-
return
|
|
119
|
+
return hash_1.Hash.sha256sha256(w.toBuffer());
|
|
120
120
|
});
|
|
121
121
|
const outputsMerkle = getMerkleRoot(outputHashes);
|
|
122
122
|
writer.write(outputsMerkle.root);
|
|
123
123
|
writer.writeUInt8(outputsMerkle.height);
|
|
124
124
|
}
|
|
125
125
|
writer.writeUInt32LE(transaction.nLockTime || 0);
|
|
126
|
-
return
|
|
126
|
+
return hash_1.Hash.sha256sha256(writer.toBuffer());
|
|
127
127
|
}
|
|
128
128
|
function sighashForForkId(transaction, sighashType, inputNumber, subscript, satoshisBN) {
|
|
129
129
|
const input = transaction.inputs[inputNumber];
|
|
130
|
-
|
|
131
|
-
let hashPrevouts =
|
|
132
|
-
let hashSequence =
|
|
133
|
-
let hashOutputs =
|
|
134
|
-
if (!(sighashType &
|
|
130
|
+
preconditions_1.Preconditions.checkArgument(satoshisBN instanceof bn_1.BN, 'For ForkId=0 signatures, satoshis or complete input must be provided');
|
|
131
|
+
let hashPrevouts = buffer_1.BufferUtil.emptyBuffer(32);
|
|
132
|
+
let hashSequence = buffer_1.BufferUtil.emptyBuffer(32);
|
|
133
|
+
let hashOutputs = buffer_1.BufferUtil.emptyBuffer(32);
|
|
134
|
+
if (!(sighashType & signature_1.Signature.SIGHASH_ANYONECANPAY)) {
|
|
135
135
|
hashPrevouts = GetPrevoutHash(transaction);
|
|
136
136
|
}
|
|
137
|
-
if (!(sighashType &
|
|
138
|
-
(sighashType & 31) !==
|
|
139
|
-
(sighashType & 31) !==
|
|
137
|
+
if (!(sighashType & signature_1.Signature.SIGHASH_ANYONECANPAY) &&
|
|
138
|
+
(sighashType & 31) !== signature_1.Signature.SIGHASH_SINGLE &&
|
|
139
|
+
(sighashType & 31) !== signature_1.Signature.SIGHASH_NONE) {
|
|
140
140
|
hashSequence = GetSequenceHash(transaction);
|
|
141
141
|
}
|
|
142
|
-
if ((sighashType & 31) !==
|
|
143
|
-
(sighashType & 31) !==
|
|
142
|
+
if ((sighashType & 31) !== signature_1.Signature.SIGHASH_SINGLE &&
|
|
143
|
+
(sighashType & 31) !== signature_1.Signature.SIGHASH_NONE) {
|
|
144
144
|
hashOutputs = GetOutputsHash(transaction);
|
|
145
145
|
}
|
|
146
|
-
else if ((sighashType & 31) ===
|
|
146
|
+
else if ((sighashType & 31) === signature_1.Signature.SIGHASH_SINGLE &&
|
|
147
147
|
inputNumber < transaction.outputs.length) {
|
|
148
148
|
hashOutputs = GetOutputsHash(transaction, inputNumber);
|
|
149
149
|
}
|
|
150
|
-
const writer = new
|
|
150
|
+
const writer = new bufferwriter_1.BufferWriter();
|
|
151
151
|
writer.writeUInt32LE(transaction.version || 2);
|
|
152
152
|
writer.write(hashPrevouts);
|
|
153
153
|
writer.write(hashSequence);
|
|
@@ -161,16 +161,16 @@ function sighashForForkId(transaction, sighashType, inputNumber, subscript, sato
|
|
|
161
161
|
writer.writeUInt32LE(transaction.nLockTime || 0);
|
|
162
162
|
writer.writeUInt32LE(sighashType >>> 0);
|
|
163
163
|
const buf = writer.toBuffer();
|
|
164
|
-
const hash =
|
|
165
|
-
return new
|
|
164
|
+
const hash = hash_1.Hash.sha256sha256(buf);
|
|
165
|
+
return new bufferreader_1.BufferReader(hash).read(32);
|
|
166
166
|
}
|
|
167
167
|
function sighashLegacy(transaction, sighashType, inputNumber, subscript) {
|
|
168
168
|
const input = transaction.inputs[inputNumber];
|
|
169
169
|
function getHash(w) {
|
|
170
170
|
const buf = w.toBuffer();
|
|
171
|
-
return
|
|
171
|
+
return hash_1.Hash.sha256sha256(buf);
|
|
172
172
|
}
|
|
173
|
-
const writer = new
|
|
173
|
+
const writer = new bufferwriter_1.BufferWriter();
|
|
174
174
|
writer.writeUInt32LE(2);
|
|
175
175
|
writer.writeVarintNum(transaction.inputs.length);
|
|
176
176
|
for (let i = 0; i < transaction.inputs.length; i++) {
|
|
@@ -186,13 +186,13 @@ function sighashLegacy(transaction, sighashType, inputNumber, subscript) {
|
|
|
186
186
|
writer.writeUInt32LENumber(txInput.sequenceNumber);
|
|
187
187
|
}
|
|
188
188
|
writer.writeVarintNum(transaction.outputs.length);
|
|
189
|
-
if ((sighashType & 31) !==
|
|
190
|
-
(sighashType & 31) !==
|
|
189
|
+
if ((sighashType & 31) !== signature_1.Signature.SIGHASH_SINGLE &&
|
|
190
|
+
(sighashType & 31) !== signature_1.Signature.SIGHASH_NONE) {
|
|
191
191
|
for (const output of transaction.outputs) {
|
|
192
192
|
output.toBufferWriter(writer);
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
-
else if ((sighashType & 31) ===
|
|
195
|
+
else if ((sighashType & 31) === signature_1.Signature.SIGHASH_SINGLE &&
|
|
196
196
|
inputNumber < transaction.outputs.length) {
|
|
197
197
|
transaction.outputs[inputNumber].toBufferWriter(writer);
|
|
198
198
|
}
|
|
@@ -204,85 +204,85 @@ function sighash(transaction, sighashType, inputNumber, subscript, satoshisBN, f
|
|
|
204
204
|
if (flags === undefined) {
|
|
205
205
|
flags = DEFAULT_SIGN_FLAGS_CONST;
|
|
206
206
|
}
|
|
207
|
-
const txcopy =
|
|
208
|
-
subscript = new
|
|
209
|
-
if (flags &
|
|
207
|
+
const txcopy = transaction_1.Transaction.shallowCopy(transaction);
|
|
208
|
+
subscript = new script_1.Script(subscript);
|
|
209
|
+
if (flags & interpreter_1.Interpreter.SCRIPT_ENABLE_REPLAY_PROTECTION) {
|
|
210
210
|
const forkValue = sighashType >> 8;
|
|
211
211
|
const newForkValue = 0xff0000 | (forkValue ^ 0xdead);
|
|
212
212
|
sighashType = (newForkValue << 8) | (sighashType & 0xff);
|
|
213
213
|
}
|
|
214
214
|
const algorithmBits = sighashType & SIGHASH_ALGORITHM_MASK;
|
|
215
|
-
if (algorithmBits ===
|
|
216
|
-
flags &
|
|
215
|
+
if (algorithmBits === signature_1.Signature.SIGHASH_LOTUS &&
|
|
216
|
+
flags & interpreter_1.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID) {
|
|
217
217
|
const spentOutputs = transaction.spentOutputs;
|
|
218
218
|
if (!spentOutputs || spentOutputs.length !== transaction.inputs.length) {
|
|
219
219
|
throw new Error('SIGHASH_LOTUS requires spent outputs for all inputs (ensure all inputs have output information)');
|
|
220
220
|
}
|
|
221
221
|
return sighashForLotus(txcopy, sighashType, inputNumber, spentOutputs);
|
|
222
222
|
}
|
|
223
|
-
if (algorithmBits ===
|
|
224
|
-
flags &
|
|
223
|
+
if (algorithmBits === signature_1.Signature.SIGHASH_FORKID &&
|
|
224
|
+
flags & interpreter_1.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID) {
|
|
225
225
|
return sighashForForkId(txcopy, sighashType, inputNumber, subscript, satoshisBN);
|
|
226
226
|
}
|
|
227
227
|
subscript.removeCodeseparators();
|
|
228
228
|
for (let i = 0; i < txcopy.inputs.length; i++) {
|
|
229
|
-
txcopy.inputs[i] = new
|
|
229
|
+
txcopy.inputs[i] = new input_1.Input({
|
|
230
230
|
prevTxId: txcopy.inputs[i].prevTxId,
|
|
231
231
|
outputIndex: txcopy.inputs[i].outputIndex,
|
|
232
232
|
sequenceNumber: txcopy.inputs[i].sequenceNumber,
|
|
233
|
-
script:
|
|
233
|
+
script: script_1.Script.empty(),
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
|
-
txcopy.inputs[inputNumber] = new
|
|
236
|
+
txcopy.inputs[inputNumber] = new input_1.Input({
|
|
237
237
|
prevTxId: txcopy.inputs[inputNumber].prevTxId,
|
|
238
238
|
outputIndex: txcopy.inputs[inputNumber].outputIndex,
|
|
239
239
|
sequenceNumber: txcopy.inputs[inputNumber].sequenceNumber,
|
|
240
240
|
script: subscript,
|
|
241
241
|
});
|
|
242
|
-
if ((sighashType & 31) ===
|
|
243
|
-
(sighashType & 31) ===
|
|
242
|
+
if ((sighashType & 31) === signature_1.Signature.SIGHASH_NONE ||
|
|
243
|
+
(sighashType & 31) === signature_1.Signature.SIGHASH_SINGLE) {
|
|
244
244
|
for (let i = 0; i < txcopy.inputs.length; i++) {
|
|
245
245
|
if (i !== inputNumber) {
|
|
246
246
|
txcopy.inputs[i].sequenceNumber = 0;
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
|
-
if ((sighashType & 31) ===
|
|
250
|
+
if ((sighashType & 31) === signature_1.Signature.SIGHASH_NONE) {
|
|
251
251
|
txcopy.outputs = [];
|
|
252
252
|
}
|
|
253
|
-
else if ((sighashType & 31) ===
|
|
253
|
+
else if ((sighashType & 31) === signature_1.Signature.SIGHASH_SINGLE) {
|
|
254
254
|
if (inputNumber >= txcopy.outputs.length) {
|
|
255
|
-
return
|
|
255
|
+
return buffer_1.BufferUtil.from(SIGHASH_SINGLE_BUG_CONST, 'hex');
|
|
256
256
|
}
|
|
257
257
|
txcopy.outputs.length = inputNumber + 1;
|
|
258
258
|
for (let i = 0; i < inputNumber; i++) {
|
|
259
|
-
txcopy.outputs[i] = new
|
|
260
|
-
satoshis:
|
|
261
|
-
script:
|
|
259
|
+
txcopy.outputs[i] = new output_1.Output({
|
|
260
|
+
satoshis: bn_1.BN.fromBuffer(buffer_1.BufferUtil.from(BITS_64_ON_CONST, 'hex')),
|
|
261
|
+
script: script_1.Script.empty(),
|
|
262
262
|
});
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
-
if (sighashType &
|
|
265
|
+
if (sighashType & signature_1.Signature.SIGHASH_ANYONECANPAY) {
|
|
266
266
|
txcopy.inputs = [txcopy.inputs[inputNumber]];
|
|
267
267
|
}
|
|
268
|
-
const buf = new
|
|
268
|
+
const buf = new bufferwriter_1.BufferWriter()
|
|
269
269
|
.write(txcopy.toBuffer())
|
|
270
270
|
.writeInt32LE(sighashType >>> 0)
|
|
271
271
|
.toBuffer();
|
|
272
|
-
const hash =
|
|
273
|
-
return new
|
|
272
|
+
const hash = hash_1.Hash.sha256sha256(buf);
|
|
273
|
+
return new bufferreader_1.BufferReader(hash).readReverse(32);
|
|
274
274
|
}
|
|
275
275
|
function sign(transaction, privateKey, sighashType, inputIndex, subscript, satoshisBN, flags, signingMethod) {
|
|
276
276
|
const hashbuf = sighash(transaction, sighashType, inputIndex, subscript, satoshisBN, flags);
|
|
277
277
|
signingMethod = signingMethod || 'ecdsa';
|
|
278
278
|
let sig;
|
|
279
279
|
if (signingMethod === 'schnorr') {
|
|
280
|
-
sig =
|
|
280
|
+
sig = schnorr_1.Schnorr.sign(hashbuf, privateKey, 'big');
|
|
281
281
|
sig.nhashtype = sighashType;
|
|
282
282
|
return sig;
|
|
283
283
|
}
|
|
284
284
|
else if (signingMethod === 'ecdsa') {
|
|
285
|
-
sig =
|
|
285
|
+
sig = ecdsa_1.ECDSA.sign(hashbuf, privateKey, 'big');
|
|
286
286
|
sig.nhashtype = sighashType;
|
|
287
287
|
return sig;
|
|
288
288
|
}
|
|
@@ -291,39 +291,39 @@ function sign(transaction, privateKey, sighashType, inputIndex, subscript, satos
|
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
function verify(transaction, signature, publicKey, inputIndex, subscript, satoshisBN, flags, signingMethod) {
|
|
294
|
-
|
|
295
|
-
|
|
294
|
+
preconditions_1.Preconditions.checkArgument(transaction !== undefined, 'Transaction is required');
|
|
295
|
+
preconditions_1.Preconditions.checkArgument(signature !== undefined && signature.nhashtype !== undefined, 'Signature with nhashtype is required');
|
|
296
296
|
const hashbuf = sighash(transaction, signature.nhashtype, inputIndex, subscript, satoshisBN, flags);
|
|
297
297
|
signingMethod = signingMethod || 'ecdsa';
|
|
298
298
|
if (signingMethod === 'schnorr') {
|
|
299
|
-
return
|
|
299
|
+
return schnorr_1.Schnorr.verify(hashbuf, signature, publicKey, 'big');
|
|
300
300
|
}
|
|
301
301
|
else if (signingMethod === 'ecdsa') {
|
|
302
|
-
return
|
|
302
|
+
return ecdsa_1.ECDSA.verify(hashbuf, signature, publicKey, 'big');
|
|
303
303
|
}
|
|
304
304
|
else {
|
|
305
305
|
throw new Error('Invalid signing method. Must be "ecdsa" or "schnorr"');
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
function GetPrevoutHash(tx) {
|
|
309
|
-
const writer = new
|
|
309
|
+
const writer = new bufferwriter_1.BufferWriter();
|
|
310
310
|
for (const input of tx.inputs) {
|
|
311
311
|
writer.writeReverse(input.prevTxId);
|
|
312
312
|
writer.writeUInt32LE(input.outputIndex);
|
|
313
313
|
}
|
|
314
314
|
const buf = writer.toBuffer();
|
|
315
|
-
return
|
|
315
|
+
return hash_1.Hash.sha256sha256(buf);
|
|
316
316
|
}
|
|
317
317
|
function GetSequenceHash(tx) {
|
|
318
|
-
const writer = new
|
|
318
|
+
const writer = new bufferwriter_1.BufferWriter();
|
|
319
319
|
for (const input of tx.inputs) {
|
|
320
320
|
writer.writeUInt32LENumber(input.sequenceNumber);
|
|
321
321
|
}
|
|
322
322
|
const buf = writer.toBuffer();
|
|
323
|
-
return
|
|
323
|
+
return hash_1.Hash.sha256sha256(buf);
|
|
324
324
|
}
|
|
325
325
|
function GetOutputsHash(tx, n) {
|
|
326
|
-
const writer = new
|
|
326
|
+
const writer = new bufferwriter_1.BufferWriter();
|
|
327
327
|
if (n === undefined) {
|
|
328
328
|
for (const output of tx.outputs) {
|
|
329
329
|
output.toBufferWriter(writer);
|
|
@@ -333,7 +333,7 @@ function GetOutputsHash(tx, n) {
|
|
|
333
333
|
tx.outputs[n].toBufferWriter(writer);
|
|
334
334
|
}
|
|
335
335
|
const buf = writer.toBuffer();
|
|
336
|
-
return
|
|
336
|
+
return hash_1.Hash.sha256sha256(buf);
|
|
337
337
|
}
|
|
338
338
|
exports.DEFAULT_SIGN_FLAGS = DEFAULT_SIGN_FLAGS_CONST;
|
|
339
339
|
exports.SIGHASH_SINGLE_BUG = SIGHASH_SINGLE_BUG_CONST;
|