@shelby-protocol/sdk 0.1.0 → 0.2.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 (88) hide show
  1. package/dist/browser/index.d.ts +6 -5
  2. package/dist/browser/index.mjs +49 -39
  3. package/dist/{chunk-DI2K6OUG.mjs → chunk-33BZ7KYA.mjs} +1 -1
  4. package/dist/chunk-3NRBHSMQ.mjs +12 -0
  5. package/dist/{chunk-FLLOQZVD.mjs → chunk-4ZOFT75Q.mjs} +12 -2
  6. package/dist/{chunk-W6YL46DT.mjs → chunk-5CES6RPZ.mjs} +33 -10
  7. package/dist/{chunk-YZXIPUVQ.mjs → chunk-7O77OM4T.mjs} +108 -29
  8. package/dist/{chunk-LZSIZJYR.mjs → chunk-AUQDI5BS.mjs} +14 -1
  9. package/dist/{chunk-RLRI2533.mjs → chunk-BXEVML7N.mjs} +4 -4
  10. package/dist/{chunk-3ZL3FSNA.mjs → chunk-CGYJLKBU.mjs} +1 -1
  11. package/dist/{chunk-VRLIOKWG.mjs → chunk-D6GQHO6G.mjs} +5 -1
  12. package/dist/{chunk-ZAM2EUVN.mjs → chunk-EFR6H3RT.mjs} +7 -7
  13. package/dist/chunk-HPPMI7DC.mjs +56 -0
  14. package/dist/{chunk-AGRRYZWV.mjs → chunk-IBAUPQOF.mjs} +37 -24
  15. package/dist/{chunk-67F5YZ25.mjs → chunk-JTXYKO3U.mjs} +10 -0
  16. package/dist/chunk-KTVNKLBT.mjs +207 -0
  17. package/dist/{chunk-PZF2VTGP.mjs → chunk-NHWWORCH.mjs} +3 -1
  18. package/dist/{chunk-UCDAABAS.mjs → chunk-OGKZ575S.mjs} +6 -19
  19. package/dist/{chunk-66GI734H.mjs → chunk-OQNP5QXH.mjs} +87 -75
  20. package/dist/{chunk-4JZO2D7T.mjs → chunk-UEZNZBJO.mjs} +9 -2
  21. package/dist/{chunk-MSCUDBMH.mjs → chunk-W37FZSMA.mjs} +1 -1
  22. package/dist/chunk-Z4FZ7W6L.mjs +39 -0
  23. package/dist/{clay-codes-pdZFxI_B.d.ts → clay-codes-DHP-bYcP.d.ts} +6 -2
  24. package/dist/core/blobs.d.ts +2 -0
  25. package/dist/core/blobs.mjs +2 -1
  26. package/dist/core/chunk.d.ts +10 -1
  27. package/dist/core/chunk.mjs +2 -2
  28. package/dist/core/clients/ShelbyBlobClient.d.ts +5 -1
  29. package/dist/core/clients/ShelbyBlobClient.mjs +11 -11
  30. package/dist/core/clients/ShelbyClient.d.ts +8 -2
  31. package/dist/core/clients/ShelbyClient.mjs +16 -15
  32. package/dist/core/clients/ShelbyMetadataClient.d.ts +123 -0
  33. package/dist/{node → core}/clients/ShelbyMetadataClient.mjs +3 -2
  34. package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +39 -34
  35. package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +6 -5
  36. package/dist/core/clients/ShelbyPlacementGroupClient.mjs +3 -3
  37. package/dist/core/clients/ShelbyRPCClient.d.ts +2 -0
  38. package/dist/core/clients/ShelbyRPCClient.mjs +6 -8
  39. package/dist/core/clients/index.d.ts +4 -2
  40. package/dist/core/clients/index.mjs +27 -23
  41. package/dist/core/commitments.d.ts +1 -1
  42. package/dist/core/commitments.mjs +4 -4
  43. package/dist/core/constants.d.ts +15 -3
  44. package/dist/core/constants.mjs +3 -1
  45. package/dist/core/erasure/clay-codes.d.ts +1 -1
  46. package/dist/core/erasure/clay-codes.mjs +5 -5
  47. package/dist/core/erasure/constants.d.ts +10 -2
  48. package/dist/core/erasure/constants.mjs +1 -1
  49. package/dist/core/erasure/default.d.ts +5 -2
  50. package/dist/core/erasure/default.mjs +12 -6
  51. package/dist/core/erasure/index.d.ts +2 -2
  52. package/dist/core/erasure/index.mjs +15 -9
  53. package/dist/core/erasure/provider.d.ts +1 -1
  54. package/dist/core/erasure/reed-solomon.d.ts +1 -1
  55. package/dist/core/erasure/reed-solomon.mjs +1 -1
  56. package/dist/core/erasure/utils.d.ts +1 -1
  57. package/dist/core/index.d.ts +6 -5
  58. package/dist/core/index.mjs +49 -39
  59. package/dist/core/layout.d.ts +5 -16
  60. package/dist/core/layout.mjs +3 -9
  61. package/dist/core/networks.d.ts +1 -1
  62. package/dist/core/networks.mjs +1 -1
  63. package/dist/core/operations/index.mjs +2 -2
  64. package/dist/core/types/blobs.d.ts +1 -1
  65. package/dist/core/types/encodings.d.ts +1 -1
  66. package/dist/core/types/index.d.ts +1 -1
  67. package/dist/core/types/index.mjs +3 -2
  68. package/dist/core/types/payments.d.ts +82 -9
  69. package/dist/core/types/payments.mjs +2 -1
  70. package/dist/core/types/placement_groups.d.ts +2 -2
  71. package/dist/core/types/storage_providers.d.ts +2 -2
  72. package/dist/core/utils.d.ts +3 -2
  73. package/dist/core/utils.mjs +3 -1
  74. package/dist/node/clients/ShelbyNodeClient.d.ts +5 -3
  75. package/dist/node/clients/ShelbyNodeClient.mjs +17 -16
  76. package/dist/node/clients/index.d.ts +3 -3
  77. package/dist/node/clients/index.mjs +18 -18
  78. package/dist/node/index.d.ts +6 -6
  79. package/dist/node/index.mjs +52 -46
  80. package/package.json +1 -1
  81. package/dist/chunk-4MG4XGY4.mjs +0 -91
  82. package/dist/chunk-OMZOR2ZF.mjs +0 -29
  83. package/dist/chunk-OTBLZL2S.mjs +0 -9
  84. package/dist/chunk-W5NRGZEP.mjs +0 -86
  85. package/dist/core/operations/generated/types.d.ts +0 -908
  86. package/dist/core/operations/generated/types.mjs +0 -63
  87. package/dist/node/clients/ShelbyMetadataClient.d.ts +0 -72
  88. /package/dist/{chunk-FGUK6IBA.mjs → chunk-WTICJPDB.mjs} +0 -0
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-AABBONAF.mjs";
7
7
  import {
8
8
  NetworkToShelbyBlobIndexerBaseUrl
9
- } from "./chunk-FLLOQZVD.mjs";
9
+ } from "./chunk-4ZOFT75Q.mjs";
10
10
 
