bsv2 2.0.24 → 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 (170) hide show
  1. package/dist/bsv2.mjs +36061 -4
  2. package/package.json +35 -39
  3. package/.babelrc.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/benchmark.js +0 -50
  12. package/bin/bsv.js +0 -11
  13. package/bin/network.js +0 -92
  14. package/build/index.html +0 -20
  15. package/dist/bsv2.bundle.js +0 -8
  16. package/dist/bsv2.cjs.js +0 -2
  17. package/dist/bsv2.cjs.js.LICENSE.txt +0 -1
  18. package/dist/bsv2.module.js +0 -2
  19. package/entry.js +0 -82
  20. package/index.js +0 -102
  21. package/karma.conf.js +0 -78
  22. package/lib/ach.js +0 -59
  23. package/lib/address.js +0 -264
  24. package/lib/aes.js +0 -57
  25. package/lib/aescbc.js +0 -38
  26. package/lib/base-58-check.js +0 -83
  27. package/lib/base-58.js +0 -59
  28. package/lib/bip-32.js +0 -472
  29. package/lib/bip-39-en-wordlist.js +0 -2054
  30. package/lib/bip-39-en.js +0 -10
  31. package/lib/bip-39-es-wordlist.js +0 -2055
  32. package/lib/bip-39-es.js +0 -10
  33. package/lib/bip-39-jp-wordlist.js +0 -2053
  34. package/lib/bip-39-jp.js +0 -10
  35. package/lib/bip-39-words.js +0 -5
  36. package/lib/bip-39.js +0 -285
  37. package/lib/block-header.js +0 -79
  38. package/lib/block.js +0 -132
  39. package/lib/bn.js +0 -467
  40. package/lib/br.js +0 -172
  41. package/lib/bsm.js +0 -127
  42. package/lib/bw.js +0 -188
  43. package/lib/cbc.js +0 -140
  44. package/lib/cmp.js +0 -37
  45. package/lib/config.js +0 -50
  46. package/lib/constants.js +0 -150
  47. package/lib/ecdsa.js +0 -495
  48. package/lib/ecies.js +0 -151
  49. package/lib/hash-cache.js +0 -41
  50. package/lib/hash.js +0 -191
  51. package/lib/interp.js +0 -2013
  52. package/lib/inv.js +0 -49
  53. package/lib/key-pair.js +0 -133
  54. package/lib/mainnet-address.js +0 -5
  55. package/lib/mainnet-bip-32.js +0 -5
  56. package/lib/mainnet-key-pair.js +0 -5
  57. package/lib/mainnet-priv-key.js +0 -5
  58. package/lib/merkle.js +0 -92
  59. package/lib/msg.js +0 -184
  60. package/lib/op-code.js +0 -398
  61. package/lib/point.js +0 -134
  62. package/lib/priv-key.js +0 -157
  63. package/lib/pub-key.js +0 -230
  64. package/lib/random.js +0 -28
  65. package/lib/script.js +0 -826
  66. package/lib/sig-operations.js +0 -120
  67. package/lib/sig.js +0 -399
  68. package/lib/struct.js +0 -389
  69. package/lib/testnet-address.js +0 -5
  70. package/lib/testnet-bip-32.js +0 -5
  71. package/lib/testnet-key-pair.js +0 -5
  72. package/lib/testnet-priv-key.js +0 -5
  73. package/lib/tx-builder.js +0 -593
  74. package/lib/tx-in.js +0 -172
  75. package/lib/tx-out-map.js +0 -57
  76. package/lib/tx-out.js +0 -73
  77. package/lib/tx-verifier.js +0 -209
  78. package/lib/tx.js +0 -430
  79. package/lib/var-int.js +0 -73
  80. package/lib/version.js +0 -92
  81. package/lib/workers-result.js +0 -65
  82. package/lib/workers.js +0 -77
  83. package/load-babel.js +0 -3
  84. package/mtest/test.html +0 -15
  85. package/mtest/test.js +0 -2
  86. package/mtest/test.mjs +0 -2
  87. package/test/ach.js +0 -172
  88. package/test/address.js +0 -464
  89. package/test/aes.js +0 -96
  90. package/test/aescbc.js +0 -65
  91. package/test/base-58-check.js +0 -128
  92. package/test/base-58.js +0 -113
  93. package/test/bip-32.js +0 -721
  94. package/test/bip-39.js +0 -282
  95. package/test/block-header.js +0 -152
  96. package/test/block.js +0 -243
  97. package/test/bn.js +0 -643
  98. package/test/br.js +0 -353
  99. package/test/bsm.js +0 -141
  100. package/test/bw.js +0 -292
  101. package/test/cbc.js +0 -335
  102. package/test/cmp.js +0 -56
  103. package/test/data/bip69.json +0 -215
  104. package/test/data/bitcoind/base58_keys_invalid.json +0 -152
  105. package/test/data/bitcoind/base58_keys_valid.json +0 -452
  106. package/test/data/bitcoind/blocks.json +0 -27
  107. package/test/data/bitcoind/script_tests.json +0 -2244
  108. package/test/data/bitcoind/sig_canonical.json +0 -7
  109. package/test/data/bitcoind/sig_noncanonical.json +0 -22
  110. package/test/data/bitcoind/tx_invalid.json +0 -177
  111. package/test/data/bitcoind/tx_valid.json +0 -224
  112. package/test/data/blk86756-testnet.dat +0 -0
  113. package/test/data/blk86756-testnet.js +0 -12
  114. package/test/data/blk86756-testnet.json +0 -684
  115. package/test/data/ecdsa.json +0 -230
  116. package/test/data/messages.json +0 -22
  117. package/test/data/sighash.json +0 -1004
  118. package/test/data/tx_creation.json +0 -85
  119. package/test/ecdsa.js +0 -748
  120. package/test/ecies.js +0 -238
  121. package/test/global.js +0 -13
  122. package/test/hash-cache.js +0 -52
  123. package/test/hash.js +0 -354
  124. package/test/index.js +0 -10
  125. package/test/interp.js +0 -512
  126. package/test/inv.js +0 -65
  127. package/test/key-pair.js +0 -243
  128. package/test/merkle.js +0 -179
  129. package/test/msg.js +0 -295
  130. package/test/op-code.js +0 -79
  131. package/test/point.js +0 -375
  132. package/test/priv-key.js +0 -264
  133. package/test/pub-key.js +0 -549
  134. package/test/random.js +0 -31
  135. package/test/script.js +0 -1340
  136. package/test/sig-operations.js +0 -149
  137. package/test/sig.js +0 -662
  138. package/test/struct.js +0 -552
  139. package/test/tx-builder.js +0 -2104
  140. package/test/tx-in.js +0 -198
  141. package/test/tx-out-map.js +0 -104
  142. package/test/tx-out.js +0 -162
  143. package/test/tx-verifier.js +0 -246
  144. package/test/tx.js +0 -539
  145. package/test/var-int.js +0 -132
  146. package/test/vectors/aes.json +0 -10392
  147. package/test/vectors/aescbc.json +0 -620
  148. package/test/vectors/bip39.json +0 -502
  149. package/test/vectors/bip69.json +0 -215
  150. package/test/vectors/bitcoin-abc/script_tests.json +0 -48
  151. package/test/vectors/bitcoin-abc/sighash.json +0 -7004
  152. package/test/vectors/bitcoin-sv/script_tests.json +0 -248
  153. package/test/vectors/bitcoind/script_invalid.json +0 -1151
  154. package/test/vectors/bitcoind/script_valid.json +0 -1462
  155. package/test/vectors/bitcoind/sighash.json +0 -3503
  156. package/test/vectors/bitcoind/tx_invalid.json +0 -883
  157. package/test/vectors/bitcoind/tx_valid.json +0 -1150
  158. package/test/vectors/coolest-tx-ever-sent.json +0 -8
  159. package/test/vectors/ecdsa.json +0 -300
  160. package/test/vectors/hash.json +0 -6133
  161. package/test/vectors/kdf.json +0 -47
  162. package/test/vectors/largesttx.json +0 -5
  163. package/test/vectors/largesttxblock.json +0 -6
  164. package/test/vectors/sig.json +0 -79
  165. package/test/vectors/sighash-single-bug.json +0 -8
  166. package/test/version.js +0 -81
  167. package/test/workers-result.js +0 -89
  168. package/test/workers.js +0 -91
  169. package/test-index.js +0 -3
  170. package/webpack.config.js +0 -115
