@pelican-identity/auth-core 1.2.7 → 1.2.9

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,31 @@
1
+ import { PelicanAuthConfig, PelicanAuthEventMap } from "../types/types";
2
+ type Listener<T> = (payload: T) => void;
3
+ export declare class PelicanAuthentication {
4
+ private readonly crypto;
5
+ private readonly stateMachine;
6
+ private transport?;
7
+ private sessionId;
8
+ private sessionKey;
9
+ private visibilityHandler?;
10
+ private listeners;
11
+ private readonly config;
12
+ constructor(config: PelicanAuthConfig);
13
+ on<K extends keyof PelicanAuthEventMap>(event: K, cb: Listener<PelicanAuthEventMap[K]>): () => boolean;
14
+ start(): Promise<void>;
15
+ stop(): void;
16
+ private fetchRelayUrl;
17
+ private emitEntryPoint;
18
+ private handleMessage;
19
+ private handleAuthSuccess;
20
+ private getCachedEntry;
21
+ private attachVisibilityRecovery;
22
+ private detachVisibilityRecovery;
23
+ private terminate;
24
+ private restartIfContinuous;
25
+ private resetSession;
26
+ destroy(): void;
27
+ private emit;
28
+ private fail;
29
+ }
30
+ export {};
31
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/engine/engine.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EAGpB,MAAM,gBAAgB,CAAC;AAYxB,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;AAMxC,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IAEnD,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,UAAU,CAAuB;IAEzC,OAAO,CAAC,iBAAiB,CAAC,CAAa;IAEvC,OAAO,CAAC,SAAS,CAEV;IAEP,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8B;gBAEzC,MAAM,EAAE,iBAAiB;IAsBrC,EAAE,CAAC,CAAC,SAAS,MAAM,mBAAmB,EACpC,KAAK,EAAE,CAAC,EACR,EAAE,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAWhC,KAAK;IAqCX,IAAI;YAOU,aAAa;YAkBb,cAAc;IAwC5B,OAAO,CAAC,aAAa;IAiCrB,OAAO,CAAC,iBAAiB;YAwCX,cAAc;IA4B5B,OAAO,CAAC,wBAAwB;IAYhC,OAAO,CAAC,wBAAwB;IAQhC,OAAO,CAAC,SAAS;IAqBjB,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,YAAY;IAMpB,OAAO;IAMP,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,IAAI;CAIb"}
@@ -0,0 +1,238 @@
1
+ import CryptoService from "../utilities/crypto";
2
+ import QRCode from "qrcode";
3
+ import { storeAuthSession, getAuthSession, clearAuthSession, } from "../utilities/storage";
4
+ import { StateMachine } from "../utilities/stateMachine";
5
+ import { Transport } from "../utilities/transport";
6
+ import { BASEURL } from "../constants";
7
+ export class PelicanAuthentication {
8
+ constructor(config) {
9
+ this.crypto = new CryptoService();
10
+ this.stateMachine = new StateMachine();
11
+ this.sessionId = "";
12
+ this.sessionKey = null;
13
+ this.listeners = {};
14
+ if (!config.publicKey)
15
+ throw new Error("Missing publicKey");
16
+ if (!config.projectId)
17
+ throw new Error("Missing projectId");
18
+ if (!config.authType)
19
+ throw new Error("Missing authType");
20
+ this.config = {
21
+ continuousMode: false,
22
+ forceQRCode: false,
23
+ ...config,
24
+ };
25
+ this.stateMachine.subscribe((s) => this.emit("state", s));
26
+ this.attachVisibilityRecovery();
27
+ }
28
+ on(event, cb) {
29
+ var _a;
30
+ (_a = this.listeners)[event] ?? (_a[event] = new Set());
31
+ this.listeners[event].add(cb);
32
+ return () => this.listeners[event].delete(cb);
33
+ }
34
+ async start() {
35
+ if (this.stateMachine.current !== "idle")
36
+ return;
37
+ this.resetSession();
38
+ clearAuthSession();
39
+ this.stateMachine.transition("initializing");
40
+ try {
41
+ const relay = await this.fetchRelayUrl();
42
+ this.sessionKey = this.crypto.generateSymmetricKey();
43
+ this.sessionId = crypto.randomUUID() + crypto.randomUUID();
44
+ this.transport = new Transport({
45
+ onOpen: () => {
46
+ this.transport.send({
47
+ type: "register",
48
+ sessionID: this.sessionId,
49
+ ...this.config,
50
+ });
51
+ this.stateMachine.transition("awaiting-pair");
52
+ },
53
+ onMessage: (msg) => this.handleMessage(msg),
54
+ onError: () => this.fail(new Error("WebSocket connection failed")),
55
+ });
56
+ this.transport.connect(relay);
57
+ await this.emitEntryPoint();
58
+ }
59
+ catch (err) {
60
+ this.fail(err instanceof Error ? err : new Error("Start failed"));
61
+ }
62
+ }
63
+ stop() {
64
+ this.terminate(false);
65
+ }
66
+ async fetchRelayUrl() {
67
+ const { publicKey, projectId, authType } = this.config;
68
+ const res = await fetch(`${BASEURL}/relay?public_key=${publicKey}&auth_type=${authType}&project_id=${projectId}`);
69
+ if (!res.ok) {
70
+ const error = await res.text();
71
+ throw new Error(error);
72
+ }
73
+ const json = await res.json();
74
+ return json.relay_url;
75
+ }
76
+ async emitEntryPoint() {
77
+ const payload = {
78
+ sessionID: this.sessionId,
79
+ sessionKey: this.sessionKey,
80
+ publicKey: this.config.publicKey,
81
+ authType: this.config.authType,
82
+ projectId: this.config.projectId,
83
+ url: window.location.href,
84
+ };
85
+ const shouldUseQR = this.config.forceQRCode ||
86
+ !/Android|iPhone|iPad/i.test(navigator.userAgent);
87
+ if (!shouldUseQR && this.sessionKey) {
88
+ storeAuthSession(this.sessionId, this.sessionKey, 5 * 60000);
89
+ this.emit("deeplink", `pelicanvault://auth/deep-link?sessionID=${encodeURIComponent(this.sessionId)}&sessionKey=${encodeURIComponent(this.sessionKey)}&publicKey=${encodeURIComponent(this.config.publicKey)}&authType=${this.config.authType}&projectId=${encodeURIComponent(this.config.projectId)}&url=${encodeURIComponent(window.location.href)}`);
90
+ }
91
+ else {
92
+ const qr = await QRCode.toDataURL(JSON.stringify(payload), {
93
+ type: "image/png",
94
+ scale: 3,
95
+ color: { light: "#ffffff", dark: "#424242ff" },
96
+ });
97
+ this.emit("qr", qr);
98
+ }
99
+ }
100
+ handleMessage(msg) {
101
+ switch (msg.type) {
102
+ case "paired":
103
+ this.stateMachine.transition("paired");
104
+ this.transport.send({
105
+ type: "authenticate",
106
+ sessionID: this.sessionId,
107
+ ...this.config,
108
+ url: window.location.href,
109
+ });
110
+ return;
111
+ case "phone-auth-success":
112
+ this.handleAuthSuccess(msg);
113
+ return;
114
+ case "phone-terminated":
115
+ this.fail(new Error("Authenticating device terminated the connection"));
116
+ this.restartIfContinuous();
117
+ return;
118
+ case "confirmed":
119
+ this.terminate(true);
120
+ this.restartIfContinuous();
121
+ return;
122
+ }
123
+ }
124
+ handleAuthSuccess(msg) {
125
+ if (!this.sessionKey || !msg.cipher || !msg.nonce) {
126
+ this.fail(new Error("Invalid authentication payload"));
127
+ this.restartIfContinuous();
128
+ return;
129
+ }
130
+ try {
131
+ const decrypted = this.crypto.decryptSymmetric({
132
+ encrypted: { cipher: msg.cipher, nonce: msg.nonce },
133
+ keyString: this.sessionKey,
134
+ });
135
+ if (!decrypted) {
136
+ this.fail(new Error("Invalid authentication data"));
137
+ this.restartIfContinuous();
138
+ return;
139
+ }
140
+ const result = JSON.parse(decrypted);
141
+ this.emit("success", result);
142
+ this.stateMachine.transition("authenticated");
143
+ this.transport?.send({
144
+ type: "confirm",
145
+ sessionID: this.sessionId,
146
+ });
147
+ }
148
+ catch {
149
+ this.fail(new Error("Failed to decrypt authentication data"));
150
+ this.restartIfContinuous();
151
+ }
152
+ }
153
+ async getCachedEntry(cached) {
154
+ try {
155
+ const res = await fetch(`${BASEURL}/session?session_id=${cached.sessionId}`);
156
+ if (!res.ok)
157
+ throw new Error("Invalid session");
158
+ const data = await res.json();
159
+ const decrypted = this.crypto.decryptSymmetric({
160
+ encrypted: { cipher: data.cipher, nonce: data.nonce },
161
+ keyString: cached.sessionKey,
162
+ });
163
+ if (!decrypted) {
164
+ this.fail(new Error("Invalid session data"));
165
+ this.restartIfContinuous();
166
+ return;
167
+ }
168
+ const result = JSON.parse(decrypted);
169
+ this.emit("success", result);
170
+ clearAuthSession();
171
+ }
172
+ catch {
173
+ this.fail(new Error("Session recovery failed"));
174
+ this.restartIfContinuous();
175
+ }
176
+ }
177
+ attachVisibilityRecovery() {
178
+ this.visibilityHandler = async () => {
179
+ if (document.visibilityState !== "visible")
180
+ return;
181
+ const cached = getAuthSession();
182
+ if (!cached)
183
+ return;
184
+ await this.getCachedEntry(cached);
185
+ };
186
+ document.addEventListener("visibilitychange", this.visibilityHandler);
187
+ }
188
+ detachVisibilityRecovery() {
189
+ if (this.visibilityHandler) {
190
+ document.removeEventListener("visibilitychange", this.visibilityHandler);
191
+ this.visibilityHandler = undefined;
192
+ }
193
+ }
194
+ terminate(success) {
195
+ if (!success) {
196
+ this.transport?.send({
197
+ type: "client-terminated",
198
+ sessionID: this.sessionId,
199
+ projectId: this.config.projectId,
200
+ publicKey: this.config.publicKey,
201
+ authType: this.config.authType,
202
+ });
203
+ }
204
+ this.transport?.close();
205
+ clearAuthSession();
206
+ this.resetSession();
207
+ if (!this.config.continuousMode) {
208
+ this.detachVisibilityRecovery();
209
+ }
210
+ this.stateMachine.transition(success ? "confirmed" : "idle");
211
+ }
212
+ restartIfContinuous() {
213
+ this.stateMachine.transition("idle");
214
+ this.transport?.close();
215
+ if (!this.config.continuousMode)
216
+ return;
217
+ setTimeout(() => {
218
+ this.start();
219
+ }, 150);
220
+ }
221
+ resetSession() {
222
+ this.sessionId = "";
223
+ this.sessionKey = null;
224
+ }
225
+ destroy() {
226
+ this.detachVisibilityRecovery();
227
+ this.transport?.close();
228
+ this.listeners = {};
229
+ }
230
+ emit(event, payload) {
231
+ this.listeners[event]?.forEach((cb) => cb(payload));
232
+ }
233
+ fail(err) {
234
+ this.emit("error", err);
235
+ this.stateMachine.transition("error");
236
+ }
237
+ }
238
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/engine/engine.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAChD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAO5B,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,GAEjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAQvC,MAAM,OAAO,qBAAqB;IAgBhC,YAAY,MAAyB;QAfpB,WAAM,GAAG,IAAI,aAAa,EAAE,CAAC;QAC7B,iBAAY,GAAG,IAAI,YAAY,EAAE,CAAC;QAG3C,cAAS,GAAG,EAAE,CAAC;QACf,eAAU,GAAkB,IAAI,CAAC;QAIjC,cAAS,GAEb,EAAE,CAAC;QAKL,IAAI,CAAC,MAAM,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAE1D,IAAI,CAAC,MAAM,GAAG;YACZ,cAAc,EAAE,KAAK;YACrB,WAAW,EAAE,KAAK;YAClB,GAAG,MAAM;SACV,CAAC;QAGF,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;QAC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ANGED
@@ -182,6 +182,6 @@ declare const getAuthSession: () => AuthSession | null;
182
182
  declare const clearAuthSession: () => void;
