Merge pull request #1397 from bitcoinjs/fixECPair
Fix publicKey type on ECPairInterface
This commit is contained in:
commit
cbc189ca8d
2 changed files with 8 additions and 7 deletions
|
@ -22,8 +22,8 @@ interface ECPairOptions {
|
||||||
export interface ECPairInterface {
|
export interface ECPairInterface {
|
||||||
compressed: boolean;
|
compressed: boolean;
|
||||||
network: Network;
|
network: Network;
|
||||||
|
publicKey: Buffer;
|
||||||
privateKey?: Buffer;
|
privateKey?: Buffer;
|
||||||
publicKey?: Buffer;
|
|
||||||
toWIF(): string;
|
toWIF(): string;
|
||||||
sign(hash: Buffer): Buffer;
|
sign(hash: Buffer): Buffer;
|
||||||
verify(hash: Buffer, signature: Buffer): boolean;
|
verify(hash: Buffer, signature: Buffer): boolean;
|
||||||
|
@ -51,8 +51,9 @@ class ECPair implements ECPairInterface {
|
||||||
return this.__D;
|
return this.__D;
|
||||||
}
|
}
|
||||||
|
|
||||||
get publicKey(): Buffer | undefined {
|
get publicKey(): Buffer {
|
||||||
if (!this.__Q) this.__Q = ecc.pointFromScalar(this.__D, this.compressed);
|
if (!this.__Q)
|
||||||
|
this.__Q = ecc.pointFromScalar(this.__D, this.compressed) as Buffer;
|
||||||
return this.__Q;
|
return this.__Q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,13 +78,13 @@ function fromPrivateKey(buffer: Buffer, options?: ECPairOptions): ECPair {
|
||||||
throw new TypeError('Private key not in range [1, n)');
|
throw new TypeError('Private key not in range [1, n)');
|
||||||
typeforce(isOptions, options);
|
typeforce(isOptions, options);
|
||||||
|
|
||||||
return new ECPair(buffer, undefined, options as ECPairOptions);
|
return new ECPair(buffer, undefined, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fromPublicKey(buffer: Buffer, options?: ECPairOptions): ECPair {
|
function fromPublicKey(buffer: Buffer, options?: ECPairOptions): ECPair {
|
||||||
typeforce(ecc.isPoint, buffer);
|
typeforce(ecc.isPoint, buffer);
|
||||||
typeforce(isOptions, options);
|
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 {
|
function fromWIF(wifString: string, network?: Network | Network[]): ECPair {
|
||||||
|
|
4
types/ecpair.d.ts
vendored
4
types/ecpair.d.ts
vendored
|
@ -8,8 +8,8 @@ interface ECPairOptions {
|
||||||
export interface ECPairInterface {
|
export interface ECPairInterface {
|
||||||
compressed: boolean;
|
compressed: boolean;
|
||||||
network: Network;
|
network: Network;
|
||||||
|
publicKey: Buffer;
|
||||||
privateKey?: Buffer;
|
privateKey?: Buffer;
|
||||||
publicKey?: Buffer;
|
|
||||||
toWIF(): string;
|
toWIF(): string;
|
||||||
sign(hash: Buffer): Buffer;
|
sign(hash: Buffer): Buffer;
|
||||||
verify(hash: Buffer, signature: Buffer): boolean;
|
verify(hash: Buffer, signature: Buffer): boolean;
|
||||||
|
@ -22,7 +22,7 @@ declare class ECPair implements ECPairInterface {
|
||||||
network: Network;
|
network: Network;
|
||||||
constructor(__D?: Buffer | undefined, __Q?: Buffer | undefined, options?: ECPairOptions);
|
constructor(__D?: Buffer | undefined, __Q?: Buffer | undefined, options?: ECPairOptions);
|
||||||
readonly privateKey: Buffer | undefined;
|
readonly privateKey: Buffer | undefined;
|
||||||
readonly publicKey: Buffer | undefined;
|
readonly publicKey: Buffer;
|
||||||
toWIF(): string;
|
toWIF(): string;
|
||||||
sign(hash: Buffer): Buffer;
|
sign(hash: Buffer): Buffer;
|
||||||
verify(hash: Buffer, signature: Buffer): boolean;
|
verify(hash: Buffer, signature: Buffer): boolean;
|
||||||
|
|
Loading…
Add table
Reference in a new issue