Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 _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 _claimProvisionalIdentity(provisionalIdentity: SecretProvisionalIdentity, tankerKeys: TankerProvisionalKeys): Promise {
await this._localUserManager.updateLocalUser();
const appProvisionalUserPrivateSignatureKey = utils.fromBase64(provisionalIdentity.private_signature_key);
const appProvisionalUserPrivateEncryptionKey = utils.fromBase64(provisionalIdentity.private_encryption_key);
const provisionalUserKeys = {
...tankerKeys,
appEncryptionKeyPair: tcrypto.getEncryptionKeyPairFromPrivateKey(appProvisionalUserPrivateEncryptionKey),
appSignatureKeyPair: tcrypto.getSignatureKeyPairFromPrivateKey(appProvisionalUserPrivateSignatureKey),
};
const { userId, deviceId, currentUserKey } = this._localUserManager.localUser;
const { payload, nature } = makeProvisionalIdentityClaim(userId, deviceId, currentUserKey.publicKey, provisionalUserKeys);
await this._client.send('push block', this._localUserManager.localUser.makeBlock(payload, nature), true);
}
}
_localUserKeysFromPrivateKey = (encryptedPrivateKey: Uint8Array, encryptionKeyPair: tcrypto.SodiumKeyPair, existingLocalUserKeys: ?LocalUserKeys): LocalUserKeys => {
const privateKey = tcrypto.sealDecrypt(encryptedPrivateKey, encryptionKeyPair);
const keyPair = tcrypto.getEncryptionKeyPairFromPrivateKey(privateKey);
const b64PublicKey = utils.toBase64(keyPair.publicKey);
const res = {};
res[b64PublicKey] = keyPair;
if (existingLocalUserKeys) {
return {
userKeys: { ...existingLocalUserKeys.userKeys, ...res },
currentUserKey: existingLocalUserKeys.currentUserKey,
};
}
return {
userKeys: res,
currentUserKey: keyPair,
};
}
export const decryptUserKeyForGhostDevice = (ghostDevice: GhostDevice, encryptedUserKey: EncryptedUserKeyForGhostDevice) => {
const ghostDeviceEncryptionKeyPair = tcrypto.getEncryptionKeyPairFromPrivateKey(ghostDevice.privateEncryptionKey);
const decryptedUserPrivateKey = tcrypto.sealDecrypt(
encryptedUserKey.encryptedPrivateUserKey,
ghostDeviceEncryptionKeyPair
);
return tcrypto.getEncryptionKeyPairFromPrivateKey(decryptedUserPrivateKey);
};