@shelby-protocol/sdk 0.0.4 → 0.0.6

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 (41) hide show
  1. package/dist/browser/index.d.ts +4 -4
  2. package/dist/browser/index.mjs +60 -35
  3. package/dist/{chunk-MYN7KW2X.mjs → chunk-2JMRK5PM.mjs} +1 -1
  4. package/dist/{chunk-KBUWZXFA.mjs → chunk-4JZO2D7T.mjs} +6 -1
  5. package/dist/{chunk-GKRHKR3J.mjs → chunk-7P3P3D3X.mjs} +7 -7
  6. package/dist/{chunk-4W3FFVXZ.mjs → chunk-CQZZRXA6.mjs} +95 -8
  7. package/dist/{chunk-3QINXXV6.mjs → chunk-HDYY6NS4.mjs} +125 -31
  8. package/dist/{chunk-VPT45MTZ.mjs → chunk-HFGEQP5N.mjs} +1 -1
  9. package/dist/{chunk-LTV26KU4.mjs → chunk-PCNLFNAT.mjs} +1 -1
  10. package/dist/{chunk-DLMDDEWF.mjs → chunk-WJKSPJSS.mjs} +26 -0
  11. package/dist/core/chunk.mjs +1 -1
  12. package/dist/core/clients/ShelbyBlobClient.d.ts +80 -17
  13. package/dist/core/clients/ShelbyBlobClient.mjs +7 -7
  14. package/dist/core/clients/ShelbyClient.d.ts +37 -1
  15. package/dist/core/clients/ShelbyClient.mjs +10 -10
  16. package/dist/core/clients/ShelbyRPCClient.d.ts +1 -1
  17. package/dist/core/clients/ShelbyRPCClient.mjs +7 -7
  18. package/dist/core/clients/index.d.ts +1 -1
  19. package/dist/core/clients/index.mjs +12 -12
  20. package/dist/core/commitments.mjs +3 -3
  21. package/dist/core/erasure/clay-codes.mjs +1 -1
  22. package/dist/core/erasure/default.mjs +1 -1
  23. package/dist/core/erasure/index.mjs +3 -3
  24. package/dist/core/index.d.ts +4 -4
  25. package/dist/core/index.mjs +60 -35
  26. package/dist/core/layout.mjs +1 -1
  27. package/dist/core/operations/generated/sdk.d.ts +307 -1
  28. package/dist/core/operations/generated/sdk.mjs +5 -1
  29. package/dist/core/operations/index.d.ts +8 -3
  30. package/dist/core/operations/index.mjs +25 -2
  31. package/dist/core/types/blobs.d.ts +9 -0
  32. package/dist/core/types/index.mjs +1 -1
  33. package/dist/core/utils.d.ts +8 -1
  34. package/dist/core/utils.mjs +3 -1
  35. package/dist/node/clients/ShelbyNodeClient.d.ts +2 -2
  36. package/dist/node/clients/ShelbyNodeClient.mjs +11 -11
  37. package/dist/node/clients/index.d.ts +1 -1
  38. package/dist/node/clients/index.mjs +13 -13
  39. package/dist/node/index.d.ts +4 -4
  40. package/dist/node/index.mjs +66 -41
  41. package/package.json +2 -1
