@dotrino/identity 0.36.0 → 0.37.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 +2 -2
  2. package/vault/remote.js +13 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/identity",
3
- "version": "0.36.0",
3
+ "version": "0.37.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",
@@ -55,7 +55,7 @@
55
55
  "url": "git+https://github.com/imdotrino/dotrino-identity.git"
56
56
  },
57
57
  "dependencies": {
58
- "@dotrino/proxy-client": "0.8.0"
58
+ "@dotrino/proxy-client": "0.9.1"
59
59
  },
60
60
  "devDependencies": {
61
61
  "fake-indexeddb": "^6.2.5"
package/vault/remote.js CHANGED
@@ -75,8 +75,20 @@ async function verificarHola (p, sn) {
75
75
  return b
76
76
  }
77
77
 
78
+
79
+ /**
80
+ * Canjea la CITA del QR: devuelve la dirección real de la conexión de la bóveda. El
81
+ * código se quema al usarse, así que esto va una sola vez por emparejamiento.
82
+ */
83
+ async function canjearCita (client, code) {
84
+ const r = await client.redeemPairingCode(code)
85
+ if (!r?.ok || !r.instance) throw new Error(r?.error || 'ese código de emparejamiento ya no vale')
86
+ return r.instance
87
+ }
88
+
78
89
  /** «¿Quién eres?» del QR corto: devuelve `{ iss, proxy, acct, m }` de la bóveda. */
79
90
  async function askVault (client, qr) {
91
+ const destino = await canjearCita(client, qr.conn)
80
92
  return new Promise((resolve, reject) => {
81
93
  const off = client.on('message', (_from, p) => {
82
94
  if (p?.type === MSG.HELLO_OK) { fin(); verificarHola(p, qr.sn).then((b) => resolve({ iss: b.iss, proxy: b.proxy || qr.proxy, acct: b.acct || '', m: b.m || qr.m }), reject) }
@@ -84,7 +96,7 @@ async function askVault (client, qr) {
84
96
  })
85
97
  const t = setTimeout(() => { fin(); reject(new Error('la bóveda no contestó: ese código pudo caducar')) }, 15000)
86
98
  const fin = () => { off(); clearTimeout(t) }
87
- try { client.send(qr.conn, { type: MSG.HELLO, sn: qr.sn }) } catch (e) { fin(); reject(e) }
99
+ try { client.send(destino, { type: MSG.HELLO, sn: qr.sn }) } catch (e) { fin(); reject(e) }
88
100
  })
89
101
  }
90
102