Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
recvActTwo(actTwo) {
assert(Buffer.isBuffer(actTwo));
if (actTwo.length !== ACT_TWO_SIZE)
throw new Error('Act two: bad size.');
if (actTwo[0] !== VERSION)
throw new Error('Act two: bad version.');
const e = actTwo.slice(1, 34);
const p = actTwo.slice(34);
if (!secp256k1.publicKeyVerify(e))
throw new Error('Act two: bad key.');
// e
this.remoteEphemeral = e;
this.mixHash(this.remoteEphemeral);
// ee
const s = ecdh(this.remoteEphemeral, this.localEphemeral);
this.mixKey(s);
if (!this.decryptHash(EMPTY, p))
throw new Error('Act two: bad tag.');
return this;
}
recvActOne(actOne) {
assert(Buffer.isBuffer(actOne));
if (actOne.length !== ACT_ONE_SIZE)
throw new Error('Act one: bad size.');
if (actOne[0] !== VERSION)
throw new Error('Act one: bad version.');
const e = actOne.slice(1, 34);
const p = actOne.slice(34);
if (!secp256k1.publicKeyVerify(e))
throw new Error('Act one: bad key.');
// e
this.remoteEphemeral = e;
this.mixHash(this.remoteEphemeral);
// es
const s = ecdh(this.remoteEphemeral, this.localStatic);
this.mixKey(s);
if (!this.decryptHash(EMPTY, p))
throw new Error('Act one: bad tag.');
return this;
}
this.logger.info(
'Repurposing peer for loader (%s).',
peer.hostname());
this.setLoader(peer);
return;
}
const addr = this.getHost();
if (!addr)
return;
if (!secp256k1.publicKeyVerify(addr.key)) {
this.logger.info('Removing addr - invalid pubkey (%s).', addr.hostname);
this.hosts.remove(addr.hostname);
return;
}
const peer = this.createOutbound(addr);
this.logger.info('Adding loader peer (%s).', peer.hostname());
this.peers.add(peer);
this.setLoader(peer);
}
static isValidPubkey(pubkey) {
if (typeof pubkey !== 'string')
return false;
if (pubkey.length !== 66)
return false;
const buf = Buffer.from(pubkey, 'hex');
return secp256k1.publicKeyVerify(buf);
}
fromOptions(options) {
if (!options)
return this;
assert(wcommon.isName(options.name), 'Bad cosigner name.');
assert(HDPublicKey.isHDPublicKey(options.key), 'Account key is required.');
assert(Buffer.isBuffer(options.authPubKey), 'authPubKey must be a buffer.');
assert(options.authPubKey.length === 33, 'Bad authPubKey length.');
assert(secp256k1.publicKeyVerify(options.authPubKey), 'Bad authPubKey.');
assert(Buffer.isBuffer(options.joinSignature),
'joinSignature must be a buffer.');
assert(options.joinSignature.length === 65, 'Bad joinSignature length.');
this.name = options.name;
this.key = options.key;
this.authPubKey = options.authPubKey;
this.joinSignature = options.joinSignature;
if (options.id != null) {
assert((options.id & 0xff) === options.id, 'ID must be uint8.');
this.id = options.id;
}
if (options.tokenDepth != null) {
fromJSON(json, details, network) {
assert((json.id & 0xff) === json.id, 'id must be an u8.');
assert(wcommon.isName(json.name), 'Bad cosigner name.');
assert(typeof json.authPubKey === 'string', 'Bad authPubKey.');
assert(typeof json.joinSignature === 'string', 'Bad joinSignature.');
assert(typeof json.accountKey === 'string', 'Bad accountKey.');
const authPubKey = Buffer.from(json.authPubKey, 'hex');
const joinSignature = Buffer.from(json.joinSignature, 'hex');
const key = HDPublicKey.fromBase58(json.accountKey, network);
assert(authPubKey.length === 33, 'Bad authPubKey length.');
assert(secp256k1.publicKeyVerify(authPubKey), 'Bad authPubKey.');
assert(joinSignature.length === 65, 'Bad joinSignature length.');
this.id = json.id;
this.name = json.name;
this.authPubKey = authPubKey;
this.joinSignature = joinSignature;
this.key = key;
if (!details)
return this;
assert((json.tokenDepth >>> 0) === json.tokenDepth,
'tokenDepth must be an u32.');
this.tokenDepth = json.tokenDepth;
assert((json.purpose >>> 0) === json.purpose);
const keys = valid.array(1, []);
const m = valid.u32(0, 0);
const n = keys.length;
if (m < 1 || n < m || n > 16)
throw new RPCError(errs.INVALID_PARAMETER, 'Invalid m and n values.');
const items = new Validator(keys);
for (let i = 0; i < keys.length; i++) {
const key = items.buf(i);
if (!key)
throw new RPCError(errs.TYPE_ERROR, 'Invalid key.');
if (!secp256k1.publicKeyVerify(key) || key.length !== 33)
throw new RPCError(errs.INVALID_ADDRESS_OR_KEY, 'Invalid key.');
keys[i] = key;
}
const script = Script.fromMultisig(m, n, keys);
if (script.getSize() > consensus.MAX_SCRIPT_PUSH) {
throw new RPCError(errs.VERIFY_ERROR,
'Redeem script exceeds size limit.');
}
const addr = Address.fromScripthash(script.sha3());
return {
address: addr.toString(this.network),