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/address.js DELETED
@@ -1,464 +0,0 @@
1
- /* global describe,it */
2
- 'use strict'
3
- import { Address } from '../lib/address'
4
- import { Constants } from '../lib/constants'
5
- import { PrivKey } from '../lib/priv-key'
6
- import { PubKey } from '../lib/pub-key'
7
- import { Script } from '../lib/script'
8
- import should from 'should'
9
-
10
- describe('Address', function () {
11
- const pubKeyHash = Buffer.from(
12
- '3c3fa3d4adcaf8f52d5b1843975e122548269937',
13
- 'hex'
14
- )
15
- const versionByteNum = 0
16
- const buf = Buffer.concat([Buffer.from([0]), pubKeyHash])
17
- const str = '16VZnHwRhwrExfeHFHGjwrgEMq8VcYPs9r'
18
-
19
- it('should satisfy these basic API features', function () {
20
- let address = new Address()
21
- should.exist(address)
22
- address = new Address()
23
- should.exist(address)
24
- address = new Address(versionByteNum, pubKeyHash)
25
- should.exist(address)
26
- new Address().constructor.should.equal(new Address().constructor)
27
- new Address.Testnet().constructor.should.equal(
28
- new Address.Testnet().constructor
29
- )
30
- const testAddr = Address.Testnet.fromRandom().toString()
31
- ;(testAddr[0] === 'm' || testAddr[0] === 'n').should.equal(true)
32
- })
33
-
34
- describe('@isValid', function () {
35
- it('should validate this valid address string', function () {
36
- Address.isValid(str).should.equal(true)
37
- })
38
-
39
- it('should invalidate this valid address string', function () {
40
- Address.isValid(str.substr(1)).should.equal(false)
41
- })
42
- })
43
-
44
- describe('#fromHex', function () {
45
- it('should make an address from a hex string', function () {
46
- new Address()
47
- .fromHex(buf.toString('hex'))
48
- .toBuffer()
49
- .slice(1)
50
- .toString('hex')
51
- .should.equal(pubKeyHash.toString('hex'))
52
- new Address()
53
- .fromHex(buf.toString('hex'))
54
- .toString()
55
- .should.equal(str)
56
- })
57
- })
58
-
59
- describe('#fromBuffer', function () {
60
- it('should make an address from a buffer', function () {
61
- new Address()
62
- .fromBuffer(buf)
63
- .toBuffer()
64
- .slice(1)
65
- .toString('hex')
66
- .should.equal(pubKeyHash.toString('hex'))
67
- new Address()
68
- .fromBuffer(buf)
69
- .toString()
70
- .should.equal(str)
71
- })
72
-
73
- it('should throw for invalid buffers', function () {
74
- ;(function () {
75
- new Address().fromBuffer(Buffer.concat([buf, Buffer.from([0])]))
76
- }.should.throw('address buffers must be exactly 21 bytes'))
77
- ;(function () {
78
- const buf2 = Buffer.from(buf)
79
- buf2[0] = 50
80
- new Address().fromBuffer(buf2)
81
- }.should.throw('address: invalid versionByteNum byte'))
82
- })
83
- })
84
-
85
- describe('@fromBuffer', function () {
86
- it('should make an address from a buffer', function () {
87
- Address.fromBuffer(buf)
88
- .toBuffer()
89
- .slice(1)
90
- .toString('hex')
91
- .should.equal(pubKeyHash.toString('hex'))
92
- Address.fromBuffer(buf)
93
- .toString()
94
- .should.equal(str)
95
- })
96
-
97
- it('should throw for invalid buffers', function () {
98
- ;(function () {
99
- Address.fromBuffer(Buffer.concat([buf, Buffer.from([0])]))
100
- }.should.throw('address buffers must be exactly 21 bytes'))
101
- ;(function () {
102
- const buf2 = Buffer.from(buf)
103
- buf2[0] = 50
104
- Address.fromBuffer(buf2)
105
- }.should.throw('address: invalid versionByteNum byte'))
106
- })
107
- })
108
-
109
- describe('#fromPubKeyHashBuf', function () {
110
- it('should make an address from a hashBuf', function () {
111
- const buf = Buffer.alloc(20)
112
- buf.fill(0)
113
- const address = new Address().fromPubKeyHashBuf(buf)
114
- address.toString().should.equal('1111111111111111111114oLvT2')
115
- })
116
- })
117
-
118
- describe('@fromPubKeyHashBuf', function () {
119
- it('should make an address from a hashBuf', function () {
120
- const buf = Buffer.alloc(20)
121
- buf.fill(0)
122
- const address = Address.fromPubKeyHashBuf(buf)
123
- address.toString().should.equal('1111111111111111111114oLvT2')
124
- })
125
- })
126
-
127
- describe('#fromPubKey', function () {
128
- it('should make this address from a compressed pubKey', function () {
129
- const pubKey = new PubKey()
130
- pubKey.fromDer(
131
- Buffer.from(
132
- '0285e9737a74c30a873f74df05124f2aa6f53042c2fc0a130d6cbd7d16b944b004',
133
- 'hex'
134
- )
135
- )
136
- const address = new Address()
137
- address.fromPubKey(pubKey)
138
- address.toString().should.equal('19gH5uhqY6DKrtkU66PsZPUZdzTd11Y7ke')
139
- })
140
-
141
- it('should make this address from an uncompressed pubKey', function () {
142
- const pubKey = new PubKey()
143
- pubKey.fromDer(
144
- Buffer.from(
145
- '0285e9737a74c30a873f74df05124f2aa6f53042c2fc0a130d6cbd7d16b944b004',
146
- 'hex'
147
- )
148
- )
149
- const address = new Address()
150
- pubKey.compressed = false
151
- address.fromPubKey(pubKey, 'mainnet')
152
- address.toString().should.equal('16JXnhxjJUhxfyx4y6H4sFcxrgt8kQ8ewX')
153
- })
154
- })
155
-
156
- describe('@fromPubKey', function () {
157
- it('should make this address from a compressed pubKey', function () {
158
- const pubKey = new PubKey()
159
- pubKey.fromDer(
160
- Buffer.from(
161
- '0285e9737a74c30a873f74df05124f2aa6f53042c2fc0a130d6cbd7d16b944b004',
162
- 'hex'
163
- )
164
- )
165
- const address = Address.fromPubKey(pubKey)
166
- address.toString().should.equal('19gH5uhqY6DKrtkU66PsZPUZdzTd11Y7ke')
167
- })
168
-
169
- it('should make this address from an uncompressed pubKey', function () {
170
- const pubKey = new PubKey()
171
- pubKey.fromDer(
172
- Buffer.from(
173
- '0285e9737a74c30a873f74df05124f2aa6f53042c2fc0a130d6cbd7d16b944b004',
174
- 'hex'
175
- )
176
- )
177
- pubKey.compressed = false
178
- const address = Address.fromPubKey(pubKey, 'mainnet')
179
- address.toString().should.equal('16JXnhxjJUhxfyx4y6H4sFcxrgt8kQ8ewX')
180
- })
181
- })
182
-
183
- describe('#asyncFromPubKey', function () {
184
- it('should asynchronously convert pubKey to address same as fromPubKey', async function () {
185
- const pubKey = new PubKey().fromPrivKey(new PrivKey().fromRandom())
186
- const address1 = new Address().fromPubKey(pubKey)
187
- const address2 = await new Address().asyncFromPubKey(pubKey)
188
- address1.toString().should.equal(address2.toString())
189
- })
190
- })
191
-
192
- describe('@asyncFromPubKey', function () {
193
- it('should asynchronously convert pubKey to address same as fromPubKey', async function () {
194
- const pubKey = new PubKey().fromPrivKey(new PrivKey().fromRandom())
195
- const address1 = Address.fromPubKey(pubKey)
196
- const address2 = await Address.asyncFromPubKey(pubKey)
197
- address1.toString().should.equal(address2.toString())
198
- })
199
- })
200
-
201
- describe('#fromPrivKey', function () {
202
- it('should make this address from a compressed pubKey', function () {
203
- const privKey = new PrivKey().fromRandom()
204
- const pubKey = new PubKey().fromPrivKey(privKey)
205
- const address = new Address().fromPrivKey(privKey)
206
- const address2 = new Address().fromPubKey(pubKey)
207
- address.toString().should.equal(address2.toString())
208
- })
209
- })
210
-
211
- describe('@fromPrivKey', function () {
212
- it('should make this address from a compressed pubKey using static method', function () {
213
- const privKey = new PrivKey().fromRandom()
214
- const pubKey = new PubKey().fromPrivKey(privKey)
215
- const address = Address.fromPrivKey(privKey)
216
- const address2 = Address.fromPubKey(pubKey)
217
- address.toString().should.equal(address2.toString())
218
- })
219
- })
220
-
221
- describe('#asyncFromPrivKey', function () {
222
- it('should asynchronously convert privKey to address same as fromPrivKey', async function () {
223
- const privKey = new PrivKey().fromRandom()
224
- const address1 = new Address().fromPrivKey(privKey)
225
- const address2 = await new Address().asyncFromPrivKey(privKey)
226
- address1.toString().should.equal(address2.toString())
227
- })
228
- })
229
-
230
- describe('@asyncFromPrivKey', function () {
231
- it('should asynchronously convert privKey to address same as fromPrivKey', async function () {
232
- const privKey = new PrivKey().fromRandom()
233
- const address1 = Address.fromPrivKey(privKey)
234
- const address2 = await Address.asyncFromPrivKey(privKey)
235
- address1.toString().should.equal(address2.toString())
236
- })
237
- })
238
-
239
- describe('#fromRandom', function () {
240
- it('should make an address from random', function () {
241
- const address = new Address().fromRandom()
242
- should.exist(address)
243
- ;(address instanceof Address).should.equal(true)
244
- })
245
- })
246
-
247
- describe('@fromRandom', function () {
248
- it('should make an address from random using static method', function () {
249
- const address = Address.fromRandom()
250
- should.exist(address)
251
- ;(address instanceof Address).should.equal(true)
252
- })
253
- })
254
-
255
- describe('#asyncFromRandom', function () {
256
- it('should asynchronously make an address from random', async function () {
257
- const address = await new Address().asyncFromRandom()
258
- should.exist(address)
259
- ;(address instanceof Address).should.equal(true)
260
- })
261
- })
262
-
263
- describe('@asyncFromRandom', function () {
264
- it('should asynchronously make an address from random using static method', async function () {
265
- const address = await Address.asyncFromRandom()
266
- should.exist(address)
267
- ;(address instanceof Address).should.equal(true)
268
- })
269
- })
270
-
271
- describe('@fromTxInScript', function () {
272
- it('should make this address from an input script', function () {
273
- const script = Script.fromAsmString('3045022100ff812330880f443637e93ae1045985de38a29e26e4e589db84e86d0f17069f9a02203ed91e19a8cfa5e406bed1becc0e292c89346f9102358317e3238cb394a9ab0b 020536acad4d0763f39718143494811f5c0ffd39f5dc3667cfe3b4a7815b331a17')
274
- const address = Address.fromTxInScript(script)
275
- address.toString().should.equal('1EyV93Vhz4YLdfb67UaNujrBkd9CC6zvgG')
276
- })
277
-
278
- it('should make this address from a zero length public key', function () {
279
- const script = Script.fromAsmString('3045022100ff812330880f443637e93ae1045985de38a29e26e4e589db84e86d0f17069f9a02203ed91e19a8cfa5e406bed1becc0e292c89346f9102358317e3238cb394a9ab0b 0')
280
- const address = Address.fromTxInScript(script)
281
- address.toString().should.equal('1HqoNfpAJFMy9E36DBSk1ktPQ9o9fn2RxX')
282
- })
283
- })
284
-
285
- describe('@fromTxOutScript', function () {
286
- it('should make this address from a script', function () {
287
- Address.fromPubKeyHashBuf(Buffer.from('6fa5502ea094d59576898b490d866b32a61b89f6', 'hex')).toString()
288
- .should.equal('1BBL3TUavUCRauDreKv2JJ1CPgnyNxVHpA')
289
- })
290
-
291
- it('should make an address from a hashBuf', function () {
292
- const buf = Buffer.alloc(20)
293
- buf.fill(0)
294
- let address = new Address().fromPubKeyHashBuf(buf)
295
- const script = address.toTxOutScript()
296
- address = Address.fromTxOutScript(script)
297
- address.toString().should.equal('1111111111111111111114oLvT2')
298
- })
299
- })
300
-
301
- describe('#fromString', function () {
302
- it('should derive from this known address string mainnet', function () {
303
- const address = new Address()
304
- address.fromString(str)
305
- address
306
- .toBuffer()
307
- .slice(1)
308
- .toString('hex')
309
- .should.equal(pubKeyHash.toString('hex'))
310
- })
311
-
312
- it('should derive from this known address string testnet', function () {
313
- const address = new Address.Testnet()
314
- address.fromString('mm1X5M2QWyHVjn7txrF7mmtZDpjCXzoa98')
315
- address.versionByteNum = Constants.Testnet.Address.pubKeyHash
316
- address.fromString(address.toString())
317
- address.toString().should.equal('mm1X5M2QWyHVjn7txrF7mmtZDpjCXzoa98')
318
- })
319
- })
320
-
321
- describe('@fromString', function () {
322
- it('should derive from this known address string mainnet', function () {
323
- const address = Address.fromString(str)
324
- address
325
- .toBuffer()
326
- .slice(1)
327
- .toString('hex')
328
- .should.equal(pubKeyHash.toString('hex'))
329
- })
330
- })
331
-
332
- describe('#asyncFromString', function () {
333
- it('should derive the same as fromString', async function () {
334
- const address1 = new Address().fromString(str)
335
- const address2 = await new Address().asyncFromString(str)
336
- address1.toString().should.equal(address2.toString())
337
- })
338
- })
339
-
340
- describe('@asyncFromString', function () {
341
- it('should derive the same as fromString', async function () {
342
- const address1 = Address.fromString(str)
343
- const address2 = await Address.asyncFromString(str)
344
- address1.toString().should.equal(address2.toString())
345
- })
346
- })
347
-
348
- describe('#isValid', function () {
349
- it('should describe this valid address as valid', function () {
350
- const address = new Address()
351
- address.fromString('1111111111111111111114oLvT2')
352
- address.isValid().should.equal(true)
353
- })
354
-
355
- it('should describe this address with unknown versionByteNum as invalid', function () {
356
- const address = new Address()
357
- address.fromString('1111111111111111111114oLvT2')
358
- address.versionByteNum = 1
359
- address.isValid().should.equal(false)
360
- })
361
- })
362
-
363
- describe('#toHex', function () {
364
- it('should output this known hash', function () {
365
- const address = new Address()
366
- address.fromString(str)
367
- address
368
- .toHex()
369
- .slice(2)
370
- .should.equal(pubKeyHash.toString('hex'))
371
- })
372
- })
373
-
374
- describe('#toBuffer', function () {
375
- it('should output this known hash', function () {
376
- const address = new Address()
377
- address.fromString(str)
378
- address
379
- .toBuffer()
380
- .slice(1)
381
- .toString('hex')
382
- .should.equal(pubKeyHash.toString('hex'))
383
- })
384
- })
385
-
386
- describe('#toJSON', function () {
387
- it('should convert an address to json', function () {
388
- const addrbuf = Buffer.alloc(21)
389
- addrbuf.fill(0)
390
- const address = new Address().fromBuffer(addrbuf)
391
- const json = address.toJSON()
392
- should.exist(json.hashBuf)
393
- json.versionByteNum.should.equal(0)
394
- })
395
- })
396
-
397
- describe('#fromJSON', function () {
398
- it('should convert a json to an address', function () {
399
- const addrbuf = Buffer.alloc(21)
400
- addrbuf.fill(0)
401
- const address = new Address().fromBuffer(addrbuf)
402
- const json = address.toJSON()
403
- const address2 = new Address().fromJSON(json)
404
- should.exist(address2.hashBuf)
405
- address2.versionByteNum.should.equal(0)
406
- })
407
- })
408
-
409
- describe('#toTxOutScript', function () {
410
- it('should convert this address into known scripts', function () {
411
- const addrbuf = Buffer.alloc(21)
412
- addrbuf.fill(0)
413
- const addr = new Address().fromBuffer(addrbuf)
414
- const script = addr.toTxOutScript()
415
- script
416
- .toString()
417
- .should.equal(
418
- 'OP_DUP OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG'
419
- )
420
- })
421
- })
422
-
423
- describe('#toString', function () {
424
- it('should output the same thing that was input', function () {
425
- const address = new Address()
426
- address.fromString(str)
427
- address.toString().should.equal(str)
428
- })
429
- })
430
-
431
- describe('#asyncToString', function () {
432
- it('should output the same as toString', async function () {
433
- const str1 = new Address().fromString(str).toString()
434
- const str2 = await new Address().fromString(str).asyncToString()
435
- str1.should.equal(str2)
436
- })
437
- })
438
-
439
- describe('#validate', function () {
440
- it('should not throw an error on this valid address', function () {
441
- const address = new Address()
442
- address.fromString(str)
443
- should.exist(address.validate())
444
- })
445
-
446
- it('should throw an error on this invalid versionByteNum', function () {
447
- const address = new Address()
448
- address.fromString(str)
449
- address.versionByteNum = 1
450
- ;(function () {
451
- address.validate()
452
- }.should.throw('invalid versionByteNum'))
453
- })
454
-
455
- it('should throw an error on this invalid versionByteNum', function () {
456
- const address = new Address()
457
- address.fromString(str)
458
- address.hashBuf = Buffer.concat([address.hashBuf, Buffer.from([0])])
459
- ;(function () {
460
- address.validate()
461
- }.should.throw('hashBuf must be a buffer of 20 bytes'))
462
- })
463
- })
464
- })
package/test/aes.js DELETED
@@ -1,96 +0,0 @@
1
- /* global describe,it */
2
- import should from 'should'
3
- import { Hash } from '../lib/hash'
4
- import { Aes } from '../lib/aes'
5
- import vectors from './vectors/aes.json'
6
-
7
- describe('Aes', function () {
8
- const m128 = Hash.sha256(Buffer.from('test1')).slice(0, 128 / 8)
9
-
10
- const k128 = Hash.sha256(Buffer.from('test2')).slice(0, 128 / 8)
11
- const k192 = Hash.sha256(Buffer.from('test2')).slice(0, 192 / 8)
12
- const k256 = Hash.sha256(Buffer.from('test2')).slice(0, 256 / 8)
13
-
14
- const e128 = Buffer.from('3477e13884125038f4dc24e9d2cfbbc7', 'hex')
15
- const e192 = Buffer.from('b670954c0e2da1aaa5f9063de04eb961', 'hex')
16
- const e256 = Buffer.from('dd2ce24581183a4a7c0b1068f8bc79f0', 'hex')
17
-
18
- should.exist(Aes)
19
-
20
- describe('@encrypt', function () {
21
- it('should encrypt with a 128 bit key', function () {
22
- const encBuf = Aes.encrypt(m128, k128)
23
- encBuf.toString('hex').should.equal(e128.toString('hex'))
24
- })
25
-
26
- it('should encrypt with a 192 bit key', function () {
27
- const encBuf = Aes.encrypt(m128, k192)
28
- encBuf.toString('hex').should.equal(e192.toString('hex'))
29
- })
30
-
31
- it('should encrypt with a 256 bit key', function () {
32
- const encBuf = Aes.encrypt(m128, k256)
33
- encBuf.toString('hex').should.equal(e256.toString('hex'))
34
- })
35
- })
36
-
37
- describe('@decrypt', function () {
38
- it('should encrypt/decrypt with a 128 bit key', function () {
39
- const encBuf = Aes.encrypt(m128, k128)
40
- const m = Aes.decrypt(encBuf, k128)
41
- m.toString('hex').should.equal(m128.toString('hex'))
42
- })
43
-
44
- it('should encrypt/decrypt with a 192 bit key', function () {
45
- const encBuf = Aes.encrypt(m128, k192)
46
- const m = Aes.decrypt(encBuf, k192)
47
- m.toString('hex').should.equal(m128.toString('hex'))
48
- })
49
-
50
- it('should encrypt/decrypt with a 256 bit key', function () {
51
- const encBuf = Aes.encrypt(m128, k256)
52
- const m = Aes.decrypt(encBuf, k256)
53
- m.toString('hex').should.equal(m128.toString('hex'))
54
- })
55
- })
56
-
57
- describe('@buf2Words', function () {
58
- it('should convert this 4 length buffer into an array', function () {
59
- const buf = Buffer.from([0, 0, 0, 0])
60
- const words = Aes.buf2Words(buf)
61
- words.length.should.equal(1)
62
- })
63
-
64
- it('should throw an error on this 5 length buffer', function () {
65
- const buf = Buffer.from([0, 0, 0, 0, 0])
66
- ;(function () {
67
- Aes.buf2Words(buf)
68
- }.should.throw())
69
- })
70
- })
71
-
72
- describe('@words2Buf', function () {
73
- it('should convert this array into a buffer', function () {
74
- const a = [100, 0]
75
- const buf = Aes.words2Buf(a)
76
- buf.length.should.equal(8)
77
- })
78
- })
79
-
80
- describe('vectors', function () {
81
- vectors.forEach(function (vector, i) {
82
- it('should pass sjcl test vector ' + i, function () {
83
- const keyBuf = Buffer.from(vector.key, 'hex')
84
- const ptbuf = Buffer.from(vector.pt, 'hex')
85
- const ctBuf = Buffer.from(vector.ct, 'hex')
86
-
87
- Aes.encrypt(ptbuf, keyBuf)
88
- .toString('hex')
89
- .should.equal(ctBuf.toString('hex'))
90
- Aes.decrypt(ctBuf, keyBuf)
91
- .toString('hex')
92
- .should.equal(ptbuf.toString('hex'))
93
- })
94
- })
95
- })
96
- })
package/test/aescbc.js DELETED
@@ -1,65 +0,0 @@
1
- /* global describe,it */
2
- 'use strict'
3
- import should from 'should'
4
- import { Aescbc } from '../lib/aescbc'
5
- import vectors from './vectors/aescbc.json'
6
-
7
- describe('Aescbc', function () {
8
- should.exist(Aescbc)
9
-
10
- describe('@encrypt', function () {
11
- it('should return encrypt one block', function () {
12
- const cipherKeyBuf = Buffer.alloc(256 / 8)
13
- cipherKeyBuf.fill(0x10)
14
- const ivBuf = Buffer.alloc(128 / 8)
15
- ivBuf.fill(0)
16
- const messageBuf = Buffer.alloc(128 / 8 - 1)
17
- messageBuf.fill(0)
18
- const encBuf = Aescbc.encrypt(messageBuf, cipherKeyBuf, ivBuf)
19
- encBuf.length.should.equal(128 / 8 + 128 / 8)
20
- })
21
-
22
- it('should return encrypt two blocks', function () {
23
- const cipherKeyBuf = Buffer.alloc(256 / 8)
24
- cipherKeyBuf.fill(0x10)
25
- const ivBuf = Buffer.alloc(128 / 8)
26
- ivBuf.fill(0)
27
- const messageBuf = Buffer.alloc(128 / 8)
28
- messageBuf.fill(0)
29
- const encBuf = Aescbc.encrypt(messageBuf, cipherKeyBuf, ivBuf)
30
- encBuf.length.should.equal(128 / 8 + 128 / 8 + 128 / 8)
31
- })
32
- })
33
-
34
- describe('@decrypt', function () {
35
- it('should decrypt that which was encrypted', function () {
36
- const cipherKeyBuf = Buffer.alloc(256 / 8)
37
- cipherKeyBuf.fill(0x10)
38
- const ivBuf = Buffer.alloc(128 / 8)
39
- ivBuf.fill(0)
40
- const messageBuf = Buffer.alloc(128 / 8)
41
- messageBuf.fill(0)
42
- const encBuf = Aescbc.encrypt(messageBuf, cipherKeyBuf, ivBuf)
43
- const messageBuf2 = Aescbc.decrypt(encBuf, cipherKeyBuf)
44
- messageBuf2.toString('hex').should.equal(messageBuf.toString('hex'))
45
- })
46
- })
47
-
48
- describe('vectors', function () {
49
- vectors.forEach(function (vector, i) {
50
- it('should pass sjcl test vector ' + i, function () {
51
- const keyBuf = Buffer.from(vector.key, 'hex')
52
- const ivBuf = Buffer.from(vector.iv, 'hex')
53
- const ptbuf = Buffer.from(vector.pt, 'hex')
54
- const ctBuf = Buffer.from(vector.ct, 'hex')
55
- Aescbc.encrypt(ptbuf, keyBuf, ivBuf)
56
- .slice(128 / 8)
57
- .toString('hex')
58
- .should.equal(vector.ct)
59
- Aescbc.decrypt(Buffer.concat([ivBuf, ctBuf]), keyBuf)
60
- .toString('hex')
61
- .should.equal(vector.pt)
62
- })
63
- })
64
- })
65
- })