@shelby-protocol/sdk 0.3.1 → 0.4.0

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 (66) hide show
  1. package/dist/browser/index.d.ts +9 -9
  2. package/dist/browser/index.mjs +1068 -589
  3. package/dist/core/clients/ShelbyBlobClient.d.ts +155 -40
  4. package/dist/core/clients/ShelbyBlobClient.mjs +314 -112
  5. package/dist/core/clients/ShelbyClient.d.ts +27 -4
  6. package/dist/core/clients/ShelbyClient.mjs +869 -551
  7. package/dist/core/clients/ShelbyClientConfig.d.ts +9 -1
  8. package/dist/core/clients/ShelbyMetadataClient.d.ts +38 -6
  9. package/dist/core/clients/ShelbyMetadataClient.mjs +95 -13
  10. package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +42 -0
  11. package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +62 -7
  12. package/dist/core/clients/ShelbyPlacementGroupClient.mjs +10 -7
  13. package/dist/core/clients/ShelbyRPCClient.d.ts +55 -66
  14. package/dist/core/clients/ShelbyRPCClient.mjs +344 -360
  15. package/dist/core/clients/index.d.ts +3 -2
  16. package/dist/core/clients/index.mjs +933 -551
  17. package/dist/core/clients/utils.mjs +1 -1
  18. package/dist/core/commitments.d.ts +12 -1
  19. package/dist/core/commitments.mjs +7 -0
  20. package/dist/core/constants.d.ts +1 -1
  21. package/dist/core/constants.mjs +1 -1
  22. package/dist/core/erasure/constants.d.ts +16 -1
  23. package/dist/core/erasure/constants.mjs +15 -1
  24. package/dist/core/erasure/index.d.ts +1 -1
  25. package/dist/core/erasure/index.mjs +15 -1
  26. package/dist/core/errors.d.ts +20 -1
  27. package/dist/core/errors.mjs +29 -0
  28. package/dist/core/index.d.ts +9 -9
  29. package/dist/core/index.mjs +1068 -589
  30. package/dist/core/operations/generated/sdk.d.ts +798 -42
  31. package/dist/core/operations/generated/sdk.mjs +93 -9
  32. package/dist/core/operations/index.d.ts +1 -1
  33. package/dist/core/operations/index.mjs +94 -10
  34. package/dist/core/rpc-responses.d.ts +1 -57
  35. package/dist/core/rpc-responses.mjs +1 -21
  36. package/dist/core/sp/chunk_proof.d.ts +23 -0
  37. package/dist/core/sp/chunk_proof.mjs +113 -0
  38. package/dist/core/sp/index.d.ts +3 -0
  39. package/dist/core/sp/index.mjs +402 -0
  40. package/dist/core/sp/sp_write_client.d.ts +53 -0
  41. package/dist/core/sp/sp_write_client.mjs +302 -0
  42. package/dist/core/types/blobs.d.ts +24 -5
  43. package/dist/core/types/blobs.mjs +24 -0
  44. package/dist/core/types/index.d.ts +2 -2
  45. package/dist/core/types/index.mjs +46 -2
  46. package/dist/core/types/payments.mjs +1 -1
  47. package/dist/core/types/storage_providers.d.ts +32 -6
  48. package/dist/core/types/storage_providers.mjs +22 -0
  49. package/dist/gen/rpc_server_pb.d.ts +295 -0
  50. package/dist/gen/rpc_server_pb.mjs +28 -0
  51. package/dist/node/clients/ShelbyNodeClient.d.ts +1 -0
  52. package/dist/node/clients/ShelbyNodeClient.mjs +869 -551
  53. package/dist/node/clients/index.d.ts +1 -0
  54. package/dist/node/clients/index.mjs +867 -551
  55. package/dist/node/index.d.ts +9 -9
  56. package/dist/node/index.mjs +1068 -589
  57. package/dist/node/parallel/commitment_worker.mjs +36 -249
  58. package/dist/node/parallel/commitment_worker_pool.mjs +56 -3
  59. package/dist/node/parallel/coverage_flush.d.ts +16 -0
  60. package/dist/node/parallel/coverage_flush.mjs +43 -0
  61. package/dist/node/parallel/default_commitment_worker_pool.mjs +56 -3
  62. package/dist/node/parallel/index.d.ts +1 -0
  63. package/dist/node/parallel/index.mjs +72 -4
  64. package/dist/node/parallel/parallel_commitments.mjs +56 -3
  65. package/dist/node/parallel/worker_pool.mjs +56 -3
  66. package/package.json +11 -4
