@shelby-protocol/sdk 0.3.0 → 0.3.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.
Files changed (106) hide show
  1. package/dist/browser/index.d.ts +12 -3
  2. package/dist/browser/index.mjs +3717 -142
  3. package/dist/core/aptos-explorer.mjs +46 -5
  4. package/dist/core/blobs.mjs +12 -4
  5. package/dist/core/chunk.mjs +58 -9
  6. package/dist/core/clients/ShelbyBlobClient.d.ts +0 -43
  7. package/dist/core/clients/ShelbyBlobClient.mjs +1084 -17
  8. package/dist/core/clients/ShelbyClient.d.ts +12 -2
  9. package/dist/core/clients/ShelbyClient.mjs +2915 -23
  10. package/dist/core/clients/ShelbyClientConfig.mjs +0 -1
  11. package/dist/core/clients/ShelbyMetadataClient.d.ts +0 -18
  12. package/dist/core/clients/ShelbyMetadataClient.mjs +306 -6
  13. package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +7 -49
  14. package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +839 -13
  15. package/dist/core/clients/ShelbyPlacementGroupClient.mjs +307 -8
  16. package/dist/core/clients/ShelbyRPCClient.d.ts +106 -3
  17. package/dist/core/clients/ShelbyRPCClient.mjs +1261 -12
  18. package/dist/core/clients/index.d.ts +2 -1
  19. package/dist/core/clients/index.mjs +3420 -39
  20. package/dist/core/clients/utils.mjs +65 -6
  21. package/dist/core/commitments.mjs +270 -11
  22. package/dist/core/constants.d.ts +2 -2
  23. package/dist/core/constants.mjs +39 -16
  24. package/dist/core/erasure/clay-codes.mjs +129 -4
  25. package/dist/core/erasure/constants.mjs +33 -10
  26. package/dist/core/erasure/default.mjs +191 -9
  27. package/dist/core/erasure/index.mjs +266 -23
  28. package/dist/core/erasure/reed-solomon.mjs +68 -4
  29. package/dist/core/erasure/utils.mjs +0 -2
  30. package/dist/core/errors.mjs +29 -8
  31. package/dist/core/index.d.ts +1 -1
  32. package/dist/core/index.mjs +3711 -142
  33. package/dist/core/layout.mjs +37 -5
  34. package/dist/core/networks.mjs +10 -5
  35. package/dist/core/operations/generated/sdk.d.ts +9 -0
  36. package/dist/core/operations/generated/sdk.mjs +183 -18
  37. package/dist/core/operations/index.mjs +284 -24
  38. package/dist/core/promises.mjs +4 -4
  39. package/dist/core/rpc-responses.mjs +29 -10
  40. package/dist/core/shelby-explorer.mjs +31 -6
  41. package/dist/core/strings.mjs +0 -2
  42. package/dist/core/types/blobs.mjs +0 -1
  43. package/dist/core/types/index.mjs +230 -9
  44. package/dist/core/types/payments.d.ts +6 -6
  45. package/dist/core/types/payments.mjs +230 -5
  46. package/dist/core/types/placement_groups.mjs +0 -1
  47. package/dist/core/types/storage_providers.mjs +0 -1
  48. package/dist/core/utils.mjs +94 -8
  49. package/dist/node/clients/ShelbyNodeClient.d.ts +1 -0
  50. package/dist/node/clients/ShelbyNodeClient.mjs +2919 -24
  51. package/dist/node/clients/index.d.ts +1 -0
  52. package/dist/node/clients/index.mjs +2920 -26
  53. package/dist/node/index.d.ts +1 -1
  54. package/dist/node/index.mjs +3734 -149
  55. package/dist/node/parallel/commitment_worker.d.ts +9 -0
  56. package/dist/node/parallel/commitment_worker.mjs +298 -0
  57. package/dist/node/parallel/commitment_worker_pool.d.ts +35 -0
  58. package/dist/node/parallel/commitment_worker_pool.mjs +286 -0
  59. package/dist/node/parallel/default_commitment_worker_pool.d.ts +24 -0
  60. package/dist/node/parallel/default_commitment_worker_pool.mjs +302 -0
  61. package/dist/node/parallel/index.d.ts +11 -0
  62. package/dist/node/parallel/index.mjs +563 -0
  63. package/dist/node/parallel/parallel_commitments.d.ts +32 -0
  64. package/dist/node/parallel/parallel_commitments.mjs +561 -0
  65. package/dist/node/parallel/worker_pool.d.ts +74 -0
  66. package/dist/node/parallel/worker_pool.mjs +248 -0
  67. package/dist/node/testUtil.mjs +8 -4
  68. package/package.json +6 -2
  69. package/dist/chunk-3NRBHSMQ.mjs +0 -12
  70. package/dist/chunk-5BVSWXQJ.mjs +0 -801
  71. package/dist/chunk-6FJNAUU5.mjs +0 -278
  72. package/dist/chunk-6XSZRDLJ.mjs +0 -375
  73. package/dist/chunk-7P6ASYW6.mjs +0 -9
  74. package/dist/chunk-A4IG6GSE.mjs +0 -21
  75. package/dist/chunk-AD2G3QYD.mjs +0 -0
  76. package/dist/chunk-AUQDI5BS.mjs +0 -43
  77. package/dist/chunk-AY3HBWXA.mjs +0 -51
  78. package/dist/chunk-BDSW5PHM.mjs +0 -37
  79. package/dist/chunk-C6RQ3AEU.mjs +0 -51
  80. package/dist/chunk-CQ6QPIZK.mjs +0 -37
  81. package/dist/chunk-D6GQHO6G.mjs +0 -15
  82. package/dist/chunk-EM67QTMR.mjs +0 -0
  83. package/dist/chunk-I6NG5GNL.mjs +0 -8
  84. package/dist/chunk-JTXYKO3U.mjs +0 -38
  85. package/dist/chunk-KG2TMLEV.mjs +0 -207
  86. package/dist/chunk-M3CP5TFP.mjs +0 -39
  87. package/dist/chunk-M7W43K2Q.mjs +0 -505
  88. package/dist/chunk-MB7C7VQF.mjs +0 -0
  89. package/dist/chunk-MNCQBEMS.mjs +0 -55
  90. package/dist/chunk-MQUVYMNQ.mjs +0 -0
  91. package/dist/chunk-NEO7Z3ZQ.mjs +0 -49
  92. package/dist/chunk-NHWWORCH.mjs +0 -72
  93. package/dist/chunk-OEK24ON7.mjs +0 -135
  94. package/dist/chunk-QQ57OGQ2.mjs +0 -0
  95. package/dist/chunk-RNNJXTX2.mjs +0 -154
  96. package/dist/chunk-S6Q4OG7H.mjs +0 -83
  97. package/dist/chunk-TET3DJEO.mjs +0 -199
  98. package/dist/chunk-UEZNZBJO.mjs +0 -104
  99. package/dist/chunk-V46D5NBW.mjs +0 -11
  100. package/dist/chunk-V4B3GAMQ.mjs +0 -42
  101. package/dist/chunk-WFWRBNTW.mjs +0 -412
  102. package/dist/chunk-WTICJPDB.mjs +0 -0
  103. package/dist/chunk-XNEIWM4O.mjs +0 -0
  104. package/dist/chunk-Z4FZ7W6L.mjs +0 -39
  105. package/dist/chunk-Z7RFCADT.mjs +0 -0
  106. package/dist/chunk-ZHXCVRZX.mjs +0 -0
