@shelby-protocol/sdk 0.3.0 → 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 (126) hide show
  1. package/dist/browser/index.d.ts +19 -10
  2. package/dist/browser/index.mjs +4200 -146
  3. package/dist/core/aptos-explorer.mjs +46 -5
  4. package/dist/core/blobs.mjs +12 -4
  5. package/dist/core/chunk.mjs +58 -9
  6. package/dist/core/clients/ShelbyBlobClient.d.ts +155 -83
  7. package/dist/core/clients/ShelbyBlobClient.mjs +1286 -17
  8. package/dist/core/clients/ShelbyClient.d.ts +39 -6
  9. package/dist/core/clients/ShelbyClient.mjs +3233 -23
  10. package/dist/core/clients/ShelbyClientConfig.d.ts +9 -1
  11. package/dist/core/clients/ShelbyClientConfig.mjs +0 -1
  12. package/dist/core/clients/ShelbyMetadataClient.d.ts +20 -6
  13. package/dist/core/clients/ShelbyMetadataClient.mjs +388 -6
  14. package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +7 -7
  15. package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +894 -13
  16. package/dist/core/clients/ShelbyPlacementGroupClient.mjs +310 -8
  17. package/dist/core/clients/ShelbyRPCClient.d.ts +117 -25
  18. package/dist/core/clients/ShelbyRPCClient.mjs +1245 -12
  19. package/dist/core/clients/index.d.ts +4 -2
  20. package/dist/core/clients/index.mjs +3802 -39
  21. package/dist/core/clients/utils.mjs +65 -6
  22. package/dist/core/commitments.d.ts +12 -1
  23. package/dist/core/commitments.mjs +277 -11
  24. package/dist/core/constants.d.ts +3 -3
  25. package/dist/core/constants.mjs +39 -16
  26. package/dist/core/erasure/clay-codes.mjs +129 -4
  27. package/dist/core/erasure/constants.d.ts +16 -1
  28. package/dist/core/erasure/constants.mjs +48 -11
  29. package/dist/core/erasure/default.mjs +191 -9
  30. package/dist/core/erasure/index.d.ts +1 -1
  31. package/dist/core/erasure/index.mjs +281 -24
  32. package/dist/core/erasure/reed-solomon.mjs +68 -4
  33. package/dist/core/erasure/utils.mjs +0 -2
  34. package/dist/core/errors.d.ts +20 -1
  35. package/dist/core/errors.mjs +58 -8
  36. package/dist/core/index.d.ts +9 -9
  37. package/dist/core/index.mjs +4194 -146
  38. package/dist/core/layout.mjs +37 -5
  39. package/dist/core/networks.mjs +10 -5
  40. package/dist/core/operations/generated/sdk.d.ts +807 -42
  41. package/dist/core/operations/generated/sdk.mjs +267 -18
  42. package/dist/core/operations/index.d.ts +1 -1
  43. package/dist/core/operations/index.mjs +368 -24
  44. package/dist/core/promises.mjs +4 -4
  45. package/dist/core/rpc-responses.d.ts +1 -57
  46. package/dist/core/rpc-responses.mjs +14 -15
  47. package/dist/core/shelby-explorer.mjs +31 -6
  48. package/dist/core/sp/chunk_proof.d.ts +23 -0
  49. package/dist/core/sp/chunk_proof.mjs +113 -0
  50. package/dist/core/sp/index.d.ts +3 -0
  51. package/dist/core/sp/index.mjs +402 -0
  52. package/dist/core/sp/sp_write_client.d.ts +53 -0
  53. package/dist/core/sp/sp_write_client.mjs +302 -0
  54. package/dist/core/strings.mjs +0 -2
  55. package/dist/core/types/blobs.d.ts +24 -5
  56. package/dist/core/types/blobs.mjs +24 -1
  57. package/dist/core/types/index.d.ts +2 -2
  58. package/dist/core/types/index.mjs +275 -10
  59. package/dist/core/types/payments.d.ts +6 -6
  60. package/dist/core/types/payments.mjs +230 -5
  61. package/dist/core/types/placement_groups.mjs +0 -1
  62. package/dist/core/types/storage_providers.d.ts +32 -6
  63. package/dist/core/types/storage_providers.mjs +22 -1
  64. package/dist/core/utils.mjs +94 -8
  65. package/dist/gen/rpc_server_pb.d.ts +295 -0
  66. package/dist/gen/rpc_server_pb.mjs +28 -0
  67. package/dist/node/clients/ShelbyNodeClient.d.ts +2 -0
  68. package/dist/node/clients/ShelbyNodeClient.mjs +3237 -24
  69. package/dist/node/clients/index.d.ts +2 -0
  70. package/dist/node/clients/index.mjs +3236 -26
  71. package/dist/node/index.d.ts +9 -9
  72. package/dist/node/index.mjs +4217 -153
  73. package/dist/node/parallel/commitment_worker.d.ts +9 -0
  74. package/dist/node/parallel/commitment_worker.mjs +85 -0
  75. package/dist/node/parallel/commitment_worker_pool.d.ts +35 -0
  76. package/dist/node/parallel/commitment_worker_pool.mjs +339 -0
  77. package/dist/node/parallel/coverage_flush.d.ts +16 -0
  78. package/dist/node/parallel/coverage_flush.mjs +43 -0
  79. package/dist/node/parallel/default_commitment_worker_pool.d.ts +24 -0
  80. package/dist/node/parallel/default_commitment_worker_pool.mjs +355 -0
  81. package/dist/node/parallel/index.d.ts +12 -0
  82. package/dist/node/parallel/index.mjs +631 -0
  83. package/dist/node/parallel/parallel_commitments.d.ts +32 -0
  84. package/dist/node/parallel/parallel_commitments.mjs +614 -0
  85. package/dist/node/parallel/worker_pool.d.ts +74 -0
  86. package/dist/node/parallel/worker_pool.mjs +301 -0
  87. package/dist/node/testUtil.mjs +8 -4
  88. package/package.json +16 -5
  89. package/dist/chunk-3NRBHSMQ.mjs +0 -12
  90. package/dist/chunk-5BVSWXQJ.mjs +0 -801
  91. package/dist/chunk-6FJNAUU5.mjs +0 -278
  92. package/dist/chunk-6XSZRDLJ.mjs +0 -375
  93. package/dist/chunk-7P6ASYW6.mjs +0 -9
  94. package/dist/chunk-A4IG6GSE.mjs +0 -21
  95. package/dist/chunk-AD2G3QYD.mjs +0 -0
  96. package/dist/chunk-AUQDI5BS.mjs +0 -43
  97. package/dist/chunk-AY3HBWXA.mjs +0 -51
  98. package/dist/chunk-BDSW5PHM.mjs +0 -37
  99. package/dist/chunk-C6RQ3AEU.mjs +0 -51
  100. package/dist/chunk-CQ6QPIZK.mjs +0 -37
  101. package/dist/chunk-D6GQHO6G.mjs +0 -15
  102. package/dist/chunk-EM67QTMR.mjs +0 -0
  103. package/dist/chunk-I6NG5GNL.mjs +0 -8
  104. package/dist/chunk-JTXYKO3U.mjs +0 -38
  105. package/dist/chunk-KG2TMLEV.mjs +0 -207
  106. package/dist/chunk-M3CP5TFP.mjs +0 -39
  107. package/dist/chunk-M7W43K2Q.mjs +0 -505
  108. package/dist/chunk-MB7C7VQF.mjs +0 -0
  109. package/dist/chunk-MNCQBEMS.mjs +0 -55
  110. package/dist/chunk-MQUVYMNQ.mjs +0 -0
  111. package/dist/chunk-NEO7Z3ZQ.mjs +0 -49
  112. package/dist/chunk-NHWWORCH.mjs +0 -72
  113. package/dist/chunk-OEK24ON7.mjs +0 -135
  114. package/dist/chunk-QQ57OGQ2.mjs +0 -0
  115. package/dist/chunk-RNNJXTX2.mjs +0 -154
  116. package/dist/chunk-S6Q4OG7H.mjs +0 -83
  117. package/dist/chunk-TET3DJEO.mjs +0 -199
  118. package/dist/chunk-UEZNZBJO.mjs +0 -104
  119. package/dist/chunk-V46D5NBW.mjs +0 -11
  120. package/dist/chunk-V4B3GAMQ.mjs +0 -42
  121. package/dist/chunk-WFWRBNTW.mjs +0 -412
  122. package/dist/chunk-WTICJPDB.mjs +0 -0
  123. package/dist/chunk-XNEIWM4O.mjs +0 -0
  124. package/dist/chunk-Z4FZ7W6L.mjs +0 -39
  125. package/dist/chunk-Z7RFCADT.mjs +0 -0
  126. package/dist/chunk-ZHXCVRZX.mjs +0 -0
