From 1c75c0203809ced5ace402ca211c2c12bb9db4bc Mon Sep 17 00:00:00 2001 From: junderw Date: Thu, 16 May 2019 16:29:23 +0900 Subject: [PATCH] Fix publicKey type on ECPairInterface --- ts_src/ecpair.ts | 11 ++++++----- types/ecpair.d.ts | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ts_src/ecpair.ts b/ts_src/ecpair.ts index 5c31e7f..18c0c9e 100644 --- a/ts_src/ecpair.ts +++ b/ts_src/ecpair.ts @@ -22,8 +22,8 @@ interface ECPairOptions { export interface ECPairInterface { compressed: boolean; network: Network; + publicKey: Buffer; privateKey?: Buffer; - publicKey?: Buffer; toWIF(): string; sign(hash: Buffer): Buffer; verify(hash: Buffer, signature: Buffer): boolean; @@ -51,8 +51,9 @@ class ECPair implements ECPairInterface { return this.__D; } - get publicKey(): Buffer | undefined { - if (!this.__Q) this.__Q = ecc.pointFromScalar(this.__D, this.compressed); + get publicKey(): Buffer { + if (!this.__Q) + this.__Q = ecc.pointFromScalar(this.__D, this.compressed) as Buffer; return this.__Q; } @@ -77,13 +78,13 @@ 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, options as ECPairOptions); + return new ECPair(buffer, undefined, options); } function fromPublicKey(buffer: Buffer, options?: ECPairOptions): ECPair { typeforce(ecc.isPoint, buffer); typeforce(isOptions, options); - return new ECPair(undefined, buffer, options as ECPairOptions); + return new ECPair(undefined, buffer, options); } function fromWIF(wifString: string, network?: Network | Network[]): ECPair { diff --git a/types/ecpair.d.ts b/types/ecpair.d.ts index 2cc2c27..896025b 100644 --- a/types/ecpair.d.ts +++ b/types/ecpair.d.ts @@ -8,8 +8,8 @@ interface ECPairOptions { export interface ECPairInterface { compressed: boolean; network: Network; + publicKey: Buffer; privateKey?: Buffer; - publicKey?: Buffer; toWIF(): string; sign(hash: Buffer): Buffer; verify(hash: Buffer, signature: Buffer): boolean; @@ -22,7 +22,7 @@ declare class ECPair implements ECPairInterface { network: Network; constructor(__D?: Buffer | undefined, __Q?: Buffer | undefined, options?: ECPairOptions); readonly privateKey: Buffer | undefined; - readonly publicKey: Buffer | undefined; + readonly publicKey: Buffer; toWIF(): string; sign(hash: Buffer): Buffer; verify(hash: Buffer, signature: Buffer): boolean;