@shelby-protocol/sdk 0.3.1 → 0.4.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/dist/browser/index.d.ts +9 -9
- package/dist/browser/index.mjs +1068 -589
- package/dist/core/clients/ShelbyBlobClient.d.ts +155 -40
- package/dist/core/clients/ShelbyBlobClient.mjs +314 -112
- package/dist/core/clients/ShelbyClient.d.ts +27 -4
- package/dist/core/clients/ShelbyClient.mjs +869 -551
- package/dist/core/clients/ShelbyClientConfig.d.ts +9 -1
- package/dist/core/clients/ShelbyMetadataClient.d.ts +38 -6
- package/dist/core/clients/ShelbyMetadataClient.mjs +95 -13
- package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +42 -0
- package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +62 -7
- package/dist/core/clients/ShelbyPlacementGroupClient.mjs +10 -7
- package/dist/core/clients/ShelbyRPCClient.d.ts +55 -66
- package/dist/core/clients/ShelbyRPCClient.mjs +344 -360
- package/dist/core/clients/index.d.ts +3 -2
- package/dist/core/clients/index.mjs +933 -551
- package/dist/core/clients/utils.mjs +1 -1
- package/dist/core/commitments.d.ts +12 -1
- package/dist/core/commitments.mjs +7 -0
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.mjs +1 -1
- package/dist/core/erasure/constants.d.ts +16 -1
- package/dist/core/erasure/constants.mjs +15 -1
- package/dist/core/erasure/index.d.ts +1 -1
- package/dist/core/erasure/index.mjs +15 -1
- package/dist/core/errors.d.ts +20 -1
- package/dist/core/errors.mjs +29 -0
- package/dist/core/index.d.ts +9 -9
- package/dist/core/index.mjs +1068 -589
- package/dist/core/operations/generated/sdk.d.ts +798 -42
- package/dist/core/operations/generated/sdk.mjs +93 -9
- package/dist/core/operations/index.d.ts +1 -1
- package/dist/core/operations/index.mjs +94 -10
- package/dist/core/rpc-responses.d.ts +1 -57
- package/dist/core/rpc-responses.mjs +1 -21
- 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/types/blobs.d.ts +24 -5
- package/dist/core/types/blobs.mjs +24 -0
- package/dist/core/types/index.d.ts +2 -2
- package/dist/core/types/index.mjs +46 -2
- package/dist/core/types/payments.mjs +1 -1
- package/dist/core/types/storage_providers.d.ts +32 -6
- package/dist/core/types/storage_providers.mjs +22 -0
- 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 +1 -0
- package/dist/node/clients/ShelbyNodeClient.mjs +869 -551
- package/dist/node/clients/index.d.ts +1 -0
- package/dist/node/clients/index.mjs +867 -551
- package/dist/node/index.d.ts +9 -9
- package/dist/node/index.mjs +1068 -589
- package/dist/node/parallel/commitment_worker.mjs +36 -249
- package/dist/node/parallel/commitment_worker_pool.mjs +56 -3
- 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.mjs +56 -3
- package/dist/node/parallel/index.d.ts +1 -0
- package/dist/node/parallel/index.mjs +72 -4
- package/dist/node/parallel/parallel_commitments.mjs +56 -3
- package/dist/node/parallel/worker_pool.mjs +56 -3
- package/package.json +10 -3
|
@@ -5,7 +5,7 @@ import { ShelbyNetwork } from '../networks.js';
|
|
|
5
5
|
* Configuration for the Shelby RPC connection.
|
|
6
6
|
*/
|
|
7
7
|
type ShelbyRPCConfig = {
|
|
8
|
-
/** Base URL of the Shelby RPC node (e.g., "https://
|
|
8
|
+
/** Base URL of the Shelby RPC node (e.g., "https://shelby.shelbynet.shelby.xyz/shelby"). */
|
|
9
9
|
baseUrl?: string;
|
|
10
10
|
/** API key for authenticating with the RPC node. */
|
|
11
11
|
apiKey?: string;
|
|
@@ -57,6 +57,14 @@ interface ShelbyClientConfig {
|
|
|
57
57
|
* generated automatically for each transaction.
|
|
58
58
|
*/
|
|
59
59
|
orderless?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Best-effort location (region) hint sent with every blob registration from this client,
|
|
62
|
+
* typically the location closest to where the client runs. Honored only for accounts in
|
|
63
|
+
* the default `FollowHint` location-preference mode, and overridden by a per-write
|
|
64
|
+
* `selectedLocation`. Without a resolvable location (no preference, no selection, no
|
|
65
|
+
* hint), writes abort on chain.
|
|
66
|
+
*/
|
|
67
|
+
locationHint?: string;
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
export type { ShelbyClientConfig, ShelbyIndexerConfig, ShelbyRPCConfig };
|
|
@@ -32,27 +32,41 @@ declare class ShelbyMetadataClient {
|
|
|
32
32
|
*/
|
|
33
33
|
getStorageProviders(): Promise<StorageProviderInfo[]>;
|
|
34
34
|
/**
|
|
35
|
-
* Retrieves the
|
|
35
|
+
* Retrieves the names of every activated location (region). Locations that are
|
|
36
|
+
* registered but not yet brought online are admin-internal and not listed.
|
|
36
37
|
*
|
|
38
|
+
* @returns The location name list.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const locations = await client.getLocationNames();
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
getLocationNames(): Promise<string[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the list of placement group addresses in a location.
|
|
48
|
+
*
|
|
49
|
+
* @param locationName - The location whose placement groups to list.
|
|
37
50
|
* @returns The placement group address list, or an empty array if none exist.
|
|
38
51
|
*
|
|
39
52
|
* @example
|
|
40
53
|
* ```typescript
|
|
41
|
-
* const pgList = await client.getPlacementGroupAddresses();
|
|
54
|
+
* const pgList = await client.getPlacementGroupAddresses("us-east-1");
|
|
42
55
|
* ```
|
|
43
56
|
*/
|
|
44
|
-
getPlacementGroupAddresses(): Promise<AccountAddress[]>;
|
|
57
|
+
getPlacementGroupAddresses(locationName: string): Promise<AccountAddress[]>;
|
|
45
58
|
/**
|
|
46
|
-
* Retrieves the list of slice addresses.
|
|
59
|
+
* Retrieves the list of slice addresses in a location.
|
|
47
60
|
*
|
|
61
|
+
* @param locationName - The location whose slices to list.
|
|
48
62
|
* @returns The slice group list, or an empty array if none exist.
|
|
49
63
|
*
|
|
50
64
|
* @example
|
|
51
65
|
* ```typescript
|
|
52
|
-
* const pgList = await client.getSliceAddresses();
|
|
66
|
+
* const pgList = await client.getSliceAddresses("us-east-1");
|
|
53
67
|
* ```
|
|
54
68
|
*/
|
|
55
|
-
getSliceAddresses(): Promise<AccountAddress[]>;
|
|
69
|
+
getSliceAddresses(locationName: string): Promise<AccountAddress[]>;
|
|
56
70
|
/**
|
|
57
71
|
* Gets the placement group address for a slice.
|
|
58
72
|
*
|
|
@@ -80,6 +94,24 @@ declare class ShelbyMetadataClient {
|
|
|
80
94
|
getDesignatedStorageProvidersForSlice(params: {
|
|
81
95
|
account: AccountAddressInput;
|
|
82
96
|
}): Promise<(AccountAddress | null)[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Retrieves the active storage providers for a slice.
|
|
99
|
+
*
|
|
100
|
+
* Active SPs have a complete copy of the data for the slot, and are not in any data transfer/repair/reconstruction phase.
|
|
101
|
+
* Active SP can be audited for the data it contains.
|
|
102
|
+
* Each slot has at most one active SP.
|
|
103
|
+
*
|
|
104
|
+
* @param params.account - The address of the slice account.
|
|
105
|
+
* @returns An array where result[i] is the active SP for slot i, or null if no SP is active.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const providers = await client.getActiveStorageProvidersForSlice({ account: sliceAddress });
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
getActiveStorageProvidersForSlice(params: {
|
|
113
|
+
account: AccountAddressInput;
|
|
114
|
+
}): Promise<(AccountAddress | null)[]>;
|
|
83
115
|
/**
|
|
84
116
|
* Retrieves the serving storage providers for a slice.
|
|
85
117
|
*
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
// src/core/constants.ts
|
|
9
9
|
import { Network } from "@aptos-labs/ts-sdk";
|
|
10
10
|
var NetworkToShelbyRPCBaseUrl = {
|
|
11
|
-
[Network.SHELBYNET]: "https://
|
|
11
|
+
[Network.SHELBYNET]: "https://shelby.shelbynet.shelby.xyz/shelby",
|
|
12
12
|
[Network.NETNA]: void 0,
|
|
13
13
|
[Network.DEVNET]: void 0,
|
|
14
14
|
[Network.TESTNET]: "https://api.testnet.shelby.xyz/shelby",
|
|
@@ -36,6 +36,18 @@ var NetworkToGasStationBaseUrl = {
|
|
|
36
36
|
};
|
|
37
37
|
var SHELBY_DEPLOYER = "0x85fdb9a176ab8ef1d9d9c1b60d60b3924f0800ac1de1cc2085fb0b8bb4988e6a";
|
|
38
38
|
|
|
39
|
+
// src/core/types/storage_providers.ts
|
|
40
|
+
var ACTIVE_PROVIDER_CONDITIONS = [
|
|
41
|
+
"Normal",
|
|
42
|
+
"Faulty",
|
|
43
|
+
"Leaving",
|
|
44
|
+
"Evicted",
|
|
45
|
+
"PendingLeaving"
|
|
46
|
+
];
|
|
47
|
+
function isActiveProviderCondition(value) {
|
|
48
|
+
return typeof value === "string" && ACTIVE_PROVIDER_CONDITIONS.includes(value);
|
|
49
|
+
}
|
|
50
|
+
|
|
39
51
|
// src/core/utils.ts
|
|
40
52
|
import {
|
|
41
53
|
AccountAddress,
|
|
@@ -77,6 +89,15 @@ var getAptosConfig = (config) => {
|
|
|
77
89
|
};
|
|
78
90
|
|
|
79
91
|
// src/core/clients/ShelbyMetadataClient.ts
|
|
92
|
+
function parseActiveProviderCondition(raw) {
|
|
93
|
+
const variant = raw?.__variant__;
|
|
94
|
+
if (!isActiveProviderCondition(variant)) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`Unknown ActiveProviderCondition variant: ${JSON.stringify(raw)}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return variant;
|
|
100
|
+
}
|
|
80
101
|
function parseStorageProviderState(raw) {
|
|
81
102
|
switch (raw.__variant__) {
|
|
82
103
|
case "Active":
|
|
@@ -84,8 +105,7 @@ function parseStorageProviderState(raw) {
|
|
|
84
105
|
variant: "Active",
|
|
85
106
|
quota: raw.quota.value,
|
|
86
107
|
stakeAtStartOfStakingEpoch: raw.stake_at_start_of_staking_epoch,
|
|
87
|
-
|
|
88
|
-
leaving: raw.leaving
|
|
108
|
+
condition: parseActiveProviderCondition(raw.condition)
|
|
89
109
|
};
|
|
90
110
|
case "Waitlisted":
|
|
91
111
|
return {
|
|
@@ -98,6 +118,10 @@ function parseStorageProviderState(raw) {
|
|
|
98
118
|
frozenFrom: raw.frozen_from,
|
|
99
119
|
frozenTill: raw.frozen_till
|
|
100
120
|
};
|
|
121
|
+
default:
|
|
122
|
+
throw new Error(
|
|
123
|
+
`Unknown StorageProviderStateDetails variant: ${JSON.stringify(raw)}`
|
|
124
|
+
);
|
|
101
125
|
}
|
|
102
126
|
}
|
|
103
127
|
var ShelbyMetadataClient = class {
|
|
@@ -156,28 +180,52 @@ var ShelbyMetadataClient = class {
|
|
|
156
180
|
}
|
|
157
181
|
}
|
|
158
182
|
/**
|
|
159
|
-
* Retrieves the
|
|
183
|
+
* Retrieves the names of every activated location (region). Locations that are
|
|
184
|
+
* registered but not yet brought online are admin-internal and not listed.
|
|
185
|
+
*
|
|
186
|
+
* @returns The location name list.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const locations = await client.getLocationNames();
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
async getLocationNames() {
|
|
194
|
+
const names = await this.aptos.view({
|
|
195
|
+
payload: {
|
|
196
|
+
function: `${this.deployer.toString()}::location::activated_location_names`,
|
|
197
|
+
functionArguments: []
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
return names[0];
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Retrieves the list of placement group addresses in a location.
|
|
160
204
|
*
|
|
205
|
+
* @param locationName - The location whose placement groups to list.
|
|
161
206
|
* @returns The placement group address list, or an empty array if none exist.
|
|
162
207
|
*
|
|
163
208
|
* @example
|
|
164
209
|
* ```typescript
|
|
165
|
-
* const pgList = await client.getPlacementGroupAddresses();
|
|
210
|
+
* const pgList = await client.getPlacementGroupAddresses("us-east-1");
|
|
166
211
|
* ```
|
|
167
212
|
*/
|
|
168
|
-
async getPlacementGroupAddresses() {
|
|
213
|
+
async getPlacementGroupAddresses(locationName) {
|
|
169
214
|
try {
|
|
170
215
|
const pgSizeMetadata = await this.aptos.view({
|
|
171
216
|
payload: {
|
|
172
217
|
function: `${this.deployer.toString()}::placement_group_registry::get_number_of_placement_groups`,
|
|
173
|
-
functionArguments: []
|
|
218
|
+
functionArguments: [locationName]
|
|
174
219
|
}
|
|
175
220
|
});
|
|
221
|
+
if (Number(pgSizeMetadata[0]) === 0) {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
176
224
|
const finalPlacementGroupIndex = pgSizeMetadata[0] - 1;
|
|
177
225
|
const addressMetadataArray = await this.aptos.view({
|
|
178
226
|
payload: {
|
|
179
227
|
function: `${this.deployer.toString()}::placement_group_registry::get_placement_group_addresses`,
|
|
180
|
-
functionArguments: [0, finalPlacementGroupIndex]
|
|
228
|
+
functionArguments: [locationName, 0, finalPlacementGroupIndex]
|
|
181
229
|
}
|
|
182
230
|
});
|
|
183
231
|
const metadata = addressMetadataArray[0];
|
|
@@ -191,28 +239,32 @@ var ShelbyMetadataClient = class {
|
|
|
191
239
|
}
|
|
192
240
|
}
|
|
193
241
|
/**
|
|
194
|
-
* Retrieves the list of slice addresses.
|
|
242
|
+
* Retrieves the list of slice addresses in a location.
|
|
195
243
|
*
|
|
244
|
+
* @param locationName - The location whose slices to list.
|
|
196
245
|
* @returns The slice group list, or an empty array if none exist.
|
|
197
246
|
*
|
|
198
247
|
* @example
|
|
199
248
|
* ```typescript
|
|
200
|
-
* const pgList = await client.getSliceAddresses();
|
|
249
|
+
* const pgList = await client.getSliceAddresses("us-east-1");
|
|
201
250
|
* ```
|
|
202
251
|
*/
|
|
203
|
-
async getSliceAddresses() {
|
|
252
|
+
async getSliceAddresses(locationName) {
|
|
204
253
|
try {
|
|
205
254
|
const sliceSizeMetadata = await this.aptos.view({
|
|
206
255
|
payload: {
|
|
207
256
|
function: `${this.deployer.toString()}::slice_registry::get_number_of_slices`,
|
|
208
|
-
functionArguments: []
|
|
257
|
+
functionArguments: [locationName]
|
|
209
258
|
}
|
|
210
259
|
});
|
|
260
|
+
if (Number(sliceSizeMetadata[0]) === 0) {
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
211
263
|
const finalSliceIndex = sliceSizeMetadata[0] - 1;
|
|
212
264
|
const addressMetadataArray = await this.aptos.view({
|
|
213
265
|
payload: {
|
|
214
266
|
function: `${this.deployer.toString()}::slice_registry::get_slice_addresses`,
|
|
215
|
-
functionArguments: [0, finalSliceIndex]
|
|
267
|
+
functionArguments: [locationName, 0, finalSliceIndex]
|
|
216
268
|
}
|
|
217
269
|
});
|
|
218
270
|
const metadata = addressMetadataArray[0];
|
|
@@ -272,6 +324,36 @@ var ShelbyMetadataClient = class {
|
|
|
272
324
|
(opt) => opt.vec.length > 0 ? normalizeAddress(opt.vec[0]) : null
|
|
273
325
|
);
|
|
274
326
|
}
|
|
327
|
+
/**
|
|
328
|
+
* Retrieves the active storage providers for a slice.
|
|
329
|
+
*
|
|
330
|
+
* Active SPs have a complete copy of the data for the slot, and are not in any data transfer/repair/reconstruction phase.
|
|
331
|
+
* Active SP can be audited for the data it contains.
|
|
332
|
+
* Each slot has at most one active SP.
|
|
333
|
+
*
|
|
334
|
+
* @param params.account - The address of the slice account.
|
|
335
|
+
* @returns An array where result[i] is the active SP for slot i, or null if no SP is active.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```typescript
|
|
339
|
+
* const providers = await client.getActiveStorageProvidersForSlice({ account: sliceAddress });
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
async getActiveStorageProvidersForSlice(params) {
|
|
343
|
+
const placementGroupAddress = await this.getPlacementGroupAddressForSlice(
|
|
344
|
+
params.account
|
|
345
|
+
);
|
|
346
|
+
const rawMetadata = await this.aptos.view({
|
|
347
|
+
payload: {
|
|
348
|
+
function: `${this.deployer.toString()}::placement_group::get_active_storage_providers`,
|
|
349
|
+
functionArguments: [placementGroupAddress]
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
const providers = rawMetadata[0];
|
|
353
|
+
return providers.map(
|
|
354
|
+
(opt) => opt.vec.length > 0 ? normalizeAddress(opt.vec[0]) : null
|
|
355
|
+
);
|
|
356
|
+
}
|
|
275
357
|
/**
|
|
276
358
|
* Retrieves the serving storage providers for a slice.
|
|
277
359
|
*
|
|
@@ -111,6 +111,48 @@ declare class ShelbyMicropaymentChannelClient {
|
|
|
111
111
|
fungibleAssetAddress: AccountAddress;
|
|
112
112
|
publicKey: Uint8Array;
|
|
113
113
|
}): InputGenerateTransactionPayloadData;
|
|
114
|
+
/**
|
|
115
|
+
* Withdraws funds from a micropayment channel as the sender.
|
|
116
|
+
*
|
|
117
|
+
* @param params.sender - The account that is withdrawing funds.
|
|
118
|
+
* @param params.receiver - The account the channel is configured to send funds to.
|
|
119
|
+
* @param params.fungibleAssetAddress - The account address of the fungible asset.
|
|
120
|
+
* @param params.options - Optional transaction generation options.
|
|
121
|
+
*
|
|
122
|
+
* @returns An object containing the pending transaction.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const { transaction } = await client.senderWithdraw({
|
|
127
|
+
* sender: sender,
|
|
128
|
+
* receiver: receiver,
|
|
129
|
+
* fungibleAssetAddress: fungibleAssetAddress,
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
senderWithdraw(params: {
|
|
134
|
+
sender: Account;
|
|
135
|
+
receiver: AccountAddress;
|
|
136
|
+
fungibleAssetAddress: AccountAddress;
|
|
137
|
+
options?: InputGenerateTransactionOptions;
|
|
138
|
+
}): Promise<{
|
|
139
|
+
transaction: PendingTransactionResponse;
|
|
140
|
+
}>;
|
|
141
|
+
/**
|
|
142
|
+
* Creates a static payload for the sender_withdraw Move function.
|
|
143
|
+
* This is a helper method for constructing the transaction payload without signing.
|
|
144
|
+
*
|
|
145
|
+
* @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER.
|
|
146
|
+
* @param params.receiver - The account address of the receiver.
|
|
147
|
+
* @param params.fungibleAssetAddress - The account address of the fungible asset.
|
|
148
|
+
*
|
|
149
|
+
* @returns An Aptos transaction payload data object for the sender_withdraw Move function.
|
|
150
|
+
*/
|
|
151
|
+
static createSenderWithdrawPayload(params: {
|
|
152
|
+
deployer?: AccountAddress;
|
|
153
|
+
receiver: AccountAddress;
|
|
154
|
+
fungibleAssetAddress: AccountAddress;
|
|
155
|
+
}): InputGenerateTransactionPayloadData;
|
|
114
156
|
/**
|
|
115
157
|
* Creates a micropayment that can be sent to a receiver.
|
|
116
158
|
* The sender signs a WithdrawApproval message that authorizes the receiver
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
// src/core/constants.ts
|
|
9
9
|
import { Network } from "@aptos-labs/ts-sdk";
|
|
10
10
|
var NetworkToShelbyRPCBaseUrl = {
|
|
11
|
-
[Network.SHELBYNET]: "https://
|
|
11
|
+
[Network.SHELBYNET]: "https://shelby.shelbynet.shelby.xyz/shelby",
|
|
12
12
|
[Network.NETNA]: void 0,
|
|
13
13
|
[Network.DEVNET]: void 0,
|
|
14
14
|
[Network.TESTNET]: "https://api.testnet.shelby.xyz/shelby",
|
|
@@ -76,18 +76,20 @@ import gql from "graphql-tag";
|
|
|
76
76
|
var GetBlobsDocument = gql`
|
|
77
77
|
query getBlobs($where: blobs_bool_exp, $orderBy: [blobs_order_by!], $limit: Int, $offset: Int) {
|
|
78
78
|
blobs(where: $where, order_by: $orderBy, limit: $limit, offset: $offset) {
|
|
79
|
+
uid
|
|
80
|
+
object_name
|
|
79
81
|
owner
|
|
80
82
|
blob_commitment
|
|
81
|
-
blob_name
|
|
82
83
|
created_at
|
|
83
84
|
expires_at
|
|
85
|
+
updated_at
|
|
84
86
|
num_chunksets
|
|
85
|
-
is_deleted
|
|
86
|
-
is_written
|
|
87
|
-
placement_group
|
|
88
87
|
size
|
|
89
|
-
updated_at
|
|
90
88
|
slice_address
|
|
89
|
+
placement_group
|
|
90
|
+
is_persisted
|
|
91
|
+
is_committed
|
|
92
|
+
is_deleted
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
`;
|
|
@@ -99,7 +101,8 @@ var GetBlobActivitiesDocument = gql`
|
|
|
99
101
|
limit: $limit
|
|
100
102
|
offset: $offset
|
|
101
103
|
) {
|
|
102
|
-
|
|
104
|
+
uid
|
|
105
|
+
object_name
|
|
103
106
|
event_index
|
|
104
107
|
event_type
|
|
105
108
|
transaction_hash
|
|
@@ -544,6 +547,58 @@ var ShelbyMicropaymentChannelClient = class _ShelbyMicropaymentChannelClient {
|
|
|
544
547
|
]
|
|
545
548
|
};
|
|
546
549
|
}
|
|
550
|
+
/**
|
|
551
|
+
* Withdraws funds from a micropayment channel as the sender.
|
|
552
|
+
*
|
|
553
|
+
* @param params.sender - The account that is withdrawing funds.
|
|
554
|
+
* @param params.receiver - The account the channel is configured to send funds to.
|
|
555
|
+
* @param params.fungibleAssetAddress - The account address of the fungible asset.
|
|
556
|
+
* @param params.options - Optional transaction generation options.
|
|
557
|
+
*
|
|
558
|
+
* @returns An object containing the pending transaction.
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* ```typescript
|
|
562
|
+
* const { transaction } = await client.senderWithdraw({
|
|
563
|
+
* sender: sender,
|
|
564
|
+
* receiver: receiver,
|
|
565
|
+
* fungibleAssetAddress: fungibleAssetAddress,
|
|
566
|
+
* });
|
|
567
|
+
* ```
|
|
568
|
+
*/
|
|
569
|
+
async senderWithdraw(params) {
|
|
570
|
+
const transaction = await this.aptos.transaction.build.simple({
|
|
571
|
+
options: params.options,
|
|
572
|
+
data: _ShelbyMicropaymentChannelClient.createSenderWithdrawPayload({
|
|
573
|
+
deployer: this.deployer,
|
|
574
|
+
receiver: params.receiver,
|
|
575
|
+
fungibleAssetAddress: params.fungibleAssetAddress
|
|
576
|
+
}),
|
|
577
|
+
sender: params.sender.accountAddress
|
|
578
|
+
});
|
|
579
|
+
return {
|
|
580
|
+
transaction: await this.aptos.signAndSubmitTransaction({
|
|
581
|
+
signer: params.sender,
|
|
582
|
+
transaction
|
|
583
|
+
})
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Creates a static payload for the sender_withdraw Move function.
|
|
588
|
+
* This is a helper method for constructing the transaction payload without signing.
|
|
589
|
+
*
|
|
590
|
+
* @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER.
|
|
591
|
+
* @param params.receiver - The account address of the receiver.
|
|
592
|
+
* @param params.fungibleAssetAddress - The account address of the fungible asset.
|
|
593
|
+
*
|
|
594
|
+
* @returns An Aptos transaction payload data object for the sender_withdraw Move function.
|
|
595
|
+
*/
|
|
596
|
+
static createSenderWithdrawPayload(params) {
|
|
597
|
+
return {
|
|
598
|
+
function: `${(params.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::sender_withdraw`,
|
|
599
|
+
functionArguments: [params.receiver, params.fungibleAssetAddress]
|
|
600
|
+
};
|
|
601
|
+
}
|
|
547
602
|
/**
|
|
548
603
|
* Creates a micropayment that can be sent to a receiver.
|
|
549
604
|
* The sender signs a WithdrawApproval message that authorizes the receiver
|
|
@@ -8,7 +8,7 @@ import { AptosConfig } from "@aptos-labs/ts-sdk";
|
|
|
8
8
|
// src/core/constants.ts
|
|
9
9
|
import { Network } from "@aptos-labs/ts-sdk";
|
|
10
10
|
var NetworkToShelbyRPCBaseUrl = {
|
|
11
|
-
[Network.SHELBYNET]: "https://
|
|
11
|
+
[Network.SHELBYNET]: "https://shelby.shelbynet.shelby.xyz/shelby",
|
|
12
12
|
[Network.NETNA]: void 0,
|
|
13
13
|
[Network.DEVNET]: void 0,
|
|
14
14
|
[Network.TESTNET]: "https://api.testnet.shelby.xyz/shelby",
|
|
@@ -70,18 +70,20 @@ import gql from "graphql-tag";
|
|
|
70
70
|
var GetBlobsDocument = gql`
|
|
71
71
|
query getBlobs($where: blobs_bool_exp, $orderBy: [blobs_order_by!], $limit: Int, $offset: Int) {
|
|
72
72
|
blobs(where: $where, order_by: $orderBy, limit: $limit, offset: $offset) {
|
|
73
|
+
uid
|
|
74
|
+
object_name
|
|
73
75
|
owner
|
|
74
76
|
blob_commitment
|
|
75
|
-
blob_name
|
|
76
77
|
created_at
|
|
77
78
|
expires_at
|
|
79
|
+
updated_at
|
|
78
80
|
num_chunksets
|
|
79
|
-
is_deleted
|
|
80
|
-
is_written
|
|
81
|
-
placement_group
|
|
82
81
|
size
|
|
83
|
-
updated_at
|
|
84
82
|
slice_address
|
|
83
|
+
placement_group
|
|
84
|
+
is_persisted
|
|
85
|
+
is_committed
|
|
86
|
+
is_deleted
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
`;
|
|
@@ -93,7 +95,8 @@ var GetBlobActivitiesDocument = gql`
|
|
|
93
95
|
limit: $limit
|
|
94
96
|
offset: $offset
|
|
95
97
|
) {
|
|
96
|
-
|
|
98
|
+
uid
|
|
99
|
+
object_name
|
|
97
100
|
event_index
|
|
98
101
|
event_type
|
|
99
102
|
transaction_hash
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Account, AccountAddressInput } from '@aptos-labs/ts-sdk';
|
|
2
2
|
import { ShelbyBlob } from '../blobs.js';
|
|
3
|
-
import {
|
|
3
|
+
import { BlobCommitments } from '../commitments.js';
|
|
4
4
|
import { ShelbyIndexerClient } from '../operations/index.js';
|
|
5
|
-
import { ChallengeResponse
|
|
5
|
+
import { ChallengeResponse } from '../rpc-responses.js';
|
|
6
|
+
import { StorageProviderAck } from '../types/blobs.js';
|
|
6
7
|
import { SenderBuiltMicropayment } from '../types/payments.js';
|
|
7
8
|
import { ShelbyRPCConfig, ShelbyClientConfig } from './ShelbyClientConfig.js';
|
|
9
|
+
import '../layout.js';
|
|
8
10
|
import 'zod';
|
|
9
11
|
import '../../clay-codes-DdXABBDx.js';
|
|
10
12
|
import '@shelby-protocol/clay-codes';
|
|
@@ -44,13 +46,26 @@ interface DerivableBlobOwnerAuth extends BlobOwnerAuthBase {
|
|
|
44
46
|
*/
|
|
45
47
|
type BlobOwnerAuth = Ed25519BlobOwnerAuth | DerivableBlobOwnerAuth;
|
|
46
48
|
type BlobDataSource = Uint8Array | ReadableStream<Uint8Array>;
|
|
47
|
-
type
|
|
48
|
-
phase: "uploading"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
type PutBlobChunksetsProgress = {
|
|
50
|
+
phase: "uploading";
|
|
51
|
+
chunksetIdx: number;
|
|
52
|
+
totalChunksets: number;
|
|
53
|
+
chunksetBytes: number;
|
|
52
54
|
uploadedBytes: number;
|
|
53
55
|
totalBytes: number;
|
|
56
|
+
acksReceived?: number;
|
|
57
|
+
/** SP blob acknowledgements from this chunkset (if any) */
|
|
58
|
+
spAcks?: StorageProviderAck[];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Result of putBlobChunksets operation.
|
|
62
|
+
*/
|
|
63
|
+
type PutBlobChunksetsResult = {
|
|
64
|
+
/**
|
|
65
|
+
* Aggregated SP blob acknowledgements collected across all chunksets.
|
|
66
|
+
* Deduplicated by slot (latest signature wins if an SP acks multiple times).
|
|
67
|
+
*/
|
|
68
|
+
spAcks: StorageProviderAck[];
|
|
54
69
|
};
|
|
55
70
|
declare class ShelbyRPCClient {
|
|
56
71
|
#private;
|
|
@@ -65,7 +80,7 @@ declare class ShelbyRPCClient {
|
|
|
65
80
|
* @param config - The client configuration object.
|
|
66
81
|
* @param config.network - The Shelby network to use.
|
|
67
82
|
* @param options.signChallengeHandler - Optional override for challenge
|
|
68
|
-
* signing. When set, `
|
|
83
|
+
* signing. When set, `putBlobChunksets` uses this instead of the built-in
|
|
69
84
|
* `signChallenge`. Intended for kit-level overrides (e.g. Solana DAA).
|
|
70
85
|
*
|
|
71
86
|
* @example
|
|
@@ -93,23 +108,6 @@ declare class ShelbyRPCClient {
|
|
|
93
108
|
* ```
|
|
94
109
|
*/
|
|
95
110
|
getChallenge(account: AccountAddressInput): Promise<ChallengeResponse>;
|
|
96
|
-
/**
|
|
97
|
-
* Check if there's an existing multipart upload for a blob.
|
|
98
|
-
* Returns the upload status including which parts have been uploaded.
|
|
99
|
-
*
|
|
100
|
-
* @param account - The account that owns the blob.
|
|
101
|
-
* @param blobName - The name of the blob.
|
|
102
|
-
* @returns The upload status, or undefined if no pending upload exists.
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```typescript
|
|
106
|
-
* const status = await client.getMultipartUploadStatus(account, "myblob.txt");
|
|
107
|
-
* if (status) {
|
|
108
|
-
* console.log(`Resuming upload ${status.uploadId}, ${status.completedParts.length} parts done`);
|
|
109
|
-
* }
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
getMultipartUploadStatus(account: AccountAddressInput, blobName: string): Promise<MultipartUploadStatusResponse | undefined>;
|
|
113
111
|
/**
|
|
114
112
|
* Sign a challenge using the given account and return auth credentials.
|
|
115
113
|
*
|
|
@@ -119,62 +117,53 @@ declare class ShelbyRPCClient {
|
|
|
119
117
|
*/
|
|
120
118
|
signChallenge(account: Account, challenge: string): BlobOwnerAuth;
|
|
121
119
|
/**
|
|
122
|
-
* Uploads blob data to the Shelby RPC node
|
|
123
|
-
* This method
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* @param params.account - The account that owns the blob.
|
|
127
|
-
* @param params.blobName - The name/path of the blob (e.g. "folder/file.txt").
|
|
128
|
-
* @param params.blobData - The raw blob data as a Uint8Array or ReadableStream.
|
|
129
|
-
* @param params.totalBytes - Total byte length. Required for streams; optional for Uint8Array.
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```typescript
|
|
133
|
-
* const blobData = new TextEncoder().encode("Hello, world!");
|
|
120
|
+
* Uploads blob data to the Shelby RPC node using the v2 chunkset API.
|
|
121
|
+
* This method authenticates using challenge-response and uploads chunksets
|
|
122
|
+
* directly to storage providers via the RPC's worker pool.
|
|
134
123
|
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* });
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
putBlob(params: {
|
|
143
|
-
account: AccountAddressInput;
|
|
144
|
-
blobName: BlobName;
|
|
145
|
-
blobData: BlobDataSource;
|
|
146
|
-
/** Required when blobData is a ReadableStream. Inferred from .length for Uint8Array. */
|
|
147
|
-
totalBytes?: number;
|
|
148
|
-
onProgress?: (progress: PutBlobProgress) => void;
|
|
149
|
-
}): Promise<void>;
|
|
150
|
-
/**
|
|
151
|
-
* Uploads blob data to the Shelby RPC node with authentication and resume support.
|
|
152
|
-
* This method authenticates using challenge-response and can resume interrupted uploads.
|
|
124
|
+
* This method:
|
|
125
|
+
* - Sends raw chunkset data directly to the RPC for erasure encoding
|
|
126
|
+
* - Requires pre-computed blob commitments to generate inclusion proofs
|
|
127
|
+
* - Does not support resume (each chunkset is idempotent on the SP side)
|
|
153
128
|
*
|
|
154
129
|
* @param params.account - The Aptos Account (with signing capability) that owns the blob.
|
|
155
|
-
* @param params.
|
|
130
|
+
* @param params.uid - The blob's on-chain UID (from `BlobRegisteredEvent` at registration).
|
|
156
131
|
* @param params.blobData - The raw blob data as a Uint8Array or ReadableStream.
|
|
132
|
+
* @param params.commitments - Pre-computed blob commitments (from generateCommitments).
|
|
157
133
|
* @param params.totalBytes - Total byte length. Required for streams; optional for Uint8Array.
|
|
134
|
+
* @param params.chunksetConcurrency - Number of chunksets to upload in parallel. Defaults to 4.
|
|
158
135
|
* @param params.onProgress - Optional callback for upload progress.
|
|
136
|
+
* @param params.signal - Optional AbortSignal for cancellation. When aborted, in-flight
|
|
137
|
+
* HTTP requests are cancelled and an AbortError is thrown.
|
|
159
138
|
*
|
|
160
139
|
* @example
|
|
161
140
|
* ```typescript
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
141
|
+
* // First, generate commitments for the blob
|
|
142
|
+
* const commitments = await generateCommitments(provider, fileData);
|
|
143
|
+
*
|
|
144
|
+
* // Register the blob on chain, then read its UID from the register tx's
|
|
145
|
+
* // BlobRegisteredEvent (see ShelbyBlobClient.registeredBlobUids).
|
|
146
|
+
*
|
|
147
|
+
* // Upload using chunkset API
|
|
148
|
+
* await rpcClient.putBlobChunksets({
|
|
149
|
+
* account: myAccount,
|
|
150
|
+
* uid: blobUid,
|
|
165
151
|
* blobData: fileData,
|
|
166
|
-
*
|
|
152
|
+
* commitments,
|
|
153
|
+
* chunksetConcurrency: 8,
|
|
167
154
|
* });
|
|
168
155
|
* ```
|
|
169
156
|
*/
|
|
170
|
-
|
|
157
|
+
putBlobChunksets(params: {
|
|
171
158
|
account: Account;
|
|
172
|
-
|
|
159
|
+
uid: bigint;
|
|
173
160
|
blobData: BlobDataSource;
|
|
161
|
+
commitments: BlobCommitments;
|
|
174
162
|
totalBytes?: number;
|
|
175
|
-
|
|
176
|
-
onProgress?: (progress:
|
|
177
|
-
|
|
163
|
+
chunksetConcurrency?: number;
|
|
164
|
+
onProgress?: (progress: PutBlobChunksetsProgress) => void;
|
|
165
|
+
signal?: AbortSignal;
|
|
166
|
+
}): Promise<PutBlobChunksetsResult>;
|
|
178
167
|
/**
|
|
179
168
|
* Downloads a blob from the Shelby RPC node.
|
|
180
169
|
* Returns a streaming response with validation to ensure data integrity.
|
|
@@ -225,4 +214,4 @@ declare class ShelbyRPCClient {
|
|
|
225
214
|
}): Promise<ShelbyBlob>;
|
|
226
215
|
}
|
|
227
216
|
|
|
228
|
-
export { type AuthScheme, type BlobDataSource, type BlobOwnerAuth, type DerivableBlobOwnerAuth, type Ed25519BlobOwnerAuth, type
|
|
217
|
+
export { type AuthScheme, type BlobDataSource, type BlobOwnerAuth, type DerivableBlobOwnerAuth, type Ed25519BlobOwnerAuth, type PutBlobChunksetsProgress, type PutBlobChunksetsResult, ShelbyRPCClient };
|