@storagehub-sdk/core 0.0.5 → 0.1.1

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.
@@ -0,0 +1,427 @@
1
+ [
2
+ {
3
+ "anonymous": false,
4
+ "inputs": [
5
+ {
6
+ "indexed": true,
7
+ "internalType": "address",
8
+ "name": "who",
9
+ "type": "address"
10
+ },
11
+ {
12
+ "indexed": true,
13
+ "internalType": "bytes32",
14
+ "name": "bucketId",
15
+ "type": "bytes32"
16
+ },
17
+ {
18
+ "indexed": true,
19
+ "internalType": "bytes32",
20
+ "name": "mspId",
21
+ "type": "bytes32"
22
+ }
23
+ ],
24
+ "name": "BucketCreated",
25
+ "type": "event"
26
+ },
27
+ {
28
+ "anonymous": false,
29
+ "inputs": [
30
+ {
31
+ "indexed": true,
32
+ "internalType": "address",
33
+ "name": "who",
34
+ "type": "address"
35
+ },
36
+ {
37
+ "indexed": true,
38
+ "internalType": "bytes32",
39
+ "name": "bucketId",
40
+ "type": "bytes32"
41
+ }
42
+ ],
43
+ "name": "BucketDeleted",
44
+ "type": "event"
45
+ },
46
+ {
47
+ "anonymous": false,
48
+ "inputs": [
49
+ {
50
+ "indexed": true,
51
+ "internalType": "address",
52
+ "name": "who",
53
+ "type": "address"
54
+ },
55
+ {
56
+ "indexed": true,
57
+ "internalType": "bytes32",
58
+ "name": "bucketId",
59
+ "type": "bytes32"
60
+ },
61
+ {
62
+ "indexed": true,
63
+ "internalType": "bytes32",
64
+ "name": "newMspId",
65
+ "type": "bytes32"
66
+ }
67
+ ],
68
+ "name": "BucketMoveRequested",
69
+ "type": "event"
70
+ },
71
+ {
72
+ "anonymous": false,
73
+ "inputs": [
74
+ {
75
+ "indexed": true,
76
+ "internalType": "address",
77
+ "name": "who",
78
+ "type": "address"
79
+ },
80
+ {
81
+ "indexed": true,
82
+ "internalType": "bytes32",
83
+ "name": "bucketId",
84
+ "type": "bytes32"
85
+ },
86
+ {
87
+ "indexed": false,
88
+ "internalType": "bool",
89
+ "name": "_private",
90
+ "type": "bool"
91
+ }
92
+ ],
93
+ "name": "BucketPrivacyUpdated",
94
+ "type": "event"
95
+ },
96
+ {
97
+ "anonymous": false,
98
+ "inputs": [
99
+ {
100
+ "indexed": true,
101
+ "internalType": "address",
102
+ "name": "who",
103
+ "type": "address"
104
+ },
105
+ {
106
+ "indexed": true,
107
+ "internalType": "bytes32",
108
+ "name": "bucketId",
109
+ "type": "bytes32"
110
+ },
111
+ {
112
+ "indexed": true,
113
+ "internalType": "bytes32",
114
+ "name": "collectionId",
115
+ "type": "bytes32"
116
+ }
117
+ ],
118
+ "name": "CollectionCreated",
119
+ "type": "event"
120
+ },
121
+ {
122
+ "anonymous": false,
123
+ "inputs": [
124
+ {
125
+ "indexed": true,
126
+ "internalType": "bytes32",
127
+ "name": "fileKey",
128
+ "type": "bytes32"
129
+ },
130
+ {
131
+ "indexed": true,
132
+ "internalType": "address",
133
+ "name": "owner",
134
+ "type": "address"
135
+ }
136
+ ],
137
+ "name": "FileDeletionRequested",
138
+ "type": "event"
139
+ },
140
+ {
141
+ "anonymous": false,
142
+ "inputs": [
143
+ {
144
+ "indexed": true,
145
+ "internalType": "address",
146
+ "name": "who",
147
+ "type": "address"
148
+ },
149
+ {
150
+ "indexed": true,
151
+ "internalType": "bytes32",
152
+ "name": "fileKey",
153
+ "type": "bytes32"
154
+ },
155
+ {
156
+ "indexed": true,
157
+ "internalType": "bytes32",
158
+ "name": "bucketId",
159
+ "type": "bytes32"
160
+ }
161
+ ],
162
+ "name": "StorageRequestIssued",
163
+ "type": "event"
164
+ },
165
+ {
166
+ "anonymous": false,
167
+ "inputs": [
168
+ {
169
+ "indexed": true,
170
+ "internalType": "bytes32",
171
+ "name": "fileKey",
172
+ "type": "bytes32"
173
+ }
174
+ ],
175
+ "name": "StorageRequestRevoked",
176
+ "type": "event"
177
+ },
178
+ {
179
+ "inputs": [
180
+ {
181
+ "internalType": "bytes32",
182
+ "name": "bucketId",
183
+ "type": "bytes32"
184
+ }
185
+ ],
186
+ "name": "createAndAssociateCollectionWithBucket",
187
+ "outputs": [],
188
+ "stateMutability": "nonpayable",
189
+ "type": "function"
190
+ },
191
+ {
192
+ "inputs": [
193
+ {
194
+ "internalType": "bytes32",
195
+ "name": "mspId",
196
+ "type": "bytes32"
197
+ },
198
+ {
199
+ "internalType": "bytes",
200
+ "name": "name",
201
+ "type": "bytes"
202
+ },
203
+ {
204
+ "internalType": "bool",
205
+ "name": "_private",
206
+ "type": "bool"
207
+ },
208
+ {
209
+ "internalType": "bytes32",
210
+ "name": "valuePropId",
211
+ "type": "bytes32"
212
+ }
213
+ ],
214
+ "name": "createBucket",
215
+ "outputs": [],
216
+ "stateMutability": "nonpayable",
217
+ "type": "function"
218
+ },
219
+ {
220
+ "inputs": [
221
+ {
222
+ "internalType": "bytes32",
223
+ "name": "bucketId",
224
+ "type": "bytes32"
225
+ }
226
+ ],
227
+ "name": "deleteBucket",
228
+ "outputs": [],
229
+ "stateMutability": "nonpayable",
230
+ "type": "function"
231
+ },
232
+ {
233
+ "inputs": [
234
+ {
235
+ "internalType": "address",
236
+ "name": "owner",
237
+ "type": "address"
238
+ },
239
+ {
240
+ "internalType": "bytes",
241
+ "name": "name",
242
+ "type": "bytes"
243
+ }
244
+ ],
245
+ "name": "deriveBucketId",
246
+ "outputs": [
247
+ {
248
+ "internalType": "bytes32",
249
+ "name": "bucketId",
250
+ "type": "bytes32"
251
+ }
252
+ ],
253
+ "stateMutability": "view",
254
+ "type": "function"
255
+ },
256
+ {
257
+ "inputs": [
258
+ {
259
+ "internalType": "address",
260
+ "name": "user",
261
+ "type": "address"
262
+ }
263
+ ],
264
+ "name": "getPendingFileDeletionRequestsCount",
265
+ "outputs": [
266
+ {
267
+ "internalType": "uint32",
268
+ "name": "count",
269
+ "type": "uint32"
270
+ }
271
+ ],
272
+ "stateMutability": "view",
273
+ "type": "function"
274
+ },
275
+ {
276
+ "inputs": [
277
+ {
278
+ "internalType": "bytes32",
279
+ "name": "bucketId",
280
+ "type": "bytes32"
281
+ },
282
+ {
283
+ "internalType": "bytes",
284
+ "name": "location",
285
+ "type": "bytes"
286
+ },
287
+ {
288
+ "internalType": "bytes32",
289
+ "name": "fingerprint",
290
+ "type": "bytes32"
291
+ },
292
+ {
293
+ "internalType": "uint64",
294
+ "name": "size",
295
+ "type": "uint64"
296
+ },
297
+ {
298
+ "internalType": "bytes32",
299
+ "name": "mspId",
300
+ "type": "bytes32"
301
+ },
302
+ {
303
+ "internalType": "bytes[]",
304
+ "name": "peerIds",
305
+ "type": "bytes[]"
306
+ },
307
+ {
308
+ "internalType": "enum FileSystem.ReplicationTarget",
309
+ "name": "replicationTarget",
310
+ "type": "uint8"
311
+ },
312
+ {
313
+ "internalType": "uint32",
314
+ "name": "customReplicationTarget",
315
+ "type": "uint32"
316
+ }
317
+ ],
318
+ "name": "issueStorageRequest",
319
+ "outputs": [],
320
+ "stateMutability": "nonpayable",
321
+ "type": "function"
322
+ },
323
+ {
324
+ "inputs": [
325
+ {
326
+ "components": [
327
+ {
328
+ "internalType": "bytes32",
329
+ "name": "fileKey",
330
+ "type": "bytes32"
331
+ },
332
+ {
333
+ "internalType": "enum FileSystem.FileOperation",
334
+ "name": "operation",
335
+ "type": "uint8"
336
+ }
337
+ ],
338
+ "internalType": "struct FileSystem.FileOperationIntention",
339
+ "name": "signedIntention",
340
+ "type": "tuple"
341
+ },
342
+ {
343
+ "internalType": "bytes",
344
+ "name": "signature",
345
+ "type": "bytes"
346
+ },
347
+ {
348
+ "internalType": "bytes32",
349
+ "name": "bucketId",
350
+ "type": "bytes32"
351
+ },
352
+ {
353
+ "internalType": "bytes",
354
+ "name": "location",
355
+ "type": "bytes"
356
+ },
357
+ {
358
+ "internalType": "uint64",
359
+ "name": "size",
360
+ "type": "uint64"
361
+ },
362
+ {
363
+ "internalType": "bytes32",
364
+ "name": "fingerprint",
365
+ "type": "bytes32"
366
+ }
367
+ ],
368
+ "name": "requestDeleteFile",
369
+ "outputs": [],
370
+ "stateMutability": "nonpayable",
371
+ "type": "function"
372
+ },
373
+ {
374
+ "inputs": [
375
+ {
376
+ "internalType": "bytes32",
377
+ "name": "bucketId",
378
+ "type": "bytes32"
379
+ },
380
+ {
381
+ "internalType": "bytes32",
382
+ "name": "newMspId",
383
+ "type": "bytes32"
384
+ },
385
+ {
386
+ "internalType": "bytes32",
387
+ "name": "newValuePropId",
388
+ "type": "bytes32"
389
+ }
390
+ ],
391
+ "name": "requestMoveBucket",
392
+ "outputs": [],
393
+ "stateMutability": "nonpayable",
394
+ "type": "function"
395
+ },
396
+ {
397
+ "inputs": [
398
+ {
399
+ "internalType": "bytes32",
400
+ "name": "fileKey",
401
+ "type": "bytes32"
402
+ }
403
+ ],
404
+ "name": "revokeStorageRequest",
405
+ "outputs": [],
406
+ "stateMutability": "nonpayable",
407
+ "type": "function"
408
+ },
409
+ {
410
+ "inputs": [
411
+ {
412
+ "internalType": "bytes32",
413
+ "name": "bucketId",
414
+ "type": "bytes32"
415
+ },
416
+ {
417
+ "internalType": "bool",
418
+ "name": "_private",
419
+ "type": "bool"
420
+ }
421
+ ],
422
+ "name": "updateBucketPrivacy",
423
+ "outputs": [],
424
+ "stateMutability": "nonpayable",
425
+ "type": "function"
426
+ }
427
+ ]
@@ -0,0 +1,49 @@
1
+ export declare const filesystemAbi: ({
2
+ anonymous: boolean;
3
+ inputs: {
4
+ indexed: boolean;
5
+ internalType: string;
6
+ name: string;
7
+ type: string;
8
+ }[];
9
+ name: string;
10
+ type: string;
11
+ outputs?: never;
12
+ stateMutability?: never;
13
+ } | {
14
+ inputs: {
15
+ internalType: string;
16
+ name: string;
17
+ type: string;
18
+ }[];
19
+ name: string;
20
+ outputs: {
21
+ internalType: string;
22
+ name: string;
23
+ type: string;
24
+ }[];
25
+ stateMutability: string;
26
+ type: string;
27
+ anonymous?: never;
28
+ } | {
29
+ inputs: ({
30
+ components: {
31
+ internalType: string;
32
+ name: string;
33
+ type: string;
34
+ }[];
35
+ internalType: string;
36
+ name: string;
37
+ type: string;
38
+ } | {
39
+ internalType: string;
40
+ name: string;
41
+ type: string;
42
+ components?: never;
43
+ })[];
44
+ name: string;
45
+ outputs: never[];
46
+ stateMutability: string;
47
+ type: string;
48
+ anonymous?: never;
49
+ })[];
@@ -0,0 +1,49 @@
1
+ /**
2
+ * EVM client helpers (Core)
3
+ *
4
+ * Normalize how Core talks to an EVM endpoint in both environments (browser EIP‑1193 and Node HTTP)
5
+ * and return viem clients for reads (public) and writes (wallet) with a minimal API.
6
+ */
7
+ import { type Account, type Chain, createPublicClient, createWalletClient, type EIP1193Provider } from "viem";
8
+ /**
9
+ * HTTP transport configuration.
10
+ * - Requires a JSON‑RPC URL and an explicit viem Chain.
11
+ */
12
+ type HttpTransport = {
13
+ httpUrl: string;
14
+ chain: Chain;
15
+ };
16
+ /**
17
+ * EIP‑1193 transport configuration (e.g., window.ethereum).
18
+ * - Chain can be inferred from the provider; explicit Chain is not required.
19
+ */
20
+ type Eip1193Transport = {
21
+ eip1193: EIP1193Provider;
22
+ };
23
+ export type EvmClientsOptions = {
24
+ transport: HttpTransport | Eip1193Transport;
25
+ account?: Account | `0x${string}`;
26
+ timeoutMs?: number;
27
+ };
28
+ /**
29
+ * Returned clients:
30
+ * - readClient: public client for reads/logs (always available)
31
+ * - writeClient: wallet client for transactions (only when account is provided)
32
+ */
33
+ export type EvmClients = {
34
+ readClient: ReturnType<typeof createPublicClient>;
35
+ writeClient: ReturnType<typeof createWalletClient> | undefined;
36
+ };
37
+ /**
38
+ * Factory to create EVM clients for Core.
39
+ *
40
+ * Transport:
41
+ * - HTTP: { transport: { httpUrl, chain }, account?, timeoutMs? }
42
+ * - EIP1193:{ transport: { eip1193 }, account?, timeoutMs? }
43
+ *
44
+ * Returns:
45
+ * - readClient: always present (public client)
46
+ * - writeClient: present when an account is provided (wallet client)
47
+ */
48
+ export declare function createEvmClients(opts: EvmClientsOptions): EvmClients;
49
+ export {};
@@ -0,0 +1,149 @@
1
+ /**
2
+ * StorageHubClient - Unified EVM client for StorageHub blockchain
3
+ *
4
+ * Provides ergonomic read/write methods for StorageHub precompiles using viem.
5
+ * Handles gas estimation automatically with Frontier-optimized defaults.
6
+ *
7
+ * All arguments are strongly typed. String data (names, paths) are passed as strings and encoded internally.
8
+ * Binary data (signatures) are passed as Uint8Array. Hex values are 0x-prefixed strings (32-byte IDs).
9
+ */
10
+ import { filesystemAbi } from "../abi/filesystem";
11
+ import type { EvmWriteOptions, StorageHubClientOptions } from "./types";
12
+ import type { ReplicationLevel } from "./types";
13
+ import { type Address } from "viem";
14
+ export { filesystemAbi };
15
+ export declare class StorageHubClient {
16
+ private readonly publicClient;
17
+ private readonly walletClient;
18
+ private readonly filesystemContractAddress;
19
+ private static readonly MAX_BUCKET_NAME_BYTES;
20
+ private static readonly MAX_LOCATION_BYTES;
21
+ private static readonly MAX_PEER_ID_BYTES;
22
+ private static readonly DEFAULT_GAS_MULTIPLIER;
23
+ private static readonly DEFAULT_GAS_PRICE;
24
+ /**
25
+ * Get write contract instance bound to the wallet client.
26
+ *
27
+ * @returns Contract instance for write operations (transactions)
28
+ */
29
+ private getWriteContract;
30
+ /**
31
+ * Get read contract instance bound to the public client.
32
+ *
33
+ * @returns Contract instance for read operations (view calls)
34
+ */
35
+ private getReadContract;
36
+ /**
37
+ * Reusable gas estimation for any contract method.
38
+ *
39
+ * Uses internal PublicClient for reliable estimation on Frontier chains.
40
+ * Applies safety multiplier to handle weight→gas conversion issues.
41
+ *
42
+ * @param functionName - Contract method name
43
+ * @param args - Method arguments
44
+ * @param options - Gas overrides (explicit gas, multiplier, etc.)
45
+ * @returns Estimated gas limit with safety multiplier applied
46
+ */
47
+ private estimateGas;
48
+ /**
49
+ * Build transaction options with gas and fee settings.
50
+ * Handles both legacy and EIP-1559 fee structures.
51
+ */
52
+ private buildTxOptions;
53
+ /**
54
+ * Validate string length in UTF-8 bytes and convert to hex.
55
+ * @param str - Input string to validate and encode
56
+ * @param maxBytes - Maximum allowed byte length
57
+ * @param label - Label for error messages
58
+ * @returns 0x-prefixed hex string
59
+ */
60
+ private validateStringLength;
61
+ /**
62
+ * Create a StorageHub client with automatic gas estimation.
63
+ *
64
+ * @param opts.rpcUrl - RPC endpoint URL for the StorageHub chain
65
+ * @param opts.chain - Viem chain configuration
66
+ * @param opts.walletClient - Wallet client for transaction signing
67
+ * @param opts.filesystemContractAddress - Optional filesystem precompile address
68
+ */
69
+ constructor(opts: StorageHubClientOptions);
70
+ /**
71
+ * Derive a bucket ID deterministically from owner + name.
72
+ * @param owner - EVM address of the bucket owner
73
+ * @param name - bucket name as string (max 100 UTF-8 bytes)
74
+ * @returns bucketId as 0x-prefixed 32-byte hex
75
+ */
76
+ deriveBucketId(owner: Address, name: string): Promise<unknown> | undefined;
77
+ /**
78
+ * Get how many file deletion requests a user currently has pending.
79
+ * @param user - user EVM address
80
+ * @returns count as number
81
+ */
82
+ getPendingFileDeletionRequestsCount(user: Address): Promise<unknown> | undefined;
83
+ /**
84
+ * Create a new bucket.
85
+ * @param mspId - 32-byte MSP ID (0x-prefixed hex)
86
+ * @param name - bucket name as string (max 100 UTF-8 bytes)
87
+ * @param isPrivate - true for private bucket
88
+ * @param valuePropId - 32-byte value proposition ID (0x-prefixed hex)
89
+ * @param options - optional gas and fee overrides
90
+ */
91
+ createBucket(mspId: `0x${string}`, name: string, isPrivate: boolean, valuePropId: `0x${string}`, options?: EvmWriteOptions): Promise<`0x${string}` | undefined>;
92
+ /**
93
+ * Request moving a bucket to a new MSP/value proposition.
94
+ * @param bucketId - 32-byte bucket ID
95
+ * @param newMspId - 32-byte new MSP ID
96
+ * @param newValuePropId - 32-byte new value proposition ID
97
+ * @param options - optional gas and fee overrides
98
+ */
99
+ requestMoveBucket(bucketId: `0x${string}`, newMspId: `0x${string}`, newValuePropId: `0x${string}`, options?: EvmWriteOptions): Promise<`0x${string}` | undefined>;
100
+ /**
101
+ * Update bucket privacy flag.
102
+ * @param bucketId - 32-byte bucket ID
103
+ * @param isPrivate - true for private
104
+ * @param options - optional gas and fee overrides
105
+ */
106
+ updateBucketPrivacy(bucketId: `0x${string}`, isPrivate: boolean, options?: EvmWriteOptions): Promise<`0x${string}` | undefined>;
107
+ /**
108
+ * Create and associate a collection with a bucket.
109
+ * @param bucketId - 32-byte bucket ID
110
+ * @param options - optional gas and fee overrides
111
+ */
112
+ createAndAssociateCollectionWithBucket(bucketId: `0x${string}`, options?: EvmWriteOptions): Promise<`0x${string}` | undefined>;
113
+ /**
114
+ * Delete an empty bucket.
115
+ * @param bucketId - 32-byte bucket ID
116
+ * @param options - optional gas and fee overrides
117
+ */
118
+ deleteBucket(bucketId: `0x${string}`, options?: EvmWriteOptions): Promise<`0x${string}` | undefined>;
119
+ /**
120
+ * Issue a storage request for a file.
121
+ * @param bucketId - 32-byte bucket ID
122
+ * @param location - file path as string (max 512 UTF-8 bytes)
123
+ * @param fingerprint - 32-byte file fingerprint
124
+ * @param size - file size as bigint (storage units)
125
+ * @param mspId - 32-byte MSP ID
126
+ * @param peerIds - array of peer ID strings (max 5 entries, each max 100 UTF-8 bytes)
127
+ * @param replicationLevel - replication level
128
+ * @param replicas - number of replicas (only required for ReplicationLevel.Custom)
129
+ * @param options - optional gas and fee overrides
130
+ */
131
+ issueStorageRequest(bucketId: `0x${string}`, location: string, fingerprint: `0x${string}`, size: bigint, mspId: `0x${string}`, peerIds: string[], replicationLevel: ReplicationLevel, replicas: number, options?: EvmWriteOptions): Promise<`0x${string}` | undefined>;
132
+ /**
133
+ * Revoke a pending storage request by file key.
134
+ * @param fileKey - 32-byte file key
135
+ * @param options - optional gas and fee overrides
136
+ */
137
+ revokeStorageRequest(fileKey: `0x${string}`, options?: EvmWriteOptions): Promise<`0x${string}` | undefined>;
138
+ /**
139
+ * Request deletion of a file using a signed intention.
140
+ * @param signedIntention - tuple [fileKey: 0x32, operation: number] where operation must be 0 (Delete)
141
+ * @param signature - 65-byte secp256k1 signature over the SCALE-encoded intention
142
+ * @param bucketId - 32-byte bucket ID
143
+ * @param location - file path as string (max 512 UTF-8 bytes)
144
+ * @param size - file size as bigint (storage units)
145
+ * @param fingerprint - 32-byte file fingerprint
146
+ * @param options - optional gas and fee overrides
147
+ */
148
+ requestDeleteFile(signedIntention: readonly [`0x${string}`, number], signature: Uint8Array, bucketId: `0x${string}`, location: string, size: bigint, fingerprint: `0x${string}`, options?: EvmWriteOptions): Promise<`0x${string}` | undefined>;
149
+ }