negotium 0.2.0 → 0.2.1

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/main.js CHANGED
@@ -411,9 +411,9 @@ var init_sqlite = __esm(async () => {
411
411
  }
412
412
  });
413
413
 
414
- // ../../packages/core/src/storage/vault-crypto.ts
414
+ // ../../packages/core/src/storage/vault-crypto-core.ts
415
415
  import { createCipheriv, createDecipheriv, createHash, randomBytes as randomBytes2 } from "crypto";
416
- function encryptionKey(masterKey = VAULT_MASTER_KEY) {
416
+ function encryptionKey(masterKey) {
417
417
  return createHash("sha256").update("otium-vault-value-v1\x00", "utf8").update(masterKey, "utf8").digest().subarray(0, KEY_BYTES);
418
418
  }
419
419
  function aad(userId, key) {
@@ -422,7 +422,7 @@ function aad(userId, key) {
422
422
  function isEncryptedVaultValue(value) {
423
423
  return value.startsWith(ENVELOPE_PREFIX);
424
424
  }
425
- function encryptVaultValue(userId, key, value, masterKey = VAULT_MASTER_KEY) {
425
+ function encryptVaultValueWithKey(userId, key, value, masterKey) {
426
426
  const iv = randomBytes2(IV_BYTES);
427
427
  const cipher = createCipheriv("aes-256-gcm", encryptionKey(masterKey), iv);
428
428
  cipher.setAAD(aad(userId, key));
@@ -430,7 +430,7 @@ function encryptVaultValue(userId, key, value, masterKey = VAULT_MASTER_KEY) {
430
430
  const tag = cipher.getAuthTag();
431
431
  return `${ENVELOPE_PREFIX}${iv.toString("base64url")}.${ciphertext.toString("base64url")}.${tag.toString("base64url")}`;
432
432
  }
433
- function decryptVaultValue(userId, key, storedValue, masterKey = VAULT_MASTER_KEY) {
433
+ function decryptVaultValueWithKey(userId, key, storedValue, masterKey) {
434
434
  if (!isEncryptedVaultValue(storedValue)) {
435
435
  return { value: storedValue, legacyPlaintext: true };
436
436
  }
@@ -452,8 +452,18 @@ function decryptVaultValue(userId, key, storedValue, masterKey = VAULT_MASTER_KE
452
452
  return { value: plaintext.toString("utf8"), legacyPlaintext: false };
453
453
  }
454
454
  var ENVELOPE_PREFIX = "otium-vault:v1:", IV_BYTES = 12, KEY_BYTES = 32;
455
+ var init_vault_crypto_core = () => {};
456
+
457
+ // ../../packages/core/src/storage/vault-crypto.ts
458
+ function encryptVaultValue(userId, key, value, masterKey = VAULT_MASTER_KEY) {
459
+ return encryptVaultValueWithKey(userId, key, value, masterKey);
460
+ }
461
+ function decryptVaultValue(userId, key, storedValue, masterKey = VAULT_MASTER_KEY) {
462
+ return decryptVaultValueWithKey(userId, key, storedValue, masterKey);
463
+ }
455
464
  var init_vault_crypto = __esm(() => {
456
465
  init_config();
466
+ init_vault_crypto_core();
457
467
  });
458
468
 
459
469
  // ../../packages/core/src/storage/vault.ts
@@ -4584,7 +4594,7 @@ var exports_version = {};
4584
4594
  __export(exports_version, {
4585
4595
  NEGOTIUM_VERSION: () => NEGOTIUM_VERSION
4586
4596
  });
4587
- var NEGOTIUM_VERSION = "0.2.0";
4597
+ var NEGOTIUM_VERSION = "0.2.1";
4588
4598
 
4589
4599
  // ../../packages/core/src/agents/codex-native-multi-agent.ts
4590
4600
  import { spawn as spawn3 } from "child_process";
@@ -43800,8 +43810,8 @@ function migrateDatabase(dbPath, source, masterKey, legacyTopicProfiles = []) {
43800
43810
  throw new Error("Cannot migrate encrypted vault rows without vault-master-key.");
43801
43811
  const rows = database.query("SELECT key, value FROM vault WHERE user_id = ?").all(source);
43802
43812
  for (const row of rows) {
43803
- const plaintext = decryptVaultValue(source, row.key, row.value, masterKey).value;
43804
- database.query("UPDATE vault SET value = ? WHERE user_id = ? AND key = ?").run(encryptVaultValue(CANONICAL_LOCAL_USER_ID, row.key, plaintext, masterKey), source, row.key);
43813
+ const plaintext = decryptVaultValueWithKey(source, row.key, row.value, masterKey).value;
43814
+ database.query("UPDATE vault SET value = ? WHERE user_id = ? AND key = ?").run(encryptVaultValueWithKey(CANONICAL_LOCAL_USER_ID, row.key, plaintext, masterKey), source, row.key);
43805
43815
  }
43806
43816
  }
43807
43817
  database.query(`UPDATE ${quote(table)} SET user_id = ? WHERE user_id = ?`).run(CANONICAL_LOCAL_USER_ID, source);
@@ -44082,7 +44092,7 @@ function migrateSingleUserState(options) {
44082
44092
  }
44083
44093
  var CANONICAL_LOCAL_USER_ID = "local", SINGLE_USER_MIGRATION_ID = "negotium-0.2.0-single-user";
44084
44094
  var init_single_user = __esm(async () => {
44085
- init_vault_crypto();
44095
+ init_vault_crypto_core();
44086
44096
  await init_sqlite();
44087
44097
  });
44088
44098
 
@@ -44788,4 +44798,4 @@ switch (command) {
44788
44798
  }
44789
44799
  }
44790
44800
 
44791
- //# debugId=0E990AB8BEC23DD564756E2164756E21
44801
+ //# debugId=9371DDB5367979FC64756E2164756E21