ephem 1.0.2 → 1.0.3

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/README.md CHANGED
@@ -23,8 +23,6 @@ In modern infrastructure, TLS (Transport Layer Security) often terminates at the
23
23
 
24
24
  Ephem is also suitable for **Server-to-Server** communication for high-security microservices that need to pass secrets over untrusted internal pipes.
25
25
 
26
- Ephem is also suitable for **Server-to-Server** communication for high-security microservices that need to pass secrets over untrusted internal pipes.
27
-
28
26
  **Transport Agnostic:** Since Ephem operates at the application layer, it works independently of the transport protocol. You can send capsules over HTTP, WebSockets, FTP, email, or even sneakernet.
29
27
 
30
28
  **Horizontal Scaling:** Ephem supports high-availability clusters. By using `inMemory: false` and implementing persistence hooks (backed by Redis, Postgres, etc.), any server in your fleet can open a capsule, regardless of which server issued it. State is shared, not siloed.
@@ -369,8 +367,6 @@ Attempts to decrypt a sealed payload.
369
367
  * The capsule has exceeded its `maxOpens` count.
370
368
  * The decryption fails (wrong key, tampering detected).
371
369
 
372
- * The decryption fails (wrong key, tampering detected).
373
-
374
370
  ---
375
371
 
376
372
  ### `ephem.getAnalytics()`
@@ -496,6 +492,35 @@ const ephem = new Ephem({
496
492
  });
