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.
- package/dist/bsv2.mjs +1 -1
- package/package.json +3 -2
- package/.babel.test +0 -10
- package/.editorconfig +0 -4
- package/.env.defaults +0 -1
- package/.env.schema +0 -1
- package/.husky/pre-commit +0 -1
- package/.mocharc.yml +0 -4
- package/.nvmrc +0 -1
- package/.travis.yml +0 -7
- package/babel.config.cjs +0 -44
- package/benchmark.js +0 -42
- package/bin/bsv.js +0 -11
- package/bin/network.js +0 -93
- package/build/index.html +0 -20
- package/dist/bsv2.umd.js +0 -28
- package/doc/assets/anchor.js +0 -350
- package/doc/assets/bass-addons.css +0 -12
- package/doc/assets/bass.css +0 -544
- package/doc/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
- package/doc/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
- package/doc/assets/fonts/LICENSE.txt +0 -93
- package/doc/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
- package/doc/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
- package/doc/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
- package/doc/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
- package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
- package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
- package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
- package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
- package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
- package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
- package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
- package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
- package/doc/assets/fonts/source-code-pro.css +0 -23
- package/doc/assets/github.css +0 -123
- package/doc/assets/site.js +0 -168
- package/doc/assets/split.css +0 -15
- package/doc/assets/split.js +0 -782
- package/doc/assets/style.css +0 -147
- package/doc/index.html +0 -9461
- package/entry.js +0 -81
- package/eslint.config.mjs +0 -8
- package/index.js +0 -98
- package/karma.conf.ts +0 -77
- package/lib/ach.js +0 -59
- package/lib/address.js +0 -266
- package/lib/aes.js +0 -57
- package/lib/aescbc.js +0 -38
- package/lib/base-58-check.js +0 -83
- package/lib/base-58.js +0 -59
- package/lib/bip-32.js +0 -472
- package/lib/bip-39-en-wordlist.js +0 -2054
- package/lib/bip-39-en.js +0 -10
- package/lib/bip-39-es-wordlist.js +0 -2055
- package/lib/bip-39-es.js +0 -10
- package/lib/bip-39-jp-wordlist.js +0 -2053
- package/lib/bip-39-jp.js +0 -10
- package/lib/bip-39-words.js +0 -5
- package/lib/bip-39.js +0 -286
- package/lib/block-header.js +0 -79
- package/lib/block.js +0 -132
- package/lib/bn.js +0 -462
- package/lib/br.js +0 -172
- package/lib/bsm.js +0 -127
- package/lib/bw.js +0 -188
- package/lib/cbc.js +0 -140
- package/lib/cmp.js +0 -37
- package/lib/config.js +0 -50
- package/lib/constants.js +0 -150
- package/lib/ecdsa.js +0 -496
- package/lib/ecies.js +0 -151
- package/lib/hash-cache.js +0 -41
- package/lib/hash.js +0 -191
- package/lib/interp.js +0 -2017
- package/lib/inv.js +0 -49
- package/lib/key-pair.js +0 -133
- package/lib/mainnet-address.js +0 -5
- package/lib/mainnet-bip-32.js +0 -5
- package/lib/mainnet-key-pair.js +0 -5
- package/lib/mainnet-priv-key.js +0 -5
- package/lib/merkle.js +0 -92
- package/lib/msg.js +0 -184
- package/lib/op-code.js +0 -400
- package/lib/point.js +0 -134
- package/lib/priv-key.js +0 -157
- package/lib/pub-key.js +0 -230
- package/lib/random.js +0 -28
- package/lib/script.js +0 -828
- package/lib/sig-operations.js +0 -120
- package/lib/sig.js +0 -399
- package/lib/struct.js +0 -392
- package/lib/testnet-address.js +0 -5
- package/lib/testnet-bip-32.js +0 -5
- package/lib/testnet-key-pair.js +0 -5
- package/lib/testnet-priv-key.js +0 -5
- package/lib/tx-builder.js +0 -593
- package/lib/tx-in.js +0 -172
- package/lib/tx-out-map.js +0 -57
- package/lib/tx-out.js +0 -73
- package/lib/tx-verifier.js +0 -209
- package/lib/tx.js +0 -430
- package/lib/var-int.js +0 -73
- package/lib/version.js +0 -92
- package/lib/workers-result.js +0 -65
- package/lib/workers.js +0 -77
- package/load-babel.js +0 -5
- package/mtest/test.html +0 -17
- package/mtest/test.js +0 -2
- package/mtest/test.mjs +0 -2
- package/mtest/webpack.config.js +0 -115
- package/out/Sig.html +0 -541
- package/out/bip-32.js.html +0 -523
- package/out/bip-39.js.html +0 -336
- package/out/block.js.html +0 -183
- package/out/bn.js.html +0 -512
- package/out/ecdsa.js.html +0 -546
- package/out/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/out/fonts/OpenSans-Bold-webfont.svg +0 -1830
- package/out/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/out/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/out/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
- package/out/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/out/fonts/OpenSans-Italic-webfont.svg +0 -1830
- package/out/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Light-webfont.eot +0 -0
- package/out/fonts/OpenSans-Light-webfont.svg +0 -1831
- package/out/fonts/OpenSans-Light-webfont.woff +0 -0
- package/out/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/out/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
- package/out/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/out/fonts/OpenSans-Regular-webfont.svg +0 -1831
- package/out/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/out/global.html +0 -220
- package/out/index.html +0 -128
- package/out/interp.js.html +0 -2064
- package/out/merkle.js.html +0 -143
- package/out/msg.js.html +0 -235
- package/out/priv-key.js.html +0 -208
- package/out/pub-key.js.html +0 -281
- package/out/script.js.html +0 -876
- package/out/scripts/linenumber.js +0 -25
- package/out/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/out/scripts/prettify/lang-css.js +0 -2
- package/out/scripts/prettify/prettify.js +0 -28
- package/out/sig-operations.js.html +0 -171
- package/out/sig.js.html +0 -450
- package/out/struct.js.html +0 -440
- package/out/styles/jsdoc-default.css +0 -358
- package/out/styles/prettify-jsdoc.css +0 -111
- package/out/styles/prettify-tomorrow.css +0 -132
- package/out/tx-builder.js.html +0 -644
- package/out/tx-in.js.html +0 -223
- package/out/tx-verifier.js.html +0 -260
- package/out/tx.js.html +0 -481
- package/test/ach.js +0 -172
- package/test/address.js +0 -464
- package/test/aes.js +0 -96
- package/test/aescbc.js +0 -65
- package/test/base-58-check.js +0 -128
- package/test/base-58.js +0 -113
- package/test/bip-32.js +0 -721
- package/test/bip-39.js +0 -282
- package/test/block-header.js +0 -152
- package/test/block.js +0 -243
- package/test/bn.js +0 -643
- package/test/br.js +0 -353
- package/test/bsm.js +0 -141
- package/test/bw.js +0 -292
- package/test/cbc.js +0 -335
- package/test/cmp.js +0 -56
- package/test/data/bip69.json +0 -215
- package/test/data/bitcoind/base58_keys_invalid.json +0 -152
- package/test/data/bitcoind/base58_keys_valid.json +0 -452
- package/test/data/bitcoind/blocks.json +0 -27
- package/test/data/bitcoind/script_tests.json +0 -2244
- package/test/data/bitcoind/sig_canonical.json +0 -7
- package/test/data/bitcoind/sig_noncanonical.json +0 -22
- package/test/data/bitcoind/tx_invalid.json +0 -177
- package/test/data/bitcoind/tx_valid.json +0 -224
- package/test/data/blk86756-testnet.dat +0 -0
- package/test/data/blk86756-testnet.js +0 -12
- package/test/data/blk86756-testnet.json +0 -684
- package/test/data/ecdsa.json +0 -230
- package/test/data/messages.json +0 -22
- package/test/data/sighash.json +0 -1004
- package/test/data/tx_creation.json +0 -85
- package/test/ecdsa.js +0 -748
- package/test/ecies.js +0 -238
- package/test/global.js +0 -13
- package/test/hash-cache.js +0 -52
- package/test/hash.js +0 -354
- package/test/index.js +0 -10
- package/test/interp.js +0 -512
- package/test/inv.js +0 -65
- package/test/key-pair.js +0 -243
- package/test/merkle.js +0 -179
- package/test/msg.js +0 -295
- package/test/op-code.js +0 -79
- package/test/point.js +0 -375
- package/test/priv-key.js +0 -264
- package/test/pub-key.js +0 -549
- package/test/random.js +0 -31
- package/test/script.js +0 -1340
- package/test/sig-operations.js +0 -149
- package/test/sig.js +0 -662
- package/test/struct.js +0 -552
- package/test/tx-builder.js +0 -2104
- package/test/tx-in.js +0 -198
- package/test/tx-out-map.js +0 -104
- package/test/tx-out.js +0 -162
- package/test/tx-verifier.js +0 -246
- package/test/tx.js +0 -539
- package/test/var-int.js +0 -132
- package/test/vectors/aes.json +0 -10392
- package/test/vectors/aescbc.json +0 -620
- package/test/vectors/bip39.json +0 -502
- package/test/vectors/bip69.json +0 -215
- package/test/vectors/bitcoin-abc/script_tests.json +0 -48
- package/test/vectors/bitcoin-abc/sighash.json +0 -7004
- package/test/vectors/bitcoin-sv/script_tests.json +0 -248
- package/test/vectors/bitcoind/script_invalid.json +0 -1151
- package/test/vectors/bitcoind/script_valid.json +0 -1462
- package/test/vectors/bitcoind/sighash.json +0 -3503
- package/test/vectors/bitcoind/tx_invalid.json +0 -883
- package/test/vectors/bitcoind/tx_valid.json +0 -1150
- package/test/vectors/coolest-tx-ever-sent.json +0 -8
- package/test/vectors/ecdsa.json +0 -300
- package/test/vectors/hash.json +0 -6133
- package/test/vectors/kdf.json +0 -47
- package/test/vectors/largesttx.json +0 -5
- package/test/vectors/largesttxblock.json +0 -6
- package/test/vectors/sig.json +0 -79
- package/test/vectors/sighash-single-bug.json +0 -8
- package/test/version.js +0 -81
- package/test/workers-result.js +0 -89
- package/test/workers.js +0 -91
- package/test-index.js +0 -3
- package/vite.config.js +0 -36
package/out/merkle.js.html
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title>JSDoc: Source: merkle.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: merkle.js</h1>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
<section>
|
|
28
|
-
<article>
|
|
29
|
-
<pre class="prettyprint source linenums"><code>/**
|
|
30
|
-
* Merkle
|
|
31
|
-
* ======
|
|
32
|
-
*
|
|
33
|
-
* A node in a Merkle tree (possibly the root node, in which case it is the
|
|
34
|
-
* Merkle root). A node either contains a buffer or links to two other nodes.
|
|
35
|
-
*/
|
|
36
|
-
'use strict'
|
|
37
|
-
|
|
38
|
-
import { Hash } from './hash'
|
|
39
|
-
import { Struct } from './struct'
|
|
40
|
-
|
|
41
|
-
class Merkle extends Struct {
|
|
42
|
-
constructor (hashBuf, buf, merkle1, merkle2) {
|
|
43
|
-
super({ hashBuf, buf, merkle1, merkle2 })
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
hash () {
|
|
47
|
-
if (this.hashBuf) {
|
|
48
|
-
return this.hashBuf
|
|
49
|
-
}
|
|
50
|
-
if (this.buf) {
|
|
51
|
-
return Hash.sha256Sha256(this.buf)
|
|
52
|
-
}
|
|
53
|
-
const hashBuf1 = this.merkle1.hash()
|
|
54
|
-
const hashBuf2 = this.merkle2.hash()
|
|
55
|
-
this.buf = Buffer.concat([hashBuf1, hashBuf2])
|
|
56
|
-
return Hash.sha256Sha256(this.buf)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
fromBuffers (bufs) {
|
|
60
|
-
if (bufs.length < 1) {
|
|
61
|
-
throw new Error('buffers must have a length')
|
|
62
|
-
}
|
|
63
|
-
bufs = bufs.slice()
|
|
64
|
-
const log = Math.log2(bufs.length)
|
|
65
|
-
if (!Number.isInteger(log)) {
|
|
66
|
-
// If a merkle tree does not have a number of ends that is a power of 2,
|
|
67
|
-
// then we have to copy the last value until it is a power of 2. Note
|
|
68
|
-
// that we copy *the actual object* over and over again, which ensures
|
|
69
|
-
// that when we finds its hash, the hash is cached.
|
|
70
|
-
const lastval = bufs[bufs.length - 1]
|
|
71
|
-
const len = Math.pow(2, Math.ceil(log))
|
|
72
|
-
for (let i = bufs.length; i < len; i++) {
|
|
73
|
-
bufs.push(lastval)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const bufs1 = bufs.slice(0, bufs.length / 2)
|
|
77
|
-
const bufs2 = bufs.slice(bufs.length / 2)
|
|
78
|
-
this.fromBufferArrays(bufs1, bufs2)
|
|
79
|
-
return this
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
static fromBuffers (bufs) {
|
|
83
|
-
return new this().fromBuffers(bufs)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Takes two arrays, both of which *must* be of a length that is a power of
|
|
88
|
-
* two.
|
|
89
|
-
*/
|
|
90
|
-
fromBufferArrays (bufs1, bufs2) {
|
|
91
|
-
if (bufs1.length === 1) {
|
|
92
|
-
this.merkle1 = new Merkle(undefined, bufs1[0])
|
|
93
|
-
this.merkle2 = new Merkle(undefined, bufs2[0])
|
|
94
|
-
return this
|
|
95
|
-
}
|
|
96
|
-
const bufs11 = bufs1.slice(0, bufs1.length / 2)
|
|
97
|
-
const bufs12 = bufs1.slice(bufs1.length / 2)
|
|
98
|
-
this.merkle1 = new Merkle().fromBufferArrays(bufs11, bufs12)
|
|
99
|
-
const bufs21 = bufs2.slice(0, bufs2.length / 2)
|
|
100
|
-
const bufs22 = bufs2.slice(bufs2.length / 2)
|
|
101
|
-
this.merkle2 = new Merkle().fromBufferArrays(bufs21, bufs22)
|
|
102
|
-
return this
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
static fromBufferArrays (bufs1, bufs2) {
|
|
106
|
-
return new this().fromBufferArrays(bufs1, bufs2)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
leavesNum () {
|
|
110
|
-
if (this.merkle1) {
|
|
111
|
-
return this.merkle1.leavesNum() + this.merkle2.leavesNum()
|
|
112
|
-
}
|
|
113
|
-
if (this.buf) {
|
|
114
|
-
return 1
|
|
115
|
-
}
|
|
116
|
-
throw new Error('invalid number of leaves')
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export { Merkle }
|
|
121
|
-
</code></pre>
|
|
122
|
-
</article>
|
|
123
|
-
</section>
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
</div>
|
|
129
|
-
|
|
130
|
-
<nav>
|
|
131
|
-
<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>
|
|
132
|
-
</nav>
|
|
133
|
-
|
|
134
|
-
<br class="clear">
|
|
135
|
-
|
|
136
|
-
<footer>
|
|
137
|
-
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)
|
|
138
|
-
</footer>
|
|
139
|
-
|
|
140
|
-
<script> prettyPrint(); </script>
|
|
141
|
-
<script src="scripts/linenumber.js"> </script>
|
|
142
|
-
</body>
|
|
143
|
-
</html>
|
package/out/msg.js.html
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title>JSDoc: Source: msg.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: msg.js</h1>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
<section>
|
|
28
|
-
<article>
|
|
29
|
-
<pre class="prettyprint source linenums"><code>/**
|
|
30
|
-
* Peer-to-Peer Network Message
|
|
31
|
-
* ============================
|
|
32
|
-
*
|
|
33
|
-
* A message on the bitcoin p2p network.
|
|
34
|
-
*/
|
|
35
|
-
'use strict'
|
|
36
|
-
|
|
37
|
-
import { Br } from './br'
|
|
38
|
-
import { Bw } from './bw'
|
|
39
|
-
import { Constants, getConstants } from './constants'
|
|
40
|
-
import { Hash } from './hash'
|
|
41
|
-
import { Struct } from './struct'
|
|
42
|
-
import { cmp } from './cmp'
|
|
43
|
-
|
|
44
|
-
class Msg extends Struct {
|
|
45
|
-
constructor (magicNum, cmdbuf, datasize, checksumbuf, dataBuf, constants = null) {
|
|
46
|
-
super()
|
|
47
|
-
this.constants = constants || Constants.Default
|
|
48
|
-
this.magicNum = this.constants.Msg.magicNum
|
|
49
|
-
this.fromObject({ magicNum, cmdbuf, datasize, checksumbuf, dataBuf })
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
setCmd (cmdname) {
|
|
53
|
-
this.cmdbuf = Buffer.alloc(12)
|
|
54
|
-
this.cmdbuf.fill(0)
|
|
55
|
-
this.cmdbuf.write(cmdname)
|
|
56
|
-
return this
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
getCmd () {
|
|
60
|
-
let end = this.cmdbuf.length
|
|
61
|
-
for (let i = end; i > 0; i--) {
|
|
62
|
-
if (this.cmdbuf[i - 1] !== 0) {
|
|
63
|
-
end = i
|
|
64
|
-
break
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return this.cmdbuf.toString('utf8', 0, end)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
static checksum (dataBuf) {
|
|
71
|
-
return Hash.sha256Sha256(dataBuf).slice(0, 4)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
static async asyncChecksum (dataBuf) {
|
|
75
|
-
const hashBuf = await Hash.asyncSha256Sha256(dataBuf)
|
|
76
|
-
return hashBuf.slice(0, 4)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
setData (dataBuf) {
|
|
80
|
-
this.dataBuf = dataBuf
|
|
81
|
-
this.datasize = dataBuf.length
|
|
82
|
-
this.checksumbuf = Msg.checksum(dataBuf)
|
|
83
|
-
return this
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async asyncSetData (dataBuf) {
|
|
87
|
-
this.dataBuf = dataBuf
|
|
88
|
-
this.datasize = dataBuf.length
|
|
89
|
-
this.checksumbuf = await Msg.asyncChecksum(dataBuf)
|
|
90
|
-
return this
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* An iterator to produce a message from a series of buffers. Set opts.strict
|
|
95
|
-
* to throw an error if an invalid message occurs in stream.
|
|
96
|
-
*/
|
|
97
|
-
* genFromBuffers (opts) {
|
|
98
|
-
opts = opts === undefined ? {} : opts
|
|
99
|
-
let res
|
|
100
|
-
res = yield * this.expect(4)
|
|
101
|
-
this.magicNum = new Br(res.buf).readUInt32BE()
|
|
102
|
-
if (opts.strict && this.magicNum !== this.constants.Msg.magicNum) {
|
|
103
|
-
throw new Error('invalid magicNum')
|
|
104
|
-
}
|
|
105
|
-
res = yield * this.expect(12, res.remainderbuf)
|
|
106
|
-
this.cmdbuf = new Br(res.buf).read(12)
|
|
107
|
-
res = yield * this.expect(4, res.remainderbuf)
|
|
108
|
-
this.datasize = new Br(res.buf).readUInt32BE()
|
|
109
|
-
if (opts.strict && this.datasize > this.constants.MaxSize) {
|
|
110
|
-
throw new Error('message size greater than maxsize')
|
|
111
|
-
}
|
|
112
|
-
res = yield * this.expect(4, res.remainderbuf)
|
|
113
|
-
this.checksumbuf = new Br(res.buf).read(4)
|
|
114
|
-
res = yield * this.expect(this.datasize, res.remainderbuf)
|
|
115
|
-
this.dataBuf = new Br(res.buf).read(this.datasize)
|
|
116
|
-
return res.remainderbuf
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
fromBr (br) {
|
|
120
|
-
this.magicNum = br.readUInt32BE()
|
|
121
|
-
this.constants = getConstants(this.magicNum)
|
|
122
|
-
this.cmdbuf = br.read(12)
|
|
123
|
-
this.datasize = br.readUInt32BE()
|
|
124
|
-
this.checksumbuf = br.read(4)
|
|
125
|
-
this.dataBuf = br.read()
|
|
126
|
-
return this
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
toBw (bw) {
|
|
130
|
-
if (!bw) {
|
|
131
|
-
bw = new Bw()
|
|
132
|
-
}
|
|
133
|
-
bw.writeUInt32BE(this.magicNum)
|
|
134
|
-
bw.write(this.cmdbuf)
|
|
135
|
-
bw.writeUInt32BE(this.datasize)
|
|
136
|
-
bw.write(this.checksumbuf)
|
|
137
|
-
bw.write(this.dataBuf)
|
|
138
|
-
return bw
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
fromJSON (json) {
|
|
142
|
-
this.magicNum = json.magicNum
|
|
143
|
-
this.constants = getConstants(this.magicNum)
|
|
144
|
-
this.cmdbuf = Buffer.from(json.cmdbuf, 'hex')
|
|
145
|
-
this.datasize = json.datasize
|
|
146
|
-
this.checksumbuf = Buffer.from(json.checksumbuf, 'hex')
|
|
147
|
-
this.dataBuf = Buffer.from(json.dataBuf, 'hex')
|
|
148
|
-
return this
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
toJSON () {
|
|
152
|
-
return {
|
|
153
|
-
magicNum: this.magicNum,
|
|
154
|
-
cmdbuf: this.cmdbuf.toString('hex'),
|
|
155
|
-
datasize: this.datasize,
|
|
156
|
-
checksumbuf: this.checksumbuf.toString('hex'),
|
|
157
|
-
dataBuf: this.dataBuf.toString('hex')
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
isValid () {
|
|
162
|
-
// TODO: Add more checks
|
|
163
|
-
const checksumbuf = Msg.checksum(this.dataBuf)
|
|
164
|
-
return cmp(checksumbuf, this.checksumbuf)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async asyncIsValid () {
|
|
168
|
-
// TODO: Add more checks
|
|
169
|
-
const checksumbuf = await Msg.asyncChecksum(this.dataBuf)
|
|
170
|
-
return cmp(checksumbuf, this.checksumbuf)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
validate () {
|
|
174
|
-
if (!this.isValid()) {
|
|
175
|
-
throw new Error('invalid message')
|
|
176
|
-
}
|
|
177
|
-
return this
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
async asyncValidate () {
|
|
181
|
-
const isValid = await this.asyncIsValid()
|
|
182
|
-
if (isValid !== true) {
|
|
183
|
-
throw new Error('invalid message')
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
Msg.Mainnet = class extends Msg {
|
|
189
|
-
constructor (magicNum, cmdbuf, datasize, checksumbuf, dataBuf) {
|
|
190
|
-
super(magicNum, cmdbuf, datasize, checksumbuf, dataBuf, Constants.Mainnet)
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
Msg.Testnet = class extends Msg {
|
|
195
|
-
constructor (magicNum, cmdbuf, datasize, checksumbuf, dataBuf) {
|
|
196
|
-
super(magicNum, cmdbuf, datasize, checksumbuf, dataBuf, Constants.Testnet)
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
Msg.Regtest = class extends Msg {
|
|
201
|
-
constructor (magicNum, cmdbuf, datasize, checksumbuf, dataBuf) {
|
|
202
|
-
super(magicNum, cmdbuf, datasize, checksumbuf, dataBuf, Constants.Regtest)
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
Msg.STN = class extends Msg {
|
|
207
|
-
constructor (magicNum, cmdbuf, datasize, checksumbuf, dataBuf) {
|
|
208
|
-
super(magicNum, cmdbuf, datasize, checksumbuf, dataBuf, Constants.STN)
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export { Msg }
|
|
213
|
-
</code></pre>
|
|
214
|
-
</article>
|
|
215
|
-
</section>
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
</div>
|
|
221
|
-
|
|
222
|
-
<nav>
|
|
223
|
-
<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>
|
|
224
|
-
</nav>
|
|
225
|
-
|
|
226
|
-
<br class="clear">
|
|
227
|
-
|
|
228
|
-
<footer>
|
|
229
|
-
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)
|
|
230
|
-
</footer>
|
|
231
|
-
|
|
232
|
-
<script> prettyPrint(); </script>
|
|
233
|
-
<script src="scripts/linenumber.js"> </script>
|
|
234
|
-
</body>
|
|
235
|
-
</html>
|
package/out/priv-key.js.html
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title>JSDoc: Source: priv-key.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: priv-key.js</h1>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
<section>
|
|
28
|
-
<article>
|
|
29
|
-
<pre class="prettyprint source linenums"><code>/**
|
|
30
|
-
* Private Key
|
|
31
|
-
* ===========
|
|
32
|
-
*
|
|
33
|
-
* A private key is used for signing transactions (or messages). The primary
|
|
34
|
-
* way to use this is new PrivKey().fromRandom(), or new PrivKey().fromBuffer(buf).
|
|
35
|
-
*/
|
|
36
|
-
'use strict'
|
|
37
|
-
|
|
38
|
-
import { Bn } from './bn'
|
|
39
|
-
import { Point } from './point'
|
|
40
|
-
import { Constants } from './constants'
|
|
41
|
-
import { Base58Check } from './base-58-check'
|
|
42
|
-
import { Random } from './random'
|
|
43
|
-
import { Struct } from './struct'
|
|
44
|
-
|
|
45
|
-
class PrivKey extends Struct {
|
|
46
|
-
constructor (bn, compressed, constants = null) {
|
|
47
|
-
super({ bn, compressed })
|
|
48
|
-
constants = constants || Constants.Default.PrivKey
|
|
49
|
-
this.Constants = constants
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
fromJSON (json) {
|
|
53
|
-
this.fromHex(json)
|
|
54
|
-
return this
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
toJSON () {
|
|
58
|
-
return this.toHex()
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
fromRandom () {
|
|
62
|
-
let privBuf, bn, condition
|
|
63
|
-
|
|
64
|
-
do {
|
|
65
|
-
privBuf = Random.getRandomBuffer(32)
|
|
66
|
-
bn = new Bn().fromBuffer(privBuf)
|
|
67
|
-
condition = bn.lt(Point.getN())
|
|
68
|
-
} while (!condition)
|
|
69
|
-
|
|
70
|
-
this.fromObject({
|
|
71
|
-
bn,
|
|
72
|
-
compressed: true
|
|
73
|
-
})
|
|
74
|
-
return this
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
static fromRandom () {
|
|
78
|
-
return new this().fromRandom()
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
toBuffer () {
|
|
82
|
-
let compressed = this.compressed
|
|
83
|
-
|
|
84
|
-
if (compressed === undefined) {
|
|
85
|
-
compressed = true
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const privBuf = this.bn.toBuffer({ size: 32 })
|
|
89
|
-
let buf
|
|
90
|
-
if (compressed) {
|
|
91
|
-
buf = Buffer.concat([
|
|
92
|
-
Buffer.from([this.Constants.versionByteNum]),
|
|
93
|
-
privBuf,
|
|
94
|
-
Buffer.from([0x01])
|
|
95
|
-
])
|
|
96
|
-
} else {
|
|
97
|
-
buf = Buffer.concat([Buffer.from([this.Constants.versionByteNum]), privBuf])
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return buf
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
fromBuffer (buf) {
|
|
104
|
-
if (buf.length === 1 + 32 + 1 && buf[1 + 32 + 1 - 1] === 1) {
|
|
105
|
-
this.compressed = true
|
|
106
|
-
} else if (buf.length === 1 + 32) {
|
|
107
|
-
this.compressed = false
|
|
108
|
-
} else {
|
|
109
|
-
throw new Error(
|
|
110
|
-
'Length of privKey buffer must be 33 (uncompressed pubKey) or 34 (compressed pubKey)'
|
|
111
|
-
)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (buf[0] !== this.Constants.versionByteNum) {
|
|
115
|
-
throw new Error('Invalid versionByteNum byte')
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return this.fromBn(new Bn().fromBuffer(buf.slice(1, 1 + 32)))
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
toBn () {
|
|
122
|
-
return this.bn
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
fromBn (bn) {
|
|
126
|
-
this.bn = bn
|
|
127
|
-
return this
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
static fromBn (bn) {
|
|
131
|
-
return new this().fromBn(bn)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
validate () {
|
|
135
|
-
if (!this.bn.lt(Point.getN())) {
|
|
136
|
-
throw new Error('Number must be less than N')
|
|
137
|
-
}
|
|
138
|
-
if (typeof this.compressed !== 'boolean') {
|
|
139
|
-
throw new Error(
|
|
140
|
-
'Must specify whether the corresponding public key is compressed or not (true or false)'
|
|
141
|
-
)
|
|
142
|
-
}
|
|
143
|
-
return this
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Output the private key a Wallet Import Format (Wif) string.
|
|
148
|
-
*/
|
|
149
|
-
toWif () {
|
|
150
|
-
return Base58Check.encode(this.toBuffer())
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Input the private key from a Wallet Import Format (Wif) string.
|
|
155
|
-
*/
|
|
156
|
-
fromWif (str) {
|
|
157
|
-
return this.fromBuffer(Base58Check.decode(str))
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
static fromWif (str) {
|
|
161
|
-
return new this().fromWif(str)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
toString () {
|
|
165
|
-
return this.toWif()
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
fromString (str) {
|
|
169
|
-
return this.fromWif(str)
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
PrivKey.Mainnet = class extends PrivKey {
|
|
174
|
-
constructor (bn, compressed) {
|
|
175
|
-
super(bn, compressed, Constants.Mainnet.PrivKey)
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
PrivKey.Testnet = class extends PrivKey {
|
|
180
|
-
constructor (bn, compressed) {
|
|
181
|
-
super(bn, compressed, Constants.Testnet.PrivKey)
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export { PrivKey }
|
|
186
|
-
</code></pre>
|
|
187
|
-
</article>
|
|
188
|
-
</section>
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
</div>
|
|
194
|
-
|
|
195
|
-
<nav>
|
|
196
|
-
<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>
|
|
197
|
-
</nav>
|
|
198
|
-
|
|
199
|
-
<br class="clear">
|
|
200
|
-
|
|
201
|
-
<footer>
|
|
202
|
-
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)
|
|
203
|
-
</footer>
|
|
204
|
-
|
|
205
|
-
<script> prettyPrint(); </script>
|
|
206
|
-
<script src="scripts/linenumber.js"> </script>
|
|
207
|
-
</body>
|
|
208
|
-
</html>
|