@shelby-protocol/sdk 0.0.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/browser/index.d.ts +17 -10
  2. package/dist/browser/index.mjs +89 -28
  3. package/dist/{chunk-XWAPNLU6.mjs → chunk-2WEX3K7C.mjs} +6 -4
  4. package/dist/chunk-4MG4XGY4.mjs +91 -0
  5. package/dist/{chunk-SEXQTDX6.mjs → chunk-4ZOFT75Q.mjs} +16 -2
  6. package/dist/{chunk-BTHSKDJR.mjs → chunk-7PN65RDX.mjs} +44 -10
  7. package/dist/chunk-AABBONAF.mjs +34 -0
  8. package/dist/{chunk-ZPW742E7.mjs → chunk-AUQDI5BS.mjs} +17 -2
  9. package/dist/{chunk-HFGEQP5N.mjs → chunk-CGYJLKBU.mjs} +4 -4
  10. package/dist/chunk-CQ6QPIZK.mjs +37 -0
  11. package/dist/{chunk-VRLIOKWG.mjs → chunk-D6GQHO6G.mjs} +5 -1
  12. package/dist/chunk-E5QCRTBU.mjs +493 -0
  13. package/dist/chunk-HPPMI7DC.mjs +56 -0
  14. package/dist/chunk-IE6LYVIA.mjs +26 -0
  15. package/dist/{chunk-67F5YZ25.mjs → chunk-JTXYKO3U.mjs} +10 -0
  16. package/dist/{chunk-WJKSPJSS.mjs → chunk-KJ24NKPH.mjs} +46 -0
  17. package/dist/{chunk-WBFEX7OM.mjs → chunk-MV6FNYAU.mjs} +31 -7
  18. package/dist/{chunk-PZF2VTGP.mjs → chunk-NHWWORCH.mjs} +3 -1
  19. package/dist/{chunk-NLPIHQ7K.mjs → chunk-OGKZ575S.mjs} +6 -19
  20. package/dist/{chunk-5I3MBJGN.mjs → chunk-PJVWGMVI.mjs} +164 -35
  21. package/dist/{chunk-7UVMDCCR.mjs → chunk-SRV4YWFH.mjs} +232 -47
  22. package/dist/chunk-W37FZSMA.mjs +83 -0
  23. package/dist/chunk-WTICJPDB.mjs +0 -0
  24. package/dist/chunk-Z4FZ7W6L.mjs +39 -0
  25. package/dist/{chunk-QFWQ7FIC.mjs → chunk-ZEDD2MPU.mjs} +1 -1
  26. package/dist/{clay-codes-pdZFxI_B.d.ts → clay-codes-DHP-bYcP.d.ts} +6 -2
  27. package/dist/core/blobs.d.ts +2 -0
  28. package/dist/core/chunk.d.ts +10 -1
  29. package/dist/core/chunk.mjs +2 -2
  30. package/dist/core/clients/ShelbyBlobClient.d.ts +165 -12
  31. package/dist/core/clients/ShelbyBlobClient.mjs +13 -11
  32. package/dist/core/clients/ShelbyClient.d.ts +21 -4
  33. package/dist/core/clients/ShelbyClient.mjs +17 -14
  34. package/dist/core/clients/ShelbyClientConfig.d.ts +7 -2
  35. package/dist/{node → core}/clients/ShelbyMetadataClient.d.ts +3 -3
  36. package/dist/core/clients/ShelbyMetadataClient.mjs +9 -0
  37. package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +349 -0
  38. package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +16 -0
  39. package/dist/core/clients/ShelbyPlacementGroupClient.d.ts +73 -0
  40. package/dist/core/clients/ShelbyPlacementGroupClient.mjs +11 -0
  41. package/dist/core/clients/ShelbyRPCClient.d.ts +30 -4
  42. package/dist/core/clients/ShelbyRPCClient.mjs +8 -8
  43. package/dist/core/clients/index.d.ts +11 -5
  44. package/dist/core/clients/index.mjs +35 -15
  45. package/dist/core/clients/utils.d.ts +54 -0
  46. package/dist/core/clients/utils.mjs +1 -1
  47. package/dist/core/commitments.d.ts +6 -2
  48. package/dist/core/commitments.mjs +5 -3
  49. package/dist/core/constants.d.ts +18 -3
  50. package/dist/core/constants.mjs +5 -1
  51. package/dist/core/erasure/clay-codes.d.ts +1 -1
  52. package/dist/core/erasure/clay-codes.mjs +5 -5
  53. package/dist/core/erasure/constants.d.ts +15 -3
  54. package/dist/core/erasure/constants.mjs +3 -1
  55. package/dist/core/erasure/default.d.ts +5 -2
  56. package/dist/core/erasure/default.mjs +12 -6
  57. package/dist/core/erasure/index.d.ts +3 -3
  58. package/dist/core/erasure/index.mjs +15 -7
  59. package/dist/core/erasure/provider.d.ts +1 -1
  60. package/dist/core/erasure/reed-solomon.d.ts +1 -1
  61. package/dist/core/erasure/reed-solomon.mjs +1 -1
  62. package/dist/core/erasure/utils.d.ts +1 -1
  63. package/dist/core/errors.d.ts +58 -0
  64. package/dist/core/errors.mjs +15 -0
  65. package/dist/core/index.d.ts +17 -10
  66. package/dist/core/index.mjs +89 -28
  67. package/dist/core/layout.d.ts +5 -16
  68. package/dist/core/layout.mjs +3 -9
  69. package/dist/core/networks.d.ts +1 -1
  70. package/dist/core/networks.mjs +1 -1
  71. package/dist/core/operations/generated/sdk.d.ts +207 -17
  72. package/dist/core/operations/generated/sdk.mjs +7 -1
  73. package/dist/core/operations/index.d.ts +9 -3
  74. package/dist/core/operations/index.mjs +10 -4
  75. package/dist/core/rpc-responses.d.ts +69 -0
  76. package/dist/core/rpc-responses.mjs +15 -0
  77. package/dist/core/types/blobs.d.ts +8 -4
  78. package/dist/core/types/encodings.d.ts +1 -1
  79. package/dist/core/types/index.d.ts +4 -2
  80. package/dist/core/types/index.mjs +12 -2
  81. package/dist/core/types/payments.d.ts +94 -0
  82. package/dist/core/types/payments.mjs +9 -0
  83. package/dist/core/types/placement_groups.d.ts +30 -1
  84. package/dist/core/types/placement_groups.mjs +1 -0
  85. package/dist/core/types/storage_providers.d.ts +32 -2
  86. package/dist/node/clients/ShelbyNodeClient.d.ts +9 -6
  87. package/dist/node/clients/ShelbyNodeClient.mjs +18 -15
  88. package/dist/node/clients/index.d.ts +7 -6
  89. package/dist/node/clients/index.mjs +19 -17
  90. package/dist/node/index.d.ts +17 -11
  91. package/dist/node/index.mjs +91 -34
  92. package/package.json +3 -2
  93. package/dist/chunk-CPNZAQVY.mjs +0 -29
  94. package/dist/chunk-GY5DCVVL.mjs +0 -86
  95. package/dist/chunk-RBFWGDMY.mjs +0 -30
  96. package/dist/node/clients/ShelbyMetadataClient.mjs +0 -9
  97. /package/dist/{chunk-DJJD2AXO.mjs → chunk-AD2G3QYD.mjs} +0 -0
  98. /package/dist/{chunk-MWDW4ROU.mjs → chunk-EM67QTMR.mjs} +0 -0
  99. /package/dist/{chunk-RNXGC54D.mjs → chunk-QQ57OGQ2.mjs} +0 -0
