@opcat-labs/opcat 1.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 (138) hide show
  1. package/.mocharc.yaml +3 -0
  2. package/index.d.ts +1541 -0
  3. package/index.js +74 -0
  4. package/lib/address.js +478 -0
  5. package/lib/block/block.js +277 -0
  6. package/lib/block/blockheader.js +295 -0
  7. package/lib/block/index.js +4 -0
  8. package/lib/block/merkleblock.js +323 -0
  9. package/lib/bn.js +3423 -0
  10. package/lib/crypto/bn.js +278 -0
  11. package/lib/crypto/ecdsa.js +339 -0
  12. package/lib/crypto/hash.browser.js +171 -0
  13. package/lib/crypto/hash.js +2 -0
  14. package/lib/crypto/hash.node.js +171 -0
  15. package/lib/crypto/point.js +221 -0
  16. package/lib/crypto/random.browser.js +28 -0
  17. package/lib/crypto/random.js +2 -0
  18. package/lib/crypto/random.node.js +11 -0
  19. package/lib/crypto/signature.js +325 -0
  20. package/lib/encoding/base58.js +111 -0
  21. package/lib/encoding/base58check.js +121 -0
  22. package/lib/encoding/bufferreader.js +212 -0
  23. package/lib/encoding/bufferwriter.js +140 -0
  24. package/lib/encoding/decode-asm.js +24 -0
  25. package/lib/encoding/decode-hex.js +32 -0
  26. package/lib/encoding/decode-script-chunks.js +43 -0
  27. package/lib/encoding/encode-hex.js +284 -0
  28. package/lib/encoding/is-hex.js +7 -0
  29. package/lib/encoding/varint.js +75 -0
  30. package/lib/errors/index.js +54 -0
  31. package/lib/errors/spec.js +314 -0
  32. package/lib/hash-cache.js +50 -0
  33. package/lib/hdprivatekey.js +678 -0
  34. package/lib/hdpublickey.js +525 -0
  35. package/lib/message/message.js +191 -0
  36. package/lib/mnemonic/mnemonic.js +303 -0
  37. package/lib/mnemonic/pbkdf2.browser.js +68 -0
  38. package/lib/mnemonic/pbkdf2.js +2 -0
  39. package/lib/mnemonic/pbkdf2.node.js +68 -0
  40. package/lib/mnemonic/words/chinese.js +2054 -0
  41. package/lib/mnemonic/words/english.js +2054 -0
  42. package/lib/mnemonic/words/french.js +2054 -0
  43. package/lib/mnemonic/words/index.js +8 -0
  44. package/lib/mnemonic/words/italian.js +2054 -0
  45. package/lib/mnemonic/words/japanese.js +2054 -0
  46. package/lib/mnemonic/words/spanish.js +2054 -0
  47. package/lib/networks.js +379 -0
  48. package/lib/opcode.js +255 -0
  49. package/lib/privatekey.js +374 -0
  50. package/lib/publickey.js +386 -0
  51. package/lib/script/index.js +5 -0
  52. package/lib/script/interpreter.js +1834 -0
  53. package/lib/script/script.js +1074 -0
  54. package/lib/script/stack.js +109 -0
  55. package/lib/script/write-i32-le.js +17 -0
  56. package/lib/script/write-push-data.js +35 -0
  57. package/lib/script/write-u16-le.js +12 -0
  58. package/lib/script/write-u32-le.js +16 -0
  59. package/lib/script/write-u64-le.js +24 -0
  60. package/lib/script/write-u8-le.js +8 -0
  61. package/lib/script/write-varint.js +46 -0
  62. package/lib/transaction/index.js +7 -0
  63. package/lib/transaction/input/index.js +5 -0
  64. package/lib/transaction/input/input.js +354 -0
  65. package/lib/transaction/input/multisig.js +242 -0
  66. package/lib/transaction/input/publickey.js +100 -0
  67. package/lib/transaction/input/publickeyhash.js +118 -0
  68. package/lib/transaction/output.js +231 -0
  69. package/lib/transaction/sighash.js +167 -0
  70. package/lib/transaction/signature.js +97 -0
  71. package/lib/transaction/transaction.js +1639 -0
  72. package/lib/transaction/unspentoutput.js +113 -0
  73. package/lib/util/_.js +47 -0
  74. package/lib/util/js.js +90 -0
  75. package/lib/util/preconditions.js +33 -0
  76. package/package.json +26 -0
  77. package/test/address.js +509 -0
  78. package/test/block/block.js +251 -0
  79. package/test/block/blockheader.js +275 -0
  80. package/test/block/merklebloack.js +211 -0
  81. package/test/crypto/bn.js +177 -0
  82. package/test/crypto/ecdsa.js +391 -0
  83. package/test/crypto/hash.browser.js +135 -0
  84. package/test/crypto/hash.js +136 -0
  85. package/test/crypto/point.js +224 -0
  86. package/test/crypto/random.js +32 -0
  87. package/test/crypto/signature.js +409 -0
  88. package/test/data/bip69.json +215 -0
  89. package/test/data/bitcoind/base58_keys_invalid.json +52 -0
  90. package/test/data/bitcoind/base58_keys_valid.json +335 -0
  91. package/test/data/bitcoind/blocks.json +22 -0
  92. package/test/data/bitcoind/script_tests.json +3822 -0
  93. package/test/data/bitcoind/sig_canonical.json +7 -0
  94. package/test/data/bitcoind/sig_noncanonical.json +36 -0
  95. package/test/data/bitcoind/tx_invalid.json +445 -0
  96. package/test/data/bitcoind/tx_valid.json +44 -0
  97. package/test/data/blk86756-testnet.dat +0 -0
  98. package/test/data/blk86756-testnet.js +14 -0
  99. package/test/data/blk86756-testnet.json +684 -0
  100. package/test/data/block.hex +1 -0
  101. package/test/data/ecdsa.json +230 -0
  102. package/test/data/merkleblocks.js +488 -0
  103. package/test/data/messages.json +22 -0
  104. package/test/data/sighash.json +12 -0
  105. package/test/data/tx_creation.json +95 -0
  106. package/test/encoding/base58.js +131 -0
  107. package/test/encoding/base58check.js +136 -0
  108. package/test/encoding/bufferreader.js +337 -0
  109. package/test/encoding/bufferwriter.js +172 -0
  110. package/test/encoding/varint.js +104 -0
  111. package/test/hashCache.js +67 -0
  112. package/test/hdkeys.js +445 -0
  113. package/test/hdprivatekey.js +332 -0
  114. package/test/hdpublickey.js +304 -0
  115. package/test/index.js +16 -0
  116. package/test/message/message.js +204 -0
  117. package/test/mnemonic/data/fixtures.json +300 -0
  118. package/test/mnemonic/mnemonic.js +259 -0
  119. package/test/mnemonic/mocha.opts +1 -0
  120. package/test/mnemonic/pbkdf2.test.js +59 -0
  121. package/test/networks.js +159 -0
  122. package/test/opcode.js +161 -0
  123. package/test/privatekey.js +439 -0
  124. package/test/publickey.js +554 -0
  125. package/test/script/interpreter.js +734 -0
  126. package/test/script/script.js +1437 -0
  127. package/test/transaction/deserialize.js +34 -0
  128. package/test/transaction/input/input.js +90 -0
  129. package/test/transaction/input/multisig.js +90 -0
  130. package/test/transaction/input/publickey.js +68 -0
  131. package/test/transaction/input/publickeyhash.js +51 -0
  132. package/test/transaction/output.js +185 -0
  133. package/test/transaction/sighash.js +65 -0
  134. package/test/transaction/signature.js +114 -0
  135. package/test/transaction/transaction.js +1109 -0
  136. package/test/transaction/unspentoutput.js +110 -0
  137. package/test/util/js.js +76 -0
  138. package/test/util/preconditions.js +79 -0
