@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,88 +1,141 @@
1
- import "../chunk-7S6RVKYB.mjs";
1
+ import "../chunk-MB7C7VQF.mjs";
2
+ import {
3
+ ShelbyMetadataClient
4
+ } from "../chunk-NTJSNNA7.mjs";
2
5
  import {
3
6
  ShelbyNodeClient
4
- } from "../chunk-C33H3C3N.mjs";
7
+ } from "../chunk-EAPAG4L7.mjs";
5
8
  import {
6
9
  testUtil_exports
7
10
  } from "../chunk-A4IG6GSE.mjs";
8
- import "../chunk-PLUDE5C3.mjs";
11
+ import "../chunk-TUANYVZQ.mjs";
12
+ import "../chunk-RNXGC54D.mjs";
9
13
  import "../chunk-MWDW4ROU.mjs";
10
14
  import "../chunk-ZHXCVRZX.mjs";
11
- import "../chunk-IHTPXUYI.mjs";
12
- import "../chunk-QKT5R735.mjs";
15
+ import "../chunk-MQUVYMNQ.mjs";
13
16
  import {
14
17
  ShelbyClient
15
- } from "../chunk-QM5BVKLD.mjs";
18
+ } from "../chunk-6MDQI7PW.mjs";
16
19
  import {
17
20
  ShelbyBlobClient
18
- } from "../chunk-B3CB2YEO.mjs";
21
+ } from "../chunk-XGMJ4CG4.mjs";
22
+ import "../chunk-Z7RFCADT.mjs";
19
23
  import {
20
24
  ShelbyRPCClient
21
- } from "../chunk-2FF5FICZ.mjs";
25
+ } from "../chunk-JSR44EDC.mjs";
26
+ import {
27
+ createShelbyIndexerClient,
28
+ getShelbyIndexerClient
29
+ } from "../chunk-75VHXY5P.mjs";
30
+ import "../chunk-DLMDDEWF.mjs";
31
+ import "../chunk-RBFWGDMY.mjs";
32
+ import "../chunk-I6NG5GNL.mjs";
22
33
  import {
23
34
  createBlobKey
24
- } from "../chunk-QEMIORTL.mjs";
35
+ } from "../chunk-OTBLZL2S.mjs";
25
36
  import {
26
37
  BlobCommitmentsSchema,
27
38
  ChunksetCommitmentSchema,
39
+ expectedTotalChunksets,
28
40
  generateCommitments
29
- } from "../chunk-G263DBCY.mjs";
41
+ } from "../chunk-LTV26KU4.mjs";
30
42
  import {
43
+ buildRequestUrl,
31
44
  concatHashes,
32
45
  readInChunks,
33
- zeroPadBuffer
34
- } from "../chunk-5Z3RVWU3.mjs";
46
+ zeroPadBytes
47
+ } from "../chunk-KBUWZXFA.mjs";
35
48
  import {
36
- erasureEncode
37
- } from "../chunk-P7BVGLTV.mjs";
49
+ DEFAULT_PROJECT_DESCRIPTION,
50
+ DEFAULT_PROJECT_NAME,
51
+ NetworkToShelbyBlobIndexerBaseUrl,
52
+ NetworkToShelbyRPCBaseUrl,
53
+ SHELBYUSD_TOKEN_ADDRESS,
54
+ SHELBYUSD_TOKEN_MODULE,
55
+ SHELBYUSD_TOKEN_NAME,
56
+ SHELBYUSD_TOKEN_TYPE,
57
+ SHELBY_DEPLOYER,
58
+ TOKEN_DEPLOYER,
59
+ TOKEN_OBJECT_ADDRESS
60
+ } from "../chunk-HPVCKAN2.mjs";
38
61
  import {
39
62
  BlobNameSchema,
40
63
  ChunkKey,
41
64
  allChunksForBlob,
42
65
  roundSize
43
- } from "../chunk-GGYTHP5F.mjs";
66
+ } from "../chunk-FIFKKWXV.mjs";
44
67
  import {
45
- CHUNKSET_SIZE_BYTES,
46
- DEFAULT_PROJECT_DESCRIPTION,
47
- DEFAULT_PROJECT_NAME,
48
- DEFAULT_SHELBY_BASE_URL,
49
- ERASURE_K,
50
- ERASURE_M,
51
- SHELBY_DEPLOYER,
52
- TOKEN_DEPLOYER,
53
- TOKEN_OBJECT_ADDRESS,
54
- getChunkSizeBytes,
55
- getChunksetSizeBytes
56
- } from "../chunk-D2FERD4A.mjs";
57
- import "../chunk-I6NG5GNL.mjs";
68
+ CHUNK_SIZE_PARAMS,
69
+ ChunkSizeScheme,
70
+ ClayErasureCodingProvider,
71
+ DEFAULT_CHUNKSET_SIZE_BYTES,
72
+ DEFAULT_CHUNK_SIZE_BYTES,
73
+ ERASURE_CODE_AND_CHUNK_MAPPING,
74
+ createDefaultErasureCodingProvider
75
+ } from "../chunk-APML3CGJ.mjs";
76
+ import {
77
+ ReedSolomonErasureCodingProvider
78
+ } from "../chunk-3ZDXWPYC.mjs";
79
+ import {
80
+ DEFAULT_ERASURE_D,
81
+ DEFAULT_ERASURE_K,
82
+ DEFAULT_ERASURE_M,
83
+ DEFAULT_ERASURE_N,
84
+ ERASURE_CODE_PARAMS,
85
+ ErasureCodingScheme
86
+ } from "../chunk-ZPW742E7.mjs";
87
+ import {
88
+ isShelbyNetwork,
89
+ shelbyNetworks
90
+ } from "../chunk-VRLIOKWG.mjs";
58
91
  import "../chunk-7P6ASYW6.mjs";