@@ -16,10 +16,10 @@ export { ShelbyIndexerClient, createShelbyIndexerClient, getShelbyIndexerClient
16
16
  export { getShelbyAccountBlobsExplorerUrl, getShelbyAccountExplorerUrl, getShelbyBlobExplorerUrl } from '../core/shelby-explorer.js';
17
17
  export { BlobActivity, BlobActivityType, BlobEncoding, BlobMetadata, ClayEncoding } from '../core/types/blobs.js';
18
18
  export { StorageProviderInfo } from '../core/types/storage_providers.js';
19
- export { buildRequestUrl, concatHashes, readInChunks, zeroPadBytes } from '../core/utils.js';
19
+ export { buildRequestUrl, concatHashes, getBlobNameSuffix, readInChunks, zeroPadBytes } from '../core/utils.js';
20
+ export { Bigint_Comparison_Exp, Blob_Activities, Blob_Activities_Aggregate, Blob_Activities_Aggregate_Fields, Blob_Activities_Aggregate_FieldsCountArgs, Blob_Activities_Avg_Fields, Blob_Activities_Bool_Exp, Blob_Activities_Max_Fields, Blob_Activities_Min_Fields, Blob_Activities_Order_By, Blob_Activities_Select_Column, Blob_Activities_Stddev_Fields, Blob_Activities_Stddev_Pop_Fields, Blob_Activities_Stddev_Samp_Fields, Blob_Activities_Stream_Cursor_Input, Blob_Activities_Stream_Cursor_Value_Input, Blob_Activities_Sum_Fields, Blob_Activities_Var_Pop_Fields, Blob_Activities_Var_Samp_Fields, Blob_Activities_Variance_Fields, Blobs, BlobsPlacement_Group_SlotsArgs, Blobs_Aggregate, Blobs_Aggregate_Fields, Blobs_Aggregate_FieldsCountArgs, Blobs_Avg_Fields, Blobs_Bool_Exp, Blobs_Max_Fields, Blobs_Min_Fields, Blobs_Order_By, Blobs_Select_Column, Blobs_Stddev_Fields, Blobs_Stddev_Pop_Fields, Blobs_Stddev_Samp_Fields, Blobs_Stream_Cursor_Input, Blobs_Stream_Cursor_Value_Input, Blobs_Sum_Fields, Blobs_Var_Pop_Fields, Blobs_Var_Samp_Fields, Blobs_Variance_Fields, Cursor_Ordering, Exact, GetBlobActivitiesCountDocument, GetBlobActivitiesCountQuery, GetBlobActivitiesCountQueryVariables, GetBlobActivitiesDocument, GetBlobActivitiesQuery, GetBlobActivitiesQueryVariables, GetBlobsCountDocument, GetBlobsCountQuery, GetBlobsCountQueryVariables, GetBlobsDocument, GetBlobsQuery, GetBlobsQueryVariables, Incremental, InputMaybe, MakeEmpty, MakeMaybe, MakeOptional, Maybe, Numeric_Comparison_Exp, Order_By, Placement_Group_Slots, Placement_Group_Slots_Aggregate_Order_By, Placement_Group_Slots_Avg_Order_By, Placement_Group_Slots_Bool_Exp, Placement_Group_Slots_Max_Order_By, Placement_Group_Slots_Min_Order_By, Placement_Group_Slots_Order_By, Placement_Group_Slots_Select_Column, Placement_Group_Slots_Stddev_Order_By, Placement_Group_Slots_Stddev_Pop_Order_By, Placement_Group_Slots_Stddev_Samp_Order_By, Placement_Group_Slots_Stream_Cursor_Input, Placement_Group_Slots_Stream_Cursor_Value_Input, Placement_Group_Slots_Sum_Order_By, Placement_Group_Slots_Var_Pop_Order_By, Placement_Group_Slots_Var_Samp_Order_By, Placement_Group_Slots_Variance_Order_By, Processor_Status, Processor_Status_Bool_Exp, Processor_Status_Order_By, Processor_Status_Select_Column, Processor_Status_Stream_Cursor_Input, Processor_Status_Stream_Cursor_Value_Input, Query_Root, Query_RootBlob_ActivitiesArgs, Query_RootBlob_Activities_AggregateArgs, Query_RootBlob_Activities_By_PkArgs, Query_RootBlobsArgs, Query_RootBlobs_AggregateArgs, Query_RootBlobs_By_PkArgs, Query_RootPlacement_Group_SlotsArgs, Query_RootPlacement_Group_Slots_By_PkArgs, Query_RootProcessor_StatusArgs, Scalars, Sdk, SdkFunctionWrapper, String_Comparison_Exp, Subscription_Root, Subscription_RootBlob_ActivitiesArgs, Subscription_RootBlob_Activities_AggregateArgs, Subscription_RootBlob_Activities_By_PkArgs, Subscription_RootBlob_Activities_StreamArgs, Subscription_RootBlobsArgs, Subscription_RootBlobs_AggregateArgs, Subscription_RootBlobs_By_PkArgs, Subscription_RootBlobs_StreamArgs, Subscription_RootPlacement_Group_SlotsArgs, Subscription_RootPlacement_Group_Slots_By_PkArgs, Subscription_RootPlacement_Group_Slots_StreamArgs, Subscription_RootProcessor_StatusArgs, Subscription_RootProcessor_Status_StreamArgs, Timestamp_Comparison_Exp, getSdk } from '../core/operations/generated/sdk.js';
20
21
  import '@aptos-labs/ts-sdk';
21
22
  import 'zod';
22
- import '../core/operations/generated/sdk.js';
23
- import 'graphql';
24
- import 'graphql-request';
25
23
  import '@shelby-protocol/clay-codes';
24
+ import 'graphql-request';
25
+ import 'graphql';
@@ -1,29 +1,15 @@
1
1
  import "../chunk-DJJD2AXO.mjs";
2
2
  import "../chunk-MWDW4ROU.mjs";
3
- import "../chunk-ZHXCVRZX.mjs";
4
3
  import "../chunk-MQUVYMNQ.mjs";
5
4
  import "../chunk-RNXGC54D.mjs";
6
5
  import {
7
6
  ShelbyClient
8
- } from "../chunk-4W3FFVXZ.mjs";
9
- import {
10
- ShelbyBlobClient
11
- } from "../chunk-3QINXXV6.mjs";
7
+ } from "../chunk-CQZZRXA6.mjs";
12
8
  import "../chunk-Z7RFCADT.mjs";