11
11
  // src/core/operations/index.ts
12
12
  import { Network } from "@aptos-labs/ts-sdk";
@@ -1,6 +1,10 @@
1
1
  // src/core/networks.ts
2
2
  import { Network } from "@aptos-labs/ts-sdk";
3
- var shelbyNetworks = [Network.LOCAL, Network.SHELBYNET];
3
+ var shelbyNetworks = [
4
+ Network.LOCAL,
5
+ Network.TESTNET,
6
+ Network.SHELBYNET
7
+ ];
4
8
  var isShelbyNetwork = (network) => {
5
9
  return shelbyNetworks.includes(network.toLowerCase());
6
10
  };
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  StaleChannelStateError
3
- } from "./chunk-4MG4XGY4.mjs";
3
+ } from "./chunk-KTVNKLBT.mjs";
4
4
  import {
5
5
  getShelbyIndexerClient
6
- } from "./chunk-3ZL3FSNA.mjs";
6
+ } from "./chunk-CGYJLKBU.mjs";
7
7
  import {
8
8
  BlobNameSchema
9
- } from "./chunk-W5NRGZEP.mjs";
9
+ } from "./chunk-Z4FZ7W6L.mjs";
10
10
  import {
11
11
  sleep
12
12
  } from "./chunk-I6NG5GNL.mjs";
@@ -16,14 +16,14 @@ import {
16
16
  } from "./chunk-IE6LYVIA.mjs";
