Skip to content

Commit ab96720

Browse files
feat(auth): LIT-4211 - Add initial auth package
- Define localStorage storage plugin w/ tests
1 parent 23958f6 commit ab96720

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

packages/auth/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { getAuthManager } from './lib/auth-manager';
2+
import { localStorage } from './lib/storage';
3+
4+
import type { LitAuthStorageProvider } from './lib/storage/types';
5+
import type { LitAuthData } from './lib/types';
6+
7+
export type { LitAuthStorageProvider, LitAuthData };
8+
9+
export const storagePlugins = { localStorage };
10+
11+
export { getAuthManager };
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { nacl } from '@lit-protocol/nacl';
2+
import { SessionKeyPair } from '@lit-protocol/types';
3+
import { uint8arrayToString } from '@lit-protocol/uint8arrays';
4+
5+
import type { LitAuthStorageProvider } from './storage/types';
6+
import type { LitAuthData } from '@lit-protocol/auth';
7+
8+
interface LitAuthManagerConfig {
9+
storage: LitAuthStorageProvider;
10+
}
11+
12+
function generateSessionKeyPair(): SessionKeyPair {
13+
const keyPair = nacl.sign.keyPair();
14+
15+
return {
16+
publicKey: uint8arrayToString(keyPair.publicKey, 'base16'),
17+
secretKey: uint8arrayToString(keyPair.secretKey, 'base16'),
18+
};
19+
}
20+
21+
async function tryGetCachedAuthData() {
22+
// Use `storage` to see if there is cached auth data
23+
// If error thrown trying to get it, error to caller or ??
24+
}
25+
26+
async function tryGetAuthMethodFromAuthenticator() {
27+
// Use authenticator `getAuthMethod()` method to get a new auth method
28+
}
29+
30+
function validateAuthData(authData: LitAuthData) {
31+
// Validate auth data is not expired, and is well-formed
32+
}
33+
34+
async function signSessionKey({ storage }: LitAuthManagerConfig) {
35+
// Use LitNodeClient to signSessionKey with AuthData
36+
}
37+
38+
export function getAuthManager({ storage }: LitAuthManagerConfig) {
39+
return {
40+
getAuthContext() {},
41+
};
42+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// AuthProviders live in this dir tree

0 commit comments

Comments
 (0)