@majikah/majik-message 0.3.9 → 0.3.11

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.
@@ -10,10 +10,10 @@ import { MajikFile, MajikFileJSON } from "@majikah/majik-file";
10
10
  import { EnvelopeInfo, ExpectedSigner, MajikSignature, SealInfo, SealVerificationResult, SignatoriesFilter, SignatoriesResult, SignatoryInfo, type MajikSignatureJSON, type MajikSignerPublicKeys, type VerificationResult } from "@majikah/majik-signature";
11
11
  import { MajikContactManager, MajikContactManagerAdapters } from "./core/contacts/majik-contact-manager";
12
12
  import { MajikContactManagerJSON } from "./core/contacts/types";
13
- import { ClientStateStorageAdapter, MajikKeyStorageAdapter, SQLiteDatabase } from "./core/storage";
13
+ import { ClientStateStorageAdapter, MajikKeyStorageAdapter, MajikMessageChatStorageAdapter, SQLiteDatabase } from "./core/storage";
14
14
  import { MajikKeyManager } from "./core/crypto/keystore-manager";
15
15
  import { ClientStateManager } from "./core/client-state-manager";
16
- type MajikMessageEvents = "message" | "envelope" | "untrusted" | "error" | "new-account" | "new-contact" | "new-contact-group" | "removed-account" | "removed-contact" | "removed-contact-group" | "contact-group-change" | "active-account-change";
16
+ type MajikMessageEvents = "new-account" | "removed-account" | "active-account-change" | "unlock" | "lock" | "new-contact" | "removed-contact" | "new-contact-group" | "removed-contact-group" | "contact-group-change" | "message" | "envelope" | "untrusted" | "error";
17
17
  export interface MajikMessageConfig {
18
18
  dbSQL?: SQLiteDatabase;
19
19
  /**
@@ -36,6 +36,7 @@ export interface MajikMessageConfig {
36
36
  adapters?: {
37
37
  contacts?: MajikContactManagerAdapters;
38
38
  keys?: MajikKeyStorageAdapter;
39
+ chats?: MajikMessageChatStorageAdapter;
39
40
  /**
40
41
  * Adapter for client-level state (account order, invoice defaults, etc.).
41
42
  * Defaults to IDB_ADAPTER_CLIENT_STATE in browser environments.
@@ -55,7 +56,6 @@ export interface MajikMessageJSON {
55
56
  }
56
57
  type EventCallback = (...args: any[]) => void;
57
58
  export declare class MajikMessage {
58
- private readonly _id;
59
59
  private _db;
60
60
  private _contacts;
61
61
  private _keys;
@@ -147,12 +147,18 @@ export declare class MajikMessage {
147
147
  getActiveAccountKey(): MajikKey | null;
148
148
  isAccountActive(id: string): boolean;
149
149
  setActiveAccount(id: string, bypassIdentity?: boolean): Promise<boolean>;
150
+ unlockAccount(id: string, passphrase: string): Promise<void>;
151
+ lockAccount(id: string): void;
152
+ lockAllAccounts(): void;
153
+ verifyPassphrase(id: string, passphrase: string): Promise<boolean>;
150
154
  listOwnAccounts(majikahOnly?: boolean): MajikContact[];
151
155
  isContactMajikahRegistered(id: string): boolean;
152
156
  isContactMajikahIdentityChecked(id: string): boolean;
153
157
  setContactMajikahStatus(id: string, status: boolean): void;
154
158
  hasOwnIdentity(fingerprint: string): Promise<boolean>;
155
159
  getContactByID(id: string): MajikContact | null;
160
+ hasContact(id: string): boolean;
161
+ hasContactByPublicKeyBase64(publicKey: MajikMessagePublicKey): Promise<boolean>;
156
162
  getContactByPublicKey(publicKeyBase64: string): Promise<MajikContact | null>;
157
163
  getContactsByID(ids: string[], strict?: boolean): MajikContact[];
158
164
  getContactsByPublicKey(publicKeys: string[]): Promise<MajikContact[]>;
@@ -166,7 +172,7 @@ export declare class MajikMessage {
166
172
  importContactCompressed(base64Str: string): Promise<MajikContact>;
167
173
  addContact(contact: MajikContact): Promise<void>;
168
174
  removeContact(id: string): Promise<void>;
169
- listContacts(includeOwnAccounts?: boolean): MajikContact[];
175
+ listContacts(includeOwnAccounts?: boolean, majikahOnly?: boolean): MajikContact[];
170
176
  updateContactMeta(id: string, meta: Partial<MajikContactMeta>): Promise<void>;
171
177
  createGroup(id: string, name: string, meta?: Partial<Omit<MajikContactGroupMeta, "name">>, initialMemberIds?: string[]): Promise<this>;
172
178
  addGroup(group: MajikContactGroup): Promise<this>;
@@ -1,8 +1,7 @@
1
1
  // MajikMessage.ts
2
2
  import { MessageEnvelope } from "./core/messages/message-envelope";
3
3
  import { EnvelopeCache, } from "./core/messages/envelope-cache";
4
- import { arrayToBase64, base64ToUint8Array } from "./core/utils/utilities";
5
- import { randomBytes } from "@stablelib/random";
4
+ import { base64ToUint8Array } from "./core/utils/utilities";
6
5
  import { MajikMessageChat } from "./core/database/chat/majik-message-chat";
7
6
  import { MajikKey } from "@majikah/majik-key";
8
7
  import { MajikEnvelope, } from "@majikah/majik-envelope";
@@ -14,7 +13,6 @@ import { MajikKeyManager } from "./core/crypto/keystore-manager";
14
13
  import { ClientStateManager } from "./core/client-state-manager";
15
14
  // ─── MajikMessage ─────────────────────────────────────────────────────────────
16
15
  export class MajikMessage {
17
- _id;
18
16
  _db;
19
17
  _contacts;
20
18
  _keys;
@@ -31,7 +29,6 @@ export class MajikMessage {
31
29
  _ownAccountsOrder = [];
32
30
  _autosaveOrderTimer = null;
33
31
  constructor(config, id) {
34
- this._id = id || arrayToBase64(randomBytes(32));
35
32
  this._db = config.dbSQL || null;
36
33
  this.envelopeCache = config.envelopeCache || new EnvelopeCache(undefined);
37
34
  this._contacts =
@@ -40,22 +37,26 @@ export class MajikMessage {
40
37
  this._keys =
41
38
  config.keyManager ??
42
39
  new MajikKeyManager(config.adapters?.keys ?? new InMemoryKeystoreAdapter());
40
+ // this._chats =
41
+ // config.
43
42
  this._state =
44
43
  config.clientStateManager ??
45
44
  new ClientStateManager(config.adapters?.clientState ?? new InMemoryClientStateAdapter());
46
45
  const events = [
47
- "message",
48
- "envelope",
49
- "untrusted",
50
- "error",
51
46
  "new-account",
52
- "new-contact",
53
- "new-contact-group",
54
47
  "removed-account",
48
+ "active-account-change",
49
+ "unlock",
50
+ "lock",
51
+ "new-contact",
55
52
  "removed-contact",
53
+ "new-contact-group",
56
54
  "removed-contact-group",
57
55
  "contact-group-change",
58
- "active-account-change",
56
+ "message",
57
+ "envelope",
58
+ "untrusted",
59
+ "error",
59
60
  ];
60
61
  events.forEach((e) => this._listeners.set(e, []));
61
62
  }
@@ -373,6 +374,28 @@ export class MajikMessage {
373
374
  }
374
375
  return true;
375
376
  }
377
+ async unlockAccount(id, passphrase) {
378
+ try {
379
+ await this._keys.unlock(id, passphrase);
380
+ this._emit("unlock", id);
381
+ }
382
+ catch (err) {
383
+ this._emit("error", err, { context: "unlockAccount", id });
384
+ throw err;
385
+ }
386
+ }
387
+ lockAccount(id) {
388
+ this._keys.lock(id);
389
+ this._emit("lock", id);
390
+ }
391
+ lockAllAccounts() {
392
+ this._keys.lockAll();
393
+ for (const id of this._ownAccountsOrder)
394
+ this._emit("lock", id);
395
+ }
396
+ async verifyPassphrase(id, passphrase) {
397
+ return this._keys.isPassphraseValid(id, passphrase);
398
+ }
376
399
  listOwnAccounts(majikahOnly = false) {
377
400
  let accounts = this._ownAccountsOrder
378
401
  .map((id) => this._ownAccounts.get(id))
@@ -402,6 +425,16 @@ export class MajikMessage {
402
425
  throw new Error("Invalid contact ID");
403
426
  return this._contacts.getContact(id) ?? null;
404
427
  }
428
+ hasContact(id) {
429
+ if (!id?.trim())
430
+ throw new Error("Invalid contact ID");
431
+ return this._contacts.hasContact(id);
432
+ }
433
+ async hasContactByPublicKeyBase64(publicKey) {
434
+ if (!publicKey?.trim())
435
+ throw new Error("Invalid contact public key");
436
+ return await this._contacts.hasContactByPublicKeyBase64(publicKey);
437
+ }
405
438
  async getContactByPublicKey(publicKeyBase64) {
406
439
  if (!publicKeyBase64?.trim())
407
440
  throw new Error("Invalid public key");
@@ -477,8 +510,8 @@ export class MajikMessage {
477
510
  throw new Error(result.message);
478
511
  this._emit("removed-contact", id);
479
512
  }
480
- listContacts(includeOwnAccounts = false) {
481
- const contacts = this._contacts.listContacts(true);
513
+ listContacts(includeOwnAccounts = false, majikahOnly = false) {
514
+ const contacts = this._contacts.listContacts(true, majikahOnly);
482
515
  if (includeOwnAccounts)
483
516
  return contacts;
484
517
  const ownIds = new Set(this.listOwnAccounts().map((a) => a.id));
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.3.9",
5
+ "version": "0.3.11",
6
6
  "license": "Apache-2.0",
7
7
  "author": "Zelijah",
8
8
  "main": "./dist/index.js",