@net-protocol/storage 0.1.11 → 0.1.13

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
@@ -32,8 +32,8 @@ Net Storage supports three storage patterns for different file sizes:
32
32
 
33
33
  ### XML Storage
34
34
 
35
- **Best for**: Large files (> 20KB) or files containing XML references
36
- **How it works**: Splits large files into 80KB pieces, stores each using ChunkedStorage (compressed and chunked into 20KB pieces), maintains references as XML metadata
35
+ **Best for**: Large files (> 20KB) or files containing XML references
36
+ **How it works**: Splits large files into 80KB pieces (configurable via `chunkSize`), stores each using ChunkedStorage (compressed and chunked into 20KB pieces), maintains references as XML metadata
37
37
  **Use cases**: Videos, large images, datasets, any large file
38
38
 
39
39
  ## What can you do with this package?
@@ -133,38 +133,24 @@ function XmlComponent() {
133
133
  return <div>{data}</div>;
134
134
  }
135
135
 
136
- // XML storage with format options
137
- function XmlWithFormats() {
138
- // Return as tuple format with hex output
139
- const { data: tupleData } = useXmlStorage({
136
+ // XML storage with options
137
+ function XmlWithOptions() {
138
+ // With hex output (default)
139
+ const { data: hexData, isXml } = useXmlStorage({
140
140
  chainId: 8453,
141
141
  key: "my-xml-key",
142
142
  operatorAddress: "0x...",
143
- returnFormat: "tuple", // Returns [text, data] tuple
144
143
  outputFormat: "hex", // Data is hex string (default)
145
144
  useRouter: true, // Use StorageRouter for automatic detection
146
145
  });
147
146
 
148
- // Return as tuple format with string output
149
- const { data: tupleStringData } = useXmlStorage({
147
+ // With string output
148
+ const { data: stringData } = useXmlStorage({
150
149
  chainId: 8453,
151
150
  key: "my-xml-key",
152
151
  operatorAddress: "0x...",
153
- returnFormat: "tuple",
154
152
  outputFormat: "string", // Data is plain string
155
153
  });
156
-
157
- // Return as object format (default)
158
- const {
159
- data: objectData,
160
- filename,
161
- isXml,
162
- } = useXmlStorage({
163
- chainId: 8453,
164
- key: "my-xml-key",
165
- operatorAddress: "0x...",
166
- returnFormat: "object", // Returns { data, filename, isLoading, error, isXml }
167
- });
168
154
  }
169
155
 
170
156
  // Storage from router (handles chunked storage)
@@ -228,6 +214,7 @@ import {
228
214
  fileToDataUri,
229
215
  detectFileTypeFromBase64,
230
216
  base64ToDataUri,
217
+ OPTIMAL_CHUNK_SIZE,
231
218
  } from "@net-protocol/storage";
232
219
 
233
220
  // Generate storage key bytes
@@ -242,8 +229,11 @@ const assembled = assembleChunks(chunks);
242
229
  // Parse XML references
243
230
  const references = parseNetReferences('<net k="hash" v="0.0.1" />');
244
231
 
245
- // Process data for XML storage
246
- const result = processDataForStorage(data, operatorAddress);
232
+ // Process data for XML storage (default 80KB chunk size)
233
+ const result = processDataForStorage(data, operatorAddress, storageKey);
234
+
235
+ // Process with custom chunk size (40KB)
236
+ const result2 = processDataForStorage(data, operatorAddress, storageKey, 40000);
247
237
  ```
248
238
 
249
239
  ### File Utilities
@@ -297,6 +287,11 @@ const dataUri = base64ToDataUri(base64Data);
297
287
  - `getForOperatorAndKey(params)` - Get storage by operator and key
298
288
  - `readStorageData(params)` - Read with XML resolution
299
289
  - `readChunkedStorage(params)` - Read chunked storage with decompression
290
+ - `prepareXmlStorage(params)` - Prepare XML storage transactions (supports optional `chunkSize`)
291
+
292
+ ### Constants
293
+
294
+ - `OPTIMAL_CHUNK_SIZE` - Default chunk size for XML storage (80000 bytes)
300
295
 
301
296
  ## Storage Types
302
297
 
package/dist/index.d.mts CHANGED
@@ -183,6 +183,7 @@ declare class StorageClient {
183
183
  filename?: string;
184
184
  useChunkedStorageBackend?: boolean;
185
185
  keyFormat?: "raw" | "bytes32";
186
+ chunkSize?: number;
186
187
  }): {
187
188
  transactionConfigs: WriteTransactionConfig[];
188
189
  topLevelHash: string;
@@ -297,6 +298,7 @@ declare function resolveOperator(reference: XmlReference, defaultOperator: strin
297
298
  */
298
299
  declare function getReferenceKey(reference: XmlReference, defaultOperator: string): string;
299
300
 
301
+ declare const OPTIMAL_CHUNK_SIZE: number;
300
302
  /**
301
303
  * Split data into chunks of specified size
302
304
  */
@@ -325,7 +327,7 @@ declare function computeTopLevelHash(chunkHashes: string[]): string;
325
327
  /**
326
328
  * Complete chunking and hash generation process
327
329
  */
328
- declare function processDataForStorage(data: string, operatorAddress: string, storageKey?: string): {
330
+ declare function processDataForStorage(data: string, operatorAddress: string, storageKey?: string, chunkSize?: number): {
329
331
  chunks: string[];
330
332
  chunkHashes: string[];
331
333
  xmlMetadata: string;
@@ -512,4 +514,4 @@ declare const CONCURRENT_XML_FETCHES = 3;
512
514
  */
513
515
  declare function resolveXmlRecursive(content: string, defaultOperator: string, client: PublicClient, maxDepth: number, visited?: Set<string>, inheritedOperator?: string): Promise<string>;
514
516
 
515
- export { BulkStorageKey, CHUNKED_STORAGE_CONTRACT, CHUNKED_STORAGE_READER_CONTRACT, CONCURRENT_XML_FETCHES, MAX_XML_DEPTH, SAFE_STORAGE_READER_CONTRACT, STORAGE_CONTRACT, STORAGE_ROUTER_CONTRACT, StorageClient, StorageClientOptions, StorageData, type StreamingChunkResult, type StreamingProcessResult, assembleChunks, base64ToDataUri, chunkData, chunkDataForStorage, computeTopLevelHash, containsXmlReferences, detectFileTypeFromBase64, detectStorageType, encodeStorageKeyForUrl, estimateChunkCount, fileToDataUri, formatStorageKeyForDisplay, generateStorageEmbedTag, generateXmlMetadata, generateXmlMetadataWithSource, getChunkCount, getReferenceKey, getStorageKeyBytes, isBinaryFile, parseNetReferences, processDataForStorage, processFileStreaming, processFileStreamingComplete, readFileSlice, resolveOperator, resolveXmlRecursive, shouldSuggestXmlStorage, validateDataSize };
517
+ export { BulkStorageKey, CHUNKED_STORAGE_CONTRACT, CHUNKED_STORAGE_READER_CONTRACT, CONCURRENT_XML_FETCHES, MAX_XML_DEPTH, OPTIMAL_CHUNK_SIZE, SAFE_STORAGE_READER_CONTRACT, STORAGE_CONTRACT, STORAGE_ROUTER_CONTRACT, StorageClient, StorageClientOptions, StorageData, type StreamingChunkResult, type StreamingProcessResult, assembleChunks, base64ToDataUri, chunkData, chunkDataForStorage, computeTopLevelHash, containsXmlReferences, detectFileTypeFromBase64, detectStorageType, encodeStorageKeyForUrl, estimateChunkCount, fileToDataUri, formatStorageKeyForDisplay, generateStorageEmbedTag, generateXmlMetadata, generateXmlMetadataWithSource, getChunkCount, getReferenceKey, getStorageKeyBytes, isBinaryFile, parseNetReferences, processDataForStorage, processFileStreaming, processFileStreamingComplete, readFileSlice, resolveOperator, resolveXmlRecursive, shouldSuggestXmlStorage, validateDataSize };
package/dist/index.d.ts CHANGED
@@ -183,6 +183,7 @@ declare class StorageClient {
183
183
  filename?: string;
184
184
  useChunkedStorageBackend?: boolean;
185
185
  keyFormat?: "raw" | "bytes32";
186
+ chunkSize?: number;
186
187
  }): {
187
188
  transactionConfigs: WriteTransactionConfig[];
188
189
  topLevelHash: string;
@@ -297,6 +298,7 @@ declare function resolveOperator(reference: XmlReference, defaultOperator: strin
297
298
  */
298
299
  declare function getReferenceKey(reference: XmlReference, defaultOperator: string): string;
299
300
 
301
+ declare const OPTIMAL_CHUNK_SIZE: number;
300
302
  /**
301
303
  * Split data into chunks of specified size
302
304
  */
@@ -325,7 +327,7 @@ declare function computeTopLevelHash(chunkHashes: string[]): string;
325
327
  /**
326
328
  * Complete chunking and hash generation process
327
329
  */
328
- declare function processDataForStorage(data: string, operatorAddress: string, storageKey?: string): {
330
+ declare function processDataForStorage(data: string, operatorAddress: string, storageKey?: string, chunkSize?: number): {
329
331
  chunks: string[];
330
332
  chunkHashes: string[];
331
333
  xmlMetadata: string;
@@ -512,4 +514,4 @@ declare const CONCURRENT_XML_FETCHES = 3;
512
514
  */
513
515
  declare function resolveXmlRecursive(content: string, defaultOperator: string, client: PublicClient, maxDepth: number, visited?: Set<string>, inheritedOperator?: string): Promise<string>;
514
516
 
515
- export { BulkStorageKey, CHUNKED_STORAGE_CONTRACT, CHUNKED_STORAGE_READER_CONTRACT, CONCURRENT_XML_FETCHES, MAX_XML_DEPTH, SAFE_STORAGE_READER_CONTRACT, STORAGE_CONTRACT, STORAGE_ROUTER_CONTRACT, StorageClient, StorageClientOptions, StorageData, type StreamingChunkResult, type StreamingProcessResult, assembleChunks, base64ToDataUri, chunkData, chunkDataForStorage, computeTopLevelHash, containsXmlReferences, detectFileTypeFromBase64, detectStorageType, encodeStorageKeyForUrl, estimateChunkCount, fileToDataUri, formatStorageKeyForDisplay, generateStorageEmbedTag, generateXmlMetadata, generateXmlMetadataWithSource, getChunkCount, getReferenceKey, getStorageKeyBytes, isBinaryFile, parseNetReferences, processDataForStorage, processFileStreaming, processFileStreamingComplete, readFileSlice, resolveOperator, resolveXmlRecursive, shouldSuggestXmlStorage, validateDataSize };
517
+ export { BulkStorageKey, CHUNKED_STORAGE_CONTRACT, CHUNKED_STORAGE_READER_CONTRACT, CONCURRENT_XML_FETCHES, MAX_XML_DEPTH, OPTIMAL_CHUNK_SIZE, SAFE_STORAGE_READER_CONTRACT, STORAGE_CONTRACT, STORAGE_ROUTER_CONTRACT, StorageClient, StorageClientOptions, StorageData, type StreamingChunkResult, type StreamingProcessResult, assembleChunks, base64ToDataUri, chunkData, chunkDataForStorage, computeTopLevelHash, containsXmlReferences, detectFileTypeFromBase64, detectStorageType, encodeStorageKeyForUrl, estimateChunkCount, fileToDataUri, formatStorageKeyForDisplay, generateStorageEmbedTag, generateXmlMetadata, generateXmlMetadataWithSource, getChunkCount, getReferenceKey, getStorageKeyBytes, isBinaryFile, parseNetReferences, processDataForStorage, processFileStreaming, processFileStreamingComplete, readFileSlice, resolveOperator, resolveXmlRecursive, shouldSuggestXmlStorage, validateDataSize };
package/dist/index.js CHANGED
@@ -1010,8 +1010,8 @@ function validateDataSize(chunks) {
1010
1010
  function computeTopLevelHash(chunkHashes) {
1011
1011
  return core.keccak256HashString(chunkHashes.join(""));
1012
1012
  }
1013
- function processDataForStorage(data, operatorAddress, storageKey) {
1014
- const chunks = chunkData(data);
1013
+ function processDataForStorage(data, operatorAddress, storageKey, chunkSize) {
1014
+ const chunks = chunkData(data, chunkSize);
1015
1015
  const validation = validateDataSize(chunks);
1016
1016
  if (!validation.valid) {
1017
1017
  return {
@@ -1482,7 +1482,8 @@ var StorageClient = class {
1482
1482
  const result = processDataForStorage(
1483
1483
  params.data,
1484
1484
  params.operatorAddress,
1485
- params.storageKey
1485
+ params.storageKey,
1486
+ params.chunkSize
1486
1487
  );
1487
1488
  if (!result.valid) {
1488
1489
  throw new Error(result.error || "Failed to process data for storage");
@@ -1775,6 +1776,7 @@ exports.CHUNKED_STORAGE_CONTRACT = CHUNKED_STORAGE_CONTRACT;
1775
1776
  exports.CHUNKED_STORAGE_READER_CONTRACT = CHUNKED_STORAGE_READER_CONTRACT;
1776
1777
  exports.CONCURRENT_XML_FETCHES = CONCURRENT_XML_FETCHES;
1777
1778
  exports.MAX_XML_DEPTH = MAX_XML_DEPTH;
1779
+ exports.OPTIMAL_CHUNK_SIZE = OPTIMAL_CHUNK_SIZE;
1778
1780
  exports.SAFE_STORAGE_READER_CONTRACT = SAFE_STORAGE_READER_CONTRACT;
1779
1781
  exports.STORAGE_CONTRACT = STORAGE_CONTRACT;
1780
1782
  exports.STORAGE_ROUTER_CONTRACT = STORAGE_ROUTER_CONTRACT;