wire-mesh-core 3.7.2 → 3.9.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.
Files changed (121) hide show
  1. package/dist/adapters/byte-stream-connection.d.cts +2 -2
  2. package/dist/adapters/byte-stream-connection.d.mts +2 -2
  3. package/dist/adapters/frame-codec.d.cts +1 -1
  4. package/dist/adapters/frame-codec.d.mts +1 -1
  5. package/dist/adapters/node-identity.d.cts +2 -2
  6. package/dist/adapters/node-identity.d.mts +2 -2
  7. package/dist/adapters/tcp-transport.d.cts +1 -1
  8. package/dist/adapters/tcp-transport.d.mts +1 -1
  9. package/dist/adapters/threshold-identity.d.cts +2 -2
  10. package/dist/adapters/threshold-identity.d.mts +2 -2
  11. package/dist/adapters/threshold-wasm.d.cts +1 -1
  12. package/dist/adapters/threshold-wasm.d.mts +1 -1
  13. package/dist/adapters/tls-transport.d.cts +1 -1
  14. package/dist/adapters/tls-transport.d.mts +1 -1
  15. package/dist/domain/advert-extension-policy.d.cts +1 -1
  16. package/dist/domain/advert-extension-policy.d.mts +1 -1
  17. package/dist/domain/bulk.d.cts +2 -2
  18. package/dist/domain/bulk.d.mts +2 -2
  19. package/dist/domain/capability-grant.cjs +4 -4
  20. package/dist/domain/capability-grant.d.cts +3 -3
  21. package/dist/domain/capability-grant.d.mts +3 -3
  22. package/dist/domain/capability-grant.mjs +2 -2
  23. package/dist/domain/capability-request.cjs +66 -6
  24. package/dist/domain/capability-request.d.cts +21 -3
  25. package/dist/domain/capability-request.d.mts +21 -3
  26. package/dist/domain/capability-request.mjs +64 -6
  27. package/dist/domain/coordinator-election.d.cts +1 -1
  28. package/dist/domain/coordinator-election.d.mts +1 -1
  29. package/dist/domain/data-sync.d.cts +2 -2
  30. package/dist/domain/data-sync.d.mts +2 -2
  31. package/dist/domain/device-id.d.cts +1 -1
  32. package/dist/domain/device-id.d.mts +1 -1
  33. package/dist/domain/direct-manage-request.d.cts +2 -2
  34. package/dist/domain/direct-manage-request.d.mts +2 -2
  35. package/dist/domain/gossip-expansion.d.cts +1 -1
  36. package/dist/domain/gossip-expansion.d.mts +1 -1
  37. package/dist/domain/grant-candidates.cjs +2 -2
  38. package/dist/domain/grant-candidates.d.cts +1 -1
  39. package/dist/domain/grant-candidates.d.mts +1 -1
  40. package/dist/domain/grant-candidates.mjs +1 -1
  41. package/dist/domain/handshake.d.cts +1 -1
  42. package/dist/domain/handshake.d.mts +1 -1
  43. package/dist/domain/hub-mailbox.d.cts +1 -1
  44. package/dist/domain/hub-mailbox.d.mts +1 -1
  45. package/dist/domain/mesh-session.cjs +3 -3
  46. package/dist/domain/mesh-session.d.cts +3 -3
  47. package/dist/domain/mesh-session.d.mts +3 -3
  48. package/dist/domain/mesh-session.mjs +2 -2
  49. package/dist/domain/notice-board.d.cts +3 -3
  50. package/dist/domain/notice-board.d.mts +3 -3
  51. package/dist/domain/path-trace.d.cts +1 -1
  52. package/dist/domain/path-trace.d.mts +1 -1
  53. package/dist/domain/peer-advert.cjs +2 -2
  54. package/dist/domain/peer-advert.d.cts +2 -2
  55. package/dist/domain/peer-advert.d.mts +2 -2
  56. package/dist/domain/peer-advert.mjs +1 -1
  57. package/dist/domain/relay-advert.d.cts +1 -1
  58. package/dist/domain/relay-advert.d.mts +1 -1
  59. package/dist/domain/relay-hub.d.cts +2 -2
  60. package/dist/domain/relay-hub.d.mts +2 -2
  61. package/dist/domain/relay-use-gate.d.cts +2 -2
  62. package/dist/domain/relay-use-gate.d.mts +2 -2
  63. package/dist/domain/revocation-view.cjs +2 -2
  64. package/dist/domain/revocation-view.d.cts +2 -2
  65. package/dist/domain/revocation-view.d.mts +2 -2
  66. package/dist/domain/revocation-view.mjs +1 -1
  67. package/dist/domain/room-rekey.d.cts +3 -3
  68. package/dist/domain/room-rekey.d.mts +3 -3
  69. package/dist/domain/room-token-verification.cjs +2 -2
  70. package/dist/domain/room-token-verification.d.cts +1 -1
  71. package/dist/domain/room-token-verification.d.mts +1 -1
  72. package/dist/domain/room-token-verification.mjs +1 -1
  73. package/dist/domain/room.d.cts +4 -4
  74. package/dist/domain/room.d.mts +4 -4
  75. package/dist/domain/shard-manifest.d.cts +1 -1
  76. package/dist/domain/shard-manifest.d.mts +1 -1
  77. package/dist/domain/threshold-subject.cjs +2 -2
  78. package/dist/domain/threshold-subject.mjs +1 -1
  79. package/dist/domain/token-predicates.cjs +184 -0
  80. package/dist/domain/token-predicates.d.cts +2 -0
  81. package/dist/domain/token-predicates.d.mts +2 -0
  82. package/dist/domain/token-predicates.mjs +173 -0
  83. package/dist/{token-scope-CxHXTT3u.cjs → domain/token-scope.cjs} +3 -12
  84. package/dist/domain/token-scope.d.cts +11 -0
  85. package/dist/domain/token-scope.d.mts +11 -0
  86. package/dist/{token-scope-Z4bmci4M.mjs → domain/token-scope.mjs} +1 -1
  87. package/dist/domain/tokens.cjs +466 -7
  88. package/dist/domain/tokens.d.cts +131 -2
  89. package/dist/domain/tokens.d.mts +131 -2
  90. package/dist/domain/tokens.mjs +459 -2
  91. package/dist/domain/topology-snapshot.d.cts +1 -1
  92. package/dist/domain/topology-snapshot.d.mts +1 -1
  93. package/dist/domain/topology.d.cts +1 -1
  94. package/dist/domain/topology.d.mts +1 -1
  95. package/dist/domain/webrtc-signaling.cjs +2 -2
  96. package/dist/domain/webrtc-signaling.d.cts +2 -2
  97. package/dist/domain/webrtc-signaling.d.mts +2 -2
  98. package/dist/domain/webrtc-signaling.mjs +1 -1
  99. package/dist/generated/protocol.cjs +4 -1
  100. package/dist/generated/protocol.d.cts +1 -1
  101. package/dist/generated/protocol.d.mts +1 -1
  102. package/dist/generated/protocol.mjs +4 -1
  103. package/dist/{identity-DVCNuFLG.d.cts → identity-DJbr96J3.d.cts} +1 -1
  104. package/dist/{identity-DcaYgjXT.d.mts → identity-ViYdZrIU.d.mts} +1 -1
  105. package/dist/ports/identity.d.cts +1 -1
  106. package/dist/ports/identity.d.mts +1 -1
  107. package/dist/ports/transport.d.cts +1 -1
  108. package/dist/ports/transport.d.mts +1 -1
  109. package/dist/{protocol-DCDae3z4.d.cts → protocol-BgR1e_NI.d.cts} +3 -0
  110. package/dist/{protocol-DCDae3z4.d.mts → protocol-BgR1e_NI.d.mts} +3 -0
  111. package/dist/{room-token-verification-CkGnFuQc.d.mts → room-token-verification-BpQ6yJtj.d.cts} +2 -2
  112. package/dist/{room-token-verification-PSv4eQ1x.d.cts → room-token-verification-CTQSihUO.d.mts} +2 -2
  113. package/dist/token-predicates-C-aIe1DT.d.cts +72 -0
  114. package/dist/token-predicates-DqvyS7Y8.d.mts +72 -0
  115. package/dist/{transport-DIXjoQKn.d.cts → transport-DP3hdehk.d.cts} +1 -1
  116. package/dist/{transport-B0GywEzG.d.mts → transport-Dv_LTCsF.d.mts} +1 -1
  117. package/package.json +9 -1
  118. package/dist/tokens-CBiSYuzp.d.mts +0 -126
  119. package/dist/tokens-CMdWiRBb.mjs +0 -459
  120. package/dist/tokens-DSG3SDr8.cjs +0 -494
  121. package/dist/tokens-DqFu7iMX.d.cts +0 -126
