smartledger-bsv 3.0.0

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