@opcat-labs/opcat 1.0.1 → 1.0.3
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/.cjs2esm.json +18 -0
- package/.mocharc.yaml +1 -1
- package/CHANGELOG.md +12 -0
- package/README.md +6 -0
- package/{lib/address.js → cjs/address.cjs} +77 -72
- package/cjs/block/block.cjs +332 -0
- package/{lib/block/blockheader.js → cjs/block/blockheader.cjs} +8 -7
- package/cjs/block/index.cjs +2 -0
- package/{lib/block/merkleblock.js → cjs/block/merkleblock.cjs} +23 -15
- package/cjs/bn.cjs +3411 -0
- package/{lib/crypto/bn.js → cjs/crypto/bn.cjs} +3 -3
- package/{lib/crypto/ecdsa.js → cjs/crypto/ecdsa.cjs} +150 -14
- package/{lib/crypto/hash.node.js → cjs/crypto/hash.cjs} +13 -2
- package/cjs/crypto/index.cjs +16 -0
- package/{lib/crypto/point.js → cjs/crypto/point.cjs} +11 -4
- package/cjs/crypto/random.cjs +18 -0
- package/{lib/crypto/signature.js → cjs/crypto/signature.cjs} +158 -8
- package/{lib/encoding/base58.js → cjs/encoding/base58.cjs} +58 -2
- package/cjs/encoding/base58check.cjs +192 -0
- package/cjs/encoding/bufferreader.cjs +333 -0
- package/cjs/encoding/bufferwriter.cjs +244 -0
- package/{lib/encoding/decode-asm.js → cjs/encoding/decode-asm.cjs} +4 -4
- package/{lib/encoding/decode-hex.js → cjs/encoding/decode-hex.cjs} +1 -1
- package/cjs/encoding/index.cjs +14 -0
- package/cjs/encoding/varint.cjs +116 -0
- package/{lib/errors/index.js → cjs/errors/index.cjs} +9 -9
- package/{lib/errors/spec.js → cjs/errors/spec.cjs} +2 -2
- package/cjs/hash-cache.cjs +98 -0
- package/{lib/hdprivatekey.js → cjs/hdprivatekey.cjs} +232 -140
- package/{lib/hdpublickey.js → cjs/hdpublickey.cjs} +120 -93
- package/cjs/index.cjs +94 -0
- package/cjs/interpreter/index.cjs +2 -0
- package/cjs/interpreter/interpreter.cjs +1988 -0
- package/{lib/script/stack.js → cjs/interpreter/stack.cjs} +9 -2
- package/{lib/message/message.js → cjs/message/message.cjs} +62 -25
- package/cjs/mnemonic/index.cjs +3 -0
- package/{lib/mnemonic/mnemonic.js → cjs/mnemonic/mnemonic.cjs} +44 -13
- package/{lib/mnemonic/pbkdf2.node.js → cjs/mnemonic/pbkdf2.cjs} +9 -2
- package/cjs/mnemonic/words/index.cjs +66 -0
- package/cjs/network.cjs +13 -0
- package/cjs/networks.cjs +321 -0
- package/{lib/opcode.js → cjs/opcode.cjs} +69 -5
- package/cjs/privatekey.cjs +422 -0
- package/{lib/publickey.js → cjs/publickey.cjs} +14 -16
- package/cjs/script/index.cjs +2 -0
- package/{lib/script/script.js → cjs/script/script.cjs} +322 -67
- package/cjs/transaction/index.cjs +5 -0
- package/cjs/transaction/input/index.cjs +34 -0
- package/cjs/transaction/input/input.cjs +396 -0
- package/{lib/transaction/input/multisig.js → cjs/transaction/input/multisig.cjs} +112 -18
- package/{lib/transaction/input/publickey.js → cjs/transaction/input/publickey.cjs} +29 -19
- package/{lib/transaction/input/publickeyhash.js → cjs/transaction/input/publickeyhash.cjs} +25 -17
- package/{lib/transaction/output.js → cjs/transaction/output.cjs} +100 -15
- package/cjs/transaction/sighash.cjs +187 -0
- package/{lib/transaction/signature.js → cjs/transaction/signature.cjs} +30 -6
- package/cjs/transaction/transaction.cjs +2000 -0
- package/{lib/transaction/unspentoutput.js → cjs/transaction/unspentoutput.cjs} +5 -5
- package/cjs/util/derivation.cjs +53 -0
- package/cjs/util/index.cjs +11 -0
- package/cjs/util/js.cjs +95 -0
- package/{lib/util/preconditions.js → cjs/util/preconditions.cjs} +2 -2
- package/esm/address.js +483 -0
- package/{lib → esm}/block/block.js +82 -27
- package/esm/block/blockheader.js +296 -0
- package/esm/block/index.js +2 -0
- package/esm/block/merkleblock.js +331 -0
- package/esm/bn.js +3411 -0
- package/esm/crypto/bn.js +278 -0
- package/esm/crypto/ecdsa.js +475 -0
- package/{lib/crypto/hash.browser.js → esm/crypto/hash.js} +18 -7
- package/esm/crypto/index.js +16 -0
- package/esm/crypto/point.js +228 -0
- package/esm/crypto/random.js +18 -0
- package/esm/crypto/signature.js +475 -0
- package/esm/encoding/base58.js +167 -0
- package/esm/encoding/base58check.js +192 -0
- package/esm/encoding/bufferreader.js +333 -0
- package/esm/encoding/bufferwriter.js +243 -0
- package/esm/encoding/decode-asm.js +24 -0
- package/esm/encoding/decode-hex.js +32 -0
- package/esm/encoding/decode-script-chunks.js +43 -0
- package/esm/encoding/encode-hex.js +284 -0
- package/esm/encoding/index.js +14 -0
- package/esm/encoding/is-hex.js +7 -0
- package/esm/encoding/varint.js +116 -0
- package/esm/errors/index.js +54 -0
- package/esm/errors/spec.js +314 -0
- package/esm/hash-cache.js +98 -0
- package/esm/hdprivatekey.js +768 -0
- package/esm/hdpublickey.js +549 -0
- package/esm/index.js +66 -0
- package/esm/interpreter/index.js +2 -0
- package/{lib/script → esm/interpreter}/interpreter.js +219 -66
- package/esm/interpreter/stack.js +116 -0
- package/esm/message/message.js +228 -0
- package/esm/mnemonic/index.js +3 -0
- package/esm/mnemonic/mnemonic.js +332 -0
- package/{lib/mnemonic/pbkdf2.browser.js → esm/mnemonic/pbkdf2.js} +13 -6
- package/esm/mnemonic/words/chinese.js +2054 -0
- package/esm/mnemonic/words/english.js +2054 -0
- package/esm/mnemonic/words/french.js +2054 -0
- package/esm/mnemonic/words/index.js +66 -0
- package/esm/mnemonic/words/italian.js +2054 -0
- package/esm/mnemonic/words/japanese.js +2054 -0
- package/esm/mnemonic/words/spanish.js +2054 -0
- package/esm/network.js +13 -0
- package/{lib → esm}/networks.js +61 -120
- package/esm/opcode.js +319 -0
- package/{lib → esm}/privatekey.js +76 -28
- package/esm/publickey.js +384 -0
- package/esm/script/index.js +2 -0
- package/esm/script/script.js +1329 -0
- package/esm/script/write-i32-le.js +17 -0
- package/esm/script/write-push-data.js +35 -0
- package/esm/script/write-u16-le.js +12 -0
- package/esm/script/write-u32-le.js +16 -0
- package/esm/script/write-u64-le.js +24 -0
- package/esm/script/write-u8-le.js +8 -0
- package/esm/script/write-varint.js +46 -0
- package/esm/transaction/index.js +5 -0
- package/esm/transaction/input/index.js +33 -0
- package/{lib → esm}/transaction/input/input.js +132 -90
- package/esm/transaction/input/multisig.js +335 -0
- package/esm/transaction/input/publickey.js +108 -0
- package/esm/transaction/input/publickeyhash.js +124 -0
- package/esm/transaction/output.js +316 -0
- package/{lib → esm}/transaction/sighash.js +42 -22
- package/esm/transaction/signature.js +120 -0
- package/{lib → esm}/transaction/transaction.js +522 -163
- package/esm/transaction/unspentoutput.js +112 -0
- package/esm/util/_.js +47 -0
- package/esm/util/derivation.js +53 -0
- package/esm/util/index.js +12 -0
- package/esm/util/js.js +95 -0
- package/esm/util/preconditions.js +33 -0
- package/fixup.cjs +17 -0
- package/package.json +18 -4
- package/test/{address.js → address.cjs} +14 -43
- package/test/block/{block.js → block.cjs} +3 -5
- package/test/block/{blockheader.js → blockheader.cjs} +2 -2
- package/test/block/{merklebloack.js → merklebloack.cjs} +2 -2
- package/test/crypto/{ecdsa.js → ecdsa.cjs} +9 -9
- package/test/crypto/{hash.browser.js → hash.browser.cjs} +2 -1
- package/test/crypto/{signature.js → signature.cjs} +2 -2
- package/test/data/bitcoind/script_tests.json +5 -5
- package/test/{hashCache.js → hashCache.cjs} +2 -1
- package/test/{hdkeys.js → hdkeys.cjs} +4 -2
- package/test/{hdprivatekey.js → hdprivatekey.cjs} +7 -6
- package/test/{hdpublickey.js → hdpublickey.cjs} +2 -7
- package/test/mnemonic/{pbkdf2.test.js → pbkdf2.test.cjs} +2 -2
- package/test/{networks.js → networks.cjs} +12 -31
- package/test/{publickey.js → publickey.cjs} +2 -2
- package/test/script/{interpreter.js → interpreter.cjs} +5 -5
- package/test/script/{script.js → script.cjs} +8 -2
- package/test/transaction/{deserialize.js → deserialize.cjs} +2 -2
- package/test/transaction/input/{input.js → input.cjs} +1 -1
- package/test/transaction/input/{multisig.js → multisig.cjs} +2 -1
- package/test/transaction/input/{publickeyhash.js → publickeyhash.cjs} +1 -1
- package/test/transaction/{sighash.js → sighash.cjs} +1 -1
- package/test/transaction/{transaction.js → transaction.cjs} +2 -2
- package/tsconfig.json +13 -0
- package/types/address.d.cts +252 -0
- package/types/block/block.d.cts +139 -0
- package/types/block/blockheader.d.cts +125 -0
- package/types/block/index.d.cts +2 -0
- package/types/block/merkleblock.d.cts +95 -0
- package/types/bn.d.cts +202 -0
- package/types/crypto/bn.d.cts +2 -0
- package/types/crypto/ecdsa.d.cts +187 -0
- package/types/crypto/hash.d.cts +118 -0
- package/types/crypto/index.d.cts +7 -0
- package/types/crypto/point.d.cts +134 -0
- package/types/crypto/random.d.cts +13 -0
- package/types/crypto/signature.d.cts +160 -0
- package/types/encoding/base58.d.cts +106 -0
- package/types/encoding/base58check.d.cts +107 -0
- package/types/encoding/bufferreader.d.cts +164 -0
- package/types/encoding/bufferwriter.d.cts +126 -0
- package/types/encoding/decode-asm.d.cts +2 -0
- package/types/encoding/decode-hex.d.cts +2 -0
- package/types/encoding/decode-script-chunks.d.cts +14 -0
- package/types/encoding/encode-hex.d.cts +2 -0
- package/types/encoding/index.d.cts +6 -0
- package/types/encoding/is-hex.d.cts +2 -0
- package/types/encoding/varint.d.cts +66 -0
- package/types/errors/index.d.cts +4 -0
- package/types/errors/spec.d.cts +22 -0
- package/types/hash-cache.d.cts +65 -0
- package/types/hdprivatekey.d.cts +281 -0
- package/types/hdpublickey.d.cts +240 -0
- package/types/index.d.cts +26 -0
- package/types/interpreter/index.d.cts +2 -0
- package/types/interpreter/interpreter.d.cts +228 -0
- package/types/interpreter/stack.d.cts +35 -0
- package/types/message/message.d.cts +110 -0
- package/types/mnemonic/index.d.cts +2 -0
- package/types/mnemonic/mnemonic.d.cts +171 -0
- package/types/mnemonic/pbkdf2.d.cts +14 -0
- package/types/mnemonic/words/chinese.d.cts +2 -0
- package/types/mnemonic/words/english.d.cts +2 -0
- package/types/mnemonic/words/french.d.cts +2 -0
- package/types/mnemonic/words/index.d.cts +22 -0
- package/types/mnemonic/words/italian.d.cts +2 -0
- package/types/mnemonic/words/japanese.d.cts +2 -0
- package/types/mnemonic/words/spanish.d.cts +2 -0
- package/types/network.d.cts +11 -0
- package/types/networks.d.cts +76 -0
- package/types/opcode.d.cts +93 -0
- package/types/privatekey.d.cts +169 -0
- package/types/publickey.d.cts +202 -0
- package/types/script/index.d.cts +2 -0
- package/types/script/script.d.cts +449 -0
- package/types/script/write-i32-le.d.cts +2 -0
- package/types/script/write-push-data.d.cts +2 -0
- package/types/script/write-u16-le.d.cts +2 -0
- package/types/script/write-u32-le.d.cts +2 -0
- package/types/script/write-u64-le.d.cts +2 -0
- package/types/script/write-u8-le.d.cts +2 -0
- package/types/script/write-varint.d.cts +2 -0
- package/types/transaction/index.d.cts +2 -0
- package/types/transaction/input/index.d.cts +2 -0
- package/types/transaction/input/input.d.cts +178 -0
- package/types/transaction/input/multisig.d.cts +127 -0
- package/types/transaction/input/publickey.d.cts +44 -0
- package/types/transaction/input/publickeyhash.d.cts +45 -0
- package/types/transaction/output.d.cts +118 -0
- package/types/transaction/sighash.d.cts +61 -0
- package/types/transaction/signature.d.cts +43 -0
- package/types/transaction/transaction.d.cts +716 -0
- package/types/transaction/unspentoutput.d.cts +83 -0
- package/types/util/_.d.cts +26 -0
- package/types/util/derivation.d.cts +21 -0
- package/types/util/index.d.cts +5 -0
- package/types/util/js.d.cts +50 -0
- package/types/util/preconditions.d.cts +3 -0
- package/index.d.ts +0 -1541
- package/index.js +0 -74
- package/lib/block/index.js +0 -4
- package/lib/bn.js +0 -3423
- package/lib/crypto/hash.js +0 -2
- package/lib/crypto/random.browser.js +0 -28
- package/lib/crypto/random.js +0 -2
- package/lib/crypto/random.node.js +0 -11
- package/lib/encoding/base58check.js +0 -121
- package/lib/encoding/bufferreader.js +0 -212
- package/lib/encoding/bufferwriter.js +0 -140
- package/lib/encoding/varint.js +0 -75
- package/lib/hash-cache.js +0 -50
- package/lib/mnemonic/pbkdf2.js +0 -2
- package/lib/mnemonic/words/index.js +0 -8
- package/lib/script/index.js +0 -5
- package/lib/transaction/index.js +0 -7
- package/lib/transaction/input/index.js +0 -5
- package/lib/util/js.js +0 -90
- /package/{lib/encoding/decode-script-chunks.js → cjs/encoding/decode-script-chunks.cjs} +0 -0
- /package/{lib/encoding/encode-hex.js → cjs/encoding/encode-hex.cjs} +0 -0
- /package/{lib/encoding/is-hex.js → cjs/encoding/is-hex.cjs} +0 -0
- /package/{lib/mnemonic/words/chinese.js → cjs/mnemonic/words/chinese.cjs} +0 -0
- /package/{lib/mnemonic/words/english.js → cjs/mnemonic/words/english.cjs} +0 -0
- /package/{lib/mnemonic/words/french.js → cjs/mnemonic/words/french.cjs} +0 -0
- /package/{lib/mnemonic/words/italian.js → cjs/mnemonic/words/italian.cjs} +0 -0
- /package/{lib/mnemonic/words/japanese.js → cjs/mnemonic/words/japanese.cjs} +0 -0
- /package/{lib/mnemonic/words/spanish.js → cjs/mnemonic/words/spanish.cjs} +0 -0
- /package/{lib/script/write-i32-le.js → cjs/script/write-i32-le.cjs} +0 -0
- /package/{lib/script/write-push-data.js → cjs/script/write-push-data.cjs} +0 -0
- /package/{lib/script/write-u16-le.js → cjs/script/write-u16-le.cjs} +0 -0
- /package/{lib/script/write-u32-le.js → cjs/script/write-u32-le.cjs} +0 -0
- /package/{lib/script/write-u64-le.js → cjs/script/write-u64-le.cjs} +0 -0
- /package/{lib/script/write-u8-le.js → cjs/script/write-u8-le.cjs} +0 -0
- /package/{lib/script/write-varint.js → cjs/script/write-varint.cjs} +0 -0
- /package/{lib/util/_.js → cjs/util/_.cjs} +0 -0
- /package/test/crypto/{bn.js → bn.cjs} +0 -0
- /package/test/crypto/{hash.js → hash.cjs} +0 -0
- /package/test/crypto/{point.js → point.cjs} +0 -0
- /package/test/crypto/{random.js → random.cjs} +0 -0
- /package/test/data/{blk86756-testnet.js → blk86756-testnet.cjs} +0 -0
- /package/test/data/{merkleblocks.js → merkleblocks.cjs} +0 -0
- /package/test/encoding/{base58.js → base58.cjs} +0 -0
- /package/test/encoding/{base58check.js → base58check.cjs} +0 -0
- /package/test/encoding/{bufferreader.js → bufferreader.cjs} +0 -0
- /package/test/encoding/{bufferwriter.js → bufferwriter.cjs} +0 -0
- /package/test/encoding/{varint.js → varint.cjs} +0 -0
- /package/test/{index.js → index.cjs} +0 -0
- /package/test/message/{message.js → message.cjs} +0 -0
- /package/test/mnemonic/{mnemonic.js → mnemonic.cjs} +0 -0
- /package/test/{opcode.js → opcode.cjs} +0 -0
- /package/test/{privatekey.js → privatekey.cjs} +0 -0
- /package/test/transaction/input/{publickey.js → publickey.cjs} +0 -0
- /package/test/transaction/{output.js → output.cjs} +0 -0
- /package/test/transaction/{signature.js → signature.cjs} +0 -0
- /package/test/transaction/{unspentoutput.js → unspentoutput.cjs} +0 -0
- /package/test/util/{js.js → js.cjs} +0 -0
- /package/test/util/{preconditions.js → preconditions.cjs} +0 -0
package/esm/network.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A network is merely a map containing values that correspond to version
|
|
3
|
+
* numbers for each bitcoin network. Currently only supporting "livenet"
|
|
4
|
+
* (a.k.a. "mainnet"), "testnet", "regtest".
|
|
5
|
+
* @constructor
|
|
6
|
+
*/
|
|
7
|
+
function Network() { }
|
|
8
|
+
|
|
9
|
+
Network.prototype.toString = function toString() {
|
|
10
|
+
return this.name;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default Network;
|
package/{lib → esm}/networks.js
RENAMED
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var JSUtil = require('./util/js');
|
|
1
|
+
import _ from './util/_.js';
|
|
2
|
+
import JSUtil from './util/js.js';
|
|
3
|
+
import Network from './network.js';
|
|
5
4
|
var networks = [];
|
|
6
5
|
var networkMaps = {};
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
|
-
* A
|
|
10
|
-
* numbers for each bitcoin network. Currently only supporting "livenet"
|
|
11
|
-
* (a.k.a. "mainnet"), "testnet", "regtest" and "stn".
|
|
8
|
+
* A tool class for managing all supported networks
|
|
12
9
|
* @constructor
|
|
13
10
|
*/
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
Network.prototype.toString = function toString() {
|
|
17
|
-
return this.name;
|
|
18
|
-
};
|
|
11
|
+
var Networks = function Networks() { }
|
|
19
12
|
|
|
20
13
|
/**
|
|
21
14
|
* @function
|
|
@@ -25,7 +18,7 @@ Network.prototype.toString = function toString() {
|
|
|
25
18
|
* @param {string|Array} keys - if set, only check if the magic number associated with this name matches
|
|
26
19
|
* @return Network
|
|
27
20
|
*/
|
|
28
|
-
function get(arg, keys) {
|
|
21
|
+
Networks.get = function get(arg, keys) {
|
|
29
22
|
if (~networks.indexOf(arg)) {
|
|
30
23
|
return arg;
|
|
31
24
|
}
|
|
@@ -60,6 +53,27 @@ function cashAddrPrefixToArray(cashAddrPrefix) {
|
|
|
60
53
|
return result;
|
|
61
54
|
}
|
|
62
55
|
|
|
56
|
+
|
|
57
|
+
function indexNetworkBy(network, keys) {
|
|
58
|
+
for (var i = 0; i < keys.length; i++) {
|
|
59
|
+
var key = keys[i];
|
|
60
|
+
var networkValue = network[key];
|
|
61
|
+
if (!_.isUndefined(networkValue) && !_.isObject(networkValue)) {
|
|
62
|
+
networkMaps[networkValue] = network;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function unindexNetworkBy(network, values) {
|
|
68
|
+
for (var index = 0; index < values.length; index++) {
|
|
69
|
+
var value = values[index];
|
|
70
|
+
if (networkMaps[value] === network) {
|
|
71
|
+
delete networkMaps[value];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
63
77
|
/**
|
|
64
78
|
* @function
|
|
65
79
|
* @member Networks#add
|
|
@@ -77,7 +91,8 @@ function cashAddrPrefixToArray(cashAddrPrefix) {
|
|
|
77
91
|
* @param {Array} data.dnsSeeds - An array of dns seeds
|
|
78
92
|
* @return Network
|
|
79
93
|
*/
|
|
80
|
-
function
|
|
94
|
+
Networks.add = function add(data) {
|
|
95
|
+
|
|
81
96
|
var network = new Network();
|
|
82
97
|
|
|
83
98
|
JSUtil.defineImmutable(network, {
|
|
@@ -121,24 +136,7 @@ function addNetwork(data) {
|
|
|
121
136
|
return network;
|
|
122
137
|
}
|
|
123
138
|
|
|
124
|
-
function indexNetworkBy(network, keys) {
|
|
125
|
-
for (var i = 0; i < keys.length; i++) {
|
|
126
|
-
var key = keys[i];
|
|
127
|
-
var networkValue = network[key];
|
|
128
|
-
if (!_.isUndefined(networkValue) && !_.isObject(networkValue)) {
|
|
129
|
-
networkMaps[networkValue] = network;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
139
|
|
|
134
|
-
function unindexNetworkBy(network, values) {
|
|
135
|
-
for (var index = 0; index < values.length; index++) {
|
|
136
|
-
var value = values[index];
|
|
137
|
-
if (networkMaps[value] === network) {
|
|
138
|
-
delete networkMaps[value];
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
140
|
|
|
143
141
|
/**
|
|
144
142
|
* @function
|
|
@@ -146,7 +144,7 @@ function unindexNetworkBy(network, values) {
|
|
|
146
144
|
* Will remove a custom network
|
|
147
145
|
* @param {Network} network
|
|
148
146
|
*/
|
|
149
|
-
function
|
|
147
|
+
Networks.remove = function remove(network) {
|
|
150
148
|
for (var i = 0; i < networks.length; i++) {
|
|
151
149
|
if (networks[i] === network) {
|
|
152
150
|
networks.splice(i, 1);
|
|
@@ -159,17 +157,16 @@ var networkMagic = {
|
|
|
159
157
|
livenet: 0xe3e1f3e8,
|
|
160
158
|
testnet: 0xf4e5f3f4,
|
|
161
159
|
regtest: 0xdab5bffa,
|
|
162
|
-
stn: 0xfbcec4f9,
|
|
163
160
|
};
|
|
164
161
|
|
|
165
|
-
var dnsSeeds = ['
|
|
162
|
+
var dnsSeeds = [''];
|
|
166
163
|
|
|
167
164
|
var TESTNET = {
|
|
168
165
|
PORT: 18333,
|
|
169
166
|
NETWORK_MAGIC: networkMagic.testnet,
|
|
170
167
|
DNS_SEEDS: dnsSeeds,
|
|
171
168
|
PREFIX: 'testnet',
|
|
172
|
-
CASHADDRPREFIX: '
|
|
169
|
+
CASHADDRPREFIX: 'opcattest',
|
|
173
170
|
};
|
|
174
171
|
|
|
175
172
|
var REGTEST = {
|
|
@@ -177,22 +174,14 @@ var REGTEST = {
|
|
|
177
174
|
NETWORK_MAGIC: networkMagic.regtest,
|
|
178
175
|
DNS_SEEDS: [],
|
|
179
176
|
PREFIX: 'regtest',
|
|
180
|
-
CASHADDRPREFIX: '
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
var STN = {
|
|
184
|
-
PORT: 9333,
|
|
185
|
-
NETWORK_MAGIC: networkMagic.stn,
|
|
186
|
-
DNS_SEEDS: ['stn-seed.bitcoinsv.io'],
|
|
187
|
-
PREFIX: 'stn',
|
|
188
|
-
CASHADDRPREFIX: 'opcatstn',
|
|
177
|
+
CASHADDRPREFIX: 'opcatreg',
|
|
189
178
|
};
|
|
190
179
|
|
|
191
180
|
var liveNetwork = {
|
|
192
181
|
name: 'livenet',
|
|
193
182
|
alias: 'mainnet',
|
|
194
183
|
prefix: 'bitcoin',
|
|
195
|
-
cashAddrPrefix: '
|
|
184
|
+
cashAddrPrefix: 'opcat',
|
|
196
185
|
pubkeyhash: 0x00,
|
|
197
186
|
privatekey: 0x80,
|
|
198
187
|
scripthash: 0x05,
|
|
@@ -230,150 +219,102 @@ var regtestNetwork = {
|
|
|
230
219
|
dnsSeeds: [],
|
|
231
220
|
indexBy: ['port', 'name', 'cashAddrPrefix', 'networkMagic'],
|
|
232
221
|
};
|
|
233
|
-
var stnNetwork = {
|
|
234
|
-
name: 'stn',
|
|
235
|
-
prefix: STN.PREFIX,
|
|
236
|
-
cashAddrPrefix: STN.CASHADDRPREFIX,
|
|
237
|
-
pubkeyhash: 0x6f,
|
|
238
|
-
privatekey: 0xef,
|
|
239
|
-
scripthash: 0xc4,
|
|
240
|
-
xpubkey: 0x043587cf,
|
|
241
|
-
xprivkey: 0x04358394,
|
|
242
|
-
networkMagic: STN.NETWORK_MAGIC,
|
|
243
|
-
indexBy: ['port', 'name', 'cashAddrPrefix', 'networkMagic'],
|
|
244
|
-
};
|
|
245
|
-
// Add configurable values for testnet/regtest
|
|
246
222
|
|
|
247
|
-
addNetwork(testNetwork);
|
|
248
|
-
addNetwork(stnNetwork);
|
|
249
|
-
addNetwork(regtestNetwork);
|
|
250
|
-
addNetwork(liveNetwork);
|
|
251
223
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
224
|
+
Networks.add(testNetwork);
|
|
225
|
+
Networks.add(regtestNetwork);
|
|
226
|
+
Networks.add(liveNetwork);
|
|
227
|
+
|
|
228
|
+
var livenet = Networks.get('livenet');
|
|
229
|
+
var regtest = Networks.get('regtest');
|
|
230
|
+
var testnet = Networks.get('testnet');
|
|
256
231
|
|
|
257
|
-
|
|
232
|
+
Networks.livenet = livenet;
|
|
233
|
+
Networks.regtest = regtest;
|
|
234
|
+
Networks.testnet = testnet;
|
|
235
|
+
Networks.defaultNetwork = livenet;
|
|
236
|
+
|
|
237
|
+
Object.defineProperty(Networks.testnet, 'port', {
|
|
258
238
|
enumerable: true,
|
|
259
239
|
configurable: false,
|
|
260
240
|
get: function () {
|
|
261
241
|
if (this.regtestEnabled) {
|
|
262
242
|
return REGTEST.PORT;
|
|
263
|
-
} else if (this.stnEnabled) {
|
|
264
|
-
return STN.PORT;
|
|
265
243
|
} else {
|
|
266
244
|
return TESTNET.PORT;
|
|
267
245
|
}
|
|
268
246
|
},
|
|
269
247
|
});
|
|
270
248
|
|
|
271
|
-
Object.defineProperty(testnet, 'networkMagic', {
|
|
249
|
+
Object.defineProperty(Networks.testnet, 'networkMagic', {
|
|
272
250
|
enumerable: true,
|
|
273
251
|
configurable: false,
|
|
274
252
|
get: function () {
|
|
275
253
|
if (this.regtestEnabled) {
|
|
276
254
|
return JSUtil.integerAsBuffer(REGTEST.NETWORK_MAGIC);
|
|
277
|
-
} else if (this.stnEnabled) {
|
|
278
|
-
return JSUtil.integerAsBuffer(STN.NETWORK_MAGIC);
|
|
279
255
|
} else {
|
|
280
256
|
return JSUtil.integerAsBuffer(TESTNET.NETWORK_MAGIC);
|
|
281
257
|
}
|
|
282
258
|
},
|
|
283
259
|
});
|
|
284
260
|
|
|
285
|
-
Object.defineProperty(testnet, 'dnsSeeds', {
|
|
261
|
+
Object.defineProperty(Networks.testnet, 'dnsSeeds', {
|
|
286
262
|
enumerable: true,
|
|
287
263
|
configurable: false,
|
|
288
264
|
get: function () {
|
|
289
265
|
if (this.regtestEnabled) {
|
|
290
266
|
return REGTEST.DNS_SEEDS;
|
|
291
|
-
} else if (this.stnEnabled) {
|
|
292
|
-
return STN.DNS_SEEDS;
|
|
293
267
|
} else {
|
|
294
268
|
return TESTNET.DNS_SEEDS;
|
|
295
269
|
}
|
|
296
270
|
},
|
|
297
271
|
});
|
|
298
272
|
|
|
299
|
-
Object.defineProperty(testnet, 'cashAddrPrefix', {
|
|
273
|
+
Object.defineProperty(Networks.testnet, 'cashAddrPrefix', {
|
|
300
274
|
enumerable: true,
|
|
301
275
|
configurable: false,
|
|
302
276
|
get: function () {
|
|
303
277
|
if (this.regtestEnabled) {
|
|
304
278
|
return REGTEST.CASHADDRPREFIX;
|
|
305
|
-
} else if (this.stnEnabled) {
|
|
306
|
-
return STN.CASHADDRPREFIX;
|
|
307
279
|
} else {
|
|
308
280
|
return TESTNET.CASHADDRPREFIX;
|
|
309
281
|
}
|
|
310
282
|
},
|
|
311
283
|
});
|
|
312
284
|
|
|
313
|
-
Object.defineProperty(testnet, 'cashAddrPrefixArray', {
|
|
285
|
+
Object.defineProperty(Networks.testnet, 'cashAddrPrefixArray', {
|
|
314
286
|
enumerable: true,
|
|
315
287
|
configurable: false,
|
|
316
288
|
get: function () {
|
|
317
289
|
if (this.regtestEnabled) {
|
|
318
290
|
return cashAddrPrefixToArray(REGTEST.CASHADDRPREFIX);
|
|
319
|
-
} else if (this.stnEnabled) {
|
|
320
|
-
return STN.cashAddrPrefixToArray(STN.CASHADDRPREFIX);
|
|
321
291
|
} else {
|
|
322
292
|
return cashAddrPrefixToArray(TESTNET.CASHADDRPREFIX);
|
|
323
293
|
}
|
|
324
294
|
},
|
|
325
295
|
});
|
|
326
296
|
|
|
297
|
+
|
|
327
298
|
/**
|
|
328
|
-
*
|
|
299
|
+
* Enables regtest network mode for testing purposes.
|
|
329
300
|
* @member Networks#enableRegtest
|
|
330
|
-
*
|
|
301
|
+
* @function
|
|
331
302
|
*/
|
|
332
|
-
function enableRegtest() {
|
|
303
|
+
Networks.enableRegtest = function enableRegtest() {
|
|
333
304
|
testnet.regtestEnabled = true;
|
|
334
305
|
}
|
|
335
306
|
|
|
307
|
+
|
|
336
308
|
/**
|
|
337
309
|
* @function
|
|
338
310
|
* @member Networks#disableRegtest
|
|
339
|
-
*
|
|
311
|
+
* Disables the regtest network configuration.
|
|
312
|
+
* This sets the `regtestEnabled` flag to false in the testnet configuration.
|
|
340
313
|
*/
|
|
341
|
-
function disableRegtest() {
|
|
314
|
+
Networks.disableRegtest = function disableRegtest() {
|
|
342
315
|
testnet.regtestEnabled = false;
|
|
343
316
|
}
|
|
344
|
-
/**
|
|
345
|
-
* @function
|
|
346
|
-
* @member Networks#enableStn
|
|
347
|
-
* Will enable stn features for testnet
|
|
348
|
-
*/
|
|
349
|
-
function enableStn() {
|
|
350
|
-
testnet.stnEnabled = true;
|
|
351
|
-
}
|
|
352
317
|
|
|
353
|
-
/**
|
|
354
|
-
* @function
|
|
355
|
-
* @member Networks#disableStn
|
|
356
|
-
* Will disable stn features for testnet
|
|
357
|
-
*/
|
|
358
|
-
function disableStn() {
|
|
359
|
-
testnet.stnEnabled = false;
|
|
360
|
-
}
|
|
361
318
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
*/
|
|
365
|
-
module.exports = {
|
|
366
|
-
add: addNetwork,
|
|
367
|
-
remove: removeNetwork,
|
|
368
|
-
defaultNetwork: livenet,
|
|
369
|
-
livenet: livenet,
|
|
370
|
-
mainnet: livenet,
|
|
371
|
-
testnet: testnet,
|
|
372
|
-
regtest: regtest,
|
|
373
|
-
stn: stn,
|
|
374
|
-
get: get,
|
|
375
|
-
enableRegtest: enableRegtest,
|
|
376
|
-
disableRegtest: disableRegtest,
|
|
377
|
-
enableStn: enableStn,
|
|
378
|
-
disableStn: disableStn,
|
|
379
|
-
};
|
|
319
|
+
|
|
320
|
+
export default Networks;
|
package/esm/opcode.js
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import _ from './util/_.js';
|
|
4
|
+
import $ from './util/preconditions.js';
|
|
5
|
+
import JSUtil from './util/js.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates an Opcode instance from a number or string representation.
|
|
9
|
+
* @constructor
|
|
10
|
+
* @param {number|string} num - The numeric value or string name of the opcode
|
|
11
|
+
* @throws {TypeError} If the input type is not recognized
|
|
12
|
+
* @returns {Opcode} A new Opcode instance
|
|
13
|
+
*/
|
|
14
|
+
function Opcode(num) {
|
|
15
|
+
if (!(this instanceof Opcode)) {
|
|
16
|
+
return new Opcode(num);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var value;
|
|
20
|
+
|
|
21
|
+
if (_.isNumber(num)) {
|
|
22
|
+
value = num;
|
|
23
|
+
} else if (_.isString(num)) {
|
|
24
|
+
value = Opcode.map[num];
|
|
25
|
+
} else {
|
|
26
|
+
throw new TypeError('Unrecognized num type: "' + typeof num + '" for Opcode');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
JSUtil.defineImmutable(this, {
|
|
30
|
+
num: value,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates an Opcode instance from a Buffer.
|
|
38
|
+
* @param {Buffer} buf - The buffer containing the opcode data.
|
|
39
|
+
* @returns {Opcode} The constructed Opcode instance.
|
|
40
|
+
* @throws {Error} If the input is not a Buffer.
|
|
41
|
+
*/
|
|
42
|
+
Opcode.fromBuffer = function (buf) {
|
|
43
|
+
$.checkArgument(Buffer.isBuffer(buf));
|
|
44
|
+
return new Opcode(Number('0x' + buf.toString('hex')));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates an Opcode instance from a number.
|
|
49
|
+
* @param {number} num - The numeric value to convert to an Opcode.
|
|
50
|
+
* @returns {Opcode} A new Opcode instance.
|
|
51
|
+
* @throws {Error} If the input is not a number.
|
|
52
|
+
*/
|
|
53
|
+
Opcode.fromNumber = function (num) {
|
|
54
|
+
$.checkArgument(_.isNumber(num));
|
|
55
|
+
return new Opcode(num);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Creates an Opcode instance from a string representation.
|
|
60
|
+
* @param {string} str - The string representation of the opcode.
|
|
61
|
+
* @returns {Opcode} A new Opcode instance corresponding to the input string.
|
|
62
|
+
* @throws {TypeError} If the input string is not a valid opcode representation.
|
|
63
|
+
*/
|
|
64
|
+
Opcode.fromString = function (str) {
|
|
65
|
+
$.checkArgument(_.isString(str));
|
|
66
|
+
var value = Opcode.map[str];
|
|
67
|
+
if (typeof value === 'undefined') {
|
|
68
|
+
throw new TypeError('Invalid opcodestr');
|
|
69
|
+
}
|
|
70
|
+
return new Opcode(value);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Converts the opcode number to its hexadecimal string representation.
|
|
75
|
+
* @returns {string} Hexadecimal string of the opcode number.
|
|
76
|
+
*/
|
|
77
|
+
Opcode.prototype.toHex = function () {
|
|
78
|
+
return this.num.toString(16);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Converts the opcode to a Buffer by first converting it to a hex string.
|
|
83
|
+
* @returns {Buffer} The opcode represented as a Buffer.
|
|
84
|
+
*/
|
|
85
|
+
Opcode.prototype.toBuffer = function () {
|
|
86
|
+
return Buffer.from(this.toHex(), 'hex');
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Gets the numeric value of the opcode.
|
|
91
|
+
* @returns {number} The numeric representation of the opcode.
|
|
92
|
+
*/
|
|
93
|
+
Opcode.prototype.toNumber = function () {
|
|
94
|
+
return this.num;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Converts the opcode number to its string representation.
|
|
99
|
+
* @throws {Error} If the opcode number has no corresponding string mapping.
|
|
100
|
+
* @returns {string} The string representation of the opcode.
|
|
101
|
+
*/
|
|
102
|
+
Opcode.prototype.toString = function () {
|
|
103
|
+
var str = Opcode.reverseMap[this.num];
|
|
104
|
+
if (typeof str === 'undefined') {
|
|
105
|
+
throw new Error('Opcode does not have a string representation');
|
|
106
|
+
}
|
|
107
|
+
return str;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Converts the opcode to a human-readable string representation.
|
|
112
|
+
* If the opcode has a known mnemonic, returns that string.
|
|
113
|
+
* Otherwise, returns the hexadecimal representation of the opcode.
|
|
114
|
+
* @returns {string} The safe string representation of the opcode.
|
|
115
|
+
*/
|
|
116
|
+
Opcode.prototype.toSafeString = function () {
|
|
117
|
+
var str = Opcode.reverseMap[this.num];
|
|
118
|
+
if (typeof str === 'undefined') {
|
|
119
|
+
return this.toHex();
|
|
120
|
+
}
|
|
121
|
+
return str;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Converts a small integer (0-16) to its corresponding opcode.
|
|
126
|
+
* @param {number} n - The integer to convert (must be between 0 and 16)
|
|
127
|
+
* @returns {Opcode} The corresponding opcode (OP_0 for 0, OP_1+n-1 for 1-16)
|
|
128
|
+
* @throws {Error} If n is not a number or outside valid range
|
|
129
|
+
*/
|
|
130
|
+
Opcode.smallInt = function (n) {
|
|
131
|
+
$.checkArgument(_.isNumber(n), 'Invalid Argument: n should be number');
|
|
132
|
+
$.checkArgument(n >= 0 && n <= 16, 'Invalid Argument: n must be between 0 and 16');
|
|
133
|
+
if (n === 0) {
|
|
134
|
+
return Opcode('OP_0');
|
|
135
|
+
}
|
|
136
|
+
return new Opcode(Opcode.map.OP_1 + n - 1);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* A map of opcode names to their corresponding numeric values.
|
|
141
|
+
* @type {Object.<string, number>}
|
|
142
|
+
*/
|
|
143
|
+
Opcode.map = {
|
|
144
|
+
// push value
|
|
145
|
+
OP_FALSE: 0,
|
|
146
|
+
OP_0: 0,
|
|
147
|
+
OP_PUSHDATA1: 76,
|
|
148
|
+
OP_PUSHDATA2: 77,
|
|
149
|
+
OP_PUSHDATA4: 78,
|
|
150
|
+
OP_1NEGATE: 79,
|
|
151
|
+
OP_RESERVED: 80,
|
|
152
|
+
OP_TRUE: 81,
|
|
153
|
+
OP_1: 81,
|
|
154
|
+
OP_2: 82,
|
|
155
|
+
OP_3: 83,
|
|
156
|
+
OP_4: 84,
|
|
157
|
+
OP_5: 85,
|
|
158
|
+
OP_6: 86,
|
|
159
|
+
OP_7: 87,
|
|
160
|
+
OP_8: 88,
|
|
161
|
+
OP_9: 89,
|
|
162
|
+
OP_10: 90,
|
|
163
|
+
OP_11: 91,
|
|
164
|
+
OP_12: 92,
|
|
165
|
+
OP_13: 93,
|
|
166
|
+
OP_14: 94,
|
|
167
|
+
OP_15: 95,
|
|
168
|
+
OP_16: 96,
|
|
169
|
+
|
|
170
|
+
// control
|
|
171
|
+
OP_NOP: 97,
|
|
172
|
+
OP_VER: 98,
|
|
173
|
+
OP_IF: 99,
|
|
174
|
+
OP_NOTIF: 100,
|
|
175
|
+
OP_VERIF: 101,
|
|
176
|
+
OP_VERNOTIF: 102,
|
|
177
|
+
OP_ELSE: 103,
|
|
178
|
+
OP_ENDIF: 104,
|
|
179
|
+
OP_VERIFY: 105,
|
|
180
|
+
OP_RETURN: 106,
|
|
181
|
+
|
|
182
|
+
// stack ops
|
|
183
|
+
OP_TOALTSTACK: 107,
|
|
184
|
+
OP_FROMALTSTACK: 108,
|
|
185
|
+
OP_2DROP: 109,
|
|
186
|
+
OP_2DUP: 110,
|
|
187
|
+
OP_3DUP: 111,
|
|
188
|
+
OP_2OVER: 112,
|
|
189
|
+
OP_2ROT: 113,
|
|
190
|
+
OP_2SWAP: 114,
|
|
191
|
+
OP_IFDUP: 115,
|
|
192
|
+
OP_DEPTH: 116,
|
|
193
|
+
OP_DROP: 117,
|
|
194
|
+
OP_DUP: 118,
|
|
195
|
+
OP_NIP: 119,
|
|
196
|
+
OP_OVER: 120,
|
|
197
|
+
OP_PICK: 121,
|
|
198
|
+
OP_ROLL: 122,
|
|
199
|
+
OP_ROT: 123,
|
|
200
|
+
OP_SWAP: 124,
|
|
201
|
+
OP_TUCK: 125,
|
|
202
|
+
|
|
203
|
+
// splice ops
|
|
204
|
+
OP_CAT: 126,
|
|
205
|
+
OP_SPLIT: 127,
|
|
206
|
+
OP_NUM2BIN: 128,
|
|
207
|
+
OP_BIN2NUM: 129,
|
|
208
|
+
OP_SIZE: 130,
|
|
209
|
+
|
|
210
|
+
// bit logic
|
|
211
|
+
OP_INVERT: 131,
|
|
212
|
+
OP_AND: 132,
|
|
213
|
+
OP_OR: 133,
|
|
214
|
+
OP_XOR: 134,
|
|
215
|
+
OP_EQUAL: 135,
|
|
216
|
+
OP_EQUALVERIFY: 136,
|
|
217
|
+
OP_RESERVED1: 137,
|
|
218
|
+
OP_RESERVED2: 138,
|
|
219
|
+
|
|
220
|
+
// numeric
|
|
221
|
+
OP_1ADD: 139,
|
|
222
|
+
OP_1SUB: 140,
|
|
223
|
+
OP_2MUL: 141,
|
|
224
|
+
OP_2DIV: 142,
|
|
225
|
+
OP_NEGATE: 143,
|
|
226
|
+
OP_ABS: 144,
|
|
227
|
+
OP_NOT: 145,
|
|
228
|
+
OP_0NOTEQUAL: 146,
|
|
229
|
+
|
|
230
|
+
OP_ADD: 147,
|
|
231
|
+
OP_SUB: 148,
|
|
232
|
+
OP_MUL: 149,
|
|
233
|
+
OP_DIV: 150,
|
|
234
|
+
OP_MOD: 151,
|
|
235
|
+
OP_LSHIFT: 152,
|
|
236
|
+
OP_RSHIFT: 153,
|
|
237
|
+
|
|
238
|
+
OP_BOOLAND: 154,
|
|
239
|
+
OP_BOOLOR: 155,
|
|
240
|
+
OP_NUMEQUAL: 156,
|
|
241
|
+
OP_NUMEQUALVERIFY: 157,
|
|
242
|
+
OP_NUMNOTEQUAL: 158,
|
|
243
|
+
OP_LESSTHAN: 159,
|
|
244
|
+
OP_GREATERTHAN: 160,
|
|
245
|
+
OP_LESSTHANOREQUAL: 161,
|
|
246
|
+
OP_GREATERTHANOREQUAL: 162,
|
|
247
|
+
OP_MIN: 163,
|
|
248
|
+
OP_MAX: 164,
|
|
249
|
+
|
|
250
|
+
OP_WITHIN: 165,
|
|
251
|
+
|
|
252
|
+
// crypto
|
|
253
|
+
OP_RIPEMD160: 166,
|
|
254
|
+
OP_SHA1: 167,
|
|
255
|
+
OP_SHA256: 168,
|
|
256
|
+
OP_HASH160: 169,
|
|
257
|
+
OP_HASH256: 170,
|
|
258
|
+
OP_CODESEPARATOR: 171,
|
|
259
|
+
OP_CHECKSIG: 172,
|
|
260
|
+
OP_CHECKSIGVERIFY: 173,
|
|
261
|
+
OP_CHECKMULTISIG: 174,
|
|
262
|
+
OP_CHECKMULTISIGVERIFY: 175,
|
|
263
|
+
|
|
264
|
+
OP_CHECKLOCKTIMEVERIFY: 177,
|
|
265
|
+
OP_CHECKSEQUENCEVERIFY: 178,
|
|
266
|
+
|
|
267
|
+
// expansion
|
|
268
|
+
OP_NOP1: 176,
|
|
269
|
+
OP_NOP2: 177,
|
|
270
|
+
OP_NOP3: 178,
|
|
271
|
+
OP_NOP4: 179,
|
|
272
|
+
OP_NOP5: 180,
|
|
273
|
+
OP_NOP6: 181,
|
|
274
|
+
OP_NOP7: 182,
|
|
275
|
+
OP_NOP8: 183,
|
|
276
|
+
OP_NOP9: 184,
|
|
277
|
+
OP_NOP10: 185,
|
|
278
|
+
|
|
279
|
+
// template matching params
|
|
280
|
+
OP_PUBKEYHASH: 253,
|
|
281
|
+
OP_PUBKEY: 254,
|
|
282
|
+
OP_INVALIDOPCODE: 255,
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Reverse mapping array for opcode lookup.
|
|
287
|
+
*/
|
|
288
|
+
Opcode.reverseMap = [];
|
|
289
|
+
|
|
290
|
+
for (var k in Opcode.map) {
|
|
291
|
+
Opcode.reverseMap[Opcode.map[k]] = k;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Easier access to opcodes
|
|
295
|
+
_.extend(Opcode, Opcode.map);
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Checks if the given opcode is a small integer opcode (OP_0 to OP_16).
|
|
300
|
+
* @param {number|Opcode} opcode - The opcode to check, either as a number or Opcode instance.
|
|
301
|
+
* @returns {boolean} True if the opcode is a small integer opcode, false otherwise.
|
|
302
|
+
*/
|
|
303
|
+
Opcode.isSmallIntOp = function (opcode) {
|
|
304
|
+
if (opcode instanceof Opcode) {
|
|
305
|
+
opcode = opcode.toNumber();
|
|
306
|
+
}
|
|
307
|
+
return opcode === Opcode.map.OP_0 || (opcode >= Opcode.map.OP_1 && opcode <= Opcode.map.OP_16);
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Will return a string formatted for the console
|
|
312
|
+
*
|
|
313
|
+
* @returns {string} Script opcode
|
|
314
|
+
*/
|
|
315
|
+
Opcode.prototype.inspect = function () {
|
|
316
|
+
return '<Opcode: ' + this.toString() + ', hex: ' + this.toHex() + ', decimal: ' + this.num + '>';
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
export default Opcode;
|