MCPcopy Create free account
hub / github.com/DeepNotesApp/DeepNotes / generateRandomUserKeys

Function generateRandomUserKeys

apps/client/src/code/crypto.ts:69–103  ·  view source on GitHub ↗
(
  userId: string,
  masterKey: SymmetricKey,
)

Source from the content-addressed store, hash-verified

67 };
68}
69export 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
105export async function generateGroupValues(input: {
106 userKeyPair: KeyPair;

Callers 1

getRegistrationValuesFunction · 0.90

Calls 5

createKeyringFunction · 0.90
createPrivateKeyringFunction · 0.90
wrapKeyPairFunction · 0.90
createSymmetricKeyringFunction · 0.90
wrapSymmetricMethod · 0.65

Tested by

no test coverage detected