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,20 +1,21 @@
|
|
|
1
|
-
import { Preconditions } from '../util/preconditions
|
|
2
|
-
import { JSUtil } from '../util/js
|
|
3
|
-
import { BufferReader } from '../encoding/bufferreader
|
|
4
|
-
import { BufferWriter } from '../encoding/bufferwriter
|
|
5
|
-
import { Hash } from '../crypto/hash
|
|
6
|
-
import { Signature } from '../crypto/signature
|
|
7
|
-
import { verify } from './sighash
|
|
8
|
-
import { BitcoreError } from '../errors
|
|
9
|
-
import { Address } from '../address
|
|
10
|
-
import { UnspentOutput } from './unspentoutput
|
|
11
|
-
import { Input, MultisigInput, MultisigScriptHashInput, PublicKeyInput, PublicKeyHashInput, TaprootInput,
|
|
12
|
-
import { Output } from './output
|
|
13
|
-
import { Script } from '../script
|
|
14
|
-
import { PrivateKey } from '../privatekey
|
|
15
|
-
import { BN } from '../crypto/bn
|
|
16
|
-
import { sighash as computeSighash } from './sighash
|
|
17
|
-
import { Interpreter } from '../script/interpreter
|
|
1
|
+
import { Preconditions } from '../util/preconditions';
|
|
2
|
+
import { JSUtil } from '../util/js';
|
|
3
|
+
import { BufferReader } from '../encoding/bufferreader';
|
|
4
|
+
import { BufferWriter } from '../encoding/bufferwriter';
|
|
5
|
+
import { Hash } from '../crypto/hash';
|
|
6
|
+
import { Signature } from '../crypto/signature';
|
|
7
|
+
import { verify } from './sighash';
|
|
8
|
+
import { BitcoreError } from '../errors';
|
|
9
|
+
import { Address } from '../address';
|
|
10
|
+
import { UnspentOutput } from './unspentoutput';
|
|
11
|
+
import { Input, MultisigInput, MultisigScriptHashInput, PublicKeyInput, PublicKeyHashInput, TaprootInput, MuSig2TaprootInput, } from './input';
|
|
12
|
+
import { Output } from './output';
|
|
13
|
+
import { Script } from '../script';
|
|
14
|
+
import { PrivateKey } from '../privatekey';
|
|
15
|
+
import { BN } from '../crypto/bn';
|
|
16
|
+
import { sighash as computeSighash } from './sighash';
|
|
17
|
+
import { Interpreter } from '../script/interpreter';
|
|
18
|
+
import { BufferUtil } from '../util';
|
|
18
19
|
const CURRENT_VERSION = 2;
|
|
19
20
|
const DEFAULT_NLOCKTIME = 0;
|
|
20
21
|
const MAX_BLOCK_SIZE = 32_000_000;
|
|
@@ -26,7 +27,7 @@ const NLOCKTIME_MAX_VALUE = 4294967295;
|
|
|
26
27
|
const FEE_PER_KB = 1_000;
|
|
27
28
|
const CHANGE_OUTPUT_MAX_SIZE = 20 + 4 + 34 + 4;
|
|
28
29
|
const MAXIMUM_EXTRA_SIZE = 4 + 9 + 9 + 4;
|
|
29
|
-
const NULL_HASH =
|
|
30
|
+
const NULL_HASH = BufferUtil.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
|
|
30
31
|
export class Transaction {
|
|
31
32
|
static DUST_AMOUNT = DUST_AMOUNT;
|
|
32
33
|
static FEE_SECURITY_MARGIN = FEE_SECURITY_MARGIN;
|
|
@@ -62,7 +63,7 @@ export class Transaction {
|
|
|
62
63
|
else if (typeof serialized === 'string' && JSUtil.isHexa(serialized)) {
|
|
63
64
|
this.fromString(serialized);
|
|
64
65
|
}
|
|
65
|
-
else if (
|
|
66
|
+
else if (BufferUtil.isBuffer(serialized)) {
|
|
66
67
|
this.fromBuffer(serialized);
|
|
67
68
|
}
|
|
68
69
|
else if (serialized && typeof serialized === 'object') {
|
|
@@ -99,6 +100,9 @@ export class Transaction {
|
|
|
99
100
|
}
|
|
100
101
|
return this._hash;
|
|
101
102
|
}
|
|
103
|
+
get hashBuffer() {
|
|
104
|
+
return this._getHash();
|
|
105
|
+
}
|
|
102
106
|
get id() {
|
|
103
107
|
return this.txid;
|
|
104
108
|
}
|
|
@@ -110,6 +114,9 @@ export class Transaction {
|
|
|
110
114
|
}
|
|
111
115
|
return this._txid;
|
|
112
116
|
}
|
|
117
|
+
get txidBuffer() {
|
|
118
|
+
return this._getTxid();
|
|
119
|
+
}
|
|
113
120
|
get inputAmount() {
|
|
114
121
|
return this._getInputAmount();
|
|
115
122
|
}
|
|
@@ -198,7 +205,7 @@ export class Transaction {
|
|
|
198
205
|
size += 1;
|
|
199
206
|
}
|
|
200
207
|
for (let i = 0; i < size; i += 2) {
|
|
201
|
-
const buf =
|
|
208
|
+
const buf = BufferUtil.concat([hashes[j + i], hashes[j + i + 1]]);
|
|
202
209
|
hashes.push(Hash.sha256sha256(buf));
|
|
203
210
|
}
|
|
204
211
|
j += size;
|
|
@@ -347,7 +354,7 @@ export class Transaction {
|
|
|
347
354
|
return this;
|
|
348
355
|
}
|
|
349
356
|
fromString(str) {
|
|
350
|
-
return this.fromBuffer(
|
|
357
|
+
return this.fromBuffer(BufferUtil.from(str, 'hex'));
|
|
351
358
|
}
|
|
352
359
|
toObject() {
|
|
353
360
|
const inputs = this.inputs.map(input => input.toObject());
|
|
@@ -504,12 +511,12 @@ export class Transaction {
|
|
|
504
511
|
return this.sign(privateKey, Signature.SIGHASH_ALL | Signature.SIGHASH_LOTUS, 'schnorr');
|
|
505
512
|
}
|
|
506
513
|
getMuSig2Inputs() {
|
|
507
|
-
return this.inputs.filter(input => input instanceof
|
|
514
|
+
return this.inputs.filter(input => input instanceof MuSig2TaprootInput);
|
|
508
515
|
}
|
|
509
516
|
getMuSig2Sighash(inputIndex) {
|
|
510
517
|
const input = this.inputs[inputIndex];
|
|
511
|
-
if (!(input instanceof
|
|
512
|
-
throw new Error(`Input ${inputIndex} is not a
|
|
518
|
+
if (!(input instanceof MuSig2TaprootInput)) {
|
|
519
|
+
throw new Error(`Input ${inputIndex} is not a MuSig2TaprootInput`);
|
|
513
520
|
}
|
|
514
521
|
if (!input.output) {
|
|
515
522
|
throw new Error(`Input ${inputIndex} is missing output information`);
|
|
@@ -519,16 +526,16 @@ export class Transaction {
|
|
|
519
526
|
}
|
|
520
527
|
addMuSig2Nonce(inputIndex, signerIndex, nonce) {
|
|
521
528
|
const input = this.inputs[inputIndex];
|
|
522
|
-
if (!(input instanceof
|
|
523
|
-
throw new Error(`Input ${inputIndex} is not a
|
|
529
|
+
if (!(input instanceof MuSig2TaprootInput)) {
|
|
530
|
+
throw new Error(`Input ${inputIndex} is not a MuSig2TaprootInput`);
|
|
524
531
|
}
|
|
525
532
|
input.addPublicNonce(signerIndex, nonce);
|
|
526
533
|
return this;
|
|
527
534
|
}
|
|
528
535
|
addMuSig2PartialSignature(inputIndex, signerIndex, partialSig) {
|
|
529
536
|
const input = this.inputs[inputIndex];
|
|
530
|
-
if (!(input instanceof
|
|
531
|
-
throw new Error(`Input ${inputIndex} is not a
|
|
537
|
+
if (!(input instanceof MuSig2TaprootInput)) {
|
|
538
|
+
throw new Error(`Input ${inputIndex} is not a MuSig2TaprootInput`);
|
|
532
539
|
}
|
|
533
540
|
input.addPartialSignature(signerIndex, partialSig);
|
|
534
541
|
return this;
|
|
@@ -537,13 +544,13 @@ export class Transaction {
|
|
|
537
544
|
const musigInputs = this.getMuSig2Inputs();
|
|
538
545
|
for (let i = 0; i < this.inputs.length; i++) {
|
|
539
546
|
const input = this.inputs[i];
|
|
540
|
-
if (input instanceof
|
|
547
|
+
if (input instanceof MuSig2TaprootInput) {
|
|
541
548
|
if (!input.hasAllPartialSignatures()) {
|
|
542
549
|
throw new Error(`MuSig2 input ${i} is missing partial signatures. ` +
|
|
543
550
|
`Has ${input.partialSignatures?.size || 0} of ${input.keyAggContext?.pubkeys.length || 0}`);
|
|
544
551
|
}
|
|
545
552
|
const sighash = this.getMuSig2Sighash(i);
|
|
546
|
-
input.
|
|
553
|
+
input.finalizeMuSig2Signature(this, sighash);
|
|
547
554
|
}
|
|
548
555
|
}
|
|
549
556
|
return this;
|
|
@@ -556,7 +563,7 @@ export class Transaction {
|
|
|
556
563
|
const input = this.inputs[index];
|
|
557
564
|
let inputSigtype = sigtype;
|
|
558
565
|
if (!inputSigtype) {
|
|
559
|
-
if (input.output?.script.
|
|
566
|
+
if (input.output?.script.isTaprootOut()) {
|
|
560
567
|
const taprootInput = input;
|
|
561
568
|
if (taprootInput.hasScriptTree()) {
|
|
562
569
|
inputSigtype = Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID;
|
|
@@ -660,7 +667,7 @@ export class Transaction {
|
|
|
660
667
|
x.i = i++;
|
|
661
668
|
});
|
|
662
669
|
copy.sort((first, second) => {
|
|
663
|
-
const prevTxIdCompare =
|
|
670
|
+
const prevTxIdCompare = BufferUtil.compare(first.prevTxId, second.prevTxId);
|
|
664
671
|
if (prevTxIdCompare !== 0)
|
|
665
672
|
return prevTxIdCompare;
|
|
666
673
|
const outputIndexCompare = first.outputIndex - second.outputIndex;
|
|
@@ -682,7 +689,7 @@ export class Transaction {
|
|
|
682
689
|
const satoshisCompare = first.satoshis - second.satoshis;
|
|
683
690
|
if (satoshisCompare !== 0)
|
|
684
691
|
return satoshisCompare;
|
|
685
|
-
const scriptCompare =
|
|
692
|
+
const scriptCompare = BufferUtil.compare(first.scriptBuffer, second.scriptBuffer);
|
|
686
693
|
if (scriptCompare !== 0)
|
|
687
694
|
return scriptCompare;
|
|
688
695
|
return (first.i -
|
|
@@ -817,13 +824,10 @@ export class Transaction {
|
|
|
817
824
|
try {
|
|
818
825
|
const verifyFlags = flags !== undefined
|
|
819
826
|
? flags
|
|
820
|
-
: Interpreter.
|
|
821
|
-
Interpreter.
|
|
822
|
-
Interpreter.
|
|
823
|
-
Interpreter.
|
|
824
|
-
Interpreter.SCRIPT_VERIFY_NULLFAIL |
|
|
825
|
-
Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID |
|
|
826
|
-
Interpreter.SCRIPT_ENABLE_SCHNORR_MULTISIG;
|
|
827
|
+
: Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID |
|
|
828
|
+
Interpreter.SCRIPT_VERIFY_CLEANSTACK |
|
|
829
|
+
Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS |
|
|
830
|
+
Interpreter.SCRIPT_VERIFY_INPUT_SIGCHECKS;
|
|
827
831
|
const interpreter = new Interpreter();
|
|
828
832
|
const isValid = interpreter.verify(input.script, input.output.script, this, i, verifyFlags, BigInt(input.output.satoshis));
|
|
829
833
|
if (!isValid) {
|
|
@@ -870,11 +874,14 @@ export class Transaction {
|
|
|
870
874
|
_fromNonP2SH(utxo) {
|
|
871
875
|
let clazz;
|
|
872
876
|
const unspentOutput = new UnspentOutput(utxo);
|
|
873
|
-
if (unspentOutput.script.
|
|
877
|
+
if (unspentOutput.script.isTaprootOut()) {
|
|
874
878
|
if (unspentOutput.keyAggContext &&
|
|
875
879
|
unspentOutput.mySignerIndex !== undefined) {
|
|
876
|
-
|
|
877
|
-
|
|
880
|
+
if (!unspentOutput.internalPubKey || !unspentOutput.merkleRoot) {
|
|
881
|
+
throw new BitcoreError('MuSig2 Taproot input requires internalPubKey and merkleRoot');
|
|
882
|
+
}
|
|
883
|
+
clazz = MuSig2TaprootInput;
|
|
884
|
+
const input = new MuSig2TaprootInput({
|
|
878
885
|
output: new Output({
|
|
879
886
|
script: unspentOutput.script,
|
|
880
887
|
satoshis: unspentOutput.satoshis,
|
|
@@ -884,10 +891,15 @@ export class Transaction {
|
|
|
884
891
|
script: new Script(),
|
|
885
892
|
keyAggContext: unspentOutput.keyAggContext,
|
|
886
893
|
mySignerIndex: unspentOutput.mySignerIndex,
|
|
894
|
+
internalPubKey: unspentOutput.internalPubKey,
|
|
895
|
+
merkleRoot: unspentOutput.merkleRoot,
|
|
887
896
|
});
|
|
888
897
|
this.addInput(input);
|
|
889
898
|
return;
|
|
890
899
|
}
|
|
900
|
+
if (!unspentOutput.internalPubKey) {
|
|
901
|
+
throw new BitcoreError('Taproot input requires internalPubKey');
|
|
902
|
+
}
|
|
891
903
|
clazz = TaprootInput;
|
|
892
904
|
const taprootInput = new TaprootInput({
|
|
893
905
|
output: new Output({
|
|
@@ -898,12 +910,12 @@ export class Transaction {
|
|
|
898
910
|
outputIndex: unspentOutput.outputIndex,
|
|
899
911
|
script: new Script(),
|
|
900
912
|
internalPubKey: unspentOutput.internalPubKey,
|
|
901
|
-
merkleRoot: unspentOutput.merkleRoot ||
|
|
913
|
+
merkleRoot: unspentOutput.merkleRoot || BufferUtil.alloc(32),
|
|
902
914
|
});
|
|
903
915
|
this.addInput(taprootInput);
|
|
904
916
|
return;
|
|
905
917
|
}
|
|
906
|
-
else if (unspentOutput.script.
|
|
918
|
+
else if (unspentOutput.script.isPublicKeyHashOut()) {
|
|
907
919
|
clazz = PublicKeyHashInput;
|
|
908
920
|
}
|
|
909
921
|
else if (unspentOutput.script.isPublicKeyOut()) {
|
|
@@ -936,7 +948,7 @@ export class Transaction {
|
|
|
936
948
|
script: new Script(),
|
|
937
949
|
}), pubkeys, threshold, undefined, opts));
|
|
938
950
|
}
|
|
939
|
-
else if (unspentOutput.script.
|
|
951
|
+
else if (unspentOutput.script.isScriptHashOut()) {
|
|
940
952
|
this.addInput(new MultisigScriptHashInput(new Input({
|
|
941
953
|
output: new Output({
|
|
942
954
|
script: unspentOutput.script,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Preconditions } from '../util/preconditions
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { Preconditions } from '../util/preconditions';
|
|
2
|
+
import { BufferUtil } from '../util/buffer';
|
|
3
|
+
import { JSUtil } from '../util/js';
|
|
4
|
+
import { Script } from '../script';
|
|
5
|
+
import { Address } from '../address';
|
|
6
|
+
import { PublicKey } from '../publickey';
|
|
7
|
+
import { Unit } from '../unit';
|
|
7
8
|
export class UnspentOutput {
|
|
8
9
|
address;
|
|
9
10
|
txId;
|
|
@@ -18,7 +19,7 @@ export class UnspentOutput {
|
|
|
18
19
|
Preconditions.checkArgument(typeof data === 'object' && data !== null, 'Must provide an object from where to extract data');
|
|
19
20
|
const address = data.address ? new Address(data.address) : undefined;
|
|
20
21
|
const txId = data.txid || data.txId;
|
|
21
|
-
if (!txId || !JSUtil.
|
|
22
|
+
if (!txId || !JSUtil.isHexa(txId) || txId.length > 64) {
|
|
22
23
|
throw new Error('Invalid TXID in object: ' + JSON.stringify(data));
|
|
23
24
|
}
|
|
24
25
|
const outputIndex = data.vout !== undefined ? data.vout : data.outputIndex;
|
|
@@ -51,7 +52,7 @@ export class UnspentOutput {
|
|
|
51
52
|
if (data.internalPubKey instanceof PublicKey) {
|
|
52
53
|
this.internalPubKey = data.internalPubKey;
|
|
53
54
|
}
|
|
54
|
-
else if (
|
|
55
|
+
else if (BufferUtil.isBuffer(data.internalPubKey)) {
|
|
55
56
|
this.internalPubKey = new PublicKey(data.internalPubKey);
|
|
56
57
|
}
|
|
57
58
|
else if (typeof data.internalPubKey === 'string') {
|
|
@@ -69,7 +70,7 @@ export class UnspentOutput {
|
|
|
69
70
|
return Unit.fromSatoshis(this.satoshis);
|
|
70
71
|
}
|
|
71
72
|
isValid() {
|
|
72
|
-
return (JSUtil.
|
|
73
|
+
return (JSUtil.isHexa(this.txId) &&
|
|
73
74
|
this.txId.length === 64 &&
|
|
74
75
|
this.outputIndex >= 0 &&
|
|
75
76
|
this.satoshis > 0 &&
|
|
@@ -116,10 +117,13 @@ export class UnspentOutput {
|
|
|
116
117
|
return this.txId + ':' + this.outputIndex;
|
|
117
118
|
}
|
|
118
119
|
isPayToPublicKeyHash() {
|
|
119
|
-
return this.script.
|
|
120
|
+
return this.script.isPublicKeyHashOut();
|
|
120
121
|
}
|
|
121
122
|
isPayToScriptHash() {
|
|
122
|
-
return this.script.
|
|
123
|
+
return this.script.isScriptHashOut();
|
|
124
|
+
}
|
|
125
|
+
isPayToTaproot() {
|
|
126
|
+
return this.script.isTaprootOut();
|
|
123
127
|
}
|
|
124
128
|
getAddress() {
|
|
125
129
|
try {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function bitsToBytes(bits) {
|
|
2
|
+
const bytes = new Array(Math.ceil(bits.length / 8)).fill(0);
|
|
3
|
+
for (let p = 0; p < bits.length; p++) {
|
|
4
|
+
bytes[p >> 3] |= (bits[p] ? 1 : 0) << (p & 7);
|
|
5
|
+
}
|
|
6
|
+
return bytes;
|
|
7
|
+
}
|
|
8
|
+
export function bytesToBits(bytes) {
|
|
9
|
+
const bits = new Array(bytes.length * 8);
|
|
10
|
+
for (let p = 0; p < bits.length; p++) {
|
|
11
|
+
bits[p] = (bytes[p >> 3] & (1 << (p & 7))) !== 0;
|
|
12
|
+
}
|
|
13
|
+
return bits;
|
|
14
|
+
}
|
|
15
|
+
export function extractBit(bytes, position) {
|
|
16
|
+
return (bytes[position >> 3] & (1 << (position & 7))) !== 0;
|
|
17
|
+
}
|
|
18
|
+
export function setBit(bytes, position, value) {
|
|
19
|
+
const byteIndex = position >> 3;
|
|
20
|
+
const bitIndex = position & 7;
|
|
21
|
+
if (value) {
|
|
22
|
+
bytes[byteIndex] |= 1 << bitIndex;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
bytes[byteIndex] &= ~(1 << bitIndex);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Buffer } from 'buffer/';
|
|
2
2
|
export class BufferUtil {
|
|
3
|
+
static Buffer = Buffer;
|
|
3
4
|
static fill(buffer, value) {
|
|
4
|
-
Preconditions.checkArgumentType(buffer, 'Buffer', 'buffer');
|
|
5
|
-
Preconditions.checkArgumentType(value, 'number', 'value');
|
|
6
5
|
const length = buffer.length;
|
|
7
6
|
for (let i = 0; i < length; i++) {
|
|
8
7
|
buffer[i] = value;
|
|
@@ -18,13 +17,15 @@ export class BufferUtil {
|
|
|
18
17
|
return Buffer.isBuffer(arg) || arg instanceof Uint8Array;
|
|
19
18
|
}
|
|
20
19
|
static emptyBuffer(bytes) {
|
|
21
|
-
Preconditions.checkArgumentType(bytes, 'number', 'bytes');
|
|
22
20
|
const result = Buffer.alloc(bytes);
|
|
23
21
|
for (let i = 0; i < bytes; i++) {
|
|
24
22
|
result.write('\0', i);
|
|
25
23
|
}
|
|
26
24
|
return result;
|
|
27
25
|
}
|
|
26
|
+
static alloc(size, fill) {
|
|
27
|
+
return Buffer.alloc(size, fill);
|
|
28
|
+
}
|
|
28
29
|
static concat(list, totalLength) {
|
|
29
30
|
return Buffer.concat(list, totalLength);
|
|
30
31
|
}
|
|
@@ -44,11 +45,9 @@ export class BufferUtil {
|
|
|
44
45
|
return BufferUtil.equals(a, b);
|
|
45
46
|
}
|
|
46
47
|
static integerAsSingleByteBuffer(integer) {
|
|
47
|
-
Preconditions.checkArgumentType(integer, 'number', 'integer');
|
|
48
48
|
return Buffer.from([integer & 0xff]);
|
|
49
49
|
}
|
|
50
50
|
static integerAsBuffer(integer) {
|
|
51
|
-
Preconditions.checkArgumentType(integer, 'number', 'integer');
|
|
52
51
|
const bytes = [];
|
|
53
52
|
bytes.push((integer >> 24) & 0xff);
|
|
54
53
|
bytes.push((integer >> 16) & 0xff);
|
|
@@ -57,20 +56,32 @@ export class BufferUtil {
|
|
|
57
56
|
return Buffer.from(bytes);
|
|
58
57
|
}
|
|
59
58
|
static integerFromBuffer(buffer) {
|
|
60
|
-
Preconditions.checkArgumentType(buffer, 'Buffer', 'buffer');
|
|
61
59
|
return (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
|
|
62
60
|
}
|
|
63
61
|
static integerFromSingleByteBuffer(buffer) {
|
|
64
|
-
Preconditions.checkArgumentType(buffer, 'Buffer', 'buffer');
|
|
65
62
|
return buffer[0];
|
|
66
63
|
}
|
|
67
64
|
static bufferToHex(buffer) {
|
|
68
|
-
Preconditions.checkArgumentType(buffer, 'Buffer', 'buffer');
|
|
69
65
|
return buffer.toString('hex');
|
|
70
66
|
}
|
|
71
67
|
static reverse(param) {
|
|
72
68
|
return Buffer.from(param).reverse();
|
|
73
69
|
}
|
|
70
|
+
static from(data, byteOffsetOrEncoding, length) {
|
|
71
|
+
if (Array.isArray(data)) {
|
|
72
|
+
return Buffer.from(data);
|
|
73
|
+
}
|
|
74
|
+
if (typeof data === 'string') {
|
|
75
|
+
return Buffer.from(data, (byteOffsetOrEncoding || 'utf8'));
|
|
76
|
+
}
|
|
77
|
+
if (data instanceof ArrayBuffer) {
|
|
78
|
+
return Buffer.from(data, byteOffsetOrEncoding, length);
|
|
79
|
+
}
|
|
80
|
+
return Buffer.from(data);
|
|
81
|
+
}
|
|
82
|
+
static compare(buf1, buf2) {
|
|
83
|
+
return Buffer.compare(buf1, buf2);
|
|
84
|
+
}
|
|
74
85
|
}
|
|
75
86
|
export const NULL_HASH = BufferUtil.fill(Buffer.alloc(32), 0);
|
|
76
87
|
export const EMPTY_BUFFER = Buffer.alloc(0);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Hash } from '../crypto/hash';
|
|
2
|
+
import { BufferUtil } from './buffer';
|
|
3
|
+
export function calcTreeWidth(nLeaves, height) {
|
|
4
|
+
return (nLeaves + (1 << height) - 1) >> height;
|
|
5
|
+
}
|
|
6
|
+
export function calcTreeHeight(nLeaves) {
|
|
7
|
+
let height = 0;
|
|
8
|
+
while (calcTreeWidth(nLeaves, height) > 1) {
|
|
9
|
+
height++;
|
|
10
|
+
}
|
|
11
|
+
return height;
|
|
12
|
+
}
|
|
13
|
+
export function calcMerkleHash(height, pos, hashes, nullHash = BufferUtil.alloc(32)) {
|
|
14
|
+
if (height === 0) {
|
|
15
|
+
return hashes[pos];
|
|
16
|
+
}
|
|
17
|
+
const left = calcMerkleHash(height - 1, pos * 2, hashes, nullHash);
|
|
18
|
+
let right = left;
|
|
19
|
+
if (pos * 2 + 1 < calcTreeWidth(hashes.length, height - 1)) {
|
|
20
|
+
right = calcMerkleHash(height - 1, pos * 2 + 1, hashes, nullHash);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
right = nullHash.toString('hex');
|
|
24
|
+
}
|
|
25
|
+
return Hash.sha256sha256(BufferUtil.concat([
|
|
26
|
+
BufferUtil.from(left, 'hex'),
|
|
27
|
+
BufferUtil.from(right, 'hex'),
|
|
28
|
+
])).toString('hex');
|
|
29
|
+
}
|
|
30
|
+
export function traverseAndBuild(height, pos, nLeaves, hashes, vfMatch, vBits, vHash, nullHash = BufferUtil.alloc(32)) {
|
|
31
|
+
let fParentOfMatch = false;
|
|
32
|
+
const startIdx = pos << height;
|
|
33
|
+
const endIdx = Math.min((pos + 1) << height, nLeaves);
|
|
34
|
+
for (let p = startIdx; p < endIdx; p++) {
|
|
35
|
+
fParentOfMatch ||= vfMatch[p];
|
|
36
|
+
}
|
|
37
|
+
vBits.push(fParentOfMatch);
|
|
38
|
+
if (height === 0 || !fParentOfMatch) {
|
|
39
|
+
vHash.push(calcMerkleHash(height, pos, hashes, nullHash));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
traverseAndBuild(height - 1, pos * 2, nLeaves, hashes, vfMatch, vBits, vHash, nullHash);
|
|
43
|
+
if (pos * 2 + 1 < calcTreeWidth(nLeaves, height - 1)) {
|
|
44
|
+
traverseAndBuild(height - 1, pos * 2 + 1, nLeaves, hashes, vfMatch, vBits, vHash, nullHash);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { BitcoreError } from '../errors
|
|
1
|
+
import { BitcoreError } from '../errors';
|
|
2
|
+
import { BufferUtil } from './buffer';
|
|
2
3
|
export class Preconditions {
|
|
3
4
|
static checkState(condition, message) {
|
|
4
5
|
if (!condition) {
|
|
@@ -14,7 +15,7 @@ export class Preconditions {
|
|
|
14
15
|
argumentName = argumentName || '(unknown name)';
|
|
15
16
|
if (typeof type === 'string') {
|
|
16
17
|
if (type === 'Buffer') {
|
|
17
|
-
if (!
|
|
18
|
+
if (!BufferUtil.isBuffer(argument)) {
|
|
18
19
|
throw new BitcoreError.Precondition.InvalidArgumentType(argument, type, argumentName);
|
|
19
20
|
}
|
|
20
21
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Buffer } from 'buffer/';
|
|
1
2
|
import { Preconditions } from './util/preconditions.js';
|
|
2
3
|
import { Base58 } from './encoding/base58.js';
|
|
3
4
|
import { BufferWriter } from './encoding/bufferwriter.js';
|
|
@@ -5,8 +6,6 @@ import { Networks } from './networks.js';
|
|
|
5
6
|
import { Hash } from './crypto/hash.js';
|
|
6
7
|
import { JSUtil } from './util/js.js';
|
|
7
8
|
import { BufferUtil } from './util/buffer.js';
|
|
8
|
-
const TOKEN_NAME = 'lotus';
|
|
9
|
-
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
10
9
|
export class XAddress {
|
|
11
10
|
static PayToPublicKeyHash = 'pubkeyhash';
|
|
12
11
|
static PayToScriptHash = 'scripthash';
|
|
@@ -15,7 +14,7 @@ export class XAddress {
|
|
|
15
14
|
hashBuffer;
|
|
16
15
|
network;
|
|
17
16
|
type;
|
|
18
|
-
constructor(data, network, type, prefix =
|
|
17
|
+
constructor(data, network, type, prefix = 'lotus') {
|
|
19
18
|
if (data instanceof XAddress) {
|
|
20
19
|
return data;
|
|
21
20
|
}
|
|
@@ -96,7 +95,7 @@ export class XAddress {
|
|
|
96
95
|
}
|
|
97
96
|
return info;
|
|
98
97
|
}
|
|
99
|
-
static _transformBuffer(buffer, network, type, prefix =
|
|
98
|
+
static _transformBuffer(buffer, network, type, prefix = 'lotus') {
|
|
100
99
|
const info = {};
|
|
101
100
|
if (!Buffer.isBuffer(buffer) && !(buffer instanceof Uint8Array)) {
|
|
102
101
|
throw new TypeError('XAddress supplied is not a buffer.');
|
|
@@ -188,7 +187,7 @@ function createChecksum(prefix, networkChar, typeByte, payload) {
|
|
|
188
187
|
typeByte,
|
|
189
188
|
payload,
|
|
190
189
|
]);
|
|
191
|
-
return Hash.sha256(data).
|
|
190
|
+
return Hash.sha256(data).slice(0, 4);
|
|
192
191
|
}
|
|
193
192
|
function createChecksumLegacy(prefix, networkChar, typeByte, payload) {
|
|
194
193
|
const bw = new BufferWriter();
|
|
@@ -199,7 +198,7 @@ function createChecksumLegacy(prefix, networkChar, typeByte, payload) {
|
|
|
199
198
|
bw.writeVarintNum(payload.length);
|
|
200
199
|
bw.write(payload);
|
|
201
200
|
const buf = bw.concat();
|
|
202
|
-
return Hash.sha256(buf).
|
|
201
|
+
return Hash.sha256(buf).slice(0, 4);
|
|
203
202
|
}
|
|
204
203
|
function getType(typeByte) {
|
|
205
204
|
switch (typeByte) {
|
|
@@ -210,7 +209,7 @@ function getType(typeByte) {
|
|
|
210
209
|
case 2:
|
|
211
210
|
return 'taproot';
|
|
212
211
|
}
|
|
213
|
-
return
|
|
212
|
+
return null;
|
|
214
213
|
}
|
|
215
214
|
function getTypeByte(type) {
|
|
216
215
|
switch (type) {
|
|
@@ -263,15 +262,20 @@ function decode(address) {
|
|
|
263
262
|
const networkChar = address.substring(splitLocation, splitLocation + 1);
|
|
264
263
|
const encodedPayload = address.substring(splitLocation + 1);
|
|
265
264
|
const decodedBytes = Base58.decode(encodedPayload);
|
|
266
|
-
const typeByte = decodedBytes.
|
|
267
|
-
const payload = decodedBytes.
|
|
268
|
-
const decodedChecksum = decodedBytes.
|
|
265
|
+
const typeByte = decodedBytes.slice(0, 1);
|
|
266
|
+
const payload = decodedBytes.slice(1, decodedBytes.length - 4);
|
|
267
|
+
const decodedChecksum = decodedBytes.slice(decodedBytes.length - 4);
|
|
269
268
|
const checksum = createChecksum(prefix, networkChar, typeByte, payload);
|
|
270
|
-
|
|
269
|
+
const legacyChecksum = createChecksumLegacy(prefix, networkChar, typeByte, payload);
|
|
270
|
+
const validChecksum = checksum.toString('hex') === decodedChecksum.toString('hex') ||
|
|
271
|
+
legacyChecksum.toString('hex') === decodedChecksum.toString('hex');
|
|
272
|
+
Preconditions.checkArgument(validChecksum, 'checksum', 'Invalid checksum: ' + address);
|
|
273
|
+
const type = getType(typeByte[0]);
|
|
274
|
+
Preconditions.checkArgument(type !== null, 'typeByte', 'Invalid type byte: ' + typeByte[0]);
|
|
271
275
|
const info = {};
|
|
272
276
|
info.hashBuffer = payload;
|
|
273
277
|
info.network = getNetworkFromChar(networkChar);
|
|
274
|
-
info.type =
|
|
278
|
+
info.type = type;
|
|
275
279
|
info.prefix = prefix;
|
|
276
280
|
return info;
|
|
277
281
|
}
|