@net-protocol/storage 0.1.12 → 0.1.14
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 +19 -24
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -2
- package/dist/index.mjs.map +1 -1
- package/dist/react.js.map +1 -1
- package/dist/react.mjs.map +1 -1
- package/package.json +3 -3
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
|
|
137
|
-
function
|
|
138
|
-
//
|
|
139
|
-
const { data:
|
|
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
|
-
//
|
|
149
|
-
const { data:
|
|
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
|
@@ -208,6 +208,17 @@ declare function formatStorageKeyForDisplay(storageKey: string): {
|
|
|
208
208
|
* @param keyFormat - Optional format override: "raw" to always convert, "bytes32" to use as-is, undefined for auto-detect
|
|
209
209
|
*/
|
|
210
210
|
declare function getStorageKeyBytes(input: string, keyFormat?: "raw" | "bytes32"): string;
|
|
211
|
+
/**
|
|
212
|
+
* Extract a storage key from a message's hex-encoded data field.
|
|
213
|
+
*
|
|
214
|
+
* Follows the same detection heuristic as the Net website:
|
|
215
|
+
* a value is treated as a storage key reference if the decoded string
|
|
216
|
+
* starts with "netid-" or is 32 characters or fewer.
|
|
217
|
+
*
|
|
218
|
+
* @param data - The hex-encoded data field from a NetMessage
|
|
219
|
+
* @returns The decoded storage key string, or null if not a storage reference
|
|
220
|
+
*/
|
|
221
|
+
declare function extractStorageKeyFromMessageData(data: `0x${string}` | string | undefined): string | null;
|
|
211
222
|
/**
|
|
212
223
|
* Encodes a storage key for use in URL paths.
|
|
213
224
|
*
|
|
@@ -514,4 +525,4 @@ declare const CONCURRENT_XML_FETCHES = 3;
|
|
|
514
525
|
*/
|
|
515
526
|
declare function resolveXmlRecursive(content: string, defaultOperator: string, client: PublicClient, maxDepth: number, visited?: Set<string>, inheritedOperator?: string): Promise<string>;
|
|
516
527
|
|
|
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 };
|
|
528
|
+
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, extractStorageKeyFromMessageData, fileToDataUri, formatStorageKeyForDisplay, generateStorageEmbedTag, generateXmlMetadata, generateXmlMetadataWithSource, getChunkCount, getReferenceKey, getStorageKeyBytes, isBinaryFile, parseNetReferences, processDataForStorage, processFileStreaming, processFileStreamingComplete, readFileSlice, resolveOperator, resolveXmlRecursive, shouldSuggestXmlStorage, validateDataSize };
|
package/dist/index.d.ts
CHANGED
|
@@ -208,6 +208,17 @@ declare function formatStorageKeyForDisplay(storageKey: string): {
|
|
|
208
208
|
* @param keyFormat - Optional format override: "raw" to always convert, "bytes32" to use as-is, undefined for auto-detect
|
|
209
209
|
*/
|
|
210
210
|
declare function getStorageKeyBytes(input: string, keyFormat?: "raw" | "bytes32"): string;
|
|
211
|
+
/**
|
|
212
|
+
* Extract a storage key from a message's hex-encoded data field.
|
|
213
|
+
*
|
|
214
|
+
* Follows the same detection heuristic as the Net website:
|
|
215
|
+
* a value is treated as a storage key reference if the decoded string
|
|
216
|
+
* starts with "netid-" or is 32 characters or fewer.
|
|
217
|
+
*
|
|
218
|
+
* @param data - The hex-encoded data field from a NetMessage
|
|
219
|
+
* @returns The decoded storage key string, or null if not a storage reference
|
|
220
|
+
*/
|
|
221
|
+
declare function extractStorageKeyFromMessageData(data: `0x${string}` | string | undefined): string | null;
|
|
211
222
|
/**
|
|
212
223
|
* Encodes a storage key for use in URL paths.
|
|
213
224
|
*
|
|
@@ -514,4 +525,4 @@ declare const CONCURRENT_XML_FETCHES = 3;
|
|
|
514
525
|
*/
|
|
515
526
|
declare function resolveXmlRecursive(content: string, defaultOperator: string, client: PublicClient, maxDepth: number, visited?: Set<string>, inheritedOperator?: string): Promise<string>;
|
|
516
527
|
|
|
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 };
|
|
528
|
+
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, extractStorageKeyFromMessageData, fileToDataUri, formatStorageKeyForDisplay, generateStorageEmbedTag, generateXmlMetadata, generateXmlMetadataWithSource, getChunkCount, getReferenceKey, getStorageKeyBytes, isBinaryFile, parseNetReferences, processDataForStorage, processFileStreaming, processFileStreamingComplete, readFileSlice, resolveOperator, resolveXmlRecursive, shouldSuggestXmlStorage, validateDataSize };
|
package/dist/index.js
CHANGED
|
@@ -629,6 +629,17 @@ function getStorageKeyBytes(input, keyFormat) {
|
|
|
629
629
|
}
|
|
630
630
|
return input.length > 32 ? core.keccak256HashString(input.toLowerCase()) : core.toBytes32(input.toLowerCase());
|
|
631
631
|
}
|
|
632
|
+
function extractStorageKeyFromMessageData(data) {
|
|
633
|
+
if (!data || data === "0x" || !data.startsWith("0x")) return null;
|
|
634
|
+
try {
|
|
635
|
+
const decoded = viem.hexToString(data);
|
|
636
|
+
if (decoded.startsWith("netid-") || decoded.length <= 32) {
|
|
637
|
+
return decoded;
|
|
638
|
+
}
|
|
639
|
+
} catch {
|
|
640
|
+
}
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
632
643
|
function encodeStorageKeyForUrl(key) {
|
|
633
644
|
return encodeURIComponent(key);
|
|
634
645
|
}
|
|
@@ -1791,6 +1802,7 @@ exports.detectFileTypeFromBase64 = detectFileTypeFromBase64;
|
|
|
1791
1802
|
exports.detectStorageType = detectStorageType;
|
|
1792
1803
|
exports.encodeStorageKeyForUrl = encodeStorageKeyForUrl;
|
|
1793
1804
|
exports.estimateChunkCount = estimateChunkCount;
|
|
1805
|
+
exports.extractStorageKeyFromMessageData = extractStorageKeyFromMessageData;
|
|
1794
1806
|
exports.fileToDataUri = fileToDataUri;
|
|
1795
1807
|
exports.formatStorageKeyForDisplay = formatStorageKeyForDisplay;
|
|
1796
1808
|
exports.generateStorageEmbedTag = generateStorageEmbedTag;
|