Stealthkey toJSON/fromJSON
This commit is contained in:
parent
d6e3266179
commit
5c7149aeab
|
@ -27,6 +27,21 @@ Stealthkey.prototype.set = function(obj) {
|
||||||
return this;
|
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() {
|
Stealthkey.prototype.fromRandom = function() {
|
||||||
this.payloadKeypair = Keypair().fromRandom();
|
this.payloadKeypair = Keypair().fromRandom();
|
||||||
this.scanKeypair = Keypair().fromRandom();
|
this.scanKeypair = Keypair().fromRandom();
|
||||||
|
|
|
@ -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() {
|
describe('#fromRandom', function() {
|
||||||
|
|
||||||
it('should create a new stealthkey from random', function() {
|
it('should create a new stealthkey from random', function() {
|
||||||
|
|
Loading…
Reference in New Issue