@shelby-protocol/sdk 0.0.1-experimental.4 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/README.md +41 -0
  2. package/dist/browser/index.d.ts +17 -8
  3. package/dist/browser/index.mjs +83 -34
  4. package/dist/chunk-3ZDXWPYC.mjs +65 -0
  5. package/dist/chunk-6MDQI7PW.mjs +177 -0
  6. package/dist/chunk-75VHXY5P.mjs +48 -0
  7. package/dist/chunk-APML3CGJ.mjs +176 -0
  8. package/dist/chunk-DLMDDEWF.mjs +112 -0
  9. package/dist/{chunk-C33H3C3N.mjs → chunk-EAPAG4L7.mjs} +1 -1
  10. package/dist/{chunk-GGYTHP5F.mjs → chunk-FIFKKWXV.mjs} +19 -17
  11. package/dist/chunk-HPVCKAN2.mjs +41 -0
  12. package/dist/{chunk-2FF5FICZ.mjs → chunk-JSR44EDC.mjs} +96 -42
  13. package/dist/chunk-KBUWZXFA.mjs +92 -0
  14. package/dist/chunk-LTV26KU4.mjs +141 -0
  15. package/dist/chunk-NTJSNNA7.mjs +175 -0
  16. package/dist/{chunk-QEMIORTL.mjs → chunk-OTBLZL2S.mjs} +1 -1
  17. package/dist/chunk-RBFWGDMY.mjs +30 -0
  18. package/dist/chunk-VRLIOKWG.mjs +11 -0
  19. package/dist/chunk-XGMJ4CG4.mjs +384 -0
  20. package/dist/chunk-Z7RFCADT.mjs +0 -0
  21. package/dist/chunk-ZPW742E7.mjs +28 -0
  22. package/dist/clay-codes-Ce9EmXfa.d.ts +129 -0
  23. package/dist/core/blobs.mjs +1 -1
  24. package/dist/core/chunk.d.ts +34 -0
  25. package/dist/core/chunk.mjs +17 -0
  26. package/dist/core/clients/ShelbyBlobClient.d.ts +121 -89
  27. package/dist/core/clients/ShelbyBlobClient.mjs +11 -3
  28. package/dist/core/clients/ShelbyClient.d.ts +71 -30
  29. package/dist/core/clients/ShelbyClient.mjs +14 -9
  30. package/dist/core/clients/ShelbyClientConfig.d.ts +43 -9
  31. package/dist/core/clients/ShelbyClientConfig.mjs +1 -0
  32. package/dist/core/clients/ShelbyRPCClient.d.ts +47 -20
  33. package/dist/core/clients/ShelbyRPCClient.mjs +10 -3
  34. package/dist/core/clients/index.d.ts +10 -5
  35. package/dist/core/clients/index.mjs +16 -10
  36. package/dist/core/clients/utils.d.ts +7 -0
  37. package/dist/core/clients/utils.mjs +7 -0
  38. package/dist/core/commitments.d.ts +18 -18
  39. package/dist/core/commitments.mjs +7 -5
  40. package/dist/core/constants.d.ts +24 -19
  41. package/dist/core/constants.mjs +15 -15
  42. package/dist/core/erasure/clay-codes.d.ts +2 -0
  43. package/dist/core/erasure/clay-codes.mjs +9 -0
  44. package/dist/core/erasure/constants.d.ts +48 -0
  45. package/dist/core/erasure/constants.mjs +17 -0
  46. package/dist/core/erasure/default.d.ts +6 -0
  47. package/dist/core/erasure/default.mjs +9 -0
  48. package/dist/core/erasure/index.d.ts +4 -0
  49. package/dist/core/erasure/index.mjs +27 -0
  50. package/dist/core/erasure/provider.d.ts +2 -0
  51. package/dist/core/erasure/provider.mjs +0 -0
  52. package/dist/core/erasure/reed-solomon.d.ts +2 -0
  53. package/dist/core/erasure/reed-solomon.mjs +7 -0
  54. package/dist/core/erasure/utils.d.ts +12 -0
  55. package/dist/core/erasure/utils.mjs +33 -0
  56. package/dist/core/index.d.ts +17 -8
  57. package/dist/core/index.mjs +83 -34
  58. package/dist/core/layout.mjs +4 -2
  59. package/dist/core/networks.d.ts +7 -0
  60. package/dist/core/networks.mjs +9 -0
  61. package/dist/core/operations/generated/sdk.d.ts +686 -0
  62. package/dist/core/operations/generated/sdk.mjs +23 -0
  63. package/dist/core/operations/index.d.ts +31 -0
  64. package/dist/core/operations/index.mjs +12 -0
  65. package/dist/core/strings.d.ts +6 -0
  66. package/dist/core/strings.mjs +9 -0
  67. package/dist/core/types/blobs.d.ts +49 -79
  68. package/dist/core/types/encodings.d.ts +5 -13
  69. package/dist/core/types/encodings.mjs +0 -1
  70. package/dist/core/types/index.d.ts +4 -2
  71. package/dist/core/types/index.mjs +1 -1
  72. package/dist/core/types/placement_groups.d.ts +15 -0
  73. package/dist/core/types/placement_groups.mjs +0 -0
  74. package/dist/core/types/storage_providers.d.ts +31 -0
  75. package/dist/core/types/storage_providers.mjs +1 -0
  76. package/dist/core/utils.d.ts +15 -3
  77. package/dist/core/utils.mjs +5 -3
  78. package/dist/node/clients/ShelbyMetadataClient.d.ts +72 -0
  79. package/dist/node/clients/ShelbyMetadataClient.mjs +9 -0
  80. package/dist/node/clients/ShelbyNodeClient.d.ts +8 -3
  81. package/dist/node/clients/ShelbyNodeClient.mjs +15 -10
  82. package/dist/node/clients/index.d.ts +12 -5
  83. package/dist/node/clients/index.mjs +20 -11
  84. package/dist/node/index.d.ts +18 -8
  85. package/dist/node/index.mjs +89 -36
  86. package/package.json +25 -12
  87. package/dist/chunk-5Z3RVWU3.mjs +0 -67
  88. package/dist/chunk-B3CB2YEO.mjs +0 -318
  89. package/dist/chunk-D2FERD4A.mjs +0 -39
  90. package/dist/chunk-G263DBCY.mjs +0 -105
  91. package/dist/chunk-P7BVGLTV.mjs +0 -32
  92. package/dist/chunk-QM5BVKLD.mjs +0 -109
  93. package/dist/core/erasure.d.ts +0 -6
  94. package/dist/core/erasure.mjs +0 -7
  95. /package/dist/{chunk-7S6RVKYB.mjs → chunk-MB7C7VQF.mjs} +0 -0
  96. /package/dist/{chunk-IHTPXUYI.mjs → chunk-MQUVYMNQ.mjs} +0 -0
  97. /package/dist/{chunk-PLUDE5C3.mjs → chunk-RNXGC54D.mjs} +0 -0
  98. /package/dist/{chunk-QKT5R735.mjs → chunk-TUANYVZQ.mjs} +0 -0
@@ -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
- };
@@ -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
- };
@@ -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
- };
@@ -1,6 +0,0 @@
1
- /**
2
- * Split `data` into `k` data shards + `m` parity shards (Reed-Solomon).
3
- */
4
- declare function erasureEncode(data: Buffer, k: number, m: number): Promise<Buffer[]>;
5
-
6
- export { erasureEncode };
@@ -1,7 +0,0 @@
1
- import {
2
- erasureEncode
3
- } from "../chunk-P7BVGLTV.mjs";
4
- import "../chunk-7P6ASYW6.mjs";
5
- export {
6
- erasureEncode
7
- };
File without changes
File without changes
File without changes
File without changes