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/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
- })