cojson 0.20.7 → 0.20.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.
Files changed (209) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +26 -0
  3. package/dist/SyncStateManager.d.ts.map +1 -1
  4. package/dist/SyncStateManager.js +0 -2
  5. package/dist/SyncStateManager.js.map +1 -1
  6. package/dist/base64url.d.ts +15 -0
  7. package/dist/base64url.d.ts.map +1 -1
  8. package/dist/base64url.js +101 -5
  9. package/dist/base64url.js.map +1 -1
  10. package/dist/base64url.test.js +76 -1
  11. package/dist/base64url.test.js.map +1 -1
  12. package/dist/coValue.d.ts +2 -1
  13. package/dist/coValue.d.ts.map +1 -1
  14. package/dist/coValue.js.map +1 -1
  15. package/dist/coValueCore/coValueCore.d.ts +9 -11
  16. package/dist/coValueCore/coValueCore.d.ts.map +1 -1
  17. package/dist/coValueCore/coValueCore.js +92 -65
  18. package/dist/coValueCore/coValueCore.js.map +1 -1
  19. package/dist/coValueCore/verifiedState.d.ts +38 -7
  20. package/dist/coValueCore/verifiedState.d.ts.map +1 -1
  21. package/dist/coValueCore/verifiedState.js +226 -30
  22. package/dist/coValueCore/verifiedState.js.map +1 -1
  23. package/dist/coValues/binaryCoStream.d.ts +63 -0
  24. package/dist/coValues/binaryCoStream.d.ts.map +1 -0
  25. package/dist/coValues/binaryCoStream.js +125 -0
  26. package/dist/coValues/binaryCoStream.js.map +1 -0
  27. package/dist/coValues/coList.d.ts +3 -1
  28. package/dist/coValues/coList.d.ts.map +1 -1
  29. package/dist/coValues/coList.js +15 -6
  30. package/dist/coValues/coList.js.map +1 -1
  31. package/dist/coValues/coMap.d.ts +1 -1
  32. package/dist/coValues/coMap.d.ts.map +1 -1
  33. package/dist/coValues/coMap.js +2 -2
  34. package/dist/coValues/coMap.js.map +1 -1
  35. package/dist/coValues/coStream.d.ts +0 -38
  36. package/dist/coValues/coStream.d.ts.map +1 -1
  37. package/dist/coValues/coStream.js +0 -86
  38. package/dist/coValues/coStream.js.map +1 -1
  39. package/dist/coValues/group.d.ts +44 -6
  40. package/dist/coValues/group.d.ts.map +1 -1
  41. package/dist/coValues/group.js +198 -17
  42. package/dist/coValues/group.js.map +1 -1
  43. package/dist/coreToCoValue.d.ts +2 -1
  44. package/dist/coreToCoValue.d.ts.map +1 -1
  45. package/dist/coreToCoValue.js +2 -1
  46. package/dist/coreToCoValue.js.map +1 -1
  47. package/dist/crypto/NapiCrypto.d.ts +18 -24
  48. package/dist/crypto/NapiCrypto.d.ts.map +1 -1
  49. package/dist/crypto/NapiCrypto.js +98 -60
  50. package/dist/crypto/NapiCrypto.js.map +1 -1
  51. package/dist/crypto/RNCrypto.d.ts +16 -3
  52. package/dist/crypto/RNCrypto.d.ts.map +1 -1
  53. package/dist/crypto/RNCrypto.js +117 -54
  54. package/dist/crypto/RNCrypto.js.map +1 -1
  55. package/dist/crypto/WasmCrypto.d.ts +18 -24
  56. package/dist/crypto/WasmCrypto.d.ts.map +1 -1
  57. package/dist/crypto/WasmCrypto.js +100 -61
  58. package/dist/crypto/WasmCrypto.js.map +1 -1
  59. package/dist/crypto/crypto.d.ts +55 -19
  60. package/dist/crypto/crypto.d.ts.map +1 -1
  61. package/dist/crypto/crypto.js +14 -3
  62. package/dist/crypto/crypto.js.map +1 -1
  63. package/dist/exports.d.ts +7 -3
  64. package/dist/exports.d.ts.map +1 -1
  65. package/dist/exports.js +4 -2
  66. package/dist/exports.js.map +1 -1
  67. package/dist/localNode.d.ts +3 -1
  68. package/dist/localNode.d.ts.map +1 -1
  69. package/dist/localNode.js +10 -3
  70. package/dist/localNode.js.map +1 -1
  71. package/dist/media.d.ts +1 -1
  72. package/dist/media.d.ts.map +1 -1
  73. package/dist/permissions.d.ts +2 -1
  74. package/dist/permissions.d.ts.map +1 -1
  75. package/dist/permissions.js +19 -3
  76. package/dist/permissions.js.map +1 -1
  77. package/dist/storage/sqliteAsync/client.d.ts +24 -12
  78. package/dist/storage/sqliteAsync/client.d.ts.map +1 -1
  79. package/dist/storage/sqliteAsync/client.js +70 -58
  80. package/dist/storage/sqliteAsync/client.js.map +1 -1
  81. package/dist/storage/sqliteAsync/types.d.ts +1 -1
  82. package/dist/storage/sqliteAsync/types.d.ts.map +1 -1
  83. package/dist/storage/types.d.ts +1 -0
  84. package/dist/storage/types.d.ts.map +1 -1
  85. package/dist/sync.d.ts.map +1 -1
  86. package/dist/sync.js +7 -1
  87. package/dist/sync.js.map +1 -1
  88. package/dist/tests/CojsonMessageChannel.test.js +2 -2
  89. package/dist/tests/SQLiteClientAsync.test.d.ts +2 -0
  90. package/dist/tests/SQLiteClientAsync.test.d.ts.map +1 -0
  91. package/dist/tests/SQLiteClientAsync.test.js +64 -0
  92. package/dist/tests/SQLiteClientAsync.test.js.map +1 -0
  93. package/dist/tests/StorageApiAsync.test.js +2 -8
  94. package/dist/tests/StorageApiAsync.test.js.map +1 -1
  95. package/dist/tests/SyncStateManager.test.js +2 -2
  96. package/dist/tests/WasmCrypto.test.js +1 -15
  97. package/dist/tests/WasmCrypto.test.js.map +1 -1
  98. package/dist/tests/coList.test.js +24 -5
  99. package/dist/tests/coList.test.js.map +1 -1
  100. package/dist/tests/coStream.test.js +4 -3
  101. package/dist/tests/coStream.test.js.map +1 -1
  102. package/dist/tests/coValueCore.initTransaction.test.d.ts +2 -0
  103. package/dist/tests/coValueCore.initTransaction.test.d.ts.map +1 -0
  104. package/dist/tests/coValueCore.initTransaction.test.js +438 -0
  105. package/dist/tests/coValueCore.initTransaction.test.js.map +1 -0
  106. package/dist/tests/coValueCore.test.js +11 -19
  107. package/dist/tests/coValueCore.test.js.map +1 -1
  108. package/dist/tests/crypto.test.js +83 -0
  109. package/dist/tests/crypto.test.js.map +1 -1
  110. package/dist/tests/deleteCoValue.test.js +5 -5
  111. package/dist/tests/deleteCoValue.test.js.map +1 -1
  112. package/dist/tests/group.inheritance.test.js +11 -0
  113. package/dist/tests/group.inheritance.test.js.map +1 -1
  114. package/dist/tests/group.test.js +24 -1
  115. package/dist/tests/group.test.js.map +1 -1
  116. package/dist/tests/groupSealer.test.d.ts +2 -0
  117. package/dist/tests/groupSealer.test.d.ts.map +1 -0
  118. package/dist/tests/groupSealer.test.js +913 -0
  119. package/dist/tests/groupSealer.test.js.map +1 -0
  120. package/dist/tests/setup.js +5 -0
  121. package/dist/tests/setup.js.map +1 -1
  122. package/dist/tests/sync.auth.test.js +10 -10
  123. package/dist/tests/sync.concurrentLoad.test.js +12 -12
  124. package/dist/tests/sync.deleted.test.js +8 -8
  125. package/dist/tests/sync.garbageCollection.test.js +10 -10
  126. package/dist/tests/sync.invite.test.js +12 -12
  127. package/dist/tests/sync.known.test.js +2 -2
  128. package/dist/tests/sync.load.test.js +107 -107
  129. package/dist/tests/sync.mesh.test.js +164 -46
  130. package/dist/tests/sync.mesh.test.js.map +1 -1
  131. package/dist/tests/sync.multipleServers.test.js +43 -43
  132. package/dist/tests/sync.peerReconciliation.test.js +29 -29
  133. package/dist/tests/sync.sharding.test.js +3 -3
  134. package/dist/tests/sync.storage.test.js +104 -104
  135. package/dist/tests/sync.storage.test.js.map +1 -1
  136. package/dist/tests/sync.storageAsync.test.js +56 -56
  137. package/dist/tests/sync.upload.test.js +22 -22
  138. package/dist/tests/testStorage.d.ts +2 -0
  139. package/dist/tests/testStorage.d.ts.map +1 -1
  140. package/dist/tests/testStorage.js +30 -6
  141. package/dist/tests/testStorage.js.map +1 -1
  142. package/dist/typeUtils/isCoValue.js +1 -1
  143. package/dist/typeUtils/isCoValue.js.map +1 -1
  144. package/package.json +4 -4
  145. package/src/SyncStateManager.ts +0 -2
  146. package/src/base64url.test.ts +89 -1
  147. package/src/base64url.ts +134 -6
  148. package/src/coValue.ts +2 -1
  149. package/src/coValueCore/coValueCore.ts +126 -84
  150. package/src/coValueCore/verifiedState.ts +335 -53
  151. package/src/coValues/binaryCoStream.ts +217 -0
  152. package/src/coValues/coList.ts +21 -8
  153. package/src/coValues/coMap.ts +3 -0
  154. package/src/coValues/coStream.ts +0 -170
  155. package/src/coValues/group.ts +270 -21
  156. package/src/coreToCoValue.ts +2 -1
  157. package/src/crypto/NapiCrypto.ts +198 -95
  158. package/src/crypto/RNCrypto.ts +229 -102
  159. package/src/crypto/WasmCrypto.ts +201 -95
  160. package/src/crypto/crypto.ts +118 -45
  161. package/src/exports.ts +11 -5
  162. package/src/localNode.ts +17 -1
  163. package/src/media.ts +1 -1
  164. package/src/permissions.ts +30 -7
  165. package/src/storage/sqliteAsync/client.ts +136 -115
  166. package/src/storage/sqliteAsync/types.ts +3 -1
  167. package/src/storage/types.ts +4 -0
  168. package/src/sync.ts +10 -1
  169. package/src/tests/CojsonMessageChannel.test.ts +2 -2
  170. package/src/tests/SQLiteClientAsync.test.ts +75 -0
  171. package/src/tests/StorageApiAsync.test.ts +4 -9
  172. package/src/tests/SyncStateManager.test.ts +2 -2
  173. package/src/tests/WasmCrypto.test.ts +1 -25
  174. package/src/tests/coList.test.ts +39 -5
  175. package/src/tests/coStream.test.ts +4 -5
  176. package/src/tests/coValueCore.initTransaction.test.ts +836 -0
  177. package/src/tests/coValueCore.test.ts +11 -22
  178. package/src/tests/crypto.test.ts +107 -0
  179. package/src/tests/deleteCoValue.test.ts +5 -5
  180. package/src/tests/group.inheritance.test.ts +16 -0
  181. package/src/tests/group.test.ts +29 -1
  182. package/src/tests/groupSealer.test.ts +1473 -0
  183. package/src/tests/setup.ts +6 -0
  184. package/src/tests/sync.auth.test.ts +10 -10
  185. package/src/tests/sync.concurrentLoad.test.ts +12 -12
  186. package/src/tests/sync.deleted.test.ts +8 -8
  187. package/src/tests/sync.garbageCollection.test.ts +10 -10
  188. package/src/tests/sync.invite.test.ts +12 -12
  189. package/src/tests/sync.known.test.ts +2 -2
  190. package/src/tests/sync.load.test.ts +107 -107
  191. package/src/tests/sync.mesh.test.ts +189 -46
  192. package/src/tests/sync.multipleServers.test.ts +43 -43
  193. package/src/tests/sync.peerReconciliation.test.ts +29 -29
  194. package/src/tests/sync.sharding.test.ts +3 -3
  195. package/src/tests/sync.storage.test.ts +104 -104
  196. package/src/tests/sync.storageAsync.test.ts +56 -56
  197. package/src/tests/sync.upload.test.ts +22 -22
  198. package/src/tests/testStorage.ts +39 -9
  199. package/src/typeUtils/isCoValue.ts +1 -1
  200. package/dist/coValueCore/SessionMap.d.ts +0 -55
  201. package/dist/coValueCore/SessionMap.d.ts.map +0 -1
  202. package/dist/coValueCore/SessionMap.js +0 -206
  203. package/dist/coValueCore/SessionMap.js.map +0 -1
  204. package/dist/tests/coreWasm.test.d.ts +0 -2
  205. package/dist/tests/coreWasm.test.d.ts.map +0 -1
  206. package/dist/tests/coreWasm.test.js +0 -203
  207. package/dist/tests/coreWasm.test.js.map +0 -1
  208. package/src/coValueCore/SessionMap.ts +0 -394
  209. package/src/tests/coreWasm.test.ts +0 -452
