@totalreclaw/mcp-server 1.6.4 → 1.6.5

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.
@@ -1,27 +1,66 @@
1
1
  "use strict";
2
2
  /**
3
- * TotalReclaw MCP - Crypto Operations
3
+ * TotalReclaw MCP - Crypto Operations (WASM-backed)
4
4
  *
5
- * All cryptographic primitives used by the MCP server. These must
6
- * produce byte-for-byte identical output to the TotalReclaw client library
7
- * (`client/src/crypto/`) so that memories written by one can be read by
8
- * the other.
5
+ * Thin wrappers over `@totalreclaw/core` WASM module. Same function
6
+ * signatures as the previous pure-TS implementation so callers don't
7
+ * need to change.
9
8
  *
10
- * Key derivation chain:
11
- * master_password + salt
12
- * -> Argon2id(t=3, m=65536, p=4, dkLen=32) -> masterKey
13
- * -> HKDF-SHA256(masterKey, salt, "totalreclaw-auth-key-v1", 32) -> authKey
14
- * -> HKDF-SHA256(masterKey, salt, "totalreclaw-encryption-key-v1", 32) -> encryptionKey
15
- * -> HKDF-SHA256(masterKey, salt, "openmemory-dedup-v1", 32) -> dedupKey
9
+ * The WASM module handles BIP-39 key derivation, AES-256-GCM encrypt/
10
+ * decrypt, SHA-256 blind indices, HMAC-SHA256 content fingerprints,
11
+ * and LSH seed derivation.
16
12
  *
17
- * Encryption: AES-256-GCM (12-byte IV, 16-byte tag)
18
- * Blind indices: SHA-256 of lowercase tokens
19
- * Content fingerprint: HMAC-SHA256(dedupKey, normalizeText(plaintext))
13
+ * The legacy Argon2id path (arbitrary password, not a BIP-39 mnemonic)
14
+ * is kept in TypeScript because the WASM module only supports BIP-39.
15
+ *
16
+ * Key derivation chain (BIP-39 path — handled by WASM):
17
+ * mnemonic -> BIP-39 PBKDF2 -> 512-bit seed
18
+ * -> HKDF-SHA256(seed, salt, "totalreclaw-auth-key-v1", 32) -> authKey
19
+ * -> HKDF-SHA256(seed, salt, "totalreclaw-encryption-key-v1", 32) -> encryptionKey
20
+ * -> HKDF-SHA256(seed, salt, "openmemory-dedup-v1", 32) -> dedupKey
21
+ *
22
+ * Key derivation chain (Argon2id legacy path — kept in TS):
23
+ * password + salt -> Argon2id(t=3, m=65536, p=4, dkLen=32) -> masterKey
24
+ * -> HKDF-SHA256 per sub-key (same info strings as above)
20
25
  */
26
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
27
+ if (k2 === undefined) k2 = k;
28
+ var desc = Object.getOwnPropertyDescriptor(m, k);
29
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
30
+ desc = { enumerable: true, get: function() { return m[k]; } };
31
+ }
32
+ Object.defineProperty(o, k2, desc);
33
+ }) : (function(o, m, k, k2) {
34
+ if (k2 === undefined) k2 = k;
35
+ o[k2] = m[k];
36
+ }));
37
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
38
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
39
+ }) : function(o, v) {
40
+ o["default"] = v;
41
+ });
42
+ var __importStar = (this && this.__importStar) || (function () {
43
+ var ownKeys = function(o) {
44
+ ownKeys = Object.getOwnPropertyNames || function (o) {
45
+ var ar = [];
46
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
47
+ return ar;
48
+ };
49
+ return ownKeys(o);
50
+ };
51
+ return function (mod) {
52
+ if (mod && mod.__esModule) return mod;
53
+ var result = {};
54
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
55
+ __setModuleDefault(result, mod);
56
+ return result;
57
+ };
58
+ })();
21
59
  var __importDefault = (this && this.__importDefault) || function (mod) {
22
60
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
61
  };
24
62
  Object.defineProperty(exports, "__esModule", { value: true });