@@ -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
+ };
@@ -1,5 +1,3 @@
1
- import "../chunk-7P6ASYW6.mjs";
2
-
3
1
  // src/core/strings.ts
4
2
  var ciEquals = (a, b) => {
5
3
  return a.toLowerCase() === b.toLowerCase();
@@ -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 };
@@ -1 +1,24 @@
1
- import "../../chunk-ZHXCVRZX.mjs";
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,14 +1,279 @@
1
- import "../../chunk-QQ57OGQ2.mjs";
2
- import "../../chunk-MQUVYMNQ.mjs";
3
- import "../../chunk-ZHXCVRZX.mjs";
4
- import "../../chunk-AD2G3QYD.mjs";
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
+
22
+ // src/core/types/payments.ts
5
23
  import {
6
- SenderBuiltMicropayment,
7
- StaleChannelStateError
8
- } from "../../chunk-KG2TMLEV.mjs";
9
- import "../../chunk-MNCQBEMS.mjs";
10
- import "../../chunk-7P6ASYW6.mjs";
24
+ AccountAddress,
25
+ Deserializer,
26
+ Hex,
27
+ Serializer
28
+ } from "@aptos-labs/ts-sdk";
29
+
30
+ // src/core/constants.ts
31
+ import { Network } from "@aptos-labs/ts-sdk";
32
+ var NetworkToShelbyRPCBaseUrl = {
33
+ [Network.SHELBYNET]: "https://shelby.shelbynet.shelby.xyz/shelby",
34
+ [Network.NETNA]: void 0,
35
+ [Network.DEVNET]: void 0,
36
+ [Network.TESTNET]: "https://api.testnet.shelby.xyz/shelby",
37
+ [Network.MAINNET]: void 0,
38
+ [Network.LOCAL]: "http://localhost:9090",
39
+ [Network.CUSTOM]: void 0
40
+ };
41
+ var NetworkToShelbyBlobIndexerBaseUrl = {
42
+ [Network.SHELBYNET]: "https://api.shelbynet.aptoslabs.com/nocode/v1/public/alias/shelby/shelbynet/v1/graphql",
43
+ [Network.NETNA]: void 0,
44
+ [Network.DEVNET]: void 0,
45
+ [Network.TESTNET]: "https://api.testnet.aptoslabs.com/nocode/v1/public/alias/shelby/testnet/v1/graphql",
46
+ [Network.MAINNET]: void 0,
47
+ [Network.LOCAL]: "http://localhost:8091/v1/graphql",
48
+ [Network.CUSTOM]: void 0
49
+ };
50
+ var NetworkToGasStationBaseUrl = {
51
+ [Network.SHELBYNET]: "https://api.shelbynet.shelby.xyz/gs/v1",
52
+ [Network.NETNA]: void 0,
53
+ [Network.DEVNET]: void 0,
54
+ [Network.TESTNET]: "https://api.testnet.shelby.xyz/gs/v1",
55
+ [Network.MAINNET]: void 0,
56
+ [Network.LOCAL]: void 0,
57
+ [Network.CUSTOM]: void 0
58
+ };
59
+ var MICROPAYMENTS_DEPLOYER = "0x1ae7275148bf6ef742b658fd9cbcc2e094201606f4a7bc707bab0201da8043ee";
60
+
61
+ // src/core/types/payments.ts
62
+ var MICROPAYMENTS_MODULE_NAME = "micropayments";
63
+ var WITHDRAW_APPROVAL_STRUCT_NAME = "WithdrawApproval";
64
+ function serializeTypeInfo(serializer, moduleAddress, moduleName, structName) {
65
+ moduleAddress.serialize(serializer);
66
+ const moduleNameBytes = new TextEncoder().encode(moduleName);
67
+ serializer.serializeBytes(moduleNameBytes);
68
+ const structNameBytes = new TextEncoder().encode(structName);
69
+ serializer.serializeBytes(structNameBytes);
70
+ }
71
+ var StaleChannelStateError = class _StaleChannelStateError extends Error {
72
+ /**
73
+ * The last valid micropayment stored by the server.
74
+ * Clients can use this to reset their local channel state.
75
+ */
76
+ storedMicropayment;
77
+ constructor(storedMicropayment, message) {
78
+ super(
79
+ message ?? "Client has stale channel state. Use the returned micropayment to reset local state."
80
+ );
81
+ this.name = "StaleChannelStateError";
82
+ this.storedMicropayment = storedMicropayment;
83
+ }
84
+ /**
85
+ * Returns the stored micropayment as a base64-encoded string.
86
+ */
87
+ toBase64() {
88
+ const bytes = this.storedMicropayment.bcsToBytes();
89
+ const binaryString = Array.from(
90
+ bytes,
91
+ (byte) => String.fromCharCode(byte)
92
+ ).join("");
93
+ return btoa(binaryString);
94
+ }
95
+ /**
96
+ * Creates a StaleChannelStateError from a base64-encoded micropayment string.
97
+ */
98
+ static fromBase64(base64, message) {
99
+ const binaryString = atob(base64);
100
+ const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
101
+ const micropayment = SenderBuiltMicropayment.deserialize(bytes);
102
+ return new _StaleChannelStateError(micropayment, message);
103
+ }
104
+ };
105
+ var SenderBuiltMicropayment = class _SenderBuiltMicropayment {
106
+ /**
107
+ * The sender's address (owner of the payment channel).
108
+ */
109
+ sender;
110
+ /**
111
+ * The receiver's address (beneficiary of the withdrawal).
112
+ */
113
+ receiver;
114
+ /**
115
+ * The unique ID of the payment channel.
116
+ */
117
+ paymentChannelId;
118
+ /**
119
+ * The cumulative amount the receiver is authorized to withdraw.
120
+ */
121
+ amount;
122
+ /**
123
+ * The fungible asset metadata address.
124
+ */
125
+ fungibleAssetAddress;
126
+ /**
127
+ * Monotonically increasing sequence number for replay protection.
128
+ */
129
+ sequenceNumber;
130
+ /**
131
+ * The sender's Ed25519 public key (32 bytes).
132
+ * Used by the receiver to verify the signature before submitting.
133
+ */
134
+ publicKey;
135
+ /**
136
+ * The Ed25519 signature of the SignedMessage<WithdrawApproval> struct.
137
+ * The SignedMessage includes TypeInfo for domain separation.
138
+ */
139
+ signature;
140
+ /**
141
+ * The deployer address of the micropayments module.
142
+ * This is needed to reconstruct the TypeInfo for signature verification.
143
+ */
144
+ deployer;
145
+ constructor(sender, receiver, paymentChannelId, amount, fungibleAssetAddress, sequenceNumber, publicKey, signature, deployer) {
146
+ this.sender = sender;
147
+ this.receiver = receiver;
148
+ this.paymentChannelId = paymentChannelId;
149
+ this.amount = amount;
150
+ this.fungibleAssetAddress = fungibleAssetAddress;
151
+ this.sequenceNumber = sequenceNumber;
152
+ this.publicKey = publicKey;
153
+ this.signature = signature;
154
+ this.deployer = deployer ?? AccountAddress.fromString(MICROPAYMENTS_DEPLOYER);
155
+ }
156
+ /**
157
+ * Creates the BCS-serialized message that was signed.
158
+ * This is a SignedMessage<WithdrawApproval> which includes:
159
+ * 1. TypeInfo (module_address, module_name, struct_name)
160
+ * 2. WithdrawApproval struct fields
161
+ *
162
+ * This format is used with signature_verify_strict_t for domain separation.
163
+ */
164
+ getSignedMessage() {
165
+ return _SenderBuiltMicropayment.buildSignedMessage({
166
+ deployer: this.deployer,
167
+ sender: this.sender,
168
+ receiver: this.receiver,
169
+ fungibleAssetAddress: this.fungibleAssetAddress,
170
+ amount: this.amount,
171
+ paymentChannelId: this.paymentChannelId,
172
+ sequenceNumber: this.sequenceNumber
173
+ });
174
+ }
175
+ /**
176
+ * Static helper to build the SignedMessage<WithdrawApproval> bytes from raw parameters.
177
+ * This can be used to create the message for signing without constructing the full object.
178
+ *
179
+ * @param params - The withdrawal approval parameters.
180
+ * @returns The BCS-serialized SignedMessage<WithdrawApproval> bytes.
181
+ */
182
+ static buildSignedMessage(params) {
183
+ const serializer = new Serializer();
184
+ serializeTypeInfo(
185
+ serializer,
186
+ params.deployer,
187
+ MICROPAYMENTS_MODULE_NAME,
188
+ WITHDRAW_APPROVAL_STRUCT_NAME
189
+ );
190
+ params.sender.serialize(serializer);
191
+ params.receiver.serialize(serializer);
192
+ params.fungibleAssetAddress.serialize(serializer);
193
+ serializer.serializeU64(params.amount);
194
+ serializer.serializeU64(params.paymentChannelId);
195
+ serializer.serializeU64(params.sequenceNumber);
196
+ return serializer.toUint8Array();
197
+ }
198
+ serialize(serializer) {
199
+ this.sender.serialize(serializer);
200
+ this.receiver.serialize(serializer);
201
+ this.fungibleAssetAddress.serialize(serializer);
202
+ serializer.serializeU64(this.amount);
203
+ serializer.serializeU64(this.paymentChannelId);
204
+ serializer.serializeU64(this.sequenceNumber);
205
+ serializer.serializeBytes(this.publicKey);
206
+ serializer.serializeBytes(this.signature);
207
+ this.deployer.serialize(serializer);
208
+ }
209
+ bcsToBytes() {
210
+ const serializer = new Serializer();
211
+ this.serialize(serializer);
212
+ return serializer.toUint8Array();
213
+ }
214
+ bcsToHex() {
215
+ return Hex.fromHexInput(this.bcsToBytes());
216
+ }
217
+ toStringWithoutPrefix() {
218
+ return this.bcsToHex().toStringWithoutPrefix();
219
+ }
220
+ toString() {
221
+ return this.bcsToHex().toString();
222
+ }
223
+ /**
224
+ * Deserializes a SenderBuiltMicropayment from BCS bytes.
225
+ * @param bytes - The bytes to deserialize from (Uint8Array or hex string).
226
+ * @returns A new SenderBuiltMicropayment instance.
227
+ */
228
+ static deserialize(bytes) {
229
+ const bytesArray = typeof bytes === "string" ? Hex.fromHexInput(bytes).toUint8Array() : bytes;
230
+ const deserializer = new Deserializer(bytesArray);
231
+ const sender = AccountAddress.deserialize(deserializer);
232
+ const receiver = AccountAddress.deserialize(deserializer);
233
+ const fungibleAssetAddress = AccountAddress.deserialize(deserializer);
234
+ const amount = deserializer.deserializeU64();
235
+ const paymentChannelId = deserializer.deserializeU64();
236
+ const sequenceNumber = deserializer.deserializeU64();
237
+ const publicKey = deserializer.deserializeBytes();
238
+ const signature = deserializer.deserializeBytes();
239
+ const deployer = AccountAddress.deserialize(deserializer);
240
+ return new _SenderBuiltMicropayment(
241
+ sender,
242
+ receiver,
243
+ paymentChannelId,
244
+ amount,
245
+ fungibleAssetAddress,
246
+ sequenceNumber,
247
+ publicKey,
248
+ signature,
249
+ deployer
250
+ );
251
+ }
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
+ }
11
272
  export {
12
273
  SenderBuiltMicropayment,
13
- StaleChannelStateError
274
+ StaleChannelStateError,
275
+ blobEncryptionFromMoveVariant,
276
+ blobEncryptionToMoveEnumIndex,
277
+ isActiveForTasks,
278
+ isActiveProviderCondition
14
279
  };