@abraca/dabra 1.3.0 → 1.3.1
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 +68 -17
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +68 -17
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +22 -0
- package/package.json +1 -1
- package/src/AbracadabraClient.ts +37 -0
- package/src/webrtc/AbracadabraWebRTC.ts +64 -42
|
@@ -3252,6 +3252,30 @@ var AbracadabraClient = class {
|
|
|
3252
3252
|
auth: false
|
|
3253
3253
|
});
|
|
3254
3254
|
}
|
|
3255
|
+
/** Request a device session token after successful crypto auth. Requires valid JWT. */
|
|
3256
|
+
async requestDeviceSession(opts) {
|
|
3257
|
+
return this.request("POST", "/auth/device-session", { body: {
|
|
3258
|
+
publicKey: opts.publicKey,
|
|
3259
|
+
deviceName: opts.deviceName
|
|
3260
|
+
} });
|
|
3261
|
+
}
|
|
3262
|
+
/** Exchange a device session token for a fresh JWT. No biometric/passkey needed. */
|
|
3263
|
+
async refreshWithDeviceSession(sessionToken) {
|
|
3264
|
+
const res = await this.request("POST", "/auth/refresh", {
|
|
3265
|
+
body: { sessionToken },
|
|
3266
|
+
auth: false
|
|
3267
|
+
});
|
|
3268
|
+
this.token = res.token;
|
|
3269
|
+
return res.token;
|
|
3270
|
+
}
|
|
3271
|
+
/** List active device sessions for the authenticated user. */
|
|
3272
|
+
async listDeviceSessions() {
|
|
3273
|
+
return (await this.request("GET", "/auth/device-session")).sessions;
|
|
3274
|
+
}
|
|
3275
|
+
/** Revoke a device session by ID. */
|
|
3276
|
+
async revokeDeviceSession(sessionId) {
|
|
3277
|
+
await this.request("DELETE", `/auth/device-session/${encodeURIComponent(sessionId)}`);
|
|
3278
|
+
}
|
|
3255
3279
|
/**
|
|
3256
3280
|
* Fetch a short-lived anonymous pairing token for WebRTC signaling.
|
|
3257
3281
|
* No authentication required. The token only grants access to `__pairing_*` rooms.
|
|
@@ -10150,6 +10174,8 @@ var AbracadabraWebRTC = class AbracadabraWebRTC extends EventEmitter {
|
|
|
10150
10174
|
this.signaling.destroy();
|
|
10151
10175
|
this.signaling = null;
|
|
10152
10176
|
}
|
|
10177
|
+
this._resolvedE2ee = null;
|
|
10178
|
+
this._resolveE2eePromise = null;
|
|
10153
10179
|
this.removeAllListeners();
|
|
10154
10180
|
}
|
|
10155
10181
|
setMuted(muted) {
|
|
@@ -10291,28 +10317,54 @@ var AbracadabraWebRTC = class AbracadabraWebRTC extends EventEmitter {
|
|
|
10291
10317
|
return this._resolvedE2ee;
|
|
10292
10318
|
}
|
|
10293
10319
|
attachDataHandlers(peerId, pc) {
|
|
10294
|
-
if (this.config.e2ee)
|
|
10320
|
+
if (!this.config.e2ee) {
|
|
10321
|
+
this.startDataSync(peerId, pc);
|
|
10322
|
+
return;
|
|
10323
|
+
}
|
|
10324
|
+
let e2ee = null;
|
|
10325
|
+
const pendingMessages = [];
|
|
10326
|
+
let pendingKeyExchangeChannel = null;
|
|
10327
|
+
pc.router.on("channelMessage", async ({ name, data }) => {
|
|
10328
|
+
if (name !== KEY_EXCHANGE_CHANNEL) return;
|
|
10329
|
+
const buf = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
|
|
10330
|
+
if (!e2ee) {
|
|
10331
|
+
pendingMessages.push(buf);
|
|
10332
|
+
return;
|
|
10333
|
+
}
|
|
10334
|
+
try {
|
|
10335
|
+
await e2ee.handleKeyExchange(buf);
|
|
10336
|
+
} catch (err) {
|
|
10337
|
+
this.emit("e2eeFailed", {
|
|
10338
|
+
peerId,
|
|
10339
|
+
error: err
|
|
10340
|
+
});
|
|
10341
|
+
}
|
|
10342
|
+
});
|
|
10343
|
+
pc.router.on("channelOpen", ({ name, channel }) => {
|
|
10344
|
+
if (name !== KEY_EXCHANGE_CHANNEL) return;
|
|
10345
|
+
if (!e2ee) {
|
|
10346
|
+
pendingKeyExchangeChannel = channel;
|
|
10347
|
+
return;
|
|
10348
|
+
}
|
|
10349
|
+
channel.send(e2ee.getKeyExchangeMessage());
|
|
10350
|
+
});
|
|
10351
|
+
this.resolveE2ee().then(async (identity) => {
|
|
10295
10352
|
if (!identity) {
|
|
10296
10353
|
this.startDataSync(peerId, pc);
|
|
10297
10354
|
return;
|
|
10298
10355
|
}
|
|
10299
|
-
|
|
10356
|
+
e2ee = new E2EEChannel(identity, this.config.docId);
|
|
10300
10357
|
this.e2eeChannels.set(peerId, e2ee);
|
|
10301
10358
|
pc.router.setEncryptor(e2ee);
|
|
10302
|
-
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
}
|
|
10312
|
-
});
|
|
10313
|
-
pc.router.on("channelOpen", ({ name, channel }) => {
|
|
10314
|
-
if (name === KEY_EXCHANGE_CHANNEL) channel.send(e2ee.getKeyExchangeMessage());
|
|
10315
|
-
});
|
|
10359
|
+
if (pendingKeyExchangeChannel) pendingKeyExchangeChannel.send(e2ee.getKeyExchangeMessage());
|
|
10360
|
+
for (const msg of pendingMessages) try {
|
|
10361
|
+
await e2ee.handleKeyExchange(msg);
|
|
10362
|
+
} catch (err) {
|
|
10363
|
+
this.emit("e2eeFailed", {
|
|
10364
|
+
peerId,
|
|
10365
|
+
error: err
|
|
10366
|
+
});
|
|
10367
|
+
}
|
|
10316
10368
|
e2ee.on("established", () => {
|
|
10317
10369
|
this.emit("e2eeEstablished", { peerId });
|
|
10318
10370
|
this.startDataSync(peerId, pc);
|
|
@@ -10330,7 +10382,6 @@ var AbracadabraWebRTC = class AbracadabraWebRTC extends EventEmitter {
|
|
|
10330
10382
|
});
|
|
10331
10383
|
this.startDataSync(peerId, pc);
|
|
10332
10384
|
});
|
|
10333
|
-
else this.startDataSync(peerId, pc);
|
|
10334
10385
|
}
|
|
10335
10386
|
startDataSync(peerId, pc) {
|
|
10336
10387
|
if (this.config.document && this.config.enableDocSync) {
|