@@ -1,5 +1,5 @@
1
1
  import {
2
- SessionLog,
2
+ SessionMap as NativeSessionMap,
3
3
  Blake3Hasher,
4
4
  blake3HashOnce,
5
5
  blake3HashOnceWithContext,
@@ -10,37 +10,37 @@ import {
10
10
  newEd25519SigningKey,
11
11
  newX25519PrivateKey,
12
12
  seal,
13
+ sealForGroup,
14
+ shortHash,
13
15
  sign,
14
16
  unseal,
17
+ unsealForGroup,
15
18
  verify,
16
19
  } from "cojson-core-napi";
17
20
  import { base64URLtoBytes, bytesToBase64url } from "../base64url.js";
18
- import { RawCoID, SessionID, TransactionID } from "../ids.js";
21
+ import { RawCoID, TransactionID } from "../ids.js";
19
22
  import { Stringified, stableStringify } from "../jsonStringify.js";
20
- import { JsonObject, JsonValue } from "../jsonValue.js";
23
+ import { JsonValue } from "../jsonValue.js";
21
24
  import { logger } from "../logger.js";
22
25
  import {
23
26
  CryptoProvider,
24
27
  Encrypted,
25
- KeyID,
26
28
  KeySecret,
27
29
  Sealed,
30
+ SealedForGroup,
28
31
  SealerID,
29
32
  SealerSecret,
33
+ SessionMapImpl,
34
+ ShortHash,
30
35
  Signature,
31
36
  SignerID,
32
37
  SignerSecret,
33
38
  textDecoder,
34
39
  textEncoder,
35
40
  } from "./crypto.js";
36
- import { ControlledAccountOrAgent } from "../coValues/account.js";
37
41
  import { WasmCrypto } from "./WasmCrypto.js";
38
42
 
39
- import {
40
- PrivateTransaction,
41
- Transaction,
42
- TrustingTransaction,
43
- } from "../coValueCore/verifiedState.js";
43
+ import { Transaction } from "../coValueCore/verifiedState.js";
44
44
 
45
45
  type Blake3State = Blake3Hasher;
46
46
 
@@ -72,6 +72,10 @@ export class NapiCrypto extends CryptoProvider<Blake3State> {
72
72
  return blake3HashOnceWithContext(data, context);
73
73
  }
74
74
 
75
+ shortHash(value: JsonValue): ShortHash {
76
+ return shortHash(stableStringify(value)) as ShortHash;
77
+ }
78
+
75
79
  newEd25519SigningKey(): Uint8Array {
76
80
  return newEd25519SigningKey();
77
81
  }
@@ -176,119 +180,218 @@ export class NapiCrypto extends CryptoProvider<Blake3State> {
176
180
  }
177
181
  }
