bsv2 2.1.0 → 2.1.2

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/dist/bsv2.umd.js +1 -1
  3. package/package.json +7 -3
  4. package/.babel.test +0 -10
  5. package/.editorconfig +0 -4
  6. package/.env.defaults +0 -1
  7. package/.env.schema +0 -1
  8. package/.husky/pre-commit +0 -1
  9. package/.mocharc.yml +0 -4
  10. package/.nvmrc +0 -1
  11. package/.travis.yml +0 -7
  12. package/babel.config.cjs +0 -44
  13. package/benchmark.js +0 -42
  14. package/bin/bsv.js +0 -11
  15. package/bin/network.js +0 -93
  16. package/build/index.html +0 -20
  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/test/point.js DELETED
@@ -1,375 +0,0 @@
1
- /* global describe,it */
2
- 'use strict'
3
- import should from 'should'
4
- import { Point } from '../lib/point'
5
- import { Bn } from '../lib/bn'
6
-
7
- describe('Point', function () {
8
- it('should create a point', function () {
9
- let p = new Point()
10
- should.exist(p)
11
- p = new Point()
12
- should.exist(p)
13
- ;(p instanceof Point).should.equal(true)
14
- })
15
-
16
- it('should have the standard properties for a point', function () {
17
- const p = new Point()
18
- const props = ['curve', 'type', 'precomputed', 'x', 'y', 'inf']
19
-
20
- // all enumerable, own properties should be in prop
21
- for (const k in p) {
22
- if (Object.prototype.hasOwnProperty.call(p, k)) {
23
- props.indexOf(k).should.not.equal(-1)
24
- }
25
- }
26
-
27
- // all props should be properties of a point
28
- props.forEach(function (k) {
29
- ;(p[k] === undefined).should.equal(false)
30
- })
31
- })
32
-
33
- describe('#copyFrom', function () {
34
- it('should copy G', function () {
35
- const point = Point.getG()
36
- let point2
37
- ;(function () {
38
- point.copyFrom(point2)
39
- }.should.throw()) // point2 is not a Point yet
40
- const point3 = new Point()
41
- point.copyFrom(point3)
42
- point.toString().should.equal(point3.toString())
43
- })
44
- })
45
-
46
- describe('#toJSON', function () {
47
- it('should print G to JSON', function () {
48
- const G = Point.getG()
49
- const json = G.toJSON()
50
- json.x.should.equal(G.x.toString())
51
- json.y.should.equal(G.y.toString())
52
- })
53
- })
54
-
55
- describe('#fromJSON', function () {
56
- it('should recover G', function () {
57
- new Point()
58
- .fromJSON(Point.getG().toJSON())
59
- .eq(Point.getG())
60
- .should.equal(true)
61
- })
62
- })
63
-
64
- describe('#toString', function () {
65
- it('should convert G to a string', function () {
66
- const G = Point.getG()
67
- G.toString().should.equal(JSON.stringify(G.toJSON()))
68
- })
69
- })
70
-
71
- describe('#fromString', function () {
72
- it('should convert a json string to G', function () {
73
- const G = Point.getG()
74
- new Point()
75
- .fromString(G.toString())
76
- .eq(G)
77
- .should.equal(true)
78
- })
79
- })
80
-
81
- describe('#getX', function () {
82
- it('should return a Bn', function () {
83
- const p = new Point()
84
- ;(p.getX() instanceof Bn).should.equal(true)
85
- })
86
-
87
- it('should return 0', function () {
88
- const p = new Point()
89
- p
90
- .getX()
91
- .toString()
92
- .should.equal('0')
93
- })
94
-
95
- it('should be convertable to a buffer', function () {
96
- const p = new Point()
97
- p
98
- .getX()
99
- .toBuffer({ size: 32 })
100
- .length.should.equal(32)
101
- })
102
- })
103
-
104
- describe('#getY', function () {
105
- it('should return a Bn', function () {
106
- const p = new Point()
107
- ;(p.getY() instanceof Bn).should.equal(true)
108
- })
109
-
110
- it('should return 0', function () {
111
- const p = new Point()
112
- p
113
- .getY()
114
- .toString()
115
- .should.equal('0')
116
- })
117
-
118
- it('should be convertable to a buffer', function () {
119
- const p = new Point()
120
- p
121
- .getY()
122
- .toBuffer({ size: 32 })
123
- .length.should.equal(32)
124
- })
125
- })
126
-
127
- describe('#add', function () {
128
- it('should get back a point', function () {
129
- const p1 = Point.getG()
130
- const p2 = Point.getG()
131
- const p3 = p1.add(p2)
132
- ;(p3 instanceof Point).should.equal(true)
133
- })
134
-
135
- it('should accurately add g to itself', function () {
136
- const p1 = Point.getG()
137
- const p2 = Point.getG()
138
- const p3 = p1.add(p2)
139
- p3
140
- .getX()
141
- .toString()
142
- .should.equal(
143
- '89565891926547004231252920425935692360644145829622209833684329913297188986597'
144
- )
145
- p3
146
- .getY()
147
- .toString()
148
- .should.equal(
149
- '12158399299693830322967808612713398636155367887041628176798871954788371653930'
150
- )
151
- })
152
- })
153
-
154
- describe('#mul', function () {
155
- it('should get back a point', function () {
156
- const g = Point.getG()
157
- const b = g.mul(new Bn(2))
158
- ;(b instanceof Point).should.equal(true)
159
- })
160
-
161
- it('should accurately multiply g by 2', function () {
162
- const g = Point.getG()
163
- const b = g.mul(new Bn(2))
164
- b
165
- .getX()
166
- .toString()
167
- .should.equal(
168
- '89565891926547004231252920425935692360644145829622209833684329913297188986597'
169
- )
170
- b
171
- .getY()
172
- .toString()
173
- .should.equal(
174
- '12158399299693830322967808612713398636155367887041628176798871954788371653930'
175
- )
176
- })
177
-
178
- it('should accurately multiply g by n-1', function () {
179
- const g = Point.getG()
180
- const n = Point.getN()
181
- const b = g.mul(n.sub(1))
182
- b
183
- .getX()
184
- .toString()
185
- .should.equal(
186
- '55066263022277343669578718895168534326250603453777594175500187360389116729240'
187
- )
188
- b
189
- .getY()
190
- .toString()
191
- .should.equal(
192
- '83121579216557378445487899878180864668798711284981320763518679672151497189239'
193
- )
194
- })
195
-
196
- it('should accurate multiply these problematic values related to a bug in bn.js', function () {
197
- // see these discussions:
198
- // https://github.com/bitpay/bitcore/pull/894
199
- // https://github.com/indutny/elliptic/issues/17
200
- // https://github.com/indutny/elliptic/pull/18
201
- // https://github.com/indutny/elliptic/pull/19
202
- // https://github.com/indutny/bn.js/commit/3557d780b07ed0ed301e128f326f83c2226fb679
203
- ;(function () {
204
- const nhex =
205
- '6d1229a6b24c2e775c062870ad26bc261051e0198c67203167273c7c62538846'
206
- const n = new Bn(nhex, 16)
207
- const g1 = Point.getG() // precomputed g
208
- const g2 = new Point().fromX(
209
- false,
210
- new Bn(
211
- '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
212
- 16
213
- )
214
- ) // non-precomputed g
215
- const p1 = g1.mul(n)
216
- const p2 = g2.mul(n)
217
- const pxhex =
218
- 'd6106302d2698d6a41e9c9a114269e7be7c6a0081317de444bb2980bf9265a01'
219
- const pyhex =
220
- 'e05fb262e64b108991a29979809fcef9d3e70cafceb3248c922c17d83d66bc9d'
221
- p1
222
- .getX()
223
- .toBuffer()
224
- .toString('hex')
225
- .should.equal(pxhex)
226
- p1
227
- .getY()
228
- .toBuffer()
229
- .toString('hex')
230
- .should.equal(pyhex)
231
- p2
232
- .getX()
233
- .toBuffer()
234
- .toString('hex')
235
- .should.equal(pxhex)
236
- p2
237
- .getY()
238
- .toBuffer()
239
- .toString('hex')
240
- .should.equal(pyhex)
241
- })()
242
- ;(function () {
243
- const nhex =
244
- 'f2cc9d2b008927db94b89e04e2f6e70c180e547b3e5e564b06b8215d1c264b53'
245
- const n = new Bn(nhex, 16)
246
- const g1 = Point.getG() // precomputed g
247
- const g2 = new Point().fromX(
248
- false,
249
- new Bn(
250
- '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
251
- 16
252
- )
253
- ) // non-precomputed g
254
- const p1 = g1.mul(n)
255
- const p2 = g2.mul(n)
256
- const pxhex =
257
- 'e275faa35bd1e88f5df6e8f9f6edb93bdf1d65f4915efc79fd7a726ec0c21700'
258
- const pyhex =
259
- '367216cb35b086e6686d69dddd822a8f4d52eb82ac5d9de18fdcd9bf44fa7df7'
260
- p1
261
- .getX()
262
- .toBuffer()
263
- .toString('hex')
264
- .should.equal(pxhex)
265
- p1
266
- .getY()
267
- .toBuffer()
268
- .toString('hex')
269
- .should.equal(pyhex)
270
- p2
271
- .getX()
272
- .toBuffer()
273
- .toString('hex')
274
- .should.equal(pxhex)
275
- p2
276
- .getY()
277
- .toBuffer()
278
- .toString('hex')
279
- .should.equal(pyhex)
280
- })()
281
- })
282
- })
283
-
284
- describe('#mulAdd', function () {
285
- it('should get back a point', function () {
286
- const p1 = Point.getG()
287
- const bn1 = new Bn(5)
288
- const p2 = Point.getG().add(p1)
289
- const bn2 = new Bn(6)
290
- p1
291
- .mulAdd(bn1, p2, bn2)
292
- .getX()
293
- .toString()
294
- .should.equal(
295
- p1
296
- .mul(bn1)
297
- .add(p2.mul(bn2))
298
- .getX()
299
- .toString()
300
- )
301
- p1
302
- .mulAdd(bn1, p2, bn2)
303
- .getY()
304
- .toString()
305
- .should.equal(
306
- p1
307
- .mul(bn1)
308
- .add(p2.mul(bn2))
309
- .getY()
310
- .toString()
311
- )
312
- })
313
- })
314
-
315
- describe('@getN', function () {
316
- it('should return n', function () {
317
- const bn = Point.getN()
318
- ;(bn instanceof Bn).should.equal(true)
319
- })
320
- })
321
-
322
- describe('@fromX', function () {
323
- it('should return g', function () {
324
- const g = Point.getG()
325
- const p = Point.fromX(false, g.getX())
326
- g.eq(p).should.equal(true)
327
- })
328
- })
329
-
330
- describe('#fromX', function () {
331
- it('should return g', function () {
332
- const g = Point.getG()
333
- const p = new Point().fromX(false, g.getX())
334
- g.eq(p).should.equal(true)
335
- })
336
- })
337
-
338
- describe('#validate', function () {
339
- it('should validate this valid point', function () {
340
- const x = new Bn().fromBuffer(
341
- Buffer.from(
342
- 'ac242d242d23be966085a2b2b893d989f824e06c9ad0395a8a52f055ba39abb2',
343
- 'hex'
344
- )
345
- )
346
- const y = new Bn().fromBuffer(
347
- Buffer.from(
348
- '4836ab292c105a711ed10fcfd30999c31ff7c02456147747e03e739ad527c380',
349
- 'hex'
350
- )
351
- )
352
- const p = new Point(x, y)
353
- should.exist(p.validate())
354
- })
355
-
356
- it('should invalidate this invalid point', function () {
357
- const x = new Bn().fromBuffer(
358
- Buffer.from(
359
- 'ac242d242d23be966085a2b2b893d989f824e06c9ad0395a8a52f055ba39abb2',
360
- 'hex'
361
- )
362
- )
363
- const y = new Bn().fromBuffer(
364
- Buffer.from(
365
- '0000000000000000000000000000000000000000000000000000000000000000',
366
- 'hex'
367
- )
368
- )
369
- const p = new Point(x, y)
370
- ;(function () {
371
- p.validate()
372
- }.should.throw('Invalid y value of public key'))
373
- })
374
- })
375
- })
package/test/priv-key.js DELETED
@@ -1,264 +0,0 @@
1
- /* global describe,it */
2
- 'use strict'
3
- import { PrivKey } from '../lib/priv-key'
4
- import { Bn } from '../lib/bn'
5
- import { Point } from '../lib/point'
6
- import should from 'should'
7
-
8
- describe('PrivKey', function () {
9
- const hex = '96c132224121b509b7d0a16245e957d9192609c5637c6228311287b1be21627a'
10
- const buf = Buffer.from(hex, 'hex')
11
- const enctestnet = 'cSdkPxkAjA4HDr5VHgsebAPDEh9Gyub4HK8UJr2DFGGqKKy4K5sG'
12
- const enctu = '92jJzK4tbURm1C7udQXxeCBvXHoHJstDXRxAMouPG1k1XUaXdsu'
13
- const encmainnet = 'L2Gkw3kKJ6N24QcDuH4XDqt9cTqsKTVNDGz1CRZhk9cq4auDUbJy'
14
- const encmu = '5JxgQaFM1FMd38cd14e3mbdxsdSa9iM2BV6DHBYsvGzxkTNQ7Un'
15
-
16
- it('should satisfy these basic API features', function () {
17
- let privKey = new PrivKey()
18
- should.exist(privKey)
19
- privKey = new PrivKey()
20
- should.exist(privKey)
21
-
22
- new PrivKey().constructor.should.equal(new PrivKey().constructor)
23
- new PrivKey.Testnet().constructor.should.equal(
24
- new PrivKey.Testnet().constructor
25
- )
26
-
27
- PrivKey.Testnet.fromRandom()
28
- .toString()[0]
29
- .should.equal('c')
30
- })
31
-
32
- it('should create a 0 private key with this convenience method', function () {
33
- const bn = new Bn(0)
34
- const privKey = new PrivKey(bn)
35
- privKey.bn.toString().should.equal(bn.toString())
36
- })
37
-
38
- it('should create a mainnet private key', function () {
39
- const privKey = new PrivKey(Bn.fromBuffer(buf), true)
40
- privKey.toString().should.equal(encmainnet)
41
- })
42
-
43
- it('should create an uncompressed testnet private key', function () {
44
- const privKey = new PrivKey.Testnet(Bn.fromBuffer(buf), false)
45
- privKey.toString().should.equal(enctu)
46
- })
47
-
48
- it('should create an uncompressed mainnet private key', function () {
49
- const privKey = new PrivKey(Bn.fromBuffer(buf), false)
50
- privKey.toString().should.equal(encmu)
51
- })
52
-
53
- describe('#fromObject', function () {
54
- it('should set bn', function () {
55
- should.exist(new PrivKey().fromObject({ bn: Bn.fromBuffer(buf) }).bn)
56
- })
57
- })
58
-
59
- describe('#fromJSON', function () {
60
- it('should input this address correctly', function () {
61
- const privKey = new PrivKey()
62
- privKey.fromString(encmu)
63
- const privKey2 = new PrivKey()
64
- privKey2.fromJSON(privKey.toHex())
65
- privKey2.toWif().should.equal(encmu)
66
- })
67
- })
68
-
69
- describe('#toString', function () {
70
- it('should output this address correctly', function () {
71
- const privKey = new PrivKey()
72
- privKey.fromString(encmu)
73
- privKey.toString().should.equal(encmu)
74
- })
75
- })
76
-
77
- describe('#fromRandom', function () {
78
- it('should set bn gt 0 and lt n, and should be compressed', function () {
79
- const privKey = new PrivKey().fromRandom()
80
- privKey.bn.gt(new Bn(0)).should.equal(true)
81
- privKey.bn.lt(Point.getN()).should.equal(true)
82
- privKey.compressed.should.equal(true)
83
- })
84
- })
85
-
86
- describe('@fromRandom', function () {
87
- it('should set bn gt 0 and lt n, and should be compressed', function () {
88
- const privKey = PrivKey.fromRandom()
89
- privKey.bn.gt(new Bn(0)).should.equal(true)
90
- privKey.bn.lt(Point.getN()).should.equal(true)
91
- privKey.compressed.should.equal(true)
92
- })
93
- })
94
-
95
- describe('#toHex', function () {
96
- it('should return a hex string', function () {
97
- const privKey = new PrivKey().fromBn(new Bn(5))
98
- privKey
99
- .toHex()
100
- .should.equal(
101
- '80000000000000000000000000000000000000000000000000000000000000000501'
102
- )
103
- })
104
- })
105
-
106
- describe('#toBuffer', function () {
107
- it('should return a buffer', function () {
108
- const privKey = new PrivKey().fromBn(new Bn(5))
109
- privKey
110
- .toBuffer()
111
- .toString('hex')
112
- .should.equal(
113
- '80000000000000000000000000000000000000000000000000000000000000000501'
114
- )
115
- })
116
- })
117
-
118
- describe('#fromHex', function () {
119
- it('should return a hex string', function () {
120
- const privKey = new PrivKey().fromHex(
121
- '80000000000000000000000000000000000000000000000000000000000000000501'
122
- )
123
- privKey
124
- .toHex()
125
- .should.equal(
126
- '80000000000000000000000000000000000000000000000000000000000000000501'
127
- )
128
- })
129
- })
130
-
131
- describe('#fromBuffer', function () {
132
- it('should return a buffer', function () {
133
- const privKey = new PrivKey().fromBuffer(
134
- Buffer.from(
135
- '80000000000000000000000000000000000000000000000000000000000000000501',
136
- 'hex'
137
- )
138
- )
139
- privKey
140
- .toBuffer()
141
- .toString('hex')
142
- .should.equal(
143
- '80000000000000000000000000000000000000000000000000000000000000000501'
144
- )
145
- })
146
-
147
- it('should throw an error if buffer is wrong length', function () {
148
- ;(function () {
149
- new PrivKey().fromBuffer(
150
- Buffer.from(
151
- '8000000000000000000000000000000000000000000000000000000000000000050100',
152
- 'hex'
153
- )
154
- )
155
- }.should.throw(
156
- 'Length of privKey buffer must be 33 (uncompressed pubKey) or 34 (compressed pubKey)'
157
- ))
158
- ;(function () {
159
- new PrivKey().fromBuffer(
160
- Buffer.from(
161
- '8000000000000000000000000000000000000000000000000000000000000005',
162
- 'hex'
163
- )
164
- )
165
- }.should.throw(
166
- 'Length of privKey buffer must be 33 (uncompressed pubKey) or 34 (compressed pubKey)'
167
- ))
168
- })
169
-
170
- it('should throw an error if buffer has wrong versionByteNum byte', function () {
171
- ;(function () {
172
- new PrivKey().fromBuffer(
173
- Buffer.from(
174
- '90000000000000000000000000000000000000000000000000000000000000000501',
175
- 'hex'
176
- )
177
- )
178
- }.should.throw('Invalid versionByteNum byte'))
179
- })
180
- })
181
-
182
- describe('#toBn', function () {
183
- it('should return a bn', function () {
184
- const privKey = new PrivKey().fromBn(new Bn(5))
185
- privKey
186
- .toBn()
187
- .eq(new Bn(5))
188
- .should.equal(true)
189
- })
190
- })
191
-
192
- describe('#fromBn', function () {
193
- it('should create a privKey from a bignum', function () {
194
- const privKey = new PrivKey().fromBn(new Bn(5))
195
- privKey.bn.toString().should.equal('5')
196
- })
197
- })
198
-
199
- describe('@fromBn', function () {
200
- it('should create a privKey from a bignum', function () {
201
- const privKey = PrivKey.fromBn(new Bn(5))
202
- privKey.bn.toString().should.equal('5')
203
- })
204
- })
205
-
206
- describe('#validate', function () {
207
- it('should unvalidate these privKeys', function () {
208
- const privKey = new PrivKey()
209
- privKey.compressed = true
210
- privKey.bn = Point.getN()
211
- ;(function () {
212
- privKey.validate()
213
- }.should.throw('Number must be less than N'))
214
- privKey.bn = Point.getN().sub(1)
215
- privKey.compressed = undefined
216
- ;(function () {
217
- privKey.validate()
218
- }.should.throw(
219
- 'Must specify whether the corresponding public key is compressed or not (true or false)'
220
- ))
221
- privKey.compressed = true
222
- privKey.validate().should.equal(privKey)
223
- })
224
- })
225
-
226
- describe('#fromWif', function () {
227
- it('should parse this compressed testnet address correctly', function () {
228
- const privKey = new PrivKey()
229
- privKey.fromWif(encmainnet)
230
- privKey.toWif().should.equal(encmainnet)
231
- })
232
- })
233
-
234
- describe('@fromWif', function () {
235
- it('should parse this compressed testnet address correctly', function () {
236
- const privKey = PrivKey.fromWif(encmainnet)
237
- privKey.toWif().should.equal(encmainnet)
238
- })
239
- })
240
-
241
- describe('#toWif', function () {
242
- it('should parse this compressed testnet address correctly', function () {
243
- const privKey = new PrivKey.Testnet()
244
- privKey.fromWif(enctestnet)
245
- privKey.toWif().should.equal(enctestnet)
246
- })
247
- })
248
-
249
- describe('#fromString', function () {
250
- it('should parse this uncompressed testnet address correctly', function () {
251
- const privKey = new PrivKey.Testnet()
252
- privKey.fromString(enctu)
253
- privKey.toWif().should.equal(enctu)
254
- })
255
- })
256
-
257
- describe('#toString', function () {
258
- it('should parse this uncompressed mainnet address correctly', function () {
259
- const privKey = new PrivKey()
260
- privKey.fromString(encmu)
261
- privKey.toString().should.equal(encmu)
262
- })
263
- })
264
- })