@@ -1,5 +1,5 @@
1
- import { N as Frame } from "../protocol-DCDae3z4.cjs";
2
- import { t as Connection } from "../transport-DIXjoQKn.cjs";
1
+ import { N as Frame } from "../protocol-BgR1e_NI.cjs";
2
+ import { t as Connection } from "../transport-DP3hdehk.cjs";
3
3
  //#region src/adapters/byte-stream-connection.d.ts
4
4
  /** The largest frame body a peer may announce in a length prefix, matching the 100 MiB the `ws` package applies to one message on the same hub, so a WebSocket peer and a byte-stream peer are bounded alike. Without a bound a peer-controlled 4 GiB prefix makes the reader buffer until memory runs out. */
5
5
  export declare const MAX_FRAME_BYTES: number;
@@ -1,5 +1,5 @@
1
- import { N as Frame } from "../protocol-DCDae3z4.mjs";
2
- import { t as Connection } from "../transport-B0GywEzG.mjs";
1
+ import { N as Frame } from "../protocol-BgR1e_NI.mjs";
2
+ import { t as Connection } from "../transport-Dv_LTCsF.mjs";
3
3
  //#region src/adapters/byte-stream-connection.d.ts
4
4
  /** The largest frame body a peer may announce in a length prefix, matching the 100 MiB the `ws` package applies to one message on the same hub, so a WebSocket peer and a byte-stream peer are bounded alike. Without a bound a peer-controlled 4 GiB prefix makes the reader buffer until memory runs out. */
5
5
  export declare const MAX_FRAME_BYTES: number;
@@ -1,4 +1,4 @@
1
- import { D as DeviceId, N as Frame, ht as RelayDataFrame } from "../protocol-DCDae3z4.cjs";
1
+ import { D as DeviceId, N as Frame, ht as RelayDataFrame } from "../protocol-BgR1e_NI.cjs";
2
2
  //#region src/adapters/frame-codec.d.ts
3
3
  export declare function messageFromFrame(frame: Frame): Uint8Array<ArrayBuffer>;
4
4
  /** Wraps frame as a relay-data-frame's own opaque payload, stamping to-device when the caller knows which established pairing to address it to (wire-mesh#30) -- the outbound counterpart to tryDecodeFrame's own doc comment below, which describes the inbound side of the same relay-data envelope. Omitting toDevice leaves the frame unaddressed, which the receiving hub then routes via its own most-recently-established-pairing fallback. */
@@ -1,4 +1,4 @@
1
- import { D as DeviceId, N as Frame, ht as RelayDataFrame } from "../protocol-DCDae3z4.mjs";
1
+ import { D as DeviceId, N as Frame, ht as RelayDataFrame } from "../protocol-BgR1e_NI.mjs";
2
2
  //#region src/adapters/frame-codec.d.ts
3
3
  export declare function messageFromFrame(frame: Frame): Uint8Array<ArrayBuffer>;
4
4
  /** Wraps frame as a relay-data-frame's own opaque payload, stamping to-device when the caller knows which established pairing to address it to (wire-mesh#30) -- the outbound counterpart to tryDecodeFrame's own doc comment below, which describes the inbound side of the same relay-data envelope. Omitting toDevice leaves the frame unaddressed, which the receiving hub then routes via its own most-recently-established-pairing fallback. */
@@ -1,5 +1,5 @@
1
- import { B as IdentityKey, D as DeviceId } from "../protocol-DCDae3z4.cjs";
2
- import { t as IdentityPort } from "../identity-DVCNuFLG.cjs";
1
+ import { B as IdentityKey, D as DeviceId } from "../protocol-BgR1e_NI.cjs";
2
+ import { t as IdentityPort } from "../identity-DJbr96J3.cjs";
3
3
  import { webcrypto } from "node:crypto";
4
4
  //#region src/adapters/node-identity.d.ts
5
5
  export declare function deriveDeviceId(publicKey: Uint8Array): Promise<DeviceId>;
@@ -1,5 +1,5 @@
1
- import { B as IdentityKey, D as DeviceId } from "../protocol-DCDae3z4.mjs";
2
- import { t as IdentityPort } from "../identity-DcaYgjXT.mjs";
1
+ import { B as IdentityKey, D as DeviceId } from "../protocol-BgR1e_NI.mjs";
2
+ import { t as IdentityPort } from "../identity-ViYdZrIU.mjs";
3
3
  import { webcrypto } from "node:crypto";
4
4
  //#region src/adapters/node-identity.d.ts
5
5
  export declare function deriveDeviceId(publicKey: Uint8Array): Promise<DeviceId>;
@@ -1,4 +1,4 @@
1
- import { r as Transport } from "../transport-DIXjoQKn.cjs";
1
+ import { r as Transport } from "../transport-DP3hdehk.cjs";
2
2
  //#region src/adapters/tcp-transport.d.ts
3
3
  /** A Node net.Socket-based Transport: length-prefixed, CBOR-encoded frames over plain TCP -- matching Cascade's own transport shape, since interop with Cascade nodes is wire-mesh's stated goal. Framing (not TLS) is this adapter's own concern; a TLS-terminated variant is a separate adapter behind the same Transport contract. */
4
4
  export declare function createTcpTransport(): Transport;
@@ -1,4 +1,4 @@
1
- import { r as Transport } from "../transport-B0GywEzG.mjs";
1
+ import { r as Transport } from "../transport-Dv_LTCsF.mjs";
2
2
  //#region src/adapters/tcp-transport.d.ts
3
3
  /** A Node net.Socket-based Transport: length-prefixed, CBOR-encoded frames over plain TCP -- matching Cascade's own transport shape, since interop with Cascade nodes is wire-mesh's stated goal. Framing (not TLS) is this adapter's own concern; a TLS-terminated variant is a separate adapter behind the same Transport contract. */
4
4
  export declare function createTcpTransport(): Transport;
@@ -1,5 +1,5 @@
1
- import { D as DeviceId } from "../protocol-DCDae3z4.cjs";
2
- import { t as IdentityPort } from "../identity-DVCNuFLG.cjs";
1
+ import { D as DeviceId } from "../protocol-BgR1e_NI.cjs";
2
+ import { t as IdentityPort } from "../identity-DJbr96J3.cjs";
3
3
  import { DeviceKeyed } from "./threshold-wasm.cjs";
4
4
  import { ThresholdSubject } from "../domain/threshold-subject.cjs";
5
5
  //#region src/adapters/threshold-identity.d.ts
