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