Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
web3,
trustbase,
inquirer
}) {
const username = argv._.length > 1 ? argv._[1] : (await inquirer.prompt(usernamePrompt)).username
if (username === '') {
ora().fail('Invalid username')
process.exit(1)
}
const usernameHash = web3.utils.sha3(username)
let {
publicKey,
privateKey
} = sodium.crypto_sign_keypair()
publicKey = sodium.to_hex(publicKey)
privateKey = sodium.to_hex(privateKey)
const identityPath = path.resolve(os.homedir(), `.trustbase/idents/${usernameHash}.json`)
if ((await fs.exists(identityPath))) {
ora().info(`Found identity for '${username}' locally`)
process.exit(0)
}
const records = (await fs.exists(RECORD_PATH)) ? (await fs.readJSON(RECORD_PATH)) : {}
if (records[username]) {
await checkRegister({
argv: {
_: ['check-register', username]
},
web3,
}
const done = ret(cb);
let payload, isk;
[ payload ] = iparse(message);
[ sk ] = cparse(sk);
switch (sk && Buffer.byteLength(sk)) {
case sodium.crypto_sign_SECRETKEYBYTES:
isk = sk;
break;
case sodium.crypto_sign_SEEDBYTES:
isk = sodium.crypto_sign_seed_keypair(sk).privateKey;
break;
default:
isk = sodium.crypto_sign_keypair().privateKey;
sk = sodium.crypto_sign_ed25519_sk_to_seed(isk);
}
let signature;
try {
signature = sodium.crypto_sign_detached(payload, isk);
} catch(ex) {
return done(new Error('Libsodium error: ' + ex));
}
return done(null, convert({
alg: 'ed25519',
sk: sk,
payload: payload,
signature: signature
}));
return sodium.ready.then(() => {
return (self.protocol() instanceof V1)
? self.inject(extcrypto.keygen(), (err) => { return done(err); })
: self.inject(Buffer.from(sodium.crypto_sign_keypair().privateKey), (err) => { return done(err); });
});
}
TransactionHelper.prototype.getProofs = function (provingServiceUri, callbackfn) {
if (!this._anchor) throw new Error('Must call setAnchor() before getProofs()')
var keyPair = sodium.crypto_sign_keypair()
this.joinSplitPubKey = Buffer.from(keyPair.publicKey)
this._joinSplitPrivKey = Buffer.from(keyPair.privateKey)
for (var i = 0; i < this._jsouts.length; i += 2) {
var inputs = [
JSInput.dummy(),
JSInput.dummy()
]
var outputs = [
this._jsouts[i],
this._jsouts[i + 1] || JSOutput.dummy()
]
var value = outputs.reduce(function (sum, output) { return sum + output.value }, 0)
this.jss.push(JSDescription.withWitness(inputs, outputs, this.joinSplitPubKey, value, 0, this._anchor))