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,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnspentOutput = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
4
|
+
const preconditions_1 = require("../util/preconditions");
|
|
5
|
+
const buffer_1 = require("../util/buffer");
|
|
6
|
+
const js_1 = require("../util/js");
|
|
7
|
+
const script_1 = require("../script");
|
|
8
|
+
const address_1 = require("../address");
|
|
9
|
+
const publickey_1 = require("../publickey");
|
|
10
|
+
const unit_1 = require("../unit");
|
|
10
11
|
class UnspentOutput {
|
|
11
12
|
address;
|
|
12
13
|
txId;
|
|
@@ -18,22 +19,22 @@ class UnspentOutput {
|
|
|
18
19
|
keyAggContext;
|
|
19
20
|
mySignerIndex;
|
|
20
21
|
constructor(data) {
|
|
21
|
-
|
|
22
|
-
const address = data.address ? new
|
|
22
|
+
preconditions_1.Preconditions.checkArgument(typeof data === 'object' && data !== null, 'Must provide an object from where to extract data');
|
|
23
|
+
const address = data.address ? new address_1.Address(data.address) : undefined;
|
|
23
24
|
const txId = data.txid || data.txId;
|
|
24
|
-
if (!txId || !
|
|
25
|
+
if (!txId || !js_1.JSUtil.isHexa(txId) || txId.length > 64) {
|
|
25
26
|
throw new Error('Invalid TXID in object: ' + JSON.stringify(data));
|
|
26
27
|
}
|
|
27
28
|
const outputIndex = data.vout !== undefined ? data.vout : data.outputIndex;
|
|
28
29
|
if (typeof outputIndex !== 'number') {
|
|
29
30
|
throw new Error('Invalid outputIndex, received ' + outputIndex);
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
const script = new
|
|
33
|
-
|
|
32
|
+
preconditions_1.Preconditions.checkArgument(data.scriptPubKey !== undefined || data.script !== undefined, 'Must provide the scriptPubKey for that output!');
|
|
33
|
+
const script = new script_1.Script(data.scriptPubKey || data.script);
|
|
34
|
+
preconditions_1.Preconditions.checkArgument(data.amount !== undefined || data.satoshis !== undefined, 'Must provide an amount for the output');
|
|
34
35
|
let amount;
|
|
35
36
|
if (data.amount !== undefined) {
|
|
36
|
-
amount = Number(
|
|
37
|
+
amount = Number(unit_1.Unit.fromXPI(data.amount).toSatoshis());
|
|
37
38
|
}
|
|
38
39
|
else if (data.satoshis !== undefined) {
|
|
39
40
|
amount =
|
|
@@ -44,21 +45,21 @@ class UnspentOutput {
|
|
|
44
45
|
else {
|
|
45
46
|
throw new Error('No amount provided');
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
+
preconditions_1.Preconditions.checkArgument(typeof amount === 'number', 'Amount must be a number');
|
|
48
49
|
this.address = address;
|
|
49
50
|
this.txId = txId;
|
|
50
51
|
this.outputIndex = outputIndex;
|
|
51
52
|
this.script = script;
|
|
52
53
|
this.satoshis = amount;
|
|
53
54
|
if (data.internalPubKey) {
|
|
54
|
-
if (data.internalPubKey instanceof
|
|
55
|
+
if (data.internalPubKey instanceof publickey_1.PublicKey) {
|
|
55
56
|
this.internalPubKey = data.internalPubKey;
|
|
56
57
|
}
|
|
57
|
-
else if (
|
|
58
|
-
this.internalPubKey = new
|
|
58
|
+
else if (buffer_1.BufferUtil.isBuffer(data.internalPubKey)) {
|
|
59
|
+
this.internalPubKey = new publickey_1.PublicKey(data.internalPubKey);
|
|
59
60
|
}
|
|
60
61
|
else if (typeof data.internalPubKey === 'string') {
|
|
61
|
-
this.internalPubKey = new
|
|
62
|
+
this.internalPubKey = new publickey_1.PublicKey(data.internalPubKey);
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
this.merkleRoot = data.merkleRoot;
|
|
@@ -69,10 +70,10 @@ class UnspentOutput {
|
|
|
69
70
|
return this.satoshis / 1000000;
|
|
70
71
|
}
|
|
71
72
|
getUnit() {
|
|
72
|
-
return
|
|
73
|
+
return unit_1.Unit.fromSatoshis(this.satoshis);
|
|
73
74
|
}
|
|
74
75
|
isValid() {
|
|
75
|
-
return (
|
|
76
|
+
return (js_1.JSUtil.isHexa(this.txId) &&
|
|
76
77
|
this.txId.length === 64 &&
|
|
77
78
|
this.outputIndex >= 0 &&
|
|
78
79
|
this.satoshis > 0 &&
|
|
@@ -87,7 +88,7 @@ class UnspentOutput {
|
|
|
87
88
|
txid: this.txId,
|
|
88
89
|
vout: this.outputIndex,
|
|
89
90
|
scriptPubKey: this.script.toBuffer().toString('hex'),
|
|
90
|
-
amount:
|
|
91
|
+
amount: unit_1.Unit.fromSatoshis(this.satoshis).toXPI(),
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
toJSON = this.toObject;
|
|
@@ -119,10 +120,13 @@ class UnspentOutput {
|
|
|
119
120
|
return this.txId + ':' + this.outputIndex;
|
|
120
121
|
}
|
|
121
122
|
isPayToPublicKeyHash() {
|
|
122
|
-
return this.script.
|
|
123
|
+
return this.script.isPublicKeyHashOut();
|
|
123
124
|
}
|
|
124
125
|
isPayToScriptHash() {
|
|
125
|
-
return this.script.
|
|
126
|
+
return this.script.isScriptHashOut();
|
|
127
|
+
}
|
|
128
|
+
isPayToTaproot() {
|
|
129
|
+
return this.script.isTaprootOut();
|
|
126
130
|
}
|
|
127
131
|
getAddress() {
|
|
128
132
|
try {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bitsToBytes = bitsToBytes;
|
|
4
|
+
exports.bytesToBits = bytesToBits;
|
|
5
|
+
exports.extractBit = extractBit;
|
|
6
|
+
exports.setBit = setBit;
|
|
7
|
+
function bitsToBytes(bits) {
|
|
8
|
+
const bytes = new Array(Math.ceil(bits.length / 8)).fill(0);
|
|
9
|
+
for (let p = 0; p < bits.length; p++) {
|
|
10
|
+
bytes[p >> 3] |= (bits[p] ? 1 : 0) << (p & 7);
|
|
11
|
+
}
|
|
12
|
+
return bytes;
|
|
13
|
+
}
|
|
14
|
+
function bytesToBits(bytes) {
|
|
15
|
+
const bits = new Array(bytes.length * 8);
|
|
16
|
+
for (let p = 0; p < bits.length; p++) {
|
|
17
|
+
bits[p] = (bytes[p >> 3] & (1 << (p & 7))) !== 0;
|
|
18
|
+
}
|
|
19
|
+
return bits;
|
|
20
|
+
}
|
|
21
|
+
function extractBit(bytes, position) {
|
|
22
|
+
return (bytes[position >> 3] & (1 << (position & 7))) !== 0;
|
|
23
|
+
}
|
|
24
|
+
function setBit(bytes, position, value) {
|
|
25
|
+
const byteIndex = position >> 3;
|
|
26
|
+
const bitIndex = position & 7;
|
|
27
|
+
if (value) {
|
|
28
|
+
bytes[byteIndex] |= 1 << bitIndex;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
bytes[byteIndex] &= ~(1 << bitIndex);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EMPTY_BUFFER = exports.NULL_HASH = exports.BufferUtil = void 0;
|
|
4
|
-
const
|
|
4
|
+
const buffer_1 = require("buffer/");
|
|
5
5
|
class BufferUtil {
|
|
6
|
+
static Buffer = buffer_1.Buffer;
|
|
6
7
|
static fill(buffer, value) {
|
|
7
|
-
preconditions_js_1.Preconditions.checkArgumentType(buffer, 'Buffer', 'buffer');
|
|
8
|
-
preconditions_js_1.Preconditions.checkArgumentType(value, 'number', 'value');
|
|
9
8
|
const length = buffer.length;
|
|
10
9
|
for (let i = 0; i < length; i++) {
|
|
11
10
|
buffer[i] = value;
|
|
@@ -13,23 +12,25 @@ class BufferUtil {
|
|
|
13
12
|
return buffer;
|
|
14
13
|
}
|
|
15
14
|
static copy(original) {
|
|
16
|
-
const buffer = Buffer.alloc(original.length);
|
|
15
|
+
const buffer = buffer_1.Buffer.alloc(original.length);
|
|
17
16
|
original.copy(buffer);
|
|
18
17
|
return buffer;
|
|
19
18
|
}
|
|
20
19
|
static isBuffer(arg) {
|
|
21
|
-
return Buffer.isBuffer(arg) || arg instanceof Uint8Array;
|
|
20
|
+
return buffer_1.Buffer.isBuffer(arg) || arg instanceof Uint8Array;
|
|
22
21
|
}
|
|
23
22
|
static emptyBuffer(bytes) {
|
|
24
|
-
|
|
25
|
-
const result = Buffer.alloc(bytes);
|
|
23
|
+
const result = buffer_1.Buffer.alloc(bytes);
|
|
26
24
|
for (let i = 0; i < bytes; i++) {
|
|
27
25
|
result.write('\0', i);
|
|
28
26
|
}
|
|
29
27
|
return result;
|
|
30
28
|
}
|
|
29
|
+
static alloc(size, fill) {
|
|
30
|
+
return buffer_1.Buffer.alloc(size, fill);
|
|
31
|
+
}
|
|
31
32
|
static concat(list, totalLength) {
|
|
32
|
-
return Buffer.concat(list, totalLength);
|
|
33
|
+
return buffer_1.Buffer.concat(list, totalLength);
|
|
33
34
|
}
|
|
34
35
|
static equals(a, b) {
|
|
35
36
|
if (a.length !== b.length) {
|
|
@@ -47,34 +48,44 @@ class BufferUtil {
|
|
|
47
48
|
return BufferUtil.equals(a, b);
|
|
48
49
|
}
|
|
49
50
|
static integerAsSingleByteBuffer(integer) {
|
|
50
|
-
|
|
51
|
-
return Buffer.from([integer & 0xff]);
|
|
51
|
+
return buffer_1.Buffer.from([integer & 0xff]);
|
|
52
52
|
}
|
|
53
53
|
static integerAsBuffer(integer) {
|
|
54
|
-
preconditions_js_1.Preconditions.checkArgumentType(integer, 'number', 'integer');
|
|
55
54
|
const bytes = [];
|
|
56
55
|
bytes.push((integer >> 24) & 0xff);
|
|
57
56
|
bytes.push((integer >> 16) & 0xff);
|
|
58
57
|
bytes.push((integer >> 8) & 0xff);
|
|
59
58
|
bytes.push(integer & 0xff);
|
|
60
|
-
return Buffer.from(bytes);
|
|
59
|
+
return buffer_1.Buffer.from(bytes);
|
|
61
60
|
}
|
|
62
61
|
static integerFromBuffer(buffer) {
|
|
63
|
-
preconditions_js_1.Preconditions.checkArgumentType(buffer, 'Buffer', 'buffer');
|
|
64
62
|
return (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
|
|
65
63
|
}
|
|
66
64
|
static integerFromSingleByteBuffer(buffer) {
|
|
67
|
-
preconditions_js_1.Preconditions.checkArgumentType(buffer, 'Buffer', 'buffer');
|
|
68
65
|
return buffer[0];
|
|
69
66
|
}
|
|
70
67
|
static bufferToHex(buffer) {
|
|
71
|
-
preconditions_js_1.Preconditions.checkArgumentType(buffer, 'Buffer', 'buffer');
|
|
72
68
|
return buffer.toString('hex');
|
|
73
69
|
}
|
|
74
70
|
static reverse(param) {
|
|
75
|
-
return Buffer.from(param).reverse();
|
|
71
|
+
return buffer_1.Buffer.from(param).reverse();
|
|
72
|
+
}
|
|
73
|
+
static from(data, byteOffsetOrEncoding, length) {
|
|
74
|
+
if (Array.isArray(data)) {
|
|
75
|
+
return buffer_1.Buffer.from(data);
|
|
76
|
+
}
|
|
77
|
+
if (typeof data === 'string') {
|
|
78
|
+
return buffer_1.Buffer.from(data, (byteOffsetOrEncoding || 'utf8'));
|
|
79
|
+
}
|
|
80
|
+
if (data instanceof ArrayBuffer) {
|
|
81
|
+
return buffer_1.Buffer.from(data, byteOffsetOrEncoding, length);
|
|
82
|
+
}
|
|
83
|
+
return buffer_1.Buffer.from(data);
|
|
84
|
+
}
|
|
85
|
+
static compare(buf1, buf2) {
|
|
86
|
+
return buffer_1.Buffer.compare(buf1, buf2);
|
|
76
87
|
}
|
|
77
88
|
}
|
|
78
89
|
exports.BufferUtil = BufferUtil;
|
|
79
|
-
exports.NULL_HASH = BufferUtil.fill(Buffer.alloc(32), 0);
|
|
80
|
-
exports.EMPTY_BUFFER = Buffer.alloc(0);
|
|
90
|
+
exports.NULL_HASH = BufferUtil.fill(buffer_1.Buffer.alloc(32), 0);
|
|
91
|
+
exports.EMPTY_BUFFER = buffer_1.Buffer.alloc(0);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calcTreeWidth = calcTreeWidth;
|
|
4
|
+
exports.calcTreeHeight = calcTreeHeight;
|
|
5
|
+
exports.calcMerkleHash = calcMerkleHash;
|
|
6
|
+
exports.traverseAndBuild = traverseAndBuild;
|
|
7
|
+
const hash_1 = require("../crypto/hash");
|
|
8
|
+
const buffer_1 = require("./buffer");
|
|
9
|
+
function calcTreeWidth(nLeaves, height) {
|
|
10
|
+
return (nLeaves + (1 << height) - 1) >> height;
|
|
11
|
+
}
|
|
12
|
+
function calcTreeHeight(nLeaves) {
|
|
13
|
+
let height = 0;
|
|
14
|
+
while (calcTreeWidth(nLeaves, height) > 1) {
|
|
15
|
+
height++;
|
|
16
|
+
}
|
|
17
|
+
return height;
|
|
18
|
+
}
|
|
19
|
+
function calcMerkleHash(height, pos, hashes, nullHash = buffer_1.BufferUtil.alloc(32)) {
|
|
20
|
+
if (height === 0) {
|
|
21
|
+
return hashes[pos];
|
|
22
|
+
}
|
|
23
|
+
const left = calcMerkleHash(height - 1, pos * 2, hashes, nullHash);
|
|
24
|
+
let right = left;
|
|
25
|
+
if (pos * 2 + 1 < calcTreeWidth(hashes.length, height - 1)) {
|
|
26
|
+
right = calcMerkleHash(height - 1, pos * 2 + 1, hashes, nullHash);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
right = nullHash.toString('hex');
|
|
30
|
+
}
|
|
31
|
+
return hash_1.Hash.sha256sha256(buffer_1.BufferUtil.concat([
|
|
32
|
+
buffer_1.BufferUtil.from(left, 'hex'),
|
|
33
|
+
buffer_1.BufferUtil.from(right, 'hex'),
|
|
34
|
+
])).toString('hex');
|
|
35
|
+
}
|
|
36
|
+
function traverseAndBuild(height, pos, nLeaves, hashes, vfMatch, vBits, vHash, nullHash = buffer_1.BufferUtil.alloc(32)) {
|
|
37
|
+
let fParentOfMatch = false;
|
|
38
|
+
const startIdx = pos << height;
|
|
39
|
+
const endIdx = Math.min((pos + 1) << height, nLeaves);
|
|
40
|
+
for (let p = startIdx; p < endIdx; p++) {
|
|
41
|
+
fParentOfMatch ||= vfMatch[p];
|
|
42
|
+
}
|
|
43
|
+
vBits.push(fParentOfMatch);
|
|
44
|
+
if (height === 0 || !fParentOfMatch) {
|
|
45
|
+
vHash.push(calcMerkleHash(height, pos, hashes, nullHash));
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
traverseAndBuild(height - 1, pos * 2, nLeaves, hashes, vfMatch, vBits, vHash, nullHash);
|
|
49
|
+
if (pos * 2 + 1 < calcTreeWidth(nLeaves, height - 1)) {
|
|
50
|
+
traverseAndBuild(height - 1, pos * 2 + 1, nLeaves, hashes, vfMatch, vBits, vHash, nullHash);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Preconditions = void 0;
|
|
4
|
-
const
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const buffer_1 = require("./buffer");
|
|
5
6
|
class Preconditions {
|
|
6
7
|
static checkState(condition, message) {
|
|
7
8
|
if (!condition) {
|
|
8
|
-
throw new
|
|
9
|
+
throw new errors_1.BitcoreError.Precondition.InvalidState(message);
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
12
|
static checkArgument(condition, argumentName, message, docsPath) {
|
|
12
13
|
if (!condition) {
|
|
13
|
-
throw new
|
|
14
|
+
throw new errors_1.BitcoreError.Precondition.InvalidArgument(argumentName, message, docsPath);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
static checkArgumentType(argument, type, argumentName) {
|
|
17
18
|
argumentName = argumentName || '(unknown name)';
|
|
18
19
|
if (typeof type === 'string') {
|
|
19
20
|
if (type === 'Buffer') {
|
|
20
|
-
if (!
|
|
21
|
-
throw new
|
|
21
|
+
if (!buffer_1.BufferUtil.isBuffer(argument)) {
|
|
22
|
+
throw new errors_1.BitcoreError.Precondition.InvalidArgumentType(argument, type, argumentName);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
else if (typeof argument !== type) {
|
|
25
|
-
throw new
|
|
26
|
+
throw new errors_1.BitcoreError.Precondition.InvalidArgumentType(argument, type, argumentName);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
else {
|
|
29
30
|
if (!(argument instanceof type)) {
|
|
30
|
-
throw new
|
|
31
|
+
throw new errors_1.BitcoreError.Precondition.InvalidArgumentType(argument, type.name, argumentName);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.XAddress = void 0;
|
|
4
|
+
const buffer_1 = require("buffer/");
|
|
4
5
|
const preconditions_js_1 = require("./util/preconditions.js");
|
|
5
6
|
const base58_js_1 = require("./encoding/base58.js");
|
|
6
7
|
const bufferwriter_js_1 = require("./encoding/bufferwriter.js");
|
|
@@ -8,8 +9,6 @@ const networks_js_1 = require("./networks.js");
|
|
|
8
9
|
const hash_js_1 = require("./crypto/hash.js");
|
|
9
10
|
const js_js_1 = require("./util/js.js");
|
|
10
11
|
const buffer_js_1 = require("./util/buffer.js");
|
|
11
|
-
const TOKEN_NAME = 'lotus';
|
|
12
|
-
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
13
12
|
class XAddress {
|
|
14
13
|
static PayToPublicKeyHash = 'pubkeyhash';
|
|
15
14
|
static PayToScriptHash = 'scripthash';
|
|
@@ -18,7 +17,7 @@ class XAddress {
|
|
|
18
17
|
hashBuffer;
|
|
19
18
|
network;
|
|
20
19
|
type;
|
|
21
|
-
constructor(data, network, type, prefix =
|
|
20
|
+
constructor(data, network, type, prefix = 'lotus') {
|
|
22
21
|
if (data instanceof XAddress) {
|
|
23
22
|
return data;
|
|
24
23
|
}
|
|
@@ -49,7 +48,7 @@ class XAddress {
|
|
|
49
48
|
if (typeof data === 'string') {
|
|
50
49
|
return XAddress._transformString(data, networkExplicitlyProvided ? network : undefined, type);
|
|
51
50
|
}
|
|
52
|
-
else if (Buffer.isBuffer(data) || data instanceof Uint8Array) {
|
|
51
|
+
else if (buffer_1.Buffer.isBuffer(data) || data instanceof Uint8Array) {
|
|
53
52
|
return XAddress._transformBuffer(data, network, type, prefix);
|
|
54
53
|
}
|
|
55
54
|
else if (typeof data === 'object' && data !== null) {
|
|
@@ -63,7 +62,7 @@ class XAddress {
|
|
|
63
62
|
preconditions_js_1.Preconditions.checkArgument(data.hashBuffer !== undefined, 'data', 'Must provide a `hash` or `hashBuffer` property');
|
|
64
63
|
preconditions_js_1.Preconditions.checkArgument(data.type !== undefined, 'data', 'Must provide a `type` property');
|
|
65
64
|
return {
|
|
66
|
-
hashBuffer: data.hashBuffer || Buffer.from(data.hashBuffer.toString(), 'hex'),
|
|
65
|
+
hashBuffer: data.hashBuffer || buffer_1.Buffer.from(data.hashBuffer.toString(), 'hex'),
|
|
67
66
|
network: networks_js_1.Networks.get(data.network) || networks_js_1.Networks.defaultNetwork,
|
|
68
67
|
type: data.type,
|
|
69
68
|
prefix: data.prefix,
|
|
@@ -99,9 +98,9 @@ class XAddress {
|
|
|
99
98
|
}
|
|
100
99
|
return info;
|
|
101
100
|
}
|
|
102
|
-
static _transformBuffer(buffer, network, type, prefix =
|
|
101
|
+
static _transformBuffer(buffer, network, type, prefix = 'lotus') {
|
|
103
102
|
const info = {};
|
|
104
|
-
if (!Buffer.isBuffer(buffer) && !(buffer instanceof Uint8Array)) {
|
|
103
|
+
if (!buffer_1.Buffer.isBuffer(buffer) && !(buffer instanceof Uint8Array)) {
|
|
105
104
|
throw new TypeError('XAddress supplied is not a buffer.');
|
|
106
105
|
}
|
|
107
106
|
const networkObj = networks_js_1.Networks.get(network);
|
|
@@ -112,7 +111,7 @@ class XAddress {
|
|
|
112
111
|
throw new TypeError('Unknown type.');
|
|
113
112
|
}
|
|
114
113
|
info.prefix = prefix;
|
|
115
|
-
info.hashBuffer = Buffer.from(buffer);
|
|
114
|
+
info.hashBuffer = buffer_1.Buffer.from(buffer);
|
|
116
115
|
info.network = networkObj || networks_js_1.Networks.defaultNetwork;
|
|
117
116
|
info.type = type;
|
|
118
117
|
return info;
|
|
@@ -123,7 +122,7 @@ class XAddress {
|
|
|
123
122
|
}
|
|
124
123
|
static fromObject(obj) {
|
|
125
124
|
preconditions_js_1.Preconditions.checkState(js_js_1.JSUtil.isHexa(obj.hash), 'Unexpected hash property, "' + obj.hash + '", expected to be hex.');
|
|
126
|
-
const hashBuffer = Buffer.from(obj.hash, 'hex');
|
|
125
|
+
const hashBuffer = buffer_1.Buffer.from(obj.hash, 'hex');
|
|
127
126
|
return new XAddress(hashBuffer, obj.network, obj.type, obj.prefix);
|
|
128
127
|
}
|
|
129
128
|
static getValidationError(data, network, type) {
|
|
@@ -142,10 +141,10 @@ class XAddress {
|
|
|
142
141
|
return decode(address);
|
|
143
142
|
}
|
|
144
143
|
toBuffer() {
|
|
145
|
-
const version = Buffer.from([
|
|
144
|
+
const version = buffer_1.Buffer.from([
|
|
146
145
|
this.network[this.type],
|
|
147
146
|
]);
|
|
148
|
-
const buf = Buffer.concat([version, this.hashBuffer]);
|
|
147
|
+
const buf = buffer_1.Buffer.concat([version, this.hashBuffer]);
|
|
149
148
|
return buf;
|
|
150
149
|
}
|
|
151
150
|
toObject() {
|
|
@@ -162,7 +161,7 @@ class XAddress {
|
|
|
162
161
|
toXAddress() {
|
|
163
162
|
const prefix = this.prefix;
|
|
164
163
|
const networkChar = getNetworkChar(this.network);
|
|
165
|
-
const typeByte = Buffer.from([getTypeByte(this.type)]);
|
|
164
|
+
const typeByte = buffer_1.Buffer.from([getTypeByte(this.type)]);
|
|
166
165
|
const payload = this.hashBuffer;
|
|
167
166
|
const checksum = createChecksum(prefix, networkChar, typeByte, payload);
|
|
168
167
|
const encodedPayload = encodePayload(typeByte, payload, checksum);
|
|
@@ -187,23 +186,23 @@ class XAddress {
|
|
|
187
186
|
exports.XAddress = XAddress;
|
|
188
187
|
function createChecksum(prefix, networkChar, typeByte, payload) {
|
|
189
188
|
const data = buffer_js_1.BufferUtil.concat([
|
|
190
|
-
Buffer.from(prefix),
|
|
191
|
-
Buffer.from(networkChar),
|
|
189
|
+
buffer_1.Buffer.from(prefix),
|
|
190
|
+
buffer_1.Buffer.from(networkChar),
|
|
192
191
|
typeByte,
|
|
193
192
|
payload,
|
|
194
193
|
]);
|
|
195
|
-
return hash_js_1.Hash.sha256(data).
|
|
194
|
+
return hash_js_1.Hash.sha256(data).slice(0, 4);
|
|
196
195
|
}
|
|
197
196
|
function createChecksumLegacy(prefix, networkChar, typeByte, payload) {
|
|
198
197
|
const bw = new bufferwriter_js_1.BufferWriter();
|
|
199
198
|
bw.writeVarintNum(prefix.length);
|
|
200
|
-
bw.write(Buffer.from(prefix));
|
|
199
|
+
bw.write(buffer_1.Buffer.from(prefix));
|
|
201
200
|
bw.writeUInt8(networkChar.charCodeAt(0));
|
|
202
201
|
bw.writeUInt8(typeByte[0]);
|
|
203
202
|
bw.writeVarintNum(payload.length);
|
|
204
203
|
bw.write(payload);
|
|
205
204
|
const buf = bw.concat();
|
|
206
|
-
return hash_js_1.Hash.sha256(buf).
|
|
205
|
+
return hash_js_1.Hash.sha256(buf).slice(0, 4);
|
|
207
206
|
}
|
|
208
207
|
function getType(typeByte) {
|
|
209
208
|
switch (typeByte) {
|
|
@@ -214,7 +213,7 @@ function getType(typeByte) {
|
|
|
214
213
|
case 2:
|
|
215
214
|
return 'taproot';
|
|
216
215
|
}
|
|
217
|
-
return
|
|
216
|
+
return null;
|
|
218
217
|
}
|
|
219
218
|
function getTypeByte(type) {
|
|
220
219
|
switch (type) {
|
|
@@ -267,15 +266,20 @@ function decode(address) {
|
|
|
267
266
|
const networkChar = address.substring(splitLocation, splitLocation + 1);
|
|
268
267
|
const encodedPayload = address.substring(splitLocation + 1);
|
|
269
268
|
const decodedBytes = base58_js_1.Base58.decode(encodedPayload);
|
|
270
|
-
const typeByte = decodedBytes.
|
|
271
|
-
const payload = decodedBytes.
|
|
272
|
-
const decodedChecksum = decodedBytes.
|
|
269
|
+
const typeByte = decodedBytes.slice(0, 1);
|
|
270
|
+
const payload = decodedBytes.slice(1, decodedBytes.length - 4);
|
|
271
|
+
const decodedChecksum = decodedBytes.slice(decodedBytes.length - 4);
|
|
273
272
|
const checksum = createChecksum(prefix, networkChar, typeByte, payload);
|
|
274
|
-
|
|
273
|
+
const legacyChecksum = createChecksumLegacy(prefix, networkChar, typeByte, payload);
|
|
274
|
+
const validChecksum = checksum.toString('hex') === decodedChecksum.toString('hex') ||
|
|
275
|
+
legacyChecksum.toString('hex') === decodedChecksum.toString('hex');
|
|
276
|
+
preconditions_js_1.Preconditions.checkArgument(validChecksum, 'checksum', 'Invalid checksum: ' + address);
|
|
277
|
+
const type = getType(typeByte[0]);
|
|
278
|
+
preconditions_js_1.Preconditions.checkArgument(type !== null, 'typeByte', 'Invalid type byte: ' + typeByte[0]);
|
|
275
279
|
const info = {};
|
|
276
280
|
info.hashBuffer = payload;
|
|
277
281
|
info.network = getNetworkFromChar(networkChar);
|
|
278
|
-
info.type =
|
|
282
|
+
info.type = type;
|
|
279
283
|
info.prefix = prefix;
|
|
280
284
|
return info;
|
|
281
285
|
}
|