(input: {
userKeyPair: KeyPair;
isPublic: boolean;
password?: string;
})
| 103 | } |
| 104 | |
| 105 | export 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, |
no test coverage detected