Skip to content

Commit

Permalink
should generate from hex added
Browse files Browse the repository at this point in the history
  • Loading branch information
maraoz committed Mar 19, 2014
1 parent d84dc65 commit 53eb98b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
11 changes: 5 additions & 6 deletions WalletKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var imports = require('soop').imports();

var coinUtil = require('./util/util');
var timeUtil = require('./util/time');
var Key= require('./Key');
var Key = require('./Key');
var PrivateKey = require('./PrivateKey');
var Address = require('./Address');

Expand Down Expand Up @@ -37,11 +37,10 @@ WalletKey.prototype.storeObj = function() {
WalletKey.prototype.fromObj = function(obj) {
this.created = obj.created;
this.privKey = new Key();
if (obj.priv.length==64) {
this.privKey.private = new Buffer(obj.priv,'hex');
this.privKey.compressed = true;
}
else {
if (obj.priv.length == 64) {
this.privKey.private = new Buffer(obj.priv, 'hex');
this.privKey.compressed = typeof obj.compressed === 'undefined'? true: obj.compressed;
} else {
var priv = new PrivateKey(obj.priv);
this.privKey.private = new Buffer(priv.payload());
this.privKey.compressed = priv.compressed();
Expand Down
17 changes: 13 additions & 4 deletions test/test.misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ describe('Miscelaneous stuff', function() {
if (meta.isPrivkey) {
describe('base58 private key valid ' + b58, function() {
var k;
var opts = {
network: network
};
before(function() {
k = new WalletKey({
network: network
});
k = new WalletKey(opts);
});
it('parse', function() {
it('should generate correctly from WIF', function() {
k.fromObj({
priv: b58
});
Expand All @@ -95,6 +96,14 @@ describe('Miscelaneous stuff', function() {
it('should not be an Address', function() {
new Address(b58).isValid().should.equal(false);
});
it('should generate correctly from hex', function() {
var k2 = new WalletKey(opts);
k2.fromObj({
priv: hexPayload,
compressed: meta.isCompressed
});
k2.storeObj().priv.should.equal(b58);
});
});
} else {
describe('base58 address valid ' + b58, function() {
Expand Down

0 comments on commit 53eb98b

Please sign in to comment.