@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
|
@@ -3222,6 +3222,30 @@ var AbracadabraClient = class {
|
|
|
3222
3222
|
auth: false
|
|
3223
3223
|
});
|
|
3224
3224
|
}
|
|
3225
|
+
/** Request a device session token after successful crypto auth. Requires valid JWT. */
|
|
3226
|
+
async requestDeviceSession(opts) {
|
|
3227
|
+
return this.request("POST", "/auth/device-session", { body: {
|
|
3228
|
+
publicKey: opts.publicKey,
|
|
3229
|
+
deviceName: opts.deviceName
|
|
3230
|
+
} });
|
|
3231
|
+
}
|
|
3232
|
+
/** Exchange a device session token for a fresh JWT. No biometric/passkey needed. */
|
|
3233
|
+
async refreshWithDeviceSession(sessionToken) {
|
|
3234
|
+
const res = await this.request("POST", "/auth/refresh", {
|
|
3235
|
+
body: { sessionToken },
|
|
3236
|
+
auth: false
|
|
3237
|
+
});
|
|
3238
|
+
this.token = res.token;
|
|
3239
|
+
return res.token;
|
|
3240
|
+
}
|
|
3241
|
+
/** List active device sessions for the authenticated user. */
|
|
3242
|
+
async listDeviceSessions() {
|
|
3243
|
+
return (await this.request("GET", "/auth/device-session")).sessions;
|
|
3244
|
+
}
|
|
3245
|
+
/** Revoke a device session by ID. */
|
|
3246
|
+
async revokeDeviceSession(sessionId) {
|
|
3247
|
+
await this.request("DELETE", `/auth/device-session/${encodeURIComponent(sessionId)}`);
|
|
3248
|
+
}
|
|
3225
3249
|
/**
|
|
3226
3250
|
* Fetch a short-lived anonymous pairing token for WebRTC signaling.
|
|
3227
3251
|
* No authentication required. The token only grants access to `__pairing_*` rooms.
|
|
@@ -10098,6 +10122,8 @@ var AbracadabraWebRTC = class AbracadabraWebRTC extends EventEmitter {
|
|
|
10098
10122
|
this.signaling.destroy();
|
|
10099
10123
|
this.signaling = null;
|
|
10100
10124
|
}
|
|
10125
|
+
this._resolvedE2ee = null;
|
|
10126
|
+
this._resolveE2eePromise = null;
|
|
10101
10127
|
this.removeAllListeners();
|
|
10102
10128
|
}
|
|
10103
10129
|
setMuted(muted) {
|
|
@@ -10239,28 +10265,54 @@ var AbracadabraWebRTC = class AbracadabraWebRTC extends EventEmitter {
|
|
|
10239
10265
|
return this._resolvedE2ee;
|
|
10240
10266
|
}
|
|
10241
10267
|
attachDataHandlers(peerId, pc) {
|
|
10242
|
-
if (this.config.e2ee)
|
|
10268
|
+
if (!this.config.e2ee) {
|
|
10269
|
+
this.startDataSync(peerId, pc);
|
|
10270
|
+
return;
|
|
10271
|
+
}
|
|
10272
|
+
let e2ee = null;
|
|
10273
|
+
const pendingMessages = [];
|
|
10274
|
+
let pendingKeyExchangeChannel = null;
|
|
10275
|
+
pc.router.on("channelMessage", async ({ name, data }) => {
|
|
10276
|
+
if (name !== KEY_EXCHANGE_CHANNEL) return;
|
|
10277
|
+
const buf = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
|
|
10278
|
+
if (!e2ee) {
|
|
10279
|
+
pendingMessages.push(buf);
|
|
10280
|
+
return;
|
|
10281
|
+
}
|
|
10282
|
+
try {
|
|
10283
|
+
await e2ee.handleKeyExchange(buf);
|
|
10284
|
+
} catch (err) {
|
|
10285
|
+
this.emit("e2eeFailed", {
|
|
10286
|
+
peerId,
|
|
10287
|
+
error: err
|
|
10288
|
+
});
|
|
10289
|
+
}
|
|
10290
|
+
});
|
|
10291
|
+
pc.router.on("channelOpen", ({ name, channel }) => {
|
|
10292
|
+
if (name !== KEY_EXCHANGE_CHANNEL) return;
|
|
10293
|
+
if (!e2ee) {
|
|
10294
|
+
pendingKeyExchangeChannel = channel;
|
|
10295
|
+
return;
|
|
10296
|
+
}
|
|
10297
|
+
channel.send(e2ee.getKeyExchangeMessage());
|
|
10298
|
+
});
|
|
10299
|
+
this.resolveE2ee().then(async (identity) => {
|
|
10243
10300
|
if (!identity) {
|
|
10244
10301
|
this.startDataSync(peerId, pc);
|
|
10245
10302
|
return;
|
|
10246
10303
|
}
|
|
10247
|
-
|
|
10304
|
+
e2ee = new E2EEChannel(identity, this.config.docId);
|
|
10248
10305
|
this.e2eeChannels.set(peerId, e2ee);
|
|
10249
10306
|
pc.router.setEncryptor(e2ee);
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
|
|
10256
|
-
|
|
10257
|
-
|
|
10258
|
-
|
|
10259
|
-
}
|
|
10260
|
-
});
|
|
10261
|
-
pc.router.on("channelOpen", ({ name, channel }) => {
|
|
10262
|
-
if (name === KEY_EXCHANGE_CHANNEL) channel.send(e2ee.getKeyExchangeMessage());
|
|
10263
|
-
});
|
|
10307
|
+
if (pendingKeyExchangeChannel) pendingKeyExchangeChannel.send(e2ee.getKeyExchangeMessage());
|
|
10308
|
+
for (const msg of pendingMessages) try {
|
|
10309
|
+
await e2ee.handleKeyExchange(msg);
|
|
10310
|
+
} catch (err) {
|
|
10311
|
+
this.emit("e2eeFailed", {
|
|
10312
|
+
peerId,
|
|
10313
|
+
error: err
|
|
10314
|
+
});
|
|
10315
|
+
}
|
|
10264
10316
|
e2ee.on("established", () => {
|
|
10265
10317
|
this.emit("e2eeEstablished", { peerId });
|
|
10266
10318
|
this.startDataSync(peerId, pc);
|
|
@@ -10278,7 +10330,6 @@ var AbracadabraWebRTC = class AbracadabraWebRTC extends EventEmitter {
|
|
|
10278
10330
|
});
|
|
10279
10331
|
this.startDataSync(peerId, pc);
|
|
10280
10332
|
});
|
|
10281
|
-
else this.startDataSync(peerId, pc);
|
|
10282
10333
|
}
|
|
10283
10334
|
startDataSync(peerId, pc) {
|
|
10284
10335
|
if (this.config.document && this.config.enableDocSync) {
|