@shelby-protocol/sdk 0.0.6 → 0.0.8

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 (48) hide show
  1. package/dist/browser/index.d.ts +3 -3
  2. package/dist/browser/index.mjs +21 -14
  3. package/dist/chunk-67F5YZ25.mjs +28 -0
  4. package/dist/{chunk-HDYY6NS4.mjs → chunk-BBOG5JSX.mjs} +71 -4
  5. package/dist/chunk-CPNZAQVY.mjs +29 -0
  6. package/dist/{chunk-FIFKKWXV.mjs → chunk-GY5DCVVL.mjs} +1 -1
  7. package/dist/{chunk-2JMRK5PM.mjs → chunk-LGNWAXBG.mjs} +1 -1
  8. package/dist/{chunk-CQZZRXA6.mjs → chunk-MGAN2SBA.mjs} +83 -7
  9. package/dist/{chunk-APML3CGJ.mjs → chunk-NLPIHQ7K.mjs} +17 -44
  10. package/dist/{chunk-3ZDXWPYC.mjs → chunk-PZF2VTGP.mjs} +5 -0
  11. package/dist/{chunk-7P3P3D3X.mjs → chunk-QRGZJBAG.mjs} +1 -1
  12. package/dist/chunk-XNEIWM4O.mjs +0 -0
  13. package/dist/{chunk-PCNLFNAT.mjs → chunk-XWAPNLU6.mjs} +39 -13
  14. package/dist/{clay-codes-Ce9EmXfa.d.ts → clay-codes-pdZFxI_B.d.ts} +7 -0
  15. package/dist/core/chunk.mjs +1 -2
  16. package/dist/core/clients/ShelbyBlobClient.d.ts +51 -3
  17. package/dist/core/clients/ShelbyBlobClient.mjs +7 -4
  18. package/dist/core/clients/ShelbyClient.d.ts +40 -1
  19. package/dist/core/clients/ShelbyClient.mjs +10 -7
  20. package/dist/core/clients/ShelbyClientConfig.d.ts +2 -0
  21. package/dist/core/clients/ShelbyRPCClient.mjs +3 -4
  22. package/dist/core/clients/index.d.ts +1 -1
  23. package/dist/core/clients/index.mjs +10 -7
  24. package/dist/core/commitments.d.ts +30 -29
  25. package/dist/core/commitments.mjs +6 -5
  26. package/dist/core/erasure/clay-codes.d.ts +1 -1
  27. package/dist/core/erasure/clay-codes.mjs +2 -2
  28. package/dist/core/erasure/default.d.ts +1 -1
  29. package/dist/core/erasure/default.mjs +3 -2
  30. package/dist/core/erasure/index.d.ts +1 -1
  31. package/dist/core/erasure/index.mjs +8 -4
  32. package/dist/core/erasure/provider.d.ts +1 -1
  33. package/dist/core/erasure/reed-solomon.d.ts +1 -1
  34. package/dist/core/erasure/reed-solomon.mjs +1 -1
  35. package/dist/core/erasure/utils.d.ts +1 -1
  36. package/dist/core/index.d.ts +3 -3
  37. package/dist/core/index.mjs +21 -14
  38. package/dist/core/layout.mjs +2 -3
  39. package/dist/core/types/blobs.d.ts +19 -2
  40. package/dist/core/types/encodings.d.ts +1 -1
  41. package/dist/core/types/index.d.ts +2 -2
  42. package/dist/node/clients/ShelbyNodeClient.d.ts +1 -1
  43. package/dist/node/clients/ShelbyNodeClient.mjs +11 -8
  44. package/dist/node/clients/index.d.ts +1 -1
  45. package/dist/node/clients/index.mjs +11 -8
  46. package/dist/node/index.d.ts +3 -3
  47. package/dist/node/index.mjs +22 -15
  48. package/package.json +2 -2
@@ -5,16 +5,16 @@ export { ShelbyBlobClient } from '../core/clients/ShelbyBlobClient.js';
5
5
  export { ShelbyClient, UploadOptions } from '../core/clients/ShelbyClient.js';
6
6
  export { ShelbyClientConfig, ShelbyIndexerConfig, ShelbyRPCConfig } from '../core/clients/ShelbyClientConfig.js';
7
7
  export { ShelbyRPCClient } from '../core/clients/ShelbyRPCClient.js';
