diff --git a/lib/privatekey.js b/lib/privatekey.js index f820cae09..141abd1b6 100644 --- a/lib/privatekey.js +++ b/lib/privatekey.js @@ -103,7 +103,7 @@ PrivateKey.prototype._classifyArguments = function(data, network) { info.network = Networks.get(data); } else if (typeof(data) === 'string'){ if (JSUtil.isHexa(data)) { - info.bn = new BN(new Buffer(data, 'hex')); + info.bn = new BN(data, 'hex'); } else { info = PrivateKey._transformWIF(data, network); } diff --git a/test/privatekey.js b/test/privatekey.js index db45f6080..4bd034ab0 100644 --- a/test/privatekey.js +++ b/test/privatekey.js @@ -153,6 +153,13 @@ describe('PrivateKey', function() { privkey.publicKey.toString().should.equal(pubhex); }); + it('can be instantiated from a single-character hex string', function() { + var privhex = '1'; + var pubhex = '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'; + var privkey = new PrivateKey(privhex); + privkey.publicKey.toString().should.equal(pubhex); + }); + it('should not be able to instantiate because of unrecognized data', function() { expect(function() { return new PrivateKey(new Error());