@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
@@ -0,0 +1,384 @@
1
+ import {
2
+ getShelbyIndexerClient
3
+ } from "./chunk-75VHXY5P.mjs";
4
+ import {
5
+ getAptosConfig
6
+ } from "./chunk-RBFWGDMY.mjs";
7
+ import {
8
+ createBlobKey
9
+ } from "./chunk-OTBLZL2S.mjs";
10
+ import {
11
+ expectedTotalChunksets
12
+ } from "./chunk-LTV26KU4.mjs";
13
+ import {
14
+ SHELBY_DEPLOYER
15
+ } from "./chunk-HPVCKAN2.mjs";
16
+ import {
17
+ DEFAULT_CHUNKSET_SIZE_BYTES,
18
+ ERASURE_CODE_AND_CHUNK_MAPPING
19
+ } from "./chunk-APML3CGJ.mjs";
20
+ import {
21
+ ERASURE_CODE_PARAMS
22
+ } from "./chunk-ZPW742E7.mjs";
23
+
24
+ // src/core/clients/ShelbyBlobClient.ts
25
+ import {
26
+ AccountAddress,
27
+ Aptos,
28
+ AptosConfig,
29
+ Hex,
30
+ MoveVector
31
+ } from "@aptos-labs/ts-sdk";
32
+ var ShelbyBlobClient = class _ShelbyBlobClient {
33
+ aptos;
34
+ deployer;
35
+ indexer;
36
+ /**
37
+ * The ShelbyBlobClient is used to interact with the Shelby contract on the Aptos blockchain. This
38
+ * includes functions for registering blob commitments and retrieving blob metadata.
39
+ *
40
+ * @param config - The client configuration object.
41
+ * @param config.network - The Shelby network to use.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const blobClient = new ShelbyBlobClient({
46
+ * aptos: {
47
+ * network: Network.SHELBYNET,
48
+ * clientConfig: {
49
+ * API_KEY: "AG-***",
50
+ * },
51
+ * },
52
+ * });
53
+ * ```
54
+ */
55
+ constructor(config) {
56
+ const baseAptosConfig = getAptosConfig(config);
57
+ const aptosConfig = new AptosConfig({
58
+ ...baseAptosConfig,
59
+ clientConfig: {
60
+ ...baseAptosConfig.clientConfig,
61
+ // Only use top-level apiKey if no API_KEY is already provided in Aptos settings
62
+ API_KEY: baseAptosConfig.clientConfig?.API_KEY ?? config.apiKey
63
+ }
64
+ });
65
+ this.aptos = new Aptos(aptosConfig);
66
+ this.deployer = config.deployer ?? AccountAddress.fromString(SHELBY_DEPLOYER);
67
+ this.indexer = getShelbyIndexerClient(config);
68
+ }
69
+ /**
70
+ * Retrieves the blob metadata from the blockchain. If it does not exist,
71
+ * returns `undefined`.
72
+ *
73
+ * @param params.account - The account namespace the blob is stored in (e.g. "0x1")
74
+ * @param params.name - The name of the blob (e.g. "foo/bar")
75
+ * @returns The blob metadata.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const metadata = await client.getBlobMetadata({
80
+ * account: AccountAddress.fromString("0x1"),
81
+ * name: "foo/bar.txt",
82
+ * });
83
+ * ```
84
+ */
85
+ async getBlobMetadata(params) {
86
+ try {
87
+ const rawMetadata = await this.aptos.view({
88
+ payload: {
89
+ function: `${this.deployer.toString()}::global_metadata::get_blob_metadata`,
90
+ functionArguments: [
91
+ createBlobKey({
92
+ account: params.account,
93
+ blobName: params.name
94
+ })
95
+ ]
96
+ }
97
+ });
98
+ if (!rawMetadata?.[0]?.vec?.[0]) {
99
+ return void 0;
100
+ }
101
+ const metadata = rawMetadata[0].vec[0];
102
+ let encoding;
103
+ if (metadata.encoding.__variant__ === "ClayCode_16Total_10Data_13Helper") {
104
+ encoding = {
105
+ variant: "clay",
106
+ ...ERASURE_CODE_PARAMS[metadata.encoding.__variant__],
107
+ ...ERASURE_CODE_AND_CHUNK_MAPPING[metadata.encoding.__variant__]
108
+ };
109
+ } else {
110
+ throw new Error(
111
+ "Could not parse encoding from Shelby Smart Contract, this SDK is out of date."
112
+ );
113
+ }
114
+ return {
115
+ blobMerkleRoot: Hex.fromHexInput(
116
+ metadata.blob_commitment
117
+ ).toUint8Array(),
118
+ owner: AccountAddress.fromString(metadata.owner),
119
+ name: params.name,
120
+ size: Number(metadata.blob_size),
121
+ encoding,
122
+ expirationMicros: metadata.expiration_micros,
123
+ sliceAddress: AccountAddress.fromString(metadata.slice.inner),
124
+ isWritten: metadata.is_written
125
+ };
126
+ } catch (error) {
127
+ if (error instanceof Error && // Depending on the network, the error message may show up differently.
128
+ (error.message?.includes("sub_status: Some(404)") || error.message?.includes("EBLOB_NOT_FOUND"))) {
129
+ return void 0;
130
+ }
131
+ throw error;
132
+ }
133
+ }
134
+ /**
135
+ * Retrieves all the blobs and their metadata for an account from the
136
+ * blockchain.
137
+ *
138
+ * @param params.account - The account namespace the blobs are stored in (e.g. "0x1")
139
+ * @param params.pagination (optional) - The pagination options.
140
+ * @param params.orderBy (optional) - The order by clause to sort the blobs by.
141
+ * @returns The blob metadata for all the blobs for the account.
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * // BlobMetadata[]
146
+ * const blobs = await client.getAccountBlobs({
147
+ * account: AccountAddress.fromString("0x1"),
148
+ * });
149
+ * ```
150
+ */
151
+ getAccountBlobs(params) {
152
+ return this.getBlobs({
153
+ where: { owner: { _eq: AccountAddress.from(params.account).toString() } },
154
+ pagination: params.pagination,
155
+ orderBy: params.orderBy
156
+ });
157
+ }
158
+ /**
159
+ * Retrieves blobs and their metadata from the blockchain.
160
+ *
161
+ * @param params.where (optional) - The where clause to filter the blobs by.
162
+ * @param params.pagination (optional) - The pagination options.
163
+ * @param params.orderBy (optional) - The order by clause to sort the blobs by.
164
+ * @returns The blob metadata for all the blobs that match the where clause.
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * // BlobMetadata[]
169
+ * const blobs = await client.getBlobs({
170
+ * where: { owner: { _eq: AccountAddress.fromString("0x1").toString() } },
171
+ * });
172
+ * ```
173
+ */
174
+ async getBlobs(params = {}) {
175
+ const { limit, offset } = params.pagination ?? {};
176
+ const { orderBy, where } = params;
177
+ const { blobs } = await this.indexer.getBlobs({
178
+ where,
179
+ limit,
180
+ offset,
181
+ orderBy
182
+ });
183
+ return blobs.map(
184
+ (blob) => ({
185
+ owner: AccountAddress.from(blob.owner),
186
+ name: blob.blob_name,
187
+ blobMerkleRoot: Hex.fromHexInput(blob.blob_commitment).toUint8Array(),
188
+ size: blob.size,
189
+ // TODO: Add encoding when supported in NCI
190
+ encoding: {
191
+ variant: "clay",
192
+ ...ERASURE_CODE_PARAMS.ClayCode_16Total_10Data_13Helper,
193
+ ...ERASURE_CODE_AND_CHUNK_MAPPING.ClayCode_16Total_10Data_13Helper
194
+ },
195
+ expirationMicros: blob.expires_at,
196
+ sliceAddress: AccountAddress.from(blob.slice_address),
197
+ isWritten: blob.is_written
198
+ })
199
+ );
200
+ }
201
+ async getBlobActivities(params) {
202
+ const { limit, offset } = params.pagination ?? {};
203
+ const { orderBy, where } = params;
204
+ const { blob_activities } = await this.indexer.getBlobActivities({
205
+ where,
206
+ limit,
207
+ offset,
208
+ orderBy
209
+ });
210
+ const activityTypeMapping = {
211
+ [`${this.deployer.toStringLong()}::global_metadata::BlobRegisteredEvent`]: "register_blob",
212
+ [`${this.deployer.toStringLong()}::global_metadata::BlobDeletedEvent`]: "delete_blob",
213
+ [`${this.deployer.toStringLong()}::global_metadata::BlobExpirationExtendedEvent`]: "extend_blob_expiration",
214
+ [`${this.deployer.toStringLong()}::global_metadata::BlobWrittenEvent`]: "write_blob"
215
+ };
216
+ return blob_activities.map(
217
+ (activity) => ({
218
+ blobName: activity.blob_name,
219
+ accountAddress: AccountAddress.from(
220
+ activity.blob_name.substring(1, 65)
221
+ ),
222
+ type: activityTypeMapping[activity.event_type] ?? "unknown",
223
+ eventType: activity.event_type,
224
+ eventIndex: activity.event_index,
225
+ transactionHash: activity.transaction_hash,
226
+ transactionVersion: activity.transaction_version,
227
+ timestamp: activity.timestamp
228
+ })
229
+ );
230
+ }
231
+ /**
232
+ * Retrieves the blob chunks for a given blob from the blockchain. The blob chunk will contain
233
+ * the commitment, the storage provider location, and the status of the chunk (stored or pending).
234
+ *
235
+ * @deprecated Will need to get reworked when we are acking blobs from storage providers.
236
+ *
237
+ * @param params.account - The account namespace the blob is stored in (e.g. "0x1")
238
+ * @param params.name - The name of the blob (e.g. "foo/bar")
239
+ * @returns The chunks that make up the blob.
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * // BlobChunk[]
244
+ * const chunks = await client.getBlobChunks({
245
+ * account: AccountAddress.fromString("0x1"),
246
+ * name: "foo/bar.txt",
247
+ * });
248
+ *
249
+ * const isStored = chunks.every((c) => c.location.variant === "stored");
250
+ * ```
251
+ */
252
+ getBlobChunks(_params) {
253
+ throw new Error("Not implemented");
254
+ }
255
+ /**
256
+ * Registers a blob on the blockchain by writing its merkle root and metadata.
257
+ *
258
+ * @param params.account - The account that is signing and paying for the transaction.
259
+ * @param params.blobName - The name/path of the blob (e.g. "foo/bar.txt").
260
+ * @param params.blobMerkleRoot - The merkle root of the blob commitments.
261
+ * @param params.size - The size of the blob in bytes.
262
+ * @param params.expirationMicros - The expiration time of the blob in microseconds.
263
+ * @param params.options - Optional transaction building options.
264
+ * @param params.options.chunksetSizeBytes - Custom chunkset size (defaults to DEFAULT_CHUNKSET_SIZE_BYTES).
265
+ * @param params.options.build - Additional Aptos transaction building options.
266
+ *
267
+ * @returns An object containing the pending transaction.
268
+ *
269
+ * @example
270
+ * ```typescript
271
+ * const provider = await ClayErasureCodingProvider.create();
272
+ * const blobCommitments = await generateCommitments(provider, data);
273
+ *
274
+ * const { transaction } = await client.registerBlob({
275
+ * account: signer,
276
+ * blobName: "foo/bar.txt",
277
+ * blobMerkleRoot: blobCommitments.blob_merkle_root,
278
+ * size: data.length,
279
+ * expirationMicros: Date.now() * 1000 + 3600_000_000, // 1 hour from now in microseconds
280
+ * });
281
+ * ```
282
+ */
283
+ async registerBlob(params) {
284
+ const chunksetSize = params.options?.chunksetSizeBytes ?? DEFAULT_CHUNKSET_SIZE_BYTES;
285
+ const transaction = await this.aptos.transaction.build.simple({
286
+ ...params.options?.build,
287
+ data: _ShelbyBlobClient.createRegisterBlobPayload({
288
+ deployer: this.deployer,
289
+ account: params.account.accountAddress,
290
+ blobName: params.blobName,
291
+ blobSize: params.size,
292
+ blobMerkleRoot: params.blobMerkleRoot,
293
+ numChunksets: expectedTotalChunksets(params.size, chunksetSize),
294
+ expirationMicros: params.expirationMicros
295
+ }),
296
+ sender: params.account.accountAddress
297
+ });
298
+ return {
299
+ transaction: await this.aptos.signAndSubmitTransaction({
300
+ signer: params.account,
301
+ transaction
302
+ })
303
+ };
304
+ }
305
+ /**
306
+ * Creates a transaction payload to register a blob on the blockchain.
307
+ * This is a static helper method for constructing the Move function call payload.
308
+ *
309
+ * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
310
+ * @param params.account - The account that will own the blob.
311
+ * @param params.blobName - The name/path of the blob (e.g. "foo/bar.txt").
312
+ * @param params.blobSize - The size of the blob in bytes.
313
+ * @param params.blobMerkleRoot - The merkle root of the blob commitments as a hex string.
314
+ * @param params.expirationMicros - The expiration time of the blob in microseconds.
315
+ * @param params.numChunksets - The total number of chunksets in the blob.
316
+ *
317
+ * @returns An Aptos transaction payload data object for the register_blob Move function.
318
+ *
319
+ * @see https://github.com/shelby/shelby/blob/e08e84742cf2b80ad8bb7227deb3013398076d53/move/shelby_contract/sources/global_metadata.move#L357
320
+ */
321
+ static createRegisterBlobPayload(params) {
322
+ return {
323
+ function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::global_metadata::register_blob`,
324
+ functionArguments: [
325
+ params.blobName,
326
+ params.expirationMicros,
327
+ MoveVector.U8(params.blobMerkleRoot),
328
+ params.numChunksets,
329
+ params.blobSize,
330
+ // TODO
331
+ 0,
332
+ // payment tier
333
+ 0
334
+ // encoding
335
+ ]
336
+ };
337
+ }
338
+ /**
339
+ * Creates a transaction payload to register multiple blobs on the blockchain.
340
+ * This is a static helper method for constructing the Move function call payload.
341
+ *
342
+ * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
343
+ * @param params.account - The account that will own the blobs.
344
+ * @param params.expirationMicros - The expiration time of the blobs in microseconds.
345
+ * @param params.blobs - The blobs to register.
346
+ * @param params.blobs.blobName - The name/path of the blob (e.g. "foo/bar.txt").
347
+ * @param params.blobs.blobSize - The size of the blob in bytes.
348
+ * @param params.blobs.blobMerkleRoot - The merkle root of the blob commitments as a hex string.
349
+ * @param params.blobs.numChunksets - The total number of chunksets in the blob.
350
+ *
351
+ * @returns An Aptos transaction payload data object for the register_multiple_blobs Move function.
352
+ *
353
+ * @see https://github.com/shelby/shelby/blob/e08e84742cf2b80ad8bb7227deb3013398076d53/move/shelby_contract/sources/global_metadata.move#L357
354
+ */
355
+ static createBatchRegisterBlobsPayload(params) {
356
+ const blobNames = [];
357
+ const blobMerkleRoots = [];
358
+ const blobNumChunksets = [];
359
+ const blobSizes = [];
360
+ params.blobs.forEach((blob) => {
361
+ blobNames.push(blob.blobName);
362
+ blobMerkleRoots.push(MoveVector.U8(blob.blobMerkleRoot));
363
+ blobNumChunksets.push(blob.numChunksets);
364
+ blobSizes.push(blob.blobSize);
365
+ });
366
+ return {
367
+ function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::global_metadata::register_multiple_blobs`,
368
+ functionArguments: [
369
+ blobNames,
370
+ params.expirationMicros,
371
+ blobMerkleRoots,
372
+ blobNumChunksets,
373
+ blobSizes,
374
+ // TODO
375
+ 0,
376
+ 0
377
+ ]
378
+ };
379
+ }
380
+ };
381
+
382
+ export {
383
+ ShelbyBlobClient
384
+ };
File without changes
@@ -0,0 +1,28 @@
1
+ // src/core/erasure/constants.ts
2
+ var ErasureCodingScheme = /* @__PURE__ */ ((ErasureCodingScheme2) => {
3
+ ErasureCodingScheme2["ClayCode_16Total_10Data_13Helper"] = "ClayCode_16Total_10Data_13Helper";
4
+ return ErasureCodingScheme2;
5
+ })(ErasureCodingScheme || {});
6
+ var ERASURE_CODE_PARAMS = {
7
+ ["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */]: {
8
+ // total chunks (data + parity)
9
+ erasure_n: 16,
10
+ // data chunks
11
+ erasure_k: 10,
12
+ // helper nodes
13
+ erasure_d: 13
14
+ }
15
+ };
16
+ var DEFAULT_ERASURE_N = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_n;
17
+ var DEFAULT_ERASURE_K = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_k;
18
+ var DEFAULT_ERASURE_D = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_d;
19
+ var DEFAULT_ERASURE_M = DEFAULT_ERASURE_N - DEFAULT_ERASURE_K;
20
+
21
+ export {
22
+ ErasureCodingScheme,
23
+ ERASURE_CODE_PARAMS,
24
+ DEFAULT_ERASURE_N,
25
+ DEFAULT_ERASURE_K,
26
+ DEFAULT_ERASURE_D,
27
+ DEFAULT_ERASURE_M
28
+ };
@@ -0,0 +1,129 @@
1
+ import { ChunkCollection, DecoderReconfigureOptions } from '@shelby-protocol/clay-codes';
2
+
3
+ interface ReedSolomonConfig extends ErasureCodingConfig {
4
+ }
5
+ type ReedSolomonProviderOptions = Partial<ReedSolomonConfig>;
6
+ declare class ReedSolomonErasureCodingProvider implements ErasureCodingProvider {
7
+ readonly config: ReedSolomonConfig;
8
+ constructor(options?: ReedSolomonProviderOptions);
9
+ encode(data: Uint8Array): ChunkCollection;
10
+ decode(_available: Uint8Array[], _config: DecodeConfig): ChunkCollection;
11
+ }
12
+
13
+ /**
14
+ * Erasure coding provider abstraction for the SDK.
15
+ *
16
+ * Providers implement different erasure coding schemes (Clay, Reed-Solomon, etc.)
17
+ * while maintaining a consistent interface for encoding and decoding operations.
18
+ */
19
+
20
+ /**
21
+ * Base configuration shared by all erasure coding schemes.
22
+ *
23
+ * All schemes must specify:
24
+ * - `chunkSizeBytes`: Size in bytes of each chunk
25
+ */
26
+ interface ErasureCodingConfig {
27
+ /** Number of total chunks. */
28
+ erasure_n: number;
29
+ /** Number of data chunks. */
30
+ erasure_k: number;
31
+ /** Size in bytes of every chunk. */
32
+ chunkSizeBytes: number;
33
+ }
34
+ /**
35
+ * Union of all supported erasure coding configurations.
36
+ */
37
+ type InitConfig = ReedSolomonConfig | ClayConfig;
38
+ /**
39
+ * Base marker type for decode configuration.
40
+ *
41
+ * Specific providers extend this with their erasure pattern specification options.
42
+ * The configuration indicates which chunks are available/missing in the decode operation.
43
+ */
44
+ type DecodeConfig = Record<string, unknown>;
45
+ /**
46
+ * Contract for pluggable erasure coding backends.
47
+ *
48
+ * Implementations provide encode/decode operations for different erasure
49
+ * coding schemes while maintaining consistent semantics:
50
+ *
51
+ * - **Encode**: Takes raw data and produces n = k + m chunks
52
+ * - **Decode**: Takes n chunks (some may be missing/undefined) and recovers all chunks
53
+ *
54
+ * All implementations must support both array and flat buffer inputs.
55
+ */
56
+ interface ErasureCodingProvider {
57
+ /** Configuration for this erasure coding instance. */
58
+ readonly config: ErasureCodingConfig;
59
+ /**
60
+ * Encode data into systematic and parity chunks.
61
+ *
62
+ * @param data - Raw data buffer that will be split into k chunks
63
+ * @returns Collection containing all n chunks (k systematic + m parity)
64
+ */
65
+ encode(data: Uint8Array): ChunkCollection;
66
+ /**
67
+ * Decode available chunks back to original data, recovering any missing chunks.
68
+ *
69
+ * @param available - Array of available chunks (must have at least k chunks)
70
+ * @param config - Decode configuration specifying which chunk indexes are available
71
+ * @returns Recovered chunk collection with all n chunks reconstructed
72
+ * @throws Error if fewer than k chunks are available
73
+ */
74
+ decode(available: Uint8Array[], config: DecodeConfig): ChunkCollection;
75
+ }
76
+
77
+ interface ClayConfig extends ErasureCodingConfig, ClayErasureCodeParams {
78
+ }
79
+ /**
80
+ * Parameters that define a Clay erasure coding scheme.
81
+ *
82
+ * These values specify only the coding characteristics, not
83
+ * implementation details like chunk size or storage layout.
84
+ *
85
+ * - `erasure_n`: Total number of chunks (data + parity)
86
+ * - `erasure_k`: Number of data chunks
87
+ * - `erasure_d`: Number of helper nodes participating in reconstruction
88
+ */
89
+ interface ClayErasureCodeParams {
90
+ erasure_n: number;
91
+ erasure_k: number;
92
+ erasure_d: number;
93
+ }
94
+ type ClayProviderOptions = Partial<ClayErasureCodeParams & ErasureCodingConfig>;
95
+ /**
96
+ * Clay-specific decode configuration.
97
+ *
98
+ * Supports flexible erasure pattern specification in any of three formats:
99
+ * - availableChunkIndexes: Array of available chunk positions
100
+ * - erasedChunkIndexes: Array of missing chunk positions
101
+ * - erasedChunksMask: Bitmask where bit i=1 means chunk i is missing
102
+ *
103
+ * Exactly one of these three options must be provided.
104
+ */
105
+ type ClayDecodeConfig = DecoderReconfigureOptions;
106
+ declare class ClayErasureCodingProvider implements ErasureCodingProvider {
107
+ readonly config: ClayConfig;
108
+ private encoderCache?;
109
+ private decoderCache?;
110
+ private constructor();
111
+ /**
112
+ * Static factory method to create an initialized ClayErasureCodingProvider
113
+ */
114
+ static create<T extends ClayProviderOptions>(options?: T): Promise<ClayErasureCodingProvider>;
115
+ encode(data: Uint8Array): ChunkCollection;
116
+ decode(available: Uint8Array[], config: ClayDecodeConfig): ChunkCollection;
117
+ /**
118
+ * Determines if data can be erasure coded as-is or requires padding.
119
+ *
120
+ * Data can be erasure coded without padding if its size exactly matches
121
+ * the total systematic data capacity (k * chunkSizeBytes).
122
+ *
123
+ * @param dataSize - Size of the data in bytes
124
+ * @returns true if data needs padding, false if it can be coded as-is
125
+ */
126
+ requiresPadding(dataSize: number): boolean;
127
+ }
128
+
129
+ 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 };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createBlobKey
3
- } from "../chunk-QEMIORTL.mjs";
3
+ } from "../chunk-OTBLZL2S.mjs";
4
4
  import "../chunk-7P6ASYW6.mjs";