183
183
  declare const clearAllAuthData: () => void;
184
184
 
185
- declare const BASEURL = "http://192.168.1.2:8080";
185
+ declare const BASEURL = "https://identityapi.pelicanidentity.com";
186
186
 
187
187
  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, type PelicanWebAuthProps, StateMachine, Transport, clearAllAuthData, clearAuthSession, getAuthSession, storeAuthSession };
package/dist/index.d.ts CHANGED
@@ -1,187 +1,8 @@
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
- interface PelicanWebAuthProps extends PelicanAuthConfig {
96
- onClose?: () => void;
97
- onSuccess: (result: IdentityResult) => void;
98
- onError?: (error: Error) => void;
99
- buttonComponent?: React.ReactElement;
100
- buttonText?: string;
101
- }
102
-
103
- type Listener<T> = (payload: T) => void;
104
- declare class PelicanAuthentication {
105
- private readonly crypto;
106
- private readonly stateMachine;
107
- private transport?;
108
- private sessionId;
109
- private sessionKey;
110
- private visibilityHandler?;
111
- private listeners;
112
- private readonly config;
113
- constructor(config: PelicanAuthConfig);
114
- on<K extends keyof PelicanAuthEventMap>(event: K, cb: Listener<PelicanAuthEventMap[K]>): () => boolean;
115
- start(): Promise<void>;
116
- stop(): void;
117
- private fetchRelayUrl;
118
- private emitEntryPoint;
119
- private handleMessage;
120
- private handleAuthSuccess;
121
- private getCachedEntry;
122
- private attachVisibilityRecovery;
123
- private detachVisibilityRecovery;
124
- private terminate;
125
- private restartIfContinuous;
126
- private resetSession;
127
- destroy(): void;
128
- private emit;
129
- private fail;
130
- }
131
-
132
- interface EncryptedMessage {
133
- cipher: string;
134
- nonce: string;
135
- }
136
- declare class CryptoService {
137
- generateSymmetricKey(): string;
138
- encryptSymmetric({ plaintext, keyString, }: {
139
- plaintext: string;
140
- keyString: string;
141
- }): EncryptedMessage;
142
- decryptSymmetric({ encrypted, keyString, }: {
143
- encrypted: EncryptedMessage;
144
- keyString: string;
145
- }): string | null;
146
- }
147
-
148
- declare class StateMachine {
149
- private state;
150
- private listeners;
151
- get current(): PelicanAuthState;
152
- transition(next: PelicanAuthState): void;
153
- subscribe(fn: (s: PelicanAuthState) => void): () => boolean;
154
- }
155
-
156
- type TransportHandlers = {
157
- onOpen?: () => void;
158
- onMessage?: (msg: ISocketMessage) => void;
159
- onError?: (err: Event) => void;
160
- onClose?: (ev: CloseEvent) => void;
161
- };
162
- declare class Transport {
163
- private socket?;
164
- private handlers;
165
- private reconnectAttempts;
166
- private maxReconnectAttempts;
167
- private isExplicitlyClosed;
168
- private url?;
169
- constructor(handlers: TransportHandlers);
170
- connect(url: string): void;
171
- private attemptReconnect;
172
- send(payload: ISocketMessage): void;
173
- close(): void;
174
- }
175
-
176
- interface AuthSession {
177
- sessionId: string;
178
- sessionKey: string;
179
- }
180
- declare const storeAuthSession: (sessionId: string, sessionKey: string, ttlMs?: number) => void;
181
- declare const getAuthSession: () => AuthSession | null;
182
- declare const clearAuthSession: () => void;
183
- declare const clearAllAuthData: () => void;
184
-
185
- declare const BASEURL = "http://192.168.1.2:8080";
186
-
187
- 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, type PelicanWebAuthProps, StateMachine, Transport, clearAllAuthData, clearAuthSession, getAuthSession, storeAuthSession };
1
+ export * from "./types/types";
2
+ export { PelicanAuthentication } from "./engine/engine";
3
+ export { CryptoService } from "./utilities/crypto";
4
+ export { StateMachine } from "./utilities/stateMachine";
5
+ export { Transport } from "./utilities/transport";
6
+ export * from "./utilities/storage";
7
+ export { BASEURL } from "./constants";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAC;AAE9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}