@shelby-protocol/sdk 0.3.0 → 0.4.0
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/browser/index.d.ts +19 -10
- package/dist/browser/index.mjs +4200 -146
- package/dist/core/aptos-explorer.mjs +46 -5
- package/dist/core/blobs.mjs +12 -4
- package/dist/core/chunk.mjs +58 -9
- package/dist/core/clients/ShelbyBlobClient.d.ts +155 -83
- package/dist/core/clients/ShelbyBlobClient.mjs +1286 -17
- package/dist/core/clients/ShelbyClient.d.ts +39 -6
- package/dist/core/clients/ShelbyClient.mjs +3233 -23
- package/dist/core/clients/ShelbyClientConfig.d.ts +9 -1
- package/dist/core/clients/ShelbyClientConfig.mjs +0 -1
- package/dist/core/clients/ShelbyMetadataClient.d.ts +20 -6
- package/dist/core/clients/ShelbyMetadataClient.mjs +388 -6
- package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +7 -7
- package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +894 -13
- package/dist/core/clients/ShelbyPlacementGroupClient.mjs +310 -8
- package/dist/core/clients/ShelbyRPCClient.d.ts +117 -25
- package/dist/core/clients/ShelbyRPCClient.mjs +1245 -12
- package/dist/core/clients/index.d.ts +4 -2
- package/dist/core/clients/index.mjs +3802 -39
- package/dist/core/clients/utils.mjs +65 -6
- package/dist/core/commitments.d.ts +12 -1
- package/dist/core/commitments.mjs +277 -11
- package/dist/core/constants.d.ts +3 -3
- package/dist/core/constants.mjs +39 -16
- package/dist/core/erasure/clay-codes.mjs +129 -4
- package/dist/core/erasure/constants.d.ts +16 -1
- package/dist/core/erasure/constants.mjs +48 -11
- package/dist/core/erasure/default.mjs +191 -9
- package/dist/core/erasure/index.d.ts +1 -1
- package/dist/core/erasure/index.mjs +281 -24
- package/dist/core/erasure/reed-solomon.mjs +68 -4
- package/dist/core/erasure/utils.mjs +0 -2
- package/dist/core/errors.d.ts +20 -1
- package/dist/core/errors.mjs +58 -8
- package/dist/core/index.d.ts +9 -9
- package/dist/core/index.mjs +4194 -146
- package/dist/core/layout.mjs +37 -5
- package/dist/core/networks.mjs +10 -5
- package/dist/core/operations/generated/sdk.d.ts +807 -42
- package/dist/core/operations/generated/sdk.mjs +267 -18
- package/dist/core/operations/index.d.ts +1 -1
- package/dist/core/operations/index.mjs +368 -24
- package/dist/core/promises.mjs +4 -4
- package/dist/core/rpc-responses.d.ts +1 -57
- package/dist/core/rpc-responses.mjs +14 -15
- package/dist/core/shelby-explorer.mjs +31 -6
- package/dist/core/sp/chunk_proof.d.ts +23 -0
- package/dist/core/sp/chunk_proof.mjs +113 -0
- package/dist/core/sp/index.d.ts +3 -0
- package/dist/core/sp/index.mjs +402 -0
- package/dist/core/sp/sp_write_client.d.ts +53 -0
- package/dist/core/sp/sp_write_client.mjs +302 -0
- package/dist/core/strings.mjs +0 -2
- package/dist/core/types/blobs.d.ts +24 -5
- package/dist/core/types/blobs.mjs +24 -1
- package/dist/core/types/index.d.ts +2 -2
- package/dist/core/types/index.mjs +275 -10
- package/dist/core/types/payments.d.ts +6 -6
- package/dist/core/types/payments.mjs +230 -5
- package/dist/core/types/placement_groups.mjs +0 -1
- package/dist/core/types/storage_providers.d.ts +32 -6
- package/dist/core/types/storage_providers.mjs +22 -1
- package/dist/core/utils.mjs +94 -8
- package/dist/gen/rpc_server_pb.d.ts +295 -0
- package/dist/gen/rpc_server_pb.mjs +28 -0
- package/dist/node/clients/ShelbyNodeClient.d.ts +2 -0
- package/dist/node/clients/ShelbyNodeClient.mjs +3237 -24
- package/dist/node/clients/index.d.ts +2 -0
- package/dist/node/clients/index.mjs +3236 -26
- package/dist/node/index.d.ts +9 -9
- package/dist/node/index.mjs +4217 -153
- package/dist/node/parallel/commitment_worker.d.ts +9 -0
- package/dist/node/parallel/commitment_worker.mjs +85 -0
- package/dist/node/parallel/commitment_worker_pool.d.ts +35 -0
- package/dist/node/parallel/commitment_worker_pool.mjs +339 -0
- package/dist/node/parallel/coverage_flush.d.ts +16 -0
- package/dist/node/parallel/coverage_flush.mjs +43 -0
- package/dist/node/parallel/default_commitment_worker_pool.d.ts +24 -0
- package/dist/node/parallel/default_commitment_worker_pool.mjs +355 -0
- package/dist/node/parallel/index.d.ts +12 -0
- package/dist/node/parallel/index.mjs +631 -0
- package/dist/node/parallel/parallel_commitments.d.ts +32 -0
- package/dist/node/parallel/parallel_commitments.mjs +614 -0
- package/dist/node/parallel/worker_pool.d.ts +74 -0
- package/dist/node/parallel/worker_pool.mjs +301 -0
- package/dist/node/testUtil.mjs +8 -4
- package/package.json +16 -5
- package/dist/chunk-3NRBHSMQ.mjs +0 -12
- package/dist/chunk-5BVSWXQJ.mjs +0 -801
- package/dist/chunk-6FJNAUU5.mjs +0 -278
- package/dist/chunk-6XSZRDLJ.mjs +0 -375
- package/dist/chunk-7P6ASYW6.mjs +0 -9
- package/dist/chunk-A4IG6GSE.mjs +0 -21
- package/dist/chunk-AD2G3QYD.mjs +0 -0
- package/dist/chunk-AUQDI5BS.mjs +0 -43
- package/dist/chunk-AY3HBWXA.mjs +0 -51
- package/dist/chunk-BDSW5PHM.mjs +0 -37
- package/dist/chunk-C6RQ3AEU.mjs +0 -51
- package/dist/chunk-CQ6QPIZK.mjs +0 -37
- package/dist/chunk-D6GQHO6G.mjs +0 -15
- package/dist/chunk-EM67QTMR.mjs +0 -0
- package/dist/chunk-I6NG5GNL.mjs +0 -8
- package/dist/chunk-JTXYKO3U.mjs +0 -38
- package/dist/chunk-KG2TMLEV.mjs +0 -207
- package/dist/chunk-M3CP5TFP.mjs +0 -39
- package/dist/chunk-M7W43K2Q.mjs +0 -505
- package/dist/chunk-MB7C7VQF.mjs +0 -0
- package/dist/chunk-MNCQBEMS.mjs +0 -55
- package/dist/chunk-MQUVYMNQ.mjs +0 -0
- package/dist/chunk-NEO7Z3ZQ.mjs +0 -49
- package/dist/chunk-NHWWORCH.mjs +0 -72
- package/dist/chunk-OEK24ON7.mjs +0 -135
- package/dist/chunk-QQ57OGQ2.mjs +0 -0
- package/dist/chunk-RNNJXTX2.mjs +0 -154
- package/dist/chunk-S6Q4OG7H.mjs +0 -83
- package/dist/chunk-TET3DJEO.mjs +0 -199
- package/dist/chunk-UEZNZBJO.mjs +0 -104
- package/dist/chunk-V46D5NBW.mjs +0 -11
- package/dist/chunk-V4B3GAMQ.mjs +0 -42
- package/dist/chunk-WFWRBNTW.mjs +0 -412
- package/dist/chunk-WTICJPDB.mjs +0 -0
- package/dist/chunk-XNEIWM4O.mjs +0 -0
- package/dist/chunk-Z4FZ7W6L.mjs +0 -39
- package/dist/chunk-Z7RFCADT.mjs +0 -0
- package/dist/chunk-ZHXCVRZX.mjs +0 -0
package/dist/chunk-6FJNAUU5.mjs
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getAptosConfig
|
|
3
|
-
} from "./chunk-V4B3GAMQ.mjs";
|
|
4
|
-
import {
|
|
5
|
-
normalizeAddress
|
|
6
|
-
} from "./chunk-UEZNZBJO.mjs";
|
|
7
|
-
import {
|
|
8
|
-
SHELBY_DEPLOYER
|
|
9
|
-
} from "./chunk-MNCQBEMS.mjs";
|
|
10
|
-
|
|
11
|
-
// src/core/clients/ShelbyMetadataClient.ts
|
|
12
|
-
import {
|
|
13
|
-
AccountAddress,
|
|
14
|
-
Aptos,
|
|
15
|
-
Hex
|
|
16
|
-
} from "@aptos-labs/ts-sdk";
|
|
17
|
-
function parseStorageProviderState(raw) {
|
|
18
|
-
switch (raw.__variant__) {
|
|
19
|
-
case "Active":
|
|
20
|
-
return {
|
|
21
|
-
variant: "Active",
|
|
22
|
-
quota: raw.quota.value,
|
|
23
|
-
stakeAtStartOfStakingEpoch: raw.stake_at_start_of_staking_epoch,
|
|
24
|
-
faulty: raw.faulty,
|
|
25
|
-
leaving: raw.leaving
|
|
26
|
-
};
|
|
27
|
-
case "Waitlisted":
|
|
28
|
-
return {
|
|
29
|
-
variant: "Waitlisted"
|
|
30
|
-
};
|
|
31
|
-
case "Frozen":
|
|
32
|
-
return {
|
|
33
|
-
variant: "Frozen",
|
|
34
|
-
frozenReason: raw.frozen_reason,
|
|
35
|
-
frozenFrom: raw.frozen_from,
|
|
36
|
-
frozenTill: raw.frozen_till
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
var ShelbyMetadataClient = class {
|
|
41
|
-
aptos;
|
|
42
|
-
deployer;
|
|
43
|
-
/**
|
|
44
|
-
* The ShelbyMetadataClient is used to interact with the Shelby contract on the Aptos blockchain. This
|
|
45
|
-
* includes functions like gathering basic details about the Shelby system, including storage provider information.
|
|
46
|
-
*
|
|
47
|
-
* @param config.aptos.config - The Aptos config.
|
|
48
|
-
* @param config.shelbyDeployer - The deployer account address of the Shelby contract. If not provided, the default deployer address will be used.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* const aptos = new Aptos(new AptosConfig({ network: Network.TESTNET }));
|
|
53
|
-
* const metadataClient = new ShelbyMetadataClient({ aptos });
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
constructor(config) {
|
|
57
|
-
this.aptos = new Aptos(getAptosConfig(config));
|
|
58
|
-
this.deployer = config.deployer ?? AccountAddress.fromString(SHELBY_DEPLOYER);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Retrieves storage provider list from the blockchain.
|
|
62
|
-
*
|
|
63
|
-
* @returns A list of storage providers, or empty array if none exist.
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```typescript
|
|
67
|
-
* const spList = await client.getStorageProviders();
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
async getStorageProviders() {
|
|
71
|
-
try {
|
|
72
|
-
const rawMetadata = await this.aptos.view({
|
|
73
|
-
payload: {
|
|
74
|
-
function: `${this.deployer.toString()}::storage_provider_registry::get_all_storage_providers`,
|
|
75
|
-
functionArguments: []
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
const metadata = rawMetadata[0];
|
|
79
|
-
return metadata.map((provider) => ({
|
|
80
|
-
address: normalizeAddress(provider.address),
|
|
81
|
-
ipAddress: provider.ip_address,
|
|
82
|
-
port: provider.port,
|
|
83
|
-
blsPublicKey: Hex.fromHexInput(provider.bls_public_key).toUint8Array(),
|
|
84
|
-
availabilityZone: provider.availability_zone,
|
|
85
|
-
state: parseStorageProviderState(provider.state)
|
|
86
|
-
}));
|
|
87
|
-
} catch (error) {
|
|
88
|
-
if (error instanceof Error && // Depending on the network, the error message may show up differently.
|
|
89
|
-
error.message?.includes("sub_status: Some(404)")) {
|
|
90
|
-
return [];
|
|
91
|
-
}
|
|
92
|
-
throw error;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Retrieves the list of placement group addresses.
|
|
97
|
-
*
|
|
98
|
-
* @returns The placement group address list, or an empty array if none exist.
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```typescript
|
|
102
|
-
* const pgList = await client.getPlacementGroupAddresses();
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
async getPlacementGroupAddresses() {
|
|
106
|
-
try {
|
|
107
|
-
const pgSizeMetadata = await this.aptos.view({
|
|
108
|
-
payload: {
|
|
109
|
-
function: `${this.deployer.toString()}::placement_group_registry::get_number_of_placement_groups`,
|
|
110
|
-
functionArguments: []
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
const finalPlacementGroupIndex = pgSizeMetadata[0] - 1;
|
|
114
|
-
const addressMetadataArray = await this.aptos.view({
|
|
115
|
-
payload: {
|
|
116
|
-
function: `${this.deployer.toString()}::placement_group_registry::get_placement_group_addresses`,
|
|
117
|
-
functionArguments: [0, finalPlacementGroupIndex]
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
const metadata = addressMetadataArray[0];
|
|
121
|
-
return metadata.map((pg) => normalizeAddress(pg));
|
|
122
|
-
} catch (error) {
|
|
123
|
-
if (error instanceof Error && // Depending on the network, the error message may show up differently.
|
|
124
|
-
(error.message?.includes("sub_status: Some(404)") || error.message?.includes("E_PLACEMENT_GROUP_NOT_FOUND"))) {
|
|
125
|
-
return [];
|
|
126
|
-
}
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Retrieves the list of slice addresses.
|
|
132
|
-
*
|
|
133
|
-
* @returns The slice group list, or an empty array if none exist.
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* ```typescript
|
|
137
|
-
* const pgList = await client.getSliceAddresses();
|
|
138
|
-
* ```
|
|
139
|
-
*/
|
|
140
|
-
async getSliceAddresses() {
|
|
141
|
-
try {
|
|
142
|
-
const sliceSizeMetadata = await this.aptos.view({
|
|
143
|
-
payload: {
|
|
144
|
-
function: `${this.deployer.toString()}::slice_registry::get_number_of_slices`,
|
|
145
|
-
functionArguments: []
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
const finalSliceIndex = sliceSizeMetadata[0] - 1;
|
|
149
|
-
const addressMetadataArray = await this.aptos.view({
|
|
150
|
-
payload: {
|
|
151
|
-
function: `${this.deployer.toString()}::slice_registry::get_slice_addresses`,
|
|
152
|
-
functionArguments: [0, finalSliceIndex]
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
const metadata = addressMetadataArray[0];
|
|
156
|
-
return metadata.map((slice) => normalizeAddress(slice));
|
|
157
|
-
} catch (error) {
|
|
158
|
-
if (error instanceof Error && // Depending on the network, the error message may show up differently.
|
|
159
|
-
(error.message?.includes("sub_status: Some(404)") || error.message?.includes("E_SLICE_NOT_FOUND"))) {
|
|
160
|
-
return [];
|
|
161
|
-
}
|
|
162
|
-
throw error;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Gets the placement group address for a slice.
|
|
167
|
-
*
|
|
168
|
-
* @param sliceAddress - The address of the slice account.
|
|
169
|
-
* @returns The placement group address as a string.
|
|
170
|
-
*/
|
|
171
|
-
async getPlacementGroupAddressForSlice(sliceAddress) {
|
|
172
|
-
const sliceMetadata = await this.aptos.view({
|
|
173
|
-
payload: {
|
|
174
|
-
function: `${this.deployer.toString()}::slice::get_slice_info`,
|
|
175
|
-
functionArguments: [sliceAddress.toString()]
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
return sliceMetadata[0].placement_group_assignments[0].placement_group_address;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Retrieves the designated storage providers for a slice.
|
|
182
|
-
*
|
|
183
|
-
* Designated SPs are those appointed to store data for their slots:
|
|
184
|
-
* - Active: Currently serving data
|
|
185
|
-
* - Receiving: Receiving data during slot transfer
|
|
186
|
-
* - Repairing: Repairing data after crash or failed transfer
|
|
187
|
-
* - Reconstructing: Reconstructing data if the repair fails
|
|
188
|
-
*
|
|
189
|
-
* @param params.account - The address of the slice account.
|
|
190
|
-
* @returns An array where result[i] is the designated SP for slot i, or null if no SP is designated.
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* ```typescript
|
|
194
|
-
* const providers = await client.getDesignatedStorageProvidersForSlice({ account: sliceAddress });
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
197
|
-
async getDesignatedStorageProvidersForSlice(params) {
|
|
198
|
-
const placementGroupAddress = await this.getPlacementGroupAddressForSlice(
|
|
199
|
-
params.account
|
|
200
|
-
);
|
|
201
|
-
const rawMetadata = await this.aptos.view({
|
|
202
|
-
payload: {
|
|
203
|
-
function: `${this.deployer.toString()}::placement_group::get_designated_storage_providers`,
|
|
204
|
-
functionArguments: [placementGroupAddress]
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
const providers = rawMetadata[0];
|
|
208
|
-
return providers.map(
|
|
209
|
-
(opt) => opt.vec.length > 0 ? normalizeAddress(opt.vec[0]) : null
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Retrieves the active storage providers for a slice.
|
|
214
|
-
*
|
|
215
|
-
* Active SPs have a complete copy of the data for the slot, and are not in any data transfer/repair/reconstruction phase.
|
|
216
|
-
* Active SP can be audited for the data it contains.
|
|
217
|
-
* Each slot has at most one active SP.
|
|
218
|
-
*
|
|
219
|
-
* @param params.account - The address of the slice account.
|
|
220
|
-
* @returns An array where result[i] is the active SP for slot i, or null if no SP is active.
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```typescript
|
|
224
|
-
* const providers = await client.getActiveStorageProvidersForSlice({ account: sliceAddress });
|
|
225
|
-
* ```
|
|
226
|
-
*/
|
|
227
|
-
async getActiveStorageProvidersForSlice(params) {
|
|
228
|
-
const placementGroupAddress = await this.getPlacementGroupAddressForSlice(
|
|
229
|
-
params.account
|
|
230
|
-
);
|
|
231
|
-
const rawMetadata = await this.aptos.view({
|
|
232
|
-
payload: {
|
|
233
|
-
function: `${this.deployer.toString()}::placement_group::get_active_storage_providers`,
|
|
234
|
-
functionArguments: [placementGroupAddress]
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
const providers = rawMetadata[0];
|
|
238
|
-
return providers.map(
|
|
239
|
-
(opt) => opt.vec.length > 0 ? normalizeAddress(opt.vec[0]) : null
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Retrieves the serving storage providers for a slice.
|
|
244
|
-
*
|
|
245
|
-
* Serving SPs are those that can respond to read requests. The serving logic is:
|
|
246
|
-
* - If an Active SP exists for a slot: Only the Active SP is serving
|
|
247
|
-
* - If no Active SP (transition in progress): Both Designated and Vacating SPs serve
|
|
248
|
-
*
|
|
249
|
-
* Each slot may have multiple serving SPs during transitions.
|
|
250
|
-
*
|
|
251
|
-
* @param params.account - The address of the slice account.
|
|
252
|
-
* @returns An array where result[i] contains the serving SPs for slot i.
|
|
253
|
-
*
|
|
254
|
-
* @example
|
|
255
|
-
* ```typescript
|
|
256
|
-
* const providers = await client.getServingStorageProvidersForSlice({ account: sliceAddress });
|
|
257
|
-
* ```
|
|
258
|
-
*/
|
|
259
|
-
async getServingStorageProvidersForSlice(params) {
|
|
260
|
-
const placementGroupAddress = await this.getPlacementGroupAddressForSlice(
|
|
261
|
-
params.account
|
|
262
|
-
);
|
|
263
|
-
const rawMetadata = await this.aptos.view({
|
|
264
|
-
payload: {
|
|
265
|
-
function: `${this.deployer.toString()}::placement_group::get_serving_storage_providers`,
|
|
266
|
-
functionArguments: [placementGroupAddress]
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
const providers = rawMetadata[0];
|
|
270
|
-
return providers.map(
|
|
271
|
-
(slotProviders) => slotProviders.map((addr) => normalizeAddress(addr))
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
export {
|
|
277
|
-
ShelbyMetadataClient
|
|
278
|
-
};
|
package/dist/chunk-6XSZRDLJ.mjs
DELETED
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ShelbyRPCClient
|
|
3
|
-
} from "./chunk-WFWRBNTW.mjs";
|
|
4
|
-
import {
|
|
5
|
-
ShelbyBlobClient
|
|
6
|
-
} from "./chunk-5BVSWXQJ.mjs";
|
|
7
|
-
import {
|
|
8
|
-
defaultErasureCodingConfig
|
|
9
|
-
} from "./chunk-AY3HBWXA.mjs";
|
|
10
|
-
import {
|
|
11
|
-
ClayErasureCodingProvider
|
|
12
|
-
} from "./chunk-OEK24ON7.mjs";
|
|
13
|
-
import {
|
|
14
|
-
ShelbyMetadataClient
|
|
15
|
-
} from "./chunk-6FJNAUU5.mjs";
|
|
16
|
-
import {
|
|
17
|
-
getAptosConfig,
|
|
18
|
-
getShelbyRPCBaseUrl
|
|
19
|
-
} from "./chunk-V4B3GAMQ.mjs";
|
|
20
|
-
import {
|
|
21
|
-
createBlobKey
|
|
22
|
-
} from "./chunk-3NRBHSMQ.mjs";
|
|
23
|
-
import {
|
|
24
|
-
generateCommitments
|
|
25
|
-
} from "./chunk-RNNJXTX2.mjs";
|
|
26
|
-
import {
|
|
27
|
-
normalizeAddress
|
|
28
|
-
} from "./chunk-UEZNZBJO.mjs";
|
|
29
|
-
|
|
30
|
-
// src/core/clients/ShelbyClient.ts
|
|
31
|
-
import {
|
|
32
|
-
Aptos,
|
|
33
|
-
DEFAULT_TXN_TIMEOUT_SEC,
|
|
34
|
-
Network,
|
|
35
|
-
TransactionResponseType
|
|
36
|
-
} from "@aptos-labs/ts-sdk";
|
|
37
|
-
import pLimit from "p-limit";
|
|
38
|
-
var ShelbyClient = class {
|
|
39
|
-
/**
|
|
40
|
-
* The coordination client is used to interact with the Aptos blockchain which handles the commitments
|
|
41
|
-
* and metadata for blobs.
|
|
42
|
-
*/
|
|
43
|
-
coordination;
|
|
44
|
-
/**
|
|
45
|
-
* The metadata client is used for protocol-level metadata queries.
|
|
46
|
-
*/
|
|
47
|
-
metadata;
|
|
48
|
-
/**
|
|
49
|
-
* The RPC client is used to interact with the Shelby RPC node which can be responsible for storing,
|
|
50
|
-
* confirming, and retrieving blobs from the storage layer.
|
|
51
|
-
*
|
|
52
|
-
* If not provided, the default RPC client will be created.
|
|
53
|
-
*/
|
|
54
|
-
rpc;
|
|
55
|
-
/**
|
|
56
|
-
* The configuration for the Shelby client.
|
|
57
|
-
*/
|
|
58
|
-
config;
|
|
59
|
-
/**
|
|
60
|
-
* The Aptos client.
|
|
61
|
-
*
|
|
62
|
-
* If not provided, a default Aptos client will be created.
|
|
63
|
-
*/
|
|
64
|
-
aptos;
|
|
65
|
-
/**
|
|
66
|
-
* The erasure coding provider used for encoding/decoding operations.
|
|
67
|
-
* Lazily initialized on first use if not provided.
|
|
68
|
-
*/
|
|
69
|
-
_provider;
|
|
70
|
-
/**
|
|
71
|
-
* Creates a new ShelbyClient instance for interacting with the Shelby Protocol.
|
|
72
|
-
* This client combines blockchain operations (via coordination) and storage operations (via RPC).
|
|
73
|
-
*
|
|
74
|
-
* @param config - The client configuration object.
|
|
75
|
-
* @param config.aptos.config - The Aptos network configuration.
|
|
76
|
-
* @param config.shelby.rpc.baseUrl - The base URL of the Shelby RPC node (optional, defaults to devnet).
|
|
77
|
-
* @param config.shelby.indexer - The indexer configuration for GraphQL queries.
|
|
78
|
-
* @param provider - Optional erasure coding provider for encoding/decoding operations.
|
|
79
|
-
* If not provided, a ClayErasureCodingProvider will be created on first use.
|
|
80
|
-
* Pass a shared provider to reuse across multiple clients.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```typescript
|
|
84
|
-
* // Basic usage (provider created automatically)
|
|
85
|
-
* const client = new ShelbyClient({
|
|
86
|
-
* network: Network.SHELBYNET,
|
|
87
|
-
* });
|
|
88
|
-
*
|
|
89
|
-
* // Advanced: Share provider across multiple clients
|
|
90
|
-
* const provider = await ClayErasureCodingProvider.create();
|
|
91
|
-
* const mainnetClient = new ShelbyClient(mainnetConfig, provider);
|
|
92
|
-
* const devnetClient = new ShelbyClient(devnetConfig, provider);
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
constructor(config, provider) {
|
|
96
|
-
this.config = config;
|
|
97
|
-
this.aptos = new Aptos(getAptosConfig(config));
|
|
98
|
-
this.coordination = new ShelbyBlobClient(config);
|
|
99
|
-
this.metadata = new ShelbyMetadataClient(config);
|
|
100
|
-
this.rpc = new ShelbyRPCClient(config);
|
|
101
|
-
this._provider = provider;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Get the erasure coding provider, creating it if necessary.
|
|
105
|
-
* This allows lazy initialization for users who don't provide a provider.
|
|
106
|
-
*/
|
|
107
|
-
async getProvider() {
|
|
108
|
-
if (!this._provider) {
|
|
109
|
-
this._provider = await ClayErasureCodingProvider.create(
|
|
110
|
-
defaultErasureCodingConfig()
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
return this._provider;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* The base URL for the Shelby RPC node.
|
|
117
|
-
*/
|
|
118
|
-
get baseUrl() {
|
|
119
|
-
return getShelbyRPCBaseUrl(this.config);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Uploads a blob to the Shelby network.
|
|
123
|
-
* This method handles the complete upload flow including commitment generation,
|
|
124
|
-
* blockchain registration, and storage upload.
|
|
125
|
-
*
|
|
126
|
-
* Note: This method accepts only `Uint8Array` and buffers the entire blob in memory.
|
|
127
|
-
* For streaming uploads of large files (e.g. >2 GiB), orchestrate the steps manually
|
|
128
|
-
* using `generateCommitments()`, `coordination.registerBlob()`, and `rpc.putBlob()`
|
|
129
|
-
* with a `ReadableStream`.
|
|
130
|
-
*
|
|
131
|
-
* @param params.blobData - The raw data to upload as a Uint8Array.
|
|
132
|
-
* @param params.signer - The account that signs and pays for the transaction.
|
|
133
|
-
* @param params.blobName - The name/path of the blob (e.g. "folder/file.txt").
|
|
134
|
-
* @param params.expirationMicros - The expiration time in microseconds since Unix epoch.
|
|
135
|
-
* @param params.options - Optional upload configuration.
|
|
136
|
-
* @param params.options.chunksetSizeBytes - Custom chunkset size.
|
|
137
|
-
* @param params.options.build - Additional Aptos transaction options.
|
|
138
|
-
*
|
|
139
|
-
* @returns The transaction and generated blob commitments (when implemented).
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* ```typescript
|
|
143
|
-
* await client.upload({
|
|
144
|
-
* blobData: Buffer.from("Hello, World!"),
|
|
145
|
-
* signer: account,
|
|
146
|
-
* blobName: "hello.txt",
|
|
147
|
-
* expirationMicros: Date.now() * 1000 + 86400_000_000 // 24 hours from now
|
|
148
|
-
* });
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
async upload(params) {
|
|
152
|
-
const existingBlobMetadata = await this.coordination.getBlobMetadata({
|
|
153
|
-
account: params.signer.accountAddress,
|
|
154
|
-
name: params.blobName
|
|
155
|
-
});
|
|
156
|
-
if (!existingBlobMetadata) {
|
|
157
|
-
const provider = await this.getProvider();
|
|
158
|
-
const blobCommitments = await generateCommitments(
|
|
159
|
-
provider,
|
|
160
|
-
params.blobData
|
|
161
|
-
);
|
|
162
|
-
const { transaction: pendingRegisterBlobTransaction } = await this.coordination.registerBlob({
|
|
163
|
-
account: params.signer,
|
|
164
|
-
blobName: params.blobName,
|
|
165
|
-
blobMerkleRoot: blobCommitments.blob_merkle_root,
|
|
166
|
-
size: params.blobData.length,
|
|
167
|
-
expirationMicros: params.expirationMicros,
|
|
168
|
-
config: provider.config,
|
|
169
|
-
options: params.options
|
|
170
|
-
});
|
|
171
|
-
await this.coordination.aptos.waitForTransaction({
|
|
172
|
-
transactionHash: pendingRegisterBlobTransaction.hash
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
await this.rpc.putBlob({
|
|
176
|
-
account: params.signer.accountAddress,
|
|
177
|
-
blobName: params.blobName,
|
|
178
|
-
blobData: params.blobData
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Uploads a batch of blobs to the Shelby network.
|
|
183
|
-
* This method handles the complete upload flow including commitment generation,
|
|
184
|
-
* blockchain registration, and storage upload.
|
|
185
|
-
*
|
|
186
|
-
* Note: This method accepts only `Uint8Array` and buffers each blob in memory.
|
|
187
|
-
* For streaming uploads of large files, orchestrate the steps manually using
|
|
188
|
-
* `generateCommitments()`, `coordination.registerBlob()`, and `rpc.putBlob()`
|
|
189
|
-
* with a `ReadableStream`.
|
|
190
|
-
*
|
|
191
|
-
* @param params.blobs - The blobs to upload.
|
|
192
|
-
* @param params.blobs.blobData - The raw data to upload as a Uint8Array.
|
|
193
|
-
* @param params.blobs.blobName - The name/path of the blob (e.g. "folder/file.txt").
|
|
194
|
-
* @param params.expirationMicros - The expiration time in microseconds since Unix epoch.
|
|
195
|
-
* @param params.signer - The account that signs and pays for the transaction.
|
|
196
|
-
* @param params.options - Optional upload configuration.
|
|
197
|
-
* @param params.options.chunksetSizeBytes - Custom chunkset size.
|
|
198
|
-
* @param params.options.build - Additional Aptos transaction options.
|
|
199
|
-
*
|
|
200
|
-
* @returns The transaction and generated blob commitments (when implemented).
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* ```typescript
|
|
204
|
-
* await client.batchUpload({
|
|
205
|
-
* blobs: [
|
|
206
|
-
* { blobData: Buffer.from("Hello, World!"), blobName: "hello.txt" },
|
|
207
|
-
* { blobData: Buffer.from("Hello, World 2!"), blobName: "hello2.txt" },
|
|
208
|
-
* ],
|
|
209
|
-
* expirationMicros: Date.now() * 1000 + 86400_000_000 // 24 hours from now
|
|
210
|
-
* });
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
async batchUpload(params) {
|
|
214
|
-
const existingBlobs = await this.coordination.getBlobs({
|
|
215
|
-
where: {
|
|
216
|
-
blob_name: {
|
|
217
|
-
_in: params.blobs.map(
|
|
218
|
-
(blob) => createBlobKey({
|
|
219
|
-
account: params.signer.accountAddress,
|
|
220
|
-
blobName: blob.blobName
|
|
221
|
-
})
|
|
222
|
-
)
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
const blobsToRegister = params.blobs.filter(
|
|
227
|
-
(blob) => !existingBlobs.some(
|
|
228
|
-
(existingBlob) => existingBlob.name === createBlobKey({
|
|
229
|
-
account: params.signer.accountAddress,
|
|
230
|
-
blobName: blob.blobName
|
|
231
|
-
})
|
|
232
|
-
)
|
|
233
|
-
);
|
|
234
|
-
if (blobsToRegister.length > 0) {
|
|
235
|
-
const provider = await this.getProvider();
|
|
236
|
-
const blobCommitments = await Promise.all(
|
|
237
|
-
blobsToRegister.map(
|
|
238
|
-
async (blob) => generateCommitments(provider, blob.blobData)
|
|
239
|
-
)
|
|
240
|
-
);
|
|
241
|
-
const { transaction: pendingRegisterBlobTransaction } = await this.coordination.batchRegisterBlobs({
|
|
242
|
-
account: params.signer,
|
|
243
|
-
expirationMicros: params.expirationMicros,
|
|
244
|
-
blobs: blobsToRegister.map((blob, index) => ({
|
|
245
|
-
blobName: blob.blobName,
|
|
246
|
-
blobSize: blob.blobData.length,
|
|
247
|
-
blobMerkleRoot: blobCommitments[index].blob_merkle_root
|
|
248
|
-
})),
|
|
249
|
-
config: provider.config,
|
|
250
|
-
options: params.options
|
|
251
|
-
});
|
|
252
|
-
await this.coordination.aptos.waitForTransaction({
|
|
253
|
-
transactionHash: pendingRegisterBlobTransaction.hash,
|
|
254
|
-
options: { waitForIndexer: true }
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
const limit = pLimit(3);
|
|
258
|
-
await Promise.all(
|
|
259
|
-
params.blobs.map(
|
|
260
|
-
(blob) => limit(
|
|
261
|
-
() => this.rpc.putBlob({
|
|
262
|
-
account: params.signer.accountAddress,
|
|
263
|
-
blobName: blob.blobName,
|
|
264
|
-
blobData: blob.blobData
|
|
265
|
-
})
|
|
266
|
-
)
|
|
267
|
-
)
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Downloads a blob from the Shelby RPC node.
|
|
272
|
-
*
|
|
273
|
-
* @param params.account - The account namespace the blob is stored in (e.g. "0x1")
|
|
274
|
-
* @param params.blobName - The name of the blob (e.g. "foo/bar")
|
|
275
|
-
* @param params.range - The range of the blob to download.
|
|
276
|
-
*
|
|
277
|
-
* @returns A `ShelbyBlob` object containing the blob data.
|
|
278
|
-
*
|
|
279
|
-
* @example
|
|
280
|
-
* ```typescript
|
|
281
|
-
* const blob = await client.download({
|
|
282
|
-
* account,
|
|
283
|
-
* blobName: "foo/bar.txt",
|
|
284
|
-
* });
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
async download(params) {
|
|
288
|
-
return await this.rpc.getBlob(params);
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
*
|
|
292
|
-
* Funds an account with ShelbyUSD tokens.
|
|
293
|
-
*
|
|
294
|
-
* @param params.address - The address to fund.
|
|
295
|
-
* @param params.amount - The amount to fund.
|
|
296
|
-
* @returns The transaction hash of the funded account.
|
|
297
|
-
*
|
|
298
|
-
* @example
|
|
299
|
-
* ```typescript
|
|
300
|
-
* const hash = await client.fundAccountWithShelbyUSD({
|
|
301
|
-
* address: "0x1",
|
|
302
|
-
* amount: 100000000,
|
|
303
|
-
* });
|
|
304
|
-
* ```
|
|
305
|
-
*/
|
|
306
|
-
async fundAccountWithShelbyUSD(params) {
|
|
307
|
-
if (this.config.network === Network.TESTNET) {
|
|
308
|
-
throw new Error(
|
|
309
|
-
`ShelbyUSD cannot be minted programmatically on ${Network.TESTNET}. Please use the faucet at https://docs.shelby.xyz/apis/faucet/shelbyusd instead.`
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
const { address, amount } = params;
|
|
313
|
-
try {
|
|
314
|
-
const faucet = this.config.faucet?.baseUrl ?? "https://faucet.shelbynet.shelby.xyz/fund?asset=shelbyusd";
|
|
315
|
-
const authToken = this.config.faucet?.authToken;
|
|
316
|
-
const response = await fetch(`${faucet}`, {
|
|
317
|
-
method: "POST",
|
|
318
|
-
body: JSON.stringify({
|
|
319
|
-
address: normalizeAddress(address).toString(),
|
|
320
|
-
amount
|
|
321
|
-
}),
|
|
322
|
-
headers: {
|
|
323
|
-
"Content-Type": "application/json",
|
|
324
|
-
...authToken ? { Authorization: `Bearer ${authToken}` } : {}
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
if (!response.ok) {
|
|
328
|
-
const errorBody = await response.text();
|
|
329
|
-
throw new Error(`Failed to fund account: ${errorBody}`);
|
|
330
|
-
}
|
|
331
|
-
const json = await response.json();
|
|
332
|
-
const res = await this.aptos.waitForTransaction({
|
|
333
|
-
transactionHash: json.txn_hashes[0],
|
|
334
|
-
options: {
|
|
335
|
-
timeoutSecs: DEFAULT_TXN_TIMEOUT_SEC,
|
|
336
|
-
checkSuccess: true
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
if (res.type === TransactionResponseType.User) {
|
|
340
|
-
return res.hash;
|
|
341
|
-
}
|
|
342
|
-
throw new Error(
|
|
343
|
-
`Unexpected transaction received for fund account: ${res.type}`
|
|
344
|
-
);
|
|
345
|
-
} catch (error) {
|
|
346
|
-
throw new Error(`Failed to fund account: ${error}`);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Fund an account with APT tokens
|
|
351
|
-
*
|
|
352
|
-
* @param params.address - The address to fund
|
|
353
|
-
* @param params.amount - The amount to fund
|
|
354
|
-
* @returns The transaction hash of the funded account
|
|
355
|
-
*
|
|
356
|
-
* @example
|
|
357
|
-
* ```typescript
|
|
358
|
-
* const hash = await client.fundAccountWithAPT({
|
|
359
|
-
* address: "0x1",
|
|
360
|
-
* amount: 100000000,
|
|
361
|
-
* });
|
|
362
|
-
* ```
|
|
363
|
-
*/
|
|
364
|
-
async fundAccountWithAPT(params) {
|
|
365
|
-
const transaction = await this.aptos.fundAccount({
|
|
366
|
-
accountAddress: params.address,
|
|
367
|
-
amount: params.amount
|
|
368
|
-
});
|
|
369
|
-
return transaction.hash;
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
|
|
373
|
-
export {
|
|
374
|
-
ShelbyClient
|
|
375
|
-
};
|
package/dist/chunk-7P6ASYW6.mjs
DELETED
package/dist/chunk-A4IG6GSE.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__export
|
|
3
|
-
} from "./chunk-7P6ASYW6.mjs";
|
|
4
|
-
|
|
5
|
-
// src/node/testUtil.ts
|
|
6
|
-
var testUtil_exports = {};
|
|
7
|
-
__export(testUtil_exports, {
|
|
8
|
-
makeChunk: () => makeChunk
|
|
9
|
-
});
|
|
10
|
-
function makeChunk(n) {
|
|
11
|
-
const c = Buffer.alloc(n);
|
|
12
|
-
for (let i = 0; i < n; ++i) {
|
|
13
|
-
c[i] = i % 256;
|
|
14
|
-
}
|
|
15
|
-
return c;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export {
|
|
19
|
-
makeChunk,
|
|
20
|
-
testUtil_exports
|
|
21
|
-
};
|
package/dist/chunk-AD2G3QYD.mjs
DELETED
|
File without changes
|