@agentvault/agentvault 0.20.26 → 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")),
@@ -65284,7 +65284,7 @@ var init_channel = __esm({
65284
65284
  const identity = new TextEncoder().encode(this._persisted.deviceId);
65285
65285
  const kp = await mgr.generateKeyPackage(identity);
65286
65286
  this._pendingMlsKpBundle = kp;
65287
- await savePendingKpBundle(this.config.dataDir, groupId, kp);
65287
+ await savePendingKpBundle(this.config.dataDir, groupId, kp, MLSGroupManager.serializeKeyPackage);
65288
65288
  const kpBytes = MLSGroupManager.serializeKeyPackage(kp.publicPackage);
65289
65289
  await fetch(`${this.config.apiUrl}/api/v1/mls/key-packages`, {
65290
65290
  method: "POST",
@@ -67148,17 +67148,26 @@ ${messageText}`;
67148
67148
  async _handleMlsWelcome(data) {
67149
67149
  const groupId = data.group_id;
67150
67150
  const conversationId = data.conversation_id;
67151
- const persistedKpAvailable = await hasPendingWelcome(this.config.dataDir, groupId);
67152
- 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";
67153
67152
  console.log(`[SecureChannel] Received MLS welcome for group ${groupId?.slice(0, 8)}${conversationId ? ` conv=${conversationId.slice(0, 8)}` : ""} kpSource=${kpSource}`);
67154
67153
  try {
67155
67154
  const welcomeBytes = new Uint8Array(Buffer.from(data.payload, "hex"));
67156
67155
  const mgr = new MLSGroupManager();
67157
- const persistedKp = await loadPendingKpBundle(this.config.dataDir, groupId);
67158
- 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) {
67159
67168
  const identity = new TextEncoder().encode(this._deviceId);
67160
- return mgr.generateKeyPackage(identity);
67161
- })();
67169
+ kp = await mgr.generateKeyPackage(identity);
67170
+ }
67162
67171
  console.log(`[SecureChannel] Welcome joinFromWelcome: group=${groupId?.slice(0, 8)} kpSource=${kpSource} welcomeLen=${welcomeBytes.length}`);
67163
67172
  await mgr.joinFromWelcome(welcomeBytes, kp);
67164
67173
  if (conversationId) {
@@ -94860,7 +94869,7 @@ var init_index = __esm({
94860
94869
  init_skill_invoker();
94861
94870
  await init_skill_telemetry();
94862
94871
  await init_policy_enforcer();
94863
- VERSION = true ? "0.20.26" : "0.0.0-dev";
94872
+ VERSION = true ? "0.20.27" : "0.0.0-dev";
94864
94873
  }
94865
94874
  });
94866
94875
  await init_index();