@totalreclaw/core 0.1.0 → 1.1.0

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/package.json CHANGED
@@ -1,28 +1,17 @@
1
1
  {
2
2
  "name": "@totalreclaw/core",
3
- "description": "TotalReclaw core crypto primitives (WASM) — E2EE, LSH, blind indices, protobuf encoding. Single source of truth for all TotalReclaw clients.",
4
- "version": "0.1.0",
3
+ "description": "TotalReclaw core — E2EE crypto, reranker, wallet, UserOp, store/search pipelines. Single source of truth for all clients.",
4
+ "version": "1.1.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/p-diogo/totalreclaw",
9
- "directory": "rust/totalreclaw-core"
8
+ "url": "https://github.com/p-diogo/totalreclaw"
10
9
  },
11
10
  "files": [
12
11
  "totalreclaw_core_bg.wasm",
13
12
  "totalreclaw_core.js",
14
- "totalreclaw_core.d.ts",
15
- "totalreclaw_core_bg.wasm.d.ts"
13
+ "totalreclaw_core.d.ts"
16
14
  ],
17
15
  "main": "totalreclaw_core.js",
18
- "types": "totalreclaw_core.d.ts",
19
- "keywords": [
20
- "totalreclaw",
21
- "crypto",
22
- "wasm",
23
- "aes-256-gcm",
24
- "lsh",
25
- "blind-indices",
26
- "e2ee"
27
- ]
16
+ "types": "totalreclaw_core.d.ts"
28
17
  }