8
- export { BlobCommitments, BlobCommitmentsSchema, ChunksetCommitment, ChunksetCommitmentSchema, GenerateCommitmentsOptions, expectedTotalChunksets, generateCommitments } from '../core/commitments.js';
8
+ export { BlobCommitments, BlobCommitmentsSchema, ChunksetCommitment, ChunksetCommitmentSchema, GenerateCommitmentsOptions, expectedTotalChunksets, generateCommitments, generateMerkleRoot } from '../core/commitments.js';
9
9
  export { DEFAULT_PROJECT_DESCRIPTION, DEFAULT_PROJECT_NAME, NetworkToShelbyBlobIndexerBaseUrl, NetworkToShelbyRPCBaseUrl, SHELBYUSD_FA_METADATA_ADDRESS, SHELBYUSD_TOKEN_ADDRESS, SHELBYUSD_TOKEN_MODULE, SHELBYUSD_TOKEN_NAME, SHELBY_DEPLOYER, TOKEN_DEPLOYER, TOKEN_OBJECT_ADDRESS } from '../core/constants.js';
10
- export { C as ClayErasureCodingProvider, D as DecodeConfig, E as ErasureCodingConfig, a as ErasureCodingProvider, R as ReedSolomonErasureCodingProvider } from '../clay-codes-Ce9EmXfa.js';
10
+ export { C as ClayErasureCodingProvider, D as DecodeConfig, E as ErasureCodingConfig, a as ErasureCodingProvider, R as ReedSolomonErasureCodingProvider } from '../clay-codes-pdZFxI_B.js';
11
11
  export { DEFAULT_ERASURE_D, DEFAULT_ERASURE_K, DEFAULT_ERASURE_M, DEFAULT_ERASURE_N, ERASURE_CODE_PARAMS, ErasureCodeParams, ErasureCodingScheme, ErasureSchemeParams } from '../core/erasure/constants.js';
12
12
  export { createDefaultErasureCodingProvider } from '../core/erasure/default.js';
13
13
  export { BlobName, BlobNameSchema, ChunkKey, allChunksForBlob, roundSize } from '../core/layout.js';
14
14
  export { ShelbyNetwork, isShelbyNetwork, shelbyNetworks } from '../core/networks.js';
15
15
  export { ShelbyIndexerClient, createShelbyIndexerClient, getShelbyIndexerClient } from '../core/operations/index.js';
16
16
  export { getShelbyAccountBlobsExplorerUrl, getShelbyAccountExplorerUrl, getShelbyBlobExplorerUrl } from '../core/shelby-explorer.js';
17
- export { BlobActivity, BlobActivityType, BlobEncoding, BlobMetadata, ClayEncoding } from '../core/types/blobs.js';
17
+ export { BlobActivity, BlobActivityType, BlobEncoding, BlobMetadata, ClayEncoding, StorageProviderAck } from '../core/types/blobs.js';
18
18
  export { StorageProviderInfo } from '../core/types/storage_providers.js';
19
19
  export { buildRequestUrl, concatHashes, getBlobNameSuffix, readInChunks, zeroPadBytes } from '../core/utils.js';
20
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';
@@ -1,15 +1,15 @@
1
1
  import "../chunk-DJJD2AXO.mjs";
2
2
  import "../chunk-MWDW4ROU.mjs";
3
3
  import "../chunk-MQUVYMNQ.mjs";
4
+ import "../chunk-ZHXCVRZX.mjs";
4
5
  import "../chunk-RNXGC54D.mjs";
5
6
  import {
6
7
  ShelbyClient
7
- } from "../chunk-CQZZRXA6.mjs";
8
+ } from "../chunk-MGAN2SBA.mjs";
8
9
  import "../chunk-Z7RFCADT.mjs";