@@ -1,48 +1,58 @@
1
+ import {
2
+ defaultErasureCodingConfig
3
+ } from "./chunk-HPPMI7DC.mjs";
1
4
  import {
2
5
  getShelbyIndexerClient
3
- } from "./chunk-HFGEQP5N.mjs";
6
+ } from "./chunk-CGYJLKBU.mjs";
4
7
  import {
5
8
  getAptosConfig
6
- } from "./chunk-RBFWGDMY.mjs";
9
+ } from "./chunk-AABBONAF.mjs";
7
10
  import {
8
11
  createBlobKey
9
12
  } from "./chunk-OTBLZL2S.mjs";
10
13
  import {
11
14
  expectedTotalChunksets
12
- } from "./chunk-XWAPNLU6.mjs";
15
+ } from "./chunk-2WEX3K7C.mjs";
13
16
  import {
14
17
  getBlobNameSuffix
15
18
  } from "./chunk-4JZO2D7T.mjs";
16
19
  import {
17
- DEFAULT_CHUNKSET_SIZE_BYTES,
18
20
  ERASURE_CODE_AND_CHUNK_MAPPING
19
- } from "./chunk-67F5YZ25.mjs";
21
+ } from "./chunk-JTXYKO3U.mjs";
20
22
  import {
21
23
  ERASURE_CODE_PARAMS
22
- } from "./chunk-ZPW742E7.mjs";
24
+ } from "./chunk-AUQDI5BS.mjs";
23
25
  import {
24
26
  SHELBY_DEPLOYER
25
- } from "./chunk-SEXQTDX6.mjs";
27
+ } from "./chunk-4ZOFT75Q.mjs";
26
28
 
27
29
  // src/core/clients/ShelbyBlobClient.ts
28
30
  import {
29
31
  AccountAddress,
30
32
  Aptos,
31
- AptosConfig,
32
33
  Hex,
33
- MoveVector,
34
34
  U32
35
35
  } from "@aptos-labs/ts-sdk";