package/test/pub-key.js DELETED
@@ -1,549 +0,0 @@
1
- /* global describe,it */
2
- 'use strict'
3
- import { Bn } from '../lib/bn'
4
- import { Point } from '../lib/point'
5
- import { PrivKey } from '../lib/priv-key'
6
- import { PubKey } from '../lib/pub-key'
7
- import should from 'should'
8
-
9
- describe('PubKey', function () {
10
- it('should create a blank public key', function () {
11
- const pk = new PubKey()
12
- should.exist(pk)
13
- })
14
-
15
- it('should create a public key with a point', function () {
16
- const p = new Point()
17
- const pk = new PubKey({ point: p })
18
- should.exist(pk.point)
19
- })
20
-
21
- it('should create a public key with a point with this convenient method', function () {
22
- const p = new Point()
23
- const pk = new PubKey(p)
24
- should.exist(pk.point)
25
- pk.point.toString().should.equal(p.toString())
26
- })
27
-
28
- describe('#fromObject', function () {
29
- it('should make a public key from a point', function () {
30
- should.exist(new PubKey().fromObject({ point: Point.getG() }).point)
31
- })
32
- })
33
-
34
- describe('#fromJSON', function () {
35
- it('should input this public key', function () {
36
- const pk = new PubKey()
37
- pk.fromJSON(
38
- '00041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
39
- )
40
- pk.point
41
- .getX()
42
- .toString(16)
43
- .should.equal(
44
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
45
- )
46
- pk.point
47
- .getY()
48
- .toString(16)
49
- .should.equal(
50
- '7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
51
- )
52
- })
53
- })
54
-
55
- describe('#toJSON', function () {
56
- it('should output this pubKey', function () {
57
- const pk = new PubKey()
58
- const hex =
59
- '01041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
60
- pk
61
- .fromJSON(hex)
62
- .toJSON()
63
- .should.equal(hex)
64
- })
65
-
66
- it('should output this uncompressed pubKey', function () {
67
- const pk = new PubKey()
68
- const hex =
69
- '00041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
70
- pk
71
- .fromJSON(hex)
72
- .toJSON()
73
- .should.equal(hex)
74
- })
75
- })
76
-
77
- describe('#fromPrivKey', function () {
78
- it('should make a public key from a privKey', function () {
79
- should.exist(new PubKey().fromPrivKey(new PrivKey().fromRandom()))
80
- })
81
- })
82
-
83
- describe('@fromPrivKey', function () {
84
- it('should make a public key from a privKey', function () {
85
- should.exist(PubKey.fromPrivKey(new PrivKey().fromRandom()))
86
- })
87
- })
88
-
89
- describe('#asyncFromPrivKey', function () {
90
- it('should result the same as fromPrivKey', async function () {
91
- const privKey = new PrivKey().fromRandom()
92
- const pubKey1 = new PubKey().fromPrivKey(privKey)
93
- const pubKey2 = await new PubKey().asyncFromPrivKey(privKey)
94
- pubKey1.toString().should.equal(pubKey2.toString())
95
- })
96
-
97
- it('should result the same as fromPrivKey', async function () {
98
- const privKey = new PrivKey().fromBn(new Bn(5))
99
- const pubKey1 = new PubKey().fromPrivKey(privKey)
100
- const pubKey2 = await new PubKey().asyncFromPrivKey(privKey)
101
- pubKey1.toString().should.equal(pubKey2.toString())
102
- })
103
- })
104
-
105
- describe('@asyncFromPrivKey', function () {
106
- it('should result the same as fromPrivKey', async function () {
107
- const privKey = new PrivKey().fromRandom()
108
- const pubKey1 = PubKey.fromPrivKey(privKey)
109
- const pubKey2 = await PubKey.asyncFromPrivKey(privKey)
110
- pubKey1.toString().should.equal(pubKey2.toString())
111
- })
112
-
113
- it('should result the same as fromPrivKey', async function () {
114
- const privKey = new PrivKey().fromBn(new Bn(5))
115
- const pubKey1 = PubKey.fromPrivKey(privKey)
116
- const pubKey2 = await PubKey.asyncFromPrivKey(privKey)
117
- pubKey1.toString().should.equal(pubKey2.toString())
118
- })
119
- })
120
-
121
- describe('#fromHex', function () {
122
- it('should parse this uncompressed public key', function () {
123
- const pk = new PubKey()
124
- pk.fromHex(
125
- '041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
126
- )
127
- pk.point
128
- .getX()
129
- .toString(16)
130
- .should.equal(
131
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
132
- )
133
- pk.point
134
- .getY()
135
- .toString(16)
136
- .should.equal(
137
- '7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
138
- )
139
- })
140
- })
141
-
142
- describe('#fromBuffer', function () {
143
- it('should parse this uncompressed public key', function () {
144
- const pk = new PubKey()
145
- pk.fromBuffer(
146
- Buffer.from(
147
- '041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341',
148
- 'hex'
149
- )
150
- )
151
- pk.point
152
- .getX()
153
- .toString(16)
154
- .should.equal(
155
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
156
- )
157
- pk.point
158
- .getY()
159
- .toString(16)
160
- .should.equal(
161
- '7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
162
- )
163
- })
164
-
165
- it('should parse this compressed public key', function () {
166
- const pk = new PubKey()
167
- pk.fromBuffer(
168
- Buffer.from(
169
- '031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
170
- 'hex'
171
- )
172
- )
173
- pk.point
174
- .getX()
175
- .toString(16)
176
- .should.equal(
177
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
178
- )
179
- pk.point
180
- .getY()
181
- .toString(16)
182
- .should.equal(
183
- '7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
184
- )
185
- })
186
-
187
- it('should throw an error on this invalid public key', function () {
188
- const pk = new PubKey()
189
- ;(function () {
190
- pk.fromBuffer(
191
- Buffer.from(
192
- '091ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
193
- 'hex'
194
- )
195
- )
196
- }.should.throw())
197
- })
198
- })
199
-
200
- describe('#asyncFromBuffer', function () {
201
- it('should derive the same as fromBuffer', async function () {
202
- const pubKey = new PubKey().fromPrivKey(new PrivKey().fromRandom())
203
- const pubKey1 = new PubKey().fromBuffer(pubKey.toBuffer())
204
- const pubKey2 = await new PubKey().asyncFromBuffer(pubKey.toBuffer())
205
- pubKey1.toString().should.equal(pubKey2.toString())
206
- })
207
- })
208
-
209
- describe('@asyncFromBuffer', function () {
210
- it('should derive the same as fromBuffer', async function () {
211
- const pubKey = PubKey.fromPrivKey(new PrivKey().fromRandom())
212
- const pubKey1 = PubKey.fromBuffer(pubKey.toBuffer())
213
- const pubKey2 = await PubKey.asyncFromBuffer(pubKey.toBuffer())
214
- pubKey1.toString().should.equal(pubKey2.toString())
215
- })
216
- })
217
-
218
- describe('#fromFastBuffer', function () {
219
- it('should convert from this known fast buffer', function () {
220
- const pubKey = new PubKey().fromFastBuffer(
221
- Buffer.from(
222
- '01041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341',
223
- 'hex'
224
- )
225
- )
226
- pubKey.point
227
- .getX()
228
- .toString(16)
229
- .should.equal(
230
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
231
- )
232
- })
233
- })
234
-
235
- describe('#fromDer', function () {
236
- it('should parse this uncompressed public key', function () {
237
- const pk = new PubKey()
238
- pk.fromDer(
239
- Buffer.from(
240
- '041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341',
241
- 'hex'
242
- )
243
- )
244
- pk.point
245
- .getX()
246
- .toString(16)
247
- .should.equal(
248
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
249
- )
250
- pk.point
251
- .getY()
252
- .toString(16)
253
- .should.equal(
254
- '7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
255
- )
256
- })
257
-
258
- it('should parse this compressed public key', function () {
259
- const pk = new PubKey()
260
- pk.fromDer(
261
- Buffer.from(
262
- '031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
263
- 'hex'
264
- )
265
- )
266
- pk.point
267
- .getX()
268
- .toString(16)
269
- .should.equal(
270
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
271
- )
272
- pk.point
273
- .getY()
274
- .toString(16)
275
- .should.equal(
276
- '7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
277
- )
278
- })
279
-
280
- it('should throw an error on this invalid public key', function () {
281
- const pk = new PubKey()
282
- ;(function () {
283
- pk.fromDer(
284
- Buffer.from(
285
- '091ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
286
- 'hex'
287
- )
288
- )
289
- }.should.throw())
290
- })
291
- })
292
-
293
- describe('@fromDer', function () {
294
- it('should parse this uncompressed public key', function () {
295
- const pk = PubKey.fromDer(
296
- Buffer.from(
297
- '041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341',
298
- 'hex'
299
- )
300
- )
301
- pk.point
302
- .getX()
303
- .toString(16)
304
- .should.equal(
305
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
306
- )
307
- pk.point
308
- .getY()
309
- .toString(16)
310
- .should.equal(
311
- '7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
312
- )
313
- })
314
-
315
- it('should parse this compressed public key', function () {
316
- const pk = PubKey.fromDer(
317
- Buffer.from(
318
- '031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
319
- 'hex'
320
- )
321
- )
322
- pk.point
323
- .getX()
324
- .toString(16)
325
- .should.equal(
326
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
327
- )
328
- pk.point
329
- .getY()
330
- .toString(16)
331
- .should.equal(
332
- '7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
333
- )
334
- })
335
-
336
- it('should throw an error on this invalid public key', function () {
337
- ;(function () {
338
- PubKey.fromDer(
339
- Buffer.from(
340
- '091ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
341
- 'hex'
342
- )
343
- )
344
- }.should.throw())
345
- })
346
- })
347
-
348
- describe('#fromString', function () {
349
- it('should parse this known valid public key', function () {
350
- const pk = new PubKey()
351
- pk.fromString(
352
- '041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
353
- )
354
- pk.point
355
- .getX()
356
- .toString(16)
357
- .should.equal(
358
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
359
- )
360
- pk.point
361
- .getY()
362
- .toString(16)
363
- .should.equal(
364
- '7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
365
- )
366
- })
367
- })
368
-
369
- describe('#fromX', function () {
370
- it('should create this known public key', function () {
371
- const x = Bn.fromBuffer(
372
- Buffer.from(
373
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
374
- 'hex'
375
- )
376
- )
377
- const pk = new PubKey()
378
- pk.fromX(true, x)
379
- pk.point
380
- .getX()
381
- .toString(16)
382
- .should.equal(
383
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
384
- )
385
- pk.point
386
- .getY()
387
- .toString(16)
388
- .should.equal(
389
- '7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
390
- )
391
- })
392
- })
393
-
394
- describe('@fromX', function () {
395
- it('should create this known public key', function () {
396
- const x = Bn.fromBuffer(
397
- Buffer.from(
398
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
399
- 'hex'
400
- )
401
- )
402
- const pk = new PubKey()
403
- pk.fromX(true, x)
404
- pk.point
405
- .getX()
406
- .toString(16)
407
- .should.equal(
408
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
409
- )
410
- pk.point
411
- .getY()
412
- .toString(16)
413
- .should.equal(
414
- '7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
415
- )
416
- })
417
- })
418
-
419
- describe('#toHex', function () {
420
- it('should return this compressed DER format', function () {
421
- const x = new Bn().fromHex(
422
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
423
- )
424
- const pk = new PubKey()
425
- pk.fromX(true, x)
426
- pk
427
- .toHex()
428
- .should.equal(
429
- '031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
430
- )
431
- })
432
- })
433
-
434
- describe('#toBuffer', function () {
435
- it('should return this compressed DER format', function () {
436
- const x = Bn.fromBuffer(
437
- Buffer.from(
438
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
439
- 'hex'
440
- )
441
- )
442
- const pk = new PubKey()
443
- pk.fromX(true, x)
444
- pk
445
- .toBuffer()
446
- .toString('hex')
447
- .should.equal(
448
- '031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
449
- )
450
- })
451
- })
452
-
453
- describe('#toFastBuffer', function () {
454
- it('should return fast buffer', function () {
455
- const x = Bn.fromBuffer(
456
- Buffer.from(
457
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
458
- 'hex'
459
- )
460
- )
461
- const pk = new PubKey()
462
- pk.fromX(true, x)
463
- pk
464
- .toFastBuffer()
465
- .toString('hex')
466
- .should.equal(
467
- '01041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
468
- )
469
- pk.toFastBuffer().length.should.greaterThan(64)
470
- })
471
- })
472
-
473
- describe('#toDer', function () {
474
- it('should return this compressed DER format', function () {
475
- const x = Bn.fromBuffer(
476
- Buffer.from(
477
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
478
- 'hex'
479
- )
480
- )
481
- const pk = new PubKey()
482
- pk.fromX(true, x)
483
- pk
484
- .toDer(true)
485
- .toString('hex')
486
- .should.equal(
487
- '031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
488
- )
489
- })
490
-
491
- it('should return this uncompressed DER format', function () {
492
- const x = Bn.fromBuffer(
493
- Buffer.from(
494
- '1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
495
- 'hex'
496
- )
497
- )
498
- const pk = new PubKey()
499
- pk.fromX(true, x)
500
- pk
501
- .toDer(false)
502
- .toString('hex')
503
- .should.equal(
504
- '041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
505
- )
506
- })
507
- })
508
-
509
- describe('#toString', function () {
510
- it('should print this known public key', function () {
511
- const hex =
512
- '031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
513
- const pk = new PubKey()
514
- pk.fromString(hex)
515
- pk.toString().should.equal(hex)
516
- })
517
- })
518
-
519
- describe('#validate', function () {
520
- it('should not throw an error if pubKey is valid', function () {
521
- const hex =
522
- '031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
523
- const pk = new PubKey()
524
- pk.fromString(hex)
525
- should.exist(pk.validate())
526
- })
527
-
528
- it('should not throw an error if pubKey is invalid', function () {
529
- const hex =
530
- '041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a0000000000000000000000000000000000000000000000000000000000000000'
531
- const pk = new PubKey()
532
- pk.fromString(hex)
533
- ;(function () {
534
- pk.validate()
535
- }.should.throw('Invalid y value of public key'))
536
- })
537
-
538
- it('should throw an error if pubKey is infinity', function () {
539
- const pk = new PubKey()
540
- let errm = ''
541
- try {
542
- pk.point = Point.getG().mul(Point.getN())
543
- } catch (err) {
544
- errm = err.message
545
- }
546
- errm.should.equal('point mul out of range')
547
- })
548
- })
549
- })
package/test/random.js DELETED
@@ -1,31 +0,0 @@
1
- /* global describe,it */
2
- import { Random } from '../lib/random'
3
- import 'should'
4
-
5
- describe('Random', function () {
6
- describe('@getRandomBuffer', function () {
7
- it('should return a buffer', function () {
8
- const bytes = Random.getRandomBuffer(8)
9
- bytes.length.should.equal(8)
10
- Buffer.isBuffer(bytes).should.equal(true)
11
- })
12
-
13
- it('should not equate two 256 bit random buffers', function () {
14
- const bytes1 = Random.getRandomBuffer(32)
15
- const bytes2 = Random.getRandomBuffer(32)
16
- bytes1.toString('hex').should.not.equal(bytes2.toString('hex'))
17
- })
18
-
19
- it('should generate 100 8 byte buffers in a row that are not equal', function () {
20
- const hexs = []
21
- for (let i = 0; i < 100; i++) {
22
- hexs[i] = Random.getRandomBuffer(8).toString('hex')
23
- }
24
- for (let i = 0; i < 100; i++) {
25
- for (let j = i + 1; j < 100; j++) {
26
- hexs[i].should.not.equal(hexs[j])
27
- }
28
- }
29
- })
30
- })
31
- })