@storagehub-sdk/core 0.3.1 → 0.3.3

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/dist/types.d.ts CHANGED
@@ -9,4 +9,15 @@ export interface FileInfo {
9
9
  location: string;
10
10
  /** File size in bytes (using bigint for blockchain compatibility) */
11
11
  size: bigint;
12
+ /**
13
+ * Block hash where the file was created (32-byte hex string).
14
+ * Contains the block hash where the NewStorageRequest event was emitted.
15
+ */
16
+ blockHash: `0x${string}`;
17
+ /**
18
+ * EVM transaction hash that created this file (32-byte hex string).
19
+ * Only present for files created via EVM transactions on EVM-enabled runtimes.
20
+ * Will be undefined for files created via native Substrate extrinsics.
21
+ */
22
+ txHash?: `0x${string}`;
12
23
  }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Utility functions for StorageHub SDK
3
+ */
4
+ /**
5
+ * Ensures a hex string has the '0x' prefix
6
+ * @param hex - The hex string to process
7
+ * @returns The hex string with '0x' prefix
8
+ */
9
+ export declare function ensure0xPrefix(hex: string): `0x${string}`;
10
+ /**
11
+ * Removes the '0x' prefix from a hex string if present
12
+ * @param hex - The hex string to process
13
+ * @returns The hex string without '0x' prefix
14
+ */
15
+ export declare function removeHexPrefix(hex: string): string;
16
+ /**
17
+ * Converts a hex string to Uint8Array
18
+ * @param hex - The hex string to convert (with or without 0x prefix)
19
+ * @returns Uint8Array representation
20
+ */
21
+ /**
22
+ * Safely parse a date string, validating that it results in a valid Date object.
23
+ * @param dateString - The date string to parse (expected to be an ISO timestamp)
24
+ * @returns A valid Date object
25
+ * @throws Error if the date string is invalid or results in an Invalid Date
26
+ */
27
+ export declare function parseDate(dateString: string): Date;
28
+ export declare function hexToBytes(hex: string): Uint8Array;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storagehub-sdk/core",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Core primitives for StorageHub SDK (types, crypto, filemanager, storage, wasm bindings)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.node.js",
@@ -26,11 +26,14 @@
26
26
  "dependencies": {
27
27
  "@polkadot/types": "^16.4.7",
28
28
  "abitype": "^1.0.0",
29
- "ethers": "^6.15.0",
30
- "viem": "^2.37.6"
29
+ "ethers": "^6.15.0"
30
+ },
31
+ "peerDependencies": {
32
+ "viem": ">=2.38.3"
31
33
  },
32
34
  "devDependencies": {
33
35
  "@types/node": "^20.11.19",
36
+ "viem": ">=2.38.3",
34
37
  "solc": "^0.8.26"
35
38
  },
36
39
  "engines": {
@@ -24,6 +24,12 @@ export class FileTrie {
24
24
  free(): void;
25
25
  constructor();
26
26
  push_chunk(bytes: Uint8Array): void;
27
+ /**
28
+ * Push many chunks at once. The input buffer is split into FILE_CHUNK_SIZE-sized
29
+ * windows, and any remainder (< FILE_CHUNK_SIZE) is pushed as the final chunk.
30
+ * This preserves the canonical chunking while dramatically reducing JS→WASM calls.
31
+ */
32
+ push_chunks_batched(bytes: Uint8Array): void;
27
33
  /**
28
34
  * Current Merkle root as a hex string.
29
35
  */
@@ -34,18 +40,19 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
34
40
 
35
41
  export interface InitOutput {
36
42
  readonly memory: WebAssembly.Memory;
37
- readonly __wbg_filemetadata_free: (a: number, b: number) => void;
38
- readonly filemetadata_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number, i: number) => [number, number, number];
39
- readonly filemetadata_getFileKey: (a: number) => [number, number];
40
- readonly filemetadata_encode: (a: number) => [number, number];
41
43
  readonly __wbg_filetrie_free: (a: number, b: number) => void;
42
44
  readonly filetrie_new: () => number;
43
45
  readonly filetrie_push_chunk: (a: number, b: number, c: number) => void;
46
+ readonly filetrie_push_chunks_batched: (a: number, b: number, c: number) => void;
44
47
  readonly filetrie_get_root: (a: number) => [number, number];
48
+ readonly __wbg_filemetadata_free: (a: number, b: number) => void;
49
+ readonly filemetadata_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number, i: number) => [number, number, number];
50
+ readonly filemetadata_getFileKey: (a: number) => [number, number];
51
+ readonly filemetadata_encode: (a: number) => [number, number];
45
52
  readonly __wbindgen_export_0: WebAssembly.Table;
46
53
  readonly __wbindgen_malloc: (a: number, b: number) => number;
47
- readonly __externref_table_dealloc: (a: number) => void;
48
54
  readonly __wbindgen_free: (a: number, b: number, c: number) => void;
55
+ readonly __externref_table_dealloc: (a: number) => void;
49
56
  readonly __wbindgen_start: () => void;
50
57
  }
