@agentvault/agentvault 0.20.25 → 0.20.27

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
@@ -62734,10 +62734,10 @@ async function hasPendingWelcome(dataDir, groupId) {
62734
62734
  return false;
62735
62735
  }
62736
62736
  }
62737
- async function savePendingKpBundle(dataDir, groupId, kp) {
62737
+ async function savePendingKpBundle(dataDir, groupId, kp, serializePublicFn) {
62738
62738
  await mkdir(dataDir, { recursive: true, mode: DIR_MODE });
62739
62739
  const serialized = {
62740
- publicPackage: Buffer.from(kp.publicPackage).toString("base64"),
62740
+ publicPackageBytes: Buffer.from(serializePublicFn(kp.publicPackage)).toString("base64"),
62741
62741
  privatePackage: {
62742
62742
  initPrivateKey: Buffer.from(kp.privatePackage.initPrivateKey).toString("base64"),
62743
62743
  hpkePrivateKey: Buffer.from(kp.privatePackage.hpkePrivateKey).toString("base64"),
@@ -62751,7 +62751,7 @@ async function loadPendingKpBundle(dataDir, groupId) {
62751
62751
  const raw = await readFile(pendingKpPath(dataDir, groupId), "utf-8");
62752
62752
  const parsed = JSON.parse(raw);
62753
62753
  return {
62754
- publicPackage: new Uint8Array(Buffer.from(parsed.publicPackage, "base64")),
62754
+ publicPackageBytes: new Uint8Array(Buffer.from(parsed.publicPackageBytes, "base64")),
62755
62755
  privatePackage: {
62756
62756
  initPrivateKey: new Uint8Array(Buffer.from(parsed.privatePackage.initPrivateKey, "base64")),
62757
62757
  hpkePrivateKey: new Uint8Array(Buffer.from(parsed.privatePackage.hpkePrivateKey, "base64")),
@@ -65280,12 +65280,11 @@ var init_channel = __esm({
65280
65280
  console.log(`[SecureChannel] A2A ${chId.slice(0, 8)} sync fallback: skipping \u2014 Welcome already pending for group=${groupId.slice(0, 8)}`);
65281
65281
  continue;
65282
65282
  }
65283
- await setPendingWelcome(this.config.dataDir, groupId);
65284
65283
  const mgr = new MLSGroupManager();
65285
65284
  const identity = new TextEncoder().encode(this._persisted.deviceId);
65286
65285
  const kp = await mgr.generateKeyPackage(identity);
65287
65286
  this._pendingMlsKpBundle = kp;
65288
- await savePendingKpBundle(this.config.dataDir, groupId, kp);
65287
+ await savePendingKpBundle(this.config.dataDir, groupId, kp, MLSGroupManager.serializeKeyPackage);
65289
65288
  const kpBytes = MLSGroupManager.serializeKeyPackage(kp.publicPackage);
65290
65289
  await fetch(`${this.config.apiUrl}/api/v1/mls/key-packages`, {
65291
65290
  method: "POST",
@@ -67149,17 +67148,26 @@ ${messageText}`;
67149
67148
  async _handleMlsWelcome(data) {
67150
67149
  const groupId = data.group_id;
67151
67150
  const conversationId = data.conversation_id;
67152
- const persistedKpAvailable = await hasPendingWelcome(this.config.dataDir, groupId);
67153
- const kpSource = this._pendingMlsKpBundle ? "pending" : persistedKpAvailable ? "persisted" : this._mlsKeyPackage ? "connect" : "generated";
67151
+ const kpSource = this._pendingMlsKpBundle ? "pending" : this._mlsKeyPackage ? "connect" : await hasPendingWelcome(this.config.dataDir, groupId) ? "persisted" : "generated";
67154
67152
  console.log(`[SecureChannel] Received MLS welcome for group ${groupId?.slice(0, 8)}${conversationId ? ` conv=${conversationId.slice(0, 8)}` : ""} kpSource=${kpSource}`);
67155
67153
  try {
67156
67154
  const welcomeBytes = new Uint8Array(Buffer.from(data.payload, "hex"));
67157
67155
  const mgr = new MLSGroupManager();
67158
- const persistedKp = await loadPendingKpBundle(this.config.dataDir, groupId);
67159
- const kp = this._pendingMlsKpBundle ?? persistedKp ?? this._mlsKeyPackage ?? await (async () => {
67156
+ let kp = this._pendingMlsKpBundle ?? this._mlsKeyPackage;
67157
+ if (!kp) {
67158
+ const persisted = await loadPendingKpBundle(this.config.dataDir, groupId);
67159
+ if (persisted) {
67160
+ kp = {
67161
+ publicPackage: MLSGroupManager.deserializeKeyPackage(persisted.publicPackageBytes),
67162
+ privatePackage: persisted.privatePackage
67163
+ };
67164
+ console.log(`[SecureChannel] Loaded persisted KP bundle for group ${groupId?.slice(0, 8)}`);
67165
+ }
67166
+ }
67167
+ if (!kp) {
67160
67168
  const identity = new TextEncoder().encode(this._deviceId);
67161
- return mgr.generateKeyPackage(identity);
67162
- })();
67169
+ kp = await mgr.generateKeyPackage(identity);
67170
+ }
67163
67171
  console.log(`[SecureChannel] Welcome joinFromWelcome: group=${groupId?.slice(0, 8)} kpSource=${kpSource} welcomeLen=${welcomeBytes.length}`);
67164
67172
  await mgr.joinFromWelcome(welcomeBytes, kp);
67165
67173
  if (conversationId) {
@@ -94861,7 +94869,7 @@ var init_index = __esm({
94861
94869
  init_skill_invoker();
94862
94870
  await init_skill_telemetry();
94863
94871
  await init_policy_enforcer();
94864
- VERSION = true ? "0.20.25" : "0.0.0-dev";
94872
+ VERSION = true ? "0.20.27" : "0.0.0-dev";
94865
94873
  }
94866
94874
  });
94867
94875
  await init_index();