Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit fdf2d22

Browse files
ECPair: simplify getPublicKeyBuffer
The BigInteger type provided `bigi` already supports padding (as seen a few lines below in `toWIF()`) https://github.com/cryptocoinjs/bigi/blob/cb7026/lib/convert.js#L77 The custom padding is not required. Issue: BLOCK-261.
1 parent 288f662 commit fdf2d22

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

src/ecpair.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,7 @@ ECPair.prototype.getPublicKeyBuffer = function () {
138138
ECPair.prototype.getPrivateKeyBuffer = function () {
139139
if (!this.d) throw new Error('Missing private key')
140140

141-
var bigIntBuffer = this.d.toBuffer()
142-
if (bigIntBuffer.length > 32) throw new Error('Private key size exceeds 32 bytes')
143-
144-
if (bigIntBuffer.length === 32) {
145-
return bigIntBuffer
146-
}
147-
var newBuffer = Buffer.alloc(32)
148-
bigIntBuffer.copy(newBuffer, newBuffer.length - bigIntBuffer.length, 0, bigIntBuffer.length)
149-
return newBuffer
141+
return this.d.toBuffer(32)
150142
}
151143

152144
ECPair.prototype.sign = function (hash) {

0 commit comments

Comments
 (0)