9
10
  import {
10
11
  ShelbyRPCClient
11
- } from "../chunk-7P3P3D3X.mjs";
12
- import "../chunk-ZHXCVRZX.mjs";
12
+ } from "../chunk-QRGZJBAG.mjs";
13
13
  import {
14
14
  isShelbyNetwork,
15
15
  shelbyNetworks
@@ -22,7 +22,11 @@ import {
22
22
  } from "../chunk-BDSW5PHM.mjs";
23
23
  import {
24
24
  ShelbyBlobClient
25
- } from "../chunk-HDYY6NS4.mjs";
25
+ } from "../chunk-BBOG5JSX.mjs";
26
+ import "../chunk-XNEIWM4O.mjs";
27
+ import {
28
+ ReedSolomonErasureCodingProvider
29
+ } from "../chunk-PZF2VTGP.mjs";
26
30
  import {
27
31
  createShelbyIndexerClient,
28
32
  getShelbyIndexerClient
@@ -41,6 +45,12 @@ import {
41
45
  getSdk
42
46
  } from "../chunk-WJKSPJSS.mjs";
43
47
  import "../chunk-RBFWGDMY.mjs";
48
+ import {
49
+ createDefaultErasureCodingProvider
50
+ } from "../chunk-CPNZAQVY.mjs";
51
+ import {
52
+ ClayErasureCodingProvider
53
+ } from "../chunk-NLPIHQ7K.mjs";
44
54
  import {
45
55
  getAptosAccountExplorerUrl,
46
56
  getAptosTransactionExplorerUrl
@@ -52,8 +62,9 @@ import {
52
62
  BlobCommitmentsSchema,
53
63
  ChunksetCommitmentSchema,
54
64
  expectedTotalChunksets,
55
- generateCommitments
56
- } from "../chunk-PCNLFNAT.mjs";
65
+ generateCommitments,
66
+ generateMerkleRoot
67
+ } from "../chunk-XWAPNLU6.mjs";
57
68
  import {
58
69
  buildRequestUrl,
59
70
  concatHashes,
@@ -79,19 +90,14 @@ import {
79
90
  ChunkKey,
80
91
  allChunksForBlob,
81
92
  roundSize
82
- } from "../chunk-FIFKKWXV.mjs";
93
+ } from "../chunk-GY5DCVVL.mjs";
83
94
  import {
84
95
  CHUNK_SIZE_PARAMS,
85
96
  ChunkSizeScheme,
86
- ClayErasureCodingProvider,
87
97
  DEFAULT_CHUNKSET_SIZE_BYTES,
88
98
  DEFAULT_CHUNK_SIZE_BYTES,
89
- ERASURE_CODE_AND_CHUNK_MAPPING,
90
- createDefaultErasureCodingProvider
91
- } from "../chunk-APML3CGJ.mjs";
92
- import {
93
- ReedSolomonErasureCodingProvider
94
- } from "../chunk-3ZDXWPYC.mjs";
99
+ ERASURE_CODE_AND_CHUNK_MAPPING
100
+ } from "../chunk-67F5YZ25.mjs";
95
101
  import {
96
102
  DEFAULT_ERASURE_D,
97
103
  DEFAULT_ERASURE_K,
@@ -151,6 +157,7 @@ export {
151
157
  createShelbyIndexerClient,
152
158
  expectedTotalChunksets,
153
159
  generateCommitments,
160
+ generateMerkleRoot,
154
161
  getAptosAccountExplorerUrl,
155
162
  getAptosTransactionExplorerUrl,
156
163
  getBlobNameSuffix,
@@ -0,0 +1,28 @@
1
+ // src/core/chunk.ts
2
+ var ChunkSizeScheme = /* @__PURE__ */ ((ChunkSizeScheme2) => {
3
+ ChunkSizeScheme2["ChunkSet10MiB_Chunk1MiB"] = "ChunkSet10MiB_Chunk1MiB";
4
+ return ChunkSizeScheme2;
5
+ })(ChunkSizeScheme || {});
6
+ var CHUNK_SIZE_PARAMS = {
7
+ ["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */]: {
8
+ // 1MiB
9
+ chunkSizeBytes: 1 * 1024 * 1024,
10
+ // 10MiB
11
+ chunksetSizeBytes: 10 * 1024 * 1024
12
+ }
13
+ };
14
+ var DEFAULT_CHUNK_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */].chunkSizeBytes;
15
+ var DEFAULT_CHUNKSET_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */].chunksetSizeBytes;
16
+ var ERASURE_CODE_AND_CHUNK_MAPPING = {
17
+ ["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */]: {
18
+ ...CHUNK_SIZE_PARAMS.ChunkSet10MiB_Chunk1MiB
19
+ }
20
+ };
21
+
22
+ export {
23
+ ChunkSizeScheme,
24
+ CHUNK_SIZE_PARAMS,
25
+ DEFAULT_CHUNK_SIZE_BYTES,
26
+ DEFAULT_CHUNKSET_SIZE_BYTES,
27
+ ERASURE_CODE_AND_CHUNK_MAPPING
28
+ };
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-OTBLZL2S.mjs";
10
10
  import {
11
11
  expectedTotalChunksets
12
- } from "./chunk-PCNLFNAT.mjs";
12
+ } from "./chunk-XWAPNLU6.mjs";
13
13
  import {
14
14
  getBlobNameSuffix
15
15
  } from "./chunk-4JZO2D7T.mjs";