178
182
 
179
- createSessionLog(coID: RawCoID, sessionID: SessionID, signerID?: SignerID) {
180
- return new SessionLogAdapter(new SessionLog(coID, sessionID, signerID));
183
+ sealForGroup<T extends JsonValue>({
184
+ message,
185
+ to,
186
+ nOnceMaterial,
187
+ }: {
188
+ message: T;
189
+ to: SealerID;
190
+ nOnceMaterial: { in: RawCoID; tx: TransactionID };
191
+ }): SealedForGroup<T> {
192
+ return `sealedForGroup_U${bytesToBase64url(
193
+ sealForGroup(
194
+ textEncoder.encode(stableStringify(message)),
195
+ to,
196
+ textEncoder.encode(stableStringify(nOnceMaterial)),
197
+ ),
198
+ )}` as SealedForGroup<T>;
199
+ }
200
+
201
+ unsealForGroup<T extends JsonValue>(
202
+ sealed: SealedForGroup<T>,
203
+ groupSealerSecret: SealerSecret,
204
+ nOnceMaterial: { in: RawCoID; tx: TransactionID },
205
+ ): T | undefined {
206
+ try {
207
+ const plaintext = textDecoder.decode(
208
+ unsealForGroup(
209
+ base64URLtoBytes(sealed.substring("sealedForGroup_U".length)),
210
+ groupSealerSecret,
211
+ textEncoder.encode(stableStringify(nOnceMaterial)),
212
+ ),
213
+ );
214
+ return JSON.parse(plaintext) as T;
215
+ } catch (e) {
216
+ logger.error("Failed to decrypt/parse sealed for group message", {
217
+ err: e,
218
+ });
219
+ return undefined;
220
+ }
221
+ }
222
+
223
+ createSessionMap(
224
+ coID: RawCoID,
225
+ headerJson: string,
226
+ maxTxSize?: number,
227
+ skipVerify?: boolean,
228
+ ): SessionMapImpl {
229
+ return new SessionMapAdapter(
230
+ new NativeSessionMap(coID, headerJson, maxTxSize, skipVerify),
231
+ );
181
232
  }
182
233
  }