@@ -0,0 +1,302 @@
1
+ // src/core/sp/sp_write_client.ts
2
+ import * as net from "net";
3
+ import { create, fromBinary, toBinary } from "@bufbuild/protobuf";
4
+
5
+ // src/gen/rpc_server_pb.ts
6
+ import { fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv2";
7
+ var file_rpc_server = /* @__PURE__ */ fileDesc("ChBycGNfc2VydmVyLnByb3RvEgNjYXYiGgoHUGF5bWVudBIPCgdwYXltZW50GAEgASgMIhkKCVByb29mTm9kZRIMCgRoYXNoGAEgASgMIiwKBVByb29mEiMKC3Byb29mX25vZGVzGAEgAygLMg4uY2F2LlByb29mTm9kZSJFCghDaHVua0tleRIQCghibG9iX3VpZBgBIAEoBBIUCgxjaHVua3NldF9pZHgYAiABKA0SEQoJY2h1bmtfaWR4GAMgASgNIk8KC1JlYWRSZXF1ZXN0EiEKCmlkZW50aWZpZXIYASABKAsyDS5jYXYuQ2h1bmtLZXkSHQoHcGF5bWVudBgCIAEoCzIMLmNhdi5QYXltZW50InEKGUNsYXlIZWxwZXJEYXRhUmVhZFJlcXVlc3QSIQoKaWRlbnRpZmllchgBIAEoCzINLmNhdi5DaHVua0tleRIYChB0YXJnZXRfY2h1bmtfaWR4GAIgASgNEhcKD2hlbHBlcl9zZXRfbWFzaxgDIAEoBCJgCgxXcml0ZVJlcXVlc3QSIQoKaWRlbnRpZmllchgBIAEoCzINLmNhdi5DaHVua0tleRIMCgRib2R5GAIgASgMEhkKBXByb29mGAMgASgLMgouY2F2LlByb29mSgQIBBAFIsQBCgdSZXF1ZXN0EiQKCHJlYWRfcmVxGAEgASgLMhAuY2F2LlJlYWRSZXF1ZXN0SAASJgoJd3JpdGVfcmVxGAIgASgLMhEuY2F2LldyaXRlUmVxdWVzdEgAEjkKD2hlbHBlcl9yZWFkX3JlcRgFIAEoCzIeLmNhdi5DbGF5SGVscGVyRGF0YVJlYWRSZXF1ZXN0SAASEgoKcmVxdWVzdF9pZBgDIAEoBBIRCglzaWduYXR1cmUYBCABKAxCCQoHcmVxdWVzdCJXCgxSZWFkUmVzcG9uc2USDAoEYm9keRgBIAEoDBIZCgVwcm9vZhgCIAEoCzIKLmNhdi5Qcm9vZhIeChZoZWxwZXJfY2h1bmtfcm9vdF9oYXNoGAMgASgMIk0KDVdyaXRlUmVzcG9uc2USGgoSYmxvYl9hY2tfc2lnbmF0dXJlGAIgASgMEiAKGG1pc3NpbmdfY2h1bmtzZXRfaW5kaWNlcxgDIAMoDSKWAQoIUmVzcG9uc2USEgoKcmVxdWVzdF9pZBgBIAEoBBISCgplcnJvcl9jb2RlGAIgASgEEiYKCXJlYWRfcmVzcBgDIAEoCzIRLmNhdi5SZWFkUmVzcG9uc2VIABIoCgp3cml0ZV9yZXNwGAQgASgLMhIuY2F2LldyaXRlUmVzcG9uc2VIAEIKCghyZXNwb25zZUoECAUQBmIGcHJvdG8z");
8
+ var ProofNodeSchema = /* @__PURE__ */ messageDesc(file_rpc_server, 1);
9
+ var ProofSchema = /* @__PURE__ */ messageDesc(file_rpc_server, 2);
10
+ var ChunkKeySchema = /* @__PURE__ */ messageDesc(file_rpc_server, 3);
11
+ var ReadRequestSchema = /* @__PURE__ */ messageDesc(file_rpc_server, 4);
12
+ var WriteRequestSchema = /* @__PURE__ */ messageDesc(file_rpc_server, 6);
13
+ var RequestSchema = /* @__PURE__ */ messageDesc(file_rpc_server, 7);
14
+ var ResponseSchema = /* @__PURE__ */ messageDesc(file_rpc_server, 10);
15
+
16
+ // src/core/sp/chunk_proof.ts
17
+ import { createHash } from "crypto";
18
+
19
+ // src/core/utils.ts
20
+ import {
21
+ AccountAddress,
22
+ Hex
23
+ } from "@aptos-labs/ts-sdk";
24
+
25
+ // src/core/sp/chunk_proof.ts
26
+ var SP_WRITE_SUCCESS_ERROR_CODE = 1n;
27
+
28
+ // src/core/sp/sp_write_client.ts
29
+ var SP_CLIENT_LOG = process.env.SHELBY_SP_CLIENT_LOG === "1";
30
+ var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
31
+ var DEFAULT_CONNECTIONS = 4;
32
+ var SpWriteClient = class {
33
+ constructor(host, port, numConnections = DEFAULT_CONNECTIONS, requestTimeoutMs = DEFAULT_REQUEST_TIMEOUT_MS) {
34
+ this.host = host;
35
+ this.port = port;
36
+ this.numConnections = numConnections;
37
+ this.requestTimeoutMs = requestTimeoutMs;
38
+ }
39
+ connections = [];
40
+ nextConnectionIdx = 0;
41
+ nextRequestId = 1n;
42
+ connected = false;
43
+ async connect() {
44
+ if (this.connected) {
45
+ return;
46
+ }
47
+ const connectPromises = [];
48
+ for (let i = 0; i < this.numConnections; i++) {
49
+ connectPromises.push(this.createConnection());
50
+ }
51
+ await Promise.all(connectPromises);
52
+ this.connected = true;
53
+ }
54
+ createConnection() {
55
+ return new Promise((resolve, reject) => {
56
+ const socket = new net.Socket();
57
+ let settled = false;
58
+ const state = {
59
+ socket,
60
+ responseBuffer: Buffer.alloc(0),
61
+ expectedSize: null,
62
+ pending: /* @__PURE__ */ new Map(),
63
+ writeQueue: [],
64
+ draining: false,
65
+ closed: false
66
+ };
67
+ socket.on("connect", () => {
68
+ this.connections.push(state);
69
+ settled = true;
70
+ resolve();
71
+ });
72
+ socket.on("data", (data) => {
73
+ this.handleData(state, data);
74
+ });
75
+ socket.on("error", (err) => {
76
+ if (SP_CLIENT_LOG)
77
+ console.error(
78
+ `[SpWriteClient] socket error ${this.host}:${this.port}: ${err.message}`
79
+ );
80
+ if (!settled) {
81
+ settled = true;
82
+ reject(err);
83
+ }
84
+ this.handleDisconnect(state, err);
85
+ });
86
+ socket.on("close", (hadError) => {
87
+ if (SP_CLIENT_LOG)
88
+ console.error(
89
+ `[SpWriteClient] socket closed ${this.host}:${this.port} (hadError=${hadError})`
90
+ );
91
+ this.handleDisconnect(state, new Error("SP connection closed"));
92
+ });
93
+ socket.on("timeout", () => {
94
+ if (SP_CLIENT_LOG)
95
+ console.error(
96
+ `[SpWriteClient] socket idle timeout ${this.host}:${this.port} after ${this.requestTimeoutMs}ms`
97
+ );
98
+ socket.destroy(new Error("SP connection timed out"));
99
+ });
100
+ socket.connect(this.port, this.host);
101
+ });
102
+ }
103
+ handleData(state, data) {
104
+ state.responseBuffer = Buffer.concat([state.responseBuffer, data]);
105
+ while (true) {
106
+ if (state.expectedSize === null) {
107
+ if (state.responseBuffer.length < 8) {
108
+ return;
109
+ }
110
+ state.expectedSize = Number(state.responseBuffer.readBigUInt64LE(0));
111
+ }
112
+ const totalNeeded = 8 + state.expectedSize;
113
+ if (state.responseBuffer.length < totalNeeded) {
114
+ return;
115
+ }
116
+ const responseBytes = state.responseBuffer.subarray(8, totalNeeded);
117
+ state.responseBuffer = state.responseBuffer.subarray(totalNeeded);
118
+ state.expectedSize = null;
119
+ try {
120
+ const response = fromBinary(ResponseSchema, responseBytes);
121
+ const pending = state.pending.get(response.requestId);
122
+ if (pending) {
123
+ clearTimeout(pending.timeoutId);
124
+ state.pending.delete(response.requestId);
125
+ const success = response.errorCode === SP_WRITE_SUCCESS_ERROR_CODE;
126
+ if (pending.resolver.kind === "write") {
127
+ const blobAckSignature = response.response.case === "writeResp" ? response.response.value.blobAckSignature : new Uint8Array(0);
128
+ pending.resolver.resolve({
129
+ success,
130
+ errorCode: response.errorCode,
131
+ blobAckSignature
132
+ });
133
+ } else {
134
+ const body = response.response.case === "readResp" ? response.response.value.body : new Uint8Array(0);
135
+ pending.resolver.resolve({
136
+ success,
137
+ errorCode: response.errorCode,
138
+ bytesRead: body.byteLength
139
+ });
140
+ }
141
+ }
142
+ } catch (error) {
143
+ for (const [, pending] of state.pending) {
144
+ clearTimeout(pending.timeoutId);
145
+ pending.reject(
146
+ error instanceof Error ? error : new Error(String(error))
147
+ );
148
+ }
149
+ state.pending.clear();
150
+ }
151
+ }
152
+ }
153
+ handleDisconnect(state, error) {
154
+ if (state.closed) {
155
+ return;
156
+ }
157
+ state.closed = true;
158
+ for (const [, pending] of state.pending) {
159
+ clearTimeout(pending.timeoutId);
160
+ pending.reject(error);
161
+ }
162
+ state.pending.clear();
163
+ const idx = this.connections.indexOf(state);
164
+ if (idx !== -1) {
165
+ this.connections.splice(idx, 1);
166
+ }
167
+ }
168
+ drainConnection(state) {
169
+ if (state.draining || state.writeQueue.length === 0 || state.closed) {
170
+ return;
171
+ }
172
+ state.draining = true;
173
+ const frame = state.writeQueue.shift();
174
+ const canContinue = state.socket.write(frame, () => {
175
+ state.draining = false;
176
+ this.drainConnection(state);
177
+ });
178
+ if (!canContinue) {
179
+ state.socket.once("drain", () => {
180
+ state.draining = false;
181
+ this.drainConnection(state);
182
+ });
183
+ } else {
184
+ state.draining = false;
185
+ this.drainConnection(state);
186
+ }
187
+ }
188
+ selectConnection() {
189
+ if (this.connections.length === 0) {
190
+ throw new Error("Not connected to SP");
191
+ }
192
+ for (let i = 0; i < this.connections.length; i++) {
193
+ const idx = (this.nextConnectionIdx + i) % this.connections.length;
194
+ const conn = this.connections[idx];
195
+ if (!conn.closed) {
196
+ this.nextConnectionIdx = (idx + 1) % this.connections.length;
197
+ return conn;
198
+ }
199
+ }
200
+ throw new Error("No available SP connections");
201
+ }
202
+ async writeChunk(params) {
203
+ if (!this.connected) {
204
+ await this.connect();
205
+ }
206
+ const conn = this.selectConnection();
207
+ const requestId = this.nextRequestId++;
208
+ const chunkKey = create(ChunkKeySchema, {
209
+ blobUid: params.blobUid,
210
+ chunksetIdx: params.chunksetIdx,
211
+ chunkIdx: params.chunkIdx
212
+ });
213
+ const proofNodes = [];
214
+ for (let i = 0; i < params.proof.length; i += 32) {
215
+ proofNodes.push(
216
+ create(ProofNodeSchema, {
217
+ hash: params.proof.slice(i, i + 32)
218
+ })
219
+ );
220
+ }
221
+ const request = create(RequestSchema, {
222
+ request: {
223
+ case: "writeReq",
224
+ value: create(WriteRequestSchema, {
225
+ identifier: chunkKey,
226
+ body: params.chunkData,
227
+ proof: create(ProofSchema, { proofNodes })
228
+ })
229
+ },
230
+ requestId,
231
+ signature: new Uint8Array(64)
232
+ });
233
+ const requestBytes = toBinary(RequestSchema, request);
234
+ const lengthBuffer = Buffer.alloc(8);
235
+ lengthBuffer.writeBigUInt64LE(BigInt(requestBytes.length), 0);
236
+ const frame = Buffer.concat([lengthBuffer, Buffer.from(requestBytes)]);
237
+ return new Promise((resolve, reject) => {
238
+ const timeoutId = setTimeout(() => {
239
+ conn.pending.delete(requestId);
240
+ reject(new Error(`SP write request ${requestId} timed out`));
241
+ }, this.requestTimeoutMs);
242
+ conn.pending.set(requestId, {
243
+ resolver: { kind: "write", resolve },
244
+ reject,
245
+ timeoutId
246
+ });
247
+ conn.writeQueue.push(frame);
248
+ this.drainConnection(conn);
249
+ });
250
+ }
251
+ async readChunk(params) {
252
+ if (!this.connected) {
253
+ await this.connect();
254
+ }
255
+ const conn = this.selectConnection();
256
+ const requestId = this.nextRequestId++;
257
+ const chunkKey = create(ChunkKeySchema, {
258
+ blobUid: params.blobUid,
259
+ chunksetIdx: params.chunksetIdx,
260
+ chunkIdx: params.chunkIdx
261
+ });
262
+ const request = create(RequestSchema, {
263
+ request: {
264
+ case: "readReq",
265
+ value: create(ReadRequestSchema, {
266
+ identifier: chunkKey
267
+ })
268
+ },
269
+ requestId,
270
+ signature: new Uint8Array(64)
271
+ });
272
+ const requestBytes = toBinary(RequestSchema, request);
273
+ const lengthBuffer = Buffer.alloc(8);
274
+ lengthBuffer.writeBigUInt64LE(BigInt(requestBytes.length), 0);
275
+ const frame = Buffer.concat([lengthBuffer, Buffer.from(requestBytes)]);
276
+ return new Promise((resolve, reject) => {
277
+ const timeoutId = setTimeout(() => {
278
+ conn.pending.delete(requestId);
279
+ reject(new Error(`SP read request ${requestId} timed out`));
280
+ }, this.requestTimeoutMs);
281
+ conn.pending.set(requestId, {
282
+ resolver: { kind: "read", resolve },
283
+ reject,
284
+ timeoutId
285
+ });
286
+ conn.writeQueue.push(frame);
287
+ this.drainConnection(conn);
288
+ });
289
+ }
290
+ // biome-ignore lint/suspicious/useAwait: callers rely on Promise return
291
+ async close() {
292
+ this.connected = false;
293
+ for (const conn of this.connections) {
294
+ conn.closed = true;
295
+ conn.socket.destroy();
296
+ }
297
+ this.connections = [];
298
+ }
299
+ };
300
+ export {
301
+ SpWriteClient
302
+ };
@@ -21,12 +21,25 @@ type ClayEncoding = Required<ClayProviderOptions & {
21
21
  * @link https://github.com/shelby/shelby/blob/e08e84742cf2b80ad8bb7227deb3013398076d53/move/shelby_contract/sources/common_types.move#L32
22
22
  */
23
23
  type BlobEncoding = ClayEncoding;
24
+ /**
25
+ * The encryption scheme a blob's contents were registered with. Mirrors the
26
+ * on-chain `blob_metadata::EncryptionScheme` variants.
27
+ */
28
+ type BlobEncryption = "Unencrypted" | "AES_GCM_V1";
29
+ type BlobEncryptionMoveEnumIndex = 0 | 1;
30
+ declare function blobEncryptionToMoveEnumIndex(encryption: BlobEncryption): BlobEncryptionMoveEnumIndex;
31
+ declare function blobEncryptionFromMoveVariant(variant: string): BlobEncryption;
24
32
  /**
25
33
  * The metadata of a blob that describes the blob and its properties.
26
- *
27
- * @link https://github.com/shelby/shelby/blob/e08e84742cf2b80ad8bb7227deb3013398076d53/move/shelby_contract/sources/global_metadata.move#L185
28
34
  */
29
- interface BlobMetadata {
35
+ interface FullObjectMetadata {
36
+ /**
37
+ * The on-chain UID the object name currently resolves to. Populated on both
38
+ * the view path (`get_full_object_metadata`) and the indexer path (the
39
+ * committed row's `uid`). Optional only for callers constructing metadata by
40
+ * hand.
41
+ */
42
+ uid?: bigint;
30
43
  /**
31
44
  * The owner of the blob.
32
45
  */
@@ -56,6 +69,12 @@ interface BlobMetadata {
56
69
  * The encoding of the blob.
57
70
  */
58
71
  encoding: BlobEncoding;
72
+ /**
73
+ * The encryption scheme the blob was registered with. Present from the
74
+ * on-chain view path; absent for indexer-sourced metadata, which does not
75
+ * yet surface it.
76
+ */
77
+ encryption?: BlobEncryption;
59
78
  /**
60
79
  * The expiration timestamp of the blob in microseconds.
61
80
  */
@@ -77,7 +96,7 @@ interface BlobMetadata {
77
96
  */
78
97
  isDeleted?: boolean;
79
98
  }
80
- type BlobActivityType = "register_blob" | "delete_blob" | "extend_blob_expiration" | "write_blob" | "unknown";
99
+ type BlobActivityType = "register_blob" | "delete_blob" | "extend_blob_expiration" | "write_blob" | "commit_object" | "delete_object" | "reject_object_commit" | "unknown";
81
100
  /**
82
101
  * The activity of a blob.
83
102
  */
@@ -129,4 +148,4 @@ interface StorageProviderAck {
129
148
  signature: Uint8Array;
130
149
  }
131
150
 
132
- export type { BlobActivity, BlobActivityType, BlobEncoding, BlobMetadata, ClayEncoding, StorageProviderAck };
151
+ export { type BlobActivity, type BlobActivityType, type BlobEncoding, type BlobEncryption, type BlobEncryptionMoveEnumIndex, type ClayEncoding, type FullObjectMetadata, type StorageProviderAck, blobEncryptionFromMoveVariant, blobEncryptionToMoveEnumIndex };
@@ -0,0 +1,24 @@
1
+ // src/core/types/blobs.ts
2
+ var BLOB_ENCRYPTION_TO_MOVE_ENUM_INDEX = {
3
+ Unencrypted: 0,
4
+ AES_GCM_V1: 1
5
+ };
6
+ function blobEncryptionToMoveEnumIndex(encryption) {
7
+ return BLOB_ENCRYPTION_TO_MOVE_ENUM_INDEX[encryption];
8
+ }
9
+ function blobEncryptionFromMoveVariant(variant) {
10
+ switch (variant) {
11
+ case "Unencrypted":
12
+ return "Unencrypted";
13
+ case "AES_GCM_V1":
14
+ return "AES_GCM_V1";
15
+ default:
16
+ throw new Error(
17
+ "Could not parse encryption from Shelby Smart Contract, this SDK is out of date."
18
+ );
19
+ }
20
+ }
21
+ export {
22
+ blobEncryptionFromMoveVariant,
23
+ blobEncryptionToMoveEnumIndex
24
+ };
@@ -1,7 +1,7 @@
1
- export { BlobActivity, BlobActivityType, BlobEncoding, BlobMetadata, ClayEncoding, StorageProviderAck } from './blobs.js';
1
+ export { BlobActivity, BlobActivityType, BlobEncoding, BlobEncryption, BlobEncryptionMoveEnumIndex, ClayEncoding, FullObjectMetadata, StorageProviderAck, blobEncryptionFromMoveVariant, blobEncryptionToMoveEnumIndex } from './blobs.js';
2
2
  export { ChannelInfo, SenderBuiltMicropayment, StaleChannelStateError } from './payments.js';
3
3
  export { PlacementGroupInfo, PlacementGroupSlot, PlacementGroupSlotStatus } from './placement_groups.js';
4
- export { ActiveStateDetails, FrozenStateDetails, StorageProviderInfo, StorageProviderStateDetails, WaitlistedStateDetails } from './storage_providers.js';
4
+ export { ActiveProviderCondition, ActiveStateDetails, FrozenStateDetails, StorageProviderInfo, StorageProviderStateDetails, WaitlistedStateDetails, isActiveForTasks, isActiveProviderCondition } from './storage_providers.js';
5
5
  import '@aptos-labs/ts-sdk';
6
6
  import '../../clay-codes-DdXABBDx.js';
7
7
  import '@shelby-protocol/clay-codes';
@@ -1,3 +1,24 @@
1
+ // src/core/types/blobs.ts
2
+ var BLOB_ENCRYPTION_TO_MOVE_ENUM_INDEX = {
3
+ Unencrypted: 0,
4
+ AES_GCM_V1: 1
5
+ };
6
+ function blobEncryptionToMoveEnumIndex(encryption) {
7
+ return BLOB_ENCRYPTION_TO_MOVE_ENUM_INDEX[encryption];
8
+ }
9
+ function blobEncryptionFromMoveVariant(variant) {
10
+ switch (variant) {
11
+ case "Unencrypted":
12
+ return "Unencrypted";
13
+ case "AES_GCM_V1":
14
+ return "AES_GCM_V1";
15
+ default:
16
+ throw new Error(
17
+ "Could not parse encryption from Shelby Smart Contract, this SDK is out of date."
18
+ );
19
+ }
20
+ }
21
+
1
22
  // src/core/types/payments.ts
2
23
  import {
3
24
  AccountAddress,
@@ -9,7 +30,7 @@ import {
9
30
  // src/core/constants.ts
10
31
  import { Network } from "@aptos-labs/ts-sdk";
11
32
  var NetworkToShelbyRPCBaseUrl = {
12
- [Network.SHELBYNET]: "https://api.shelbynet.shelby.xyz/shelby",
33
+ [Network.SHELBYNET]: "https://shelby.shelbynet.shelby.xyz/shelby",
13
34
  [Network.NETNA]: void 0,
14
35
  [Network.DEVNET]: void 0,
15
36
  [Network.TESTNET]: "https://api.testnet.shelby.xyz/shelby",
@@ -229,7 +250,30 @@ var SenderBuiltMicropayment = class _SenderBuiltMicropayment {
229
250
  );
230
251
  }
231
252
  };
253
+
254
+ // src/core/types/storage_providers.ts
255
+ var ACTIVE_PROVIDER_CONDITIONS = [
256
+ "Normal",
257
+ "Faulty",
258
+ "Leaving",
259
+ "Evicted",
260
+ "PendingLeaving"
261
+ ];
262
+ function isActiveProviderCondition(value) {
263
+ return typeof value === "string" && ACTIVE_PROVIDER_CONDITIONS.includes(value);
264
+ }
265
+ var TASK_ELIGIBLE_CONDITIONS = /* @__PURE__ */ new Set([
266
+ "Normal",
267
+ "PendingLeaving"
268
+ ]);
269
+ function isActiveForTasks(condition) {
270
+ return TASK_ELIGIBLE_CONDITIONS.has(condition);
271
+ }
232
272
  export {
233
273
  SenderBuiltMicropayment,
234
- StaleChannelStateError
274
+ StaleChannelStateError,
275
+ blobEncryptionFromMoveVariant,
276
+ blobEncryptionToMoveEnumIndex,
277
+ isActiveForTasks,
278
+ isActiveProviderCondition
235
279
  };
@@ -9,7 +9,7 @@ import {
9
9
  // src/core/constants.ts
10
10
  import { Network } from "@aptos-labs/ts-sdk";
11
11
  var NetworkToShelbyRPCBaseUrl = {
12
- [Network.SHELBYNET]: "https://api.shelbynet.shelby.xyz/shelby",
12
+ [Network.SHELBYNET]: "https://shelby.shelbynet.shelby.xyz/shelby",
13
13
  [Network.NETNA]: void 0,
14
14
  [Network.DEVNET]: void 0,
15
15
  [Network.TESTNET]: "https://api.testnet.shelby.xyz/shelby",
@@ -1,23 +1,49 @@
1
1
  import { AccountAddress } from '@aptos-labs/ts-sdk';
2
2
 
3
3
  /**
4
- * State details for active storage providers
4
+ * Variant names of `ActiveProviderCondition`. Single source of truth — the
5
+ * type below is derived from this tuple so adding a variant means editing
6
+ * one array.
7
+ *
8
+ * Mirrors the on-chain `ActiveProviderCondition` enum in
9
+ * `move/shelby_contract/sources/storage_provider_registry.move`. Keep in sync
10
+ * with the Move enum — the metadata-client parser fails closed (throws) on
11
+ * unknown variants so the mismatch surfaces immediately.
12
+ */
13
+ declare const ACTIVE_PROVIDER_CONDITIONS: readonly ["Normal", "Faulty", "Leaving", "Evicted", "PendingLeaving"];
14
+ /**
15
+ * Condition of an active storage provider.
16
+ */
17
+ type ActiveProviderCondition = (typeof ACTIVE_PROVIDER_CONDITIONS)[number];
18
+ /**
19
+ * Type guard for `ActiveProviderCondition` — used by the metadata-client
20
+ * parser to reject unknown wire-format variants.
21
+ */
22
+ declare function isActiveProviderCondition(value: unknown): value is ActiveProviderCondition;
23
+ /**
24
+ * Returns whether a condition is task-eligible. Mirrors Move's
25
+ * `is_active_for_tasks` in `storage_provider_registry.move` — adding a new
26
+ * task-eligible condition on-chain means updating the set above.
27
+ */
28
+ declare function isActiveForTasks(condition: ActiveProviderCondition): boolean;
29
+ /**
30
+ * State details for active storage providers.
5
31
  */
6
32
  interface ActiveStateDetails {
7
33
  variant: "Active";
34
+ /** FixedPoint64 serializes as string. */
8
35
  quota: string;
9
36
  stakeAtStartOfStakingEpoch: string;
10
- faulty: boolean;
11
- leaving: boolean;
37
+ condition: ActiveProviderCondition;
12
38
  }
13
39
  /**
14
- * State details for waitlisted storage providers
40
+ * State details for waitlisted storage providers.
15
41
  */
16
42
  interface WaitlistedStateDetails {
17
43
  variant: "Waitlisted";
18
44
  }
19
45
  /**
20
- * State details for frozen storage providers
46
+ * State details for frozen storage providers.
21
47
  */
22
48
  interface FrozenStateDetails {
23
49
  variant: "Frozen";
@@ -58,4 +84,4 @@ interface StorageProviderInfo {
58
84
  state: StorageProviderStateDetails;
59
85
  }
60
86
 
61
- export type { ActiveStateDetails, FrozenStateDetails, StorageProviderInfo, StorageProviderStateDetails, WaitlistedStateDetails };
87
+ export { type ActiveProviderCondition, type ActiveStateDetails, type FrozenStateDetails, type StorageProviderInfo, type StorageProviderStateDetails, type WaitlistedStateDetails, isActiveForTasks, isActiveProviderCondition };
@@ -0,0 +1,22 @@
1
+ // src/core/types/storage_providers.ts
2
+ var ACTIVE_PROVIDER_CONDITIONS = [
3
+ "Normal",
4
+ "Faulty",
5
+ "Leaving",
6
+ "Evicted",
7
+ "PendingLeaving"
8
+ ];
9
+ function isActiveProviderCondition(value) {
10
+ return typeof value === "string" && ACTIVE_PROVIDER_CONDITIONS.includes(value);
11
+ }
12
+ var TASK_ELIGIBLE_CONDITIONS = /* @__PURE__ */ new Set([
13
+ "Normal",
14
+ "PendingLeaving"
15
+ ]);
16
+ function isActiveForTasks(condition) {
17
+ return TASK_ELIGIBLE_CONDITIONS.has(condition);
18
+ }
19
+ export {
20
+ isActiveForTasks,
21
+ isActiveProviderCondition
22
+ };