63
+ exports.validateMnemonic = void 0;
25
64
  exports.deriveKeysFromMnemonic = deriveKeysFromMnemonic;
26
65
  exports.deriveKeys = deriveKeys;
27
66
  exports.deriveLshSeed = deriveLshSeed;
@@ -33,29 +72,27 @@ exports.generateContentFingerprint = generateContentFingerprint;
33
72
  const argon2_js_1 = require("@noble/hashes/argon2.js");
34
73
  const hkdf_js_1 = require("@noble/hashes/hkdf.js");
35
74
  const sha2_js_1 = require("@noble/hashes/sha2.js");
36
- const hmac_js_1 = require("@noble/hashes/hmac.js");
37
75
  const bip39_1 = require("@scure/bip39");
76
+ Object.defineProperty(exports, "validateMnemonic", { enumerable: true, get: function () { return bip39_1.validateMnemonic; } });
38
77
  const english_js_1 = require("@scure/bip39/wordlists/english.js");
39
- const porter_stemmer_1 = require("porter-stemmer");
40
78
  const node_crypto_1 = __importDefault(require("node:crypto"));
79
+ const wasm = __importStar(require("@totalreclaw/core"));
41
80
  // ---------------------------------------------------------------------------
42
- // Key Derivation
81
+ // Constants (only needed for the Argon2id legacy path)
43
82
  // ---------------------------------------------------------------------------
44
- /** HKDF context strings -- must match client/src/crypto/kdf.ts exactly. */
45
83
  const AUTH_KEY_INFO = 'totalreclaw-auth-key-v1';
46
84
  const ENCRYPTION_KEY_INFO = 'totalreclaw-encryption-key-v1';
47
85
  const DEDUP_KEY_INFO = 'openmemory-dedup-v1';
48
- /** Argon2id parameters -- OWASP recommendations, matching client defaults. */
49
86
  const ARGON2_TIME_COST = 3;
50
- const ARGON2_MEMORY_COST = 65536; // 64 MB in KiB
87
+ const ARGON2_MEMORY_COST = 65536;
51
88
  const ARGON2_PARALLELISM = 4;
52
89
  const ARGON2_DK_LEN = 32;
53
- /** AES-256-GCM constants. */
54
- const IV_LENGTH = 12;
55
- const TAG_LENGTH = 16;
56
- const KEY_LENGTH = 32;
90
+ // ---------------------------------------------------------------------------
91
+ // Helpers
92
+ // ---------------------------------------------------------------------------
57
93
  /**
58
- * Check if the input looks like a BIP-39 mnemonic (12 or 24 words from the BIP-39 English wordlist).
94
+ * Check if the input looks like a BIP-39 mnemonic (12 or 24 words from
95
+ * the BIP-39 English wordlist).
59
96
  */