13
9
  import {
14
10
  ShelbyRPCClient
15
- } from "../chunk-GKRHKR3J.mjs";
16
- import {
17
- createShelbyIndexerClient,
18
- getShelbyIndexerClient
19
- } from "../chunk-VPT45MTZ.mjs";
20
- import "../chunk-DLMDDEWF.mjs";
21
- import {
22
- BlobNameSchema,
23
- ChunkKey,
24
- allChunksForBlob,
25
- roundSize
26
- } from "../chunk-FIFKKWXV.mjs";
11
+ } from "../chunk-7P3P3D3X.mjs";
12
+ import "../chunk-ZHXCVRZX.mjs";
27
13
  import {
28
14
  isShelbyNetwork,
29
15
  shelbyNetworks
@@ -34,6 +20,26 @@ import {
34
20
  getShelbyAccountExplorerUrl,
35
21
  getShelbyBlobExplorerUrl
36
22
  } from "../chunk-BDSW5PHM.mjs";
23
+ import {
24
+ ShelbyBlobClient
25
+ } from "../chunk-HDYY6NS4.mjs";
26
+ import {
27
+ createShelbyIndexerClient,
28
+ getShelbyIndexerClient
29
+ } from "../chunk-HFGEQP5N.mjs";
30
+ import {
31
+ Blob_Activities_Select_Column,
32
+ Blobs_Select_Column,
33
+ Cursor_Ordering,
34
+ GetBlobActivitiesCountDocument,
35
+ GetBlobActivitiesDocument,
36
+ GetBlobsCountDocument,
37
+ GetBlobsDocument,
38
+ Order_By,
39
+ Placement_Group_Slots_Select_Column,
40
+ Processor_Status_Select_Column,
41
+ getSdk
42
+ } from "../chunk-WJKSPJSS.mjs";
37
43
  import "../chunk-RBFWGDMY.mjs";
38
44
  import {
39
45
  getAptosAccountExplorerUrl,
@@ -47,13 +53,33 @@ import {
47
53
  ChunksetCommitmentSchema,
48
54
  expectedTotalChunksets,
49
55
  generateCommitments
50
- } from "../chunk-LTV26KU4.mjs";
56
+ } from "../chunk-PCNLFNAT.mjs";
51
57
  import {
52
58
  buildRequestUrl,
53
59
  concatHashes,
60
+ getBlobNameSuffix,
54
61
  readInChunks,
55
62
  zeroPadBytes
56
- } from "../chunk-KBUWZXFA.mjs";
63
+ } from "../chunk-4JZO2D7T.mjs";
64
+ import {
65
+ DEFAULT_PROJECT_DESCRIPTION,
66
+ DEFAULT_PROJECT_NAME,
67
+ NetworkToShelbyBlobIndexerBaseUrl,
68
+ NetworkToShelbyRPCBaseUrl,
69
+ SHELBYUSD_FA_METADATA_ADDRESS,
70
+ SHELBYUSD_TOKEN_ADDRESS,
71
+ SHELBYUSD_TOKEN_MODULE,
72
+ SHELBYUSD_TOKEN_NAME,
73
+ SHELBY_DEPLOYER,
74
+ TOKEN_DEPLOYER,
75
+ TOKEN_OBJECT_ADDRESS
76
+ } from "../chunk-SEXQTDX6.mjs";
77
+ import {
78
+ BlobNameSchema,
79
+ ChunkKey,
80
+ allChunksForBlob,
81
+ roundSize
82
+ } from "../chunk-FIFKKWXV.mjs";
57
83
  import {
58
84
  CHUNK_SIZE_PARAMS,
59
85
  ChunkSizeScheme,
@@ -63,6 +89,9 @@ import {
63
89
  ERASURE_CODE_AND_CHUNK_MAPPING,
64
90
  createDefaultErasureCodingProvider
65
91
  } from "../chunk-APML3CGJ.mjs";
92
+ import {
93
+ ReedSolomonErasureCodingProvider
94
+ } from "../chunk-3ZDXWPYC.mjs";
66
95
  import {
67
96
  DEFAULT_ERASURE_D,
68
97
  DEFAULT_ERASURE_K,
@@ -71,31 +100,18 @@ import {
71
100
  ERASURE_CODE_PARAMS,
72
101
  ErasureCodingScheme
73
102
  } from "../chunk-ZPW742E7.mjs";
74
- import {
75
- ReedSolomonErasureCodingProvider
76
- } from "../chunk-3ZDXWPYC.mjs";
77
- import {
78
- DEFAULT_PROJECT_DESCRIPTION,
79
- DEFAULT_PROJECT_NAME,
80
- NetworkToShelbyBlobIndexerBaseUrl,
81
- NetworkToShelbyRPCBaseUrl,
82
- SHELBYUSD_FA_METADATA_ADDRESS,
83
- SHELBYUSD_TOKEN_ADDRESS,
84
- SHELBYUSD_TOKEN_MODULE,
85
- SHELBYUSD_TOKEN_NAME,
86
- SHELBY_DEPLOYER,
87
- TOKEN_DEPLOYER,
88
- TOKEN_OBJECT_ADDRESS
89
- } from "../chunk-SEXQTDX6.mjs";
90
103
  import "../chunk-7P6ASYW6.mjs";
91
104
  export {
92
105
  BlobCommitmentsSchema,
93
106
  BlobNameSchema,
107
+ Blob_Activities_Select_Column,
108
+ Blobs_Select_Column,
94
109
  CHUNK_SIZE_PARAMS,
95
110
  ChunkKey,
96
111
  ChunkSizeScheme,
97
112
  ChunksetCommitmentSchema,
98
113
  ClayErasureCodingProvider,
114
+ Cursor_Ordering,
99
115
  DEFAULT_CHUNKSET_SIZE_BYTES,
100
116
  DEFAULT_CHUNK_SIZE_BYTES,
101
117
  DEFAULT_ERASURE_D,
@@ -107,8 +123,15 @@ export {
107
123
  ERASURE_CODE_AND_CHUNK_MAPPING,
108
124
  ERASURE_CODE_PARAMS,
109
125
  ErasureCodingScheme,
126
+ GetBlobActivitiesCountDocument,
127
+ GetBlobActivitiesDocument,
128
+ GetBlobsCountDocument,
129
+ GetBlobsDocument,
110
130
  NetworkToShelbyBlobIndexerBaseUrl,
111
131
  NetworkToShelbyRPCBaseUrl,
132
+ Order_By,
133
+ Placement_Group_Slots_Select_Column,
134
+ Processor_Status_Select_Column,
112
135
  ReedSolomonErasureCodingProvider,
113
136
  SHELBYUSD_FA_METADATA_ADDRESS,
114
137
  SHELBYUSD_TOKEN_ADDRESS,
@@ -130,6 +153,8 @@ export {
130
153
  generateCommitments,
131
154
  getAptosAccountExplorerUrl,
132
155
  getAptosTransactionExplorerUrl,
156
+ getBlobNameSuffix,
157
+ getSdk,
133
158
  getShelbyAccountBlobsExplorerUrl,
134
159
  getShelbyAccountExplorerUrl,
135
160
  getShelbyBlobExplorerUrl,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ShelbyClient
3
- } from "./chunk-4W3FFVXZ.mjs";
3
+ } from "./chunk-CQZZRXA6.mjs";
4
4
 
5
5
  // src/node/clients/ShelbyNodeClient.ts
6
6
  var ShelbyNodeClient = class extends ShelbyClient {
@@ -83,10 +83,15 @@ function buildRequestUrl(path, baseUrl) {
83
83
  const safePath = path.replace(/^\/+/, "");
84
84
  return new URL(safePath, safeBase);
85
85
  }
86
+ function getBlobNameSuffix(blobName) {
87
+ const parts = blobName.split("/");
88
+ return parts.slice(1).join("/") || "";
89
+ }
86
90
 
87
91
  export {
88
92
  readInChunks,
89
93
  zeroPadBytes,
90
94
  concatHashes,
91
- buildRequestUrl
95
+ buildRequestUrl,
96
+ getBlobNameSuffix
92
97
  };
@@ -1,18 +1,18 @@
1
- import {
2
- getShelbyIndexerClient
3
- } from "./chunk-VPT45MTZ.mjs";
4
- import {
5
- BlobNameSchema
6
- } from "./chunk-FIFKKWXV.mjs";
7
1
  import {
8
2
  sleep
9
3
  } from "./chunk-I6NG5GNL.mjs";
4
+ import {
5
+ getShelbyIndexerClient
6
+ } from "./chunk-HFGEQP5N.mjs";
10
7
  import {
11
8
  buildRequestUrl
12
- } from "./chunk-KBUWZXFA.mjs";
9
+ } from "./chunk-4JZO2D7T.mjs";
13
10
  import {
14
11
  NetworkToShelbyRPCBaseUrl
15
12
  } from "./chunk-SEXQTDX6.mjs";
13
+ import {
14
+ BlobNameSchema
15
+ } from "./chunk-FIFKKWXV.mjs";
16
16
 
17
17
  // src/core/clients/ShelbyRPCClient.ts
18
18
  import { AccountAddress } from "@aptos-labs/ts-sdk";
@@ -1,26 +1,30 @@
1
- import {
2
- ShelbyBlobClient
3
- } from "./chunk-3QINXXV6.mjs";
4
1
  import {
5
2
  ShelbyRPCClient
6
- } from "./chunk-GKRHKR3J.mjs";
3
+ } from "./chunk-7P3P3D3X.mjs";
4
+ import {
5
+ ShelbyBlobClient
6
+ } from "./chunk-HDYY6NS4.mjs";
7
7
  import {
8
8
  getAptosConfig
9
9
  } from "./chunk-RBFWGDMY.mjs";
10
10
  import {
11
- generateCommitments
12
- } from "./chunk-LTV26KU4.mjs";
11
+ createBlobKey
12
+ } from "./chunk-OTBLZL2S.mjs";
13
13
  import {
14
- ClayErasureCodingProvider
15
- } from "./chunk-APML3CGJ.mjs";
14
+ generateCommitments
15
+ } from "./chunk-PCNLFNAT.mjs";
16
16
  import {
17
17
  NetworkToShelbyRPCBaseUrl
18
18
  } from "./chunk-SEXQTDX6.mjs";
