Browse Source

should generate from hex added

patch-2
Manuel Araoz 11 years ago
parent
commit
53eb98babc
  1. 11
      WalletKey.js
  2. 17
      test/test.misc.js

11
WalletKey.js

@ -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');
@ -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();

17
test/test.misc.js

@ -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
});
@ -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() {

Loading…
Cancel
Save