bsv2 2.1.0 → 2.1.1

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 (241) hide show
  1. package/dist/bsv2.mjs +1 -1
  2. package/package.json +3 -2
  3. package/.babel.test +0 -10
  4. package/.editorconfig +0 -4
  5. package/.env.defaults +0 -1
  6. package/.env.schema +0 -1
  7. package/.husky/pre-commit +0 -1
  8. package/.mocharc.yml +0 -4
  9. package/.nvmrc +0 -1
  10. package/.travis.yml +0 -7
  11. package/babel.config.cjs +0 -44
  12. package/benchmark.js +0 -42
  13. package/bin/bsv.js +0 -11
  14. package/bin/network.js +0 -93
  15. package/build/index.html +0 -20
  16. package/dist/bsv2.umd.js +0 -28
  17. package/doc/assets/anchor.js +0 -350
  18. package/doc/assets/bass-addons.css +0 -12
  19. package/doc/assets/bass.css +0 -544
  20. package/doc/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
  21. package/doc/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
  22. package/doc/assets/fonts/LICENSE.txt +0 -93
  23. package/doc/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
  24. package/doc/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
  25. package/doc/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
  26. package/doc/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
  27. package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
  28. package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
  29. package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
  30. package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
  31. package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
  32. package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
  33. package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
  34. package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
  35. package/doc/assets/fonts/source-code-pro.css +0 -23
  36. package/doc/assets/github.css +0 -123
  37. package/doc/assets/site.js +0 -168
  38. package/doc/assets/split.css +0 -15
  39. package/doc/assets/split.js +0 -782
  40. package/doc/assets/style.css +0 -147
  41. package/doc/index.html +0 -9461
  42. package/entry.js +0 -81
  43. package/eslint.config.mjs +0 -8
  44. package/index.js +0 -98
  45. package/karma.conf.ts +0 -77
  46. package/lib/ach.js +0 -59
  47. package/lib/address.js +0 -266
  48. package/lib/aes.js +0 -57
  49. package/lib/aescbc.js +0 -38
  50. package/lib/base-58-check.js +0 -83
  51. package/lib/base-58.js +0 -59
  52. package/lib/bip-32.js +0 -472
  53. package/lib/bip-39-en-wordlist.js +0 -2054
  54. package/lib/bip-39-en.js +0 -10
  55. package/lib/bip-39-es-wordlist.js +0 -2055
  56. package/lib/bip-39-es.js +0 -10
  57. package/lib/bip-39-jp-wordlist.js +0 -2053
  58. package/lib/bip-39-jp.js +0 -10
  59. package/lib/bip-39-words.js +0 -5
  60. package/lib/bip-39.js +0 -286
  61. package/lib/block-header.js +0 -79
  62. package/lib/block.js +0 -132
  63. package/lib/bn.js +0 -462
  64. package/lib/br.js +0 -172
  65. package/lib/bsm.js +0 -127
  66. package/lib/bw.js +0 -188
  67. package/lib/cbc.js +0 -140
  68. package/lib/cmp.js +0 -37
  69. package/lib/config.js +0 -50
  70. package/lib/constants.js +0 -150
  71. package/lib/ecdsa.js +0 -496
  72. package/lib/ecies.js +0 -151
  73. package/lib/hash-cache.js +0 -41
  74. package/lib/hash.js +0 -191
  75. package/lib/interp.js +0 -2017
  76. package/lib/inv.js +0 -49
  77. package/lib/key-pair.js +0 -133
  78. package/lib/mainnet-address.js +0 -5
  79. package/lib/mainnet-bip-32.js +0 -5
  80. package/lib/mainnet-key-pair.js +0 -5
  81. package/lib/mainnet-priv-key.js +0 -5
  82. package/lib/merkle.js +0 -92
  83. package/lib/msg.js +0 -184
  84. package/lib/op-code.js +0 -400
  85. package/lib/point.js +0 -134
  86. package/lib/priv-key.js +0 -157
  87. package/lib/pub-key.js +0 -230
  88. package/lib/random.js +0 -28
  89. package/lib/script.js +0 -828
  90. package/lib/sig-operations.js +0 -120
  91. package/lib/sig.js +0 -399
  92. package/lib/struct.js +0 -392
  93. package/lib/testnet-address.js +0 -5
  94. package/lib/testnet-bip-32.js +0 -5
  95. package/lib/testnet-key-pair.js +0 -5
  96. package/lib/testnet-priv-key.js +0 -5
  97. package/lib/tx-builder.js +0 -593
  98. package/lib/tx-in.js +0 -172
  99. package/lib/tx-out-map.js +0 -57
  100. package/lib/tx-out.js +0 -73
  101. package/lib/tx-verifier.js +0 -209
  102. package/lib/tx.js +0 -430
  103. package/lib/var-int.js +0 -73
  104. package/lib/version.js +0 -92
  105. package/lib/workers-result.js +0 -65
  106. package/lib/workers.js +0 -77
  107. package/load-babel.js +0 -5
  108. package/mtest/test.html +0 -17
  109. package/mtest/test.js +0 -2
  110. package/mtest/test.mjs +0 -2
  111. package/mtest/webpack.config.js +0 -115
  112. package/out/Sig.html +0 -541
  113. package/out/bip-32.js.html +0 -523
  114. package/out/bip-39.js.html +0 -336
  115. package/out/block.js.html +0 -183
  116. package/out/bn.js.html +0 -512
  117. package/out/ecdsa.js.html +0 -546
  118. package/out/fonts/OpenSans-Bold-webfont.eot +0 -0
  119. package/out/fonts/OpenSans-Bold-webfont.svg +0 -1830
  120. package/out/fonts/OpenSans-Bold-webfont.woff +0 -0
  121. package/out/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  122. package/out/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  123. package/out/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  124. package/out/fonts/OpenSans-Italic-webfont.eot +0 -0
  125. package/out/fonts/OpenSans-Italic-webfont.svg +0 -1830
  126. package/out/fonts/OpenSans-Italic-webfont.woff +0 -0
  127. package/out/fonts/OpenSans-Light-webfont.eot +0 -0
  128. package/out/fonts/OpenSans-Light-webfont.svg +0 -1831
  129. package/out/fonts/OpenSans-Light-webfont.woff +0 -0
  130. package/out/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  131. package/out/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  132. package/out/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  133. package/out/fonts/OpenSans-Regular-webfont.eot +0 -0
  134. package/out/fonts/OpenSans-Regular-webfont.svg +0 -1831
  135. package/out/fonts/OpenSans-Regular-webfont.woff +0 -0
  136. package/out/global.html +0 -220
  137. package/out/index.html +0 -128
  138. package/out/interp.js.html +0 -2064
  139. package/out/merkle.js.html +0 -143
  140. package/out/msg.js.html +0 -235
  141. package/out/priv-key.js.html +0 -208
  142. package/out/pub-key.js.html +0 -281
  143. package/out/script.js.html +0 -876
  144. package/out/scripts/linenumber.js +0 -25
  145. package/out/scripts/prettify/Apache-License-2.0.txt +0 -202
  146. package/out/scripts/prettify/lang-css.js +0 -2
  147. package/out/scripts/prettify/prettify.js +0 -28
  148. package/out/sig-operations.js.html +0 -171
  149. package/out/sig.js.html +0 -450
  150. package/out/struct.js.html +0 -440
  151. package/out/styles/jsdoc-default.css +0 -358
  152. package/out/styles/prettify-jsdoc.css +0 -111
  153. package/out/styles/prettify-tomorrow.css +0 -132
  154. package/out/tx-builder.js.html +0 -644
  155. package/out/tx-in.js.html +0 -223
  156. package/out/tx-verifier.js.html +0 -260
  157. package/out/tx.js.html +0 -481
  158. package/test/ach.js +0 -172
  159. package/test/address.js +0 -464
  160. package/test/aes.js +0 -96
  161. package/test/aescbc.js +0 -65
  162. package/test/base-58-check.js +0 -128
  163. package/test/base-58.js +0 -113
  164. package/test/bip-32.js +0 -721
  165. package/test/bip-39.js +0 -282
  166. package/test/block-header.js +0 -152
  167. package/test/block.js +0 -243
  168. package/test/bn.js +0 -643
  169. package/test/br.js +0 -353
  170. package/test/bsm.js +0 -141
  171. package/test/bw.js +0 -292
  172. package/test/cbc.js +0 -335
  173. package/test/cmp.js +0 -56
  174. package/test/data/bip69.json +0 -215
  175. package/test/data/bitcoind/base58_keys_invalid.json +0 -152
  176. package/test/data/bitcoind/base58_keys_valid.json +0 -452
  177. package/test/data/bitcoind/blocks.json +0 -27
  178. package/test/data/bitcoind/script_tests.json +0 -2244
  179. package/test/data/bitcoind/sig_canonical.json +0 -7
  180. package/test/data/bitcoind/sig_noncanonical.json +0 -22
  181. package/test/data/bitcoind/tx_invalid.json +0 -177
  182. package/test/data/bitcoind/tx_valid.json +0 -224
  183. package/test/data/blk86756-testnet.dat +0 -0
  184. package/test/data/blk86756-testnet.js +0 -12
  185. package/test/data/blk86756-testnet.json +0 -684
  186. package/test/data/ecdsa.json +0 -230
  187. package/test/data/messages.json +0 -22
  188. package/test/data/sighash.json +0 -1004
  189. package/test/data/tx_creation.json +0 -85
  190. package/test/ecdsa.js +0 -748
  191. package/test/ecies.js +0 -238
  192. package/test/global.js +0 -13
  193. package/test/hash-cache.js +0 -52
  194. package/test/hash.js +0 -354
  195. package/test/index.js +0 -10
  196. package/test/interp.js +0 -512
  197. package/test/inv.js +0 -65
  198. package/test/key-pair.js +0 -243
  199. package/test/merkle.js +0 -179
  200. package/test/msg.js +0 -295
  201. package/test/op-code.js +0 -79
  202. package/test/point.js +0 -375
  203. package/test/priv-key.js +0 -264
  204. package/test/pub-key.js +0 -549
  205. package/test/random.js +0 -31
  206. package/test/script.js +0 -1340
  207. package/test/sig-operations.js +0 -149
  208. package/test/sig.js +0 -662
  209. package/test/struct.js +0 -552
  210. package/test/tx-builder.js +0 -2104
  211. package/test/tx-in.js +0 -198
  212. package/test/tx-out-map.js +0 -104
  213. package/test/tx-out.js +0 -162
  214. package/test/tx-verifier.js +0 -246
  215. package/test/tx.js +0 -539
  216. package/test/var-int.js +0 -132
  217. package/test/vectors/aes.json +0 -10392
  218. package/test/vectors/aescbc.json +0 -620
  219. package/test/vectors/bip39.json +0 -502
  220. package/test/vectors/bip69.json +0 -215
  221. package/test/vectors/bitcoin-abc/script_tests.json +0 -48
  222. package/test/vectors/bitcoin-abc/sighash.json +0 -7004
  223. package/test/vectors/bitcoin-sv/script_tests.json +0 -248
  224. package/test/vectors/bitcoind/script_invalid.json +0 -1151
  225. package/test/vectors/bitcoind/script_valid.json +0 -1462
  226. package/test/vectors/bitcoind/sighash.json +0 -3503
  227. package/test/vectors/bitcoind/tx_invalid.json +0 -883
  228. package/test/vectors/bitcoind/tx_valid.json +0 -1150
  229. package/test/vectors/coolest-tx-ever-sent.json +0 -8
  230. package/test/vectors/ecdsa.json +0 -300
  231. package/test/vectors/hash.json +0 -6133
  232. package/test/vectors/kdf.json +0 -47
  233. package/test/vectors/largesttx.json +0 -5
  234. package/test/vectors/largesttxblock.json +0 -6
  235. package/test/vectors/sig.json +0 -79
  236. package/test/vectors/sighash-single-bug.json +0 -8
  237. package/test/version.js +0 -81
  238. package/test/workers-result.js +0 -89
  239. package/test/workers.js +0 -91
  240. package/test-index.js +0 -3
  241. package/vite.config.js +0 -36