5
5
  export {
6
6
  createBlobKey
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Chunk and chunkset size configurations supported by Shelby.
3
+ */
4
+ declare enum ChunkSizeScheme {
5
+ ChunkSet10MiB_Chunk1MiB = "ChunkSet10MiB_Chunk1MiB"
6
+ }
7
+ /**
8
+ * Parameters for chunk and chunkset sizes in bytes.
9
+ */
10
+ declare const CHUNK_SIZE_PARAMS: {
11
+ readonly ChunkSet10MiB_Chunk1MiB: {
12
+ readonly chunkSizeBytes: number;
13
+ readonly chunksetSizeBytes: number;
14
+ };
15
+ };
16
+ /**
17
+ * The default size of a chunk in bytes.
18
+ */
19
+ declare const DEFAULT_CHUNK_SIZE_BYTES: number;
20
+ /**
21
+ * The default size of a chunkset in bytes.
22
+ */
23
+ declare const DEFAULT_CHUNKSET_SIZE_BYTES: number;
24
+ /**
25
+ * Mapping between erasure codes and chunks
26
+ */
27
+ declare const ERASURE_CODE_AND_CHUNK_MAPPING: {
28
+ readonly ClayCode_16Total_10Data_13Helper: {
29
+ readonly chunkSizeBytes: number;
30
+ readonly chunksetSizeBytes: number;
31
+ };
32
+ };
33
+
34
+ export { CHUNK_SIZE_PARAMS, ChunkSizeScheme, DEFAULT_CHUNKSET_SIZE_BYTES, DEFAULT_CHUNK_SIZE_BYTES, ERASURE_CODE_AND_CHUNK_MAPPING };
@@ -0,0 +1,17 @@
1
+ import {
2
+ CHUNK_SIZE_PARAMS,
3
+ ChunkSizeScheme,
4
+ DEFAULT_CHUNKSET_SIZE_BYTES,
5
+ DEFAULT_CHUNK_SIZE_BYTES,
6
+ ERASURE_CODE_AND_CHUNK_MAPPING
7
+ } from "../chunk-APML3CGJ.mjs";
8
+ import "../chunk-3ZDXWPYC.mjs";
9
+ import "../chunk-ZPW742E7.mjs";
10
+ import "../chunk-7P6ASYW6.mjs";
11
+ export {
12
+ CHUNK_SIZE_PARAMS,
13
+ ChunkSizeScheme,
14
+ DEFAULT_CHUNKSET_SIZE_BYTES,
15
+ DEFAULT_CHUNK_SIZE_BYTES,
16
+ ERASURE_CODE_AND_CHUNK_MAPPING
17
+ };