@abraca/dabra 1.2.0 → 1.3.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/dist/abracadabra-provider.cjs +54 -3
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +54 -3
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +13 -3
- package/package.json +1 -1
- package/src/CryptoIdentityKeystore.ts +23 -0
- package/src/IdentityDoc.ts +2 -2
- package/src/webrtc/AbracadabraWebRTC.ts +61 -29
- package/src/webrtc/types.ts +1 -1
|
@@ -7340,6 +7340,30 @@ var CryptoIdentityKeystore = class {
|
|
|
7340
7340
|
db.close();
|
|
7341
7341
|
}
|
|
7342
7342
|
}
|
|
7343
|
+
/**
|
|
7344
|
+
* Updates the cached username for a given credential (or the first cached identity).
|
|
7345
|
+
* Call this after the user sets/changes their display name so it persists across devices.
|
|
7346
|
+
*/
|
|
7347
|
+
async setUsername(username, credentialIdHint) {
|
|
7348
|
+
const db = await openDb$4();
|
|
7349
|
+
try {
|
|
7350
|
+
if (credentialIdHint) {
|
|
7351
|
+
const stored = await dbGet(db, credentialIdHint);
|
|
7352
|
+
if (stored) await dbPut(db, credentialIdHint, {
|
|
7353
|
+
...stored,
|
|
7354
|
+
username
|
|
7355
|
+
});
|
|
7356
|
+
} else {
|
|
7357
|
+
const all = await dbGetAll(db);
|
|
7358
|
+
if (all.length > 0) await dbPut(db, all[0].key, {
|
|
7359
|
+
...all[0].value,
|
|
7360
|
+
username
|
|
7361
|
+
});
|
|
7362
|
+
}
|
|
7363
|
+
} finally {
|
|
7364
|
+
db.close();
|
|
7365
|
+
}
|
|
7366
|
+
}
|
|
7343
7367
|
/** Returns true if an identity is cached in IndexedDB. */
|
|
7344
7368
|
async hasIdentity() {
|
|
7345
7369
|
const db = await openDb$4();
|
|
@@ -9984,6 +10008,8 @@ var AbracadabraWebRTC = class AbracadabraWebRTC extends EventEmitter {
|
|
|
9984
10008
|
this.yjsChannels = /* @__PURE__ */ new Map();
|
|
9985
10009
|
this.fileChannels = /* @__PURE__ */ new Map();
|
|
9986
10010
|
this.e2eeChannels = /* @__PURE__ */ new Map();
|
|
10011
|
+
this._resolvedE2ee = null;
|
|
10012
|
+
this._resolveE2eePromise = null;
|
|
9987
10013
|
this.peers = /* @__PURE__ */ new Map();
|
|
9988
10014
|
this.localPeerId = null;
|
|
9989
10015
|
this.isConnected = false;
|
|
@@ -10250,9 +10276,27 @@ var AbracadabraWebRTC = class AbracadabraWebRTC extends EventEmitter {
|
|
|
10250
10276
|
this.attachDataHandlers(peerId, pc);
|
|
10251
10277
|
return pc;
|
|
10252
10278
|
}
|
|
10279
|
+
/** Resolve the E2EE identity, supporting both pre-resolved objects and lazy factories. */
|
|
10280
|
+
async resolveE2ee() {
|
|
10281
|
+
if (this._resolvedE2ee) return this._resolvedE2ee;
|
|
10282
|
+
if (!this.config.e2ee) return null;
|
|
10283
|
+
if (typeof this.config.e2ee === "function") {
|
|
10284
|
+
if (!this._resolveE2eePromise) this._resolveE2eePromise = this.config.e2ee().then((id) => {
|
|
10285
|
+
this._resolvedE2ee = id;
|
|
10286
|
+
return id;
|
|
10287
|
+
});
|
|
10288
|
+
return this._resolveE2eePromise;
|
|
10289
|
+
}
|
|
10290
|
+
this._resolvedE2ee = this.config.e2ee;
|
|
10291
|
+
return this._resolvedE2ee;
|
|
10292
|
+
}
|
|
10253
10293
|
attachDataHandlers(peerId, pc) {
|
|
10254
|
-
if (this.config.e2ee) {
|
|
10255
|
-
|
|
10294
|
+
if (this.config.e2ee) this.resolveE2ee().then((identity) => {
|
|
10295
|
+
if (!identity) {
|
|
10296
|
+
this.startDataSync(peerId, pc);
|
|
10297
|
+
return;
|
|
10298
|
+
}
|
|
10299
|
+
const e2ee = new E2EEChannel(identity, this.config.docId);
|
|
10256
10300
|
this.e2eeChannels.set(peerId, e2ee);
|
|
10257
10301
|
pc.router.setEncryptor(e2ee);
|
|
10258
10302
|
pc.router.on("channelMessage", async ({ name, data }) => {
|
|
@@ -10279,7 +10323,14 @@ var AbracadabraWebRTC = class AbracadabraWebRTC extends EventEmitter {
|
|
|
10279
10323
|
error: err
|
|
10280
10324
|
});
|
|
10281
10325
|
});
|
|
10282
|
-
}
|
|
10326
|
+
}).catch((err) => {
|
|
10327
|
+
this.emit("e2eeFailed", {
|
|
10328
|
+
peerId,
|
|
10329
|
+
error: err
|
|
10330
|
+
});
|
|
10331
|
+
this.startDataSync(peerId, pc);
|
|
10332
|
+
});
|
|
10333
|
+
else this.startDataSync(peerId, pc);
|
|
10283
10334
|
}
|
|
10284
10335
|
startDataSync(peerId, pc) {
|
|
10285
10336
|
if (this.config.document && this.config.enableDocSync) {
|