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/test/pub-key.js
DELETED
|
@@ -1,549 +0,0 @@
|
|
|
1
|
-
/* global describe,it */
|
|
2
|
-
'use strict'
|
|
3
|
-
import { Bn } from '../lib/bn'
|
|
4
|
-
import { Point } from '../lib/point'
|
|
5
|
-
import { PrivKey } from '../lib/priv-key'
|
|
6
|
-
import { PubKey } from '../lib/pub-key'
|
|
7
|
-
import should from 'should'
|
|
8
|
-
|
|
9
|
-
describe('PubKey', function () {
|
|
10
|
-
it('should create a blank public key', function () {
|
|
11
|
-
const pk = new PubKey()
|
|
12
|
-
should.exist(pk)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('should create a public key with a point', function () {
|
|
16
|
-
const p = new Point()
|
|
17
|
-
const pk = new PubKey({ point: p })
|
|
18
|
-
should.exist(pk.point)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('should create a public key with a point with this convenient method', function () {
|
|
22
|
-
const p = new Point()
|
|
23
|
-
const pk = new PubKey(p)
|
|
24
|
-
should.exist(pk.point)
|
|
25
|
-
pk.point.toString().should.equal(p.toString())
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
describe('#fromObject', function () {
|
|
29
|
-
it('should make a public key from a point', function () {
|
|
30
|
-
should.exist(new PubKey().fromObject({ point: Point.getG() }).point)
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
describe('#fromJSON', function () {
|
|
35
|
-
it('should input this public key', function () {
|
|
36
|
-
const pk = new PubKey()
|
|
37
|
-
pk.fromJSON(
|
|
38
|
-
'00041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
39
|
-
)
|
|
40
|
-
pk.point
|
|
41
|
-
.getX()
|
|
42
|
-
.toString(16)
|
|
43
|
-
.should.equal(
|
|
44
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
45
|
-
)
|
|
46
|
-
pk.point
|
|
47
|
-
.getY()
|
|
48
|
-
.toString(16)
|
|
49
|
-
.should.equal(
|
|
50
|
-
'7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
51
|
-
)
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
describe('#toJSON', function () {
|
|
56
|
-
it('should output this pubKey', function () {
|
|
57
|
-
const pk = new PubKey()
|
|
58
|
-
const hex =
|
|
59
|
-
'01041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
60
|
-
pk
|
|
61
|
-
.fromJSON(hex)
|
|
62
|
-
.toJSON()
|
|
63
|
-
.should.equal(hex)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it('should output this uncompressed pubKey', function () {
|
|
67
|
-
const pk = new PubKey()
|
|
68
|
-
const hex =
|
|
69
|
-
'00041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
70
|
-
pk
|
|
71
|
-
.fromJSON(hex)
|
|
72
|
-
.toJSON()
|
|
73
|
-
.should.equal(hex)
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
describe('#fromPrivKey', function () {
|
|
78
|
-
it('should make a public key from a privKey', function () {
|
|
79
|
-
should.exist(new PubKey().fromPrivKey(new PrivKey().fromRandom()))
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
describe('@fromPrivKey', function () {
|
|
84
|
-
it('should make a public key from a privKey', function () {
|
|
85
|
-
should.exist(PubKey.fromPrivKey(new PrivKey().fromRandom()))
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
describe('#asyncFromPrivKey', function () {
|
|
90
|
-
it('should result the same as fromPrivKey', async function () {
|
|
91
|
-
const privKey = new PrivKey().fromRandom()
|
|
92
|
-
const pubKey1 = new PubKey().fromPrivKey(privKey)
|
|
93
|
-
const pubKey2 = await new PubKey().asyncFromPrivKey(privKey)
|
|
94
|
-
pubKey1.toString().should.equal(pubKey2.toString())
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('should result the same as fromPrivKey', async function () {
|
|
98
|
-
const privKey = new PrivKey().fromBn(new Bn(5))
|
|
99
|
-
const pubKey1 = new PubKey().fromPrivKey(privKey)
|
|
100
|
-
const pubKey2 = await new PubKey().asyncFromPrivKey(privKey)
|
|
101
|
-
pubKey1.toString().should.equal(pubKey2.toString())
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
describe('@asyncFromPrivKey', function () {
|
|
106
|
-
it('should result the same as fromPrivKey', async function () {
|
|
107
|
-
const privKey = new PrivKey().fromRandom()
|
|
108
|
-
const pubKey1 = PubKey.fromPrivKey(privKey)
|
|
109
|
-
const pubKey2 = await PubKey.asyncFromPrivKey(privKey)
|
|
110
|
-
pubKey1.toString().should.equal(pubKey2.toString())
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
it('should result the same as fromPrivKey', async function () {
|
|
114
|
-
const privKey = new PrivKey().fromBn(new Bn(5))
|
|
115
|
-
const pubKey1 = PubKey.fromPrivKey(privKey)
|
|
116
|
-
const pubKey2 = await PubKey.asyncFromPrivKey(privKey)
|
|
117
|
-
pubKey1.toString().should.equal(pubKey2.toString())
|
|
118
|
-
})
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
describe('#fromHex', function () {
|
|
122
|
-
it('should parse this uncompressed public key', function () {
|
|
123
|
-
const pk = new PubKey()
|
|
124
|
-
pk.fromHex(
|
|
125
|
-
'041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
126
|
-
)
|
|
127
|
-
pk.point
|
|
128
|
-
.getX()
|
|
129
|
-
.toString(16)
|
|
130
|
-
.should.equal(
|
|
131
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
132
|
-
)
|
|
133
|
-
pk.point
|
|
134
|
-
.getY()
|
|
135
|
-
.toString(16)
|
|
136
|
-
.should.equal(
|
|
137
|
-
'7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
138
|
-
)
|
|
139
|
-
})
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
describe('#fromBuffer', function () {
|
|
143
|
-
it('should parse this uncompressed public key', function () {
|
|
144
|
-
const pk = new PubKey()
|
|
145
|
-
pk.fromBuffer(
|
|
146
|
-
Buffer.from(
|
|
147
|
-
'041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341',
|
|
148
|
-
'hex'
|
|
149
|
-
)
|
|
150
|
-
)
|
|
151
|
-
pk.point
|
|
152
|
-
.getX()
|
|
153
|
-
.toString(16)
|
|
154
|
-
.should.equal(
|
|
155
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
156
|
-
)
|
|
157
|
-
pk.point
|
|
158
|
-
.getY()
|
|
159
|
-
.toString(16)
|
|
160
|
-
.should.equal(
|
|
161
|
-
'7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
162
|
-
)
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
it('should parse this compressed public key', function () {
|
|
166
|
-
const pk = new PubKey()
|
|
167
|
-
pk.fromBuffer(
|
|
168
|
-
Buffer.from(
|
|
169
|
-
'031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
|
|
170
|
-
'hex'
|
|
171
|
-
)
|
|
172
|
-
)
|
|
173
|
-
pk.point
|
|
174
|
-
.getX()
|
|
175
|
-
.toString(16)
|
|
176
|
-
.should.equal(
|
|
177
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
178
|
-
)
|
|
179
|
-
pk.point
|
|
180
|
-
.getY()
|
|
181
|
-
.toString(16)
|
|
182
|
-
.should.equal(
|
|
183
|
-
'7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
184
|
-
)
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
it('should throw an error on this invalid public key', function () {
|
|
188
|
-
const pk = new PubKey()
|
|
189
|
-
;(function () {
|
|
190
|
-
pk.fromBuffer(
|
|
191
|
-
Buffer.from(
|
|
192
|
-
'091ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
|
|
193
|
-
'hex'
|
|
194
|
-
)
|
|
195
|
-
)
|
|
196
|
-
}.should.throw())
|
|
197
|
-
})
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
describe('#asyncFromBuffer', function () {
|
|
201
|
-
it('should derive the same as fromBuffer', async function () {
|
|
202
|
-
const pubKey = new PubKey().fromPrivKey(new PrivKey().fromRandom())
|
|
203
|
-
const pubKey1 = new PubKey().fromBuffer(pubKey.toBuffer())
|
|
204
|
-
const pubKey2 = await new PubKey().asyncFromBuffer(pubKey.toBuffer())
|
|
205
|
-
pubKey1.toString().should.equal(pubKey2.toString())
|
|
206
|
-
})
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
describe('@asyncFromBuffer', function () {
|
|
210
|
-
it('should derive the same as fromBuffer', async function () {
|
|
211
|
-
const pubKey = PubKey.fromPrivKey(new PrivKey().fromRandom())
|
|
212
|
-
const pubKey1 = PubKey.fromBuffer(pubKey.toBuffer())
|
|
213
|
-
const pubKey2 = await PubKey.asyncFromBuffer(pubKey.toBuffer())
|
|
214
|
-
pubKey1.toString().should.equal(pubKey2.toString())
|
|
215
|
-
})
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
describe('#fromFastBuffer', function () {
|
|
219
|
-
it('should convert from this known fast buffer', function () {
|
|
220
|
-
const pubKey = new PubKey().fromFastBuffer(
|
|
221
|
-
Buffer.from(
|
|
222
|
-
'01041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341',
|
|
223
|
-
'hex'
|
|
224
|
-
)
|
|
225
|
-
)
|
|
226
|
-
pubKey.point
|
|
227
|
-
.getX()
|
|
228
|
-
.toString(16)
|
|
229
|
-
.should.equal(
|
|
230
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
231
|
-
)
|
|
232
|
-
})
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
describe('#fromDer', function () {
|
|
236
|
-
it('should parse this uncompressed public key', function () {
|
|
237
|
-
const pk = new PubKey()
|
|
238
|
-
pk.fromDer(
|
|
239
|
-
Buffer.from(
|
|
240
|
-
'041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341',
|
|
241
|
-
'hex'
|
|
242
|
-
)
|
|
243
|
-
)
|
|
244
|
-
pk.point
|
|
245
|
-
.getX()
|
|
246
|
-
.toString(16)
|
|
247
|
-
.should.equal(
|
|
248
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
249
|
-
)
|
|
250
|
-
pk.point
|
|
251
|
-
.getY()
|
|
252
|
-
.toString(16)
|
|
253
|
-
.should.equal(
|
|
254
|
-
'7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
255
|
-
)
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
it('should parse this compressed public key', function () {
|
|
259
|
-
const pk = new PubKey()
|
|
260
|
-
pk.fromDer(
|
|
261
|
-
Buffer.from(
|
|
262
|
-
'031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
|
|
263
|
-
'hex'
|
|
264
|
-
)
|
|
265
|
-
)
|
|
266
|
-
pk.point
|
|
267
|
-
.getX()
|
|
268
|
-
.toString(16)
|
|
269
|
-
.should.equal(
|
|
270
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
271
|
-
)
|
|
272
|
-
pk.point
|
|
273
|
-
.getY()
|
|
274
|
-
.toString(16)
|
|
275
|
-
.should.equal(
|
|
276
|
-
'7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
277
|
-
)
|
|
278
|
-
})
|
|
279
|
-
|
|
280
|
-
it('should throw an error on this invalid public key', function () {
|
|
281
|
-
const pk = new PubKey()
|
|
282
|
-
;(function () {
|
|
283
|
-
pk.fromDer(
|
|
284
|
-
Buffer.from(
|
|
285
|
-
'091ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
|
|
286
|
-
'hex'
|
|
287
|
-
)
|
|
288
|
-
)
|
|
289
|
-
}.should.throw())
|
|
290
|
-
})
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
describe('@fromDer', function () {
|
|
294
|
-
it('should parse this uncompressed public key', function () {
|
|
295
|
-
const pk = PubKey.fromDer(
|
|
296
|
-
Buffer.from(
|
|
297
|
-
'041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341',
|
|
298
|
-
'hex'
|
|
299
|
-
)
|
|
300
|
-
)
|
|
301
|
-
pk.point
|
|
302
|
-
.getX()
|
|
303
|
-
.toString(16)
|
|
304
|
-
.should.equal(
|
|
305
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
306
|
-
)
|
|
307
|
-
pk.point
|
|
308
|
-
.getY()
|
|
309
|
-
.toString(16)
|
|
310
|
-
.should.equal(
|
|
311
|
-
'7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
312
|
-
)
|
|
313
|
-
})
|
|
314
|
-
|
|
315
|
-
it('should parse this compressed public key', function () {
|
|
316
|
-
const pk = PubKey.fromDer(
|
|
317
|
-
Buffer.from(
|
|
318
|
-
'031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
|
|
319
|
-
'hex'
|
|
320
|
-
)
|
|
321
|
-
)
|
|
322
|
-
pk.point
|
|
323
|
-
.getX()
|
|
324
|
-
.toString(16)
|
|
325
|
-
.should.equal(
|
|
326
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
327
|
-
)
|
|
328
|
-
pk.point
|
|
329
|
-
.getY()
|
|
330
|
-
.toString(16)
|
|
331
|
-
.should.equal(
|
|
332
|
-
'7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
333
|
-
)
|
|
334
|
-
})
|
|
335
|
-
|
|
336
|
-
it('should throw an error on this invalid public key', function () {
|
|
337
|
-
;(function () {
|
|
338
|
-
PubKey.fromDer(
|
|
339
|
-
Buffer.from(
|
|
340
|
-
'091ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
|
|
341
|
-
'hex'
|
|
342
|
-
)
|
|
343
|
-
)
|
|
344
|
-
}.should.throw())
|
|
345
|
-
})
|
|
346
|
-
})
|
|
347
|
-
|
|
348
|
-
describe('#fromString', function () {
|
|
349
|
-
it('should parse this known valid public key', function () {
|
|
350
|
-
const pk = new PubKey()
|
|
351
|
-
pk.fromString(
|
|
352
|
-
'041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
353
|
-
)
|
|
354
|
-
pk.point
|
|
355
|
-
.getX()
|
|
356
|
-
.toString(16)
|
|
357
|
-
.should.equal(
|
|
358
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
359
|
-
)
|
|
360
|
-
pk.point
|
|
361
|
-
.getY()
|
|
362
|
-
.toString(16)
|
|
363
|
-
.should.equal(
|
|
364
|
-
'7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
365
|
-
)
|
|
366
|
-
})
|
|
367
|
-
})
|
|
368
|
-
|
|
369
|
-
describe('#fromX', function () {
|
|
370
|
-
it('should create this known public key', function () {
|
|
371
|
-
const x = Bn.fromBuffer(
|
|
372
|
-
Buffer.from(
|
|
373
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
|
|
374
|
-
'hex'
|
|
375
|
-
)
|
|
376
|
-
)
|
|
377
|
-
const pk = new PubKey()
|
|
378
|
-
pk.fromX(true, x)
|
|
379
|
-
pk.point
|
|
380
|
-
.getX()
|
|
381
|
-
.toString(16)
|
|
382
|
-
.should.equal(
|
|
383
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
384
|
-
)
|
|
385
|
-
pk.point
|
|
386
|
-
.getY()
|
|
387
|
-
.toString(16)
|
|
388
|
-
.should.equal(
|
|
389
|
-
'7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
390
|
-
)
|
|
391
|
-
})
|
|
392
|
-
})
|
|
393
|
-
|
|
394
|
-
describe('@fromX', function () {
|
|
395
|
-
it('should create this known public key', function () {
|
|
396
|
-
const x = Bn.fromBuffer(
|
|
397
|
-
Buffer.from(
|
|
398
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
|
|
399
|
-
'hex'
|
|
400
|
-
)
|
|
401
|
-
)
|
|
402
|
-
const pk = new PubKey()
|
|
403
|
-
pk.fromX(true, x)
|
|
404
|
-
pk.point
|
|
405
|
-
.getX()
|
|
406
|
-
.toString(16)
|
|
407
|
-
.should.equal(
|
|
408
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
409
|
-
)
|
|
410
|
-
pk.point
|
|
411
|
-
.getY()
|
|
412
|
-
.toString(16)
|
|
413
|
-
.should.equal(
|
|
414
|
-
'7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
415
|
-
)
|
|
416
|
-
})
|
|
417
|
-
})
|
|
418
|
-
|
|
419
|
-
describe('#toHex', function () {
|
|
420
|
-
it('should return this compressed DER format', function () {
|
|
421
|
-
const x = new Bn().fromHex(
|
|
422
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
423
|
-
)
|
|
424
|
-
const pk = new PubKey()
|
|
425
|
-
pk.fromX(true, x)
|
|
426
|
-
pk
|
|
427
|
-
.toHex()
|
|
428
|
-
.should.equal(
|
|
429
|
-
'031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
430
|
-
)
|
|
431
|
-
})
|
|
432
|
-
})
|
|
433
|
-
|
|
434
|
-
describe('#toBuffer', function () {
|
|
435
|
-
it('should return this compressed DER format', function () {
|
|
436
|
-
const x = Bn.fromBuffer(
|
|
437
|
-
Buffer.from(
|
|
438
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
|
|
439
|
-
'hex'
|
|
440
|
-
)
|
|
441
|
-
)
|
|
442
|
-
const pk = new PubKey()
|
|
443
|
-
pk.fromX(true, x)
|
|
444
|
-
pk
|
|
445
|
-
.toBuffer()
|
|
446
|
-
.toString('hex')
|
|
447
|
-
.should.equal(
|
|
448
|
-
'031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
449
|
-
)
|
|
450
|
-
})
|
|
451
|
-
})
|
|
452
|
-
|
|
453
|
-
describe('#toFastBuffer', function () {
|
|
454
|
-
it('should return fast buffer', function () {
|
|
455
|
-
const x = Bn.fromBuffer(
|
|
456
|
-
Buffer.from(
|
|
457
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
|
|
458
|
-
'hex'
|
|
459
|
-
)
|
|
460
|
-
)
|
|
461
|
-
const pk = new PubKey()
|
|
462
|
-
pk.fromX(true, x)
|
|
463
|
-
pk
|
|
464
|
-
.toFastBuffer()
|
|
465
|
-
.toString('hex')
|
|
466
|
-
.should.equal(
|
|
467
|
-
'01041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
468
|
-
)
|
|
469
|
-
pk.toFastBuffer().length.should.greaterThan(64)
|
|
470
|
-
})
|
|
471
|
-
})
|
|
472
|
-
|
|
473
|
-
describe('#toDer', function () {
|
|
474
|
-
it('should return this compressed DER format', function () {
|
|
475
|
-
const x = Bn.fromBuffer(
|
|
476
|
-
Buffer.from(
|
|
477
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
|
|
478
|
-
'hex'
|
|
479
|
-
)
|
|
480
|
-
)
|
|
481
|
-
const pk = new PubKey()
|
|
482
|
-
pk.fromX(true, x)
|
|
483
|
-
pk
|
|
484
|
-
.toDer(true)
|
|
485
|
-
.toString('hex')
|
|
486
|
-
.should.equal(
|
|
487
|
-
'031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
488
|
-
)
|
|
489
|
-
})
|
|
490
|
-
|
|
491
|
-
it('should return this uncompressed DER format', function () {
|
|
492
|
-
const x = Bn.fromBuffer(
|
|
493
|
-
Buffer.from(
|
|
494
|
-
'1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a',
|
|
495
|
-
'hex'
|
|
496
|
-
)
|
|
497
|
-
)
|
|
498
|
-
const pk = new PubKey()
|
|
499
|
-
pk.fromX(true, x)
|
|
500
|
-
pk
|
|
501
|
-
.toDer(false)
|
|
502
|
-
.toString('hex')
|
|
503
|
-
.should.equal(
|
|
504
|
-
'041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'
|
|
505
|
-
)
|
|
506
|
-
})
|
|
507
|
-
})
|
|
508
|
-
|
|
509
|
-
describe('#toString', function () {
|
|
510
|
-
it('should print this known public key', function () {
|
|
511
|
-
const hex =
|
|
512
|
-
'031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
513
|
-
const pk = new PubKey()
|
|
514
|
-
pk.fromString(hex)
|
|
515
|
-
pk.toString().should.equal(hex)
|
|
516
|
-
})
|
|
517
|
-
})
|
|
518
|
-
|
|
519
|
-
describe('#validate', function () {
|
|
520
|
-
it('should not throw an error if pubKey is valid', function () {
|
|
521
|
-
const hex =
|
|
522
|
-
'031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'
|
|
523
|
-
const pk = new PubKey()
|
|
524
|
-
pk.fromString(hex)
|
|
525
|
-
should.exist(pk.validate())
|
|
526
|
-
})
|
|
527
|
-
|
|
528
|
-
it('should not throw an error if pubKey is invalid', function () {
|
|
529
|
-
const hex =
|
|
530
|
-
'041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a0000000000000000000000000000000000000000000000000000000000000000'
|
|
531
|
-
const pk = new PubKey()
|
|
532
|
-
pk.fromString(hex)
|
|
533
|
-
;(function () {
|
|
534
|
-
pk.validate()
|
|
535
|
-
}.should.throw('Invalid y value of public key'))
|
|
536
|
-
})
|
|
537
|
-
|
|
538
|
-
it('should throw an error if pubKey is infinity', function () {
|
|
539
|
-
const pk = new PubKey()
|
|
540
|
-
let errm = ''
|
|
541
|
-
try {
|
|
542
|
-
pk.point = Point.getG().mul(Point.getN())
|
|
543
|
-
} catch (err) {
|
|
544
|
-
errm = err.message
|
|
545
|
-
}
|
|
546
|
-
errm.should.equal('point mul out of range')
|
|
547
|
-
})
|
|
548
|
-
})
|
|
549
|
-
})
|
package/test/random.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/* global describe,it */
|
|
2
|
-
import { Random } from '../lib/random'
|
|
3
|
-
import 'should'
|
|
4
|
-
|
|
5
|
-
describe('Random', function () {
|
|
6
|
-
describe('@getRandomBuffer', function () {
|
|
7
|
-
it('should return a buffer', function () {
|
|
8
|
-
const bytes = Random.getRandomBuffer(8)
|
|
9
|
-
bytes.length.should.equal(8)
|
|
10
|
-
Buffer.isBuffer(bytes).should.equal(true)
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
it('should not equate two 256 bit random buffers', function () {
|
|
14
|
-
const bytes1 = Random.getRandomBuffer(32)
|
|
15
|
-
const bytes2 = Random.getRandomBuffer(32)
|
|
16
|
-
bytes1.toString('hex').should.not.equal(bytes2.toString('hex'))
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('should generate 100 8 byte buffers in a row that are not equal', function () {
|
|
20
|
-
const hexs = []
|
|
21
|
-
for (let i = 0; i < 100; i++) {
|
|
22
|
-
hexs[i] = Random.getRandomBuffer(8).toString('hex')
|
|
23
|
-
}
|
|
24
|
-
for (let i = 0; i < 100; i++) {
|
|
25
|
-
for (let j = i + 1; j < 100; j++) {
|
|
26
|
-
hexs[i].should.not.equal(hexs[j])
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
})
|