bsv2 2.0.24 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/dist/bsv2.mjs +36061 -4
  2. package/package.json +35 -39
  3. package/.babelrc.test +0 -10
  4. package/.editorconfig +0 -4
  5. package/.env.defaults +0 -1
  6. package/.env.schema +0 -1
  7. package/.husky/pre-commit +0 -1
  8. package/.mocharc.yml +0 -4
  9. package/.nvmrc +0 -1
  10. package/.travis.yml +0 -7
  11. package/benchmark.js +0 -50
  12. package/bin/bsv.js +0 -11
  13. package/bin/network.js +0 -92
  14. package/build/index.html +0 -20
  15. package/dist/bsv2.bundle.js +0 -8
  16. package/dist/bsv2.cjs.js +0 -2
  17. package/dist/bsv2.cjs.js.LICENSE.txt +0 -1
  18. package/dist/bsv2.module.js +0 -2
  19. package/entry.js +0 -82
  20. package/index.js +0 -102
  21. package/karma.conf.js +0 -78
  22. package/lib/ach.js +0 -59
  23. package/lib/address.js +0 -264
  24. package/lib/aes.js +0 -57
  25. package/lib/aescbc.js +0 -38
  26. package/lib/base-58-check.js +0 -83
  27. package/lib/base-58.js +0 -59
  28. package/lib/bip-32.js +0 -472
  29. package/lib/bip-39-en-wordlist.js +0 -2054
  30. package/lib/bip-39-en.js +0 -10
  31. package/lib/bip-39-es-wordlist.js +0 -2055
  32. package/lib/bip-39-es.js +0 -10
  33. package/lib/bip-39-jp-wordlist.js +0 -2053
  34. package/lib/bip-39-jp.js +0 -10
  35. package/lib/bip-39-words.js +0 -5
  36. package/lib/bip-39.js +0 -285
  37. package/lib/block-header.js +0 -79
  38. package/lib/block.js +0 -132
  39. package/lib/bn.js +0 -467
  40. package/lib/br.js +0 -172
  41. package/lib/bsm.js +0 -127
  42. package/lib/bw.js +0 -188
  43. package/lib/cbc.js +0 -140
  44. package/lib/cmp.js +0 -37
  45. package/lib/config.js +0 -50
  46. package/lib/constants.js +0 -150
  47. package/lib/ecdsa.js +0 -495
  48. package/lib/ecies.js +0 -151
  49. package/lib/hash-cache.js +0 -41
  50. package/lib/hash.js +0 -191
  51. package/lib/interp.js +0 -2013
  52. package/lib/inv.js +0 -49
  53. package/lib/key-pair.js +0 -133
  54. package/lib/mainnet-address.js +0 -5
  55. package/lib/mainnet-bip-32.js +0 -5
  56. package/lib/mainnet-key-pair.js +0 -5
  57. package/lib/mainnet-priv-key.js +0 -5
  58. package/lib/merkle.js +0 -92
  59. package/lib/msg.js +0 -184
  60. package/lib/op-code.js +0 -398
  61. package/lib/point.js +0 -134
  62. package/lib/priv-key.js +0 -157
  63. package/lib/pub-key.js +0 -230
  64. package/lib/random.js +0 -28
  65. package/lib/script.js +0 -826
  66. package/lib/sig-operations.js +0 -120
  67. package/lib/sig.js +0 -399
  68. package/lib/struct.js +0 -389
  69. package/lib/testnet-address.js +0 -5
  70. package/lib/testnet-bip-32.js +0 -5
  71. package/lib/testnet-key-pair.js +0 -5
  72. package/lib/testnet-priv-key.js +0 -5
  73. package/lib/tx-builder.js +0 -593
  74. package/lib/tx-in.js +0 -172
  75. package/lib/tx-out-map.js +0 -57
  76. package/lib/tx-out.js +0 -73
  77. package/lib/tx-verifier.js +0 -209
  78. package/lib/tx.js +0 -430
  79. package/lib/var-int.js +0 -73
  80. package/lib/version.js +0 -92
  81. package/lib/workers-result.js +0 -65
  82. package/lib/workers.js +0 -77
  83. package/load-babel.js +0 -3
  84. package/mtest/test.html +0 -15
  85. package/mtest/test.js +0 -2
  86. package/mtest/test.mjs +0 -2
  87. package/test/ach.js +0 -172
  88. package/test/address.js +0 -464
  89. package/test/aes.js +0 -96
  90. package/test/aescbc.js +0 -65
  91. package/test/base-58-check.js +0 -128
  92. package/test/base-58.js +0 -113
  93. package/test/bip-32.js +0 -721
  94. package/test/bip-39.js +0 -282
  95. package/test/block-header.js +0 -152
  96. package/test/block.js +0 -243
  97. package/test/bn.js +0 -643
  98. package/test/br.js +0 -353
  99. package/test/bsm.js +0 -141
  100. package/test/bw.js +0 -292
  101. package/test/cbc.js +0 -335
  102. package/test/cmp.js +0 -56
  103. package/test/data/bip69.json +0 -215
  104. package/test/data/bitcoind/base58_keys_invalid.json +0 -152
  105. package/test/data/bitcoind/base58_keys_valid.json +0 -452
  106. package/test/data/bitcoind/blocks.json +0 -27
  107. package/test/data/bitcoind/script_tests.json +0 -2244
  108. package/test/data/bitcoind/sig_canonical.json +0 -7
  109. package/test/data/bitcoind/sig_noncanonical.json +0 -22
  110. package/test/data/bitcoind/tx_invalid.json +0 -177
  111. package/test/data/bitcoind/tx_valid.json +0 -224
  112. package/test/data/blk86756-testnet.dat +0 -0
  113. package/test/data/blk86756-testnet.js +0 -12
  114. package/test/data/blk86756-testnet.json +0 -684
  115. package/test/data/ecdsa.json +0 -230
  116. package/test/data/messages.json +0 -22
  117. package/test/data/sighash.json +0 -1004
  118. package/test/data/tx_creation.json +0 -85
  119. package/test/ecdsa.js +0 -748
  120. package/test/ecies.js +0 -238
  121. package/test/global.js +0 -13
  122. package/test/hash-cache.js +0 -52
  123. package/test/hash.js +0 -354
  124. package/test/index.js +0 -10
  125. package/test/interp.js +0 -512
  126. package/test/inv.js +0 -65
  127. package/test/key-pair.js +0 -243
  128. package/test/merkle.js +0 -179
  129. package/test/msg.js +0 -295
  130. package/test/op-code.js +0 -79
  131. package/test/point.js +0 -375
  132. package/test/priv-key.js +0 -264
  133. package/test/pub-key.js +0 -549
  134. package/test/random.js +0 -31
  135. package/test/script.js +0 -1340
  136. package/test/sig-operations.js +0 -149
  137. package/test/sig.js +0 -662
  138. package/test/struct.js +0 -552
  139. package/test/tx-builder.js +0 -2104
  140. package/test/tx-in.js +0 -198
  141. package/test/tx-out-map.js +0 -104
  142. package/test/tx-out.js +0 -162
  143. package/test/tx-verifier.js +0 -246
  144. package/test/tx.js +0 -539
  145. package/test/var-int.js +0 -132
  146. package/test/vectors/aes.json +0 -10392
  147. package/test/vectors/aescbc.json +0 -620
  148. package/test/vectors/bip39.json +0 -502
  149. package/test/vectors/bip69.json +0 -215
  150. package/test/vectors/bitcoin-abc/script_tests.json +0 -48
  151. package/test/vectors/bitcoin-abc/sighash.json +0 -7004
  152. package/test/vectors/bitcoin-sv/script_tests.json +0 -248
  153. package/test/vectors/bitcoind/script_invalid.json +0 -1151
  154. package/test/vectors/bitcoind/script_valid.json +0 -1462
  155. package/test/vectors/bitcoind/sighash.json +0 -3503
  156. package/test/vectors/bitcoind/tx_invalid.json +0 -883
  157. package/test/vectors/bitcoind/tx_valid.json +0 -1150
  158. package/test/vectors/coolest-tx-ever-sent.json +0 -8
  159. package/test/vectors/ecdsa.json +0 -300
  160. package/test/vectors/hash.json +0 -6133
  161. package/test/vectors/kdf.json +0 -47
  162. package/test/vectors/largesttx.json +0 -5
  163. package/test/vectors/largesttxblock.json +0 -6
  164. package/test/vectors/sig.json +0 -79
  165. package/test/vectors/sighash-single-bug.json +0 -8
  166. package/test/version.js +0 -81
  167. package/test/workers-result.js +0 -89
  168. package/test/workers.js +0 -91
  169. package/test-index.js +0 -3
  170. package/webpack.config.js +0 -115