@@ -19,7 +19,7 @@ import {
19
19
  import {
20
20
  DEFAULT_CHUNKSET_SIZE_BYTES,
21
21
  ERASURE_CODE_AND_CHUNK_MAPPING
22
- } from "./chunk-APML3CGJ.mjs";
22
+ } from "./chunk-67F5YZ25.mjs";
23
23
  import {
24
24
  ERASURE_CODE_PARAMS
25
25
  } from "./chunk-ZPW742E7.mjs";
@@ -30,7 +30,8 @@ import {
30
30
  Aptos,
31
31
  AptosConfig,
32
32
  Hex,
33
- MoveVector
33
+ MoveVector,
34
+ U32
34
35
  } from "@aptos-labs/ts-sdk";
35
36
  var ShelbyBlobClient = class _ShelbyBlobClient {
36
37
  aptos;
@@ -123,7 +124,8 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
123
124
  blobNameSuffix: getBlobNameSuffix(params.name),
124
125
  size: Number(metadata.blob_size),
125
126
  encoding,
126
- expirationMicros: metadata.expiration_micros,
127
+ expirationMicros: Number(metadata.expiration_micros),
128
+ creationMicros: Number(metadata.creation_micros),
127
129
  sliceAddress: AccountAddress.fromString(metadata.slice.inner),
128
130
  isWritten: metadata.is_written
129
131
  };
@@ -208,6 +210,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
208
210
  ...ERASURE_CODE_AND_CHUNK_MAPPING.ClayCode_16Total_10Data_13Helper
209
211
  },
210
212
  expirationMicros: Number(blob.expires_at),
213
+ creationMicros: Number(blob.created_at),
211
214
  sliceAddress: AccountAddress.from(blob.slice_address),
212
215
  isWritten: Boolean(Number(blob.is_written))
213
216
  })
@@ -325,6 +328,50 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
325
328
  })
326
329
  };
327
330
  }