60
97
  function isBip39Mnemonic(input) {
61
98
  const words = input.trim().split(/\s+/);
@@ -63,52 +100,37 @@ function isBip39Mnemonic(input) {
63
100
  return false;
64
101
  return (0, bip39_1.validateMnemonic)(input.trim(), english_js_1.wordlist);
65
102
  }
103
+ // ---------------------------------------------------------------------------
104
+ // Key Derivation
105
+ // ---------------------------------------------------------------------------
66
106
  /**
67
107
  * Derive encryption keys from a BIP-39 mnemonic.
68
- * Uses the 512-bit BIP-39 seed as HKDF input (NOT the derived private key)
69
- * for proper key separation from the Ethereum signing key.
108
+ *
109
+ * Delegates to the WASM module which performs BIP-39 seed derivation
110
+ * and HKDF key separation.
70
111
  */
71
112
  function deriveKeysFromMnemonic(mnemonic) {
72
- // BIP-39: mnemonic -> 512-bit seed via PBKDF2(mnemonic, "mnemonic", 2048 rounds)
73
- const seed = (0, bip39_1.mnemonicToSeedSync)(mnemonic.trim());
74
- // Use first 32 bytes of seed as deterministic salt for HKDF
75
- // (BIP-39 mnemonics are self-salting via PBKDF2, no random salt needed)
76
- const salt = Buffer.from(seed.slice(0, 32));
77
- // HKDF-SHA256 from the full 512-bit seed, using distinct info strings
78
- const enc = (s) => Buffer.from(s, 'utf8');
79
- const seedBuf = Buffer.from(seed);
80
- const authKey = Buffer.from((0, hkdf_js_1.hkdf)(sha2_js_1.sha256, seedBuf, salt, enc(AUTH_KEY_INFO), 32));
81
- const encryptionKey = Buffer.from((0, hkdf_js_1.hkdf)(sha2_js_1.sha256, seedBuf, salt, enc(ENCRYPTION_KEY_INFO), 32));
82
- const dedupKey = Buffer.from((0, hkdf_js_1.hkdf)(sha2_js_1.sha256, seedBuf, salt, enc(DEDUP_KEY_INFO), 32));
83
- return { authKey, encryptionKey, dedupKey, salt };
113
+ const result = wasm.deriveKeysFromMnemonic(mnemonic.trim());
114
+ return {
115
+ authKey: Buffer.from(result.auth_key, 'hex'),
116
+ encryptionKey: Buffer.from(result.encryption_key, 'hex'),
117
+ dedupKey: Buffer.from(result.dedup_key, 'hex'),
118
+ salt: Buffer.from(result.salt, 'hex'),
119
+ };
84
120
  }
85
121
  /**
86
122
  * Derive auth, encryption, and dedup keys from a recovery phrase.
87
123
  *
88
124
  * If the password is a valid BIP-39 mnemonic (12 or 24 words), keys are
89
- * derived from the 512-bit BIP-39 seed via HKDF. Otherwise, the legacy
90
- * Argon2id path is used.
91
- *
92
- * For the Argon2id path: if no salt is provided a fresh 32-byte random salt
93
- * is generated. Pass an existing salt when restoring a previously-registered
94
- * account so that the derived keys match the original registration.
95
- *
96
- * @returns Object containing authKey, encryptionKey, dedupKey, and salt (all Buffers).
125
+ * derived via the WASM module. Otherwise, the legacy Argon2id path is used.
97
126
  */
98
127
  function deriveKeys(password, existingSalt) {
99
- // Auto-detect BIP-39 mnemonic vs arbitrary password
100
128
  if (isBip39Mnemonic(password)) {
101
- // BIP-39 path: mnemonic is self-salting, existingSalt is ignored for derivation
102
- // but we still return the deterministic salt for server registration
103
129
  return deriveKeysFromMnemonic(password);
104
130
  }
105
- // Legacy path: arbitrary password via Argon2id
131
+ // Legacy path: arbitrary password via Argon2id (not in WASM)
106
132
  const salt = existingSalt ?? node_crypto_1.default.randomBytes(32);
107
- // Step 1 -- Argon2id to derive a 32-byte master key.
108
- // @noble/hashes argon2id accepts Uint8Array for both password and salt.
109
133
  const masterKey = (0, argon2_js_1.argon2id)(Buffer.from(password, 'utf8'), salt, { t: ARGON2_TIME_COST, m: ARGON2_MEMORY_COST, p: ARGON2_PARALLELISM, dkLen: ARGON2_DK_LEN });
110
- // Step 2 -- HKDF-SHA256 for each sub-key using distinct info strings.
111
- // @noble/hashes v2 requires Uint8Array for info param.
112
134
  const enc = (s) => Buffer.from(s, 'utf8');
113
135
  const authKey = Buffer.from((0, hkdf_js_1.hkdf)(sha2_js_1.sha256, masterKey, salt, enc(AUTH_KEY_INFO), 32));
114
136
  const encryptionKey = Buffer.from((0, hkdf_js_1.hkdf)(sha2_js_1.sha256, masterKey, salt, enc(ENCRYPTION_KEY_INFO), 32));
@@ -119,32 +141,18 @@ function deriveKeys(password, existingSalt) {
119
141
  // LSH Seed Derivation
120
142
  // ---------------------------------------------------------------------------
121
143
  /**
122
- * HKDF context string for LSH seed derivation.
123
- *
124
- * The LSH hasher needs a deterministic seed so that the same master key
125
- * always generates the same random hyperplane matrices. We derive this seed
126
- * from the master key using HKDF with a unique info string.
144
+ * Derive a 32-byte seed for the LSH hasher.
127
145
  *
128
- * For the BIP-39 path the HKDF input is the 512-bit BIP-39 seed; for the
129
- * Argon2id path it is the 32-byte master key.
130
- */
131
- const LSH_SEED_INFO = 'openmemory-lsh-seed-v1';
132
- /**
133
- * Derive a 32-byte seed for the LSH hasher from the master key derivation
134
- * chain.
135
- *
136
- * Call this once during initialization and pass the result to `new LSHHasher(seed, dims)`.
137
- *
138
- * For the BIP-39 path we use the full 512-bit BIP-39 seed as IKM; for the
139
- * Argon2id path we use the 32-byte Argon2id-derived master key. In both
140
- * cases the salt from `deriveKeys()` is reused for domain separation.
146
+ * For the BIP-39 path, delegates to the WASM module. For the Argon2id
147
+ * legacy path, stays in TypeScript.
141
148
  */
142
149
  function deriveLshSeed(password, salt) {
143
150
  if (isBip39Mnemonic(password)) {
144
- const seed = (0, bip39_1.mnemonicToSeedSync)(password.trim());
145
- return new Uint8Array((0, hkdf_js_1.hkdf)(sha2_js_1.sha256, Buffer.from(seed), salt, Buffer.from(LSH_SEED_INFO, 'utf8'), 32));
151
+ const seedHex = wasm.deriveLshSeed(password.trim(), salt.toString('hex'));
152
+ return new Uint8Array(Buffer.from(seedHex, 'hex'));
146
153
  }
147
154
  // Argon2id path: re-derive the master key, then HKDF with LSH info string.
155
+ const LSH_SEED_INFO = 'openmemory-lsh-seed-v1';
148
156
  const masterKey = (0, argon2_js_1.argon2id)(Buffer.from(password, 'utf8'), salt, { t: ARGON2_TIME_COST, m: ARGON2_MEMORY_COST, p: ARGON2_PARALLELISM, dkLen: ARGON2_DK_LEN });
149
157
  return new Uint8Array((0, hkdf_js_1.hkdf)(sha2_js_1.sha256, masterKey, salt, Buffer.from(LSH_SEED_INFO, 'utf8'), 32));
150
158
  }
@@ -153,13 +161,9 @@ function deriveLshSeed(password, salt) {
153
161
  // ---------------------------------------------------------------------------
154
162
  /**
155
163
  * Compute the SHA-256 hash of the auth key.
156
- *
157
- * The server stores SHA256(authKey) during registration and uses it to look
158
- * up users on every request. The hex string returned here is what the plugin
159
- * sends to `/v1/register` as `auth_key_hash`.
160
164
  */
161
165
  function computeAuthKeyHash(authKey) {
162
- return Buffer.from((0, sha2_js_1.sha256)(authKey)).toString('hex');
166
+ return wasm.computeAuthKeyHash(authKey.toString('hex'));
163
167
  }
164
168
  // ---------------------------------------------------------------------------
165
169
  // AES-256-GCM Encrypt / Decrypt
@@ -169,45 +173,15 @@ function computeAuthKeyHash(authKey) {
169
173
  *
170
174
  * Wire format (base64-encoded):
171
175
  * [iv: 12 bytes][tag: 16 bytes][ciphertext: variable]
172
- *
173
- * This matches `serializeEncryptedData` in `client/src/crypto/aes.ts`.
174
176
  */
175
177
  function encrypt(plaintext, encryptionKey) {
176
- if (encryptionKey.length !== KEY_LENGTH) {
177
- throw new Error(`Invalid key length: expected ${KEY_LENGTH}, got ${encryptionKey.length}`);
178
- }
179
- const iv = node_crypto_1.default.randomBytes(IV_LENGTH);
180
- const cipher = node_crypto_1.default.createCipheriv('aes-256-gcm', encryptionKey, iv, {
181
- authTagLength: TAG_LENGTH,
182
- });
183
- const ciphertext = Buffer.concat([cipher.update(plaintext, 'utf8'), cipher.final()]);
184
- const tag = cipher.getAuthTag();
185
- // Combine: iv || tag || ciphertext (same order as client library)
186
- const combined = Buffer.concat([iv, tag, ciphertext]);
187
- return combined.toString('base64');
178
+ return wasm.encrypt(plaintext, encryptionKey.toString('hex'));
188
179
  }
189
180
  /**
190
181
  * Decrypt a base64-encoded AES-256-GCM blob back to a UTF-8 string.
191
- *
192
- * Expects the wire format produced by `encrypt()` above.
193
182
  */
194
183
  function decrypt(encryptedBase64, encryptionKey) {
195
- if (encryptionKey.length !== KEY_LENGTH) {
196
- throw new Error(`Invalid key length: expected ${KEY_LENGTH}, got ${encryptionKey.length}`);
197
- }
198
- const combined = Buffer.from(encryptedBase64, 'base64');
199
- if (combined.length < IV_LENGTH + TAG_LENGTH) {
200
- throw new Error('Encrypted data too short');
201
- }
202
- const iv = combined.subarray(0, IV_LENGTH);
203
- const tag = combined.subarray(IV_LENGTH, IV_LENGTH + TAG_LENGTH);
204
- const ciphertext = combined.subarray(IV_LENGTH + TAG_LENGTH);
205
- const decipher = node_crypto_1.default.createDecipheriv('aes-256-gcm', encryptionKey, iv, {
206
- authTagLength: TAG_LENGTH,
207
- });
208
- decipher.setAuthTag(tag);
209
- const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
210
- return plaintext.toString('utf8');
184
+ return wasm.decrypt(encryptedBase64, encryptionKey.toString('hex'));
211
185
  }
212
186
  // ---------------------------------------------------------------------------
213
187
  // Blind Indices
@@ -215,73 +189,21 @@ function decrypt(encryptedBase64, encryptionKey) {
215
189
  /**
216
190
  * Generate blind indices (SHA-256 hashes of tokens) for a text string.
217
191
  *
218
- * Tokenization rules (must match `client/src/crypto/blind.ts#tokenize`):
219
- * 1. Lowercase
220
- * 2. Remove punctuation (keep Unicode letters, numbers, whitespace)
221
- * 3. Split on whitespace
222
- * 4. Filter tokens shorter than 2 characters
223
- *
224
- * Each surviving token is SHA-256 hashed and returned as a hex string.
225
- * The returned array is deduplicated.
192
+ * Delegates to the WASM module which performs tokenization, stemming,
193
+ * and SHA-256 hashing.
226
194
  */
227
195
  function generateBlindIndices(text) {
228
- const tokens = text
229
- .toLowerCase()
230
- .replace(/[^\p{L}\p{N}\s]/gu, ' ') // Remove punctuation, keep letters/numbers
231
- .split(/\s+/)
232
- .filter((t) => t.length >= 2);
233
- const seen = new Set();
234
- const indices = [];
235
- for (const token of tokens) {
236
- // Exact word hash (unchanged behavior).
237
- const hash = Buffer.from((0, sha2_js_1.sha256)(Buffer.from(token, 'utf8'))).toString('hex');
238
- if (!seen.has(hash)) {
239
- seen.add(hash);
240
- indices.push(hash);
241
- }
242
- // Stemmed word hash. The stem is prefixed with "stem:" before hashing
243
- // to avoid collisions between a word that happens to equal another
244
- // word's stem (e.g., the word "commun" vs the stem of "community").
245
- const stem = (0, porter_stemmer_1.stemmer)(token);
246
- if (stem.length >= 2 && stem !== token) {
247
- const stemHash = Buffer.from((0, sha2_js_1.sha256)(Buffer.from(`stem:${stem}`, 'utf8'))).toString('hex');
248
- if (!seen.has(stemHash)) {
249
- seen.add(stemHash);
250
- indices.push(stemHash);
251
- }
252
- }
253
- }
254
- return indices;
196
+ return wasm.generateBlindIndices(text);
255
197
  }
256
198
  // ---------------------------------------------------------------------------
257
199
  // Content Fingerprint (Dedup)
258
200
  // ---------------------------------------------------------------------------
259
- /**
260
- * Normalize text for deterministic fingerprinting.
261
- *
262
- * Steps (matching `client/src/crypto/fingerprint.ts#normalizeText`):
263
- * 1. Unicode NFC normalization
264
- * 2. Lowercase
265
- * 3. Collapse whitespace (spaces/tabs/newlines to single space)
266
- * 4. Trim leading/trailing whitespace
267
- */
268
- function normalizeText(text) {
269
- return text
270
- .normalize('NFC')
271
- .toLowerCase()
272
- .replace(/\s+/g, ' ')
273
- .trim();
274
- }
275
201
  /**
276
202
  * Compute an HMAC-SHA256 content fingerprint for exact-duplicate detection.
277
203
  *
278
- * The server stores this fingerprint and uses it to reject duplicate writes
279
- * without ever seeing the plaintext.
280
- *
281
204
  * @returns 64-character hex string.
282
205
  */
283
206
  function generateContentFingerprint(plaintext, dedupKey) {
284
- const normalized = normalizeText(plaintext);
285
- return Buffer.from((0, hmac_js_1.hmac)(sha2_js_1.sha256, dedupKey, Buffer.from(normalized, 'utf8'))).toString('hex');
207
+ return wasm.generateContentFingerprint(plaintext, dedupKey.toString('hex'));
286
208
  }
287
209
  //# sourceMappingURL=crypto.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/subgraph/crypto.ts"],"names":[],"mappings":";AAAA;;;;;;;;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AO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,8EAA8E;AAC9E,gCAAgC;AAChC,8EAA8E;AAE9E;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,SAAiB,EAAE,aAAqB;IAC9D,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAChE,CAAC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAC,eAAuB,EAAE,aAAqB;IACpE,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAE9E;;;;;GAKG;AACH,SAAgB,oBAAoB,CAAC,IAAY;IAC/C,OAAO,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC;AAED,8EAA8E;AAC9E,8BAA8B;AAC9B,8EAA8E;AAE9E;;;;GAIG;AACH,SAAgB,0BAA0B,CAAC,SAAiB,EAAE,QAAgB;IAC5E,OAAO,IAAI,CAAC,0BAA0B,CAAC,SAAS,EAAE,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9E,CAAC"}
@@ -1,27 +1,13 @@
1
1
  /**
2
- * TotalReclaw MCP - LSH Hasher (Locality-Sensitive Hashing)
2
+ * TotalReclaw MCP - LSH Hasher (WASM-backed)
3
3
  *
4
- * Pure TypeScript implementation of Random Hyperplane LSH for server-blind
5
- * semantic search. Generates deterministic hyperplane matrices from a seed
6
- * derived from the user's master key, so the same embedding always hashes to
7
- * the same buckets across sessions.
8
- *
9
- * Architecture overview:
10
- * 1. Seed (32 bytes from HKDF) -> HKDF per table -> random bytes
11
- * 2. Random bytes -> Box-Muller transform -> Gaussian-distributed hyperplanes
12
- * 3. Embedding dot hyperplane -> sign bit -> N-bit signature per table
13
- * 4. Signature -> `lsh_t{table}_{signature}` -> SHA-256 -> blind hash
14
- *
15
- * The blind hashes are merged with the existing blind word indices in the
16
- * `blind_indices` array. The server never knows which hashes are word-based
17
- * and which are LSH-based.
4
+ * Thin wrapper over `WasmLshHasher` from `@totalreclaw/core`. Same class
5
+ * interface as the previous pure-TS implementation so callers don't need
6
+ * to change.
18
7
  *
19
8
  * Default parameters:
20
- * - 32 bits per table (balanced discrimination vs. recall)
21
- * - 20 tables (moderate table count for good coverage)
22
- * - Middle ground between 64-bit x 12 (too strict) and 12-bit x 28 (too loose)
23
- *
24
- * Dependencies: @noble/hashes only (already in project).
9
+ * - 32 bits per table
10
+ * - 20 tables
25
11
  */
26
12
  /**
27
13
  * Random Hyperplane LSH hasher.
@@ -30,57 +16,19 @@
30
16
  * Construct once per session; call `hash()` for every store/search operation.
31
17
  */
32
18
  export declare class LSHHasher {
33
- /**
34
- * Flat hyperplane storage.
35
- *
36
- * `hyperplanes[t]` is a Float64Array of length `dims * nBits` containing the
37
- * hyperplane matrix for table `t`. The hyperplane for bit `b` starts at
38
- * offset `b * dims`.
39
- */
40
- private hyperplanes;
41
- /** Embedding dimensionality. */
42
- private readonly dims;
43
- /** Number of independent hash tables. */
44
- private readonly nTables;
45
- /** Number of bits (hyperplanes) per table. */
46
- private readonly nBits;
19
+ private inner;
47
20
  /**
48
21
  * Create a new LSH hasher.
49
22
  *
50
- * @param seed - 32-byte seed from `deriveLshSeed()` in crypto.ts.
51
- * @param dims - Embedding dimensionality (e.g. 1536 for text-embedding-3-small).
23
+ * @param seed - 32-byte seed from `deriveLshSeed()` in crypto.ts.
24
+ * @param dims - Embedding dimensionality (e.g. 1024 for Qwen3).
52
25
  * @param nTables - Number of independent hash tables (default 20).
53
26
  * @param nBits - Number of bits per table (default 32).
54
27
  */
55
28
  constructor(seed: Uint8Array, dims: number, nTables?: number, nBits?: number);
56
- /**
57
- * Generate the hyperplane matrix for a single table.
58
- *
59
- * Each table gets a unique HKDF-derived byte stream. We consume 8 bytes
60
- * per Gaussian sample (Box-Muller uses two uniform uint32 values).
61
- *
62
- * The hyperplanes are NOT normalised to unit length. Normalisation is
63
- * unnecessary because we only care about the sign of the dot product,
64
- * which is scale-invariant.
65
- */
66
- private generateTableHyperplanes;
67
- /**
68
- * Derive `length` pseudo-random bytes from the seed using HKDF with
69
- * chunked sub-blocks.
70
- *
71
- * A single HKDF-SHA256 call can output at most 255 * 32 = 8,160 bytes.
72
- * For large embedding dimensions we need more, so we iterate over
73
- * sub-block indices as part of the info string.
74
- */
75
- private deriveRandomBytes;
76
29
  /**
77
30
  * Hash an embedding vector to an array of blind-hashed bucket IDs.
78
31
  *
79
- * For each table:
80
- * 1. Compute the 64-bit signature (sign of dot product with each hyperplane).
81
- * 2. Build the bucket string: `lsh_t{tableIndex}_{binarySignature}`.
82
- * 3. SHA-256 the bucket string to produce a blind hash (hex).
83
- *
84
32
  * @param embedding - The embedding vector (must have `dims` elements).
85
33
  * @returns Array of `nTables` hex strings (one blind hash per table).
86
34
  */
@@ -1 +1 @@
1
- {"version":3,"file":"lsh.d.ts","sourceRoot":"","sources":["../../src/subgraph/lsh.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAsBH;;;;;GAKG;AACH,qBAAa,SAAS;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,WAAW,CAAiB;IAEpC,gCAAgC;IAChC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAE9B,yCAAyC;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,8CAA8C;IAC9C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAE/B;;;;;;;OAOG;gBAED,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAyB,EAClC,KAAK,GAAE,MAAuB;IA8BhC;;;;;;;;;OASG;IACH,OAAO,CAAC,wBAAwB;IAmChC;;;;;;;OAOG;IACH,OAAO,CAAC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