Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const senderSignatureKeyPair = tcrypto.makeSignKeyPair();
const unlockKeyMessage = await createUnlockKeyMessage({
trustchainId,
deviceId: senderDeviceId,
email,
password,
unlockKey,
userSecret,
privateSigKey: senderSignatureKeyPair.privateKey,
});
expect(unlockKeyMessage.trustchainId).to.deep.equal(trustchainId);
expect(unlockKeyMessage.deviceId).to.deep.equal(senderDeviceId);
expect(unlockKeyMessage.claims.email).to.deep.equal(utils.fromString(email));
expect(unlockKeyMessage.claims.password).to.deep.equal(generichash(utils.fromString(password)));
//$FlowIKnow
expect(utils.toString(EncryptorV2.decrypt(userSecret, unlockKeyMessage.claims.unlockKey))).to.deep.equal(unlockKey);
const signedBuffer = getSignData(unlockKeyMessage);
expect(tcrypto.verifySignature(signedBuffer, unlockKeyMessage.signature, senderSignatureKeyPair.publicKey)).to.equal(true);
});
});
export const formatVerificationRequest = (verification: RemoteVerification, localUser: LocalUser): VerificationRequest => {
if (verification.email) {
return {
hashed_email: generichash(utils.fromString(verification.email)),
encrypted_email: encryptionV2.compatEncrypt(localUser.userSecret, utils.fromString(verification.email)),
verification_code: verification.verificationCode,
};
}
if (verification.passphrase) {
return {
hashed_passphrase: generichash(utils.fromString(verification.passphrase)),
};
}
if (verification.oidcIdToken) {
return {
oidc_id_token: verification.oidcIdToken,
};
}
throw new InternalError('Assertion error: invalid remote verification in formatVerificationRequest');
};
function checksumByte(secretRand: Uint8Array, userIdBytes: Uint8Array): number {
const hashSize = 16;
const input = new Uint8Array(USER_SECRET_SIZE - 1 + userIdBytes.length);
input.set(secretRand);
input.set(userIdBytes, USER_SECRET_SIZE - 1);
return generichash(input, hashSize)[0];
}
email,
password,
unlockKey,
userSecret,
privateSigKey
}: CreateUnlockKeyMessageParams): Promise {
const message = {
trustchainId,
deviceId,
claims: {},
signature: new Uint8Array(0)
};
if (email)
message.claims.email = utils.fromString(email);
if (password)
message.claims.password = generichash(utils.fromString(password));
if (unlockKey)
message.claims.unlockKey = EncryptorV2.encrypt(userSecret, utils.fromString(unlockKey));
const buff = getSignData(message);
message.signature = tcrypto.sign(buff, privateSigKey);
return message;
}
export function hashBlock(block: Block | BlockNoSignature): Uint8Array {
const fullPayload = utils.concatArrays(natureToVarint(block.nature), block.author, block.payload);
return generichash(fullPayload);
}
async _getProvisionalIdentityKeys(email: string): Promise {
let result;
try {
result = await this._client.send('get verified provisional identity', b64RequestObject({
verification_method: {
type: 'email',
hashed_email: generichash(utils.fromString(email)),
},
}));
} catch (e) {
if (e instanceof VerificationNeeded) {
return null;
}
throw e;
}
return tankerProvisionalKeys(result);
}