@dotrino/identity 0.13.0 → 0.14.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/remote.js +7 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/identity",
3
- "version": "0.13.0",
3
+ "version": "0.14.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/remote.js CHANGED
@@ -12,7 +12,7 @@
12
12
  * No reimplementa cripto: usa `@dotrino/identity/capabilities`. Transporte:
13
13
  * `@dotrino/proxy-client` (importado perezosamente; solo se carga al emparejar).
14
14
  */
15
- import { makeDeviceKey, signWithDevice, verifyDelegation, makePairingCode, commitCode, pubkeyId } from './capabilities.js'
15
+ import { makeDeviceKey, signWithDevice, verifyDelegation, makePairingCode, pubkeyId } from './capabilities.js'
16
16
 
17
17
  const MSG = {
18
18
  ENROLL: 'vault.enroll',
@@ -43,15 +43,18 @@ export async function enrollDevice ({ qr, device, onChallenge, label = '', appro
43
43
  // El DISPOSITIVO genera el código y manda solo su COMPROMISO (no el código). El vault
44
44
  // aprende el código únicamente cuando vos lo tipeás en el PC → aprobar exige tener el dispositivo.
45
45
  const code = makePairingCode()
46
- const commit = await commitCode({ code, dpub: dev.publickey, sn: qr.sn })
47
- const data = { op: 'enroll', dpub: dev.publickey, token: qr.token, sn: qr.sn, commit, label, ts: Date.now() }
46
+ // NO se manda el código ni un compromiso: el vault lo aprende SOLO cuando lo tipeás, y al
47
+ // ECHARLO de vuelta el dispositivo confía. Un vault falso no conoce el código → no empareja.
48
+ const data = { op: 'enroll', dpub: dev.publickey, token: qr.token, sn: qr.sn, label, ts: Date.now() }
48
49
  const { signature } = await signWithDevice({ privateJwk: dev.privateJwk, data })
49
50
 
50
51
  const enrolled = new Promise((resolve, reject) => {
51
52
  const off = client.on('message', (_from, p) => {
52
53
  if (!p || typeof p !== 'object') return
53
54
  if (p.type === MSG.ENROLL_CHALLENGE) { try { onChallenge?.({ deviceId, code }) } catch (_) {} }
54
- else if (p.type === MSG.ENROLLED) { cleanup(); resolve(p) }
55
+ // El vault ECHA el código que tipeaste; aceptamos SOLO si coincide con el que generamos.
56
+ // (Un código distinto = un vault que no lo conoce → lo ignoramos y seguimos esperando.)
57
+ else if (p.type === MSG.ENROLLED) { if (p.code === code) { cleanup(); resolve(p) } }
55
58
  else if (p.type === MSG.ERROR) { cleanup(); reject(new Error(p.error)) }
56
59
  })
57
60
  const t = setTimeout(() => { cleanup(); reject(new Error('timeout esperando la aprobación en el vault')) }, approveTimeoutMs)