From 6a734aef4c0dfc2503ee67ef878f3296291e0397 Mon Sep 17 00:00:00 2001 From: junderw <junderwood@bitcoinbank.co.jp> Date: Thu, 7 Mar 2019 12:06:12 +0900 Subject: [PATCH] Fix lint for ecpair.ts --- src/ecpair.js | 22 +++++++++++----------- test/ecpair.js | 2 +- ts_src/ecpair.ts | 36 ++++++++++++++++++------------------ types/ecpair.d.ts | 4 ++-- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/ecpair.js b/src/ecpair.js index 7d376ac..1335014 100644 --- a/src/ecpair.js +++ b/src/ecpair.js @@ -17,30 +17,30 @@ class ECPair { this.compressed = options.compressed === undefined ? true : options.compressed; this.network = options.network || NETWORKS.bitcoin; - this.__d = undefined; + this.__D = undefined; this.__Q = undefined; if (d !== undefined) - this.__d = d; + this.__D = d; if (Q !== undefined) this.__Q = ecc.pointCompress(Q, this.compressed); } get privateKey() { - return this.__d; + return this.__D; } get publicKey() { if (!this.__Q) - this.__Q = ecc.pointFromScalar(this.__d, this.compressed); + this.__Q = ecc.pointFromScalar(this.__D, this.compressed); return this.__Q; } toWIF() { - if (!this.__d) + if (!this.__D) throw new Error('Missing private key'); - return wif.encode(this.network.wif, this.__d, this.compressed); + return wif.encode(this.network.wif, this.__D, this.compressed); } sign(hash) { - if (!this.__d) + if (!this.__D) throw new Error('Missing private key'); - return ecc.sign(hash, this.__d); + return ecc.sign(hash, this.__D); } verify(hash, signature) { return ecc.verify(hash, this.publicKey, signature); @@ -60,13 +60,13 @@ function fromPublicKey(buffer, options) { return new ECPair(undefined, buffer, options); } exports.fromPublicKey = fromPublicKey; -function fromWIF(string, network) { - const decoded = wif.decode(string); +function fromWIF(wifString, network) { + const decoded = wif.decode(wifString); const version = decoded.version; // list of networks? if (types.Array(network)) { network = network - .filter(function (x) { + .filter((x) => { return version === x.wif; }) .pop(); diff --git a/test/ecpair.js b/test/ecpair.js index 0ff0e8b..de5c485 100644 --- a/test/ecpair.js +++ b/test/ecpair.js @@ -238,7 +238,7 @@ describe('ECPair', function () { })) it('throws if no private key is found', function () { - delete keyPair.__d + delete keyPair.__D assert.throws(function () { keyPair.sign(hash) diff --git a/ts_src/ecpair.ts b/ts_src/ecpair.ts index 15ec00a..ec8dc13 100644 --- a/ts_src/ecpair.ts +++ b/ts_src/ecpair.ts @@ -33,7 +33,7 @@ export interface ECPairInterface { class ECPair implements ECPairInterface { compressed: boolean; network: Network; - private __d?: Buffer; + private __D?: Buffer; private __Q?: Buffer; constructor(d?: Buffer, Q?: Buffer, options?: ECPairOptions) { @@ -42,29 +42,29 @@ class ECPair implements ECPairInterface { options.compressed === undefined ? true : options.compressed; this.network = options.network || NETWORKS.bitcoin; - this.__d = undefined; + this.__D = undefined; this.__Q = undefined; - if (d !== undefined) this.__d = d; + if (d !== undefined) this.__D = d; if (Q !== undefined) this.__Q = ecc.pointCompress(Q, this.compressed); } get privateKey(): Buffer | undefined { - return this.__d; + return this.__D; } get publicKey(): Buffer | undefined { - if (!this.__Q) this.__Q = ecc.pointFromScalar(this.__d, this.compressed); + if (!this.__Q) this.__Q = ecc.pointFromScalar(this.__D, this.compressed); return this.__Q; } toWIF(): string { - if (!this.__d) throw new Error('Missing private key'); - return wif.encode(this.network.wif, this.__d, this.compressed); + if (!this.__D) throw new Error('Missing private key'); + return wif.encode(this.network.wif, this.__D, this.compressed); } sign(hash: Buffer): Buffer { - if (!this.__d) throw new Error('Missing private key'); - return ecc.sign(hash, this.__d); + if (!this.__D) throw new Error('Missing private key'); + return ecc.sign(hash, this.__D); } verify(hash: Buffer, signature: Buffer): Buffer { @@ -78,26 +78,26 @@ function fromPrivateKey(buffer: Buffer, options?: ECPairOptions): ECPair { throw new TypeError('Private key not in range [1, n)'); typeforce(isOptions, options); - return new ECPair(buffer, undefined, <ECPairOptions>options); + return new ECPair(buffer, undefined, options as ECPairOptions); } function fromPublicKey(buffer: Buffer, options?: ECPairOptions): ECPair { typeforce(ecc.isPoint, buffer); typeforce(isOptions, options); - return new ECPair(undefined, buffer, <ECPairOptions>options); + return new ECPair(undefined, buffer, options as ECPairOptions); } -function fromWIF(string: string, network?: Network | Array<Network>): ECPair { - const decoded = wif.decode(string); +function fromWIF(wifString: string, network?: Network | Network[]): ECPair { + const decoded = wif.decode(wifString); const version = decoded.version; // list of networks? if (types.Array(network)) { - network = <Network>(<Array<Network>>network) - .filter(function(x: Network) { + network = (network as Network[]) + .filter((x: Network) => { return version === x.wif; }) - .pop(); + .pop() as Network; if (!network) throw new Error('Unknown network version'); @@ -105,13 +105,13 @@ function fromWIF(string: string, network?: Network | Array<Network>): ECPair { } else { network = network || NETWORKS.bitcoin; - if (version !== (<Network>network).wif) + if (version !== (network as Network).wif) throw new Error('Invalid network version'); } return fromPrivateKey(decoded.privateKey, { compressed: decoded.compressed, - network: <Network>network, + network: network as Network, }); } diff --git a/types/ecpair.d.ts b/types/ecpair.d.ts index 58ea4be..674615b 100644 --- a/types/ecpair.d.ts +++ b/types/ecpair.d.ts @@ -18,7 +18,7 @@ export interface ECPairInterface { declare class ECPair implements ECPairInterface { compressed: boolean; network: Network; - private __d?; + private __D?; private __Q?; constructor(d?: Buffer, Q?: Buffer, options?: ECPairOptions); readonly privateKey: Buffer | undefined; @@ -29,6 +29,6 @@ declare class ECPair implements ECPairInterface { } declare function fromPrivateKey(buffer: Buffer, options?: ECPairOptions): ECPair; declare function fromPublicKey(buffer: Buffer, options?: ECPairOptions): ECPair; -declare function fromWIF(string: string, network?: Network | Array<Network>): ECPair; +declare function fromWIF(wifString: string, network?: Network | Network[]): ECPair; declare function makeRandom(options?: ECPairOptions): ECPair; export { makeRandom, fromPrivateKey, fromPublicKey, fromWIF };