package/test/sig.js DELETED
@@ -1,662 +0,0 @@
1
- /* global describe,it */
2
- 'use strict'
3
- import { Bn } from '../lib/bn'
4
- import should from 'should'
5
- import { Sig } from '../lib/sig'
6
- import vectors from './vectors/sig.json'
7
-
8
- describe('Sig', function () {
9
- it('should make a blank signature', function () {
10
- const sig = new Sig()
11
- should.exist(sig)
12
- })
13
-
14
- it('should work with conveniently setting r, s', function () {
15
- const r = new Bn()
16
- const s = new Bn()
17
- const sig = new Sig(r, s)
18
- should.exist(sig)
19
- sig.r.toString().should.equal(r.toString())
20
- sig.s.toString().should.equal(s.toString())
21
- })
22
-
23
- describe('#fromObject', function () {
24
- it('should set compressed', function () {
25
- should.exist(new Sig().fromObject({ compressed: true }))
26
- })
27
- })
28
-
29
- describe('#fromHex', function () {
30
- it('should parse this known signature and rebuild it', function () {
31
- const hex =
32
- '3044022007415aa37ce7eaa6146001ac8bdefca0ddcba0e37c5dc08c4ac99392124ebac802207d382307fd53f65778b07b9c63b6e196edeadf0be719130c5db21ff1e700d67501'
33
- const sig = new Sig().fromHex(hex)
34
- sig.toHex().should.equal(hex)
35
- })
36
-
37
- it('should create a signature from a compressed signature', function () {
38
- const blank = Buffer.alloc(32)
39
- blank.fill(0)
40
- const compressed = Buffer.concat([Buffer.from([0 + 27 + 4]), blank, blank])
41
- const sig = new Sig()
42
- sig.fromHex(compressed.toString('hex'))
43
- sig.r.cmp(0).should.equal(0)
44
- sig.s.cmp(0).should.equal(0)
45
- })
46
-
47
- it('should parse this DER format signature', function () {
48
- const buf = Buffer.from(
49
- '3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2',
50
- 'hex'
51
- )
52
- const sig = new Sig()
53
- sig.fromHex(buf.toString('hex'))
54
- sig.r
55
- .toBuffer({ size: 32 })
56
- .toString('hex')
57
- .should.equal(
58
- '75fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e6277'
59
- )
60
- sig.s
61
- .toBuffer({ size: 32 })
62
- .toString('hex')
63
- .should.equal(
64
- '729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2'
65
- )
66
- })
67
-
68
- it('should parse this known signature and rebuild it', function () {
69
- const hex =
70
- '3044022007415aa37ce7eaa6146001ac8bdefca0ddcba0e37c5dc08c4ac99392124ebac802207d382307fd53f65778b07b9c63b6e196edeadf0be719130c5db21ff1e700d67501'
71
- const sig = new Sig().fromHex(hex)
72
- sig
73
- .toTxFormat()
74
- .toString('hex')
75
- .should.equal(hex)
76
- })
77
- })
78
-
79
- describe('#fromBuffer', function () {
80
- it('should create a signature from a compressed signature', function () {
81
- const blank = Buffer.alloc(32)
82
- blank.fill(0)
83
- const compressed = Buffer.concat([Buffer.from([0 + 27 + 4]), blank, blank])
84
- const sig = new Sig()
85
- sig.fromBuffer(compressed)
86
- sig.r.cmp(0).should.equal(0)
87
- sig.s.cmp(0).should.equal(0)
88
- })
89
-
90
- it('should parse this DER format signature', function () {
91
- const buf = Buffer.from(
92
- '3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2',
93
- 'hex'
94
- )
95
- const sig = new Sig()
96
- sig.fromBuffer(buf)
97
- sig.r
98
- .toBuffer({ size: 32 })
99
- .toString('hex')
100
- .should.equal(
101
- '75fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e6277'
102
- )
103
- sig.s
104
- .toBuffer({ size: 32 })
105
- .toString('hex')
106
- .should.equal(
107
- '729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2'
108
- )
109
- })
110
-
111
- it('should parse this known signature and rebuild it', function () {
112
- const hex =
113
- '3044022007415aa37ce7eaa6146001ac8bdefca0ddcba0e37c5dc08c4ac99392124ebac802207d382307fd53f65778b07b9c63b6e196edeadf0be719130c5db21ff1e700d67501'
114
- const buf = Buffer.from(hex, 'hex')
115
- const sig = new Sig().fromBuffer(buf)
116
- sig
117
- .toTxFormat()
118
- .toString('hex')
119
- .should.equal(hex)
120
- })
121
- })
122
-
123
- describe('#fromCompact', function () {
124
- it('should create a signature from a compressed signature', function () {
125
- const blank = Buffer.alloc(32)
126
- blank.fill(0)
127
- const compact = Buffer.concat([Buffer.from([0 + 27 + 4]), blank, blank])
128
- const sig = new Sig()
129
- sig.fromCompact(compact)
130
- sig.compressed.should.equal(true)
131
- sig.r.cmp(0).should.equal(0)
132
- sig.s.cmp(0).should.equal(0)
133
- })
134
- })
135
-
136
- describe('@fromCompact', function () {
137
- it('should create a signature from a compressed signature', function () {
138
- const blank = Buffer.alloc(32)
139
- blank.fill(0)
140
- const compact = Buffer.concat([Buffer.from([0 + 27 + 4]), blank, blank])
141
- const sig = Sig.fromCompact(compact)
142
- sig.compressed.should.equal(true)
143
- sig.r.cmp(0).should.equal(0)
144
- sig.s.cmp(0).should.equal(0)
145
- })
146
- })
147
-
148
- describe('#fromDer', function () {
149
- const buf = Buffer.from(
150
- '3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2',
151
- 'hex'
152
- )
153
-
154
- it('should parse this DER format signature', function () {
155
- const sig = new Sig()
156
- sig.fromDer(buf)
157
- sig.r
158
- .toBuffer({ size: 32 })
159
- .toString('hex')
160
- .should.equal(
161
- '75fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e6277'
162
- )
163
- sig.s
164
- .toBuffer({ size: 32 })
165
- .toString('hex')
166
- .should.equal(
167
- '729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2'
168
- )
169
- })
170
- })
171
-
172
- describe('@fromDer', function () {
173
- const buf = Buffer.from(
174
- '3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2',
175
- 'hex'
176
- )
177
-
178
- it('should parse this DER format signature', function () {
179
- const sig = Sig.fromDer(buf)
180
- sig.r
181
- .toBuffer({ size: 32 })
182
- .toString('hex')
183
- .should.equal(
184
- '75fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e6277'
185
- )
186
- sig.s
187
- .toBuffer({ size: 32 })
188
- .toString('hex')
189
- .should.equal(
190
- '729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2'
191
- )
192
- })
193
- })
194
-
195
- describe('#fromTxFormat', function () {
196
- it('should convert from this known tx-format buffer', function () {
197
- const buf = Buffer.from(
198
- '30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e7201',
199
- 'hex'
200
- )
201
- const sig = new Sig().fromTxFormat(buf)
202
- sig.r
203
- .toString()
204
- .should.equal(
205
- '63173831029936981022572627018246571655303050627048489594159321588908385378810'
206
- )
207
- sig.s
208
- .toString()
209
- .should.equal(
210
- '4331694221846364448463828256391194279133231453999942381442030409253074198130'
211
- )
212
- sig.nHashType.should.equal(Sig.SIGHASH_ALL)
213
- })
214
-
215
- it('should parse this known signature and rebuild it', function () {
216
- const hex =
217
- '3044022007415aa37ce7eaa6146001ac8bdefca0ddcba0e37c5dc08c4ac99392124ebac802207d382307fd53f65778b07b9c63b6e196edeadf0be719130c5db21ff1e700d67501'
218
- const buf = Buffer.from(hex, 'hex')
219
- const sig = new Sig().fromTxFormat(buf)
220
- sig
221
- .toTxFormat()
222
- .toString('hex')
223
- .should.equal(hex)
224
- })
225
- })
226
-
227
- describe('@fromTxFormat', function () {
228
- it('should convert from this known tx-format buffer', function () {
229
- const buf = Buffer.from(
230
- '30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e7201',
231
- 'hex'
232
- )
233
- const sig = Sig.fromTxFormat(buf)
234
- sig.r
235
- .toString()
236
- .should.equal(
237
- '63173831029936981022572627018246571655303050627048489594159321588908385378810'
238
- )
239
- sig.s
240
- .toString()
241
- .should.equal(
242
- '4331694221846364448463828256391194279133231453999942381442030409253074198130'
243
- )
244
- sig.nHashType.should.equal(Sig.SIGHASH_ALL)
245
- })
246
-
247
- it('should parse this known signature and rebuild it', function () {
248
- const hex =
249
- '3044022007415aa37ce7eaa6146001ac8bdefca0ddcba0e37c5dc08c4ac99392124ebac802207d382307fd53f65778b07b9c63b6e196edeadf0be719130c5db21ff1e700d67501'
250
- const buf = Buffer.from(hex, 'hex')
251
- const sig = Sig.fromTxFormat(buf)
252
- sig
253
- .toTxFormat()
254
- .toString('hex')
255
- .should.equal(hex)
256
- })
257
- })
258
-
259
- describe('#fromString', function () {
260
- const buf = Buffer.from(
261
- '3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2',
262
- 'hex'
263
- )
264
-
265
- it('should parse this DER format signature in hex', function () {
266
- const sig = new Sig()
267
- sig.fromString(buf.toString('hex'))
268
- sig.r
269
- .toBuffer({ size: 32 })
270
- .toString('hex')
271
- .should.equal(
272
- '75fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e6277'
273
- )
274
- sig.s
275
- .toBuffer({ size: 32 })
276
- .toString('hex')
277
- .should.equal(
278
- '729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2'
279
- )
280
- })
281
- })
282
-
283
- describe('#parseDer', function () {
284
- it('should parse this signature generated in node', function () {
285
- const sighex =
286
- '30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
287
- const sig = Buffer.from(sighex, 'hex')
288
- const parsed = Sig.parseDer(sig)
289
- parsed.header.should.equal(0x30)
290
- parsed.length.should.equal(69)
291
- parsed.rlength.should.equal(33)
292
- parsed.rneg.should.equal(true)
293
- parsed.rbuf
294
- .toString('hex')
295
- .should.equal(
296
- '008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa'
297
- )
298
- parsed.r
299
- .toString()
300
- .should.equal(
301
- '63173831029936981022572627018246571655303050627048489594159321588908385378810'
302
- )
303
- parsed.slength.should.equal(32)
304
- parsed.sneg.should.equal(false)
305
- parsed.sbuf
306
- .toString('hex')
307
- .should.equal(
308
- '0993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
309
- )
310
- parsed.s
311
- .toString()
312
- .should.equal(
313
- '4331694221846364448463828256391194279133231453999942381442030409253074198130'
314
- )
315
- })
316
-
317
- it('should parse this 69 byte signature', function () {
318
- const sighex =
319
- '3043021f59e4705959cc78acbfcf8bd0114e9cc1b389a4287fb33152b73a38c319b50302202f7428a27284c757e409bf41506183e9e49dfb54d5063796dfa0d403a4deccfa'
320
- const sig = Buffer.from(sighex, 'hex')
321
- const parsed = Sig.parseDer(sig)
322
- parsed.header.should.equal(0x30)
323
- parsed.length.should.equal(67)
324
- parsed.rlength.should.equal(31)
325
- parsed.rneg.should.equal(false)
326
- parsed.rbuf
327
- .toString('hex')
328
- .should.equal(
329
- '59e4705959cc78acbfcf8bd0114e9cc1b389a4287fb33152b73a38c319b503'
330
- )
331
- parsed.r
332
- .toString()
333
- .should.equal(
334
- '158826015856106182499128681792325160381907915189052224498209222621383996675'
335
- )
336
- parsed.slength.should.equal(32)
337
- parsed.sneg.should.equal(false)
338
- parsed.sbuf
339
- .toString('hex')
340
- .should.equal(
341
- '2f7428a27284c757e409bf41506183e9e49dfb54d5063796dfa0d403a4deccfa'
342
- )
343
- parsed.s
344
- .toString()
345
- .should.equal(
346
- '21463938592353267769710297084836796652964571266930856168996063301532842380538'
347
- )
348
- })
349
-
350
- it('should parse this 68 byte signature', function () {
351
- const sighex =
352
- '3042021e17cfe77536c3fb0526bd1a72d7a8e0973f463add210be14063c8a9c37632022061bfa677f825ded82ba0863fb0c46ca1388dd3e647f6a93c038168b59d131a51'
353
- const sig = Buffer.from(sighex, 'hex')
354
- const parsed = Sig.parseDer(sig)
355
- parsed.header.should.equal(0x30)
356
- parsed.length.should.equal(66)
357
- parsed.rlength.should.equal(30)
358
- parsed.rneg.should.equal(false)
359
- parsed.rbuf
360
- .toString('hex')
361
- .should.equal(
362
- '17cfe77536c3fb0526bd1a72d7a8e0973f463add210be14063c8a9c37632'
363
- )
364
- parsed.r
365
- .toString()
366
- .should.equal(
367
- '164345250294671732127776123343329699648286106708464198588053542748255794'
368
- )
369
- parsed.slength.should.equal(32)
370
- parsed.sneg.should.equal(false)
371
- parsed.sbuf
372
- .toString('hex')
373
- .should.equal(
374
- '61bfa677f825ded82ba0863fb0c46ca1388dd3e647f6a93c038168b59d131a51'
375
- )
376
- parsed.s
377
- .toString()
378
- .should.equal(
379
- '44212963026209759051804639008236126356702363229859210154760104982946304432721'
380
- )
381
- })
382
- })
383
-
384
- describe('@IsTxDer', function () {
385
- it('should know this is a DER signature', function () {
386
- const sighex =
387
- '3042021e17cfe77536c3fb0526bd1a72d7a8e0973f463add210be14063c8a9c37632022061bfa677f825ded82ba0863fb0c46ca1388dd3e647f6a93c038168b59d131a5101'
388
- const sigbuf = Buffer.from(sighex, 'hex')
389
- Sig.IsTxDer(sigbuf).should.equal(true)
390
- })
391
-
392
- it('should know this is not a DER signature', function () {
393
- // for more extensive tests, see the script interpreter
394
- const sighex =
395
- '3042021e17cfe77536c3fb0526bd1a72d7a8e0973f463add210be14063c8a9c37632022061bfa677f825ded82ba0863fb0c46ca1388dd3e647f6a93c038168b59d131a5101'
396
- const sigbuf = Buffer.from(sighex, 'hex')
397
- sigbuf[0] = 0x31
398
- Sig.IsTxDer(sigbuf).should.equal(false)
399
- })
400
- })
401
-
402
- describe('#toHex', function () {
403
- it('should convert these known r and s values into a known signature', function () {
404
- const r = new Bn(
405
- '63173831029936981022572627018246571655303050627048489594159321588908385378810'
406
- )
407
- const s = new Bn(
408
- '4331694221846364448463828256391194279133231453999942381442030409253074198130'
409
- )
410
- const sig = new Sig(r, s)
411
- sig
412
- .toHex()
413
- .should.equal(
414
- '30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
415
- )
416
- })
417
-
418
- it('should convert these known r, s, nHashType values into a known signature', function () {
419
- const r = new Bn(
420
- '63173831029936981022572627018246571655303050627048489594159321588908385378810'
421
- )
422
- const s = new Bn(
423
- '4331694221846364448463828256391194279133231453999942381442030409253074198130'
424
- )
425
- const nHashType = Sig.SIGHASH_ALL
426
- const sig = new Sig(r, s, nHashType)
427
- sig
428
- .toHex()
429
- .should.equal(
430
- '30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e7201'
431
- )
432
- })
433
-
434
- it('should convert these known r and s values and guessed i values into signature', function () {
435
- const r = new Bn(
436
- '63173831029936981022572627018246571655303050627048489594159321588908385378810'
437
- )
438
- const s = new Bn(
439
- '4331694221846364448463828256391194279133231453999942381442030409253074198130'
440
- )
441
- let sig = Sig.fromObject({ r: r, s: s, recovery: 0 })
442
- sig
443
- .toHex()
444
- .toString('hex')
445
- .should.equal(
446
- '1f8bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa0993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
447
- )
448
- sig = Sig.fromObject({ r: r, s: s, recovery: 1 })
449
- sig
450
- .toHex()
451
- .toString('hex')
452
- .should.equal(
453
- '208bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa0993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
454
- )
455
- sig = Sig.fromObject({ r: r, s: s, recovery: 2 })
456
- sig
457
- .toHex()
458
- .toString('hex')
459
- .should.equal(
460
- '218bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa0993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
461
- )
462
- sig = Sig.fromObject({ r: r, s: s, recovery: 3 })
463
- sig
464
- .toHex()
465
- .toString('hex')
466
- .should.equal(
467
- '228bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa0993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
468
- )
469
- })
470
- })
471
-
472
- describe('#toBuffer', function () {
473
- it('should convert these known r and s values into a known signature', function () {
474
- const r = new Bn(
475
- '63173831029936981022572627018246571655303050627048489594159321588908385378810'
476
- )
477
- const s = new Bn(
478
- '4331694221846364448463828256391194279133231453999942381442030409253074198130'
479
- )
480
- const sig = Sig.fromObject({ r: r, s: s })
481
- const der = sig.toBuffer()
482
- der
483
- .toString('hex')
484
- .should.equal(
485
- '30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
486
- )
487
- })
488
-
489
- it('should convert these known r, s, nHashType values into a known signature', function () {
490
- const r = new Bn(
491
- '63173831029936981022572627018246571655303050627048489594159321588908385378810'
492
- )
493
- const s = new Bn(
494
- '4331694221846364448463828256391194279133231453999942381442030409253074198130'
495
- )
496
- const nHashType = Sig.SIGHASH_ALL
497
- const sig = new Sig(r, s, nHashType)
498
- const buf = sig.toBuffer()
499
- buf
500
- .toString('hex')
501
- .should.equal(
502
- '30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e7201'
503
- )
504
- })
505
-
506
- it('should convert these known r and s values and guessed recovery values into signature', function () {
507
- const r = new Bn(
508
- '63173831029936981022572627018246571655303050627048489594159321588908385378810'
509
- )
510
- const s = new Bn(
511
- '4331694221846364448463828256391194279133231453999942381442030409253074198130'
512
- )
513
- let sig = Sig.fromObject({ r: r, s: s, recovery: 0 })
514
- sig
515
- .toBuffer()
516
- .toString('hex')
517
- .should.equal(
518
- '1f8bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa0993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
519
- )
520
- sig = Sig.fromObject({ r: r, s: s, recovery: 1 })
521
- sig
522
- .toBuffer()
523
- .toString('hex')
524
- .should.equal(
525
- '208bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa0993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
526
- )
527
- sig = Sig.fromObject({ r: r, s: s, recovery: 2 })
528
- sig
529
- .toBuffer()
530
- .toString('hex')
531
- .should.equal(
532
- '218bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa0993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
533
- )
534
- sig = Sig.fromObject({ r: r, s: s, recovery: 3 })
535
- sig
536
- .toBuffer()
537
- .toString('hex')
538
- .should.equal(
539
- '228bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa0993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
540
- )
541
- })
542
- })
543
-
544
- describe('#toCompact', function () {
545
- it('should convert these known r and s values and guessed i values into signature', function () {
546
- const r = new Bn(
547
- '63173831029936981022572627018246571655303050627048489594159321588908385378810'
548
- )
549
- const s = new Bn(
550
- '4331694221846364448463828256391194279133231453999942381442030409253074198130'
551
- )
552
- let sig = Sig.fromObject({ r: r, s: s, recovery: 0 })
553
- sig
554
- .toCompact()
555
- .toString('hex')
556
- .should.equal(
557
- '1f8bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa0993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
558
- )
559
- sig = Sig.fromObject({ r: r, s: s, recovery: 1 })
560
- sig
561
- .toCompact()
562
- .toString('hex')
563
- .should.equal(
564
- '208bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa0993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
565
- )
566
- sig = Sig.fromObject({ r: r, s: s, recovery: 2 })
567
- sig
568
- .toCompact()
569
- .toString('hex')
570
- .should.equal(
571
- '218bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa0993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
572
- )
573
- sig = Sig.fromObject({ r: r, s: s, recovery: 3 })
574
- sig
575
- .toCompact()
576
- .toString('hex')
577
- .should.equal(
578
- '228bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa0993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
579
- )
580
- })
581
- })
582
-
583
- describe('#toDer', function () {
584
- it('should convert these known r and s values into a known signature', function () {
585
- const r = new Bn(
586
- '63173831029936981022572627018246571655303050627048489594159321588908385378810'
587
- )
588
- const s = new Bn(
589
- '4331694221846364448463828256391194279133231453999942381442030409253074198130'
590
- )
591
- const sig = Sig.fromObject({ r: r, s: s })
592
- const der = sig.toDer()
593
- der
594
- .toString('hex')
595
- .should.equal(
596
- '30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
597
- )
598
- })
599
- })
600
-
601
- describe('#toTxFormat', function () {
602
- it('should convert these known r, s, nHashType values into a known signature', function () {
603
- const r = new Bn(
604
- '63173831029936981022572627018246571655303050627048489594159321588908385378810'
605
- )
606
- const s = new Bn(
607
- '4331694221846364448463828256391194279133231453999942381442030409253074198130'
608
- )
609
- const nHashType = Sig.SIGHASH_ALL
610
- const sig = new Sig(r, s, nHashType)
611
- const buf = sig.toTxFormat()
612
- buf
613
- .toString('hex')
614
- .should.equal(
615
- '30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e7201'
616
- )
617
- })
618
- })
619
-
620
- describe('#toString', function () {
621
- it('should convert this signature in to hex DER', function () {
622
- const r = new Bn(
623
- '63173831029936981022572627018246571655303050627048489594159321588908385378810'
624
- )
625
- const s = new Bn(
626
- '4331694221846364448463828256391194279133231453999942381442030409253074198130'
627
- )
628
- const sig = Sig.fromObject({ r: r, s: s })
629
- const hex = sig.toString()
630
- hex.should.equal(
631
- '30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'
632
- )
633
- })
634
- })
635
-
636
- describe('vectors', function () {
637
- // TODO: These vectors were taken from BitcoinJS-lib during a debugging
638
- // expedition. I only took a subset relevant for the stuff I wanted to
639
- // test, but it would be valuable to revisit these test vectors and make
640
- // sure all of them pass.
641
- vectors.valid.forEach(function (vector) {
642
- it('should pass this vector', function () {
643
- const compact = vector.compact
644
- const sig = Sig.fromCompact(Buffer.from(compact.hex, 'hex'))
645
- sig.recovery.should.equal(compact.i)
646
- sig.compressed.should.equal(compact.compressed)
647
- sig
648
- .toCompact()
649
- .toString('hex')
650
- .should.equal(compact.hex)
651
- })
652
- })
653
-
654
- vectors.invalid.compact.forEach(function (compact) {
655
- it('should pass this vector', function () {
656
- ;(function () {
657
- Sig.fromCompact(Buffer.from(compact.hex, 'hex'))
658
- }.should.throw())
659
- })
660
- })
661
- })
662
- })