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,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Address = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
4
|
+
const preconditions_1 = require("./util/preconditions");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
const base58check_1 = require("./encoding/base58check");
|
|
7
|
+
const networks_1 = require("./networks");
|
|
8
|
+
const hash_1 = require("./crypto/hash");
|
|
9
|
+
const util_1 = require("./util");
|
|
10
|
+
const publickey_1 = require("./publickey");
|
|
11
|
+
const xaddress_1 = require("./xaddress");
|
|
12
|
+
const script_1 = require("./script");
|
|
13
|
+
const opcode_1 = require("./opcode");
|
|
13
14
|
class Address {
|
|
14
15
|
static PayToPublicKeyHash = 'pubkeyhash';
|
|
15
16
|
static PayToScriptHash = 'scripthash';
|
|
@@ -21,12 +22,12 @@ class Address {
|
|
|
21
22
|
if (data instanceof Address) {
|
|
22
23
|
return data;
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
if (network && !(0,
|
|
25
|
+
preconditions_1.Preconditions.checkArgument(data !== undefined, 'data', 'First argument is required, please include address data.', 'guide/address.html');
|
|
26
|
+
if (network && !(0, networks_1.get)(network)) {
|
|
26
27
|
throw new TypeError('Second argument must be "livenet", "testnet", or "regtest".');
|
|
27
28
|
}
|
|
28
29
|
const networkExplicitlyProvided = network !== undefined;
|
|
29
|
-
network ||=
|
|
30
|
+
network ||= networks_1.defaultNetwork;
|
|
30
31
|
if (type &&
|
|
31
32
|
type !== Address.PayToPublicKeyHash &&
|
|
32
33
|
type !== Address.PayToScriptHash &&
|
|
@@ -34,9 +35,9 @@ class Address {
|
|
|
34
35
|
throw new TypeError('Third argument must be "pubkeyhash", "scripthash", or "taproot".');
|
|
35
36
|
}
|
|
36
37
|
const info = this._classifyArguments(data, network, type, networkExplicitlyProvided);
|
|
37
|
-
info.network = info.network || (0,
|
|
38
|
+
info.network = info.network || (0, networks_1.get)(network) || networks_1.defaultNetwork;
|
|
38
39
|
info.type = info.type || type || Address.PayToPublicKeyHash;
|
|
39
|
-
|
|
40
|
+
util_1.JSUtil.defineImmutable(this, {
|
|
40
41
|
hashBuffer: info.hashBuffer,
|
|
41
42
|
network: info.network,
|
|
42
43
|
type: info.type,
|
|
@@ -44,32 +45,32 @@ class Address {
|
|
|
44
45
|
}
|
|
45
46
|
_classifyArguments(data, network, type, networkExplicitlyProvided = true) {
|
|
46
47
|
if (typeof network === 'string') {
|
|
47
|
-
const networkObj = (0,
|
|
48
|
+
const networkObj = (0, networks_1.get)(network);
|
|
48
49
|
if (!networkObj) {
|
|
49
50
|
throw new TypeError('Unknown network');
|
|
50
51
|
}
|
|
51
52
|
network = networkObj;
|
|
52
53
|
}
|
|
53
|
-
if ((
|
|
54
|
+
if ((util_1.BufferUtil.isBuffer(data) || data instanceof Uint8Array) &&
|
|
54
55
|
data.length === 20) {
|
|
55
56
|
return Address._transformHash(data);
|
|
56
57
|
}
|
|
57
|
-
else if ((
|
|
58
|
+
else if ((util_1.BufferUtil.isBuffer(data) || data instanceof Uint8Array) &&
|
|
58
59
|
data.length === 21) {
|
|
59
60
|
return Address._transformBuffer(data, network, type);
|
|
60
61
|
}
|
|
61
|
-
else if ((
|
|
62
|
+
else if ((util_1.BufferUtil.isBuffer(data) || data instanceof Uint8Array) &&
|
|
62
63
|
data.length === 33) {
|
|
63
64
|
return {
|
|
64
|
-
hashBuffer:
|
|
65
|
-
network: typeof network === 'string' ? (0,
|
|
65
|
+
hashBuffer: util_1.BufferUtil.from(data),
|
|
66
|
+
network: typeof network === 'string' ? (0, networks_1.get)(network) : network,
|
|
66
67
|
type: type || Address.PayToTaproot,
|
|
67
68
|
};
|
|
68
69
|
}
|
|
69
|
-
else if (data instanceof
|
|
70
|
+
else if (data instanceof publickey_1.PublicKey) {
|
|
70
71
|
return Address._transformPublicKey(data, network);
|
|
71
72
|
}
|
|
72
|
-
else if (data instanceof
|
|
73
|
+
else if (data instanceof script_1.Script) {
|
|
73
74
|
return Address._transformScript(data, network);
|
|
74
75
|
}
|
|
75
76
|
else if (typeof data === 'string') {
|
|
@@ -87,8 +88,8 @@ class Address {
|
|
|
87
88
|
}
|
|
88
89
|
static _classifyFromVersion(buffer) {
|
|
89
90
|
const version = {};
|
|
90
|
-
const pubkeyhashNetwork = (0,
|
|
91
|
-
const scripthashNetwork = (0,
|
|
91
|
+
const pubkeyhashNetwork = (0, networks_1.get)(buffer[0], 'pubkeyhash');
|
|
92
|
+
const scripthashNetwork = (0, networks_1.get)(buffer[0], 'scripthash');
|
|
92
93
|
if (pubkeyhashNetwork) {
|
|
93
94
|
version.network = pubkeyhashNetwork;
|
|
94
95
|
version.type = Address.PayToPublicKeyHash;
|
|
@@ -104,7 +105,7 @@ class Address {
|
|
|
104
105
|
throw new TypeError('data parameter supplied is not a string.');
|
|
105
106
|
}
|
|
106
107
|
data = data.trim();
|
|
107
|
-
const networkObj = (0,
|
|
108
|
+
const networkObj = (0, networks_1.get)(network);
|
|
108
109
|
if (network && !networkObj) {
|
|
109
110
|
throw new TypeError('Unknown network');
|
|
110
111
|
}
|
|
@@ -115,7 +116,7 @@ class Address {
|
|
|
115
116
|
throw new TypeError('Address has mismatched network type.');
|
|
116
117
|
}
|
|
117
118
|
return {
|
|
118
|
-
hashBuffer:
|
|
119
|
+
hashBuffer: util_1.BufferUtil.from(info.hashBuffer),
|
|
119
120
|
network: info.network,
|
|
120
121
|
type: info.type,
|
|
121
122
|
};
|
|
@@ -137,12 +138,12 @@ class Address {
|
|
|
137
138
|
}
|
|
138
139
|
static _transformLegacyString(data, network, type) {
|
|
139
140
|
const info = {};
|
|
140
|
-
const decoded =
|
|
141
|
+
const decoded = base58check_1.Base58Check.decode(data);
|
|
141
142
|
const version = Address._classifyFromVersion(decoded);
|
|
142
143
|
if (!version.network || !version.type) {
|
|
143
144
|
throw new TypeError('Address has invalid version.');
|
|
144
145
|
}
|
|
145
|
-
info.hashBuffer = decoded.
|
|
146
|
+
info.hashBuffer = decoded.slice(1);
|
|
146
147
|
info.network = version.network;
|
|
147
148
|
info.type = version.type;
|
|
148
149
|
return info;
|
|
@@ -153,10 +154,10 @@ class Address {
|
|
|
153
154
|
}
|
|
154
155
|
static _transformXAddressString(data, network, type) {
|
|
155
156
|
if (typeof network === 'string') {
|
|
156
|
-
network = (0,
|
|
157
|
+
network = (0, networks_1.get)(network);
|
|
157
158
|
}
|
|
158
|
-
network ||=
|
|
159
|
-
const decodedXAddress =
|
|
159
|
+
network ||= networks_1.defaultNetwork;
|
|
160
|
+
const decodedXAddress = xaddress_1.XAddress._decode(data);
|
|
160
161
|
if (!decodedXAddress.hashBuffer) {
|
|
161
162
|
throw new TypeError('Invalid XAddress.');
|
|
162
163
|
}
|
|
@@ -165,10 +166,10 @@ class Address {
|
|
|
165
166
|
const decodedType = decodedXAddress.type;
|
|
166
167
|
if (decodedType === 'taproot' || decodedType === Address.PayToTaproot) {
|
|
167
168
|
if (hashBuffer.length === 36 &&
|
|
168
|
-
hashBuffer[0] ===
|
|
169
|
-
hashBuffer[1] ===
|
|
169
|
+
hashBuffer[0] === opcode_1.Opcode.OP_SCRIPTTYPE &&
|
|
170
|
+
hashBuffer[1] === opcode_1.Opcode.OP_1 &&
|
|
170
171
|
hashBuffer[2] === 0x21) {
|
|
171
|
-
hashBuffer = hashBuffer.
|
|
172
|
+
hashBuffer = hashBuffer.slice(3, 36);
|
|
172
173
|
}
|
|
173
174
|
else if (hashBuffer.length === 33) {
|
|
174
175
|
}
|
|
@@ -182,16 +183,16 @@ class Address {
|
|
|
182
183
|
};
|
|
183
184
|
}
|
|
184
185
|
if (hashBuffer.length === 25 &&
|
|
185
|
-
hashBuffer[0] ===
|
|
186
|
-
hashBuffer[1] ===
|
|
186
|
+
hashBuffer[0] === opcode_1.Opcode.OP_DUP &&
|
|
187
|
+
hashBuffer[1] === opcode_1.Opcode.OP_HASH160 &&
|
|
187
188
|
hashBuffer[2] === 0x14) {
|
|
188
|
-
hashBuffer = hashBuffer.
|
|
189
|
+
hashBuffer = hashBuffer.slice(3, 23);
|
|
189
190
|
}
|
|
190
191
|
else if (hashBuffer.length === 23 &&
|
|
191
|
-
hashBuffer[0] ===
|
|
192
|
+
hashBuffer[0] === opcode_1.Opcode.OP_HASH160 &&
|
|
192
193
|
hashBuffer[1] === 0x14 &&
|
|
193
|
-
hashBuffer[22] ===
|
|
194
|
-
hashBuffer = hashBuffer.
|
|
194
|
+
hashBuffer[22] === opcode_1.Opcode.OP_EQUAL) {
|
|
195
|
+
hashBuffer = hashBuffer.slice(2, 22);
|
|
195
196
|
return {
|
|
196
197
|
hashBuffer: hashBuffer,
|
|
197
198
|
network: decodedNetwork,
|
|
@@ -206,25 +207,25 @@ class Address {
|
|
|
206
207
|
}
|
|
207
208
|
static _transformHash(hash) {
|
|
208
209
|
const info = {};
|
|
209
|
-
if (!
|
|
210
|
+
if (!util_1.BufferUtil.isBuffer(hash)) {
|
|
210
211
|
throw new TypeError('Address supplied is not a buffer.');
|
|
211
212
|
}
|
|
212
213
|
if (hash.length !== 20) {
|
|
213
214
|
throw new TypeError('Address hashbuffers must be exactly 20 bytes.');
|
|
214
215
|
}
|
|
215
|
-
info.hashBuffer =
|
|
216
|
+
info.hashBuffer = util_1.BufferUtil.from(hash);
|
|
216
217
|
return info;
|
|
217
218
|
}
|
|
218
219
|
static _transformBuffer(buffer, network, type) {
|
|
219
220
|
const info = {};
|
|
220
|
-
if (!
|
|
221
|
+
if (!util_1.BufferUtil.isBuffer(buffer)) {
|
|
221
222
|
throw new TypeError('Address supplied is not a buffer.');
|
|
222
223
|
}
|
|
223
224
|
if (buffer.length !== 21) {
|
|
224
225
|
throw new TypeError('Address buffers must be exactly 21 bytes.');
|
|
225
226
|
}
|
|
226
|
-
const networkObj = (0,
|
|
227
|
-
const bufferVersion = Address._classifyFromVersion(
|
|
227
|
+
const networkObj = (0, networks_1.get)(network);
|
|
228
|
+
const bufferVersion = Address._classifyFromVersion(util_1.BufferUtil.from(buffer));
|
|
228
229
|
if (network && !networkObj) {
|
|
229
230
|
throw new TypeError('Unknown network');
|
|
230
231
|
}
|
|
@@ -235,29 +236,29 @@ class Address {
|
|
|
235
236
|
if (!bufferVersion.type || (type && type !== bufferVersion.type)) {
|
|
236
237
|
throw new TypeError('Address has mismatched type.');
|
|
237
238
|
}
|
|
238
|
-
info.hashBuffer =
|
|
239
|
+
info.hashBuffer = util_1.BufferUtil.from(buffer).slice(1);
|
|
239
240
|
info.network = bufferVersion.network;
|
|
240
241
|
info.type = bufferVersion.type;
|
|
241
242
|
return info;
|
|
242
243
|
}
|
|
243
244
|
static _transformPublicKey(pubkey, network) {
|
|
244
245
|
const info = {};
|
|
245
|
-
if (!(pubkey instanceof
|
|
246
|
+
if (!(pubkey instanceof publickey_1.PublicKey)) {
|
|
246
247
|
throw new TypeError('Address must be an instance of PublicKey.');
|
|
247
248
|
}
|
|
248
|
-
info.hashBuffer =
|
|
249
|
+
info.hashBuffer = hash_1.Hash.sha256ripemd160(pubkey.toBuffer());
|
|
249
250
|
info.type = Address.PayToPublicKeyHash;
|
|
250
|
-
info.network = network ??
|
|
251
|
+
info.network = network ?? networks_1.defaultNetwork;
|
|
251
252
|
return info;
|
|
252
253
|
}
|
|
253
254
|
static _transformScript(script, network) {
|
|
254
|
-
|
|
255
|
+
preconditions_1.Preconditions.checkArgument(script instanceof script_1.Script, 'script', 'script must be a Script instance');
|
|
255
256
|
const address = script.getAddressInfo();
|
|
256
257
|
if (!address) {
|
|
257
|
-
throw new
|
|
258
|
+
throw new errors_1.BitcoreError.Script.CantDeriveAddress('Cannot derive address from script');
|
|
258
259
|
}
|
|
259
260
|
if (typeof network === 'string') {
|
|
260
|
-
network = (0,
|
|
261
|
+
network = (0, networks_1.get)(network);
|
|
261
262
|
}
|
|
262
263
|
return {
|
|
263
264
|
hashBuffer: address.hashBuffer,
|
|
@@ -266,34 +267,34 @@ class Address {
|
|
|
266
267
|
};
|
|
267
268
|
}
|
|
268
269
|
static _transformObject(data) {
|
|
269
|
-
|
|
270
|
-
|
|
270
|
+
preconditions_1.Preconditions.checkArgument(data.hashBuffer !== undefined, 'data', 'Must provide a `hash` or `hashBuffer` property');
|
|
271
|
+
preconditions_1.Preconditions.checkArgument(data.type !== undefined, 'data', 'Must provide a `type` property');
|
|
271
272
|
return {
|
|
272
|
-
hashBuffer: data.hashBuffer ||
|
|
273
|
-
network: (0,
|
|
273
|
+
hashBuffer: data.hashBuffer || util_1.BufferUtil.from(data.hashBuffer.toString(), 'hex'),
|
|
274
|
+
network: (0, networks_1.get)(data.network) || networks_1.defaultNetwork,
|
|
274
275
|
type: data.type,
|
|
275
276
|
};
|
|
276
277
|
}
|
|
277
278
|
static createMultisig(publicKeys, threshold, network) {
|
|
278
|
-
const networkObj = network || publicKeys[0].network ||
|
|
279
|
-
return Address.payingTo(
|
|
279
|
+
const networkObj = network || publicKeys[0].network || networks_1.defaultNetwork;
|
|
280
|
+
return Address.payingTo(script_1.Script.buildMultisigOut(publicKeys, threshold, {}), networkObj);
|
|
280
281
|
}
|
|
281
282
|
static fromPublicKey(data, network) {
|
|
282
|
-
const networkObj = (0,
|
|
283
|
+
const networkObj = (0, networks_1.get)(network) || networks_1.defaultNetwork;
|
|
283
284
|
const info = Address._transformPublicKey(data, networkObj);
|
|
284
285
|
return new Address(info.hashBuffer, info.network, info.type);
|
|
285
286
|
}
|
|
286
287
|
static fromPublicKeyHash(hash, network) {
|
|
287
|
-
const networkObj = (0,
|
|
288
|
+
const networkObj = (0, networks_1.get)(network) || networks_1.defaultNetwork;
|
|
288
289
|
return new Address(hash, networkObj, Address.PayToPublicKeyHash);
|
|
289
290
|
}
|
|
290
291
|
static fromScriptHash(hash, network) {
|
|
291
|
-
const networkObj = (0,
|
|
292
|
+
const networkObj = (0, networks_1.get)(network) || networks_1.defaultNetwork;
|
|
292
293
|
return new Address(hash, networkObj, Address.PayToScriptHash);
|
|
293
294
|
}
|
|
294
295
|
static fromTaprootCommitment(commitment, network) {
|
|
295
|
-
const networkObj = (0,
|
|
296
|
-
const commitmentBuf = commitment instanceof
|
|
296
|
+
const networkObj = (0, networks_1.get)(network) || networks_1.defaultNetwork;
|
|
297
|
+
const commitmentBuf = commitment instanceof publickey_1.PublicKey ? commitment.toBuffer() : commitment;
|
|
297
298
|
if (commitmentBuf.length !== 33) {
|
|
298
299
|
throw new Error('Taproot commitment must be 33-byte compressed public key');
|
|
299
300
|
}
|
|
@@ -308,19 +309,19 @@ class Address {
|
|
|
308
309
|
return new Address(info.hashBuffer, info.network, info.type);
|
|
309
310
|
}
|
|
310
311
|
static fromObject(obj) {
|
|
311
|
-
|
|
312
|
-
const hashBuffer =
|
|
312
|
+
preconditions_1.Preconditions.checkState(util_1.JSUtil.isHexa(obj.hash), 'Unexpected hash property, "' + obj.hash + '", expected to be hex.');
|
|
313
|
+
const hashBuffer = util_1.BufferUtil.from(obj.hash, 'hex');
|
|
313
314
|
return new Address(hashBuffer, obj.network, obj.type);
|
|
314
315
|
}
|
|
315
316
|
static fromScript(script, network) {
|
|
316
|
-
|
|
317
|
+
preconditions_1.Preconditions.checkArgument(script instanceof script_1.Script, 'script', 'script must be a Script instance');
|
|
317
318
|
const info = Address._transformScript(script, network);
|
|
318
319
|
return new Address(info.hashBuffer, network, info.type);
|
|
319
320
|
}
|
|
320
321
|
static payingTo(script, network) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
return Address.fromScriptHash(
|
|
322
|
+
preconditions_1.Preconditions.checkArgument(script !== null, 'script', 'script is required');
|
|
323
|
+
preconditions_1.Preconditions.checkArgument(script instanceof script_1.Script, 'script', 'script must be instance of Script');
|
|
324
|
+
return Address.fromScriptHash(hash_1.Hash.sha256ripemd160(script.toBuffer()), network);
|
|
324
325
|
}
|
|
325
326
|
static getValidationError(data, network, type) {
|
|
326
327
|
try {
|
|
@@ -347,10 +348,10 @@ class Address {
|
|
|
347
348
|
return this.hashBuffer;
|
|
348
349
|
}
|
|
349
350
|
toFullBuffer() {
|
|
350
|
-
const version =
|
|
351
|
+
const version = util_1.BufferUtil.from([
|
|
351
352
|
this.network[this.type],
|
|
352
353
|
]);
|
|
353
|
-
const buf =
|
|
354
|
+
const buf = util_1.BufferUtil.concat([version, this.hashBuffer]);
|
|
354
355
|
return buf;
|
|
355
356
|
}
|
|
356
357
|
toCashBuffer() {
|
|
@@ -377,11 +378,11 @@ class Address {
|
|
|
377
378
|
}
|
|
378
379
|
toXAddress(network) {
|
|
379
380
|
if (this.isPayToTaproot()) {
|
|
380
|
-
const xaddr = new
|
|
381
|
+
const xaddr = new xaddress_1.XAddress(this.hashBuffer, network ?? this.network, this.type);
|
|
381
382
|
return xaddr.toString();
|
|
382
383
|
}
|
|
383
|
-
const script =
|
|
384
|
-
const xaddr = new
|
|
384
|
+
const script = script_1.Script.fromAddress(this);
|
|
385
|
+
const xaddr = new xaddress_1.XAddress(script.toBuffer(), network ?? this.network, this.type);
|
|
385
386
|
return xaddr.toString();
|
|
386
387
|
}
|
|
387
388
|
static decodeCashAddress(address) {
|