package/lib/op-code.js DELETED
@@ -1,400 +0,0 @@
1
- /*
2
- * OpCode
3
- * ======
4
- *
5
- * An opCode is one of the operations in the bitcoin scripting language. Each
6
- * operation is just a number from 0-255, and it has a corresponding string,
7
- * e.g. 'OP_RETURN', which comes from the name of that constant in the bitcoind
8
- * source code. The way you probably want to use this is with
9
- * new OpCode(str).toNumber() or new OpCode(num).toString()
10
- */
11
- 'use strict'
12
-
13
- import { Struct } from './struct'
14
- const noopmap = {
15
- // push value
16
- FALSE: 0x00,
17
- 0: 0x00,
18
- PUSHDATA1: 0x4c,
19
- PUSHDATA2: 0x4d,
20
- PUSHDATA4: 0x4e,
21
- '1NEGATE': 0x4f,
22
- RESERVED: 0x50,
23
- TRUE: 0x51,
24
- 1: 0x51,
25
- 2: 0x52,
26
- 3: 0x53,
27
- 4: 0x54,
28
- 5: 0x55,
29
- 6: 0x56,
30
- 7: 0x57,
31
- 8: 0x58,
32
- 9: 0x59,
33
- 10: 0x5a,
34
- 11: 0x5b,
35
- 12: 0x5c,
36
- 13: 0x5d,
37
- 14: 0x5e,
38
- 15: 0x5f,
39
- 16: 0x60,
40
-
41
- // control
42
- NOP: 0x61,
43
- VER: 0x62,
44
- IF: 0x63,
45
- NOTIF: 0x64,
46
- VERIF: 0x65,
47
- VERNOTIF: 0x66,
48
- ELSE: 0x67,
49
- ENDIF: 0x68,
50
- VERIFY: 0x69,
51
- RETURN: 0x6a,
52
-
53
- // stack ops
54
- TOALTSTACK: 0x6b,
55
- FROMALTSTACK: 0x6c,
56
- '2DROP': 0x6d,
57
- '2DUP': 0x6e,
58
- '3DUP': 0x6f,
59
- '2OVER': 0x70,
60
- '2ROT': 0x71,
61
- '2SWAP': 0x72,
62
- IFDUP: 0x73,
63
- DEPTH: 0x74,
64
- DROP: 0x75,
65
- DUP: 0x76,
66
- NIP: 0x77,
67
- OVER: 0x78,
68
- PICK: 0x79,
69
- ROLL: 0x7a,
70
- ROT: 0x7b,
71
- SWAP: 0x7c,
72
- TUCK: 0x7d,
73
-
74
- // data manipulation ops
75
- CAT: 0x7e,
76
- SUBSTR: 0x7f, // Replaced in BSV
77
- SPLIT: 0x7f,
78
- LEFT: 0x80, // Replaced in BSV
79
- NUM2BIN: 0x80,
80
- RIGHT: 0x81, // Replaced in BSV
81
- BIN2NUM: 0x81,
82
- SIZE: 0x82,
83
-
84
- // bit logic
85
- INVERT: 0x83,
86
- AND: 0x84,
87
- OR: 0x85,
88
- XOR: 0x86,
89
- EQUAL: 0x87,
90
- EQUALVERIFY: 0x88,
91
- RESERVED1: 0x89,
92
- RESERVED2: 0x8a,
93
-
94
- // numeric
95
- '1ADD': 0x8b,
96
- '1SUB': 0x8c,
97
- '2MUL': 0x8d,
98
- '2DIV': 0x8e,
99
- NEGATE: 0x8f,
100
- ABS: 0x90,
101
- NOT: 0x91,
102
- '0NOTEQUAL': 0x92,
103
-
104
- ADD: 0x93,
105
- SUB: 0x94,
106
- MUL: 0x95,
107
- DIV: 0x96,
108
- MOD: 0x97,
109
- LSHIFT: 0x98,
110
- RSHIFT: 0x99,
111
-
112
- BOOLAND: 0x9a,
113
- BOOLOR: 0x9b,
114
- NUMEQUAL: 0x9c,
115
- NUMEQUALVERIFY: 0x9d,
116
- NUMNOTEQUAL: 0x9e,
117
- LESSTHAN: 0x9f,
118
- GREATERTHAN: 0xa0,
119
- LESSTHANOREQUAL: 0xa1,
120
- GREATERTHANOREQUAL: 0xa2,
121
- MIN: 0xa3,
122
- MAX: 0xa4,
123
-
124
- WITHIN: 0xa5,
125
-
126
- // crypto
127
- RIPEMD160: 0xa6,
128
- SHA1: 0xa7,
129
- SHA256: 0xa8,
130
- HASH160: 0xa9,
131
- HASH256: 0xaa,
132
- CODESEPARATOR: 0xab,
133
- CHECKSIG: 0xac,
134
- CHECKSIGVERIFY: 0xad,
135
- CHECKMULTISIG: 0xae,
136
- CHECKMULTISIGVERIFY: 0xaf,
137
-
138
- // expansion
139
- NOP1: 0xb0,
140
- NOP2: 0xb1,
141
- CHECKLOCKTIMEVERIFY: 0xb1,
142
- NOP3: 0xb2,
143
- CHECKSEQUENCEVERIFY: 0xb2,
144
- NOP4: 0xb3,
145
- NOP5: 0xb4,
146
- NOP6: 0xb5,
147
- NOP7: 0xb6,
148
- NOP8: 0xb7,
149
- NOP9: 0xb8,
150
- NOP10: 0xb9,
151
-
152
- // template matching params
153
- SMALLDATA: 0xf9,
154
- SMALLINTEGER: 0xfa,
155
- PUBKEYS: 0xfb,
156
- PUBKEYHASH: 0xfd,
157
- PUBKEY: 0xfe,
158
-
159
- INVALIDOPCODE: 0xff
160
- }
161
-
162
- const map = {
163
- // push value
164
- OP_FALSE: 0x00,
165
- OP_0: 0x00,
166
- OP_PUSHDATA1: 0x4c,
167
- OP_PUSHDATA2: 0x4d,
168
- OP_PUSHDATA4: 0x4e,
169
- OP_1NEGATE: 0x4f,
170
- OP_RESERVED: 0x50,
171
- OP_TRUE: 0x51,
172
- OP_1: 0x51,
173
- OP_2: 0x52,
174
- OP_3: 0x53,
175
- OP_4: 0x54,
176
- OP_5: 0x55,
177
- OP_6: 0x56,
178
- OP_7: 0x57,
179
- OP_8: 0x58,
180
- OP_9: 0x59,
181
- OP_10: 0x5a,
182
- OP_11: 0x5b,
183
- OP_12: 0x5c,
184
- OP_13: 0x5d,
185
- OP_14: 0x5e,
186
- OP_15: 0x5f,
187
- OP_16: 0x60,
188
-
189
- // control
190
- OP_NOP: 0x61,
191
- OP_VER: 0x62,
192
- OP_IF: 0x63,
193
- OP_NOTIF: 0x64,
194
- OP_VERIF: 0x65,
195
- OP_VERNOTIF: 0x66,
196
- OP_ELSE: 0x67,
197
- OP_ENDIF: 0x68,
198
- OP_VERIFY: 0x69,
199
- OP_RETURN: 0x6a,
200
-
201
- // stack ops
202
- OP_TOALTSTACK: 0x6b,
203
- OP_FROMALTSTACK: 0x6c,
204
- OP_2DROP: 0x6d,
205
- OP_2DUP: 0x6e,
206
- OP_3DUP: 0x6f,
207
- OP_2OVER: 0x70,
208
- OP_2ROT: 0x71,
209
- OP_2SWAP: 0x72,
210
- OP_IFDUP: 0x73,
211
- OP_DEPTH: 0x74,
212
- OP_DROP: 0x75,
213
- OP_DUP: 0x76,
214
- OP_NIP: 0x77,
215
- OP_OVER: 0x78,
216
- OP_PICK: 0x79,
217
- OP_ROLL: 0x7a,
218
- OP_ROT: 0x7b,
219
- OP_SWAP: 0x7c,
220
- OP_TUCK: 0x7d,
221
-
222
- // data manipulation ops
223
- OP_CAT: 0x7e,
224
- OP_SUBSTR: 0x7f, // Replaced in BSV
225
- OP_SPLIT: 0x7f,
226
- OP_LEFT: 0x80, // Replaced in BSV
227
- OP_NUM2BIN: 0x80,
228
- OP_RIGHT: 0x81, // Replaced in BSV
229
- OP_BIN2NUM: 0x81,
230
- OP_SIZE: 0x82,
231
-
232
- // bit logic
233
- OP_INVERT: 0x83,
234
- OP_AND: 0x84,
235
- OP_OR: 0x85,
236
- OP_XOR: 0x86,
237
- OP_EQUAL: 0x87,
238
- OP_EQUALVERIFY: 0x88,
239
- OP_RESERVED1: 0x89,
240
- OP_RESERVED2: 0x8a,
241
-
242
- // numeric
243
- OP_1ADD: 0x8b,
244
- OP_1SUB: 0x8c,
245
- OP_2MUL: 0x8d,
246
- OP_2DIV: 0x8e,
247
- OP_NEGATE: 0x8f,
248
- OP_ABS: 0x90,
249
- OP_NOT: 0x91,
250
- OP_0NOTEQUAL: 0x92,
251
-
252
- OP_ADD: 0x93,
253
- OP_SUB: 0x94,
254
- OP_MUL: 0x95,
255
- OP_DIV: 0x96,
256
- OP_MOD: 0x97,
257
- OP_LSHIFT: 0x98,
258
- OP_RSHIFT: 0x99,
259
-
260
- OP_BOOLAND: 0x9a,
261
- OP_BOOLOR: 0x9b,
262
- OP_NUMEQUAL: 0x9c,
263
- OP_NUMEQUALVERIFY: 0x9d,
264
- OP_NUMNOTEQUAL: 0x9e,
265
- OP_LESSTHAN: 0x9f,
266
- OP_GREATERTHAN: 0xa0,
267
- OP_LESSTHANOREQUAL: 0xa1,
268
- OP_GREATERTHANOREQUAL: 0xa2,
269
- OP_MIN: 0xa3,
270
- OP_MAX: 0xa4,
271
-
272
- OP_WITHIN: 0xa5,
273
-
274
- // crypto
275
- OP_RIPEMD160: 0xa6,
276
- OP_SHA1: 0xa7,
277
- OP_SHA256: 0xa8,
278
- OP_HASH160: 0xa9,
279
- OP_HASH256: 0xaa,
280
- OP_CODESEPARATOR: 0xab,
281
- OP_CHECKSIG: 0xac,
282
- OP_CHECKSIGVERIFY: 0xad,
283
- OP_CHECKMULTISIG: 0xae,
284
- OP_CHECKMULTISIGVERIFY: 0xaf,
285
-
286
- // expansion
287
- OP_NOP1: 0xb0,
288
- OP_NOP2: 0xb1,
289
- OP_CHECKLOCKTIMEVERIFY: 0xb1,
290
- OP_NOP3: 0xb2,
291
- OP_CHECKSEQUENCEVERIFY: 0xb2,
292
- OP_NOP4: 0xb3,
293
- OP_NOP5: 0xb4,
294
- OP_NOP6: 0xb5,
295
- OP_NOP7: 0xb6,
296
- OP_NOP8: 0xb7,
297
- OP_NOP9: 0xb8,
298
- OP_NOP10: 0xb9,
299
-
300
- // template matching params
301
- OP_SMALLDATA: 0xf9,
302
- OP_SMALLINTEGER: 0xfa,
303
- OP_PUBKEYS: 0xfb,
304
- OP_PUBKEYHASH: 0xfd,
305
- OP_PUBKEY: 0xfe,
306
-
307
- OP_INVALIDOPCODE: 0xff
308
- }
309
-
310
- class OpCode extends Struct {
311
- constructor (num) {
312
- super({ num })
313
- }
314
-
315
- fromNumber (num) {
316
- this.num = num
317
- return this
318
- }
319
-
320
- static fromNumber (num) {
321
- return new this().fromNumber(num)
322
- }
323
-
324
- toNumber () {
325
- return this.num
326
- }
327
-
328
- fromString (str) {
329
- const num = map[str]
330
- if (num === undefined) {
331
- throw new Error('Invalid opCodeStr')
332
- }
333
- this.num = num
334
- return this
335
- }
336
-
337
- fromNoOpString (str) {
338
- const num = noopmap[str]
339
- if (num === undefined) {
340
- throw new Error('Invalid opCodeStr')
341
- }
342
- this.num = num
343
- return this
344
- }
345
-
346
- static fromString (str) {
347
- return new this().fromString(str)
348
- }
349
-
350
- static fromNoOpString (str) {
351
- return new this().fromNoOpString(str)
352
- }
353
-
354
- toString () {
355
- const str = OpCode.str[this.num]
356
- if (str === undefined) {
357
- if (this.num > 0 && this.num < OpCode.OP_PUSHDATA1) {
358
- return this.num.toString()
359
- } else {
360
- return 'OP_' + this.num.toNumber()
361
- }
362
- // throw new Error('OpCode does not have a string representation')
363
- }
364
- return str
365
- }
366
-
367
- toNoOpString () {
368
- const str = OpCode.noopstr[this.num]
369
- if (str === undefined) {
370
- if (this.num > 0 && this.num < OpCode.OP_PUSHDATA1) {
371
- return this.num.toString()
372
- } else {
373
- return this.num.toNumber()
374
- }
375
- // throw new Error('OpCode does not have a string representation')
376
- }
377
- return str
378
- }
379
- }
380
-
381
- OpCode.str = {}
382
- OpCode.noopstr = {}
383
-
384
- for (const opCodeStr in map) {
385
- OpCode[opCodeStr] = map[opCodeStr]
386
-
387
- if (Object.prototype.hasOwnProperty.call(map, opCodeStr)) {
388
- OpCode.str[map[opCodeStr]] = opCodeStr
389
- }
390
- }
391
-
392
- for (const CodeStr in noopmap) {
393
- OpCode[CodeStr] = noopmap[CodeStr]
394
-
395
- if (Object.prototype.hasOwnProperty.call(noopmap, CodeStr)) {
396
- OpCode.noopstr[noopmap[CodeStr]] = CodeStr
397
- }
398
- }
399
-
400
- export { OpCode }
package/lib/point.js DELETED
@@ -1,134 +0,0 @@
1
- /**
2
- * Point (on secp256k1)
3
- * ====================
4
- *
5
- * A point is a point on the secp256k1 curve which is the elliptic curve used
6
- * by bitcoin. This code is a wrapper for Fedor Indutny's Point class from his
7
- * elliptic library. This code adds a few minor conveniences, but is mostly the
8
- * same. Since Fedor's code returns points and big numbers that are instances
9
- * of his point and big number classes, we have to wrap all the methods such as
10
- * getX() to return the Yours Bitcoin point and big number types.
11
- */
12
- 'use strict'
13
-
14
- import { Bn } from './bn'
15
- import elliptic from 'bitcoin-elliptic'
16
-
17
- const ec = elliptic.curves.secp256k1
18
- const _point = ec.curve.point()
19
- const _Point = _point.constructor
20
-
21
- class Point extends _Point {
22
- constructor (x, y, isRed) {
23
- super(ec.curve, x, y, isRed)
24
- }
25
-
26
- static fromX (isOdd, x) {
27
- const _point = ec.curve.pointFromX(x, isOdd)
28
- const point = Object.create(Point.prototype)
29
- return point.copyFrom(_point)
30
- }
31
-
32
- copyFrom (point) {
33
- if (!(point instanceof _Point)) {
34
- throw new Error('point should be an external point')
35
- }
36
- Object.keys(point).forEach(
37
- function (key) {
38
- this[key] = point[key]
39
- }.bind(this)
40
- )
41
- return this
42
- }
43
-
44
- add (p) {
45
- p = _Point.prototype.add.call(this, p)
46
- const point = Object.create(Point.prototype)
47
- return point.copyFrom(p)
48
- }
49
-
50
- mul (bn) {
51
- if (!bn.lt(Point.getN())) {
52
- throw new Error('point mul out of range')
53
- }
54
- const p = _Point.prototype.mul.call(this, bn)
55
- const point = Object.create(Point.prototype)
56
- return point.copyFrom(p)
57
- }
58
-
59
- mulAdd (bn1, point, bn2) {
60
- const p = _Point.prototype.mulAdd.call(this, bn1, point, bn2)
61
- point = Object.create(Point.prototype)
62
- return point.copyFrom(p)
63
- }
64
-
65
- getX () {
66
- const _x = _Point.prototype.getX.call(this)
67
- const x = Object.create(Bn.prototype)
68
- _x.copy(x)
69
- return x
70
- }
71
-
72
- getY () {
73
- const _y = _Point.prototype.getY.call(this)
74
- const y = Object.create(Bn.prototype)
75
- _y.copy(y)
76
- return y
77
- }
78
-
79
- fromX (isOdd, x) {
80
- const point = Point.fromX(isOdd, x)
81
- return this.copyFrom(point)
82
- }
83
-
84
- toJSON () {
85
- return {
86
- x: this.getX().toString(),
87
- y: this.getY().toString()
88
- }
89
- }
90
-
91
- fromJSON (json) {
92
- const x = new Bn().fromString(json.x)
93
- const y = new Bn().fromString(json.y)
94
- const point = new Point(x, y)
95
- return this.copyFrom(point)
96
- }
97
-
98
- toString () {
99
- return JSON.stringify(this.toJSON())
100
- }
101
-
102
- fromString (str) {
103
- const json = JSON.parse(str)
104
- const p = new Point().fromJSON(json)
105
- return this.copyFrom(p)
106
- }
107
-
108
- static getG () {
109
- const _g = ec.curve.g
110
- const g = Object.create(Point.prototype)
111
- return g.copyFrom(_g)
112
- }
113
-
114
- static getN () {
115
- return new Bn(ec.curve.n.toArray())
116
- }
117
-
118
- // https://www.iacr.org/archive/pkc2003/25670211/25670211.pdf
119
- validate () {
120
- const p2 = Point.fromX(this.getY().isOdd(), this.getX())
121
- if (!(p2.getY().cmp(this.getY()) === 0)) {
122
- throw new Error('Invalid y value of public key')
123
- }
124
- if (
125
- !(this.getX().gt(-1) && this.getX().lt(Point.getN())) ||
126
- !(this.getY().gt(-1) && this.getY().lt(Point.getN()))
127
- ) {
128
- throw new Error('Point does not lie on the curve')
129
- }
130
- return this
131
- }
132
- }
133
-
134
- export { Point }
package/lib/priv-key.js DELETED
@@ -1,157 +0,0 @@
1
- /**
2
- * Private Key
3
- * ===========
4
- *
5
- * A private key is used for signing transactions (or messages). The primary
6
- * way to use this is new PrivKey().fromRandom(), or new PrivKey().fromBuffer(buf).
7
- */
8
- 'use strict'
9
-
10
- import { Bn } from './bn'
11
- import { Point } from './point'
12
- import { Constants } from './constants'
13
- import { Base58Check } from './base-58-check'
14
- import { Random } from './random'
15
- import { Struct } from './struct'
16
-
17
- class PrivKey extends Struct {
18
- constructor (bn, compressed, constants = null) {
19
- super({ bn, compressed })
20
- constants = constants || Constants.Default.PrivKey
21
- this.Constants = constants
22
- }
23
-
24
- fromJSON (json) {
25
- this.fromHex(json)
26
- return this
27
- }
28
-
29
- toJSON () {
30
- return this.toHex()
31
- }
32
-
33
- fromRandom () {
34
- let privBuf, bn, condition
35
-
36
- do {
37
- privBuf = Random.getRandomBuffer(32)
38
- bn = new Bn().fromBuffer(privBuf)
39
- condition = bn.lt(Point.getN())
40
- } while (!condition)
41
-
42
- this.fromObject({
43
- bn,
44
- compressed: true
45
- })
46
- return this
47
- }
48
-
49
- static fromRandom () {
50
- return new this().fromRandom()
51
- }
52
-
53
- toBuffer () {
54
- let compressed = this.compressed
55
-
56
- if (compressed === undefined) {
57
- compressed = true
58
- }
59
-
60
- const privBuf = this.bn.toBuffer({ size: 32 })
61
- let buf
62
- if (compressed) {
63
- buf = Buffer.concat([
64
- Buffer.from([this.Constants.versionByteNum]),
65
- privBuf,
66
- Buffer.from([0x01])
67
- ])
68
- } else {
69
- buf = Buffer.concat([Buffer.from([this.Constants.versionByteNum]), privBuf])
70
- }
71
-
72
- return buf
73
- }
74
-
75
- fromBuffer (buf) {
76
- if (buf.length === 1 + 32 + 1 && buf[1 + 32 + 1 - 1] === 1) {
77
- this.compressed = true
78
- } else if (buf.length === 1 + 32) {
79
- this.compressed = false
80
- } else {
81
- throw new Error(
82
- 'Length of privKey buffer must be 33 (uncompressed pubKey) or 34 (compressed pubKey)'
83
- )
84
- }
85
-
86
- if (buf[0] !== this.Constants.versionByteNum) {
87
- throw new Error('Invalid versionByteNum byte')
88
- }
89
-
90
- return this.fromBn(new Bn().fromBuffer(buf.slice(1, 1 + 32)))
91
- }
92
-
93
- toBn () {
94
- return this.bn
95
- }
96
-
97
- fromBn (bn) {
98
- this.bn = bn
99
- return this
100
- }
101
-
102
- static fromBn (bn) {
103
- return new this().fromBn(bn)
104
- }
105
-
106
- validate () {
107
- if (!this.bn.lt(Point.getN())) {
108
- throw new Error('Number must be less than N')
109
- }
110
- if (typeof this.compressed !== 'boolean') {
111
- throw new Error(
112
- 'Must specify whether the corresponding public key is compressed or not (true or false)'
113
- )
114
- }
115
- return this
116
- }
117
-
118
- /**
119
- * Output the private key a Wallet Import Format (Wif) string.
120
- */
121
- toWif () {
122
- return Base58Check.encode(this.toBuffer())
123
- }
124
-
125
- /**
126
- * Input the private key from a Wallet Import Format (Wif) string.
127
- */
128
- fromWif (str) {
129
- return this.fromBuffer(Base58Check.decode(str))
130
- }
131
-
132
- static fromWif (str) {
133
- return new this().fromWif(str)
134
- }
135
-
136
- toString () {
137
- return this.toWif()
138
- }
139
-
140
- fromString (str) {
141
- return this.fromWif(str)
142
- }
143
- }
144
-
145
- PrivKey.Mainnet = class extends PrivKey {
146
- constructor (bn, compressed) {
147
- super(bn, compressed, Constants.Mainnet.PrivKey)
148
- }
149
- }
150
-
151
- PrivKey.Testnet = class extends PrivKey {
152
- constructor (bn, compressed) {
153
- super(bn, compressed, Constants.Testnet.PrivKey)
154
- }
155
- }
156
-
157
- export { PrivKey }