@nice-code/commander 0.111.0 → 0.112.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/build/cli.mjs CHANGED
@@ -4723,6 +4723,7 @@ var ClientCryptoKeyLink = class {
4723
4723
  localVerifyKeyPair;
4724
4724
  linkedClientKeys = /* @__PURE__ */ new Map();
4725
4725
  storage;
4726
+ storageAdapter;
4726
4727
  identityMode;
4727
4728
  initialized = false;
4728
4729
  initializePromise;
@@ -4730,9 +4731,18 @@ var ClientCryptoKeyLink = class {
4730
4731
  localVerifyKeyPairPromise;
4731
4732
  constructor({ storageAdapter, identityMode } = {}) {
4732
4733
  if (storageAdapter != null) this.storage = createTypedStorage({ storageAdapter });
4734
+ this.storageAdapter = storageAdapter;
4733
4735
  this.identityMode = identityMode ?? "lazy";
4734
4736
  }
4735
4737
  /**
4738
+ * A namespace of this identity's own store (same backing storage, `prefix` appended), for state
4739
+ * that belongs to this identity and must go wherever its keys go — e.g. a connector's established
4740
+ * sessions. `undefined` when the link has no storage.
4741
+ */
4742
+ scopedStorage(prefix) {
4743
+ return this.storageAdapter?.withKeyPrefix(prefix);
4744
+ }
4745
+ /**
4736
4746
  * Loads the local key pairs and any linked client public keys from storage (when a storage
4737
4747
  * adapter was provided), generating and persisting fresh local key pairs if none exist yet.
4738
4748
  *
@@ -9646,6 +9656,12 @@ function assembleWireConnectionParts(options) {
9646
9656
  }
9647
9657
  //#endregion
9648
9658
  //#region ../nice-wire/src/Connect/exchangeEnvelope.ts
9659
+ /**
9660
+ * The `err` id an acceptor sends when it refused the session itself (expired, tampered or
9661
+ * wrong-key ticket, or an act at the wrong level) — before any lane ran, so the connector may
9662
+ * drop the session, handshake again and resend the same act.
9663
+ */
9664
+ const WIRE_EXCHANGE_SESSION_REFUSED = "session_refused";
9649
9665
  function encodeExchange(envelope) {
9650
9666
  return JSON.stringify(envelope);
9651
9667
  }
@@ -9674,33 +9690,261 @@ function hasEnvelopeKind(value) {
9674
9690
  return typeof value === "object" && value != null && "k" in value;
9675
9691
  }
9676
9692
  //#endregion
9693
+ //#region ../nice-wire/src/SecureSession/exchangeTicketSeal.ts
9694
+ const SEALED_ENVELOPE_LENGTH = 2;
9695
+ function createExchangeTicketSealer(link, options = {}) {
9696
+ let keyPromise;
9697
+ const getKey = () => {
9698
+ if (keyPromise == null) keyPromise = link.deriveLocalSealKey({ version: options.version }).catch((err) => {
9699
+ keyPromise = void 0;
9700
+ throw err;
9701
+ });
9702
+ return keyPromise;
9703
+ };
9704
+ return {
9705
+ async seal(value, ttlMs) {
9706
+ const { nonce, ciphertext } = await encryptBytesWithAesGcmKey({
9707
+ dataToEncrypt: pack({
9708
+ v: value,
9709
+ exp: Date.now() + ttlMs
9710
+ }),
9711
+ aesGcmKey: await getKey()
9712
+ });
9713
+ return bytesToBase64(pack([nonce, ciphertext]));
9714
+ },
9715
+ async open(blob) {
9716
+ try {
9717
+ const envelope = unpack(base64ToBytes(blob));
9718
+ if (!Array.isArray(envelope) || envelope.length !== SEALED_ENVELOPE_LENGTH) return void 0;
9719
+ const [nonce, ciphertext] = envelope;
9720
+ if (!(nonce instanceof Uint8Array) || !(ciphertext instanceof Uint8Array)) return void 0;
9721
+ const payload = unpack(await decryptBytesWithAesGcmKey({
9722
+ dataToDecrypt: {
9723
+ nonce,
9724
+ ciphertext
9725
+ },
9726
+ aesGcmKey: await getKey()
9727
+ }));
9728
+ if (payload == null || typeof payload.exp !== "number" || payload.exp < Date.now()) return;
9729
+ return payload.v;
9730
+ } catch {
9731
+ return;
9732
+ }
9733
+ }
9734
+ };
9735
+ }
9736
+ //#endregion
9737
+ //#region ../nice-wire/src/Connect/exchangeSessionShelf.ts
9738
+ /** Lapse a little before the acceptor would, so a request is never sent on its last second. */
9739
+ function expiryFor(receivedAt, ttlMs) {
9740
+ if (ttlMs == null || !(ttlMs > 0)) return void 0;
9741
+ return receivedAt + ttlMs - Math.min(6e4, ttlMs / 10);
9742
+ }
9743
+ function stateFromRecord(link, record) {
9744
+ const crypto = record.km != null ? createActionFrameCrypto({
9745
+ link,
9746
+ keyMaterial: record.km
9747
+ }) : void 0;
9748
+ return {
9749
+ token: record.t,
9750
+ crypto,
9751
+ expiresAt: record.exp,
9752
+ record
9753
+ };
9754
+ }
9755
+ function isLapsed(state) {
9756
+ return state.expiresAt != null && Date.now() >= state.expiresAt;
9757
+ }
9758
+ /**
9759
+ * One session's lifecycle: at most one handshake in flight, shared by every caller; a refused or
9760
+ * lapsed session is replaced once, however many requests noticed it.
9761
+ */
9762
+ var ExchangeSessionSlot = class {
9763
+ _entry;
9764
+ current(initial, replacement) {
9765
+ const entry = this._entry;
9766
+ if (entry == null) return this._start(initial);
9767
+ if (entry.state != null && isLapsed(entry.state)) return this.renew(entry.state, replacement);
9768
+ return entry.promise;
9769
+ }
9770
+ renew(stale, replacement) {
9771
+ const entry = this._entry;
9772
+ if (entry != null && entry.state !== stale) return entry.promise;
9773
+ return this._start(replacement);
9774
+ }
9775
+ _start(establish) {
9776
+ const entry = { promise: establish() };
9777
+ this._entry = entry;
9778
+ entry.promise.then((state) => {
9779
+ entry.state = state;
9780
+ }, () => {
9781
+ if (this._entry === entry) this._entry = void 0;
9782
+ });
9783
+ return entry.promise;
9784
+ }
9785
+ };
9786
+ /** A session source for one transport alone — today's behaviour, plus renewal on refusal. */
9787
+ function privateSessionSource(handshake) {
9788
+ const slot = new ExchangeSessionSlot();
9789
+ return {
9790
+ current: () => slot.current(handshake, handshake),
9791
+ renew: (stale) => slot.renew(stale, handshake)
9792
+ };
9793
+ }
9794
+ const STORE_KEY = "sessions";
9795
+ const SEAL_VERSION = "connector-exchange-session/v1";
9796
+ /**
9797
+ * Every session one crypto identity holds with its peers, keyed by peer identity: shared in memory
9798
+ * by all of the link's transports, and kept in the link's own storage so a reload restores it.
9799
+ * Stored copies are sealed with a key derived from the link's private key — useless to another
9800
+ * device, and unopenable once the identity is reset.
9801
+ */
9802
+ var ExchangeSessionShelf = class {
9803
+ _link;
9804
+ _slots = /* @__PURE__ */ new Map();
9805
+ _storage;
9806
+ _sealer;
9807
+ constructor(_link) {
9808
+ this._link = _link;
9809
+ this._storage = _link.scopedStorage("wire-exchange/");
9810
+ this._sealer = createExchangeTicketSealer(_link, { version: SEAL_VERSION });
9811
+ }
9812
+ source(key, handshake) {
9813
+ let slot = this._slots.get(key);
9814
+ if (slot == null) {
9815
+ slot = new ExchangeSessionSlot();
9816
+ this._slots.set(key, slot);
9817
+ }
9818
+ const held = slot;
9819
+ const handshakeAndKeep = async () => {
9820
+ const state = await handshake();
9821
+ await this._keep(key, state).catch(() => void 0);
9822
+ return state;
9823
+ };
9824
+ const restoreOrHandshake = async () => {
9825
+ return await this._restore(key).catch(() => void 0) ?? await handshakeAndKeep();
9826
+ };
9827
+ const replace = async () => {
9828
+ await this._forget(key).catch(() => void 0);
9829
+ return await handshakeAndKeep();
9830
+ };
9831
+ return {
9832
+ current: () => held.current(restoreOrHandshake, replace),
9833
+ renew: (stale) => held.renew(stale, replace)
9834
+ };
9835
+ }
9836
+ async _restore(key) {
9837
+ const storage = this._storage;
9838
+ if (storage == null) return void 0;
9839
+ const stored = (await storage.getJson(STORE_KEY))?.[key];
9840
+ if (stored == null || stored.exp <= Date.now()) return void 0;
9841
+ await this._link.initialize();
9842
+ const record = await this._sealer.open(stored.sealed);
9843
+ if (record == null || typeof record.t !== "string") return void 0;
9844
+ return stateFromRecord(this._link, record);
9845
+ }
9846
+ async _keep(key, state) {
9847
+ const storage = this._storage;
9848
+ const record = state.record;
9849
+ if (storage == null || record?.exp == null) return;
9850
+ const ttl = record.exp - Date.now();
9851
+ if (ttl <= 0) return;
9852
+ const sealed = await this._sealer.seal(record, ttl);
9853
+ await this._update(storage, (sessions) => ({
9854
+ ...sessions,
9855
+ [key]: {
9856
+ exp: record.exp ?? 0,
9857
+ sealed
9858
+ }
9859
+ }));
9860
+ }
9861
+ async _forget(key) {
9862
+ const storage = this._storage;
9863
+ if (storage == null) return;
9864
+ await this._update(storage, (sessions) => {
9865
+ const { [key]: _dropped, ...rest } = sessions;
9866
+ return rest;
9867
+ });
9868
+ }
9869
+ async _update(storage, change) {
9870
+ await storage.updateJsonOrDef(STORE_KEY, {}, (current) => {
9871
+ const now = Date.now();
9872
+ const live = {};
9873
+ for (const [key, entry] of Object.entries(change(current))) if (entry.exp > now) live[key] = entry;
9874
+ return live;
9875
+ });
9876
+ }
9877
+ };
9878
+ const shelves = /* @__PURE__ */ new WeakMap();
9879
+ /**
9880
+ * The source a secure exchange draws its session from: shared by peer identity when the config asks
9881
+ * for reuse and names the peer, private to this transport otherwise.
9882
+ */
9883
+ function exchangeSessionSource(secure, lane, handshake) {
9884
+ const peer = secure.expectedPeer;
9885
+ if (secure.reuseExchangeSessions !== true || peer == null) return privateSessionSource(handshake);
9886
+ let shelf = shelves.get(secure.link);
9887
+ if (shelf == null) {
9888
+ shelf = new ExchangeSessionShelf(secure.link);
9889
+ shelves.set(secure.link, shelf);
9890
+ }
9891
+ const key = JSON.stringify([
9892
+ secure.localCoordinate.envId,
9893
+ secure.localCoordinate.perId ?? null,
9894
+ peer.envId,
9895
+ peer.perId ?? null,
9896
+ secure.securityLevel,
9897
+ lane.dictionaryVersion,
9898
+ [...lane.channels ?? []].sort()
9899
+ ]);
9900
+ return shelf.source(key, handshake);
9901
+ }
9902
+ //#endregion
9677
9903
  //#region ../nice-wire/src/Connect/exchangeSession.ts
9678
9904
  const textEncoder$1 = new TextEncoder();
9679
9905
  const textDecoder$1 = new TextDecoder();
9906
+ const PLAIN_STATE = {};
9680
9907
  /** Plain path (no handshake/token): every wire rides a bare `act` envelope, plaintext both ways. */
9681
9908
  function establishPlainExchangeSession(carrier) {
9682
- return makeSession(carrier, {});
9909
+ return makeSession(carrier, {
9910
+ current: async () => PLAIN_STATE,
9911
+ renew: async () => PLAIN_STATE
9912
+ });
9683
9913
  }
9684
9914
  /**
9685
- * Secure path: run the handshake (two exchanges) once at bring-up, then reuse the token + crypto.
9686
- * The lane supplies the handshake payload (`dictionaryVersion`/`channels`, E5 — emitted under the
9687
- * byte-frozen wire names; the version is signed into the challenge).
9915
+ * Secure path: run the handshake (two exchanges) at bring-up — or restore a kept session — then
9916
+ * reuse the token + crypto. The lane supplies the handshake payload (`dictionaryVersion`/`channels`,
9917
+ * E5 — emitted under the byte-frozen wire names; the version is signed into the challenge).
9688
9918
  */
9689
9919
  async function establishSecureExchangeSession(ctx) {
9690
- const state = await runConnectorExchangeHandshake(ctx.carrier, ctx.secure, ctx.lane);
9691
- return makeSession(ctx.carrier, state);
9692
- }
9693
- function makeSession(carrier, state) {
9694
- const runExchange = async (wire, opts) => {
9695
- const request = await buildRequestEnvelope(state, wire);
9696
- return carrier.exchange(encodeExchange(request), { signal: opts?.signal });
9920
+ const source = exchangeSessionSource(ctx.secure, ctx.lane, () => runConnectorExchangeHandshake(ctx.carrier, ctx.secure, ctx.lane));
9921
+ await source.current();
9922
+ return makeSession(ctx.carrier, source, ctx.secure.localCoordinate.insId);
9923
+ }
9924
+ function makeSession(carrier, source, insId) {
9925
+ const post = async (state, wire, signal) => {
9926
+ const request = await buildRequestEnvelope(state, wire, insId);
9927
+ return decodeExchangeReply(asString(await carrier.exchange(encodeExchange(request), { signal })));
9928
+ };
9929
+ const roundTrip = async (wire, signal) => {
9930
+ const state = await source.current();
9931
+ const reply = await post(state, wire, signal);
9932
+ if (reply?.k !== "err" || reply.id !== "session_refused" || state.token == null) return {
9933
+ state,
9934
+ reply
9935
+ };
9936
+ const renewed = await source.renew(state);
9937
+ return {
9938
+ state: renewed,
9939
+ reply: await post(renewed, wire, signal)
9940
+ };
9697
9941
  };
9698
9942
  return {
9699
9943
  send: async (wire, opts) => {
9700
- await runExchange(wire, opts);
9944
+ await roundTrip(wire, opts?.signal);
9701
9945
  },
9702
9946
  exchange: async (wire, opts) => {
9703
- const reply = decodeExchangeReply(asString(await runExchange(wire, opts)));
9947
+ const { state, reply } = await roundTrip(wire, opts?.signal);
9704
9948
  if (reply == null) return {
9705
9949
  ok: false,
9706
9950
  reason: "malformed_reply"
@@ -9722,18 +9966,21 @@ function makeSession(carrier, state) {
9722
9966
  }
9723
9967
  };
9724
9968
  }
9725
- async function buildRequestEnvelope(state, wire) {
9969
+ async function buildRequestEnvelope(state, wire, insId) {
9970
+ const i = state.token != null ? insId : void 0;
9726
9971
  if (state.crypto != null) {
9727
9972
  const ciphertext = await state.crypto.encryptFrame(textEncoder$1.encode(JSON.stringify(wire)));
9728
9973
  return {
9729
9974
  k: "act",
9730
9975
  t: state.token,
9976
+ i,
9731
9977
  c: bytesToBase64(ciphertext)
9732
9978
  };
9733
9979
  }
9734
9980
  return {
9735
9981
  k: "act",
9736
9982
  t: state.token,
9983
+ i,
9737
9984
  w: wire
9738
9985
  };
9739
9986
  }
@@ -9776,14 +10023,13 @@ async function runConnectorExchangeHandshake(carrier, secure, lane) {
9776
10023
  if (accept.t !== "accept") throw nonProtocolReply(carrier, "an accept frame", `hs/${accept.t}`);
9777
10024
  if (acceptReply.t == null) throw new Error(`[${HANDSHAKE_STAGE}] accept missing session token${at(carrier)}`);
9778
10025
  const result = await handshake.onAccept(accept);
9779
- const crypto = result.securityLevel === "encrypted" && result.encryptionKeyMaterial != null ? createActionFrameCrypto({
9780
- link: secure.link,
9781
- keyMaterial: result.encryptionKeyMaterial
9782
- }) : void 0;
9783
- return {
9784
- token: acceptReply.t,
9785
- crypto
9786
- };
10026
+ const keyMaterial = result.securityLevel === "encrypted" ? result.encryptionKeyMaterial : void 0;
10027
+ return stateFromRecord(secure.link, {
10028
+ t: acceptReply.t,
10029
+ level: result.securityLevel,
10030
+ km: keyMaterial,
10031
+ exp: expiryFor(Date.now(), acceptReply.ttl)
10032
+ });
9787
10033
  }
9788
10034
  const HANDSHAKE_STAGE = "exchange-handshake";
9789
10035
  /**
@@ -10369,50 +10615,6 @@ var WireAcceptor = class {
10369
10615
  }
10370
10616
  };
10371
10617
  //#endregion
10372
- //#region ../nice-wire/src/SecureSession/exchangeTicketSeal.ts
10373
- const SEALED_ENVELOPE_LENGTH = 2;
10374
- function createExchangeTicketSealer(link, options = {}) {
10375
- let keyPromise;
10376
- const getKey = () => {
10377
- if (keyPromise == null) keyPromise = link.deriveLocalSealKey({ version: options.version }).catch((err) => {
10378
- keyPromise = void 0;
10379
- throw err;
10380
- });
10381
- return keyPromise;
10382
- };
10383
- return {
10384
- async seal(value, ttlMs) {
10385
- const { nonce, ciphertext } = await encryptBytesWithAesGcmKey({
10386
- dataToEncrypt: pack({
10387
- v: value,
10388
- exp: Date.now() + ttlMs
10389
- }),
10390
- aesGcmKey: await getKey()
10391
- });
10392
- return bytesToBase64(pack([nonce, ciphertext]));
10393
- },
10394
- async open(blob) {
10395
- try {
10396
- const envelope = unpack(base64ToBytes(blob));
10397
- if (!Array.isArray(envelope) || envelope.length !== SEALED_ENVELOPE_LENGTH) return void 0;
10398
- const [nonce, ciphertext] = envelope;
10399
- if (!(nonce instanceof Uint8Array) || !(ciphertext instanceof Uint8Array)) return void 0;
10400
- const payload = unpack(await decryptBytesWithAesGcmKey({
10401
- dataToDecrypt: {
10402
- nonce,
10403
- ciphertext
10404
- },
10405
- aesGcmKey: await getKey()
10406
- }));
10407
- if (payload == null || typeof payload.exp !== "number" || payload.exp < Date.now()) return;
10408
- return payload.v;
10409
- } catch {
10410
- return;
10411
- }
10412
- }
10413
- };
10414
- }
10415
- //#endregion
10416
10618
  //#region ../nice-wire/src/Connect/WireExchangeAcceptor.ts
10417
10619
  /** The default session-ticket lifetime — see {@link IWireExchangeAcceptorOptions.sessionTtlMs}. */
10418
10620
  const DEFAULT_SESSION_TTL_MS = 720 * 60 * 1e3;
@@ -10482,11 +10684,17 @@ var WireExchangeAcceptor = class {
10482
10684
  m: encodeHandshakeMessage(reply)
10483
10685
  };
10484
10686
  const pending = handshake.exportPending();
10485
- if (pending == null) return {
10687
+ const dv = this._dictionaryVersion(message.channels);
10688
+ if (pending == null || dv == null) return {
10486
10689
  k: "err",
10487
10690
  message: "handshake produced no continuation state"
10488
10691
  };
10489
- const hsc = await this._sealer.seal(pending, HANDSHAKE_CONTINUATION_TTL_MS);
10692
+ const continuation = {
10693
+ ...pending,
10694
+ dv,
10695
+ ch: message.channels
10696
+ };
10697
+ const hsc = await this._sealer.seal(continuation, HANDSHAKE_CONTINUATION_TTL_MS);
10490
10698
  return {
10491
10699
  k: "hs",
10492
10700
  m: encodeHandshakeMessage(reply),
@@ -10498,11 +10706,12 @@ var WireExchangeAcceptor = class {
10498
10706
  k: "err",
10499
10707
  message: "prove missing continuation token"
10500
10708
  };
10501
- const pending = await this._sealer.open(request.hsc);
10502
- if (pending == null) return {
10709
+ const continuation = await this._sealer.open(request.hsc);
10710
+ if (continuation == null) return {
10503
10711
  k: "err",
10504
10712
  message: "invalid or expired continuation token"
10505
10713
  };
10714
+ const { dv, ch, ...pending } = continuation;
10506
10715
  const handshake = this._makeHandshake();
10507
10716
  await handshake.restorePending(pending);
10508
10717
  const reply = await handshake.onProve(message);
@@ -10511,13 +10720,16 @@ var WireExchangeAcceptor = class {
10511
10720
  const ticket = {
10512
10721
  client: result.remote,
10513
10722
  securityLevel: result.securityLevel,
10514
- keyMaterial: result.encryptionKeyMaterial
10723
+ keyMaterial: result.encryptionKeyMaterial,
10724
+ dv,
10725
+ ch
10515
10726
  };
10516
10727
  const t = await this._sealer.seal(ticket, this._sessionTtlMs);
10517
10728
  return {
10518
10729
  k: "hs",
10519
10730
  m: encodeHandshakeMessage(reply),
10520
- t
10731
+ t,
10732
+ ttl: this._sessionTtlMs
10521
10733
  };
10522
10734
  }
10523
10735
  return {
@@ -10530,6 +10742,10 @@ var WireExchangeAcceptor = class {
10530
10742
  message: `unexpected handshake message ${message.t}`
10531
10743
  };
10532
10744
  }
10745
+ _dictionaryVersion(channels) {
10746
+ const version = this._lane.dictionaryVersion;
10747
+ return typeof version === "function" ? version({ channels: channels == null ? void 0 : [...channels] }) : version;
10748
+ }
10533
10749
  async _handleAction(request) {
10534
10750
  let client;
10535
10751
  let crypto;
@@ -10537,24 +10753,30 @@ var WireExchangeAcceptor = class {
10537
10753
  let securityLevel = "none";
10538
10754
  if (request.t != null) {
10539
10755
  const ticket = await this._sealer.open(request.t);
10540
- if (ticket == null) return {
10541
- k: "err",
10542
- message: "unknown or expired session token"
10543
- };
10544
- client = new RuntimeCoordinate(ticket.client);
10756
+ if (ticket == null) return refused("unknown or expired session token");
10757
+ if (ticket.dv != null && ticket.dv !== this._dictionaryVersion(ticket.ch)) return refused("session was agreed under another dictionary version");
10758
+ client = new RuntimeCoordinate(typeof request.i === "string" ? {
10759
+ ...ticket.client,
10760
+ insId: request.i
10761
+ } : ticket.client);
10545
10762
  securityLevel = ticket.securityLevel;
10546
- crypto = ticket.securityLevel === "encrypted" && ticket.keyMaterial != null ? createActionFrameCrypto({
10547
- link: this._security.link,
10548
- keyMaterial: ticket.keyMaterial
10549
- }) : void 0;
10550
- if ("c" in request) {
10551
- if (crypto == null) return {
10552
- k: "err",
10553
- message: "session is not encrypted"
10554
- };
10555
- const plain = await crypto.decryptFrame(base64ToBytes(request.c));
10556
- wire = JSON.parse(textDecoder.decode(plain));
10557
- } else wire = request.w;
10763
+ if (ticket.securityLevel === "encrypted") {
10764
+ if (!("c" in request)) return refused("encrypted session refuses a plaintext act");
10765
+ if (ticket.keyMaterial == null) return refused("encrypted session has no key material");
10766
+ crypto = createActionFrameCrypto({
10767
+ link: this._security.link,
10768
+ keyMaterial: ticket.keyMaterial
10769
+ });
10770
+ try {
10771
+ const plain = await crypto.decryptFrame(base64ToBytes(request.c));
10772
+ wire = JSON.parse(textDecoder.decode(plain));
10773
+ } catch {
10774
+ return refused("undecryptable act");
10775
+ }
10776
+ } else {
10777
+ if ("c" in request) return refused("session is not encrypted");
10778
+ wire = request.w;
10779
+ }
10558
10780
  } else {
10559
10781
  if (!this._noneAllowed || "c" in request) return {
10560
10782
  k: "err",
@@ -10572,7 +10794,7 @@ var WireExchangeAcceptor = class {
10572
10794
  k: "err",
10573
10795
  message: laneReply.message
10574
10796
  };
10575
- if (crypto != null && "c" in request) return {
10797
+ if (crypto != null) return {
10576
10798
  k: "act",
10577
10799
  c: bytesToBase64(await crypto.encryptFrame(textEncoder.encode(JSON.stringify(laneReply.wire))))
10578
10800
  };
@@ -10588,6 +10810,13 @@ var WireExchangeAcceptor = class {
10588
10810
  });
10589
10811
  }
10590
10812
  };
10813
+ function refused(message) {
10814
+ return {
10815
+ k: "err",
10816
+ message,
10817
+ id: WIRE_EXCHANGE_SESSION_REFUSED
10818
+ };
10819
+ }
10591
10820
  //#endregion
10592
10821
  //#region ../nice-wire/src/codec/controlFrame.ts
10593
10822
  /** msgpack map (object) first-byte prefixes — fixmap `0x80–0x8f`, map16 `0xde`, map32 `0xdf`. */
@@ -16981,6 +17210,7 @@ function transport(options) {
16981
17210
  link,
16982
17211
  localCoordinate: (options.identity ?? options.runtime.coordinate).toJsonObject(),
16983
17212
  expectedPeer: options.expectedPeer?.toJsonObject(),
17213
+ reuseExchangeSessions: options.reuseExchangeSessions,
16984
17214
  dictionaryVersion: channel.dictionaryVersion,
16985
17215
  channelTags: channel.tags,
16986
17216
  mux: options.mux
@@ -17148,6 +17378,7 @@ function connectChannel(runtime, channel, options) {
17148
17378
  secure: descriptor.secure ?? true,
17149
17379
  link,
17150
17380
  securityLevel: descriptor.securityLevel ?? securityLevel,
17381
+ reuseExchangeSessions: options.reuseExchangeSessions,
17151
17382
  available: descriptor.available,
17152
17383
  label: descriptor.label,
17153
17384
  mux: wireMux,