59
92
  export {
60
93
  BlobCommitmentsSchema,
61
94
  BlobNameSchema,
62
- CHUNKSET_SIZE_BYTES,
95
+ CHUNK_SIZE_PARAMS,
63
96
  ChunkKey,
97
+ ChunkSizeScheme,
64
98
  ChunksetCommitmentSchema,
99
+ ClayErasureCodingProvider,
100
+ DEFAULT_CHUNKSET_SIZE_BYTES,
101
+ DEFAULT_CHUNK_SIZE_BYTES,
102
+ DEFAULT_ERASURE_D,
103
+ DEFAULT_ERASURE_K,
104
+ DEFAULT_ERASURE_M,
105
+ DEFAULT_ERASURE_N,
65
106
  DEFAULT_PROJECT_DESCRIPTION,
66
107
  DEFAULT_PROJECT_NAME,
67
- DEFAULT_SHELBY_BASE_URL,
68
- ERASURE_K,
69
- ERASURE_M,
108
+ ERASURE_CODE_AND_CHUNK_MAPPING,
109
+ ERASURE_CODE_PARAMS,
110
+ ErasureCodingScheme,
111
+ NetworkToShelbyBlobIndexerBaseUrl,
112
+ NetworkToShelbyRPCBaseUrl,
113
+ ReedSolomonErasureCodingProvider,
114
+ SHELBYUSD_TOKEN_ADDRESS,
115
+ SHELBYUSD_TOKEN_MODULE,
116
+ SHELBYUSD_TOKEN_NAME,
117
+ SHELBYUSD_TOKEN_TYPE,
70
118
  SHELBY_DEPLOYER,
71
119
  ShelbyBlobClient,
72
120
  ShelbyClient,
121
+ ShelbyMetadataClient,
73
122
  ShelbyNodeClient,
74
123
  ShelbyRPCClient,
75
124
  TOKEN_DEPLOYER,
76
125
  TOKEN_OBJECT_ADDRESS,
77
126
  allChunksForBlob,
127
+ buildRequestUrl,
78
128
  concatHashes,
79
129
  createBlobKey,
80
- erasureEncode,
130
+ createDefaultErasureCodingProvider,
131
+ createShelbyIndexerClient,
132
+ expectedTotalChunksets,
81
133
  generateCommitments,
82
- getChunkSizeBytes,
83
- getChunksetSizeBytes,
134
+ getShelbyIndexerClient,
135
+ isShelbyNetwork,
84
136
  readInChunks,
85
137
  roundSize,
138
+ shelbyNetworks,
86
139
  testUtil_exports as testUtil,
87
- zeroPadBuffer
140
+ zeroPadBytes
88
141
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shelby-protocol/sdk",
3
- "version": "0.0.1-experimental.4",
3
+ "version": "0.0.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -19,13 +19,33 @@
19
19
  "import": "./dist/browser/index.mjs"
20
20
  }