331
+ /**
332
+ * Acks the blob chunksets on-chain. If each chunkset meets the necessary threshold, the entire blob will be marked as written.
333
+ *
334
+ * @param params.account - The account that is signing the transaction.
335
+ * @param params.blobOwner - The account that owns the blob.
336
+ * @param params.blobName - The name of the blob (e.g. "foo/bar")
337
+ * @param params.creationMicros - The creation time of the blob in microseconds.
338
+ * @param params.chunksetIdx - The index of the chunkset being acknowledged.
339
+ * @param params.storageProviderChunksetAcks - The signatures
340
+ * @param params.options - Additional options for transaction building and encoding.
341
+ *
342
+ * @returns The blob commitments and the pending transaction.
343
+ *
344
+ * @example
345
+ * ```typescript
346
+ * const { transaction } = await client.addChunksetAcknowledgements({
347
+ * account: signer,
348
+ * blobOwner: owner,
349
+ * blobName: "foo/bar.txt",
350
+ * creationMicros, // Taken from the blob metadata at registration time.
351
+ * chunksetIdx,
352
+ * storageProviderAcks: An array of StorageProviderAck types, each having the slot index and signature from the SP.
353
+ * });
354
+ * ```
355
+ */
356
+ async addChunksetAcknowledgements(params) {
357
+ const transaction = await this.aptos.transaction.build.simple({
358
+ ...params.options?.build,
359
+ data: _ShelbyBlobClient.createChunksetAcknowledgementsPayload({
360
+ blobOwner: params.blobOwner,
361
+ blobName: params.blobName,
362
+ creationMicros: params.creationMicros,
363
+ chunksetIdx: params.chunksetIdx,
364
+ storageProviderAcks: params.storageProviderAcks
365
+ }),
366
+ sender: params.account.accountAddress
367
+ });
368
+ return {
369
+ transaction: await this.aptos.signAndSubmitTransaction({
370
+ signer: params.account,
371
+ transaction
372
+ })
373
+ };
374
+ }
328
375
  /**
329
376
  * Registers multiple blobs on the blockchain by writing their merkle roots and metadata.
330
377
  *
@@ -474,6 +521,26 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
474
521
  functionArguments: [params.blobNameSuffix]
475
522
  };
476
523
  }
524
+ static createChunksetAcknowledgementsPayload(params) {
525
+ const ackBitMask = params.storageProviderAcks.reduce(
526
+ (acc, ack) => acc | 1 << ack.slot,
527
+ 0
528
+ );
529
+ const signatures = new MoveVector(params.storageProviderAcks.map((ack) => MoveVector.U8(ack.signature)));
530
+ return {
531
+ function: `${SHELBY_DEPLOYER}::blob_metadata::add_chunkset_acknowledgements`,
532
+ functionArguments: [
533
+ createBlobKey({
534
+ account: params.blobOwner,
535
+ blobName: params.blobName
536
+ }),
537
+ params.chunksetIdx,
538
+ params.creationMicros,
539
+ new U32(Number(ackBitMask)),
540
+ signatures
541
+ ]
542
+ };
543
+ }
477
544
  };
478
545
 
479
546
  export {
@@ -0,0 +1,29 @@
1
+ import {
2
+ ClayErasureCodingProvider
3
+ } from "./chunk-NLPIHQ7K.mjs";
4
+ import {
5
+ DEFAULT_CHUNK_SIZE_BYTES
6
+ } from "./chunk-67F5YZ25.mjs";
7
+ import {
8
+ DEFAULT_ERASURE_D,
9
+ DEFAULT_ERASURE_K,
10
+ DEFAULT_ERASURE_N
11
+ } from "./chunk-ZPW742E7.mjs";
12
+
13
+ // src/core/erasure/default.ts
14
+ var defaultProviderPromise;
15
+ function createDefaultErasureCodingProvider() {
16
+ if (!defaultProviderPromise) {
17
+ defaultProviderPromise = ClayErasureCodingProvider.create({
18
+ erasure_n: DEFAULT_ERASURE_N,
19
+ erasure_k: DEFAULT_ERASURE_K,
20
+ erasure_d: DEFAULT_ERASURE_D,
21
+ chunkSizeBytes: DEFAULT_CHUNK_SIZE_BYTES
22
+ });
23
+ }
24
+ return defaultProviderPromise;
25
+ }
26
+
27
+ export {
28
+ createDefaultErasureCodingProvider
29
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DEFAULT_CHUNKSET_SIZE_BYTES,
3
3
  DEFAULT_CHUNK_SIZE_BYTES
4
- } from "./chunk-APML3CGJ.mjs";
4
+ } from "./chunk-67F5YZ25.mjs";
5
5
  import {
6
6
  DEFAULT_ERASURE_K,
7
7
  DEFAULT_ERASURE_N
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ShelbyClient
3
- } from "./chunk-CQZZRXA6.mjs";
3
+ } from "./chunk-MGAN2SBA.mjs";
4
4
 
5
5
  // src/node/clients/ShelbyNodeClient.ts
6
6
  var ShelbyNodeClient = class extends ShelbyClient {
@@ -1,28 +1,31 @@
1
1
  import {
2
2
  ShelbyRPCClient
3
- } from "./chunk-7P3P3D3X.mjs";
3
+ } from "./chunk-QRGZJBAG.mjs";
4
4
  import {
5
5
  ShelbyBlobClient
6
- } from "./chunk-HDYY6NS4.mjs";
6
+ } from "./chunk-BBOG5JSX.mjs";
7
7
  import {
8
8
  getAptosConfig
9
9
  } from "./chunk-RBFWGDMY.mjs";
10
+ import {
11
+ ClayErasureCodingProvider
12
+ } from "./chunk-NLPIHQ7K.mjs";
10
13
  import {
11
14
  createBlobKey
12
15
  } from "./chunk-OTBLZL2S.mjs";
13
16
  import {
14
17
  generateCommitments
15
- } from "./chunk-PCNLFNAT.mjs";
18
+ } from "./chunk-XWAPNLU6.mjs";
16
19
  import {
17
20
  NetworkToShelbyRPCBaseUrl
18
21
  } from "./chunk-SEXQTDX6.mjs";
19
- import {
20
- ClayErasureCodingProvider
21
- } from "./chunk-APML3CGJ.mjs";
22
22
 
23
23
  // src/core/clients/ShelbyClient.ts
24
24
  import {
25
- Aptos
25
+ AccountAddress,
26
+ Aptos,
27
+ DEFAULT_TXN_TIMEOUT_SEC,
28
+ TransactionResponseType
26
29
  } from "@aptos-labs/ts-sdk";
27
30
  import pLimit from "p-limit";
28
31
  var ShelbyClient = class {
@@ -257,6 +260,79 @@ var ShelbyClient = class {
257
260
  async download(params) {
258
261
  return await this.rpc.getBlob(params);
259
262
  }
263
+ /**
264
+ *
265
+ * Funds an account with ShelbyUSD tokens.
266
+ *
267
+ * @param params.address - The address to fund.
268
+ * @param params.amount - The amount to fund.
269
+ * @returns The transaction hash of the funded account.
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * const hash = await client.fundAccountWithShelbyUSD({
274
+ * address: "0x1",
275
+ * amount: 100000000,
276
+ * });
277
+ * ```
278
+ */
279
+ async fundAccountWithShelbyUSD(params) {
280
+ const { address, amount } = params;
281
+ try {
282
+ const faucet = this.config.faucet ?? "https://faucet.shelbynet.shelby.xyz/fund?asset=shelbyusd";
283
+ const response = await fetch(`${faucet}`, {
284
+ method: "POST",
285
+ body: JSON.stringify({
286
+ address: AccountAddress.from(address).toString(),
287
+ amount
288
+ }),
289
+ headers: {
290
+ "Content-Type": "application/json"
291
+ }
292
+ });
293
+ if (!response.ok) {
294
+ throw new Error("Failed to fund account");
295
+ }
296
+ const json = await response.json();
297
+ const res = await this.aptos.waitForTransaction({
298
+ transactionHash: json.txn_hashes[0],
299
+ options: {
300
+ timeoutSecs: DEFAULT_TXN_TIMEOUT_SEC,
301
+ checkSuccess: true
302
+ }
303
+ });
304
+ if (res.type === TransactionResponseType.User) {
305
+ return res.hash;
306
+ }
307
+ throw new Error(
308
+ `Unexpected transaction received for fund account: ${res.type}`
309
+ );
310
+ } catch (error) {
311
+ throw new Error(`Failed to fund account: ${error}`);
312
+ }
313
+ }
314
+ /**
315
+ * Fund an account with APT tokens
316
+ *
317
+ * @param params.address - The address to fund
318
+ * @param params.amount - The amount to fund
319
+ * @returns The transaction hash of the funded account
320
+ *
321
+ * @example
322
+ * ```typescript
323
+ * const hash = await client.fundAccountWithAPT({
324
+ * address: "0x1",
325
+ * amount: 100000000,
326
+ * });
327
+ * ```
328
+ */
329
+ async fundAccountWithAPT(params) {
330
+ const transaction = await this.aptos.fundAccount({
331
+ accountAddress: params.address,
332
+ amount: params.amount
333
+ });
334
+ return transaction.hash;
335
+ }
260
336
  };
