@agentvault/agentvault 0.20.24 → 0.20.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -62729,22 +62729,43 @@ function mlsFileName(groupId) {
62729
62729
  }
62730
62730
  async function hasPendingWelcome(dataDir2, groupId) {
62731
62731
  try {
62732
- const filePath = join(dataDir2, `mls-kp-pending-${groupId.replace(/[^a-zA-Z0-9_-]/g, "_")}.lock`);
62733
- await readFile(filePath);
62732
+ await readFile(pendingKpPath(dataDir2, groupId));
62734
62733
  return true;
62735
62734
  } catch {
62736
62735
  return false;
62737
62736
  }
62738
62737
  }
62739
- async function setPendingWelcome(dataDir2, groupId) {
62738
+ async function savePendingKpBundle(dataDir2, groupId, kp) {
62740
62739
  await mkdir(dataDir2, { recursive: true, mode: DIR_MODE });
62741
- const filePath = join(dataDir2, `mls-kp-pending-${groupId.replace(/[^a-zA-Z0-9_-]/g, "_")}.lock`);
62742
- await writeFile(filePath, (/* @__PURE__ */ new Date()).toISOString(), { encoding: "utf-8", mode: FILE_MODE });
62740
+ const serialized = {
62741
+ publicPackage: Buffer.from(kp.publicPackage).toString("base64"),
62742
+ privatePackage: {
62743
+ initPrivateKey: Buffer.from(kp.privatePackage.initPrivateKey).toString("base64"),
62744
+ hpkePrivateKey: Buffer.from(kp.privatePackage.hpkePrivateKey).toString("base64"),
62745
+ signaturePrivateKey: Buffer.from(kp.privatePackage.signaturePrivateKey).toString("base64")
62746
+ }
62747
+ };
62748
+ await writeFile(pendingKpPath(dataDir2, groupId), JSON.stringify(serialized), { encoding: "utf-8", mode: FILE_MODE });
62749
+ }
62750
+ async function loadPendingKpBundle(dataDir2, groupId) {
62751
+ try {
62752
+ const raw = await readFile(pendingKpPath(dataDir2, groupId), "utf-8");
62753
+ const parsed = JSON.parse(raw);
62754
+ return {
62755
+ publicPackage: new Uint8Array(Buffer.from(parsed.publicPackage, "base64")),
62756
+ privatePackage: {
62757
+ initPrivateKey: new Uint8Array(Buffer.from(parsed.privatePackage.initPrivateKey, "base64")),
62758
+ hpkePrivateKey: new Uint8Array(Buffer.from(parsed.privatePackage.hpkePrivateKey, "base64")),
62759
+ signaturePrivateKey: new Uint8Array(Buffer.from(parsed.privatePackage.signaturePrivateKey, "base64"))
62760
+ }
62761
+ };
62762
+ } catch {
62763
+ return null;
62764
+ }
62743
62765
  }
62744
62766
  async function clearPendingWelcome(dataDir2, groupId) {
62745
62767
  try {
62746
- const filePath = join(dataDir2, `mls-kp-pending-${groupId.replace(/[^a-zA-Z0-9_-]/g, "_")}.lock`);
62747
- await rm(filePath);
62768
+ await rm(pendingKpPath(dataDir2, groupId));
62748
62769
  } catch {
62749
62770
  }
62750
62771
  }
@@ -62768,12 +62789,13 @@ async function deleteMlsState(dataDir2, groupId) {
62768
62789
  } catch {
62769
62790
  }
62770
62791
  }
62771
- var FILE_MODE, DIR_MODE;
62792
+ var FILE_MODE, DIR_MODE, pendingKpPath;
62772
62793
  var init_mls_state = __esm({
62773
62794
  "src/mls-state.ts"() {
62774
62795
  "use strict";
62775
62796
  FILE_MODE = 384;
62776
62797
  DIR_MODE = 448;
62798
+ pendingKpPath = (dataDir2, groupId) => join(dataDir2, `mls-kp-pending-${groupId.replace(/[^a-zA-Z0-9_-]/g, "_")}.json`);
62777
62799
  }
62778
62800
  });
62779
62801
 
@@ -65264,6 +65286,7 @@ var init_channel = __esm({
65264
65286
  const identity = new TextEncoder().encode(this._persisted.deviceId);
65265
65287
  const kp = await mgr.generateKeyPackage(identity);
65266
65288
  this._pendingMlsKpBundle = kp;
65289
+ await savePendingKpBundle(this.config.dataDir, groupId, kp);
65267
65290
  const kpBytes = MLSGroupManager.serializeKeyPackage(kp.publicPackage);
65268
65291
  await fetch(`${this.config.apiUrl}/api/v1/mls/key-packages`, {
65269
65292
  method: "POST",
@@ -67127,12 +67150,14 @@ ${messageText}`;
67127
67150
  async _handleMlsWelcome(data) {
67128
67151
  const groupId = data.group_id;
67129
67152
  const conversationId = data.conversation_id;
67130
- const kpSource = this._pendingMlsKpBundle ? "pending" : this._mlsKeyPackage ? "connect" : "generated";
67153
+ const persistedKpAvailable = await hasPendingWelcome(this.config.dataDir, groupId);
67154
+ const kpSource = this._pendingMlsKpBundle ? "pending" : persistedKpAvailable ? "persisted" : this._mlsKeyPackage ? "connect" : "generated";
67131
67155
  console.log(`[SecureChannel] Received MLS welcome for group ${groupId?.slice(0, 8)}${conversationId ? ` conv=${conversationId.slice(0, 8)}` : ""} kpSource=${kpSource}`);
67132
67156
  try {
67133
67157
  const welcomeBytes = new Uint8Array(Buffer.from(data.payload, "hex"));
67134
67158
  const mgr = new MLSGroupManager();
67135
- const kp = this._pendingMlsKpBundle ?? this._mlsKeyPackage ?? await (async () => {
67159
+ const persistedKp = await loadPendingKpBundle(this.config.dataDir, groupId);
67160
+ const kp = this._pendingMlsKpBundle ?? persistedKp ?? this._mlsKeyPackage ?? await (async () => {
67136
67161
  const identity = new TextEncoder().encode(this._deviceId);
67137
67162
  return mgr.generateKeyPackage(identity);
67138
67163
  })();
@@ -88939,7 +88964,7 @@ var init_index = __esm({
88939
88964
  init_skill_invoker();
88940
88965
  await init_skill_telemetry();
88941
88966
  await init_policy_enforcer();
88942
- VERSION = true ? "0.20.24" : "0.0.0-dev";
88967
+ VERSION = true ? "0.20.25" : "0.0.0-dev";
88943
88968
  }
88944
88969
  });
88945
88970