@@ -1,21 +1,1088 @@
1
+ // src/core/clients/ShelbyBlobClient.ts
1
2
  import {
2
- MissingTransactionSubmitterError,
3
- ShelbyBlobClient
4
- } from "../../chunk-5BVSWXQJ.mjs";
5
- import "../../chunk-XNEIWM4O.mjs";
6
- import "../../chunk-NHWWORCH.mjs";
7
- import "../../chunk-AY3HBWXA.mjs";
8
- import "../../chunk-OEK24ON7.mjs";
9
- import "../../chunk-NEO7Z3ZQ.mjs";
10
- import "../../chunk-TET3DJEO.mjs";
11
- import "../../chunk-V4B3GAMQ.mjs";
12
- import "../../chunk-3NRBHSMQ.mjs";
13
- import "../../chunk-RNNJXTX2.mjs";
14
- import "../../chunk-UEZNZBJO.mjs";
15
- import "../../chunk-JTXYKO3U.mjs";
16
- import "../../chunk-AUQDI5BS.mjs";
17
- import "../../chunk-MNCQBEMS.mjs";
18
- import "../../chunk-7P6ASYW6.mjs";
3
+ AccountAddress as AccountAddress2,
4
+ Aptos,
5
+ Hex as Hex3,
6
+ U32
7
+ } from "@aptos-labs/ts-sdk";
8
+
9
+ // src/core/utils.ts
10
+ import {
11
+ AccountAddress,
12
+ Hex
13
+ } from "@aptos-labs/ts-sdk";
14
+ function getBlobNameSuffix(blobName) {
15
+ const parts = blobName.split("/");
16
+ return parts.slice(1).join("/") || "";
17
+ }
18
+ function normalizeAddress(address) {
19
+ return AccountAddress.from(address, { maxMissingChars: 63 });
20
+ }
21
+
22
+ // src/core/blobs.ts
23
+ var createBlobKey = (params) => {
24
+ return `@${normalizeAddress(params.account).toStringLongWithoutPrefix()}/${params.blobName}`;
25
+ };
26
+
27
+ // src/core/erasure/constants.ts
28
+ var ERASURE_CODE_PARAMS = {
29
+ ["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */]: {
30
+ // total chunks (data + parity)
31
+ erasure_n: 16,
32
+ // data chunks
33
+ erasure_k: 10,
34
+ // helper nodes
35
+ erasure_d: 13,
36
+ // enum index
37
+ enumIndex: 0
38
+ },
39
+ ["ClayCode_4Total_2Data_3Helper" /* ClayCode_4Total_2Data_3Helper */]: {
40
+ // total chunks (data + parity)
41
+ erasure_n: 4,
42
+ // data chunks
43
+ erasure_k: 2,
44
+ // helper nodes
45
+ erasure_d: 3,
46
+ // enum index
47
+ enumIndex: 1
48
+ }
49
+ };
50
+ var DEFAULT_ERASURE_N = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_n;
51
+ var DEFAULT_ERASURE_K = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_k;
52
+ var DEFAULT_ERASURE_D = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_d;
53
+ var DEFAULT_ERASURE_M = DEFAULT_ERASURE_N - DEFAULT_ERASURE_K;
54
+
55
+ // src/core/chunk.ts
56
+ var CHUNK_SIZE_PARAMS = {
57
+ ["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */]: {
58
+ // 1MiB
59
+ chunkSizeBytes: 1 * 1024 * 1024,
60
+ // 10MiB
61
+ chunksetSizeBytes: 10 * 1024 * 1024
62
+ },
63
+ ["ChunkSet2MiB_Chunk1MiB" /* ChunkSet2MiB_Chunk1MiB */]: {
64
+ // 1MiB
65
+ chunkSizeBytes: 1 * 1024 * 1024,
66
+ // 2MiB
67
+ chunksetSizeBytes: 2 * 1024 * 1024
68
+ }
69
+ };
70
+ var DEFAULT_CHUNK_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */].chunkSizeBytes;
71
+ var DEFAULT_CHUNKSET_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */].chunksetSizeBytes;
72
+ var ERASURE_CODE_AND_CHUNK_MAPPING = {
73
+ ["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */]: {
74
+ ...CHUNK_SIZE_PARAMS.ChunkSet10MiB_Chunk1MiB
75
+ },
76
+ ["ClayCode_4Total_2Data_3Helper" /* ClayCode_4Total_2Data_3Helper */]: {
77
+ ...CHUNK_SIZE_PARAMS.ChunkSet2MiB_Chunk1MiB
78
+ }
79
+ };
80
+
81
+ // src/core/commitments.ts
82
+ import { Hex as Hex2 } from "@aptos-labs/ts-sdk";
83
+ import { z } from "zod";
84
+ var ChunksetCommitmentSchema = z.object({
85
+ // Chunkset root (vector commitment of child chunks)
86
+ chunkset_root: z.string(),
87
+ // the size is known statically from the current configuration
88
+ chunk_commitments: z.array(z.string())
89
+ }).refine(
90
+ (data) => {
91
+ return data.chunk_commitments.length === DEFAULT_ERASURE_K + DEFAULT_ERASURE_M;
92
+ },
93
+ {
94
+ message: `Chunkset must have exactly ${DEFAULT_ERASURE_K + DEFAULT_ERASURE_M} chunks (ERASURE_K + ERASURE_M = ${DEFAULT_ERASURE_K} + ${DEFAULT_ERASURE_M})`,
95
+ path: ["chunk_commitments"]
96
+ }
97
+ );
98
+ function expectedTotalChunksets(rawSize, chunksetSize = DEFAULT_CHUNKSET_SIZE_BYTES) {
99
+ if (chunksetSize <= 0) {
100
+ throw new Error("chunksetSize must be positive");
101
+ }
102
+ if (rawSize === 0) return 1;
103
+ return Math.ceil(rawSize / chunksetSize);
104
+ }
105
+ var BlobCommitmentsSchema = z.object({
106
+ schema_version: z.string(),
107
+ raw_data_size: z.number(),
108
+ // FIXME I am not sure about this being here, or if it should be somewhere else
109
+ blob_merkle_root: z.string(),
110
+ chunkset_commitments: z.array(ChunksetCommitmentSchema)
111
+ }).refine(
112
+ (data) => {
113
+ return expectedTotalChunksets(data.raw_data_size) === data.chunkset_commitments.length;
114
+ },
115
+ {
116
+ message: "Total chunkset count mismatches with raw data size",
117
+ // FIXME put more details in here
118
+ path: ["chunkset_commitments"]
119
+ }
120
+ );
121
+
122
+ // src/core/constants.ts
123
+ import { Network } from "@aptos-labs/ts-sdk";
124
+ var NetworkToShelbyRPCBaseUrl = {
125
+ [Network.SHELBYNET]: "https://api.shelbynet.shelby.xyz/shelby",
126
+ [Network.NETNA]: void 0,
127
+ [Network.DEVNET]: void 0,
128
+ [Network.TESTNET]: "https://api.testnet.shelby.xyz/shelby",
129
+ [Network.MAINNET]: void 0,
130
+ [Network.LOCAL]: "http://localhost:9090",
131
+ [Network.CUSTOM]: void 0
132
+ };
133
+ var NetworkToShelbyBlobIndexerBaseUrl = {
134
+ [Network.SHELBYNET]: "https://api.shelbynet.aptoslabs.com/nocode/v1/public/alias/shelby/shelbynet/v1/graphql",
135
+ [Network.NETNA]: void 0,
136
+ [Network.DEVNET]: void 0,
137
+ [Network.TESTNET]: "https://api.testnet.aptoslabs.com/nocode/v1/public/alias/shelby/testnet/v1/graphql",
138
+ [Network.MAINNET]: void 0,
139
+ [Network.LOCAL]: "http://localhost:8091/v1/graphql",
140
+ [Network.CUSTOM]: void 0
141
+ };
142
+ var NetworkToGasStationBaseUrl = {
143
+ [Network.SHELBYNET]: "https://api.shelbynet.shelby.xyz/gs/v1",
144
+ [Network.NETNA]: void 0,
145
+ [Network.DEVNET]: void 0,
146
+ [Network.TESTNET]: "https://api.testnet.shelby.xyz/gs/v1",
147
+ [Network.MAINNET]: void 0,
148
+ [Network.LOCAL]: void 0,
149
+ [Network.CUSTOM]: void 0
150
+ };
151
+ var SHELBY_DEPLOYER = "0x85fdb9a176ab8ef1d9d9c1b60d60b3924f0800ac1de1cc2085fb0b8bb4988e6a";
152
+
153
+ // src/core/erasure/clay-codes.ts
154
+ import {
155
+ createDecoder,
156
+ createEncoder
157
+ } from "@shelby-protocol/clay-codes";
158
+
159
+ // src/core/erasure/default.ts
160
+ function defaultErasureCodingConfig() {
161
+ const encoding = Number(process.env.SHELBY_ENCODING) || 0;
162
+ if (encoding === 0) {
163
+ return erasureCodingConfig16Total10Data13Helper();
164
+ }
165
+ return erasureCodingConfig4Total2Data3Helper();
166
+ }
167
+ function erasureCodingConfig16Total10Data13Helper() {
168
+ return erasureCodingConfig(
169
+ "ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */
170
+ );
171
+ }
172
+ function erasureCodingConfig4Total2Data3Helper() {
173
+ return erasureCodingConfig("ClayCode_4Total_2Data_3Helper" /* ClayCode_4Total_2Data_3Helper */);
174
+ }
175
+ function erasureCodingConfig(encodingScheme) {
176
+ return {
177
+ erasure_n: ERASURE_CODE_PARAMS[encodingScheme].erasure_n,
178
+ erasure_k: ERASURE_CODE_PARAMS[encodingScheme].erasure_k,
179
+ erasure_d: ERASURE_CODE_PARAMS[encodingScheme].erasure_d,
180
+ chunkSizeBytes: DEFAULT_CHUNK_SIZE_BYTES,
181
+ enumIndex: ERASURE_CODE_PARAMS[encodingScheme].enumIndex
182
+ };
183
+ }
184
+
185
+ // src/core/erasure/reed-solomon.ts
186
+ import { createWasmReedSolomonBinding } from "@shelby-protocol/reed-solomon";
187
+ var DEFAULT_CHUNK_SIZE_BYTES2 = 2 * 1024 * 1024;
188
+
189
+ // src/core/operations/index.ts
190
+ import { Network as Network2 } from "@aptos-labs/ts-sdk";
191
+ import { GraphQLClient } from "graphql-request";
192
+
193
+ // src/core/clients/utils.ts
194
+ import { AptosConfig } from "@aptos-labs/ts-sdk";
195
+ var getAptosConfig = (config) => {
196
+ const baseFaucetConfig = config.faucet?.authToken ? { AUTH_TOKEN: config.faucet.authToken } : void 0;
197
+ if (config.aptos) {
198
+ return new AptosConfig({
199
+ // Spread user's aptos config first
200
+ ...config.aptos,
201
+ // Network from top-level is authoritative - cannot be overridden
202
+ network: config.network,
203
+ // Merge clientConfig with API_KEY default
204
+ clientConfig: {
205
+ API_KEY: config.apiKey,
206
+ ...config.aptos.clientConfig
207
+ },
208
+ // Merge faucetConfig: aptos config first, then base authToken (authoritative)
209
+ faucetConfig: {
210
+ ...config.aptos.faucetConfig,
211
+ ...baseFaucetConfig
212
+ }
213
+ });
214
+ }
215
+ return new AptosConfig({
216
+ network: config.network,
217
+ clientConfig: {
218
+ API_KEY: config.apiKey
219
+ },
220
+ faucetConfig: baseFaucetConfig
221
+ });
222
+ };
223
+
224
+ // src/core/operations/generated/sdk.ts
225
+ import gql from "graphql-tag";
226
+ var GetBlobsDocument = gql`
227
+ query getBlobs($where: blobs_bool_exp, $orderBy: [blobs_order_by!], $limit: Int, $offset: Int) {
228
+ blobs(where: $where, order_by: $orderBy, limit: $limit, offset: $offset) {
229
+ owner
230
+ blob_commitment
231
+ blob_name
232
+ created_at
233
+ expires_at
234
+ num_chunksets
235
+ is_deleted
236
+ is_written
237
+ placement_group
238
+ size
239
+ updated_at
240
+ slice_address
241
+ }
242
+ }
243
+ `;
244
+ var GetBlobActivitiesDocument = gql`
245
+ query getBlobActivities($where: blob_activities_bool_exp, $orderBy: [blob_activities_order_by!], $limit: Int, $offset: Int) {
246
+ blob_activities(
247
+ where: $where
248
+ order_by: $orderBy
249
+ limit: $limit
250
+ offset: $offset
251
+ ) {
252
+ blob_name
253
+ event_index
254
+ event_type
255
+ transaction_hash
256
+ transaction_version
257
+ timestamp
258
+ owner
259
+ }
260
+ }
261
+ `;
262
+ var GetBlobsCountDocument = gql`
263
+ query getBlobsCount($where: blobs_bool_exp) {
264
+ blobs_aggregate(where: $where) {
265
+ aggregate {
266
+ count
267
+ }
268
+ }
269
+ }
270
+ `;
271
+ var GetBlobActivitiesCountDocument = gql`
272
+ query getBlobActivitiesCount($where: blob_activities_bool_exp) {
273
+ blob_activities_aggregate(where: $where) {
274
+ aggregate {
275
+ count
276
+ }
277
+ }
278
+ }
279
+ `;
280
+ var GetTotalBlobsSizeDocument = gql`
281
+ query getTotalBlobsSize($where: blobs_bool_exp) {
282
+ blobs_aggregate(where: $where) {
283
+ aggregate {
284
+ sum {
285
+ size
286
+ }
287
+ }
288
+ }
289
+ }
290
+ `;
291
+ var GetPlacementGroupSlotsDocument = gql`
292
+ query getPlacementGroupSlots($where: placement_group_slots_bool_exp, $orderBy: [placement_group_slots_order_by!], $limit: Int, $offset: Int) {
293
+ placement_group_slots(
294
+ where: $where
295
+ order_by: $orderBy
296
+ limit: $limit
297
+ offset: $offset
298
+ ) {
299
+ placement_group
300
+ slot_index
301
+ storage_provider
302
+ status
303
+ updated_at
304
+ }
305
+ }
306
+ `;
307
+ var GetPlacementGroupSlotsCountDocument = gql`
308
+ query getPlacementGroupSlotsCount($where: placement_group_slots_bool_exp) {
309
+ placement_group_slots_aggregate(where: $where) {
310
+ aggregate {
311
+ count
312
+ }
313
+ }
314
+ }
315
+ `;
316
+ var GetProcessorStatusDocument = gql`
317
+ query getProcessorStatus {
318
+ processor_status {
319
+ last_success_version
320
+ last_transaction_timestamp
321
+ last_updated
322
+ }
323
+ }
324
+ `;
325
+ var defaultWrapper = (action, _operationName, _operationType, _variables) => action();
326
+ function getSdk(client, withWrapper = defaultWrapper) {
327
+ return {
328
+ getBlobs(variables, requestHeaders, signal) {
329
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetBlobsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "getBlobs", "query", variables);
330
+ },
331
+ getBlobActivities(variables, requestHeaders, signal) {
332
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetBlobActivitiesDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "getBlobActivities", "query", variables);
333
+ },
334
+ getBlobsCount(variables, requestHeaders, signal) {
335
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetBlobsCountDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "getBlobsCount", "query", variables);
336
+ },
337
+ getBlobActivitiesCount(variables, requestHeaders, signal) {
338
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetBlobActivitiesCountDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "getBlobActivitiesCount", "query", variables);
339
+ },
340
+ getTotalBlobsSize(variables, requestHeaders, signal) {
341
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetTotalBlobsSizeDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "getTotalBlobsSize", "query", variables);
342
+ },
343
+ getPlacementGroupSlots(variables, requestHeaders, signal) {
344
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetPlacementGroupSlotsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "getPlacementGroupSlots", "query", variables);
345
+ },
346
+ getPlacementGroupSlotsCount(variables, requestHeaders, signal) {
347
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetPlacementGroupSlotsCountDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "getPlacementGroupSlotsCount", "query", variables);
348
+ },
349
+ getProcessorStatus(variables, requestHeaders, signal) {
350
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetProcessorStatusDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "getProcessorStatus", "query", variables);
351
+ }
352
+ };
353
+ }
354
+
355
+ // src/core/operations/index.ts
356
+ function createShelbyIndexerClient(baseUrl, options) {
357
+ const graphqlClient = new GraphQLClient(baseUrl, options);
358
+ return getSdk(graphqlClient);
359
+ }
360
+ function getShelbyIndexerClient(config) {
361
+ const aptosConfig = getAptosConfig(config);
362
+ let { apiKey: indexerApiKey, baseUrl } = config.indexer ?? {};
363
+ if (!baseUrl) {
364
+ switch (aptosConfig?.network) {
365
+ // TODO: Add endpoints for core networks
366
+ case Network2.MAINNET:
367
+ case Network2.TESTNET:
368
+ case Network2.DEVNET:
369
+ case Network2.SHELBYNET:
370
+ case Network2.LOCAL:
371
+ baseUrl = NetworkToShelbyBlobIndexerBaseUrl[aptosConfig.network];
372
+ break;
373
+ }
374
+ }
375
+ if (baseUrl === void 0) {
376
+ throw new Error(
377
+ "The ShelbyClientConfig does not support the Shelby indexer. Please configure the endpoint in the ShelbyClientConfig.indexer.endpoint or provide a supported Aptos network."
378
+ );
379
+ }
380
+ const apiKey = indexerApiKey ?? config.apiKey;
381
+ return createShelbyIndexerClient(baseUrl, {
382
+ headers: {
383
+ ...apiKey ? { Authorization: `Bearer ${apiKey}` } : {},
384
+ "x-aptos-client": "shelby-ts-sdk"
385
+ }
386
+ });
387
+ }
388
+
389
+ // src/core/clients/ShelbyBlobClient.ts
390
+ var MissingTransactionSubmitterError = class extends Error {
391
+ constructor() {
392
+ super(
393
+ "USD sponsorship (usdSponsor) requires a transaction submitter to be configured. The sponsored transaction is a multi-agent transaction that must be co-signed by the sponsor. Configure a transaction submitter via aptos.pluginSettings.TRANSACTION_SUBMITTER that routes transactions to a service (like a gas station) capable of providing the sponsor's signature."
394
+ );
395
+ this.name = "MissingTransactionSubmitterError";
396
+ }
397
+ };
398
+ var ShelbyBlobClient = class _ShelbyBlobClient {
399
+ aptos;
400
+ deployer;
401
+ indexer;
402
+ defaultOptions;
403
+ orderless;
404
+ /**
405
+ * The ShelbyBlobClient is used to interact with the Shelby contract on the Aptos blockchain. This
406
+ * includes functions for registering blob commitments and retrieving blob metadata.
407
+ *
408
+ * @param config - The client configuration object.
409
+ * @param config.network - The Shelby network to use.
410
+ * @param defaultOptions - Optional default options for blob operations.
411
+ *
412
+ * @example
413
+ * ```typescript
414
+ * const blobClient = new ShelbyBlobClient({
415
+ * aptos: {
416
+ * network: Network.SHELBYNET,
417
+ * clientConfig: {
418
+ * API_KEY: "AG-***",
419
+ * },
420
+ * },
421
+ * });
422
+ * ```
423
+ *
424
+ * @example
425
+ * ```typescript
426
+ * // With default options for USD sponsorship
427
+ * const blobClient = new ShelbyBlobClient(
428
+ * {
429
+ * network: Network.SHELBYNET,
430
+ * aptos: {
431
+ * pluginSettings: {
432
+ * TRANSACTION_SUBMITTER: myGasStationSubmitter,
433
+ * },
434
+ * },
435
+ * },
436
+ * {
437
+ * usdSponsor: { feePayerAddress: sponsorAddress },
438
+ * }
439
+ * );
440
+ * ```
441
+ */
442
+ constructor(config, defaultOptions) {
443
+ this.aptos = new Aptos(getAptosConfig(config));
444
+ this.deployer = config.deployer ?? AccountAddress2.fromString(SHELBY_DEPLOYER);
445
+ this.indexer = getShelbyIndexerClient(config);
446
+ this.defaultOptions = defaultOptions ?? {};
447
+ this.orderless = config.orderless ?? false;
448
+ }
449
+ /**
450
+ * Merges method-level options with default options, giving precedence to method-level values.
451
+ */
452
+ mergeOptions(options) {
453
+ return {
454
+ build: options?.build ?? this.defaultOptions.build,
455
+ submit: options?.submit ?? this.defaultOptions.submit,
456
+ usdSponsor: options?.usdSponsor ?? this.defaultOptions.usdSponsor,
457
+ chunksetSizeBytes: options?.chunksetSizeBytes ?? this.defaultOptions.chunksetSizeBytes
458
+ };
459
+ }
460
+ /**
461
+ * Validates that if USD sponsorship is requested, a transaction submitter is
462
+ * configured as well. Checks both the client-level and method-level transaction
463
+ * submitter configurations. Throws MissingTransactionSubmitterError if usdSponsor is
464
+ * provided without a transaction submitter.
465
+ */
466
+ validateUsdSponsorConfig(usdSponsor, submit) {
467
+ if (!usdSponsor) {
468
+ return;
469
+ }
470
+ const hasClientSubmitter = this.aptos.config.getTransactionSubmitter();
471
+ const hasMethodSubmitter = submit?.transactionSubmitter !== void 0 && submit?.transactionSubmitter !== null;
472
+ if (!hasClientSubmitter && !hasMethodSubmitter) {
473
+ throw new MissingTransactionSubmitterError();
474
+ }
475
+ }
476
+ /**
477
+ * Merges orderless replay protection into transaction options when
478
+ * `config.orderless` is enabled. If the caller already supplies options
479
+ * (e.g. custom gas limits), those are preserved and the nonce is injected
480
+ * alongside them. When orderless mode is off, user options are returned as-is.
481
+ */
482
+ orderlessTxOptions(userOptions) {
483
+ if (!this.orderless) return userOptions;
484
+ return {
485
+ replayProtectionNonce: crypto.getRandomValues(new Uint32Array(1))[0],
486
+ ...userOptions
487
+ };
488
+ }
489
+ /**
490
+ * Retrieves the blob metadata from the blockchain. If it does not exist,
491
+ * returns `undefined`.
492
+ *
493
+ * @param params.account - The account namespace the blob is stored in (e.g. "0x1")
494
+ * @param params.name - The name of the blob (e.g. "foo/bar")
495
+ * @returns The blob metadata.
496
+ *
497
+ * @example
498
+ * ```typescript
499
+ * const metadata = await client.getBlobMetadata({
500
+ * account: AccountAddress.fromString("0x1"),
501
+ * name: "foo/bar.txt",
502
+ * });
503
+ * ```
504
+ */
505
+ async getBlobMetadata(params) {
506
+ try {
507
+ const rawMetadata = await this.aptos.view({
508
+ payload: {
509
+ function: `${this.deployer.toString()}::blob_metadata::get_blob_metadata`,
510
+ functionArguments: [
511
+ createBlobKey({
512
+ account: params.account,
513
+ blobName: params.name
514
+ })
515
+ ]
516
+ }
517
+ });
518
+ if (!rawMetadata?.[0]?.vec?.[0]) {
519
+ return void 0;
520
+ }
521
+ const metadata = rawMetadata[0].vec[0];
522
+ let encoding;
523
+ if (metadata.encoding.__variant__ === "ClayCode_16Total_10Data_13Helper") {
524
+ encoding = {
525
+ variant: "clay",
526
+ ...ERASURE_CODE_PARAMS[metadata.encoding.__variant__],
527
+ ...ERASURE_CODE_AND_CHUNK_MAPPING[metadata.encoding.__variant__]
528
+ };
529
+ } else if (metadata.encoding.__variant__ === "ClayCode_4Total_2Data_3Helper") {
530
+ encoding = {
531
+ variant: "clay",
532
+ ...ERASURE_CODE_PARAMS[metadata.encoding.__variant__],
533
+ ...ERASURE_CODE_AND_CHUNK_MAPPING[metadata.encoding.__variant__]
534
+ };
535
+ } else {
536
+ throw new Error(
537
+ "Could not parse encoding from Shelby Smart Contract, this SDK is out of date."
538
+ );
539
+ }
540
+ return {
541
+ blobMerkleRoot: Hex3.fromHexInput(
542
+ metadata.blob_commitment
543
+ ).toUint8Array(),
544
+ owner: normalizeAddress(metadata.owner),
545
+ name: params.name,
546
+ blobNameSuffix: getBlobNameSuffix(params.name),
547
+ size: Number(metadata.blob_size),
548
+ encoding,
549
+ expirationMicros: Number(metadata.expiration_micros),
550
+ creationMicros: Number(metadata.creation_micros),
551
+ sliceAddress: normalizeAddress(metadata.slice.inner),
552
+ isWritten: metadata.is_written
553
+ };
554
+ } catch (error) {
555
+ if (error instanceof Error && // Depending on the network, the error message may show up differently.
556
+ (error.message?.includes("sub_status: Some(404)") || error.message?.includes("EBLOB_NOT_FOUND"))) {
557
+ return void 0;
558
+ }
559
+ throw error;
560
+ }
561
+ }
562
+ /**
563
+ * Retrieves all the blobs and their metadata for an account from the
564
+ * blockchain.
565
+ *
566
+ * @param params.account - The account namespace the blobs are stored in (e.g. "0x1")
567
+ * @param params.pagination (optional) - The pagination options.
568
+ * @param params.orderBy (optional) - The order by clause to sort the blobs by.
569
+ * @returns The blob metadata for all the blobs for the account.
570
+ *
571
+ * @example
572
+ * ```typescript
573
+ * // BlobMetadata[]
574
+ * const blobs = await client.getAccountBlobs({
575
+ * account: AccountAddress.fromString("0x1"),
576
+ * });
577
+ * ```
578
+ */
579
+ getAccountBlobs(params) {
580
+ const { where, ...rest } = params;
581
+ return this.getBlobs({
582
+ where: {
583
+ ...where,
584
+ owner: { _eq: normalizeAddress(params.account).toString() }
585
+ },
586
+ pagination: rest.pagination,
587
+ orderBy: rest.orderBy
588
+ });
589
+ }
590
+ /**
591
+ * Retrieves blobs and their metadata from the blockchain.
592
+ *
593
+ * @param params.where (optional) - The where clause to filter the blobs by.
594
+ * @param params.pagination (optional) - The pagination options.
595
+ * @param params.orderBy (optional) - The order by clause to sort the blobs by.
596
+ * @returns The blob metadata for all the blobs that match the where clause.
597
+ *
598
+ * @example
599
+ * ```typescript
600
+ * // BlobMetadata[]
601
+ * const blobs = await client.getBlobs({
602
+ * where: { owner: { _eq: AccountAddress.fromString("0x1").toString() } },
603
+ * });
604
+ * ```
605
+ */
606
+ async getBlobs(params = {}) {
607
+ const { limit, offset } = params.pagination ?? {};
608
+ const { orderBy, where } = params;
609
+ const currentMicros = String(Date.now() * 1e3);
610
+ const defaultActiveFilter = {
611
+ expires_at: { _gte: currentMicros },
612
+ is_deleted: { _eq: "0" }
613
+ };
614
+ const finalWhere = where !== void 0 ? { ...defaultActiveFilter, ...where } : defaultActiveFilter;
615
+ const { blobs } = await this.indexer.getBlobs({
616
+ where: finalWhere,
617
+ limit,
618
+ offset,
619
+ orderBy
620
+ });
621
+ return blobs.map(
622
+ (blob) => ({
623
+ owner: normalizeAddress(blob.owner),
624
+ name: blob.blob_name,
625
+ blobNameSuffix: getBlobNameSuffix(blob.blob_name),
626
+ blobMerkleRoot: Hex3.fromHexInput(blob.blob_commitment).toUint8Array(),
627
+ size: Number(blob.size),
628
+ // TODO: Add encoding when supported in NCI
629
+ encoding: {
630
+ variant: "clay",
631
+ ...ERASURE_CODE_PARAMS.ClayCode_16Total_10Data_13Helper,
632
+ ...ERASURE_CODE_AND_CHUNK_MAPPING.ClayCode_16Total_10Data_13Helper
633
+ },
634
+ expirationMicros: Number(blob.expires_at),
635
+ creationMicros: Number(blob.created_at),
636
+ sliceAddress: normalizeAddress(blob.slice_address),
637
+ isWritten: Boolean(Number(blob.is_written)),
638
+ isDeleted: Boolean(Number(blob.is_deleted))
639
+ })
640
+ );
641
+ }
642
+ async getBlobActivities(params) {
643
+ const { limit, offset } = params.pagination ?? {};
644
+ const { orderBy, where } = params;
645
+ const { blob_activities } = await this.indexer.getBlobActivities({
646
+ where,
647
+ limit,
648
+ offset,
649
+ orderBy
650
+ });
651
+ const activityTypeMapping = {
652
+ [`${this.deployer.toStringLong()}::blob_metadata::BlobRegisteredEvent`]: "register_blob",
653
+ [`${this.deployer.toStringLong()}::blob_metadata::BlobDeletedEvent`]: "delete_blob",
654
+ [`${this.deployer.toStringLong()}::blob_metadata::BlobExpirationExtendedEvent`]: "extend_blob_expiration",
655
+ [`${this.deployer.toStringLong()}::blob_metadata::BlobWrittenEvent`]: "write_blob"
656
+ };
657
+ return blob_activities.map(
658
+ (activity) => ({
659
+ blobName: activity.blob_name,
660
+ accountAddress: normalizeAddress(activity.blob_name.substring(1, 65)),
661
+ type: activityTypeMapping[activity.event_type] ?? "unknown",
662
+ eventType: activity.event_type,
663
+ eventIndex: Number(activity.event_index),
664
+ transactionHash: activity.transaction_hash,
665
+ // Using Number here in JS is technically not okay because txn version can be
666
+ // as large as u64::MAX, but it should be fine for a long while.
667
+ transactionVersion: Number(activity.transaction_version),
668
+ timestamp: `${activity.timestamp}Z`
669
+ })
670
+ );
671
+ }
672
+ /**
673
+ * Retrieves the total number of blobs from the blockchain.
674
+ *
675
+ * @param params.where (optional) - The where clause to filter the blobs by.
676
+ * @returns The total number of blobs.
677
+ *
678
+ * @example
679
+ * ```typescript
680
+ * const count = await client.getBlobsCount();
681
+ * ```
682
+ */
683
+ async getBlobsCount(params) {
684
+ const { where } = params;
685
+ const { blobs_aggregate } = await this.indexer.getBlobsCount({ where });
686
+ return blobs_aggregate?.aggregate?.count ?? 0;
687
+ }
688
+ /**
689
+ * Retrieves the total size of blobs from the blockchain.
690
+ *
691
+ * @param params.where (optional) - The where clause to filter the blobs by.
692
+ * @returns The total size of blobs in bytes.
693
+ *
694
+ * @example
695
+ * ```typescript
696
+ * const size = await client.getTotalBlobsSize();
697
+ * ```
698
+ */
699
+ async getTotalBlobsSize(params = {}) {
700
+ const { where } = params;
701
+ const { blobs_aggregate } = await this.indexer.getTotalBlobsSize({ where });
702
+ return Number(blobs_aggregate?.aggregate?.sum?.size ?? 0);
703
+ }
704
+ /**
705
+ * Retrieves the total number of blob activities from the blockchain.
706
+ *
707
+ * @param params.where (optional) - The where clause to filter the blob activities by.
708
+ * @returns The total number of blob activities.
709
+ *
710
+ * @example
711
+ * ```typescript
712
+ * const count = await client.getBlobActivitiesCount();
713
+ * ```
714
+ */
715
+ async getBlobActivitiesCount(params) {
716
+ const { where } = params;
717
+ const { blob_activities_aggregate } = await this.indexer.getBlobActivitiesCount({ where });
718
+ return blob_activities_aggregate?.aggregate?.count ?? 0;
719
+ }
720
+ /**
721
+ * Registers a blob on the blockchain by writing its merkle root and metadata.
722
+ *
723
+ * @param params.account - The account that is signing and paying for the transaction.
724
+ * @param params.blobName - The name/path of the blob (e.g. "foo/bar.txt").
725
+ * @param params.blobMerkleRoot - The merkle root of the blob commitments.
726
+ * @param params.size - The size of the blob in bytes.
727
+ * @param params.expirationMicros - The expiration time of the blob in microseconds.
728
+ * @param params.options - Optional transaction building options.
729
+ * @param params.options.chunksetSizeBytes - Custom chunkset size (defaults to DEFAULT_CHUNKSET_SIZE_BYTES).
730
+ * @param params.options.build - Additional Aptos transaction building options.
731
+ *
732
+ * @returns An object containing the pending transaction.
733
+ *
734
+ * @example
735
+ * ```typescript
736
+ * const provider = await ClayErasureCodingProvider.create();
737
+ * const blobCommitments = await generateCommitments(provider, data);
738
+ *
739
+ * const { transaction } = await client.registerBlob({
740
+ * account: signer,
741
+ * blobName: "foo/bar.txt",
742
+ * blobMerkleRoot: blobCommitments.blob_merkle_root,
743
+ * size: data.length,
744
+ * expirationMicros: Date.now() * 1000 + 3600_000_000, // 1 hour from now in microseconds
745
+ * });
746
+ * ```
747
+ */
748
+ async registerBlob(params) {
749
+ const options = this.mergeOptions(params.options);
750
+ this.validateUsdSponsorConfig(options.usdSponsor, options.submit);
751
+ const config = params.config ?? defaultErasureCodingConfig();
752
+ const chunksetSize = config.chunkSizeBytes * config.erasure_k;
753
+ const buildArgs = {
754
+ ...options.build,
755
+ options: this.orderlessTxOptions(options.build?.options),
756
+ data: _ShelbyBlobClient.createRegisterBlobPayload({
757
+ deployer: this.deployer,
758
+ account: params.account.accountAddress,
759
+ blobName: params.blobName,
760
+ blobSize: params.size,
761
+ blobMerkleRoot: params.blobMerkleRoot,
762
+ numChunksets: expectedTotalChunksets(params.size, chunksetSize),
763
+ expirationMicros: params.expirationMicros,
764
+ useSponsoredUsdVariant: options.usdSponsor !== void 0,
765
+ encoding: config.enumIndex
766
+ }),
767
+ sender: params.account.accountAddress
768
+ };
769
+ const transaction = options.usdSponsor ? await this.aptos.transaction.build.multiAgent({
770
+ ...buildArgs,
771
+ secondarySignerAddresses: [options.usdSponsor.feePayerAddress]
772
+ }) : await this.aptos.transaction.build.simple(buildArgs);
773
+ return {
774
+ transaction: await this.aptos.signAndSubmitTransaction({
775
+ signer: params.account,
776
+ transaction,
777
+ ...options.submit
778
+ })
779
+ };
780
+ }
781
+ /**
782
+ * Deletes a blob on the blockchain.
783
+ *
784
+ * @param params.account - The account that is signing and paying for the transaction.
785
+ * @param params.blobName - The name/path of the blob (e.g. "foo/bar.txt").
786
+ * @param params.options - Optional transaction building options.
787
+ *
788
+ * @returns An object containing the pending transaction.
789
+ *
790
+ * @example
791
+ * ```typescript
792
+ *
793
+ * const { transaction } = await client.deleteBlob({
794
+ * account: signer,
795
+ * blobName: "foo/bar.txt",
796
+ * });
797
+ * ```
798
+ */
799
+ async deleteBlob(params) {
800
+ const transaction = await this.aptos.transaction.build.simple({
801
+ options: this.orderlessTxOptions(params.options),
802
+ data: _ShelbyBlobClient.createDeleteBlobPayload({
803
+ deployer: this.deployer,
804
+ blobName: params.blobName
805
+ }),
806
+ sender: params.account.accountAddress
807
+ });
808
+ return {
809
+ transaction: await this.aptos.signAndSubmitTransaction({
810
+ signer: params.account,
811
+ transaction
812
+ })
813
+ };
814
+ }
815
+ /**
816
+ * Deletes multiple blobs on the blockchain in a single atomic transaction.
817
+ *
818
+ * **Note:** This function requires the `delete_multiple_blobs` entry function
819
+ * which will be deployed to the smart contract on 2026-02-04. Using this
820
+ * function before that date will result in a transaction failure.
821
+ *
822
+ * This operation is atomic: if any blob deletion fails (e.g., blob not found),
823
+ * the entire transaction fails and no blobs are deleted.
824
+ *
825
+ * @param params.account - The account that is signing and paying for the transaction.
826
+ * @param params.blobNames - Array of blob name suffixes without the account address prefix
827
+ * (e.g. ["foo/bar.txt", "baz.txt"], NOT ["0x1/foo/bar.txt"]). The account address
828
+ * prefix is automatically derived from the signer.
829
+ * @param params.options - Optional transaction building options.
830
+ *
831
+ * @returns An object containing the pending transaction.
832
+ *
833
+ * @example
834
+ * ```typescript
835
+ *
836
+ * const { transaction } = await client.deleteMultipleBlobs({
837
+ * account: signer,
838
+ * blobNames: ["foo/bar.txt", "baz.txt"],
839
+ * });
840
+ * ```
841
+ */
842
+ async deleteMultipleBlobs(params) {
843
+ const transaction = await this.aptos.transaction.build.simple({
844
+ options: this.orderlessTxOptions(params.options),
845
+ data: _ShelbyBlobClient.createDeleteMultipleBlobsPayload({
846
+ deployer: this.deployer,
847
+ blobNames: params.blobNames
848
+ }),
849
+ sender: params.account.accountAddress
850
+ });
851
+ return {
852
+ transaction: await this.aptos.signAndSubmitTransaction({
853
+ signer: params.account,
854
+ transaction
855
+ })
856
+ };
857
+ }
858
+ /**
859
+ * Registers multiple blobs on the blockchain by writing their merkle roots and metadata.
860
+ *
861
+ * @param params.account - The account that is signing and paying for the transaction.
862
+ * @param params.expirationMicros - The expiration time of the blobs in microseconds.
863
+ * @param params.blobs - The blobs to register.
864
+ * @param params.blobs.blobName - The name/path of the blob (e.g. "foo/bar.txt").
865
+ * @param params.blobs.blobSize - The size of the blob in bytes.
866
+ * @param params.blobs.blobMerkleRoot - The merkle root of the blob commitments as a hex string.
867
+ * @param params.options - Optional transaction building options.
868
+ * @param params.options.chunksetSizeBytes - Custom chunkset size (defaults to DEFAULT_CHUNKSET_SIZE_BYTES).
869
+ * @param params.options.build - Additional Aptos transaction building options.
870
+ *
871
+ * @returns An object containing the pending transaction.
872
+ *
873
+ * @example
874
+ * ```typescript
875
+ * const provider = await ClayErasureCodingProvider.create();
876
+ * const blobCommitments = await generateCommitments(provider, data);
877
+ *
878
+ * const { transaction } = await client.batchRegisterBlobs({
879
+ * account: signer,
880
+ * expirationMicros: Date.now() * 1000 + 3600_000_000, // 1 hour from now in microseconds
881
+ * blobs: [
882
+ * {
883
+ * blobName: "foo/bar.txt",
884
+ * blobSize: data.length,
885
+ * blobMerkleRoot: blobCommitments.blob_merkle_root,
886
+ * },
887
+ * ],
888
+ * });
889
+ * ```
890
+ */
891
+ async batchRegisterBlobs(params) {
892
+ const options = this.mergeOptions(params.options);
893
+ this.validateUsdSponsorConfig(options.usdSponsor, options.submit);
894
+ const config = params.config ?? defaultErasureCodingConfig();
895
+ const chunksetSize = config.chunkSizeBytes * config.erasure_k;
896
+ const buildArgs = {
897
+ ...options.build,
898
+ options: this.orderlessTxOptions(options.build?.options),
899
+ sender: params.account.accountAddress,
900
+ data: _ShelbyBlobClient.createBatchRegisterBlobsPayload({
901
+ deployer: this.deployer,
902
+ account: params.account.accountAddress,
903
+ expirationMicros: params.expirationMicros,
904
+ blobs: params.blobs.map((blob) => ({
905
+ blobName: blob.blobName,
906
+ blobSize: blob.blobSize,
907
+ blobMerkleRoot: blob.blobMerkleRoot,
908
+ numChunksets: expectedTotalChunksets(blob.blobSize, chunksetSize)
909
+ })),
910
+ useSponsoredUsdVariant: options.usdSponsor !== void 0,
911
+ encoding: config.enumIndex
912
+ })
913
+ };
914
+ const transaction = options.usdSponsor ? await this.aptos.transaction.build.multiAgent({
915
+ ...buildArgs,
916
+ secondarySignerAddresses: [options.usdSponsor.feePayerAddress]
917
+ }) : await this.aptos.transaction.build.simple(buildArgs);
918
+ return {
919
+ transaction: await this.aptos.signAndSubmitTransaction({
920
+ signer: params.account,
921
+ transaction,
922
+ ...options.submit
923
+ })
924
+ };
925
+ }
926
+ /**
927
+ * Creates a transaction payload to register a blob on the blockchain.
928
+ * This is a static helper method for constructing the Move function call payload.
929
+ *
930
+ * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
931
+ * @param params.account - The account that will own the blob.
932
+ * @param params.blobName - The name/path of the blob (e.g. "foo/bar.txt").
933
+ * @param params.blobSize - The size of the blob in bytes.
934
+ * @param params.blobMerkleRoot - The merkle root of the blob commitments as a hex string.
935
+ * @param params.expirationMicros - The expiration time of the blob in microseconds.
936
+ * @param params.numChunksets - The total number of chunksets in the blob.
937
+ *
938
+ * @returns An Aptos transaction payload data object for the register_blob Move function.
939
+ *
940
+ * @see https://github.com/shelby/shelby/blob/e08e84742cf2b80ad8bb7227deb3013398076d53/move/shelby_contract/sources/global_metadata.move#L357
941
+ */
942
+ static createRegisterBlobPayload(params) {
943
+ const functionName = params.useSponsoredUsdVariant ? "register_blob_with_sponsor" : "register_blob";
944
+ return {
945
+ function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::${functionName}`,
946
+ functionArguments: [
947
+ params.blobName,
948
+ params.expirationMicros,
949
+ Hex3.fromHexString(params.blobMerkleRoot).toUint8Array(),
950
+ params.numChunksets,
951
+ params.blobSize,
952
+ // TODO
953
+ 0,
954
+ // payment tier
955
+ params.encoding
956
+ ]
957
+ };
958
+ }
959
+ /**
960
+ * Creates a transaction payload to register multiple blobs on the blockchain.
961
+ * This is a static helper method for constructing the Move function call payload.
962
+ *
963
+ * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
964
+ * @param params.account - The account that will own the blobs.
965
+ * @param params.expirationMicros - The expiration time of the blobs in microseconds.
966
+ * @param params.blobs - The blobs to register.
967
+ * @param params.blobs.blobName - The name/path of the blob (e.g. "foo/bar.txt").
968
+ * @param params.blobs.blobSize - The size of the blob in bytes.
969
+ * @param params.blobs.blobMerkleRoot - The merkle root of the blob commitments as a hex string.
970
+ * @param params.blobs.numChunksets - The total number of chunksets in the blob.
971
+ *
972
+ * @returns An Aptos transaction payload data object for the register_multiple_blobs Move function.
973
+ *
974
+ * @see https://github.com/shelby/shelby/blob/e08e84742cf2b80ad8bb7227deb3013398076d53/move/shelby_contract/sources/global_metadata.move#L357
975
+ */
976
+ static createBatchRegisterBlobsPayload(params) {
977
+ const functionName = params.useSponsoredUsdVariant ? "register_multiple_blobs_with_sponsor" : "register_multiple_blobs";
978
+ const blobNames = [];
979
+ const blobMerkleRoots = [];
980
+ const blobNumChunksets = [];
981
+ const blobSizes = [];
982
+ params.blobs.forEach((blob) => {
983
+ blobNames.push(blob.blobName);
984
+ blobMerkleRoots.push(
985
+ Hex3.fromHexString(blob.blobMerkleRoot).toUint8Array()
986
+ );
987
+ blobNumChunksets.push(blob.numChunksets);
988
+ blobSizes.push(blob.blobSize);
989
+ });
990
+ return {
991
+ function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::${functionName}`,
992
+ functionArguments: [
993
+ blobNames,
994
+ params.expirationMicros,
995
+ blobMerkleRoots,
996
+ blobNumChunksets,
997
+ blobSizes,
998
+ // TODO
999
+ 0,
1000
+ // payment tier
1001
+ params.encoding
1002
+ ]
1003
+ };
1004
+ }
1005
+ /**
1006
+ * Creates a transaction payload to delete a blob on the blockchain.
1007
+ * This is a static helper method for constructing the Move function call payload.
1008
+ *
1009
+ * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
1010
+ * @param params.blobName - The blob name (e.g. "bar.txt", without the account address prefix).
1011
+ *
1012
+ * @returns An Aptos transaction payload data object for the delete_blob Move function.
1013
+ *
1014
+ * @see https://github.com/shelby/shelby/blob/64e9d7b4f0005e586faeb1e4085c79159234b6b6/move/shelby_contract/sources/global_metadata.move#L616
1015
+ */
1016
+ static createDeleteBlobPayload(params) {
1017
+ return {
1018
+ function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::delete_blob`,
1019
+ functionArguments: [params.blobName]
1020
+ };
1021
+ }
1022
+ /**
1023
+ * Creates a transaction payload to delete multiple blobs on the blockchain.
1024
+ * This is a static helper method for constructing the Move function call payload.
1025
+ *
1026
+ * **Note:** This function requires the `delete_multiple_blobs` entry function
1027
+ * which will be deployed to the smart contract on 2026-02-04. Using this
1028
+ * function before that date will result in a transaction failure.
1029
+ *
1030
+ * This operation is atomic: if any blob deletion fails (e.g., blob not found),
1031
+ * the entire transaction fails and no blobs are deleted.
1032
+ *
1033
+ * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
1034
+ * @param params.blobNames - Array of blob name suffixes without the account address prefix
1035
+ * (e.g. ["foo/bar.txt", "baz.txt"], NOT ["0x1/foo/bar.txt"]). The account address
1036
+ * prefix is automatically derived from the transaction sender.
1037
+ *
1038
+ * @returns An Aptos transaction payload data object for the delete_multiple_blobs Move function.
1039
+ *
1040
+ * @see https://github.com/shelby/shelby/blob/main/move/shelby_contract/sources/blob_metadata.move
1041
+ */
1042
+ static createDeleteMultipleBlobsPayload(params) {
1043
+ return {
1044
+ function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::delete_multiple_blobs`,
1045
+ functionArguments: [params.blobNames]
1046
+ };
1047
+ }
1048
+ static createBlobAcknowledgementsPayload(params) {
1049
+ const ackBitMask = params.storageProviderAcks.reduce(
1050
+ (acc, ack) => acc | 1 << ack.slot,
1051
+ 0
1052
+ );
1053
+ return {
1054
+ function: `${SHELBY_DEPLOYER}::blob_metadata::add_blob_acknowledgements`,
1055
+ functionArguments: [
1056
+ createBlobKey({
1057
+ account: params.blobOwner,
1058
+ blobName: params.blobName
1059
+ }),
1060
+ params.creationMicros,
1061
+ new U32(Number(ackBitMask)),
1062
+ params.storageProviderAcks.map((ack) => ack.signature)
1063
+ ]
1064
+ };
1065
+ }
1066
+ async addBlobAcknowledgements(params) {
1067
+ const transaction = await this.aptos.transaction.build.simple({
1068
+ ...params.options?.build,
1069
+ options: this.orderlessTxOptions(params.options?.build?.options),
1070
+ data: _ShelbyBlobClient.createBlobAcknowledgementsPayload({
1071
+ blobOwner: params.blobOwner,
1072
+ blobName: params.blobName,
1073
+ creationMicros: params.creationMicros,
1074
+ storageProviderAcks: params.storageProviderAcks
1075
+ }),
1076
+ sender: params.account.accountAddress
1077
+ });
1078
+ return {
1079
+ transaction: await this.aptos.signAndSubmitTransaction({
1080
+ signer: params.account,
1081
+ transaction
1082
+ })
1083
+ };
1084
+ }
1085
+ };
19
1086
  export {
20
1087
  MissingTransactionSubmitterError,
21
1088
  ShelbyBlobClient