Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function verifySignature(manifest) {
const sfSequence = '$'
const sfPublicKey = 'q'
const sfSigningPubKey = 's'
// Form manifest
var sequence_buf = new Buffer(4)
sequence_buf.writeUInt32BE(manifest.sequence)
const sequence_bytes = sequence_buf.toJSON().data
var master_public_bytes = addressCodec.decodeNodePublic(manifest.master_public_key)
const signature = manifest.master_signature ? manifest.master_signature : manifest.signature
const signature_bytes = new Buffer(signature, 'hex').toJSON().data
var manifest_data = new Buffer('MAN\0').toJSON().data
manifest_data = manifest_data.concat(new Buffer(sfSequence).toJSON().data,
sequence_bytes,
new Buffer(sfPublicKey).toJSON().data,
[master_public_bytes.length],
master_public_bytes)
if (manifest.ephemeral_public_key) {
const ephemeral_public_bytes = addressCodec.decodeNodePublic(manifest.ephemeral_public_key)
manifest_data = manifest_data.concat(
new Buffer(sfSigningPubKey).toJSON().data,
[ephemeral_public_bytes.length],
ephemeral_public_bytes)
sequence_buf.writeUInt32BE(manifest.sequence)
const sequence_bytes = sequence_buf.toJSON().data
var master_public_bytes = addressCodec.decodeNodePublic(manifest.master_public_key)
const signature = manifest.master_signature ? manifest.master_signature : manifest.signature
const signature_bytes = new Buffer(signature, 'hex').toJSON().data
var manifest_data = new Buffer('MAN\0').toJSON().data
manifest_data = manifest_data.concat(new Buffer(sfSequence).toJSON().data,
sequence_bytes,
new Buffer(sfPublicKey).toJSON().data,
[master_public_bytes.length],
master_public_bytes)
if (manifest.ephemeral_public_key) {
const ephemeral_public_bytes = addressCodec.decodeNodePublic(manifest.ephemeral_public_key)
manifest_data = manifest_data.concat(
new Buffer(sfSigningPubKey).toJSON().data,
[ephemeral_public_bytes.length],
ephemeral_public_bytes)
}
master_public_bytes.shift()
if (!Ed25519.verify(manifest_data, signature_bytes, master_public_bytes)) {
return false;
}
return true;
};