@xnetjs/react 2.1.0 → 2.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/{chunk-H44ZSIH4.js → chunk-5ILJMPKO.js} +29 -6
- package/dist/{chunk-ANCTAEML.js → chunk-CZUUWSJ7.js} +254 -116
- package/dist/{chunk-SZQNGRTO.js → chunk-KK6VADMZ.js} +1 -1
- package/dist/{chunk-HTFAHJQK.js → chunk-QSJJNEFY.js} +1 -1
- package/dist/{chunk-ZGP56IIJ.js → chunk-RW3DSDKO.js} +1 -1
- package/dist/{chunk-VZMZQTR7.js → chunk-UVJJN33U.js} +2 -2
- package/dist/core.js +3 -3
- package/dist/database.js +2 -2
- package/dist/{experimental-DyPoZcJT.d.ts → experimental-Dv0MIlsc.d.ts} +65 -3
- package/dist/experimental.d.ts +1 -1
- package/dist/experimental.js +3 -3
- package/dist/index.d.ts +61 -5
- package/dist/index.js +59 -12
- package/dist/internal.js +2 -2
- package/package.json +10 -10
|
@@ -282,13 +282,33 @@ function scheduleIdle(fn) {
|
|
|
282
282
|
import { createUCAN } from "@xnetjs/identity";
|
|
283
283
|
import { useCallback } from "react";
|
|
284
284
|
var HUB_CAPABILITIES = [
|
|
285
|
-
|
|
286
|
-
{ with: "*", can: "
|
|
287
|
-
{ with: "*", can: "
|
|
288
|
-
{ with: "*", can: "
|
|
289
|
-
{ with: "*", can: "
|
|
285
|
+
// Connection + rooms: room-level authorization happens hub-side.
|
|
286
|
+
{ with: "*", can: "hub/connect" },
|
|
287
|
+
{ with: "*", can: "hub/signal" },
|
|
288
|
+
{ with: "*", can: "hub/relay" },
|
|
289
|
+
{ with: "*", can: "hub/query" },
|
|
290
|
+
{ with: "*", can: "hub/backup" },
|
|
291
|
+
// Per-DID stores: backup blobs, files, query, search shards.
|
|
292
|
+
{ with: "*", can: "backup/read" },
|
|
293
|
+
{ with: "*", can: "backup/write" },
|
|
294
|
+
{ with: "*", can: "backup/delete" },
|
|
295
|
+
{ with: "*", can: "files/read" },
|
|
296
|
+
{ with: "*", can: "files/write" },
|
|
297
|
+
{ with: "*", can: "query/read" },
|
|
298
|
+
{ with: "*", can: "index/write" },
|
|
299
|
+
// Calls (0167) + push registration (0168) + own-usage telemetry (0187).
|
|
300
|
+
{ with: "*", can: "call/join" },
|
|
301
|
+
{ with: "*", can: "call/signal" },
|
|
302
|
+
{ with: "*", can: "notify/register" },
|
|
303
|
+
{ with: "*", can: "telemetry/ingest" }
|
|
290
304
|
];
|
|
291
305
|
var HUB_TOKEN_TTL_SECONDS = 60 * 60 * 24;
|
|
306
|
+
var mintNonce = () => {
|
|
307
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
308
|
+
return crypto.randomUUID();
|
|
309
|
+
}
|
|
310
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
311
|
+
};
|
|
292
312
|
function useHubAuthToken(input) {
|
|
293
313
|
const { authorDID, signingKey, hubUrl, autoAuth, staticHubAuthToken } = input;
|
|
294
314
|
return useCallback(async () => {
|
|
@@ -300,9 +320,12 @@ function useHubAuthToken(input) {
|
|
|
300
320
|
return createUCAN({
|
|
301
321
|
issuer: authorDID,
|
|
302
322
|
issuerKey: signingKey,
|
|
323
|
+
// The hub accepts its DID or its URL as audience (audienceAccepted);
|
|
324
|
+
// the URL is what the client reliably knows before connecting.
|
|
303
325
|
audience: hubUrl,
|
|
304
326
|
capabilities: HUB_CAPABILITIES,
|
|
305
|
-
expiration: Math.floor(Date.now() / 1e3) + HUB_TOKEN_TTL_SECONDS
|
|
327
|
+
expiration: Math.floor(Date.now() / 1e3) + HUB_TOKEN_TTL_SECONDS,
|
|
328
|
+
nonce: mintNonce()
|
|
306
329
|
});
|
|
307
330
|
}, [authorDID, autoAuth, signingKey, hubUrl, staticHubAuthToken]);
|
|
308
331
|
}
|