497
493
  ```
498
494
 
495
+ ### Cleanup Responsibilities (Persistent Mode)
496
+
497
+ When `inMemory: false`, Ephem's internal `capsuleCleanUp` loop is **disabled**. You are responsible for removing expired capsules from your storage backend.
498
+
499
+ If you are using **Redis**, simpler is better: use the `EXPIRE` command (TTL) when setting the key, as shown in the example above. Redis will automatically remove the key when it expires.
500
+
501
+ If you are using a **SQL Database** (Postgres, MySQL), you should run a periodic cleanup job (CRON).
502
+
503
+ #### Example: SQL Cleanup Cron
504
+
505
+ ```typescript
506
+ // run-cleanup.ts
507
+ import db from './my-db';
508
+
509
+ async function cleanup() {
510
+ const now = Date.now();
511
+
512
+ // Delete expired capsules
513
+ await db.query('DELETE FROM capsules WHERE expires_at < $1', [now]);
514
+
515
+ // Optional: Delete exhausted capsules if your logic allows
516
+ // (Usually handled in real-time by onCapsuleOpen, but good for safety)
517
+ await db.query('DELETE FROM capsules WHERE open_count >= max_opens AND max_opens > 0');
518
+ }
519
+
520
+ // Run every minute
521
+ setInterval(cleanup, 60 * 1000);
522
+ ```
523
+
499
524
  ## Contributing
500
525
  Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
501
526
 
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Encrypts (seals) a plaintext message into an ephemeral capsule format.
3
+ *
4
+ * @param text The plaintext message to encrypt.
5
+ * @param publicKeyPem The recipient's Public Key (PEM format).
6
+ * @param cid The Capsule ID (provided by the server).
7
+ * @param allowInsecureFallback If true, allows "secure" operations in non-secure contexts (DEV ONLY).
8
+ * @returns The sealed ciphertext string in the format: `cid.iv.ciphertext.encryptedKey`
9
+ */
1
10
  declare function seal(text: string, publicKeyPem: string, cid: string, allowInsecureFallback?: boolean): Promise<string>;
2
11
 
3
12
  export { seal };
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Encrypts (seals) a plaintext message into an ephemeral capsule format.
3
+ *
4
+ * @param text The plaintext message to encrypt.
5
+ * @param publicKeyPem The recipient's Public Key (PEM format).
6
+ * @param cid The Capsule ID (provided by the server).
7
+ * @param allowInsecureFallback If true, allows "secure" operations in non-secure contexts (DEV ONLY).
8
+ * @returns The sealed ciphertext string in the format: `cid.iv.ciphertext.encryptedKey`
9
+ */
1
10
  declare function seal(text: string, publicKeyPem: string, cid: string, allowInsecureFallback?: boolean): Promise<string>;
2
11
 
3
12
  export { seal };
package/dist/index.d.mts CHANGED
@@ -1,51 +1,111 @@
1
+ /**
2
+ * Represents a key used in the system.
3
+ */
1
4
  type Key = string;
5
+ /**
6
+ * Represents an individual ephemeral capsule.
7
+ */
2
8
  interface Capsule {
9
+ /** The private key associated with this capsule */
3
10
  privateKey: Key;
11
+ /** Maximum number of times this capsule can be opened */
4
12
  maxOpens: number;
13
+ /** Current number of times this capsule has been opened */
5
14
  openCount: number;
15
+ /** Timestamp (ms) when this capsule expires */
6
16
  expiresAt: number;
7
17
  }
18
+ /**
19
+ * Callback function triggered when a capsule is created (persistent mode).
20
+ * Should return true if storage was successful, false otherwise.
21
+ */
8
22
  type OnCreationFunction = (cid: string, privateKey: string, openCount: number, maxOpens: number, expiresAt: number) => Promise<boolean>;
23
+ /**
24
+ * Callback function triggered when a capsule is opened (persistent mode).
25
+ * Used to update the open count in external storage.
26
+ */
9
27
  type OnOpenFunction = (cid: string, openCount: number) => Promise<boolean>;
28
+ /**
29
+ * Callback function to retrieve a capsule by its ID from external storage.
30
+ */
10
31
  type OnGetByCIDFunction = (cid: string) => Promise<{
11
32
  privateKey: unknown;
12
33
  maxOpens: unknown;
13
34
  openCount: unknown;
14
35
  expiresAt: unknown;
15
36
  } | null>;
37
+ /**
38
+ * Reason for capsule deletion.
39
+ */
16
40
  type CapsuleDeletionReason = 'expired' | 'max_opened';
41
+ /**
42
+ * Callback function triggered when a capsule is deleted (persistent mode).
43
+ */
17
44
  type OnDeletionFuntion = (cid: string, deleteReason: CapsuleDeletionReason) => Promise<void>;
45
+ /**
46
+ * Configuration for running Ephem in-memory.
47
+ */
18
48
  interface EphemConfigInMemory {
49
+ /** Set to true for in-memory operation */
19
50
  inMemory?: true;
51
+ /** Maximum number of concurrent capsules allowed in memory */
20
52
  maxConcurrentCapsules?: number;
53
+ /** Default lifetime for a capsule in milliseconds */
21
54
  defaultCaptsuleLifetimeMS?: number;
55
+ /** Interval for the cleanup loop in milliseconds */
22
56
  capsuleCleanupIntervalMS?: number;
23
57
  onCapsuleCreation?: OnCreationFunction;
24
58
  onCapsuleOpen?: OnOpenFunction;
25
59
  OnGetCapsuleByCID?: OnGetByCIDFunction;
26
60
  onCapsuleDelete?: OnDeletionFuntion;
61
+ /** Enable logging */
27
62
  logging?: boolean;
28
63
  }
64
+ /**
65
+ * Configuration for running Ephem with persistent storage.
66
+ */
29
67
  interface EphemConfigPersistent {
68
+ /** Set to false for persistent operation */
30
69
  inMemory: false;
31
70
  maxConcurrentCapsules?: number;
32
71
  defaultCaptsuleLifetimeMS?: number;
33
72
  capsuleCleanupIntervalMS?: number;
73
+ /** Required: Callback to store a new capsule */
34
74
  onCapsuleCreation: OnCreationFunction;
75
+ /** Required: Callback to update a capsule's open count */
35
76
  onCapsuleOpen: OnOpenFunction;
77
+ /** Required: Callback to retrieve a capsule */
36
78
  OnGetCapsuleByCID: OnGetByCIDFunction;
79
+ /** Required: Callback to delete a capsule */
37
80
  onCapsuleDelete: OnDeletionFuntion;
81
+ /** Enable logging */
38
82
  logging?: boolean;
39
83
  }
84
+ /**
85
+ * Union type for Ephem configuration.
86
+ */
40
87
  type EphemConfig = EphemConfigInMemory | EphemConfigPersistent;
88
+ /**
89
+ * Object returned when a capsule is successfully created.
90
+ */
41
91
  interface CreateCapsuleReturnObj {
92
+ /** The Capsule ID */
42
93
  cid: string;
94
+ /** The Public Key (PEM) associated with the capsule */
43
95
  publicKey: string;
44
96
  }
97
+ /**
98
+ * Configuration options for creating a single capsule.
99
+ */
45
100
  interface CreateCapsuleConfig {
101
+ /** Maximum number of times the capsule can be opened */
46
102
  maxOpens?: number;
103
+ /** Lifetime of the capsule in milliseconds */
47
104
  lifetimeDurationMS?: number;
48
105
  }
106
+ /**
107
+ * Callback for the createCapsule method.
108
+ */
49
109
  type CreateCapsuleCallback = (res: CreateCapsuleReturnObj | null) => void | Promise<void>;
50
110
  /**
51
111
  * Keeps track of ephem's analytics since initialization.
@@ -56,18 +116,35 @@ declare class Analytics {
56
116
  totalExpiredCapsules: number;
57
117
  constructor();
58
118
  }
119
+ /**
120
+ * Ephem: Robust, Ephemeral End-to-End Encryption for the Application Layer.
121
+ */
59
122
  declare class Ephem {
60
123
  private readonly config;
61
124
  private genUUID;
62
125
  private slug;
63
126
  private capsules;
64
127
  private analytics;
128
+ /**
129
+ * Internal logging method.
130
+ */
65
131
  private log;
132
+ /**
133
+ * Initializes a new instance of Ephem.
134
+ * @param config Configuration object for Ephem.
135
+ */
66
136
  constructor(config?: EphemConfig);
67
137
  /**
68
- * Alias Handshake
138
+ * Creates a new ephemeral capsule.
139
+ * @param callback Callback function receiving the result (Capsule ID and Public Key) or null on failure.
140
+ * @param config Optional configuration for this specific capsule.
69
141
  */
70
142
  createCapsule(callback: CreateCapsuleCallback, config?: CreateCapsuleConfig): Promise<void>;
143
+ /**
144
+ * Promise-based wrapper for createCapsule.
145
+ * @param config Optional configuration for this specific capsule.
146
+ * @returns Promise resolving to the capsule details.
147
+ */
71
148
  createCapsulePromise(config?: CreateCapsuleConfig): Promise<CreateCapsuleReturnObj | null>;
72
149
  /**
73
150
  * Handles periodic cleanup of in-memory capsules.
@@ -75,13 +152,27 @@ declare class Ephem {
75
152
  * Else, user should implement their own cleanup elsewhere
76
153
  */
77
154
  private capsuleCleanUp;
155
+ /**
156
+ * Retrieves a capsule by its ID (CID).
157
+ * @param cid Capsule ID.
158
+ */
78
159
  getCapsule(cid: string): Promise<Capsule | null>;
160
+ /**
161
+ * Removes a single capsule.
162
+ * @param cid Capsule ID.
163
+ * @param reason Reason for deletion.
164
+ */
79
165
  removeIndividualCapsule(cid: string, reason: CapsuleDeletionReason): void;
80
166
  /**
81
- * Decrypts encrypted data.
167
+ * Decrypts an encrypted payload (cipher string).
168
+ * @param cipher The dot-separated cipher string [cid.iv.ciphertext.encryptedKey].
169
+ * @returns The decrypted plaintext or null if decryption fails or capsule is invalid.
82
170
  */
83
171
  open(cipher: string): Promise<string | null>;
172
+ /**
173
+ * Returns a snapshot of current analytics.
174
+ */
84
175
  getAnalytics(): Readonly<Analytics>;
85
176
  }
86
177
 
87
- export { type Capsule, type CapsuleDeletionReason, type CreateCapsuleCallback, type CreateCapsuleConfig, type CreateCapsuleReturnObj, type EphemConfig, type EphemConfigInMemory, type EphemConfigPersistent, type Key, type OnCreationFunction, type OnDeletionFuntion, type OnGetByCIDFunction, type OnOpenFunction, Ephem as default };
178
+ export { Analytics, type Capsule, type CapsuleDeletionReason, type CreateCapsuleCallback, type CreateCapsuleConfig, type CreateCapsuleReturnObj, type EphemConfig, type EphemConfigInMemory, type EphemConfigPersistent, type Key, type OnCreationFunction, type OnDeletionFuntion, type OnGetByCIDFunction, type OnOpenFunction, Ephem as default };
package/dist/index.d.ts CHANGED
@@ -1,51 +1,111 @@
1
+ /**
2
+ * Represents a key used in the system.
3
+ */
1
4
  type Key = string;
5
+ /**
6
+ * Represents an individual ephemeral capsule.
7
+ */
2
8
  interface Capsule {
9
+ /** The private key associated with this capsule */
3
10
  privateKey: Key;
11
+ /** Maximum number of times this capsule can be opened */
4
12
  maxOpens: number;
13
+ /** Current number of times this capsule has been opened */
5
14
  openCount: number;
15
+ /** Timestamp (ms) when this capsule expires */
6
16
  expiresAt: number;
7
17
  }
18
+ /**
19
+ * Callback function triggered when a capsule is created (persistent mode).
20
+ * Should return true if storage was successful, false otherwise.
21
+ */
8
22
  type OnCreationFunction = (cid: string, privateKey: string, openCount: number, maxOpens: number, expiresAt: number) => Promise<boolean>;
23
+ /**
24
+ * Callback function triggered when a capsule is opened (persistent mode).
25
+ * Used to update the open count in external storage.
26
+ */
9
27
  type OnOpenFunction = (cid: string, openCount: number) => Promise<boolean>;
28
+ /**
29
+ * Callback function to retrieve a capsule by its ID from external storage.
30
+ */
10
31
  type OnGetByCIDFunction = (cid: string) => Promise<{
11
32
  privateKey: unknown;
12
33
  maxOpens: unknown;
13
34
  openCount: unknown;
14
35
  expiresAt: unknown;
15
36
  } | null>;
37
+ /**
38
+ * Reason for capsule deletion.
39
+ */
16
40
  type CapsuleDeletionReason = 'expired' | 'max_opened';
41
+ /**
42
+ * Callback function triggered when a capsule is deleted (persistent mode).
43
+ */
17
44
  type OnDeletionFuntion = (cid: string, deleteReason: CapsuleDeletionReason) => Promise<void>;
45
+ /**
46
+ * Configuration for running Ephem in-memory.
47
+ */
18
48
  interface EphemConfigInMemory {
49
+ /** Set to true for in-memory operation */
19
50
  inMemory?: true;
51
+ /** Maximum number of concurrent capsules allowed in memory */
20
52
  maxConcurrentCapsules?: number;
53
+ /** Default lifetime for a capsule in milliseconds */
21
54
  defaultCaptsuleLifetimeMS?: number;
55
+ /** Interval for the cleanup loop in milliseconds */
22
56
  capsuleCleanupIntervalMS?: number;
23
57
  onCapsuleCreation?: OnCreationFunction;
24
58
  onCapsuleOpen?: OnOpenFunction;
25
59
  OnGetCapsuleByCID?: OnGetByCIDFunction;
26
60
  onCapsuleDelete?: OnDeletionFuntion;
61
+ /** Enable logging */
27
62
  logging?: boolean;
28
63
  }
64
+ /**
65
+ * Configuration for running Ephem with persistent storage.
66
+ */
29
67
  interface EphemConfigPersistent {
68
+ /** Set to false for persistent operation */
30
69
  inMemory: false;
31
70
  maxConcurrentCapsules?: number;
32
71
  defaultCaptsuleLifetimeMS?: number;
33
72
  capsuleCleanupIntervalMS?: number;
73
+ /** Required: Callback to store a new capsule */
34
74
  onCapsuleCreation: OnCreationFunction;
75
+ /** Required: Callback to update a capsule's open count */
35
76
  onCapsuleOpen: OnOpenFunction;
77
+ /** Required: Callback to retrieve a capsule */
36
78
  OnGetCapsuleByCID: OnGetByCIDFunction;
79
+ /** Required: Callback to delete a capsule */
37
80
  onCapsuleDelete: OnDeletionFuntion;
81
+ /** Enable logging */
38
82
  logging?: boolean;
39
83
  }
84
+ /**
85
+ * Union type for Ephem configuration.
86
+ */
40
87
  type EphemConfig = EphemConfigInMemory | EphemConfigPersistent;
88
+ /**
89
+ * Object returned when a capsule is successfully created.
90
+ */
41
91
  interface CreateCapsuleReturnObj {
92
+ /** The Capsule ID */
42
93
  cid: string;
94
+ /** The Public Key (PEM) associated with the capsule */
43
95
  publicKey: string;
44
96
  }
97
+ /**
98
+ * Configuration options for creating a single capsule.
99
+ */
45
100
  interface CreateCapsuleConfig {
101
+ /** Maximum number of times the capsule can be opened */
46
102
  maxOpens?: number;
103
+ /** Lifetime of the capsule in milliseconds */
47
104
  lifetimeDurationMS?: number;
48
105
  }
106
+ /**
107
+ * Callback for the createCapsule method.
108
+ */
49
109
  type CreateCapsuleCallback = (res: CreateCapsuleReturnObj | null) => void | Promise<void>;
50
110
  /**
51
111
  * Keeps track of ephem's analytics since initialization.
@@ -56,18 +116,35 @@ declare class Analytics {
56
116
  totalExpiredCapsules: number;
57
117
  constructor();
58
118
  }
119
+ /**
120
+ * Ephem: Robust, Ephemeral End-to-End Encryption for the Application Layer.
121
+ */
59
122
  declare class Ephem {
60
123
  private readonly config;
61
124
  private genUUID;
62
125
  private slug;
63
126
  private capsules;
64
127
  private analytics;
128
+ /**
129
+ * Internal logging method.
130
+ */
65
131
  private log;
132
+ /**
133
+ * Initializes a new instance of Ephem.
134
+ * @param config Configuration object for Ephem.
135
+ */
66
136
  constructor(config?: EphemConfig);
67
137
  /**
68
- * Alias Handshake
138
+ * Creates a new ephemeral capsule.
139
+ * @param callback Callback function receiving the result (Capsule ID and Public Key) or null on failure.
140
+ * @param config Optional configuration for this specific capsule.
69
141
  */
70
142
  createCapsule(callback: CreateCapsuleCallback, config?: CreateCapsuleConfig): Promise<void>;
143
+ /**
144
+ * Promise-based wrapper for createCapsule.
145
+ * @param config Optional configuration for this specific capsule.
146
+ * @returns Promise resolving to the capsule details.
147
+ */
71
148
  createCapsulePromise(config?: CreateCapsuleConfig): Promise<CreateCapsuleReturnObj | null>;
72
149
  /**
73
150
  * Handles periodic cleanup of in-memory capsules.
@@ -75,15 +152,29 @@ declare class Ephem {
75
152
  * Else, user should implement their own cleanup elsewhere
76
153
  */
77
154
  private capsuleCleanUp;
155
+ /**
156
+ * Retrieves a capsule by its ID (CID).
157
+ * @param cid Capsule ID.
158
+ */
78
159
  getCapsule(cid: string): Promise<Capsule | null>;
160
+ /**
161
+ * Removes a single capsule.
162
+ * @param cid Capsule ID.
163
+ * @param reason Reason for deletion.
164
+ */
79
165
  removeIndividualCapsule(cid: string, reason: CapsuleDeletionReason): void;
80
166
  /**
81
- * Decrypts encrypted data.
167
+ * Decrypts an encrypted payload (cipher string).
168
+ * @param cipher The dot-separated cipher string [cid.iv.ciphertext.encryptedKey].
169
+ * @returns The decrypted plaintext or null if decryption fails or capsule is invalid.
82
170
  */
83
171
  open(cipher: string): Promise<string | null>;
172
+ /**
173
+ * Returns a snapshot of current analytics.
174
+ */
84
175
  getAnalytics(): Readonly<Analytics>;
85
176
  }
86
177
 
87
178
  // @ts-ignore
88
179
  export = Ephem;
89
- export type { Capsule, CapsuleDeletionReason, CreateCapsuleCallback, CreateCapsuleConfig, CreateCapsuleReturnObj, EphemConfig, EphemConfigInMemory, EphemConfigPersistent, Key, OnCreationFunction, OnDeletionFuntion, OnGetByCIDFunction, OnOpenFunction };
180
+ export { Analytics, type Capsule, type CapsuleDeletionReason, type CreateCapsuleCallback, type CreateCapsuleConfig, type CreateCapsuleReturnObj, type EphemConfig, type EphemConfigInMemory, type EphemConfigPersistent, type Key, type OnCreationFunction, type OnDeletionFuntion, type OnGetByCIDFunction, type OnOpenFunction };
package/dist/index.js CHANGED
@@ -86,11 +86,18 @@ var Ephem = class {
86
86
  slug = `Ephem`;
87
87
  capsules;
88
88
  analytics;
89
+ /**
90
+ * Internal logging method.
91
+ */
89
92
  log(...message) {
90
93
  if (this.config.logging) {
91
94
  console.log(`${this.slug} =>`, ...message);
92
95
  }
93
96
  }
97
+ /**
98
+ * Initializes a new instance of Ephem.
99
+ * @param config Configuration object for Ephem.
100
+ */
94
101
  constructor(config) {
95
102
  this.analytics = new Analytics();
96
103
  this.config = normalizeConfig(config);
@@ -103,7 +110,9 @@ var Ephem = class {
103
110
  }
104
111
  }
105
112
  /**
106
- * Alias Handshake
113
+ * Creates a new ephemeral capsule.
114
+ * @param callback Callback function receiving the result (Capsule ID and Public Key) or null on failure.
115
+ * @param config Optional configuration for this specific capsule.
107
116
  */
108
117
  async createCapsule(callback, config = {}) {
109
118
  try {
@@ -150,6 +159,11 @@ var Ephem = class {
150
159
  callback(null);
151
160
  }
152
161
  }
162
+ /**
163
+ * Promise-based wrapper for createCapsule.
164
+ * @param config Optional configuration for this specific capsule.
165
+ * @returns Promise resolving to the capsule details.
166
+ */
153
167
  createCapsulePromise(config = {}) {
154
168
  return new Promise(async (resolve, reject) => {
155
169
  this.createCapsule((r) => {
@@ -195,6 +209,10 @@ var Ephem = class {
195
209
  }
196
210
  this.log(`cleanup ended.`);
197
211
  }
212
+ /**
213
+ * Retrieves a capsule by its ID (CID).
214
+ * @param cid Capsule ID.
215
+ */
198
216
  async getCapsule(cid) {
199
217
  if (this.config.inMemory) {
200
218
  if (this.capsules.has(cid)) {
@@ -223,6 +241,11 @@ var Ephem = class {
223
241
  }
224
242
  }
225
243
  }
244
+ /**
245
+ * Removes a single capsule.
246
+ * @param cid Capsule ID.
247
+ * @param reason Reason for deletion.
248
+ */
226
249
  removeIndividualCapsule(cid, reason) {
227
250
  if (this.config.inMemory) {
228
251
  if (this.capsules.has(cid)) {
@@ -238,7 +261,9 @@ var Ephem = class {
238
261
  }
239
262
  }
240
263
  /**
241
- * Decrypts encrypted data.
264
+ * Decrypts an encrypted payload (cipher string).
265
+ * @param cipher The dot-separated cipher string [cid.iv.ciphertext.encryptedKey].
266
+ * @returns The decrypted plaintext or null if decryption fails or capsule is invalid.
242
267
  */
243
268
  async open(cipher) {
244
269
  if (cipher.startsWith("##INSECURE##")) {
@@ -300,6 +325,9 @@ var Ephem = class {
300
325
  return null;
301
326
  }
302
327
  }
328
+ /**
329
+ * Returns a snapshot of current analytics.
330
+ */
303
331
  getAnalytics() {
304
332
  const snap = { ...this.analytics };
305
333
  return snap;
package/dist/index.mjs CHANGED
@@ -66,11 +66,18 @@ var Ephem = class {
66
66
  slug = `Ephem`;
67
67
  capsules;
68
68
  analytics;
69
+ /**
70
+ * Internal logging method.
71
+ */
69
72
  log(...message) {
70
73
  if (this.config.logging) {
71
74
  console.log(`${this.slug} =>`, ...message);
72
75
  }
73
76
  }
77
+ /**
78
+ * Initializes a new instance of Ephem.
79
+ * @param config Configuration object for Ephem.
80
+ */
74
81
  constructor(config) {
75
82
  this.analytics = new Analytics();
76
83
  this.config = normalizeConfig(config);
@@ -83,7 +90,9 @@ var Ephem = class {
83
90
  }
84
91
  }
85
92
  /**
86
- * Alias Handshake
93
+ * Creates a new ephemeral capsule.
94
+ * @param callback Callback function receiving the result (Capsule ID and Public Key) or null on failure.
95
+ * @param config Optional configuration for this specific capsule.
87
96
  */
88
97
  async createCapsule(callback, config = {}) {
89
98
  try {
@@ -130,6 +139,11 @@ var Ephem = class {
130
139
  callback(null);
131
140
  }
132
141
  }
142
+ /**
143
+ * Promise-based wrapper for createCapsule.
144
+ * @param config Optional configuration for this specific capsule.
145
+ * @returns Promise resolving to the capsule details.
146
+ */
133
147
  createCapsulePromise(config = {}) {
134
148
  return new Promise(async (resolve, reject) => {
135
149
  this.createCapsule((r) => {
@@ -175,6 +189,10 @@ var Ephem = class {
175
189
  }
176
190
  this.log(`cleanup ended.`);
177
191
  }
192
+ /**
193
+ * Retrieves a capsule by its ID (CID).
194
+ * @param cid Capsule ID.
195
+ */
178
196
  async getCapsule(cid) {
179
197
  if (this.config.inMemory) {
180
198
  if (this.capsules.has(cid)) {
@@ -203,6 +221,11 @@ var Ephem = class {
203
221
  }
204
222
  }
205
223
  }
224
+ /**
225
+ * Removes a single capsule.
226
+ * @param cid Capsule ID.
227
+ * @param reason Reason for deletion.
228
+ */
206
229
  removeIndividualCapsule(cid, reason) {
207
230
  if (this.config.inMemory) {
208
231
  if (this.capsules.has(cid)) {
@@ -218,7 +241,9 @@ var Ephem = class {
218
241
  }
219
242
  }
220
243
  /**
221
- * Decrypts encrypted data.
244
+ * Decrypts an encrypted payload (cipher string).
245
+ * @param cipher The dot-separated cipher string [cid.iv.ciphertext.encryptedKey].
246
+ * @returns The decrypted plaintext or null if decryption fails or capsule is invalid.
222
247
  */
223
248
  async open(cipher) {
224
249
  if (cipher.startsWith("##INSECURE##")) {
@@ -280,6 +305,9 @@ var Ephem = class {
280
305
  return null;
281
306
  }
282
307
  }
308
+ /**
309
+ * Returns a snapshot of current analytics.
310
+ */
283
311
  getAnalytics() {
284
312
  const snap = { ...this.analytics };
285
313
  return snap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ephem",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Robust, Ephemeral End-to-End Encryption for the Application Layer. Secure data-in-transit with disposable capsules.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",