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

Commit

Permalink
ECPair: simplify getPublicKeyBuffer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OttoAllmendinger committed Jan 6, 2020
1 parent 288f662 commit fdf2d22
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/ecpair.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,7 @@ ECPair.prototype.getPublicKeyBuffer = function () {
ECPair.prototype.getPrivateKeyBuffer = function () {
if (!this.d) throw new Error('Missing private key')

var bigIntBuffer = this.d.toBuffer()
if (bigIntBuffer.length > 32) throw new Error('Private key size exceeds 32 bytes')

if (bigIntBuffer.length === 32) {
return bigIntBuffer
}
var newBuffer = Buffer.alloc(32)
bigIntBuffer.copy(newBuffer, newBuffer.length - bigIntBuffer.length, 0, bigIntBuffer.length)
return newBuffer
return this.d.toBuffer(32)
}

ECPair.prototype.sign = function (hash) {
Expand Down

0 comments on commit fdf2d22

Please sign in to comment.