Merge pull request #1442 from bitcoinjs/lowRECPair
Move lowR to public writable attribute
This commit is contained in:
commit
1c639c06e5
5 changed files with 16 additions and 8 deletions
8
package-lock.json
generated
8
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "bitcoinjs-lib",
|
"name": "bitcoinjs-lib",
|
||||||
"version": "5.1.1",
|
"version": "5.1.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -205,9 +205,9 @@
|
||||||
"integrity": "sha512-AaoWrkYtv6A2y8H+qzs6NvRWypzNbADT8PQGpM9rnP+jLzeol+uzhe3Myeuq/dwrHYtmsW8V71HmX2oXhQGagw=="
|
"integrity": "sha512-AaoWrkYtv6A2y8H+qzs6NvRWypzNbADT8PQGpM9rnP+jLzeol+uzhe3Myeuq/dwrHYtmsW8V71HmX2oXhQGagw=="
|
||||||
},
|
},
|
||||||
"bip32": {
|
"bip32": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/bip32/-/bip32-2.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/bip32/-/bip32-2.0.4.tgz",
|
||||||
"integrity": "sha512-Tg4dHUXiYBkJyCQq4g++C2PqKcZRveVqy7cKxyl88Uai7MmmknFGaF88odYrXcXk5EMyrlXLuAMC3yEiLxRnNA==",
|
"integrity": "sha512-ioPytarPDIrWckWMuK4RNUtvwhvWEc2fvuhnO0WEwu732k5OLjUXv4rXi2c/KJHw9ZMNQMkYRJrBw81RujShGQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@types/node": "10.12.18",
|
"@types/node": "10.12.18",
|
||||||
"bs58check": "^2.1.1",
|
"bs58check": "^2.1.1",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "bitcoinjs-lib",
|
"name": "bitcoinjs-lib",
|
||||||
"version": "5.1.1",
|
"version": "5.1.2",
|
||||||
"description": "Client-side Bitcoin JavaScript library",
|
"description": "Client-side Bitcoin JavaScript library",
|
||||||
"main": "./src/index.js",
|
"main": "./src/index.js",
|
||||||
"types": "./types/index.d.ts",
|
"types": "./types/index.d.ts",
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
"@types/node": "10.12.18",
|
"@types/node": "10.12.18",
|
||||||
"bech32": "^1.1.2",
|
"bech32": "^1.1.2",
|
||||||
"bip174": "^1.0.0",
|
"bip174": "^1.0.0",
|
||||||
"bip32": "^2.0.3",
|
"bip32": "^2.0.4",
|
||||||
"bip66": "^1.1.0",
|
"bip66": "^1.1.0",
|
||||||
"bitcoin-ops": "^1.4.0",
|
"bitcoin-ops": "^1.4.0",
|
||||||
"bs58check": "^2.0.0",
|
"bs58check": "^2.0.0",
|
||||||
|
|
|
@ -16,6 +16,7 @@ class ECPair {
|
||||||
constructor(__D, __Q, options) {
|
constructor(__D, __Q, options) {
|
||||||
this.__D = __D;
|
this.__D = __D;
|
||||||
this.__Q = __Q;
|
this.__Q = __Q;
|
||||||
|
this.lowR = false;
|
||||||
if (options === undefined) options = {};
|
if (options === undefined) options = {};
|
||||||
this.compressed =
|
this.compressed =
|
||||||
options.compressed === undefined ? true : options.compressed;
|
options.compressed === undefined ? true : options.compressed;
|
||||||
|
@ -33,8 +34,9 @@ class ECPair {
|
||||||
if (!this.__D) throw new Error('Missing private key');
|
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, lowR = false) {
|
sign(hash, lowR) {
|
||||||
if (!this.__D) throw new Error('Missing private key');
|
if (!this.__D) throw new Error('Missing private key');
|
||||||
|
if (lowR === undefined) lowR = this.lowR;
|
||||||
if (lowR === false) {
|
if (lowR === false) {
|
||||||
return ecc.sign(hash, this.__D);
|
return ecc.sign(hash, this.__D);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -36,6 +36,7 @@ export interface SignerAsync {
|
||||||
export interface ECPairInterface extends Signer {
|
export interface ECPairInterface extends Signer {
|
||||||
compressed: boolean;
|
compressed: boolean;
|
||||||
network: Network;
|
network: Network;
|
||||||
|
lowR: boolean;
|
||||||
privateKey?: Buffer;
|
privateKey?: Buffer;
|
||||||
toWIF(): string;
|
toWIF(): string;
|
||||||
verify(hash: Buffer, signature: Buffer): boolean;
|
verify(hash: Buffer, signature: Buffer): boolean;
|
||||||
|
@ -44,12 +45,14 @@ export interface ECPairInterface extends Signer {
|
||||||
class ECPair implements ECPairInterface {
|
class ECPair implements ECPairInterface {
|
||||||
compressed: boolean;
|
compressed: boolean;
|
||||||
network: Network;
|
network: Network;
|
||||||
|
lowR: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private __D?: Buffer,
|
private __D?: Buffer,
|
||||||
private __Q?: Buffer,
|
private __Q?: Buffer,
|
||||||
options?: ECPairOptions,
|
options?: ECPairOptions,
|
||||||
) {
|
) {
|
||||||
|
this.lowR = false;
|
||||||
if (options === undefined) options = {};
|
if (options === undefined) options = {};
|
||||||
this.compressed =
|
this.compressed =
|
||||||
options.compressed === undefined ? true : options.compressed;
|
options.compressed === undefined ? true : options.compressed;
|
||||||
|
@ -73,8 +76,9 @@ class ECPair implements ECPairInterface {
|
||||||
return wif.encode(this.network.wif, this.__D, this.compressed);
|
return wif.encode(this.network.wif, this.__D, this.compressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
sign(hash: Buffer, lowR: boolean = false): Buffer {
|
sign(hash: Buffer, lowR?: boolean): Buffer {
|
||||||
if (!this.__D) throw new Error('Missing private key');
|
if (!this.__D) throw new Error('Missing private key');
|
||||||
|
if (lowR === undefined) lowR = this.lowR;
|
||||||
if (lowR === false) {
|
if (lowR === false) {
|
||||||
return ecc.sign(hash, this.__D);
|
return ecc.sign(hash, this.__D);
|
||||||
} else {
|
} else {
|
||||||
|
|
2
types/ecpair.d.ts
vendored
2
types/ecpair.d.ts
vendored
|
@ -20,6 +20,7 @@ export interface SignerAsync {
|
||||||
export interface ECPairInterface extends Signer {
|
export interface ECPairInterface extends Signer {
|
||||||
compressed: boolean;
|
compressed: boolean;
|
||||||
network: Network;
|
network: Network;
|
||||||
|
lowR: boolean;
|
||||||
privateKey?: Buffer;
|
privateKey?: Buffer;
|
||||||
toWIF(): string;
|
toWIF(): string;
|
||||||
verify(hash: Buffer, signature: Buffer): boolean;
|
verify(hash: Buffer, signature: Buffer): boolean;
|
||||||
|
@ -29,6 +30,7 @@ declare class ECPair implements ECPairInterface {
|
||||||
private __Q?;
|
private __Q?;
|
||||||
compressed: boolean;
|
compressed: boolean;
|
||||||
network: Network;
|
network: Network;
|
||||||
|
lowR: boolean;
|
||||||
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;
|
readonly publicKey: Buffer;
|
||||||
|
|
Loading…
Add table
Reference in a new issue