@zensre/lenny-wasm 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # lenny-wasm
2
+
3
+ WebAssembly bindings for the [Lenny](https://github.com/ZenSRE/lenny) secret redaction engine.
4
+
5
+ Runs in Node.js, browsers, Deno, and any WASM-capable runtime. No native compilation needed. Scans and redacts known secrets using BLAKE3 + rolling hash. Includes 216 built-in pattern rules.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install lenny-wasm
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Exact-match redaction
16
+
17
+ ```js
18
+ import { Engine, PatternScanner } from 'lenny-wasm';
19
+
20
+ const engine = new Engine();
21
+ engine.loadSecrets([{ name: 'key', value: 'secret123' }]);
22
+
23
+ const result = engine.scan('the key is secret123');
24
+ console.log(result.output); // "the key is [REDACTED:key]"
25
+ console.log(result.hasRedactions); // true
26
+ ```
27
+
28
+ ### Pattern scanning
29
+
30
+ ```js
31
+ const scanner = new PatternScanner();
32
+ const matches = scanner.scan('AWS_KEY=AKIAIOSFODNN7EXAMPLE');
33
+ console.log(matches[0].ruleId); // "aws-access-key"
34
+ ```
35
+
36
+ ### Binary scanning
37
+
38
+ ```js
39
+ const redacted = engine.scanBytes(new Uint8Array([...]));
40
+ ```
41
+
42
+ ## API
43
+
44
+ ### `new Engine(opts?)`
45
+
46
+ Creates a scanning engine. Options: `{ patterns: boolean }` (default: true).
47
+
48
+ ### `engine.loadSecrets(secrets)`
49
+
50
+ Load secrets from an array of objects. Required: `name` (string), `value` (string).
51
+
52
+ Optional fields:
53
+ - `tier`: `"log"` (default), `"alert"`, or `"page"`
54
+ - `redaction`: `"tagged"` (default), `"full"`, or `"partial"`
55
+ - `prefix` / `suffix`: bytes for partial redaction (default: 4)
56
+ - `canary`: boolean (default: false)
57
+ - `transformations`: array of `"base64"` and/or `"url"`
58
+
59
+ ### `engine.scan(input) -> ScanResult`
60
+
61
+ Scan a string. Returns an object with:
62
+ - `output` (string) -- redacted output
63
+ - `hasRedactions`, `hasCanaryHit`, `hasExactMatchRedactions` (boolean)
64
+ - `eventCount` (number)
65
+ - `events` (array) -- `secretName`, `tier`, `isCanary`, `byteOffset`, `matchedLen`, `contextSnippet`, `source`
66
+
67
+ ### `engine.scanBytes(Uint8Array) -> Uint8Array`
68
+
69
+ Scan binary data. Returns redacted bytes only (no events).
70
+
71
+ ### `new PatternScanner()`
72
+
73
+ - `scan(input)` -- returns array of `{ ruleId, description, tier, start, end }`
74
+ - `ruleCount()` -- returns number of loaded rules
75
+
76
+ ## Native Alternative
77
+
78
+ For maximum performance, use [`@zensre/lenny-napi`](https://www.npmjs.com/package/@zensre/lenny-napi) (native addon, ~10x faster).
79
+
80
+ ## Full Documentation
81
+
82
+ See the [Lenny project](https://github.com/ZenSRE/lenny) for configuration, deployment, threat model, and the complete list of pattern rules.
83
+
84
+ ## License
85
+
86
+ MIT
@@ -0,0 +1,78 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class Engine {
5
+ free(): void;
6
+ [Symbol.dispose](): void;
7
+ /**
8
+ * Load secrets from a JSON string.
9
+ *
10
+ * Each element must have at minimum `name` (string) and `value` (string).
11
+ * Optional fields:
12
+ * - `tier`: `"log"` (default) | `"alert"` | `"page"`
13
+ * - `redaction`: `"full"` | `"tagged"` (default)
14
+ * - `canary`: boolean (default false)
15
+ * - `transformations`: array of `"base64"` | `"url"`
16
+ *
17
+ * Example:
18
+ * ```json
19
+ * [{"name":"MY_KEY","value":"s3cr3t","tier":"alert","redaction":"tagged","canary":false,"transformations":["base64"]}]
20
+ * ```
21
+ */
22
+ loadSecrets(secrets: any): void;
23
+ /**
24
+ * Create an Engine with built-in pattern scanning enabled by default.
25
+ * Pass a configuration object like `{ patterns: false }` to disable pattern scanning.
26
+ */
27
+ constructor(opts?: any | null);
28
+ /**
29
+ * Scan a string for secrets.
30
+ *
31
+ * Returns a native JavaScript object:
32
+ * ```
33
+ * {
34
+ * output: "...",
35
+ * hasRedactions: true,
36
+ * hasCanaryHit: false,
37
+ * hasExactMatchRedactions: true,
38
+ * eventCount: 1,
39
+ * events: [
40
+ * {
41
+ * secretName: "MY_KEY",
42
+ * tier: "alert",
43
+ * isCanary: false,
44
+ * byteOffset: 12,
45
+ * matchedLen: 6,
46
+ * contextSnippet: "...MY_KEY=[REDACTED]..."
47
+ * }
48
+ * ]
49
+ * }
50
+ * ```
51
+ */
52
+ scan(input: string): any;
53
+ /**
54
+ * Scan bytes (Uint8Array). Returns the redacted bytes.
55
+ */
56
+ scanBytes(input: Uint8Array): Uint8Array;
57
+ }
58
+
59
+ export class PatternScanner {
60
+ free(): void;
61
+ [Symbol.dispose](): void;
62
+ constructor();
63
+ /**
64
+ * Returns the number of loaded pattern rules.
65
+ */
66
+ ruleCount(): number;
67
+ /**
68
+ * Scan for pattern matches.
69
+ *
70
+ * Returns a native JavaScript array of objects:
71
+ * ```
72
+ * [{ ruleId: "aws-access-key", description: "AWS Access Key", tier: "alert", start: 0, end: 20 }]
73
+ * ```
74
+ */
75
+ scan(input: string): any;
76
+ }
77
+
78
+ export function init(): void;
package/lenny_wasm.js ADDED
@@ -0,0 +1,557 @@
1
+ /* @ts-self-types="./lenny_wasm.d.ts" */
2
+
3
+ class Engine {
4
+ __destroy_into_raw() {
5
+ const ptr = this.__wbg_ptr;
6
+ this.__wbg_ptr = 0;
7
+ EngineFinalization.unregister(this);
8
+ return ptr;
9
+ }
10
+ free() {
11
+ const ptr = this.__destroy_into_raw();
12
+ wasm.__wbg_engine_free(ptr, 0);
13
+ }
14
+ /**
15
+ * Load secrets from a JSON string.
16
+ *
17
+ * Each element must have at minimum `name` (string) and `value` (string).
18
+ * Optional fields:
19
+ * - `tier`: `"log"` (default) | `"alert"` | `"page"`
20
+ * - `redaction`: `"full"` | `"tagged"` (default)
21
+ * - `canary`: boolean (default false)
22
+ * - `transformations`: array of `"base64"` | `"url"`
23
+ *
24
+ * Example:
25
+ * ```json
26
+ * [{"name":"MY_KEY","value":"s3cr3t","tier":"alert","redaction":"tagged","canary":false,"transformations":["base64"]}]
27
+ * ```
28
+ * @param {any} secrets
29
+ */
30
+ loadSecrets(secrets) {
31
+ const ret = wasm.engine_loadSecrets(this.__wbg_ptr, secrets);
32
+ if (ret[1]) {
33
+ throw takeFromExternrefTable0(ret[0]);
34
+ }
35
+ }
36
+ /**
37
+ * Create an Engine with built-in pattern scanning enabled by default.
38
+ * Pass a configuration object like `{ patterns: false }` to disable pattern scanning.
39
+ * @param {any | null} [opts]
40
+ */
41
+ constructor(opts) {
42
+ const ret = wasm.engine_new(isLikeNone(opts) ? 0 : addToExternrefTable0(opts));
43
+ if (ret[2]) {
44
+ throw takeFromExternrefTable0(ret[1]);
45
+ }
46
+ this.__wbg_ptr = ret[0] >>> 0;
47
+ EngineFinalization.register(this, this.__wbg_ptr, this);
48
+ return this;
49
+ }
50
+ /**
51
+ * Scan a string for secrets.
52
+ *
53
+ * Returns a native JavaScript object:
54
+ * ```
55
+ * {
56
+ * output: "...",
57
+ * hasRedactions: true,
58
+ * hasCanaryHit: false,
59
+ * hasExactMatchRedactions: true,
60
+ * eventCount: 1,
61
+ * events: [
62
+ * {
63
+ * secretName: "MY_KEY",
64
+ * tier: "alert",
65
+ * isCanary: false,
66
+ * byteOffset: 12,
67
+ * matchedLen: 6,
68
+ * contextSnippet: "...MY_KEY=[REDACTED]..."
69
+ * }
70
+ * ]
71
+ * }
72
+ * ```
73
+ * @param {string} input
74
+ * @returns {any}
75
+ */
76
+ scan(input) {
77
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
78
+ const len0 = WASM_VECTOR_LEN;
79
+ const ret = wasm.engine_scan(this.__wbg_ptr, ptr0, len0);
80
+ if (ret[2]) {
81
+ throw takeFromExternrefTable0(ret[1]);
82
+ }
83
+ return takeFromExternrefTable0(ret[0]);
84
+ }
85
+ /**
86
+ * Scan bytes (Uint8Array). Returns the redacted bytes.
87
+ * @param {Uint8Array} input
88
+ * @returns {Uint8Array}
89
+ */
90
+ scanBytes(input) {
91
+ const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
92
+ const len0 = WASM_VECTOR_LEN;
93
+ const ret = wasm.engine_scanBytes(this.__wbg_ptr, ptr0, len0);
94
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
95
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
96
+ return v2;
97
+ }
98
+ }
99
+ if (Symbol.dispose) Engine.prototype[Symbol.dispose] = Engine.prototype.free;
100
+ exports.Engine = Engine;
101
+
102
+ class PatternScanner {
103
+ __destroy_into_raw() {
104
+ const ptr = this.__wbg_ptr;
105
+ this.__wbg_ptr = 0;
106
+ PatternScannerFinalization.unregister(this);
107
+ return ptr;
108
+ }
109
+ free() {
110
+ const ptr = this.__destroy_into_raw();
111
+ wasm.__wbg_patternscanner_free(ptr, 0);
112
+ }
113
+ constructor() {
114
+ const ret = wasm.patternscanner_new();
115
+ this.__wbg_ptr = ret >>> 0;
116
+ PatternScannerFinalization.register(this, this.__wbg_ptr, this);
117
+ return this;
118
+ }
119
+ /**
120
+ * Returns the number of loaded pattern rules.
121
+ * @returns {number}
122
+ */
123
+ ruleCount() {
124
+ const ret = wasm.patternscanner_ruleCount(this.__wbg_ptr);
125
+ return ret >>> 0;
126
+ }
127
+ /**
128
+ * Scan for pattern matches.
129
+ *
130
+ * Returns a native JavaScript array of objects:
131
+ * ```
132
+ * [{ ruleId: "aws-access-key", description: "AWS Access Key", tier: "alert", start: 0, end: 20 }]
133
+ * ```
134
+ * @param {string} input
135
+ * @returns {any}
136
+ */
137
+ scan(input) {
138
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
139
+ const len0 = WASM_VECTOR_LEN;
140
+ const ret = wasm.patternscanner_scan(this.__wbg_ptr, ptr0, len0);
141
+ if (ret[2]) {
142
+ throw takeFromExternrefTable0(ret[1]);
143
+ }
144
+ return takeFromExternrefTable0(ret[0]);
145
+ }
146
+ }
147
+ if (Symbol.dispose) PatternScanner.prototype[Symbol.dispose] = PatternScanner.prototype.free;
148
+ exports.PatternScanner = PatternScanner;
149
+
150
+ function init() {
151
+ wasm.init();
152
+ }
153
+ exports.init = init;
154
+
155
+ function __wbg_get_imports() {
156
+ const import0 = {
157
+ __proto__: null,
158
+ __wbg_Error_2e59b1b37a9a34c3: function(arg0, arg1) {
159
+ const ret = Error(getStringFromWasm0(arg0, arg1));
160
+ return ret;
161
+ },
162
+ __wbg_Number_e6ffdb596c888833: function(arg0) {
163
+ const ret = Number(arg0);
164
+ return ret;
165
+ },
166
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
167
+ const ret = String(arg1);
168
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
169
+ const len1 = WASM_VECTOR_LEN;
170
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
171
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
172
+ },
173
+ __wbg___wbindgen_bigint_get_as_i64_2c5082002e4826e2: function(arg0, arg1) {
174
+ const v = arg1;
175
+ const ret = typeof(v) === 'bigint' ? v : undefined;
176
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
177
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
178
+ },
179
+ __wbg___wbindgen_boolean_get_a86c216575a75c30: function(arg0) {
180
+ const v = arg0;
181
+ const ret = typeof(v) === 'boolean' ? v : undefined;
182
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
183
+ },
184
+ __wbg___wbindgen_debug_string_dd5d2d07ce9e6c57: function(arg0, arg1) {
185
+ const ret = debugString(arg1);
186
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
187
+ const len1 = WASM_VECTOR_LEN;
188
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
189
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
190
+ },
191
+ __wbg___wbindgen_in_4bd7a57e54337366: function(arg0, arg1) {
192
+ const ret = arg0 in arg1;
193
+ return ret;
194
+ },
195
+ __wbg___wbindgen_is_bigint_6c98f7e945dacdde: function(arg0) {
196
+ const ret = typeof(arg0) === 'bigint';
197
+ return ret;
198
+ },
199
+ __wbg___wbindgen_is_function_49868bde5eb1e745: function(arg0) {
200
+ const ret = typeof(arg0) === 'function';
201
+ return ret;
202
+ },
203
+ __wbg___wbindgen_is_null_344c8750a8525473: function(arg0) {
204
+ const ret = arg0 === null;
205
+ return ret;
206
+ },
207
+ __wbg___wbindgen_is_object_40c5a80572e8f9d3: function(arg0) {
208
+ const val = arg0;
209
+ const ret = typeof(val) === 'object' && val !== null;
210
+ return ret;
211
+ },
212
+ __wbg___wbindgen_is_undefined_c0cca72b82b86f4d: function(arg0) {
213
+ const ret = arg0 === undefined;
214
+ return ret;
215
+ },
216
+ __wbg___wbindgen_jsval_eq_7d430e744a913d26: function(arg0, arg1) {
217
+ const ret = arg0 === arg1;
218
+ return ret;
219
+ },
220
+ __wbg___wbindgen_jsval_loose_eq_3a72ae764d46d944: function(arg0, arg1) {
221
+ const ret = arg0 == arg1;
222
+ return ret;
223
+ },
224
+ __wbg___wbindgen_number_get_7579aab02a8a620c: function(arg0, arg1) {
225
+ const obj = arg1;
226
+ const ret = typeof(obj) === 'number' ? obj : undefined;
227
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
228
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
229
+ },
230
+ __wbg___wbindgen_string_get_914df97fcfa788f2: function(arg0, arg1) {
231
+ const obj = arg1;
232
+ const ret = typeof(obj) === 'string' ? obj : undefined;
233
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
234
+ var len1 = WASM_VECTOR_LEN;
235
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
236
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
237
+ },
238
+ __wbg___wbindgen_throw_81fc77679af83bc6: function(arg0, arg1) {
239
+ throw new Error(getStringFromWasm0(arg0, arg1));
240
+ },
241
+ __wbg_call_7f2987183bb62793: function() { return handleError(function (arg0, arg1) {
242
+ const ret = arg0.call(arg1);
243
+ return ret;
244
+ }, arguments); },
245
+ __wbg_done_547d467e97529006: function(arg0) {
246
+ const ret = arg0.done;
247
+ return ret;
248
+ },
249
+ __wbg_get_ed0642c4b9d31ddf: function() { return handleError(function (arg0, arg1) {
250
+ const ret = Reflect.get(arg0, arg1);
251
+ return ret;
252
+ }, arguments); },
253
+ __wbg_get_unchecked_7d7babe32e9e6a54: function(arg0, arg1) {
254
+ const ret = arg0[arg1 >>> 0];
255
+ return ret;
256
+ },
257
+ __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
258
+ const ret = arg0[arg1];
259
+ return ret;
260
+ },
261
+ __wbg_instanceof_ArrayBuffer_ff7c1337a5e3b33a: function(arg0) {
262
+ let result;
263
+ try {
264
+ result = arg0 instanceof ArrayBuffer;
265
+ } catch (_) {
266
+ result = false;
267
+ }
268
+ const ret = result;
269
+ return ret;
270
+ },
271
+ __wbg_instanceof_Uint8Array_4b8da683deb25d72: function(arg0) {
272
+ let result;
273
+ try {
274
+ result = arg0 instanceof Uint8Array;
275
+ } catch (_) {
276
+ result = false;
277
+ }
278
+ const ret = result;
279
+ return ret;
280
+ },
281
+ __wbg_isArray_db61795ad004c139: function(arg0) {
282
+ const ret = Array.isArray(arg0);
283
+ return ret;
284
+ },
285
+ __wbg_isSafeInteger_ea83862ba994770c: function(arg0) {
286
+ const ret = Number.isSafeInteger(arg0);
287
+ return ret;
288
+ },
289
+ __wbg_iterator_de403ef31815a3e6: function() {
290
+ const ret = Symbol.iterator;
291
+ return ret;
292
+ },
293
+ __wbg_length_0c32cb8543c8e4c8: function(arg0) {
294
+ const ret = arg0.length;
295
+ return ret;
296
+ },
297
+ __wbg_length_6e821edde497a532: function(arg0) {
298
+ const ret = arg0.length;
299
+ return ret;
300
+ },
301
+ __wbg_new_4f9fafbb3909af72: function() {
302
+ const ret = new Object();
303
+ return ret;
304
+ },
305
+ __wbg_new_a560378ea1240b14: function(arg0) {
306
+ const ret = new Uint8Array(arg0);
307
+ return ret;
308
+ },
309
+ __wbg_new_f3c9df4f38f3f798: function() {
310
+ const ret = new Array();
311
+ return ret;
312
+ },
313
+ __wbg_next_01132ed6134b8ef5: function(arg0) {
314
+ const ret = arg0.next;
315
+ return ret;
316
+ },
317
+ __wbg_next_b3713ec761a9dbfd: function() { return handleError(function (arg0) {
318
+ const ret = arg0.next();
319
+ return ret;
320
+ }, arguments); },
321
+ __wbg_prototypesetcall_3e05eb9545565046: function(arg0, arg1, arg2) {
322
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
323
+ },
324
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
325
+ arg0[arg1] = arg2;
326
+ },
327
+ __wbg_set_6c60b2e8ad0e9383: function(arg0, arg1, arg2) {
328
+ arg0[arg1 >>> 0] = arg2;
329
+ },
330
+ __wbg_value_7f6052747ccf940f: function(arg0) {
331
+ const ret = arg0.value;
332
+ return ret;
333
+ },
334
+ __wbindgen_cast_0000000000000001: function(arg0) {
335
+ // Cast intrinsic for `F64 -> Externref`.
336
+ const ret = arg0;
337
+ return ret;
338
+ },
339
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
340
+ // Cast intrinsic for `Ref(String) -> Externref`.
341
+ const ret = getStringFromWasm0(arg0, arg1);
342
+ return ret;
343
+ },
344
+ __wbindgen_cast_0000000000000003: function(arg0) {
345
+ // Cast intrinsic for `U64 -> Externref`.
346
+ const ret = BigInt.asUintN(64, arg0);
347
+ return ret;
348
+ },
349
+ __wbindgen_init_externref_table: function() {
350
+ const table = wasm.__wbindgen_externrefs;
351
+ const offset = table.grow(4);
352
+ table.set(0, undefined);
353
+ table.set(offset + 0, undefined);
354
+ table.set(offset + 1, null);
355
+ table.set(offset + 2, true);
356
+ table.set(offset + 3, false);
357
+ },
358
+ };
359
+ return {
360
+ __proto__: null,
361
+ "./lenny_wasm_bg.js": import0,
362
+ };
363
+ }
364
+
365
+ const EngineFinalization = (typeof FinalizationRegistry === 'undefined')
366
+ ? { register: () => {}, unregister: () => {} }
367
+ : new FinalizationRegistry(ptr => wasm.__wbg_engine_free(ptr >>> 0, 1));
368
+ const PatternScannerFinalization = (typeof FinalizationRegistry === 'undefined')
369
+ ? { register: () => {}, unregister: () => {} }
370
+ : new FinalizationRegistry(ptr => wasm.__wbg_patternscanner_free(ptr >>> 0, 1));
371
+
372
+ function addToExternrefTable0(obj) {
373
+ const idx = wasm.__externref_table_alloc();
374
+ wasm.__wbindgen_externrefs.set(idx, obj);
375
+ return idx;
376
+ }
377
+
378
+ function debugString(val) {
379
+ // primitive types
380
+ const type = typeof val;
381
+ if (type == 'number' || type == 'boolean' || val == null) {
382
+ return `${val}`;
383
+ }
384
+ if (type == 'string') {
385
+ return `"${val}"`;
386
+ }
387
+ if (type == 'symbol') {
388
+ const description = val.description;
389
+ if (description == null) {
390
+ return 'Symbol';
391
+ } else {
392
+ return `Symbol(${description})`;
393
+ }
394
+ }
395
+ if (type == 'function') {
396
+ const name = val.name;
397
+ if (typeof name == 'string' && name.length > 0) {
398
+ return `Function(${name})`;
399
+ } else {
400
+ return 'Function';
401
+ }
402
+ }
403
+ // objects
404
+ if (Array.isArray(val)) {
405
+ const length = val.length;
406
+ let debug = '[';
407
+ if (length > 0) {
408
+ debug += debugString(val[0]);
409
+ }
410
+ for(let i = 1; i < length; i++) {
411
+ debug += ', ' + debugString(val[i]);
412
+ }
413
+ debug += ']';
414
+ return debug;
415
+ }
416
+ // Test for built-in
417
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
418
+ let className;
419
+ if (builtInMatches && builtInMatches.length > 1) {
420
+ className = builtInMatches[1];
421
+ } else {
422
+ // Failed to match the standard '[object ClassName]'
423
+ return toString.call(val);
424
+ }
425
+ if (className == 'Object') {
426
+ // we're a user defined class or Object
427
+ // JSON.stringify avoids problems with cycles, and is generally much
428
+ // easier than looping through ownProperties of `val`.
429
+ try {
430
+ return 'Object(' + JSON.stringify(val) + ')';
431
+ } catch (_) {
432
+ return 'Object';
433
+ }
434
+ }
435
+ // errors
436
+ if (val instanceof Error) {
437
+ return `${val.name}: ${val.message}\n${val.stack}`;
438
+ }
439
+ // TODO we could test for more things here, like `Set`s and `Map`s.
440
+ return className;
441
+ }
442
+
443
+ function getArrayU8FromWasm0(ptr, len) {
444
+ ptr = ptr >>> 0;
445
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
446
+ }
447
+
448
+ let cachedDataViewMemory0 = null;
449
+ function getDataViewMemory0() {
450
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
451
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
452
+ }
453
+ return cachedDataViewMemory0;
454
+ }
455
+
456
+ function getStringFromWasm0(ptr, len) {
457
+ ptr = ptr >>> 0;
458
+ return decodeText(ptr, len);
459
+ }
460
+
461
+ let cachedUint8ArrayMemory0 = null;
462
+ function getUint8ArrayMemory0() {
463
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
464
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
465
+ }
466
+ return cachedUint8ArrayMemory0;
467
+ }
468
+
469
+ function handleError(f, args) {
470
+ try {
471
+ return f.apply(this, args);
472
+ } catch (e) {
473
+ const idx = addToExternrefTable0(e);
474
+ wasm.__wbindgen_exn_store(idx);
475
+ }
476
+ }
477
+
478
+ function isLikeNone(x) {
479
+ return x === undefined || x === null;
480
+ }
481
+
482
+ function passArray8ToWasm0(arg, malloc) {
483
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
484
+ getUint8ArrayMemory0().set(arg, ptr / 1);
485
+ WASM_VECTOR_LEN = arg.length;
486
+ return ptr;
487
+ }
488
+
489
+ function passStringToWasm0(arg, malloc, realloc) {
490
+ if (realloc === undefined) {
491
+ const buf = cachedTextEncoder.encode(arg);
492
+ const ptr = malloc(buf.length, 1) >>> 0;
493
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
494
+ WASM_VECTOR_LEN = buf.length;
495
+ return ptr;
496
+ }
497
+
498
+ let len = arg.length;
499
+ let ptr = malloc(len, 1) >>> 0;
500
+
501
+ const mem = getUint8ArrayMemory0();
502
+
503
+ let offset = 0;
504
+
505
+ for (; offset < len; offset++) {
506
+ const code = arg.charCodeAt(offset);
507
+ if (code > 0x7F) break;
508
+ mem[ptr + offset] = code;
509
+ }
510
+ if (offset !== len) {
511
+ if (offset !== 0) {
512
+ arg = arg.slice(offset);
513
+ }
514
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
515
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
516
+ const ret = cachedTextEncoder.encodeInto(arg, view);
517
+
518
+ offset += ret.written;
519
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
520
+ }
521
+
522
+ WASM_VECTOR_LEN = offset;
523
+ return ptr;
524
+ }
525
+
526
+ function takeFromExternrefTable0(idx) {
527
+ const value = wasm.__wbindgen_externrefs.get(idx);
528
+ wasm.__externref_table_dealloc(idx);
529
+ return value;
530
+ }
531
+
532
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
533
+ cachedTextDecoder.decode();
534
+ function decodeText(ptr, len) {
535
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
536
+ }
537
+
538
+ const cachedTextEncoder = new TextEncoder();
539
+
540
+ if (!('encodeInto' in cachedTextEncoder)) {
541
+ cachedTextEncoder.encodeInto = function (arg, view) {
542
+ const buf = cachedTextEncoder.encode(arg);
543
+ view.set(buf);
544
+ return {
545
+ read: arg.length,
546
+ written: buf.length
547
+ };
548
+ };
549
+ }
550
+
551
+ let WASM_VECTOR_LEN = 0;
552
+
553
+ const wasmPath = `${__dirname}/lenny_wasm_bg.wasm`;
554
+ const wasmBytes = require('fs').readFileSync(wasmPath);
555
+ const wasmModule = new WebAssembly.Module(wasmBytes);
556
+ let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
557
+ wasm.__wbindgen_start();
Binary file
package/package.json CHANGED
@@ -1 +1,24 @@
1
- {"name":"@zensre/lenny-wasm","version":"0.0.0","description":"WebAssembly bindings for Lenny secret redaction engine"}
1
+ {
2
+ "name": "@zensre/lenny-wasm",
3
+ "description": "WebAssembly bindings for Lenny secret redaction engine",
4
+ "version": "0.0.1",
5
+ "license": "MIT OR Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/ZenSRE/lenny"
9
+ },
10
+ "files": [
11
+ "lenny_wasm_bg.wasm",
12
+ "lenny_wasm.js",
13
+ "lenny_wasm.d.ts"
14
+ ],
15
+ "main": "lenny_wasm.js",
16
+ "types": "lenny_wasm.d.ts",
17
+ "keywords": [
18
+ "security",
19
+ "secrets",
20
+ "redaction",
21
+ "scanning",
22
+ "proxy"
23
+ ]
24
+ }