17
17
  import {
18
18
  buildRequestUrl,
19
+ normalizeAddress,
19
20
  readInChunks
20
- } from "./chunk-4JZO2D7T.mjs";
21
+ } from "./chunk-UEZNZBJO.mjs";
21
22
  import {
22
23
  NetworkToShelbyRPCBaseUrl
23
- } from "./chunk-FLLOQZVD.mjs";
24
+ } from "./chunk-4ZOFT75Q.mjs";
24
25
 
25
26
  // src/core/clients/ShelbyRPCClient.ts
26
- import { AccountAddress } from "@aptos-labs/ts-sdk";
27
27
  var MICROPAYMENT_HEADER = "X-Shelby-Micropayment";
28
28
  function encodeURIComponentKeepSlashes(str) {
29
29
  return encodeURIComponent(str).replace(/%2F/g, "/");
@@ -399,7 +399,7 @@ var ShelbyRPCClient = class {
399
399
  }
400
400
  });
401
401
  return {
402
- account: AccountAddress.from(params.account),
402
+ account: normalizeAddress(params.account),
403
403
  name: params.blobName,
404
404
  readable: validatingStream,
405
405
  contentLength: expectedContentLength
@@ -0,0 +1,56 @@
1
+ import {
2
+ ClayErasureCodingProvider
3
+ } from "./chunk-OGKZ575S.mjs";
4
+ import {
5
+ DEFAULT_CHUNK_SIZE_BYTES
6
+ } from "./chunk-JTXYKO3U.mjs";
7
+ import {
8
+ ERASURE_CODE_PARAMS
9
+ } from "./chunk-AUQDI5BS.mjs";
10
+
11
+ // src/core/erasure/default.ts
12
+ var defaultProviderPromise;
13
+ function createDefaultErasureCodingProvider() {
14
+ if (!defaultProviderPromise) {
15
+ defaultProviderPromise = ClayErasureCodingProvider.create(
16
+ defaultErasureCodingConfig()
17
+ );
18
+ }
19
+ return defaultProviderPromise;
20
+ }
21
+ function defaultErasureCodingConfig() {
22
+ console.log(
23
+ `default erasure coding, with env: ${process.env.SHELBY_ENCODING}`
24
+ );
25
+ const encoding = Number(process.env.SHELBY_ENCODING) || 0;
26
+ if (encoding === 0) {
27
+ console.log("getting default erasure coding (16,10,13)");
28
+ return erasureCodingConfig16Total10Data13Helper();
29
+ }
30
+ console.log("getting default erasure coding (4,2,3)");
31
+ return erasureCodingConfig4Total2Data3Helper();
32
+ }
33
+ function erasureCodingConfig16Total10Data13Helper() {
34
+ return erasureCodingConfig(
35
+ "ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */
36
+ );
37
+ }
38
+ function erasureCodingConfig4Total2Data3Helper() {
39
+ return erasureCodingConfig("ClayCode_4Total_2Data_3Helper" /* ClayCode_4Total_2Data_3Helper */);
40
+ }
41
+ function erasureCodingConfig(encodingScheme) {
42
+ return {
43
+ erasure_n: ERASURE_CODE_PARAMS[encodingScheme].erasure_n,
44
+ erasure_k: ERASURE_CODE_PARAMS[encodingScheme].erasure_k,
45
+ erasure_d: ERASURE_CODE_PARAMS[encodingScheme].erasure_d,
46
+ chunkSizeBytes: DEFAULT_CHUNK_SIZE_BYTES,
47
+ enumIndex: ERASURE_CODE_PARAMS[encodingScheme].enumIndex
48
+ };
49
+ }
50
+
51
+ export {
52
+ createDefaultErasureCodingProvider,
53
+ defaultErasureCodingConfig,
54
+ erasureCodingConfig16Total10Data13Helper,
55
+ erasureCodingConfig4Total2Data3Helper
56
+ };
@@ -1,28 +1,31 @@
1
+ import {
2
+ defaultErasureCodingConfig
3
+ } from "./chunk-HPPMI7DC.mjs";
1
4
  import {
2
5
  getShelbyIndexerClient
3
- } from "./chunk-3ZL3FSNA.mjs";
6
+ } from "./chunk-CGYJLKBU.mjs";
4
7
  import {
5
8
  getAptosConfig
6
9
  } from "./chunk-AABBONAF.mjs";
