@shelby-protocol/sdk 0.2.4 → 0.3.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 (124) hide show
  1. package/dist/browser/index.d.ts +13 -4
  2. package/dist/browser/index.mjs +3719 -140
  3. package/dist/{clay-codes-DHP-bYcP.d.ts → clay-codes-DdXABBDx.d.ts} +0 -7
  4. package/dist/core/aptos-explorer.mjs +46 -5
  5. package/dist/core/blobs.d.ts +1 -1
  6. package/dist/core/blobs.mjs +12 -4
  7. package/dist/core/chunk.mjs +58 -9
  8. package/dist/core/clients/ShelbyBlobClient.d.ts +9 -44
  9. package/dist/core/clients/ShelbyBlobClient.mjs +1084 -17
  10. package/dist/core/clients/ShelbyClient.d.ts +12 -2
  11. package/dist/core/clients/ShelbyClient.mjs +2915 -23
  12. package/dist/core/clients/ShelbyClientConfig.d.ts +8 -0
  13. package/dist/core/clients/ShelbyClientConfig.mjs +0 -1
  14. package/dist/core/clients/ShelbyMetadataClient.d.ts +0 -18
  15. package/dist/core/clients/ShelbyMetadataClient.mjs +306 -6
  16. package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +7 -49
  17. package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +839 -13
  18. package/dist/core/clients/ShelbyPlacementGroupClient.mjs +307 -8
  19. package/dist/core/clients/ShelbyRPCClient.d.ts +107 -4
  20. package/dist/core/clients/ShelbyRPCClient.mjs +1261 -12
  21. package/dist/core/clients/index.d.ts +3 -2
  22. package/dist/core/clients/index.mjs +3421 -40
  23. package/dist/core/clients/utils.mjs +65 -6
  24. package/dist/core/commitments.d.ts +3 -12
  25. package/dist/core/commitments.mjs +270 -11
  26. package/dist/core/constants.d.ts +4 -4
  27. package/dist/core/constants.mjs +39 -16
  28. package/dist/core/erasure/clay-codes.d.ts +1 -1
  29. package/dist/core/erasure/clay-codes.mjs +129 -4
  30. package/dist/core/erasure/constants.mjs +33 -10
  31. package/dist/core/erasure/default.d.ts +1 -1
  32. package/dist/core/erasure/default.mjs +191 -9
  33. package/dist/core/erasure/index.d.ts +1 -1
  34. package/dist/core/erasure/index.mjs +266 -23
  35. package/dist/core/erasure/provider.d.ts +1 -1
  36. package/dist/core/erasure/reed-solomon.d.ts +1 -1
  37. package/dist/core/erasure/reed-solomon.mjs +68 -4
  38. package/dist/core/erasure/utils.d.ts +1 -1
  39. package/dist/core/erasure/utils.mjs +0 -2
  40. package/dist/core/errors.mjs +29 -8
  41. package/dist/core/index.d.ts +4 -4
  42. package/dist/core/index.mjs +3713 -140
  43. package/dist/core/layout.d.ts +1 -1
  44. package/dist/core/layout.mjs +37 -5
  45. package/dist/core/networks.mjs +10 -5
  46. package/dist/core/operations/generated/sdk.d.ts +9 -0
  47. package/dist/core/operations/generated/sdk.mjs +183 -18
  48. package/dist/core/operations/index.mjs +284 -24
  49. package/dist/core/promises.mjs +4 -4
  50. package/dist/core/rpc-responses.d.ts +38 -1
  51. package/dist/core/rpc-responses.mjs +31 -8
  52. package/dist/core/shelby-explorer.mjs +31 -6
  53. package/dist/core/strings.mjs +0 -2
  54. package/dist/core/types/blobs.d.ts +1 -1
  55. package/dist/core/types/blobs.mjs +0 -1
  56. package/dist/core/types/index.d.ts +1 -1
  57. package/dist/core/types/index.mjs +230 -9
  58. package/dist/core/types/payments.d.ts +6 -6
  59. package/dist/core/types/payments.mjs +230 -5
  60. package/dist/core/types/placement_groups.mjs +0 -1
  61. package/dist/core/types/storage_providers.mjs +0 -1
  62. package/dist/core/utils.mjs +94 -8
  63. package/dist/node/clients/ShelbyNodeClient.d.ts +2 -1
  64. package/dist/node/clients/ShelbyNodeClient.mjs +2919 -24
  65. package/dist/node/clients/index.d.ts +2 -1
  66. package/dist/node/clients/index.mjs +2920 -26
  67. package/dist/node/index.d.ts +4 -4
  68. package/dist/node/index.mjs +3736 -147
  69. package/dist/node/parallel/commitment_worker.d.ts +9 -0
  70. package/dist/node/parallel/commitment_worker.mjs +298 -0
  71. package/dist/node/parallel/commitment_worker_pool.d.ts +35 -0
  72. package/dist/node/parallel/commitment_worker_pool.mjs +286 -0
  73. package/dist/node/parallel/default_commitment_worker_pool.d.ts +24 -0
  74. package/dist/node/parallel/default_commitment_worker_pool.mjs +302 -0
  75. package/dist/node/parallel/index.d.ts +11 -0
  76. package/dist/node/parallel/index.mjs +563 -0
  77. package/dist/node/parallel/parallel_commitments.d.ts +32 -0
  78. package/dist/node/parallel/parallel_commitments.mjs +561 -0
  79. package/dist/node/parallel/worker_pool.d.ts +74 -0
  80. package/dist/node/parallel/worker_pool.mjs +248 -0
  81. package/dist/node/testUtil.mjs +8 -4
  82. package/package.json +9 -6
  83. package/dist/chunk-3NRBHSMQ.mjs +0 -12
  84. package/dist/chunk-3PCG7PNP.mjs +0 -375
  85. package/dist/chunk-7OV5ZYW6.mjs +0 -55
  86. package/dist/chunk-7P6ASYW6.mjs +0 -9
  87. package/dist/chunk-A4IG6GSE.mjs +0 -21
  88. package/dist/chunk-AD2G3QYD.mjs +0 -0
  89. package/dist/chunk-AEDVYYGD.mjs +0 -11
  90. package/dist/chunk-AUQDI5BS.mjs +0 -43
  91. package/dist/chunk-BDSW5PHM.mjs +0 -37
  92. package/dist/chunk-BKL7NCUB.mjs +0 -412
  93. package/dist/chunk-BUWAD67L.mjs +0 -505
  94. package/dist/chunk-BXEVML7N.mjs +0 -169
  95. package/dist/chunk-C6RQ3AEU.mjs +0 -51
  96. package/dist/chunk-CQ6QPIZK.mjs +0 -37
  97. package/dist/chunk-D6GQHO6G.mjs +0 -15
  98. package/dist/chunk-EM67QTMR.mjs +0 -0
  99. package/dist/chunk-I6NG5GNL.mjs +0 -8
  100. package/dist/chunk-IE6LYVIA.mjs +0 -26
  101. package/dist/chunk-IKRWBDG5.mjs +0 -42
  102. package/dist/chunk-JTXYKO3U.mjs +0 -38
  103. package/dist/chunk-KYQRWJ3U.mjs +0 -49
  104. package/dist/chunk-MB7C7VQF.mjs +0 -0
  105. package/dist/chunk-MQUVYMNQ.mjs +0 -0
  106. package/dist/chunk-NHWWORCH.mjs +0 -72
  107. package/dist/chunk-NI6XBZLI.mjs +0 -83
  108. package/dist/chunk-OGKZ575S.mjs +0 -136
  109. package/dist/chunk-QQ57OGQ2.mjs +0 -0
  110. package/dist/chunk-SSE4MFNN.mjs +0 -278
  111. package/dist/chunk-TET3DJEO.mjs +0 -199
  112. package/dist/chunk-TVLV7C74.mjs +0 -207
  113. package/dist/chunk-UEZNZBJO.mjs +0 -104
  114. package/dist/chunk-WJTVYLKW.mjs +0 -782
  115. package/dist/chunk-WTICJPDB.mjs +0 -0
  116. package/dist/chunk-XNEIWM4O.mjs +0 -0
  117. package/dist/chunk-XRLHLAOW.mjs +0 -51
  118. package/dist/chunk-Z4FZ7W6L.mjs +0 -39
  119. package/dist/chunk-Z7RFCADT.mjs +0 -0
  120. package/dist/chunk-ZHXCVRZX.mjs +0 -0
  121. package/dist/core/operations/generated/types.d.ts +0 -908
  122. package/dist/core/operations/generated/types.mjs +0 -63
  123. package/dist/core/types/encodings.d.ts +0 -11
  124. package/dist/core/types/encodings.mjs +0 -0
