@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.
@@ -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
- { with: "*", can: "hub/*" },
286
- { with: "*", can: "backup/*" },
287
- { with: "*", can: "files/*" },
288
- { with: "*", can: "query/*" },
289
- { with: "*", can: "index/*" }
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
  }