7
10
  import {
8
11
  createBlobKey
9
- } from "./chunk-OTBLZL2S.mjs";
12
+ } from "./chunk-3NRBHSMQ.mjs";
10
13
  import {
11
14
  expectedTotalChunksets
12
- } from "./chunk-RLRI2533.mjs";
15
+ } from "./chunk-BXEVML7N.mjs";
13
16
  import {
14
- getBlobNameSuffix
15
- } from "./chunk-4JZO2D7T.mjs";
17
+ getBlobNameSuffix,
18
+ normalizeAddress
19
+ } from "./chunk-UEZNZBJO.mjs";
16
20
  import {
17
- DEFAULT_CHUNKSET_SIZE_BYTES,
18
21
  ERASURE_CODE_AND_CHUNK_MAPPING
19
- } from "./chunk-67F5YZ25.mjs";
22
+ } from "./chunk-JTXYKO3U.mjs";
20
23
  import {
21
24
  ERASURE_CODE_PARAMS
22
- } from "./chunk-LZSIZJYR.mjs";
25
+ } from "./chunk-AUQDI5BS.mjs";
23
26
  import {
24
27
  SHELBY_DEPLOYER
25
- } from "./chunk-FLLOQZVD.mjs";
28
+ } from "./chunk-4ZOFT75Q.mjs";
26
29
 
27
30
  // src/core/clients/ShelbyBlobClient.ts
28
31
  import {
@@ -150,6 +153,14 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
150
153
  const metadata = rawMetadata[0].vec[0];
151
154
  let encoding;
152
155
  if (metadata.encoding.__variant__ === "ClayCode_16Total_10Data_13Helper") {
156
+ console.log("read blob metadata with ClayCode_16Total_10Data_13Helper");
157
+ encoding = {
158
+ variant: "clay",
159
+ ...ERASURE_CODE_PARAMS[metadata.encoding.__variant__],
160
+ ...ERASURE_CODE_AND_CHUNK_MAPPING[metadata.encoding.__variant__]
161
+ };
162
+ } else if (metadata.encoding.__variant__ === "ClayCode_4Total_2Data_3Helper") {
163
+ console.log("read blob metadata with ClayCode_4Total_2Data_3Helper");
153
164
  encoding = {
154
165
  variant: "clay",
155
166
  ...ERASURE_CODE_PARAMS[metadata.encoding.__variant__],
@@ -164,14 +175,14 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
164
175
  blobMerkleRoot: Hex.fromHexInput(
165
176
  metadata.blob_commitment
166
177
  ).toUint8Array(),
167
- owner: AccountAddress.fromString(metadata.owner),
178
+ owner: normalizeAddress(metadata.owner),
168
179
  name: params.name,
169
180
  blobNameSuffix: getBlobNameSuffix(params.name),
170
181
  size: Number(metadata.blob_size),
171
182
  encoding,
172
183
  expirationMicros: Number(metadata.expiration_micros),
173
184
  creationMicros: Number(metadata.creation_micros),
174
- sliceAddress: AccountAddress.fromString(metadata.slice.inner),
185
+ sliceAddress: normalizeAddress(metadata.slice.inner),
175
186
  isWritten: metadata.is_written
176
187
  };
177
188
  } catch (error) {
@@ -204,7 +215,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
204
215
  return this.getBlobs({
205
216
  where: {
206
217
  ...where,
207
- owner: { _eq: AccountAddress.from(params.account).toString() }
218
+ owner: { _eq: normalizeAddress(params.account).toString() }
208
219
  },
209
220
  pagination: rest.pagination,
210
221
  orderBy: rest.orderBy
@@ -243,7 +254,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
243
254
  });
244
255
  return blobs.map(
245
256
  (blob) => ({
246
- owner: AccountAddress.from(blob.owner),
257
+ owner: normalizeAddress(blob.owner),
247
258
  name: blob.blob_name,
248
259
  blobNameSuffix: getBlobNameSuffix(blob.blob_name),
249
260
  blobMerkleRoot: Hex.fromHexInput(blob.blob_commitment).toUint8Array(),
@@ -256,7 +267,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
256
267
  },
257
268
  expirationMicros: Number(blob.expires_at),
258
269
  creationMicros: Number(blob.created_at),
259
- sliceAddress: AccountAddress.from(blob.slice_address),
270
+ sliceAddress: normalizeAddress(blob.slice_address),
260
271
  isWritten: Boolean(Number(blob.is_written)),
261
272
  isDeleted: Boolean(Number(blob.is_deleted))
262
273
  })
@@ -280,9 +291,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
280
291
  return blob_activities.map(
281
292
  (activity) => ({
282
293
  blobName: activity.blob_name,
283
- accountAddress: AccountAddress.from(
284
- activity.blob_name.substring(1, 65)
285
- ),
294
+ accountAddress: normalizeAddress(activity.blob_name.substring(1, 65)),
286
295
  type: activityTypeMapping[activity.event_type] ?? "unknown",
287
296
  eventType: activity.event_type,
288
297
  eventIndex: Number(activity.event_index),
@@ -357,7 +366,8 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
357
366
  async registerBlob(params) {
358
367
  const options = this.mergeOptions(params.options);
359
368
  this.validateUsdSponsorConfig(options.usdSponsor, options.submit);
360
- const chunksetSize = options.chunksetSizeBytes ?? DEFAULT_CHUNKSET_SIZE_BYTES;
369
+ const config = params.config ?? defaultErasureCodingConfig();
370
+ const chunksetSize = config.chunkSizeBytes * config.erasure_k;
361
371
  const buildArgs = {
362
372
  ...options.build,
363
373
  data: _ShelbyBlobClient.createRegisterBlobPayload({
@@ -368,7 +378,8 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
368
378
  blobMerkleRoot: params.blobMerkleRoot,
369
379
  numChunksets: expectedTotalChunksets(params.size, chunksetSize),
370
380
  expirationMicros: params.expirationMicros,
371
- useSponsoredUsdVariant: options.usdSponsor !== void 0
381
+ useSponsoredUsdVariant: options.usdSponsor !== void 0,
382
+ encoding: config.enumIndex
372
383
  }),
373
384
  sender: params.account.accountAddress
374
385
  };
@@ -541,7 +552,8 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
541
552
  async batchRegisterBlobs(params) {
542
553
  const options = this.mergeOptions(params.options);
543
554
  this.validateUsdSponsorConfig(options.usdSponsor, options.submit);
544
- const chunksetSize = options.chunksetSizeBytes ?? DEFAULT_CHUNKSET_SIZE_BYTES;
555
+ const config = params.config ?? defaultErasureCodingConfig();
556
+ const chunksetSize = config.chunkSizeBytes * config.erasure_k;
545
557
  const buildArgs = {
546
558
  ...options.build,
547
559
  sender: params.account.accountAddress,
@@ -555,7 +567,8 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
555
567
  blobMerkleRoot: blob.blobMerkleRoot,
556
568
  numChunksets: expectedTotalChunksets(blob.blobSize, chunksetSize)
557
569
  })),
558
- useSponsoredUsdVariant: options.usdSponsor !== void 0
570
+ useSponsoredUsdVariant: options.usdSponsor !== void 0,
571
+ encoding: config.enumIndex
559
572
  })
560
573
  };
561
574
  const transaction = options.usdSponsor ? await this.aptos.transaction.build.multiAgent({
@@ -599,8 +612,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
599
612
  // TODO
600
613
  0,
601
614
  // payment tier
602
- 0
603
- // encoding
615
+ params.encoding
604
616
  ]
605
617
  };
606
618
  }
@@ -645,7 +657,8 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
645
657
  blobSizes,
646
658
  // TODO
647
659
  0,
648
- 0
660
+ // payment tier
661
+ params.encoding
649
662
  ]
