@dotrino/identity 0.38.0 → 0.39.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/identity",
3
- "version": "0.38.0",
3
+ "version": "0.39.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/src/index.js CHANGED
@@ -278,6 +278,7 @@ export class Identity {
278
278
 
279
279
  /** Cambia las capacidades de un miembro (solo el master). */
280
280
  async setCaps (pub, caps) { return this._call('setCaps', { pub, caps }) }
281
+ async setLabel (pub, label) { return this._call('setLabel', { pub, label }) }
281
282
 
282
283
  /** Expulsa a un miembro (solo el master; al master no se le puede expulsar). */
283
284
  async removeMember (pub) { return this._call('removeMember', { pub }) }
package/src/node.js CHANGED
@@ -168,6 +168,7 @@ export class Identity {
168
168
  isMaster () { return this._h('isMaster') }
169
169
  admitMember (member) { return this._h('admitMember', member) }
170
170
  setCaps (pub, caps) { return this._h('setCaps', { pub, caps }) }
171
+ setLabel (pub, label) { return this._h('setLabel', { pub, label }) }
171
172
  removeMember (pub) { return this._h('removeMember', { pub }) }
172
173
  handoverMaster (to, member = null) { return this._h('handoverMaster', { to, member }) }
173
174
  renounceCaps (caps) { return this._h('renounceCaps', { caps }) }
package/vault/acta.js CHANGED
@@ -247,6 +247,17 @@ export async function applyChanges (acta, changes, { by, now = Date.now() } = {}
247
247
  m.caps = cleanCaps(ch.caps).filter((c) => (m.cn ? SERVICE_CAPS : DEVICE_CAPS).includes(c))
248
248
  break
249
249
  }
250
+ case 'label': {
251
+ // RENOMBRAR un miembro. La etiqueta se escribía solo al admitir, con lo que el
252
+ // aparato se quedaba para siempre con el nombre que tuviera el día que entró
253
+ // (normalmente el apodo del usuario en ese momento), y para cambiarlo había que
254
+ // revocarlo y volver a emparejarlo. Es un nombre para el humano: no toca permisos
255
+ // ni llaves, pero se sella y se firma como cualquier otro cambio del acta.
256
+ const m = find(ch.pub)
257
+ if (!m) throw new Error('label: that member is not in the record')
258
+ m.label = String(ch.label || '').slice(0, 60)
259
+ break
260
+ }
250
261
  case 'remove': {
251
262
  const i = next.members.findIndex((m) => m.pub === ch.pub)
252
263
  if (i < 0) throw new Error('remove: that member is not in the record')
package/vault/core.js CHANGED
@@ -1191,6 +1191,22 @@ export async function createIdentityCore ({ kv: rawKv, peers, makeSync = null, k
1191
1191
  return { ok: true, seq: acta.seq }
1192
1192
  },
1193
1193
 
1194
+ /**
1195
+ * RENOMBRA un miembro (el nombre con el que lo reconoces). Se escribe en el acta y
1196
+ * TAMBIÉN en la delegación: son dos registros distintos —el acta dice quién es del
1197
+ * perfil, las delegaciones qué certs se emitieron— y las listas de dispositivos leen
1198
+ * la segunda, así que tocar solo una deja el nombre viejo a la vista.
1199
+ */
1200
+ async setLabel ({ pub, label } = {}) {
1201
+ const limpio = String(label || '').slice(0, 60)
1202
+ const acta = await sealChanges([{ op: 'label', pub, label: limpio }])
1203
+ const store = loadDelegations()
1204
+ let tocadas = 0
1205
+ for (const d of Object.values(store)) { if (d.sub === pub) { d.label = limpio; tocadas++ } }
1206
+ if (tocadas) saveDelegations(store)
1207
+ return { ok: true, seq: acta.seq, label: limpio, delegations: tocadas }
1208
+ },
1209
+
1194
1210
  async removeMember ({ pub } = {}) {
1195
1211
  const acta = await sealChanges([{ op: 'remove', pub }])
1196
1212
  // Expulsar rota la clave: el que sale no podrá abrir el contenido NUEVO. Lo que ya