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
@@ -1,336 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <title>JSDoc: Source: bip-39.js</title>
6
-
7
- <script src="scripts/prettify/prettify.js"> </script>
8
- <script src="scripts/prettify/lang-css.js"> </script>
9
- <!--[if lt IE 9]>
10
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11
- <![endif]-->
12
- <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13
- <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14
- </head>
15
-
16
- <body>
17
-
18
- <div id="main">
19
-
20
- <h1 class="page-title">Source: bip-39.js</h1>
21
-
22
-
23
-
24
-
25
-
26
-
27
- <section>
28
- <article>
29
- <pre class="prettyprint source linenums"><code>/**
30
- * Bip39: Mnemonic Seeds
31
- * =====================
32
- *
33
- * Bip39 is a way to turn random entropy into a mnemonic (a string of words
34
- * from a wordlist), and then that mnemonic into a seed. The seed can then be
35
- * used in Bip32 to derive hierarchical deterministic keys. It does not go the
36
- * other way around (i.e., you cannot turn a seed into a mnemonic). The usual
37
- * way to use it is either to generate a new one, like this:
38
- *
39
- * const mnemonic = new Bip39().fromRandom().toString()
40
- *
41
- * or from a known mnemonic:
42
- *
43
- * const seed = new Bip39().fromString(mnemonic).toSeed()
44
- */
45
- 'use strict'
46
-
47
- import { Bw } from './bw'
48
- import { Hash } from './hash'
49
- import pbkdf2 from 'pbkdf2'
50
- import { Random } from './random'
51
- import { Struct } from './struct'
52
- import { en, es, jp } from './bip-39-words'
53
- import { Workers } from './workers'
54
-
55
- class Bip39 extends Struct {
56
- constructor (mnemonic, seed, wordlist) {
57
- super({ mnemonic, seed, wordlist })
58
- this.Wordlist = en
59
- this.es = es
60
- this.jp = jp
61
- }
62
-
63
- setLang (lang) {
64
- switch (lang) {
65
- case 'es': this.Wordlist = es; break
66
- case 'jp': this.Wordlist = jp; break
67
- case 'en': default: this.Wordlist = en; break
68
- }
69
- }
70
-
71
- toBw (bw) {
72
- if (!bw) {
73
- bw = new Bw()
74
- }
75
- if (this.mnemonic) {
76
- const buf = Buffer.from(this.mnemonic)
77
- bw.writeVarIntNum(buf.length)
78
- bw.write(buf)
79
- } else {
80
- bw.writeVarIntNum(0)
81
- }
82
- if (this.seed) {
83
- bw.writeVarIntNum(this.seed.length)
84
- bw.write(this.seed)
85
- } else {
86
- bw.writeVarIntNum(0)
87
- }
88
- return bw
89
- }
90
-
91
- fromBr (br) {
92
- const mnemoniclen = br.readVarIntNum()
93
- if (mnemoniclen > 0) {
94
- this.mnemonic = br.read(mnemoniclen).toString()
95
- }
96
- const seedlen = br.readVarIntNum()
97
- if (seedlen > 0) {
98
- this.seed = br.read(seedlen)
99
- }
100
- return this
101
- }
102
-
103
- /**
104
- * Generate a random new mnemonic from the wordlist.
105
- */
106
- fromRandom (bits) {
107
- if (!bits) {
108
- bits = 128
109
- }
110
- if (bits % 32 !== 0) {
111
- throw new Error('bits must be multiple of 32')
112
- }
113
- if (bits &lt; 128) {
114
- throw new Error('bits must be at least 128')
115
- }
116
- const buf = Random.getRandomBuffer(bits / 8)
117
- this.entropy2Mnemonic(buf)
118
- this.mnemonic2Seed()
119
- return this
120
- }
121
-
122
- static fromRandom (bits) {
123
- return new this().fromRandom(bits)
124
- }
125
-
126
- async asyncFromRandom (bits) {
127
- if (!bits) {
128
- bits = 128
129
- }
130
- const buf = Random.getRandomBuffer(bits / 8)
131
- let workersResult = await Workers.asyncObjectMethod(
132
- this,
133
- 'entropy2Mnemonic',
134
- [buf]
135
- )
136
- const bip39 = new Bip39().fromFastBuffer(workersResult.resbuf)
137
- workersResult = await Workers.asyncObjectMethod(
138
- bip39,
139
- 'mnemonic2Seed',
140
- []
141
- )
142
- return this.fromFastBuffer(workersResult.resbuf)
143
- }
144
-
145
- static asyncFromRandom (bits) {
146
- return new this().asyncFromRandom(bits)
147
- }
148
-
149
- fromEntropy (buf) {
150
- this.entropy2Mnemonic(buf)
151
- return this
152
- }
153
-
154
- static fromEntropy (buf) {
155
- return new this().fromEntropy(buf)
156
- }
157
-
158
- async asyncFromEntropy (buf) {
159
- const workersResult = await Workers.asyncObjectMethod(this, 'fromEntropy', [
160
- buf
161
- ])
162
- return this.fromFastBuffer(workersResult.resbuf)
163
- }
164
-
165
- static asyncFromEntropy (buf) {
166
- return new this().asyncFromEntropy(buf)
167
- }
168
-
169
- fromString (mnemonic) {
170
- this.mnemonic = mnemonic.trim()
171
- return this
172
- }
173
-
174
- toString () {
175
- return this.mnemonic
176
- }
177
-
178
- toSeed (passphrase) {
179
- this.mnemonic2Seed(passphrase)
180
- return this.seed
181
- }
182
-
183
- async asyncToSeed (passphrase) {
184
- if (passphrase === undefined) {
185
- passphrase = ''
186
- }
187
- const args = [passphrase]
188
- const workersResult = await Workers.asyncObjectMethod(this, 'toSeed', args)
189
- return workersResult.resbuf
190
- }
191
-
192
- /**
193
- * Generate a new mnemonic from some entropy generated somewhere else. The
194
- * entropy must be at least 128 bits.
195
- */
196
- entropy2Mnemonic (buf) {
197
- if (!Buffer.isBuffer(buf) || buf.length &lt; 128 / 8) {
198
- throw new Error(
199
- 'Entropy is less than 128 bits. It must be 128 bits or more.'
200
- )
201
- }
202
-
203
- const hash = Hash.sha256(buf)
204
- let bin = ''
205
- const bits = buf.length * 8
206
- for (let i = 0; i &lt; buf.length; i++) {
207
- bin = bin + ('00000000' + buf[i].toString(2)).slice(-8)
208
- }
209
- let hashbits = hash[0].toString(2)
210
- hashbits = ('00000000' + hashbits).slice(-8).slice(0, bits / 32)
211
- bin = bin + hashbits
212
-
213
- if (bin.length % 11 !== 0) {
214
- throw new Error(
215
- 'internal error - entropy not an even multiple of 11 bits - ' +
216
- bin.length
217
- )
218
- }
219
-
220
- let mnemonic = ''
221
- for (let i = 0; i &lt; bin.length / 11; i++) {
222
- if (mnemonic !== '') {
223
- mnemonic = mnemonic + this.Wordlist.space
224
- }
225
- const wi = parseInt(bin.slice(i * 11, (i + 1) * 11), 2)
226
- mnemonic = mnemonic + this.Wordlist[wi]
227
- }
228
-
229
- this.mnemonic = mnemonic
230
- return this
231
- }
232
-
233
- /**
234
- * Check that a mnemonic is valid. This means there should be no superfluous
235
- * whitespace, no invalid words, and the checksum should match.
236
- */
237
- check () {
238
- const mnemonic = this.mnemonic
239
-
240
- // confirm no invalid words
241
- const words = mnemonic.split(this.Wordlist.space)
242
- let bin = ''
243
- for (let i = 0; i &lt; words.length; i++) {
244
- const ind = this.Wordlist.indexOf(words[i])
245
- if (ind &lt; 0) {
246
- return false
247
- }
248
- bin = bin + ('00000000000' + ind.toString(2)).slice(-11)
249
- }
250
-
251
- if (bin.length % 11 !== 0) {
252
- throw new Error(
253
- 'internal error - entropy not an even multiple of 11 bits - ' +
254
- bin.length
255
- )
256
- }
257
-
258
- // confirm checksum
259
- const cs = bin.length / 33
260
- const hashBits = bin.slice(-cs)
261
- const nonhashBits = bin.slice(0, bin.length - cs)
262
- const buf = Buffer.alloc(nonhashBits.length / 8)
263
- for (let i = 0; i &lt; nonhashBits.length / 8; i++) {
264
- buf.writeUInt8(parseInt(bin.slice(i * 8, (i + 1) * 8), 2), i)
265
- }
266
- const hash = Hash.sha256(buf)
267
- let expectedHashBits = hash[0].toString(2)
268
- expectedHashBits = ('00000000' + expectedHashBits).slice(-8).slice(0, cs)
269
-
270
- return expectedHashBits === hashBits
271
- }
272
-
273
- /**
274
- * Convert a mnemonic to a seed. Does not check for validity of the mnemonic -
275
- * for that, you should manually run check() first.
276
- */
277
- mnemonic2Seed (passphrase = '') {
278
- let mnemonic = this.mnemonic
279
- if (!this.check()) {
280
- throw new Error(
281
- 'Mnemonic does not pass the check - was the mnemonic typed incorrectly? Are there extra spaces?'
282
- )
283
- }
284
- if (typeof passphrase !== 'string') {
285
- throw new Error('passphrase must be a string or undefined')
286
- }
287
- mnemonic = mnemonic.normalize('NFKD')
288
- passphrase = passphrase.normalize('NFKD')
289
- const mbuf = Buffer.from(mnemonic)
290
- const pbuf = Buffer.concat([
291
- Buffer.from('mnemonic'),
292
- Buffer.from(passphrase)
293
- ])
294
- this.seed = pbkdf2.pbkdf2Sync(mbuf, pbuf, 2048, 64, 'sha512')
295
- return this
296
- }
297
-
298
- isValid (passphrase = '') {
299
- let isValid
300
- try {
301
- isValid = !!this.mnemonic2Seed(passphrase)
302
- } catch (err) {
303
- isValid = false
304
- }
305
- return isValid
306
- }
307
-
308
- static isValid (mnemonic, passphrase = '') {
309
- return new Bip39(mnemonic).isValid(passphrase)
310
- }
311
- }
312
-
313
- export { Bip39 }
314
- </code></pre>
315
- </article>
316
- </section>
317
-
318
-
319
-
320
-
321
- </div>
322
-
323
- <nav>
324
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sig.html">Sig</a></li></ul><h3>Global</h3><ul><li><a href="global.html#decorate">decorate</a></li></ul>
325
- </nav>
326
-
327
- <br class="clear">
328
-
329
- <footer>
330
- Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Fri Feb 28 2025 03:51:24 GMT+0100 (hora estándar de Europa central)
331
- </footer>
332
-
333
- <script> prettyPrint(); </script>
334
- <script src="scripts/linenumber.js"> </script>
335
- </body>
336
- </html>
package/out/block.js.html DELETED
@@ -1,183 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <title>JSDoc: Source: block.js</title>
6
-
7
- <script src="scripts/prettify/prettify.js"> </script>
8
- <script src="scripts/prettify/lang-css.js"> </script>
9
- <!--[if lt IE 9]>
10
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11
- <![endif]-->
12
- <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13
- <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14
- </head>
15
-
16
- <body>
17
-
18
- <div id="main">
19
-
20
- <h1 class="page-title">Source: block.js</h1>
21
-
22
-
23
-
24
-
25
-
26
-
27
- <section>
28
- <article>
29
- <pre class="prettyprint source linenums"><code>/**
30
- * Block
31
- * =====
32
- *
33
- * A block, of course, is a collection of transactions. This class is somewhat
34
- * incompconste at the moment. In the future, it should support the ability to
35
- * check to see if a transaction is in a block (thanks to the magic of merkle
36
- * trees). You will probably never use Yours Bitcoin to create a block, since almost
37
- * everyone will use bitcoind for that. As such, the primary way to use this is
38
- * new Block().fromBuffer(buf), which will parse the block and prepare its insides
39
- * for you to inspect.
40
- */
41
- 'use strict'
42
-
43
- import { Br } from './br'
44
- import { Bw } from './bw'
45
- import { BlockHeader } from './block-header'
46
- import { Hash } from './hash'
47
- import { Merkle } from './merkle'
48
- import { Struct } from './struct'
49
- import { Tx } from './tx'
50
- import { VarInt } from './var-int'
51
- import { Workers } from './workers'
52
-
53
- class Block extends Struct {
54
- constructor (blockHeader, txsVi, txs) {
55
- super({ blockHeader, txsVi, txs })
56
- }
57
-
58
- fromJSON (json) {
59
- const txs = []
60
- json.txs.forEach(function (tx) {
61
- txs.push(new Tx().fromJSON(tx))
62
- })
63
- this.fromObject({
64
- blockHeader: new BlockHeader().fromJSON(json.blockHeader),
65
- txsVi: new VarInt().fromJSON(json.txsVi),
66
- txs
67
- })
68
- return this
69
- }
70
-
71
- toJSON () {
72
- const txs = []
73
- this.txs.forEach(function (tx) {
74
- txs.push(tx.toJSON())
75
- })
76
- return {
77
- blockHeader: this.blockHeader.toJSON(),
78
- txsVi: this.txsVi.toJSON(),
79
- txs
80
- }
81
- }
82
-
83
- fromBr (br) {
84
- this.blockHeader = new BlockHeader().fromBr(br)
85
- this.txsVi = new VarInt(br.readVarIntBuf())
86
- const txsNum = this.txsVi.toNumber()
87
- this.txs = []
88
- for (let i = 0; i &lt; txsNum; i++) {
89
- this.txs.push(new Tx().fromBr(br))
90
- }
91
- return this
92
- }
93
-
94
- toBw (bw) {
95
- if (!bw) {
96
- bw = new Bw()
97
- }
98
- bw.write(this.blockHeader.toBuffer())
99
- bw.write(this.txsVi.buf)
100
- const txsNum = this.txsVi.toNumber()
101
- for (let i = 0; i &lt; txsNum; i++) {
102
- this.txs[i].toBw(bw)
103
- }
104
- return bw
105
- }
106
-
107
- hash () {
108
- return Hash.sha256Sha256(this.blockHeader.toBuffer())
109
- }
110
-
111
- async asyncHash () {
112
- const workersResult = await Workers.asyncObjectMethod(this, 'hash', [])
113
- return workersResult.resbuf
114
- }
115
-
116
- id () {
117
- return new Br(this.hash()).readReverse().toString('hex')
118
- }
119
-
120
- async asyncId () {
121
- const workersResult = await Workers.asyncObjectMethod(this, 'id', [])
122
- return JSON.parse(workersResult.resbuf.toString())
123
- }
124
-
125
- verifyMerkleRoot () {
126
- const txsbufs = this.txs.map(tx => tx.toBuffer())
127
- const merkleRootBuf = Merkle.fromBuffers(txsbufs).hash()
128
- return Buffer.compare(merkleRootBuf, this.blockHeader.merkleRootBuf)
129
- }
130
-
131
- /**
132
- * Sometimes we don't want to parse an entire block into memory. Instead, we
133
- * simply want to iterate through all transactions in the block. That is what
134
- * this method is for. This method returns an efficient iterator which can be
135
- * used in a `for (tx of txs)` construct that returns each tx one at a time
136
- * without first parsing all of them into memory.
137
- *
138
- * @param {Buffer} blockBuf A buffer of a block.
139
- */
140
- static iterateTxs (blockBuf) {
141
- const br = new Br(blockBuf)
142
- const blockHeader = new BlockHeader().fromBr(br)
143
- const txsVi = new VarInt(br.readVarIntBuf())
144
- const txsNum = txsVi.toNumber()
145
- return {
146
- blockHeader,
147
- txsVi,
148
- txsNum,
149
- * [Symbol.iterator] () {
150
- for (let i = 0; i &lt; txsNum; i++) {
151
- yield new Tx().fromBr(br)
152
- }
153
- }
154
- }
155
- }
156
- }
157
-
158
- Block.MAX_BLOCK_SIZE = 1000000
159
-
160
- export { Block }
161
- </code></pre>
162
- </article>
163
- </section>
164
-
165
-
166
-
167
-
168
- </div>
169
-
170
- <nav>
171
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sig.html">Sig</a></li></ul><h3>Global</h3><ul><li><a href="global.html#decorate">decorate</a></li></ul>
172
- </nav>
173
-
174
- <br class="clear">
175
-
176
- <footer>
177
- Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Fri Feb 28 2025 03:51:24 GMT+0100 (hora estándar de Europa central)
178
- </footer>
179
-
180
- <script> prettyPrint(); </script>
181
- <script src="scripts/linenumber.js"> </script>
182
- </body>
183
- </html>