650
663
  };
651
664
  }
@@ -1,6 +1,7 @@
1
1
  // src/core/chunk.ts
2
2
  var ChunkSizeScheme = /* @__PURE__ */ ((ChunkSizeScheme2) => {
3
3
  ChunkSizeScheme2["ChunkSet10MiB_Chunk1MiB"] = "ChunkSet10MiB_Chunk1MiB";
4
+ ChunkSizeScheme2["ChunkSet2MiB_Chunk1MiB"] = "ChunkSet2MiB_Chunk1MiB";
4
5
  return ChunkSizeScheme2;
5
6
  })(ChunkSizeScheme || {});
6
7
  var CHUNK_SIZE_PARAMS = {
@@ -9,6 +10,12 @@ var CHUNK_SIZE_PARAMS = {
9
10
  chunkSizeBytes: 1 * 1024 * 1024,
10
11
  // 10MiB
11
12
  chunksetSizeBytes: 10 * 1024 * 1024
13
+ },
14
+ ["ChunkSet2MiB_Chunk1MiB" /* ChunkSet2MiB_Chunk1MiB */]: {
15
+ // 1MiB
16
+ chunkSizeBytes: 1 * 1024 * 1024,
17
+ // 2MiB
18
+ chunksetSizeBytes: 2 * 1024 * 1024
12
19
  }
13
20
  };
