Check private key length in getPublic
This commit is contained in:
parent
f8c682da07
commit
513d880c64
|
@ -5,11 +5,16 @@
|
|||
"use strict";
|
||||
|
||||
require("es6-promise").polyfill();
|
||||
var assert = require("assert");
|
||||
var EC = require("elliptic").ec;
|
||||
|
||||
var ec = new EC("secp256k1");
|
||||
|
||||
exports.getPublic = function(privateKey) {
|
||||
// `elliptic` doesn't have such checkings so we do it ourself. We
|
||||
// should always ensure that library user doesn't try to do something
|
||||
// dumb.
|
||||
assert(privateKey.length === 32, "Bad private key");
|
||||
// XXX(Kagami): `elliptic.utils.encode` returns array for every
|
||||
// encoding except `hex`.
|
||||
return new Buffer(ec.keyPair(privateKey).getPublic("arr"));
|
||||
|
|
Loading…
Reference in New Issue
Block a user