@shelby-protocol/sdk 0.0.1-experimental.4 → 0.0.2
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/README.md +41 -0
- package/dist/browser/index.d.ts +17 -8
- package/dist/browser/index.mjs +84 -35
- package/dist/chunk-3ZDXWPYC.mjs +65 -0
- package/dist/chunk-75VHXY5P.mjs +48 -0
- package/dist/chunk-APML3CGJ.mjs +176 -0
- package/dist/chunk-DLMDDEWF.mjs +112 -0
- package/dist/{chunk-GGYTHP5F.mjs → chunk-FIFKKWXV.mjs} +19 -17
- package/dist/chunk-HPVCKAN2.mjs +41 -0
- package/dist/chunk-KBUWZXFA.mjs +92 -0
- package/dist/{chunk-C33H3C3N.mjs → chunk-LSNN4V5F.mjs} +1 -1
- package/dist/chunk-LTV26KU4.mjs +141 -0
- package/dist/{chunk-2FF5FICZ.mjs → chunk-NRNVAY72.mjs} +97 -43
- package/dist/chunk-NTJSNNA7.mjs +175 -0
- package/dist/{chunk-QEMIORTL.mjs → chunk-OTBLZL2S.mjs} +1 -1
- package/dist/chunk-QP2C6ORP.mjs +177 -0
- package/dist/chunk-RBFWGDMY.mjs +30 -0
- package/dist/chunk-VRLIOKWG.mjs +11 -0
- package/dist/chunk-XGMJ4CG4.mjs +384 -0
- package/dist/chunk-Z7RFCADT.mjs +0 -0
- package/dist/chunk-ZPW742E7.mjs +28 -0
- package/dist/clay-codes-Ce9EmXfa.d.ts +129 -0
- package/dist/core/blobs.mjs +1 -1
- package/dist/core/chunk.d.ts +34 -0
- package/dist/core/chunk.mjs +17 -0
- package/dist/core/clients/ShelbyBlobClient.d.ts +121 -89
- package/dist/core/clients/ShelbyBlobClient.mjs +11 -3
- package/dist/core/clients/ShelbyClient.d.ts +71 -30
- package/dist/core/clients/ShelbyClient.mjs +14 -9
- package/dist/core/clients/ShelbyClientConfig.d.ts +43 -9
- package/dist/core/clients/ShelbyClientConfig.mjs +1 -0
- package/dist/core/clients/ShelbyRPCClient.d.ts +47 -20
- package/dist/core/clients/ShelbyRPCClient.mjs +10 -3
- package/dist/core/clients/index.d.ts +10 -5
- package/dist/core/clients/index.mjs +18 -12
- package/dist/core/clients/utils.d.ts +7 -0
- package/dist/core/clients/utils.mjs +7 -0
- package/dist/core/commitments.d.ts +18 -18
- package/dist/core/commitments.mjs +7 -5
- package/dist/core/constants.d.ts +24 -19
- package/dist/core/constants.mjs +15 -15
- package/dist/core/erasure/clay-codes.d.ts +2 -0
- package/dist/core/erasure/clay-codes.mjs +9 -0
- package/dist/core/erasure/constants.d.ts +48 -0
- package/dist/core/erasure/constants.mjs +17 -0
- package/dist/core/erasure/default.d.ts +6 -0
- package/dist/core/erasure/default.mjs +9 -0
- package/dist/core/erasure/index.d.ts +4 -0
- package/dist/core/erasure/index.mjs +27 -0
- package/dist/core/erasure/provider.d.ts +2 -0
- package/dist/core/erasure/provider.mjs +0 -0
- package/dist/core/erasure/reed-solomon.d.ts +2 -0
- package/dist/core/erasure/reed-solomon.mjs +7 -0
- package/dist/core/erasure/utils.d.ts +12 -0
- package/dist/core/erasure/utils.mjs +33 -0
- package/dist/core/index.d.ts +17 -8
- package/dist/core/index.mjs +84 -35
- package/dist/core/layout.mjs +4 -2
- package/dist/core/networks.d.ts +7 -0
- package/dist/core/networks.mjs +9 -0
- package/dist/core/operations/generated/sdk.d.ts +686 -0
- package/dist/core/operations/generated/sdk.mjs +23 -0
- package/dist/core/operations/index.d.ts +31 -0
- package/dist/core/operations/index.mjs +12 -0
- package/dist/core/strings.d.ts +6 -0
- package/dist/core/strings.mjs +9 -0
- package/dist/core/types/blobs.d.ts +49 -79
- package/dist/core/types/encodings.d.ts +5 -13
- package/dist/core/types/encodings.mjs +0 -1
- package/dist/core/types/index.d.ts +4 -2
- package/dist/core/types/index.mjs +1 -1
- package/dist/core/types/placement_groups.d.ts +15 -0
- package/dist/core/types/placement_groups.mjs +0 -0
- package/dist/core/types/storage_providers.d.ts +31 -0
- package/dist/core/types/storage_providers.mjs +1 -0
- package/dist/core/utils.d.ts +15 -3
- package/dist/core/utils.mjs +5 -3
- package/dist/node/clients/ShelbyMetadataClient.d.ts +72 -0
- package/dist/node/clients/ShelbyMetadataClient.mjs +9 -0
- package/dist/node/clients/ShelbyNodeClient.d.ts +8 -3
- package/dist/node/clients/ShelbyNodeClient.mjs +15 -10
- package/dist/node/clients/index.d.ts +12 -5
- package/dist/node/clients/index.mjs +20 -11
- package/dist/node/index.d.ts +18 -8
- package/dist/node/index.mjs +90 -37
- package/package.json +17 -5
- package/dist/chunk-5Z3RVWU3.mjs +0 -67
- package/dist/chunk-B3CB2YEO.mjs +0 -318
- package/dist/chunk-D2FERD4A.mjs +0 -39
- package/dist/chunk-G263DBCY.mjs +0 -105
- package/dist/chunk-P7BVGLTV.mjs +0 -32
- package/dist/chunk-QM5BVKLD.mjs +0 -109
- package/dist/core/erasure.d.ts +0 -6
- package/dist/core/erasure.mjs +0 -7
- /package/dist/{chunk-7S6RVKYB.mjs → chunk-MB7C7VQF.mjs} +0 -0
- /package/dist/{chunk-IHTPXUYI.mjs → chunk-MQUVYMNQ.mjs} +0 -0
- /package/dist/{chunk-PLUDE5C3.mjs → chunk-RNXGC54D.mjs} +0 -0
- /package/dist/{chunk-QKT5R735.mjs → chunk-TUANYVZQ.mjs} +0 -0
package/README.md
CHANGED
|
@@ -29,6 +29,47 @@ import { ShelbyBlob } from '@shelby-protocol/sdk/browser';
|
|
|
29
29
|
// Your code here...
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
### Working with Erasure Coding Providers
|
|
33
|
+
|
|
34
|
+
The SDK supports two patterns for managing erasure coding providers:
|
|
35
|
+
|
|
36
|
+
#### Default Pattern (Recommended for most users)
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { ShelbyClient } from '@shelby-protocol/sdk';
|
|
40
|
+
|
|
41
|
+
// Provider is created internally on first use
|
|
42
|
+
const client = new ShelbyClient(config);
|
|
43
|
+
|
|
44
|
+
// The client will automatically create and manage the provider
|
|
45
|
+
await client.upload({
|
|
46
|
+
blobData: data,
|
|
47
|
+
signer: account,
|
|
48
|
+
blobName: "example.txt",
|
|
49
|
+
expirationMicros: Date.now() * 1000 + 3600_000_000,
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### Shared Provider Pattern (For advanced use cases)
|
|
54
|
+
|
|
55
|
+
When working with multiple clients (e.g., different networks), you can share a single provider instance:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { ShelbyClient, ClayErasureCodingProvider } from '@shelby-protocol/sdk';
|
|
59
|
+
|
|
60
|
+
// Create a single provider instance
|
|
61
|
+
const provider = await ClayErasureCodingProvider.create();
|
|
62
|
+
|
|
63
|
+
// Share it across multiple clients
|
|
64
|
+
const mainnetClient = new ShelbyClient(mainnetConfig, provider);
|
|
65
|
+
const devnetClient = new ShelbyClient(devnetConfig, provider);
|
|
66
|
+
const testnetClient = new ShelbyClient(testnetConfig, provider);
|
|
67
|
+
|
|
68
|
+
// All clients use the same provider instance
|
|
69
|
+
await mainnetClient.upload({ /* ... */ });
|
|
70
|
+
await devnetClient.upload({ /* ... */ });
|
|
71
|
+
```
|
|
72
|
+
|
|
32
73
|
## Peer Dependencies
|
|
33
74
|
|
|
34
75
|
- `@aptos-labs/ts-sdk`
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
export { ShelbyBlob, createBlobKey } from '../core/blobs.js';
|
|
2
|
+
export { CHUNK_SIZE_PARAMS, ChunkSizeScheme, DEFAULT_CHUNKSET_SIZE_BYTES, DEFAULT_CHUNK_SIZE_BYTES, ERASURE_CODE_AND_CHUNK_MAPPING } from '../core/chunk.js';
|
|
2
3
|
export { ShelbyBlobClient } from '../core/clients/ShelbyBlobClient.js';
|
|
3
|
-
export { ShelbyClient } from '../core/clients/ShelbyClient.js';
|
|
4
|
-
export { ShelbyClientConfig } from '../core/clients/ShelbyClientConfig.js';
|
|
4
|
+
export { ShelbyClient, UploadOptions } from '../core/clients/ShelbyClient.js';
|
|
5
|
+
export { ShelbyClientConfig, ShelbyIndexerConfig, ShelbyRPCConfig } from '../core/clients/ShelbyClientConfig.js';
|
|
5
6
|
export { ShelbyRPCClient } from '../core/clients/ShelbyRPCClient.js';
|
|
6
|
-
export { BlobCommitments, BlobCommitmentsSchema, ChunksetCommitment, ChunksetCommitmentSchema, generateCommitments } from '../core/commitments.js';
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
7
|
+
export { BlobCommitments, BlobCommitmentsSchema, ChunksetCommitment, ChunksetCommitmentSchema, GenerateCommitmentsOptions, expectedTotalChunksets, generateCommitments } from '../core/commitments.js';
|
|
8
|
+
export { DEFAULT_PROJECT_DESCRIPTION, DEFAULT_PROJECT_NAME, NetworkToShelbyBlobIndexerBaseUrl, NetworkToShelbyRPCBaseUrl, SHELBYUSD_TOKEN_ADDRESS, SHELBYUSD_TOKEN_MODULE, SHELBYUSD_TOKEN_NAME, SHELBYUSD_TOKEN_TYPE, SHELBY_DEPLOYER, TOKEN_DEPLOYER, TOKEN_OBJECT_ADDRESS } from '../core/constants.js';
|
|
9
|
+
export { C as ClayErasureCodingProvider, D as DecodeConfig, E as ErasureCodingConfig, a as ErasureCodingProvider, R as ReedSolomonErasureCodingProvider } from '../clay-codes-Ce9EmXfa.js';
|
|
10
|
+
export { DEFAULT_ERASURE_D, DEFAULT_ERASURE_K, DEFAULT_ERASURE_M, DEFAULT_ERASURE_N, ERASURE_CODE_PARAMS, ErasureCodeParams, ErasureCodingScheme, ErasureSchemeParams } from '../core/erasure/constants.js';
|
|
11
|
+
export { createDefaultErasureCodingProvider } from '../core/erasure/default.js';
|
|
9
12
|
export { BlobName, BlobNameSchema, ChunkKey, allChunksForBlob, roundSize } from '../core/layout.js';
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
+
export { ShelbyNetwork, isShelbyNetwork, shelbyNetworks } from '../core/networks.js';
|
|
14
|
+
export { ShelbyIndexerClient, createShelbyIndexerClient, getShelbyIndexerClient } from '../core/operations/index.js';
|
|
15
|
+
export { BlobActivity, BlobActivityType, BlobEncoding, BlobMetadata, ClayEncoding } from '../core/types/blobs.js';
|
|
16
|
+
export { StorageProviderInfo } from '../core/types/storage_providers.js';
|
|
17
|
+
export { buildRequestUrl, concatHashes, readInChunks, zeroPadBytes } from '../core/utils.js';
|
|
13
18
|
import '@aptos-labs/ts-sdk';
|
|
14
19
|
import 'zod';
|
|
20
|
+
import '../core/operations/generated/sdk.js';
|
|
21
|
+
import 'graphql';
|
|
22
|
+
import 'graphql-request';
|
|
23
|
+
import '@shelby-protocol/clay-codes';
|
package/dist/browser/index.mjs
CHANGED
|
@@ -1,65 +1,110 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-TUANYVZQ.mjs";
|
|
2
2
|
import "../chunk-MWDW4ROU.mjs";
|
|
3
|
+
import "../chunk-MQUVYMNQ.mjs";
|
|
3
4
|
import "../chunk-ZHXCVRZX.mjs";
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-QKT5R735.mjs";
|
|
5
|
+
import "../chunk-RNXGC54D.mjs";
|
|
6
6
|
import {
|
|
7
7
|
ShelbyClient
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-QP2C6ORP.mjs";
|
|
9
|
+
import {
|
|
10
|
+
ShelbyRPCClient
|
|
11
|
+
} from "../chunk-NRNVAY72.mjs";
|
|
12
|
+
import "../chunk-I6NG5GNL.mjs";
|
|
9
13
|
import {
|
|
10
14
|
ShelbyBlobClient
|
|
11
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-XGMJ4CG4.mjs";
|
|
12
16
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
createShelbyIndexerClient,
|
|
18
|
+
getShelbyIndexerClient
|
|
19
|
+
} from "../chunk-75VHXY5P.mjs";
|
|
20
|
+
import "../chunk-DLMDDEWF.mjs";
|
|
21
|
+
import "../chunk-RBFWGDMY.mjs";
|
|
22
|
+
import "../chunk-Z7RFCADT.mjs";
|
|
15
23
|
import {
|
|
16
24
|
createBlobKey
|
|
17
|
-
} from "../chunk-
|
|
25
|
+
} from "../chunk-OTBLZL2S.mjs";
|
|
18
26
|
import {
|
|
19
27
|
BlobCommitmentsSchema,
|
|
20
28
|
ChunksetCommitmentSchema,
|
|
29
|
+
expectedTotalChunksets,
|
|
21
30
|
generateCommitments
|
|
22
|
-
} from "../chunk-
|
|
31
|
+
} from "../chunk-LTV26KU4.mjs";
|
|
23
32
|
import {
|
|
33
|
+
buildRequestUrl,
|
|
24
34
|
concatHashes,
|
|
25
35
|
readInChunks,
|
|
26
|
-
|
|
27
|
-
} from "../chunk-
|
|
36
|
+
zeroPadBytes
|
|
37
|
+
} from "../chunk-KBUWZXFA.mjs";
|
|
28
38
|
import {
|
|
29
|
-
|
|
30
|
-
|
|
39
|
+
DEFAULT_PROJECT_DESCRIPTION,
|
|
40
|
+
DEFAULT_PROJECT_NAME,
|
|
41
|
+
NetworkToShelbyBlobIndexerBaseUrl,
|
|
42
|
+
NetworkToShelbyRPCBaseUrl,
|
|
43
|
+
SHELBYUSD_TOKEN_ADDRESS,
|
|
44
|
+
SHELBYUSD_TOKEN_MODULE,
|
|
45
|
+
SHELBYUSD_TOKEN_NAME,
|
|
46
|
+
SHELBYUSD_TOKEN_TYPE,
|
|
47
|
+
SHELBY_DEPLOYER,
|
|
48
|
+
TOKEN_DEPLOYER,
|
|
49
|
+
TOKEN_OBJECT_ADDRESS
|
|
50
|
+
} from "../chunk-HPVCKAN2.mjs";
|
|
31
51
|
import {
|
|
32
52
|
BlobNameSchema,
|
|
33
53
|
ChunkKey,
|
|
34
54
|
allChunksForBlob,
|
|
35
55
|
roundSize
|
|
36
|
-
} from "../chunk-
|
|
56
|
+
} from "../chunk-FIFKKWXV.mjs";
|
|
37
57
|
import {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
58
|
+
CHUNK_SIZE_PARAMS,
|
|
59
|
+
ChunkSizeScheme,
|
|
60
|
+
ClayErasureCodingProvider,
|
|
61
|
+
DEFAULT_CHUNKSET_SIZE_BYTES,
|
|
62
|
+
DEFAULT_CHUNK_SIZE_BYTES,
|
|
63
|
+
ERASURE_CODE_AND_CHUNK_MAPPING,
|
|
64
|
+
createDefaultErasureCodingProvider
|
|
65
|
+
} from "../chunk-APML3CGJ.mjs";
|
|
66
|
+
import {
|
|
67
|
+
ReedSolomonErasureCodingProvider
|
|
68
|
+
} from "../chunk-3ZDXWPYC.mjs";
|
|
69
|
+
import {
|
|
70
|
+
DEFAULT_ERASURE_D,
|
|
71
|
+
DEFAULT_ERASURE_K,
|
|
72
|
+
DEFAULT_ERASURE_M,
|
|
73
|
+
DEFAULT_ERASURE_N,
|
|
74
|
+
ERASURE_CODE_PARAMS,
|
|
75
|
+
ErasureCodingScheme
|
|
76
|
+
} from "../chunk-ZPW742E7.mjs";
|
|
77
|
+
import {
|
|
78
|
+
isShelbyNetwork,
|
|
79
|
+
shelbyNetworks
|
|
80
|
+
} from "../chunk-VRLIOKWG.mjs";
|
|
51
81
|
import "../chunk-7P6ASYW6.mjs";
|
|
52
82
|
export {
|
|
53
83
|
BlobCommitmentsSchema,
|
|
54
84
|
BlobNameSchema,
|
|
55
|
-
|
|
85
|
+
CHUNK_SIZE_PARAMS,
|
|
56
86
|
ChunkKey,
|
|
87
|
+
ChunkSizeScheme,
|
|
57
88
|
ChunksetCommitmentSchema,
|
|
89
|
+
ClayErasureCodingProvider,
|
|
90
|
+
DEFAULT_CHUNKSET_SIZE_BYTES,
|
|
91
|
+
DEFAULT_CHUNK_SIZE_BYTES,
|
|
92
|
+
DEFAULT_ERASURE_D,
|
|
93
|
+
DEFAULT_ERASURE_K,
|
|
94
|
+
DEFAULT_ERASURE_M,
|
|
95
|
+
DEFAULT_ERASURE_N,
|
|
58
96
|
DEFAULT_PROJECT_DESCRIPTION,
|
|
59
97
|
DEFAULT_PROJECT_NAME,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
98
|
+
ERASURE_CODE_AND_CHUNK_MAPPING,
|
|
99
|
+
ERASURE_CODE_PARAMS,
|
|
100
|
+
ErasureCodingScheme,
|
|
101
|
+
NetworkToShelbyBlobIndexerBaseUrl,
|
|
102
|
+
NetworkToShelbyRPCBaseUrl,
|
|
103
|
+
ReedSolomonErasureCodingProvider,
|
|
104
|
+
SHELBYUSD_TOKEN_ADDRESS,
|
|
105
|
+
SHELBYUSD_TOKEN_MODULE,
|
|
106
|
+
SHELBYUSD_TOKEN_NAME,
|
|
107
|
+
SHELBYUSD_TOKEN_TYPE,
|
|
63
108
|
SHELBY_DEPLOYER,
|
|
64
109
|
ShelbyBlobClient,
|
|
65
110
|
ShelbyClient,
|
|
@@ -67,13 +112,17 @@ export {
|
|
|
67
112
|
TOKEN_DEPLOYER,
|
|
68
113
|
TOKEN_OBJECT_ADDRESS,
|
|
69
114
|
allChunksForBlob,
|
|
115
|
+
buildRequestUrl,
|
|
70
116
|
concatHashes,
|
|
71
117
|
createBlobKey,
|
|
72
|
-
|
|
118
|
+
createDefaultErasureCodingProvider,
|
|
119
|
+
createShelbyIndexerClient,
|
|
120
|
+
expectedTotalChunksets,
|
|
73
121
|
generateCommitments,
|
|
74
|
-
|
|
75
|
-
|
|
122
|
+
getShelbyIndexerClient,
|
|
123
|
+
isShelbyNetwork,
|
|
76
124
|
readInChunks,
|
|
77
125
|
roundSize,
|
|
78
|
-
|
|
126
|
+
shelbyNetworks,
|
|
127
|
+
zeroPadBytes
|
|
79
128
|
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// src/core/erasure/reed-solomon.ts
|
|
2
|
+
import { createWasmReedSolomonBinding } from "@shelby-protocol/reed-solomon";
|
|
3
|
+
var DEFAULT_ERASURE_K = 10;
|
|
4
|
+
var DEFAULT_ERASURE_N = 16;
|
|
5
|
+
var DEFAULT_CHUNK_SIZE_BYTES = 2 * 1024 * 1024;
|
|
6
|
+
var ReedSolomonErasureCodingProvider = class {
|
|
7
|
+
config;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
const erasure_k = options?.erasure_k ?? DEFAULT_ERASURE_K;
|
|
10
|
+
const erasure_n = options?.erasure_n ?? DEFAULT_ERASURE_N;
|
|
11
|
+
const chunkSizeBytes = options?.chunkSizeBytes ?? DEFAULT_CHUNK_SIZE_BYTES;
|
|
12
|
+
if (erasure_k <= 0)
|
|
13
|
+
throw new Error("erasure_k (number of data chunks) must be > 0");
|
|
14
|
+
if (erasure_n <= erasure_k)
|
|
15
|
+
throw new Error(
|
|
16
|
+
`erasure_n (${erasure_n}) must be > erasure_k (${erasure_k})`
|
|
17
|
+
);
|
|
18
|
+
if (chunkSizeBytes <= 0) throw new Error("chunkSizeBytes must be > 0");
|
|
19
|
+
this.config = {
|
|
20
|
+
erasure_n,
|
|
21
|
+
erasure_k,
|
|
22
|
+
chunkSizeBytes
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
encode(data) {
|
|
26
|
+
const { erasure_k, erasure_n, chunkSizeBytes } = this.config;
|
|
27
|
+
const erasure_m = erasure_n - erasure_k;
|
|
28
|
+
const systematicCapacity = erasure_k * chunkSizeBytes;
|
|
29
|
+
if (data.byteLength > systematicCapacity) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Data size ${data.byteLength} bytes exceeds systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}).`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
if (data.byteLength !== systematicCapacity) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`Data size ${data.byteLength} bytes does not match systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}). Provide pre-padded data before encoding.`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
const reedSolomon = createWasmReedSolomonBinding();
|
|
40
|
+
const shards = new Uint8Array(
|
|
41
|
+
systematicCapacity + erasure_m * chunkSizeBytes
|
|
42
|
+
);
|
|
43
|
+
shards.set(data, 0);
|
|
44
|
+
reedSolomon.encode(shards, erasure_k, erasure_m);
|
|
45
|
+
const chunks = new Array(erasure_n);
|
|
46
|
+
for (let idx = 0; idx < erasure_n; idx++) {
|
|
47
|
+
const start = idx * chunkSizeBytes;
|
|
48
|
+
chunks[idx] = shards.slice(start, start + chunkSizeBytes);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
chunks,
|
|
52
|
+
systematic: chunks.slice(0, erasure_k),
|
|
53
|
+
parity: chunks.slice(erasure_k)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
decode(_available, _config) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
"ReedSolomonErasureCodingProvider does not implement decode"
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
ReedSolomonErasureCodingProvider
|
|
65
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSdk
|
|
3
|
+
} from "./chunk-DLMDDEWF.mjs";
|
|
4
|
+
import {
|
|
5
|
+
getAptosConfig
|
|
6
|
+
} from "./chunk-RBFWGDMY.mjs";
|
|
7
|
+
import {
|
|
8
|
+
NetworkToShelbyBlobIndexerBaseUrl
|
|
9
|
+
} from "./chunk-HPVCKAN2.mjs";
|
|
10
|
+
|
|
11
|
+
// src/core/operations/index.ts
|
|
12
|
+
import { Network } from "@aptos-labs/ts-sdk";
|
|
13
|
+
import { GraphQLClient } from "graphql-request";
|
|
14
|
+
function createShelbyIndexerClient(baseUrl, options) {
|
|
15
|
+
const graphqlClient = new GraphQLClient(baseUrl, options);
|
|
16
|
+
return getSdk(graphqlClient);
|
|
17
|
+
}
|
|
18
|
+
function getShelbyIndexerClient(config) {
|
|
19
|
+
const aptosConfig = config.aptos ?? getAptosConfig(config);
|
|
20
|
+
let { apiKey, baseUrl } = config.indexer ?? {};
|
|
21
|
+
if (!baseUrl) {
|
|
22
|
+
switch (aptosConfig?.network) {
|
|
23
|
+
// TODO: Add endpoints for core networks
|
|
24
|
+
case Network.MAINNET:
|
|
25
|
+
case Network.TESTNET:
|
|
26
|
+
case Network.DEVNET:
|
|
27
|
+
case Network.SHELBYNET:
|
|
28
|
+
baseUrl = NetworkToShelbyBlobIndexerBaseUrl[aptosConfig.network];
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (baseUrl === void 0) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"The ShelbyClientConfig does not support the Shelby indexer. Please configure the endpoint in the ShelbyClientConfig.indexer.endpoint or provide a supported Aptos network."
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return createShelbyIndexerClient(baseUrl, {
|
|
38
|
+
headers: {
|
|
39
|
+
...apiKey ? { Authorization: `Bearer ${apiKey}` } : {},
|
|
40
|
+
"x-aptos-client": "shelby-ts-sdk"
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
createShelbyIndexerClient,
|
|
47
|
+
getShelbyIndexerClient
|
|
48
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ERASURE_D,
|
|
3
|
+
DEFAULT_ERASURE_K,
|
|
4
|
+
DEFAULT_ERASURE_N
|
|
5
|
+
} from "./chunk-ZPW742E7.mjs";
|
|
6
|
+
|
|
7
|
+
// src/core/erasure/clay-codes.ts
|
|
8
|
+
import {
|
|
9
|
+
createDecoder,
|
|
10
|
+
createEncoder
|
|
11
|
+
} from "@shelby-protocol/clay-codes";
|
|
12
|
+
|
|
13
|
+
// src/core/erasure/default.ts
|
|
14
|
+
var defaultProviderPromise;
|
|
15
|
+
function createDefaultErasureCodingProvider() {
|
|
16
|
+
if (!defaultProviderPromise) {
|
|
17
|
+
defaultProviderPromise = ClayErasureCodingProvider.create({
|
|
18
|
+
erasure_n: DEFAULT_ERASURE_N,
|
|
19
|
+
erasure_k: DEFAULT_ERASURE_K,
|
|
20
|
+
erasure_d: DEFAULT_ERASURE_D,
|
|
21
|
+
chunkSizeBytes: DEFAULT_CHUNK_SIZE_BYTES
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return defaultProviderPromise;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/core/chunk.ts
|
|
28
|
+
var ChunkSizeScheme = /* @__PURE__ */ ((ChunkSizeScheme2) => {
|
|
29
|
+
ChunkSizeScheme2["ChunkSet10MiB_Chunk1MiB"] = "ChunkSet10MiB_Chunk1MiB";
|
|
30
|
+
return ChunkSizeScheme2;
|
|
31
|
+
})(ChunkSizeScheme || {});
|
|
32
|
+
var CHUNK_SIZE_PARAMS = {
|
|
33
|
+
["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */]: {
|
|
34
|
+
// 1MiB
|
|
35
|
+
chunkSizeBytes: 1 * 1024 * 1024,
|
|
36
|
+
// 10MiB
|
|
37
|
+
chunksetSizeBytes: 10 * 1024 * 1024
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var DEFAULT_CHUNK_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */].chunkSizeBytes;
|
|
41
|
+
var DEFAULT_CHUNKSET_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */].chunksetSizeBytes;
|
|
42
|
+
var ERASURE_CODE_AND_CHUNK_MAPPING = {
|
|
43
|
+
["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */]: {
|
|
44
|
+
...CHUNK_SIZE_PARAMS.ChunkSet10MiB_Chunk1MiB
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/core/erasure/clay-codes.ts
|
|
49
|
+
function getTotalChunks(config) {
|
|
50
|
+
return config.erasure_n;
|
|
51
|
+
}
|
|
52
|
+
var ClayErasureCodingProvider = class _ClayErasureCodingProvider {
|
|
53
|
+
config;
|
|
54
|
+
encoderCache;
|
|
55
|
+
decoderCache;
|
|
56
|
+
constructor(config) {
|
|
57
|
+
this.config = config;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Static factory method to create an initialized ClayErasureCodingProvider
|
|
61
|
+
*/
|
|
62
|
+
static async create(options) {
|
|
63
|
+
const config = buildClayConfig({
|
|
64
|
+
erasure_n: options?.erasure_n ?? DEFAULT_ERASURE_N,
|
|
65
|
+
erasure_k: options?.erasure_k ?? DEFAULT_ERASURE_K,
|
|
66
|
+
erasure_d: options?.erasure_d ?? DEFAULT_ERASURE_D,
|
|
67
|
+
chunkSizeBytes: options?.chunkSizeBytes ?? DEFAULT_CHUNK_SIZE_BYTES
|
|
68
|
+
});
|
|
69
|
+
const provider = new _ClayErasureCodingProvider(config);
|
|
70
|
+
[provider.encoderCache, provider.decoderCache] = await Promise.all([
|
|
71
|
+
createEncoder({
|
|
72
|
+
n: getTotalChunks(config),
|
|
73
|
+
k: config.erasure_k,
|
|
74
|
+
d: config.erasure_d,
|
|
75
|
+
chunkSizeBytes: config.chunkSizeBytes
|
|
76
|
+
}),
|
|
77
|
+
createDecoder({
|
|
78
|
+
n: getTotalChunks(config),
|
|
79
|
+
k: config.erasure_k,
|
|
80
|
+
d: config.erasure_d,
|
|
81
|
+
chunkSizeBytes: config.chunkSizeBytes,
|
|
82
|
+
erasedChunksMask: 0
|
|
83
|
+
// No chunks erased initially; will be reconfigured on decode
|
|
84
|
+
})
|
|
85
|
+
]);
|
|
86
|
+
return provider;
|
|
87
|
+
}
|
|
88
|
+
encode(data) {
|
|
89
|
+
const { erasure_k, chunkSizeBytes } = this.config;
|
|
90
|
+
if (!this.encoderCache) {
|
|
91
|
+
throw new Error("Encoder cache is missing");
|
|
92
|
+
}
|
|
93
|
+
const systematicCapacity = erasure_k * chunkSizeBytes;
|
|
94
|
+
if (data.byteLength > systematicCapacity) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`Data size ${data.byteLength} bytes exceeds systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}).`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
if (this.requiresPadding(data.length)) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Data size ${data.length} bytes does not match systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}). Provide pre-padded data before encoding.`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return this.encoderCache.erasureCode(data);
|
|
105
|
+
}
|
|
106
|
+
decode(available, config) {
|
|
107
|
+
if (!this.decoderCache) {
|
|
108
|
+
throw new Error("Decoder cache is missing");
|
|
109
|
+
}
|
|
110
|
+
const { erasure_k, chunkSizeBytes } = this.config;
|
|
111
|
+
if (available.length < erasure_k) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
`Insufficient available chunks: need at least ${erasure_k}, received ${available.length}.`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
for (let i = 0; i < available.length; i++) {
|
|
117
|
+
const chunk = available[i];
|
|
118
|
+
if (chunk.length !== chunkSizeBytes) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
`Chunk ${i} size ${chunk.length} bytes does not match expected chunkSizeBytes ${chunkSizeBytes}.`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return this.decoderCache.decode(available, config);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Determines if data can be erasure coded as-is or requires padding.
|
|
128
|
+
*
|
|
129
|
+
* Data can be erasure coded without padding if its size exactly matches
|
|
130
|
+
* the total systematic data capacity (k * chunkSizeBytes).
|
|
131
|
+
*
|
|
132
|
+
* @param dataSize - Size of the data in bytes
|
|
133
|
+
* @returns true if data needs padding, false if it can be coded as-is
|
|
134
|
+
*/
|
|
135
|
+
requiresPadding(dataSize) {
|
|
136
|
+
const { erasure_k, chunkSizeBytes } = this.config;
|
|
137
|
+
const systematicCapacity = erasure_k * chunkSizeBytes;
|
|
138
|
+
return dataSize !== systematicCapacity;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
function buildClayConfig(input) {
|
|
142
|
+
const { erasure_n, erasure_k, erasure_d, chunkSizeBytes } = input;
|
|
143
|
+
if (erasure_n <= 0)
|
|
144
|
+
throw new Error("erasure_n (total number of chunks) must be > 0");
|
|
145
|
+
if (erasure_k <= 0)
|
|
146
|
+
throw new Error("erasure_k (number of data chunks) must be > 0");
|
|
147
|
+
if (erasure_k >= erasure_n)
|
|
148
|
+
throw new Error(
|
|
149
|
+
`erasure_k (${erasure_k}) must be < erasure_n (${erasure_n})`
|
|
150
|
+
);
|
|
151
|
+
if (erasure_d <= erasure_k)
|
|
152
|
+
throw new Error(
|
|
153
|
+
`erasure_d (${erasure_d}) must be > erasure_k (${erasure_k})`
|
|
154
|
+
);
|
|
155
|
+
if (erasure_d >= erasure_n)
|
|
156
|
+
throw new Error(
|
|
157
|
+
`erasure_d (${erasure_d}) must be < erasure_n (${erasure_n})`
|
|
158
|
+
);
|
|
159
|
+
if (chunkSizeBytes <= 0) throw new Error("chunkSizeBytes must be > 0");
|
|
160
|
+
return {
|
|
161
|
+
erasure_n,
|
|
162
|
+
erasure_k,
|
|
163
|
+
erasure_d,
|
|
164
|
+
chunkSizeBytes
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export {
|
|
169
|
+
ClayErasureCodingProvider,
|
|
170
|
+
createDefaultErasureCodingProvider,
|
|
171
|
+
ChunkSizeScheme,
|
|
172
|
+
CHUNK_SIZE_PARAMS,
|
|
173
|
+
DEFAULT_CHUNK_SIZE_BYTES,
|
|
174
|
+
DEFAULT_CHUNKSET_SIZE_BYTES,
|
|
175
|
+
ERASURE_CODE_AND_CHUNK_MAPPING
|
|
176
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// src/core/operations/generated/sdk.ts
|
|
2
|
+
import gql from "graphql-tag";
|
|
3
|
+
var Blob_Activities_Select_Column = /* @__PURE__ */ ((Blob_Activities_Select_Column2) => {
|
|
4
|
+
Blob_Activities_Select_Column2["BlobName"] = "blob_name";
|
|
5
|
+
Blob_Activities_Select_Column2["EventIndex"] = "event_index";
|
|
6
|
+
Blob_Activities_Select_Column2["EventType"] = "event_type";
|
|
7
|
+
Blob_Activities_Select_Column2["Timestamp"] = "timestamp";
|
|
8
|
+
Blob_Activities_Select_Column2["TransactionHash"] = "transaction_hash";
|
|
9
|
+
Blob_Activities_Select_Column2["TransactionVersion"] = "transaction_version";
|
|
10
|
+
return Blob_Activities_Select_Column2;
|
|
11
|
+
})(Blob_Activities_Select_Column || {});
|
|
12
|
+
var Blobs_Select_Column = /* @__PURE__ */ ((Blobs_Select_Column2) => {
|
|
13
|
+
Blobs_Select_Column2["BlobCommitment"] = "blob_commitment";
|
|
14
|
+
Blobs_Select_Column2["BlobName"] = "blob_name";
|
|
15
|
+
Blobs_Select_Column2["CreatedAt"] = "created_at";
|
|
16
|
+
Blobs_Select_Column2["ExpiresAt"] = "expires_at";
|
|
17
|
+
Blobs_Select_Column2["IsDeleted"] = "is_deleted";
|
|
18
|
+
Blobs_Select_Column2["IsWritten"] = "is_written";
|
|
19
|
+
Blobs_Select_Column2["NumChunksets"] = "num_chunksets";
|
|
20
|
+
Blobs_Select_Column2["Owner"] = "owner";
|
|
21
|
+
Blobs_Select_Column2["PlacementGroup"] = "placement_group";
|
|
22
|
+
Blobs_Select_Column2["Size"] = "size";
|
|
23
|
+
Blobs_Select_Column2["SliceAddress"] = "slice_address";
|
|
24
|
+
Blobs_Select_Column2["UpdatedAt"] = "updated_at";
|
|
25
|
+
return Blobs_Select_Column2;
|
|
26
|
+
})(Blobs_Select_Column || {});
|
|
27
|
+
var Cursor_Ordering = /* @__PURE__ */ ((Cursor_Ordering2) => {
|
|
28
|
+
Cursor_Ordering2["Asc"] = "ASC";
|
|
29
|
+
Cursor_Ordering2["Desc"] = "DESC";
|
|
30
|
+
return Cursor_Ordering2;
|
|
31
|
+
})(Cursor_Ordering || {});
|
|
32
|
+
var Order_By = /* @__PURE__ */ ((Order_By2) => {
|
|
33
|
+
Order_By2["Asc"] = "asc";
|
|
34
|
+
Order_By2["AscNullsFirst"] = "asc_nulls_first";
|
|
35
|
+
Order_By2["AscNullsLast"] = "asc_nulls_last";
|
|
36
|
+
Order_By2["Desc"] = "desc";
|
|
37
|
+
Order_By2["DescNullsFirst"] = "desc_nulls_first";
|
|
38
|
+
Order_By2["DescNullsLast"] = "desc_nulls_last";
|
|
39
|
+
return Order_By2;
|
|
40
|
+
})(Order_By || {});
|
|
41
|
+
var Placement_Group_Slots_Select_Column = /* @__PURE__ */ ((Placement_Group_Slots_Select_Column2) => {
|
|
42
|
+
Placement_Group_Slots_Select_Column2["PlacementGroup"] = "placement_group";
|
|
43
|
+
Placement_Group_Slots_Select_Column2["SlotIndex"] = "slot_index";
|
|
44
|
+
Placement_Group_Slots_Select_Column2["Status"] = "status";
|
|
45
|
+
Placement_Group_Slots_Select_Column2["StorageProvider"] = "storage_provider";
|
|
46
|
+
Placement_Group_Slots_Select_Column2["UpdatedAt"] = "updated_at";
|
|
47
|
+
return Placement_Group_Slots_Select_Column2;
|
|
48
|
+
})(Placement_Group_Slots_Select_Column || {});
|
|
49
|
+
var Processor_Status_Select_Column = /* @__PURE__ */ ((Processor_Status_Select_Column2) => {
|
|
50
|
+
Processor_Status_Select_Column2["LastSuccessVersion"] = "last_success_version";
|
|
51
|
+
Processor_Status_Select_Column2["LastTransactionTimestamp"] = "last_transaction_timestamp";
|
|
52
|
+
Processor_Status_Select_Column2["LastUpdated"] = "last_updated";
|
|
53
|
+
return Processor_Status_Select_Column2;
|
|
54
|
+
})(Processor_Status_Select_Column || {});
|
|
55
|
+
var GetBlobsDocument = gql`
|
|
56
|
+
query getBlobs($where: blobs_bool_exp, $orderBy: [blobs_order_by!], $limit: Int, $offset: Int) {
|
|
57
|
+
blobs(where: $where, order_by: $orderBy, limit: $limit, offset: $offset) {
|
|
58
|
+
owner
|
|
59
|
+
blob_commitment
|
|
60
|
+
blob_name
|
|
61
|
+
created_at
|
|
62
|
+
expires_at
|
|
63
|
+
num_chunksets
|
|
64
|
+
is_deleted
|
|
65
|
+
is_written
|
|
66
|
+
placement_group
|
|
67
|
+
size
|
|
68
|
+
updated_at
|
|
69
|
+
slice_address
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
var GetBlobActivitiesDocument = gql`
|
|
74
|
+
query getBlobActivities($where: blob_activities_bool_exp, $orderBy: [blob_activities_order_by!], $limit: Int, $offset: Int) {
|
|
75
|
+
blob_activities(
|
|
76
|
+
where: $where
|
|
77
|
+
order_by: $orderBy
|
|
78
|
+
limit: $limit
|
|
79
|
+
offset: $offset
|
|
80
|
+
) {
|
|
81
|
+
blob_name
|
|
82
|
+
event_index
|
|
83
|
+
event_type
|
|
84
|
+
transaction_hash
|
|
85
|
+
transaction_version
|
|
86
|
+
timestamp
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
var defaultWrapper = (action, _operationName, _operationType, _variables) => action();
|
|
91
|
+
function getSdk(client, withWrapper = defaultWrapper) {
|
|
92
|
+
return {
|
|
93
|
+
getBlobs(variables, requestHeaders, signal) {
|
|
94
|
+
return withWrapper((wrappedRequestHeaders) => client.request({ document: GetBlobsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "getBlobs", "query", variables);
|
|
95
|
+
},
|
|
96
|
+
getBlobActivities(variables, requestHeaders, signal) {
|
|
97
|
+
return withWrapper((wrappedRequestHeaders) => client.request({ document: GetBlobActivitiesDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "getBlobActivities", "query", variables);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export {
|
|
103
|
+
Blob_Activities_Select_Column,
|
|
104
|
+
Blobs_Select_Column,
|
|
105
|
+
Cursor_Ordering,
|
|
106
|
+
Order_By,
|
|
107
|
+
Placement_Group_Slots_Select_Column,
|
|
108
|
+
Processor_Status_Select_Column,
|
|
109
|
+
GetBlobsDocument,
|
|
110
|
+
GetBlobActivitiesDocument,
|
|
111
|
+
getSdk
|
|
112
|
+
};
|