14
21
  var DEFAULT_CHUNK_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /* ChunkSet10MiB_Chunk1MiB */].chunkSizeBytes;
@@ -16,6 +23,9 @@ var DEFAULT_CHUNKSET_SIZE_BYTES = CHUNK_SIZE_PARAMS["ChunkSet10MiB_Chunk1MiB" /*
16
23
  var ERASURE_CODE_AND_CHUNK_MAPPING = {
17
24
  ["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */]: {
18
25
  ...CHUNK_SIZE_PARAMS.ChunkSet10MiB_Chunk1MiB
26
+ },
27
+ ["ClayCode_4Total_2Data_3Helper" /* ClayCode_4Total_2Data_3Helper */]: {
28
+ ...CHUNK_SIZE_PARAMS.ChunkSet2MiB_Chunk1MiB
19
29
  }
20
30
  };
21
31
 
@@ -0,0 +1,207 @@
1
+ import {
2
+ MICROPAYMENTS_DEPLOYER
3
+ } from "./chunk-4ZOFT75Q.mjs";
4
+
5
+ // src/core/types/payments.ts
6
+ import {
7
+ AccountAddress,
8
+ Deserializer,
9
+ Hex,
10
+ Serializer
11
+ } from "@aptos-labs/ts-sdk";
12
+ var MICROPAYMENTS_MODULE_NAME = "micropayments";
13
+ var WITHDRAW_APPROVAL_STRUCT_NAME = "WithdrawApproval";
14
+ function serializeTypeInfo(serializer, moduleAddress, moduleName, structName) {
15
+ moduleAddress.serialize(serializer);
16
+ const moduleNameBytes = new TextEncoder().encode(moduleName);
17
+ serializer.serializeBytes(moduleNameBytes);
18
+ const structNameBytes = new TextEncoder().encode(structName);
19
+ serializer.serializeBytes(structNameBytes);
20
+ }
21
+ var StaleChannelStateError = class _StaleChannelStateError extends Error {
22
+ /**
23
+ * The last valid micropayment stored by the server.
24
+ * Clients can use this to reset their local channel state.
25
+ */
26
+ storedMicropayment;
27
+ constructor(storedMicropayment, message) {
28
+ super(
29
+ message ?? "Client has stale channel state. Use the returned micropayment to reset local state."
30
+ );
31
+ this.name = "StaleChannelStateError";
32
+ this.storedMicropayment = storedMicropayment;
33
+ }
34
+ /**
35
+ * Returns the stored micropayment as a base64-encoded string.
36
+ */
37
+ toBase64() {
38
+ const bytes = this.storedMicropayment.bcsToBytes();
39
+ const binaryString = Array.from(
40
+ bytes,
41
+ (byte) => String.fromCharCode(byte)
42
+ ).join("");
43
+ return btoa(binaryString);
44
+ }
45
+ /**
46
+ * Creates a StaleChannelStateError from a base64-encoded micropayment string.
47
+ */
48
+ static fromBase64(base64, message) {
49
+ const binaryString = atob(base64);
50
+ const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
51
+ const micropayment = SenderBuiltMicropayment.deserialize(bytes);
52
+ return new _StaleChannelStateError(micropayment, message);
53
+ }
54
+ };
55
+ var SenderBuiltMicropayment = class _SenderBuiltMicropayment {
56
+ /**
57
+ * The sender's address (owner of the payment channel).
58
+ */
59
+ sender;
60
+ /**
61
+ * The receiver's address (beneficiary of the withdrawal).
62
+ */
63
+ receiver;
64
+ /**
65
+ * The unique ID of the payment channel.
66
+ */
67
+ paymentChannelId;
68
+ /**
69
+ * The cumulative amount the receiver is authorized to withdraw.
70
+ */
71
+ amount;
72
+ /**
73
+ * The fungible asset metadata address.
74
+ */
75
+ fungibleAssetAddress;
76
+ /**
77
+ * Monotonically increasing sequence number for replay protection.
78
+ */
79
+ sequenceNumber;
80
+ /**
81
+ * The sender's Ed25519 public key (32 bytes).
82
+ * Used by the receiver to verify the signature before submitting.
83
+ */
84
+ publicKey;
85
+ /**
86
+ * The Ed25519 signature of the SignedMessage<WithdrawApproval> struct.
87
+ * The SignedMessage includes TypeInfo for domain separation.
88
+ */
89
+ signature;
90
+ /**
91
+ * The deployer address of the micropayments module.
92
+ * This is needed to reconstruct the TypeInfo for signature verification.
93
+ */
94
+ deployer;
95
+ constructor(sender, receiver, paymentChannelId, amount, fungibleAssetAddress, sequenceNumber, publicKey, signature, deployer) {
96
+ this.sender = sender;
97
+ this.receiver = receiver;
98
+ this.paymentChannelId = paymentChannelId;
99
+ this.amount = amount;
100
+ this.fungibleAssetAddress = fungibleAssetAddress;
101
+ this.sequenceNumber = sequenceNumber;
102
+ this.publicKey = publicKey;
103
+ this.signature = signature;
104
+ this.deployer = deployer ?? AccountAddress.fromString(MICROPAYMENTS_DEPLOYER);
105
+ }
106
+ /**
107
+ * Creates the BCS-serialized message that was signed.
108
+ * This is a SignedMessage<WithdrawApproval> which includes:
109
+ * 1. TypeInfo (module_address, module_name, struct_name)
110
+ * 2. WithdrawApproval struct fields
111
+ *
112
+ * This format is used with signature_verify_strict_t for domain separation.
113
+ */
114
+ getSignedMessage() {
115
+ return _SenderBuiltMicropayment.buildSignedMessage({
116
+ deployer: this.deployer,
117
+ sender: this.sender,
118
+ receiver: this.receiver,
119
+ fungibleAssetAddress: this.fungibleAssetAddress,
120
+ amount: this.amount,
121
+ paymentChannelId: this.paymentChannelId,
122
+ sequenceNumber: this.sequenceNumber
123
+ });
124
+ }
125
+ /**
126
+ * Static helper to build the SignedMessage<WithdrawApproval> bytes from raw parameters.
127
+ * This can be used to create the message for signing without constructing the full object.
128
+ *
129
+ * @param params - The withdrawal approval parameters.
130
+ * @returns The BCS-serialized SignedMessage<WithdrawApproval> bytes.
131
+ */
132
+ static buildSignedMessage(params) {
133
+ const serializer = new Serializer();
134
+ serializeTypeInfo(
135
+ serializer,
136
+ params.deployer,
137
+ MICROPAYMENTS_MODULE_NAME,
138
+ WITHDRAW_APPROVAL_STRUCT_NAME
139
+ );
140
+ params.sender.serialize(serializer);
141
+ params.receiver.serialize(serializer);
142
+ params.fungibleAssetAddress.serialize(serializer);
143
+ serializer.serializeU64(params.amount);
144
+ serializer.serializeU64(params.paymentChannelId);
145
+ serializer.serializeU64(params.sequenceNumber);
146
+ return serializer.toUint8Array();
147
+ }
148
+ serialize(serializer) {
149
+ this.sender.serialize(serializer);
150
+ this.receiver.serialize(serializer);
151
+ this.fungibleAssetAddress.serialize(serializer);
152
+ serializer.serializeU64(this.amount);
153
+ serializer.serializeU64(this.paymentChannelId);
154
+ serializer.serializeU64(this.sequenceNumber);
155
+ serializer.serializeBytes(this.publicKey);
156
+ serializer.serializeBytes(this.signature);
157
+ this.deployer.serialize(serializer);
158
+ }
159
+ bcsToBytes() {
160
+ const serializer = new Serializer();
161
+ this.serialize(serializer);
162
+ return serializer.toUint8Array();
163
+ }
164
+ bcsToHex() {
165
+ return Hex.fromHexInput(this.bcsToBytes());
166
+ }
167
+ toStringWithoutPrefix() {
168
+ return this.bcsToHex().toStringWithoutPrefix();
169
+ }
170
+ toString() {
171
+ return this.bcsToHex().toString();
172
+ }
173
+ /**
174
+ * Deserializes a SenderBuiltMicropayment from BCS bytes.
175
+ * @param bytes - The bytes to deserialize from (Uint8Array or hex string).
176
+ * @returns A new SenderBuiltMicropayment instance.
177
+ */
178
+ static deserialize(bytes) {
179
+ const bytesArray = typeof bytes === "string" ? Hex.fromHexInput(bytes).toUint8Array() : bytes;
180
+ const deserializer = new Deserializer(bytesArray);
181
+ const sender = AccountAddress.deserialize(deserializer);
182
+ const receiver = AccountAddress.deserialize(deserializer);
183
+ const fungibleAssetAddress = AccountAddress.deserialize(deserializer);
184
+ const amount = deserializer.deserializeU64();
185
+ const paymentChannelId = deserializer.deserializeU64();
186
+ const sequenceNumber = deserializer.deserializeU64();
187
+ const publicKey = deserializer.deserializeBytes();
188
+ const signature = deserializer.deserializeBytes();
189
+ const deployer = AccountAddress.deserialize(deserializer);
190
+ return new _SenderBuiltMicropayment(
191
+ sender,
192
+ receiver,
193
+ paymentChannelId,
194
+ amount,
195
+ fungibleAssetAddress,
196
+ sequenceNumber,
197
+ publicKey,
198
+ signature,
199
+ deployer
200
+ );
201
+ }
202
+ };
203
+
204
+ export {
205
+ StaleChannelStateError,
206
+ SenderBuiltMicropayment
207
+ };
@@ -9,6 +9,7 @@ var ReedSolomonErasureCodingProvider = class {
9
9
  const erasure_k = options?.erasure_k ?? DEFAULT_ERASURE_K;
10
10
  const erasure_n = options?.erasure_n ?? DEFAULT_ERASURE_N;
11
11
  const chunkSizeBytes = options?.chunkSizeBytes ?? DEFAULT_CHUNK_SIZE_BYTES;
12
+ const enumIndex = -1;
12
13
  if (erasure_k <= 0)
13
14
  throw new Error("erasure_k (number of data chunks) must be > 0");
14
15
  if (erasure_n <= erasure_k)
@@ -19,7 +20,8 @@ var ReedSolomonErasureCodingProvider = class {
19
20
  this.config = {
20
21
  erasure_n,
21
22
  erasure_k,
22
- chunkSizeBytes
23
+ chunkSizeBytes,
24
+ enumIndex
23
25
  };
24
26
  }
25
27
  encode(data) {
@@ -1,12 +1,3 @@
1
- import {
2
- DEFAULT_CHUNK_SIZE_BYTES
3
- } from "./chunk-67F5YZ25.mjs";
4
- import {
5
- DEFAULT_ERASURE_D,
6
- DEFAULT_ERASURE_K,
7
- DEFAULT_ERASURE_N
8
- } from "./chunk-LZSIZJYR.mjs";
9
-
10
1
  // src/core/erasure/clay-codes.ts
11
2
  import {
12
3
  createDecoder,
@@ -27,13 +18,7 @@ var ClayErasureCodingProvider = class _ClayErasureCodingProvider {
27
18
  /**
28
19
  * Static factory method to create an initialized ClayErasureCodingProvider
29
20
  */
30
- static async create(options) {
31
- const config = buildClayConfig({
32
- erasure_n: options?.erasure_n ?? DEFAULT_ERASURE_N,
33
- erasure_k: options?.erasure_k ?? DEFAULT_ERASURE_K,
34
- erasure_d: options?.erasure_d ?? DEFAULT_ERASURE_D,
35
- chunkSizeBytes: options?.chunkSizeBytes ?? DEFAULT_CHUNK_SIZE_BYTES
36
- });
21
+ static async create(config) {
37
22
  const provider = new _ClayErasureCodingProvider(config);
38
23
  [provider.encoderCache, provider.decoderCache] = await Promise.all([
39
24
  createEncoder({
@@ -118,7 +103,7 @@ var ClayErasureCodingProvider = class _ClayErasureCodingProvider {
118
103
  }
119
104
  };
120
105
  function buildClayConfig(input) {
121
- const { erasure_n, erasure_k, erasure_d, chunkSizeBytes } = input;
106
+ const { erasure_n, erasure_k, erasure_d, chunkSizeBytes, enumIndex } = input;
122
107
  if (erasure_n <= 0)
123
108
  throw new Error("erasure_n (total number of chunks) must be > 0");
124
109
  if (erasure_k <= 0)
@@ -140,10 +125,12 @@ function buildClayConfig(input) {
140
125
  erasure_n,
141
126
  erasure_k,
142
127
  erasure_d,
143
- chunkSizeBytes
128
+ chunkSizeBytes,
129
+ enumIndex
144
130
  };
145
131
  }
146
132
 
147
133
  export {
148
- ClayErasureCodingProvider
134
+ ClayErasureCodingProvider,
135
+ buildClayConfig
149
136
  };