@agentvault/agentvault 0.20.24 → 0.20.26

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/index.js CHANGED
@@ -62728,22 +62728,43 @@ function mlsFileName(groupId) {
62728
62728
  }
62729
62729
  async function hasPendingWelcome(dataDir, groupId) {
62730
62730
  try {
62731
- const filePath = join(dataDir, `mls-kp-pending-${groupId.replace(/[^a-zA-Z0-9_-]/g, "_")}.lock`);
62732
- await readFile(filePath);
62731
+ await readFile(pendingKpPath(dataDir, groupId));
62733
62732
  return true;
62734
62733
  } catch {
62735
62734
  return false;
62736
62735
  }
62737
62736
  }
62738
- async function setPendingWelcome(dataDir, groupId) {
62737
+ async function savePendingKpBundle(dataDir, groupId, kp) {
62739
62738
  await mkdir(dataDir, { recursive: true, mode: DIR_MODE });
62740
- const filePath = join(dataDir, `mls-kp-pending-${groupId.replace(/[^a-zA-Z0-9_-]/g, "_")}.lock`);
62741
- await writeFile(filePath, (/* @__PURE__ */ new Date()).toISOString(), { encoding: "utf-8", mode: FILE_MODE });
62739
+ const serialized = {
62740
+ publicPackage: Buffer.from(kp.publicPackage).toString("base64"),
62741
+ privatePackage: {
62742
+ initPrivateKey: Buffer.from(kp.privatePackage.initPrivateKey).toString("base64"),
62743
+ hpkePrivateKey: Buffer.from(kp.privatePackage.hpkePrivateKey).toString("base64"),
62744
+ signaturePrivateKey: Buffer.from(kp.privatePackage.signaturePrivateKey).toString("base64")
62745
+ }
62746
+ };
62747
+ await writeFile(pendingKpPath(dataDir, groupId), JSON.stringify(serialized), { encoding: "utf-8", mode: FILE_MODE });
62748
+ }
62749
+ async function loadPendingKpBundle(dataDir, groupId) {
62750
+ try {
62751
+ const raw = await readFile(pendingKpPath(dataDir, groupId), "utf-8");
62752
+ const parsed = JSON.parse(raw);
62753
+ return {
62754
+ publicPackage: new Uint8Array(Buffer.from(parsed.publicPackage, "base64")),
62755
+ privatePackage: {
62756
+ initPrivateKey: new Uint8Array(Buffer.from(parsed.privatePackage.initPrivateKey, "base64")),
62757
+ hpkePrivateKey: new Uint8Array(Buffer.from(parsed.privatePackage.hpkePrivateKey, "base64")),
62758
+ signaturePrivateKey: new Uint8Array(Buffer.from(parsed.privatePackage.signaturePrivateKey, "base64"))
62759
+ }
62760
+ };
62761
+ } catch {
62762
+ return null;
62763
+ }
62742
62764
  }
62743
62765
  async function clearPendingWelcome(dataDir, groupId) {
62744
62766
  try {
62745
- const filePath = join(dataDir, `mls-kp-pending-${groupId.replace(/[^a-zA-Z0-9_-]/g, "_")}.lock`);
62746
- await rm(filePath);
62767
+ await rm(pendingKpPath(dataDir, groupId));
62747
62768
  } catch {
62748
62769
  }
62749
62770
  }
@@ -62767,12 +62788,13 @@ async function deleteMlsState(dataDir, groupId) {
62767
62788
  } catch {
62768
62789
  }
62769
62790
  }
62770
- var FILE_MODE, DIR_MODE;
62791
+ var FILE_MODE, DIR_MODE, pendingKpPath;
62771
62792
  var init_mls_state = __esm({
62772
62793
  "src/mls-state.ts"() {
62773
62794
  "use strict";
62774
62795
  FILE_MODE = 384;
62775
62796
  DIR_MODE = 448;
62797
+ pendingKpPath = (dataDir, groupId) => join(dataDir, `mls-kp-pending-${groupId.replace(/[^a-zA-Z0-9_-]/g, "_")}.json`);
62776
62798
  }
62777
62799
  });
62778
62800
 
@@ -65258,11 +65280,11 @@ var init_channel = __esm({
65258
65280
  console.log(`[SecureChannel] A2A ${chId.slice(0, 8)} sync fallback: skipping \u2014 Welcome already pending for group=${groupId.slice(0, 8)}`);
65259
65281
  continue;
65260
65282
  }
65261
- await setPendingWelcome(this.config.dataDir, groupId);
65262
65283
  const mgr = new MLSGroupManager();
65263
65284
  const identity = new TextEncoder().encode(this._persisted.deviceId);
65264
65285
  const kp = await mgr.generateKeyPackage(identity);
65265
65286
  this._pendingMlsKpBundle = kp;
65287
+ await savePendingKpBundle(this.config.dataDir, groupId, kp);
65266
65288
  const kpBytes = MLSGroupManager.serializeKeyPackage(kp.publicPackage);
65267
65289
  await fetch(`${this.config.apiUrl}/api/v1/mls/key-packages`, {
65268
65290
  method: "POST",
@@ -67126,12 +67148,14 @@ ${messageText}`;
67126
67148
  async _handleMlsWelcome(data) {
67127
67149
  const groupId = data.group_id;
67128
67150
  const conversationId = data.conversation_id;
67129
- const kpSource = this._pendingMlsKpBundle ? "pending" : this._mlsKeyPackage ? "connect" : "generated";
67151
+ const persistedKpAvailable = await hasPendingWelcome(this.config.dataDir, groupId);
67152
+ const kpSource = this._pendingMlsKpBundle ? "pending" : persistedKpAvailable ? "persisted" : this._mlsKeyPackage ? "connect" : "generated";
67130
67153
  console.log(`[SecureChannel] Received MLS welcome for group ${groupId?.slice(0, 8)}${conversationId ? ` conv=${conversationId.slice(0, 8)}` : ""} kpSource=${kpSource}`);
67131
67154
  try {
67132
67155
  const welcomeBytes = new Uint8Array(Buffer.from(data.payload, "hex"));
67133
67156
  const mgr = new MLSGroupManager();
67134
- const kp = this._pendingMlsKpBundle ?? this._mlsKeyPackage ?? await (async () => {
67157
+ const persistedKp = await loadPendingKpBundle(this.config.dataDir, groupId);
67158
+ const kp = this._pendingMlsKpBundle ?? persistedKp ?? this._mlsKeyPackage ?? await (async () => {
67135
67159
  const identity = new TextEncoder().encode(this._deviceId);
67136
67160
  return mgr.generateKeyPackage(identity);
67137
67161
  })();
@@ -94836,7 +94860,7 @@ var init_index = __esm({
94836
94860
  init_skill_invoker();
94837
94861
  await init_skill_telemetry();
94838
94862
  await init_policy_enforcer();
94839
- VERSION = true ? "0.20.24" : "0.0.0-dev";
94863
+ VERSION = true ? "0.20.26" : "0.0.0-dev";
94840
94864
  }
94841
94865
  });
94842
94866
  await init_index();