Stealthkey toJSON/fromJSON

This commit is contained in:
Ryan X. Charles 2014-09-22 14:45:41 -07:00
parent d6e3266179
commit 5c7149aeab
2 changed files with 39 additions and 0 deletions

View File

@ -27,6 +27,21 @@ Stealthkey.prototype.set = function(obj) {
return this;
};
Stealthkey.prototype.fromJSON = function(json) {
this.set({
payloadKeypair: Keypair().fromJSON(json.payloadKeypair),
scanKeypair: Keypair().fromJSON(json.scanKeypair)
});
return this;
};
Stealthkey.prototype.toJSON = function() {
return {
payloadKeypair: this.payloadKeypair.toJSON(),
scanKeypair: this.scanKeypair.toJSON()
};
};
Stealthkey.prototype.fromRandom = function() {
this.payloadKeypair = Keypair().fromRandom();
this.scanKeypair = Keypair().fromRandom();

View File

@ -49,6 +49,30 @@ describe('Stealthkey', function() {
});
describe('#fromJSON', function() {
it('should make a stealthkey from this JSON', function() {
var sk = Stealthkey().fromJSON({
payloadKeypair: stealthkey.payloadKeypair.toJSON(),
scanKeypair: stealthkey.scanKeypair.toJSON()
});
sk.payloadKeypair.toString().should.equal(stealthkey.payloadKeypair.toString());
sk.scanKeypair.toString().should.equal(stealthkey.scanKeypair.toString());
});
});
describe('#toJSON', function() {
it('should convert this stealthkey to json', function() {
var json = stealthkey.toJSON()
var json2 = Stealthkey().fromJSON(json).toJSON();
json.payloadKeypair.privkey.should.equal(json2.payloadKeypair.privkey);
json.scanKeypair.privkey.should.equal(json2.scanKeypair.privkey);
});
});
describe('#fromRandom', function() {
it('should create a new stealthkey from random', function() {