Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('returns a list of public identities (provisional and permanent)', async () => {
const email1 = makeTestEmail();
const email2 = makeTestEmail();
// email1 exists, while email2 is provisional
const priv1 = await fa.getIdentity(email1);
const [pub1, pub2] = await fa.getPublicIdentities([email1, email2]);
const priv2 = await fa.getIdentity(email2);
expectMatchingPublicIdentities(pub1, await getPublicIdentity(priv1.identity));
expectMatchingPublicIdentities(pub2, await getPublicIdentity(priv2.provisionalIdentity));
});
it('returns a list of public identities (provisional and permanent)', async () => {
const email1 = makeTestEmail();
const email2 = makeTestEmail();
// email1 exists, while email2 is provisional
const priv1 = await fa.getIdentity(email1);
const [pub1, pub2] = await fa.getPublicIdentities([email1, email2]);
const priv2 = await fa.getIdentity(email2);
expectMatchingPublicIdentities(pub1, await getPublicIdentity(priv1.identity));
expectMatchingPublicIdentities(pub2, await getPublicIdentity(priv2.provisionalIdentity));
});
createUser(args: { userId: string, parentDevice?: GeneratorDevice, userKeys: tcrypto.SodiumKeyPair, nature: Nature}): CreateUserResult {
const ephemeralKeys = tcrypto.makeSignKeyPair();
const signKeys = tcrypto.makeSignKeyPair();
const encryptionKeys = tcrypto.makeEncryptionKeyPair();
const obfuscatedUserId = obfuscateUserId(this.trustchainId, args.userId);
const delegationBuffer = utils.concatArrays(ephemeralKeys.publicKey, obfuscatedUserId);
let authorPrivateKey = this.appSignKeys.privateKey;
let author = this.root.entry.hash;
if (args.parentDevice) {
// A parent device exists so we are in the add Device case
authorPrivateKey = args.parentDevice.signKeys.privateKey;
author = args.parentDevice.id;
}
let userKeyPair = null;
if (args.nature === NATURE.device_creation_v3) {
userKeyPair = {
public_encryption_key: args.userKeys.publicKey,
encrypted_private_encryption_key: new Uint8Array(SEALED_KEY_SIZE),
};
}
it('encrypt and share with a provisional identity', async () => {
const email = 'alice@tanker-functional-test.io';
const provisionalIdentity = await createProvisionalIdentity(utils.toBase64(args.appHelper.appId), email);
const publicProvisionalIdentity = await getPublicIdentity(provisionalIdentity);
await expect(bobLaptop.encrypt(clearText, { shareWithUsers: [publicProvisionalIdentity] })).to.be.fulfilled;
});
it('share keys with added provisional group members', async () => {
const provisionalEmail = `${uuid.v4()}@tanker-functional-test.io`;
const provisionalIdentity = await createProvisionalIdentity(utils.toBase64(args.appHelper.appId), provisionalEmail);
const provisionalPublicIdentity = await getPublicIdentity(provisionalIdentity);
const groupId = await bobLaptop.createGroup([bobPublicIdentity]);
await bobLaptop.updateGroupMembers(groupId, { usersToAdd: [provisionalPublicIdentity] });
const encrypted = await bobLaptop.encrypt(message, { shareWithGroups: [groupId] });
const verificationCode = await args.appHelper.getVerificationCode(provisionalEmail);
await aliceLaptop.attachProvisionalIdentity(provisionalIdentity);
await aliceLaptop.verifyProvisionalIdentity({ email: provisionalEmail, verificationCode });
expect(await aliceLaptop.decrypt(encrypted)).to.deep.equal(message);
});
});
it('returns the proper public identity before and after the private identity has been used', async () => {
const email = makeTestEmail();
const [publicProvIdentity1] = await fa.getPublicIdentities([email]);
const { identity, provisionalIdentity } = await fa.getIdentity(email);
const [publicProvIdentity2] = await fa.getPublicIdentities([email]);
await fa.setIdentityRegistered(email);
const [publicPermIdentity] = await fa.getPublicIdentities([email]);
expectMatchingPublicIdentities(publicProvIdentity1, await getPublicIdentity(provisionalIdentity));
expectMatchingPublicIdentities(publicProvIdentity2, await getPublicIdentity(provisionalIdentity));
expectMatchingPublicIdentities(publicPermIdentity, await getPublicIdentity(identity));
});
});
it('throws InvalidArgument as appropriate', async () => {
const { users, builder, generator } = await makeTestUsers();
await builder.newUserCreationV3('alice');
await builder.newUserCreationV3('bob');
const aliceIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'alice');
const bobIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'bob');
const casperUnregisteredIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'casper');
const publicIdentities = await toPublicIdentities([aliceIdentity, bobIdentity, casperUnregisteredIdentity]);
await expect(users.getUsers({ publicIdentities })).to.be.rejectedWith(InvalidArgument);
});
});
it('throws InvalidArgument as appropriate', async () => {
const { users, builder, generator } = await makeTestUsers();
await builder.newUserCreationV3('alice');
await builder.newUserCreationV3('bob');
const aliceIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'alice');
const bobIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'bob');
const casperUnregisteredIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'casper');
const publicIdentities = await toPublicIdentities([aliceIdentity, bobIdentity, casperUnregisteredIdentity]);
await expect(users.getUsers({ publicIdentities })).to.be.rejectedWith(InvalidArgument);
});
});
it('throws when having configured a non existing app', async () => {
const nonExistentB64AppSecret = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==';
const publicKey = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=';
const publicKeyBytes = utils.fromBase64(publicKey);
const nonExistentB64AppId = utils.toBase64(utils.generateAppID(publicKeyBytes));
const userId = 'bob';
bobIdentity = await createIdentity(nonExistentB64AppId, nonExistentB64AppSecret, userId);
bobLaptop = args.makeTanker(nonExistentB64AppId);
await expect(bobLaptop.start(bobIdentity)).to.be.rejectedWith(errors.NetworkError, 'trustchain_not_found');
});
it('throws InvalidArgument as appropriate', async () => {
const { users, builder, generator } = await makeTestUsers();
await builder.newUserCreationV3('alice');
await builder.newUserCreationV3('bob');
const aliceIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'alice');
const bobIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'bob');
const casperUnregisteredIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'casper');
const publicIdentities = await toPublicIdentities([aliceIdentity, bobIdentity, casperUnregisteredIdentity]);
await expect(users.getUsers({ publicIdentities })).to.be.rejectedWith(InvalidArgument);
});
});