261
337
 
262
338
  export {
@@ -1,3 +1,6 @@
1
+ import {
2
+ DEFAULT_CHUNK_SIZE_BYTES
3
+ } from "./chunk-67F5YZ25.mjs";
1
4
  import {
2
5
  DEFAULT_ERASURE_D,
3
6
  DEFAULT_ERASURE_K,
@@ -9,43 +12,6 @@ import {
9
12
  createDecoder,
10
13
  createEncoder
11
14
  } from "@shelby-protocol/clay-codes";
12
-
13
- // src/core/erasure/default.ts
14
- var defaultProviderPromise;
15
- function createDefaultErasureCodingProvider() {
16
- if (!defaultProviderPromise) {
17
- defaultProviderPromise = ClayErasureCodingProvider.create({
18
- erasure_n: DEFAULT_ERASURE_N,
19
- erasure_k: DEFAULT_ERASURE_K,
20
- erasure_d: DEFAULT_ERASURE_D,
21
- chunkSizeBytes: DEFAULT_CHUNK_SIZE_BYTES
22
- });
23
- }
24
- return defaultProviderPromise;
25
- }
26
-
27
- // src/core/chunk.ts
28
- var ChunkSizeScheme = /* @__PURE__ */ ((ChunkSizeScheme2) => {
29
- ChunkSizeScheme2["ChunkSet10MiB_Chunk1MiB"] = "ChunkSet10MiB_Chunk1MiB";
30
- return ChunkSizeScheme2;
31
- })(ChunkSizeScheme || {});
32
- var CHUNK_SIZE_PARAMS = {
33
- ["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */]: {
34
- // 1MiB
35
- chunkSizeBytes: 1 * 1024 * 1024,
36
- // 10MiB
37
- chunksetSizeBytes: 10 * 1024 * 1024
38
- }
39
- };
40
- var DEFAULT_CHUNK_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */].chunkSizeBytes;
41
- var DEFAULT_CHUNKSET_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */].chunksetSizeBytes;
42
- var ERASURE_CODE_AND_CHUNK_MAPPING = {
43
- ["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */]: {
44
- ...CHUNK_SIZE_PARAMS.ChunkSet10MiB_Chunk1MiB
45
- }
46
- };
47
-
48
- // src/core/erasure/clay-codes.ts
49
15
  function getTotalChunks(config) {
50
16
  return config.erasure_n;
51
17
  }