183
234
 
184
- class SessionLogAdapter {
185
- constructor(private readonly sessionLog: SessionLog) {}
235
+ /**
236
+ * Adapter wrapping NativeSessionMap to implement SessionMapImpl interface
237
+ */
238
+ class SessionMapAdapter implements SessionMapImpl {
239
+ constructor(private readonly sessionMap: NativeSessionMap) {}
240
+
241
+ // === Header ===
242
+ getHeader(): string {
243
+ return this.sessionMap.getHeader();
244
+ }
186
245
 
187
- tryAdd(
188
- transactions: Transaction[],
189
- newSignature: Signature,
246
+ // === Transaction Operations ===
247
+ addTransactions(
248
+ sessionId: string,
249
+ signerId: string | undefined,
250
+ transactionsJson: string,
251
+ signature: string,
190
252
  skipVerify: boolean,
191
253
  ): void {
192
- // Use direct calls instead of JSON.stringify for better performance
193
- for (const tx of transactions) {
194
- if (tx.privacy === "private") {
195
- this.sessionLog.addExistingPrivateTransaction(
196
- tx.encryptedChanges,
197
- tx.keyUsed,
198
- tx.madeAt,
199
- tx.meta,
200
- );
201
- } else {
202
- this.sessionLog.addExistingTrustingTransaction(
203
- tx.changes,
204
- tx.madeAt,
205
- tx.meta,
206
- );
207
- }
208
- }
209
- this.sessionLog.commitTransactions(newSignature, skipVerify);
254
+ this.sessionMap.addTransactions(
255
+ sessionId,
256
+ signerId,
257
+ transactionsJson,
258
+ signature,
259
+ skipVerify,
260
+ );
210
261
  }
211
262
 
212
- addNewPrivateTransaction(
213
- signerAgent: ControlledAccountOrAgent,
214
- changes: JsonValue[],
215
- keyID: KeyID,
216
- keySecret: KeySecret,
263
+ makeNewPrivateTransaction(
264
+ sessionId: string,
265
+ signerSecret: string,
266
+ changesJson: string,
267
+ keyId: string,
268
+ keySecret: string,
269
+ metaJson: string | undefined,
217
270
  madeAt: number,
218
- meta: JsonObject | undefined,
219
- ): { signature: Signature; transaction: PrivateTransaction } {
220
- const output = this.sessionLog.addNewPrivateTransaction(
221
- // We can avoid stableStringify because it will be encrypted.
222
- JSON.stringify(changes),
223
- signerAgent.currentSignerSecret(),
271
+ ): string {
272
+ return this.sessionMap.makeNewPrivateTransaction(
273
+ sessionId,
274
+ signerSecret,
275
+ changesJson,
276
+ keyId,
224
277
  keySecret,
225
- keyID,
278
+ metaJson,
226
279
  madeAt,
227
- // We can avoid stableStringify because it will be encrypted.
228
- meta ? JSON.stringify(meta) : undefined,
229
280
  );
230
- const parsedOutput = JSON.parse(output);
231
- const transaction: PrivateTransaction = {
232
- privacy: "private",
233
- madeAt,
234
- encryptedChanges: parsedOutput.encrypted_changes,
235
- keyUsed: keyID,
236
- meta: parsedOutput.meta,
237
- };
238
- return { signature: parsedOutput.signature, transaction };
239
281
  }
240
282
 
241
- addNewTrustingTransaction(
242
- signerAgent: ControlledAccountOrAgent,
243
- changes: JsonValue[],
283
+ makeNewTrustingTransaction(
284
+ sessionId: string,
285
+ signerSecret: string,
286
+ changesJson: string,
287
+ metaJson: string | undefined,
244
288
  madeAt: number,
245
- meta: JsonObject | undefined,
246
- ): { signature: Signature; transaction: TrustingTransaction } {
247
- // We can avoid stableStringify because the changes will be in a string format already.
248
- const stringifiedChanges = JSON.stringify(changes);
249
- // We can avoid stableStringify because the meta will be in a string format already.
250
- const stringifiedMeta = meta ? JSON.stringify(meta) : undefined;
251
- const output = this.sessionLog.addNewTrustingTransaction(
252
- stringifiedChanges,
253
- signerAgent.currentSignerSecret(),
289
+ ): string {
290
+ return this.sessionMap.makeNewTrustingTransaction(
291
+ sessionId,
292
+ signerSecret,
293
+ changesJson,
294
+ metaJson,
254
295
  madeAt,
255
- stringifiedMeta,
256
296
  );
257
- const transaction: TrustingTransaction = {
258
- privacy: "trusting",
259
- madeAt,
260
- changes: stringifiedChanges as Stringified<JsonValue[]>,
261
- meta: stringifiedMeta as Stringified<JsonObject> | undefined,
297
+ }
298
+
299
+ // === Session Queries ===
300
+ getSessionIds(): string[] {
301
+ return this.sessionMap.getSessionIds();
302
+ }
303
+
304
+ getTransactionCount(sessionId: string): number {
305
+ return this.sessionMap.getTransactionCount(sessionId);
306
+ }
307
+
308
+ getTransaction(sessionId: string, txIndex: number): Transaction | undefined {
309
+ const result = this.sessionMap.getTransaction(sessionId, txIndex);
310
+ if (!result) return undefined;
311
+ return JSON.parse(result) as Transaction;
312
+ }
313
+
314
+ getSessionTransactions(
315
+ sessionId: string,
316
+ fromIndex: number,
317
+ ): Transaction[] | undefined {
318
+ const result = this.sessionMap.getSessionTransactions(sessionId, fromIndex);
319
+ if (!result) return undefined;
320
+ return result.map((tx) => JSON.parse(tx) as Transaction);
321
+ }
322
+
323
+ getLastSignature(sessionId: string): string | undefined {
324
+ return this.sessionMap.getLastSignature(sessionId) ?? undefined;
325
+ }
326
+
327
+ getSignatureAfter(sessionId: string, txIndex: number): string | undefined {
328
+ return this.sessionMap.getSignatureAfter(sessionId, txIndex) ?? undefined;
329
+ }
330
+
331
+ getLastSignatureCheckpoint(sessionId: string): number | undefined {
332
+ return this.sessionMap.getLastSignatureCheckpoint(sessionId) ?? undefined;
333
+ }
334
+
335
+ // === Known State ===
336
+ getKnownState(): {
337
+ id: string;
338
+ header: boolean;
339
+ sessions: Record<string, number>;
340
+ } {
341
+ // NAPI returns a native JS object via #[napi(object)]
342
+ return this.sessionMap.getKnownState() as {
343
+ id: string;
344
+ header: boolean;
345
+ sessions: Record<string, number>;
262
346
  };
263
- return { signature: output as Signature, transaction };
264
347
  }
265
348
 
266
- decryptNextTransactionChangesJson(
267
- txIndex: number,
268
- keySecret: KeySecret,
269
- ): string {
270
- const output = this.sessionLog.decryptNextTransactionChangesJson(
271
- txIndex,
272
- keySecret,
273
- );
274
- return output;
349
+ getKnownStateWithStreaming():
350
+ | { id: string; header: boolean; sessions: Record<string, number> }
351
+ | undefined {
352
+ // NAPI returns a native JS object via #[napi(object)], or undefined
353
+ const result = this.sessionMap.getKnownStateWithStreaming();
354
+ if (!result || result === undefined) return undefined;
355
+ return result as {
356
+ id: string;
357
+ header: boolean;
358
+ sessions: Record<string, number>;
359
+ };
360
+ }
361
+
362
+ setStreamingKnownState(streamingJson: string): void {
363
+ this.sessionMap.setStreamingKnownState(streamingJson);
364
+ }
365
+
366
+ // === Deletion ===
367
+ markAsDeleted(): void {
368
+ this.sessionMap.markAsDeleted();
369
+ }
370
+
371
+ isDeleted(): boolean {
372
+ return this.sessionMap.isDeleted();
275
373
  }
276
374
 
277
- decryptNextTransactionMetaJson(
375
+ // === Decryption ===
376
+ decryptTransaction(
377
+ sessionId: string,
278
378
  txIndex: number,
279
- keySecret: KeySecret,
379
+ keySecret: string,
280
380
  ): string | undefined {
281
381
  return (
282
- this.sessionLog.decryptNextTransactionMetaJson(txIndex, keySecret) ||
382
+ this.sessionMap.decryptTransaction(sessionId, txIndex, keySecret) ??
283
383
  undefined
284
384
  );
285
385
  }
286
386
 
287
- free() {
288
- // No-op since the underlying SessionLog doesn't require explicit freeing
289
- }
290
-
291
- clone(): SessionLogAdapter {
292
- return new SessionLogAdapter(this.sessionLog.clone());
387
+ decryptTransactionMeta(
388
+ sessionId: string,
389
+ txIndex: number,
390
+ keySecret: string,
391
+ ): string | undefined {
392
+ return (
393
+ this.sessionMap.decryptTransactionMeta(sessionId, txIndex, keySecret) ??
394
+ undefined
395
+ );
293
396
  }
294
397
  }