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/test/ecies.js DELETED
@@ -1,238 +0,0 @@
1
- /* global describe,it */
2
- 'use strict'
3
- import { Ecies } from '../lib/ecies'
4
- import should from 'should'
5
- import { KeyPair } from '../lib/key-pair'
6
- import { PrivKey } from '../lib/priv-key'
7
- import { Hash } from '../lib/hash'
8
-
9
- describe('#Ecies', function () {
10
- it('should make a new Ecies object', function () {
11
- should.exist(Ecies)
12
- })
13
-
14
- const fromkey = new KeyPair().fromRandom()
15
- const tokey = new KeyPair().fromRandom()
16
- const messageBuf = Hash.sha256(
17
- Buffer.from('my message is the hash of this string')
18
- )
19
-
20
- describe('@bitcoreEncrypt', function () {
21
- it('should return a buffer', function () {
22
- const encBuf = Ecies.bitcoreEncrypt(messageBuf, tokey.pubKey, fromkey)
23
- Buffer.isBuffer(encBuf).should.equal(true)
24
- })
25
-
26
- it('should return a buffer if fromkey is not present', function () {
27
- const encBuf = Ecies.bitcoreEncrypt(messageBuf, tokey.pubKey)
28
- Buffer.isBuffer(encBuf).should.equal(true)
29
- })
30
- })
31
-
32
- describe('@asyncBitcoreEncrypt', function () {
33
- it('should return a buffer', async function () {
34
- const encBuf = await Ecies.asyncBitcoreEncrypt(messageBuf, tokey.pubKey, fromkey)
35
- Buffer.isBuffer(encBuf).should.equal(true)
36
- })
37
-
38
- it('should return a buffer if fromkey is not present', async function () {
39
- const encBuf = await Ecies.asyncBitcoreEncrypt(messageBuf, tokey.pubKey)
40
- Buffer.isBuffer(encBuf).should.equal(true)
41
- })
42
- })
43
-
44
- describe('@bitcoreDecrypt', function () {
45
- it('should decrypt that which was encrypted', function () {
46
- const encBuf = Ecies.bitcoreEncrypt(messageBuf, tokey.pubKey, fromkey)
47
- const messageBuf2 = Ecies.bitcoreDecrypt(encBuf, tokey.privKey)
48
- messageBuf2.toString('hex').should.equal(messageBuf.toString('hex'))
49
- })
50
-
51
- it('should decrypt that which was encrypted if fromKeyPair was randomly generated', function () {
52
- const encBuf = Ecies.bitcoreEncrypt(messageBuf, tokey.pubKey)
53
- const messageBuf2 = Ecies.bitcoreDecrypt(encBuf, tokey.privKey)
54
- messageBuf2.toString('hex').should.equal(messageBuf.toString('hex'))
55
- })
56
- })
57
-
58
- describe('@asyncDecrypt', function () {
59
- it('should decrypt that which was encrypted', async function () {
60
- const encBuf = await Ecies.asyncBitcoreEncrypt(messageBuf, tokey.pubKey, fromkey)
61
- const messageBuf2 = await Ecies.asyncBitcoreDecrypt(encBuf, tokey.privKey)
62
- messageBuf2.toString('hex').should.equal(messageBuf.toString('hex'))
63
- })
64
-
65
- it('should decrypt that which was encrypted if fromKeyPair was randomly generated', async function () {
66
- const encBuf = await Ecies.asyncBitcoreEncrypt(messageBuf, tokey.pubKey)
67
- const messageBuf2 = await Ecies.asyncBitcoreDecrypt(encBuf, tokey.privKey)
68
- messageBuf2.toString('hex').should.equal(messageBuf.toString('hex'))
69
- })
70
- })
71
-
72
- describe('Electrum Ecies', function () {
73
- const alicePrivKey = PrivKey.fromString('L1Ejc5dAigm5XrM3mNptMEsNnHzS7s51YxU7J61ewGshZTKkbmzJ')
74
- const aliceKeyPair = KeyPair.fromPrivKey(alicePrivKey)
75
- const bobPrivKey = PrivKey.fromString('KxfxrUXSMjJQcb3JgnaaA6MqsrKQ1nBSxvhuigdKRyFiEm6BZDgG')
76
- const bobKeyPair = KeyPair.fromPrivKey(bobPrivKey)
77
-
78
- it('should do these test vectors correctly', function () {
79
- const message = Buffer.from('this is my test message')
80
-
81
- Ecies.electrumDecrypt(Buffer.from('QklFMQOGFyMXLo9Qv047K3BYJhmnJgt58EC8skYP/R2QU/U0yXXHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbiaH4FsxKIOOvzolIFVAS0FplUmib2HnlAM1yP/iiPsU=', 'base64'), alicePrivKey).toString().should.equal(message.toString())
82
- Ecies.electrumDecrypt(Buffer.from('QklFMQM55QTWSSsILaluEejwOXlrBs1IVcEB4kkqbxDz4Fap53XHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbvZJHgyAzxA6SoujduvJXv+A9ri3po9veilrmc8p6dwo=', 'base64'), bobPrivKey).toString().should.equal(message.toString())
83
-
84
- Ecies.electrumEncrypt(message, bobKeyPair.pubKey, aliceKeyPair).toString('base64').should.equal('QklFMQM55QTWSSsILaluEejwOXlrBs1IVcEB4kkqbxDz4Fap53XHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbvZJHgyAzxA6SoujduvJXv+A9ri3po9veilrmc8p6dwo=')
85
- Ecies.electrumEncrypt(message, aliceKeyPair.pubKey, bobKeyPair).toString('base64').should.equal('QklFMQOGFyMXLo9Qv047K3BYJhmnJgt58EC8skYP/R2QU/U0yXXHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbiaH4FsxKIOOvzolIFVAS0FplUmib2HnlAM1yP/iiPsU=')
86
- })
87
-
88
- it('should encrypt and decrypt symmetrically with matching strings in ECDH noKey mode', function () {
89
- const message = Buffer.from('this is my ECDH test message')
90
- const ecdhMessageEncryptedBob = Ecies.electrumEncrypt(message, bobKeyPair.pubKey, aliceKeyPair, true)
91
- const ecdhMessageEncryptedAlice = Ecies.electrumEncrypt(message, aliceKeyPair.pubKey, bobKeyPair, true)
92
- ecdhMessageEncryptedBob.toString("base64").should.equal(ecdhMessageEncryptedAlice.toString("base64"))
93
- Ecies.electrumDecrypt(ecdhMessageEncryptedAlice, bobPrivKey, aliceKeyPair.pubKey).toString().should.equal('this is my ECDH test message')
94
- Ecies.electrumDecrypt(ecdhMessageEncryptedBob, alicePrivKey, bobKeyPair.pubKey).toString().should.equal('this is my ECDH test message')
95
- })
96
- /*
97
- const message = 'attack at dawn'
98
- const encrypted = 'QklFMQM55QTWSSsILaluEejwOXlrBs1IVcEB4kkqbxDz4Fap56+ajq0hzmnaQJXwUMZ/DUNgEx9i2TIhCA1mpBFIfxWZy+sH6H+sqqfX3sPHsGu0ug=='
99
- const encBuf = Buffer.from(encrypted, 'base64')
100
-
101
- it('correctly encrypts a message', function () {
102
- const ciphertext = alice.encrypt(message)
103
- Buffer.isBuffer(ciphertext).should.equal(true)
104
- ciphertext.toString('base64').should.equal(encrypted)
105
- })
106
-
107
- it('correctly decrypts a message', function () {
108
- const decrypted = bob
109
- .decrypt(encBuf)
110
- .toString()
111
- decrypted.should.equal(message)
112
- })
113
-
114
- it('correctly recovers a message', function () {
115
- const decrypted = aliceReloaded
116
- .decrypt(encBuf)
117
- .toString()
118
- decrypted.should.equal(message)
119
- })
120
-
121
- it('retrieves senders PubKey from the encypted buffer', function () {
122
- const bob2 = Ecies().PrivKey(bobPrivKey)
123
- const decrypted = bob2.decrypt(encBuf).toString()
124
- bob2._PubKey.toDER().should.deep.equal(alicePrivKey.PubKey.toDER())
125
- decrypted.should.equal(message)
126
- })
127
-
128
- const message1 = 'This is message from first sender'
129
- const message2 = 'This is message from second sender'
130
-
131
- it('decrypt messages from different senders', function () {
132
- const sender1 = Ecies().PubKey(bobPrivKey.PubKey)
133
- const sender2 = Ecies().PubKey(bobPrivKey.PubKey)
134
- const bob2 = Ecies().PrivKey(bobPrivKey)
135
- const decrypted1 = bob2.decrypt(sender1.encrypt(message1)).toString()
136
- const decrypted2 = bob2.decrypt(sender2.encrypt(message2)).toString()
137
- decrypted1.should.equal(message1)
138
- decrypted2.should.equal(message2)
139
- })
140
-
141
- it('roundtrips', function () {
142
- const secret = 'some secret message!!!'
143
- const encrypted = alice.encrypt(secret)
144
- const decrypted = bob
145
- .decrypt(encrypted)
146
- .toString()
147
- decrypted.should.equal(secret)
148
- })
149
-
150
- it('roundtrips (no public key)', function () {
151
- alice.opts.noKey = true
152
- bob.opts.noKey = true
153
- const secret = 'some secret message!!!'
154
- const encrypted = alice.encrypt(secret)
155
- const decrypted = bob
156
- .decrypt(encrypted)
157
- .toString()
158
- decrypted.should.equal(secret)
159
- })
160
-
161
- it('roundtrips (short tag)', function () {
162
- alice.opts.shortTag = true
163
- bob.opts.shortTag = true
164
- const secret = 'some secret message!!!'
165
- const encrypted = alice.encrypt(secret)
166
- const decrypted = bob
167
- .decrypt(encrypted)
168
- .toString()
169
- decrypted.should.equal(secret)
170
- })
171
-
172
- it('roundtrips (no public key & short tag)', function () {
173
- alice.opts.noKey = true
174
- alice.opts.shortTag = true
175
- bob.opts.noKey = true
176
- bob.opts.shortTag = true
177
- const secret = 'some secret message!!!'
178
- const encrypted = alice.encrypt(secret)
179
- const decrypted = bob
180
- .decrypt(encrypted)
181
- .toString()
182
- decrypted.should.equal(secret)
183
- })
184
-
185
- it('errors', function () {
186
- should.exist(bsv.errors.Ecies)
187
- })
188
-
189
- it('correctly fails if trying to decrypt a bad message', function () {
190
- const encrypted = Buffer.from(encBuf)
191
- encrypted[encrypted.length - 1] = 2
192
- ;(function () {
193
- return bob.decrypt(encrypted)
194
- }).should.throw('Invalid checksum')
195
- })
196
-
197
- it('decrypting uncompressed keys', function () {
198
- const secret = 'test'
199
-
200
- // test uncompressed
201
- const alicePrivKey = bsv.PrivKey.fromObject({
202
- bn: '1fa76f9c799ca3a51e2c7c901d3ba8e24f6d870beccf8df56faf30120b38f360',
203
- compressed: false,
204
- network: 'livenet'
205
- })
206
- const alicePubKey = bsv.PubKey.fromPrivKey(alicePrivKey) // alicePrivKey.PubKey
207
- alicePrivKey.compressed.should.equal(false)
208
-
209
- const cypher1 = Ecies().PrivKey(alicePrivKey).PubKey(alicePubKey)
210
- const encrypted = cypher1.encrypt(secret)
211
-
212
- const cypher2 = Ecies().PrivKey(alicePrivKey).PubKey(alicePubKey)
213
- const decrypted = cypher2.decrypt(encrypted)
214
- secret.should.equal(decrypted.toString())
215
- })
216
-
217
- it('decrypting compressed keys', function () {
218
- const secret = 'test'
219
-
220
- // test compressed
221
- const alicePrivKey = bsv.PrivKey.fromObject({
222
- bn: '1fa76f9c799ca3a51e2c7c901d3ba8e24f6d870beccf8df56faf30120b38f360',
223
- compressed: true,
224
- network: 'livenet'
225
- })
226
- const alicePubKey = bsv.PubKey.fromPrivKey(alicePrivKey) // alicePrivKey.PubKey
227
- alicePrivKey.compressed.should.equal(true)
228
-
229
- const cypher1 = Ecies().PrivKey(alicePrivKey).PubKey(alicePubKey)
230
- const encrypted = cypher1.encrypt(secret)
231
-
232
- const cypher2 = Ecies().PrivKey(alicePrivKey).PubKey(alicePubKey)
233
- const decrypted = cypher2.decrypt(encrypted)
234
- secret.should.equal(decrypted.toString())
235
- })
236
- */
237
- })
238
- })
package/test/global.js DELETED
@@ -1,13 +0,0 @@
1
- /* global after */
2
- /**
3
- * Global "before" and "after" to run before and after all tests. These can be
4
- * used to establish and also tear down global database connections, network
5
- * connections, and worker connections. It's important not to leave thins
6
- * hanging when the tests are done running so that the tests end properly.
7
- */
8
- 'use strict'
9
- import { Workers } from '../lib/workers'
10
-
11
- after(function () {
12
- Workers.endGlobalWorkers()
13
- })
@@ -1,52 +0,0 @@
1
- /* global describe,it */
2
- 'use strict'
3
- import { HashCache } from '../lib/hash-cache'
4
- import should from 'should'
5
-
6
- describe('HashCache', function () {
7
- const prevoutsHashBuf = Buffer.from('01'.repeat(32), 'hex')
8
- const sequenceHashBuf = Buffer.from('02'.repeat(32), 'hex')
9
- const outputsHashBuf = Buffer.from('03'.repeat(32), 'hex')
10
-
11
- it('should satisfy this basic API', function () {
12
- const hashCache = new HashCache(prevoutsHashBuf, sequenceHashBuf, outputsHashBuf)
13
- should.exist(hashCache)
14
- hashCache.prevoutsHashBuf.length.should.equal(32)
15
- hashCache.sequenceHashBuf.length.should.equal(32)
16
- hashCache.outputsHashBuf.length.should.equal(32)
17
- })
18
-
19
- describe('#fromBuffer', function () {
20
- it('should parse this known message', function () {
21
- const hashCache = new HashCache().fromBuffer(new HashCache(prevoutsHashBuf, sequenceHashBuf, outputsHashBuf).toBuffer())
22
- hashCache.toHex().should.equal('7b22707265766f75747348617368427566223a2230313031303130313031303130313031303130313031303130313031303130313031303130313031303130313031303130313031303130313031303130313031222c2273657175656e636548617368427566223a2230323032303230323032303230323032303230323032303230323032303230323032303230323032303230323032303230323032303230323032303230323032222c226f75747075747348617368427566223a2230333033303330333033303330333033303330333033303330333033303330333033303330333033303330333033303330333033303330333033303330333033227d')
23
- })
24
- })
25
-
26
- describe('#toBuffer', function () {
27
- it('should parse this known message', function () {
28
- const hashCache = new HashCache(prevoutsHashBuf, sequenceHashBuf, outputsHashBuf)
29
- hashCache
30
- .toBuffer()
31
- .toString('hex')
32
- .should.equal('7b22707265766f75747348617368427566223a2230313031303130313031303130313031303130313031303130313031303130313031303130313031303130313031303130313031303130313031303130313031222c2273657175656e636548617368427566223a2230323032303230323032303230323032303230323032303230323032303230323032303230323032303230323032303230323032303230323032303230323032222c226f75747075747348617368427566223a2230333033303330333033303330333033303330333033303330333033303330333033303330333033303330333033303330333033303330333033303330333033227d')
33
- })
34
- })
35
-
36
- describe('#fromJSON', function () {
37
- it('should parse this known json hashCache', function () {
38
- new HashCache()
39
- .fromJSON(JSON.parse('{"prevoutsHashBuf":"0101010101010101010101010101010101010101010101010101010101010101","sequenceHashBuf":"0202020202020202020202020202020202020202020202020202020202020202","outputsHashBuf":"0303030303030303030303030303030303030303030303030303030303030303"}'))
40
- .toHex()
41
- .should.equal('7b22707265766f75747348617368427566223a2230313031303130313031303130313031303130313031303130313031303130313031303130313031303130313031303130313031303130313031303130313031222c2273657175656e636548617368427566223a2230323032303230323032303230323032303230323032303230323032303230323032303230323032303230323032303230323032303230323032303230323032222c226f75747075747348617368427566223a2230333033303330333033303330333033303330333033303330333033303330333033303330333033303330333033303330333033303330333033303330333033227d')
42
- })
43
- })
44
-
45
- describe('#toJSON', function () {
46
- it('should create this known message', function () {
47
- JSON.stringify(new HashCache(prevoutsHashBuf, sequenceHashBuf, outputsHashBuf).toJSON()).should.equal(
48
- '{"prevoutsHashBuf":"0101010101010101010101010101010101010101010101010101010101010101","sequenceHashBuf":"0202020202020202020202020202020202020202020202020202020202020202","outputsHashBuf":"0303030303030303030303030303030303030303030303030303030303030303"}'
49
- )
50
- })
51
- })
52
- })
package/test/hash.js DELETED
@@ -1,354 +0,0 @@
1
- /* global describe,it */
2
- 'use strict'
3
- import 'should'
4
- import { Hash } from '../lib/hash'
5
- import vectors from './vectors/hash'
6
-
7
- describe('Hash', function () {
8
- const buf = Buffer.from([0, 1, 2, 3, 253, 254, 255])
9
- const str = 'test string'
10
-
11
- it('should have the blockSize for some hash functions', function () {
12
- Hash.sha1.blockSize.should.equal(512)
13
- Hash.sha256.blockSize.should.equal(512)
14
- Hash.sha512.blockSize.should.equal(1024)
15
- })
16
-
17
- describe('@hmac', function () {
18
- it('should throw errors in these cases', function () {
19
- ;(function () {
20
- Hash.hmac(
21
- 'non-supported-hash-function',
22
- Buffer.from([]),
23
- Buffer.from([])
24
- )
25
- }.should.throw('invalid choice of hash function'))
26
- ;(function () {
27
- Hash.hmac('sha512', Buffer.from([]), '')
28
- }.should.throw('data and key must be buffers'))
29
- ;(function () {
30
- Hash.hmac('sha512', '', Buffer.from([]))
31
- }.should.throw('data and key must be buffers'))
32
- })
33
- })
34
-
35
- describe('@sha1', function () {
36
- it('should calculate the hash of this buffer correctly', function () {
37
- let hash = Hash.sha1(buf)
38
- hash
39
- .toString('hex')
40
- .should.equal('de69b8a4a5604d0486e6420db81e39eb464a17b2')
41
- hash = Hash.sha1(Buffer.alloc(0))
42
- hash
43
- .toString('hex')
44
- .should.equal('da39a3ee5e6b4b0d3255bfef95601890afd80709')
45
- })
46
-
47
- it('should throw an error when the input is not a buffer', function () {
48
- ;(function () {
49
- Hash.sha1(str)
50
- }.should.throw('sha1 hash must be of a buffer'))
51
- })
52
- })
53
-
54
- describe('@asyncSha1', function () {
55
- it('should compute the same as sha1', async function () {
56
- const sha1buf1 = Hash.sha1(buf)
57
- const sha1buf2 = await Hash.asyncSha1(buf)
58
- sha1buf1.toString('hex').should.equal(sha1buf2.toString('hex'))
59
- })
60
-
61
- it('should compute the same as sha1 twice in a row', async function () {
62
- const sha1buf1 = Hash.sha1(buf)
63
- const sha1buf1b = Hash.sha1(buf)
64
- const sha1buf2 = await Hash.asyncSha1(buf)
65
- const sha1buf2b = await Hash.asyncSha1(buf)
66
- sha1buf1.toString('hex').should.equal(sha1buf2.toString('hex'))
67
- sha1buf1b.toString('hex').should.equal(sha1buf2b.toString('hex'))
68
- })
69
- })
70
-
71
- describe('@sha1Hmac', function () {
72
- // http://tools.ietf.org/html/rfc2202.html
73
-
74
- it('should calculate this known empty test vector correctly', function () {
75
- const hex = 'b617318655057264e28bc0b6fb378c8ef146be00'
76
- Hash.sha1Hmac(
77
- Buffer.from('Hi There'),
78
- Buffer.from('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex')
79
- )
80
- .toString('hex')
81
- .should.equal(hex)
82
- })
83
- })
84
-
85
- describe('@asyncSha1Hmac', function () {
86
- it('should compute the same as sha1Hmac', async function () {
87
- const data = Buffer.from('Hi There')
88
- const key = Buffer.from('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex')
89
- const sha1Hmacbuf1 = Hash.sha1Hmac(data, key)
90
- const sha1Hmacbuf2 = await Hash.asyncSha1Hmac(data, key)
91
- sha1Hmacbuf1.toString('hex').should.equal(sha1Hmacbuf2.toString('hex'))
92
- })
93
- })
94
-
95
- describe('@sha256', function () {
96
- it('should calculate the hash of this buffer correctly', function () {
97
- const hash = Hash.sha256(buf)
98
- hash
99
- .toString('hex')
100
- .should.equal(
101
- '6f2c7b22fd1626998287b3636089087961091de80311b9279c4033ec678a83e8'
102
- )
103
- })
104
-
105
- it('should throw an error when the input is not a buffer', function () {
106
- ;(function () {
107
- Hash.sha256(str)
108
- }.should.throw('sha256 hash must be of a buffer'))
109
- })
110
- })
111
-
112
- describe('@asyncSha256', function () {
113
- it('should compute the same as sha256', async function () {
114
- const sha256buf1 = Hash.sha1(buf)
115
- const sha256buf2 = await Hash.asyncSha1(buf)
116
- sha256buf1.toString('hex').should.equal(sha256buf2.toString('hex'))
117
- })
118
-
119
- it('should compute a hash for 5mb data', async function () {
120
- this.timeout(10000)
121
- const data = Buffer.alloc(5e6)
122
- data.fill(0)
123
- const hash1 = Hash.sha256(data)
124
- const hash2 = await Hash.asyncSha256(data)
125
- hash1.toString('hex').should.equal(hash2.toString('hex'))
126
- })
127
- })
128
-
129
- describe('@sha256Hmac', function () {
130
- it('should compute this known empty test vector correctly', function () {
131
- const key = Buffer.from('')
132
- const data = Buffer.from('')
133
- Hash.sha256Hmac(data, key)
134
- .toString('hex')
135
- .should.equal(
136
- 'b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad'
137
- )
138
- })
139
-
140
- it('should compute this known non-empty test vector correctly', function () {
141
- const key = Buffer.from('key')
142
- const data = Buffer.from('The quick brown fox jumps over the lazy dog')
143
- Hash.sha256Hmac(data, key)
144
- .toString('hex')
145
- .should.equal(
146
- 'f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8'
147
- )
148
- })
149
- })
150
-
151
- describe('@asyncSha256Hmac', function () {
152
- it('should compute the same as sha256Hmac', async function () {
153
- const data = Buffer.from('Hi There')
154
- const key = Buffer.from('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex')
155
- const sha256Hmacbuf1 = Hash.sha256Hmac(data, key)
156
- const sha256Hmacbuf2 = await Hash.asyncSha256Hmac(data, key)
157
- sha256Hmacbuf1
158
- .toString('hex')
159
- .should.equal(sha256Hmacbuf2.toString('hex'))
160
- })
161
- })
162
-
163
- describe('@sha256Sha256', function () {
164
- it('should calculate the hash of this buffer correctly', function () {
165
- const hash = Hash.sha256Sha256(buf)
166
- hash
167
- .toString('hex')
168
- .should.equal(
169
- 'be586c8b20dee549bdd66018c7a79e2b67bb88b7c7d428fa4c970976d2bec5ba'
170
- )
171
- })
172
-
173
- it('should throw an error when the input is not a buffer', function () {
174
- ;(function () {
175
- Hash.sha256Sha256(str)
176
- }.should.throw(
177
- 'sha256Sha256 hash must be of a buffer: Error: sha256 hash must be of a buffer'
178
- ))
179
- })
180
- })
181
-
182
- describe('@asyncSha256Sha256', function () {
183
- it('should compute the same as sha256Sha256', async function () {
184
- const sha256Sha256buf1 = Hash.sha256Sha256(buf)
185
- const sha256Sha256buf2 = await Hash.asyncSha256Sha256(buf)
186
- sha256Sha256buf1
187
- .toString('hex')
188
- .should.equal(sha256Sha256buf2.toString('hex'))
189
- })
190
- })
191
-
192
- describe('@sha256Ripemd160', function () {
193
- it('should calculate the hash of this buffer correctly', function () {
194
- const hash = Hash.sha256Ripemd160(buf)
195
- hash
196
- .toString('hex')
197
- .should.equal('7322e2bd8535e476c092934e16a6169ca9b707ec')
198
- })
199
-
200
- it('should throw an error when the input is not a buffer', function () {
201
- ;(function () {
202
- Hash.sha256Ripemd160(str)
203
- }.should.throw(
204
- 'sha256Ripemd160 hash must be of a buffer: Error: sha256 hash must be of a buffer'
205
- ))
206
- })
207
- })
208
-
209
- describe('@asyncSha256Ripemd160', function () {
210
- it('should compute the same as sha256Sha256', async function () {
211
- const sha256Ripemd160buf1 = Hash.sha256Ripemd160(buf)
212
- const sha256Ripemd160buf2 = await Hash.asyncSha256Ripemd160(buf)
213
- sha256Ripemd160buf1
214
- .toString('hex')
215
- .should.equal(sha256Ripemd160buf2.toString('hex'))
216
- })
217
- })
218
-
219
- describe('@ripemd160', function () {
220
- it('should calculate the hash of this buffer correctly', function () {
221
- const hash = Hash.ripemd160(buf)
222
- hash
223
- .toString('hex')
224
- .should.equal('fa0f4565ff776fee0034c713cbf48b5ec06b7f5c')
225
- })
226
-
227
- it('should throw an error when the input is not a buffer', function () {
228
- ;(function () {
229
- Hash.ripemd160(str)
230
- }.should.throw('ripemd160 hash must be of a buffer'))
231
- })
232
- })
233
-
234
- describe('@asyncRipemd160', function () {
235
- it('should compute the same as ripemd160', async function () {
236
- const ripemd160buf1 = Hash.ripemd160(buf)
237
- const ripemd160buf2 = await Hash.asyncRipemd160(buf)
238
- ripemd160buf1.toString('hex').should.equal(ripemd160buf2.toString('hex'))
239
- })
240
- })
241
-
242
- describe('@sha512', function () {
243
- it('should calculate the hash of this buffer correctly', function () {
244
- const hash = Hash.sha512(buf)
245
- hash
246
- .toString('hex')
247
- .should.equal(
248
- 'c0530aa32048f4904ae162bc14b9eb535eab6c465e960130005feddb71613e7d62aea75f7d3333ba06e805fc8e45681454524e3f8050969fe5a5f7f2392e31d0'
249
- )
250
- })
251
-
252
- it('should throw an error when the input is not a buffer', function () {
253
- ;(function () {
254
- Hash.sha512(str)
255
- }.should.throw('sha512 hash must be of a buffer'))
256
- })
257
- })
258
-
259
- describe('@asyncSha512', function () {
260
- it('should compute the same as sha512', async function () {
261
- const sha512buf1 = Hash.sha512(buf)
262
- const sha512buf2 = await Hash.asyncSha512(buf)
263
- sha512buf1.toString('hex').should.equal(sha512buf2.toString('hex'))
264
- })
265
- })
266
-
267
- describe('@sha512Hmac', function () {
268
- it('should calculate this value where key size is the same as block size', function () {
269
- const key = Buffer.alloc(Hash.sha512.blockSize / 8)
270
- key.fill(0)
271
- const data = Buffer.from([])
272
- // test vector calculated with node's createHmac
273
- const hex =
274
- 'b936cee86c9f87aa5d3c6f2e84cb5a4239a5fe50480a6ec66b70ab5b1f4ac6730c6c515421b327ec1d69402e53dfb49ad7381eb067b338fd7b0cb22247225d47'
275
- Hash.sha512Hmac(data, key)
276
- .toString('hex')
277
- .should.equal(hex)
278
- })
279
-
280
- it('should calculate this known empty test vector correctly', function () {
281
- const hex =
282
- 'b936cee86c9f87aa5d3c6f2e84cb5a4239a5fe50480a6ec66b70ab5b1f4ac6730c6c515421b327ec1d69402e53dfb49ad7381eb067b338fd7b0cb22247225d47'
283
- Hash.sha512Hmac(Buffer.from([]), Buffer.from([]))
284
- .toString('hex')
285
- .should.equal(hex)
286
- })
287
-
288
- it('should calculate this known non-empty test vector correctly', function () {
289
- const hex =
290
- 'c40bd7c15aa493b309c940e08a73ffbd28b2e4cb729eb94480d727e4df577b13cc403a78e6150d83595f3b17c4cc331f12ca5952691de3735a63c1d4c69a2bac'
291
- const data = Buffer.from('test1')
292
- const key = Buffer.from('test2')
293
- Hash.sha512Hmac(data, key)
294
- .toString('hex')
295
- .should.equal(hex)
296
- })
297
- })
298
-
299
- describe('@asyncSha512Hmac', function () {
300
- it('should compute the same as sha512Hmac', async function () {
301
- const data = Buffer.from('Hi There')
302
- const key = Buffer.from('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex')
303
- const sha512Hmacbuf1 = Hash.sha512Hmac(data, key)
304
- const sha512Hmacbuf2 = await Hash.asyncSha512Hmac(data, key)
305
- sha512Hmacbuf1
306
- .toString('hex')
307
- .should.equal(sha512Hmacbuf2.toString('hex'))
308
- })
309
- })
310
-
311
- describe('vectors', function () {
312
- vectors.sha1.forEach(function (vector, i) {
313
- it('should pass sjcl sha1 test vector ' + i, function () {
314
- const data = Buffer.from(vector[0])
315
- Hash.sha1(data)
316
- .toString('hex')
317
- .should.equal(vector[1])
318
- })
319
- })
320
-
321
- vectors.sha256.forEach(function (vector, i) {
322
- it('should pass sjcl sha256 test vector ' + i, function () {
323
- const data = Buffer.from(vector[0])
324
- Hash.sha256(data)
325
- .toString('hex')
326
- .should.equal(vector[1])
327
- })
328
- })
329
-
330
- vectors.sha512.forEach(function (vector, i) {
331
- it('should pass sjcl sha512 test vector ' + i, function () {
332
- const data = Buffer.from(vector[0])
333
- Hash.sha512(data)
334
- .toString('hex')
335
- .should.equal(vector[1])
336
- })
337
- })
338
-
339
- vectors.hmac.forEach(function (vector, i) {
340
- it('should pass standard hmac test vector ' + i, function () {
341
- const keyBuf = Buffer.from(vector.key, 'hex')
342
- const dataBuf = Buffer.from(vector.data, 'hex')
343
- Hash.sha256Hmac(dataBuf, keyBuf)
344
- .toString('hex')
345
- .substr(0, vector.sha256hmac.length)
346
- .should.equal(vector.sha256hmac)
347
- Hash.sha512Hmac(dataBuf, keyBuf)
348
- .toString('hex')
349
- .substr(0, vector.sha512hmac.length)
350
- .should.equal(vector.sha512hmac)
351
- })
352
- })
353
- })
354
- })
package/test/index.js DELETED
@@ -1,10 +0,0 @@
1
- /* global describe,it */
2
- 'use strict'
3
- import should from 'should'
4
- import * as bsv from '../entry'
5
-
6
- describe('bsv', function () {
7
- it('should pass this sanity check on loading the main package', function () {
8
- should.exist(bsv)
9
- })
10
- })