@shelby-protocol/sdk 0.3.0 → 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.
- package/dist/browser/index.d.ts +12 -3
- package/dist/browser/index.mjs +3717 -142
- package/dist/core/aptos-explorer.mjs +46 -5
- package/dist/core/blobs.mjs +12 -4
- package/dist/core/chunk.mjs +58 -9
- package/dist/core/clients/ShelbyBlobClient.d.ts +0 -43
- package/dist/core/clients/ShelbyBlobClient.mjs +1084 -17
- package/dist/core/clients/ShelbyClient.d.ts +12 -2
- package/dist/core/clients/ShelbyClient.mjs +2915 -23
- package/dist/core/clients/ShelbyClientConfig.mjs +0 -1
- package/dist/core/clients/ShelbyMetadataClient.d.ts +0 -18
- package/dist/core/clients/ShelbyMetadataClient.mjs +306 -6
- package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +7 -49
- package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +839 -13
- package/dist/core/clients/ShelbyPlacementGroupClient.mjs +307 -8
- package/dist/core/clients/ShelbyRPCClient.d.ts +106 -3
- package/dist/core/clients/ShelbyRPCClient.mjs +1261 -12
- package/dist/core/clients/index.d.ts +2 -1
- package/dist/core/clients/index.mjs +3420 -39
- package/dist/core/clients/utils.mjs +65 -6
- package/dist/core/commitments.mjs +270 -11
- package/dist/core/constants.d.ts +2 -2
- package/dist/core/constants.mjs +39 -16
- package/dist/core/erasure/clay-codes.mjs +129 -4
- package/dist/core/erasure/constants.mjs +33 -10
- package/dist/core/erasure/default.mjs +191 -9
- package/dist/core/erasure/index.mjs +266 -23
- package/dist/core/erasure/reed-solomon.mjs +68 -4
- package/dist/core/erasure/utils.mjs +0 -2
- package/dist/core/errors.mjs +29 -8
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.mjs +3711 -142
- package/dist/core/layout.mjs +37 -5
- package/dist/core/networks.mjs +10 -5
- package/dist/core/operations/generated/sdk.d.ts +9 -0
- package/dist/core/operations/generated/sdk.mjs +183 -18
- package/dist/core/operations/index.mjs +284 -24
- package/dist/core/promises.mjs +4 -4
- package/dist/core/rpc-responses.mjs +29 -10
- package/dist/core/shelby-explorer.mjs +31 -6
- package/dist/core/strings.mjs +0 -2
- package/dist/core/types/blobs.mjs +0 -1
- package/dist/core/types/index.mjs +230 -9
- package/dist/core/types/payments.d.ts +6 -6
- package/dist/core/types/payments.mjs +230 -5
- package/dist/core/types/placement_groups.mjs +0 -1
- package/dist/core/types/storage_providers.mjs +0 -1
- package/dist/core/utils.mjs +94 -8
- package/dist/node/clients/ShelbyNodeClient.d.ts +1 -0
- package/dist/node/clients/ShelbyNodeClient.mjs +2919 -24
- package/dist/node/clients/index.d.ts +1 -0
- package/dist/node/clients/index.mjs +2920 -26
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.mjs +3734 -149
- package/dist/node/parallel/commitment_worker.d.ts +9 -0
- package/dist/node/parallel/commitment_worker.mjs +298 -0
- package/dist/node/parallel/commitment_worker_pool.d.ts +35 -0
- package/dist/node/parallel/commitment_worker_pool.mjs +286 -0
- package/dist/node/parallel/default_commitment_worker_pool.d.ts +24 -0
- package/dist/node/parallel/default_commitment_worker_pool.mjs +302 -0
- package/dist/node/parallel/index.d.ts +11 -0
- package/dist/node/parallel/index.mjs +563 -0
- package/dist/node/parallel/parallel_commitments.d.ts +32 -0
- package/dist/node/parallel/parallel_commitments.mjs +561 -0
- package/dist/node/parallel/worker_pool.d.ts +74 -0
- package/dist/node/parallel/worker_pool.mjs +248 -0
- package/dist/node/testUtil.mjs +8 -4
- package/package.json +6 -2
- package/dist/chunk-3NRBHSMQ.mjs +0 -12
- package/dist/chunk-5BVSWXQJ.mjs +0 -801
- package/dist/chunk-6FJNAUU5.mjs +0 -278
- package/dist/chunk-6XSZRDLJ.mjs +0 -375
- package/dist/chunk-7P6ASYW6.mjs +0 -9
- package/dist/chunk-A4IG6GSE.mjs +0 -21
- package/dist/chunk-AD2G3QYD.mjs +0 -0
- package/dist/chunk-AUQDI5BS.mjs +0 -43
- package/dist/chunk-AY3HBWXA.mjs +0 -51
- package/dist/chunk-BDSW5PHM.mjs +0 -37
- package/dist/chunk-C6RQ3AEU.mjs +0 -51
- package/dist/chunk-CQ6QPIZK.mjs +0 -37
- package/dist/chunk-D6GQHO6G.mjs +0 -15
- package/dist/chunk-EM67QTMR.mjs +0 -0
- package/dist/chunk-I6NG5GNL.mjs +0 -8
- package/dist/chunk-JTXYKO3U.mjs +0 -38
- package/dist/chunk-KG2TMLEV.mjs +0 -207
- package/dist/chunk-M3CP5TFP.mjs +0 -39
- package/dist/chunk-M7W43K2Q.mjs +0 -505
- package/dist/chunk-MB7C7VQF.mjs +0 -0
- package/dist/chunk-MNCQBEMS.mjs +0 -55
- package/dist/chunk-MQUVYMNQ.mjs +0 -0
- package/dist/chunk-NEO7Z3ZQ.mjs +0 -49
- package/dist/chunk-NHWWORCH.mjs +0 -72
- package/dist/chunk-OEK24ON7.mjs +0 -135
- package/dist/chunk-QQ57OGQ2.mjs +0 -0
- package/dist/chunk-RNNJXTX2.mjs +0 -154
- package/dist/chunk-S6Q4OG7H.mjs +0 -83
- package/dist/chunk-TET3DJEO.mjs +0 -199
- package/dist/chunk-UEZNZBJO.mjs +0 -104
- package/dist/chunk-V46D5NBW.mjs +0 -11
- package/dist/chunk-V4B3GAMQ.mjs +0 -42
- package/dist/chunk-WFWRBNTW.mjs +0 -412
- package/dist/chunk-WTICJPDB.mjs +0 -0
- package/dist/chunk-XNEIWM4O.mjs +0 -0
- package/dist/chunk-Z4FZ7W6L.mjs +0 -39
- package/dist/chunk-Z7RFCADT.mjs +0 -0
- package/dist/chunk-ZHXCVRZX.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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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,27 +1,270 @@
|
|
|
1
|
-
|
|
1
|
+
// src/core/erasure/clay-codes.ts
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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,7 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
};
|
package/dist/core/errors.mjs
CHANGED
|
@@ -1,11 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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,
|
package/dist/core/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ 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';
|
|
10
|
+
export { AuthScheme, BlobDataSource, BlobOwnerAuth, DerivableBlobOwnerAuth, Ed25519BlobOwnerAuth, PutBlobProgress, ShelbyRPCClient } from './clients/ShelbyRPCClient.js';
|
|
11
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
13
|
export { C as ClayErasureCodingProvider, D as DecodeConfig, E as ErasureCodingConfig, a as ErasureCodingProvider, R as ReedSolomonErasureCodingProvider } from '../clay-codes-DdXABBDx.js';
|