21
21
  },
22
+ "scripts": {
23
+ "prepublishOnly": "pnpm run build",
24
+ "lint": "biome check .",
25
+ "fmt": "biome check . --write",
26
+ "generate": "graphql-codegen",
27
+ "generate:watch": "graphql-codegen --watch",
28
+ "verify:config": "tsx scripts/verify-config.ts",
29
+ "build": "tsc --noEmit && (rimraf dist; tsup) && pnpm run verify:config",
30
+ "test": "vitest dev",
31
+ "test:once": "vitest run",
32
+ "benchmark:erasure": "tsx benchmark/erasure.ts"
33
+ },
22
34
  "dependencies": {
23
- "zod": "^3.24.3",
24
- "@shelby-protocol/reed-solomon": "0.0.1-experimental.1"
35
+ "@shelby-protocol/reed-solomon": "workspace:*",
36
+ "graphql": "^16.11.0",
37
+ "graphql-request": "^7.2.0",
38
+ "graphql-tag": "^2.12.6",
39
+ "@shelby-protocol/clay-codes": "workspace:*",
40
+ "zod": "^3.24.3"
25
41
  },
26
42
  "devDependencies": {
27
- "@aptos-labs/ts-sdk": "^5.0.0",
43
+ "@aptos-labs/ts-sdk": "^5.1.1",
44
+ "@graphql-codegen/cli": "^6.0.0",
45
+ "@graphql-codegen/typescript-graphql-request": "^6.3.0",
46
+ "@parcel/watcher": "^2.5.1",
28
47
  "@types/fs-extra": "^11.0.4",
48
+ "@types/node": "^22",
29
49
  "dotenv": "^16.5.0",
30
50
  "fs-extra": "^11.3.1",
31
51
  "rimraf": "^6",
@@ -36,12 +56,5 @@
36
56
  },
37
57
  "peerDependencies": {
38
58
  "@aptos-labs/ts-sdk": "^2.0.1 || ^3.0.0 || ^4.0.0 || ^5.0.0"
39
- },
40
- "scripts": {
41
- "lint": "biome check .",
42
- "fmt": "biome check . --write",
43
- "build": "tsc --noEmit && (rimraf dist; tsup)",
44
- "test": "vitest dev",
45
- "test:once": "vitest run"
46
59
  }