51
58
 
@@ -27,17 +27,17 @@ function passArray8ToWasm0(arg, malloc) {
27
27
  return ptr;
28
28
  }
29
29
 
30
+ function getArrayU8FromWasm0(ptr, len) {
31
+ ptr = ptr >>> 0;
32
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
33
+ }
34
+
30
35
  function takeFromExternrefTable0(idx) {
31
36
  const value = wasm.__wbindgen_export_0.get(idx);
32
37
  wasm.__externref_table_dealloc(idx);
33
38
  return value;
34
39
  }
35
40
 
36
- function getArrayU8FromWasm0(ptr, len) {
37
- ptr = ptr >>> 0;
38
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
39
- }
40
-
41
41
  const FileMetadataFinalization = (typeof FinalizationRegistry === 'undefined')
42
42
  ? { register: () => {}, unregister: () => {} }
43
43
  : new FinalizationRegistry(ptr => wasm.__wbg_filemetadata_free(ptr >>> 0, 1));
@@ -138,6 +138,17 @@ export class FileTrie {
138
138
  const len0 = WASM_VECTOR_LEN;
139
139
  wasm.filetrie_push_chunk(this.__wbg_ptr, ptr0, len0);
140
140
  }
141
+ /**
142
+ * Push many chunks at once. The input buffer is split into FILE_CHUNK_SIZE-sized
143
+ * windows, and any remainder (< FILE_CHUNK_SIZE) is pushed as the final chunk.
144
+ * This preserves the canonical chunking while dramatically reducing JS→WASM calls.
145
+ * @param {Uint8Array} bytes
146
+ */
147
+ push_chunks_batched(bytes) {
148
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
149
+ const len0 = WASM_VECTOR_LEN;
150
+ wasm.filetrie_push_chunks_batched(this.__wbg_ptr, ptr0, len0);
151
+ }
141
152
  /**
142
153
  * Current Merkle root as a hex string.
143
154
  * @returns {Uint8Array}
Binary file
@@ -1,16 +1,17 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
- export const __wbg_filemetadata_free: (a: number, b: number) => void;
5
- export const filemetadata_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number, i: number) => [number, number, number];
6
- export const filemetadata_getFileKey: (a: number) => [number, number];
7
- export const filemetadata_encode: (a: number) => [number, number];
8
4
  export const __wbg_filetrie_free: (a: number, b: number) => void;
9
5
  export const filetrie_new: () => number;
10
6
  export const filetrie_push_chunk: (a: number, b: number, c: number) => void;
7
+ export const filetrie_push_chunks_batched: (a: number, b: number, c: number) => void;
11
8
  export const filetrie_get_root: (a: number) => [number, number];
9
+ export const __wbg_filemetadata_free: (a: number, b: number) => void;
10
+ export const filemetadata_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number, i: number) => [number, number, number];
11
+ export const filemetadata_getFileKey: (a: number) => [number, number];
12
+ export const filemetadata_encode: (a: number) => [number, number];
12
13
  export const __wbindgen_export_0: WebAssembly.Table;
13
14
  export const __wbindgen_malloc: (a: number, b: number) => number;
14
- export const __externref_table_dealloc: (a: number) => void;
15
15
  export const __wbindgen_free: (a: number, b: number, c: number) => void;
16
+ export const __externref_table_dealloc: (a: number) => void;
16
17
  export const __wbindgen_start: () => void;