wire-mesh-core 1.22.0 → 1.24.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.
@@ -0,0 +1,27 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/domain/relay-use-gate.ts
3
+ /** An in-memory, per-connection authorization set. Keyed by Connection identity (reference equality), matching RelayHub's own registry -- a connection that reconnects is a new object and starts unauthorized again, exactly as a fresh relay-hub registration would. */
4
+ function createRelayUseAuthorizationTracker() {
5
+ const authorized = /* @__PURE__ */ new Set();
6
+ return {
7
+ isAuthorized: (connection) => authorized.has(connection),
8
+ authorize: (connection) => {
9
+ authorized.add(connection);
10
+ },
11
+ revoke: (connection) => {
12
+ authorized.delete(connection);
13
+ }
14
+ };
15
+ }
16
+ /**
17
+ * Wraps a RelayHub's own onFrame with the relay:use check: a relay-connect from an unauthorized connection is silently dropped before ever reaching the hub, matching relay-connect-frame's own existing "no error frame defined for this" precedent for an unresolvable request (spec/transport.cddl, relay-hub.ts's own handleFrame comment for an unknown target-device). Every other frame type passes through unconditionally -- gossip needs no gate (it carries no relay effect on its own), and relay-data needs none either, since it can only ever act within a pairing that itself required an authorized relay-connect to establish in the first place; gating it again would be redundant, not additionally safe.
18
+ */
19
+ function createGatedRelayFrameHandler(options) {
20
+ return async function gatedOnFrame(connection, frame) {
21
+ if (frame.type === "relay-connect" && !options.isAuthorized(connection)) return;
22
+ await options.onFrame(connection, frame);
23
+ };
24
+ }
25
+ //#endregion
26
+ exports.createGatedRelayFrameHandler = createGatedRelayFrameHandler;
27
+ exports.createRelayUseAuthorizationTracker = createRelayUseAuthorizationTracker;
@@ -0,0 +1,23 @@
1
+ import { D as Frame } from "../protocol-l9RMR3s5.cjs";
2
+ import { t as Connection } from "../transport-Baipikk7.cjs";
3
+ //#region src/domain/relay-use-gate.d.ts
4
+ export interface RelayUseAuthorizationTracker {
5
+ /** True once authorize() has been called for this exact connection and revoke() has not been called since. */
6
+ isAuthorized: (connection: Readonly<Connection>) => boolean;
7
+ /** Marks a connection as holding a currently-valid relay:use grant -- called from the accepting side of a capability-request/capability-grant-ok exchange once it decides to grant. */
8
+ authorize: (connection: Readonly<Connection>) => void;
9
+ /** Withdraws a connection's own authorization, e.g. once its granted token's own expiry has passed or it was revoked. Tracking here is a live boolean, not the token itself -- a caller enforcing expiry calls this when it decides the grant is no longer current. */
10
+ revoke: (connection: Readonly<Connection>) => void;
11
+ }
12
+ /** An in-memory, per-connection authorization set. Keyed by Connection identity (reference equality), matching RelayHub's own registry -- a connection that reconnects is a new object and starts unauthorized again, exactly as a fresh relay-hub registration would. */
13
+ export declare function createRelayUseAuthorizationTracker(): RelayUseAuthorizationTracker;
14
+ export interface CreateGatedRelayFrameHandlerOptions {
15
+ /** The RelayHub method this gate wraps -- typically a real RelayHub's own onFrame (wire-mesh#102), but accepting just the one method it needs keeps this module decoupled from RelayHub's full interface. */
16
+ onFrame: (connection: Readonly<Connection>, frame: Frame) => Promise<void>;
17
+ isAuthorized: (connection: Readonly<Connection>) => boolean;
18
+ }
19
+ /**
20
+ * Wraps a RelayHub's own onFrame with the relay:use check: a relay-connect from an unauthorized connection is silently dropped before ever reaching the hub, matching relay-connect-frame's own existing "no error frame defined for this" precedent for an unresolvable request (spec/transport.cddl, relay-hub.ts's own handleFrame comment for an unknown target-device). Every other frame type passes through unconditionally -- gossip needs no gate (it carries no relay effect on its own), and relay-data needs none either, since it can only ever act within a pairing that itself required an authorized relay-connect to establish in the first place; gating it again would be redundant, not additionally safe.
21
+ */
22
+ export declare function createGatedRelayFrameHandler(options: Readonly<CreateGatedRelayFrameHandlerOptions>): (connection: Readonly<Connection>, frame: Frame) => Promise<void>;
23
+ //#endregion
@@ -0,0 +1,23 @@
1
+ import { D as Frame } from "../protocol-l9RMR3s5.mjs";
2
+ import { t as Connection } from "../transport-DWbvUc3L.mjs";
3
+ //#region src/domain/relay-use-gate.d.ts
4
+ export interface RelayUseAuthorizationTracker {
5
+ /** True once authorize() has been called for this exact connection and revoke() has not been called since. */
6
+ isAuthorized: (connection: Readonly<Connection>) => boolean;
7
+ /** Marks a connection as holding a currently-valid relay:use grant -- called from the accepting side of a capability-request/capability-grant-ok exchange once it decides to grant. */
8
+ authorize: (connection: Readonly<Connection>) => void;
9
+ /** Withdraws a connection's own authorization, e.g. once its granted token's own expiry has passed or it was revoked. Tracking here is a live boolean, not the token itself -- a caller enforcing expiry calls this when it decides the grant is no longer current. */
10
+ revoke: (connection: Readonly<Connection>) => void;
11
+ }
12
+ /** An in-memory, per-connection authorization set. Keyed by Connection identity (reference equality), matching RelayHub's own registry -- a connection that reconnects is a new object and starts unauthorized again, exactly as a fresh relay-hub registration would. */
13
+ export declare function createRelayUseAuthorizationTracker(): RelayUseAuthorizationTracker;
14
+ export interface CreateGatedRelayFrameHandlerOptions {
15
+ /** The RelayHub method this gate wraps -- typically a real RelayHub's own onFrame (wire-mesh#102), but accepting just the one method it needs keeps this module decoupled from RelayHub's full interface. */
16
+ onFrame: (connection: Readonly<Connection>, frame: Frame) => Promise<void>;
17
+ isAuthorized: (connection: Readonly<Connection>) => boolean;
18
+ }
19
+ /**
20
+ * Wraps a RelayHub's own onFrame with the relay:use check: a relay-connect from an unauthorized connection is silently dropped before ever reaching the hub, matching relay-connect-frame's own existing "no error frame defined for this" precedent for an unresolvable request (spec/transport.cddl, relay-hub.ts's own handleFrame comment for an unknown target-device). Every other frame type passes through unconditionally -- gossip needs no gate (it carries no relay effect on its own), and relay-data needs none either, since it can only ever act within a pairing that itself required an authorized relay-connect to establish in the first place; gating it again would be redundant, not additionally safe.
21
+ */
22
+ export declare function createGatedRelayFrameHandler(options: Readonly<CreateGatedRelayFrameHandlerOptions>): (connection: Readonly<Connection>, frame: Frame) => Promise<void>;
23
+ //#endregion
@@ -0,0 +1,25 @@
1
+ //#region src/domain/relay-use-gate.ts
2
+ /** An in-memory, per-connection authorization set. Keyed by Connection identity (reference equality), matching RelayHub's own registry -- a connection that reconnects is a new object and starts unauthorized again, exactly as a fresh relay-hub registration would. */
3
+ function createRelayUseAuthorizationTracker() {
4
+ const authorized = /* @__PURE__ */ new Set();
5
+ return {
6
+ isAuthorized: (connection) => authorized.has(connection),
7
+ authorize: (connection) => {
8
+ authorized.add(connection);
9
+ },
10
+ revoke: (connection) => {
11
+ authorized.delete(connection);
12
+ }
13
+ };
14
+ }
15
+ /**
16
+ * Wraps a RelayHub's own onFrame with the relay:use check: a relay-connect from an unauthorized connection is silently dropped before ever reaching the hub, matching relay-connect-frame's own existing "no error frame defined for this" precedent for an unresolvable request (spec/transport.cddl, relay-hub.ts's own handleFrame comment for an unknown target-device). Every other frame type passes through unconditionally -- gossip needs no gate (it carries no relay effect on its own), and relay-data needs none either, since it can only ever act within a pairing that itself required an authorized relay-connect to establish in the first place; gating it again would be redundant, not additionally safe.
17
+ */
18
+ function createGatedRelayFrameHandler(options) {
19
+ return async function gatedOnFrame(connection, frame) {
20
+ if (frame.type === "relay-connect" && !options.isAuthorized(connection)) return;
21
+ await options.onFrame(connection, frame);
22
+ };
23
+ }
24
+ //#endregion
25
+ export { createGatedRelayFrameHandler, createRelayUseAuthorizationTracker };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wire-mesh-core",
3
- "version": "1.22.0",
3
+ "version": "1.24.0",
4
4
  "type": "module",
5
5
  "packageManager": "pnpm@12.4.1+sha512.2e81e399d73fe8390dab25e06aa788ab7a5908248d2f5a370f82b481147a6a7a367bf8048f9a6fdb6460f21a66f0542dedb8b94ca2c8723596741920b1656d4c",
6
6
  "repository": {
@@ -114,6 +114,10 @@
114
114
  "import": "./dist/domain/relay-hub.mjs",
115
115
  "require": "./dist/domain/relay-hub.cjs"
116
116
  },
117
+ "./domain/relay-use-gate": {
118
+ "import": "./dist/domain/relay-use-gate.mjs",
119
+ "require": "./dist/domain/relay-use-gate.cjs"
120
+ },
117
121
  "./domain/revocation-view": {
118
122
  "import": "./dist/domain/revocation-view.mjs",
119
123
  "require": "./dist/domain/revocation-view.cjs"