19
+ import {
20
+ ClayErasureCodingProvider
21
+ } from "./chunk-APML3CGJ.mjs";
19
22
 
20
23
  // src/core/clients/ShelbyClient.ts
21
24
  import {
22
25
  Aptos
23
26
  } from "@aptos-labs/ts-sdk";
27
+ import pLimit from "p-limit";
24
28
  var ShelbyClient = class {
25
29
  /**
26
30
  * The coordination client is used to interact with the Aptos blockchain which handles the commitments
@@ -150,6 +154,89 @@ var ShelbyClient = class {
150
154
  blobData: params.blobData
151
155
  });
152
156
  }
157
+ /**
158
+ * Uploads a batch of blobs to the Shelby network.
159
+ * This method handles the complete upload flow including commitment generation,
160
+ * blockchain registration, and storage upload.
161
+ *
162
+ * @param params.blobs - The blobs to upload.
163
+ * @param params.blobs.blobData - The raw data to upload as a Uint8Array.
164
+ * @param params.blobs.blobName - The name/path of the blob (e.g. "folder/file.txt").
165
+ * @param params.expirationMicros - The expiration time in microseconds since Unix epoch.
166
+ * @param params.signer - The account that signs and pays for the transaction.
167
+ * @param params.options - Optional upload configuration.
168
+ * @param params.options.chunksetSizeBytes - Custom chunkset size.
169
+ * @param params.options.build - Additional Aptos transaction options.
170
+ *
171
+ * @returns The transaction and generated blob commitments (when implemented).
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * await client.batchUpload({
176
+ * blobs: [
177
+ * { blobData: Buffer.from("Hello, World!"), blobName: "hello.txt" },
178
+ * { blobData: Buffer.from("Hello, World 2!"), blobName: "hello2.txt" },
179
+ * ],
180
+ * expirationMicros: Date.now() * 1000 + 86400_000_000 // 24 hours from now
181
+ * });
182
+ * ```
183
+ */
184
+ async batchUpload(params) {
185
+ const existingBlobs = await this.coordination.getBlobs({
186
+ where: {
187
+ blob_name: {
188
+ _in: params.blobs.map(
189
+ (blob) => createBlobKey({
190
+ account: params.signer.accountAddress,
191
+ blobName: blob.blobName
192
+ })
193
+ )
194
+ }
195
+ }
196
+ });
197
+ const blobsToRegister = params.blobs.filter(
198
+ (blob) => !existingBlobs.some(
199
+ (existingBlob) => existingBlob.name === createBlobKey({
200
+ account: params.signer.accountAddress,
201
+ blobName: blob.blobName
202
+ })
203
+ )
204
+ );
205
+ if (blobsToRegister.length > 0) {
206
+ const provider = await this.getProvider();
207
+ const blobCommitments = await Promise.all(
208
+ blobsToRegister.map(
209
+ async (blob) => generateCommitments(provider, blob.blobData)
210
+ )
211
+ );
212
+ const { transaction: pendingRegisterBlobTransaction } = await this.coordination.batchRegisterBlobs({
213
+ account: params.signer,
214
+ expirationMicros: params.expirationMicros,
215
+ blobs: blobsToRegister.map((blob, index) => ({
216
+ blobName: blob.blobName,
217
+ blobSize: blob.blobData.length,
218
+ blobMerkleRoot: blobCommitments[index].blob_merkle_root
219
+ })),
220
+ options: params.options
221
+ });
222
+ await this.coordination.aptos.waitForTransaction({
223
+ transactionHash: pendingRegisterBlobTransaction.hash,
224
+ options: { waitForIndexer: true }
225
+ });
226
+ }
227
+ const limit = pLimit(3);
228
+ await Promise.all(
229
+ params.blobs.map(
230
+ (blob) => limit(
231
+ () => this.rpc.putBlob({
232
+ account: params.signer.accountAddress,
233
+ blobName: blob.blobName,
234
+ blobData: blob.blobData
235
+ })
236
+ )
237
+ )
238
+ );
239
+ }
153
240
  /**
154
241
  * Downloads a blob from the Shelby RPC node.
155
242
  *
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getShelbyIndexerClient
3
- } from "./chunk-VPT45MTZ.mjs";
3
+ } from "./chunk-HFGEQP5N.mjs";
4
4
  import {
5
5
  getAptosConfig
6
6
  } from "./chunk-RBFWGDMY.mjs";
@@ -9,7 +9,13 @@ import {
9
9
  } from "./chunk-OTBLZL2S.mjs";
10
10
  import {
11
11
  expectedTotalChunksets
12
- } from "./chunk-LTV26KU4.mjs";
12
+ } from "./chunk-PCNLFNAT.mjs";
13
+ import {
14
+ getBlobNameSuffix
15
+ } from "./chunk-4JZO2D7T.mjs";
16
+ import {
17
+ SHELBY_DEPLOYER
18
+ } from "./chunk-SEXQTDX6.mjs";
13
19
  import {
14
20
  DEFAULT_CHUNKSET_SIZE_BYTES,
15
21
  ERASURE_CODE_AND_CHUNK_MAPPING
@@ -17,9 +23,6 @@ import {
17
23
  import {
18
24
  ERASURE_CODE_PARAMS
19
25
  } from "./chunk-ZPW742E7.mjs";
20
- import {
21
- SHELBY_DEPLOYER
22
- } from "./chunk-SEXQTDX6.mjs";
23
26
 
24
27
  // src/core/clients/ShelbyBlobClient.ts
25
28
  import {
@@ -86,7 +89,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
86
89
  try {
87
90
  const rawMetadata = await this.aptos.view({
88
91
  payload: {
89
- function: `${this.deployer.toString()}::global_metadata::get_blob_metadata`,
92
+ function: `${this.deployer.toString()}::blob_metadata::get_blob_metadata`,
90
93
  functionArguments: [
91
94
  createBlobKey({
92
95
  account: params.account,
@@ -117,6 +120,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
117
120
  ).toUint8Array(),
118
121
  owner: AccountAddress.fromString(metadata.owner),
119
122
  name: params.name,
123
+ blobNameSuffix: getBlobNameSuffix(params.name),
120
124
  size: Number(metadata.blob_size),
121
125
  encoding,
122
126
  expirationMicros: metadata.expiration_micros,
@@ -149,13 +153,14 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
149
153
  * ```
150
154
  */
151
155
  getAccountBlobs(params) {
156
+ const { where, ...rest } = params;
152
157
  return this.getBlobs({
153
158
  where: {
154
- ...params.where,
159
+ ...where ?? {},
155
160
  owner: { _eq: AccountAddress.from(params.account).toString() }
156
161
  },
157
- pagination: params.pagination,
158
- orderBy: params.orderBy
162
+ pagination: rest.pagination,
163
+ orderBy: rest.orderBy
159
164
  });
160
165
  }
161
166
  /**
@@ -177,8 +182,14 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
177
182
  async getBlobs(params = {}) {
178
183
  const { limit, offset } = params.pagination ?? {};
179
184
  const { orderBy, where } = params;
185
+ const currentMicros = Date.now() * 1e3;
186
+ const defaultActiveFilter = {
187
+ expires_at: { _gte: currentMicros },
188
+ is_deleted: { _eq: "0" }
189
+ };
190
+ const finalWhere = where !== void 0 ? { ...defaultActiveFilter, ...where } : defaultActiveFilter;
180
191
  const { blobs } = await this.indexer.getBlobs({
181
- where,
192
+ where: finalWhere,
182
193
  limit,
183
194
  offset,
184
195
  orderBy
@@ -187,6 +198,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
187
198
  (blob) => ({
188
199
  owner: AccountAddress.from(blob.owner),
189
200
  name: blob.blob_name,
201
+ blobNameSuffix: getBlobNameSuffix(blob.blob_name),
190
202
  blobMerkleRoot: Hex.fromHexInput(blob.blob_commitment).toUint8Array(),
191
203
  size: Number(blob.size),
192
204
  // TODO: Add encoding when supported in NCI
@@ -211,10 +223,10 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
211
223
  orderBy
212
224
  });
213
225
  const activityTypeMapping = {
214
- [`${this.deployer.toStringLong()}::global_metadata::BlobRegisteredEvent`]: "register_blob",
215
- [`${this.deployer.toStringLong()}::global_metadata::BlobDeletedEvent`]: "delete_blob",
216
- [`${this.deployer.toStringLong()}::global_metadata::BlobExpirationExtendedEvent`]: "extend_blob_expiration",
217
- [`${this.deployer.toStringLong()}::global_metadata::BlobWrittenEvent`]: "write_blob"
226
+ [`${this.deployer.toStringLong()}::blob_metadata::BlobRegisteredEvent`]: "register_blob",
227
+ [`${this.deployer.toStringLong()}::blob_metadata::BlobDeletedEvent`]: "delete_blob",
228
+ [`${this.deployer.toStringLong()}::blob_metadata::BlobExpirationExtendedEvent`]: "extend_blob_expiration",
229
+ [`${this.deployer.toStringLong()}::blob_metadata::BlobWrittenEvent`]: "write_blob"
218
230
  };
219
231
  return blob_activities.map(
220
232
  (activity) => ({
@@ -232,28 +244,36 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
232
244
  );
233
245
  }
234
246
  /**
235
- * Retrieves the blob chunks for a given blob from the blockchain. The blob chunk will contain
236
- * the commitment, the storage provider location, and the status of the chunk (stored or pending).
247
+ * Retrieves the total number of blobs from the blockchain.
237
248
  *
238
- * @deprecated Will need to get reworked when we are acking blobs from storage providers.
239
- *
240
- * @param params.account - The account namespace the blob is stored in (e.g. "0x1")
241
- * @param params.name - The name of the blob (e.g. "foo/bar")
242
- * @returns The chunks that make up the blob.
249
+ * @param params.where (optional) - The where clause to filter the blobs by.
250
+ * @returns The total number of blobs.
243
251
  *
244
252
  * @example
245
253
  * ```typescript
246
- * // BlobChunk[]
247
- * const chunks = await client.getBlobChunks({
248
- * account: AccountAddress.fromString("0x1"),
249
- * name: "foo/bar.txt",
250
- * });
254
+ * const count = await client.getBlobsCount();
255
+ * ```
256
+ */
257
+ async getBlobsCount(params) {
258
+ const { where } = params;
259
+ const { blobs_aggregate } = await this.indexer.getBlobsCount({ where });
260
+ return blobs_aggregate?.aggregate?.count ?? 0;
261
+ }
262
+ /**
263
+ * Retrieves the total number of blob activities from the blockchain.
264
+ *
265
+ * @param params.where (optional) - The where clause to filter the blob activities by.
266
+ * @returns The total number of blob activities.
251
267
  *
252
- * const isStored = chunks.every((c) => c.location.variant === "stored");
268
+ * @example
269
+ * ```typescript
270
+ * const count = await client.getBlobActivitiesCount();
253
271
  * ```
254
272
  */
255
- getBlobChunks(_params) {
256
- throw new Error("Not implemented");
273
+ async getBlobActivitiesCount(params) {
274
+ const { where } = params;
275
+ const { blob_activities_aggregate } = await this.indexer.getBlobActivitiesCount({ where });
276
+ return blob_activities_aggregate?.aggregate?.count ?? 0;
257
277
  }
258
278
  /**
259
279
  * Registers a blob on the blockchain by writing its merkle root and metadata.
@@ -305,6 +325,63 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
305
325
  })
306
326
  };
307
327
  }
328
+ /**
329
+ * Registers multiple blobs on the blockchain by writing their merkle roots and metadata.
330
+ *
331
+ * @param params.account - The account that is signing and paying for the transaction.
332
+ * @param params.expirationMicros - The expiration time of the blobs in microseconds.
333
+ * @param params.blobs - The blobs to register.
334
+ * @param params.blobs.blobName - The name/path of the blob (e.g. "foo/bar.txt").
335
+ * @param params.blobs.blobSize - The size of the blob in bytes.
336
+ * @param params.blobs.blobMerkleRoot - The merkle root of the blob commitments as a hex string.
337
+ * @param params.options - Optional transaction building options.
338
+ * @param params.options.chunksetSizeBytes - Custom chunkset size (defaults to DEFAULT_CHUNKSET_SIZE_BYTES).
339
+ * @param params.options.build - Additional Aptos transaction building options.
340
+ *
341
+ * @returns An object containing the pending transaction.
342
+ *
343
+ * @example
344
+ * ```typescript
345
+ * const provider = await ClayErasureCodingProvider.create();
346
+ * const blobCommitments = await generateCommitments(provider, data);
347
+ *
348
+ * const { transaction } = await client.batchRegisterBlobs({
349
+ * account: signer,
350
+ * expirationMicros: Date.now() * 1000 + 3600_000_000, // 1 hour from now in microseconds
351
+ * blobs: [
352
+ * {
353
+ * blobName: "foo/bar.txt",
354
+ * blobSize: data.length,
355
+ * blobMerkleRoot: blobCommitments.blob_merkle_root,
356
+ * },
357
+ * ],
358
+ * });
359
+ * ```
360
+ */
361
+ async batchRegisterBlobs(params) {
362
+ const chunksetSize = params.options?.chunksetSizeBytes ?? DEFAULT_CHUNKSET_SIZE_BYTES;
363
+ const transaction = await this.aptos.transaction.build.simple({
364
+ ...params.options?.build,
365
+ sender: params.account.accountAddress,
366
+ data: _ShelbyBlobClient.createBatchRegisterBlobsPayload({
367
+ deployer: this.deployer,
368
+ account: params.account.accountAddress,
369
+ expirationMicros: params.expirationMicros,
370
+ blobs: params.blobs.map((blob) => ({
371
+ blobName: blob.blobName,
372
+ blobSize: blob.blobSize,
373
+ blobMerkleRoot: blob.blobMerkleRoot,
374
+ numChunksets: expectedTotalChunksets(blob.blobSize, chunksetSize)
375
+ }))
376
+ })
377
+ });
378
+ return {
379
+ transaction: await this.aptos.signAndSubmitTransaction({
380
+ signer: params.account,
381
+ transaction
382
+ })
383
+ };
384
+ }
308
385
  /**
309
386
  * Creates a transaction payload to register a blob on the blockchain.
310
387
  * This is a static helper method for constructing the Move function call payload.
@@ -323,7 +400,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
323
400
  */
324
401
  static createRegisterBlobPayload(params) {
325
402
  return {
326
- function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::global_metadata::register_blob`,
403
+ function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::register_blob`,
327
404
  functionArguments: [
328
405
  params.blobName,
329
406
  params.expirationMicros,
@@ -367,7 +444,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
367
444
  blobSizes.push(blob.blobSize);
368
445
  });
369
446
  return {
370
- function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::global_metadata::register_multiple_blobs`,
447
+ function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::register_multiple_blobs`,
371
448
  functionArguments: [
372
449
  blobNames,
373
450
  params.expirationMicros,
@@ -380,6 +457,23 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
380
457
  ]
381
458
  };
382
459
  }
460
+ /**
461
+ * Creates a transaction payload to delete a blob on the blockchain.
462
+ * This is a static helper method for constructing the Move function call payload.
463
+ *
464
+ * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
465
+ * @param params.blobNameSuffix - The blob name suffix (e.g. "bar.txt").
466
+ *
467
+ * @returns An Aptos transaction payload data object for the delete_blob Move function.
468
+ *
469
+ * @see https://github.com/shelby/shelby/blob/64e9d7b4f0005e586faeb1e4085c79159234b6b6/move/shelby_contract/sources/global_metadata.move#L616
470
+ */
471
+ static createDeleteBlobPayload(params) {
472
+ return {
473
+ function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::blob_metadata::delete_blob`,
474
+ functionArguments: [params.blobNameSuffix]
475
+ };
476
+ }
383
477
  };
384
478
 
385
479
  export {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getSdk
3
- } from "./chunk-DLMDDEWF.mjs";
3
+ } from "./chunk-WJKSPJSS.mjs";
4
4
  import {
5
5
  getAptosConfig
6
6
  } from "./chunk-RBFWGDMY.mjs";
@@ -2,7 +2,7 @@ import {
2
2
  concatHashes,
3
3
  readInChunks,
4
4
  zeroPadBytes
5
- } from "./chunk-KBUWZXFA.mjs";
5
+ } from "./chunk-4JZO2D7T.mjs";
6
6
  import {
7
7
  DEFAULT_CHUNKSET_SIZE_BYTES
8
8
  } from "./chunk-APML3CGJ.mjs";