( userId: string, masterKey: SymmetricKey, )
| 67 | }; |
| 68 | } |
| 69 | export function generateRandomUserKeys( |
| 70 | userId: string, |
| 71 | masterKey: SymmetricKey, |
| 72 | ) { |
| 73 | const rawKeyPair = sodium.crypto_box_keypair(); |
| 74 | |
| 75 | const publicKeyring = createKeyring(rawKeyPair.publicKey); |
| 76 | const privateKeyring = createPrivateKeyring(rawKeyPair.privateKey); |
| 77 | |
| 78 | const keyPair = wrapKeyPair(publicKeyring, privateKeyring); |
| 79 | |
| 80 | const symmetricKeyring = createSymmetricKeyring(); |
| 81 | |
| 82 | return { |
| 83 | // Asymmetric keys |
| 84 | |
| 85 | keyPair, |
| 86 | encryptedPrivateKeyring: privateKeyring.wrapSymmetric(masterKey, { |
| 87 | associatedData: { |
| 88 | context: 'UserPrivateKeyring', |
| 89 | userId, |
| 90 | }, |
| 91 | }), |
| 92 | |
| 93 | // Symmetric key |
| 94 | |
| 95 | symmetricKeyring, |
| 96 | encryptedSymmetricKeyring: symmetricKeyring.wrapSymmetric(masterKey, { |
| 97 | associatedData: { |
| 98 | context: 'UserSymmetricKeyring', |
| 99 | userId, |
| 100 | }, |
| 101 | }), |
| 102 | }; |
| 103 | } |
| 104 | |
| 105 | export async function generateGroupValues(input: { |
| 106 | userKeyPair: KeyPair; |
no test coverage detected