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

Function login

apps/client/src/code/auth/login.ts:9–102  ·  view source on GitHub ↗
(input: {
  demo?: boolean;

  rememberSession: boolean;

  masterKey: SymmetricKey;

  userId: string;

  publicKeyring: Uint8Array;
  encryptedPrivateKeyring: Uint8Array;
  encryptedSymmetricKeyring: Uint8Array;

  sessionId: string;
  sessionKey: Uint8Array;

  personalGroupId: string;
})

Source from the content-addressed store, hash-verified

7import { storeClientTokenExpirations } from './tokens';
8
9export 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,

Callers 1

enterDemoFunction · 0.90

Calls 9

bytesToBase64Function · 0.90
wrapSymmetricKeyFunction · 0.90
createPrivateKeyringFunction · 0.90
createSymmetricKeyringFunction · 0.90
multiModePathFunction · 0.90
routeFunction · 0.85
wrapSymmetricMethod · 0.65
unwrapSymmetricMethod · 0.65

Tested by

no test coverage detected