Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private writeConfig() {
// Generate Ed25519 Keys
if (!this.publicKey || !this.privateKey) {
const seed = crypto.randomBytes(32);
const keyPair = Ed25519.MakeKeypair(seed);
this.publicKey = keyPair.publicKey;
this.privateKey = keyPair.privateKey;
}
FS.writeFileSync(this.configDir, JSON.stringify({
CCN: this.CCN,
pairings: this.pairings,
publicKey: this.publicKey.toString('hex'),
privateKey: this.privateKey.toString('hex'),
UUIDMap: this.UUIDMap
}), 'utf8');
}
}, function (err) {
if (err) {
return cb(err[0].message);
}
var hash = crypto.createHash('sha256').update(body.secret, 'utf8').digest();
var keypair = ed.MakeKeypair(hash);
if (body.publicKey) {
if (keypair.publicKey.toString('hex') != body.publicKey) {
return cb("Invalid passphrase");
}
}
var query = {};
var followingAddress = body.following.substring(1, body.following.length);
var isAddress = /^[0-9]+[L|l]$/g;
if (isAddress.test(followingAddress)) {
query.address = followingAddress;
} else {
query.username = followingAddress;
}
throw new Error(validateErrors[0].message);
}
var transaction = await this.runtime.transaction.getUnconfirmedTransaction(body.transactionId);
if (!transaction) {
throw new Error("Transaction not found");
}
if (body.publicKey) {
if (keypair.publicKey.toString('hex') != body.publicKey) {
throw new Error("Invalid passphrase");
}
}
var hash = crypto.createHash('sha256').update(body.secret, 'utf8').digest();
var keypair = ed.MakeKeypair(hash);
var sign = await this.runtime.transaction.multisign(keypair, transaction);
if (transaction.type == AssetTypes.MULTISIGNATURE) {
if ((transaction.asset.multisignature.keysgroup.indexOf(`+${keypair.publicKey.toString('hex')}`) == -1) ||
(transaction.signatures && transaction.signatures.indexOf(sign.toString('hex')) != -1)) {
throw new Error("Permission to sign transaction denied");
}
setImmediate(async() => {
try
{
await this.runtime.socketio.emit('multisignatures/singature/change', {});
}
catch (err)
{
function AccessoryInfo(displayName,username, pincode) {
if (!(this instanceof AccessoryInfo)) {
return new AccessoryInfo(displayName,username);
}
this.displayName = displayName;
this.username = username;
this.pincode = pincode;
var seed = crypto.randomBytes(32);
var keyPair = ed25519.MakeKeypair(seed);
this.keyPair = {
signSk: keyPair.privateKey,
signPk: keyPair.publicKey,
paired: false
};
}
Config.prototype.writeConfig = function () {
if (!this.publicKey || !this.privateKey) {
var seed = crypto.randomBytes(32);
var keyPair = Ed25519.MakeKeypair(seed);
this.publicKey = keyPair.publicKey;
this.privateKey = keyPair.privateKey;
}
FS.writeFileSync(this.configDir, JSON.stringify({
CCN: this.CCN,
pairings: this.pairings,
publicKey: this.publicKey.toString('hex'),
privateKey: this.privateKey.toString('hex'),
UUIDMap: this.UUIDMap
}), 'utf8');
};
Config.prototype.setServer = function (server) {
Config.prototype.writeConfig = function () {
if (!this.publicKey || !this.privateKey) {
var seed = crypto.randomBytes(32);
var keyPair = Ed25519.MakeKeypair(seed);
this.publicKey = keyPair.publicKey;
this.privateKey = keyPair.privateKey;
}
FS.writeFileSync(this.configDir, JSON.stringify({
CCN: this.CCN,
pairings: this.pairings,
publicKey: this.publicKey.toString('hex'),
privateKey: this.privateKey.toString('hex'),
UUIDMap: this.UUIDMap
}), 'utf8');
};
Config.prototype.setServer = function (server) {
getM5Request() {
const seed = crypto.randomBytes(32);
const keyPair = ed25519.MakeKeypair(seed);
this._rangerPairingID = Buffer.from(uuid());
this._rangerLTSK = keyPair.privateKey;
this._rangerLTPK = keyPair.publicKey;
this._srpSharedSecret = this._srp.computeK();
const controllerSalt = Buffer.from("Pair-Setup-Controller-Sign-Salt");
const controllerInfo = Buffer.from("Pair-Setup-Controller-Sign-Info");
const iOSDeviceX = hkdf("sha512", controllerSalt, this._srpSharedSecret, controllerInfo, 32);
const iOSDeviceInfo = Buffer.concat([iOSDeviceX, this._rangerPairingID, this._rangerLTPK]);
const iOSDeviceSignature = ed25519.Sign(iOSDeviceInfo, this._rangerLTSK);
let subtlv = {};
subtlv[TLVType.Identifier] = this._rangerPairingID;
subtlv[TLVType.PublicKey] = this._rangerLTPK;
if (requester.publicKey == account.publicKey) {
return cb("Incorrect requester");
}
if (!following) {
return cb("Username not found");
}
followingAddress = body.following[0] + following.address;
var secondKeypair = null;
if (requester.secondSignature) {
var secondHash = crypto.createHash('sha256').update(body.secondSecret, 'utf8').digest();
secondKeypair = ed.MakeKeypair(secondHash);
}
try {
var transaction = library.logic.transaction.create({
type: TransactionTypes.FOLLOW,
sender: account,
keypair: keypair,
secondKeypair: secondKeypair,
contactAddress: followingAddress,
requester: keypair
});
} catch (e) {
return cb(e.toString());
}
modules.transactions.receiveTransactions([transaction], cb);
});
if (err) {
return cb(err.toString());
}
if (!account || !account.publicKey) {
return cb("Account not found");
}
if (account.secondSignature && !body.secondSecret) {
return cb("Invalid second passphrase");
}
var secondKeypair = null;
if (account.secondSignature) {
var secondHash = crypto.createHash('sha256').update(body.secondSecret, 'utf8').digest();
secondKeypair = ed.MakeKeypair(secondHash);
}
try {
var transaction = library.base.transaction.create({
type: TransactionTypes.VOTE,
votes: body.delegates,
sender: account,
keypair: keypair,
secondKeypair: secondKeypair
});
} catch (e) {
return cb(e.toString());
}
modules.transactions.receiveTransactions([transaction], cb);
});
}
if (err) {
return cb(err.toString());
}
if (!account || !account.publicKey) {
return cb("Account not found");
}
if (account.secondSignature && !body.secondSecret) {
return cb("Invalid second passphrase");
}
var secondKeypair = null;
if (account.secondSignature) {
var secondHash = crypto.createHash('sha256').update(body.secondSecret, 'utf8').digest();
secondKeypair = ed.MakeKeypair(secondHash);
}
try {
var transaction = library.base.transaction.create({
type: TransactionTypes.MULTI,
sender: account,
keypair: keypair,
secondKeypair: secondKeypair,
min: body.min,
keysgroup: body.keysgroup,
lifetime: body.lifetime
});
} catch (e) {
return cb(e.toString());
}