Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
switch (this.type) {
case keyTypes.RSA: {
this.n = base16.decode(json.n);
this.e = base16.decode(json.e);
this.nonce = base16.decode(json.nonce, 32);
break;
}
case keyTypes.GOO: {
this.C1 = base16.decode(json.C1);
break;
}
case keyTypes.P256: {
this.point = base16.decode(json.point, 33);
this.nonce = base16.decode(json.nonce, 32);
break;
}
case keyTypes.ED25519: {
this.point = base16.decode(json.point, 32);
this.nonce = base16.decode(json.nonce, 32);
break;
}
case keyTypes.ADDRESS: {
assert((json.version & 0xff) === json.version);
assert(Number.isSafeInteger(json.value) && json.value >= 0);
assert(typeof json.sponsor === 'boolean');
this.version = json.version;
this.address = base16.decode(json.address);
for (const hash of json.proof)
this.proof.push(base16.decode(hash, 32));
this.subindex = json.subindex;
for (const hash of json.subproof)
this.subproof.push(base16.decode(hash, 32));
if (json.key)
this.key = AirdropKey.fromJSON(json.key).encode();
this.version = json.version;
this.address = base16.decode(json.address);
this.fee = json.fee;
this.signature = base16.decode(json.signature);
return this;
}
}
for (const hash of json.proof)
this.proof.push(base16.decode(hash, 32));
this.subindex = json.subindex;
for (const hash of json.subproof)
this.subproof.push(base16.decode(hash, 32));
if (json.key)
this.key = AirdropKey.fromJSON(json.key).encode();
this.version = json.version;
this.address = base16.decode(json.address);
this.fee = json.fee;
this.signature = base16.decode(json.signature);
return this;
}
}
fromJSON(json) {
assert(json && typeof json === 'object');
assert(typeof json.type === 'string');
assert(keyTypes.hasOwnProperty(json.type));
this.type = keyTypes[json.type];
switch (this.type) {
case keyTypes.RSA: {
this.n = base16.decode(json.n);
this.e = base16.decode(json.e);
this.nonce = base16.decode(json.nonce, 32);
break;
}
case keyTypes.GOO: {
this.C1 = base16.decode(json.C1);
break;
}
case keyTypes.P256: {
this.point = base16.decode(json.point, 33);
this.nonce = base16.decode(json.nonce, 32);
break;
}
case keyTypes.ED25519: {
this.nonce = base16.decode(json.nonce, 32);
break;
}
case keyTypes.ED25519: {
this.point = base16.decode(json.point, 32);
this.nonce = base16.decode(json.nonce, 32);
break;
}
case keyTypes.ADDRESS: {
assert((json.version & 0xff) === json.version);
assert(Number.isSafeInteger(json.value) && json.value >= 0);
assert(typeof json.sponsor === 'boolean');
this.version = json.version;
this.address = base16.decode(json.address);
this.value = json.value;
this.sponsor = json.sponsor;
break;
}
default: {
throw new Error('Unknown key type.');
}
}
return this;
}
assert(Array.isArray(json.subproof));
assert(json.key == null || (json.key && typeof json.key === 'object'));
assert((json.version & 0xff) === json.version);
assert(typeof json.address === 'string');
assert(Number.isSafeInteger(json.fee) && json.fee >= 0);
assert(typeof json.signature === 'string');
this.index = json.index;
for (const hash of json.proof)
this.proof.push(base16.decode(hash, 32));
this.subindex = json.subindex;
for (const hash of json.subproof)
this.subproof.push(base16.decode(hash, 32));
if (json.key)
this.key = AirdropKey.fromJSON(json.key).encode();
this.version = json.version;
this.address = base16.decode(json.address);
this.fee = json.fee;
this.signature = base16.decode(json.signature);
return this;
}
}
fromJSON(json) {
assert(json && typeof json === 'object');
assert(typeof json.type === 'string');
assert(keyTypes.hasOwnProperty(json.type));
this.type = keyTypes[json.type];
switch (this.type) {
case keyTypes.RSA: {
this.n = base16.decode(json.n);
this.e = base16.decode(json.e);
this.nonce = base16.decode(json.nonce, 32);
break;
}
case keyTypes.GOO: {
this.C1 = base16.decode(json.C1);
break;
}
case keyTypes.P256: {
this.point = base16.decode(json.point, 33);
this.nonce = base16.decode(json.nonce, 32);
break;
}
case keyTypes.ED25519: {
this.point = base16.decode(json.point, 32);
this.index = json.index;
for (const hash of json.proof)
this.proof.push(base16.decode(hash, 32));
this.subindex = json.subindex;
for (const hash of json.subproof)
this.subproof.push(base16.decode(hash, 32));
if (json.key)
this.key = AirdropKey.fromJSON(json.key).encode();
this.version = json.version;
this.address = base16.decode(json.address);
this.fee = json.fee;
this.signature = base16.decode(json.signature);
return this;
}
}
break;
}
case keyTypes.GOO: {
this.C1 = base16.decode(json.C1);
break;
}
case keyTypes.P256: {
this.point = base16.decode(json.point, 33);
this.nonce = base16.decode(json.nonce, 32);
break;
}
case keyTypes.ED25519: {
this.point = base16.decode(json.point, 32);
this.nonce = base16.decode(json.nonce, 32);
break;
}
case keyTypes.ADDRESS: {
assert((json.version & 0xff) === json.version);
assert(Number.isSafeInteger(json.value) && json.value >= 0);
assert(typeof json.sponsor === 'boolean');
this.version = json.version;
this.address = base16.decode(json.address);
this.value = json.value;
this.sponsor = json.sponsor;
break;
}
default: {
this.index = json.index;
for (const hash of json.proof)
this.proof.push(base16.decode(hash, 32));
this.subindex = json.subindex;
for (const hash of json.subproof)
this.subproof.push(base16.decode(hash, 32));
if (json.key)
this.key = AirdropKey.fromJSON(json.key).encode();
this.version = json.version;
this.address = base16.decode(json.address);
this.fee = json.fee;
this.signature = base16.decode(json.signature);
return this;
}
}