@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.
- package/README.md +132 -0
- package/dist/_wasm_embed.d.ts +1 -1
- package/dist/abi/FileSystem.abi.json +427 -0
- package/dist/abi/filesystem.d.ts +49 -0
- package/dist/evm/clients.d.ts +49 -0
- package/dist/evm/storageHubClient.d.ts +149 -0
- package/dist/evm/types.d.ts +77 -0
- package/dist/file-manager.d.ts +9 -2
- package/dist/http/HttpClient.d.ts +1 -1
- package/dist/index.browser.js +1 -1
- package/dist/index.browser.js.map +4 -4
- package/dist/index.d.ts +13 -7
- package/dist/index.node.js +1 -1
- package/dist/index.node.js.map +4 -4
- package/dist/wallet/base.d.ts +1 -1
- package/dist/wallet/eip1193.d.ts +2 -2
- package/dist/wallet/errors.d.ts +1 -1
- package/dist/wallet/local.d.ts +2 -2
- package/dist/wasm.d.ts +1 -1
- package/package.json +22 -18
- package/wasm/pkg/storagehub_wasm.d.ts +10 -4
- package/wasm/pkg/storagehub_wasm.js +16 -5
- package/wasm/pkg/storagehub_wasm_bg.wasm +0 -0
- package/wasm/pkg/storagehub_wasm_bg.wasm.d.ts +5 -4
package/README.md
CHANGED
|
@@ -31,7 +31,139 @@ import { HttpClient, type HttpClientConfig } from '@storagehub-sdk/core';
|
|
|
31
31
|
const http = new HttpClient({
|
|
32
32
|
baseUrl: 'https://example.invalid',
|
|
33
33
|
} satisfies HttpClientConfig);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### EVM Integration with StorageHub
|
|
37
|
+
|
|
38
|
+
The Core SDK provides seamless integration with StorageHub's EVM precompiles, offering automatic gas estimation, type safety, and a clean developer experience.
|
|
39
|
+
|
|
40
|
+
#### ABI Generation
|
|
41
|
+
- Solidity contracts are automatically compiled to ABI during `prebuild` using `solc-js`
|
|
42
|
+
- Generated ABIs are strongly typed using `viem` and `abitype`
|
|
43
|
+
- No code generation required - pure TypeScript type inference
|
|
44
|
+
|
|
45
|
+
#### StorageHubClient - Unified EVM Interface
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { StorageHubClient } from '@storagehub-sdk/core';
|
|
49
|
+
import { createWalletClient, defineChain, http } from 'viem';
|
|
50
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
51
|
+
|
|
52
|
+
// Define your StorageHub chain
|
|
53
|
+
const storageHubChain = defineChain({
|
|
54
|
+
id: 181222,
|
|
55
|
+
name: 'StorageHub',
|
|
56
|
+
nativeCurrency: { name: 'StorageHub', symbol: 'SH', decimals: 18 },
|
|
57
|
+
rpcUrls: { default: { http: ['http://localhost:9944'] } },
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Create wallet client
|
|
61
|
+
const account = privateKeyToAccount('0x...');
|
|
62
|
+
const walletClient = createWalletClient({
|
|
63
|
+
chain: storageHubChain,
|
|
64
|
+
account,
|
|
65
|
+
transport: http('http://localhost:9944')
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Create StorageHub client - handles everything automatically
|
|
69
|
+
const hub = new StorageHubClient({
|
|
70
|
+
rpcUrl: 'http://localhost:9944',
|
|
71
|
+
chain: storageHubChain,
|
|
72
|
+
walletClient
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### Basic Usage
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
// Read operations (no gas required)
|
|
80
|
+
const name = new TextEncoder().encode('my-bucket');
|
|
81
|
+
const bucketId = await hub.deriveBucketId('0xOwnerAddress', name);
|
|
82
|
+
const pendingRequests = await hub.getPendingFileDeletionRequestsCount('0xUserAddress');
|
|
83
|
+
|
|
84
|
+
// Write operations (automatic gas estimation)
|
|
85
|
+
const txHash = await hub.createBucket(
|
|
86
|
+
'0xMspId', // MSP ID
|
|
87
|
+
name, // Bucket name (max 100 bytes)
|
|
88
|
+
false, // isPrivate
|
|
89
|
+
'0xValuePropId' // Value proposition ID
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Write with custom gas options
|
|
93
|
+
const txHash2 = await hub.updateBucketPrivacy('0xBucketId', true, {
|
|
94
|
+
gasMultiplier: 8, // Higher safety margin
|
|
95
|
+
gasPrice: parseGwei('2') // Custom gas price
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### Available Methods
|
|
100
|
+
|
|
101
|
+
**Bucket Management:**
|
|
102
|
+
- `createBucket(mspId, name, isPrivate, valuePropId, options?)`
|
|
103
|
+
- `deleteBucket(bucketId, options?)`
|
|
104
|
+
- `updateBucketPrivacy(bucketId, isPrivate, options?)`
|
|
105
|
+
- `requestMoveBucket(bucketId, newMspId, newValuePropId, options?)`
|
|
106
|
+
|
|
107
|
+
**Storage Operations:**
|
|
108
|
+
- `issueStorageRequest(bucketId, location, fingerprint, size, mspId, peerIds, replicationTarget, customReplicationTarget, options?)`
|
|
109
|
+
- `revokeStorageRequest(fileKey, options?)`
|
|
110
|
+
- `requestDeleteFile(signedIntention, signature, bucketId, location, size, fingerprint, options?)`
|
|
111
|
+
|
|
112
|
+
**Collections:**
|
|
113
|
+
- `createAndAssociateCollectionWithBucket(bucketId, options?)`
|
|
114
|
+
|
|
115
|
+
**Read Operations:**
|
|
116
|
+
- `deriveBucketId(owner, name)`
|
|
117
|
+
- `getPendingFileDeletionRequestsCount(user)`
|
|
118
|
+
|
|
119
|
+
#### Gas Handling
|
|
120
|
+
|
|
121
|
+
The SDK provides intelligent gas estimation with Frontier chain optimizations:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
// Automatic gas estimation (recommended)
|
|
125
|
+
await hub.createBucket(mspId, name, false, valuePropId);
|
|
126
|
+
|
|
127
|
+
// Custom gas options
|
|
128
|
+
await hub.createBucket(mspId, name, false, valuePropId, {
|
|
129
|
+
gasMultiplier: 6, // Safety multiplier (default: 5)
|
|
130
|
+
gasPrice: parseGwei('1.5'), // Legacy gas pricing
|
|
131
|
+
// OR EIP-1559 fees:
|
|
132
|
+
maxFeePerGas: parseGwei('2'),
|
|
133
|
+
maxPriorityFeePerGas: parseGwei('0.5')
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Explicit gas limit
|
|
137
|
+
await hub.createBucket(mspId, name, false, valuePropId, {
|
|
138
|
+
gas: 500_000n // Skip estimation, use exact amount
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### Error Handling
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
try {
|
|
146
|
+
await hub.createBucket(mspId, name, false, valuePropId);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (error.message.includes('exceeds maximum length')) {
|
|
149
|
+
// Handle validation errors
|
|
150
|
+
} else if (error.message.includes('OutOfGas')) {
|
|
151
|
+
// Handle gas estimation issues
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### Type Safety
|
|
157
|
+
|
|
158
|
+
All methods are fully typed with parameter validation:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
// ✅ Type-safe parameters
|
|
162
|
+
const name = new TextEncoder().encode('bucket-name'); // Uint8Array
|
|
163
|
+
const mspId = '0x...' as `0x${string}`; // Hex string type
|
|
34
164
|
|
|
165
|
+
// ❌ Compile-time errors for invalid types
|
|
166
|
+
await hub.createBucket('invalid', 'string', false, mspId); // TypeScript error
|
|
35
167
|
```
|
|
36
168
|
|
|
37
169
|
### Local wallet
|