@truly-you/trulyyou-web-sdk 0.1.3 → 0.1.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.
@@ -10,6 +10,11 @@ export declare class TrulyYouSDK {
10
10
  private realtimeUrl;
11
11
  private mockMobileDevice;
12
12
  constructor(config: TrulyYouSDKConfig);
13
+ /**
14
+ * Extract actual keyId from stored value (authFlowId_keyId format)
15
+ * Returns just the keyId part after the underscore
16
+ */
17
+ private extractActualKeyId;
13
18
  /**
14
19
  * Fetch app branding from SDK backend
15
20
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truly-you/trulyyou-web-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "TrulyYou Web SDK for secure authentication and payload signing",
5
5
  "type": "module",
6
6
  "main": "dist/index.esm.js",
@@ -44,4 +44,3 @@
44
44
  "pusher-js": "^8.4.0-rc2"
45
45
  }
46
46
  }
47
-
@@ -42,6 +42,22 @@ export class TrulyYouSDK {
42
42
  }
43
43
 
44
44
 
45
+ /**
46
+ * Extract actual keyId from stored value (authFlowId_keyId format)
47
+ * Returns just the keyId part after the underscore
48
+ */
49
+ private extractActualKeyId(storedKeyId: string): string {
50
+ // Format is: authFlowId_keyId
51
+ // We only want the part after the underscore
52
+ const parts = storedKeyId.split('_')
53
+ if (parts.length > 1) {
54
+ // Return everything after the first underscore
55
+ return parts.slice(1).join('_')
56
+ }
57
+ // If no underscore, return as-is (backward compatibility)
58
+ return storedKeyId
59
+ }
60
+
45
61
  /**
46
62
  * Fetch app branding from SDK backend
47
63
  */
@@ -353,12 +369,12 @@ export class TrulyYouSDK {
353
369
  const clientId = `client_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
354
370
 
355
371
  // Create session directly via SDK backend
372
+ // Backend will fetch authFlowId from the app document
356
373
  const sessionResponse = await fetch(`${this.apiUrl}/api/sessions`, {
357
374
  method: 'POST',
358
375
  headers: { 'Content-Type': 'application/json' },
359
376
  body: JSON.stringify({
360
377
  appId: appId,
361
- flowId: app.authFlowId,
362
378
  clientId: clientId
363
379
  })
364
380
  })
@@ -1683,7 +1699,8 @@ export class TrulyYouSDK {
1683
1699
  signatureId = `sig_${Date.now()}_${Math.random().toString(36).substring(2, 15)}${Math.random().toString(36).substring(2, 15)}${Math.random().toString(36).substring(2, 15)}${Math.random().toString(36).substring(2, 15)}`
1684
1700
 
1685
1701
  // Get keyId and userId from localStorage
1686
- let keyId = localStorage.getItem('trulyYouKeyId')
1702
+ let storedKeyId = localStorage.getItem('trulyYouKeyId')
1703
+ let keyId = storedKeyId ? this.extractActualKeyId(storedKeyId) : null
1687
1704
  const userIdStr = localStorage.getItem('trulyYouUserId')
1688
1705
  let userId: string | undefined
1689
1706
  if (userIdStr) {
@@ -1702,7 +1719,8 @@ export class TrulyYouSDK {
1702
1719
  console.log('[SDK]: No key found in localStorage, triggering enrollment...')
1703
1720
 
1704
1721
  // Probe iframe first to check if key exists there
1705
- keyId = await this.probeIframeForKey()
1722
+ storedKeyId = await this.probeIframeForKey()
1723
+ keyId = storedKeyId ? this.extractActualKeyId(storedKeyId) : null
1706
1724
 
1707
1725
  if (!keyId) {
1708
1726
  // No key found, trigger enrollment
@@ -1710,7 +1728,8 @@ export class TrulyYouSDK {
1710
1728
  await this.enrollWithPopup()
1711
1729
 
1712
1730
  // After enrollment, probe again to get the new key
1713
- keyId = await this.probeIframeForKey()
1731
+ storedKeyId = await this.probeIframeForKey()
1732
+ keyId = storedKeyId ? this.extractActualKeyId(storedKeyId) : null
1714
1733
 
1715
1734
  if (!keyId) {
1716
1735
  throw new Error('Enrollment completed but no key found. Please try again.')
@@ -1754,9 +1773,11 @@ export class TrulyYouSDK {
1754
1773
 
1755
1774
  // Make the actual API call with signature and signatureId in header
1756
1775
  // Use keyId from signingResult (Device B's keyId for handoff, or localStorage keyId for mobile)
1757
- console.log('[SDK]: 🔍 KeyId debug - signingResult.keyId:', signingResult.keyId, 'localStorage keyId:', keyId, 'keyId type:', typeof signingResult.keyId, 'empty?:', signingResult.keyId === '')
1758
- const keyIdForAuth = signingResult.keyId || keyId || ''
1759
- console.log('[SDK]: Final keyId for auth header:', keyIdForAuth, '(from', signingResult.keyId && signingResult.keyId !== '' ? 'Device B' : 'localStorage fallback', ')')
1776
+ // Extract actual keyId from signingResult if it's in authFlowId_keyId format
1777
+ const signingResultKeyId = signingResult.keyId ? this.extractActualKeyId(signingResult.keyId) : ''
1778
+ console.log('[SDK]: 🔍 KeyId debug - signingResult.keyId:', signingResultKeyId, 'localStorage keyId:', keyId, 'keyId type:', typeof signingResultKeyId, 'empty?:', signingResultKeyId === '')
1779
+ const keyIdForAuth = signingResultKeyId || keyId || ''
1780
+ console.log('[SDK]: ✅ Final keyId for auth header:', keyIdForAuth, '(from', signingResultKeyId && signingResultKeyId !== '' ? 'Device B' : 'localStorage fallback', ')')
1760
1781
  const authHeaderValue = btoa(JSON.stringify({ signature: signingResult.signature, keyId: keyIdForAuth, signatureId }))
1761
1782
 
1762
1783
  const response = await fetch(url, {