@@ -1,13 +1,195 @@
1
+ // src/core/erasure/constants.ts
2
+ var ERASURE_CODE_PARAMS = {
3
+ ["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */]: {
4
+ // total chunks (data + parity)
5
+ erasure_n: 16,
6
+ // data chunks
7
+ erasure_k: 10,
8
+ // helper nodes
9
+ erasure_d: 13,
10
+ // enum index
11
+ enumIndex: 0
12
+ },
13
+ ["ClayCode_4Total_2Data_3Helper" /* ClayCode_4Total_2Data_3Helper */]: {
14
+ // total chunks (data + parity)
15
+ erasure_n: 4,
16
+ // data chunks
17
+ erasure_k: 2,
18
+ // helper nodes
19
+ erasure_d: 3,
20
+ // enum index
21
+ enumIndex: 1
22
+ }
23
+ };
24
+ var DEFAULT_ERASURE_N = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_n;
25
+ var DEFAULT_ERASURE_K = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_k;
26
+ var DEFAULT_ERASURE_D = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_d;
27
+ var DEFAULT_ERASURE_M = DEFAULT_ERASURE_N - DEFAULT_ERASURE_K;
28
+
29
+ // src/core/chunk.ts
30
+ var CHUNK_SIZE_PARAMS = {
31
+ ["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */]: {
32
+ // 1MiB
33
+ chunkSizeBytes: 1 * 1024 * 1024,
34
+ // 10MiB
35
+ chunksetSizeBytes: 10 * 1024 * 1024
36
+ },
37
+ ["ChunkSet2MiB_Chunk1MiB" /* ChunkSet2MiB_Chunk1MiB */]: {
38
+ // 1MiB
39
+ chunkSizeBytes: 1 * 1024 * 1024,
40
+ // 2MiB
41
+ chunksetSizeBytes: 2 * 1024 * 1024
42
+ }
43
+ };
44
+ var DEFAULT_CHUNK_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */].chunkSizeBytes;
45
+ var DEFAULT_CHUNKSET_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */].chunksetSizeBytes;
46
+ var ERASURE_CODE_AND_CHUNK_MAPPING = {
47
+ ["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */]: {
48
+ ...CHUNK_SIZE_PARAMS.ChunkSet10MiB_Chunk1MiB
49
+ },
50
+ ["ClayCode_4Total_2Data_3Helper" /* ClayCode_4Total_2Data_3Helper */]: {
51
+ ...CHUNK_SIZE_PARAMS.ChunkSet2MiB_Chunk1MiB
52
+ }
53
+ };
54
+
55
+ // src/core/erasure/clay-codes.ts
1
56
  import {
2
- createDefaultErasureCodingProvider,
3
- defaultErasureCodingConfig,
4
- erasureCodingConfig16Total10Data13Helper,
5
- erasureCodingConfig4Total2Data3Helper
6
- } from "../../chunk-XRLHLAOW.mjs";
7
- import "../../chunk-OGKZ575S.mjs";
8
- import "../../chunk-JTXYKO3U.mjs";
9
- import "../../chunk-AUQDI5BS.mjs";
10
- import "../../chunk-7P6ASYW6.mjs";
57
+ createDecoder,
58
+ createEncoder
59
+ } from "@shelby-protocol/clay-codes";
60
+ function getTotalChunks(config) {
61
+ return config.erasure_n;
62
+ }
63
+ var ClayErasureCodingProvider = class _ClayErasureCodingProvider {
64
+ config;
65
+ encoderCache;
66
+ decoderCache;
67
+ lastFunction;
68
+ constructor(config) {
69
+ this.config = config;
70
+ this.lastFunction = "none" /* NONE */;
71
+ }
72
+ /**
73
+ * Static factory method to create an initialized ClayErasureCodingProvider
74
+ */
75
+ static async create(config) {
76
+ const provider = new _ClayErasureCodingProvider(config);
77
+ [provider.encoderCache, provider.decoderCache] = await Promise.all([
78
+ createEncoder({
79
+ n: getTotalChunks(config),
80
+ k: config.erasure_k,
81
+ d: config.erasure_d,
82
+ chunkSizeBytes: config.chunkSizeBytes
83
+ }),
84
+ createDecoder({
85
+ n: getTotalChunks(config),
86
+ k: config.erasure_k,
87
+ d: config.erasure_d,
88
+ chunkSizeBytes: config.chunkSizeBytes,
89
+ erasedChunkIndexes: []
90
+ })
91
+ ]);
92
+ return provider;
93
+ }
94
+ encode(data) {
95
+ const { erasure_k, chunkSizeBytes } = this.config;
96
+ if (!this.encoderCache) {
97
+ throw new Error("Encoder cache is missing");
98
+ }
99
+ const systematicCapacity = erasure_k * chunkSizeBytes;
100
+ if (data.byteLength > systematicCapacity) {
101
+ throw new Error(
102
+ `Data size ${data.byteLength} bytes exceeds systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}).`
103
+ );
104
+ }
105
+ if (this.requiresPadding(data.length)) {
106
+ throw new Error(
107
+ `Data size ${data.length} bytes does not match systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}). Provide pre-padded data before encoding.`
108
+ );
109
+ }
110
+ this.lastFunction = "encoded" /* ENCODED */;
111
+ return this.encoderCache.erasureCode(data);
112
+ }
113
+ decode(available, config) {
114
+ if (!this.decoderCache) {
115
+ throw new Error("Decoder cache is missing");
116
+ }
117
+ const { erasure_k, chunkSizeBytes } = this.config;
118
+ if (available.length < erasure_k) {
119
+ throw new Error(
120
+ `Insufficient available chunks: need at least ${erasure_k}, received ${available.length}.`
121
+ );
122
+ }
123
+ for (let i = 0; i < available.length; i++) {
124
+ const chunk = available[i];
125
+ if (chunk.length !== chunkSizeBytes) {
126
+ throw new Error(
127
+ `Chunk ${i} size ${chunk.length} bytes does not match expected chunkSizeBytes ${chunkSizeBytes}.`
128
+ );
129
+ }
130
+ }
131
+ this.lastFunction = "decoded" /* DECODED */;
132
+ return this.decoderCache.decode(available, config);
133
+ }
134
+ getChunkMerkleRoots() {
135
+ if (this.decoderCache && this.lastFunction === "decoded" /* DECODED */)
136
+ return this.decoderCache.getChunkMerkleRoots();
137
+ if (this.encoderCache && this.lastFunction === "encoded" /* ENCODED */)
138
+ return this.encoderCache.getChunkMerkleRoots();
139
+ throw new Error(
140
+ "You must call encode or decode before calling getChunkMerkleRoots"
141
+ );
142
+ }
143
+ /**
144
+ * Determines if data can be erasure coded as-is or requires padding.
145
+ *
146
+ * Data can be erasure coded without padding if its size exactly matches
147
+ * the total systematic data capacity (k * chunkSizeBytes).
148
+ *
149
+ * @param dataSize - Size of the data in bytes
150
+ * @returns true if data needs padding, false if it can be coded as-is
151
+ */
152
+ requiresPadding(dataSize) {
153
+ const { erasure_k, chunkSizeBytes } = this.config;
154
+ const systematicCapacity = erasure_k * chunkSizeBytes;
155
+ return dataSize !== systematicCapacity;
156
+ }
157
+ };
158
+
159
+ // src/core/erasure/default.ts
160
+ var defaultProviderPromise;
161
+ function createDefaultErasureCodingProvider() {
162
+ if (!defaultProviderPromise) {
163
+ defaultProviderPromise = ClayErasureCodingProvider.create(
164
+ defaultErasureCodingConfig()
165
+ );
166
+ }
167
+ return defaultProviderPromise;
168
+ }
169
+ function defaultErasureCodingConfig() {
170
+ const encoding = Number(process.env.SHELBY_ENCODING) || 0;
171
+ if (encoding === 0) {
172
+ return erasureCodingConfig16Total10Data13Helper();
173
+ }
174
+ return erasureCodingConfig4Total2Data3Helper();
175
+ }
176
+ function erasureCodingConfig16Total10Data13Helper() {
177
+ return erasureCodingConfig(
178
+ "ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */
179
+ );
180
+ }
181
+ function erasureCodingConfig4Total2Data3Helper() {
182
+ return erasureCodingConfig("ClayCode_4Total_2Data_3Helper" /* ClayCode_4Total_2Data_3Helper */);
183
+ }
184
+ function erasureCodingConfig(encodingScheme) {
185
+ return {
186
+ erasure_n: ERASURE_CODE_PARAMS[encodingScheme].erasure_n,
187
+ erasure_k: ERASURE_CODE_PARAMS[encodingScheme].erasure_k,
188
+ erasure_d: ERASURE_CODE_PARAMS[encodingScheme].erasure_d,
189
+ chunkSizeBytes: DEFAULT_CHUNK_SIZE_BYTES,
190
+ enumIndex: ERASURE_CODE_PARAMS[encodingScheme].enumIndex
191
+ };
192
+ }
11
193
  export {
12
194
  createDefaultErasureCodingProvider,
13
195
  defaultErasureCodingConfig,
@@ -1,4 +1,4 @@
1
- export { C as ClayErasureCodingProvider, D as DecodeConfig, E as ErasureCodingConfig, a as ErasureCodingProvider, R as ReedSolomonErasureCodingProvider } from '../../clay-codes-DHP-bYcP.js';
1
+ export { C as ClayErasureCodingProvider, D as DecodeConfig, E as ErasureCodingConfig, a as ErasureCodingProvider, R as ReedSolomonErasureCodingProvider } from '../../clay-codes-DdXABBDx.js';
2
2
  export { DEFAULT_ERASURE_D, DEFAULT_ERASURE_K, DEFAULT_ERASURE_M, DEFAULT_ERASURE_N, DEFAULT_SAMPLE_SIZE, ERASURE_CODE_PARAMS, ErasureCodeParams, ErasureCodingScheme, ErasureSchemeParams } from './constants.js';
3
3
  export { createDefaultErasureCodingProvider, defaultErasureCodingConfig, erasureCodingConfig16Total10Data13Helper, erasureCodingConfig4Total2Data3Helper } from './default.js';
4
4
  import '@shelby-protocol/clay-codes';
@@ -1,27 +1,270 @@
1
- import "../../chunk-XNEIWM4O.mjs";
1
+ // src/core/erasure/clay-codes.ts
2
2
  import {
3
- ReedSolomonErasureCodingProvider
4
- } from "../../chunk-NHWWORCH.mjs";
5
- import {
6
- createDefaultErasureCodingProvider,
7
- defaultErasureCodingConfig,
8
- erasureCodingConfig16Total10Data13Helper,
9
- erasureCodingConfig4Total2Data3Helper
10
- } from "../../chunk-XRLHLAOW.mjs";
11
- import {
12
- ClayErasureCodingProvider
13
- } from "../../chunk-OGKZ575S.mjs";
14
- import "../../chunk-JTXYKO3U.mjs";
15
- import {
16
- DEFAULT_ERASURE_D,
17
- DEFAULT_ERASURE_K,
18
- DEFAULT_ERASURE_M,
19
- DEFAULT_ERASURE_N,
20
- DEFAULT_SAMPLE_SIZE,
21
- ERASURE_CODE_PARAMS,
22
- ErasureCodingScheme
23
- } from "../../chunk-AUQDI5BS.mjs";
24
- import "../../chunk-7P6ASYW6.mjs";
3
+ createDecoder,
4
+ createEncoder
5
+ } from "@shelby-protocol/clay-codes";
6
+ function getTotalChunks(config) {
7
+ return config.erasure_n;
8
+ }
9
+ var ClayErasureCodingProvider = class _ClayErasureCodingProvider {
10
+ config;
11
+ encoderCache;
12
+ decoderCache;
13
+ lastFunction;
14
+ constructor(config) {
15
+ this.config = config;
16
+ this.lastFunction = "none" /* NONE */;
17
+ }
18
+ /**
19
+ * Static factory method to create an initialized ClayErasureCodingProvider
20
+ */
21
+ static async create(config) {
22
+ const provider = new _ClayErasureCodingProvider(config);
23
+ [provider.encoderCache, provider.decoderCache] = await Promise.all([
24
+ createEncoder({
25
+ n: getTotalChunks(config),
26
+ k: config.erasure_k,
27
+ d: config.erasure_d,
28
+ chunkSizeBytes: config.chunkSizeBytes
29
+ }),
30
+ createDecoder({
31
+ n: getTotalChunks(config),
32
+ k: config.erasure_k,
33
+ d: config.erasure_d,
34
+ chunkSizeBytes: config.chunkSizeBytes,
35
+ erasedChunkIndexes: []
36
+ })
37
+ ]);
38
+ return provider;
39
+ }
40
+ encode(data) {
41
+ const { erasure_k, chunkSizeBytes } = this.config;
42
+ if (!this.encoderCache) {
43
+ throw new Error("Encoder cache is missing");
44
+ }
45
+ const systematicCapacity = erasure_k * chunkSizeBytes;
46
+ if (data.byteLength > systematicCapacity) {
47
+ throw new Error(
48
+ `Data size ${data.byteLength} bytes exceeds systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}).`
49
+ );
50
+ }
51
+ if (this.requiresPadding(data.length)) {
52
+ throw new Error(
53
+ `Data size ${data.length} bytes does not match systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}). Provide pre-padded data before encoding.`
54
+ );
55
+ }
56
+ this.lastFunction = "encoded" /* ENCODED */;
57
+ return this.encoderCache.erasureCode(data);
58
+ }
59
+ decode(available, config) {
60
+ if (!this.decoderCache) {
61
+ throw new Error("Decoder cache is missing");
62
+ }
63
+ const { erasure_k, chunkSizeBytes } = this.config;
64
+ if (available.length < erasure_k) {
65
+ throw new Error(
66
+ `Insufficient available chunks: need at least ${erasure_k}, received ${available.length}.`
67
+ );
68
+ }
69
+ for (let i = 0; i < available.length; i++) {
70
+ const chunk = available[i];
71
+ if (chunk.length !== chunkSizeBytes) {
72
+ throw new Error(
73
+ `Chunk ${i} size ${chunk.length} bytes does not match expected chunkSizeBytes ${chunkSizeBytes}.`
74
+ );
75
+ }
76
+ }
77
+ this.lastFunction = "decoded" /* DECODED */;
78
+ return this.decoderCache.decode(available, config);
79
+ }
80
+ getChunkMerkleRoots() {
81
+ if (this.decoderCache && this.lastFunction === "decoded" /* DECODED */)
82
+ return this.decoderCache.getChunkMerkleRoots();
83
+ if (this.encoderCache && this.lastFunction === "encoded" /* ENCODED */)
84
+ return this.encoderCache.getChunkMerkleRoots();
85
+ throw new Error(
86
+ "You must call encode or decode before calling getChunkMerkleRoots"
87
+ );
88
+ }
89
+ /**
90
+ * Determines if data can be erasure coded as-is or requires padding.
91
+ *
92
+ * Data can be erasure coded without padding if its size exactly matches
93
+ * the total systematic data capacity (k * chunkSizeBytes).
94
+ *
95
+ * @param dataSize - Size of the data in bytes
96
+ * @returns true if data needs padding, false if it can be coded as-is
97
+ */
98
+ requiresPadding(dataSize) {
99
+ const { erasure_k, chunkSizeBytes } = this.config;
100
+ const systematicCapacity = erasure_k * chunkSizeBytes;
101
+ return dataSize !== systematicCapacity;
102
+ }
103
+ };
104
+
105
+ // src/core/erasure/constants.ts
106
+ var ErasureCodingScheme = /* @__PURE__ */ ((ErasureCodingScheme2) => {
107
+ ErasureCodingScheme2["ClayCode_16Total_10Data_13Helper"] = "ClayCode_16Total_10Data_13Helper";
108
+ ErasureCodingScheme2["ClayCode_4Total_2Data_3Helper"] = "ClayCode_4Total_2Data_3Helper";
109
+ return ErasureCodingScheme2;
110
+ })(ErasureCodingScheme || {});
111
+ var ERASURE_CODE_PARAMS = {
112
+ ["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */]: {
113
+ // total chunks (data + parity)
114
+ erasure_n: 16,
115
+ // data chunks
116
+ erasure_k: 10,
117
+ // helper nodes
118
+ erasure_d: 13,
119
+ // enum index
120
+ enumIndex: 0
121
+ },
122
+ ["ClayCode_4Total_2Data_3Helper" /* ClayCode_4Total_2Data_3Helper */]: {
123
+ // total chunks (data + parity)
124
+ erasure_n: 4,
125
+ // data chunks
126
+ erasure_k: 2,
127
+ // helper nodes
128
+ erasure_d: 3,
129
+ // enum index
130
+ enumIndex: 1
131
+ }
132
+ };
133
+ var DEFAULT_ERASURE_N = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_n;
134
+ var DEFAULT_ERASURE_K = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_k;
135
+ var DEFAULT_ERASURE_D = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_d;
136
+ var DEFAULT_ERASURE_M = DEFAULT_ERASURE_N - DEFAULT_ERASURE_K;
137
+ var DEFAULT_SAMPLE_SIZE = 1024;
138
+
139
+ // src/core/chunk.ts
140
+ var CHUNK_SIZE_PARAMS = {
141
+ ["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */]: {
142
+ // 1MiB
143
+ chunkSizeBytes: 1 * 1024 * 1024,
144
+ // 10MiB
145
+ chunksetSizeBytes: 10 * 1024 * 1024
146
+ },
147
+ ["ChunkSet2MiB_Chunk1MiB" /* ChunkSet2MiB_Chunk1MiB */]: {
148
+ // 1MiB
149
+ chunkSizeBytes: 1 * 1024 * 1024,
150
+ // 2MiB
151
+ chunksetSizeBytes: 2 * 1024 * 1024
152
+ }
153
+ };
154
+ var DEFAULT_CHUNK_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */].chunkSizeBytes;
155
+ var DEFAULT_CHUNKSET_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */].chunksetSizeBytes;
156
+ var ERASURE_CODE_AND_CHUNK_MAPPING = {
157
+ ["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */]: {
158
+ ...CHUNK_SIZE_PARAMS.ChunkSet10MiB_Chunk1MiB
159
+ },
160
+ ["ClayCode_4Total_2Data_3Helper" /* ClayCode_4Total_2Data_3Helper */]: {
161
+ ...CHUNK_SIZE_PARAMS.ChunkSet2MiB_Chunk1MiB
162
+ }
163
+ };
164
+
165
+ // src/core/erasure/default.ts
166
+ var defaultProviderPromise;
167
+ function createDefaultErasureCodingProvider() {
168
+ if (!defaultProviderPromise) {
169
+ defaultProviderPromise = ClayErasureCodingProvider.create(
170
+ defaultErasureCodingConfig()
171
+ );
172
+ }
173
+ return defaultProviderPromise;
174
+ }
175
+ function defaultErasureCodingConfig() {
176
+ const encoding = Number(process.env.SHELBY_ENCODING) || 0;
177
+ if (encoding === 0) {
178
+ return erasureCodingConfig16Total10Data13Helper();
179
+ }
180
+ return erasureCodingConfig4Total2Data3Helper();
181
+ }
182
+ function erasureCodingConfig16Total10Data13Helper() {
183
+ return erasureCodingConfig(
184
+ "ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */
185
+ );
186
+ }
187
+ function erasureCodingConfig4Total2Data3Helper() {
188
+ return erasureCodingConfig("ClayCode_4Total_2Data_3Helper" /* ClayCode_4Total_2Data_3Helper */);
189
+ }
190
+ function erasureCodingConfig(encodingScheme) {
191
+ return {
192
+ erasure_n: ERASURE_CODE_PARAMS[encodingScheme].erasure_n,
193
+ erasure_k: ERASURE_CODE_PARAMS[encodingScheme].erasure_k,
194
+ erasure_d: ERASURE_CODE_PARAMS[encodingScheme].erasure_d,
195
+ chunkSizeBytes: DEFAULT_CHUNK_SIZE_BYTES,
196
+ enumIndex: ERASURE_CODE_PARAMS[encodingScheme].enumIndex
197
+ };
198
+ }
199
+
200
+ // src/core/erasure/reed-solomon.ts
201
+ import { createWasmReedSolomonBinding } from "@shelby-protocol/reed-solomon";
202
+ var DEFAULT_ERASURE_K2 = 10;
203
+ var DEFAULT_ERASURE_N2 = 16;
204
+ var DEFAULT_CHUNK_SIZE_BYTES2 = 2 * 1024 * 1024;
205
+ var ReedSolomonErasureCodingProvider = class {
206
+ config;
207
+ constructor(options) {
208
+ const erasure_k = options?.erasure_k ?? DEFAULT_ERASURE_K2;
209
+ const erasure_n = options?.erasure_n ?? DEFAULT_ERASURE_N2;
210
+ const chunkSizeBytes = options?.chunkSizeBytes ?? DEFAULT_CHUNK_SIZE_BYTES2;
211
+ const enumIndex = -1;
212
+ if (erasure_k <= 0)
213
+ throw new Error("erasure_k (number of data chunks) must be > 0");
214
+ if (erasure_n <= erasure_k)
215
+ throw new Error(
216
+ `erasure_n (${erasure_n}) must be > erasure_k (${erasure_k})`
217
+ );
218
+ if (chunkSizeBytes <= 0) throw new Error("chunkSizeBytes must be > 0");
219
+ this.config = {
220
+ erasure_n,
221
+ erasure_k,
222
+ chunkSizeBytes,
223
+ enumIndex
224
+ };
225
+ }
226
+ encode(data) {
227
+ const { erasure_k, erasure_n, chunkSizeBytes } = this.config;
228
+ const erasure_m = erasure_n - erasure_k;
229
+ const systematicCapacity = erasure_k * chunkSizeBytes;
230
+ if (data.byteLength > systematicCapacity) {
231
+ throw new Error(
232
+ `Data size ${data.byteLength} bytes exceeds systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}).`
233
+ );
234
+ }
235
+ if (data.byteLength !== systematicCapacity) {
236
+ throw new Error(
237
+ `Data size ${data.byteLength} bytes does not match systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}). Provide pre-padded data before encoding.`
238
+ );
239
+ }
240
+ const reedSolomon = createWasmReedSolomonBinding();
241
+ const shards = new Uint8Array(
242
+ systematicCapacity + erasure_m * chunkSizeBytes
243
+ );
244
+ shards.set(data, 0);
245
+ reedSolomon.encode(shards, erasure_k, erasure_m);
246
+ const chunks = new Array(erasure_n);
247
+ for (let idx = 0; idx < erasure_n; idx++) {
248
+ const start = idx * chunkSizeBytes;
249
+ chunks[idx] = shards.slice(start, start + chunkSizeBytes);
250
+ }
251
+ return {
252
+ chunks,
253
+ systematic: chunks.slice(0, erasure_k),
254
+ parity: chunks.slice(erasure_k)
255
+ };
256
+ }
257
+ decode(_available, _config) {
258
+ throw new Error(
259
+ "ReedSolomonErasureCodingProvider does not implement decode"
260
+ );
261
+ }
262
+ getChunkMerkleRoots() {
263
+ throw new Error(
264
+ "ReedSolomonErasureCodingProvider does not implement getChunkMerkleRoots"
265
+ );
266
+ }
267
+ };
25
268
  export {
26
269
  ClayErasureCodingProvider,
27
270
  DEFAULT_ERASURE_D,
@@ -1,2 +1,2 @@
1
1
  import '@shelby-protocol/clay-codes';
2
- export { D as DecodeConfig, E as ErasureCodingConfig, a as ErasureCodingProvider, I as InitConfig } from '../../clay-codes-DHP-bYcP.js';
2
+ export { D as DecodeConfig, E as ErasureCodingConfig, a as ErasureCodingProvider, I as InitConfig } from '../../clay-codes-DdXABBDx.js';
@@ -1,2 +1,2 @@
1
1
  import '@shelby-protocol/clay-codes';
2
- export { d as ReedSolomonConfig, R as ReedSolomonErasureCodingProvider, e as ReedSolomonProviderOptions } from '../../clay-codes-DHP-bYcP.js';
2
+ export { d as ReedSolomonConfig, R as ReedSolomonErasureCodingProvider, e as ReedSolomonProviderOptions } from '../../clay-codes-DdXABBDx.js';
@@ -1,7 +1,71 @@
1
- import {
2
- ReedSolomonErasureCodingProvider
3
- } from "../../chunk-NHWWORCH.mjs";
4
- import "../../chunk-7P6ASYW6.mjs";
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
+ const enumIndex = -1;
13
+ if (erasure_k <= 0)
14
+ throw new Error("erasure_k (number of data chunks) must be > 0");
15
+ if (erasure_n <= erasure_k)
16
+ throw new Error(
17
+ `erasure_n (${erasure_n}) must be > erasure_k (${erasure_k})`
18
+ );
19
+ if (chunkSizeBytes <= 0) throw new Error("chunkSizeBytes must be > 0");
20
+ this.config = {
21
+ erasure_n,
22
+ erasure_k,
23
+ chunkSizeBytes,
24
+ enumIndex
25
+ };
26
+ }
27
+ encode(data) {
28
+ const { erasure_k, erasure_n, chunkSizeBytes } = this.config;
29
+ const erasure_m = erasure_n - erasure_k;
30
+ const systematicCapacity = erasure_k * chunkSizeBytes;
31
+ if (data.byteLength > systematicCapacity) {
32
+ throw new Error(
33
+ `Data size ${data.byteLength} bytes exceeds systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}).`
34
+ );
35
+ }
36
+ if (data.byteLength !== systematicCapacity) {
37
+ throw new Error(
38
+ `Data size ${data.byteLength} bytes does not match systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}). Provide pre-padded data before encoding.`
39
+ );
40
+ }
41
+ const reedSolomon = createWasmReedSolomonBinding();
42
+ const shards = new Uint8Array(
43
+ systematicCapacity + erasure_m * chunkSizeBytes
44
+ );
45
+ shards.set(data, 0);
46
+ reedSolomon.encode(shards, erasure_k, erasure_m);
47
+ const chunks = new Array(erasure_n);
48
+ for (let idx = 0; idx < erasure_n; idx++) {
49
+ const start = idx * chunkSizeBytes;
50
+ chunks[idx] = shards.slice(start, start + chunkSizeBytes);
51
+ }
52
+ return {
53
+ chunks,
54
+ systematic: chunks.slice(0, erasure_k),
55
+ parity: chunks.slice(erasure_k)
56
+ };
57
+ }
58
+ decode(_available, _config) {
59
+ throw new Error(
60
+ "ReedSolomonErasureCodingProvider does not implement decode"
61
+ );
62
+ }
63
+ getChunkMerkleRoots() {
64
+ throw new Error(
65
+ "ReedSolomonErasureCodingProvider does not implement getChunkMerkleRoots"
66
+ );
67
+ }
68
+ };
5
69
  export {
6
70
  ReedSolomonErasureCodingProvider
7
71
  };
