Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function delete_private_key (name) {
// FIXME: poor man's secure erase
for (var i = 0; i < 5; ++i) {
seed = nacl.randomBytes(nacl.sign.seedLength);
localStorage.setItem(name, util.btoa(seed));
localStorage.setItem(name, '');
localStorage.setItem(name, null);
}
}
describe("resource.delete", () => {
let seed = Math.floor(Math.random() * 99999);
let ctx: Context.aliceBobWithDeviceAndGroupCtx;
let aliceChildSecret = nacl.randomBytes(128);
let aliceChild: Context.userAndSessionCtx;
let resourceA: Utils.Resource, resourceB: Utils.Resource;
let resourceC: Utils.Resource, resourceD: Utils.Resource;
let randomResourceId: number;
let randomResourceIdLong: Long;
before(async () => {
let init = await Context.init();
ctx = await Context.aliceBobWithDeviceAndGroup(init);
aliceChild = await Context.userAndSession(init, "aliceChild");
let resourceADataPeps = await new ResourceAPI(aliceChild.session).create(
"test kind",
{ text: "payload A" },
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
identities = [];
promises = [];
options = options ? options : {};
name = options.name == null ? "id" : options.name;
for (i = 0; i < n; i++) {
secret = nacl.randomBytes(128);
identity_1 = generateIdentityFields(init, __assign({}, options, { name: "" + name + i }));
promises.push(create(identity_1, secret));
identities.push(__assign({}, identity_1, { created: new Date(), admin: false, active: true }));
}
return [4 /*yield*/, Promise.all(promises)];
case 1:
_a.sent();
return [2 /*return*/, { identities: identities }];
}
});
});
private generateMasterSalt() {
if (this.masterSalt == null || this.masterSalt.length == 0) {
this.masterSalt = nacl.randomBytes(16);
}
}
async generateSyncEncryptionKey(): Promise {
this.key = ab2str(nacl.randomBytes(nacl.secretbox.keyLength))
await this._storeKey()
}
Create = function (bk, algo, language) {
let secret = Nacl.randomBytes(16);
let keyPair;
switch (bk) {
case "iris":
keyPair = IrisnetKeyPair.Create(secret, algo);
}
if (keyPair) {
let seed = Wordcodec.BytesToWords(keyPair.secret, language);
let phrase = seed.toString().replace(/,/g, " ");
return {
"address": keyPair.address,
"phrase": phrase,
"privateKey": keyPair.privateKey,
"publicKey": keyPair.publicKey
};
}
};
constructor(arg) {
if (!arg.clientKey) {
if (arg.nonce) {
this.buffer = arg.nonce;
} else {
this.buffer = new Buffer(nacl.randomBytes(nacl.box.nonceLength));
}
} else {
var b2 = blake2.createHash('blake2b', { digestLength: 24 });
if (arg.nonce) {
b2.update(arg.nonce.getBuffer());
}
b2.update(arg.clientKey);
b2.update(arg.serverKey);
this.buffer = b2.digest();
}
}
createRandomBytes = function(num) {
return nacl.randomBytes(num);
},
getPrivateSeedBuffer = function(obj) {
function generateSalt(): string {
return naclutil.encodeBase64(nacl.randomBytes(SALT_BYTES));
}