sed -i 's/ var / const /', with const->let fixes
This commit is contained in:
parent
91b8823aa8
commit
a5db0a4e44
46 changed files with 776 additions and 769 deletions
test
|
@ -24,13 +24,13 @@ const GROUP_ORDER_LESS_1 = Buffer.from('fffffffffffffffffffffffffffffffebaaedce6
|
|||
describe('ECPair', function () {
|
||||
describe('constructor', function () {
|
||||
it('defaults to compressed', function () {
|
||||
let keyPair = ECPair.fromPrivateKey(ONE)
|
||||
const keyPair = ECPair.fromPrivateKey(ONE)
|
||||
|
||||
assert.strictEqual(keyPair.compressed, true)
|
||||
})
|
||||
|
||||
it('supports the uncompressed option', function () {
|
||||
let keyPair = ECPair.fromPrivateKey(ONE, {
|
||||
const keyPair = ECPair.fromPrivateKey(ONE, {
|
||||
compressed: false
|
||||
})
|
||||
|
||||
|
@ -38,7 +38,7 @@ describe('ECPair', function () {
|
|||
})
|
||||
|
||||
it('supports the network option', function () {
|
||||
let keyPair = ECPair.fromPrivateKey(ONE, {
|
||||
const keyPair = ECPair.fromPrivateKey(ONE, {
|
||||
compressed: false,
|
||||
network: NETWORKS.testnet
|
||||
})
|
||||
|
@ -48,10 +48,10 @@ describe('ECPair', function () {
|
|||
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('derives public key for ' + f.WIF, function () {
|
||||
let d = Buffer.from(f.d, 'hex')
|
||||
const d = Buffer.from(f.d, 'hex')
|
||||
console.log(d)
|
||||
|
||||
let keyPair = ECPair.fromPrivateKey(d, {
|
||||
const keyPair = ECPair.fromPrivateKey(d, {
|
||||
compressed: f.compressed
|
||||
})
|
||||
|
||||
|
@ -62,12 +62,12 @@ describe('ECPair', function () {
|
|||
fixtures.invalid.constructor.forEach(function (f) {
|
||||
it('throws ' + f.exception, function () {
|
||||
if (f.d) {
|
||||
let d = Buffer.from(f.d, 'hex')
|
||||
const d = Buffer.from(f.d, 'hex')
|
||||
assert.throws(function () {
|
||||
ECPair.fromPrivateKey(d, f.options)
|
||||
}, new RegExp(f.exception))
|
||||
} else {
|
||||
let Q = Buffer.from(f.Q, 'hex')
|
||||
const Q = Buffer.from(f.Q, 'hex')
|
||||
assert.throws(function () {
|
||||
ECPair.fromPublicKey(Q, f.options)
|
||||
}, new RegExp(f.exception))
|
||||
|
@ -95,8 +95,8 @@ describe('ECPair', function () {
|
|||
describe('fromWIF', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('imports ' + f.WIF + ' (' + f.network + ')', function () {
|
||||
let network = NETWORKS[f.network]
|
||||
let keyPair = ECPair.fromWIF(f.WIF, network)
|
||||
const network = NETWORKS[f.network]
|
||||
const keyPair = ECPair.fromWIF(f.WIF, network)
|
||||
|
||||
assert.strictEqual(keyPair.privateKey.toString('hex'), f.d)
|
||||
assert.strictEqual(keyPair.compressed, f.compressed)
|
||||
|
@ -106,7 +106,7 @@ describe('ECPair', function () {
|
|||
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('imports ' + f.WIF + ' (via list of networks)', function () {
|
||||
let keyPair = ECPair.fromWIF(f.WIF, NETWORKS_LIST)
|
||||
const keyPair = ECPair.fromWIF(f.WIF, NETWORKS_LIST)
|
||||
|
||||
assert.strictEqual(keyPair.privateKey.toString('hex'), f.d)
|
||||
assert.strictEqual(keyPair.compressed, f.compressed)
|
||||
|
@ -117,7 +117,7 @@ describe('ECPair', function () {
|
|||
fixtures.invalid.fromWIF.forEach(function (f) {
|
||||
it('throws on ' + f.WIF, function () {
|
||||
assert.throws(function () {
|
||||
let networks = f.network ? NETWORKS[f.network] : NETWORKS_LIST
|
||||
const networks = f.network ? NETWORKS[f.network] : NETWORKS_LIST
|
||||
|
||||
ECPair.fromWIF(f.WIF, networks)
|
||||
}, new RegExp(f.exception))
|
||||
|
@ -128,29 +128,29 @@ describe('ECPair', function () {
|
|||
describe('toWIF', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('exports ' + f.WIF, function () {
|
||||
let keyPair = ECPair.fromWIF(f.WIF, NETWORKS_LIST)
|
||||
let result = keyPair.toWIF()
|
||||
const keyPair = ECPair.fromWIF(f.WIF, NETWORKS_LIST)
|
||||
const result = keyPair.toWIF()
|
||||
assert.strictEqual(result, f.WIF)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('makeRandom', function () {
|
||||
let d = Buffer.alloc(32, 4)
|
||||
let exWIF = 'KwMWvwRJeFqxYyhZgNwYuYjbQENDAPAudQx5VEmKJrUZcq6aL2pv'
|
||||
const d = Buffer.alloc(32, 4)
|
||||
const exWIF = 'KwMWvwRJeFqxYyhZgNwYuYjbQENDAPAudQx5VEmKJrUZcq6aL2pv'
|
||||
|
||||
describe('uses randombytes RNG', function () {
|
||||
it('generates a ECPair', function () {
|
||||
let stub = { randombytes: function () { return d } }
|
||||
let ProxiedECPair = proxyquire('../src/ecpair', stub)
|
||||
const stub = { randombytes: function () { return d } }
|
||||
const ProxiedECPair = proxyquire('../src/ecpair', stub)
|
||||
|
||||
let keyPair = ProxiedECPair.makeRandom()
|
||||
const keyPair = ProxiedECPair.makeRandom()
|
||||
assert.strictEqual(keyPair.toWIF(), exWIF)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows a custom RNG to be used', function () {
|
||||
let keyPair = ECPair.makeRandom({
|
||||
const keyPair = ECPair.makeRandom({
|
||||
rng: function (size) { return d.slice(0, size) }
|
||||
})
|
||||
|
||||
|
@ -158,14 +158,14 @@ describe('ECPair', function () {
|
|||
})
|
||||
|
||||
it('retains the same defaults as ECPair constructor', function () {
|
||||
let keyPair = ECPair.makeRandom()
|
||||
const keyPair = ECPair.makeRandom()
|
||||
|
||||
assert.strictEqual(keyPair.compressed, true)
|
||||
assert.strictEqual(keyPair.network, NETWORKS.bitcoin)
|
||||
})
|
||||
|
||||
it('supports the options parameter', function () {
|
||||
let keyPair = ECPair.makeRandom({
|
||||
const keyPair = ECPair.makeRandom({
|
||||
compressed: false,
|
||||
network: NETWORKS.testnet
|
||||
})
|
||||
|
@ -185,7 +185,7 @@ describe('ECPair', function () {
|
|||
})
|
||||
|
||||
it('loops until d is within interval [1, n) : 1', hoodwink(function () {
|
||||
let rng = this.stub(function f () {
|
||||
const rng = this.stub(function f () {
|
||||
if (f.calls === 0) return ZERO // 0
|
||||
return ONE // >0
|
||||
}, 2)
|
||||
|
@ -194,7 +194,7 @@ describe('ECPair', function () {
|
|||
}))
|
||||
|
||||
it('loops until d is within interval [1, n) : n - 1', hoodwink(function () {
|
||||
let rng = this.stub(function f () {
|
||||
const rng = this.stub(function f () {
|
||||
if (f.calls === 0) return ZERO // <1
|
||||
if (f.calls === 1) return GROUP_ORDER // >n-1
|
||||
return GROUP_ORDER_LESS_1 // n-1
|
||||
|
@ -207,8 +207,8 @@ describe('ECPair', function () {
|
|||
describe('.network', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('returns ' + f.network + ' for ' + f.WIF, function () {
|
||||
let network = NETWORKS[f.network]
|
||||
let keyPair = ECPair.fromWIF(f.WIF, NETWORKS_LIST)
|
||||
const network = NETWORKS[f.network]
|
||||
const keyPair = ECPair.fromWIF(f.WIF, NETWORKS_LIST)
|
||||
|
||||
assert.strictEqual(keyPair.network, network)
|
||||
})
|
||||
|
@ -216,7 +216,9 @@ describe('ECPair', function () {
|
|||
})
|
||||
|
||||
describe('tinysecp wrappers', function () {
|
||||
let keyPair, hash, signature
|
||||
let keyPair
|
||||
let hash
|
||||
let signature
|
||||
|
||||
beforeEach(function () {
|
||||
keyPair = ECPair.makeRandom()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue