@dotrino/identity 0.15.0 → 0.16.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/vault/core.js +16 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/identity",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Identidad y rating de usuarios compartidos entre apps de Dotrino (vault iframe + postMessage)",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/vault/core.js CHANGED
@@ -195,6 +195,16 @@ export async function createIdentityCore ({ kv: rawKv, peers, makeSync = null })
195
195
  // Canal de eventos 'vault' (p.ej. el SAS a comparar durante el emparejamiento).
196
196
  const vaultListeners = new Set()
197
197
  const emitVault = (p) => { for (const fn of vaultListeners) { try { fn(p) } catch (_) {} } }
198
+ // Si el vault RECHAZA por cert revocado, este dispositivo perdió el acceso: limpiamos el
199
+ // cert local (ya no sirve) y emitimos 'revoked' → @dotrino/store borra SOLO el store de
200
+ // ESTE perfil (los demás perfiles quedan intactos). Cualquier otro error se propaga igual.
201
+ const handleVaultError = (e) => {
202
+ if (e && /\brevoked\b/.test(e.message || '')) {
203
+ try { kv.removeItem(VAULT_CERT_STORAGE); kv.removeItem(VAULT_DEVICE_STORAGE) } catch (_) {}
204
+ emitVault({ phase: 'revoked' })
205
+ }
206
+ throw e
207
+ }
198
208
  const loadVaultCert = () => { try { return JSON.parse(kv.getItem(VAULT_CERT_STORAGE) || 'null') } catch (_) { return null } }
199
209
  const loadVaultDevice = () => { try { return JSON.parse(kv.getItem(VAULT_DEVICE_STORAGE) || 'null') } catch (_) { return null } }
200
210
 
@@ -613,7 +623,8 @@ export async function createIdentityCore ({ kv: rawKv, peers, makeSync = null })
613
623
  async vaultSign ({ payload }) {
614
624
  const v = loadVaultCert(); const device = loadVaultDevice()
615
625
  if (!v?.cert || !device) throw new Error('este dispositivo no está emparejado con un vault')
616
- return remoteSign({ master: v.master, proxy: v.proxy, device, cert: v.cert, payload })
626
+ try { return await remoteSign({ master: v.master, proxy: v.proxy, device, cert: v.cert, payload }) }
627
+ catch (e) { return handleVaultError(e) }
617
628
  },
618
629
 
619
630
  // Store DELEGADO: lee/escribe el store de hilos+aperturas EN tu vault (con el cert).
@@ -621,14 +632,16 @@ export async function createIdentityCore ({ kv: rawKv, peers, makeSync = null })
621
632
  async vaultStore ({ method, args }) {
622
633
  const v = loadVaultCert(); const device = loadVaultDevice()
623
634
  if (!v?.cert || !device) throw new Error('este dispositivo no está emparejado con un vault')
624
- return remoteStore({ master: v.master, proxy: v.proxy, device, cert: v.cert, method, args })
635
+ try { return await remoteStore({ master: v.master, proxy: v.proxy, device, cert: v.cert, method, args }) }
636
+ catch (e) { return handleVaultError(e) }
625
637
  },
626
638
 
627
639
  // Lista (solo lectura) de dispositivos enrolados en tu vault.
628
640
  async listVaultDevices () {
629
641
  const v = loadVaultCert(); const device = loadVaultDevice()
630
642
  if (!v?.cert || !device) throw new Error('este dispositivo no está emparejado con un vault')
631
- return remoteDevices({ master: v.master, proxy: v.proxy, device, cert: v.cert })
643
+ try { return await remoteDevices({ master: v.master, proxy: v.proxy, device, cert: v.cert }) }
644
+ catch (e) { return handleVaultError(e) }
632
645
  },
633
646
 
634
647
  // El cert de delegación de este dispositivo (para presentarlo al proxy en `identify`