Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const block = blockGenerator.createUserGroup(
groupSignatureKeyPair,
groupEncryptionKeyPair,
[user],
[]
);
const entry = getGroupEntryFromBlock(block);
const record: UserGroupCreationRecordV2 = (entry: any);
expect(record.public_signature_key).to.deep.equal(groupSignatureKeyPair.publicKey);
expect(record.public_encryption_key).to.deep.equal(groupEncryptionKeyPair.publicKey);
expect(tcrypto.sealDecrypt(record.encrypted_group_private_signature_key, groupEncryptionKeyPair)).to.deep.equal(groupSignatureKeyPair.privateKey);
expect(record.encrypted_group_private_encryption_keys_for_users.length).to.deep.equal(1);
expect(record.encrypted_group_private_encryption_keys_for_users[0].public_user_encryption_key).to.deep.equal(userKeys.publicKey);
expect(tcrypto.sealDecrypt(record.encrypted_group_private_encryption_keys_for_users[0].encrypted_group_private_encryption_key, userKeys)).to.deep.equal(groupEncryptionKeyPair.privateKey);
const signData = getUserGroupCreationBlockSignDataV2(record);
expect(tcrypto.verifySignature(signData, record.self_signature, groupSignatureKeyPair.publicKey)).to.equal(true);
});
makeUserCreation = async (userId: Uint8Array): Promise => {
const deviceSignatureKeyPair = tcrypto.makeSignKeyPair();
const deviceEncryptionKeyPair = tcrypto.makeEncryptionKeyPair();
const delegationToken = createDelegationToken(userId, this._trustchainKeys.privateKey);
const ghostDeviceKeys = generateGhostDeviceKeys();
const { userCreationBlock, ghostDevice } = generateUserCreation(this._trustchainId, userId, deviceEncryptionKeyPair, deviceSignatureKeyPair, ghostDeviceKeys, delegationToken);
const unverifiedDeviceCreation = ((userEntryFromBlock(userCreationBlock): any): DeviceCreationEntry);
const privateUserKey = tcrypto.sealDecrypt(unverifiedDeviceCreation.user_key_pair.encrypted_private_encryption_key, ghostDeviceKeys.encryptionKeyPair);
const testDevice: TestDevice = {
id: unverifiedDeviceCreation.hash,
signKeys: ghostDeviceKeys.signatureKeyPair,
encryptionKeys: ghostDeviceKeys.encryptionKeyPair,
revoked: false,
isGhost: true,
};
const identity = await createIdentity(utils.toBase64(this._trustchainId), utils.toBase64(this._trustchainKeys.privateKey), utils.toBase64(userId));
const publicIdentity = await getPublicIdentity(identity);
const testUser: TestUser = {
id: userId,
userKeys: [{
publicKey: unverifiedDeviceCreation.user_key_pair.public_encryption_key,
privateKey: privateUserKey,
async decryptResourceKeyPublishedToProvisionalIdentity(keyPublishEntry: KeyPublish): Promise {
const keys = this._localUser.findProvisionalUserKey(keyPublishEntry.recipient);
if (!keys)
throw new Error('Provisional user key not found');
const d1 = tcrypto.sealDecrypt(keyPublishEntry.key, keys.tankerEncryptionKeyPair);
const d2 = tcrypto.sealDecrypt(d1, keys.appEncryptionKeyPair);
return d2;
}
async _decryptPrivateProvisionalKeys(recipientUserPublicKey: Uint8Array, encryptedPrivateProvisionalKeys: Uint8Array): Promise {
const userKeyPair = await this._localUserManager.findUserKey(recipientUserPublicKey);
const provisionalUserPrivateKeys = tcrypto.sealDecrypt(encryptedPrivateProvisionalKeys, userKeyPair);
const appEncryptionKeyPair = tcrypto.getEncryptionKeyPairFromPrivateKey(new Uint8Array(provisionalUserPrivateKeys.subarray(0, tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE)));
const tankerEncryptionKeyPair = tcrypto.getEncryptionKeyPairFromPrivateKey(new Uint8Array(provisionalUserPrivateKeys.subarray(tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE)));
return { appEncryptionKeyPair, tankerEncryptionKeyPair };
}
async decryptResourceKeyPublishedToUser(keyPublishEntry: KeyPublish): Promise {
const userKey = this._localUser.findUserKey(keyPublishEntry.recipient);
if (!userKey)
throw new Error('User key not found');
return tcrypto.sealDecrypt(keyPublishEntry.key, userKey);
}
function provisionalUnseal(ciphertext: Uint8Array, keys: ProvisionalUserKeyPairs): Uint8Array {
const intermediate = tcrypto.sealDecrypt(ciphertext, keys.tankerEncryptionKeyPair);
return tcrypto.sealDecrypt(intermediate, keys.appEncryptionKeyPair);
}
function provisionalUnseal(ciphertext: Uint8Array, keys: ProvisionalUserKeyPairs): Uint8Array {
const intermediate = tcrypto.sealDecrypt(ciphertext, keys.tankerEncryptionKeyPair);
return tcrypto.sealDecrypt(intermediate, keys.appEncryptionKeyPair);
}
function provisionalUnseal(ciphertext: Uint8Array, keys: ProvisionalUserKeyPairs): Uint8Array {
const intermediate = tcrypto.sealDecrypt(ciphertext, keys.tankerEncryptionKeyPair);
return tcrypto.sealDecrypt(intermediate, keys.appEncryptionKeyPair);
}