@majikah/majik-message 0.2.6 → 0.2.9

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.
@@ -208,6 +208,7 @@ export declare class MajikKeyStore {
208
208
  * Drop-in for MajikKeyStore.deleteIdentity().
209
209
  */
210
210
  static deleteIdentity(id: string): Promise<void>;
211
+ static deleteAll(): Promise<void>;
211
212
  /**
212
213
  * Drop-in for MajikKeyStore.generateMnemonic().
213
214
  */
@@ -6,7 +6,7 @@
6
6
  *
7
7
  */
8
8
  import { MajikKey } from "@majikah/majik-key";
9
- import { base64ToArrayBuffer } from "../utils/utilities";
9
+ // import { base64ToArrayBuffer } from "../utils/utilities";
10
10
  import { KDF_VERSION } from "./constants";
11
11
  // ─── IDB Config ───────────────────────────────────────────────────────────────
12
12
  const STORE_NAME = "majik-keys";
@@ -381,11 +381,11 @@ export class MajikKeyStore {
381
381
  if (!si.id || !si.publicKey || !si.fingerprint) {
382
382
  throw new MajikKeyStoreError("Invalid legacy SerializedIdentity: missing required fields");
383
383
  }
384
- // SerializedIdentity may or may not have encryptedPrivateKey
385
- // (some records were stored without it — public-key-only contacts)
386
- const encryptedPrivateKey = si.encryptedPrivateKey
387
- ? base64ToArrayBuffer(si.encryptedPrivateKey)
388
- : new ArrayBuffer(0);
384
+ // // SerializedIdentity may or may not have encryptedPrivateKey
385
+ // // (some records were stored without it — public-key-only contacts)
386
+ // const encryptedPrivateKey = si.encryptedPrivateKey
387
+ // ? base64ToArrayBuffer(si.encryptedPrivateKey)
388
+ // : new ArrayBuffer(0);
389
389
  // Reconstruct as a minimal MajikKeyJSON (v1 PBKDF2, no ML-KEM)
390
390
  const json = {
391
391
  id: si.id,
@@ -519,6 +519,20 @@ export class MajikKeyStore {
519
519
  static async deleteIdentity(id) {
520
520
  return this.delete(id);
521
521
  }
522
+ static async deleteAll() {
523
+ const db = await this._getDB();
524
+ const clearStore = (storeName) => new Promise((resolve, reject) => {
525
+ if (!db.objectStoreNames.contains(storeName))
526
+ return resolve();
527
+ const tx = db.transaction(storeName, "readwrite");
528
+ const req = tx.objectStore(storeName).clear();
529
+ req.onsuccess = () => resolve();
530
+ req.onerror = () => reject(new MajikKeyStoreError(`Failed to clear store: ${storeName}`, req.error));
531
+ });
532
+ await clearStore(STORE_NAME);
533
+ await clearStore(LEGACY_STORE_NAME);
534
+ this._keys.clear();
535
+ }
522
536
  /**
523
537
  * Drop-in for MajikKeyStore.generateMnemonic().
524
538
  */
@@ -28,7 +28,6 @@ export interface EnvelopeCacheItem {
28
28
  message?: string;
29
29
  }
30
30
  export declare class EnvelopeCache {
31
- private userProfile;
32
31
  private dbPromise;
33
32
  private dbName;
34
33
  private storeName;
@@ -15,7 +15,7 @@ export class EnvelopeCacheError extends Error {
15
15
  * EnvelopeCache
16
16
  * ------------------------------- */
17
17
  export class EnvelopeCache {
18
- userProfile = "default";
18
+ // private userProfile: string = "default";
19
19
  dbPromise;
20
20
  dbName;
21
21
  storeName;
@@ -29,7 +29,7 @@ export class EnvelopeCache {
29
29
  this.maxEntries = config?.maxEntries;
30
30
  this.memoryCacheSize = config?.memoryCacheSize || 100;
31
31
  this.memoryCache = new Map();
32
- this.userProfile = userProfile || "default";
32
+ // this.userProfile = userProfile || "default";
33
33
  this.dbPromise = this.initDB();
34
34
  }
35
35
  /* -------------------------------
@@ -44,11 +44,6 @@ export declare class MajikMessage {
44
44
  private readonly autosaveIntervalMs;
45
45
  private readonly autosaveDebounceMs;
46
46
  constructor(config: MajikMessageConfig, id?: string, userProfile?: string);
47
- /**
48
- * Resolve a list of account/contact IDs into MajikRecipient objects.
49
- * Each recipient needs their ML-KEM public key from MajikKeyStore.
50
- */
51
- private _resolveRecipients;
52
47
  /**
53
48
  * Resolve a list of account/contact IDs into MajikRecipient objects.
54
49
  * Each recipient needs their ML-KEM public key from MajikKeyStore.
@@ -59,27 +59,30 @@ export class MajikMessage {
59
59
  this.attachAutosaveHandlers();
60
60
  }
61
61
  // ── Private: Envelope helpers ────────────────────────────────────────────
62
- /**
63
- * Resolve a list of account/contact IDs into MajikRecipient objects.
64
- * Each recipient needs their ML-KEM public key from MajikKeyStore.
65
- */
66
- async _resolveRecipients(ids) {
67
- return Promise.all(ids.map(async (id) => {
68
- const contact = this.contactDirectory.getContact(id);
69
- if (!contact)
70
- throw new Error(`No contact found for id "${id}"`);
71
- // const key = await MajikKeyStore.load(id);
72
- const mlPubKey = base64ToUint8Array(contact.mlKey);
73
- if (!mlPubKey) {
74
- throw new Error(`Contact "${id}" has no ML-KEM public key. ` +
75
- `They may need to upgrade their account via importFromMnemonicBackup().`);
76
- }
77
- return {
78
- fingerprint: contact.fingerprint,
79
- mlKemPublicKey: mlPubKey,
80
- };
81
- }));
82
- }
62
+ // /**
63
+ // * Resolve a list of account/contact IDs into MajikRecipient objects.
64
+ // * Each recipient needs their ML-KEM public key from MajikKeyStore.
65
+ // */
66
+ // private async _resolveRecipients(ids: string[]): Promise<MajikRecipient[]> {
67
+ // return Promise.all(
68
+ // ids.map(async (id) => {
69
+ // const contact = this.contactDirectory.getContact(id);
70
+ // if (!contact) throw new Error(`No contact found for id "${id}"`);
71
+ // // const key = await MajikKeyStore.load(id);
72
+ // const mlPubKey = base64ToUint8Array(contact.mlKey);
73
+ // if (!mlPubKey) {
74
+ // throw new Error(
75
+ // `Contact "${id}" has no ML-KEM public key. ` +
76
+ // `They may need to upgrade their account via importFromMnemonicBackup().`,
77
+ // );
78
+ // }
79
+ // return {
80
+ // fingerprint: contact.fingerprint,
81
+ // mlKemPublicKey: mlPubKey,
82
+ // } satisfies MajikRecipient;
83
+ // }),
84
+ // );
85
+ // }
83
86
  /**
84
87
  * Resolve a list of account/contact IDs into MajikRecipient objects.
85
88
  * Each recipient needs their ML-KEM public key from MajikKeyStore.
@@ -1998,6 +2001,12 @@ export class MajikMessage {
1998
2001
  catch {
1999
2002
  /* ignore */
2000
2003
  }
2004
+ try {
2005
+ await MajikKeyStore.deleteAll();
2006
+ }
2007
+ catch {
2008
+ /* ignore */
2009
+ }
2001
2010
  this.pinHash = null;
2002
2011
  this.id = arrayToBase64(randomBytes(32));
2003
2012
  try {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@majikah/majik-message",
3
3
  "type": "module",
4
4
  "description": "Post-quantum end-to-end encryption with ML-KEM-768. Seed phrase–based accounts. Auto-expiring messages. Offline-ready. Exportable encrypted messages. Tamper-proof threads with blockchain-like integrity. Quantum-resistant messaging.",
5
- "version": "0.2.6",
5
+ "version": "0.2.9",
6
6
  "license": "Apache-2.0",
7
7
  "author": "Zelijah",
8
8
  "main": "./dist/index.js",
@@ -81,9 +81,9 @@
81
81
  "dependencies": {
82
82
  "@bokuweb/zstd-wasm": "^0.0.27",
83
83
  "@majikah/majik-envelope": "^0.0.1",
84
- "@majikah/majik-file": "^0.0.17",
85
- "@majikah/majik-key": "^0.2.0",
86
- "@majikah/majik-signature": "^0.0.3",
84
+ "@majikah/majik-file": "^0.0.19",
85
+ "@majikah/majik-key": "^0.2.2",
86
+ "@majikah/majik-signature": "^0.0.6",
87
87
  "@noble/hashes": "^2.0.1",
88
88
  "@noble/post-quantum": "^0.5.4",
89
89
  "@scure/bip39": "^1.6.0",