@@ -1,4 +1,4 @@
1
- import { a as ErasureCodingProvider } from '../../clay-codes-DHP-bYcP.js';
1
+ import { a as ErasureCodingProvider } from '../../clay-codes-DdXABBDx.js';
2
2
  import '@shelby-protocol/clay-codes';
3
3
 
4
4
  declare function allocateAndCopy(data: Uint8Array, desiredLength: number): Uint8Array;
@@ -1,5 +1,3 @@
1
- import "../../chunk-7P6ASYW6.mjs";
2
-
3
1
  // src/core/erasure/utils.ts
4
2
  function allocateAndCopy(data, desiredLength) {
5
3
  if (data.byteLength === desiredLength) {
@@ -1,11 +1,32 @@
1
- import {
2
- ShelbyErrorCodes,
3
- isAccessDeniedError,
4
- isBlobAlreadyExistsError,
5
- isBlobExpiredError,
6
- isBlobNotFoundError
7
- } from "../chunk-CQ6QPIZK.mjs";
8
- import "../chunk-7P6ASYW6.mjs";
1
+ // src/core/errors.ts
2
+ var ShelbyErrorCodes = {
3
+ // blob_metadata.move errors
4
+ E_BLOB_NOT_FOUND: "E_BLOB_NOT_FOUND",
5
+ E_INVALID_EXPIRATION_TIME: "E_INVALID_EXPIRATION_TIME",
6
+ E_TEST_ENCODING_NOT_ALLOWED: "E_TEST_ENCODING_NOT_ALLOWED",
7
+ E_BLOB_NOT_EXPIRED: "E_BLOB_NOT_EXPIRED",
8
+ E_INVALID_CHUNKSET_COUNT: "E_INVALID_CHUNKSET_COUNT",
9
+ E_NOT_BLOB_OWNER: "E_NOT_BLOB_OWNER",
10
+ E_NOT_ADMIN: "E_NOT_ADMIN",
11
+ E_BLOB_EXPIRED: "E_BLOB_EXPIRED",
12
+ E_BLOB_NAME_TOO_LONG: "E_BLOB_NAME_TOO_LONG",
13
+ E_INVALID_PAYMENT_EPOCHS: "E_INVALID_PAYMENT_EPOCHS",
14
+ E_NO_SLICES_AVAILABLE: "E_NO_SLICES_AVAILABLE",
15
+ // Common Aptos/Move errors
16
+ EALREADY_EXISTS: "EALREADY_EXISTS"
17
+ };
18
+ function isBlobAlreadyExistsError(errorMessage) {
19
+ return errorMessage.includes(ShelbyErrorCodes.EALREADY_EXISTS) || errorMessage.includes("already exists");
20
+ }
21
+ function isAccessDeniedError(errorMessage) {
22
+ return errorMessage.includes(ShelbyErrorCodes.E_NOT_BLOB_OWNER) || errorMessage.includes(ShelbyErrorCodes.E_NOT_ADMIN) || errorMessage.includes("ENOT_AUTHORIZED") || errorMessage.includes("not authorized") || errorMessage.includes("permission denied");
23
+ }
24
+ function isBlobNotFoundError(errorMessage) {
25
+ return errorMessage.includes(ShelbyErrorCodes.E_BLOB_NOT_FOUND);
26
+ }
27
+ function isBlobExpiredError(errorMessage) {
28
+ return errorMessage.includes(ShelbyErrorCodes.E_BLOB_EXPIRED);
29
+ }
9
30
  export {
10
31
  ShelbyErrorCodes,
11
32
  isAccessDeniedError,
@@ -7,17 +7,17 @@ export { ShelbyClientConfig, ShelbyIndexerConfig, ShelbyRPCConfig } from './clie
7
7
  export { ShelbyMetadataClient } from './clients/ShelbyMetadataClient.js';
8
8
  export { ShelbyMicropaymentChannelClient } from './clients/ShelbyMicropaymentChannelClient.js';
9
9
  export { ShelbyPlacementGroupClient } from './clients/ShelbyPlacementGroupClient.js';
10
- export { BlobDataSource, PutBlobProgress, ShelbyRPCClient } from './clients/ShelbyRPCClient.js';
11
- export { BlobCommitments, BlobCommitmentsSchema, COMMITMENT_SCHEMA_VERSION, ChunksetCommitment, ChunksetCommitmentSchema, GenerateCommitmentsOptions, expectedTotalChunksets, generateCommitments, generateMerkleRoot } from './commitments.js';
10
+ export { AuthScheme, BlobDataSource, BlobOwnerAuth, DerivableBlobOwnerAuth, Ed25519BlobOwnerAuth, PutBlobProgress, ShelbyRPCClient } from './clients/ShelbyRPCClient.js';
11
+ export { BlobCommitments, BlobCommitmentsSchema, COMMITMENT_SCHEMA_VERSION, ChunksetCommitment, ChunksetCommitmentSchema, expectedTotalChunksets, generateCommitments, generateMerkleRoot } from './commitments.js';
12
12
  export { DEFAULT_PROJECT_DESCRIPTION, DEFAULT_PROJECT_NAME, MICROPAYMENTS_DEPLOYER, NetworkToGasStationBaseUrl, NetworkToShelbyBlobIndexerBaseUrl, NetworkToShelbyRPCBaseUrl, SHELBYUSD_FA_METADATA_ADDRESS, SHELBYUSD_TOKEN_ADDRESS, SHELBYUSD_TOKEN_MODULE, SHELBYUSD_TOKEN_NAME, SHELBY_DEPLOYER, TOKEN_DEPLOYER, TOKEN_OBJECT_ADDRESS } from './constants.js';
13
- export { C as ClayErasureCodingProvider, D as DecodeConfig, E as ErasureCodingConfig, a as ErasureCodingProvider, R as ReedSolomonErasureCodingProvider } from '../clay-codes-DHP-bYcP.js';
13
+ export { C as ClayErasureCodingProvider, D as DecodeConfig, E as ErasureCodingConfig, a as ErasureCodingProvider, R as ReedSolomonErasureCodingProvider } from '../clay-codes-DdXABBDx.js';
14
14
  export { DEFAULT_ERASURE_D, DEFAULT_ERASURE_K, DEFAULT_ERASURE_M, DEFAULT_ERASURE_N, DEFAULT_SAMPLE_SIZE, ERASURE_CODE_PARAMS, ErasureCodeParams, ErasureCodingScheme, ErasureSchemeParams } from './erasure/constants.js';
15
15
  export { createDefaultErasureCodingProvider, defaultErasureCodingConfig, erasureCodingConfig16Total10Data13Helper, erasureCodingConfig4Total2Data3Helper } from './erasure/default.js';
16
16
  export { ShelbyErrorCodes, isAccessDeniedError, isBlobAlreadyExistsError, isBlobExpiredError, isBlobNotFoundError } from './errors.js';
17
17
  export { BlobName, BlobNameSchema, ChunkKey } from './layout.js';
18
18
  export { ShelbyNetwork, isShelbyNetwork, shelbyNetworks } from './networks.js';
19
19
  export { ShelbyIndexerClient, createShelbyIndexerClient, getShelbyIndexerClient } from './operations/index.js';
20
- export { CompleteMultipartUploadResponse, CompleteMultipartUploadResponseSchema, RPCErrorResponse, RPCErrorResponseSchema, StaleMicropaymentErrorResponse, StaleMicropaymentErrorResponseSchema, StartMultipartUploadResponse, StartMultipartUploadResponseSchema, UploadPartResponse, UploadPartResponseSchema } from './rpc-responses.js';
20
+ export { ChallengeResponse, ChallengeResponseSchema, CompleteMultipartUploadResponse, CompleteMultipartUploadResponseSchema, MultipartUploadStatusResponse, MultipartUploadStatusResponseSchema, RPCErrorResponse, RPCErrorResponseSchema, StaleMicropaymentErrorResponse, StaleMicropaymentErrorResponseSchema, StartMultipartUploadResponse, StartMultipartUploadResponseSchema, UploadPartResponse, UploadPartResponseSchema } from './rpc-responses.js';
21
21
  export { getShelbyAccountBlobsExplorerUrl, getShelbyAccountExplorerUrl, getShelbyBlobExplorerUrl } from './shelby-explorer.js';
22
22
  export { BlobActivity, BlobActivityType, BlobEncoding, BlobMetadata, ClayEncoding, StorageProviderAck } from './types/blobs.js';
23
23
  export { ChannelInfo, SenderBuiltMicropayment, StaleChannelStateError } from './types/payments.js';