Skip to content

Commit 1c639c0

Browse files
authored
Merge pull request #1442 from bitcoinjs/lowRECPair
Move lowR to public writable attribute
2 parents af8f41a + 4a29cb4 commit 1c639c0

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bitcoinjs-lib",
3-
"version": "5.1.1",
3+
"version": "5.1.2",
44
"description": "Client-side Bitcoin JavaScript library",
55
"main": "./src/index.js",
66
"types": "./types/index.d.ts",
@@ -48,7 +48,7 @@
4848
"@types/node": "10.12.18",
4949
"bech32": "^1.1.2",
5050
"bip174": "^1.0.0",
51-
"bip32": "^2.0.3",
51+
"bip32": "^2.0.4",
5252
"bip66": "^1.1.0",
5353
"bitcoin-ops": "^1.4.0",
5454
"bs58check": "^2.0.0",

src/ecpair.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class ECPair {
1616
constructor(__D, __Q, options) {
1717
this.__D = __D;
1818
this.__Q = __Q;
19+
this.lowR = false;
1920
if (options === undefined) options = {};
2021
this.compressed =
2122
options.compressed === undefined ? true : options.compressed;
@@ -33,8 +34,9 @@ class ECPair {
3334
if (!this.__D) throw new Error('Missing private key');
3435
return wif.encode(this.network.wif, this.__D, this.compressed);
3536
}
36-
sign(hash, lowR = false) {
37+
sign(hash, lowR) {
3738
if (!this.__D) throw new Error('Missing private key');
39+
if (lowR === undefined) lowR = this.lowR;
3840
if (lowR === false) {
3941
return ecc.sign(hash, this.__D);
4042
} else {

ts_src/ecpair.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface SignerAsync {
3636
export interface ECPairInterface extends Signer {
3737
compressed: boolean;
3838
network: Network;
39+
lowR: boolean;
3940
privateKey?: Buffer;
4041
toWIF(): string;
4142
verify(hash: Buffer, signature: Buffer): boolean;
@@ -44,12 +45,14 @@ export interface ECPairInterface extends Signer {
4445
class ECPair implements ECPairInterface {
4546
compressed: boolean;
4647
network: Network;
48+
lowR: boolean;
4749

4850
constructor(
4951
private __D?: Buffer,
5052
private __Q?: Buffer,
5153
options?: ECPairOptions,
5254
) {
55+
this.lowR = false;
5356
if (options === undefined) options = {};
5457
this.compressed =
5558
options.compressed === undefined ? true : options.compressed;
@@ -73,8 +76,9 @@ class ECPair implements ECPairInterface {
7376
return wif.encode(this.network.wif, this.__D, this.compressed);
7477
}
7578

76-
sign(hash: Buffer, lowR: boolean = false): Buffer {
79+
sign(hash: Buffer, lowR?: boolean): Buffer {
7780
if (!this.__D) throw new Error('Missing private key');
81+
if (lowR === undefined) lowR = this.lowR;
7882
if (lowR === false) {
7983
return ecc.sign(hash, this.__D);
8084
} else {

types/ecpair.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface SignerAsync {
2020
export interface ECPairInterface extends Signer {
2121
compressed: boolean;
2222
network: Network;
23+
lowR: boolean;
2324
privateKey?: Buffer;
2425
toWIF(): string;
2526
verify(hash: Buffer, signature: Buffer): boolean;
@@ -29,6 +30,7 @@ declare class ECPair implements ECPairInterface {
2930
private __Q?;
3031
compressed: boolean;
3132
network: Network;
33+
lowR: boolean;
3234
constructor(__D?: Buffer | undefined, __Q?: Buffer | undefined, options?: ECPairOptions);
3335
readonly privateKey: Buffer | undefined;
3436
readonly publicKey: Buffer;

0 commit comments

Comments
 (0)