postex-auth-sdk-stage 1.2.3 → 1.2.5

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.
@@ -1,135 +1,135 @@
1
- function D() {
1
+ function K() {
2
2
  return typeof window < "u" && typeof window.PublicKeyCredential < "u" && typeof navigator < "u" && typeof navigator.credentials < "u";
3
3
  }
4
- async function J() {
5
- if (!D()) return !1;
4
+ async function j() {
5
+ if (!K()) return !1;
6
6
  try {
7
7
  return await PublicKeyCredential.isConditionalMediationAvailable?.() ?? !1;
8
8
  } catch {
9
9
  return !1;
10
10
  }
11
11
  }
12
- function h(a) {
12
+ function y(a) {
13
13
  const e = new Uint8Array(a);
14
14
  let n = "";
15
15
  for (let t = 0; t < e.byteLength; t++)
16
16
  n += String.fromCharCode(e[t]);
17
17
  return btoa(n);
18
18
  }
19
- function w(a) {
19
+ function k(a) {
20
20
  if (typeof a != "string" || !a)
21
21
  throw new Error("Invalid base64: expected non-empty string");
22
22
  const e = a.replace(/\s/g, "").replace(/-/g, "+").replace(/_/g, "/"), n = e.length % 4, t = n > 0 ? e + "=".repeat(4 - n) : e;
23
23
  try {
24
- const r = atob(t), o = new Uint8Array(r.length);
25
- for (let s = 0; s < r.length; s++)
26
- o[s] = r.charCodeAt(s);
27
- return o.buffer;
24
+ const o = atob(t), s = new Uint8Array(o.length);
25
+ for (let r = 0; r < o.length; r++)
26
+ s[r] = o.charCodeAt(r);
27
+ return s.buffer;
28
28
  } catch {
29
29
  throw new Error(
30
30
  "Invalid base64: string is not correctly encoded. Check challenge/credentialId from server."
31
31
  );
32
32
  }
33
33
  }
34
- function b(a) {
35
- return h(a).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
34
+ function g(a) {
35
+ return y(a).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
36
36
  }
37
- function L(a) {
37
+ function J(a) {
38
38
  return /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i.test(
39
39
  a
40
40
  );
41
41
  }
42
- function M(a) {
42
+ function L(a) {
43
43
  const e = a.replace(/-/g, ""), n = new Uint8Array(e.length / 2);
44
44
  for (let t = 0; t < n.length; t++)
45
45
  n[t] = parseInt(e.substr(t * 2, 2), 16);
46
46
  return n.buffer;
47
47
  }
48
- function W(a) {
48
+ function M(a) {
49
49
  if (!a || typeof a != "string")
50
50
  throw new Error("Invalid input: expected non-empty string");
51
- return L(a) ? M(a) : w(a);
51
+ return J(a) ? L(a) : k(a);
52
52
  }
53
- function S(a) {
53
+ function _(a) {
54
54
  return new TextEncoder().encode(a).buffer;
55
55
  }
56
- function H(a) {
56
+ function W(a) {
57
57
  return String.fromCharCode(...a);
58
58
  }
59
- const Y = "xpay_webauthn", F = 1, d = "passkey_data", E = "passkey_email", x = "passkey_mobile_number";
60
- function p() {
59
+ const H = "xpay_webauthn", Y = 1, u = "passkey_data", S = "passkey_email", E = "passkey_mobile_number";
60
+ function h() {
61
61
  return new Promise((a, e) => {
62
- const n = indexedDB.open(Y, F);
62
+ const n = indexedDB.open(H, Y);
63
63
  n.onerror = () => e(n.error), n.onsuccess = () => a(n.result), n.onupgradeneeded = () => {
64
64
  const t = n.result;
65
- t.objectStoreNames.contains(d) || t.createObjectStore(d);
65
+ t.objectStoreNames.contains(u) || t.createObjectStore(u);
66
66
  };
67
67
  });
68
68
  }
69
- async function G() {
69
+ async function F() {
70
70
  try {
71
- const a = await p();
71
+ const a = await h();
72
72
  return new Promise((e, n) => {
73
- const t = a.transaction(d, "readonly"), o = t.objectStore(d).get(E);
74
- o.onerror = () => n(o.error), o.onsuccess = () => e(o.result ?? null), t.oncomplete = () => a.close();
73
+ const t = a.transaction(u, "readonly"), s = t.objectStore(u).get(S);
74
+ s.onerror = () => n(s.error), s.onsuccess = () => e(s.result ?? null), t.oncomplete = () => a.close();
75
75
  });
76
76
  } catch {
77
77
  return null;
78
78
  }
79
79
  }
80
- async function V(a) {
80
+ async function G(a) {
81
81
  try {
82
- const e = await p();
82
+ const e = await h();
83
83
  return new Promise((n, t) => {
84
- const r = e.transaction(d, "readwrite"), s = r.objectStore(d).put(a, E);
85
- s.onerror = () => t(s.error), s.onsuccess = () => n(), r.oncomplete = () => e.close();
84
+ const o = e.transaction(u, "readwrite"), r = o.objectStore(u).put(a, S);
85
+ r.onerror = () => t(r.error), r.onsuccess = () => n(), o.oncomplete = () => e.close();
86
86
  });
87
87
  } catch {
88
88
  }
89
89
  }
90
- async function z() {
90
+ async function V() {
91
91
  try {
92
- const a = await p();
92
+ const a = await h();
93
93
  return new Promise((e, n) => {
94
- const t = a.transaction(d, "readwrite"), o = t.objectStore(d).delete(E);
95
- o.onerror = () => n(o.error), o.onsuccess = () => e(), t.oncomplete = () => a.close();
94
+ const t = a.transaction(u, "readwrite"), s = t.objectStore(u).delete(S);
95
+ s.onerror = () => n(s.error), s.onsuccess = () => e(), t.oncomplete = () => a.close();
96
96
  });
97
97
  } catch {
98
98
  }
99
99
  }
100
- async function X() {
100
+ async function z() {
101
101
  try {
102
- const a = await p();
102
+ const a = await h();
103
103
  return new Promise((e, n) => {
104
- const t = a.transaction(d, "readonly"), o = t.objectStore(d).get(x);
105
- o.onerror = () => n(o.error), o.onsuccess = () => e(o.result ?? null), t.oncomplete = () => a.close();
104
+ const t = a.transaction(u, "readonly"), s = t.objectStore(u).get(E);
105
+ s.onerror = () => n(s.error), s.onsuccess = () => e(s.result ?? null), t.oncomplete = () => a.close();
106
106
  });
107
107
  } catch {
108
108
  return null;
109
109
  }
110
110
  }
111
- async function Q(a) {
111
+ async function X(a) {
112
112
  try {
113
- const e = await p();
113
+ const e = await h();
114
114
  return new Promise((n, t) => {
115
- const r = e.transaction(d, "readwrite"), s = r.objectStore(d).put(a, x);
116
- s.onerror = () => t(s.error), s.onsuccess = () => n(), r.oncomplete = () => e.close();
115
+ const o = e.transaction(u, "readwrite"), r = o.objectStore(u).put(a, E);
116
+ r.onerror = () => t(r.error), r.onsuccess = () => n(), o.oncomplete = () => e.close();
117
117
  });
118
118
  } catch {
119
119
  }
120
120
  }
121
- async function Z() {
121
+ async function Q() {
122
122
  try {
123
- const a = await p();
123
+ const a = await h();
124
124
  return new Promise((e, n) => {
125
- const t = a.transaction(d, "readwrite"), o = t.objectStore(d).delete(x);
126
- o.onerror = () => n(o.error), o.onsuccess = () => e(), t.oncomplete = () => a.close();
125
+ const t = a.transaction(u, "readwrite"), s = t.objectStore(u).delete(E);
126
+ s.onerror = () => n(s.error), s.onsuccess = () => e(), t.oncomplete = () => a.close();
127
127
  });
128
128
  } catch {
129
129
  }
130
130
  }
131
- const I = "dpop_private_key", A = "dpop_public_key_jwk";
132
- function q(a) {
131
+ const x = "dpop_private_key", I = "dpop_public_key_jwk";
132
+ function D(a) {
133
133
  return {
134
134
  kty: "EC",
135
135
  crv: "P-256",
@@ -137,7 +137,7 @@ function q(a) {
137
137
  y: a.y
138
138
  };
139
139
  }
140
- async function R(a) {
140
+ async function B(a) {
141
141
  const e = JSON.stringify({
142
142
  crv: a.crv,
143
143
  kty: a.kty,
@@ -147,65 +147,65 @@ async function R(a) {
147
147
  "SHA-256",
148
148
  new TextEncoder().encode(e)
149
149
  );
150
- return b(n);
150
+ return g(n);
151
151
  }
152
- async function B(a) {
152
+ async function q(a) {
153
153
  try {
154
- const e = await p();
154
+ const e = await h();
155
155
  return new Promise((n, t) => {
156
- const r = e.transaction(d, "readwrite"), s = r.objectStore(d).put(a, I);
157
- s.onerror = () => t(s.error), s.onsuccess = () => n(), r.oncomplete = () => e.close();
156
+ const o = e.transaction(u, "readwrite"), r = o.objectStore(u).put(a, x);
157
+ r.onerror = () => t(r.error), r.onsuccess = () => n(), o.oncomplete = () => e.close();
158
158
  });
159
159
  } catch (e) {
160
160
  console.error("Failed to store DPoP private key:", e);
161
161
  }
162
162
  }
163
- async function ee(a) {
163
+ async function Z(a) {
164
164
  try {
165
- const e = await p();
165
+ const e = await h();
166
166
  return new Promise((n, t) => {
167
- const r = e.transaction(d, "readwrite"), s = r.objectStore(d).put(a, A);
168
- s.onerror = () => t(s.error), s.onsuccess = () => n(), r.oncomplete = () => e.close();
167
+ const o = e.transaction(u, "readwrite"), r = o.objectStore(u).put(a, I);
168
+ r.onerror = () => t(r.error), r.onsuccess = () => n(), o.oncomplete = () => e.close();
169
169
  });
170
170
  } catch (e) {
171
171
  console.error("Failed to store DPoP public key JWK:", e);
172
172
  }
173
173
  }
174
- async function O() {
174
+ async function A() {
175
175
  try {
176
- const a = await p();
176
+ const a = await h();
177
177
  return new Promise((e, n) => {
178
- const t = a.transaction(d, "readonly"), o = t.objectStore(d).get(I);
179
- o.onerror = () => n(o.error), o.onsuccess = () => e(o.result ?? null), t.oncomplete = () => a.close();
178
+ const t = a.transaction(u, "readonly"), s = t.objectStore(u).get(x);
179
+ s.onerror = () => n(s.error), s.onsuccess = () => e(s.result ?? null), t.oncomplete = () => a.close();
180
180
  });
181
181
  } catch {
182
182
  return null;
183
183
  }
184
184
  }
185
- async function N() {
185
+ async function R() {
186
186
  try {
187
- const a = await p();
187
+ const a = await h();
188
188
  return new Promise((e, n) => {
189
- const t = a.transaction(d, "readonly"), o = t.objectStore(d).get(A);
190
- o.onerror = () => n(o.error), o.onsuccess = () => e(o.result ?? null), t.oncomplete = () => a.close();
189
+ const t = a.transaction(u, "readonly"), s = t.objectStore(u).get(I);
190
+ s.onerror = () => n(s.error), s.onsuccess = () => e(s.result ?? null), t.oncomplete = () => a.close();
191
191
  });
192
192
  } catch {
193
193
  return null;
194
194
  }
195
195
  }
196
- async function C() {
196
+ async function U() {
197
197
  try {
198
- const a = await p();
198
+ const a = await h();
199
199
  return new Promise((e, n) => {
200
- const t = a.transaction(d, "readwrite"), r = t.objectStore(d);
201
- r.delete(I), r.delete(A), t.onerror = () => n(t.error), t.oncomplete = () => {
200
+ const t = a.transaction(u, "readwrite"), o = t.objectStore(u);
201
+ o.delete(x), o.delete(I), t.onerror = () => n(t.error), t.oncomplete = () => {
202
202
  a.close(), e();
203
203
  };
204
204
  });
205
205
  } catch {
206
206
  }
207
207
  }
208
- async function g() {
208
+ async function T() {
209
209
  const a = await crypto.subtle.generateKey(
210
210
  {
211
211
  name: "ECDSA",
@@ -214,90 +214,99 @@ async function g() {
214
214
  !1,
215
215
  // Private key is non-extractable
216
216
  ["sign", "verify"]
217
- ), e = await crypto.subtle.exportKey("jwk", a.publicKey), n = q(e), t = await R(n);
218
- return await B(a.privateKey), await ee(n), { publicKey: n, thumbprint: t };
217
+ ), e = await crypto.subtle.exportKey("jwk", a.publicKey), n = D(e), t = await B(n);
218
+ return await q(a.privateKey), await Z(n), { publicKey: n, thumbprint: t };
219
219
  }
220
- async function T(a, e, n) {
220
+ async function w(a, e, n) {
221
221
  try {
222
- const t = await O(), r = await N();
223
- if (!t || !r) return null;
224
- const o = {
222
+ const t = await A(), o = await R();
223
+ if (!t || !o) return null;
224
+ const s = {
225
225
  typ: "dpop+jwt",
226
226
  alg: "ES256",
227
- jwk: r
227
+ jwk: o
228
228
  // Public key in JWK format
229
- }, s = new URL(
229
+ }, r = new URL(
230
230
  e,
231
231
  typeof window < "u" ? window.location.origin : void 0
232
- ), i = `${s.origin}${s.pathname}`, u = {
232
+ ), i = `${r.origin}${r.pathname}`, d = {
233
233
  jti: crypto.randomUUID(),
234
234
  htm: a.toUpperCase(),
235
235
  htu: i,
236
236
  iat: Math.floor(Date.now() / 1e3)
237
237
  };
238
238
  if (n) {
239
- const _ = new TextEncoder().encode(n), j = await crypto.subtle.digest("SHA-256", _);
240
- u.ath = b(j);
239
+ const P = new TextEncoder().encode(n), $ = await crypto.subtle.digest("SHA-256", P);
240
+ d.ath = g($);
241
241
  }
242
- const l = b(
243
- new TextEncoder().encode(JSON.stringify(o)).buffer
244
- ), c = b(
245
- new TextEncoder().encode(JSON.stringify(u)).buffer
246
- ), y = `${l}.${c}`, f = await crypto.subtle.sign(
242
+ const l = g(
243
+ new TextEncoder().encode(JSON.stringify(s)).buffer
244
+ ), c = g(
245
+ new TextEncoder().encode(JSON.stringify(d)).buffer
246
+ ), p = `${l}.${c}`, f = await crypto.subtle.sign(
247
247
  {
248
248
  name: "ECDSA",
249
249
  hash: { name: "SHA-256" }
250
250
  },
251
251
  t,
252
- new TextEncoder().encode(y)
253
- ), m = b(f);
254
- return `${l}.${c}.${m}`;
252
+ new TextEncoder().encode(p)
253
+ ), b = g(f);
254
+ return `${l}.${c}.${b}`;
255
255
  } catch (t) {
256
256
  return console.error("Failed to generate DPoP proof:", t), null;
257
257
  }
258
258
  }
259
- async function te() {
260
- return await O() !== null;
259
+ async function ee() {
260
+ return await A() !== null;
261
261
  }
262
- const ne = B, $ = {
263
- isWebAuthnSupported: D,
264
- isConditionalUISupported: J,
265
- arrayBufferToBase64: h,
266
- base64ToArrayBuffer: w,
267
- arrayBufferToBase64url: b,
268
- base64urlToArrayBuffer: W,
269
- stringToArrayBuffer: S,
270
- uint8ArrayToString: H,
271
- getPasskeyEmail: G,
272
- setPasskeyEmail: V,
273
- clearPasskeyEmail: z,
274
- getPasskeyMobileNumber: X,
275
- setPasskeyMobileNumber: Q,
276
- clearPasskeyMobileNumber: Z,
277
- toMinimalJWK: q,
278
- calculateThumbprint: R,
279
- getDPoPKey: O,
280
- getDPoPPublicKeyJWK: N,
281
- clearDPoPKey: C,
282
- generateDPoPKeyPair: g,
283
- generateDPoPProof: T,
284
- isDPoPEnabled: te,
285
- storeDPoPKey: ne
262
+ const te = q, N = {
263
+ isWebAuthnSupported: K,
264
+ isConditionalUISupported: j,
265
+ arrayBufferToBase64: y,
266
+ base64ToArrayBuffer: k,
267
+ arrayBufferToBase64url: g,
268
+ base64urlToArrayBuffer: M,
269
+ stringToArrayBuffer: _,
270
+ uint8ArrayToString: W,
271
+ getPasskeyEmail: F,
272
+ setPasskeyEmail: G,
273
+ clearPasskeyEmail: V,
274
+ getPasskeyMobileNumber: z,
275
+ setPasskeyMobileNumber: X,
276
+ clearPasskeyMobileNumber: Q,
277
+ toMinimalJWK: D,
278
+ calculateThumbprint: B,
279
+ getDPoPKey: A,
280
+ getDPoPPublicKeyJWK: R,
281
+ clearDPoPKey: U,
282
+ generateDPoPKeyPair: T,
283
+ generateDPoPProof: w,
284
+ isDPoPEnabled: ee,
285
+ storeDPoPKey: te
286
+ };
287
+ typeof window < "u" && (window.WebAuthn = N);
288
+ const ne = typeof window < "u" ? window : globalThis;
289
+ ne.WebAuthn = N;
290
+ const m = "postex-auth-token", se = "postexglobal", oe = {
291
+ xstak: "https://auth-stage.xstak.com/public/v1",
292
+ postex: "https://auth-stage.postex.pk/public/v1",
293
+ callcourier: "https://auth-stage.callcourier.com.pk/public/v1",
294
+ postexglobal: "https://auth-stage.postexglobal.com/public/v1"
286
295
  };
287
- typeof window < "u" && (window.WebAuthn = $);
288
- const oe = typeof window < "u" ? window : globalThis;
289
- oe.WebAuthn = $;
290
- const P = "postex-auth-token", k = "https://auth-stage.postexglobal.com/public/v1";
291
296
  class re extends Error {
292
297
  constructor(e, n, t) {
293
298
  super(t ?? `Request failed with status ${e}`), this.response = { status: e, data: n }, this.name = "AuthSDKFetchError";
294
299
  }
295
300
  }
296
- const K = "auth_sdk_id_token", v = "auth_sdk_refresh_token";
297
- class U {
301
+ const O = "auth_sdk_id_token", v = "auth_sdk_refresh_token";
302
+ class C {
298
303
  constructor(e) {
299
304
  this.config = e;
300
305
  }
306
+ getBaseUrl() {
307
+ const e = this.config.appId ?? se;
308
+ return oe[e];
309
+ }
301
310
  normalizeAuthIdentifier(e) {
302
311
  return typeof e == "string" ? { email: e } : {
303
312
  email: e.email,
@@ -305,36 +314,36 @@ class U {
305
314
  };
306
315
  }
307
316
  buildUrl(e, n) {
308
- const t = k.replace(/\/$/, ""), r = e.startsWith("/") ? e : `/${e}`, o = `${t}${r}`;
309
- if (!n || Object.keys(n).length === 0) return o;
310
- const s = new URLSearchParams(n).toString();
311
- return `${o}?${s}`;
317
+ const t = this.getBaseUrl().replace(/\/$/, ""), o = e.startsWith("/") ? e : `/${e}`, s = `${t}${o}`;
318
+ if (!n || Object.keys(n).length === 0) return s;
319
+ const r = new URLSearchParams(n).toString();
320
+ return `${s}?${r}`;
312
321
  }
313
322
  async request(e, n, t) {
314
- const r = this.buildUrl(n, t?.params), o = {
323
+ const o = this.buildUrl(n, t?.params), s = {
315
324
  "Content-Type": "application/json",
316
325
  Accept: "application/json",
317
326
  "X-API-Key": this.config.apiKey ?? "",
318
327
  ...t?.headers
319
- }, s = {
328
+ }, r = {
320
329
  method: e,
321
330
  credentials: "include",
322
- headers: o
331
+ headers: s
323
332
  };
324
- t?.body !== void 0 && t?.body !== null && (s.body = JSON.stringify(t.body));
325
- const i = await fetch(r, s);
333
+ t?.body !== void 0 && t?.body !== null && (r.body = JSON.stringify(t.body));
334
+ const i = await fetch(o, r);
326
335
  if (!i.ok) {
327
336
  let c;
328
337
  try {
329
- const y = await i.text();
330
- c = y ? JSON.parse(y) : void 0;
338
+ const p = await i.text();
339
+ c = p ? JSON.parse(p) : void 0;
331
340
  } catch {
332
341
  c = void 0;
333
342
  }
334
343
  throw i.status === 401 && await this.clearTokens(), new re(i.status, c);
335
344
  }
336
- const u = await i.text();
337
- return { data: u ? JSON.parse(u) : {} };
345
+ const d = await i.text();
346
+ return { data: d ? JSON.parse(d) : {} };
338
347
  }
339
348
  /**
340
349
  * Returns auth headers (Authorization + DPoP) for the given request.
@@ -343,16 +352,16 @@ class U {
343
352
  * @param url - Full request URL
344
353
  */
345
354
  async getRequestAuthHeaders(e, n) {
346
- const t = localStorage.getItem(P);
355
+ const t = localStorage.getItem(m);
347
356
  if (!t) return {};
348
- const r = n.startsWith("http") ? n : `${k}${n}`, o = await T(
357
+ const o = n.startsWith("http") ? n : `${this.getBaseUrl()}${n}`, s = await w(
349
358
  e.toUpperCase(),
350
- r,
359
+ o,
351
360
  t
352
- ), s = {
361
+ ), r = {
353
362
  Authorization: `Bearer ${t}`
354
363
  };
355
- return o && (s.DPoP = o), s;
364
+ return s && (r.DPoP = s), r;
356
365
  }
357
366
  /**
358
367
  * GET /auth/status - Check if client has trusted device session and what auth method is available.
@@ -373,12 +382,12 @@ class U {
373
382
  async initiateAuth(e) {
374
383
  const n = this.normalizeAuthIdentifier(e), t = await this.request("POST", "/auth/initiate", {
375
384
  body: n
376
- }), r = t.data.data ?? t.data;
385
+ }), o = t.data.data ?? t.data;
377
386
  return {
378
- status: r.status,
379
- challenge: r.challenge,
380
- credentialIds: r.credentialIds,
381
- rp: r.rp
387
+ status: o.status,
388
+ challenge: o.challenge,
389
+ credentialIds: o.credentialIds,
390
+ rp: o.rp
382
391
  };
383
392
  }
384
393
  /**
@@ -386,29 +395,29 @@ class U {
386
395
  * Stores tokens from the response.
387
396
  */
388
397
  async verifyOTP(e) {
389
- await g();
390
- const n = await T(
398
+ await T();
399
+ const n = await w(
391
400
  "POST",
392
- `${k}/otp/verify`
401
+ `${this.getBaseUrl()}/otp/verify`
393
402
  ), t = await this.request("POST", "/otp/verify", {
394
403
  body: { otp: e },
395
404
  headers: n ? { DPoP: n } : {}
396
- }), r = t.data.data ?? t.data, o = r.AuthenticationResult ?? r, s = o.access_token ?? o.accessToken ?? o.AccessToken, i = o.refresh_token ?? o.refreshToken ?? o.RefreshToken, u = o.id_token ?? o.idToken ?? o.IdToken, l = o.expires_in ?? o.expiresIn ?? o.ExpiresIn ?? 3600, c = o.token_type ?? o.tokenType ?? o.TokenType ?? "Bearer";
397
- return s && await this.storeTokens({
398
- accessToken: s,
405
+ }), o = t.data.data ?? t.data, s = o.AuthenticationResult ?? o, r = s.access_token ?? s.accessToken ?? s.AccessToken, i = s.refresh_token ?? s.refreshToken ?? s.RefreshToken, d = s.id_token ?? s.idToken ?? s.IdToken, l = s.expires_in ?? s.expiresIn ?? s.ExpiresIn ?? 3600, c = s.token_type ?? s.tokenType ?? s.TokenType ?? "Bearer";
406
+ return r && await this.storeTokens({
407
+ accessToken: r,
399
408
  refreshToken: i ?? "",
400
- idToken: u ?? "",
409
+ idToken: d ?? "",
401
410
  expiresIn: l ?? 3600,
402
411
  tokenType: c ?? "Bearer"
403
412
  }), {
404
- access_token: s,
413
+ access_token: r,
405
414
  refresh_token: i ?? "",
406
- id_token: u ?? "",
415
+ id_token: d ?? "",
407
416
  expires_in: l,
408
417
  token_type: c,
409
- verified: o.verified ?? o.Verified ?? !0,
410
- email: o.email ?? o.Email ?? "",
411
- ...o
418
+ verified: s.verified ?? s.Verified ?? !0,
419
+ email: s.email ?? s.Email ?? "",
420
+ ...s
412
421
  };
413
422
  }
414
423
  /**
@@ -431,29 +440,29 @@ class U {
431
440
  mobileNumber: e,
432
441
  otp: n
433
442
  }) {
434
- await g();
435
- const t = await T(
443
+ await T();
444
+ const t = await w(
436
445
  "POST",
437
- `${k}/otp/signup/verify`
438
- ), r = await this.request("POST", "/otp/signup/verify", {
446
+ `${this.getBaseUrl()}/otp/signup/verify`
447
+ ), o = await this.request("POST", "/otp/signup/verify", {
439
448
  body: { mobileNumber: e, otp: n },
440
449
  headers: t ? { DPoP: t } : {}
441
- }), o = r.data.data ?? r.data, s = o.AuthenticationResult ?? o, i = s.access_token ?? s.accessToken ?? s.AccessToken, u = s.refresh_token ?? s.refreshToken ?? s.RefreshToken, l = s.id_token ?? s.idToken ?? s.IdToken, c = s.expires_in ?? s.expiresIn ?? s.ExpiresIn ?? 3600, y = s.token_type ?? s.tokenType ?? s.TokenType ?? "Bearer";
450
+ }), s = o.data.data ?? o.data, r = s.AuthenticationResult ?? s, i = r.access_token ?? r.accessToken ?? r.AccessToken, d = r.refresh_token ?? r.refreshToken ?? r.RefreshToken, l = r.id_token ?? r.idToken ?? r.IdToken, c = r.expires_in ?? r.expiresIn ?? r.ExpiresIn ?? 3600, p = r.token_type ?? r.tokenType ?? r.TokenType ?? "Bearer";
442
451
  return i && await this.storeTokens({
443
452
  accessToken: i,
444
- refreshToken: u ?? "",
453
+ refreshToken: d ?? "",
445
454
  idToken: l ?? "",
446
455
  expiresIn: c ?? 3600,
447
- tokenType: y ?? "Bearer"
456
+ tokenType: p ?? "Bearer"
448
457
  }), {
449
458
  access_token: i,
450
- refresh_token: u ?? "",
459
+ refresh_token: d ?? "",
451
460
  id_token: l ?? "",
452
461
  expires_in: c,
453
- token_type: y,
454
- verified: s.verified ?? s.Verified ?? !0,
455
- email: s.email ?? s.Email ?? "",
456
- ...s
462
+ token_type: p,
463
+ verified: r.verified ?? r.Verified ?? !0,
464
+ email: r.email ?? r.Email ?? "",
465
+ ...r
457
466
  };
458
467
  }
459
468
  /**
@@ -465,11 +474,11 @@ class U {
465
474
  }) {
466
475
  const t = await this.request("POST", "/otp/signup/resend", {
467
476
  body: { email: n, mobileNumber: e }
468
- }), r = t.data.data ?? t.data;
477
+ }), o = t.data.data ?? t.data;
469
478
  return {
470
- success: r.success ?? !0,
471
- message: r.message,
472
- ...r
479
+ success: o.success ?? !0,
480
+ message: o.message,
481
+ ...o
473
482
  };
474
483
  }
475
484
  /**
@@ -493,19 +502,19 @@ class U {
493
502
  {
494
503
  body: {}
495
504
  }
496
- ), n = e.data.data ?? e.data, t = n.AuthenticationResult ?? n, r = t.access_token ?? t.accessToken ?? t.AccessToken, o = t.refresh_token ?? t.refreshToken ?? t.RefreshToken, s = t.id_token ?? t.idToken ?? t.IdToken, i = t.expires_in ?? t.expiresIn ?? t.ExpiresIn ?? 3600, u = t.token_type ?? t.tokenType ?? t.TokenType ?? "Bearer";
497
- return r && await this.storeTokens({
498
- accessToken: r,
499
- refreshToken: o ?? "",
500
- idToken: s ?? "",
505
+ ), n = e.data.data ?? e.data, t = n.AuthenticationResult ?? n, o = t.access_token ?? t.accessToken ?? t.AccessToken, s = t.refresh_token ?? t.refreshToken ?? t.RefreshToken, r = t.id_token ?? t.idToken ?? t.IdToken, i = t.expires_in ?? t.expiresIn ?? t.ExpiresIn ?? 3600, d = t.token_type ?? t.tokenType ?? t.TokenType ?? "Bearer";
506
+ return o && await this.storeTokens({
507
+ accessToken: o,
508
+ refreshToken: s ?? "",
509
+ idToken: r ?? "",
501
510
  expiresIn: i ?? 3600,
502
- tokenType: u ?? "Bearer"
511
+ tokenType: d ?? "Bearer"
503
512
  }), {
504
- access_token: r,
505
- refresh_token: o ?? "",
506
- id_token: s ?? "",
513
+ access_token: o,
514
+ refresh_token: s ?? "",
515
+ id_token: r ?? "",
507
516
  expires_in: i,
508
- token_type: u,
517
+ token_type: d,
509
518
  verified: t.verified ?? t.Verified ?? !0,
510
519
  email: t.email ?? t.Email ?? "",
511
520
  ...t
@@ -526,23 +535,23 @@ class U {
526
535
  let t;
527
536
  if (n?.user?.id)
528
537
  try {
529
- t = w(n.user.id);
538
+ t = k(n.user.id);
530
539
  } catch {
531
- t = S(n.user.id);
540
+ t = _(n.user.id);
532
541
  }
533
542
  else
534
- t = S(e);
535
- const r = (n.pubKeyCredParams ?? [
543
+ t = _(e);
544
+ const o = (n.pubKeyCredParams ?? [
536
545
  { type: "public-key", alg: -7 },
537
546
  { type: "public-key", alg: -257 }
538
547
  ]).map((f) => ({
539
548
  type: "public-key",
540
549
  alg: f.alg
541
- })), o = n.excludeCredentials?.map((f) => ({
550
+ })), s = n.excludeCredentials?.map((f) => ({
542
551
  type: "public-key",
543
- id: w(f.id)
544
- })), s = {
545
- challenge: w(n.challenge),
552
+ id: k(f.id)
553
+ })), r = {
554
+ challenge: k(n.challenge),
546
555
  rp: {
547
556
  name: n.rp?.name ?? "XPay",
548
557
  id: n.rp?.id ?? window.location.hostname
@@ -552,8 +561,8 @@ class U {
552
561
  name: n.user?.name ?? e,
553
562
  displayName: n.user?.displayName ?? e
554
563
  },
555
- pubKeyCredParams: r,
556
- excludeCredentials: o,
564
+ pubKeyCredParams: o,
565
+ excludeCredentials: s,
557
566
  timeout: n.timeout ?? 6e4,
558
567
  attestation: n.attestation ?? "none",
559
568
  authenticatorSelection: n.authenticatorSelection ?? {
@@ -561,20 +570,20 @@ class U {
561
570
  userVerification: "required"
562
571
  }
563
572
  }, i = await navigator.credentials.create({
564
- publicKey: s
573
+ publicKey: r
565
574
  });
566
575
  if (!i) throw new Error("Credential creation failed");
567
- const u = i.response, l = {
568
- clientDataJSON: h(u.clientDataJSON),
569
- attestationObject: h(u.attestationObject),
570
- rawId: h(i.rawId)
576
+ const d = i.response, l = {
577
+ clientDataJSON: y(d.clientDataJSON),
578
+ attestationObject: y(d.attestationObject),
579
+ rawId: y(i.rawId)
571
580
  };
572
581
  if (!l.rawId) throw new Error("Raw ID is required");
573
- await g();
574
- const c = await T(
582
+ await T();
583
+ const c = await w(
575
584
  "POST",
576
- `${k}/webauthn/register/challenge`
577
- ), y = await this.request(
585
+ `${this.getBaseUrl()}/webauthn/register/challenge`
586
+ ), p = await this.request(
578
587
  "POST",
579
588
  "/webauthn/register/challenge",
580
589
  {
@@ -582,7 +591,7 @@ class U {
582
591
  headers: c ? { DPoP: c } : {}
583
592
  }
584
593
  );
585
- return y.data.data ?? y.data;
594
+ return p.data.data ?? p.data;
586
595
  }
587
596
  /**
588
597
  * POST /webauthn/authenticate/challenge - Authenticate with passkey.
@@ -592,13 +601,13 @@ class U {
592
601
  rp: n,
593
602
  credentialIds: t
594
603
  }) {
595
- const r = await navigator.credentials.get({
604
+ const o = await navigator.credentials.get({
596
605
  publicKey: {
597
- challenge: w(e),
606
+ challenge: k(e),
598
607
  rpId: n?.host ?? void 0,
599
- allowCredentials: t.map((_) => ({
608
+ allowCredentials: t.map((P) => ({
600
609
  type: "public-key",
601
- id: w(_)
610
+ id: k(P)
602
611
  // Hint browser about possible transports for faster authenticator discovery
603
612
  // transports: ["internal", "hybrid"] as AuthenticatorTransport[],
604
613
  })),
@@ -606,38 +615,38 @@ class U {
606
615
  userVerification: "required"
607
616
  }
608
617
  });
609
- if (!r) throw new Error("Authentication failed");
610
- const o = r.response, s = {
611
- clientDataJSON: h(o.clientDataJSON),
612
- authenticatorData: h(
613
- o.authenticatorData
618
+ if (!o) throw new Error("Authentication failed");
619
+ const s = o.response, r = {
620
+ clientDataJSON: y(s.clientDataJSON),
621
+ authenticatorData: y(
622
+ s.authenticatorData
614
623
  ),
615
- signature: h(o.signature),
616
- rawId: h(r.rawId),
617
- userHandle: o.userHandle ? h(o.userHandle) : ""
624
+ signature: y(s.signature),
625
+ rawId: y(o.rawId),
626
+ userHandle: s.userHandle ? y(s.userHandle) : ""
618
627
  };
619
- await g();
620
- const i = await T(
628
+ await T();
629
+ const i = await w(
621
630
  "POST",
622
- `${k}/webauthn/authenticate/challenge`
623
- ), u = await this.request(
631
+ `${this.getBaseUrl()}/webauthn/authenticate/challenge`
632
+ ), d = await this.request(
624
633
  "POST",
625
634
  "/webauthn/authenticate/challenge",
626
635
  {
627
- body: s,
636
+ body: r,
628
637
  headers: i ? { DPoP: i } : {}
629
638
  }
630
- ), l = u.data.data ?? u.data, c = l.AuthenticationResult ?? l, y = c.AccessToken ?? c.accessToken ?? c.access_token, f = c.RefreshToken ?? c.refreshToken ?? c.refresh_token, m = c.IdToken ?? c.idToken ?? c.id_token;
631
- return y && await this.storeTokens({
632
- accessToken: y,
639
+ ), l = d.data.data ?? d.data, c = l.AuthenticationResult ?? l, p = c.AccessToken ?? c.accessToken ?? c.access_token, f = c.RefreshToken ?? c.refreshToken ?? c.refresh_token, b = c.IdToken ?? c.idToken ?? c.id_token;
640
+ return p && await this.storeTokens({
641
+ accessToken: p,
633
642
  refreshToken: f ?? "",
634
- idToken: m ?? "",
643
+ idToken: b ?? "",
635
644
  expiresIn: c.expiresIn ?? c.ExpiresIn ?? 3600,
636
645
  tokenType: c.tokenType ?? c.token_type ?? "Bearer"
637
646
  }), {
638
- access_token: y,
647
+ access_token: p,
639
648
  refresh_token: f ?? "",
640
- id_token: m,
649
+ id_token: b,
641
650
  email: c.email,
642
651
  name: c.name ?? c.userName,
643
652
  expiresIn: c.expiresIn ?? c.ExpiresIn,
@@ -649,50 +658,50 @@ class U {
649
658
  * GET /webauthn/credentials/:username - Get user's passkey status.
650
659
  */
651
660
  async getPasskeyStatus(e) {
652
- const t = `/webauthn/credentials/${encodeURIComponent(e)}`, r = await this.signRequest("GET", t), o = await this.request("GET", t, {
653
- headers: r.headers
654
- }), s = o.data.data ?? o.data;
661
+ const t = `/webauthn/credentials/${encodeURIComponent(e)}`, o = await this.signRequest("GET", t), s = await this.request("GET", t, {
662
+ headers: o.headers
663
+ }), r = s.data.data ?? s.data;
655
664
  return {
656
- ...s,
657
- hasCredentials: !!(s.hasCredentials ?? s.credentialId)
665
+ ...r,
666
+ hasCredentials: !!(r.hasCredentials ?? r.credentialId)
658
667
  };
659
668
  }
660
669
  /**
661
670
  * DELETE /webauthn/credentials/:username - Remove passkey.
662
671
  */
663
672
  async removePasskey(e) {
664
- const t = `/webauthn/credentials/${encodeURIComponent(e)}`, r = await this.signRequest("DELETE", t);
673
+ const t = `/webauthn/credentials/${encodeURIComponent(e)}`, o = await this.signRequest("DELETE", t);
665
674
  await this.request("DELETE", t, {
666
- headers: r.headers
675
+ headers: o.headers
667
676
  });
668
677
  }
669
678
  /**
670
679
  * Signs a request with DPoP and Authorization headers (internal use).
671
680
  */
672
681
  async signRequest(e, n, t = {}) {
673
- const r = n.startsWith("http") ? n : `${k}${n}`, o = await this.getRequestAuthHeaders(e, r);
674
- return { ...t, headers: { ...t.headers, ...o } };
682
+ const o = n.startsWith("http") ? n : `${this.getBaseUrl()}${n}`, s = await this.getRequestAuthHeaders(e, o);
683
+ return { ...t, headers: { ...t.headers, ...s } };
675
684
  }
676
685
  /**
677
686
  * Replaces native fetch or Axios with a DPoP-signed version.
678
687
  */
679
688
  async authenticatedFetch(e, n) {
680
- const t = typeof e == "string" ? e : e instanceof URL ? e.toString() : e.url, r = n?.method || "GET", o = await this.signRequest(r, t, {
689
+ const t = typeof e == "string" ? e : e instanceof URL ? e.toString() : e.url, o = n?.method || "GET", s = await this.signRequest(o, t, {
681
690
  headers: n?.headers
682
691
  });
683
- return fetch(e, { ...n, headers: o.headers });
692
+ return fetch(e, { ...n, headers: s.headers });
684
693
  }
685
694
  /**
686
695
  * Store tokens from /webauthn/authenticate (per spec: sessionStorage preferred).
687
696
  */
688
697
  async storeTokens(e) {
689
- localStorage.setItem(P, e.accessToken), e.refreshToken && localStorage.setItem(v, e.refreshToken), e.idToken && localStorage.setItem(K, e.idToken);
698
+ localStorage.setItem(m, e.accessToken), e.refreshToken && localStorage.setItem(v, e.refreshToken), e.idToken && localStorage.setItem(O, e.idToken);
690
699
  }
691
700
  /**
692
701
  * Clear stored tokens (call on logout).
693
702
  */
694
703
  async clearTokens() {
695
- localStorage.removeItem(P), localStorage.removeItem(K), localStorage.removeItem(v);
704
+ localStorage.removeItem(m), localStorage.removeItem(O), localStorage.removeItem(v);
696
705
  }
697
706
  /**
698
707
  * POST /auth/refresh - Refresh access token using server-stored refresh token.
@@ -702,17 +711,17 @@ class U {
702
711
  async refreshToken() {
703
712
  const e = await this.request("POST", "/auth/refresh", {
704
713
  body: {}
705
- }), n = e.data.data ?? e.data, t = n.access_token, r = n.id_token ?? "", o = n.token_type ?? "Bearer", s = n.expires_in ?? 3600;
714
+ }), n = e.data.data ?? e.data, t = n.access_token, o = n.id_token ?? "", s = n.token_type ?? "Bearer", r = n.expires_in ?? 3600;
706
715
  return t && await this.storeTokens({
707
716
  accessToken: t,
708
- idToken: r,
709
- expiresIn: s,
710
- tokenType: o
717
+ idToken: o,
718
+ expiresIn: r,
719
+ tokenType: s
711
720
  }), {
712
721
  access_token: t,
713
- id_token: r,
714
- token_type: o,
715
- expires_in: s
722
+ id_token: o,
723
+ token_type: s,
724
+ expires_in: r
716
725
  };
717
726
  }
718
727
  /**
@@ -722,43 +731,43 @@ class U {
722
731
  async logout() {
723
732
  try {
724
733
  const e = await this.getAccessToken(), n = {};
725
- e && (n.Authorization = `Bearer ${e}`), await this.request("POST", "/auth/logout", { body: {}, headers: n }), C();
734
+ e && (n.Authorization = `Bearer ${e}`), await this.request("POST", "/auth/logout", { body: {}, headers: n }), U();
726
735
  } catch {
727
736
  }
728
737
  await this.clearTokens();
729
738
  }
730
739
  async getAccessToken() {
731
- return localStorage.getItem(P);
740
+ return localStorage.getItem(m);
732
741
  }
733
742
  }
734
- typeof window < "u" && (window.AuthSDK = U);
735
- const se = typeof window < "u" ? window : globalThis;
736
- se.AuthSDK = U;
743
+ typeof window < "u" && (window.AuthSDK = C);
744
+ const ae = typeof window < "u" ? window : globalThis;
745
+ ae.AuthSDK = C;
737
746
  export {
738
- U as AuthSDK,
747
+ C as AuthSDK,
739
748
  re as AuthSDKFetchError,
740
- h as arrayBufferToBase64,
741
- b as arrayBufferToBase64url,
742
- w as base64ToArrayBuffer,
743
- W as base64urlToArrayBuffer,
744
- R as calculateThumbprint,
745
- C as clearDPoPKey,
746
- z as clearPasskeyEmail,
747
- Z as clearPasskeyMobileNumber,
748
- g as generateDPoPKeyPair,
749
- T as generateDPoPProof,
750
- O as getDPoPKey,
751
- N as getDPoPPublicKeyJWK,
752
- G as getPasskeyEmail,
753
- X as getPasskeyMobileNumber,
754
- J as isConditionalUISupported,
755
- te as isDPoPEnabled,
756
- D as isWebAuthnSupported,
757
- V as setPasskeyEmail,
758
- Q as setPasskeyMobileNumber,
759
- ne as storeDPoPKey,
760
- S as stringToArrayBuffer,
761
- q as toMinimalJWK,
762
- H as uint8ArrayToString
749
+ y as arrayBufferToBase64,
750
+ g as arrayBufferToBase64url,
751
+ k as base64ToArrayBuffer,
752
+ M as base64urlToArrayBuffer,
753
+ B as calculateThumbprint,
754
+ U as clearDPoPKey,
755
+ V as clearPasskeyEmail,
756
+ Q as clearPasskeyMobileNumber,
757
+ T as generateDPoPKeyPair,
758
+ w as generateDPoPProof,
759
+ A as getDPoPKey,
760
+ R as getDPoPPublicKeyJWK,
761
+ F as getPasskeyEmail,
762
+ z as getPasskeyMobileNumber,
763
+ j as isConditionalUISupported,
764
+ ee as isDPoPEnabled,
765
+ K as isWebAuthnSupported,
766
+ G as setPasskeyEmail,
767
+ X as setPasskeyMobileNumber,
768
+ te as storeDPoPKey,
769
+ _ as stringToArrayBuffer,
770
+ D as toMinimalJWK,
771
+ W as uint8ArrayToString
763
772
  };
764
773
  //# sourceMappingURL=postex-auth-sdk-stage.es.js.map