@truly-you/trulyyou-web-sdk 0.1.21 → 0.1.23

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.
@@ -88,4 +88,9 @@ export declare class TrulyYouSDK {
88
88
  * @param handoff - If true, probes for handoff keyId (with _handoff suffix)
89
89
  */
90
90
  probeForKeyId(handoff?: boolean): Promise<string | null>;
91
+ /**
92
+ * Clear all keys (both handoff and non-handoff) from localStorage
93
+ * Clears from both same-origin localStorage and TrulyYou frontend's localStorage via iframe
94
+ */
95
+ clearAllKeys(): Promise<void>;
91
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truly-you/trulyyou-web-sdk",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "TrulyYou Web SDK for secure authentication and payload signing",
5
5
  "type": "module",
6
6
  "main": "dist/index.esm.js",
@@ -1202,6 +1202,44 @@ export class TrulyYouSDK {
1202
1202
  console.warn('[SDK]: ⚠️ WARNING - No keyId received from Device B via socket! Data:', data)
1203
1203
  }
1204
1204
  console.log('[SDK]: ✅ Using keyId from Device B:', deviceBKeyId, '(extracted from socket)')
1205
+
1206
+ // Store handoff keyId in localStorage (Device A - desktop)
1207
+ if (deviceBKeyId && this.brandingCache?.authFlowId) {
1208
+ const authFlowId = this.brandingCache.authFlowId
1209
+ const handoffStorageKey = `trulyYouKeyId_${authFlowId}_handoff`
1210
+
1211
+ // Store in same-origin localStorage
1212
+ if (typeof window !== 'undefined') {
1213
+ localStorage.setItem(handoffStorageKey, deviceBKeyId)
1214
+ console.log('[SDK]: ✅ Stored handoff keyId in localStorage:', handoffStorageKey, '=', deviceBKeyId)
1215
+ }
1216
+
1217
+ // Also store in TrulyYou frontend's localStorage via iframe
1218
+ try {
1219
+ const frontendUrl = this.frontendUrl
1220
+ const iframe = document.createElement('iframe')
1221
+ iframe.style.cssText = 'position: fixed; top: -9999px; left: -9999px; width: 1px; height: 1px; border: none; opacity: 0; pointer-events: none;'
1222
+
1223
+ const storeUrl = new URL(`${frontendUrl}/store-handoff-keyid.html`)
1224
+ storeUrl.searchParams.set('authFlowId', authFlowId)
1225
+ storeUrl.searchParams.set('keyId', deviceBKeyId)
1226
+
1227
+ iframe.src = storeUrl.toString()
1228
+ document.body.appendChild(iframe)
1229
+
1230
+ // Clean up after a delay
1231
+ setTimeout(() => {
1232
+ if (iframe.parentNode) {
1233
+ iframe.parentNode.removeChild(iframe)
1234
+ }
1235
+ }, 2000)
1236
+
1237
+ console.log('[SDK]: ✅ Stored handoff keyId in TrulyYou frontend localStorage via iframe')
1238
+ } catch (error) {
1239
+ console.warn('[SDK]: Failed to store handoff keyId in TrulyYou frontend localStorage:', error)
1240
+ }
1241
+ }
1242
+
1205
1243
  const result: SigningResult = {
1206
1244
  signature: signature,
1207
1245
  keyId: deviceBKeyId,
@@ -1931,5 +1969,55 @@ export class TrulyYouSDK {
1931
1969
  console.log(`[SDK-PROBE]: ${handoff ? 'Handoff ' : ''}KeyId not found in same-origin localStorage, probing TrulyYou frontend...`)
1932
1970
  return await this.probeIframeForKey(handoff)
1933
1971
  }
1972
+
1973
+ /**
1974
+ * Clear all keys (both handoff and non-handoff) from localStorage
1975
+ * Clears from both same-origin localStorage and TrulyYou frontend's localStorage via iframe
1976
+ */
1977
+ async clearAllKeys(): Promise<void> {
1978
+ // Ensure authFlowId is loaded first
1979
+ await this.ensureAuthFlowIdLoaded()
1980
+
1981
+ if (!this.brandingCache?.authFlowId) {
1982
+ console.warn('[SDK-CLEAR]: authFlowId is required but not available')
1983
+ return
1984
+ }
1985
+
1986
+ const authFlowId = this.brandingCache.authFlowId
1987
+
1988
+ // Clear from same-origin localStorage
1989
+ if (typeof window !== 'undefined') {
1990
+ const regularKey = `trulyYouKeyId_${authFlowId}`
1991
+ const handoffKey = `trulyYouKeyId_${authFlowId}_handoff`
1992
+
1993
+ localStorage.removeItem(regularKey)
1994
+ localStorage.removeItem(handoffKey)
1995
+
1996
+ console.log('[SDK-CLEAR]: ✅ Cleared keys from same-origin localStorage:', regularKey, handoffKey)
1997
+ }
1998
+
1999
+ // Also clear from TrulyYou frontend's localStorage via iframe
2000
+ try {
2001
+ const iframe = document.createElement('iframe')
2002
+ iframe.style.cssText = 'position: fixed; top: -9999px; left: -9999px; width: 1px; height: 1px; border: none; opacity: 0; pointer-events: none;'
2003
+
2004
+ const clearUrl = new URL(`${this.frontendUrl}/clear-keys.html`)
2005
+ clearUrl.searchParams.set('authFlowId', authFlowId)
2006
+
2007
+ iframe.src = clearUrl.toString()
2008
+ document.body.appendChild(iframe)
2009
+
2010
+ // Clean up after a delay
2011
+ setTimeout(() => {
2012
+ if (iframe.parentNode) {
2013
+ iframe.parentNode.removeChild(iframe)
2014
+ }
2015
+ }, 2000)
2016
+
2017
+ console.log('[SDK-CLEAR]: ✅ Cleared keys from TrulyYou frontend localStorage via iframe')
2018
+ } catch (error) {
2019
+ console.warn('[SDK-CLEAR]: Failed to clear keys from TrulyYou frontend localStorage:', error)
2020
+ }
2021
+ }
1934
2022
  }
1935
2023