Browse Source

Stealthkey toJSON/fromJSON

patch-2
Ryan X. Charles 10 years ago
parent
commit
5c7149aeab
  1. 15
      lib/expmt/stealthkey.js
  2. 24
      test/stealthkey.js

15
lib/expmt/stealthkey.js

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

24
test/stealthkey.js

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

Loading…
Cancel
Save