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

Function generateGroupValues

apps/client/src/code/crypto.ts:105–192  ·  view source on GitHub ↗
(input: {
  userKeyPair: KeyPair;
  isPublic: boolean;
  password?: string;
})

Source from the content-addressed store, hash-verified

103}
104
105export async function generateGroupValues(input: {
106 userKeyPair: KeyPair;
107 isPublic: boolean;
108 password?: string;
109}) {
110 const groupId = nanoid();
111
112 const accessKeyring = createSymmetricKeyring();
113 const internalKeyring = createSymmetricKeyring();
114 const contentKeyring = createSymmetricKeyring();
115
116 const rawKeyPair = sodium.crypto_box_keypair();
117
118 const publicKeyring = createKeyring(rawKeyPair.publicKey);
119 const privateKeyring = createPrivateKeyring(rawKeyPair.privateKey);
120
121 const keyPair = wrapKeyPair(publicKeyring, privateKeyring);
122
123 // Group keyring
124
125 let finalAccessKeyring = accessKeyring;
126
127 if (!input.isPublic) {
128 finalAccessKeyring = finalAccessKeyring.wrapAsymmetric(
129 input.userKeyPair,
130 input.userKeyPair.publicKey,
131 );
132 }
133
134 // Internal keyring
135
136 const encryptedInternalKeyring = internalKeyring.wrapAsymmetric(
137 input.userKeyPair,
138 input.userKeyPair.publicKey,
139 );
140
141 // Content keyring
142
143 let encryptedContentKeyring = contentKeyring;
144
145 let passwordValues;
146
147 if (input.password != null) {
148 passwordValues = await computeGroupPasswordValues(groupId, input.password);
149
150 encryptedContentKeyring = encryptedContentKeyring.wrapSymmetric(
151 passwordValues.passwordKey,
152 {
153 associatedData: {
154 context: 'GroupContentKeyringPasswordProtection',
155 groupId,
156 },
157 },
158 );
159 }
160
161 encryptedContentKeyring = encryptedContentKeyring.wrapSymmetric(
162 accessKeyring,

Callers 3

getRegistrationValuesFunction · 0.90
createPageFunction · 0.90
step1Function · 0.90

Calls 7

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

Tested by

no test coverage detected