Generate and set user's private and public key pair
This commit is contained in:
parent
580ce23c17
commit
a9e0821db0
4 changed files with 16 additions and 2 deletions
|
@ -57,11 +57,16 @@ export default function Generate() {
|
|||
await cryptoWorker.fromString(passphrase), kekSalt);
|
||||
const kekHash = await cryptoWorker.hash(kek);
|
||||
const encryptedKeyAttributes = await cryptoWorker.encrypt(key, kek);
|
||||
const keyPair = await cryptoWorker.generateKeyPair();
|
||||
const encryptedKeyPairAttributes = await cryptoWorker.encrypt(keyPair.privateKey, kek);
|
||||
const keyAttributes = {
|
||||
kekSalt: await cryptoWorker.toB64(kekSalt),
|
||||
kekHash,
|
||||
kekHash: kekHash,
|
||||
encryptedKey: await cryptoWorker.toB64(encryptedKeyAttributes.encryptedData),
|
||||
keyDecryptionNonce: await cryptoWorker.toB64(encryptedKeyAttributes.nonce),
|
||||
publicKey: await cryptoWorker.toB64(keyPair.publicKey),
|
||||
encryptedSecretKey: await cryptoWorker.toB64(encryptedKeyPairAttributes.encryptedData),
|
||||
secretKeyDecryptionNonce: await cryptoWorker.toB64(encryptedKeyPairAttributes.nonce)
|
||||
};
|
||||
await putKeyAttributes(token, keyAttributes);
|
||||
setData(LS_KEYS.KEY_ATTRIBUTES, keyAttributes);
|
||||
|
|
|
@ -13,7 +13,7 @@ export const verifyOtt = (email: string, ott: string) => {
|
|||
}
|
||||
|
||||
export const putKeyAttributes = (token: string, keyAttributes: keyAttributes) => {
|
||||
return HTTPService.put(`${ENDPOINT}/users/key-attributes`, keyAttributes, null, {
|
||||
return HTTPService.put(`${ENDPOINT}/users/attributes`, { 'keyAttributes': keyAttributes, 'name': 'Dummy Name' }, null, {
|
||||
'X-Auth-Token': token,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -87,6 +87,11 @@ export async function generateSaltToDeriveKey() {
|
|||
return sodium.randombytes_buf(sodium.crypto_pwhash_SALTBYTES);
|
||||
}
|
||||
|
||||
export async function generateKeyPair() {
|
||||
await sodium.ready;
|
||||
return sodium.crypto_box_keypair();
|
||||
}
|
||||
|
||||
export async function fromB64(input: string) {
|
||||
await sodium.ready;
|
||||
return sodium.from_base64(input, sodium.base64_variants.ORIGINAL);
|
||||
|
|
|
@ -53,6 +53,10 @@ export class Crypto {
|
|||
return libsodium.deriveKey(passphrase, salt);
|
||||
}
|
||||
|
||||
async generateKeyPair() {
|
||||
return libsodium.generateKeyPair();
|
||||
}
|
||||
|
||||
async fromString(string) {
|
||||
return libsodium.fromString(string);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue