@shelby-protocol/sdk 0.0.1-experimental.4 → 0.0.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 (98) hide show
  1. package/README.md +41 -0
  2. package/dist/browser/index.d.ts +17 -8
  3. package/dist/browser/index.mjs +83 -34
  4. package/dist/chunk-3ZDXWPYC.mjs +65 -0
  5. package/dist/chunk-6MDQI7PW.mjs +177 -0
  6. package/dist/chunk-75VHXY5P.mjs +48 -0
  7. package/dist/chunk-APML3CGJ.mjs +176 -0
  8. package/dist/chunk-DLMDDEWF.mjs +112 -0
  9. package/dist/{chunk-C33H3C3N.mjs → chunk-EAPAG4L7.mjs} +1 -1
  10. package/dist/{chunk-GGYTHP5F.mjs → chunk-FIFKKWXV.mjs} +19 -17
  11. package/dist/chunk-HPVCKAN2.mjs +41 -0
  12. package/dist/{chunk-2FF5FICZ.mjs → chunk-JSR44EDC.mjs} +96 -42
  13. package/dist/chunk-KBUWZXFA.mjs +92 -0
  14. package/dist/chunk-LTV26KU4.mjs +141 -0
  15. package/dist/chunk-NTJSNNA7.mjs +175 -0
  16. package/dist/{chunk-QEMIORTL.mjs → chunk-OTBLZL2S.mjs} +1 -1
  17. package/dist/chunk-RBFWGDMY.mjs +30 -0
  18. package/dist/chunk-VRLIOKWG.mjs +11 -0
  19. package/dist/chunk-XGMJ4CG4.mjs +384 -0
  20. package/dist/chunk-Z7RFCADT.mjs +0 -0
  21. package/dist/chunk-ZPW742E7.mjs +28 -0
  22. package/dist/clay-codes-Ce9EmXfa.d.ts +129 -0
  23. package/dist/core/blobs.mjs +1 -1
  24. package/dist/core/chunk.d.ts +34 -0
  25. package/dist/core/chunk.mjs +17 -0
  26. package/dist/core/clients/ShelbyBlobClient.d.ts +121 -89
  27. package/dist/core/clients/ShelbyBlobClient.mjs +11 -3
  28. package/dist/core/clients/ShelbyClient.d.ts +71 -30
  29. package/dist/core/clients/ShelbyClient.mjs +14 -9
  30. package/dist/core/clients/ShelbyClientConfig.d.ts +43 -9
  31. package/dist/core/clients/ShelbyClientConfig.mjs +1 -0
  32. package/dist/core/clients/ShelbyRPCClient.d.ts +47 -20
  33. package/dist/core/clients/ShelbyRPCClient.mjs +10 -3
  34. package/dist/core/clients/index.d.ts +10 -5
  35. package/dist/core/clients/index.mjs +16 -10
  36. package/dist/core/clients/utils.d.ts +7 -0
  37. package/dist/core/clients/utils.mjs +7 -0
  38. package/dist/core/commitments.d.ts +18 -18
  39. package/dist/core/commitments.mjs +7 -5
  40. package/dist/core/constants.d.ts +24 -19
  41. package/dist/core/constants.mjs +15 -15
  42. package/dist/core/erasure/clay-codes.d.ts +2 -0
  43. package/dist/core/erasure/clay-codes.mjs +9 -0
  44. package/dist/core/erasure/constants.d.ts +48 -0
  45. package/dist/core/erasure/constants.mjs +17 -0
  46. package/dist/core/erasure/default.d.ts +6 -0
  47. package/dist/core/erasure/default.mjs +9 -0
  48. package/dist/core/erasure/index.d.ts +4 -0
  49. package/dist/core/erasure/index.mjs +27 -0
  50. package/dist/core/erasure/provider.d.ts +2 -0
  51. package/dist/core/erasure/provider.mjs +0 -0
  52. package/dist/core/erasure/reed-solomon.d.ts +2 -0
  53. package/dist/core/erasure/reed-solomon.mjs +7 -0
  54. package/dist/core/erasure/utils.d.ts +12 -0
  55. package/dist/core/erasure/utils.mjs +33 -0
  56. package/dist/core/index.d.ts +17 -8
  57. package/dist/core/index.mjs +83 -34
  58. package/dist/core/layout.mjs +4 -2
  59. package/dist/core/networks.d.ts +7 -0
  60. package/dist/core/networks.mjs +9 -0
  61. package/dist/core/operations/generated/sdk.d.ts +686 -0
  62. package/dist/core/operations/generated/sdk.mjs +23 -0
  63. package/dist/core/operations/index.d.ts +31 -0
  64. package/dist/core/operations/index.mjs +12 -0
  65. package/dist/core/strings.d.ts +6 -0
  66. package/dist/core/strings.mjs +9 -0
  67. package/dist/core/types/blobs.d.ts +49 -79
  68. package/dist/core/types/encodings.d.ts +5 -13
  69. package/dist/core/types/encodings.mjs +0 -1
  70. package/dist/core/types/index.d.ts +4 -2
  71. package/dist/core/types/index.mjs +1 -1
  72. package/dist/core/types/placement_groups.d.ts +15 -0
  73. package/dist/core/types/placement_groups.mjs +0 -0
  74. package/dist/core/types/storage_providers.d.ts +31 -0
  75. package/dist/core/types/storage_providers.mjs +1 -0
  76. package/dist/core/utils.d.ts +15 -3
  77. package/dist/core/utils.mjs +5 -3
  78. package/dist/node/clients/ShelbyMetadataClient.d.ts +72 -0
  79. package/dist/node/clients/ShelbyMetadataClient.mjs +9 -0
  80. package/dist/node/clients/ShelbyNodeClient.d.ts +8 -3
  81. package/dist/node/clients/ShelbyNodeClient.mjs +15 -10
  82. package/dist/node/clients/index.d.ts +12 -5
  83. package/dist/node/clients/index.mjs +20 -11
  84. package/dist/node/index.d.ts +18 -8
  85. package/dist/node/index.mjs +89 -36
  86. package/package.json +25 -12
  87. package/dist/chunk-5Z3RVWU3.mjs +0 -67
  88. package/dist/chunk-B3CB2YEO.mjs +0 -318
  89. package/dist/chunk-D2FERD4A.mjs +0 -39
  90. package/dist/chunk-G263DBCY.mjs +0 -105
  91. package/dist/chunk-P7BVGLTV.mjs +0 -32
  92. package/dist/chunk-QM5BVKLD.mjs +0 -109
  93. package/dist/core/erasure.d.ts +0 -6
  94. package/dist/core/erasure.mjs +0 -7
  95. /package/dist/{chunk-7S6RVKYB.mjs → chunk-MB7C7VQF.mjs} +0 -0
  96. /package/dist/{chunk-IHTPXUYI.mjs → chunk-MQUVYMNQ.mjs} +0 -0
  97. /package/dist/{chunk-PLUDE5C3.mjs → chunk-RNXGC54D.mjs} +0 -0
  98. /package/dist/{chunk-QKT5R735.mjs → chunk-TUANYVZQ.mjs} +0 -0
package/README.md CHANGED
@@ -29,6 +29,47 @@ import { ShelbyBlob } from '@shelby-protocol/sdk/browser';
29
29
  // Your code here...
30
30
  ```
31
31
 
32
+ ### Working with Erasure Coding Providers
33
+
34
+ The SDK supports two patterns for managing erasure coding providers:
35
+
36
+ #### Default Pattern (Recommended for most users)
37
+
38
+ ```ts
39
+ import { ShelbyClient } from '@shelby-protocol/sdk';
40
+
41
+ // Provider is created internally on first use
42
+ const client = new ShelbyClient(config);
43
+
44
+ // The client will automatically create and manage the provider
45
+ await client.upload({
46
+ blobData: data,
47
+ signer: account,
48
+ blobName: "example.txt",
49
+ expirationMicros: Date.now() * 1000 + 3600_000_000,
50
+ });
51
+ ```
52
+
53
+ #### Shared Provider Pattern (For advanced use cases)
54
+
55
+ When working with multiple clients (e.g., different networks), you can share a single provider instance:
56
+
57
+ ```ts
58
+ import { ShelbyClient, ClayErasureCodingProvider } from '@shelby-protocol/sdk';
59
+
60
+ // Create a single provider instance
61
+ const provider = await ClayErasureCodingProvider.create();
62
+
63
+ // Share it across multiple clients
64
+ const mainnetClient = new ShelbyClient(mainnetConfig, provider);
65
+ const devnetClient = new ShelbyClient(devnetConfig, provider);
66
+ const testnetClient = new ShelbyClient(testnetConfig, provider);
67
+
68
+ // All clients use the same provider instance
69
+ await mainnetClient.upload({ /* ... */ });
70
+ await devnetClient.upload({ /* ... */ });
71
+ ```
72
+
32
73
  ## Peer Dependencies
33
74
 
34
75
  - `@aptos-labs/ts-sdk`
@@ -1,14 +1,23 @@
1
1
  export { ShelbyBlob, createBlobKey } from '../core/blobs.js';
2
+ export { CHUNK_SIZE_PARAMS, ChunkSizeScheme, DEFAULT_CHUNKSET_SIZE_BYTES, DEFAULT_CHUNK_SIZE_BYTES, ERASURE_CODE_AND_CHUNK_MAPPING } from '../core/chunk.js';
2
3
  export { ShelbyBlobClient } from '../core/clients/ShelbyBlobClient.js';
3
- export { ShelbyClient } from '../core/clients/ShelbyClient.js';
4
- export { ShelbyClientConfig } from '../core/clients/ShelbyClientConfig.js';
4
+ export { ShelbyClient, UploadOptions } from '../core/clients/ShelbyClient.js';
5
+ export { ShelbyClientConfig, ShelbyIndexerConfig, ShelbyRPCConfig } from '../core/clients/ShelbyClientConfig.js';
5
6
  export { ShelbyRPCClient } from '../core/clients/ShelbyRPCClient.js';
6
- export { BlobCommitments, BlobCommitmentsSchema, ChunksetCommitment, ChunksetCommitmentSchema, generateCommitments } from '../core/commitments.js';
7
- export { CHUNKSET_SIZE_BYTES, DEFAULT_PROJECT_DESCRIPTION, DEFAULT_PROJECT_NAME, DEFAULT_SHELBY_BASE_URL, ERASURE_K, ERASURE_M, SHELBY_DEPLOYER, TOKEN_DEPLOYER, TOKEN_OBJECT_ADDRESS, getChunkSizeBytes, getChunksetSizeBytes } from '../core/constants.js';
8
- export { erasureEncode } from '../core/erasure.js';
7
+ export { BlobCommitments, BlobCommitmentsSchema, ChunksetCommitment, ChunksetCommitmentSchema, GenerateCommitmentsOptions, expectedTotalChunksets, generateCommitments } from '../core/commitments.js';
8
+ export { DEFAULT_PROJECT_DESCRIPTION, DEFAULT_PROJECT_NAME, NetworkToShelbyBlobIndexerBaseUrl, NetworkToShelbyRPCBaseUrl, SHELBYUSD_TOKEN_ADDRESS, SHELBYUSD_TOKEN_MODULE, SHELBYUSD_TOKEN_NAME, SHELBYUSD_TOKEN_TYPE, SHELBY_DEPLOYER, TOKEN_DEPLOYER, TOKEN_OBJECT_ADDRESS } from '../core/constants.js';
9
+ export { C as ClayErasureCodingProvider, D as DecodeConfig, E as ErasureCodingConfig, a as ErasureCodingProvider, R as ReedSolomonErasureCodingProvider } from '../clay-codes-Ce9EmXfa.js';
10
+ export { DEFAULT_ERASURE_D, DEFAULT_ERASURE_K, DEFAULT_ERASURE_M, DEFAULT_ERASURE_N, ERASURE_CODE_PARAMS, ErasureCodeParams, ErasureCodingScheme, ErasureSchemeParams } from '../core/erasure/constants.js';
11
+ export { createDefaultErasureCodingProvider } from '../core/erasure/default.js';
9
12
  export { BlobName, BlobNameSchema, ChunkKey, allChunksForBlob, roundSize } from '../core/layout.js';
10
- export { BlobChunk, BlobEncoding, BlobMetadata, ChunkLocation, ClayEncoding, PendingChunkLocation, SignedChunkCommitment, StoredChunkLocation } from '../core/types/blobs.js';
11
- export { EncodingOptions } from '../core/types/encodings.js';
12
- export { concatHashes, readInChunks, zeroPadBuffer } from '../core/utils.js';
13
+ export { ShelbyNetwork, isShelbyNetwork, shelbyNetworks } from '../core/networks.js';
14
+ export { ShelbyIndexerClient, createShelbyIndexerClient, getShelbyIndexerClient } from '../core/operations/index.js';
15
+ export { BlobActivity, BlobActivityType, BlobEncoding, BlobMetadata, ClayEncoding } from '../core/types/blobs.js';
16
+ export { StorageProviderInfo } from '../core/types/storage_providers.js';
17
+ export { buildRequestUrl, concatHashes, readInChunks, zeroPadBytes } from '../core/utils.js';
13
18
  import '@aptos-labs/ts-sdk';
14
19
  import 'zod';
20
+ import '../core/operations/generated/sdk.js';
21
+ import 'graphql';
22
+ import 'graphql-request';
23
+ import '@shelby-protocol/clay-codes';
@@ -1,65 +1,110 @@
1
- import "../chunk-PLUDE5C3.mjs";
1
+ import "../chunk-TUANYVZQ.mjs";
2
+ import "../chunk-RNXGC54D.mjs";
2
3
  import "../chunk-MWDW4ROU.mjs";
3
4
  import "../chunk-ZHXCVRZX.mjs";
4
- import "../chunk-IHTPXUYI.mjs";
5
- import "../chunk-QKT5R735.mjs";
5
+ import "../chunk-MQUVYMNQ.mjs";
6
6
  import {
7
7
  ShelbyClient
8
- } from "../chunk-QM5BVKLD.mjs";
8
+ } from "../chunk-6MDQI7PW.mjs";
9
9
  import {
10
10
  ShelbyBlobClient
11
- } from "../chunk-B3CB2YEO.mjs";
11
+ } from "../chunk-XGMJ4CG4.mjs";
12
+ import "../chunk-Z7RFCADT.mjs";
12
13
  import {
13
14
  ShelbyRPCClient
14
- } from "../chunk-2FF5FICZ.mjs";
15
+ } from "../chunk-JSR44EDC.mjs";
16
+ import {
17
+ createShelbyIndexerClient,
18
+ getShelbyIndexerClient
19
+ } from "../chunk-75VHXY5P.mjs";
20
+ import "../chunk-DLMDDEWF.mjs";
21
+ import "../chunk-RBFWGDMY.mjs";
22
+ import "../chunk-I6NG5GNL.mjs";
15
23
  import {
16
24
  createBlobKey
17
- } from "../chunk-QEMIORTL.mjs";
25
+ } from "../chunk-OTBLZL2S.mjs";
18
26
  import {
19
27
  BlobCommitmentsSchema,
20
28
  ChunksetCommitmentSchema,
29
+ expectedTotalChunksets,
21
30
  generateCommitments
22
- } from "../chunk-G263DBCY.mjs";
31
+ } from "../chunk-LTV26KU4.mjs";
23
32
  import {
33
+ buildRequestUrl,
24
34
  concatHashes,
25
35
  readInChunks,
26
- zeroPadBuffer
27
- } from "../chunk-5Z3RVWU3.mjs";
36
+ zeroPadBytes
37
+ } from "../chunk-KBUWZXFA.mjs";
28
38
  import {
29
- erasureEncode
30
- } from "../chunk-P7BVGLTV.mjs";
39
+ DEFAULT_PROJECT_DESCRIPTION,
40
+ DEFAULT_PROJECT_NAME,
41
+ NetworkToShelbyBlobIndexerBaseUrl,
42
+ NetworkToShelbyRPCBaseUrl,
43
+ SHELBYUSD_TOKEN_ADDRESS,
44
+ SHELBYUSD_TOKEN_MODULE,
45
+ SHELBYUSD_TOKEN_NAME,
46
+ SHELBYUSD_TOKEN_TYPE,
47
+ SHELBY_DEPLOYER,
48
+ TOKEN_DEPLOYER,
49
+ TOKEN_OBJECT_ADDRESS
50
+ } from "../chunk-HPVCKAN2.mjs";
31
51
  import {
32
52
  BlobNameSchema,
33
53
  ChunkKey,
34
54
  allChunksForBlob,
35
55
  roundSize
36
- } from "../chunk-GGYTHP5F.mjs";
56
+ } from "../chunk-FIFKKWXV.mjs";
37
57
  import {
38
- CHUNKSET_SIZE_BYTES,
39
- DEFAULT_PROJECT_DESCRIPTION,
40
- DEFAULT_PROJECT_NAME,
41
- DEFAULT_SHELBY_BASE_URL,
42
- ERASURE_K,
43
- ERASURE_M,
44
- SHELBY_DEPLOYER,
45
- TOKEN_DEPLOYER,
46
- TOKEN_OBJECT_ADDRESS,
47
- getChunkSizeBytes,
48
- getChunksetSizeBytes
49
- } from "../chunk-D2FERD4A.mjs";
50
- import "../chunk-I6NG5GNL.mjs";
58
+ CHUNK_SIZE_PARAMS,
59
+ ChunkSizeScheme,
60
+ ClayErasureCodingProvider,
61
+ DEFAULT_CHUNKSET_SIZE_BYTES,
62
+ DEFAULT_CHUNK_SIZE_BYTES,
63
+ ERASURE_CODE_AND_CHUNK_MAPPING,
64
+ createDefaultErasureCodingProvider
65
+ } from "../chunk-APML3CGJ.mjs";
66
+ import {
67
+ ReedSolomonErasureCodingProvider
68
+ } from "../chunk-3ZDXWPYC.mjs";
69
+ import {
70
+ DEFAULT_ERASURE_D,
71
+ DEFAULT_ERASURE_K,
72
+ DEFAULT_ERASURE_M,
73
+ DEFAULT_ERASURE_N,
74
+ ERASURE_CODE_PARAMS,
75
+ ErasureCodingScheme
76
+ } from "../chunk-ZPW742E7.mjs";
77
+ import {
78
+ isShelbyNetwork,
79
+ shelbyNetworks
80
+ } from "../chunk-VRLIOKWG.mjs";
51
81
  import "../chunk-7P6ASYW6.mjs";
52
82
  export {
53
83
  BlobCommitmentsSchema,
54
84
  BlobNameSchema,
55
- CHUNKSET_SIZE_BYTES,
85
+ CHUNK_SIZE_PARAMS,
56
86
  ChunkKey,
87
+ ChunkSizeScheme,
57
88
  ChunksetCommitmentSchema,
89
+ ClayErasureCodingProvider,
90
+ DEFAULT_CHUNKSET_SIZE_BYTES,
91
+ DEFAULT_CHUNK_SIZE_BYTES,
92
+ DEFAULT_ERASURE_D,
93
+ DEFAULT_ERASURE_K,
94
+ DEFAULT_ERASURE_M,
95
+ DEFAULT_ERASURE_N,
58
96
  DEFAULT_PROJECT_DESCRIPTION,
59
97
  DEFAULT_PROJECT_NAME,
60
- DEFAULT_SHELBY_BASE_URL,
61
- ERASURE_K,
62
- ERASURE_M,
98
+ ERASURE_CODE_AND_CHUNK_MAPPING,
99
+ ERASURE_CODE_PARAMS,
100
+ ErasureCodingScheme,
101
+ NetworkToShelbyBlobIndexerBaseUrl,
102
+ NetworkToShelbyRPCBaseUrl,
103
+ ReedSolomonErasureCodingProvider,
104
+ SHELBYUSD_TOKEN_ADDRESS,
105
+ SHELBYUSD_TOKEN_MODULE,
106
+ SHELBYUSD_TOKEN_NAME,
107
+ SHELBYUSD_TOKEN_TYPE,
63
108
  SHELBY_DEPLOYER,
64
109
  ShelbyBlobClient,
65
110
  ShelbyClient,
@@ -67,13 +112,17 @@ export {
67
112
  TOKEN_DEPLOYER,
68
113
  TOKEN_OBJECT_ADDRESS,
69
114
  allChunksForBlob,
115
+ buildRequestUrl,
70
116
  concatHashes,
71
117
  createBlobKey,
72
- erasureEncode,
118
+ createDefaultErasureCodingProvider,
119
+ createShelbyIndexerClient,
120
+ expectedTotalChunksets,
73
121
  generateCommitments,
74
- getChunkSizeBytes,
75
- getChunksetSizeBytes,
122
+ getShelbyIndexerClient,
123
+ isShelbyNetwork,
76
124
  readInChunks,
77
125
  roundSize,
78
- zeroPadBuffer
126
+ shelbyNetworks,
127
+ zeroPadBytes
79
128
  };
@@ -0,0 +1,65 @@
1
+ // src/core/erasure/reed-solomon.ts
2
+ import { createWasmReedSolomonBinding } from "@shelby-protocol/reed-solomon";
3
+ var DEFAULT_ERASURE_K = 10;
4
+ var DEFAULT_ERASURE_N = 16;
5
+ var DEFAULT_CHUNK_SIZE_BYTES = 2 * 1024 * 1024;
6
+ var ReedSolomonErasureCodingProvider = class {
7
+ config;
8
+ constructor(options) {
9
+ const erasure_k = options?.erasure_k ?? DEFAULT_ERASURE_K;
10
+ const erasure_n = options?.erasure_n ?? DEFAULT_ERASURE_N;
11
+ const chunkSizeBytes = options?.chunkSizeBytes ?? DEFAULT_CHUNK_SIZE_BYTES;
12
+ if (erasure_k <= 0)
13
+ throw new Error("erasure_k (number of data chunks) must be > 0");
14
+ if (erasure_n <= erasure_k)
15
+ throw new Error(
16
+ `erasure_n (${erasure_n}) must be > erasure_k (${erasure_k})`
17
+ );
18
+ if (chunkSizeBytes <= 0) throw new Error("chunkSizeBytes must be > 0");
19
+ this.config = {
20
+ erasure_n,
21
+ erasure_k,
22
+ chunkSizeBytes
23
+ };
24
+ }
25
+ encode(data) {
26
+ const { erasure_k, erasure_n, chunkSizeBytes } = this.config;
27
+ const erasure_m = erasure_n - erasure_k;
28
+ const systematicCapacity = erasure_k * chunkSizeBytes;
29
+ if (data.byteLength > systematicCapacity) {
30
+ throw new Error(
31
+ `Data size ${data.byteLength} bytes exceeds systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}).`
32
+ );
33
+ }
34
+ if (data.byteLength !== systematicCapacity) {
35
+ throw new Error(
36
+ `Data size ${data.byteLength} bytes does not match systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}). Provide pre-padded data before encoding.`
37
+ );
38
+ }
39
+ const reedSolomon = createWasmReedSolomonBinding();
40
+ const shards = new Uint8Array(
41
+ systematicCapacity + erasure_m * chunkSizeBytes
42
+ );
43
+ shards.set(data, 0);
44
+ reedSolomon.encode(shards, erasure_k, erasure_m);
45
+ const chunks = new Array(erasure_n);
46
+ for (let idx = 0; idx < erasure_n; idx++) {
47
+ const start = idx * chunkSizeBytes;
48
+ chunks[idx] = shards.slice(start, start + chunkSizeBytes);
49
+ }
50
+ return {
51
+ chunks,
52
+ systematic: chunks.slice(0, erasure_k),
53
+ parity: chunks.slice(erasure_k)
54
+ };
55
+ }
56
+ decode(_available, _config) {
57
+ throw new Error(
58
+ "ReedSolomonErasureCodingProvider does not implement decode"
59
+ );
60
+ }
61
+ };
62
+
63
+ export {
64
+ ReedSolomonErasureCodingProvider
65
+ };
@@ -0,0 +1,177 @@
1
+ import {
2
+ ShelbyBlobClient
3
+ } from "./chunk-XGMJ4CG4.mjs";
4
+ import {
5
+ ShelbyRPCClient
6
+ } from "./chunk-JSR44EDC.mjs";
7
+ import {
8
+ getAptosConfig
9
+ } from "./chunk-RBFWGDMY.mjs";
10
+ import {
11
+ generateCommitments
12
+ } from "./chunk-LTV26KU4.mjs";
13
+ import {
14
+ NetworkToShelbyRPCBaseUrl
15
+ } from "./chunk-HPVCKAN2.mjs";
16
+ import {
17
+ ClayErasureCodingProvider
18
+ } from "./chunk-APML3CGJ.mjs";
19
+
20
+ // src/core/clients/ShelbyClient.ts
21
+ import {
22
+ Aptos
23
+ } from "@aptos-labs/ts-sdk";
24
+ var ShelbyClient = class {
25
+ /**
26
+ * The coordination client is used to interact with the Aptos blockchain which handles the commitments
27
+ * and metadata for blobs.
28
+ */
29
+ coordination;
30
+ /**
31
+ * The RPC client is used to interact with the Shelby RPC node which can be responsible for storing,
32
+ * confirming, and retrieving blobs from the storage layer.
33
+ *
34
+ * If not provided, the default RPC client will be created.
35
+ */
36
+ rpc;
37
+ /**
38
+ * The configuration for the Shelby client.
39
+ */
40
+ config;
41
+ /**
42
+ * The Aptos client.
43
+ *
44
+ * If not provided, a default Aptos client will be created.
45
+ */
46
+ aptos;
47
+ /**
48
+ * The erasure coding provider used for encoding/decoding operations.
49
+ * Lazily initialized on first use if not provided.
50
+ */
51
+ _provider;
52
+ /**
53
+ * Creates a new ShelbyClient instance for interacting with the Shelby Protocol.
54
+ * This client combines blockchain operations (via coordination) and storage operations (via RPC).
55
+ *
56
+ * @param config - The client configuration object.
57
+ * @param config.aptos.config - The Aptos network configuration.
58
+ * @param config.shelby.rpc.baseUrl - The base URL of the Shelby RPC node (optional, defaults to devnet).
59
+ * @param config.shelby.indexer - The indexer configuration for GraphQL queries.
60
+ * @param provider - Optional erasure coding provider for encoding/decoding operations.
61
+ * If not provided, a ClayErasureCodingProvider will be created on first use.
62
+ * Pass a shared provider to reuse across multiple clients.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * // Basic usage (provider created automatically)
67
+ * const client = new ShelbyClient({
68
+ * network: Network.SHELBYNET,
69
+ * });
70
+ *
71
+ * // Advanced: Share provider across multiple clients
72
+ * const provider = await ClayErasureCodingProvider.create();
73
+ * const mainnetClient = new ShelbyClient(mainnetConfig, provider);
74
+ * const devnetClient = new ShelbyClient(devnetConfig, provider);
75
+ * ```
76
+ */
77
+ constructor(config, provider) {
78
+ this.config = config;
79
+ this.aptos = new Aptos(getAptosConfig(config));
80
+ this.coordination = new ShelbyBlobClient(config);
81
+ this.rpc = new ShelbyRPCClient(config);
82
+ this._provider = provider;
83
+ }
84
+ /**
85
+ * Get the erasure coding provider, creating it if necessary.
86
+ * This allows lazy initialization for users who don't provide a provider.
87
+ */
88
+ async getProvider() {
89
+ if (!this._provider) {
90
+ this._provider = await ClayErasureCodingProvider.create();
91
+ }
92
+ return this._provider;
93
+ }
94
+ /**
95
+ * The base URL for the Shelby RPC node.
96
+ */
97
+ get baseUrl() {
98
+ return this.config.rpc?.baseUrl ?? NetworkToShelbyRPCBaseUrl.shelbynet;
99
+ }
100
+ /**
101
+ * Uploads a blob to the Shelby network.
102
+ * This method handles the complete upload flow including commitment generation,
103
+ * blockchain registration, and storage upload.
104
+ *
105
+ * @param params.blobData - The raw data to upload as a Uint8Array.
106
+ * @param params.signer - The account that signs and pays for the transaction.
107
+ * @param params.blobName - The name/path of the blob (e.g. "folder/file.txt").
108
+ * @param params.expirationMicros - The expiration time in microseconds since Unix epoch.
109
+ * @param params.options - Optional upload configuration.
110
+ * @param params.options.chunksetSizeBytes - Custom chunkset size.
111
+ * @param params.options.build - Additional Aptos transaction options.
112
+ *
113
+ * @returns The transaction and generated blob commitments (when implemented).
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * await client.upload({
118
+ * blobData: Buffer.from("Hello, World!"),
119
+ * signer: account,
120
+ * blobName: "hello.txt",
121
+ * expirationMicros: Date.now() * 1000 + 86400_000_000 // 24 hours from now
122
+ * });
123
+ * ```
124
+ */
125
+ async upload(params) {
126
+ const existingBlobMetadata = await this.coordination.getBlobMetadata({
127
+ account: params.signer.accountAddress,
128
+ name: params.blobName
129
+ });
130
+ if (!existingBlobMetadata) {
131
+ const provider = await this.getProvider();
132
+ const blobCommitments = await generateCommitments(
133
+ provider,
134
+ params.blobData
135
+ );
136
+ const { transaction: pendingRegisterBlobTransaction } = await this.coordination.registerBlob({
137
+ account: params.signer,
138
+ blobName: params.blobName,
139
+ blobMerkleRoot: blobCommitments.blob_merkle_root,
140
+ size: params.blobData.length,
141
+ expirationMicros: params.expirationMicros
142
+ });
143
+ await this.coordination.aptos.waitForTransaction({
144
+ transactionHash: pendingRegisterBlobTransaction.hash
145
+ });
146
+ }
147
+ await this.rpc.putBlob({
148
+ account: params.signer.accountAddress,
149
+ blobName: params.blobName,
150
+ blobData: params.blobData
151
+ });
152
+ }
153
+ /**
154
+ * Downloads a blob from the Shelby RPC node.
155
+ *
156
+ * @param params.account - The account namespace the blob is stored in (e.g. "0x1")
157
+ * @param params.blobName - The name of the blob (e.g. "foo/bar")
158
+ * @param params.range - The range of the blob to download.
159
+ *
160
+ * @returns A `ShelbyBlob` object containing the blob data.
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * const blob = await client.download({
165
+ * account,
166
+ * blobName: "foo/bar.txt",
167
+ * });
168
+ * ```
169
+ */
170
+ async download(params) {
171
+ return await this.rpc.getBlob(params);
172
+ }
173
+ };
174
+
175
+ export {
176
+ ShelbyClient
177
+ };
@@ -0,0 +1,48 @@
1
+ import {
2
+ getSdk
3
+ } from "./chunk-DLMDDEWF.mjs";
4
+ import {
5
+ getAptosConfig
6
+ } from "./chunk-RBFWGDMY.mjs";
7
+ import {
8
+ NetworkToShelbyBlobIndexerBaseUrl
9
+ } from "./chunk-HPVCKAN2.mjs";
10
+
11
+ // src/core/operations/index.ts
12
+ import { Network } from "@aptos-labs/ts-sdk";
13
+ import { GraphQLClient } from "graphql-request";
14
+ function createShelbyIndexerClient(baseUrl, options) {
15
+ const graphqlClient = new GraphQLClient(baseUrl, options);
16
+ return getSdk(graphqlClient);
17
+ }
18
+ function getShelbyIndexerClient(config) {
19
+ const aptosConfig = config.aptos ?? getAptosConfig(config);
20
+ let { apiKey, baseUrl } = config.indexer ?? {};
21
+ if (!baseUrl) {
22
+ switch (aptosConfig?.network) {
23
+ // TODO: Add endpoints for core networks
24
+ case Network.MAINNET:
25
+ case Network.TESTNET:
26
+ case Network.DEVNET:
27
+ case Network.SHELBYNET:
28
+ baseUrl = NetworkToShelbyBlobIndexerBaseUrl[aptosConfig.network];
29
+ break;
30
+ }
31
+ }
32
+ if (baseUrl === void 0) {
33
+ throw new Error(
34
+ "The ShelbyClientConfig does not support the Shelby indexer. Please configure the endpoint in the ShelbyClientConfig.indexer.endpoint or provide a supported Aptos network."
35
+ );
36
+ }
37
+ return createShelbyIndexerClient(baseUrl, {
38
+ headers: {
39
+ ...apiKey ? { Authorization: `Bearer ${apiKey}` } : {},
40
+ "x-aptos-client": "shelby-ts-sdk"
41
+ }
42
+ });
43
+ }
44
+
45
+ export {
46
+ createShelbyIndexerClient,
47
+ getShelbyIndexerClient
48
+ };