package/index.d.ts ADDED
@@ -0,0 +1,1541 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable @typescript-eslint/ban-types */
3
+ // Type definitions for bsv 1.5.6
4
+ // Project: https://github.com/moneybutton/bsv
5
+ // Forked From: https://github.com/bitpay/bitcore-lib
6
+ // Definitions by: Lautaro Dragan <https://github.com/lautarodragan>
7
+ // Definitions extended by: David Case <https://github.com/shruggr>
8
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9
+
10
+ // TypeScript Version: 3.0
11
+
12
+ /// <reference types="node" />
13
+
14
+ declare module '@opcat-labs/opcat' {
15
+ /**
16
+ * Opcode class, representing opcodes used in Bitcoin Script
17
+ * @constructor
18
+ * @param {number} op_code
19
+ * @class
20
+ */
21
+ class Opcode {
22
+ /**
23
+ * An empty array of bytes is pushed onto the stack. (This is not a no-op: an item is added to the stack.)
24
+ * @opcode {`0`}
25
+ * @hex {`0x00`}
26
+ * @input Nothing
27
+ * @output empty
28
+ * @static
29
+ */
30
+ static OP_0: number;
31
+ /**
32
+ * The next byte contains the number of bytes to be pushed onto the stack.
33
+ * @opcode {`76`}
34
+ * @hex {`0x4c`}
35
+ * @input special
36
+ * @output data
37
+ * @static
38
+ */
39
+ static OP_PUSHDATA1: number;
40
+ /**
41
+ * The next two bytes contain the number of bytes to be pushed onto the stack in little endian order.
42
+ * @opcode {`77`}
43
+ * @hex {`0x4d`}
44
+ * @input special
45
+ * @output data
46
+ * @static
47
+ */
48
+ static OP_PUSHDATA2: number;
49
+ /**
50
+ * The next four bytes contain the number of bytes to be pushed onto the stack in little endian order.
51
+ * @opcode {`78`}
52
+ * @hex {`0x4e`}
53
+ * @input special
54
+ * @output data
55
+ * @static
56
+ */
57
+ static OP_PUSHDATA4: number;
58
+ /**
59
+ * The number -1 is pushed onto the stack.
60
+ * @opcode {`79`}
61
+ * @hex {`0x4f`}
62
+ * @input Nothing
63
+ * @output `-1`
64
+ * @static
65
+ */
66
+ static OP_1NEGATE: number;
67
+ /**
68
+ * Reserved words, Using an unassigned opcode makes the transaction invalid.
69
+ * @opcode {`80`}
70
+ * @hex {`0x50`}
71
+ * @input Nothing
72
+ * @output Nothing
73
+ * @static
74
+ */
75
+ static OP_RESERVED: number;
76
+ /**
77
+ * The number 1 is pushed onto the stack.
78
+ * @opcode {`81`}
79
+ * @hex {`0x51`}
80
+ * @input Nothing
81
+ * @output `1`
82
+ * @static
83
+ */
84
+ static OP_TRUE: number;
85
+ /**
86
+ * The number 1 is pushed onto the stack.
87
+ * @opcode {`81`}
88
+ * @hex {`0x51`}
89
+ * @input Nothing
90
+ * @output `1`
91
+ * @static
92
+ */
93
+ static OP_1: number;
94
+ /**
95
+ * The number in the word name 2 is pushed onto the stack.
96
+ * @opcode {`82`}
97
+ * @hex {`0x52`}
98
+ * @input Nothing
99
+ * @output `2`
100
+ * @static
101
+ */
102
+ static OP_2: number;
103
+ /**
104
+ * The number in the word name 3 is pushed onto the stack.
105
+ * @opcode {`83`}
106
+ * @hex {`0x53`}
107
+ * @input Nothing
108
+ * @output `3`
109
+ * @static
110
+ */
111
+ static OP_3: number;
112
+ /**
113
+ * The number in the word name 4 is pushed onto the stack.
114
+ * @opcode {`84`}
115
+ * @hex {`0x54`}
116
+ * @input Nothing
117
+ * @output `4`
118
+ * @static
119
+ */
120
+ static OP_4: number;
121
+ /**
122
+ * The number in the word name 5 is pushed onto the stack.
123
+ * @opcode {`85`}
124
+ * @hex {`0x55`}
125
+ * @input Nothing
126
+ * @output `5`
127
+ * @static
128
+ */
129
+ static OP_5: number;
130
+ /**
131
+ * The number in the word name 6 is pushed onto the stack.
132
+ * @opcode {`86`}
133
+ * @hex {`0x56`}
134
+ * @input Nothing
135
+ * @output `6`
136
+ * @static
137
+ */
138
+ static OP_6: number;
139
+ /**
140
+ * The number in the word name 7 is pushed onto the stack.
141
+ * @opcode {`87`}
142
+ * @hex {`0x57`}
143
+ * @input Nothing
144
+ * @output `7`
145
+ * @static
146
+ */
147
+ static OP_7: number;
148
+ /**
149
+ * The number in the word name 8 is pushed onto the stack.
150
+ * @opcode {`88`}
151
+ * @hex {`0x58`}
152
+ * @input Nothing
153
+ * @output `8`
154
+ * @static
155
+ */
156
+ static OP_8: number;
157
+ /**
158
+ * The number in the word name 9 is pushed onto the stack.
159
+ * @opcode {`89`}
160
+ * @hex {`0x59`}
161
+ * @input Nothing
162
+ * @output `9`
163
+ * @static
164
+ */
165
+ static OP_9: number;
166
+ /**
167
+ * The number in the word name 10 is pushed onto the stack.
168
+ * @opcode {`90`}
169
+ * @hex {`0x5a`}
170
+ * @input Nothing
171
+ * @output `10`
172
+ * @static
173
+ */
174
+ static OP_10: number;
175
+ /**
176
+ * The number in the word name 11 is pushed onto the stack.
177
+ * @opcode {`91`}
178
+ * @hex {`0x5b`}
179
+ * @input Nothing
180
+ * @output `11`
181
+ * @static
182
+ */
183
+ static OP_11: number;
184
+ /**
185
+ * The number in the word name 12 is pushed onto the stack.
186
+ * @opcode {`92`}
187
+ * @hex {`0x5c`}
188
+ * @input Nothing
189
+ * @output `12`
190
+ * @static
191
+ */
192
+ static OP_12: number;
193
+ /**
194
+ * The number in the word name 13 is pushed onto the stack.
195
+ * @opcode {`93`}
196
+ * @hex {`0x5d`}
197
+ * @input Nothing
198
+ * @output `13`
199
+ * @static
200
+ */
201
+ static OP_13: number;
202
+ /**
203
+ * The number in the word name 14 is pushed onto the stack.
204
+ * @opcode {`94`}
205
+ * @hex {`0x5e`}
206
+ * @input Nothing
207
+ * @output `14`
208
+ * @static
209
+ */
210
+ static OP_14: number;
211
+ /**
212
+ * The number in the word name 15 is pushed onto the stack.
213
+ * @opcode {`95`}
214
+ * @hex {`0x5f`}
215
+ * @input Nothing
216
+ * @output `15`
217
+ * @static
218
+ */
219
+ static OP_15: number;
220
+ /**
221
+ * The number in the word name 16 is pushed onto the stack.
222
+ * @opcode {`96`}
223
+ * @hex {`0x60`}
224
+ * @input Nothing
225
+ * @output `16`
226
+ * @static
227
+ */
228
+ static OP_16: number;
229
+
230
+ /**
231
+ * Does nothing.
232
+ * @opcode {`97`}
233
+ * @hex {`0x61`}
234
+ * @input Nothing
235
+ * @output Nothing
236
+ * @static
237
+ */
238
+ static OP_NOP: number;
239
+
240
+ /**
241
+ * DISABLED.Puts the version of the protocol under which this transaction will be evaluated onto the stack.
242
+ * @opcode {`99`}
243
+ * @hex {`0x62`}
244
+ * @input Nothing
245
+ * @output Protocol version
246
+ * @static
247
+ */
248
+ static OP_VER: number;
249
+ /**
250
+ * If the top stack value is TRUE, statement 1 is executed.
251
+ * If the top stack value is FALSE and ELSE is used, statement 2 is executed. If ELSE is NOT used, the script jumps to ENDIF.
252
+ * The top stack value is removed.
253
+ * @opcode {`99`}
254
+ * @hex {`0x63`}
255
+ * @example
256
+ * `[expression] IF
257
+ * [statement 1]
258
+ * ENDIF`
259
+ * OR
260
+ * `[expression] IF
261
+ * [statement 1]
262
+ * ELSE
263
+ * [statement 2]
264
+ * ENDIF`
265
+ * @static
266
+ */
267
+ static OP_IF: number;
268
+ /**
269
+ * If the top stack value is FALSE, statement 1 is executed.
270
+ * If the top stack value is TRUE and ELSE is used, statement 2 is executed. If ELSE is NOT used, the script jumps to ENDIF.
271
+ * The top stack value is removed.
272
+ * @opcode {`100`}
273
+ * @hex {`0x64`}
274
+ * @example
275
+ * `[expression] NOTIF
276
+ * [statement 1]
277
+ * ENDIF`
278
+ * OR
279
+ * `[expression] NOTIF
280
+ * [statement 1]
281
+ * ELSE
282
+ * [statement 2]
283
+ * ENDIF`
284
+ * @static
285
+ */
286
+ static OP_NOTIF: number;
287
+ /**
288
+ * DISABLED
289
+ * @opcode {`101`}
290
+ * @hex {`0x65`}
291
+ * @static
292
+ */
293
+ static OP_VERIF: number;
294
+ /**
295
+ * DISABLED
296
+ * @opcode {`102`}
297
+ * @hex {`0x66`}
298
+ * @static
299
+ */
300
+ static OP_VERNOTIF: number;
301
+ /**
302
+ * If the preceding IF or NOTIF check was not valid then statement 2 is executed.
303
+ * @opcode {`103`}
304
+ * @hex {`0x67`}
305
+ * @example
306
+ * `[expression] IF
307
+ * [statement 1]
308
+ * ELSE
309
+ * [statement 2]
310
+ * ENDIF`
311
+ * @static
312
+ */
313
+ static OP_ELSE: number;
314
+ /**
315
+ * Ends an if/else block. All blocks must end, or the transaction is invalid. An OP_ENDIF without a prior matching OP_IF or OP_NOTIF is also invalid.
316
+ * @opcode {`104`}
317
+ * @hex {`0x68`}
318
+ * @example
319
+ * `[expression] IF
320
+ * [statement 1]
321
+ * ELSE
322
+ * [statement 2]
323
+ * ENDIF`
324
+ * @static
325
+ */
326
+ static OP_ENDIF: number;
327
+ /**
328
+ * Marks transaction as invalid if top stack value is not true. The top stack value is removed.
329
+ * @opcode {`105`}
330
+ * @hex {`0x69`}
331
+ * @input True / false
332
+ * @output Nothing / fail
333
+ * @static
334
+ */
335
+ static OP_VERIFY: number;
336
+ /**
337
+ * OP_RETURN can also be used to create "False Return" outputs with a scriptPubKey consisting of OP_FALSE OP_RETURN followed by data.
338
+ * Such outputs are provably unspendable and should be given a value of zero Satoshis. These outputs can be pruned from storage
339
+ * in the UTXO set, reducing its size. After the Genesis upgrade in 2020 miners will be free to mine transactions
340
+ * containing FALSE RETURN outputs of any size.
341
+ * @opcode {`106`}
342
+ * @hex {`0x6a`}
343
+ * @input Nothing
344
+ * @output Ends script with top value on stack as final result
345
+ * @static
346
+ */
347
+ static OP_RETURN: number;
348
+
349
+ // stack ops
350
+
351
+ /**
352
+ * Puts the input onto the top of the alt stack. Removes it from the main stack.
353
+ * @opcode {`107`}
354
+ * @hex {`0x6b`}
355
+ * @input x1
356
+ * @output (alt)x1
357
+ * @static
358
+ */
359
+ static OP_TOALTSTACK: number;
360
+ /**
361
+ * Puts the input onto the top of the main stack. Removes it from the alt stack.
362
+ * @opcode {`108`}
363
+ * @hex {`0x6c`}
364
+ * @input (alt)x1
365
+ * @output x1
366
+ * @static
367
+ */
368
+ static OP_FROMALTSTACK: number;
369
+ /**
370
+ * Removes the top two stack items.
371
+ * @opcode {`109`}
372
+ * @hex {`0x6d`}
373
+ * @input x1 x2
374
+ * @output Nothing
375
+ * @static
376
+ */
377
+ static OP_2DROP: number;
378
+ /**
379
+ * Duplicates the top two stack items.
380
+ * @opcode {`110`}
381
+ * @hex {`0x6e`}
382
+ * @input x1 x2
383
+ * @output x1 x2 x1 x2
384
+ * @static
385
+ */
386
+ static OP_2DUP: number;
387
+ /**
388
+ * Duplicates the top three stack items.
389
+ * @opcode {`111`}
390
+ * @hex {`0x6f`}
391
+ * @input x1 x2 x3
392
+ * @output x1 x2 x3 x1 x2 x3
393
+ * @static
394
+ */
395
+ static OP_3DUP: number;
396
+ /**
397
+ * Copies the pair of items two spaces back in the stack to the front.
398
+ * @opcode {`112`}
399
+ * @hex {`0x70`}
400
+ * @input x1 x2 x3 x4
401
+ * @output x1 x2 x3 x4 x1 x2
402
+ * @static
403
+ */
404
+ static OP_2OVER: number;
405
+ /**
406
+ * The fifth and sixth items back are moved to the top of the stack.
407
+ * @opcode {`113`}
408
+ * @hex {`0x71`}
409
+ * @input x1 x2 x3 x4 x5 x6
410
+ * @output x3 x4 x5 x6 x1 x2
411
+ * @static
412
+ */
413
+ static OP_2ROT: number;
414
+ /**
415
+ * Swaps the top two pairs of items.
416
+ * @opcode {`114`}
417
+ * @hex {`0x72`}
418
+ * @input x1 x2 x3 x4
419
+ * @output x3 x4 x1 x2
420
+ * @static
421
+ */
422
+ static OP_2SWAP: number;
423
+ /**
424
+ * If the top stack value is not 0, duplicate it.
425
+ * @opcode {`115`}
426
+ * @hex {`0x73`}
427
+ * @input x
428
+ * @output x / x x
429
+ * @static
430
+ */
431
+ static OP_IFDUP: number;
432
+ /**
433
+ * Counts the number of stack items onto the stack and places the value on the top
434
+ * @opcode {`116`}
435
+ * @hex {`0x74`}
436
+ * @input Nothing
437
+ * @output Stack size
438
+ * @static
439
+ */
440
+ static OP_DEPTH: number;
441
+ /**
442
+ * Removes the top stack item.
443
+ * @opcode {`117`}
444
+ * @hex {`0x75`}
445
+ * @input x
446
+ * @output Nothing
447
+ * @static
448
+ */
449
+ static OP_DROP: number;
450
+ /**
451
+ * Removes the top stack item.
452
+ * @opcode {`118`}
453
+ * @hex {`0x76`}
454
+ * @input x
455
+ * @output x x
456
+ * @static
457
+ */
458
+ static OP_DUP: number;
459
+ /**
460
+ * Removes the second-to-top stack item.
461
+ * @opcode {`119`}
462
+ * @hex {`0x77`}
463
+ * @input x1 x2
464
+ * @output x2
465
+ * @static
466
+ */
467
+ static OP_NIP: number;
468
+ /**
469
+ * Copies the second-to-top stack item to the top.
470
+ * @opcode {`120`}
471
+ * @hex {`0x78`}
472
+ * @input x1 x2
473
+ * @output x1 x2 x1
474
+ * @static
475
+ */
476
+ static OP_OVER: number;
477
+ /**
478
+ * The item `n` back in the stack is copied to the top.
479
+ * @opcode {`121`}
480
+ * @hex {`0x79`}
481
+ * @input xn ... x2 x1 x0 {n}
482
+ * @output xn ... x2 x1 x0 xn
483
+ * @static
484
+ */
485
+ static OP_PICK: number;
486
+ /**
487
+ * The item `n` back in the stack is copied to the top.
488
+ * @opcode {`122`}
489
+ * @hex {`0x7a`}
490
+ * @input xn ... x2 x1 x0 {n}
491
+ * @output ... x2 x1 x0 xn
492
+ * @static
493
+ */
494
+ static OP_ROLL: number;
495
+ /**
496
+ * The top three items on the stack are rotated to the left.
497
+ * @opcode {`123`}
498
+ * @hex {`0x7b`}
499
+ * @input x1 x2 x3
500
+ * @output x2 x3 x1
501
+ * @static
502
+ */
503
+ static OP_ROT: number;
504
+ /**
505
+ * The top two items on the stack are swapped.
506
+ * @opcode {`124`}
507
+ * @hex {`0x7c`}
508
+ * @input x1 x2
509
+ * @output x2 x1
510
+ * @static
511
+ */
512
+ static OP_SWAP: number;
513
+ /**
514
+ * The item at the top of the stack is copied and inserted before the second-to-top item.
515
+ * @opcode {`125`}
516
+ * @hex {`0x7d`}
517
+ * @input x1 x2
518
+ * @output x2 x1 x2
519
+ * @static
520
+ */
521
+ static OP_TUCK: number;
522
+
523
+ // splice ops
524
+ static OP_CAT: number;
525
+ static OP_SPLIT: number;
526
+ static OP_NUM2BIN: number;
527
+ static OP_BIN2NUM: number;
528
+ static OP_SIZE: number;
529
+
530
+ // bit logic
531
+ static OP_INVERT: number;
532
+ static OP_AND: number;
533
+ static OP_OR: number;
534
+ static OP_XOR: number;
535
+ static OP_EQUAL: number;
536
+ static OP_EQUALVERIFY: number;
537
+ static OP_RESERVED1: number;
538
+ static OP_RESERVED2: number;
539
+
540
+ // numeric
541
+ static OP_1ADD: number;
542
+ static OP_1SUB: number;
543
+ static OP_2MUL: number;
544
+ static OP_2DIV: number;
545
+ static OP_NEGATE: number;
546
+ static OP_ABS: number;
547
+ static OP_NOT: number;
548
+ static OP_0NOTEQUAL: number;
549
+
550
+ static OP_ADD: number;
551
+ static OP_SUB: number;
552
+ static OP_MUL: number;
553
+ static OP_DIV: number;
554
+ static OP_MOD: number;
555
+ static OP_LSHIFT: number;
556
+ static OP_RSHIFT: number;
557
+
558
+ static OP_BOOLAND: number;
559
+ static OP_BOOLOR: number;
560
+ static OP_NUMEQUAL: number;
561
+ static OP_NUMEQUALVERIFY: number;
562
+ static OP_NUMNOTEQUAL: number;
563
+ static OP_LESSTHAN: number;
564
+ static OP_GREATERTHAN: number;
565
+ static OP_LESSTHANOREQUAL: number;
566
+ static OP_GREATERTHANOREQUAL: number;
567
+ static OP_MIN: number;
568
+ static OP_MAX: number;
569
+
570
+ static OP_WITHIN: number;
571
+
572
+ // crypto
573
+ static OP_RIPEMD160: number;
574
+ static OP_SHA1: number;
575
+ static OP_SHA256: number;
576
+ static OP_HASH160: number;
577
+ static OP_HASH256: number;
578
+ static OP_CODESEPARATOR: number;
579
+ static OP_CHECKSIG: number;
580
+ static OP_CHECKSIGVERIFY: number;
581
+ static OP_CHECKMULTISIG: number;
582
+ static OP_CHECKMULTISIGVERIFY: number;
583
+
584
+ static OP_CHECKLOCKTIMEVERIFY: number;
585
+ static OP_CHECKSEQUENCEVERIFY: number;
586
+
587
+ // expansion
588
+ static OP_NOP1: number;
589
+ static OP_NOP2: number;
590
+ static OP_NOP3: number;
591
+ static OP_NOP4: number;
592
+ static OP_NOP5: number;
593
+ static OP_NOP6: number;
594
+ static OP_NOP7: number;
595
+ static OP_NOP8: number;
596
+ static OP_NOP9: number;
597
+ static OP_NOP10: number;
598
+
599
+ // template matching params
600
+ static OP_PUBKEYHASH: number;
601
+ static OP_PUBKEY: number;
602
+ static OP_INVALIDOPCODE: number;
603
+
604
+ constructor(op_code: number);
605
+ }
606
+
607
+ export namespace encoding {
608
+ class Base58 { }
609
+ class Base58Check { }
610
+ class BufferReader {
611
+ constructor(buf: Buffer);
612
+ read(len: number): Buffer;
613
+ readUInt8(): number;
614
+ readUInt16BE(): number;
615
+ readUInt16LE(): number;
616
+ readUInt32BE(): number;
617
+ readUInt32LE(): number;
618
+ readInt32LE(): number;
619
+ readUInt64BEBN(): number;
620
+ readUInt64LEBN(): number;
621
+ readVarintNum(): number;
622
+ readVarLengthBuffer(): Buffer;
623
+ readVarintBuf(): Buffer;
624
+ readVarintBN(): crypto.BN;
625
+ reverse(): this;
626
+ readReverse(len?: number): Buffer;
627
+ readAll(): Buffer;
628
+ eof(): boolean;
629
+ remaining(): number;
630
+ pos: number;
631
+ }
632
+ class BufferWriter {
633
+ write(buf: Buffer): this;
634
+ writeUInt8(n: number): this;
635
+ writeUInt16BE(n: number): this;
636
+ writeUInt16LE(n: number): this;
637
+ writeUInt32BE(n: number): this;
638
+ writeUInt32LE(n: number): this;
639
+ writeInt32LE(n: number): this;
640
+ writeUInt64BEBN(n: number): this;
641
+ writeUInt64LEBN(n: number): this;
642
+ writeVarintNum(n: number): this;
643
+ writeVarintBN(n: crypto.BN): this;
644
+ writeReverse(buf: Buffer): this;
645
+ toBuffer(): Buffer;
646
+ }
647
+ class Varint { }
648
+ }
649
+
650
+ export namespace crypto {
651
+ interface IOpts {
652
+ endian: 'big' | 'little';
653
+ size?: number;
654
+ }
655
+
656
+ type Endianness = "le" | "be";
657
+
658
+ class BN {
659
+ constructor(
660
+ number: number | bigint | string | number[] | ReadonlyArray<number> | Buffer | BN,
661
+ base?: number,
662
+ endian?: Endianness,
663
+ );
664
+
665
+ static Zero: BN;
666
+ static One: BN;
667
+ static Minus1: BN;
668
+
669
+ clone(): BN;
670
+ toString(base?: number | 'hex', length?: number): string;
671
+ toNumber(): number;
672
+ toJSON(): string;
673
+ toArray(endian?: Endianness, length?: number): number[];
674
+ toBuffer(opts?: IOpts): Buffer;
675
+ bitLength(): number;
676
+ zeroBits(): number;
677
+ byteLength(): number;
678
+ isNeg(): boolean;
679
+ isEven(): boolean;
680
+ isOdd(): boolean;
681
+ isZero(): boolean;
682
+ isBN(): boolean;
683
+ cmp(b: any): number;
684
+ lt(b: any): boolean;
685
+ lte(b: any): boolean;
686
+ gt(b: any): boolean;
687
+ gte(b: any): boolean;
688
+ eq(b: any): boolean;
689
+ eqn(b: any): boolean;
690
+ gten(b: any): boolean;
691
+ lten(b: any): boolean;
692
+ isBN(b: any): boolean;
693
+
694
+ neg(): BN;
695
+ abs(): BN;
696
+ add(b: BN): BN;
697
+ sub(b: BN): BN;
698
+ mul(b: BN): BN;
699
+ sqr(): BN;
700
+ pow(b: BN): BN;
701
+ div(b: BN): BN;
702
+ mod(b: BN): BN;
703
+ divRound(b: BN): BN;
704
+
705
+ or(b: BN): BN;
706
+ and(b: BN): BN;
707
+ xor(b: BN): BN;
708
+ setn(b: number): BN;
709
+ shln(b: number): BN;
710
+ shrn(b: number): BN;
711
+ testn(b: number): boolean;
712
+ maskn(b: number): BN;
713
+ bincn(b: number): BN;
714
+ notn(w: number): BN;
715
+
716
+ gcd(b: BN): BN;
717
+ egcd(b: BN): { a: BN; b: BN; gcd: BN };
718
+ invm(b: BN): BN;
719
+ static fromSM(buf: Buffer, opts?: IOpts): BN;
720
+ neg(): BN;
721
+ add(one: BN): BN;
722
+ toSM(opts?: IOpts): Buffer;
723
+ toNumber(): number;
724
+ static fromBuffer(buf: Buffer, opts?: IOpts): BN;
725
+ static fromNumber(n: number): BN;
726
+ static fromHex(hex: string, opts?: IOpts): BN;
727
+ static fromString(hex: string, base?: number): BN;
728
+ }
729
+
730
+ namespace ECDSA {
731
+ function sign(message: Buffer, key: PrivateKey, endian?: 'little' | 'big'): Signature;
732
+ function verify(
733
+ hashbuf: Buffer,
734
+ sig: Signature,
735
+ pubkey: PublicKey,
736
+ endian?: 'little'
737
+ ): boolean;
738
+ }
739
+
740
+ namespace Hash {
741
+ function sha1(buffer: Buffer): Buffer;
742
+ function sha256(buffer: Buffer): Buffer;
743
+ function sha256sha256(buffer: Buffer): Buffer;
744
+ function sha256ripemd160(buffer: Buffer): Buffer;
745
+ function sha512(buffer: Buffer): Buffer;
746
+ function ripemd160(buffer: Buffer): Buffer;
747
+
748
+ function sha256hmac(data: Buffer, key: Buffer): Buffer;
749
+ function sha512hmac(data: Buffer, key: Buffer): Buffer;
750
+ }
751
+
752
+ namespace Random {
753
+ function getRandomBuffer(size: number): Buffer;
754
+ }
755
+
756
+ class Point {
757
+ static fromX(odd: boolean, x: crypto.BN | string): Point;
758
+ static getG(): any;
759
+ static getN(): crypto.BN;
760
+ getX(): crypto.BN;
761
+ getY(): crypto.BN;
762
+ validate(): this;
763
+ mul(n: crypto.BN): Point;
764
+ }
765
+
766
+ class Signature {
767
+ static fromDER(sig: Buffer): Signature;
768
+ static fromTxFormat(buf: Buffer): Signature;
769
+ static fromString(data: string): Signature;
770
+ static SIGHASH_ALL: number;
771
+ static SIGHASH_NONE: number;
772
+ static SIGHASH_SINGLE: number;
773
+ static SIGHASH_FORKID: number;
774
+ static SIGHASH_ANYONECANPAY: number;
775
+
776
+ static ALL: number;
777
+ static NONE: number;
778
+ static SINGLE: number;
779
+ static ANYONECANPAY_ALL: number;
780
+ static ANYONECANPAY_NONE: number;
781
+ static ANYONECANPAY_SINGLE: number;
782
+
783
+ nhashtype: number;
784
+ toString(): string;
785
+ toBuffer(): Buffer;
786
+ toDER(): Buffer;
787
+ hasDefinedHashtype(): boolean;
788
+ static isTxDER(buf: Buffer): boolean;
789
+ hasLowS(): boolean;
790
+ toTxFormat(): Buffer;
791
+ }
792
+ }
793
+
794
+ export namespace Transaction {
795
+ interface IUnspentOutput {
796
+ address?: string;
797
+ txId: string;
798
+ outputIndex: number;
799
+ script: string;
800
+ satoshis: number;
801
+ data?: Buffer | string;
802
+ }
803
+ class UnspentOutput {
804
+ static fromObject(o: IUnspentOutput): UnspentOutput;
805
+ constructor(data: IUnspentOutput);
806
+ inspect(): string;
807
+ toObject(): IUnspentOutput;
808
+ toString(): string;
809
+ }
810
+
811
+ class Output {
812
+ readonly script: Script;
813
+ satoshis: number;
814
+ readonly satoshisBN: crypto.BN;
815
+ readonly data: Buffer;
816
+ constructor(data: {
817
+ script: Script,
818
+ satoshis: number
819
+ data?: Buffer | string;
820
+ });
821
+
822
+ setScript(script: Script | string | Buffer): this;
823
+ inspect(): string;
824
+ toObject(): { satoshis: number; script: string };
825
+ getSize(): number;
826
+ toBufferWriter(writer?: encoding.BufferWriter): encoding.BufferWriter;
827
+ static fromBufferReader(reader: encoding.BufferReader): Output
828
+ }
829
+
830
+ class Input {
831
+ readonly prevTxId: Buffer;
832
+ readonly outputIndex: number;
833
+ sequenceNumber: number;
834
+ readonly script: Script;
835
+ output?: Output;
836
+ constructor(params: {
837
+ prevTxId: Buffer,
838
+ outputIndex: number,
839
+ sequenceNumber?: number,
840
+ script?: Script,
841
+ output?: Output,
842
+ });
843
+ isValidSignature(tx: Transaction, sig: any): boolean;
844
+ setScript(script: Script): this;
845
+ getSignatures(tx: Transaction, privateKey: PrivateKey, inputIndex: number, sigtype?: number): any;
846
+ getPreimage(tx: Transaction, inputIndex: number, sigtype?: number, isLowS?: boolean, csIdx?: number): Buffer;
847
+ }
848
+
849
+ class Signature {
850
+ constructor(arg: Signature | string | object);
851
+
852
+ signature: crypto.Signature;
853
+ publicKey: PublicKey;
854
+ prevTxId: Buffer;
855
+ outputIndex: number;
856
+ inputIndex: number;
857
+ sigtype: number;
858
+ }
859
+
860
+ namespace Sighash {
861
+ function sighashPreimage(
862
+ transaction: Transaction,
863
+ sighashType: number,
864
+ inputNumber: number,
865
+ subscript: Script,
866
+ satoshisBN: crypto.BN,
867
+ flags?: number,
868
+ hashCache?: HashCache
869
+ ): Buffer;
870
+ function sighash(
871
+ transaction: Transaction,
872
+ sighashType: number,
873
+ inputNumber: number,
874
+ subscript: Script,
875
+ satoshisBN: crypto.BN,
876
+ flags?: number,
877
+ hashCache?: HashCache
878
+ ): Buffer;
879
+ function sign(
880
+ transaction: Transaction,
881
+ privateKey: PrivateKey,
882
+ sighashType: number,
883
+ inputIndex: number,
884
+ subscript: Script,
885
+ satoshisBN: crypto.BN,
886
+ flags?: number,
887
+ hashCache?: HashCache
888
+ ): crypto.Signature;
889
+ function verify(
890
+ transaction: Transaction,
891
+ signature: Signature,
892
+ publicKey: PublicKey,
893
+ inputIndex: number,
894
+ subscript: Script,
895
+ satoshisBN: crypto.BN,
896
+ flags?: number,
897
+ hashCache?: HashCache
898
+ ): boolean;
899
+ }
900
+ }
901
+
902
+ export class Transaction {
903
+ static DUMMY_PRIVATEKEY: PrivateKey;
904
+ inputs: Transaction.Input[];
905
+ outputs: Transaction.Output[];
906
+ readonly id: string;
907
+ readonly hash: string;
908
+ readonly inputAmount: number;
909
+ readonly outputAmount: number;
910
+
911
+ version: number;
912
+ nid: string;
913
+ nLockTime: number;
914
+
915
+ constructor(raw?: string);
916
+
917
+ static fromBuffer(buffer: Buffer): Transaction;
918
+ static fromString(rawTxHex: string): Transaction;
919
+ static fromObject(obj: any): Transaction;
920
+
921
+ from(
922
+ utxos: Transaction.IUnspentOutput | Transaction.IUnspentOutput[]
923
+ ): this;
924
+ fromString(rawTxHex: string): this;
925
+ fromBuffer(buffer: Buffer): this;
926
+ to(address: Address[] | Address | string, amount: number): this;
927
+ change(address: Address | string): this;
928
+ fee(amount: number): this;
929
+ feePerKb(amount: number): this;
930
+ sign(
931
+ privateKey: PrivateKey[] | string[] | PrivateKey | string,
932
+ sigtype?: number
933
+ ): this;
934
+ applySignature(sig: { inputIndex: number, sigtype: number, publicKey: PublicKey, signature: crypto.Signature }): this;
935
+ verifySignature(sig: crypto.Signature, pubkey: PublicKey, nin: number, subscript: Script, satoshisBN: crypto.BN, flags: number): boolean;
936
+ addInput(
937
+ input: Transaction.Input,
938
+ outputScript?: Script | string,
939
+ satoshis?: number,
940
+ data?: Buffer | string
941
+ ): this;
942
+ removeInput(txId: string, outputIndex: number): void;
943
+ addOutput(output: Transaction.Output): this;
944
+ addData(value: Buffer | string): this;
945
+ lockUntilDate(time: Date | number): this;
946
+ lockUntilBlockHeight(height: number): this;
947
+
948
+ toBufferWriter(forTxHash: boolean, writer?: encoding.BufferWriter): encoding.BufferWriter;
949
+
950
+ hashForSignature(inputIndex: number, hashType: number): Buffer;
951
+
952
+ toTxHashPreimage(): Buffer;
953
+
954
+ hasWitnesses(): boolean;
955
+ getFee(): number;
956
+ getChangeOutput(): Transaction.Output | null;
957
+ getChangeAddress(): Address | null;
958
+ getLockTime(): Date | number;
959
+ setLockTime(t: number): this;
960
+
961
+ verify(): string | true;
962
+ isCoinbase(): boolean;
963
+
964
+ enableRBF(): this;
965
+ isRBF(): boolean;
966
+
967
+ inspect(): string;
968
+ serialize(opts?: object): string;
969
+ uncheckedSerialize(): string;
970
+
971
+ toObject(): any;
972
+ toBuffer(): Buffer;
973
+
974
+ isFullySigned(): boolean;
975
+
976
+ getSerializationError(opts?: object): any;
977
+
978
+ getUnspentValue(): number;
979
+ setInputScript(inputIndex: number | {
980
+ inputIndex: number,
981
+ privateKey?: PrivateKey | Array<PrivateKey>,
982
+ sigtype?: number,
983
+ isLowS?: boolean
984
+ }, unlockingScript: Script | ((tx: Transaction, outputInPrevTx: Transaction.Output) => Script)): this;
985
+ setInputScriptAsync(inputIndex: number | {
986
+ inputIndex: number,
987
+ sigtype?: number,
988
+ isLowS?: boolean
989
+ }, callback: (tx: Transaction, outputInPrevTx: Transaction.Output) => Promise<Script>): Promise<this>;
990
+ setInputSequence(inputIndex: number, sequence: number): this;
991
+ setOutput(outputIndex: number, output: Transaction.Output | ((tx: Transaction) => Transaction.Output)): this;
992
+ seal(): this;
993
+ sealAsync(): Promise<this>;
994
+ isSealed(): boolean;
995
+ getChangeAmount(): number;
996
+ getEstimateSize(): number;
997
+ getEstimateFee(): number;
998
+ checkFeeRate(feePerKb?: number): boolean;
999
+ prevouts(): string;
1000
+ getSignature(inputIndex: number, privateKey?: PrivateKey | Array<PrivateKey>, sigtype?: number): string | Array<string>;
1001
+ getPreimage(inputIndex: number, sigtype?: number, isLowS?: boolean, csIdx?: number): string;
1002
+ addInputFromPrevTx(prevTx: Transaction, outputIndex?: number): this;
1003
+ addDummyInput(script: Script, satoshis: number): this;
1004
+ dummyChange(): this;
1005
+ /**
1006
+ * @deprecated please use `verifyScript` instead
1007
+ * @param inputIndex
1008
+ */
1009
+ verifyInputScript(inputIndex: number): {
1010
+ success: boolean,
1011
+ error: string,
1012
+ failedAt: any
1013
+ };
1014
+ verifyScript(inputIndex: number): {
1015
+ success: boolean,
1016
+ error: string,
1017
+ failedAt: any
1018
+ };
1019
+ getInputAmount(inputIndex: number): number;
1020
+ getOutputAmount(outputIndex: number): number;
1021
+
1022
+ clone(): Transaction;
1023
+
1024
+ toHex(): string;
1025
+ }
1026
+
1027
+ export class ECIES {
1028
+ constructor(opts?: any, algorithm?: string);
1029
+
1030
+ privateKey(privateKey: PrivateKey): ECIES;
1031
+ publicKey(publicKey: PublicKey): ECIES;
1032
+ encrypt(message: string | Buffer): Buffer;
1033
+ decrypt(encbuf: Buffer): Buffer;
1034
+ }
1035
+ export class Block {
1036
+ hash: string;
1037
+ height: number;
1038
+ transactions: Transaction[];
1039
+ header: {
1040
+ time: number;
1041
+ prevHash: string;
1042
+ };
1043
+
1044
+ constructor(data: Buffer | object);
1045
+ }
1046
+
1047
+ export class PrivateKey {
1048
+ constructor(key?: string | PrivateKey, network?: Networks.Type);
1049
+
1050
+ readonly bn: crypto.BN;
1051
+
1052
+ readonly publicKey: PublicKey;
1053
+ readonly compressed: boolean;
1054
+ readonly network: Networks.Network;
1055
+
1056
+ toAddress(network?: Networks.Type): Address;
1057
+ toPublicKey(): PublicKey;
1058
+ toString(): string;
1059
+ toObject(): object;
1060
+ toJSON(): object;
1061
+ toWIF(): string;
1062
+ toHex(): string;
1063
+ toBigNumber(): any; //BN;
1064
+ toBuffer(): Buffer;
1065
+ inspect(): string;
1066
+
1067
+ static fromString(str: string): PrivateKey;
1068
+ static fromWIF(str: string): PrivateKey;
1069
+ static fromRandom(netowrk?: string | Networks.Type): PrivateKey;
1070
+ static fromBuffer(buf: Buffer, network: Networks.Type): PrivateKey;
1071
+ static fromHex(hex: string, network: Networks.Type): PrivateKey;
1072
+ static getValidationError(data: string): any | null;
1073
+ static isValid(data: string): boolean;
1074
+ }
1075
+
1076
+ export class PublicKey {
1077
+ constructor(source: string | PublicKey | crypto.Point, extra?: object);
1078
+
1079
+ readonly point: crypto.Point;
1080
+ readonly compressed: boolean;
1081
+ readonly network: Networks.Network;
1082
+
1083
+ toDER(): Buffer;
1084
+ toObject(): object;
1085
+ toBuffer(): Buffer;
1086
+ toAddress(network?: Networks.Type): Address;
1087
+ toString(): string;
1088
+ toHex(): string;
1089
+ inspect(): string;
1090
+
1091
+ static fromPrivateKey(privateKey: PrivateKey): PublicKey;
1092
+ static fromBuffer(buf: Buffer, strict?: boolean): PublicKey;
1093
+ static fromDER(buf: Buffer, strict?: boolean): PublicKey;
1094
+ //static fromPoint(point: Point, compressed: boolean): PublicKey;
1095
+ //static fromX(odd: boolean, x: Point): PublicKey;
1096
+ static fromString(str: string): PublicKey;
1097
+ static fromHex(hex: string): PublicKey;
1098
+ static getValidationError(data: string): any | null;
1099
+ static isValid(data: string): boolean;
1100
+ }
1101
+
1102
+ export class Message {
1103
+ constructor(message: string | Buffer);
1104
+
1105
+ readonly messageBuffer: Buffer;
1106
+
1107
+ sign(privateKey: PrivateKey): string;
1108
+ verify(address: string | Address, signature: string): boolean;
1109
+ toObject(): object;
1110
+ toJSON(): string;
1111
+ toString(): string;
1112
+ inspect(): string;
1113
+
1114
+ static sign(message: string | Buffer, privateKey: PrivateKey): string;
1115
+ static verify(
1116
+ message: string | Buffer,
1117
+ address: string | Address,
1118
+ signature: string
1119
+ ): boolean;
1120
+ static MAGIC_BYTES: Buffer;
1121
+ static magicHash(): string;
1122
+ static fromString(str: string): Message;
1123
+ static fromJSON(json: string): Message;
1124
+ static fromObject(obj: object): Message;
1125
+ }
1126
+
1127
+ export class Mnemonic {
1128
+ constructor(data: string | Array<string>, wordList?: Array<string>);
1129
+
1130
+ readonly wordList: Array<string>;
1131
+ readonly phrase: string;
1132
+
1133
+ toSeed(passphrase?: string): Buffer;
1134
+ toHDPrivateKey(passphrase: string, network: Networks.Type): HDPrivateKey;
1135
+ toString(): string;
1136
+ inspect(): string;
1137
+
1138
+ static fromRandom(wordlist?: Array<string>): Mnemonic;
1139
+ static fromString(mnemonic: string, wordList?: Array<string>): Mnemonic;
1140
+ static isValid(mnemonic: string, wordList?: Array<string>): boolean;
1141
+ static fromSeed(seed: Buffer, wordlist: Array<string>): Mnemonic;
1142
+ }
1143
+
1144
+ export class HDPrivateKey {
1145
+ constructor(data?: string | Buffer | object);
1146
+
1147
+ readonly hdPublicKey: HDPublicKey;
1148
+
1149
+ readonly xprivkey: Buffer;
1150
+ readonly xpubkey: Buffer;
1151
+ readonly network: Networks.Network;
1152
+ readonly depth: number;
1153
+ readonly privateKey: PrivateKey;
1154
+ readonly publicKey: PublicKey;
1155
+ readonly fingerPrint: Buffer;
1156
+
1157
+ derive(arg: string | number, hardened?: boolean): HDPrivateKey;
1158
+ deriveChild(arg: string | number, hardened?: boolean): HDPrivateKey;
1159
+ deriveNonCompliantChild(
1160
+ arg: string | number,
1161
+ hardened?: boolean
1162
+ ): HDPrivateKey;
1163
+
1164
+ toString(): string;
1165
+ toObject(): object;
1166
+ toJSON(): object;
1167
+ toBuffer(): Buffer;
1168
+ toHex(): string;
1169
+ inspect(): string;
1170
+
1171
+ static fromRandom(): HDPrivateKey;
1172
+ static fromString(str: string): HDPrivateKey;
1173
+ static fromObject(obj: object): HDPrivateKey;
1174
+ static fromSeed(
1175
+ hexa: string | Buffer,
1176
+ network: string | Networks.Type
1177
+ ): HDPrivateKey;
1178
+ static fromBuffer(buf: Buffer): HDPrivateKey;
1179
+ static fromHex(hex: string): HDPrivateKey;
1180
+ static isValidPath(arg: string | number, hardened: boolean): boolean;
1181
+ static isValidSerialized(
1182
+ data: string | Buffer,
1183
+ network?: string | Networks.Type
1184
+ ): boolean;
1185
+ static getSerializedError(
1186
+ data: string | Buffer,
1187
+ network?: string | Networks.Type
1188
+ ): any | null;
1189
+ }
1190
+
1191
+ export class HDPublicKey {
1192
+ constructor(arg: string | Buffer | object);
1193
+
1194
+ readonly xpubkey: Buffer;
1195
+ readonly network: Networks.Network;
1196
+ readonly depth: number;
1197
+ readonly publicKey: PublicKey;
1198
+ readonly fingerPrint: Buffer;
1199
+
1200
+ derive(arg: string | number, hardened?: boolean): HDPublicKey;
1201
+ deriveChild(arg: string | number, hardened?: boolean): HDPublicKey;
1202
+
1203
+ toString(): string;
1204
+ toObject(): object;
1205
+ toJSON(): object;
1206
+ toBuffer(): Buffer;
1207
+ toHex(): string;
1208
+ inspect(): string;
1209
+
1210
+ static fromString(str: string): HDPublicKey;
1211
+ static fromObject(obj: object): HDPublicKey;
1212
+ static fromBuffer(buf: Buffer): HDPublicKey;
1213
+ static fromHex(hex: string): HDPublicKey;
1214
+
1215
+ static fromHDPrivateKey(hdPrivateKey: HDPrivateKey): HDPublicKey;
1216
+ static isValidPath(arg: string | number): boolean;
1217
+ static isValidSerialized(
1218
+ data: string | Buffer,
1219
+ network?: string | Networks.Type
1220
+ ): boolean;
1221
+ static getSerializedError(
1222
+ data: string | Buffer,
1223
+ network?: string | Networks.Type
1224
+ ): any | null;
1225
+ }
1226
+
1227
+ export namespace Script {
1228
+ const types: {
1229
+ DATA_OUT: string;
1230
+ };
1231
+
1232
+ interface IOpChunk {
1233
+ buf: Buffer;
1234
+ len: number;
1235
+ opcodenum: number;
1236
+ }
1237
+
1238
+ function buildMultisigOut(
1239
+ publicKeys: PublicKey[],
1240
+ threshold: number,
1241
+ opts: object
1242
+ ): Script;
1243
+ function buildMultisigIn(
1244
+ pubkeys: PublicKey[],
1245
+ threshold: number,
1246
+ signatures: Buffer[],
1247
+ opts: object
1248
+ ): Script;
1249
+
1250
+ function buildPublicKeyHashOut(
1251
+ address: Address | PublicKey | string
1252
+ ): Script;
1253
+ function buildPublicKeyOut(pubkey: PublicKey): Script;
1254
+ function buildSafeDataOut(
1255
+ data: string | Buffer | Array<string | Buffer>,
1256
+ encoding?: string
1257
+ ): Script;
1258
+ function buildScriptHashOut(script: Script): Script;
1259
+ function buildPublicKeyIn(
1260
+ signature: crypto.Signature | Buffer,
1261
+ sigtype: number
1262
+ ): Script;
1263
+ function buildPublicKeyHashIn(
1264
+ publicKey: PublicKey,
1265
+ signature: crypto.Signature | Buffer,
1266
+ sigtype: number
1267
+ ): Script;
1268
+
1269
+ function fromAddress(address: string | Address): Script;
1270
+ function fromASM(str: string): Script;
1271
+ function fromHex(hex: string): Script;
1272
+ function fromString(str: string): Script;
1273
+ function fromBuffer(buf: Buffer): Script;
1274
+
1275
+ function toASM(): string;
1276
+ function toBuffer(): Buffer;
1277
+ function toHex(): string;
1278
+ function toString(): string;
1279
+
1280
+ function empty(): Script;
1281
+
1282
+
1283
+ function decodeMultisigOut(): {
1284
+ m: number;
1285
+ n: number;
1286
+ pubkeys: Buffer[];
1287
+ };
1288
+ }
1289
+
1290
+ export class Script {
1291
+ constructor(data: Buffer | Address | Script | string);
1292
+
1293
+ chunks: Array<Script.IOpChunk>;
1294
+ length: number;
1295
+
1296
+ set(obj: object): this;
1297
+
1298
+ toBuffer(): Buffer;
1299
+ toASM(): string;
1300
+ toString(): string;
1301
+ toHex(): string;
1302
+
1303
+ isPublicKeyHashOut(): boolean;
1304
+ isPublicKeyHashIn(): boolean;
1305
+
1306
+ getPublicKey(): Buffer;
1307
+ getPublicKeyHash(): Buffer;
1308
+
1309
+ isPublicKeyOut(): boolean;
1310
+ isPublicKeyIn(): boolean;
1311
+
1312
+ isScriptHashOut(): boolean;
1313
+ isWitnessScriptHashOut(): boolean;
1314
+ isWitnessPublicKeyHashOut(): boolean;
1315
+ isWitnessProgram(): boolean;
1316
+ isScriptHashIn(): boolean;
1317
+ isMultisigOut(): boolean;
1318
+ isMultisigIn(): boolean;
1319
+ isDataOut(): boolean;
1320
+ isSafeDataOut(): boolean;
1321
+
1322
+ getData(): Buffer;
1323
+ isPushOnly(): boolean;
1324
+
1325
+ classify(): string;
1326
+ classifyInput(): string;
1327
+ classifyOutput(): string;
1328
+
1329
+ isStandard(): boolean;
1330
+
1331
+ prepend(obj: any): this;
1332
+ add(obj: any): this;
1333
+
1334
+ hasCodeseparators(): boolean;
1335
+ removeCodeseparators(): this;
1336
+
1337
+ equals(script: Script): boolean;
1338
+
1339
+ getAddressInfo(): Address | boolean;
1340
+ findAndDelete(script: Script): this;
1341
+ checkMinimalPush(i: number): boolean;
1342
+ getSignatureOperationsCount(accurate: boolean): number;
1343
+
1344
+ toAddress(network?: Networks.Type): Address;
1345
+
1346
+ clone(): Script;
1347
+
1348
+ subScript(n: number): Script;
1349
+
1350
+ static fromChunks(chunks: Array<Script.IOpChunk>): Script
1351
+
1352
+ decodeMultisigOut(): {
1353
+ m: number;
1354
+ n: number;
1355
+ pubkeys: Buffer[];
1356
+ };
1357
+
1358
+ }
1359
+
1360
+ export namespace Interpreter {
1361
+ interface InterpretState {
1362
+ step: any;
1363
+ mainstack: any;
1364
+ altstack: any;
1365
+ }
1366
+ type StepListenerFunction = (
1367
+ step: any,
1368
+ stack: any[],
1369
+ altstack: any[]
1370
+ ) => void;
1371
+ }
1372
+
1373
+ export class Interpreter {
1374
+ static SCRIPT_ENABLE_MAGNETIC_OPCODES: number;
1375
+ static SCRIPT_ENABLE_MONOLITH_OPCODES: number;
1376
+ static SCRIPT_VERIFY_STRICTENC: number;
1377
+ static SCRIPT_ENABLE_SIGHASH_FORKID: number;
1378
+ static SCRIPT_VERIFY_LOW_S: number;
1379
+ static SCRIPT_VERIFY_NULLFAIL: number;
1380
+ static SCRIPT_VERIFY_DERSIG: number;
1381
+ static SCRIPT_VERIFY_MINIMALDATA: number;
1382
+ static SCRIPT_VERIFY_NULLDUMMY: number;
1383
+ static SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS: number;
1384
+ static SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY: number;
1385
+ static SCRIPT_VERIFY_CHECKSEQUENCEVERIFY: number;
1386
+ static MAX_SCRIPT_ELEMENT_SIZE: number;
1387
+ static MAXIMUM_ELEMENT_SIZE: number;
1388
+ static SCRIPT_VERIFY_CLEANSTACK: number;
1389
+ static DEFAULT_FLAGS: number;
1390
+ stepListener?: Interpreter.StepListenerFunction;
1391
+ errstr?: string;
1392
+ verify: (
1393
+ scriptSig: Script,
1394
+ scriptPubkey: Script,
1395
+ txn: Transaction,
1396
+ nin: number,
1397
+ flags: number,
1398
+ satoshis: number,
1399
+ ) => boolean;
1400
+ }
1401
+
1402
+ export namespace util {
1403
+ export class js {
1404
+ static isValidJSON(arg: string): boolean;
1405
+ static isHexa(value: string): boolean;
1406
+ static isHexaString(value: string): boolean;
1407
+ static defineImmutable(target: object, values: object): object;
1408
+ static isNaturalNumber(value: number): boolean;
1409
+ static integerAsBuffer(integer: number): Buffer;
1410
+ }
1411
+ }
1412
+
1413
+ export interface Util {
1414
+ readonly buffer: {
1415
+ reverse(a: any): any;
1416
+ };
1417
+ }
1418
+
1419
+ export namespace Networks {
1420
+ interface Network {
1421
+ readonly name: string;
1422
+ readonly alias: string;
1423
+ }
1424
+
1425
+ type Type = 'livenet' | 'testnet' | Network;
1426
+
1427
+ const livenet: Network;
1428
+ const mainnet: Network;
1429
+ const testnet: Network;
1430
+ const regtest: Network;
1431
+ const defaultNetwork: Network;
1432
+
1433
+ function add(data: any): Network;
1434
+ function remove(network: Networks.Type): void;
1435
+ function get(
1436
+ args: string | number | Networks.Type,
1437
+ keys?: string | string[]
1438
+ ): Network;
1439
+ }
1440
+
1441
+ export class Address {
1442
+ readonly hashBuffer: Buffer;
1443
+ readonly network: Networks.Network;
1444
+ readonly type: string;
1445
+
1446
+ constructor(
1447
+ data: Buffer | Uint8Array | string | object,
1448
+ network?: Networks.Type | string,
1449
+ type?: string
1450
+ );
1451
+ static fromString(address: string, network?: Networks.Type): Address;
1452
+ static fromHex(hex: string, network?: Networks.Type): Address;
1453
+ static fromPublicKey(data: PublicKey, network?: Networks.Type): Address;
1454
+ static fromPrivateKey(
1455
+ privateKey: PrivateKey,
1456
+ network?: Networks.Type
1457
+ ): Address;
1458
+ static fromPublicKeyHash(
1459
+ hash: Buffer | Uint8Array,
1460
+ network?: Networks.Type
1461
+ ): Address;
1462
+ static fromScript(
1463
+ script: Script,
1464
+ network?: Networks.Type
1465
+ ): Address;
1466
+ isValid(
1467
+ data: Buffer | Uint8Array | string | object,
1468
+ network?: Networks.Type | string,
1469
+ type?: string
1470
+ ): boolean;
1471
+ toBuffer(): Buffer;
1472
+ toHex(): string;
1473
+ toString(): string;
1474
+ toObject(): {
1475
+ hash: string;
1476
+ type: string;
1477
+ network: string;
1478
+ };
1479
+ }
1480
+
1481
+ export class Unit {
1482
+ static fromBTC(amount: number): Unit;
1483
+ static fromMilis(amount: number): Unit;
1484
+ static fromBits(amount: number): Unit;
1485
+ static fromSatoshis(amount: number): Unit;
1486
+
1487
+ constructor(amount: number, unitPreference: string);
1488
+
1489
+ toBTC(): number;
1490
+ toMilis(): number;
1491
+ toBits(): number;
1492
+ toSatoshis(): number;
1493
+ }
1494
+
1495
+ export class BlockHeader {
1496
+ constructor(arg: Buffer | JSON | object);
1497
+
1498
+ toObject(): {
1499
+ hash: string;
1500
+ version: number;
1501
+ prevHash: string;
1502
+ merkleRoot: string;
1503
+ time: number;
1504
+ bits: number;
1505
+ nonce: number;
1506
+ };
1507
+ }
1508
+ export class MerkleBlock {
1509
+ constructor(arg: Buffer | JSON | object);
1510
+
1511
+ toObject(): {
1512
+ header: {
1513
+ hash: string;
1514
+ version: number;
1515
+ prevHash: string;
1516
+ merkleRoot: string;
1517
+ time: number;
1518
+ bits: number;
1519
+ nonce: number;
1520
+ };
1521
+ numTransactions: number;
1522
+ hashes: Array<string>;
1523
+ flags: Array<number>;
1524
+ };
1525
+ }
1526
+
1527
+ export class HashCache {
1528
+ constructor(
1529
+ prevoutsHashBuf?: Buffer,
1530
+ sequenceHashBuf?: Buffer,
1531
+ outputsHashBuf?: Buffer
1532
+ )
1533
+
1534
+ static fromBuffer(buf: Buffer): HashCache
1535
+ static fromJSON(json: object): HashCache
1536
+ static fromHex(hex: string): HashCache
1537
+ toBuffer(): HashCache
1538
+ toJSON(): HashCache
1539
+ toHex(): HashCache
1540
+ }
1541
+ }