@@ -21,7 +21,7 @@ export class WasmLshHasher {
21
21
  * Create a new LSH hasher with default parameters (20 tables, 32 bits).
22
22
  *
23
23
  * `seed_hex`: hex-encoded seed (>= 32 chars = 16 bytes).
24
- * `dims`: embedding dimensionality (e.g. 1024).
24
+ * `dims`: embedding dimensionality (e.g. 640).
25
25
  */
26
26
  constructor(seed_hex: string, dims: number);
27
27
  /**
@@ -47,6 +47,14 @@ export class WasmLshHasher {
47
47
  readonly tables: number;
48
48
  }
49
49
 
50
+ /**
51
+ * Build ABI-encoded calldata for a batch of prepared facts.
52
+ *
53
+ * `prepared_array_json`: JSON array of `PreparedFact` objects.
54
+ * Returns ABI-encoded calldata (Uint8Array).
55
+ */
56
+ export function buildBatchCalldataFromPrepared(prepared_array_json: string): Uint8Array;
57
+
50
58
  /**
51
59
  * Build the debrief prompt with already-stored facts filled in.
52
60
  *
@@ -54,6 +62,14 @@ export class WasmLshHasher {
54
62
  */
55
63
  export function buildDebriefPrompt(stored_facts_json: string): string;
56
64
 
65
+ /**
66
+ * Build ABI-encoded calldata for a single prepared fact.
67
+ *
68
+ * `prepared_json`: JSON string of a `PreparedFact`.
69
+ * Returns ABI-encoded calldata (Uint8Array).
70
+ */
71
+ export function buildSingleCalldataFromPrepared(prepared_json: string): Uint8Array;
72
+
57
73
  /**
58
74
  * Compute SHA-256(authKey) as a hex string.
59
75
  *
@@ -62,13 +78,57 @@ export function buildDebriefPrompt(stored_facts_json: string): string;
62
78
  export function computeAuthKeyHash(auth_key_hex: string): string;
63
79
 
64
80
  /**
65
- * Decrypt a base64-encoded AES-256-GCM blob.
81
+ * Compute the content fingerprint for dedup checks.
82
+ *
83
+ * `dedup_key_hex`: 64-char hex string (32 bytes).
84
+ * Returns 64-char hex fingerprint.
85
+ */
86
+ export function computeContentFingerprint(text: string, dedup_key_hex: string): string;
87
+
88
+ /**
89
+ * Cosine similarity between two f32 vectors.
90
+ */
91
+ export function cosineSimilarity(a: Float32Array, b: Float32Array): number;
92
+
93
+ /**
94
+ * Decrypt a base64-encoded XChaCha20-Poly1305 blob.
66
95
  *
67
96
  * `encryption_key_hex`: 64-char hex string (32 bytes).
68
97
  * Returns the plaintext UTF-8 string.
69
98
  */
70
99
  export function decrypt(encrypted_base64: string, encryption_key_hex: string): string;
71
100
 
101
+ /**
102
+ * Decrypt and rerank search candidates.
103
+ *
104
+ * Takes raw SubgraphFacts (as JSON), decrypts their content + embeddings,
105
+ * and returns top-K ranked results using BM25 + Cosine + RRF fusion.
106
+ *
107
+ * `facts_json`: JSON array of SubgraphFact objects.
108
+ * `query`: The search query text.
109
+ * `query_embedding`: Float32Array of the query embedding.
110
+ * `encryption_key_hex`: 64-char hex string (32 bytes).
111
+ * `top_k`: Number of top results to return.
112
+ *
113
+ * Returns a JsValue (JSON array of RankedResult objects).
114
+ */
115
+ export function decryptAndRerank(facts_json: string, query: string, query_embedding: Float32Array, encryption_key_hex: string, top_k: number): any;
116
+
117
+ /**
118
+ * Derive an Ethereum EOA wallet from a BIP-39 mnemonic via BIP-44.
119
+ *
120
+ * Path: m/44'/60'/0'/0/0 (standard Ethereum derivation path).
121
+ * Returns a JS object: `{ private_key: "hex...", address: "0x..." }`.
122
+ */
123
+ export function deriveEoa(mnemonic: string): any;
124
+
125
+ /**
126
+ * Derive just the Ethereum EOA address from a BIP-39 mnemonic.
127
+ *
128
+ * Returns: `"0x..."` (lowercase hex).
129
+ */
130
+ export function deriveEoaAddress(mnemonic: string): string;
131
+
72
132
  /**
73
133
  * Derive encryption keys from a BIP-39 mnemonic (strict checksum validation).
74
134
  *
@@ -92,6 +152,14 @@ export function deriveKeysFromMnemonicLenient(mnemonic: string): any;
92
152
  */
93
153
  export function deriveLshSeed(mnemonic: string, salt_hex: string): string;
94
154
 
155
+ /**
156
+ * Encode multiple fact submissions as SimpleAccount.executeBatch() calldata.
157
+ *
158
+ * `payloads_json`: JSON array of hex-encoded payload strings (e.g. `["deadbeef", "cafebabe"]`).
159
+ * Returns ABI-encoded calldata (Uint8Array).
160
+ */
161
+ export function encodeBatchCall(payloads_json: string): Uint8Array;
162
+
95
163
  /**
96
164
  * Encode a fact payload as minimal protobuf wire format.
97
165
  *
@@ -109,6 +177,14 @@ export function deriveLshSeed(mnemonic: string, salt_hex: string): string;
109
177
  */
110
178
  export function encodeFactProtobuf(json: string): Uint8Array;
111
179
 
180
+ /**
181
+ * Encode a single fact submission as SimpleAccount.execute() calldata.
182
+ *
183
+ * `protobuf_payload`: raw protobuf bytes (Uint8Array).
184
+ * Returns ABI-encoded calldata (Uint8Array).
185
+ */
186
+ export function encodeSingleCall(protobuf_payload: Uint8Array): Uint8Array;
187
+
112
188
  /**
113
189
  * Encode a tombstone protobuf for soft-deleting a fact.
114
190
  *
@@ -117,13 +193,24 @@ export function encodeFactProtobuf(json: string): Uint8Array;
117
193
  export function encodeTombstoneProtobuf(fact_id: string, owner: string): Uint8Array;
118
194
 
119
195
  /**
120
- * Encrypt a UTF-8 plaintext with AES-256-GCM.
196
+ * Encrypt a UTF-8 plaintext with XChaCha20-Poly1305.
121
197
  *
122
198
  * `encryption_key_hex`: 64-char hex string (32 bytes).
123
- * Returns base64-encoded ciphertext (wire format: iv || tag || ciphertext).
199
+ * Returns base64-encoded ciphertext (wire format: nonce || tag || ciphertext).
124
200
  */
125
201
  export function encrypt(plaintext: string, encryption_key_hex: string): string;
126
202
 
203
+ /**
204
+ * WASM binding for `find_near_duplicate`.
205
+ *
206
+ * `new_embedding`: Float32Array of the new fact's embedding.
207
+ * `existing_json`: JSON array of `{ id: string, embedding: number[] }` objects.
208
+ * `threshold`: Cosine similarity threshold.
209
+ *
210
+ * Returns `null` if no duplicate found, or a string (the duplicate fact ID).
211
+ */
212
+ export function findNearDuplicate(new_embedding: Float32Array, existing_json: string, threshold: number): any;
213
+
127
214
  /**
128
215
  * Generate blind indices (SHA-256 token hashes) for a text string.
129
216
  *
@@ -139,6 +226,37 @@ export function generateBlindIndices(text: string): any;
139
226
  */
140
227
  export function generateContentFingerprint(plaintext: string, dedup_key_hex: string): string;
141
228
 
229
+ /**
230
+ * Generate all search trapdoors for a query (word hashes + LSH bucket hashes).
231
+ *
232
+ * `query`: The search query text.
233
+ * `query_embedding`: Float32Array of the query embedding.
234
+ * `lsh_hasher`: A `WasmLshHasher` instance.
235
+ *
236
+ * Returns a JsValue (JSON array of hex-encoded trapdoor strings).
237
+ */
238
+ export function generateSearchTrapdoors(query: string, query_embedding: Float32Array, lsh_hasher: WasmLshHasher): any;
239
+
240
+ /**
241
+ * Get the GraphQL query string for broadened (fallback) search.
242
+ */
243
+ export function getBroadenedSearchQuery(): string;
244
+
245
+ /**
246
+ * WASM binding: get the consolidation cosine threshold constant.
247
+ */
248
+ export function getConsolidationCosineThreshold(): number;
249
+
250
+ /**
251
+ * Get the GraphQL query string for fact count.
252
+ */
253
+ export function getCountQuery(): string;
254
+
255
+ /**
256
+ * Get the DataEdge contract address constant.
257
+ */
258
+ export function getDataEdgeAddress(): string;
259
+
142
260
  /**
143
261
  * Source tag for debrief items.
144
262
  */
@@ -151,6 +269,21 @@ export function getDebriefSource(): string;
151
269
  */
152
270
  export function getDebriefSystemPrompt(): string;
153
271
 
272
+ /**
273
+ * Get the EntryPoint v0.7 address constant.
274
+ */
275
+ export function getEntryPointAddress(): string;
276
+
277
+ /**
278
+ * Get the GraphQL query string for paginated export.
279
+ */
280
+ export function getExportQuery(): string;
281
+
282
+ /**
283
+ * Get the maximum batch size constant.
284
+ */
285
+ export function getMaxBatchSize(): number;
286
+
154
287
  /**
155
288
  * Maximum debrief items (5).
156
289
  */
@@ -161,14 +294,130 @@ export function getMaxDebriefItems(): number;
161
294
  */
162
295
  export function getMinDebriefMessages(): number;
163
296
 
297
+ /**
298
+ * Get the page size constant.
299
+ */
300
+ export function getPageSize(): number;
301
+
302
+ /**
303
+ * Get the GraphQL query string for blind index search.
304
+ */
305
+ export function getSearchQuery(): string;
306
+
307
+ /**
308
+ * Get the SimpleAccountFactory address constant.
309
+ */
310
+ export function getSimpleAccountFactory(): string;
311
+
312
+ /**
313
+ * WASM binding: get the store-time dedup cosine threshold constant.
314
+ */
315
+ export function getStoreDedupCosineThreshold(): number;
316
+
317
+ /**
318
+ * WASM binding: get the store-time dedup max candidates constant.
319
+ */
320
+ export function getStoreDedupMaxCandidates(): number;
321
+
322
+ /**
323
+ * Get the trapdoor batch size constant.
324
+ */
325
+ export function getTrapdoorBatchSize(): number;
326
+
327
+ /**
328
+ * Compute the ERC-4337 v0.7 UserOp hash for signing.
329
+ *
330
+ * `userop_json`: JSON string of a UserOperationV7 struct.
331
+ * `entrypoint`: EntryPoint address (0x-prefixed).
332
+ * `chain_id`: Chain ID (e.g. 84532 for Base Sepolia).
333
+ * Returns 32-byte hash as hex string.
334
+ */
335
+ export function hashUserOp(userop_json: string, entrypoint: string, chain_id: bigint): string;
336
+
337
+ /**
338
+ * Convert a subgraph hex blob to base64 for decryption.
339
+ *
340
+ * `hex_blob`: Hex string (optionally `0x`-prefixed) from the subgraph.
341
+ * Returns base64-encoded bytes, or null if the hex is invalid.
342
+ */
343
+ export function hexBlobToBase64(hex_blob: string): string | undefined;
344
+
164
345
  /**
165
346
  * Normalize text (NFC, lowercase, collapse whitespace, trim).
166
347
  */
167
348
  export function normalizeText(text: string): string;
168
349
 
350
+ /**
351
+ * Parse a broadened search GraphQL response into SubgraphFact list.
352
+ *
353
+ * `response_json`: Raw JSON string from the GraphQL response.
354
+ * Returns a JsValue (JSON array of SubgraphFact objects).
355
+ */
356
+ export function parseBroadenedResponse(response_json: string): any;
357
+
169
358
  /**
170
359
  * Parse a debrief LLM response into validated items.
171
360
  *
172
361
  * Returns a JSON array of `{ text, type, importance }` objects.
173
362
  */
174
363
  export function parseDebriefResponse(response: string): any;
364
+
365
+ /**
366
+ * Parse a blind index search GraphQL response into SubgraphFact list.
367
+ *
368
+ * `response_json`: Raw JSON string from the GraphQL response.
369
+ * Returns a JsValue (JSON array of SubgraphFact objects).
370
+ */
371
+ export function parseSearchResponse(response_json: string): any;
372
+
373
+ /**
374
+ * Prepare a fact for on-chain storage.
375
+ *
376
+ * Pure computation: encrypt, generate indices, encode protobuf.
377
+ * Does NOT submit -- the host handles I/O.
378
+ *
379
+ * `encryption_key_hex`: 64-char hex string (32 bytes).
380
+ * `dedup_key_hex`: 64-char hex string (32 bytes).
381
+ * `lsh_hasher`: A `WasmLshHasher` instance.
382
+ * `embedding`: Float32Array of the pre-computed embedding vector.
383
+ * `importance`: Importance score on 1-10 scale (normalized to 0.0-1.0).
384
+ *
385
+ * Returns a JSON string with `PreparedFact` fields.
386
+ */
387
+ export function prepareFact(text: string, encryption_key_hex: string, dedup_key_hex: string, lsh_hasher: WasmLshHasher, embedding: Float32Array, importance: number, source: string, owner: string, agent_id: string): any;
388
+
389
+ /**
390
+ * Prepare a fact with a pre-normalized decay score (already 0.0-1.0).
391
+ *
392
+ * Same as `prepareFact()` but takes a raw decay score.
393
+ */
394
+ export function prepareFactWithDecayScore(text: string, encryption_key_hex: string, dedup_key_hex: string, lsh_hasher: WasmLshHasher, embedding: Float32Array, decay_score: number, source: string, owner: string, agent_id: string): any;
395
+
396
+ /**
397
+ * Prepare a tombstone (soft-delete) protobuf.
398
+ *
399
+ * Returns the protobuf bytes as a Uint8Array.
400
+ */
401
+ export function prepareTombstone(fact_id: string, owner: string): Uint8Array;
402
+
403
+ /**
404
+ * Rerank candidates using BM25 + Cosine + RRF fusion.
405
+ *
406
+ * `candidates_json`: JSON array of `{ id, text, embedding, timestamp }` objects.
407
+ * Returns a JsValue (array of `RankedResult` objects).
408
+ */
409
+ export function rerank(query: string, query_embedding: Float32Array, candidates_json: string, top_k: number): any;
410
+
411
+ /**
412
+ * WASM binding: determine if a new fact should supersede an existing one.
413
+ */
414
+ export function shouldSupersede(new_importance: number, existing_importance: number): boolean;
415
+
416
+ /**
417
+ * Sign a UserOp hash with an ECDSA private key (EIP-191 prefixed).
418
+ *
419
+ * `hash_hex`: 64-char hex string (32-byte UserOp hash).
420
+ * `private_key_hex`: 64-char hex string (32-byte private key).
421
+ * Returns 65-byte signature as hex string (r + s + v).
422
+ */
423
+ export function signUserOp(hash_hex: string, private_key_hex: string): string;
@@ -61,7 +61,7 @@ class WasmLshHasher {
61
61
  * Create a new LSH hasher with default parameters (20 tables, 32 bits).
62
62
  *
63
63
  * `seed_hex`: hex-encoded seed (>= 32 chars = 16 bytes).
64
- * `dims`: embedding dimensionality (e.g. 1024).
64
+ * `dims`: embedding dimensionality (e.g. 640).
65
65
  * @param {string} seed_hex
66
66
  * @param {number} dims
67
67
  */
@@ -110,6 +110,27 @@ class WasmLshHasher {
110
110
  if (Symbol.dispose) WasmLshHasher.prototype[Symbol.dispose] = WasmLshHasher.prototype.free;
111
111
  exports.WasmLshHasher = WasmLshHasher;
112
112
 
113
+ /**
114
+ * Build ABI-encoded calldata for a batch of prepared facts.
115
+ *
116
+ * `prepared_array_json`: JSON array of `PreparedFact` objects.
117
+ * Returns ABI-encoded calldata (Uint8Array).
118
+ * @param {string} prepared_array_json
119
+ * @returns {Uint8Array}
120
+ */
121
+ function buildBatchCalldataFromPrepared(prepared_array_json) {
122
+ const ptr0 = passStringToWasm0(prepared_array_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
123
+ const len0 = WASM_VECTOR_LEN;
124
+ const ret = wasm.buildBatchCalldataFromPrepared(ptr0, len0);
125
+ if (ret[3]) {
126
+ throw takeFromExternrefTable0(ret[2]);
127
+ }
128
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
129
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
130
+ return v2;
131
+ }
132
+ exports.buildBatchCalldataFromPrepared = buildBatchCalldataFromPrepared;
133
+
113
134
  /**
114
135
  * Build the debrief prompt with already-stored facts filled in.
115
136
  *
@@ -139,6 +160,27 @@ function buildDebriefPrompt(stored_facts_json) {
139
160
  }
140
161
  exports.buildDebriefPrompt = buildDebriefPrompt;
141
162
 
163
+ /**
164
+ * Build ABI-encoded calldata for a single prepared fact.
165
+ *
166
+ * `prepared_json`: JSON string of a `PreparedFact`.
167
+ * Returns ABI-encoded calldata (Uint8Array).
168
+ * @param {string} prepared_json
169
+ * @returns {Uint8Array}
170
+ */
171
+ function buildSingleCalldataFromPrepared(prepared_json) {
172
+ const ptr0 = passStringToWasm0(prepared_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
173
+ const len0 = WASM_VECTOR_LEN;
174
+ const ret = wasm.buildSingleCalldataFromPrepared(ptr0, len0);
175
+ if (ret[3]) {
176
+ throw takeFromExternrefTable0(ret[2]);
177
+ }
178
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
179
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
180
+ return v2;
181
+ }
182
+ exports.buildSingleCalldataFromPrepared = buildSingleCalldataFromPrepared;
183
+
142
184
  /**
143
185
  * Compute SHA-256(authKey) as a hex string.
144
186
  *
@@ -169,7 +211,56 @@ function computeAuthKeyHash(auth_key_hex) {
169
211
  exports.computeAuthKeyHash = computeAuthKeyHash;
170
212
 
171
213
  /**
172
- * Decrypt a base64-encoded AES-256-GCM blob.
214
+ * Compute the content fingerprint for dedup checks.
215
+ *
216
+ * `dedup_key_hex`: 64-char hex string (32 bytes).
217
+ * Returns 64-char hex fingerprint.
218
+ * @param {string} text
219
+ * @param {string} dedup_key_hex
220
+ * @returns {string}
221
+ */
222
+ function computeContentFingerprint(text, dedup_key_hex) {
223
+ let deferred4_0;
224
+ let deferred4_1;
225
+ try {
226
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
227
+ const len0 = WASM_VECTOR_LEN;
228
+ const ptr1 = passStringToWasm0(dedup_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
229
+ const len1 = WASM_VECTOR_LEN;
230
+ const ret = wasm.computeContentFingerprint(ptr0, len0, ptr1, len1);
231
+ var ptr3 = ret[0];
232
+ var len3 = ret[1];
233
+ if (ret[3]) {
234
+ ptr3 = 0; len3 = 0;
235
+ throw takeFromExternrefTable0(ret[2]);
236
+ }
237
+ deferred4_0 = ptr3;
238
+ deferred4_1 = len3;
239
+ return getStringFromWasm0(ptr3, len3);
240
+ } finally {
241
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
242
+ }
243
+ }
244
+ exports.computeContentFingerprint = computeContentFingerprint;
245
+
246
+ /**
247
+ * Cosine similarity between two f32 vectors.
248
+ * @param {Float32Array} a
249
+ * @param {Float32Array} b
250
+ * @returns {number}
251
+ */
252
+ function cosineSimilarity(a, b) {
253
+ const ptr0 = passArrayF32ToWasm0(a, wasm.__wbindgen_malloc);
254
+ const len0 = WASM_VECTOR_LEN;
255
+ const ptr1 = passArrayF32ToWasm0(b, wasm.__wbindgen_malloc);
256
+ const len1 = WASM_VECTOR_LEN;
257
+ const ret = wasm.cosineSimilarity(ptr0, len0, ptr1, len1);
258
+ return ret;
259
+ }
260
+ exports.cosineSimilarity = cosineSimilarity;
261
+
262
+ /**
263
+ * Decrypt a base64-encoded XChaCha20-Poly1305 blob.
173
264
  *
174
265
  * `encryption_key_hex`: 64-char hex string (32 bytes).
175
266
  * Returns the plaintext UTF-8 string.
@@ -201,6 +292,91 @@ function decrypt(encrypted_base64, encryption_key_hex) {
201
292
  }
202
293
  exports.decrypt = decrypt;
203
294
 
295
+ /**
296
+ * Decrypt and rerank search candidates.
297
+ *
298
+ * Takes raw SubgraphFacts (as JSON), decrypts their content + embeddings,
299
+ * and returns top-K ranked results using BM25 + Cosine + RRF fusion.
300
+ *
301
+ * `facts_json`: JSON array of SubgraphFact objects.
302
+ * `query`: The search query text.
303
+ * `query_embedding`: Float32Array of the query embedding.
304
+ * `encryption_key_hex`: 64-char hex string (32 bytes).
305
+ * `top_k`: Number of top results to return.
306
+ *
307
+ * Returns a JsValue (JSON array of RankedResult objects).
308
+ * @param {string} facts_json
309
+ * @param {string} query
310
+ * @param {Float32Array} query_embedding
311
+ * @param {string} encryption_key_hex
312
+ * @param {number} top_k
313
+ * @returns {any}
314
+ */
315
+ function decryptAndRerank(facts_json, query, query_embedding, encryption_key_hex, top_k) {
316
+ const ptr0 = passStringToWasm0(facts_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
317
+ const len0 = WASM_VECTOR_LEN;
318
+ const ptr1 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
319
+ const len1 = WASM_VECTOR_LEN;
320
+ const ptr2 = passArrayF32ToWasm0(query_embedding, wasm.__wbindgen_malloc);
321
+ const len2 = WASM_VECTOR_LEN;
322
+ const ptr3 = passStringToWasm0(encryption_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
323
+ const len3 = WASM_VECTOR_LEN;
324
+ const ret = wasm.decryptAndRerank(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, top_k);
325
+ if (ret[2]) {
326
+ throw takeFromExternrefTable0(ret[1]);
327
+ }
328
+ return takeFromExternrefTable0(ret[0]);
329
+ }
330
+ exports.decryptAndRerank = decryptAndRerank;
331
+
332
+ /**
333
+ * Derive an Ethereum EOA wallet from a BIP-39 mnemonic via BIP-44.
334
+ *
335
+ * Path: m/44'/60'/0'/0/0 (standard Ethereum derivation path).
336
+ * Returns a JS object: `{ private_key: "hex...", address: "0x..." }`.
337
+ * @param {string} mnemonic
338
+ * @returns {any}
339
+ */
340
+ function deriveEoa(mnemonic) {
341
+ const ptr0 = passStringToWasm0(mnemonic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
342
+ const len0 = WASM_VECTOR_LEN;
343
+ const ret = wasm.deriveEoa(ptr0, len0);
344
+ if (ret[2]) {
345
+ throw takeFromExternrefTable0(ret[1]);
346
+ }
347
+ return takeFromExternrefTable0(ret[0]);
348
+ }
349
+ exports.deriveEoa = deriveEoa;
350
+
351
+ /**
352
+ * Derive just the Ethereum EOA address from a BIP-39 mnemonic.
353
+ *
354
+ * Returns: `"0x..."` (lowercase hex).
355
+ * @param {string} mnemonic
356
+ * @returns {string}
357
+ */
358
+ function deriveEoaAddress(mnemonic) {
359
+ let deferred3_0;
360
+ let deferred3_1;
361
+ try {
362
+ const ptr0 = passStringToWasm0(mnemonic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
363
+ const len0 = WASM_VECTOR_LEN;
364
+ const ret = wasm.deriveEoaAddress(ptr0, len0);
365
+ var ptr2 = ret[0];
366
+ var len2 = ret[1];
367
+ if (ret[3]) {
368
+ ptr2 = 0; len2 = 0;
369
+ throw takeFromExternrefTable0(ret[2]);
370
+ }
371
+ deferred3_0 = ptr2;
372
+ deferred3_1 = len2;
373
+ return getStringFromWasm0(ptr2, len2);
374
+ } finally {
375
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
376
+ }
377
+ }
378
+ exports.deriveEoaAddress = deriveEoaAddress;
379
+
204
380
  /**
205
381
  * Derive encryption keys from a BIP-39 mnemonic (strict checksum validation).
206
382
  *
@@ -271,6 +447,27 @@ function deriveLshSeed(mnemonic, salt_hex) {
271
447
  }
272
448
  exports.deriveLshSeed = deriveLshSeed;
273
449
 
450
+ /**
451
+ * Encode multiple fact submissions as SimpleAccount.executeBatch() calldata.
452
+ *
453
+ * `payloads_json`: JSON array of hex-encoded payload strings (e.g. `["deadbeef", "cafebabe"]`).
454
+ * Returns ABI-encoded calldata (Uint8Array).
455
+ * @param {string} payloads_json
456
+ * @returns {Uint8Array}
457
+ */
458
+ function encodeBatchCall(payloads_json) {
459
+ const ptr0 = passStringToWasm0(payloads_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
460
+ const len0 = WASM_VECTOR_LEN;
461
+ const ret = wasm.encodeBatchCall(ptr0, len0);
462
+ if (ret[3]) {
463
+ throw takeFromExternrefTable0(ret[2]);
464
+ }
465
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
466
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
467
+ return v2;
468
+ }
469
+ exports.encodeBatchCall = encodeBatchCall;
470
+
274
471
  /**
275
472
  * Encode a fact payload as minimal protobuf wire format.
276
473
  *
@@ -301,6 +498,24 @@ function encodeFactProtobuf(json) {
301
498
  }
302
499
  exports.encodeFactProtobuf = encodeFactProtobuf;
303
500
 
501
+ /**
502
+ * Encode a single fact submission as SimpleAccount.execute() calldata.
503
+ *
504
+ * `protobuf_payload`: raw protobuf bytes (Uint8Array).
505
+ * Returns ABI-encoded calldata (Uint8Array).
506
+ * @param {Uint8Array} protobuf_payload
507
+ * @returns {Uint8Array}
508
+ */
509
+ function encodeSingleCall(protobuf_payload) {
510
+ const ptr0 = passArray8ToWasm0(protobuf_payload, wasm.__wbindgen_malloc);
511
+ const len0 = WASM_VECTOR_LEN;
512
+ const ret = wasm.encodeSingleCall(ptr0, len0);
513
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
514
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
515
+ return v2;
516
+ }
517
+ exports.encodeSingleCall = encodeSingleCall;
518
+
304
519
  /**
305
520
  * Encode a tombstone protobuf for soft-deleting a fact.
306
521
  *
@@ -322,10 +537,10 @@ function encodeTombstoneProtobuf(fact_id, owner) {
322
537
  exports.encodeTombstoneProtobuf = encodeTombstoneProtobuf;
323
538
 
324
539
  /**
325
- * Encrypt a UTF-8 plaintext with AES-256-GCM.
540
+ * Encrypt a UTF-8 plaintext with XChaCha20-Poly1305.
326
541
  *
327
542
  * `encryption_key_hex`: 64-char hex string (32 bytes).
328
- * Returns base64-encoded ciphertext (wire format: iv || tag || ciphertext).
543
+ * Returns base64-encoded ciphertext (wire format: nonce || tag || ciphertext).
329
544
  * @param {string} plaintext
330
545
  * @param {string} encryption_key_hex
331
546
  * @returns {string}
@@ -354,6 +569,32 @@ function encrypt(plaintext, encryption_key_hex) {
354
569
  }
355
570
  exports.encrypt = encrypt;
356
571
 
572
+ /**
573
+ * WASM binding for `find_near_duplicate`.
574
+ *
575
+ * `new_embedding`: Float32Array of the new fact's embedding.
576
+ * `existing_json`: JSON array of `{ id: string, embedding: number[] }` objects.
577
+ * `threshold`: Cosine similarity threshold.
578
+ *
579
+ * Returns `null` if no duplicate found, or a string (the duplicate fact ID).
580
+ * @param {Float32Array} new_embedding
581
+ * @param {string} existing_json
582
+ * @param {number} threshold
583
+ * @returns {any}
584
+ */
585
+ function findNearDuplicate(new_embedding, existing_json, threshold) {
586
+ const ptr0 = passArrayF32ToWasm0(new_embedding, wasm.__wbindgen_malloc);
587
+ const len0 = WASM_VECTOR_LEN;
588
+ const ptr1 = passStringToWasm0(existing_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
589
+ const len1 = WASM_VECTOR_LEN;
590
+ const ret = wasm.findNearDuplicate(ptr0, len0, ptr1, len1, threshold);
591
+ if (ret[2]) {
592
+ throw takeFromExternrefTable0(ret[1]);
593
+ }
594
+ return takeFromExternrefTable0(ret[0]);
595
+ }
596
+ exports.findNearDuplicate = findNearDuplicate;
597
+
357
598
  /**
358
599
  * Generate blind indices (SHA-256 token hashes) for a text string.
359
600
  *
@@ -405,6 +646,97 @@ function generateContentFingerprint(plaintext, dedup_key_hex) {
405
646
  }
406
647
  exports.generateContentFingerprint = generateContentFingerprint;
407
648
 
649
+ /**
650
+ * Generate all search trapdoors for a query (word hashes + LSH bucket hashes).
651
+ *
652
+ * `query`: The search query text.
653
+ * `query_embedding`: Float32Array of the query embedding.
654
+ * `lsh_hasher`: A `WasmLshHasher` instance.
655
+ *
656
+ * Returns a JsValue (JSON array of hex-encoded trapdoor strings).
657
+ * @param {string} query
658
+ * @param {Float32Array} query_embedding
659
+ * @param {WasmLshHasher} lsh_hasher
660
+ * @returns {any}
661
+ */
662
+ function generateSearchTrapdoors(query, query_embedding, lsh_hasher) {
663
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
664
+ const len0 = WASM_VECTOR_LEN;
665
+ const ptr1 = passArrayF32ToWasm0(query_embedding, wasm.__wbindgen_malloc);
666
+ const len1 = WASM_VECTOR_LEN;
667
+ _assertClass(lsh_hasher, WasmLshHasher);
668
+ const ret = wasm.generateSearchTrapdoors(ptr0, len0, ptr1, len1, lsh_hasher.__wbg_ptr);
669
+ if (ret[2]) {
670
+ throw takeFromExternrefTable0(ret[1]);
671
+ }
672
+ return takeFromExternrefTable0(ret[0]);
673
+ }
674
+ exports.generateSearchTrapdoors = generateSearchTrapdoors;
675
+
676
+ /**
677
+ * Get the GraphQL query string for broadened (fallback) search.
678
+ * @returns {string}
679
+ */
680
+ function getBroadenedSearchQuery() {
681
+ let deferred1_0;
682
+ let deferred1_1;
683
+ try {
684
+ const ret = wasm.getBroadenedSearchQuery();
685
+ deferred1_0 = ret[0];
686
+ deferred1_1 = ret[1];
687
+ return getStringFromWasm0(ret[0], ret[1]);
688
+ } finally {
689
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
690
+ }
691
+ }
692
+ exports.getBroadenedSearchQuery = getBroadenedSearchQuery;
693
+
694
+ /**
695
+ * WASM binding: get the consolidation cosine threshold constant.
696
+ * @returns {number}
697
+ */
698
+ function getConsolidationCosineThreshold() {
699
+ const ret = wasm.getConsolidationCosineThreshold();
700
+ return ret;
701
+ }
702
+ exports.getConsolidationCosineThreshold = getConsolidationCosineThreshold;
703
+
704
+ /**
705
+ * Get the GraphQL query string for fact count.
706
+ * @returns {string}
707
+ */
708
+ function getCountQuery() {
709
+ let deferred1_0;
710
+ let deferred1_1;
711
+ try {
712
+ const ret = wasm.getCountQuery();
713
+ deferred1_0 = ret[0];
714
+ deferred1_1 = ret[1];
715
+ return getStringFromWasm0(ret[0], ret[1]);
716
+ } finally {
717
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
718
+ }
719
+ }
720
+ exports.getCountQuery = getCountQuery;
721
+
722
+ /**
723
+ * Get the DataEdge contract address constant.
724
+ * @returns {string}
725
+ */
726
+ function getDataEdgeAddress() {
727
+ let deferred1_0;
728
+ let deferred1_1;
729
+ try {
730
+ const ret = wasm.getDataEdgeAddress();
731
+ deferred1_0 = ret[0];
732
+ deferred1_1 = ret[1];
733
+ return getStringFromWasm0(ret[0], ret[1]);
734
+ } finally {
735
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
736
+ }
737
+ }
738
+ exports.getDataEdgeAddress = getDataEdgeAddress;
739
+
408
740
  /**
409
741
  * Source tag for debrief items.
410
742
  * @returns {string}
@@ -443,6 +775,52 @@ function getDebriefSystemPrompt() {
443
775
  }
444
776
  exports.getDebriefSystemPrompt = getDebriefSystemPrompt;
445
777
 
778
+ /**
779
+ * Get the EntryPoint v0.7 address constant.
780
+ * @returns {string}
781
+ */
782
+ function getEntryPointAddress() {
783
+ let deferred1_0;
784
+ let deferred1_1;
785
+ try {
786
+ const ret = wasm.getEntryPointAddress();
787
+ deferred1_0 = ret[0];
788
+ deferred1_1 = ret[1];
789
+ return getStringFromWasm0(ret[0], ret[1]);
790
+ } finally {
791
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
792
+ }
793
+ }
794
+ exports.getEntryPointAddress = getEntryPointAddress;
795
+
796
+ /**
797
+ * Get the GraphQL query string for paginated export.
798
+ * @returns {string}
799
+ */
800
+ function getExportQuery() {
801
+ let deferred1_0;
802
+ let deferred1_1;
803
+ try {
804
+ const ret = wasm.getExportQuery();
805
+ deferred1_0 = ret[0];
806
+ deferred1_1 = ret[1];
807
+ return getStringFromWasm0(ret[0], ret[1]);
808
+ } finally {
809
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
810
+ }
811
+ }
812
+ exports.getExportQuery = getExportQuery;
813
+
814
+ /**
815
+ * Get the maximum batch size constant.
816
+ * @returns {number}
817
+ */
818
+ function getMaxBatchSize() {
819
+ const ret = wasm.getMaxBatchSize();
820
+ return ret >>> 0;
821
+ }
822
+ exports.getMaxBatchSize = getMaxBatchSize;
823
+
446
824
  /**
447
825
  * Maximum debrief items (5).
448
826
  * @returns {number}
@@ -463,6 +841,139 @@ function getMinDebriefMessages() {
463
841
  }
464
842
  exports.getMinDebriefMessages = getMinDebriefMessages;
465
843
 
844
+ /**
845
+ * Get the page size constant.
846
+ * @returns {number}
847
+ */
848
+ function getPageSize() {
849
+ const ret = wasm.getPageSize();
850
+ return ret >>> 0;
851
+ }
852
+ exports.getPageSize = getPageSize;
853
+
854
+ /**
855
+ * Get the GraphQL query string for blind index search.
856
+ * @returns {string}
857
+ */
858
+ function getSearchQuery() {
859
+ let deferred1_0;
860
+ let deferred1_1;
861
+ try {
862
+ const ret = wasm.getSearchQuery();
863
+ deferred1_0 = ret[0];
864
+ deferred1_1 = ret[1];
865
+ return getStringFromWasm0(ret[0], ret[1]);
866
+ } finally {
867
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
868
+ }
869
+ }
870
+ exports.getSearchQuery = getSearchQuery;
871
+
872
+ /**
873
+ * Get the SimpleAccountFactory address constant.
874
+ * @returns {string}
875
+ */
876
+ function getSimpleAccountFactory() {
877
+ let deferred1_0;
878
+ let deferred1_1;
879
+ try {
880
+ const ret = wasm.getSimpleAccountFactory();
881
+ deferred1_0 = ret[0];
882
+ deferred1_1 = ret[1];
883
+ return getStringFromWasm0(ret[0], ret[1]);
884
+ } finally {
885
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
886
+ }
887
+ }
888
+ exports.getSimpleAccountFactory = getSimpleAccountFactory;
889
+
890
+ /**
891
+ * WASM binding: get the store-time dedup cosine threshold constant.
892
+ * @returns {number}
893
+ */
894
+ function getStoreDedupCosineThreshold() {
895
+ const ret = wasm.getStoreDedupCosineThreshold();
896
+ return ret;
897
+ }
898
+ exports.getStoreDedupCosineThreshold = getStoreDedupCosineThreshold;
899
+
900
+ /**
901
+ * WASM binding: get the store-time dedup max candidates constant.
902
+ * @returns {number}
903
+ */
904
+ function getStoreDedupMaxCandidates() {
905
+ const ret = wasm.getStoreDedupMaxCandidates();
906
+ return ret >>> 0;
907
+ }
908
+ exports.getStoreDedupMaxCandidates = getStoreDedupMaxCandidates;
909
+
910
+ /**
911
+ * Get the trapdoor batch size constant.
912
+ * @returns {number}
913
+ */
914
+ function getTrapdoorBatchSize() {
915
+ const ret = wasm.getTrapdoorBatchSize();
916
+ return ret >>> 0;
917
+ }
918
+ exports.getTrapdoorBatchSize = getTrapdoorBatchSize;
919
+
920
+ /**
921
+ * Compute the ERC-4337 v0.7 UserOp hash for signing.
922
+ *
923
+ * `userop_json`: JSON string of a UserOperationV7 struct.
924
+ * `entrypoint`: EntryPoint address (0x-prefixed).
925
+ * `chain_id`: Chain ID (e.g. 84532 for Base Sepolia).
926
+ * Returns 32-byte hash as hex string.
927
+ * @param {string} userop_json
928
+ * @param {string} entrypoint
929
+ * @param {bigint} chain_id
930
+ * @returns {string}
931
+ */
932
+ function hashUserOp(userop_json, entrypoint, chain_id) {
933
+ let deferred4_0;
934
+ let deferred4_1;
935
+ try {
936
+ const ptr0 = passStringToWasm0(userop_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
937
+ const len0 = WASM_VECTOR_LEN;
938
+ const ptr1 = passStringToWasm0(entrypoint, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
939
+ const len1 = WASM_VECTOR_LEN;
940
+ const ret = wasm.hashUserOp(ptr0, len0, ptr1, len1, chain_id);
941
+ var ptr3 = ret[0];
942
+ var len3 = ret[1];
943
+ if (ret[3]) {
944
+ ptr3 = 0; len3 = 0;
945
+ throw takeFromExternrefTable0(ret[2]);
946
+ }
947
+ deferred4_0 = ptr3;
948
+ deferred4_1 = len3;
949
+ return getStringFromWasm0(ptr3, len3);
950
+ } finally {
951
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
952
+ }
953
+ }
954
+ exports.hashUserOp = hashUserOp;
955
+
956
+ /**
957
+ * Convert a subgraph hex blob to base64 for decryption.
958
+ *
959
+ * `hex_blob`: Hex string (optionally `0x`-prefixed) from the subgraph.
960
+ * Returns base64-encoded bytes, or null if the hex is invalid.
961
+ * @param {string} hex_blob
962
+ * @returns {string | undefined}
963
+ */
964
+ function hexBlobToBase64(hex_blob) {
965
+ const ptr0 = passStringToWasm0(hex_blob, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
966
+ const len0 = WASM_VECTOR_LEN;
967
+ const ret = wasm.hexBlobToBase64(ptr0, len0);
968
+ let v2;
969
+ if (ret[0] !== 0) {
970
+ v2 = getStringFromWasm0(ret[0], ret[1]).slice();
971
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
972
+ }
973
+ return v2;
974
+ }
975
+ exports.hexBlobToBase64 = hexBlobToBase64;
976
+
466
977
  /**
467
978
  * Normalize text (NFC, lowercase, collapse whitespace, trim).
468
979
  * @param {string} text
@@ -484,6 +995,25 @@ function normalizeText(text) {
484
995
  }
485
996
  exports.normalizeText = normalizeText;
486
997
 
998
+ /**
999
+ * Parse a broadened search GraphQL response into SubgraphFact list.
1000
+ *
1001
+ * `response_json`: Raw JSON string from the GraphQL response.
1002
+ * Returns a JsValue (JSON array of SubgraphFact objects).
1003
+ * @param {string} response_json
1004
+ * @returns {any}
1005
+ */
1006
+ function parseBroadenedResponse(response_json) {
1007
+ const ptr0 = passStringToWasm0(response_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1008
+ const len0 = WASM_VECTOR_LEN;
1009
+ const ret = wasm.parseBroadenedResponse(ptr0, len0);
1010
+ if (ret[2]) {
1011
+ throw takeFromExternrefTable0(ret[1]);
1012
+ }
1013
+ return takeFromExternrefTable0(ret[0]);
1014
+ }
1015
+ exports.parseBroadenedResponse = parseBroadenedResponse;
1016
+
487
1017
  /**
488
1018
  * Parse a debrief LLM response into validated items.
489
1019
  *
@@ -502,6 +1032,204 @@ function parseDebriefResponse(response) {
502
1032
  }
503
1033
  exports.parseDebriefResponse = parseDebriefResponse;
504
1034
 
1035
+ /**
1036
+ * Parse a blind index search GraphQL response into SubgraphFact list.
1037
+ *
1038
+ * `response_json`: Raw JSON string from the GraphQL response.
1039
+ * Returns a JsValue (JSON array of SubgraphFact objects).
1040
+ * @param {string} response_json
1041
+ * @returns {any}
1042
+ */
1043
+ function parseSearchResponse(response_json) {
1044
+ const ptr0 = passStringToWasm0(response_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1045
+ const len0 = WASM_VECTOR_LEN;
1046
+ const ret = wasm.parseSearchResponse(ptr0, len0);
1047
+ if (ret[2]) {
1048
+ throw takeFromExternrefTable0(ret[1]);
1049
+ }
1050
+ return takeFromExternrefTable0(ret[0]);
1051
+ }
1052
+ exports.parseSearchResponse = parseSearchResponse;
1053
+
1054
+ /**
1055
+ * Prepare a fact for on-chain storage.
1056
+ *
1057
+ * Pure computation: encrypt, generate indices, encode protobuf.
1058
+ * Does NOT submit -- the host handles I/O.
1059
+ *
1060
+ * `encryption_key_hex`: 64-char hex string (32 bytes).
1061
+ * `dedup_key_hex`: 64-char hex string (32 bytes).
1062
+ * `lsh_hasher`: A `WasmLshHasher` instance.
1063
+ * `embedding`: Float32Array of the pre-computed embedding vector.
1064
+ * `importance`: Importance score on 1-10 scale (normalized to 0.0-1.0).
1065
+ *
1066
+ * Returns a JSON string with `PreparedFact` fields.
1067
+ * @param {string} text
1068
+ * @param {string} encryption_key_hex
1069
+ * @param {string} dedup_key_hex
1070
+ * @param {WasmLshHasher} lsh_hasher
1071
+ * @param {Float32Array} embedding
1072
+ * @param {number} importance
1073
+ * @param {string} source
1074
+ * @param {string} owner
1075
+ * @param {string} agent_id
1076
+ * @returns {any}
1077
+ */
1078
+ function prepareFact(text, encryption_key_hex, dedup_key_hex, lsh_hasher, embedding, importance, source, owner, agent_id) {
1079
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1080
+ const len0 = WASM_VECTOR_LEN;
1081
+ const ptr1 = passStringToWasm0(encryption_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1082
+ const len1 = WASM_VECTOR_LEN;
1083
+ const ptr2 = passStringToWasm0(dedup_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1084
+ const len2 = WASM_VECTOR_LEN;
1085
+ _assertClass(lsh_hasher, WasmLshHasher);
1086
+ const ptr3 = passArrayF32ToWasm0(embedding, wasm.__wbindgen_malloc);
1087
+ const len3 = WASM_VECTOR_LEN;
1088
+ const ptr4 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1089
+ const len4 = WASM_VECTOR_LEN;
1090
+ const ptr5 = passStringToWasm0(owner, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1091
+ const len5 = WASM_VECTOR_LEN;
1092
+ const ptr6 = passStringToWasm0(agent_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1093
+ const len6 = WASM_VECTOR_LEN;
1094
+ const ret = wasm.prepareFact(ptr0, len0, ptr1, len1, ptr2, len2, lsh_hasher.__wbg_ptr, ptr3, len3, importance, ptr4, len4, ptr5, len5, ptr6, len6);
1095
+ if (ret[2]) {
1096
+ throw takeFromExternrefTable0(ret[1]);
1097
+ }
1098
+ return takeFromExternrefTable0(ret[0]);
1099
+ }
1100
+ exports.prepareFact = prepareFact;
1101
+
1102
+ /**
1103
+ * Prepare a fact with a pre-normalized decay score (already 0.0-1.0).
1104
+ *
1105
+ * Same as `prepareFact()` but takes a raw decay score.
1106
+ * @param {string} text
1107
+ * @param {string} encryption_key_hex
1108
+ * @param {string} dedup_key_hex
1109
+ * @param {WasmLshHasher} lsh_hasher
1110
+ * @param {Float32Array} embedding
1111
+ * @param {number} decay_score
1112
+ * @param {string} source
1113
+ * @param {string} owner
1114
+ * @param {string} agent_id
1115
+ * @returns {any}
1116
+ */
1117
+ function prepareFactWithDecayScore(text, encryption_key_hex, dedup_key_hex, lsh_hasher, embedding, decay_score, source, owner, agent_id) {
1118
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1119
+ const len0 = WASM_VECTOR_LEN;
1120
+ const ptr1 = passStringToWasm0(encryption_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1121
+ const len1 = WASM_VECTOR_LEN;
1122
+ const ptr2 = passStringToWasm0(dedup_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1123
+ const len2 = WASM_VECTOR_LEN;
1124
+ _assertClass(lsh_hasher, WasmLshHasher);
1125
+ const ptr3 = passArrayF32ToWasm0(embedding, wasm.__wbindgen_malloc);
1126
+ const len3 = WASM_VECTOR_LEN;
1127
+ const ptr4 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1128
+ const len4 = WASM_VECTOR_LEN;
1129
+ const ptr5 = passStringToWasm0(owner, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1130
+ const len5 = WASM_VECTOR_LEN;
1131
+ const ptr6 = passStringToWasm0(agent_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1132
+ const len6 = WASM_VECTOR_LEN;
1133
+ const ret = wasm.prepareFactWithDecayScore(ptr0, len0, ptr1, len1, ptr2, len2, lsh_hasher.__wbg_ptr, ptr3, len3, decay_score, ptr4, len4, ptr5, len5, ptr6, len6);
1134
+ if (ret[2]) {
1135
+ throw takeFromExternrefTable0(ret[1]);
1136
+ }
1137
+ return takeFromExternrefTable0(ret[0]);
1138
+ }
1139
+ exports.prepareFactWithDecayScore = prepareFactWithDecayScore;
1140
+
1141
+ /**
1142
+ * Prepare a tombstone (soft-delete) protobuf.
1143
+ *
1144
+ * Returns the protobuf bytes as a Uint8Array.
1145
+ * @param {string} fact_id
1146
+ * @param {string} owner
1147
+ * @returns {Uint8Array}
1148
+ */
1149
+ function prepareTombstone(fact_id, owner) {
1150
+ const ptr0 = passStringToWasm0(fact_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1151
+ const len0 = WASM_VECTOR_LEN;
1152
+ const ptr1 = passStringToWasm0(owner, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1153
+ const len1 = WASM_VECTOR_LEN;
1154
+ const ret = wasm.prepareTombstone(ptr0, len0, ptr1, len1);
1155
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
1156
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
1157
+ return v3;
1158
+ }
1159
+ exports.prepareTombstone = prepareTombstone;
1160
+
1161
+ /**
1162
+ * Rerank candidates using BM25 + Cosine + RRF fusion.
1163
+ *
1164
+ * `candidates_json`: JSON array of `{ id, text, embedding, timestamp }` objects.
1165
+ * Returns a JsValue (array of `RankedResult` objects).
1166
+ * @param {string} query
1167
+ * @param {Float32Array} query_embedding
1168
+ * @param {string} candidates_json
1169
+ * @param {number} top_k
1170
+ * @returns {any}
1171
+ */
1172
+ function rerank(query, query_embedding, candidates_json, top_k) {
1173
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1174
+ const len0 = WASM_VECTOR_LEN;
1175
+ const ptr1 = passArrayF32ToWasm0(query_embedding, wasm.__wbindgen_malloc);
1176
+ const len1 = WASM_VECTOR_LEN;
1177
+ const ptr2 = passStringToWasm0(candidates_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1178
+ const len2 = WASM_VECTOR_LEN;
1179
+ const ret = wasm.rerank(ptr0, len0, ptr1, len1, ptr2, len2, top_k);
1180
+ if (ret[2]) {
1181
+ throw takeFromExternrefTable0(ret[1]);
1182
+ }
1183
+ return takeFromExternrefTable0(ret[0]);
1184
+ }
1185
+ exports.rerank = rerank;
1186
+
1187
+ /**
1188
+ * WASM binding: determine if a new fact should supersede an existing one.
1189
+ * @param {number} new_importance
1190
+ * @param {number} existing_importance
1191
+ * @returns {boolean}
1192
+ */
1193
+ function shouldSupersede(new_importance, existing_importance) {
1194
+ const ret = wasm.shouldSupersede(new_importance, existing_importance);
1195
+ return ret !== 0;
1196
+ }
1197
+ exports.shouldSupersede = shouldSupersede;
1198
+
1199
+ /**
1200
+ * Sign a UserOp hash with an ECDSA private key (EIP-191 prefixed).
1201
+ *
1202
+ * `hash_hex`: 64-char hex string (32-byte UserOp hash).
1203
+ * `private_key_hex`: 64-char hex string (32-byte private key).
1204
+ * Returns 65-byte signature as hex string (r + s + v).
1205
+ * @param {string} hash_hex
1206
+ * @param {string} private_key_hex
1207
+ * @returns {string}
1208
+ */
1209
+ function signUserOp(hash_hex, private_key_hex) {
1210
+ let deferred4_0;
1211
+ let deferred4_1;
1212
+ try {
1213
+ const ptr0 = passStringToWasm0(hash_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1214
+ const len0 = WASM_VECTOR_LEN;
1215
+ const ptr1 = passStringToWasm0(private_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1216
+ const len1 = WASM_VECTOR_LEN;
1217
+ const ret = wasm.signUserOp(ptr0, len0, ptr1, len1);
1218
+ var ptr3 = ret[0];
1219
+ var len3 = ret[1];
1220
+ if (ret[3]) {
1221
+ ptr3 = 0; len3 = 0;
1222
+ throw takeFromExternrefTable0(ret[2]);
1223
+ }
1224
+ deferred4_0 = ptr3;
1225
+ deferred4_1 = len3;
1226
+ return getStringFromWasm0(ptr3, len3);
1227
+ } finally {
1228
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
1229
+ }
1230
+ }
1231
+ exports.signUserOp = signUserOp;
1232
+
505
1233
  function __wbg_get_imports() {
506
1234
  const import0 = {
507
1235
  __proto__: null,
@@ -547,6 +1275,9 @@ function __wbg_get_imports() {
547
1275
  __wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
548
1276
  arg0.getRandomValues(arg1);
549
1277
  }, arguments); },
1278
+ __wbg_getRandomValues_d49329ff89a07af1: function() { return handleError(function (arg0, arg1) {
1279
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
1280
+ }, arguments); },
550
1281
  __wbg_getTime_f6ac312467f7cf09: function(arg0) {
551
1282
  const ret = arg0.getTime();
552
1283
  return ret;
@@ -579,6 +1310,10 @@ function __wbg_get_imports() {
579
1310
  const ret = arg0.node;
580
1311
  return ret;
581
1312
  },
1313
+ __wbg_now_6798946be0e6fe2b: function() { return handleError(function () {
1314
+ const ret = Date.now();
1315
+ return ret;
1316
+ }, arguments); },
582
1317
  __wbg_process_44c7a14e11e9f69e: function(arg0) {
583
1318
  const ret = arg0.process;
584
1319
  return ret;
@@ -668,6 +1403,12 @@ function addToExternrefTable0(obj) {
668
1403
  return idx;
669
1404
  }
670
1405
 
1406
+ function _assertClass(instance, klass) {
1407
+ if (!(instance instanceof klass)) {
1408
+ throw new Error(`expected instance of ${klass.name}`);
1409
+ }
1410
+ }
1411
+
671
1412
  function getArrayU8FromWasm0(ptr, len) {
672
1413
  ptr = ptr >>> 0;
673
1414
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
@@ -681,6 +1422,14 @@ function getDataViewMemory0() {
681
1422
  return cachedDataViewMemory0;
682
1423
  }
683
1424
 
1425
+ let cachedFloat32ArrayMemory0 = null;
1426
+ function getFloat32ArrayMemory0() {
1427
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
1428
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
1429
+ }
1430
+ return cachedFloat32ArrayMemory0;
1431
+ }
1432
+
684
1433
  let cachedFloat64ArrayMemory0 = null;
685
1434
  function getFloat64ArrayMemory0() {
686
1435
  if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
@@ -715,6 +1464,20 @@ function isLikeNone(x) {
715
1464
  return x === undefined || x === null;
716
1465
  }
717
1466
 
1467
+ function passArray8ToWasm0(arg, malloc) {
1468
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
1469
+ getUint8ArrayMemory0().set(arg, ptr / 1);
1470
+ WASM_VECTOR_LEN = arg.length;
1471
+ return ptr;
1472
+ }
1473
+
1474
+ function passArrayF32ToWasm0(arg, malloc) {
1475
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
1476
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
1477
+ WASM_VECTOR_LEN = arg.length;
1478
+ return ptr;
1479
+ }
1480
+
718
1481
  function passArrayF64ToWasm0(arg, malloc) {
719
1482
  const ptr = malloc(arg.length * 8, 8) >>> 0;
720
1483
  getFloat64ArrayMemory0().set(arg, ptr / 8);
Binary file
@@ -1,35 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- export const memory: WebAssembly.Memory;
4
- export const deriveKeysFromMnemonic: (a: number, b: number) => [number, number, number];
5
- export const deriveKeysFromMnemonicLenient: (a: number, b: number) => [number, number, number];
6
- export const deriveLshSeed: (a: number, b: number, c: number, d: number) => [number, number, number, number];
7
- export const computeAuthKeyHash: (a: number, b: number) => [number, number, number, number];
8
- export const encrypt: (a: number, b: number, c: number, d: number) => [number, number, number, number];
9
- export const decrypt: (a: number, b: number, c: number, d: number) => [number, number, number, number];
10
- export const generateBlindIndices: (a: number, b: number) => [number, number, number];
11
- export const generateContentFingerprint: (a: number, b: number, c: number, d: number) => [number, number, number, number];
12
- export const normalizeText: (a: number, b: number) => [number, number];
13
- export const __wbg_wasmlshhasher_free: (a: number, b: number) => void;
14
- export const wasmlshhasher_new: (a: number, b: number, c: number) => [number, number, number];
15
- export const wasmlshhasher_withParams: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
16
- export const wasmlshhasher_hash: (a: number, b: number, c: number) => [number, number, number];
17
- export const wasmlshhasher_tables: (a: number) => number;
18
- export const wasmlshhasher_bits: (a: number) => number;
19
- export const wasmlshhasher_dimensions: (a: number) => number;
20
- export const encodeFactProtobuf: (a: number, b: number) => [number, number, number, number];
21
- export const encodeTombstoneProtobuf: (a: number, b: number, c: number, d: number) => [number, number];
22
- export const parseDebriefResponse: (a: number, b: number) => [number, number, number];
23
- export const getDebriefSystemPrompt: () => [number, number];
24
- export const buildDebriefPrompt: (a: number, b: number) => [number, number, number, number];
25
- export const getMinDebriefMessages: () => number;
26
- export const getMaxDebriefItems: () => number;
27
- export const getDebriefSource: () => [number, number];
28
- export const __wbindgen_malloc: (a: number, b: number) => number;
29
- export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
30
- export const __wbindgen_exn_store: (a: number) => void;
31
- export const __externref_table_alloc: () => number;
32
- export const __wbindgen_externrefs: WebAssembly.Table;
33
- export const __externref_table_dealloc: (a: number) => void;
34
- export const __wbindgen_free: (a: number, b: number, c: number) => void;
35
- export const __wbindgen_start: () => void;