Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// empty string / null => random new key
if (!str){
return randomKey();
}
// was passed an actual cabal://123abc key or just 64 chars that are all hex
var edKey = str.toLowerCase().replace(/cabal:\/\/|[^\w\d]/ig,'');
var strippedKey = edKey.replace(/[^a-f0-9]/ig,'');
if (edKey.length == 64 && strippedKey.length == 64){
return edKey;
}
// generate one based on string input
return shajs('sha256')
.update('cabal-clonev0:'+cabalCore.protocolVersion+':'+str,'utf8')
.digest('hex');
}