Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

allow to use single-character private key, test added #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/privatekey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions test/privatekey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down