@iscc/wasm 0.0.3 → 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/README.md CHANGED
@@ -4,9 +4,6 @@
4
4
  [![npm](https://img.shields.io/npm/v/@iscc/wasm.svg)](https://www.npmjs.com/package/@iscc/wasm)
5
5
  [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
6
 
7
- > **Experimental:** This library is in early development (v0.0.x). APIs may change without notice.
8
- > Not recommended for production use yet.
9
-
10
7
  Browser-compatible WebAssembly bindings for
11
8
  [ISO 24138:2024](https://www.iso.org/standard/77899.html) -- International Standard Content Code
12
9
  (ISCC). Built with Rust and [wasm-bindgen](https://rustwasm.github.io/wasm-bindgen/) for use in
@@ -54,6 +51,7 @@ Both browser and Node.js targets are supported.
54
51
  | `gen_data_code_v0` | Generate a Data-Code from raw bytes |
55
52
  | `gen_instance_code_v0` | Generate an Instance-Code from raw bytes |
56
53
  | `gen_iscc_code_v0` | Generate a composite ISCC-CODE |
54
+ | `gen_sum_code_v0` | Generate an ISCC-SUM from raw bytes |
57
55
 
58
56
  All code generators return ISCC strings directly.
59
57
 
package/iscc_wasm.d.ts CHANGED
@@ -94,6 +94,11 @@ export class IsccDecodeResult {
94
94
  */
95
95
  export function META_TRIM_DESCRIPTION(): number;
96
96
 
97
+ /**
98
+ * Maximum byte length for the meta field payload after decoding.
99
+ */
100
+ export function META_TRIM_META(): number;
101
+
97
102
  /**
98
103
  * Maximum byte length for the name field after trimming.
99
104
  */
@@ -104,6 +109,35 @@ export function META_TRIM_NAME(): number;
104
109
  */
105
110
  export function TEXT_NGRAM_SIZE(): number;
106
111
 
112
+ /**
113
+ * Result of [`gen_sum_code_v0`], containing the composite ISCC-CODE, data hash, and file size.
114
+ */
115
+ export class WasmSumCodeResult {
116
+ private constructor();
117
+ free(): void;
118
+ [Symbol.dispose](): void;
119
+ /**
120
+ * Hex-encoded BLAKE3 multihash (`"1e20..."`) of the data.
121
+ */
122
+ datahash: string;
123
+ /**
124
+ * Byte length of the input data (as `f64` for JS `number` compatibility).
125
+ */
126
+ filesize: number;
127
+ /**
128
+ * Composite ISCC-CODE string (e.g., `"ISCC:KAC..."`).
129
+ */
130
+ iscc: string;
131
+ /**
132
+ * Data-Code and Instance-Code ISCC strings (when `add_units` is true).
133
+ */
134
+ get units(): string[] | undefined;
135
+ /**
136
+ * Data-Code and Instance-Code ISCC strings (when `add_units` is true).
137
+ */
138
+ set units(value: string[] | null | undefined);
139
+ }
140
+
107
141
  /**
108
142
  * Split data into content-defined chunks using gear rolling hash.
109
143
  *
@@ -201,6 +235,18 @@ export function gen_meta_code_v0(name: string, description?: string | null, meta
201
235
  */
202
236
  export function gen_mixed_code_v0(codes: any, bits?: number | null): string;
203
237
 
238
+ /**
239
+ * Generate a composite ISCC-CODE from raw byte data in a single pass.
240
+ *
241
+ * Feeds both `DataHasher` (CDC/MinHash) and `InstanceHasher` (BLAKE3) from
242
+ * the same byte slice, then composes the final ISCC-CODE via
243
+ * `gen_iscc_code_v0`. WASM-compatible alternative to the file-based core API.
244
+ *
245
+ * When `add_units` is `true`, the result includes the individual Data-Code
246
+ * and Instance-Code ISCC strings.
247
+ */
248
+ export function gen_sum_code_v0(data: Uint8Array, bits?: number | null, wide?: boolean | null, add_units?: boolean | null): WasmSumCodeResult;
249
+
204
250
  /**
205
251
  * Generate a Text-Code from plain text content.
206
252
  *
@@ -297,6 +343,7 @@ export interface InitOutput {
297
343
  readonly memory: WebAssembly.Memory;
298
344
  readonly IO_READ_SIZE: () => number;
299
345
  readonly META_TRIM_DESCRIPTION: () => number;
346
+ readonly META_TRIM_META: () => number;
300
347
  readonly META_TRIM_NAME: () => number;
301
348
  readonly TEXT_NGRAM_SIZE: () => number;
302
349
  readonly __wbg_datahasher_free: (a: number, b: number) => void;
@@ -305,6 +352,10 @@ export interface InitOutput {
305
352
  readonly __wbg_get_isccdecoderesult_maintype: (a: number) => number;
306
353
  readonly __wbg_get_isccdecoderesult_subtype: (a: number) => number;
307
354
  readonly __wbg_get_isccdecoderesult_version: (a: number) => number;
355
+ readonly __wbg_get_wasmsumcoderesult_datahash: (a: number, b: number) => void;
356
+ readonly __wbg_get_wasmsumcoderesult_filesize: (a: number) => number;
357
+ readonly __wbg_get_wasmsumcoderesult_iscc: (a: number, b: number) => void;
358
+ readonly __wbg_get_wasmsumcoderesult_units: (a: number, b: number) => void;
308
359
  readonly __wbg_instancehasher_free: (a: number, b: number) => void;
309
360
  readonly __wbg_isccdecoderesult_free: (a: number, b: number) => void;
310
361
  readonly __wbg_set_isccdecoderesult_digest: (a: number, b: number, c: number) => void;
@@ -312,6 +363,11 @@ export interface InitOutput {
312
363
  readonly __wbg_set_isccdecoderesult_maintype: (a: number, b: number) => void;
313
364
  readonly __wbg_set_isccdecoderesult_subtype: (a: number, b: number) => void;
314
365
  readonly __wbg_set_isccdecoderesult_version: (a: number, b: number) => void;
366
+ readonly __wbg_set_wasmsumcoderesult_datahash: (a: number, b: number, c: number) => void;
367
+ readonly __wbg_set_wasmsumcoderesult_filesize: (a: number, b: number) => void;
368
+ readonly __wbg_set_wasmsumcoderesult_iscc: (a: number, b: number, c: number) => void;
369
+ readonly __wbg_set_wasmsumcoderesult_units: (a: number, b: number, c: number) => void;
370
+ readonly __wbg_wasmsumcoderesult_free: (a: number, b: number) => void;
315
371
  readonly alg_cdc_chunks: (a: number, b: number, c: number, d: number, e: number) => void;
316
372
  readonly alg_minhash_256: (a: number, b: number, c: number) => void;
317
373
  readonly alg_simhash: (a: number, b: number) => void;
@@ -327,6 +383,7 @@ export interface InitOutput {
327
383
  readonly gen_iscc_code_v0: (a: number, b: number, c: number) => void;
328
384
  readonly gen_meta_code_v0: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
329
385
  readonly gen_mixed_code_v0: (a: number, b: number, c: number) => void;
386
+ readonly gen_sum_code_v0: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
330
387
  readonly gen_text_code_v0: (a: number, b: number, c: number, d: number) => void;
331
388
  readonly gen_video_code_v0: (a: number, b: number, c: number) => void;
332
389
  readonly instancehasher_finalize: (a: number, b: number, c: number) => void;
package/iscc_wasm.js CHANGED
@@ -290,6 +290,15 @@ export function META_TRIM_DESCRIPTION() {
290
290
  return ret >>> 0;
291
291
  }
292
292
 
293
+ /**
294
+ * Maximum byte length for the meta field payload after decoding.
295
+ * @returns {number}
296
+ */
297
+ export function META_TRIM_META() {
298
+ const ret = wasm.META_TRIM_META();
299
+ return ret >>> 0;
300
+ }
301
+
293
302
  /**
294
303
  * Maximum byte length for the name field after trimming.
295
304
  * @returns {number}
@@ -308,6 +317,132 @@ export function TEXT_NGRAM_SIZE() {
308
317
  return ret >>> 0;
309
318
  }
310
319
 
320
+ /**
321
+ * Result of [`gen_sum_code_v0`], containing the composite ISCC-CODE, data hash, and file size.
322
+ */
323
+ export class WasmSumCodeResult {
324
+ static __wrap(ptr) {
325
+ ptr = ptr >>> 0;
326
+ const obj = Object.create(WasmSumCodeResult.prototype);
327
+ obj.__wbg_ptr = ptr;
328
+ WasmSumCodeResultFinalization.register(obj, obj.__wbg_ptr, obj);
329
+ return obj;
330
+ }
331
+ __destroy_into_raw() {
332
+ const ptr = this.__wbg_ptr;
333
+ this.__wbg_ptr = 0;
334
+ WasmSumCodeResultFinalization.unregister(this);
335
+ return ptr;
336
+ }
337
+ free() {
338
+ const ptr = this.__destroy_into_raw();
339
+ wasm.__wbg_wasmsumcoderesult_free(ptr, 0);
340
+ }
341
+ /**
342
+ * Hex-encoded BLAKE3 multihash (`"1e20..."`) of the data.
343
+ * @returns {string}
344
+ */
345
+ get datahash() {
346
+ let deferred1_0;
347
+ let deferred1_1;
348
+ try {
349
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
350
+ wasm.__wbg_get_wasmsumcoderesult_datahash(retptr, this.__wbg_ptr);
351
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
352
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
353
+ deferred1_0 = r0;
354
+ deferred1_1 = r1;
355
+ return getStringFromWasm0(r0, r1);
356
+ } finally {
357
+ wasm.__wbindgen_add_to_stack_pointer(16);
358
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
359
+ }
360
+ }
361
+ /**
362
+ * Byte length of the input data (as `f64` for JS `number` compatibility).
363
+ * @returns {number}
364
+ */
365
+ get filesize() {
366
+ const ret = wasm.__wbg_get_wasmsumcoderesult_filesize(this.__wbg_ptr);
367
+ return ret;
368
+ }
369
+ /**
370
+ * Composite ISCC-CODE string (e.g., `"ISCC:KAC..."`).
371
+ * @returns {string}
372
+ */
373
+ get iscc() {
374
+ let deferred1_0;
375
+ let deferred1_1;
376
+ try {
377
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
378
+ wasm.__wbg_get_wasmsumcoderesult_iscc(retptr, this.__wbg_ptr);
379
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
380
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
381
+ deferred1_0 = r0;
382
+ deferred1_1 = r1;
383
+ return getStringFromWasm0(r0, r1);
384
+ } finally {
385
+ wasm.__wbindgen_add_to_stack_pointer(16);
386
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
387
+ }
388
+ }
389
+ /**
390
+ * Data-Code and Instance-Code ISCC strings (when `add_units` is true).
391
+ * @returns {string[] | undefined}
392
+ */
393
+ get units() {
394
+ try {
395
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
396
+ wasm.__wbg_get_wasmsumcoderesult_units(retptr, this.__wbg_ptr);
397
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
398
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
399
+ let v1;
400
+ if (r0 !== 0) {
401
+ v1 = getArrayJsValueFromWasm0(r0, r1).slice();
402
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
403
+ }
404
+ return v1;
405
+ } finally {
406
+ wasm.__wbindgen_add_to_stack_pointer(16);
407
+ }
408
+ }
409
+ /**
410
+ * Hex-encoded BLAKE3 multihash (`"1e20..."`) of the data.
411
+ * @param {string} arg0
412
+ */
413
+ set datahash(arg0) {
414
+ const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export, wasm.__wbindgen_export2);
415
+ const len0 = WASM_VECTOR_LEN;
416
+ wasm.__wbg_set_wasmsumcoderesult_datahash(this.__wbg_ptr, ptr0, len0);
417
+ }
418
+ /**
419
+ * Byte length of the input data (as `f64` for JS `number` compatibility).
420
+ * @param {number} arg0
421
+ */
422
+ set filesize(arg0) {
423
+ wasm.__wbg_set_wasmsumcoderesult_filesize(this.__wbg_ptr, arg0);
424
+ }
425
+ /**
426
+ * Composite ISCC-CODE string (e.g., `"ISCC:KAC..."`).
427
+ * @param {string} arg0
428
+ */
429
+ set iscc(arg0) {
430
+ const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export, wasm.__wbindgen_export2);
431
+ const len0 = WASM_VECTOR_LEN;
432
+ wasm.__wbg_set_wasmsumcoderesult_iscc(this.__wbg_ptr, ptr0, len0);
433
+ }
434
+ /**
435
+ * Data-Code and Instance-Code ISCC strings (when `add_units` is true).
436
+ * @param {string[] | null} [arg0]
437
+ */
438
+ set units(arg0) {
439
+ var ptr0 = isLikeNone(arg0) ? 0 : passArrayJsValueToWasm0(arg0, wasm.__wbindgen_export);
440
+ var len0 = WASM_VECTOR_LEN;
441
+ wasm.__wbg_set_wasmsumcoderesult_units(this.__wbg_ptr, ptr0, len0);
442
+ }
443
+ }
444
+ if (Symbol.dispose) WasmSumCodeResult.prototype[Symbol.dispose] = WasmSumCodeResult.prototype.free;
445
+
311
446
  /**
312
447
  * Split data into content-defined chunks using gear rolling hash.
313
448
  *
@@ -708,6 +843,39 @@ export function gen_mixed_code_v0(codes, bits) {
708
843
  }
709
844
  }
710
845
 
846
+ /**
847
+ * Generate a composite ISCC-CODE from raw byte data in a single pass.
848
+ *
849
+ * Feeds both `DataHasher` (CDC/MinHash) and `InstanceHasher` (BLAKE3) from
850
+ * the same byte slice, then composes the final ISCC-CODE via
851
+ * `gen_iscc_code_v0`. WASM-compatible alternative to the file-based core API.
852
+ *
853
+ * When `add_units` is `true`, the result includes the individual Data-Code
854
+ * and Instance-Code ISCC strings.
855
+ * @param {Uint8Array} data
856
+ * @param {number | null} [bits]
857
+ * @param {boolean | null} [wide]
858
+ * @param {boolean | null} [add_units]
859
+ * @returns {WasmSumCodeResult}
860
+ */
861
+ export function gen_sum_code_v0(data, bits, wide, add_units) {
862
+ try {
863
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
864
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
865
+ const len0 = WASM_VECTOR_LEN;
866
+ wasm.gen_sum_code_v0(retptr, ptr0, len0, isLikeNone(bits) ? 0x100000001 : (bits) >>> 0, isLikeNone(wide) ? 0xFFFFFF : wide ? 1 : 0, isLikeNone(add_units) ? 0xFFFFFF : add_units ? 1 : 0);
867
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
868
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
869
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
870
+ if (r2) {
871
+ throw takeObject(r1);
872
+ }
873
+ return WasmSumCodeResult.__wrap(r0);
874
+ } finally {
875
+ wasm.__wbindgen_add_to_stack_pointer(16);
876
+ }
877
+ }
878
+
711
879
  /**
712
880
  * Generate a Text-Code from plain text content.
713
881
  *
@@ -1208,6 +1376,9 @@ const InstanceHasherFinalization = (typeof FinalizationRegistry === 'undefined')
1208
1376
  const IsccDecodeResultFinalization = (typeof FinalizationRegistry === 'undefined')
1209
1377
  ? { register: () => {}, unregister: () => {} }
1210
1378
  : new FinalizationRegistry(ptr => wasm.__wbg_isccdecoderesult_free(ptr >>> 0, 1));
1379
+ const WasmSumCodeResultFinalization = (typeof FinalizationRegistry === 'undefined')
1380
+ ? { register: () => {}, unregister: () => {} }
1381
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmsumcoderesult_free(ptr >>> 0, 1));
1211
1382
 
1212
1383
  function addHeapObject(obj) {
1213
1384
  if (heap_next === heap.length) heap.push(heap.length + 1);
@@ -1366,6 +1537,16 @@ function passArray8ToWasm0(arg, malloc) {
1366
1537
  return ptr;
1367
1538
  }
1368
1539
 
1540
+ function passArrayJsValueToWasm0(array, malloc) {
1541
+ const ptr = malloc(array.length * 4, 4) >>> 0;
1542
+ const mem = getDataViewMemory0();
1543
+ for (let i = 0; i < array.length; i++) {
1544
+ mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
1545
+ }
1546
+ WASM_VECTOR_LEN = array.length;
1547
+ return ptr;
1548
+ }
1549
+
1369
1550
  function passStringToWasm0(arg, malloc, realloc) {
1370
1551
  if (realloc === undefined) {
1371
1552
  const buf = cachedTextEncoder.encode(arg);
package/iscc_wasm_bg.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@iscc/wasm",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.1.0",
5
5
  "files": [
6
6
  "iscc_wasm_bg.wasm",
7
7
  "iscc_wasm.js",