Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public verifySignature(signer: string, data: Buffer | string, signature: string): boolean {
// TODO remove dummy keys
const publicKey: PublicKey = this.nodePublicKeys.get(signer) || this.nodePublicKeys.get("dummy");
logger.debug(`Got public key ${base58.encode(publicKey)} for ${signer}`);
if (!publicKey) {
return false;
}
const dataBuf: Buffer = (typeof(data) === "string") ? new Buffer(data, "utf8") : data;
const digest: Buffer = crypto.createHash("SHA256").update(dataBuf).digest();
return ec.verify(digest, base58.decode(signature), publicKey);
}
function getIpfsHashFromBytes32(bytes32Hex) {
// Add our default ipfs values for first 2 bytes:
// function:0x12=sha2, size:0x20=256 bits
// and cut off leading "0x"
const hashHex = '1220' + bytes32Hex.slice(2)
const hashBytes = Buffer.from(hashHex, 'hex')
const hashStr = bs58.encode(hashBytes)
return hashStr
}
function bytes32ToIPFSHash(hash_hex) {
//console.log('bytes32ToIPFSHash starts with hash_buffer', hash_hex.replace(/^0x/, ''));
var buf = new Buffer(hash_hex.replace(/^0x/, '1220'), 'hex')
return bs58.encode(buf)
}
toPublicKeyString(address_prefix = 'STM') {
if(this.pubdata) return address_prefix + this.pubdata
const pub_buf = this.toBuffer();
const checksum = hash.ripemd160(pub_buf);
const addy = Buffer.concat([pub_buf, checksum.slice(0, 4)]);
this.pubdata = base58.encode(addy)
return address_prefix + this.pubdata;
}
toPublicKeyString(address_prefix = config.get('address_prefix')) {
if(this.pubdata) return address_prefix + this.pubdata
const pub_buf = this.toBuffer();
const checksum = hash.ripemd160(pub_buf);
const addy = Buffer.concat([pub_buf, checksum.slice(0, 4)]);
this.pubdata = base58.encode(addy)
return address_prefix + this.pubdata;
}
toPublicKeyString(address_prefix = config.address_prefix) {
if(this.pubdata) return address_prefix + this.pubdata
const pub_buf = this.toBuffer();
const checksum = hash.ripemd160(pub_buf);
const addy = Buffer.concat([pub_buf, checksum.slice(0, 4)]);
this.pubdata = base58.encode(addy)
return address_prefix + this.pubdata;
}
toAddressString(address_prefix = ChainConfig.address_prefix) {
let pub_buf = this.toBuffer();
let pub_sha = sha512(pub_buf);
let addy = ripemd160(pub_sha);
let checksum = ripemd160(addy);
addy = Buffer.concat([addy, checksum.slice(0, 4)]);
return address_prefix + encode(addy);
}
toAddressString(address_prefix = 'STM') {
var pub_buf = this.toBuffer();
var pub_sha = hash.sha512(pub_buf);
var addy = hash.ripemd160(pub_sha);
var checksum = hash.ripemd160(addy);
addy = Buffer.concat([addy, checksum.slice(0, 4)]);
return address_prefix + base58.encode(addy);
}
module.exports = function encrypt(password, str) {
var aes256 = crypto.createCipher('aes-256-cbc', password);
var a = aes256.update(str, 'utf8');
var b = aes256.final();
var buf = new Buffer(a.length + b.length);
a.copy(buf, 0);
b.copy(buf, a.length);
return base58.encode(buf);
};
return function() {
var buf = crypto.randomBytes(randomBytes);
return base58.encode(buf);
}
};