36
+ var MissingTransactionSubmitterError = class extends Error {
37
+ constructor() {
38
+ super(
39
+ "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."
40
+ );
41
+ this.name = "MissingTransactionSubmitterError";
42
+ }
43
+ };
36
44
  var ShelbyBlobClient = class _ShelbyBlobClient {
37
45
  aptos;
38
46
  deployer;
39
47
  indexer;
48
+ defaultOptions;
40
49
  /**
41
50
  * The ShelbyBlobClient is used to interact with the Shelby contract on the Aptos blockchain. This
42
51
  * includes functions for registering blob commitments and retrieving blob metadata.
43
52
  *
44
53
  * @param config - The client configuration object.
45
54
  * @param config.network - The Shelby network to use.
55
+ * @param defaultOptions - Optional default options for blob operations.
46
56
  *
47
57
  * @example
48
58
  * ```typescript
@@ -55,20 +65,57 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
55
65
  * },
56
66
  * });
57
67
  * ```
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * // With default options for USD sponsorship
72
+ * const blobClient = new ShelbyBlobClient(
73
+ * {
74
+ * network: Network.SHELBYNET,
75
+ * aptos: {
76
+ * pluginSettings: {
77
+ * TRANSACTION_SUBMITTER: myGasStationSubmitter,
78
+ * },
79
+ * },
80
+ * },
81
+ * {
82
+ * usdSponsor: { feePayerAddress: sponsorAddress },
83
+ * }
84
+ * );
85
+ * ```
58
86
  */
59
- constructor(config) {
60
- const baseAptosConfig = getAptosConfig(config);
61
- const aptosConfig = new AptosConfig({
62
- ...baseAptosConfig,
63
- clientConfig: {
64
- ...baseAptosConfig.clientConfig,
65
- // Only use top-level apiKey if no API_KEY is already provided in Aptos settings
66
- API_KEY: baseAptosConfig.clientConfig?.API_KEY ?? config.apiKey
67
- }
68
- });
69
- this.aptos = new Aptos(aptosConfig);
87
+ constructor(config, defaultOptions) {
88
+ this.aptos = new Aptos(getAptosConfig(config));
70
89
  this.deployer = config.deployer ?? AccountAddress.fromString(SHELBY_DEPLOYER);
71
90
  this.indexer = getShelbyIndexerClient(config);
91
+ this.defaultOptions = defaultOptions ?? {};
92
+ }
93
+ /**
94
+ * Merges method-level options with default options, giving precedence to method-level values.
95
+ */
96
+ mergeOptions(options) {
97
+ return {
98
+ build: options?.build ?? this.defaultOptions.build,
99
+ submit: options?.submit ?? this.defaultOptions.submit,
100
+ usdSponsor: options?.usdSponsor ?? this.defaultOptions.usdSponsor,
101
+ chunksetSizeBytes: options?.chunksetSizeBytes ?? this.defaultOptions.chunksetSizeBytes
102
+ };
103
+ }
104
+ /**
105
+ * Validates that if USD sponsorship is requested, a transaction submitter is
106
+ * configured as well. Checks both the client-level and method-level transaction
107
+ * submitter configurations. Throws MissingTransactionSubmitterError if usdSponsor is
108
+ * provided without a transaction submitter.
109
+ */
110
+ validateUsdSponsorConfig(usdSponsor, submit) {
111
+ if (!usdSponsor) {
112
+ return;
113
+ }
114
+ const hasClientSubmitter = this.aptos.config.getTransactionSubmitter();
115
+ const hasMethodSubmitter = submit?.transactionSubmitter !== void 0 && submit?.transactionSubmitter !== null;
116
+ if (!hasClientSubmitter && !hasMethodSubmitter) {
117
+ throw new MissingTransactionSubmitterError();
118
+ }
72
119
  }
73
120
  /**
74
121
  * Retrieves the blob metadata from the blockchain. If it does not exist,
@@ -105,6 +152,14 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
105
152
  const metadata = rawMetadata[0].vec[0];
106
153
  let encoding;
107
154
  if (metadata.encoding.__variant__ === "ClayCode_16Total_10Data_13Helper") {
155
+ console.log("read blob metadata with ClayCode_16Total_10Data_13Helper");
156
+ encoding = {
157
+ variant: "clay",
158
+ ...ERASURE_CODE_PARAMS[metadata.encoding.__variant__],
159
+ ...ERASURE_CODE_AND_CHUNK_MAPPING[metadata.encoding.__variant__]
160
+ };
161
+ } else if (metadata.encoding.__variant__ === "ClayCode_4Total_2Data_3Helper") {
162
+ console.log("read blob metadata with ClayCode_4Total_2Data_3Helper");
108
163
  encoding = {
109
164
  variant: "clay",
110
165
  ...ERASURE_CODE_PARAMS[metadata.encoding.__variant__],
@@ -158,7 +213,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
158
213
  const { where, ...rest } = params;
159
214
  return this.getBlobs({
160
215
  where: {
161
- ...where ?? {},
216
+ ...where,
162
217
  owner: { _eq: AccountAddress.from(params.account).toString() }
163
218
  },
164
219
  pagination: rest.pagination,
@@ -184,7 +239,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
184
239
  async getBlobs(params = {}) {
185
240
  const { limit, offset } = params.pagination ?? {};
186
241
  const { orderBy, where } = params;
187
- const currentMicros = Date.now() * 1e3;
242
+ const currentMicros = String(Date.now() * 1e3);
188
243
  const defaultActiveFilter = {
189
244
  expires_at: { _gte: currentMicros },
190
245
  is_deleted: { _eq: "0" }
@@ -212,7 +267,8 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
212
267
  expirationMicros: Number(blob.expires_at),
213
268
  creationMicros: Number(blob.created_at),
214
269
  sliceAddress: AccountAddress.from(blob.slice_address),
215
- isWritten: Boolean(Number(blob.is_written))
270
+ isWritten: Boolean(Number(blob.is_written)),
271
+ isDeleted: Boolean(Number(blob.is_deleted))
216
272
  })
217
273
  );
218
274
  }
@@ -239,10 +295,12 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
239
295
  ),
240
296
  type: activityTypeMapping[activity.event_type] ?? "unknown",
241
297
  eventType: activity.event_type,
242
- eventIndex: activity.event_index,
298
+ eventIndex: Number(activity.event_index),
243
299
  transactionHash: activity.transaction_hash,
244
- transactionVersion: activity.transaction_version,
245
- timestamp: activity.timestamp
300
+ // Using Number here in JS is technically not okay because txn version can be
301
+ // as large as u64::MAX, but it should be fine for a long while.
302
+ transactionVersion: Number(activity.transaction_version),
303
+ timestamp: `${activity.timestamp}Z`
246
304
  })
247
305
  );
248
306
  }
@@ -307,9 +365,12 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
307
365
  * ```
308
366
  */
309
367
  async registerBlob(params) {
310
- const chunksetSize = params.options?.chunksetSizeBytes ?? DEFAULT_CHUNKSET_SIZE_BYTES;
311
- const transaction = await this.aptos.transaction.build.simple({
312
- ...params.options?.build,
368
+ const options = this.mergeOptions(params.options);
369
+ this.validateUsdSponsorConfig(options.usdSponsor, options.submit);
370
+ const config = params.config ?? defaultErasureCodingConfig();
371
+ const chunksetSize = config.chunkSizeBytes * config.erasure_k;
372
+ const buildArgs = {
373
+ ...options.build,
313
374
  data: _ShelbyBlobClient.createRegisterBlobPayload({
314
375
  deployer: this.deployer,
315
376
  account: params.account.accountAddress,
@@ -317,7 +378,91 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
317
378
  blobSize: params.size,
318
379
  blobMerkleRoot: params.blobMerkleRoot,
319
380
  numChunksets: expectedTotalChunksets(params.size, chunksetSize),
320
- expirationMicros: params.expirationMicros
381
+ expirationMicros: params.expirationMicros,
382
+ useSponsoredUsdVariant: options.usdSponsor !== void 0,
383
+ encoding: config.enumIndex
384
+ }),
385
+ sender: params.account.accountAddress
386
+ };
387
+ const transaction = options.usdSponsor ? await this.aptos.transaction.build.multiAgent({
388
+ ...buildArgs,
389
+ secondarySignerAddresses: [options.usdSponsor.feePayerAddress]
390
+ }) : await this.aptos.transaction.build.simple(buildArgs);
391
+ return {
392
+ transaction: await this.aptos.signAndSubmitTransaction({
393
+ signer: params.account,
394
+ transaction,
395
+ ...options.submit
396
+ })
397
+ };
398
+ }
399
+ /**
400
+ * Deletes a blob on the blockchain.
401
+ *
402
+ * @param params.account - The account that is signing and paying for the transaction.
403
+ * @param params.blobName - The name/path of the blob (e.g. "foo/bar.txt").
404
+ * @param params.options - Optional transaction building options.
405
+ *
406
+ * @returns An object containing the pending transaction.
407
+ *
408
+ * @example
409
+ * ```typescript
410
+ *
411
+ * const { transaction } = await client.deleteBlob({
412
+ * account: signer,
413
+ * blobName: "foo/bar.txt",
414
+ * });
415
+ * ```
416
+ */
417
+ async deleteBlob(params) {
418
+ const transaction = await this.aptos.transaction.build.simple({
419
+ ...params.options,
420
+ data: _ShelbyBlobClient.createDeleteBlobPayload({
421
+ deployer: this.deployer,
422
+ blobName: params.blobName
423
+ }),
424
+ sender: params.account.accountAddress
425
+ });
426
+ return {
427
+ transaction: await this.aptos.signAndSubmitTransaction({
428
+ signer: params.account,
429
+ transaction
430
+ })
431
+ };
432
+ }
433
+ /**
434
+ * Deletes multiple blobs on the blockchain in a single atomic transaction.
435
+ *
436
+ * **Note:** This function requires the `delete_multiple_blobs` entry function
437
+ * which will be deployed to the smart contract on 2026-02-04. Using this
438
+ * function before that date will result in a transaction failure.
439
+ *
440
+ * This operation is atomic: if any blob deletion fails (e.g., blob not found),
441
+ * the entire transaction fails and no blobs are deleted.
442
+ *
443
+ * @param params.account - The account that is signing and paying for the transaction.
444
+ * @param params.blobNames - Array of blob name suffixes without the account address prefix
445
+ * (e.g. ["foo/bar.txt", "baz.txt"], NOT ["0x1/foo/bar.txt"]). The account address
446
+ * prefix is automatically derived from the signer.
447
+ * @param params.options - Optional transaction building options.
448
+ *
449
+ * @returns An object containing the pending transaction.
450
+ *
451
+ * @example
452
+ * ```typescript
453
+ *
454
+ * const { transaction } = await client.deleteMultipleBlobs({
455
+ * account: signer,
456
+ * blobNames: ["foo/bar.txt", "baz.txt"],
457
+ * });
458
+ * ```
459
+ */
460
+ async deleteMultipleBlobs(params) {
461
+ const transaction = await this.aptos.transaction.build.simple({
462
+ ...params.options,
463
+ data: _ShelbyBlobClient.createDeleteMultipleBlobsPayload({
464
+ deployer: this.deployer,
465
+ blobNames: params.blobNames
321
466
  }),
322
467
  sender: params.account.accountAddress
323
468
  });
@@ -406,9 +551,12 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
406
551
  * ```
407
552
  */
408
553
  async batchRegisterBlobs(params) {
409
- const chunksetSize = params.options?.chunksetSizeBytes ?? DEFAULT_CHUNKSET_SIZE_BYTES;
410
- const transaction = await this.aptos.transaction.build.simple({
411
- ...params.options?.build,
554
+ const options = this.mergeOptions(params.options);
555
+ this.validateUsdSponsorConfig(options.usdSponsor, options.submit);
556
+ const config = params.config ?? defaultErasureCodingConfig();
557
+ const chunksetSize = config.chunkSizeBytes * config.erasure_k;
558
+ const buildArgs = {
559
+ ...options.build,
412
560
  sender: params.account.accountAddress,
413
561
  data: _ShelbyBlobClient.createBatchRegisterBlobsPayload({
414
562
  deployer: this.deployer,
@@ -419,13 +567,20 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
419
567
  blobSize: blob.blobSize,
420
568
  blobMerkleRoot: blob.blobMerkleRoot,
421
569
  numChunksets: expectedTotalChunksets(blob.blobSize, chunksetSize)
422
- }))
570
+ })),
571
+ useSponsoredUsdVariant: options.usdSponsor !== void 0,
572
+ encoding: config.enumIndex
423
573
  })
424
- });
574
+ };
575
+ const transaction = options.usdSponsor ? await this.aptos.transaction.build.multiAgent({
576
+ ...buildArgs,
577
+ secondarySignerAddresses: [options.usdSponsor.feePayerAddress]
578
+ }) : await this.aptos.transaction.build.simple(buildArgs);
425
579
  return {
426
580
  transaction: await this.aptos.signAndSubmitTransaction({
427
581
  signer: params.account,
428
- transaction
582
+ transaction,
583
+ ...options.submit
429
584
  })
430
585
  };
431
586
  }
@@ -446,19 +601,19 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
446
601
  * @see https://github.com/shelby/shelby/blob/e08e84742cf2b80ad8bb7227deb3013398076d53/move/shelby_contract/sources/global_metadata.move#L357
447
602
  */
448
603
  static createRegisterBlobPayload(params) {
604
+ const functionName = params.useSponsoredUsdVariant ? "register_blob_with_sponsor" : "register_blob";
449
605
  return {
450
- function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::register_blob`,
606
+ function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::${functionName}`,
451
607
  functionArguments: [
452
608
  params.blobName,
453
609
  params.expirationMicros,
454
- MoveVector.U8(params.blobMerkleRoot),
610
+ Hex.fromHexString(params.blobMerkleRoot).toUint8Array(),
455
611
  params.numChunksets,
456
612
  params.blobSize,
457
613
  // TODO
458
614
  0,
459
615
  // payment tier
460
- 0
461
- // encoding
616
+ params.encoding
462
617
  ]
463
618
  };
464
619
  }
@@ -480,18 +635,21 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
480
635
  * @see https://github.com/shelby/shelby/blob/e08e84742cf2b80ad8bb7227deb3013398076d53/move/shelby_contract/sources/global_metadata.move#L357
481
636
  */
482
637
  static createBatchRegisterBlobsPayload(params) {
638
+ const functionName = params.useSponsoredUsdVariant ? "register_multiple_blobs_with_sponsor" : "register_multiple_blobs";
483
639
  const blobNames = [];
484
640
  const blobMerkleRoots = [];
485
641
  const blobNumChunksets = [];
486
642
  const blobSizes = [];
487
643
  params.blobs.forEach((blob) => {
488
644
  blobNames.push(blob.blobName);
489
- blobMerkleRoots.push(MoveVector.U8(blob.blobMerkleRoot));
645
+ blobMerkleRoots.push(
646
+ Hex.fromHexString(blob.blobMerkleRoot).toUint8Array()
647
+ );
490
648
  blobNumChunksets.push(blob.numChunksets);
491
649
  blobSizes.push(blob.blobSize);
492
650
  });
493
651
  return {
494
- function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::register_multiple_blobs`,
652
+ function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::${functionName}`,
495
653
  functionArguments: [
496
654
  blobNames,
497
655
  params.expirationMicros,
@@ -500,7 +658,8 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
500
658
  blobSizes,
501
659
  // TODO
502
660
  0,
503
- 0
661
+ // payment tier
662
+ params.encoding
504
663
  ]
505
664
  };
506
665
  }
@@ -509,7 +668,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
509
668
  * This is a static helper method for constructing the Move function call payload.
510
669
  *
511
670
  * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
512
- * @param params.blobNameSuffix - The blob name suffix (e.g. "bar.txt").
671
+ * @param params.blobName - The blob name (e.g. "bar.txt", without the account address prefix).
513
672
  *
514
673
  * @returns An Aptos transaction payload data object for the delete_blob Move function.
515
674
  *
@@ -518,7 +677,33 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
518
677
  static createDeleteBlobPayload(params) {
519
678
  return {
520
679
  function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::delete_blob`,
521
- functionArguments: [params.blobNameSuffix]
680
+ functionArguments: [params.blobName]
681
+ };
682
+ }
683
+ /**
684
+ * Creates a transaction payload to delete multiple blobs on the blockchain.
685
+ * This is a static helper method for constructing the Move function call payload.
686
+ *
687
+ * **Note:** This function requires the `delete_multiple_blobs` entry function
688
+ * which will be deployed to the smart contract on 2026-02-04. Using this
689
+ * function before that date will result in a transaction failure.
690
+ *
691
+ * This operation is atomic: if any blob deletion fails (e.g., blob not found),
692
+ * the entire transaction fails and no blobs are deleted.
693
+ *
694
+ * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
695
+ * @param params.blobNames - Array of blob name suffixes without the account address prefix
696
+ * (e.g. ["foo/bar.txt", "baz.txt"], NOT ["0x1/foo/bar.txt"]). The account address
697
+ * prefix is automatically derived from the transaction sender.
698
+ *
699
+ * @returns An Aptos transaction payload data object for the delete_multiple_blobs Move function.
700
+ *
701
+ * @see https://github.com/shelby/shelby/blob/main/move/shelby_contract/sources/blob_metadata.move
702
+ */
703
+ static createDeleteMultipleBlobsPayload(params) {
704
+ return {
705
+ function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::delete_multiple_blobs`,
706
+ functionArguments: [params.blobNames]
522
707
  };
523
708
  }
524
709
  static createChunksetAcknowledgementsPayload(params) {
@@ -526,7 +711,6 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
526
711
  (acc, ack) => acc | 1 << ack.slot,
527
712
  0
528
713
  );
529
- const signatures = new MoveVector(params.storageProviderAcks.map((ack) => MoveVector.U8(ack.signature)));
530
714
  return {
531
715
  function: `${SHELBY_DEPLOYER}::blob_metadata::add_chunkset_acknowledgements`,
532
716
  functionArguments: [
@@ -537,12 +721,13 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
537
721
  params.chunksetIdx,
538
722
  params.creationMicros,
539
723
  new U32(Number(ackBitMask)),
540
- signatures
724
+ params.storageProviderAcks.map((ack) => ack.signature)
541
725
  ]
542
726
  };
543
727
  }
544
728
  };
545
729
 
546
730
  export {
731
+ MissingTransactionSubmitterError,
547
732
  ShelbyBlobClient
548
733
  };
@@ -0,0 +1,83 @@
1
+ import {
2
+ getShelbyIndexerClient
3
+ } from "./chunk-CGYJLKBU.mjs";
4
+
5
+ // src/core/clients/ShelbyPlacementGroupClient.ts
6
+ var ShelbyPlacementGroupClient = class {
7
+ indexer;
8
+ /**
9
+ * Creates a new ShelbyPlacementGroupClient.
10
+ *
11
+ * @param config - The client configuration object.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const pgClient = new ShelbyPlacementGroupClient({
16
+ * network: Network.SHELBYNET,
17
+ * });
18
+ * ```
19
+ */
20
+ constructor(config) {
21
+ this.indexer = getShelbyIndexerClient(config);
22
+ }
23
+ /**
24
+ * Retrieves placement group slots from the indexer.
25
+ *
26
+ * @param params.where (optional) - The where clause to filter slots by.
27
+ * @param params.pagination (optional) - The pagination options.
28
+ * @param params.orderBy (optional) - The order by clause to sort slots by.
29
+ * @returns The placement group slots that match the filter.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * // Get all active slots
34
+ * const slots = await client.getPlacementGroupSlots({
35
+ * where: { status: { _eq: "active" } },
36
+ * });
37
+ * ```
38
+ */
39
+ async getPlacementGroupSlots(params) {
40
+ const { limit, offset } = params.pagination ?? {};
41
+ const { orderBy, where } = params;
42
+ const { placement_group_slots } = await this.indexer.getPlacementGroupSlots(
43
+ {
44
+ where,
45
+ limit,
46
+ offset,
47
+ orderBy
48
+ }
49
+ );
50
+ return placement_group_slots.map(
51
+ (slot) => ({
52
+ placementGroup: slot.placement_group,
53
+ slotIndex: Number(slot.slot_index),
54
+ storageProvider: slot.storage_provider,
55
+ status: slot.status,
56
+ updatedAt: Number(slot.updated_at)
57
+ })
58
+ );
59
+ }
60
+ /**
61
+ * Retrieves the total count of placement group slots from the indexer.
62
+ *
63
+ * @param params.where (optional) - The where clause to filter slots by.
64
+ * @returns The count of placement group slots that match the filter.
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * // Get count of active slots
69
+ * const count = await client.getPlacementGroupSlotsCount({
70
+ * where: { status: { _eq: "active" } },
71
+ * });
72
+ * ```
73
+ */
74
+ async getPlacementGroupSlotsCount(params) {
75
+ const { where } = params;
76
+ const { placement_group_slots_aggregate } = await this.indexer.getPlacementGroupSlotsCount({ where });
77
+ return placement_group_slots_aggregate?.aggregate?.count ?? 0;
78
+ }
79
+ };
80
+
81
+ export {
82
+ ShelbyPlacementGroupClient
83
+ };
File without changes
@@ -0,0 +1,39 @@
1
+ // src/core/layout.ts
2
+ import { z } from "zod";
3
+ var BlobNameSchema = z.string().min(1, "Blob name path parameter cannot be empty.").max(1024, "Blob name cannot exceed 1024 characters.").refine((name) => !name.endsWith("/"), {
4
+ message: "Blob name cannot end with a slash"
5
+ });
6
+ var ChunkKey = class {
7
+ constructor(account, blobName, chunksetIdx, chunkIdx, config) {
8
+ this.account = account;
9
+ this.blobName = blobName;
10
+ this.chunksetIdx = chunksetIdx;
11
+ this.chunkIdx = chunkIdx;
12
+ this.config = config;
13
+ if (chunkIdx >= config.erasure_n) {
14
+ throw new Error(
15
+ `Cannot create a chunk with idx ${chunkIdx}. M+K=${config.erasure_n}`
16
+ );
17
+ }
18
+ }
19
+ key() {
20
+ return `${this.account.toString()}.${this.blobName}.${this.chunksetIdx}.${this.chunkIdx}`;
21
+ }
22
+ // Returns the range in the blob that this key represents, or "parity" if this is parity chunk.
23
+ range() {
24
+ if (this.chunkIdx >= this.config.erasure_k) {
25
+ return "parity";
26
+ }
27
+ const chunksetStart = this.chunksetIdx * this.config.chunkSizeBytes * this.config.erasure_k;
28
+ const chunkStart = chunksetStart + this.chunkIdx * this.config.chunkSizeBytes;
29
+ return {
30
+ start: chunkStart,
31
+ end: chunkStart + this.config.chunkSizeBytes
32
+ };
33
+ }
34
+ };
35
+
36
+ export {
37
+ BlobNameSchema,
38
+ ChunkKey
39
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ShelbyClient
3
- } from "./chunk-BTHSKDJR.mjs";
3
+ } from "./chunk-7PN65RDX.mjs";
4
4
 
5
5
  // src/node/clients/ShelbyNodeClient.ts
6
6
  var ShelbyNodeClient = class extends ShelbyClient {
@@ -31,6 +31,8 @@ interface ErasureCodingConfig {
31
31
  erasure_k: number;
32
32
  /** Size in bytes of every chunk. */
33
33
  chunkSizeBytes: number;
34
+ /** Index for the erasure code enum in the smart contract. */
35
+ enumIndex: number;
34
36
  }
35
37
  /**
36
38
  * Union of all supported erasure coding configurations.
@@ -117,7 +119,7 @@ declare class ClayErasureCodingProvider implements ErasureCodingProvider {
117
119
  /**
118
120
  * Static factory method to create an initialized ClayErasureCodingProvider
119
121
  */
120
- static create<T extends ClayProviderOptions>(options?: T): Promise<ClayErasureCodingProvider>;
122
+ static create(config: ClayConfig): Promise<ClayErasureCodingProvider>;
121
123
  encode(data: Uint8Array): ChunkCollection;
122
124
  decode(available: Uint8Array[], config: ClayDecodeConfig): ChunkCollection;
123
125
  getChunkMerkleRoots(): Uint8Array[];
@@ -132,5 +134,7 @@ declare class ClayErasureCodingProvider implements ErasureCodingProvider {
132
134
  */
133
135
  requiresPadding(dataSize: number): boolean;
134
136
  }
137
+ type ClayConfigInput = Required<ClayConfig>;
138
+ declare function buildClayConfig(input: ClayConfigInput): ClayConfig;
135
139
 
136
- export { ClayErasureCodingProvider as C, type DecodeConfig as D, type ErasureCodingConfig as E, type InitConfig as I, ReedSolomonErasureCodingProvider as R, type ErasureCodingProvider as a, type ClayProviderOptions as b, type ReedSolomonConfig as c, type ReedSolomonProviderOptions as d, type ClayConfig as e, type ClayErasureCodeParams as f, type ClayDecodeConfig as g };
140
+ export { ClayErasureCodingProvider as C, type DecodeConfig as D, type ErasureCodingConfig as E, type InitConfig as I, ReedSolomonErasureCodingProvider as R, type ErasureCodingProvider as a, type ClayConfig as b, type ClayProviderOptions as c, type ReedSolomonConfig as d, type ReedSolomonProviderOptions as e, type ClayErasureCodeParams as f, type ClayDecodeConfig as g, buildClayConfig as h };
@@ -1,6 +1,8 @@
1
1
  import { AccountAddress, AccountAddressInput } from '@aptos-labs/ts-sdk';
2
2
  import { BlobName } from './layout.js';
3
3
  import 'zod';
4
+ import '../clay-codes-DHP-bYcP.js';
5
+ import '@shelby-protocol/clay-codes';
4
6
 
5
7
  /**
6
8
  * Represents a blob on the Shelby network.
@@ -2,7 +2,8 @@
2
2
  * Chunk and chunkset size configurations supported by Shelby.
3
3
  */
4
4
  declare enum ChunkSizeScheme {
5
- ChunkSet10MiB_Chunk1MiB = "ChunkSet10MiB_Chunk1MiB"
5
+ ChunkSet10MiB_Chunk1MiB = "ChunkSet10MiB_Chunk1MiB",
6
+ ChunkSet2MiB_Chunk1MiB = "ChunkSet2MiB_Chunk1MiB"
6
7
  }
7
8
  /**
8
9
  * Parameters for chunk and chunkset sizes in bytes.
@@ -12,6 +13,10 @@ declare const CHUNK_SIZE_PARAMS: {
12
13
  readonly chunkSizeBytes: number;
13
14
  readonly chunksetSizeBytes: number;
14
15
  };
16
+ readonly ChunkSet2MiB_Chunk1MiB: {
17
+ readonly chunkSizeBytes: number;
18
+ readonly chunksetSizeBytes: number;
19
+ };
15
20
  };
16
21
  /**
17
22
  * The default size of a chunk in bytes.
@@ -29,6 +34,10 @@ declare const ERASURE_CODE_AND_CHUNK_MAPPING: {
29
34
  readonly chunkSizeBytes: number;
30
35
  readonly chunksetSizeBytes: number;
31
36
  };
37
+ readonly ClayCode_4Total_2Data_3Helper: {
38
+ readonly chunkSizeBytes: number;
39
+ readonly chunksetSizeBytes: number;
40
+ };
32
41
  };
33
42
 
34
43
  export { CHUNK_SIZE_PARAMS, ChunkSizeScheme, DEFAULT_CHUNKSET_SIZE_BYTES, DEFAULT_CHUNK_SIZE_BYTES, ERASURE_CODE_AND_CHUNK_MAPPING };
@@ -4,8 +4,8 @@ import {
4
4
  DEFAULT_CHUNKSET_SIZE_BYTES,
5
5
  DEFAULT_CHUNK_SIZE_BYTES,
6
6
  ERASURE_CODE_AND_CHUNK_MAPPING
7
- } from "../chunk-67F5YZ25.mjs";
8
- import "../chunk-ZPW742E7.mjs";
7
+ } from "../chunk-JTXYKO3U.mjs";
8
+ import "../chunk-AUQDI5BS.mjs";
9
9
  import "../chunk-7P6ASYW6.mjs";
10
10
  export {
11
11
  CHUNK_SIZE_PARAMS,