(input: {
demo?: boolean;
rememberSession: boolean;
masterKey: SymmetricKey;
userId: string;
publicKeyring: Uint8Array;
encryptedPrivateKeyring: Uint8Array;
encryptedSymmetricKeyring: Uint8Array;
sessionId: string;
sessionKey: Uint8Array;
personalGroupId: string;
})
| 7 | import { storeClientTokenExpirations } from './tokens'; |
| 8 | |
| 9 | export async function login(input: { |
| 10 | demo?: boolean; |
| 11 | |
| 12 | rememberSession: boolean; |
| 13 | |
| 14 | masterKey: SymmetricKey; |
| 15 | |
| 16 | userId: string; |
| 17 | |
| 18 | publicKeyring: Uint8Array; |
| 19 | encryptedPrivateKeyring: Uint8Array; |
| 20 | encryptedSymmetricKeyring: Uint8Array; |
| 21 | |
| 22 | sessionId: string; |
| 23 | sessionKey: Uint8Array; |
| 24 | |
| 25 | personalGroupId: string; |
| 26 | }) { |
| 27 | if (input.demo) { |
| 28 | internals.localStorage.setItem('demo', 'true'); |
| 29 | } else { |
| 30 | internals.localStorage.removeItem('demo'); |
| 31 | } |
| 32 | |
| 33 | if (input.rememberSession) { |
| 34 | internals.storage = internals.localStorage; |
| 35 | } else { |
| 36 | internals.storage = internals.sessionStorage; |
| 37 | } |
| 38 | |
| 39 | internals.storage.setItem('loggedIn', 'true'); |
| 40 | |
| 41 | internals.storage.setItem('userId', input.userId); |
| 42 | internals.storage.setItem( |
| 43 | 'publicKeyring', |
| 44 | bytesToBase64(input.publicKeyring), |
| 45 | ); |
| 46 | internals.storage.setItem('sessionId', input.sessionId); |
| 47 | internals.storage.setItem('personalGroupId', input.personalGroupId); |
| 48 | |
| 49 | const wrappedSessionKey = wrapSymmetricKey(input.sessionKey); |
| 50 | |
| 51 | internals.storage.setItem( |
| 52 | 'encryptedPrivateKeyring', |
| 53 | bytesToBase64( |
| 54 | createPrivateKeyring(input.encryptedPrivateKeyring) |
| 55 | .unwrapSymmetric(input.masterKey, { |
| 56 | associatedData: { |
| 57 | context: 'UserPrivateKeyring', |
| 58 | userId: input.userId, |
| 59 | }, |
| 60 | }) |
| 61 | .wrapSymmetric(wrappedSessionKey, { |
| 62 | associatedData: { |
| 63 | context: 'SessionUserPrivateKeyring', |
| 64 | userId: input.userId, |
| 65 | }, |
| 66 | }).wrappedValue, |
no test coverage detected