@pelican-identity/auth-core 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,175 @@
1
+ type AuthType = "login" | "signup" | "id-verification";
2
+ type PelicanAuthState = "idle" | "initializing" | "awaiting-pair" | "paired" | "awaiting-auth" | "authenticated" | "confirmed" | "error" | "terminated";
3
+ interface PelicanAuthConfig {
4
+ publicKey: string;
5
+ projectId: string;
6
+ authType: AuthType;
7
+ continuousMode?: boolean;
8
+ forceQRCode?: boolean;
9
+ }
10
+ type PelicanAuthEventMap = {
11
+ state: PelicanAuthState;
12
+ qr: string;
13
+ deeplink: string;
14
+ success: IdentityResult;
15
+ error: Error;
16
+ };
17
+ interface ISocketMessage {
18
+ type: "confirmed" | "request-passcode" | "client-terminated" | "phone-terminated" | "pair" | "paired" | "phone-auth-success" | "authenticate" | "confirm" | "register";
19
+ sessionID: string;
20
+ cipher?: string;
21
+ nonce?: string;
22
+ publicKey?: string;
23
+ url?: string;
24
+ authType?: AuthType;
25
+ projectId?: string;
26
+ grantedAttributes?: {
27
+ [key: string]: boolean;
28
+ };
29
+ }
30
+ interface IPhone {
31
+ id: number;
32
+ country: string;
33
+ callingCode: string;
34
+ number: string;
35
+ verifiedAt: string;
36
+ verificationProvider: string;
37
+ }
38
+ interface IEmail {
39
+ id: number;
40
+ value: string;
41
+ verifiedAt: string;
42
+ verificationProvider: string;
43
+ }
44
+ type IdCardTypes = "national id card" | "passport" | "driver's license" | "residence permit";
45
+ interface IKycData {
46
+ id: number;
47
+ status?: "Approved" | "Declined" | "In Review";
48
+ document_type?: IdCardTypes;
49
+ document_number?: string;
50
+ personal_number?: string;
51
+ date_of_birth?: string | Date;
52
+ age?: number;
53
+ expiration_date?: string | Date;
54
+ date_of_issue?: string | Date;
55
+ issuing_state?: string;
56
+ issuing_state_name?: string;
57
+ first_name?: string;
58
+ last_name?: string;
59
+ full_name?: string;
60
+ gender?: string;
61
+ address?: string;
62
+ formatted_address?: string;
63
+ place_of_birth?: string;
64
+ marital_status?: string;
65
+ nationality?: string;
66
+ liveness_percentage?: number;
67
+ face_match_percentage?: number;
68
+ verified_at?: string | Date;
69
+ }
70
+ interface IUserData {
71
+ first_name?: string;
72
+ last_name?: string;
73
+ other_names?: string;
74
+ email?: IEmail;
75
+ phone?: IPhone;
76
+ dob?: string | Date;
77
+ gender?: "male" | "female" | "other";
78
+ country?: string;
79
+ state?: string;
80
+ city?: string;
81
+ address?: string;
82
+ occupation?: string;
83
+ company?: string;
84
+ website?: string;
85
+ }
86
+ interface IdentityResult {
87
+ user_id: string;
88
+ user_data?: IUserData;
89
+ id_verification: IKycData;
90
+ id_downloadurls?: {
91
+ front_of_card?: string;
92
+ back_of_card?: string;
93
+ };
94
+ }
95
+
96
+ type Listener<T> = (payload: T) => void;
97
+ declare class PelicanAuthentication {
98
+ private readonly crypto;
99
+ private readonly stateMachine;
100
+ private transport?;
101
+ private sessionId;
102
+ private sessionKey;
103
+ private visibilityHandler?;
104
+ private listeners;
105
+ private readonly config;
106
+ constructor(config: PelicanAuthConfig);
107
+ on<K extends keyof PelicanAuthEventMap>(event: K, cb: Listener<PelicanAuthEventMap[K]>): () => boolean;
108
+ start(): Promise<void>;
109
+ stop(): void;
110
+ private fetchRelayUrl;
111
+ private emitEntryPoint;
112
+ private handleMessage;
113
+ private handleAuthSuccess;
114
+ private getCachedEntry;
115
+ private attachVisibilityRecovery;
116
+ private detachVisibilityRecovery;
117
+ private terminate;
118
+ private restartIfContinuous;
119
+ private resetSession;
120
+ destroy(): void;
121
+ private emit;
122
+ private fail;
123
+ }
124
+
125
+ interface EncryptedMessage {
126
+ cipher: string;
127
+ nonce: string;
128
+ }
129
+ declare class CryptoService {
130
+ generateSymmetricKey(): string;
131
+ encryptSymmetric({ plaintext, keyString, }: {
132
+ plaintext: string;
133
+ keyString: string;
134
+ }): EncryptedMessage;
135
+ decryptSymmetric({ encrypted, keyString, }: {
136
+ encrypted: EncryptedMessage;
137
+ keyString: string;
138
+ }): string | null;
139
+ }
140
+
141
+ declare class StateMachine {
142
+ private state;
143
+ private listeners;
144
+ get current(): PelicanAuthState;
145
+ transition(next: PelicanAuthState): void;
146
+ subscribe(fn: (s: PelicanAuthState) => void): () => boolean;
147
+ }
148
+
149
+ type TransportHandlers = {
150
+ onOpen?: () => void;
151
+ onMessage?: (msg: ISocketMessage) => void;
152
+ onError?: (err: Event) => void;
153
+ onClose?: (ev: CloseEvent) => void;
154
+ };
155
+ declare class Transport {
156
+ private socket?;
157
+ private handlers;
158
+ constructor(handlers: TransportHandlers);
159
+ connect(url: string): void;
160
+ send(payload: ISocketMessage): void;
161
+ close(): void;
162
+ }
163
+
164
+ interface AuthSession {
165
+ sessionId: string;
166
+ sessionKey: string;
167
+ }
168
+ declare const storeAuthSession: (sessionId: string, sessionKey: string, ttlMs?: number) => void;
169
+ declare const getAuthSession: () => AuthSession | null;
170
+ declare const clearAuthSession: () => void;
171
+ declare const clearAllAuthData: () => void;
172
+
173
+ declare const BASEURL = "http://localhost:8080";
174
+
175
+ export { type AuthSession, type AuthType, BASEURL, CryptoService, type IEmail, type IKycData, type IPhone, type ISocketMessage, type IUserData, type IdCardTypes, type IdentityResult, type PelicanAuthConfig, type PelicanAuthEventMap, type PelicanAuthState, PelicanAuthentication, StateMachine, Transport, clearAllAuthData, clearAuthSession, getAuthSession, storeAuthSession };
@@ -0,0 +1,175 @@
1
+ type AuthType = "login" | "signup" | "id-verification";
2
+ type PelicanAuthState = "idle" | "initializing" | "awaiting-pair" | "paired" | "awaiting-auth" | "authenticated" | "confirmed" | "error" | "terminated";
3
+ interface PelicanAuthConfig {
4
+ publicKey: string;
5
+ projectId: string;
6
+ authType: AuthType;
7
+ continuousMode?: boolean;
8
+ forceQRCode?: boolean;
9
+ }
10
+ type PelicanAuthEventMap = {
11
+ state: PelicanAuthState;
12
+ qr: string;
13
+ deeplink: string;
14
+ success: IdentityResult;
15
+ error: Error;
16
+ };
17
+ interface ISocketMessage {
18
+ type: "confirmed" | "request-passcode" | "client-terminated" | "phone-terminated" | "pair" | "paired" | "phone-auth-success" | "authenticate" | "confirm" | "register";
19
+ sessionID: string;
20
+ cipher?: string;
21
+ nonce?: string;
22
+ publicKey?: string;
23
+ url?: string;
24
+ authType?: AuthType;
25
+ projectId?: string;
26
+ grantedAttributes?: {
27
+ [key: string]: boolean;
28
+ };
29
+ }
30
+ interface IPhone {
31
+ id: number;
32
+ country: string;
33
+ callingCode: string;
34
+ number: string;
35
+ verifiedAt: string;
36
+ verificationProvider: string;
37
+ }
38
+ interface IEmail {
39
+ id: number;
40
+ value: string;
41
+ verifiedAt: string;
42
+ verificationProvider: string;
43
+ }
44
+ type IdCardTypes = "national id card" | "passport" | "driver's license" | "residence permit";
45
+ interface IKycData {
46
+ id: number;
47
+ status?: "Approved" | "Declined" | "In Review";
48
+ document_type?: IdCardTypes;
49
+ document_number?: string;
50
+ personal_number?: string;
51
+ date_of_birth?: string | Date;
52
+ age?: number;
53
+ expiration_date?: string | Date;
54
+ date_of_issue?: string | Date;
55
+ issuing_state?: string;
56
+ issuing_state_name?: string;
57
+ first_name?: string;
58
+ last_name?: string;
59
+ full_name?: string;
60
+ gender?: string;
61
+ address?: string;
62
+ formatted_address?: string;
63
+ place_of_birth?: string;
64
+ marital_status?: string;
65
+ nationality?: string;
66
+ liveness_percentage?: number;
67
+ face_match_percentage?: number;
68
+ verified_at?: string | Date;
69
+ }
70
+ interface IUserData {
71
+ first_name?: string;
72
+ last_name?: string;
73
+ other_names?: string;
74
+ email?: IEmail;
75
+ phone?: IPhone;
76
+ dob?: string | Date;
77
+ gender?: "male" | "female" | "other";
78
+ country?: string;
79
+ state?: string;
80
+ city?: string;
81
+ address?: string;
82
+ occupation?: string;
83
+ company?: string;
84
+ website?: string;
85
+ }
86
+ interface IdentityResult {
87
+ user_id: string;
88
+ user_data?: IUserData;
89
+ id_verification: IKycData;
90
+ id_downloadurls?: {
91
+ front_of_card?: string;
92
+ back_of_card?: string;
93
+ };
94
+ }
95
+
96
+ type Listener<T> = (payload: T) => void;
97
+ declare class PelicanAuthentication {
98
+ private readonly crypto;
99
+ private readonly stateMachine;
100
+ private transport?;
101
+ private sessionId;
102
+ private sessionKey;
103
+ private visibilityHandler?;
104
+ private listeners;
105
+ private readonly config;
106
+ constructor(config: PelicanAuthConfig);
107
+ on<K extends keyof PelicanAuthEventMap>(event: K, cb: Listener<PelicanAuthEventMap[K]>): () => boolean;
108
+ start(): Promise<void>;
109
+ stop(): void;
110
+ private fetchRelayUrl;
111
+ private emitEntryPoint;
112
+ private handleMessage;
113
+ private handleAuthSuccess;
114
+ private getCachedEntry;
115
+ private attachVisibilityRecovery;
116
+ private detachVisibilityRecovery;
117
+ private terminate;
118
+ private restartIfContinuous;
119
+ private resetSession;
120
+ destroy(): void;
121
+ private emit;
122
+ private fail;
123
+ }
124
+
125
+ interface EncryptedMessage {
126
+ cipher: string;
127
+ nonce: string;
128
+ }
129
+ declare class CryptoService {
130
+ generateSymmetricKey(): string;
131
+ encryptSymmetric({ plaintext, keyString, }: {
132
+ plaintext: string;
133
+ keyString: string;
134
+ }): EncryptedMessage;
135
+ decryptSymmetric({ encrypted, keyString, }: {
136
+ encrypted: EncryptedMessage;
137
+ keyString: string;
138
+ }): string | null;
139
+ }
140
+
141
+ declare class StateMachine {
142
+ private state;
143
+ private listeners;
144
+ get current(): PelicanAuthState;
145
+ transition(next: PelicanAuthState): void;
146
+ subscribe(fn: (s: PelicanAuthState) => void): () => boolean;
147
+ }
148
+
149
+ type TransportHandlers = {
150
+ onOpen?: () => void;
151
+ onMessage?: (msg: ISocketMessage) => void;
152
+ onError?: (err: Event) => void;
153
+ onClose?: (ev: CloseEvent) => void;
154
+ };
155
+ declare class Transport {
156
+ private socket?;
157
+ private handlers;
158
+ constructor(handlers: TransportHandlers);
159
+ connect(url: string): void;
160
+ send(payload: ISocketMessage): void;
161
+ close(): void;
162
+ }
163
+
164
+ interface AuthSession {
165
+ sessionId: string;
166
+ sessionKey: string;
167
+ }
168
+ declare const storeAuthSession: (sessionId: string, sessionKey: string, ttlMs?: number) => void;
169
+ declare const getAuthSession: () => AuthSession | null;
170
+ declare const clearAuthSession: () => void;
171
+ declare const clearAllAuthData: () => void;
172
+
173
+ declare const BASEURL = "http://localhost:8080";
174
+
175
+ export { type AuthSession, type AuthType, BASEURL, CryptoService, type IEmail, type IKycData, type IPhone, type ISocketMessage, type IUserData, type IdCardTypes, type IdentityResult, type PelicanAuthConfig, type PelicanAuthEventMap, type PelicanAuthState, PelicanAuthentication, StateMachine, Transport, clearAllAuthData, clearAuthSession, getAuthSession, storeAuthSession };