@pixagram/pixahash 0.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 ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@pixagram/pixahash",
3
+ "version": "0.1.0",
4
+ "description": "Fast WASM-optimized non-cryptographic hash (fingerprint) tuned for 5-30 kB payloads. Flexible output: uint32, uint64, 128-bit, up to a 256-bit digest as raw bytes, hex, or base58btc. Sync + auto-init async API plus an isomorphic worker pool for data-parallel hashing.",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "module": "./index.js",
8
+ "types": "./index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./index.d.ts",
12
+ "import": "./index.js"
13
+ },
14
+ "./pool": {
15
+ "types": "./index.d.ts",
16
+ "import": "./pool.js"
17
+ },
18
+ "./worker": "./worker.js",
19
+ "./load": "./load.js",
20
+ "./wasm": "./pkg/pixahash.js"
21
+ },
22
+ "files": [
23
+ "index.js",
24
+ "index.d.ts",
25
+ "load.js",
26
+ "worker.js",
27
+ "pool.js",
28
+ "pkg/pixahash.js",
29
+ "pkg/pixahash.d.ts",
30
+ "pkg/pixahash_bg.wasm",
31
+ "pkg/pixahash_bg.wasm.d.ts",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "sideEffects": false,
36
+ "engines": {
37
+ "node": ">=18"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "scripts": {
43
+ "build": "bash build.sh",
44
+ "test": "node test-node.mjs"
45
+ },
46
+ "keywords": [
47
+ "hash",
48
+ "hashing",
49
+ "non-cryptographic",
50
+ "fingerprint",
51
+ "checksum",
52
+ "wasm",
53
+ "webassembly",
54
+ "rust",
55
+ "xxhash",
56
+ "rapidhash",
57
+ "museair",
58
+ "base58",
59
+ "hex",
60
+ "worker",
61
+ "parallel",
62
+ "pixagram"
63
+ ],
64
+ "author": "Pixagram SA",
65
+ "license": "MIT",
66
+ "repository": {
67
+ "type": "git",
68
+ "url": "https://github.com/pixagram/pixahash"
69
+ }
70
+ }
@@ -0,0 +1,97 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Incremental hasher, exported to JS as a class.
6
+ */
7
+ export class Hasher {
8
+ free(): void;
9
+ [Symbol.dispose](): void;
10
+ digest32(): number;
11
+ digest64(): bigint;
12
+ digestBase58(bits: number): string;
13
+ digestHex(bits: number): string;
14
+ constructor(seed: bigint);
15
+ update(data: Uint8Array): void;
16
+ }
17
+
18
+ /**
19
+ * The full 32-byte digest.
20
+ */
21
+ export function digest(data: Uint8Array, seed: bigint): Uint8Array;
22
+
23
+ /**
24
+ * 128-bit hash as a 32-char hex string.
25
+ */
26
+ export function hash128Hex(data: Uint8Array, seed: bigint): string;
27
+
28
+ /**
29
+ * 32-bit hash as a JS number.
30
+ */
31
+ export function hash32(data: Uint8Array, seed: number): number;
32
+
33
+ /**
34
+ * 64-bit hash as a JS BigInt.
35
+ */
36
+ export function hash64(data: Uint8Array, seed: bigint): bigint;
37
+
38
+ /**
39
+ * 64-bit hash as a 16-char hex string.
40
+ */
41
+ export function hash64Hex(data: Uint8Array, seed: bigint): string;
42
+
43
+ /**
44
+ * base58btc string of the first `bits` bits of the digest (bits in 1..=256).
45
+ */
46
+ export function hashBase58(data: Uint8Array, seed: bigint, bits: number): string;
47
+
48
+ /**
49
+ * Hex string of the first `bits` bits of the digest (bits in 1..=256).
50
+ */
51
+ export function hashHex(data: Uint8Array, seed: bigint, bits: number): string;
52
+
53
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
54
+
55
+ export interface InitOutput {
56
+ readonly memory: WebAssembly.Memory;
57
+ readonly __wbg_hasher_free: (a: number, b: number) => void;
58
+ readonly digest: (a: number, b: number, c: bigint) => [number, number];
59
+ readonly hash128Hex: (a: number, b: number, c: bigint) => [number, number];
60
+ readonly hash32: (a: number, b: number, c: number) => number;
61
+ readonly hash64: (a: number, b: number, c: bigint) => bigint;
62
+ readonly hash64Hex: (a: number, b: number, c: bigint) => [number, number];
63
+ readonly hashBase58: (a: number, b: number, c: bigint, d: number) => [number, number];
64
+ readonly hashHex: (a: number, b: number, c: bigint, d: number) => [number, number];
65
+ readonly hasher_digest32: (a: number) => number;
66
+ readonly hasher_digest64: (a: number) => bigint;
67
+ readonly hasher_digestBase58: (a: number, b: number) => [number, number];
68
+ readonly hasher_digestHex: (a: number, b: number) => [number, number];
69
+ readonly hasher_new: (a: bigint) => number;
70
+ readonly hasher_update: (a: number, b: number, c: number) => void;
71
+ readonly __wbindgen_externrefs: WebAssembly.Table;
72
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
73
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
74
+ readonly __wbindgen_start: () => void;
75
+ }
76
+
77
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
78
+
79
+ /**
80
+ * Instantiates the given `module`, which can either be bytes or
81
+ * a precompiled `WebAssembly.Module`.
82
+ *
83
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
84
+ *
85
+ * @returns {InitOutput}
86
+ */
87
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
88
+
89
+ /**
90
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
91
+ * for everything else, calls `WebAssembly.instantiate` directly.
92
+ *
93
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
94
+ *
95
+ * @returns {Promise<InitOutput>}
96
+ */
97
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,366 @@
1
+ /* @ts-self-types="./pixahash.d.ts" */
2
+
3
+ /**
4
+ * Incremental hasher, exported to JS as a class.
5
+ */
6
+ export class Hasher {
7
+ __destroy_into_raw() {
8
+ const ptr = this.__wbg_ptr;
9
+ this.__wbg_ptr = 0;
10
+ HasherFinalization.unregister(this);
11
+ return ptr;
12
+ }
13
+ free() {
14
+ const ptr = this.__destroy_into_raw();
15
+ wasm.__wbg_hasher_free(ptr, 0);
16
+ }
17
+ /**
18
+ * @returns {number}
19
+ */
20
+ digest32() {
21
+ const ret = wasm.hasher_digest32(this.__wbg_ptr);
22
+ return ret >>> 0;
23
+ }
24
+ /**
25
+ * @returns {bigint}
26
+ */
27
+ digest64() {
28
+ const ret = wasm.hasher_digest64(this.__wbg_ptr);
29
+ return BigInt.asUintN(64, ret);
30
+ }
31
+ /**
32
+ * @param {number} bits
33
+ * @returns {string}
34
+ */
35
+ digestBase58(bits) {
36
+ let deferred1_0;
37
+ let deferred1_1;
38
+ try {
39
+ const ret = wasm.hasher_digestBase58(this.__wbg_ptr, bits);
40
+ deferred1_0 = ret[0];
41
+ deferred1_1 = ret[1];
42
+ return getStringFromWasm0(ret[0], ret[1]);
43
+ } finally {
44
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
45
+ }
46
+ }
47
+ /**
48
+ * @param {number} bits
49
+ * @returns {string}
50
+ */
51
+ digestHex(bits) {
52
+ let deferred1_0;
53
+ let deferred1_1;
54
+ try {
55
+ const ret = wasm.hasher_digestHex(this.__wbg_ptr, bits);
56
+ deferred1_0 = ret[0];
57
+ deferred1_1 = ret[1];
58
+ return getStringFromWasm0(ret[0], ret[1]);
59
+ } finally {
60
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
61
+ }
62
+ }
63
+ /**
64
+ * @param {bigint} seed
65
+ */
66
+ constructor(seed) {
67
+ const ret = wasm.hasher_new(seed);
68
+ this.__wbg_ptr = ret;
69
+ HasherFinalization.register(this, this.__wbg_ptr, this);
70
+ return this;
71
+ }
72
+ /**
73
+ * @param {Uint8Array} data
74
+ */
75
+ update(data) {
76
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
77
+ const len0 = WASM_VECTOR_LEN;
78
+ wasm.hasher_update(this.__wbg_ptr, ptr0, len0);
79
+ }
80
+ }
81
+ if (Symbol.dispose) Hasher.prototype[Symbol.dispose] = Hasher.prototype.free;
82
+
83
+ /**
84
+ * The full 32-byte digest.
85
+ * @param {Uint8Array} data
86
+ * @param {bigint} seed
87
+ * @returns {Uint8Array}
88
+ */
89
+ export function digest(data, seed) {
90
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
91
+ const len0 = WASM_VECTOR_LEN;
92
+ const ret = wasm.digest(ptr0, len0, seed);
93
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
94
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
95
+ return v2;
96
+ }
97
+
98
+ /**
99
+ * 128-bit hash as a 32-char hex string.
100
+ * @param {Uint8Array} data
101
+ * @param {bigint} seed
102
+ * @returns {string}
103
+ */
104
+ export function hash128Hex(data, seed) {
105
+ let deferred2_0;
106
+ let deferred2_1;
107
+ try {
108
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
109
+ const len0 = WASM_VECTOR_LEN;
110
+ const ret = wasm.hash128Hex(ptr0, len0, seed);
111
+ deferred2_0 = ret[0];
112
+ deferred2_1 = ret[1];
113
+ return getStringFromWasm0(ret[0], ret[1]);
114
+ } finally {
115
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
116
+ }
117
+ }
118
+
119
+ /**
120
+ * 32-bit hash as a JS number.
121
+ * @param {Uint8Array} data
122
+ * @param {number} seed
123
+ * @returns {number}
124
+ */
125
+ export function hash32(data, seed) {
126
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
127
+ const len0 = WASM_VECTOR_LEN;
128
+ const ret = wasm.hash32(ptr0, len0, seed);
129
+ return ret >>> 0;
130
+ }
131
+
132
+ /**
133
+ * 64-bit hash as a JS BigInt.
134
+ * @param {Uint8Array} data
135
+ * @param {bigint} seed
136
+ * @returns {bigint}
137
+ */
138
+ export function hash64(data, seed) {
139
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
140
+ const len0 = WASM_VECTOR_LEN;
141
+ const ret = wasm.hash64(ptr0, len0, seed);
142
+ return BigInt.asUintN(64, ret);
143
+ }
144
+
145
+ /**
146
+ * 64-bit hash as a 16-char hex string.
147
+ * @param {Uint8Array} data
148
+ * @param {bigint} seed
149
+ * @returns {string}
150
+ */
151
+ export function hash64Hex(data, seed) {
152
+ let deferred2_0;
153
+ let deferred2_1;
154
+ try {
155
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
156
+ const len0 = WASM_VECTOR_LEN;
157
+ const ret = wasm.hash64Hex(ptr0, len0, seed);
158
+ deferred2_0 = ret[0];
159
+ deferred2_1 = ret[1];
160
+ return getStringFromWasm0(ret[0], ret[1]);
161
+ } finally {
162
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
163
+ }
164
+ }
165
+
166
+ /**
167
+ * base58btc string of the first `bits` bits of the digest (bits in 1..=256).
168
+ * @param {Uint8Array} data
169
+ * @param {bigint} seed
170
+ * @param {number} bits
171
+ * @returns {string}
172
+ */
173
+ export function hashBase58(data, seed, bits) {
174
+ let deferred2_0;
175
+ let deferred2_1;
176
+ try {
177
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
178
+ const len0 = WASM_VECTOR_LEN;
179
+ const ret = wasm.hashBase58(ptr0, len0, seed, bits);
180
+ deferred2_0 = ret[0];
181
+ deferred2_1 = ret[1];
182
+ return getStringFromWasm0(ret[0], ret[1]);
183
+ } finally {
184
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Hex string of the first `bits` bits of the digest (bits in 1..=256).
190
+ * @param {Uint8Array} data
191
+ * @param {bigint} seed
192
+ * @param {number} bits
193
+ * @returns {string}
194
+ */
195
+ export function hashHex(data, seed, bits) {
196
+ let deferred2_0;
197
+ let deferred2_1;
198
+ try {
199
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
200
+ const len0 = WASM_VECTOR_LEN;
201
+ const ret = wasm.hashHex(ptr0, len0, seed, bits);
202
+ deferred2_0 = ret[0];
203
+ deferred2_1 = ret[1];
204
+ return getStringFromWasm0(ret[0], ret[1]);
205
+ } finally {
206
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
207
+ }
208
+ }
209
+ function __wbg_get_imports() {
210
+ const import0 = {
211
+ __proto__: null,
212
+ __wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
213
+ throw new Error(getStringFromWasm0(arg0, arg1));
214
+ },
215
+ __wbindgen_init_externref_table: function() {
216
+ const table = wasm.__wbindgen_externrefs;
217
+ const offset = table.grow(4);
218
+ table.set(0, undefined);
219
+ table.set(offset + 0, undefined);
220
+ table.set(offset + 1, null);
221
+ table.set(offset + 2, true);
222
+ table.set(offset + 3, false);
223
+ },
224
+ };
225
+ return {
226
+ __proto__: null,
227
+ "./pixahash_bg.js": import0,
228
+ };
229
+ }
230
+
231
+ const HasherFinalization = (typeof FinalizationRegistry === 'undefined')
232
+ ? { register: () => {}, unregister: () => {} }
233
+ : new FinalizationRegistry(ptr => wasm.__wbg_hasher_free(ptr, 1));
234
+
235
+ function getArrayU8FromWasm0(ptr, len) {
236
+ ptr = ptr >>> 0;
237
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
238
+ }
239
+
240
+ function getStringFromWasm0(ptr, len) {
241
+ return decodeText(ptr >>> 0, len);
242
+ }
243
+
244
+ let cachedUint8ArrayMemory0 = null;
245
+ function getUint8ArrayMemory0() {
246
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
247
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
248
+ }
249
+ return cachedUint8ArrayMemory0;
250
+ }
251
+
252
+ function passArray8ToWasm0(arg, malloc) {
253
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
254
+ getUint8ArrayMemory0().set(arg, ptr / 1);
255
+ WASM_VECTOR_LEN = arg.length;
256
+ return ptr;
257
+ }
258
+
259
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
260
+ cachedTextDecoder.decode();
261
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
262
+ let numBytesDecoded = 0;
263
+ function decodeText(ptr, len) {
264
+ numBytesDecoded += len;
265
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
266
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
267
+ cachedTextDecoder.decode();
268
+ numBytesDecoded = len;
269
+ }
270
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
271
+ }
272
+
273
+ let WASM_VECTOR_LEN = 0;
274
+
275
+ let wasmModule, wasmInstance, wasm;
276
+ function __wbg_finalize_init(instance, module) {
277
+ wasmInstance = instance;
278
+ wasm = instance.exports;
279
+ wasmModule = module;
280
+ cachedUint8ArrayMemory0 = null;
281
+ wasm.__wbindgen_start();
282
+ return wasm;
283
+ }
284
+
285
+ async function __wbg_load(module, imports) {
286
+ if (typeof Response === 'function' && module instanceof Response) {
287
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
288
+ try {
289
+ return await WebAssembly.instantiateStreaming(module, imports);
290
+ } catch (e) {
291
+ const validResponse = module.ok && expectedResponseType(module.type);
292
+
293
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
294
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
295
+
296
+ } else { throw e; }
297
+ }
298
+ }
299
+
300
+ const bytes = await module.arrayBuffer();
301
+ return await WebAssembly.instantiate(bytes, imports);
302
+ } else {
303
+ const instance = await WebAssembly.instantiate(module, imports);
304
+
305
+ if (instance instanceof WebAssembly.Instance) {
306
+ return { instance, module };
307
+ } else {
308
+ return instance;
309
+ }
310
+ }
311
+
312
+ function expectedResponseType(type) {
313
+ switch (type) {
314
+ case 'basic': case 'cors': case 'default': return true;
315
+ }
316
+ return false;
317
+ }
318
+ }
319
+
320
+ function initSync(module) {
321
+ if (wasm !== undefined) return wasm;
322
+
323
+
324
+ if (module !== undefined) {
325
+ if (Object.getPrototypeOf(module) === Object.prototype) {
326
+ ({module} = module)
327
+ } else {
328
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
329
+ }
330
+ }
331
+
332
+ const imports = __wbg_get_imports();
333
+ if (!(module instanceof WebAssembly.Module)) {
334
+ module = new WebAssembly.Module(module);
335
+ }
336
+ const instance = new WebAssembly.Instance(module, imports);
337
+ return __wbg_finalize_init(instance, module);
338
+ }
339
+
340
+ async function __wbg_init(module_or_path) {
341
+ if (wasm !== undefined) return wasm;
342
+
343
+
344
+ if (module_or_path !== undefined) {
345
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
346
+ ({module_or_path} = module_or_path)
347
+ } else {
348
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
349
+ }
350
+ }
351
+
352
+ if (module_or_path === undefined) {
353
+ module_or_path = new URL('pixahash_bg.wasm', import.meta.url);
354
+ }
355
+ const imports = __wbg_get_imports();
356
+
357
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
358
+ module_or_path = fetch(module_or_path);
359
+ }
360
+
361
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
362
+
363
+ return __wbg_finalize_init(instance, module);
364
+ }
365
+
366
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,21 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_hasher_free: (a: number, b: number) => void;
5
+ export const digest: (a: number, b: number, c: bigint) => [number, number];
6
+ export const hash128Hex: (a: number, b: number, c: bigint) => [number, number];
7
+ export const hash32: (a: number, b: number, c: number) => number;
8
+ export const hash64: (a: number, b: number, c: bigint) => bigint;
9
+ export const hash64Hex: (a: number, b: number, c: bigint) => [number, number];
10
+ export const hashBase58: (a: number, b: number, c: bigint, d: number) => [number, number];
11
+ export const hashHex: (a: number, b: number, c: bigint, d: number) => [number, number];
12
+ export const hasher_digest32: (a: number) => number;
13
+ export const hasher_digest64: (a: number) => bigint;
14
+ export const hasher_digestBase58: (a: number, b: number) => [number, number];
15
+ export const hasher_digestHex: (a: number, b: number) => [number, number];
16
+ export const hasher_new: (a: bigint) => number;
17
+ export const hasher_update: (a: number, b: number, c: number) => void;
18
+ export const __wbindgen_externrefs: WebAssembly.Table;
19
+ export const __wbindgen_malloc: (a: number, b: number) => number;
20
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
21
+ export const __wbindgen_start: () => void;