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/tx.js DELETED
@@ -1,539 +0,0 @@
1
- /* global describe,it */
2
- 'use strict'
3
- import { Bn } from '../lib/bn'
4
- import { Br } from '../lib/br'
5
- import { KeyPair } from '../lib/key-pair'
6
- import { Script } from '../lib/script'
7
- import { Sig } from '../lib/sig'
8
- import { Tx } from '../lib/tx'
9
- import { TxIn } from '../lib/tx-in'
10
- import { TxOut } from '../lib/tx-out'
11
- import { VarInt } from '../lib/var-int'
12
- import { Interp } from '../lib/interp'
13
- import should from 'should'
14
- import sinon from 'sinon'
15
-
16
- import vectorsBitcoindSighash from './vectors/bitcoind/sighash.json'
17
- import vectorsBitcoinABCSighash from './vectors/bitcoin-abc/sighash.json'
18
- import vectorsBitcoindTxValid from './vectors/bitcoind/tx_valid.json'
19
- import vectorsBitcoindTxInvalid from './vectors/bitcoind/tx_invalid.json'
20
- import largesttxvector from './vectors/largesttx.json'
21
- import fixture from './vectors/bip69.json'
22
-
23
- describe('Tx', function () {
24
- const txIn = new TxIn().fromBuffer(
25
- Buffer.from(
26
- '00000000000000000000000000000000000000000000000000000000000000000000000001ae00000000',
27
- 'hex'
28
- )
29
- )
30
- const txOut = new TxOut().fromBuffer(Buffer.from('050000000000000001ae', 'hex'))
31
- const tx = new Tx().fromObject({
32
- versionBytesNum: 0,
33
- txInsVi: VarInt.fromNumber(1),
34
- txIns: [txIn],
35
- txOutsVi: VarInt.fromNumber(1),
36
- txOuts: [txOut],
37
- nLockTime: 0
38
- })
39
- const txhex =
40
- '000000000100000000000000000000000000000000000000000000000000000000000000000000000001ae0000000001050000000000000001ae00000000'
41
- const txbuf = Buffer.from(txhex, 'hex')
42
-
43
- const tx2idhex =
44
- '8c9aa966d35bfeaf031409e0001b90ccdafd8d859799eb945a3c515b8260bcf2'
45
- const tx2hex =
46
- '01000000029e8d016a7b0dc49a325922d05da1f916d1e4d4f0cb840c9727f3d22ce8d1363f000000008c493046022100e9318720bee5425378b4763b0427158b1051eec8b08442ce3fbfbf7b30202a44022100d4172239ebd701dae2fbaaccd9f038e7ca166707333427e3fb2a2865b19a7f27014104510c67f46d2cbb29476d1f0b794be4cb549ea59ab9cc1e731969a7bf5be95f7ad5e7f904e5ccf50a9dc1714df00fbeb794aa27aaff33260c1032d931a75c56f2ffffffffa3195e7a1ab665473ff717814f6881485dc8759bebe97e31c301ffe7933a656f020000008b48304502201c282f35f3e02a1f32d2089265ad4b561f07ea3c288169dedcf2f785e6065efa022100e8db18aadacb382eed13ee04708f00ba0a9c40e3b21cf91da8859d0f7d99e0c50141042b409e1ebbb43875be5edde9c452c82c01e3903d38fa4fd89f3887a52cb8aea9dc8aec7e2c9d5b3609c03eb16259a2537135a1bf0f9c5fbbcbdbaf83ba402442ffffffff02206b1000000000001976a91420bb5c3bfaef0231dc05190e7f1c8e22e098991e88acf0ca0100000000001976a9149e3e2d23973a04ec1b02be97c30ab9f2f27c3b2c88ac00000000'
47
- const tx2buf = Buffer.from(tx2hex, 'hex')
48
-
49
- it('should make a new transaction', function () {
50
- let tx = new Tx()
51
- should.exist(tx)
52
- tx = new Tx()
53
- should.exist(tx)
54
-
55
- Tx.fromBuffer(txbuf)
56
- .toBuffer()
57
- .toString('hex')
58
- .should.equal(txhex)
59
-
60
- // should set known defaults
61
- tx.versionBytesNum.should.equal(1)
62
- tx.txInsVi.toNumber().should.equal(0)
63
- tx.txIns.length.should.equal(0)
64
- tx.txOutsVi.toNumber().should.equal(0)
65
- tx.txOuts.length.should.equal(0)
66
- tx.nLockTime.should.equal(0)
67
- })
68
-
69
- describe('#constructor', function () {
70
- it('should set these known defaults', function () {
71
- const tx = new Tx()
72
- tx.versionBytesNum.should.equal(1)
73
- tx.txInsVi.toNumber().should.equal(0)
74
- tx.txIns.length.should.equal(0)
75
- tx.txOutsVi.toNumber().should.equal(0)
76
- tx.txOuts.length.should.equal(0)
77
- tx.nLockTime.should.equal(0)
78
- })
79
- })
80
-
81
- describe('#clone', function () {
82
- it('should clone a tx', function () {
83
- const tx1 = Tx.fromHex(tx2hex)
84
- const tx2 = tx1.clone()
85
- tx2.should.not.equal(tx1)
86
- tx2.toHex().should.equal(tx1.toHex())
87
- })
88
- })
89
-
90
- describe('#cloneByBuffer', function () {
91
- it('should clone a tx by buffer', function () {
92
- const tx1 = Tx.fromHex(tx2hex)
93
- tx1.toJSON = sinon.spy()
94
- const tx2 = tx1.cloneByBuffer()
95
- tx1.toJSON.calledOnce.should.equal(false)
96
- tx2.should.not.equal(tx1)
97
- tx2.toHex().should.equal(tx1.toHex())
98
- })
99
- })
100
-
101
- describe('#fromObject', function () {
102
- it('should set all the basic parameters', function () {
103
- const tx = new Tx().fromObject({
104
- versionBytesNum: 0,
105
- txInsVi: VarInt.fromNumber(1),
106
- txIns: [txIn],
107
- txOutsVi: VarInt.fromNumber(1),
108
- txOuts: [txOut],
109
- nLockTime: 0
110
- })
111
- should.exist(tx.versionBytesNum)
112
- should.exist(tx.txInsVi)
113
- should.exist(tx.txIns)
114
- should.exist(tx.txOutsVi)
115
- should.exist(tx.txOuts)
116
- should.exist(tx.nLockTime)
117
- })
118
- })
119
-
120
- describe('#fromJSON', function () {
121
- it('should set all the basic parameters', function () {
122
- const tx = new Tx().fromJSON({
123
- versionBytesNum: 0,
124
- txInsVi: VarInt.fromNumber(1).toJSON(),
125
- txIns: [txIn.toJSON()],
126
- txOutsVi: VarInt.fromNumber(1).toJSON(),
127
- txOuts: [txOut.toJSON()],
128
- nLockTime: 0
129
- })
130
- should.exist(tx.versionBytesNum)
131
- should.exist(tx.txInsVi)
132
- should.exist(tx.txIns)
133
- should.exist(tx.txOutsVi)
134
- should.exist(tx.txOuts)
135
- should.exist(tx.nLockTime)
136
- })
137
- })
138
-
139
- describe('#toJSON', function () {
140
- it('should recover all the basic parameters', function () {
141
- const json = tx.toJSON()
142
- should.exist(json.versionBytesNum)
143
- should.exist(json.txInsVi)
144
- should.exist(json.txIns)
145
- should.exist(json.txOutsVi)
146
- should.exist(json.txOuts)
147
- should.exist(json.nLockTime)
148
- })
149
- })
150
-
151
- describe('#fromHex', function () {
152
- it('should recover from this known tx', function () {
153
- new Tx()
154
- .fromHex(txhex)
155
- .toHex()
156
- .should.equal(txhex)
157
- })
158
-
159
- it('should recover from this known tx from the blockchain', function () {
160
- new Tx()
161
- .fromHex(tx2hex)
162
- .toHex()
163
- .should.equal(tx2hex)
164
- })
165
- })
166
-
167
- describe('#fromBuffer', function () {
168
- it('should recover from this known tx', function () {
169
- new Tx()
170
- .fromBuffer(txbuf)
171
- .toBuffer()
172
- .toString('hex')
173
- .should.equal(txhex)
174
- })
175
-
176
- it('should recover from this known tx from the blockchain', function () {
177
- new Tx()
178
- .fromBuffer(tx2buf)
179
- .toBuffer()
180
- .toString('hex')
181
- .should.equal(tx2hex)
182
- })
183
- })
184
-
185
- describe('#fromBr', function () {
186
- it('should recover from this known tx', function () {
187
- new Tx()
188
- .fromBr(new Br(txbuf))
189
- .toBuffer()
190
- .toString('hex')
191
- .should.equal(txhex)
192
- })
193
- })
194
-
195
- describe('#toHex', function () {
196
- it('should produce this known tx', function () {
197
- new Tx()
198
- .fromHex(txhex)
199
- .toHex()
200
- .should.equal(txhex)
201
- })
202
- })
203
-
204
- describe('#toBuffer', function () {
205
- it('should produce this known tx', function () {
206
- new Tx()
207
- .fromBuffer(txbuf)
208
- .toBuffer()
209
- .toString('hex')
210
- .should.equal(txhex)
211
- })
212
- })
213
-
214
- describe('#toBw', function () {
215
- it('should produce this known tx', function () {
216
- new Tx()
217
- .fromBuffer(txbuf)
218
- .toBw()
219
- .toBuffer()
220
- .toString('hex')
221
- .should.equal(txhex)
222
- })
223
- })
224
-
225
- describe('#sighash', function () {
226
- it('should hash this transaction', function () {
227
- tx.sighash(0, 0, new Script()).length.should.equal(32)
228
- })
229
-
230
- it('should return 1 for the SIGHASH_SINGLE bug', function () {
231
- const tx = Tx.fromBuffer(tx2buf)
232
- tx.txOuts.length = 1
233
- tx.txOutsVi = VarInt.fromNumber(1)
234
- tx
235
- .sighash(Sig.SIGHASH_SINGLE, 1, new Script())
236
- .toString('hex')
237
- .should.equal(
238
- '0000000000000000000000000000000000000000000000000000000000000001'
239
- )
240
- })
241
- })
242
-
243
- describe('#asyncSighash', function () {
244
- it('should hash this transaction', async function () {
245
- const hashBuf = await tx.asyncSighash(0, 0, new Script())
246
- hashBuf.length.should.equal(32)
247
- })
248
-
249
- it('should return 1 for the SIGHASH_SINGLE bug', async function () {
250
- const tx = Tx.fromBuffer(tx2buf)
251
- tx.txOuts.length = 1
252
- tx.txOutsVi = VarInt.fromNumber(1)
253
- const hashBuf = await tx.asyncSighash(Sig.SIGHASH_SINGLE, 1, new Script())
254
- hashBuf
255
- .toString('hex')
256
- .should.equal(
257
- '0000000000000000000000000000000000000000000000000000000000000001'
258
- )
259
- })
260
- })
261
-
262
- describe('#sign', function () {
263
- it('should return a signature', function () {
264
- const keyPair = new KeyPair().fromRandom()
265
- const sig1 = tx.sign(keyPair, Sig.SIGHASH_ALL, 0, new Script())
266
- should.exist(sig1)
267
- const sig2 = tx.sign(keyPair, Sig.SIGHASH_SINGLE, 0, new Script())
268
- const sig3 = tx.sign(
269
- keyPair,
270
- Sig.SIGHASH_ALL,
271
- 0,
272
- new Script().fromString('OP_RETURN')
273
- )
274
- sig1.toString().should.not.equal(sig2.toString())
275
- sig1.toString().should.not.equal(sig3.toString())
276
- })
277
- })
278
-
279
- describe('#asyncSign', function () {
280
- it('should return a signature', async function () {
281
- const keyPair = new KeyPair().fromRandom()
282
- const sig1 = tx.sign(keyPair, Sig.SIGHASH_ALL, 0, new Script())
283
- const sig1b = await tx.asyncSign(keyPair, Sig.SIGHASH_ALL, 0, new Script())
284
- const sig2 = tx.sign(keyPair, Sig.SIGHASH_SINGLE, 0, new Script())
285
- const sig2b = await tx.asyncSign(
286
- keyPair,
287
- Sig.SIGHASH_SINGLE,
288
- 0,
289
- new Script()
290
- )
291
- const sig3 = tx.sign(
292
- keyPair,
293
- Sig.SIGHASH_ALL,
294
- 0,
295
- new Script().fromString('OP_RETURN')
296
- )
297
- const sig3b = await tx.asyncSign(
298
- keyPair,
299
- Sig.SIGHASH_ALL,
300
- 0,
301
- new Script().fromString('OP_RETURN')
302
- )
303
- sig1.toString().should.equal(sig1b.toString())
304
- sig2.toString().should.equal(sig2b.toString())
305
- sig3.toString().should.equal(sig3b.toString())
306
- })
307
- })
308
-
309
- describe('#verify', function () {
310
- it('should return a signature', function () {
311
- const keyPair = new KeyPair().fromRandom()
312
- const sig1 = tx.sign(keyPair, Sig.SIGHASH_ALL, 0, new Script())
313
- tx.verify(sig1, keyPair.pubKey, 0, new Script()).should.equal(true)
314
- })
315
- })
316
-
317
- describe('#asyncVerify', function () {
318
- it('should return a signature', async function () {
319
- const keyPair = new KeyPair().fromRandom()
320
- const sig1 = tx.sign(keyPair, Sig.SIGHASH_ALL, 0, new Script())
321
- const verified = await tx.asyncVerify(sig1, keyPair.pubKey, 0, new Script())
322
- verified.should.equal(true)
323
- })
324
- })
325
-
326
- describe('#hash', function () {
327
- it('should correctly calculate the hash of this known transaction', function () {
328
- const tx = Tx.fromBuffer(tx2buf)
329
- const txHashBuf = Buffer.from(
330
- Array.apply([], Buffer.from(tx2idhex, 'hex')).reverse()
331
- )
332
- tx
333
- .hash()
334
- .toString('hex')
335
- .should.equal(txHashBuf.toString('hex'))
336
- })
337
- })
338
-
339
- describe('#asyncHash', function () {
340
- it('should correctly calculate the hash of this known transaction', async function () {
341
- const tx = Tx.fromBuffer(tx2buf)
342
- const txHashBuf = Buffer.from(
343
- Array.apply([], Buffer.from(tx2idhex, 'hex')).reverse()
344
- )
345
- const hashBuf = await tx.asyncHash()
346
- hashBuf.toString('hex').should.equal(txHashBuf.toString('hex'))
347
- })
348
- })
349
-
350
- describe('#id', function () {
351
- it('should correctly calculate the id of this known transaction', function () {
352
- const tx = Tx.fromBuffer(tx2buf)
353
- tx
354
- .id()
355
- .should.equal(tx2idhex)
356
- })
357
- })
358
-
359
- describe('#asyncId', function () {
360
- it('should correctly calculate the id of this known transaction', async function () {
361
- const tx = Tx.fromBuffer(tx2buf)
362
- const idbuf = await tx.asyncId()
363
- idbuf.should.equal(tx2idhex)
364
- })
365
- })
366
-
367
- describe('#addTxIn', function () {
368
- it('should add an input', function () {
369
- const txIn = new TxIn()
370
- const tx = new Tx()
371
- tx.txInsVi.toNumber().should.equal(0)
372
- tx.addTxIn(txIn)
373
- tx.txInsVi.toNumber().should.equal(1)
374
- tx.txIns.length.should.equal(1)
375
- })
376
- })
377
-
378
- describe('#addTxOut', function () {
379
- it('should add an output', function () {
380
- const txOut = new TxOut()
381
- const tx = new Tx()
382
- tx.txOutsVi.toNumber().should.equal(0)
383
- tx.addTxOut(txOut)
384
- tx.txOutsVi.toNumber().should.equal(1)
385
- tx.txOuts.length.should.equal(1)
386
- })
387
- })
388
-
389
- describe('bectors: bip69 (from bitcoinjs)', function () {
390
- // returns index-based order of sorted against original
391
- function getIndexOrder (original, sorted) {
392
- return sorted.map((value) => {
393
- return original.indexOf(value)
394
- })
395
- }
396
-
397
- fixture.inputs.forEach((inputSet) => {
398
- it(inputSet.description, () => {
399
- const tx = new Tx()
400
- const txIns = inputSet.inputs.map((input) => {
401
- const txHashBuf = Buffer.from(input.txId, 'hex').reverse()
402
- const txOutNum = input.vout
403
- const script = new Script()
404
- const txIn = TxIn.fromProperties(txHashBuf, txOutNum, script)
405
- return txIn
406
- })
407
- tx.txIns = [...txIns]
408
- tx.sort()
409
- getIndexOrder(txIns, tx.txIns).toString().should.equal(inputSet.expected.toString())
410
- })
411
- })
412
-
413
- fixture.outputs.forEach((outputSet) => {
414
- it(outputSet.description, () => {
415
- const tx = new Tx()
416
- const txOuts = outputSet.outputs.map(function (output) {
417
- const txOut = TxOut.fromProperties(new Bn(output.value), Script.fromAsmString(output.script))
418
- return txOut
419
- })
420
- tx.txOuts = [...txOuts]
421
- tx.sort()
422
- getIndexOrder(txOuts, tx.txOuts).toString().should.equal(outputSet.expected.toString())
423
- })
424
- })
425
- })
426
-
427
- describe('vectors: a 1mb transaction', function () {
428
- it('should find the correct id of this (valid, on the blockchain) 1 mb transaction', function () {
429
- const txidhex = largesttxvector.txidhex
430
- const txhex = largesttxvector.txhex
431
- const tx = Tx.fromHex(txhex)
432
- const txid = tx.id()
433
- txid.should.equal(txidhex)
434
- })
435
- })
436
-
437
- describe('vectors: sighash and serialization', function () {
438
- vectorsBitcoindSighash.forEach(function (vector, i) {
439
- if (i === 0) {
440
- return
441
- }
442
- it('should pass bitcoind sighash test vector ' + i, function () {
443
- const txbuf = Buffer.from(vector[0], 'hex')
444
- const scriptbuf = Buffer.from(vector[1], 'hex')
445
- const subScript = new Script().fromBuffer(scriptbuf)
446
- const nIn = vector[2]
447
- const nHashType = vector[3]
448
- const sighashBuf = Buffer.from(vector[4], 'hex')
449
- const tx = Tx.fromBuffer(txbuf)
450
-
451
- // make sure transacion to/from buffer is isomorphic
452
- tx
453
- .toHex()
454
- .should.equal(txbuf.toString('hex'))
455
-
456
- // sighash ought to be correct
457
- tx
458
- .sighash(nHashType, nIn, subScript)
459
- .toString('hex')
460
- .should.equal(sighashBuf.toString('hex'))
461
- })
462
- })
463
-
464
- vectorsBitcoinABCSighash.forEach(function (vector, i) {
465
- if (i === 0) {
466
- return
467
- }
468
- it('should pass bitcoin-abc sighash test vector ' + i, function () {
469
- if (vector[0] === 'Test vectors for SIGHASH_FORKID') {
470
- return
471
- }
472
- const txbuf = Buffer.from(vector[0], 'hex')
473
- const scriptbuf = Buffer.from(vector[1], 'hex')
474
- const subScript = new Script().fromBuffer(scriptbuf)
475
- const nIn = vector[2]
476
- const nHashType = vector[3]
477
- const sighashBuf = Buffer.from(vector[4], 'hex')
478
- const tx = Tx.fromBuffer(txbuf)
479
-
480
- // make sure transacion to/from buffer is isomorphic
481
- tx
482
- .toBuffer()
483
- .toString('hex')
484
- .should.equal(txbuf.toString('hex'))
485
-
486
- // sighash ought to be correct
487
- const valueBn = new Bn(0)
488
- let flags = 0
489
- if (nHashType & Sig.SIGHASH_FORKID) {
490
- flags = Interp.SCRIPT_ENABLE_SIGHASH_FORKID
491
- }
492
- tx
493
- .sighash(nHashType, nIn, subScript, valueBn, flags)
494
- .toString('hex')
495
- .should.equal(sighashBuf.toString('hex'))
496
- })
497
- })
498
-
499
- let j = 0
500
- vectorsBitcoindTxValid.forEach(function (vector, i) {
501
- if (vector.length === 1) {
502
- return
503
- }
504
- it(
505
- 'should correctly serialized/deserialize tx_valid test vector ' + j,
506
- function () {
507
- const txhex = vector[1]
508
- const txbuf = Buffer.from(vector[1], 'hex')
509
- const tx = Tx.fromBuffer(txbuf)
510
- tx
511
- .toBuffer()
512
- .toString('hex')
513
- .should.equal(txhex)
514
- }
515
- )
516
- j++
517
- })
518
-
519
- j = 0
520
- vectorsBitcoindTxInvalid.forEach(function (vector, i) {
521
- if (vector.length === 1) {
522
- return
523
- }
524
- it(
525
- 'should correctly serialized/deserialize tx_invalid test vector ' + j,
526
- function () {
527
- const txhex = vector[1]
528
- const txbuf = Buffer.from(vector[1], 'hex')
529
- const tx = Tx.fromBuffer(txbuf)
530
- tx
531
- .toBuffer()
532
- .toString('hex')
533
- .should.equal(txhex)
534
- }
535
- )
536
- j++
537
- })
538
- })
539
- })
package/test/var-int.js DELETED
@@ -1,132 +0,0 @@
1
- /* global describe,it */
2
- 'use strict'
3
- import { Bn } from '../lib/bn'
4
- import should from 'should'
5
- import { Br } from '../lib/br'
6
- import { Bw } from '../lib/bw'
7
- import { VarInt } from '../lib/var-int'
8
-
9
- describe('VarInt', function () {
10
- it('should make a new varInt', function () {
11
- const buf = Buffer.from('00', 'hex')
12
- let varInt = new VarInt(buf)
13
- should.exist(varInt)
14
- varInt.buf.toString('hex').should.equal('00')
15
- varInt = new VarInt(buf)
16
- should.exist(varInt)
17
- varInt.buf.toString('hex').should.equal('00')
18
-
19
- // varInts can have multiple buffer representations
20
- VarInt.fromNumber(0)
21
- .toNumber()
22
- .should.equal(new VarInt(Buffer.from([0xfd, 0, 0])).toNumber())
23
- VarInt.fromNumber(0)
24
- .toBuffer()
25
- .toString('hex')
26
- .should.not.equal(
27
- new VarInt()
28
- .fromBuffer(Buffer.from([0xfd, 0, 0]))
29
- .toBuffer()
30
- .toString('hex')
31
- )
32
- })
33
-
34
- describe('#fromObject', function () {
35
- it('should set a buffer', function () {
36
- const buf = Buffer.from('00', 'hex')
37
- const varInt = new VarInt().fromObject({ buf: buf })
38
- varInt.buf.toString('hex').should.equal('00')
39
- varInt.fromObject({})
40
- varInt.buf.toString('hex').should.equal('00')
41
- })
42
- })
43
-
44
- describe('#fromJSON', function () {
45
- it('should set a buffer', function () {
46
- const buf = new Bw().writeVarIntNum(5).toBuffer()
47
- const varInt = new VarInt().fromJSON(buf.toString('hex'))
48
- varInt.toNumber().should.equal(5)
49
- })
50
- })
51
-
52
- describe('#toJSON', function () {
53
- it('should return a buffer', function () {
54
- const buf = new Bw().writeVarIntNum(5).toBuffer()
55
- const varInt = new VarInt().fromJSON(buf.toString('hex'))
56
- varInt.toJSON().should.equal('05')
57
- })
58
- })
59
-
60
- describe('#fromBuffer', function () {
61
- it('should set a buffer', function () {
62
- const buf = new Bw().writeVarIntNum(5).toBuffer()
63
- const varInt = new VarInt().fromBuffer(buf)
64
- varInt.toNumber().should.equal(5)
65
- })
66
- })
67
-
68
- describe('#fromBr', function () {
69
- it('should set a buffer reader', function () {
70
- const buf = new Bw().writeVarIntNum(5).toBuffer()
71
- const br = new Br(buf)
72
- const varInt = new VarInt().fromBr(br)
73
- varInt.toNumber().should.equal(5)
74
- })
75
- })
76
-
77
- describe('#fromBn', function () {
78
- it('should set a number', function () {
79
- const varInt = new VarInt().fromBn(new Bn(5))
80
- varInt.toNumber().should.equal(5)
81
- })
82
- })
83
-
84
- describe('@fromBn', function () {
85
- it('should set a number', function () {
86
- const varInt = VarInt.fromBn(new Bn(5))
87
- varInt.toNumber().should.equal(5)
88
- })
89
- })
90
-
91
- describe('#fromNumber', function () {
92
- it('should set a number', function () {
93
- const varInt = new VarInt().fromNumber(5)
94
- varInt.toNumber().should.equal(5)
95
- })
96
- })
97
-
98
- describe('@fromNumber', function () {
99
- it('should set a number', function () {
100
- const varInt = VarInt.fromNumber(5)
101
- varInt.toNumber().should.equal(5)
102
- })
103
- })
104
-
105
- describe('#toBuffer', function () {
106
- it('should return a buffer', function () {
107
- const buf = new Bw().writeVarIntNum(5).toBuffer()
108
- const varInt = new VarInt(buf)
109
- varInt
110
- .toBuffer()
111
- .toString('hex')
112
- .should.equal(buf.toString('hex'))
113
- })
114
- })
115
-
116
- describe('#toBn', function () {
117
- it('should return a buffer', function () {
118
- const varInt = VarInt.fromNumber(5)
119
- varInt
120
- .toBn()
121
- .toString()
122
- .should.equal(new Bn(5).toString())
123
- })
124
- })
125
-
126
- describe('#toNumber', function () {
127
- it('should return a buffer', function () {
128
- const varInt = VarInt.fromNumber(5)
129
- varInt.toNumber().should.equal(5)
130
- })
131
- })
132
- })