@shelby-protocol/sdk 0.0.1-experimental.4 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/dist/browser/index.d.ts +17 -8
- package/dist/browser/index.mjs +83 -34
- package/dist/chunk-3ZDXWPYC.mjs +65 -0
- package/dist/chunk-6MDQI7PW.mjs +177 -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-C33H3C3N.mjs → chunk-EAPAG4L7.mjs} +1 -1
- package/dist/{chunk-GGYTHP5F.mjs → chunk-FIFKKWXV.mjs} +19 -17
- package/dist/chunk-HPVCKAN2.mjs +41 -0
- package/dist/{chunk-2FF5FICZ.mjs → chunk-JSR44EDC.mjs} +96 -42
- package/dist/chunk-KBUWZXFA.mjs +92 -0
- package/dist/chunk-LTV26KU4.mjs +141 -0
- package/dist/chunk-NTJSNNA7.mjs +175 -0
- package/dist/{chunk-QEMIORTL.mjs → chunk-OTBLZL2S.mjs} +1 -1
- 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 +16 -10
- 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 +83 -34
- 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 +89 -36
- package/package.json +25 -12
- 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/dist/chunk-G263DBCY.mjs
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
concatHashes,
|
|
3
|
-
readInChunks,
|
|
4
|
-
zeroPadBuffer
|
|
5
|
-
} from "./chunk-5Z3RVWU3.mjs";
|
|
6
|
-
import {
|
|
7
|
-
erasureEncode
|
|
8
|
-
} from "./chunk-P7BVGLTV.mjs";
|
|
9
|
-
import {
|
|
10
|
-
roundSize
|
|
11
|
-
} from "./chunk-GGYTHP5F.mjs";
|
|
12
|
-
import {
|
|
13
|
-
ERASURE_K,
|
|
14
|
-
ERASURE_M,
|
|
15
|
-
getChunksetSizeBytes
|
|
16
|
-
} from "./chunk-D2FERD4A.mjs";
|
|
17
|
-
|
|
18
|
-
// src/core/commitments.ts
|
|
19
|
-
import { z } from "zod";
|
|
20
|
-
var ChunksetCommitmentSchema = z.object({
|
|
21
|
-
// Chunkset root (vector commitment of child chunks)
|
|
22
|
-
chunkset_root: z.string().nullable(),
|
|
23
|
-
// the size is known statically from the current configuration
|
|
24
|
-
chunk_commitments: z.array(z.string())
|
|
25
|
-
}).refine(
|
|
26
|
-
(data) => {
|
|
27
|
-
return data.chunk_commitments.length === ERASURE_K + ERASURE_M;
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
message: `Chunkset must have exactly ${ERASURE_K + ERASURE_M} chunks (ERASURE_K + ERASURE_M = ${ERASURE_K} + ${ERASURE_M})`,
|
|
31
|
-
path: ["chunk_commitments"]
|
|
32
|
-
}
|
|
33
|
-
);
|
|
34
|
-
function expectedTotalChunksets(rawSize) {
|
|
35
|
-
return roundSize(rawSize) / getChunksetSizeBytes();
|
|
36
|
-
}
|
|
37
|
-
var BlobCommitmentsSchema = z.object({
|
|
38
|
-
schema_version: z.string(),
|
|
39
|
-
raw_data_size: z.number(),
|
|
40
|
-
// FIXME I am not sure about this being here, or if it should be somewhere else
|
|
41
|
-
blob_merkle_root: z.string(),
|
|
42
|
-
chunkset_commitments: z.array(ChunksetCommitmentSchema)
|
|
43
|
-
}).refine(
|
|
44
|
-
(data) => {
|
|
45
|
-
return expectedTotalChunksets(data.raw_data_size) === data.chunkset_commitments.length;
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
message: "Total chunkset count mismatches with raw data size",
|
|
49
|
-
// FIXME put more details in here
|
|
50
|
-
path: ["chunkset_commitments"]
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
async function generateCommitments(fullData, onChunk, options) {
|
|
54
|
-
const chunksetCommitments = [];
|
|
55
|
-
const chunksetCommitmentHashes = [];
|
|
56
|
-
let rawDataSize = 0;
|
|
57
|
-
const chunksetGen = readInChunks(
|
|
58
|
-
fullData,
|
|
59
|
-
options?.chunksetSize ?? getChunksetSizeBytes()
|
|
60
|
-
);
|
|
61
|
-
for await (const [chunksetIdx, chunksetData] of chunksetGen) {
|
|
62
|
-
const chunkCommitments = [];
|
|
63
|
-
rawDataSize += chunksetData.length;
|
|
64
|
-
const paddedChunksetData = zeroPadBuffer(
|
|
65
|
-
chunksetData,
|
|
66
|
-
options?.chunksetSize ?? getChunksetSizeBytes()
|
|
67
|
-
);
|
|
68
|
-
const chunks = await erasureEncode(
|
|
69
|
-
paddedChunksetData,
|
|
70
|
-
options?.erasureK ?? ERASURE_K,
|
|
71
|
-
options?.erasureM ?? ERASURE_M
|
|
72
|
-
);
|
|
73
|
-
let chunkIdx = 0;
|
|
74
|
-
for (const chunkData of chunks) {
|
|
75
|
-
if (onChunk !== void 0) {
|
|
76
|
-
await onChunk(chunksetIdx, chunkIdx, chunkData);
|
|
77
|
-
}
|
|
78
|
-
const chunkHash = await concatHashes([chunkData]);
|
|
79
|
-
chunkCommitments.push(chunkHash);
|
|
80
|
-
chunkIdx += 1;
|
|
81
|
-
}
|
|
82
|
-
const h = await concatHashes(
|
|
83
|
-
chunkCommitments.map((chunk) => chunk.toUint8Array())
|
|
84
|
-
);
|
|
85
|
-
chunksetCommitments.push({
|
|
86
|
-
chunkset_root: h.toString(),
|
|
87
|
-
chunk_commitments: chunkCommitments.map((chunk) => chunk.toString())
|
|
88
|
-
});
|
|
89
|
-
chunksetCommitmentHashes.push(h);
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
schema_version: "1.3",
|
|
93
|
-
raw_data_size: rawDataSize,
|
|
94
|
-
blob_merkle_root: (await concatHashes(
|
|
95
|
-
chunksetCommitmentHashes.map((chunk) => chunk.toUint8Array())
|
|
96
|
-
)).toString(),
|
|
97
|
-
chunkset_commitments: chunksetCommitments
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export {
|
|
102
|
-
ChunksetCommitmentSchema,
|
|
103
|
-
BlobCommitmentsSchema,
|
|
104
|
-
generateCommitments
|
|
105
|
-
};
|
package/dist/chunk-P7BVGLTV.mjs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// src/core/erasure.ts
|
|
2
|
-
import { createWasmReedSolomonBinding } from "@shelby-protocol/reed-solomon";
|
|
3
|
-
function erasureEncode(data, k, m) {
|
|
4
|
-
const rawShardSize = Math.ceil(data.length / k);
|
|
5
|
-
const shardSize = Math.ceil(rawShardSize / 8) * 8;
|
|
6
|
-
const dataSize = shardSize * k;
|
|
7
|
-
const paritySize = shardSize * m;
|
|
8
|
-
const reedSolomon = createWasmReedSolomonBinding();
|
|
9
|
-
const dataBuf = Buffer.alloc(dataSize);
|
|
10
|
-
data.copy(dataBuf, 0);
|
|
11
|
-
const shards = new Uint8Array(dataSize + paritySize);
|
|
12
|
-
shards.set(new Uint8Array(dataBuf), 0);
|
|
13
|
-
reedSolomon.encode(shards, k, m);
|
|
14
|
-
const res = [];
|
|
15
|
-
for (let i = 0; i < k; i++) {
|
|
16
|
-
res.push(
|
|
17
|
-
Buffer.from(shards.slice(i * shardSize, i * shardSize + shardSize))
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
for (let j = 0; j < m; j++) {
|
|
21
|
-
res.push(
|
|
22
|
-
Buffer.from(
|
|
23
|
-
shards.slice((k + j) * shardSize, (k + j) * shardSize + shardSize)
|
|
24
|
-
)
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
return new Promise((resolve) => resolve(res));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export {
|
|
31
|
-
erasureEncode
|
|
32
|
-
};
|
package/dist/chunk-QM5BVKLD.mjs
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ShelbyBlobClient
|
|
3
|
-
} from "./chunk-B3CB2YEO.mjs";
|
|
4
|
-
import {
|
|
5
|
-
ShelbyRPCClient
|
|
6
|
-
} from "./chunk-2FF5FICZ.mjs";
|
|
7
|
-
import {
|
|
8
|
-
generateCommitments
|
|
9
|
-
} from "./chunk-G263DBCY.mjs";
|
|
10
|
-
import {
|
|
11
|
-
DEFAULT_SHELBY_BASE_URL
|
|
12
|
-
} from "./chunk-D2FERD4A.mjs";
|
|
13
|
-
|
|
14
|
-
// src/core/clients/ShelbyClient.ts
|
|
15
|
-
import {
|
|
16
|
-
Aptos
|
|
17
|
-
} from "@aptos-labs/ts-sdk";
|
|
18
|
-
var ShelbyClient = class {
|
|
19
|
-
/**
|
|
20
|
-
* The coordination client is used to interact with the Aptos blockchain which handles the commitments
|
|
21
|
-
* and metadata for blobs.
|
|
22
|
-
*/
|
|
23
|
-
coordination;
|
|
24
|
-
/**
|
|
25
|
-
* The RPC client is used to interact with the Shelby RPC node which can be responsible for storing,
|
|
26
|
-
* confirming, and retrieving blobs from the storage layer.
|
|
27
|
-
*/
|
|
28
|
-
rpc;
|
|
29
|
-
/**
|
|
30
|
-
* The configuration for the Shelby client.
|
|
31
|
-
*/
|
|
32
|
-
config;
|
|
33
|
-
/**
|
|
34
|
-
* The Aptos client.
|
|
35
|
-
*/
|
|
36
|
-
aptos;
|
|
37
|
-
/**
|
|
38
|
-
* The base class for Shelby clients
|
|
39
|
-
*
|
|
40
|
-
* @param config.aptos.config - The Aptos config.
|
|
41
|
-
* @param config.shelby.baseUrl - The base URL of the Shelby RPC node. If not provided, the default base URL will be used.
|
|
42
|
-
*/
|
|
43
|
-
constructor(config) {
|
|
44
|
-
this.config = config;
|
|
45
|
-
this.aptos = new Aptos(this.config.aptos.config);
|
|
46
|
-
this.coordination = new ShelbyBlobClient(config);
|
|
47
|
-
this.rpc = new ShelbyRPCClient(config);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* The base URL for the Shelby RPC node.
|
|
51
|
-
*/
|
|
52
|
-
get baseUrl() {
|
|
53
|
-
return this.config.shelby?.baseUrl ?? DEFAULT_SHELBY_BASE_URL;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Uploads a blob to the Shelby network.
|
|
57
|
-
*
|
|
58
|
-
* @param params.blobData - The data to upload.
|
|
59
|
-
* @param params.signer - The signer of the transaction.
|
|
60
|
-
* @param params.blobName - The name of the blob.
|
|
61
|
-
* @param params.expirationMicros - The expiration time of the blob in microseconds.
|
|
62
|
-
* @param params.options - The options for the upload.
|
|
63
|
-
*
|
|
64
|
-
* @returns The transaction and generated blob commitments.
|
|
65
|
-
*/
|
|
66
|
-
async upload(params) {
|
|
67
|
-
const generatedBlobCommitments = await generateCommitments(
|
|
68
|
-
params.blobData,
|
|
69
|
-
void 0,
|
|
70
|
-
params.options?.encoding
|
|
71
|
-
);
|
|
72
|
-
const { transaction, blobCommitments } = await this.coordination.writeBlobCommitments({
|
|
73
|
-
...params,
|
|
74
|
-
blobCommitments: generatedBlobCommitments
|
|
75
|
-
});
|
|
76
|
-
const confirmedTransaction = await this.aptos.waitForTransaction({
|
|
77
|
-
transactionHash: transaction.hash
|
|
78
|
-
});
|
|
79
|
-
await this.rpc.putBlob({
|
|
80
|
-
...params,
|
|
81
|
-
account: params.signer.accountAddress
|
|
82
|
-
});
|
|
83
|
-
return { transaction: confirmedTransaction, blobCommitments };
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Downloads a blob from the Shelby RPC node.
|
|
87
|
-
*
|
|
88
|
-
* @param params.account - The account namespace the blob is stored in (e.g. "0x1")
|
|
89
|
-
* @param params.blobName - The name of the blob (e.g. "foo/bar")
|
|
90
|
-
* @param params.range - The range of the blob to download.
|
|
91
|
-
*
|
|
92
|
-
* @returns A `ShelbyBlob` object containing the blob data.
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* const blob = await client.download({
|
|
97
|
-
* account,
|
|
98
|
-
* blobName: "foo/bar.txt",
|
|
99
|
-
* });
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
async download(params) {
|
|
103
|
-
return await this.rpc.getBlob(params);
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export {
|
|
108
|
-
ShelbyClient
|
|
109
|
-
};
|
package/dist/core/erasure.d.ts
DELETED
package/dist/core/erasure.mjs
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|