47
- }
60
+ }
@@ -1,67 +0,0 @@
1
- // src/core/utils.ts
2
- import { Hex } from "@aptos-labs/ts-sdk";
3
- async function* readInChunks(input, chunkSize) {
4
- let idx = 0;
5
- if (Buffer.isBuffer(input)) {
6
- for (let offset = 0; offset < input.length; offset += chunkSize) {
7
- yield [idx++, Buffer.from(input.subarray(offset, offset + chunkSize))];
8
- }
9
- return;
10
- }
11
- const reader = input.getReader();
12
- let buffer = new Uint8Array(chunkSize);
13
- let bufferWriteOffset = 0;
14
- try {
15
- while (true) {
16
- const { value, done } = await reader.read();
17
- if (done) break;
18
- if (value === void 0) continue;
19
- let srcOffset = 0;
20
- while (srcOffset < value.length) {
21
- const remainingCapacity = chunkSize - bufferWriteOffset;
22
- const bytesToCopy = Math.min(
23
- remainingCapacity,
24
- value.length - srcOffset
25
- );
26
- buffer.set(
27
- value.subarray(srcOffset, srcOffset + bytesToCopy),
28
- bufferWriteOffset
29
- );
30
- bufferWriteOffset += bytesToCopy;
31
- srcOffset += bytesToCopy;
32
- if (bufferWriteOffset >= chunkSize) {
33
- yield [idx++, Buffer.from(buffer)];
34
- buffer = new Uint8Array(chunkSize);
35
- bufferWriteOffset = 0;
36
- }
37
- }
38
- }
39
- } finally {
40
- reader.releaseLock();
41
- }
42
- if (bufferWriteOffset > 0) {
43
- yield [idx++, Buffer.from(buffer.subarray(0, bufferWriteOffset))];
44
- }
45
- }
46
- function zeroPadBuffer(buffer, desiredLength) {
47
- if (buffer.length >= desiredLength) {
48
- return buffer;
49
- }
50
- const paddedBuffer = Buffer.alloc(desiredLength);
51
- buffer.copy(paddedBuffer);
52
- return paddedBuffer;
53
- }
54
- async function concatHashes(parts) {
55
- const combined = Buffer.concat(
56
- parts.map((part) => Hex.fromHexInput(part).toUint8Array())
57
- );
58
- return Hex.fromHexInput(
59
- new Uint8Array(await crypto.subtle.digest("SHA-256", combined))
60
- );
61
- }
62
-
63
- export {
64
- readInChunks,
65
- zeroPadBuffer,
66
- concatHashes
67
- };
@@ -1,318 +0,0 @@
1
- import {
2
- createBlobKey
3
- } from "./chunk-QEMIORTL.mjs";
4
- import {
5
- SHELBY_DEPLOYER
6
- } from "./chunk-D2FERD4A.mjs";
7
-
8
- // src/core/clients/ShelbyBlobClient.ts
9
- import {
10
- AccountAddress,
11
- Aptos,
12
- Hex,
13
- MoveVector
14
- } from "@aptos-labs/ts-sdk";
15
- var ShelbyBlobClient = class _ShelbyBlobClient {
16
- aptos;
17
- deployer;
18
- /**
19
- * The ShelbyBlobClient is used to interact with the Shelby contract on the Aptos blockchain. This
20
- * includes functions like writing blob commitments, confirming chunks, and retrieving blob metadata.
21
- *
22
- * @param config.aptos.config - The Aptos config.
23
- * @param config.shelbyDeployer - The deployer account address of the Shelby contract. If not provided, the default deployer address will be used.
24
- *
25
- * @example
26
- * ```typescript
27
- * const aptos = new Aptos(new AptosConfig({ network: Network.TESTNET }));
28
- * const blobClient = new ShelbyBlobClient({ aptos });
29
- * ```
30
- */
31
- constructor(config) {
32
- this.aptos = new Aptos(config.aptos.config);
33
- this.deployer = config.shelby?.deployer ?? AccountAddress.fromString(SHELBY_DEPLOYER);
34
- }
35
- /**
36
- * Retrieves the blob metadata from the blockchain. If it does not exist,
37
- * returns `undefined`.
38
- *
39
- * @param params.account - The account namespace the blob is stored in (e.g. "0x1")
40
- * @param params.name - The name of the blob (e.g. "foo/bar")
41
- * @returns The blob metadata.
42
- *
43
- * @example
44
- * ```typescript
45
- * const metadata = await client.getBlobMetadata({
46
- * account: AccountAddress.fromString("0x1"),
47
- * name: "foo/bar.txt",
48
- * });
49
- * ```
50
- */
51
- async getBlobMetadata(params) {
52
- try {
53
- const rawMetadata = await this.aptos.view({
54
- payload: {
55
- function: `${this.deployer.toString()}::prototype_interface::get_metadata`,
56
- functionArguments: [
57
- createBlobKey({
58
- account: params.account,
59
- blobName: params.name
60
- })
61
- ]
62
- }
63
- });
64
- const metadata = rawMetadata[0];
65
- return {
66
- blobMerkleRoot: Hex.fromHexInput(
67
- metadata.blob_merkle_root
68
- ).toUint8Array(),
69
- owner: AccountAddress.fromString(metadata.owner),
70
- name: metadata.name,
71
- size: metadata.size,
72
- encoding: {
73
- variant: "clay",
74
- erasureK: metadata.encoding.num_data_chunks,
75
- erasureM: metadata.encoding.num_parity_chunks,
76
- chunksetSize: metadata.encoding.chunkset_size
77
- },
78
- expirationMicros: metadata.expiration_micros
79
- };
80
- } catch (error) {
81
- if (error instanceof Error && // Depending on the network, the error message may show up differently.
82
- (error.message?.includes("sub_status: Some(404)") || error.message?.includes("EBLOB_NOT_FOUND"))) {
83
- return void 0;
84
- }
85
- throw error;
86
- }
87
- }
88
- /**
89
- * Retrieves all the blobs and their metadata for an account from the
90
- * blockchain.
91
- *
92
- * @param params.account - The account namespace the blobs are stored in (e.g. "0x1")
93
- * @returns The blob metadata for all the blobs for the account.
94
- *
95
- * @example
96
- * ```typescript
97
- * // BlobMetadata[]
98
- * const blobs = await client.getAccountBlobs({
99
- * account: AccountAddress.fromString("0x1"),
100
- * });
101
- * ```
102
- */
103
- async getAccountBlobs(params) {
104
- const rawBlobMetadatas = await this.aptos.view({
105
- payload: {
106
- function: `${this.deployer.toString()}::prototype_interface::get_blobs_for_owner`,
107
- functionArguments: [params.account.toString()]
108
- }
109
- });
110
- return rawBlobMetadatas[0].map((blob) => ({
111
- blobMerkleRoot: Hex.fromHexInput(blob.blob_merkle_root).toUint8Array(),
112
- owner: AccountAddress.fromString(blob.owner),
113
- name: blob.name,
114
- size: blob.size,
115
- encoding: {
116
- variant: "clay",
117
- erasureK: blob.encoding.num_data_chunks,
118
- erasureM: blob.encoding.num_parity_chunks,
119
- chunksetSize: blob.encoding.chunkset_size
120
- },
121
- expirationMicros: blob.expiration_micros
122
- }));
123
- }
124
- /**
125
- * Retrieves the blob chunks for a given blob from the blockchain. The blob chunk will contain
126
- * the commitment, the storage provider location, and the status of the chunk (stored or pending).
127
- *
128
- * @param params.account - The account namespace the blob is stored in (e.g. "0x1")
129
- * @param params.name - The name of the blob (e.g. "foo/bar")
130
- * @returns The chunks that make up the blob.
131
- *
132
- * @example
133
- * ```typescript
134
- * // BlobChunk[]
135
- * const chunks = await client.getBlobChunks({
136
- * account: AccountAddress.fromString("0x1"),
137
- * name: "foo/bar.txt",
138
- * });
139
- *
140
- * const isStored = chunks.every((c) => c.location.variant === "stored");
141
- * ```
142
- */
143
- async getBlobChunks(params) {
144
- const chunks = await this.aptos.view({
145
- payload: {
146
- function: `${this.deployer.toString()}::prototype_interface::get_chunks`,
147
- functionArguments: [
148
- createBlobKey({
149
- account: params.account,
150
- blobName: params.name
151
- })
152
- ]
153
- }
154
- });
155
- return chunks[0].map((c) => ({
156
- commitment: Hex.fromHexInput(c.commitment).toUint8Array(),
157
- location: {
158
- variant: c.location.__variant__ === "Stored" ? "stored" : "pending",
159
- provider: AccountAddress.fromString(c.location.provider)
160
- }
161
- }));
162
- }
163
- /**
164
- * Writes the blob commitments to the blockchain.
165
- *
166
- * If `data` is provided instead of `blobCommitments`, the data will be encoded into commitments before being written
167
- * to the blockchain.
168
- *
169
- * @param params.signer - The account that is signing the transaction.
170
- * @param params.blobName - The name of the blob (e.g. "foo/bar")
171
- * @param params.expirationMicros - The expiration time of the blob in microseconds.
172
- * @param params.options - Additional options for transaction building and encoding.
173
- * @param params.blobCommitments - The blob commitments to write to the blockchain (required if `data` is not provided).
174
- * @param params.data - The data to encode into commitments before writing to the blockchain (required if `blobCommitments` is not provided).
175
- *
176
- * @returns The blob commitments and the pending transaction.
177
- *
178
- * @example
179
- * ```typescript
180
- * const blobCommitments = await generateCommitments(data);
181
- *
182
- * const { blobCommitments, transaction } = await client.writeBlobCommitments({
183
- * signer,
184
- * blobName: "foo/bar.txt",
185
- * blobCommitments,
186
- * expirationMicros: Date.now() * 1000 + 3600_000_000, // 1 hour from now in microseconds
187
- * });
188
- * ```
189
- */
190
- async writeBlobCommitments(params) {
191
- const blobCommitments = params.blobCommitments;
192
- const transaction = await this.aptos.transaction.build.simple({
193
- ...params.options?.build,
194
- data: _ShelbyBlobClient.createWriteBlobCommitmentsPayload({
195
- deployer: this.deployer,
196
- account: params.signer.accountAddress,
197
- blobName: params.blobName,
198
- blobMerkleRoot: blobCommitments.blob_merkle_root,
199
- chunksetChunkCommitments: blobCommitments.chunkset_commitments.map(
200
- (chunkset) => chunkset.chunk_commitments
201
- ),
202
- size: blobCommitments.raw_data_size,
203
- expirationMicros: params.expirationMicros
204
- }),
205
- sender: params.signer.accountAddress
206
- });
207
- return {
208
- blobCommitments,
209
- transaction: await this.aptos.signAndSubmitTransaction({
210
- signer: params.signer,
211
- transaction
212
- })
213
- };
214
- }
215
- /**
216
- * Confirms an array of signed chunk commitments for a blob. Once all chunks for a blob are confirmed, the blob is
217
- * considered "stored" and can be retrieved by RPC nodes.
218
- *
219
- * @param params.signer - The account that is signing the transaction.
220
- * @param params.account - The account namespace the blob is stored in (e.g. "0x1")
221
- * @param params.blobName - The name of the blob (e.g. "foo/bar")
222
- * @param params.signedChunksetChunkCommitments - The signed chunk commitments, signed by their storage provider.
223
- * @param params.options - Additional options for transaction building and encoding.
224
- *
225
- * @returns The pending transaction response.
226
- *
227
- * @example
228
- * ```typescript
229
- * const { transaction } = await client.confirmBlobChunks({
230
- * signer,
231
- * account: AccountAddress.fromString("0x1"),
232
- * blobName: "foo/bar.txt",
233
- * signedChunksetChunkCommitments,
234
- * });
235
- * ```
236
- */
237
- async confirmBlobChunks(params) {
238
- const transaction = await this.aptos.transaction.build.simple({
239
- ...params.options?.build,
240
- data: _ShelbyBlobClient.createConfirmBlobChunksPayload({
241
- deployer: this.deployer,
242
- account: params.account,
243
- blobName: params.blobName,
244
- signedChunksetChunkCommitments: params.signedChunksetChunkCommitments
245
- }),
246
- sender: params.signer.accountAddress
247
- });
248
- return {
249
- transaction: await this.aptos.signAndSubmitTransaction({
250
- signer: params.signer,
251
- transaction
252
- })
253
- };
254
- }
255
- /**
256
- * Creates a transaction payload to write blob commitments to the blockchain.
257
- *
258
- * @param params.deployer - The deployer account address of the Shelby contract. If not provided, the default deployer address will be used.
259
- * @param params.account - The account namespace the blob is stored in (e.g. "0x1")
260
- * @param params.blobName - The name of the blob (e.g. "foo/bar")
261
- * @param params.blobMerkleRoot - The blob merkle root.
262
- * @param params.chunksetChunkCommitments - The chunk commitments for each chunkset.
263
- * @param params.expirationMicros - The expiration time of the blob in microseconds.
264
- * @param params.size - The size of the blob in bytes.
265
- *
266
- * @see https://github.com/JumpCrypto/shelby/blob/e009607aad330ccddb08d80bf9addfaadae7972b/move/prototype/move/sources/prototype_interface.move#L211-L220
267
- */
268
- static createWriteBlobCommitmentsPayload(params) {
269
- return {
270
- function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::prototype_interface::write_commitments`,
271
- functionArguments: [
272
- createBlobKey({
273
- account: params.account,
274
- blobName: params.blobName
275
- }),
276
- params.size,
277
- MoveVector.U8(params.blobMerkleRoot),
278
- params.chunksetChunkCommitments.map(
279
- (chunkset) => chunkset.map((chunkCommitment) => MoveVector.U8(chunkCommitment))
280
- ),
281
- params.expirationMicros,
282
- true
283
- ]
284
- };
285
- }
286
- /**
287
- * Creates a transaction payload to confirm the chunks of a blob.
288
- *
289
- * @param params.deployer - The deployer account address of the Shelby contract. If not provided, the default deployer address will be used.
290
- * @param params.account - The account namespace the blob is stored in (e.g. "0x1")
291
- * @param params.blobName - The name of the blob (e.g. "foo/bar")
292
- * @param params.signedChunksetChunkCommitments - The signed chunk commitments, signed by their storage provider.
293
- *
294
- * @see https://github.com/JumpCrypto/shelby/blob/e009607aad330ccddb08d80bf9addfaadae7972b/move/prototype/move/sources/prototype_interface.move#L343-L349
295
- */
296
- static createConfirmBlobChunksPayload(params) {
297
- return {
298
- function: `${(params.deployer ?? SHELBY_DEPLOYER).toString()}::prototype_interface::write_complete`,
299
- functionArguments: [
300
- createBlobKey({
301
- account: params.account,
302
- blobName: params.blobName
303
- }),
304
- params.signedChunksetChunkCommitments.map(
305
- (chunkset) => chunkset.map((chunk) => AccountAddress.from(chunk.provider))
306
- ),
307
- params.signedChunksetChunkCommitments.map(
308
- (chunkset) => chunkset.map((chunk) => MoveVector.U8(chunk.signedCommitment))
309
- ),
310
- true
311
- ]
312
- };
313
- }
314
- };
315
-
316
- export {
317
- ShelbyBlobClient
318
- };
@@ -1,39 +0,0 @@
1
- // src/core/constants.ts
2
- var DEFAULT_PROJECT_NAME = "shelby";
3
- var DEFAULT_PROJECT_DESCRIPTION = "High performance, decentralized storage";
4
- var DEFAULT_SHELBY_BASE_URL = "https://api.shelby.dev";
5
- var SHELBY_DEPLOYER = "0xc63d6a5efb0080a6029403131715bd4971e1149f7cc099aac69bb0069b3ddbf5";
6
- var TOKEN_DEPLOYER = "0x33009e852be7f93762dd0bf303383c2cb2c5cab7a30d8238ca5f9f177ae75124";
7
- var TOKEN_OBJECT_ADDRESS = "0x249f5c642a63885ff88a5113b3ba0079840af5a1357706f8c7f3bfc5dd12511f";
8
- var ERASURE_K = 2;
9
- var ERASURE_M = 1;
10
- var CHUNKSET_SIZE_BYTES = 10 * 1024 * 1024;
11
- function computeChunkSizeBytes(k, chunksetSize) {
12
- const ret = chunksetSize / k;
13
- if (!Number.isInteger(ret)) {
14
- throw new Error(
15
- `ChunksetSize and erasure coding number of chunks are incompatible: ${chunksetSize}/${k} is not an integer`
16
- );
17
- }
18
- return ret;
19
- }
20
- function getChunksetSizeBytes() {
21
- return CHUNKSET_SIZE_BYTES;
22
- }
23
- function getChunkSizeBytes() {
24
- return computeChunkSizeBytes(ERASURE_K, getChunksetSizeBytes());
25
- }
26
-
27
- export {
28
- DEFAULT_PROJECT_NAME,
29
- DEFAULT_PROJECT_DESCRIPTION,
30
- DEFAULT_SHELBY_BASE_URL,
31
- SHELBY_DEPLOYER,
32
- TOKEN_DEPLOYER,
33
- TOKEN_OBJECT_ADDRESS,
34
- ERASURE_K,
35
- ERASURE_M,
36
- CHUNKSET_SIZE_BYTES,
37
- getChunksetSizeBytes,
38
- getChunkSizeBytes
39
- };