@@ -53,8 +19,10 @@ var ClayErasureCodingProvider = class _ClayErasureCodingProvider {
53
19
  config;
54
20
  encoderCache;
55
21
  decoderCache;
22
+ lastFunction;
56
23
  constructor(config) {
57
24
  this.config = config;
25
+ this.lastFunction = "none" /* NONE */;
58
26
  }
59
27
  /**
60
28
  * Static factory method to create an initialized ClayErasureCodingProvider
@@ -101,6 +69,7 @@ var ClayErasureCodingProvider = class _ClayErasureCodingProvider {
101
69
  `Data size ${data.length} bytes does not match systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}). Provide pre-padded data before encoding.`
102
70
  );
103
71
  }
72
+ this.lastFunction = "encoded" /* ENCODED */;
104
73
  return this.encoderCache.erasureCode(data);
105
74
  }
106
75
  decode(available, config) {
@@ -121,8 +90,18 @@ var ClayErasureCodingProvider = class _ClayErasureCodingProvider {
121
90
  );
122
91
  }
123
92
  }
93
+ this.lastFunction = "decoded" /* DECODED */;
124
94
  return this.decoderCache.decode(available, config);
125
95
  }
96
+ getChunkMerkleRoots() {
97
+ if (this.decoderCache && this.lastFunction === "decoded" /* DECODED */)
98
+ return this.decoderCache.getChunkMerkleRoots();
99
+ if (this.encoderCache && this.lastFunction === "encoded" /* ENCODED */)
100
+ return this.encoderCache.getChunkMerkleRoots();
101
+ throw new Error(
102
+ "You must call encode or decode before calling getChunkMerkleRoots"
103
+ );
104
+ }
126
105
  /**
127
106
  * Determines if data can be erasure coded as-is or requires padding.
128
107
  *
@@ -166,11 +145,5 @@ function buildClayConfig(input) {
166
145
  }
167
146
 
168
147
  export {
169
- ClayErasureCodingProvider,
170
- createDefaultErasureCodingProvider,
171
- ChunkSizeScheme,
172
- CHUNK_SIZE_PARAMS,
173
- DEFAULT_CHUNK_SIZE_BYTES,
174
- DEFAULT_CHUNKSET_SIZE_BYTES,
175
- ERASURE_CODE_AND_CHUNK_MAPPING
148
+ ClayErasureCodingProvider
176
149
  };
@@ -58,6 +58,11 @@ var ReedSolomonErasureCodingProvider = class {
58
58
  "ReedSolomonErasureCodingProvider does not implement decode"
59
59
  );
60
60
  }
61
+ getChunkMerkleRoots() {
62
+ throw new Error(
63
+ "ReedSolomonErasureCodingProvider does not implement getChunkMerkleRoots"
64
+ );
65
+ }
61
66
  };
62
67
 
63
68
  export {
@@ -12,7 +12,7 @@ import {
12
12
  } from "./chunk-SEXQTDX6.mjs";
13
13
  import {
14
14
  BlobNameSchema
15
- } from "./chunk-FIFKKWXV.mjs";
15
+ } from "./chunk-GY5DCVVL.mjs";
16
16
 
17
17
  // src/core/clients/ShelbyRPCClient.ts
18
18
  import { AccountAddress } from "@aptos-labs/ts-sdk";
File without changes
@@ -5,17 +5,18 @@ import {
5
5
  } from "./chunk-4JZO2D7T.mjs";
6
6
  import {
7
7
  DEFAULT_CHUNKSET_SIZE_BYTES
8
- } from "./chunk-APML3CGJ.mjs";
8
+ } from "./chunk-67F5YZ25.mjs";
9
9
  import {
10
10
  DEFAULT_ERASURE_K,
11
11
  DEFAULT_ERASURE_M
12
12
  } from "./chunk-ZPW742E7.mjs";
13
13
 
14
14
  // src/core/commitments.ts
15
+ import { Hex } from "@aptos-labs/ts-sdk";
15
16
  import { z } from "zod";
16
17
  var ChunksetCommitmentSchema = z.object({
17
18
  // Chunkset root (vector commitment of child chunks)
18
- chunkset_root: z.string().nullable(),
19
+ chunkset_root: z.string(),
19
20
  // the size is known statically from the current configuration
20
21
  chunk_commitments: z.array(z.string())
21
22
  }).refine(
@@ -50,9 +51,34 @@ var BlobCommitmentsSchema = z.object({
50
51
  path: ["chunkset_commitments"]
51
52
  }
52
53
  );
54
+ async function generateMerkleRoot(leafHashes) {
55
+ if (!leafHashes.length) {
56
+ throw new Error(
57
+ "An empty array cannot be used to construct a Merkle tree."
58
+ );
59
+ }
60
+ const zeroArray = new Uint8Array(leafHashes[0].toUint8Array().length);
61
+ const zeroBytes = Hex.fromHexInput(zeroArray);
62
+ let currentLeaves = leafHashes;
63
+ while (currentLeaves.length > 1) {
64
+ if (currentLeaves.length % 2 !== 0) {
65
+ currentLeaves.push(zeroBytes);
66
+ }
67
+ const nextLeaves = [];
68
+ for (let i = 0; i < currentLeaves.length; i += 2) {
69
+ nextLeaves.push(
70
+ await concatHashes([
71
+ currentLeaves[i].toUint8Array(),
72
+ currentLeaves[i + 1].toUint8Array()
73
+ ])
74
+ );
75
+ }
76
+ currentLeaves = nextLeaves;
77
+ }
78
+ return currentLeaves[0];
79
+ }
53
80
  async function generateChunksetCommitments(shouldPad, chunksetIdx, chunksetData, expectedChunksetSize, provider, onChunk) {
54
81
  const { erasure_n } = provider.config;
55
- const chunkCommitments = [];
56
82
  const chunksetPayload = shouldPad ? zeroPadBytes(chunksetData, expectedChunksetSize) : validatePrePaddedChunkset(
57
83
  chunksetData,
58
84
  expectedChunksetSize,
@@ -64,23 +90,24 @@ async function generateChunksetCommitments(shouldPad, chunksetIdx, chunksetData,
64
90
  `Erasure provider produced ${chunks.length} chunks, expected ${erasure_n}.`
65
91
  );
66
92
  }
93
+ const chunkRoots = provider.getChunkMerkleRoots();
67
94
  let chunkIdx = 0;
68
95
  for (const chunkData of chunks) {
69
96
  if (onChunk !== void 0) {
70
97
  await onChunk(chunksetIdx, chunkIdx, chunkData);
71
98
  }
72
- const chunkHash = await concatHashes([chunkData]);
73
- chunkCommitments.push(chunkHash);
74
99
  chunkIdx += 1;
75
100
  }
76
- const h = await concatHashes(
77
- chunkCommitments.map((chunk) => chunk.toUint8Array())
101
+ const a = await generateMerkleRoot(
102
+ chunkRoots.map((a2) => Hex.fromHexInput(a2))
78
103
  );
79
104
  const entry = {
80
- chunkset_root: h.toString(),
81
- chunk_commitments: chunkCommitments.map((chunk) => chunk.toString())
105
+ chunkset_root: a.toString(),
106
+ chunk_commitments: chunkRoots.map(
107
+ (chunk) => Hex.fromHexInput(chunk).toString()
108
+ )
82
109
  };
83
- return { h, entry };
110
+ return { h: a, entry };
84
111
  }
85
112
  async function generateCommitments(provider, fullData, onChunk, options) {
86
113
  const expectedChunksetSize = DEFAULT_CHUNKSET_SIZE_BYTES;
@@ -118,9 +145,7 @@ async function generateCommitments(provider, fullData, onChunk, options) {
118
145
  return {
119
146
  schema_version: "1.3",
120
147
  raw_data_size: rawDataSize,
121
- blob_merkle_root: (await concatHashes(
122
- chunksetCommitmentHashes.map((chunk) => chunk.toUint8Array())
123
- )).toString(),
148
+ blob_merkle_root: (await generateMerkleRoot(chunksetCommitmentHashes)).toString(),
124
149
  chunkset_commitments: chunksetCommitments
125
150
  };
126
151
  }
@@ -137,5 +162,6 @@ export {
137
162
  ChunksetCommitmentSchema,
138
163
  expectedTotalChunksets,
139
164
  BlobCommitmentsSchema,
165
+ generateMerkleRoot,
140
166
  generateCommitments
141
167
  };