@truly-you/trulyyou-web-sdk 0.1.4 → 0.1.6
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.
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/sdk/TrulyYouSDK.d.ts +5 -0
- package/package.json +2 -1
- package/src/sdk/TrulyYouSDK.ts +51 -9
|
@@ -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,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truly-you/trulyyou-web-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "TrulyYou Web SDK for secure authentication and payload signing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.esm.js",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
8
|
+
"unpkg": "dist/index.umd.js",
|
|
8
9
|
"types": "dist/index.d.ts",
|
|
9
10
|
"private": false,
|
|
10
11
|
"publishConfig": {
|
package/src/sdk/TrulyYouSDK.ts
CHANGED
|
@@ -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
|
*/
|
|
@@ -272,6 +288,10 @@ export class TrulyYouSDK {
|
|
|
272
288
|
probeUrl.searchParams.set('probe', 'true')
|
|
273
289
|
probeUrl.searchParams.set('origin', origin)
|
|
274
290
|
iframe.src = probeUrl.toString()
|
|
291
|
+
|
|
292
|
+
console.log('[SDK-PROBE]: Creating probe iframe with URL:', probeUrl.toString())
|
|
293
|
+
console.log('[SDK-PROBE]: Current origin:', origin)
|
|
294
|
+
console.log('[SDK-PROBE]: Frontend URL:', this.frontendUrl)
|
|
275
295
|
|
|
276
296
|
let timeout: NodeJS.Timeout | undefined
|
|
277
297
|
let backendCheckPromise: Promise<boolean> | null = null
|
|
@@ -287,16 +307,29 @@ export class TrulyYouSDK {
|
|
|
287
307
|
}
|
|
288
308
|
|
|
289
309
|
const handleMessage = async (event: MessageEvent) => {
|
|
310
|
+
console.log('[SDK-PROBE]: Received message:', event.data, 'from origin:', event.origin)
|
|
311
|
+
|
|
290
312
|
try {
|
|
291
313
|
const frontendOrigin = new URL(this.frontendUrl).origin
|
|
292
|
-
|
|
314
|
+
console.log('[SDK-PROBE]: Checking origin - expected:', frontendOrigin, 'received:', event.origin)
|
|
315
|
+
if (event.origin !== frontendOrigin) {
|
|
316
|
+
console.log('[SDK-PROBE]: Origin mismatch, ignoring message')
|
|
317
|
+
return
|
|
318
|
+
}
|
|
293
319
|
|
|
294
320
|
} catch (e) {
|
|
295
|
-
|
|
321
|
+
console.log('[SDK-PROBE]: Origin check failed, using hostname fallback')
|
|
322
|
+
if (!event.origin.includes(window.location.hostname)) {
|
|
323
|
+
console.log('[SDK-PROBE]: Hostname not in origin, ignoring message')
|
|
324
|
+
return
|
|
325
|
+
}
|
|
296
326
|
}
|
|
297
327
|
|
|
298
328
|
const data = event.data as any
|
|
329
|
+
console.log('[SDK-PROBE]: Message passed origin check, type:', data?.type)
|
|
330
|
+
|
|
299
331
|
if (data?.type === 'KEY_CHECK_RESULT') {
|
|
332
|
+
console.log('[SDK-PROBE]: KEY_CHECK_RESULT received - hasKey:', data.hasKey, 'keyId:', data.keyId)
|
|
300
333
|
cleanup()
|
|
301
334
|
if (data.hasKey && data.keyId) {
|
|
302
335
|
// Key found in localStorage - it will be validated when used in /api/signatures/create
|
|
@@ -305,6 +338,7 @@ export class TrulyYouSDK {
|
|
|
305
338
|
resolve(null)
|
|
306
339
|
}
|
|
307
340
|
} else if (data?.type === 'KEY_CHECK_FAILED') {
|
|
341
|
+
console.log('[SDK-PROBE]: KEY_CHECK_FAILED received')
|
|
308
342
|
cleanup()
|
|
309
343
|
resolve(null)
|
|
310
344
|
}
|
|
@@ -312,13 +346,16 @@ export class TrulyYouSDK {
|
|
|
312
346
|
|
|
313
347
|
window.addEventListener('message', handleMessage)
|
|
314
348
|
document.body.appendChild(iframe)
|
|
349
|
+
console.log('[SDK-PROBE]: Iframe appended to body, waiting for response...')
|
|
315
350
|
|
|
316
351
|
// Short timeout to keep UX snappy
|
|
317
352
|
timeout = setTimeout(() => {
|
|
353
|
+
console.log('[SDK-PROBE]: Timeout reached (1500ms), no response from iframe')
|
|
318
354
|
cleanup()
|
|
319
355
|
resolve(null)
|
|
320
356
|
}, 1500)
|
|
321
|
-
} catch {
|
|
357
|
+
} catch (error) {
|
|
358
|
+
console.error('[SDK-PROBE]: Error in probeIframeForKey:', error)
|
|
322
359
|
resolve(null)
|
|
323
360
|
}
|
|
324
361
|
})
|
|
@@ -1683,7 +1720,8 @@ export class TrulyYouSDK {
|
|
|
1683
1720
|
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
1721
|
|
|
1685
1722
|
// Get keyId and userId from localStorage
|
|
1686
|
-
let
|
|
1723
|
+
let storedKeyId = localStorage.getItem('trulyYouKeyId')
|
|
1724
|
+
let keyId = storedKeyId ? this.extractActualKeyId(storedKeyId) : null
|
|
1687
1725
|
const userIdStr = localStorage.getItem('trulyYouUserId')
|
|
1688
1726
|
let userId: string | undefined
|
|
1689
1727
|
if (userIdStr) {
|
|
@@ -1702,7 +1740,8 @@ export class TrulyYouSDK {
|
|
|
1702
1740
|
console.log('[SDK]: No key found in localStorage, triggering enrollment...')
|
|
1703
1741
|
|
|
1704
1742
|
// Probe iframe first to check if key exists there
|
|
1705
|
-
|
|
1743
|
+
storedKeyId = await this.probeIframeForKey()
|
|
1744
|
+
keyId = storedKeyId ? this.extractActualKeyId(storedKeyId) : null
|
|
1706
1745
|
|
|
1707
1746
|
if (!keyId) {
|
|
1708
1747
|
// No key found, trigger enrollment
|
|
@@ -1710,7 +1749,8 @@ export class TrulyYouSDK {
|
|
|
1710
1749
|
await this.enrollWithPopup()
|
|
1711
1750
|
|
|
1712
1751
|
// After enrollment, probe again to get the new key
|
|
1713
|
-
|
|
1752
|
+
storedKeyId = await this.probeIframeForKey()
|
|
1753
|
+
keyId = storedKeyId ? this.extractActualKeyId(storedKeyId) : null
|
|
1714
1754
|
|
|
1715
1755
|
if (!keyId) {
|
|
1716
1756
|
throw new Error('Enrollment completed but no key found. Please try again.')
|
|
@@ -1754,9 +1794,11 @@ export class TrulyYouSDK {
|
|
|
1754
1794
|
|
|
1755
1795
|
// Make the actual API call with signature and signatureId in header
|
|
1756
1796
|
// Use keyId from signingResult (Device B's keyId for handoff, or localStorage keyId for mobile)
|
|
1757
|
-
|
|
1758
|
-
const
|
|
1759
|
-
console.log('[SDK]:
|
|
1797
|
+
// Extract actual keyId from signingResult if it's in authFlowId_keyId format
|
|
1798
|
+
const signingResultKeyId = signingResult.keyId ? this.extractActualKeyId(signingResult.keyId) : ''
|
|
1799
|
+
console.log('[SDK]: 🔍 KeyId debug - signingResult.keyId:', signingResultKeyId, 'localStorage keyId:', keyId, 'keyId type:', typeof signingResultKeyId, 'empty?:', signingResultKeyId === '')
|
|
1800
|
+
const keyIdForAuth = signingResultKeyId || keyId || ''
|
|
1801
|
+
console.log('[SDK]: ✅ Final keyId for auth header:', keyIdForAuth, '(from', signingResultKeyId && signingResultKeyId !== '' ? 'Device B' : 'localStorage fallback', ')')
|
|
1760
1802
|
const authHeaderValue = btoa(JSON.stringify({ signature: signingResult.signature, keyId: keyIdForAuth, signatureId }))
|
|
1761
1803
|
|
|
1762
1804
|
const response = await fetch(url, {
|