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,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Block = void 0;
|
|
4
|
+
const buffer_1 = require("buffer/");
|
|
4
5
|
const preconditions_js_1 = require("../util/preconditions.js");
|
|
5
6
|
const buffer_js_1 = require("../util/buffer.js");
|
|
6
7
|
const bufferreader_js_1 = require("../encoding/bufferreader.js");
|
|
@@ -9,55 +10,34 @@ const hash_js_1 = require("../crypto/hash.js");
|
|
|
9
10
|
const js_js_1 = require("../util/js.js");
|
|
10
11
|
const index_js_1 = require("../transaction/index.js");
|
|
11
12
|
const bn_js_1 = require("../crypto/bn.js");
|
|
13
|
+
const merkle_js_1 = require("../util/merkle.js");
|
|
12
14
|
const blockheader_js_1 = require("./blockheader.js");
|
|
15
|
+
const merkleblock_js_1 = require("./merkleblock.js");
|
|
13
16
|
class Block {
|
|
14
17
|
static MAX_BLOCK_SIZE = 32 * 1024 * 1024;
|
|
15
|
-
static
|
|
16
|
-
static NULL_HASH = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
|
|
17
|
-
static Values = {
|
|
18
|
-
START_OF_BLOCK: 0,
|
|
19
|
-
NULL_HASH: Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex'),
|
|
20
|
-
};
|
|
18
|
+
static NULL_HASH = buffer_js_1.NULL_HASH;
|
|
21
19
|
header;
|
|
22
|
-
metadata;
|
|
23
20
|
transactions;
|
|
24
21
|
_id;
|
|
25
22
|
constructor(serialized) {
|
|
26
|
-
if (!(this instanceof Block)) {
|
|
27
|
-
return new Block(serialized);
|
|
28
|
-
}
|
|
29
23
|
if (serialized instanceof Block) {
|
|
30
24
|
return Block.shallowCopy(serialized);
|
|
31
25
|
}
|
|
32
26
|
else if (typeof serialized === 'string' && js_js_1.JSUtil.isHexa(serialized)) {
|
|
33
|
-
this.
|
|
34
|
-
}
|
|
35
|
-
else if (Buffer.isBuffer(serialized)) {
|
|
36
|
-
this.fromBuffer(serialized);
|
|
27
|
+
this._fromString(serialized);
|
|
37
28
|
}
|
|
38
|
-
else if (serialized
|
|
39
|
-
|
|
29
|
+
else if (buffer_1.Buffer.isBuffer(serialized) ||
|
|
30
|
+
(serialized && typeof serialized === 'object')) {
|
|
31
|
+
const info = Block._from(serialized);
|
|
32
|
+
this.header = info.header;
|
|
33
|
+
this.transactions = info.transactions;
|
|
40
34
|
}
|
|
41
35
|
else {
|
|
42
|
-
this.
|
|
36
|
+
this._initEmpty();
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
39
|
static shallowCopy(block) {
|
|
46
|
-
|
|
47
|
-
return copy;
|
|
48
|
-
}
|
|
49
|
-
static _from(arg) {
|
|
50
|
-
let info = {};
|
|
51
|
-
if (Buffer.isBuffer(arg)) {
|
|
52
|
-
info = Block._fromBufferReader(new bufferreader_js_1.BufferReader(arg));
|
|
53
|
-
}
|
|
54
|
-
else if (typeof arg === 'object' && arg !== null) {
|
|
55
|
-
info = Block._fromObject(arg);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
throw new TypeError('Unrecognized argument for Block');
|
|
59
|
-
}
|
|
60
|
-
return info;
|
|
40
|
+
return new Block(block.toBuffer());
|
|
61
41
|
}
|
|
62
42
|
static fromObject(obj) {
|
|
63
43
|
const info = Block._fromObject(obj);
|
|
@@ -65,97 +45,35 @@ class Block {
|
|
|
65
45
|
}
|
|
66
46
|
static fromBufferReader(br) {
|
|
67
47
|
preconditions_js_1.Preconditions.checkArgument(br instanceof bufferreader_js_1.BufferReader, 'br is required');
|
|
68
|
-
const info = Block.
|
|
48
|
+
const info = Block._readFromBuffer(br);
|
|
69
49
|
return new Block(info);
|
|
70
50
|
}
|
|
71
51
|
static fromBuffer(buf) {
|
|
72
52
|
return Block.fromBufferReader(new bufferreader_js_1.BufferReader(buf));
|
|
73
53
|
}
|
|
74
54
|
static fromString(str) {
|
|
75
|
-
|
|
76
|
-
return Block.fromBuffer(buf);
|
|
55
|
+
return Block.fromBuffer(buffer_1.Buffer.from(str, 'hex'));
|
|
77
56
|
}
|
|
78
57
|
static fromRawBlock(data) {
|
|
79
58
|
if (!buffer_js_1.BufferUtil.isBuffer(data)) {
|
|
80
|
-
data = Buffer.from(data, 'binary');
|
|
59
|
+
data = buffer_1.Buffer.from(data, 'binary');
|
|
81
60
|
}
|
|
82
61
|
const br = new bufferreader_js_1.BufferReader(data);
|
|
83
|
-
|
|
84
|
-
const info = Block._fromBufferReader(br);
|
|
62
|
+
const info = Block._readFromBuffer(br);
|
|
85
63
|
return new Block(info);
|
|
86
64
|
}
|
|
87
|
-
static _fromObject(data) {
|
|
88
|
-
const transactions = [];
|
|
89
|
-
if (data.transactions) {
|
|
90
|
-
data.transactions.forEach(tx => {
|
|
91
|
-
if (tx instanceof index_js_1.Transaction) {
|
|
92
|
-
transactions.push(tx);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
transactions.push(new index_js_1.Transaction(tx));
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
header: data.header
|
|
101
|
-
? data.header instanceof blockheader_js_1.BlockHeader
|
|
102
|
-
? data.header
|
|
103
|
-
: new blockheader_js_1.BlockHeader(data.header)
|
|
104
|
-
: new blockheader_js_1.BlockHeader(),
|
|
105
|
-
metadata: data.metadata || 0x00,
|
|
106
|
-
transactions: transactions,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
static _fromBufferReader(br) {
|
|
110
|
-
preconditions_js_1.Preconditions.checkState(!br.finished(), 'No block data received');
|
|
111
|
-
const header = blockheader_js_1.BlockHeader.fromBufferReader(br);
|
|
112
|
-
const metadata = br.readUInt8();
|
|
113
|
-
const transactionCount = br.readVarintNum();
|
|
114
|
-
const transactions = [];
|
|
115
|
-
for (let i = 0; i < transactionCount; i++) {
|
|
116
|
-
const tx = new index_js_1.Transaction();
|
|
117
|
-
transactions.push(tx.fromBufferReader(br));
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
header,
|
|
121
|
-
metadata,
|
|
122
|
-
transactions,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
_newBlock() {
|
|
126
|
-
this.header = new blockheader_js_1.BlockHeader();
|
|
127
|
-
this.metadata = 0x00;
|
|
128
|
-
this.transactions = [];
|
|
129
|
-
}
|
|
130
|
-
fromBuffer(buf) {
|
|
131
|
-
const info = Block._fromBufferReader(new bufferreader_js_1.BufferReader(buf));
|
|
132
|
-
this.header = info.header;
|
|
133
|
-
this.metadata = info.metadata;
|
|
134
|
-
this.transactions = info.transactions;
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
fromString(str) {
|
|
138
|
-
const buf = Buffer.from(str, 'hex');
|
|
139
|
-
return this.fromBuffer(buf);
|
|
140
|
-
}
|
|
141
|
-
fromObject(obj) {
|
|
142
|
-
const info = Block._fromObject(obj);
|
|
143
|
-
this.header = info.header;
|
|
144
|
-
this.metadata = info.metadata;
|
|
145
|
-
this.transactions = info.transactions;
|
|
146
|
-
return this;
|
|
147
|
-
}
|
|
148
65
|
toObject() {
|
|
149
66
|
const transactions = this.transactions.map(tx => tx.toObject());
|
|
150
67
|
return {
|
|
151
68
|
id: this.id,
|
|
152
69
|
hash: this.hash,
|
|
153
70
|
header: this.header.toObject(),
|
|
154
|
-
|
|
155
|
-
transactions: transactions,
|
|
71
|
+
transactions,
|
|
156
72
|
};
|
|
157
73
|
}
|
|
158
|
-
toJSON
|
|
74
|
+
toJSON() {
|
|
75
|
+
return this.toObject();
|
|
76
|
+
}
|
|
159
77
|
toBuffer() {
|
|
160
78
|
return this.toBufferWriter().concat();
|
|
161
79
|
}
|
|
@@ -167,25 +85,21 @@ class Block {
|
|
|
167
85
|
bw = new bufferwriter_js_1.BufferWriter();
|
|
168
86
|
}
|
|
169
87
|
bw.write(this.header.toBuffer());
|
|
170
|
-
bw.
|
|
88
|
+
bw.writeVarintNum(0);
|
|
171
89
|
bw.writeVarintNum(this.transactions.length);
|
|
172
|
-
for (
|
|
173
|
-
|
|
90
|
+
for (const tx of this.transactions) {
|
|
91
|
+
tx.toBufferWriter(bw);
|
|
174
92
|
}
|
|
175
93
|
return bw;
|
|
176
94
|
}
|
|
177
95
|
getTransactionHashes() {
|
|
178
|
-
const hashes = [];
|
|
179
96
|
if (this.transactions.length === 0) {
|
|
180
|
-
return [Block.
|
|
97
|
+
return [Block.NULL_HASH];
|
|
181
98
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
const buf = Buffer.concat([hash, txid]);
|
|
187
|
-
const resultHash = hash_js_1.Hash.sha256sha256(buf);
|
|
188
|
-
hashes.push(resultHash);
|
|
99
|
+
const hashes = [];
|
|
100
|
+
for (const tx of this.transactions) {
|
|
101
|
+
const combined = buffer_1.Buffer.concat([tx.hashBuffer, tx.txidBuffer]);
|
|
102
|
+
hashes.push(hash_js_1.Hash.sha256sha256(combined));
|
|
189
103
|
}
|
|
190
104
|
return hashes;
|
|
191
105
|
}
|
|
@@ -194,12 +108,12 @@ class Block {
|
|
|
194
108
|
let j = 0;
|
|
195
109
|
for (let size = tree.length; size > 1; size = Math.floor(size / 2)) {
|
|
196
110
|
if (size % 2 === 1) {
|
|
197
|
-
tree.push(Block.
|
|
111
|
+
tree.push(Block.NULL_HASH);
|
|
198
112
|
size += 1;
|
|
199
113
|
}
|
|
200
114
|
for (let i = 0; i < size; i += 2) {
|
|
201
|
-
const
|
|
202
|
-
tree.push(hash_js_1.Hash.sha256sha256(
|
|
115
|
+
const combined = buffer_1.Buffer.concat([tree[j + i], tree[j + i + 1]]);
|
|
116
|
+
tree.push(hash_js_1.Hash.sha256sha256(combined));
|
|
203
117
|
}
|
|
204
118
|
j += size;
|
|
205
119
|
}
|
|
@@ -210,16 +124,45 @@ class Block {
|
|
|
210
124
|
return tree[tree.length - 1];
|
|
211
125
|
}
|
|
212
126
|
validMerkleRoot() {
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
return true;
|
|
127
|
+
const headerRoot = bn_js_1.BN.fromBuffer(this.header.merkleRoot);
|
|
128
|
+
const computedRoot = bn_js_1.BN.fromBuffer(this.getMerkleRoot());
|
|
129
|
+
return headerRoot.eq(computedRoot);
|
|
219
130
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
131
|
+
toMerkleBlock(txids) {
|
|
132
|
+
if (!Array.isArray(txids) || txids.length === 0) {
|
|
133
|
+
throw new TypeError('txids must be a non-empty array of transaction IDs');
|
|
134
|
+
}
|
|
135
|
+
for (const txid of txids) {
|
|
136
|
+
if (!/^[0-9a-fA-F]{64}$/.test(txid)) {
|
|
137
|
+
throw new TypeError(`Invalid transaction ID format: ${txid}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (this.transactions.length === 0) {
|
|
141
|
+
throw new Error('Cannot create MerkleBlock from block with no transactions');
|
|
142
|
+
}
|
|
143
|
+
const vHashes = [];
|
|
144
|
+
const vMatch = [];
|
|
145
|
+
for (const tx of this.transactions) {
|
|
146
|
+
const txhash = tx.hash;
|
|
147
|
+
const txid = tx.txid;
|
|
148
|
+
const txidLower = txid.toLowerCase();
|
|
149
|
+
vMatch.push(false);
|
|
150
|
+
vHashes.push(txhash);
|
|
151
|
+
const isMatch = txids.some(id => id.toLowerCase() === txidLower);
|
|
152
|
+
vMatch.push(isMatch);
|
|
153
|
+
vHashes.push(txid);
|
|
154
|
+
}
|
|
155
|
+
const nLeaves = vHashes.length;
|
|
156
|
+
const height = (0, merkle_js_1.calcTreeHeight)(nLeaves);
|
|
157
|
+
const vBits = [];
|
|
158
|
+
const vHash = [];
|
|
159
|
+
(0, merkle_js_1.traverseAndBuild)(height, 0, nLeaves, vHashes, vMatch, vBits, vHash, Block.NULL_HASH);
|
|
160
|
+
return new merkleblock_js_1.MerkleBlock({
|
|
161
|
+
header: this.header,
|
|
162
|
+
numTransactions: this.transactions.length,
|
|
163
|
+
hashes: vHash,
|
|
164
|
+
flags: vBits.map(b => (b ? 1 : 0)),
|
|
165
|
+
});
|
|
223
166
|
}
|
|
224
167
|
get hash() {
|
|
225
168
|
if (!this._id) {
|
|
@@ -233,5 +176,60 @@ class Block {
|
|
|
233
176
|
inspect() {
|
|
234
177
|
return '<Block ' + this.id + '>';
|
|
235
178
|
}
|
|
179
|
+
static _from(arg) {
|
|
180
|
+
if (buffer_1.Buffer.isBuffer(arg)) {
|
|
181
|
+
return Block._readFromBuffer(new bufferreader_js_1.BufferReader(arg));
|
|
182
|
+
}
|
|
183
|
+
else if (typeof arg === 'object' && arg !== null) {
|
|
184
|
+
return Block._fromObject(arg);
|
|
185
|
+
}
|
|
186
|
+
throw new TypeError('Unrecognized argument for Block');
|
|
187
|
+
}
|
|
188
|
+
static _fromObject(data) {
|
|
189
|
+
const transactions = [];
|
|
190
|
+
if (data.transactions) {
|
|
191
|
+
for (const tx of data.transactions) {
|
|
192
|
+
transactions.push(tx instanceof index_js_1.Transaction ? tx : new index_js_1.Transaction(tx));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
let header;
|
|
196
|
+
if (data.header instanceof blockheader_js_1.BlockHeader) {
|
|
197
|
+
header = data.header;
|
|
198
|
+
}
|
|
199
|
+
else if (data.header) {
|
|
200
|
+
header = new blockheader_js_1.BlockHeader(data.header);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
header = new blockheader_js_1.BlockHeader();
|
|
204
|
+
}
|
|
205
|
+
return { header, transactions };
|
|
206
|
+
}
|
|
207
|
+
static _readFromBuffer(br) {
|
|
208
|
+
preconditions_js_1.Preconditions.checkState(!br.finished(), 'No block data received');
|
|
209
|
+
const header = blockheader_js_1.BlockHeader.fromBufferReader(br);
|
|
210
|
+
const metadataCount = br.readVarintNum();
|
|
211
|
+
for (let i = 0; i < metadataCount; i++) {
|
|
212
|
+
br.readUInt32LE();
|
|
213
|
+
const dataLength = br.readVarintNum();
|
|
214
|
+
br.read(dataLength);
|
|
215
|
+
}
|
|
216
|
+
const transactionCount = br.readVarintNum();
|
|
217
|
+
const transactions = [];
|
|
218
|
+
for (let i = 0; i < transactionCount; i++) {
|
|
219
|
+
const tx = new index_js_1.Transaction();
|
|
220
|
+
transactions.push(tx.fromBufferReader(br));
|
|
221
|
+
}
|
|
222
|
+
return { header, transactions };
|
|
223
|
+
}
|
|
224
|
+
_initEmpty() {
|
|
225
|
+
this.header = new blockheader_js_1.BlockHeader();
|
|
226
|
+
this.transactions = [];
|
|
227
|
+
}
|
|
228
|
+
_fromString(str) {
|
|
229
|
+
const buf = buffer_1.Buffer.from(str, 'hex');
|
|
230
|
+
const info = Block._readFromBuffer(new bufferreader_js_1.BufferReader(buf));
|
|
231
|
+
this.header = info.header;
|
|
232
|
+
this.transactions = info.transactions;
|
|
233
|
+
}
|
|
236
234
|
}
|
|
237
235
|
exports.Block = Block;
|