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,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NFTUtil = exports.NFT = void 0;
|
|
4
|
-
const hash_js_1 = require("
|
|
5
|
-
const script_js_1 = require("
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
4
|
+
const hash_js_1 = require("./bitcore/crypto/hash.js");
|
|
5
|
+
const script_js_1 = require("./bitcore/script.js");
|
|
6
|
+
const opcode_js_1 = require("./bitcore/opcode.js");
|
|
7
|
+
const taproot_js_1 = require("./bitcore/script/taproot.js");
|
|
8
|
+
const transaction_js_1 = require("./bitcore/transaction/transaction.js");
|
|
9
|
+
const output_js_1 = require("./bitcore/transaction/output.js");
|
|
10
|
+
const taproot_js_2 = require("./bitcore/transaction/input/taproot.js");
|
|
11
|
+
const unspentoutput_js_1 = require("./bitcore/transaction/unspentoutput.js");
|
|
12
|
+
const signature_js_1 = require("./bitcore/crypto/signature.js");
|
|
13
|
+
const index_js_1 = require("./bitcore/index.js");
|
|
12
14
|
class NFT {
|
|
13
15
|
_script;
|
|
14
16
|
_address;
|
|
@@ -19,6 +21,7 @@ class NFT {
|
|
|
19
21
|
_outputIndex;
|
|
20
22
|
_commitment;
|
|
21
23
|
_merkleRoot;
|
|
24
|
+
_controlBlock;
|
|
22
25
|
_leaves;
|
|
23
26
|
_collectionHash;
|
|
24
27
|
constructor(config) {
|
|
@@ -39,9 +42,20 @@ class NFT {
|
|
|
39
42
|
this._commitment = result.commitment;
|
|
40
43
|
this._merkleRoot = result.merkleRoot;
|
|
41
44
|
this._leaves = result.leaves;
|
|
45
|
+
if (result.leaves.length > 0) {
|
|
46
|
+
this._controlBlock = (0, taproot_js_1.createControlBlock)(config.ownerKey, 0, config.scriptTree);
|
|
47
|
+
}
|
|
42
48
|
}
|
|
43
49
|
else {
|
|
44
|
-
|
|
50
|
+
const scriptTree = { script: new script_js_1.Script().add(opcode_js_1.Opcode.OP_CHECKSIG) };
|
|
51
|
+
const result = (0, taproot_js_1.buildScriptPathTaproot)(config.ownerKey, scriptTree, this._metadataHash);
|
|
52
|
+
this._script = result.script;
|
|
53
|
+
this._commitment = result.commitment;
|
|
54
|
+
this._merkleRoot = result.merkleRoot;
|
|
55
|
+
this._leaves = result.leaves;
|
|
56
|
+
if (result.leaves.length > 0) {
|
|
57
|
+
this._controlBlock = (0, taproot_js_1.createControlBlock)(config.ownerKey, 0, scriptTree);
|
|
58
|
+
}
|
|
45
59
|
}
|
|
46
60
|
const address = this._script.toAddress(config.network);
|
|
47
61
|
if (!address) {
|
|
@@ -50,7 +64,7 @@ class NFT {
|
|
|
50
64
|
this._address = address;
|
|
51
65
|
}
|
|
52
66
|
static fromScript(script, metadata, satoshis, txid, outputIndex) {
|
|
53
|
-
if (!
|
|
67
|
+
if (!script.isTaprootOut()) {
|
|
54
68
|
throw new Error('Script is not a valid Pay-To-Taproot script');
|
|
55
69
|
}
|
|
56
70
|
const metadataHash = (0, taproot_js_1.extractTaprootState)(script);
|
|
@@ -125,6 +139,9 @@ class NFT {
|
|
|
125
139
|
get leaves() {
|
|
126
140
|
return this._leaves;
|
|
127
141
|
}
|
|
142
|
+
get controlBlock() {
|
|
143
|
+
return this._controlBlock;
|
|
144
|
+
}
|
|
128
145
|
get collectionHash() {
|
|
129
146
|
return this._collectionHash;
|
|
130
147
|
}
|
|
@@ -141,6 +158,18 @@ class NFT {
|
|
|
141
158
|
if (!this._txid || this._outputIndex === undefined) {
|
|
142
159
|
throw new Error('Cannot transfer NFT without UTXO information (txid and outputIndex)');
|
|
143
160
|
}
|
|
161
|
+
if (!this._merkleRoot ||
|
|
162
|
+
!this._controlBlock ||
|
|
163
|
+
!this._leaves ||
|
|
164
|
+
this._leaves.length === 0) {
|
|
165
|
+
throw new Error('NFT does not have required script-path spending data (merkleRoot, controlBlock, leaves)');
|
|
166
|
+
}
|
|
167
|
+
const scriptPathData = {
|
|
168
|
+
internalPubKey: currentOwnerKey.publicKey,
|
|
169
|
+
merkleRoot: this._merkleRoot,
|
|
170
|
+
controlBlock: this._controlBlock,
|
|
171
|
+
tapScript: this._leaves[0].script,
|
|
172
|
+
};
|
|
144
173
|
return NFTUtil.transferNFT({
|
|
145
174
|
currentOwnerKey,
|
|
146
175
|
newOwnerKey,
|
|
@@ -151,6 +180,7 @@ class NFT {
|
|
|
151
180
|
satoshis: this._satoshis,
|
|
152
181
|
},
|
|
153
182
|
metadataHash: this._metadataHash,
|
|
183
|
+
scriptPathData,
|
|
154
184
|
fee,
|
|
155
185
|
});
|
|
156
186
|
}
|
|
@@ -196,6 +226,9 @@ class NFT {
|
|
|
196
226
|
};
|
|
197
227
|
}
|
|
198
228
|
toJSON() {
|
|
229
|
+
if (!this._commitment || !this._merkleRoot || !this._controlBlock) {
|
|
230
|
+
throw new Error('NFT is missing required script-path data for JSON serialization');
|
|
231
|
+
}
|
|
199
232
|
return {
|
|
200
233
|
script: this._script.toBuffer().toString('hex'),
|
|
201
234
|
address: this._address.toString(),
|
|
@@ -204,12 +237,19 @@ class NFT {
|
|
|
204
237
|
satoshis: this._satoshis,
|
|
205
238
|
txid: this._txid,
|
|
206
239
|
outputIndex: this._outputIndex,
|
|
207
|
-
commitment: this._commitment
|
|
208
|
-
merkleRoot: this._merkleRoot
|
|
240
|
+
commitment: this._commitment.toString(),
|
|
241
|
+
merkleRoot: this._merkleRoot.toString('hex'),
|
|
242
|
+
controlBlock: this._controlBlock.toString('hex'),
|
|
209
243
|
collectionHash: this._collectionHash?.toString('hex'),
|
|
210
244
|
};
|
|
211
245
|
}
|
|
212
246
|
toObject() {
|
|
247
|
+
if (!this._commitment ||
|
|
248
|
+
!this._merkleRoot ||
|
|
249
|
+
!this._controlBlock ||
|
|
250
|
+
!this._leaves) {
|
|
251
|
+
throw new Error('NFT is missing required script-path data');
|
|
252
|
+
}
|
|
213
253
|
return {
|
|
214
254
|
script: this._script,
|
|
215
255
|
address: this._address,
|
|
@@ -218,6 +258,10 @@ class NFT {
|
|
|
218
258
|
satoshis: this._satoshis,
|
|
219
259
|
txid: this._txid,
|
|
220
260
|
outputIndex: this._outputIndex,
|
|
261
|
+
commitment: this._commitment,
|
|
262
|
+
merkleRoot: this._merkleRoot,
|
|
263
|
+
controlBlock: this._controlBlock,
|
|
264
|
+
leaves: this._leaves,
|
|
221
265
|
};
|
|
222
266
|
}
|
|
223
267
|
toString() {
|
|
@@ -228,11 +272,11 @@ exports.NFT = NFT;
|
|
|
228
272
|
class NFTUtil {
|
|
229
273
|
static hashMetadata(metadata) {
|
|
230
274
|
const metadataJSON = JSON.stringify(metadata);
|
|
231
|
-
return hash_js_1.Hash.sha256(
|
|
275
|
+
return hash_js_1.Hash.sha256(index_js_1.BufferUtil.from(metadataJSON, 'utf8'));
|
|
232
276
|
}
|
|
233
277
|
static hashCollection(collectionInfo) {
|
|
234
278
|
const collectionJSON = JSON.stringify(collectionInfo);
|
|
235
|
-
return hash_js_1.Hash.sha256(
|
|
279
|
+
return hash_js_1.Hash.sha256(index_js_1.BufferUtil.from(collectionJSON, 'utf8'));
|
|
236
280
|
}
|
|
237
281
|
static hashCollectionNFT(collectionHash, nftMetadata) {
|
|
238
282
|
const combinedData = {
|
|
@@ -240,7 +284,7 @@ class NFTUtil {
|
|
|
240
284
|
nft: nftMetadata,
|
|
241
285
|
};
|
|
242
286
|
const combinedJSON = JSON.stringify(combinedData);
|
|
243
|
-
return hash_js_1.Hash.sha256(
|
|
287
|
+
return hash_js_1.Hash.sha256(index_js_1.BufferUtil.from(combinedJSON, 'utf8'));
|
|
244
288
|
}
|
|
245
289
|
static verifyMetadata(metadata, hash) {
|
|
246
290
|
const computedHash = NFTUtil.hashMetadata(metadata);
|
|
@@ -251,24 +295,36 @@ class NFTUtil {
|
|
|
251
295
|
return computedHash.equals(hash);
|
|
252
296
|
}
|
|
253
297
|
static extractMetadataHash(script) {
|
|
254
|
-
if (!
|
|
298
|
+
if (!script.isTaprootOut()) {
|
|
255
299
|
throw new Error('Script is not a valid Pay-To-Taproot script');
|
|
256
300
|
}
|
|
257
301
|
return (0, taproot_js_1.extractTaprootState)(script);
|
|
258
302
|
}
|
|
259
|
-
static
|
|
303
|
+
static createNFT(ownerKey, metadata, satoshis = 1000, network) {
|
|
260
304
|
const metadataHash = NFTUtil.hashMetadata(metadata);
|
|
261
|
-
const
|
|
262
|
-
|
|
305
|
+
const metadataScript = new script_js_1.Script()
|
|
306
|
+
.add(opcode_js_1.Opcode.OP_SHA256)
|
|
307
|
+
.add(metadataHash)
|
|
308
|
+
.add(opcode_js_1.Opcode.OP_EQUALVERIFY)
|
|
309
|
+
.add(opcode_js_1.Opcode.OP_CHECKSIG);
|
|
310
|
+
const scriptTree = {
|
|
311
|
+
script: metadataScript,
|
|
312
|
+
};
|
|
313
|
+
const result = (0, taproot_js_1.buildScriptPathTaproot)(ownerKey, scriptTree, metadataHash);
|
|
314
|
+
const address = result.script.toAddress(network);
|
|
263
315
|
if (!address) {
|
|
264
316
|
throw new Error('Failed to create address from script');
|
|
265
317
|
}
|
|
266
318
|
return {
|
|
267
|
-
script,
|
|
319
|
+
script: result.script,
|
|
268
320
|
address,
|
|
269
321
|
metadataHash,
|
|
270
322
|
metadata,
|
|
271
323
|
satoshis,
|
|
324
|
+
commitment: result.commitment,
|
|
325
|
+
merkleRoot: result.merkleRoot,
|
|
326
|
+
controlBlock: (0, taproot_js_1.createControlBlock)(ownerKey, 0, scriptTree),
|
|
327
|
+
leaves: result.leaves,
|
|
272
328
|
};
|
|
273
329
|
}
|
|
274
330
|
static createScriptPathNFT(ownerKey, metadata, scriptTree, satoshis = 1000, network) {
|
|
@@ -278,6 +334,7 @@ class NFTUtil {
|
|
|
278
334
|
if (!address) {
|
|
279
335
|
throw new Error('Failed to create address from script');
|
|
280
336
|
}
|
|
337
|
+
const controlBlock = (0, taproot_js_1.createControlBlock)(ownerKey, 0, scriptTree);
|
|
281
338
|
return {
|
|
282
339
|
script,
|
|
283
340
|
address,
|
|
@@ -286,12 +343,16 @@ class NFTUtil {
|
|
|
286
343
|
satoshis,
|
|
287
344
|
commitment,
|
|
288
345
|
merkleRoot,
|
|
346
|
+
controlBlock,
|
|
289
347
|
leaves,
|
|
290
348
|
};
|
|
291
349
|
}
|
|
292
350
|
static createCollectionNFT(ownerKey, collectionHash, nftMetadata, satoshis = 1000, network) {
|
|
293
351
|
const metadataHash = NFTUtil.hashCollectionNFT(collectionHash, nftMetadata);
|
|
294
|
-
const script = (0, taproot_js_1.
|
|
352
|
+
const { script, commitment, merkleRoot, leaves } = (0, taproot_js_1.buildScriptPathTaproot)(ownerKey, { script: new script_js_1.Script().add(opcode_js_1.Opcode.OP_CHECKSIG) }, metadataHash);
|
|
353
|
+
const controlBlock = (0, taproot_js_1.createControlBlock)(ownerKey, 0, {
|
|
354
|
+
script: new script_js_1.Script().add(opcode_js_1.Opcode.OP_CHECKSIG),
|
|
355
|
+
});
|
|
295
356
|
const address = script.toAddress(network);
|
|
296
357
|
if (!address) {
|
|
297
358
|
throw new Error('Failed to create address from script');
|
|
@@ -302,11 +363,15 @@ class NFTUtil {
|
|
|
302
363
|
metadataHash,
|
|
303
364
|
metadata: nftMetadata,
|
|
304
365
|
satoshis,
|
|
366
|
+
commitment,
|
|
367
|
+
merkleRoot,
|
|
368
|
+
controlBlock,
|
|
369
|
+
leaves,
|
|
305
370
|
collectionHash,
|
|
306
371
|
};
|
|
307
372
|
}
|
|
308
373
|
static mintNFT(config) {
|
|
309
|
-
const nft = NFTUtil.
|
|
374
|
+
const nft = NFTUtil.createNFT(config.ownerKey.publicKey, config.metadata, config.satoshis || 1000, config.network);
|
|
310
375
|
const tx = new transaction_js_1.Transaction();
|
|
311
376
|
tx.addOutput(new output_js_1.Output({
|
|
312
377
|
script: nft.script,
|
|
@@ -317,7 +382,7 @@ class NFTUtil {
|
|
|
317
382
|
static mintBatch(ownerKey, nftMetadataList, satoshisPerNFT = 1000, network) {
|
|
318
383
|
const tx = new transaction_js_1.Transaction();
|
|
319
384
|
for (const metadata of nftMetadataList) {
|
|
320
|
-
const nft = NFTUtil.
|
|
385
|
+
const nft = NFTUtil.createNFT(ownerKey.publicKey, metadata, satoshisPerNFT, network);
|
|
321
386
|
tx.addOutput(new output_js_1.Output({
|
|
322
387
|
script: nft.script,
|
|
323
388
|
satoshis: nft.satoshis,
|
|
@@ -338,31 +403,35 @@ class NFTUtil {
|
|
|
338
403
|
return tx;
|
|
339
404
|
}
|
|
340
405
|
static transferNFT(config) {
|
|
341
|
-
const { currentOwnerKey, newOwnerKey, nftUtxo, metadataHash, fee } = config;
|
|
406
|
+
const { currentOwnerKey, newOwnerKey, nftUtxo, metadataHash, fee, scriptPathData, } = config;
|
|
342
407
|
const inputState = NFTUtil.extractMetadataHash(nftUtxo.script);
|
|
343
408
|
if (!inputState || !inputState.equals(metadataHash)) {
|
|
344
409
|
throw new Error('Input script metadata hash does not match');
|
|
345
410
|
}
|
|
346
|
-
const newNFTScript = (0, taproot_js_1.
|
|
411
|
+
const newNFTScript = (0, taproot_js_1.buildScriptPathTaproot)(newOwnerKey, { script: new script_js_1.Script().add(opcode_js_1.Opcode.OP_CHECKSIG) }, metadataHash).script;
|
|
347
412
|
const outputSatoshis = fee ? nftUtxo.satoshis - fee : nftUtxo.satoshis;
|
|
348
413
|
if (outputSatoshis < 546) {
|
|
349
414
|
throw new Error('Output value below dust limit (546 satoshis)');
|
|
350
415
|
}
|
|
351
416
|
const tx = new transaction_js_1.Transaction();
|
|
352
|
-
tx.addInput(new
|
|
353
|
-
prevTxId:
|
|
417
|
+
tx.addInput(new taproot_js_2.TaprootInput({
|
|
418
|
+
prevTxId: index_js_1.BufferUtil.from(nftUtxo.txid, 'hex'),
|
|
354
419
|
outputIndex: nftUtxo.outputIndex,
|
|
355
420
|
output: new output_js_1.Output({
|
|
356
421
|
script: nftUtxo.script,
|
|
357
422
|
satoshis: nftUtxo.satoshis,
|
|
358
423
|
}),
|
|
359
424
|
script: new script_js_1.Script(),
|
|
425
|
+
internalPubKey: scriptPathData.internalPubKey,
|
|
426
|
+
merkleRoot: scriptPathData.merkleRoot,
|
|
427
|
+
controlBlock: scriptPathData.controlBlock,
|
|
428
|
+
tapScript: scriptPathData.tapScript,
|
|
360
429
|
}));
|
|
361
430
|
tx.addOutput(new output_js_1.Output({
|
|
362
431
|
script: newNFTScript,
|
|
363
432
|
satoshis: outputSatoshis,
|
|
364
433
|
}));
|
|
365
|
-
tx.sign(currentOwnerKey, signature_js_1.Signature.SIGHASH_ALL | signature_js_1.Signature.
|
|
434
|
+
tx.sign(currentOwnerKey, signature_js_1.Signature.SIGHASH_ALL | signature_js_1.Signature.SIGHASH_FORKID, 'schnorr');
|
|
366
435
|
return tx;
|
|
367
436
|
}
|
|
368
437
|
static validateTransfer(inputScript, outputScript) {
|
|
@@ -386,7 +455,7 @@ class NFTUtil {
|
|
|
386
455
|
return true;
|
|
387
456
|
}
|
|
388
457
|
static isNFT(script) {
|
|
389
|
-
if (!
|
|
458
|
+
if (!script.isTaprootOut()) {
|
|
390
459
|
return false;
|
|
391
460
|
}
|
|
392
461
|
const state = (0, taproot_js_1.extractTaprootState)(script);
|
|
@@ -14,6 +14,7 @@ exports.toSentimentUTF8 = toSentimentUTF8;
|
|
|
14
14
|
exports.toCommentUTF8 = toCommentUTF8;
|
|
15
15
|
exports.toScriptRANK = toScriptRANK;
|
|
16
16
|
exports.toScriptRNKC = toScriptRNKC;
|
|
17
|
+
const buffer_1 = require("buffer/");
|
|
17
18
|
const constants_js_1 = require("../../utils/constants.js");
|
|
18
19
|
const string_js_1 = require("../../utils/string.js");
|
|
19
20
|
const opcode_js_1 = __importDefault(require("./opcode.js"));
|
|
@@ -119,15 +120,15 @@ function toProfileIdBuf(platform, profileId) {
|
|
|
119
120
|
if (profileIdSpec.regex && !profileIdSpec.regex.test(profileId)) {
|
|
120
121
|
return null;
|
|
121
122
|
}
|
|
122
|
-
const profileBuf = Buffer.alloc(profileIdSpec.len);
|
|
123
|
+
const profileBuf = buffer_1.Buffer.alloc(profileIdSpec.len);
|
|
123
124
|
switch (platform) {
|
|
124
125
|
case 'lotusia': {
|
|
125
|
-
const profileIdHex = Buffer.from(profileId, 'hex');
|
|
126
|
-
|
|
126
|
+
const profileIdHex = buffer_1.Buffer.from(profileId, 'hex');
|
|
127
|
+
profileIdHex.copy(profileBuf, profileIdSpec.len - profileIdHex.length);
|
|
127
128
|
break;
|
|
128
129
|
}
|
|
129
130
|
case 'twitter':
|
|
130
|
-
|
|
131
|
+
buffer_1.Buffer.from(profileId, 'utf8').copy(profileBuf, profileIdSpec.len - profileId.length);
|
|
131
132
|
break;
|
|
132
133
|
default:
|
|
133
134
|
return null;
|
|
@@ -140,9 +141,9 @@ function toProfileIdUTF8(profileIdBuf) {
|
|
|
140
141
|
function toPostIdBuf(platform, postId) {
|
|
141
142
|
switch (platform) {
|
|
142
143
|
case 'lotusia':
|
|
143
|
-
return Buffer.from(postId, 'hex');
|
|
144
|
+
return buffer_1.Buffer.from(postId, 'hex');
|
|
144
145
|
case 'twitter':
|
|
145
|
-
return Buffer.from(BigInt(postId).toString(16), 'hex');
|
|
146
|
+
return buffer_1.Buffer.from(BigInt(postId).toString(16), 'hex');
|
|
146
147
|
default:
|
|
147
148
|
return undefined;
|
|
148
149
|
}
|
|
@@ -150,18 +151,18 @@ function toPostIdBuf(platform, postId) {
|
|
|
150
151
|
function toPlatformBuf(platform) {
|
|
151
152
|
for (const [byte, platformName] of exports.SCRIPT_CHUNK_PLATFORM) {
|
|
152
153
|
if (platformName == platform) {
|
|
153
|
-
return Buffer.from([byte]);
|
|
154
|
+
return buffer_1.Buffer.from([byte]);
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
}
|
|
157
158
|
function toPlatformUTF8(platformBuf) {
|
|
158
|
-
return exports.SCRIPT_CHUNK_PLATFORM.get(platformBuf.
|
|
159
|
+
return exports.SCRIPT_CHUNK_PLATFORM.get(platformBuf.readUInt8(0));
|
|
159
160
|
}
|
|
160
161
|
function toSentimentOpCode(sentiment) {
|
|
161
162
|
return exports.RANK_SENTIMENT_OP_CODES.get(sentiment);
|
|
162
163
|
}
|
|
163
164
|
function toSentimentUTF8(sentimentBuf) {
|
|
164
|
-
return exports.SCRIPT_CHUNK_SENTIMENT.get(sentimentBuf.readUInt8());
|
|
165
|
+
return exports.SCRIPT_CHUNK_SENTIMENT.get(sentimentBuf.readUInt8(0));
|
|
165
166
|
}
|
|
166
167
|
function toCommentUTF8(commentBuf) {
|
|
167
168
|
return new TextDecoder('utf-8').decode(commentBuf);
|
|
@@ -198,7 +199,7 @@ function toScriptRANK(sentiment, platform, profileId, postId) {
|
|
|
198
199
|
script += (0, string_js_1.toHex)(platformSpec.postId.len);
|
|
199
200
|
script += (0, string_js_1.toHex)(toPostIdBuf(platform, postId));
|
|
200
201
|
}
|
|
201
|
-
return Buffer.from(script, 'hex');
|
|
202
|
+
return buffer_1.Buffer.from(script, 'hex');
|
|
202
203
|
}
|
|
203
204
|
function toScriptRNKC({ platform, profileId, postId, comment, }) {
|
|
204
205
|
if (!platform || !profileId) {
|
|
@@ -214,7 +215,7 @@ function toScriptRNKC({ platform, profileId, postId, comment, }) {
|
|
|
214
215
|
if (postId && !platformSpec.postId.regex.test(postId)) {
|
|
215
216
|
throw new Error(`Invalid postId: ${postId}`);
|
|
216
217
|
}
|
|
217
|
-
const commentBuf = Buffer.from(comment, 'utf8');
|
|
218
|
+
const commentBuf = buffer_1.Buffer.from(comment, 'utf8');
|
|
218
219
|
if (commentBuf.length < 1 || commentBuf.length > constants_js_1.MAX_OP_RETURN_DATA * 2) {
|
|
219
220
|
throw new Error(`Comment must be between 1 and ${constants_js_1.MAX_OP_RETURN_DATA * 2} bytes`);
|
|
220
221
|
}
|
|
@@ -230,18 +231,18 @@ function toScriptRNKC({ platform, profileId, postId, comment, }) {
|
|
|
230
231
|
scriptRNKC += (0, string_js_1.toHex)(platformSpec.postId.len);
|
|
231
232
|
scriptRNKC += (0, string_js_1.toHex)(toPostIdBuf(platform, postId));
|
|
232
233
|
}
|
|
233
|
-
scriptBufs.push(Buffer.from(scriptRNKC, 'hex'));
|
|
234
|
-
const commentBuf1 = commentBuf.
|
|
234
|
+
scriptBufs.push(buffer_1.Buffer.from(scriptRNKC, 'hex'));
|
|
235
|
+
const commentBuf1 = commentBuf.slice(0, constants_js_1.MAX_OP_RETURN_DATA);
|
|
235
236
|
let scriptComment = OP_RETURN + OP_PUSHDATA1;
|
|
236
237
|
scriptComment += (0, string_js_1.toHex)(commentBuf1.length);
|
|
237
238
|
scriptComment += (0, string_js_1.toHex)(commentBuf1);
|
|
238
|
-
scriptBufs.push(Buffer.from(scriptComment, 'hex'));
|
|
239
|
+
scriptBufs.push(buffer_1.Buffer.from(scriptComment, 'hex'));
|
|
239
240
|
if (commentBuf.length > constants_js_1.MAX_OP_RETURN_DATA) {
|
|
240
|
-
const commentBuf2 = commentBuf.
|
|
241
|
+
const commentBuf2 = commentBuf.slice(constants_js_1.MAX_OP_RETURN_DATA);
|
|
241
242
|
let scriptComment2 = OP_RETURN + OP_PUSHDATA1;
|
|
242
243
|
scriptComment2 += (0, string_js_1.toHex)(commentBuf2.length);
|
|
243
244
|
scriptComment2 += (0, string_js_1.toHex)(commentBuf2);
|
|
244
|
-
scriptBufs.push(Buffer.from(scriptComment2, 'hex'));
|
|
245
|
+
scriptBufs.push(buffer_1.Buffer.from(scriptComment2, 'hex'));
|
|
245
246
|
}
|
|
246
247
|
return scriptBufs;
|
|
247
248
|
}
|
|
@@ -261,8 +262,8 @@ class ScriptProcessor {
|
|
|
261
262
|
}
|
|
262
263
|
}
|
|
263
264
|
addScript(script) {
|
|
264
|
-
if (!(script instanceof Buffer)) {
|
|
265
|
-
script = Buffer.from(script, 'hex');
|
|
265
|
+
if (!(script instanceof buffer_1.Buffer)) {
|
|
266
|
+
script = buffer_1.Buffer.from(script, 'hex');
|
|
266
267
|
}
|
|
267
268
|
if (!(0, script_js_1.isOpReturn)(script)) {
|
|
268
269
|
return false;
|
|
@@ -274,7 +275,7 @@ class ScriptProcessor {
|
|
|
274
275
|
return this.processLokad();
|
|
275
276
|
}
|
|
276
277
|
processLokad() {
|
|
277
|
-
const lokadBuf = this.script.
|
|
278
|
+
const lokadBuf = this.script.slice(2, 6);
|
|
278
279
|
const lokad = exports.SCRIPT_CHUNK_LOKAD.get(lokadBuf.readUInt32BE(0));
|
|
279
280
|
if (!lokad) {
|
|
280
281
|
return undefined;
|
|
@@ -286,16 +287,16 @@ class ScriptProcessor {
|
|
|
286
287
|
if (!chunk || chunk.offset === null) {
|
|
287
288
|
return undefined;
|
|
288
289
|
}
|
|
289
|
-
const sentimentBuf = this.script.
|
|
290
|
-
return exports.SCRIPT_CHUNK_SENTIMENT.get(sentimentBuf.readUInt8());
|
|
290
|
+
const sentimentBuf = this.script.slice(chunk.offset, chunk.offset + chunk.len);
|
|
291
|
+
return exports.SCRIPT_CHUNK_SENTIMENT.get(sentimentBuf.readUInt8(0));
|
|
291
292
|
}
|
|
292
293
|
processPlatform() {
|
|
293
294
|
const chunk = this.chunks?.get('platform');
|
|
294
295
|
if (!chunk || chunk.offset === null) {
|
|
295
296
|
return undefined;
|
|
296
297
|
}
|
|
297
|
-
const platformBuf = this.script.
|
|
298
|
-
const platform = exports.SCRIPT_CHUNK_PLATFORM.get(platformBuf.readUInt8());
|
|
298
|
+
const platformBuf = this.script.slice(chunk.offset, chunk.offset + chunk.len);
|
|
299
|
+
const platform = exports.SCRIPT_CHUNK_PLATFORM.get(platformBuf.readUInt8(0));
|
|
299
300
|
if (!platform) {
|
|
300
301
|
return undefined;
|
|
301
302
|
}
|
|
@@ -311,7 +312,7 @@ class ScriptProcessor {
|
|
|
311
312
|
return undefined;
|
|
312
313
|
}
|
|
313
314
|
const profileIdSpec = platformSpec.profileId;
|
|
314
|
-
const profileIdBuf = this.script.
|
|
315
|
+
const profileIdBuf = this.script.slice(chunk.offset, chunk.offset + profileIdSpec.len);
|
|
315
316
|
if (profileIdBuf.length < profileIdSpec.len) {
|
|
316
317
|
return undefined;
|
|
317
318
|
}
|
|
@@ -338,7 +339,7 @@ class ScriptProcessor {
|
|
|
338
339
|
}
|
|
339
340
|
const postIdSpec = platformSpec.postId;
|
|
340
341
|
const postIdOffset = profileIdChunk.offset + platformSpec.profileId.len + 1;
|
|
341
|
-
const postIdBuf = this.script.
|
|
342
|
+
const postIdBuf = this.script.slice(postIdOffset, postIdOffset + postIdSpec.len);
|
|
342
343
|
try {
|
|
343
344
|
switch (platform) {
|
|
344
345
|
case 'lotusia':
|
|
@@ -354,7 +355,7 @@ class ScriptProcessor {
|
|
|
354
355
|
}
|
|
355
356
|
}
|
|
356
357
|
processComment(scripts) {
|
|
357
|
-
let commentBuf = Buffer.alloc(0);
|
|
358
|
+
let commentBuf = buffer_1.Buffer.alloc(0);
|
|
358
359
|
for (let i = 0; i < scripts.length; i++) {
|
|
359
360
|
const script = scripts[i];
|
|
360
361
|
if (script.readUInt8(1) !== opcode_js_1.default.OP_PUSHDATA1) {
|
|
@@ -364,7 +365,7 @@ class ScriptProcessor {
|
|
|
364
365
|
if (isNaN(dataSize) || dataSize > constants_js_1.MAX_OP_RETURN_DATA) {
|
|
365
366
|
break;
|
|
366
367
|
}
|
|
367
|
-
commentBuf = Buffer.concat([commentBuf, script.
|
|
368
|
+
commentBuf = buffer_1.Buffer.concat([commentBuf, script.slice(3, 3 + dataSize)]);
|
|
368
369
|
}
|
|
369
370
|
if (!commentBuf) {
|
|
370
371
|
return null;
|
|
@@ -4,10 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.isOpReturn = isOpReturn;
|
|
7
|
+
const buffer_1 = require("buffer/");
|
|
7
8
|
const opcode_js_1 = __importDefault(require("./opcode.js"));
|
|
8
9
|
function isOpReturn(script) {
|
|
9
10
|
if (typeof script === 'string') {
|
|
10
|
-
script = Buffer.from(script, 'hex');
|
|
11
|
+
script = buffer_1.Buffer.from(script, 'hex');
|
|
11
12
|
}
|
|
12
13
|
return script.readUInt8(0) === opcode_js_1.default.OP_RETURN;
|
|
13
14
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.processTransaction = processTransaction;
|
|
4
|
+
const buffer_1 = require("buffer/");
|
|
4
5
|
const index_js_1 = require("../bitcore/transaction/index.js");
|
|
5
6
|
function processTransaction(tx) {
|
|
6
7
|
if (typeof tx === 'string') {
|
|
@@ -9,7 +10,7 @@ function processTransaction(tx) {
|
|
|
9
10
|
}
|
|
10
11
|
tx = index_js_1.Transaction.fromString(tx);
|
|
11
12
|
}
|
|
12
|
-
else if (tx instanceof Buffer) {
|
|
13
|
+
else if (tx instanceof buffer_1.Buffer) {
|
|
13
14
|
tx = index_js_1.Transaction.fromBuffer(tx);
|
|
14
15
|
}
|
|
15
16
|
}
|
package/dist/cjs/utils/string.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.truncateSha256 = truncateSha256;
|
|
|
10
10
|
exports.truncateTxid = truncateTxid;
|
|
11
11
|
exports.truncateAddress = truncateAddress;
|
|
12
12
|
exports.truncateBlockHash = truncateBlockHash;
|
|
13
|
+
const buffer_1 = require("buffer/");
|
|
13
14
|
function isSha256(str) {
|
|
14
15
|
return isHex(str, 64);
|
|
15
16
|
}
|
|
@@ -18,9 +19,9 @@ function toHex(data) {
|
|
|
18
19
|
case 'number':
|
|
19
20
|
return data.toString(16).padStart(2, '0');
|
|
20
21
|
case 'string':
|
|
21
|
-
return Buffer.from(data, 'utf8').toString('hex');
|
|
22
|
+
return buffer_1.Buffer.from(data, 'utf8').toString('hex');
|
|
22
23
|
case 'object':
|
|
23
|
-
if (data instanceof Buffer) {
|
|
24
|
+
if (data instanceof buffer_1.Buffer) {
|
|
24
25
|
return data.toString('hex');
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -37,13 +38,13 @@ function decodeBase64(str) {
|
|
|
37
38
|
if (!isBase64(str)) {
|
|
38
39
|
throw new Error('Invalid base64 string');
|
|
39
40
|
}
|
|
40
|
-
return Buffer.from(str, 'base64').toString('utf8');
|
|
41
|
+
return buffer_1.Buffer.from(str, 'base64').toString('utf8');
|
|
41
42
|
}
|
|
42
43
|
function encodeBase64(str, encoding = 'utf8') {
|
|
43
|
-
if (!new TextDecoder('utf8').decode(Buffer.from(str, encoding))) {
|
|
44
|
+
if (!new TextDecoder('utf8').decode(buffer_1.Buffer.from(str, encoding))) {
|
|
44
45
|
throw new Error('Not a valid UTF-8 string');
|
|
45
46
|
}
|
|
46
|
-
return Buffer.from(str, encoding).toString('base64');
|
|
47
|
+
return buffer_1.Buffer.from(str, encoding).toString('base64');
|
|
47
48
|
}
|
|
48
49
|
function truncateSha256(sha256) {
|
|
49
50
|
return sha256.slice(0, 16) + '...' + sha256.slice(-6);
|