@@ -1,5 +1,5 @@
1
- import { D as DeviceId } from "../protocol-DCDae3z4.mjs";
2
- import { t as IdentityPort } from "../identity-DcaYgjXT.mjs";
1
+ import { D as DeviceId } from "../protocol-BgR1e_NI.mjs";
2
+ import { t as IdentityPort } from "../identity-ViYdZrIU.mjs";
3
3
  import { DeviceKeyed } from "./threshold-wasm.mjs";
4
4
  import { ThresholdSubject } from "../domain/threshold-subject.mjs";
5
5
  //#region src/adapters/threshold-identity.d.ts
@@ -1,4 +1,4 @@
1
- import { D as DeviceId } from "../protocol-DCDae3z4.cjs";
1
+ import { D as DeviceId } from "../protocol-BgR1e_NI.cjs";
2
2
  //#region src/adapters/threshold-wasm.d.ts
3
3
  /** One `(deviceId, bytes)` pair -- the wasm boundary's own encoding of a map keyed by participant, since wasm-bindgen has no built-in `Map<Uint8Array, Uint8Array>` marshalling. */
4
4
  export interface DeviceKeyed<T extends Uint8Array = Uint8Array<ArrayBuffer>> {
@@ -1,4 +1,4 @@
1
- import { D as DeviceId } from "../protocol-DCDae3z4.mjs";
1
+ import { D as DeviceId } from "../protocol-BgR1e_NI.mjs";
2
2
  //#region src/adapters/threshold-wasm.d.ts
3
3
  /** One `(deviceId, bytes)` pair -- the wasm boundary's own encoding of a map keyed by participant, since wasm-bindgen has no built-in `Map<Uint8Array, Uint8Array>` marshalling. */
4
4
  export interface DeviceKeyed<T extends Uint8Array = Uint8Array<ArrayBuffer>> {
@@ -1,4 +1,4 @@
1
- import { r as Transport } from "../transport-DIXjoQKn.cjs";
1
+ import { r as Transport } from "../transport-DP3hdehk.cjs";
2
2
  //#region src/adapters/tls-transport.d.ts
3
3
  export interface TlsIdentity {
4
4
  certificatePem: string;
@@ -1,4 +1,4 @@
1
- import { r as Transport } from "../transport-B0GywEzG.mjs";
1
+ import { r as Transport } from "../transport-Dv_LTCsF.mjs";
2
2
  //#region src/adapters/tls-transport.d.ts
3
3
  export interface TlsIdentity {
4
4
  certificatePem: string;
@@ -1,4 +1,4 @@
1
- import { et as PeerAdvert } from "../protocol-DCDae3z4.cjs";
1
+ import { et as PeerAdvert } from "../protocol-BgR1e_NI.cjs";
2
2
  //#region src/domain/advert-extension-policy.d.ts
3
3
  /** Whether one extension entry's value is one the hub will carry. Must be strict: a value with a field the validator did not expect is refused, since the point is that nothing unexpected is published. */
4
4
  export type ExtensionValidator = (value: unknown) => boolean;
@@ -1,4 +1,4 @@
1
- import { et as PeerAdvert } from "../protocol-DCDae3z4.mjs";
1
+ import { et as PeerAdvert } from "../protocol-BgR1e_NI.mjs";
2
2
  //#region src/domain/advert-extension-policy.d.ts
3
3
  /** Whether one extension entry's value is one the hub will carry. Must be strict: a value with a field the validator did not expect is refused, since the point is that nothing unexpected is published. */
4
4
  export type ExtensionValidator = (value: unknown) => boolean;
@@ -1,5 +1,5 @@
1
- import { D as DeviceId, N as Frame, V as ManageCommand, f as CapabilityScope, p as CapabilityToken } from "../protocol-DCDae3z4.cjs";
2
- import { t as Connection } from "../transport-DIXjoQKn.cjs";
1
+ import { D as DeviceId, N as Frame, V as ManageCommand, f as CapabilityScope, p as CapabilityToken } from "../protocol-BgR1e_NI.cjs";
2
+ import { t as Connection } from "../transport-DP3hdehk.cjs";
3
3
  import { t as KeyValueStorage } from "../storage-B403CRyu.cjs";
4
4
  import { IncomingManageRequest, MeshSession } from "./mesh-session.cjs";
5
5
  //#region src/domain/bulk.d.ts
@@ -1,5 +1,5 @@
1
- import { D as DeviceId, N as Frame, V as ManageCommand, f as CapabilityScope, p as CapabilityToken } from "../protocol-DCDae3z4.mjs";
2
- import { t as Connection } from "../transport-B0GywEzG.mjs";
1
+ import { D as DeviceId, N as Frame, V as ManageCommand, f as CapabilityScope, p as CapabilityToken } from "../protocol-BgR1e_NI.mjs";
2
+ import { t as Connection } from "../transport-Dv_LTCsF.mjs";
3
3
  import { t as KeyValueStorage } from "../storage-B403CRyu.mjs";
4
4
  import { IncomingManageRequest, MeshSession } from "./mesh-session.mjs";
5
5
  //#region src/domain/bulk.d.ts
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_generated_protocol = require("../generated/protocol.cjs");
3
- const require_token_scope = require("../token-scope-CxHXTT3u.cjs");
4
- const require_tokens = require("../tokens-DSG3SDr8.cjs");
3
+ const require_domain_token_scope = require("./token-scope.cjs");
4
+ const require_domain_tokens = require("./tokens.cjs");
5
5
  //#region src/domain/capability-grant.ts
6
6
  /**
7
7
  * The generic, capability-agnostic capability-grant primitive (wire-mesh#117, spec/management.cddl) -- the unsolicited push counterpart to capability-request.ts's own ask/response primitive. Where capability-request lifts core/room's room.join shape (a pull: the requester asks, the owner mints and returns a grant on the same response) out of that one domain, capability-grant lifts room.invite's own shape (a push: the owner mints unprompted and delivers the grant in the request itself, since there is no approval round-trip to carry it back) the same way. core/room's own room-client.ts is the reference consumer: it builds sendRoomInvite as a thin wrapper over sendCapabilityGrant below, and wires createRoomRouter's dispatch onto createCapabilityGrantHandler for the receiving side.
@@ -49,7 +49,7 @@ function createCapabilityGrantHandler(options) {
49
49
  return;
50
50
  }
51
51
  const grantedToken = parsed.data["granted-token"];
52
- const verdict = await require_tokens.verifyCapabilityToken(grantedToken, {
52
+ const verdict = await require_domain_tokens.verifyCapabilityToken(grantedToken, {
53
53
  identity: options.identity,
54
54
  clock: options.clock,
55
55
  revocation: options.revocation,
@@ -69,7 +69,7 @@ function createCapabilityGrantHandler(options) {
69
69
  });
70
70
  return;
71
71
  }
72
- if (!require_token_scope.scopeNarrows(verdict.claims.scope, incoming.scope)) {
72
+ if (!require_domain_token_scope.scopeNarrows(verdict.claims.scope, incoming.scope)) {
73
73
  await incoming.respond({
74
74
  result: "error",
75
75
  code: "scope_mismatch"
@@ -1,8 +1,8 @@
1
- import { D as DeviceId, V as ManageCommand, f as CapabilityScope, p as CapabilityToken } from "../protocol-DCDae3z4.cjs";
2
- import { t as IdentityPort } from "../identity-DVCNuFLG.cjs";
1
+ import { D as DeviceId, V as ManageCommand, f as CapabilityScope, p as CapabilityToken } from "../protocol-BgR1e_NI.cjs";
2
+ import { t as IdentityPort } from "../identity-DJbr96J3.cjs";
3
3
  import { t as Clock } from "../clock-DiSx-WKM.cjs";
4
4
  import { IncomingManageRequest, ManageOutcome, MeshSession } from "./mesh-session.cjs";
5
- import { a as RevocationCheck } from "../tokens-DqFu7iMX.cjs";
5
+ import { RevocationCheck } from "./tokens.cjs";
6
6
  //#region src/domain/capability-grant.d.ts
7
7
  /**
8
8
  * Builds a capability-grant command per management.cddl. The outer `manage-command.verb` is the capability string itself, the identical convention capability-request.ts's own buildCapabilityRequestCommand already establishes -- a receiver's per-capability handler is how it knows which grant this push is even for. `params.verb` is the fixed "capability.grant" marker. No scope or invitee field: manage-request-frame's own top-level scope already carries the former, and the request's own destination already carries the latter -- naming either a second time inside params could only ever disagree with the fact it duplicates.
@@ -1,8 +1,8 @@
1
- import { D as DeviceId, V as ManageCommand, f as CapabilityScope, p as CapabilityToken } from "../protocol-DCDae3z4.mjs";
2
- import { t as IdentityPort } from "../identity-DcaYgjXT.mjs";
1
+ import { D as DeviceId, V as ManageCommand, f as CapabilityScope, p as CapabilityToken } from "../protocol-BgR1e_NI.mjs";
2
+ import { t as IdentityPort } from "../identity-ViYdZrIU.mjs";
3
3
  import { t as Clock } from "../clock-DiSx-WKM.mjs";
4
4
  import { IncomingManageRequest, ManageOutcome, MeshSession } from "./mesh-session.mjs";
5
- import { a as RevocationCheck } from "../tokens-CBiSYuzp.mjs";
5
+ import { RevocationCheck } from "./tokens.mjs";
6
6
  //#region src/domain/capability-grant.d.ts
7
7
  /**
8
8
  * Builds a capability-grant command per management.cddl. The outer `manage-command.verb` is the capability string itself, the identical convention capability-request.ts's own buildCapabilityRequestCommand already establishes -- a receiver's per-capability handler is how it knows which grant this push is even for. `params.verb` is the fixed "capability.grant" marker. No scope or invitee field: manage-request-frame's own top-level scope already carries the former, and the request's own destination already carries the latter -- naming either a second time inside params could only ever disagree with the fact it duplicates.
@@ -1,6 +1,6 @@
1
1
  import { capabilityGrantSchema } from "../generated/protocol.mjs";
2
- import { n as scopeNarrows } from "../token-scope-Z4bmci4M.mjs";
3
- import { a as verifyCapabilityToken } from "../tokens-CMdWiRBb.mjs";
2
+ import { scopeNarrows } from "./token-scope.mjs";
3
+ import { verifyCapabilityToken } from "./tokens.mjs";
4
4
  //#region src/domain/capability-grant.ts
5
5
  /**
6
6
  * The generic, capability-agnostic capability-grant primitive (wire-mesh#117, spec/management.cddl) -- the unsolicited push counterpart to capability-request.ts's own ask/response primitive. Where capability-request lifts core/room's room.join shape (a pull: the requester asks, the owner mints and returns a grant on the same response) out of that one domain, capability-grant lifts room.invite's own shape (a push: the owner mints unprompted and delivers the grant in the request itself, since there is no approval round-trip to carry it back) the same way. core/room's own room-client.ts is the reference consumer: it builds sendRoomInvite as a thin wrapper over sendCapabilityGrant below, and wires createRoomRouter's dispatch onto createCapabilityGrantHandler for the receiving side.
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_generated_protocol = require("../generated/protocol.cjs");
3
- const require_tokens = require("../tokens-DSG3SDr8.cjs");
3
+ const require_domain_token_scope = require("./token-scope.cjs");
4
+ const require_domain_tokens = require("./tokens.cjs");
4
5
  //#region src/domain/capability-request.ts
5
6
  /**
6
7
  * The generic, capability-agnostic capability-request / capability-grant-ok primitive (wire-mesh#78, spec/management.cddl). Lifts core/room's own room.join shape -- an ungated ask, held open, a human (or any other domain-supplied decision) accepts or refuses, acceptance mints and returns a token on the same response -- out of that one domain so any capability can reuse it, not just room:member. core/room's own room-client.ts is the reference consumer: it rewires requestToJoin/createRoomRouter's room.join handling onto requestCapability/createCapabilityRequestHandler below, supplying room-specific extension fields (its member list) through this module's own extensions mechanism rather than this module knowing anything about rooms.
@@ -30,18 +31,64 @@ function buildCapabilityRequestCommand(capability, validUntil) {
30
31
  }
31
32
  };
32
33
  }
34
+ /** A capability request the other side answered with a manage-error. The code is the receiver's own (`denied` for a human's no, `token_required`, `capability_mismatch` or `scope_mismatch` from the request-permission gate, or a verifier reason for a presented token it did not accept), kept as a field so a caller can tell a policy refusal from a person's decision without parsing the message. */
35
+ var CapabilityRequestRefusedError = class extends Error {
36
+ capability;
37
+ code;
38
+ constructor(capability, code) {
39
+ super(`capability request for "${capability}" was refused (${code})`);
40
+ this.name = "CapabilityRequestRefusedError";
41
+ this.capability = capability;
42
+ this.code = code;
43
+ }
44
+ };
33
45
  /**
34
46
  * Sends a deliberately ungated capability-request (no token field at all -- per management.cddl's own header comment, this primitive puts access control entirely in the receiving side's own decision, not a capability check on the request itself, the same design room.join already established). Resolves with the freshly granted capability-grant-ok on approval (its own open `* tstr => any` tail may carry domain-specific extension fields, e.g. core/room's member list -- a caller that needs those parses the raw result itself, the same way room-client.ts's own requestToJoin wrapper does); rejects on denial (an ordinary manage-error) or a malformed response.
35
47
  *
36
48
  * targetDevice and timeoutMs forward directly to MeshSession.sendManageRequest's own identically-named parameters (relay routing and a requester-side give-up bound respectively -- wire-mesh#80 is already implemented there, not duplicated here). validUntil, when given, is attached to the request itself (wire-mesh#82) so a slow-to-answer receiver -- or a relay/facilitator forwarding this request on the caller's behalf -- can refuse or drop a now-stale ask outright rather than holding or forwarding it.
37
49
  */
38
- async function requestCapability(session, capability, scope, targetDevice, timeoutMs, validUntil) {
39
- const outcome = await session.sendManageRequest(buildCapabilityRequestCommand(capability, validUntil), scope, targetDevice, void 0, timeoutMs);
40
- if (outcome.result !== "ok") throw new Error(`capability request for "${capability}" was refused (${outcome.code})`);
50
+ async function requestCapability(session, capability, scope, targetDevice, timeoutMs, validUntil, requestToken) {
51
+ const outcome = await session.sendManageRequest(buildCapabilityRequestCommand(capability, validUntil), scope, targetDevice, requestToken, timeoutMs);
52
+ if (outcome.result !== "ok") throw new CapabilityRequestRefusedError(capability, outcome.code);
41
53
  const parsed = require_generated_protocol.capabilityGrantOkSchema.safeParse(outcome);
42
54
  if (!parsed.success) throw new Error(`capability request for "${capability}" response was malformed`);
43
55
  return parsed.data;
44
56
  }
57
+ /** The capability verb of a request-permission (wire-mesh#324): the right to ask for a capability, grantable and delegable like any other. */
58
+ const MANAGE_REQUEST_CAPABILITY = "manage:request";
59
+ /** The request-permission gate (wire-mesh#324): the incoming request must present a manage:request token naming this requester as bearer, matching this capability when the token names one, and covering the request's own scope. A wrong token is an ordinary manage-error, never an exception -- the same convention every other refusal here already follows. */
60
+ async function checkRequestPermission(incoming, options) {
61
+ if (incoming.token === void 0) return {
62
+ ok: false,
63
+ code: "token_required"
64
+ };
65
+ if (options.revocation === void 0) throw new Error("requireRequestToken needs a revocation view on the handler options");
66
+ const verdict = await require_domain_tokens.verifyCapabilityToken(incoming.token, {
67
+ identity: options.identity,
68
+ clock: options.clock,
69
+ revocation: options.revocation,
70
+ expectedBearer: options.bearerDevice,
71
+ ...options.extraPredicateResolvers !== void 0 ? { extraPredicateResolvers: options.extraPredicateResolvers } : {}
72
+ });
73
+ if (!verdict.ok) return {
74
+ ok: false,
75
+ code: verdict.reason
76
+ };
77
+ if (verdict.claims.capability !== "manage:request") return {
78
+ ok: false,
79
+ code: "capability_mismatch"
80
+ };
81
+ const requestsCapability = verdict.claims["requests-capability"];
82
+ if (requestsCapability !== void 0 && requestsCapability !== options.capability) return {
83
+ ok: false,
84
+ code: "capability_mismatch"
85
+ };
86
+ if (!require_domain_token_scope.scopeNarrows(verdict.claims.scope, incoming.scope)) return {
87
+ ok: false,
88
+ code: "scope_mismatch"
89
+ };
90
+ return { ok: true };
91
+ }
45
92
  /**
46
93
  * Builds a reusable handler for one capability's incoming capability-requests. The returned function is the generic counterpart to room-client.ts's own (now capability-specific) handleRoomJoin: given one IncomingManageRequest, it refuses a request for the wrong capability or a malformed payload as `{result:"error", code:"malformed"}`, refuses an already-expired request (per its own `valid-until`, wire-mesh#82) as `{result:"error", code:"expired"}` without ever invoking onRequest, otherwise arms the receiver-side timeout described on CreateCapabilityRequestHandlerOptions.timeoutMs and calls onRequest so the domain can accept (minting a fresh token via mintCapabilityToken and responding `{result:"ok", "granted-token": token, ...extensions}`) or reject (an ordinary manage-error) via the event's own decide().
47
94
  */
@@ -55,7 +102,18 @@ function createCapabilityRequestHandler(options) {
55
102
  });
56
103
  return;
57
104
  }
58
- const validUntil = parsed.data["valid-until"];
105
+ const params = parsed.data;
106
+ if (options.requireRequestToken === true) {
107
+ const verdict = await checkRequestPermission(incoming, options);
108
+ if (!verdict.ok) {
109
+ await incoming.respond({
110
+ result: "error",
111
+ code: verdict.code
112
+ });
113
+ return;
114
+ }
115
+ }
116
+ const validUntil = params["valid-until"];
59
117
  if (validUntil !== void 0 && validUntil <= options.clock.now()) {
60
118
  await incoming.respond({
61
119
  result: "error",
@@ -89,7 +147,7 @@ function createCapabilityRequestHandler(options) {
89
147
  });
90
148
  return;
91
149
  }
92
- const verdict = await require_tokens.mintCapabilityToken({
150
+ const verdict = await require_domain_tokens.mintCapabilityToken({
93
151
  identity: options.identity,
94
152
  clock: options.clock,
95
153
  tokenId: randomTokenId(),
@@ -117,6 +175,8 @@ function createCapabilityRequestHandler(options) {
117
175
  };
118
176
  }
119
177
  //#endregion
178
+ exports.CapabilityRequestRefusedError = CapabilityRequestRefusedError;
179
+ exports.MANAGE_REQUEST_CAPABILITY = MANAGE_REQUEST_CAPABILITY;
120
180
  exports.buildCapabilityRequestCommand = buildCapabilityRequestCommand;
121
181
  exports.createCapabilityRequestHandler = createCapabilityRequestHandler;
122
182
  exports.requestCapability = requestCapability;
@@ -1,18 +1,28 @@
1
- import { D as DeviceId, V as ManageCommand, f as CapabilityScope, u as CapabilityGrantOk } from "../protocol-DCDae3z4.cjs";
2
- import { t as IdentityPort } from "../identity-DVCNuFLG.cjs";
1
+ import { D as DeviceId, V as ManageCommand, f as CapabilityScope, p as CapabilityToken, u as CapabilityGrantOk } from "../protocol-BgR1e_NI.cjs";
2
+ import { t as IdentityPort } from "../identity-DJbr96J3.cjs";
3
3
  import { t as Clock } from "../clock-DiSx-WKM.cjs";
4
4
  import { IncomingManageRequest, MeshSession } from "./mesh-session.cjs";
5
+ import { m as TokenDelegateHandler, r as ConditionsContext } from "../token-predicates-C-aIe1DT.cjs";
6
+ import { RevocationCheck } from "./tokens.cjs";
5
7
  //#region src/domain/capability-request.d.ts
6
8
  /**
7
9
  * Builds a capability-request command per management.cddl. The outer `manage-command.verb` is the capability string itself -- the same value as this map's own `params.capability` field -- never a generic literal: capability-verb's own CDDL grammar is a closed alternation of colon-delimited `domain:noun` regexes (spec/tokens.cddl), so a bare literal like "capability" could never satisfy it, and routing by capability (the same way room.send/room.join already share the ROOM_MEMBER_CAPABILITY outer verb) is how a receiver's own per-capability handler knows which grant this ask is even for. `params.verb` is the fixed "capability.request" marker that distinguishes this ask from any other verb sharing the same outer capability (mirroring room.send/room.join's own inner `params.verb` split under one shared outer verb). `valid-until`, when given, bounds how long this ask is worth granting (wire-mesh#82) -- a receiver refuses outright once its own clock has passed it, rather than presenting a stale ask to a human for approval.
8
10
  */
9
11
  export declare function buildCapabilityRequestCommand(capability: string, validUntil?: number): ManageCommand;
12
+ /** A capability request the other side answered with a manage-error. The code is the receiver's own (`denied` for a human's no, `token_required`, `capability_mismatch` or `scope_mismatch` from the request-permission gate, or a verifier reason for a presented token it did not accept), kept as a field so a caller can tell a policy refusal from a person's decision without parsing the message. */
13
+ export declare class CapabilityRequestRefusedError extends Error {
14
+ readonly capability: string;
15
+ readonly code: string;
16
+ constructor(capability: string, code: string);
17
+ }
10
18
  /**
11
19
  * Sends a deliberately ungated capability-request (no token field at all -- per management.cddl's own header comment, this primitive puts access control entirely in the receiving side's own decision, not a capability check on the request itself, the same design room.join already established). Resolves with the freshly granted capability-grant-ok on approval (its own open `* tstr => any` tail may carry domain-specific extension fields, e.g. core/room's member list -- a caller that needs those parses the raw result itself, the same way room-client.ts's own requestToJoin wrapper does); rejects on denial (an ordinary manage-error) or a malformed response.
12
20
  *
13
21
  * targetDevice and timeoutMs forward directly to MeshSession.sendManageRequest's own identically-named parameters (relay routing and a requester-side give-up bound respectively -- wire-mesh#80 is already implemented there, not duplicated here). validUntil, when given, is attached to the request itself (wire-mesh#82) so a slow-to-answer receiver -- or a relay/facilitator forwarding this request on the caller's behalf -- can refuse or drop a now-stale ask outright rather than holding or forwarding it.
14
22
  */
15
- export declare function requestCapability(session: Readonly<Pick<MeshSession, "sendManageRequest">>, capability: string, scope: Readonly<CapabilityScope>, targetDevice?: DeviceId, timeoutMs?: number, validUntil?: number): Promise<CapabilityGrantOk>;
23
+ export declare function requestCapability(session: Readonly<Pick<MeshSession, "sendManageRequest">>, capability: string, scope: Readonly<CapabilityScope>, targetDevice?: DeviceId, timeoutMs?: number, validUntil?: number,
24
+ /** A manage:request token to present with the ask, for a receiver that gates requesting (wire-mesh#324). Absent keeps the request ungated, which is what a stranger's first contact must remain able to send. */
25
+ requestToken?: CapabilityToken): Promise<CapabilityGrantOk>;
16
26
  /**
17
27
  * A receiver's decision on one incoming capability-request, mirroring room-client.ts's own (now capability-specific) RoomJoinDecision, generalized to any capability: "accept" mints and returns a fresh token; "reject" sends an ordinary manage-error carrying an optional human-readable reason.
18
28
  */
@@ -37,11 +47,19 @@ export interface CapabilityGrantRequestEvent {
37
47
  /** Resolves this request with the domain's decision. Settles the request's response exactly once: whichever of a real decide() call or the handler's own receiver-side timeout comes first wins, and the other is a no-op -- the same single-settle guarantee agent-comms' own PendingConnection timer/accept/reject/disconnect race already established (ported here, not reinvented). */
38
48
  decide: (decision: Readonly<CapabilityGrantDecision>) => Promise<void>;
39
49
  }
50
+ /** The capability verb of a request-permission (wire-mesh#324): the right to ask for a capability, grantable and delegable like any other. */
51
+ export declare const MANAGE_REQUEST_CAPABILITY = "manage:request";
40
52
  export interface CreateCapabilityRequestHandlerOptions {
41
53
  /** The capability this handler grants. Checked against both the incoming request's own `params.capability` field (a mismatch is refused as malformed rather than trusted -- nothing about manage-command.verb structurally guarantees params.capability agrees with it) and used as the scope this handler is willing to act on at all; a caller wanting to grant several distinct capabilities over one session constructs one handler per capability, the same way core/room constructs one handler for `room:member` and nothing else. */
42
54
  capability: string;
43
55
  identity: IdentityPort;
44
56
  clock: Clock;
57
+ /** The revocation view the request-permission gate (requireRequestToken) verifies a presented manage:request token against -- the same plumbing every other token verification here already takes. Required only when the gate is on. */
58
+ revocation?: RevocationCheck;
59
+ /** Opt the receiver into the request-permission gate (wire-mesh#324): when on, a request must present a valid manage:request token whose bearer is the authenticated requester, whose requests-capability (when present) matches this handler's capability, and whose scope covers the request's own scope. Off by default so a stranger's first contact still reaches the domain's own decision. */
60
+ requireRequestToken?: boolean;
61
+ /** Domain-specific delegate systems a presented request-permission's own conditions entries may name, forwarded verbatim to verifyCapabilityToken. */
62
+ extraPredicateResolvers?: Readonly<Record<string, TokenDelegateHandler<ConditionsContext>>>;
45
63
  /** The peer device-id authenticated on this session's own connection -- the requester, and so the future bearer of any token this handler mints. One handler is constructed per session for the same reason one RoomRouter is (RoomRouterOptions.peerDevice): MeshSession exposes no way for domain code to learn the authenticated peer independently. */
46
64
  bearerDevice: DeviceId;
47
65
  /** Receiver-side auto-reject window (wire-mesh#81): how long an incoming request may sit awaiting the domain's decision before this side responds with a real manage-error timeout rather than leaving the requester's own sendManageRequest hanging indefinitely. Ported from agent-comms' PendingConnection pattern (`wire-mesh-transport.ts`'s `pendingConnectionTimeoutMs` / `expirePendingConnection`): an unref'd timer so a stray one can never by itself keep the process alive, cleared the instant decide() is actually called so it can never fire after the request has already been answered. IncomingManageRequest exposes no requester-disconnect signal at this layer (unlike agent-comms' own transport, which owns the raw connection), so only the timeout half of that pattern is implemented here -- there is nothing to detect the requester giving up early honestly, so this module does not pretend to. */
@@ -1,18 +1,28 @@
1
- import { D as DeviceId, V as ManageCommand, f as CapabilityScope, u as CapabilityGrantOk } from "../protocol-DCDae3z4.mjs";
2
- import { t as IdentityPort } from "../identity-DcaYgjXT.mjs";
1
+ import { D as DeviceId, V as ManageCommand, f as CapabilityScope, p as CapabilityToken, u as CapabilityGrantOk } from "../protocol-BgR1e_NI.mjs";
2
+ import { t as IdentityPort } from "../identity-ViYdZrIU.mjs";
3
3
  import { t as Clock } from "../clock-DiSx-WKM.mjs";
4
4
  import { IncomingManageRequest, MeshSession } from "./mesh-session.mjs";
5
+ import { m as TokenDelegateHandler, r as ConditionsContext } from "../token-predicates-DqvyS7Y8.mjs";
6
+ import { RevocationCheck } from "./tokens.mjs";
5
7
  //#region src/domain/capability-request.d.ts
6
8
  /**
7
9
  * Builds a capability-request command per management.cddl. The outer `manage-command.verb` is the capability string itself -- the same value as this map's own `params.capability` field -- never a generic literal: capability-verb's own CDDL grammar is a closed alternation of colon-delimited `domain:noun` regexes (spec/tokens.cddl), so a bare literal like "capability" could never satisfy it, and routing by capability (the same way room.send/room.join already share the ROOM_MEMBER_CAPABILITY outer verb) is how a receiver's own per-capability handler knows which grant this ask is even for. `params.verb` is the fixed "capability.request" marker that distinguishes this ask from any other verb sharing the same outer capability (mirroring room.send/room.join's own inner `params.verb` split under one shared outer verb). `valid-until`, when given, bounds how long this ask is worth granting (wire-mesh#82) -- a receiver refuses outright once its own clock has passed it, rather than presenting a stale ask to a human for approval.
8
10
  */
9
11
  export declare function buildCapabilityRequestCommand(capability: string, validUntil?: number): ManageCommand;
12
+ /** A capability request the other side answered with a manage-error. The code is the receiver's own (`denied` for a human's no, `token_required`, `capability_mismatch` or `scope_mismatch` from the request-permission gate, or a verifier reason for a presented token it did not accept), kept as a field so a caller can tell a policy refusal from a person's decision without parsing the message. */
13
+ export declare class CapabilityRequestRefusedError extends Error {
14
+ readonly capability: string;
15
+ readonly code: string;
16
+ constructor(capability: string, code: string);
17
+ }
10
18
  /**
11
19
  * Sends a deliberately ungated capability-request (no token field at all -- per management.cddl's own header comment, this primitive puts access control entirely in the receiving side's own decision, not a capability check on the request itself, the same design room.join already established). Resolves with the freshly granted capability-grant-ok on approval (its own open `* tstr => any` tail may carry domain-specific extension fields, e.g. core/room's member list -- a caller that needs those parses the raw result itself, the same way room-client.ts's own requestToJoin wrapper does); rejects on denial (an ordinary manage-error) or a malformed response.
12
20
  *
13
21
  * targetDevice and timeoutMs forward directly to MeshSession.sendManageRequest's own identically-named parameters (relay routing and a requester-side give-up bound respectively -- wire-mesh#80 is already implemented there, not duplicated here). validUntil, when given, is attached to the request itself (wire-mesh#82) so a slow-to-answer receiver -- or a relay/facilitator forwarding this request on the caller's behalf -- can refuse or drop a now-stale ask outright rather than holding or forwarding it.
14
22
  */
15
- export declare function requestCapability(session: Readonly<Pick<MeshSession, "sendManageRequest">>, capability: string, scope: Readonly<CapabilityScope>, targetDevice?: DeviceId, timeoutMs?: number, validUntil?: number): Promise<CapabilityGrantOk>;
23
+ export declare function requestCapability(session: Readonly<Pick<MeshSession, "sendManageRequest">>, capability: string, scope: Readonly<CapabilityScope>, targetDevice?: DeviceId, timeoutMs?: number, validUntil?: number,
24
+ /** A manage:request token to present with the ask, for a receiver that gates requesting (wire-mesh#324). Absent keeps the request ungated, which is what a stranger's first contact must remain able to send. */
25
+ requestToken?: CapabilityToken): Promise<CapabilityGrantOk>;
16
26
  /**
17
27
  * A receiver's decision on one incoming capability-request, mirroring room-client.ts's own (now capability-specific) RoomJoinDecision, generalized to any capability: "accept" mints and returns a fresh token; "reject" sends an ordinary manage-error carrying an optional human-readable reason.
18
28
  */
@@ -37,11 +47,19 @@ export interface CapabilityGrantRequestEvent {
37
47
  /** Resolves this request with the domain's decision. Settles the request's response exactly once: whichever of a real decide() call or the handler's own receiver-side timeout comes first wins, and the other is a no-op -- the same single-settle guarantee agent-comms' own PendingConnection timer/accept/reject/disconnect race already established (ported here, not reinvented). */
38
48
  decide: (decision: Readonly<CapabilityGrantDecision>) => Promise<void>;
39
49
  }
50
+ /** The capability verb of a request-permission (wire-mesh#324): the right to ask for a capability, grantable and delegable like any other. */
51
+ export declare const MANAGE_REQUEST_CAPABILITY = "manage:request";
40
52
  export interface CreateCapabilityRequestHandlerOptions {
41
53
  /** The capability this handler grants. Checked against both the incoming request's own `params.capability` field (a mismatch is refused as malformed rather than trusted -- nothing about manage-command.verb structurally guarantees params.capability agrees with it) and used as the scope this handler is willing to act on at all; a caller wanting to grant several distinct capabilities over one session constructs one handler per capability, the same way core/room constructs one handler for `room:member` and nothing else. */
42
54
  capability: string;
43
55
  identity: IdentityPort;
44
56
  clock: Clock;
57
+ /** The revocation view the request-permission gate (requireRequestToken) verifies a presented manage:request token against -- the same plumbing every other token verification here already takes. Required only when the gate is on. */
58
+ revocation?: RevocationCheck;
59
+ /** Opt the receiver into the request-permission gate (wire-mesh#324): when on, a request must present a valid manage:request token whose bearer is the authenticated requester, whose requests-capability (when present) matches this handler's capability, and whose scope covers the request's own scope. Off by default so a stranger's first contact still reaches the domain's own decision. */
60
+ requireRequestToken?: boolean;
61
+ /** Domain-specific delegate systems a presented request-permission's own conditions entries may name, forwarded verbatim to verifyCapabilityToken. */
62
+ extraPredicateResolvers?: Readonly<Record<string, TokenDelegateHandler<ConditionsContext>>>;
45
63
  /** The peer device-id authenticated on this session's own connection -- the requester, and so the future bearer of any token this handler mints. One handler is constructed per session for the same reason one RoomRouter is (RoomRouterOptions.peerDevice): MeshSession exposes no way for domain code to learn the authenticated peer independently. */
46
64
  bearerDevice: DeviceId;
47
65
  /** Receiver-side auto-reject window (wire-mesh#81): how long an incoming request may sit awaiting the domain's decision before this side responds with a real manage-error timeout rather than leaving the requester's own sendManageRequest hanging indefinitely. Ported from agent-comms' PendingConnection pattern (`wire-mesh-transport.ts`'s `pendingConnectionTimeoutMs` / `expirePendingConnection`): an unref'd timer so a stray one can never by itself keep the process alive, cleared the instant decide() is actually called so it can never fire after the request has already been answered. IncomingManageRequest exposes no requester-disconnect signal at this layer (unlike agent-comms' own transport, which owns the raw connection), so only the timeout half of that pattern is implemented here -- there is nothing to detect the requester giving up early honestly, so this module does not pretend to. */
@@ -1,5 +1,6 @@
1
1
  import { capabilityGrantOkSchema, capabilityRequestSchema } from "../generated/protocol.mjs";
2
- import { n as mintCapabilityToken } from "../tokens-CMdWiRBb.mjs";
2
+ import { scopeNarrows } from "./token-scope.mjs";
3
+ import { mintCapabilityToken, verifyCapabilityToken } from "./tokens.mjs";
3
4
  //#region src/domain/capability-request.ts
4
5
  /**
5
6
  * The generic, capability-agnostic capability-request / capability-grant-ok primitive (wire-mesh#78, spec/management.cddl). Lifts core/room's own room.join shape -- an ungated ask, held open, a human (or any other domain-supplied decision) accepts or refuses, acceptance mints and returns a token on the same response -- out of that one domain so any capability can reuse it, not just room:member. core/room's own room-client.ts is the reference consumer: it rewires requestToJoin/createRoomRouter's room.join handling onto requestCapability/createCapabilityRequestHandler below, supplying room-specific extension fields (its member list) through this module's own extensions mechanism rather than this module knowing anything about rooms.
@@ -29,18 +30,64 @@ function buildCapabilityRequestCommand(capability, validUntil) {
29
30
  }
30
31
  };
31
32
  }
33
+ /** A capability request the other side answered with a manage-error. The code is the receiver's own (`denied` for a human's no, `token_required`, `capability_mismatch` or `scope_mismatch` from the request-permission gate, or a verifier reason for a presented token it did not accept), kept as a field so a caller can tell a policy refusal from a person's decision without parsing the message. */
34
+ var CapabilityRequestRefusedError = class extends Error {
35
+ capability;
36
+ code;
37
+ constructor(capability, code) {
38
+ super(`capability request for "${capability}" was refused (${code})`);
39
+ this.name = "CapabilityRequestRefusedError";
40
+ this.capability = capability;
41
+ this.code = code;
42
+ }
43
+ };
32
44
  /**
33
45
  * Sends a deliberately ungated capability-request (no token field at all -- per management.cddl's own header comment, this primitive puts access control entirely in the receiving side's own decision, not a capability check on the request itself, the same design room.join already established). Resolves with the freshly granted capability-grant-ok on approval (its own open `* tstr => any` tail may carry domain-specific extension fields, e.g. core/room's member list -- a caller that needs those parses the raw result itself, the same way room-client.ts's own requestToJoin wrapper does); rejects on denial (an ordinary manage-error) or a malformed response.
34
46
  *
35
47
  * targetDevice and timeoutMs forward directly to MeshSession.sendManageRequest's own identically-named parameters (relay routing and a requester-side give-up bound respectively -- wire-mesh#80 is already implemented there, not duplicated here). validUntil, when given, is attached to the request itself (wire-mesh#82) so a slow-to-answer receiver -- or a relay/facilitator forwarding this request on the caller's behalf -- can refuse or drop a now-stale ask outright rather than holding or forwarding it.
36
48
  */
37
- async function requestCapability(session, capability, scope, targetDevice, timeoutMs, validUntil) {
38
- const outcome = await session.sendManageRequest(buildCapabilityRequestCommand(capability, validUntil), scope, targetDevice, void 0, timeoutMs);
39
- if (outcome.result !== "ok") throw new Error(`capability request for "${capability}" was refused (${outcome.code})`);
49
+ async function requestCapability(session, capability, scope, targetDevice, timeoutMs, validUntil, requestToken) {
50
+ const outcome = await session.sendManageRequest(buildCapabilityRequestCommand(capability, validUntil), scope, targetDevice, requestToken, timeoutMs);
51
+ if (outcome.result !== "ok") throw new CapabilityRequestRefusedError(capability, outcome.code);
40
52
  const parsed = capabilityGrantOkSchema.safeParse(outcome);
41
53
  if (!parsed.success) throw new Error(`capability request for "${capability}" response was malformed`);
42
54
  return parsed.data;
43
55
  }
56
+ /** The capability verb of a request-permission (wire-mesh#324): the right to ask for a capability, grantable and delegable like any other. */
57
+ const MANAGE_REQUEST_CAPABILITY = "manage:request";
58
+ /** The request-permission gate (wire-mesh#324): the incoming request must present a manage:request token naming this requester as bearer, matching this capability when the token names one, and covering the request's own scope. A wrong token is an ordinary manage-error, never an exception -- the same convention every other refusal here already follows. */
59
+ async function checkRequestPermission(incoming, options) {
60
+ if (incoming.token === void 0) return {
61
+ ok: false,
62
+ code: "token_required"
63
+ };
64
+ if (options.revocation === void 0) throw new Error("requireRequestToken needs a revocation view on the handler options");
65
+ const verdict = await verifyCapabilityToken(incoming.token, {
66
+ identity: options.identity,
67
+ clock: options.clock,
68
+ revocation: options.revocation,
69
+ expectedBearer: options.bearerDevice,
70
+ ...options.extraPredicateResolvers !== void 0 ? { extraPredicateResolvers: options.extraPredicateResolvers } : {}
71
+ });
72
+ if (!verdict.ok) return {
73
+ ok: false,
74
+ code: verdict.reason
75
+ };
76
+ if (verdict.claims.capability !== "manage:request") return {
77
+ ok: false,
78
+ code: "capability_mismatch"
79
+ };
80
+ const requestsCapability = verdict.claims["requests-capability"];
81
+ if (requestsCapability !== void 0 && requestsCapability !== options.capability) return {
82
+ ok: false,
83
+ code: "capability_mismatch"
84
+ };
85
+ if (!scopeNarrows(verdict.claims.scope, incoming.scope)) return {
86
+ ok: false,
87
+ code: "scope_mismatch"
88
+ };
89
+ return { ok: true };
90
+ }
44
91
  /**
45
92
  * Builds a reusable handler for one capability's incoming capability-requests. The returned function is the generic counterpart to room-client.ts's own (now capability-specific) handleRoomJoin: given one IncomingManageRequest, it refuses a request for the wrong capability or a malformed payload as `{result:"error", code:"malformed"}`, refuses an already-expired request (per its own `valid-until`, wire-mesh#82) as `{result:"error", code:"expired"}` without ever invoking onRequest, otherwise arms the receiver-side timeout described on CreateCapabilityRequestHandlerOptions.timeoutMs and calls onRequest so the domain can accept (minting a fresh token via mintCapabilityToken and responding `{result:"ok", "granted-token": token, ...extensions}`) or reject (an ordinary manage-error) via the event's own decide().
46
93
  */
@@ -54,7 +101,18 @@ function createCapabilityRequestHandler(options) {
54
101
  });
55
102
  return;
56
103
  }
57
- const validUntil = parsed.data["valid-until"];
104
+ const params = parsed.data;
105
+ if (options.requireRequestToken === true) {
106
+ const verdict = await checkRequestPermission(incoming, options);
107
+ if (!verdict.ok) {
108
+ await incoming.respond({
109
+ result: "error",
110
+ code: verdict.code
111
+ });
112
+ return;
113
+ }
114
+ }
115
+ const validUntil = params["valid-until"];
58
116
  if (validUntil !== void 0 && validUntil <= options.clock.now()) {
59
117
  await incoming.respond({
60
118
  result: "error",
@@ -116,4 +174,4 @@ function createCapabilityRequestHandler(options) {
116
174
  };
117
175
  }
118
176
  //#endregion
119
- export { buildCapabilityRequestCommand, createCapabilityRequestHandler, requestCapability };
177
+ export { CapabilityRequestRefusedError, MANAGE_REQUEST_CAPABILITY, buildCapabilityRequestCommand, createCapabilityRequestHandler, requestCapability };
@@ -1,4 +1,4 @@
1
- import { D as DeviceId, g as CoordinatorFrame } from "../protocol-DCDae3z4.cjs";
1
+ import { D as DeviceId, g as CoordinatorFrame } from "../protocol-BgR1e_NI.cjs";
2
2
  //#region src/domain/coordinator-election.d.ts
3
3
  /** The claim this side currently accepts: one coordinator, at the term that put it there. */
4
4
  export interface CoordinatorClaim {
@@ -1,4 +1,4 @@
1
- import { D as DeviceId, g as CoordinatorFrame } from "../protocol-DCDae3z4.mjs";
1
+ import { D as DeviceId, g as CoordinatorFrame } from "../protocol-BgR1e_NI.mjs";
2
2
  //#region src/domain/coordinator-election.d.ts
3
3
  /** The claim this side currently accepts: one coordinator, at the term that put it there. */
4
4
  export interface CoordinatorClaim {
@@ -1,6 +1,6 @@
1
- import { D as DeviceId, E as DataRequestFrame, T as DataHaveFrame, w as DataEntriesFrame } from "../protocol-DCDae3z4.cjs";
1
+ import { D as DeviceId, E as DataRequestFrame, T as DataHaveFrame, w as DataEntriesFrame } from "../protocol-BgR1e_NI.cjs";
2
2
  import { t as KeyValueStorage } from "../storage-B403CRyu.cjs";
3
- import { t as IdentityPort } from "../identity-DVCNuFLG.cjs";
3
+ import { t as IdentityPort } from "../identity-DJbr96J3.cjs";
4
4
  //#region src/domain/data-sync.d.ts
5
5
  export interface DataSyncOptions {
6
6
  identity: IdentityPort;
@@ -1,6 +1,6 @@
1
- import { D as DeviceId, E as DataRequestFrame, T as DataHaveFrame, w as DataEntriesFrame } from "../protocol-DCDae3z4.mjs";
1
+ import { D as DeviceId, E as DataRequestFrame, T as DataHaveFrame, w as DataEntriesFrame } from "../protocol-BgR1e_NI.mjs";
2
2
  import { t as KeyValueStorage } from "../storage-B403CRyu.mjs";
3
- import { t as IdentityPort } from "../identity-DcaYgjXT.mjs";
3
+ import { t as IdentityPort } from "../identity-ViYdZrIU.mjs";
4
4
  //#region src/domain/data-sync.d.ts
5
5
  export interface DataSyncOptions {
6
6
  identity: IdentityPort;
@@ -1,4 +1,4 @@
1
- import { D as DeviceId } from "../protocol-DCDae3z4.cjs";
1
+ import { D as DeviceId } from "../protocol-BgR1e_NI.cjs";
2
2
  //#region src/domain/device-id.d.ts
3
3
  /** Lowercase, byte-exact hex for an arbitrary-length byte string -- the same encoding convention deviceIdToHex uses for the fixed-length device-id case, extracted so any other byte string needing a stable, displayable, map-keyable text form (e.g. a token-id, which tokens.cddl defines as an arbitrary-length bstr rather than a 32-byte device-id) can use the identical convention without going through a device-id-shaped function. */
4
4
  export declare function bytesToHex(bytes: Uint8Array): string;