@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,801 +0,0 @@
1
- import {
2
- defaultErasureCodingConfig
3
- } from "./chunk-AY3HBWXA.mjs";
4
- import {
5
- getShelbyIndexerClient
6
- } from "./chunk-NEO7Z3ZQ.mjs";
7
- import {
8
- getAptosConfig
9
- } from "./chunk-V4B3GAMQ.mjs";
10
- import {
11
- createBlobKey
12
- } from "./chunk-3NRBHSMQ.mjs";
13
- import {
14
- expectedTotalChunksets
15
- } from "./chunk-RNNJXTX2.mjs";
16
- import {
17
- getBlobNameSuffix,
18
- normalizeAddress
19
- } from "./chunk-UEZNZBJO.mjs";
20
- import {
21
- ERASURE_CODE_AND_CHUNK_MAPPING
22
- } from "./chunk-JTXYKO3U.mjs";
23
- import {
24
- ERASURE_CODE_PARAMS
25
- } from "./chunk-AUQDI5BS.mjs";
26
- import {
27
- SHELBY_DEPLOYER
28
- } from "./chunk-MNCQBEMS.mjs";
29
-
30
- // src/core/clients/ShelbyBlobClient.ts
31
- import {
32
- AccountAddress,
33
- Aptos,
34
- Hex,
35
- U32
36
- } from "@aptos-labs/ts-sdk";
37
- var MissingTransactionSubmitterError = class extends Error {
38
- constructor() {
39
- super(
40
- "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."
41
- );
42
- this.name = "MissingTransactionSubmitterError";
43
- }
44
- };
45
- var ShelbyBlobClient = class _ShelbyBlobClient {
46
- aptos;
47
- deployer;
48
- indexer;
49
- defaultOptions;
50
- orderless;
51
- /**
52
- * The ShelbyBlobClient is used to interact with the Shelby contract on the Aptos blockchain. This
53
- * includes functions for registering blob commitments and retrieving blob metadata.
54
- *
55
- * @param config - The client configuration object.
56
- * @param config.network - The Shelby network to use.
57
- * @param defaultOptions - Optional default options for blob operations.
58
- *
59
- * @example
60
- * ```typescript
61
- * const blobClient = new ShelbyBlobClient({
62
- * aptos: {
63
- * network: Network.SHELBYNET,
64
- * clientConfig: {
65
- * API_KEY: "AG-***",
66
- * },
67
- * },
68
- * });
69
- * ```
70
- *
71
- * @example
72
- * ```typescript
73
- * // With default options for USD sponsorship
74
- * const blobClient = new ShelbyBlobClient(
75
- * {
76
- * network: Network.SHELBYNET,
77
- * aptos: {
78
- * pluginSettings: {
79
- * TRANSACTION_SUBMITTER: myGasStationSubmitter,
80
- * },
81
- * },
82
- * },
83
- * {
84
- * usdSponsor: { feePayerAddress: sponsorAddress },
85
- * }
86
- * );
87
- * ```
88
- */
89
- constructor(config, defaultOptions) {
90
- this.aptos = new Aptos(getAptosConfig(config));
91
- this.deployer = config.deployer ?? AccountAddress.fromString(SHELBY_DEPLOYER);
92
- this.indexer = getShelbyIndexerClient(config);
93
- this.defaultOptions = defaultOptions ?? {};
94
- this.orderless = config.orderless ?? false;
95
- }
96
- /**
97
- * Merges method-level options with default options, giving precedence to method-level values.
98
- */
99
- mergeOptions(options) {
100
- return {
101
- build: options?.build ?? this.defaultOptions.build,
102
- submit: options?.submit ?? this.defaultOptions.submit,
103
- usdSponsor: options?.usdSponsor ?? this.defaultOptions.usdSponsor,
104
- chunksetSizeBytes: options?.chunksetSizeBytes ?? this.defaultOptions.chunksetSizeBytes
105
- };
106
- }
107
- /**
108
- * Validates that if USD sponsorship is requested, a transaction submitter is
109
- * configured as well. Checks both the client-level and method-level transaction
110
- * submitter configurations. Throws MissingTransactionSubmitterError if usdSponsor is
111
- * provided without a transaction submitter.
112
- */
113
- validateUsdSponsorConfig(usdSponsor, submit) {
114
- if (!usdSponsor) {
115
- return;
116
- }
117
- const hasClientSubmitter = this.aptos.config.getTransactionSubmitter();
118
- const hasMethodSubmitter = submit?.transactionSubmitter !== void 0 && submit?.transactionSubmitter !== null;
119
- if (!hasClientSubmitter && !hasMethodSubmitter) {
120
- throw new MissingTransactionSubmitterError();
121
- }
122
- }
123
- /**
124
- * Merges orderless replay protection into transaction options when
125
- * `config.orderless` is enabled. If the caller already supplies options
126
- * (e.g. custom gas limits), those are preserved and the nonce is injected
127
- * alongside them. When orderless mode is off, user options are returned as-is.
128
- */
129
- orderlessTxOptions(userOptions) {
130
- if (!this.orderless) return userOptions;
131
- return {
132
- replayProtectionNonce: crypto.getRandomValues(new Uint32Array(1))[0],
133
- ...userOptions
134
- };
135
- }
136
- /**
137
- * Retrieves the blob metadata from the blockchain. If it does not exist,
138
- * returns `undefined`.
139
- *
140
- * @param params.account - The account namespace the blob is stored in (e.g. "0x1")
141
- * @param params.name - The name of the blob (e.g. "foo/bar")
142
- * @returns The blob metadata.
143
- *
144
- * @example
145
- * ```typescript
146
- * const metadata = await client.getBlobMetadata({
147
- * account: AccountAddress.fromString("0x1"),
148
- * name: "foo/bar.txt",
149
- * });
150
- * ```
151
- */
152
- async getBlobMetadata(params) {
153
- try {
154
- const rawMetadata = await this.aptos.view({
155
- payload: {
156
- function: `${this.deployer.toString()}::blob_metadata::get_blob_metadata`,
157
- functionArguments: [
158
- createBlobKey({
159
- account: params.account,
160
- blobName: params.name
161
- })
162
- ]
163
- }
164
- });
165
- if (!rawMetadata?.[0]?.vec?.[0]) {
166
- return void 0;
167
- }
168
- const metadata = rawMetadata[0].vec[0];
169
- let encoding;
170
- if (metadata.encoding.__variant__ === "ClayCode_16Total_10Data_13Helper") {
171
- encoding = {
172
- variant: "clay",
173
- ...ERASURE_CODE_PARAMS[metadata.encoding.__variant__],
174
- ...ERASURE_CODE_AND_CHUNK_MAPPING[metadata.encoding.__variant__]
175
- };
176
- } else if (metadata.encoding.__variant__ === "ClayCode_4Total_2Data_3Helper") {
177
- encoding = {
178
- variant: "clay",
179
- ...ERASURE_CODE_PARAMS[metadata.encoding.__variant__],
180
- ...ERASURE_CODE_AND_CHUNK_MAPPING[metadata.encoding.__variant__]
181
- };
182
- } else {
183
- throw new Error(
184
- "Could not parse encoding from Shelby Smart Contract, this SDK is out of date."
185
- );
186
- }
187
- return {
188
- blobMerkleRoot: Hex.fromHexInput(
189
- metadata.blob_commitment
190
- ).toUint8Array(),
191
- owner: normalizeAddress(metadata.owner),
192
- name: params.name,
193
- blobNameSuffix: getBlobNameSuffix(params.name),
194
- size: Number(metadata.blob_size),
195
- encoding,
196
- expirationMicros: Number(metadata.expiration_micros),
197
- creationMicros: Number(metadata.creation_micros),
198
- sliceAddress: normalizeAddress(metadata.slice.inner),
199
- isWritten: metadata.is_written
200
- };
201
- } catch (error) {
202
- if (error instanceof Error && // Depending on the network, the error message may show up differently.
203
- (error.message?.includes("sub_status: Some(404)") || error.message?.includes("EBLOB_NOT_FOUND"))) {
204
- return void 0;
205
- }
206
- throw error;
207
- }
208
- }
209
- /**
210
- * Retrieves all the blobs and their metadata for an account from the
211
- * blockchain.
212
- *
213
- * @param params.account - The account namespace the blobs are stored in (e.g. "0x1")
214
- * @param params.pagination (optional) - The pagination options.
215
- * @param params.orderBy (optional) - The order by clause to sort the blobs by.
216
- * @returns The blob metadata for all the blobs for the account.
217
- *
218
- * @example
219
- * ```typescript
220
- * // BlobMetadata[]
221
- * const blobs = await client.getAccountBlobs({
222
- * account: AccountAddress.fromString("0x1"),
223
- * });
224
- * ```
225
- */
226
- getAccountBlobs(params) {
227
- const { where, ...rest } = params;
228
- return this.getBlobs({
229
- where: {
230
- ...where,
231
- owner: { _eq: normalizeAddress(params.account).toString() }
232
- },
233
- pagination: rest.pagination,
234
- orderBy: rest.orderBy
235
- });
236
- }
237
- /**
238
- * Retrieves blobs and their metadata from the blockchain.
239
- *
240
- * @param params.where (optional) - The where clause to filter the blobs by.
241
- * @param params.pagination (optional) - The pagination options.
242
- * @param params.orderBy (optional) - The order by clause to sort the blobs by.
243
- * @returns The blob metadata for all the blobs that match the where clause.
244
- *
245
- * @example
246
- * ```typescript
247
- * // BlobMetadata[]
248
- * const blobs = await client.getBlobs({
249
- * where: { owner: { _eq: AccountAddress.fromString("0x1").toString() } },
250
- * });
251
- * ```
252
- */
253
- async getBlobs(params = {}) {
254
- const { limit, offset } = params.pagination ?? {};
255
- const { orderBy, where } = params;
256
- const currentMicros = String(Date.now() * 1e3);
257
- const defaultActiveFilter = {
258
- expires_at: { _gte: currentMicros },
259
- is_deleted: { _eq: "0" }
260
- };
261
- const finalWhere = where !== void 0 ? { ...defaultActiveFilter, ...where } : defaultActiveFilter;
262
- const { blobs } = await this.indexer.getBlobs({
263
- where: finalWhere,
264
- limit,
265
- offset,
266
- orderBy
267
- });
268
- return blobs.map(
269
- (blob) => ({
270
- owner: normalizeAddress(blob.owner),
271
- name: blob.blob_name,
272
- blobNameSuffix: getBlobNameSuffix(blob.blob_name),
273
- blobMerkleRoot: Hex.fromHexInput(blob.blob_commitment).toUint8Array(),
274
- size: Number(blob.size),
275
- // TODO: Add encoding when supported in NCI
276
- encoding: {
277
- variant: "clay",
278
- ...ERASURE_CODE_PARAMS.ClayCode_16Total_10Data_13Helper,
279
- ...ERASURE_CODE_AND_CHUNK_MAPPING.ClayCode_16Total_10Data_13Helper
280
- },
281
- expirationMicros: Number(blob.expires_at),
282
- creationMicros: Number(blob.created_at),
283
- sliceAddress: normalizeAddress(blob.slice_address),
284
- isWritten: Boolean(Number(blob.is_written)),
285
- isDeleted: Boolean(Number(blob.is_deleted))
286
- })
287
- );
288
- }
289
- async getBlobActivities(params) {
290
- const { limit, offset } = params.pagination ?? {};
291
- const { orderBy, where } = params;
292
- const { blob_activities } = await this.indexer.getBlobActivities({
293
- where,
294
- limit,
295
- offset,
296
- orderBy
297
- });
298
- const activityTypeMapping = {
299
- [`${this.deployer.toStringLong()}::blob_metadata::BlobRegisteredEvent`]: "register_blob",
300
- [`${this.deployer.toStringLong()}::blob_metadata::BlobDeletedEvent`]: "delete_blob",
301
- [`${this.deployer.toStringLong()}::blob_metadata::BlobExpirationExtendedEvent`]: "extend_blob_expiration",
302
- [`${this.deployer.toStringLong()}::blob_metadata::BlobWrittenEvent`]: "write_blob"
303
- };
304
- return blob_activities.map(
305
- (activity) => ({
306
- blobName: activity.blob_name,
307
- accountAddress: normalizeAddress(activity.blob_name.substring(1, 65)),
308
- type: activityTypeMapping[activity.event_type] ?? "unknown",
309
- eventType: activity.event_type,
310
- eventIndex: Number(activity.event_index),
311
- transactionHash: activity.transaction_hash,
312
- // Using Number here in JS is technically not okay because txn version can be
313
- // as large as u64::MAX, but it should be fine for a long while.
314
- transactionVersion: Number(activity.transaction_version),
315
- timestamp: `${activity.timestamp}Z`
316
- })
317
- );
318
- }
319
- /**
320
- * Retrieves the total number of blobs from the blockchain.
321
- *
322
- * @param params.where (optional) - The where clause to filter the blobs by.
323
- * @returns The total number of blobs.
324
- *
325
- * @example
326
- * ```typescript
327
- * const count = await client.getBlobsCount();
328
- * ```
329
- */
330
- async getBlobsCount(params) {
331
- const { where } = params;
332
- const { blobs_aggregate } = await this.indexer.getBlobsCount({ where });
333
- return blobs_aggregate?.aggregate?.count ?? 0;
334
- }
335
- /**
336
- * Retrieves the total size of blobs from the blockchain.
337
- *
338
- * @param params.where (optional) - The where clause to filter the blobs by.
339
- * @returns The total size of blobs in bytes.
340
- *
341
- * @example
342
- * ```typescript
343
- * const size = await client.getTotalBlobsSize();
344
- * ```
345
- */
346
- async getTotalBlobsSize(params = {}) {
347
- const { where } = params;
348
- const { blobs_aggregate } = await this.indexer.getTotalBlobsSize({ where });
349
- return Number(blobs_aggregate?.aggregate?.sum?.size ?? 0);
350
- }
351
- /**
352
- * Retrieves the total number of blob activities from the blockchain.
353
- *
354
- * @param params.where (optional) - The where clause to filter the blob activities by.
355
- * @returns The total number of blob activities.
356
- *
357
- * @example
358
- * ```typescript
359
- * const count = await client.getBlobActivitiesCount();
360
- * ```
361
- */
362
- async getBlobActivitiesCount(params) {
363
- const { where } = params;
364
- const { blob_activities_aggregate } = await this.indexer.getBlobActivitiesCount({ where });
365
- return blob_activities_aggregate?.aggregate?.count ?? 0;
366
- }
367
- /**
368
- * Registers a blob on the blockchain by writing its merkle root and metadata.
369
- *
370
- * @param params.account - The account that is signing and paying for the transaction.
371
- * @param params.blobName - The name/path of the blob (e.g. "foo/bar.txt").
372
- * @param params.blobMerkleRoot - The merkle root of the blob commitments.
373
- * @param params.size - The size of the blob in bytes.
374
- * @param params.expirationMicros - The expiration time of the blob in microseconds.
375
- * @param params.options - Optional transaction building options.
376
- * @param params.options.chunksetSizeBytes - Custom chunkset size (defaults to DEFAULT_CHUNKSET_SIZE_BYTES).
377
- * @param params.options.build - Additional Aptos transaction building options.
378
- *
379
- * @returns An object containing the pending transaction.
380
- *
381
- * @example
382
- * ```typescript
383
- * const provider = await ClayErasureCodingProvider.create();
384
- * const blobCommitments = await generateCommitments(provider, data);
385
- *
386
- * const { transaction } = await client.registerBlob({
387
- * account: signer,
388
- * blobName: "foo/bar.txt",
389
- * blobMerkleRoot: blobCommitments.blob_merkle_root,
390
- * size: data.length,
391
- * expirationMicros: Date.now() * 1000 + 3600_000_000, // 1 hour from now in microseconds
392
- * });
393
- * ```
394
- */
395
- async registerBlob(params) {
396
- const options = this.mergeOptions(params.options);
397
- this.validateUsdSponsorConfig(options.usdSponsor, options.submit);
398
- const config = params.config ?? defaultErasureCodingConfig();
399
- const chunksetSize = config.chunkSizeBytes * config.erasure_k;
400
- const buildArgs = {
401
- ...options.build,
402
- options: this.orderlessTxOptions(options.build?.options),
403
- data: _ShelbyBlobClient.createRegisterBlobPayload({
404
- deployer: this.deployer,
405
- account: params.account.accountAddress,
406
- blobName: params.blobName,
407
- blobSize: params.size,
408
- blobMerkleRoot: params.blobMerkleRoot,
409
- numChunksets: expectedTotalChunksets(params.size, chunksetSize),
410
- expirationMicros: params.expirationMicros,
411
- useSponsoredUsdVariant: options.usdSponsor !== void 0,
412
- encoding: config.enumIndex
413
- }),
414
- sender: params.account.accountAddress
415
- };
416
- const transaction = options.usdSponsor ? await this.aptos.transaction.build.multiAgent({
417
- ...buildArgs,
418
- secondarySignerAddresses: [options.usdSponsor.feePayerAddress]
419
- }) : await this.aptos.transaction.build.simple(buildArgs);
420
- return {
421
- transaction: await this.aptos.signAndSubmitTransaction({
422
- signer: params.account,
423
- transaction,
424
- ...options.submit
425
- })
426
- };
427
- }
428
- /**
429
- * Deletes a blob on the blockchain.
430
- *
431
- * @param params.account - The account that is signing and paying for the transaction.
432
- * @param params.blobName - The name/path of the blob (e.g. "foo/bar.txt").
433
- * @param params.options - Optional transaction building options.
434
- *
435
- * @returns An object containing the pending transaction.
436
- *
437
- * @example
438
- * ```typescript
439
- *
440
- * const { transaction } = await client.deleteBlob({
441
- * account: signer,
442
- * blobName: "foo/bar.txt",
443
- * });
444
- * ```
445
- */
446
- async deleteBlob(params) {
447
- const transaction = await this.aptos.transaction.build.simple({
448
- options: this.orderlessTxOptions(params.options),
449
- data: _ShelbyBlobClient.createDeleteBlobPayload({
450
- deployer: this.deployer,
451
- blobName: params.blobName
452
- }),
453
- sender: params.account.accountAddress
454
- });
455
- return {
456
- transaction: await this.aptos.signAndSubmitTransaction({
457
- signer: params.account,
458
- transaction
459
- })
460
- };
461
- }
462
- /**
463
- * Deletes multiple blobs on the blockchain in a single atomic transaction.
464
- *
465
- * **Note:** This function requires the `delete_multiple_blobs` entry function
466
- * which will be deployed to the smart contract on 2026-02-04. Using this
467
- * function before that date will result in a transaction failure.
468
- *
469
- * This operation is atomic: if any blob deletion fails (e.g., blob not found),
470
- * the entire transaction fails and no blobs are deleted.
471
- *
472
- * @param params.account - The account that is signing and paying for the transaction.
473
- * @param params.blobNames - Array of blob name suffixes without the account address prefix
474
- * (e.g. ["foo/bar.txt", "baz.txt"], NOT ["0x1/foo/bar.txt"]). The account address
475
- * prefix is automatically derived from the signer.
476
- * @param params.options - Optional transaction building options.
477
- *
478
- * @returns An object containing the pending transaction.
479
- *
480
- * @example
481
- * ```typescript
482
- *
483
- * const { transaction } = await client.deleteMultipleBlobs({
484
- * account: signer,
485
- * blobNames: ["foo/bar.txt", "baz.txt"],
486
- * });
487
- * ```
488
- */
489
- async deleteMultipleBlobs(params) {
490
- const transaction = await this.aptos.transaction.build.simple({
491
- options: this.orderlessTxOptions(params.options),
492
- data: _ShelbyBlobClient.createDeleteMultipleBlobsPayload({
493
- deployer: this.deployer,
494
- blobNames: params.blobNames
495
- }),
496
- sender: params.account.accountAddress
497
- });
498
- return {
499
- transaction: await this.aptos.signAndSubmitTransaction({
500
- signer: params.account,
501
- transaction
502
- })
503
- };
504
- }
505
- /**
506
- * Acks the blob chunksets on-chain. If each chunkset meets the necessary threshold, the entire blob will be marked as written.
507
- *
508
- * @param params.account - The account that is signing the transaction.
509
- * @param params.blobOwner - The account that owns the blob.
510
- * @param params.blobName - The name of the blob (e.g. "foo/bar")
511
- * @param params.creationMicros - The creation time of the blob in microseconds.
512
- * @param params.chunksetIdx - The index of the chunkset being acknowledged.
513
- * @param params.storageProviderChunksetAcks - The signatures
514
- * @param params.options - Additional options for transaction building and encoding.
515
- *
516
- * @returns The blob commitments and the pending transaction.
517
- *
518
- * @example
519
- * ```typescript
520
- * const { transaction } = await client.addChunksetAcknowledgements({
521
- * account: signer,
522
- * blobOwner: owner,
523
- * blobName: "foo/bar.txt",
524
- * creationMicros, // Taken from the blob metadata at registration time.
525
- * chunksetIdx,
526
- * storageProviderAcks: An array of StorageProviderAck types, each having the slot index and signature from the SP.
527
- * });
528
- * ```
529
- */
530
- async addChunksetAcknowledgements(params) {
531
- const transaction = await this.aptos.transaction.build.simple({
532
- ...params.options?.build,
533
- options: this.orderlessTxOptions(params.options?.build?.options),
534
- data: _ShelbyBlobClient.createChunksetAcknowledgementsPayload({
535
- blobOwner: params.blobOwner,
536
- blobName: params.blobName,
537
- creationMicros: params.creationMicros,
538
- chunksetIdx: params.chunksetIdx,
539
- storageProviderAcks: params.storageProviderAcks
540
- }),
541
- sender: params.account.accountAddress
542
- });
543
- return {
544
- transaction: await this.aptos.signAndSubmitTransaction({
545
- signer: params.account,
546
- transaction
547
- })
548
- };
549
- }
550
- /**
551
- * Registers multiple blobs on the blockchain by writing their merkle roots and metadata.
552
- *
553
- * @param params.account - The account that is signing and paying for the transaction.
554
- * @param params.expirationMicros - The expiration time of the blobs in microseconds.
555
- * @param params.blobs - The blobs to register.
556
- * @param params.blobs.blobName - The name/path of the blob (e.g. "foo/bar.txt").
557
- * @param params.blobs.blobSize - The size of the blob in bytes.
558
- * @param params.blobs.blobMerkleRoot - The merkle root of the blob commitments as a hex string.
559
- * @param params.options - Optional transaction building options.
560
- * @param params.options.chunksetSizeBytes - Custom chunkset size (defaults to DEFAULT_CHUNKSET_SIZE_BYTES).
561
- * @param params.options.build - Additional Aptos transaction building options.
562
- *
563
- * @returns An object containing the pending transaction.
564
- *
565
- * @example
566
- * ```typescript
567
- * const provider = await ClayErasureCodingProvider.create();
568
- * const blobCommitments = await generateCommitments(provider, data);
569
- *
570
- * const { transaction } = await client.batchRegisterBlobs({
571
- * account: signer,
572
- * expirationMicros: Date.now() * 1000 + 3600_000_000, // 1 hour from now in microseconds
573
- * blobs: [
574
- * {
575
- * blobName: "foo/bar.txt",
576
- * blobSize: data.length,
577
- * blobMerkleRoot: blobCommitments.blob_merkle_root,
578
- * },
579
- * ],
580
- * });
581
- * ```
582
- */
583
- async batchRegisterBlobs(params) {
584
- const options = this.mergeOptions(params.options);
585
- this.validateUsdSponsorConfig(options.usdSponsor, options.submit);
586
- const config = params.config ?? defaultErasureCodingConfig();
587
- const chunksetSize = config.chunkSizeBytes * config.erasure_k;
588
- const buildArgs = {
589
- ...options.build,
590
- options: this.orderlessTxOptions(options.build?.options),
591
- sender: params.account.accountAddress,
592
- data: _ShelbyBlobClient.createBatchRegisterBlobsPayload({
593
- deployer: this.deployer,
594
- account: params.account.accountAddress,
595
- expirationMicros: params.expirationMicros,
596
- blobs: params.blobs.map((blob) => ({
597
- blobName: blob.blobName,
598
- blobSize: blob.blobSize,
599
- blobMerkleRoot: blob.blobMerkleRoot,
600
- numChunksets: expectedTotalChunksets(blob.blobSize, chunksetSize)
601
- })),
602
- useSponsoredUsdVariant: options.usdSponsor !== void 0,
603
- encoding: config.enumIndex
604
- })
605
- };
606
- const transaction = options.usdSponsor ? await this.aptos.transaction.build.multiAgent({
607
- ...buildArgs,
608
- secondarySignerAddresses: [options.usdSponsor.feePayerAddress]
609
- }) : await this.aptos.transaction.build.simple(buildArgs);
610
- return {
611
- transaction: await this.aptos.signAndSubmitTransaction({
612
- signer: params.account,
613
- transaction,
614
- ...options.submit
615
- })
616
- };
617
- }
618
- /**
619
- * Creates a transaction payload to register a blob on the blockchain.
620
- * This is a static helper method for constructing the Move function call payload.
621
- *
622
- * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
623
- * @param params.account - The account that will own the blob.
624
- * @param params.blobName - The name/path of the blob (e.g. "foo/bar.txt").
625
- * @param params.blobSize - The size of the blob in bytes.
626
- * @param params.blobMerkleRoot - The merkle root of the blob commitments as a hex string.
627
- * @param params.expirationMicros - The expiration time of the blob in microseconds.
628
- * @param params.numChunksets - The total number of chunksets in the blob.
629
- *
630
- * @returns An Aptos transaction payload data object for the register_blob Move function.
631
- *
632
- * @see https://github.com/shelby/shelby/blob/e08e84742cf2b80ad8bb7227deb3013398076d53/move/shelby_contract/sources/global_metadata.move#L357
633
- */
634
- static createRegisterBlobPayload(params) {
635
- const functionName = params.useSponsoredUsdVariant ? "register_blob_with_sponsor" : "register_blob";
636
- return {
637
- function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::${functionName}`,
638
- functionArguments: [
639
- params.blobName,
640
- params.expirationMicros,
641
- Hex.fromHexString(params.blobMerkleRoot).toUint8Array(),
642
- params.numChunksets,
643
- params.blobSize,
644
- // TODO
645
- 0,
646
- // payment tier
647
- params.encoding
648
- ]
649
- };
650
- }
651
- /**
652
- * Creates a transaction payload to register multiple blobs on the blockchain.
653
- * This is a static helper method for constructing the Move function call payload.
654
- *
655
- * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
656
- * @param params.account - The account that will own the blobs.
657
- * @param params.expirationMicros - The expiration time of the blobs in microseconds.
658
- * @param params.blobs - The blobs to register.
659
- * @param params.blobs.blobName - The name/path of the blob (e.g. "foo/bar.txt").
660
- * @param params.blobs.blobSize - The size of the blob in bytes.
661
- * @param params.blobs.blobMerkleRoot - The merkle root of the blob commitments as a hex string.
662
- * @param params.blobs.numChunksets - The total number of chunksets in the blob.
663
- *
664
- * @returns An Aptos transaction payload data object for the register_multiple_blobs Move function.
665
- *
666
- * @see https://github.com/shelby/shelby/blob/e08e84742cf2b80ad8bb7227deb3013398076d53/move/shelby_contract/sources/global_metadata.move#L357
667
- */
668
- static createBatchRegisterBlobsPayload(params) {
669
- const functionName = params.useSponsoredUsdVariant ? "register_multiple_blobs_with_sponsor" : "register_multiple_blobs";
670
- const blobNames = [];
671
- const blobMerkleRoots = [];
672
- const blobNumChunksets = [];
673
- const blobSizes = [];
674
- params.blobs.forEach((blob) => {
675
- blobNames.push(blob.blobName);
676
- blobMerkleRoots.push(
677
- Hex.fromHexString(blob.blobMerkleRoot).toUint8Array()
678
- );
679
- blobNumChunksets.push(blob.numChunksets);
680
- blobSizes.push(blob.blobSize);
681
- });
682
- return {
683
- function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::${functionName}`,
684
- functionArguments: [
685
- blobNames,
686
- params.expirationMicros,
687
- blobMerkleRoots,
688
- blobNumChunksets,
689
- blobSizes,
690
- // TODO
691
- 0,
692
- // payment tier
693
- params.encoding
694
- ]
695
- };
696
- }
697
- /**
698
- * Creates a transaction payload to delete a blob on the blockchain.
699
- * This is a static helper method for constructing the Move function call payload.
700
- *
701
- * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
702
- * @param params.blobName - The blob name (e.g. "bar.txt", without the account address prefix).
703
- *
704
- * @returns An Aptos transaction payload data object for the delete_blob Move function.
705
- *
706
- * @see https://github.com/shelby/shelby/blob/64e9d7b4f0005e586faeb1e4085c79159234b6b6/move/shelby_contract/sources/global_metadata.move#L616
707
- */
708
- static createDeleteBlobPayload(params) {
709
- return {
710
- function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::delete_blob`,
711
- functionArguments: [params.blobName]
712
- };
713
- }
714
- /**
715
- * Creates a transaction payload to delete multiple blobs on the blockchain.
716
- * This is a static helper method for constructing the Move function call payload.
717
- *
718
- * **Note:** This function requires the `delete_multiple_blobs` entry function
719
- * which will be deployed to the smart contract on 2026-02-04. Using this
720
- * function before that date will result in a transaction failure.
721
- *
722
- * This operation is atomic: if any blob deletion fails (e.g., blob not found),
723
- * the entire transaction fails and no blobs are deleted.
724
- *
725
- * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
726
- * @param params.blobNames - Array of blob name suffixes without the account address prefix
727
- * (e.g. ["foo/bar.txt", "baz.txt"], NOT ["0x1/foo/bar.txt"]). The account address
728
- * prefix is automatically derived from the transaction sender.
729
- *
730
- * @returns An Aptos transaction payload data object for the delete_multiple_blobs Move function.
731
- *
732
- * @see https://github.com/shelby/shelby/blob/main/move/shelby_contract/sources/blob_metadata.move
733
- */
734
- static createDeleteMultipleBlobsPayload(params) {
735
- return {
736
- function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::delete_multiple_blobs`,
737
- functionArguments: [params.blobNames]
738
- };
739
- }
740
- static createChunksetAcknowledgementsPayload(params) {
741
- const ackBitMask = params.storageProviderAcks.reduce(
742
- (acc, ack) => acc | 1 << ack.slot,
743
- 0
744
- );
745
- return {
746
- function: `${SHELBY_DEPLOYER}::blob_metadata::add_chunkset_acknowledgements`,
747
- functionArguments: [
748
- createBlobKey({
749
- account: params.blobOwner,
750
- blobName: params.blobName
751
- }),
752
- params.chunksetIdx,
753
- params.creationMicros,
754
- new U32(Number(ackBitMask)),
755
- params.storageProviderAcks.map((ack) => ack.signature)
756
- ]
757
- };
758
- }
759
- static createBlobAcknowledgementsPayload(params) {
760
- const ackBitMask = params.storageProviderAcks.reduce(
761
- (acc, ack) => acc | 1 << ack.slot,
762
- 0
763
- );
764
- return {
765
- function: `${SHELBY_DEPLOYER}::blob_metadata::add_blob_acknowledgements`,
766
- functionArguments: [
767
- createBlobKey({
768
- account: params.blobOwner,
769
- blobName: params.blobName
770
- }),
771
- params.creationMicros,
772
- new U32(Number(ackBitMask)),
773
- params.storageProviderAcks.map((ack) => ack.signature)
774
- ]
775
- };
776
- }
777
- async addBlobAcknowledgements(params) {
778
- const transaction = await this.aptos.transaction.build.simple({
779
- ...params.options?.build,
780
- options: this.orderlessTxOptions(params.options?.build?.options),
781
- data: _ShelbyBlobClient.createBlobAcknowledgementsPayload({
782
- blobOwner: params.blobOwner,
783
- blobName: params.blobName,
784
- creationMicros: params.creationMicros,
785
- storageProviderAcks: params.storageProviderAcks
786
- }),
787
- sender: params.account.accountAddress
788
- });
789
- return {
790
- transaction: await this.aptos.signAndSubmitTransaction({
791
- signer: params.account,
792
- transaction
793
- })
794
- };
795
- }
796
- };
797
-
798
- export {
799
- MissingTransactionSubmitterError,
800
- ShelbyBlobClient
801
- };