@shelby-protocol/sdk 0.3.0 → 0.3.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 (106) hide show
  1. package/dist/browser/index.d.ts +12 -3
  2. package/dist/browser/index.mjs +3717 -142
  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 +0 -43
  7. package/dist/core/clients/ShelbyBlobClient.mjs +1084 -17
  8. package/dist/core/clients/ShelbyClient.d.ts +12 -2
  9. package/dist/core/clients/ShelbyClient.mjs +2915 -23
  10. package/dist/core/clients/ShelbyClientConfig.mjs +0 -1
  11. package/dist/core/clients/ShelbyMetadataClient.d.ts +0 -18
  12. package/dist/core/clients/ShelbyMetadataClient.mjs +306 -6
  13. package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +7 -49
  14. package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +839 -13
  15. package/dist/core/clients/ShelbyPlacementGroupClient.mjs +307 -8
  16. package/dist/core/clients/ShelbyRPCClient.d.ts +106 -3
  17. package/dist/core/clients/ShelbyRPCClient.mjs +1261 -12
  18. package/dist/core/clients/index.d.ts +2 -1
  19. package/dist/core/clients/index.mjs +3420 -39
  20. package/dist/core/clients/utils.mjs +65 -6
  21. package/dist/core/commitments.mjs +270 -11
  22. package/dist/core/constants.d.ts +2 -2
  23. package/dist/core/constants.mjs +39 -16
  24. package/dist/core/erasure/clay-codes.mjs +129 -4
  25. package/dist/core/erasure/constants.mjs +33 -10
  26. package/dist/core/erasure/default.mjs +191 -9
  27. package/dist/core/erasure/index.mjs +266 -23
  28. package/dist/core/erasure/reed-solomon.mjs +68 -4
  29. package/dist/core/erasure/utils.mjs +0 -2
  30. package/dist/core/errors.mjs +29 -8
  31. package/dist/core/index.d.ts +1 -1
  32. package/dist/core/index.mjs +3711 -142
  33. package/dist/core/layout.mjs +37 -5
  34. package/dist/core/networks.mjs +10 -5
  35. package/dist/core/operations/generated/sdk.d.ts +9 -0
  36. package/dist/core/operations/generated/sdk.mjs +183 -18
  37. package/dist/core/operations/index.mjs +284 -24
  38. package/dist/core/promises.mjs +4 -4
  39. package/dist/core/rpc-responses.mjs +29 -10
  40. package/dist/core/shelby-explorer.mjs +31 -6
  41. package/dist/core/strings.mjs +0 -2
  42. package/dist/core/types/blobs.mjs +0 -1
  43. package/dist/core/types/index.mjs +230 -9
  44. package/dist/core/types/payments.d.ts +6 -6
  45. package/dist/core/types/payments.mjs +230 -5
  46. package/dist/core/types/placement_groups.mjs +0 -1
  47. package/dist/core/types/storage_providers.mjs +0 -1
  48. package/dist/core/utils.mjs +94 -8
  49. package/dist/node/clients/ShelbyNodeClient.d.ts +1 -0
  50. package/dist/node/clients/ShelbyNodeClient.mjs +2919 -24
  51. package/dist/node/clients/index.d.ts +1 -0
  52. package/dist/node/clients/index.mjs +2920 -26
  53. package/dist/node/index.d.ts +1 -1
  54. package/dist/node/index.mjs +3734 -149
  55. package/dist/node/parallel/commitment_worker.d.ts +9 -0
  56. package/dist/node/parallel/commitment_worker.mjs +298 -0
  57. package/dist/node/parallel/commitment_worker_pool.d.ts +35 -0
  58. package/dist/node/parallel/commitment_worker_pool.mjs +286 -0
  59. package/dist/node/parallel/default_commitment_worker_pool.d.ts +24 -0
  60. package/dist/node/parallel/default_commitment_worker_pool.mjs +302 -0
  61. package/dist/node/parallel/index.d.ts +11 -0
  62. package/dist/node/parallel/index.mjs +563 -0
  63. package/dist/node/parallel/parallel_commitments.d.ts +32 -0
  64. package/dist/node/parallel/parallel_commitments.mjs +561 -0
  65. package/dist/node/parallel/worker_pool.d.ts +74 -0
  66. package/dist/node/parallel/worker_pool.mjs +248 -0
  67. package/dist/node/testUtil.mjs +8 -4
  68. package/package.json +6 -2
  69. package/dist/chunk-3NRBHSMQ.mjs +0 -12
  70. package/dist/chunk-5BVSWXQJ.mjs +0 -801
  71. package/dist/chunk-6FJNAUU5.mjs +0 -278
  72. package/dist/chunk-6XSZRDLJ.mjs +0 -375
  73. package/dist/chunk-7P6ASYW6.mjs +0 -9
  74. package/dist/chunk-A4IG6GSE.mjs +0 -21
  75. package/dist/chunk-AD2G3QYD.mjs +0 -0
  76. package/dist/chunk-AUQDI5BS.mjs +0 -43
  77. package/dist/chunk-AY3HBWXA.mjs +0 -51
  78. package/dist/chunk-BDSW5PHM.mjs +0 -37
  79. package/dist/chunk-C6RQ3AEU.mjs +0 -51
  80. package/dist/chunk-CQ6QPIZK.mjs +0 -37
  81. package/dist/chunk-D6GQHO6G.mjs +0 -15
  82. package/dist/chunk-EM67QTMR.mjs +0 -0
  83. package/dist/chunk-I6NG5GNL.mjs +0 -8
  84. package/dist/chunk-JTXYKO3U.mjs +0 -38
  85. package/dist/chunk-KG2TMLEV.mjs +0 -207
  86. package/dist/chunk-M3CP5TFP.mjs +0 -39
  87. package/dist/chunk-M7W43K2Q.mjs +0 -505
  88. package/dist/chunk-MB7C7VQF.mjs +0 -0
  89. package/dist/chunk-MNCQBEMS.mjs +0 -55
  90. package/dist/chunk-MQUVYMNQ.mjs +0 -0
  91. package/dist/chunk-NEO7Z3ZQ.mjs +0 -49
  92. package/dist/chunk-NHWWORCH.mjs +0 -72
  93. package/dist/chunk-OEK24ON7.mjs +0 -135
  94. package/dist/chunk-QQ57OGQ2.mjs +0 -0
  95. package/dist/chunk-RNNJXTX2.mjs +0 -154
  96. package/dist/chunk-S6Q4OG7H.mjs +0 -83
  97. package/dist/chunk-TET3DJEO.mjs +0 -199
  98. package/dist/chunk-UEZNZBJO.mjs +0 -104
  99. package/dist/chunk-V46D5NBW.mjs +0 -11
  100. package/dist/chunk-V4B3GAMQ.mjs +0 -42
  101. package/dist/chunk-WFWRBNTW.mjs +0 -412
  102. package/dist/chunk-WTICJPDB.mjs +0 -0
  103. package/dist/chunk-XNEIWM4O.mjs +0 -0
  104. package/dist/chunk-Z4FZ7W6L.mjs +0 -39
  105. package/dist/chunk-Z7RFCADT.mjs +0 -0
  106. package/dist/chunk-ZHXCVRZX.mjs +0 -0
@@ -1,12 +1,98 @@
1
+ // src/core/utils.ts
1
2
  import {
2
- buildRequestUrl,
3
- concatHashes,
4
- getBlobNameSuffix,
5
- normalizeAddress,
6
- readInChunks,
7
- zeroPadBytes
8
- } from "../chunk-UEZNZBJO.mjs";
9
- import "../chunk-7P6ASYW6.mjs";
3
+ AccountAddress,
4
+ Hex
5
+ } from "@aptos-labs/ts-sdk";
6
+ async function* readInChunks(input, chunkSize) {
7
+ let idx = 0;
8
+ if (isReadableStream(input)) {
9
+ const reader = input.getReader();
10
+ let buffer = new Uint8Array(chunkSize);
11
+ let bufferWriteOffset = 0;
12
+ try {
13
+ while (true) {
14
+ const { value, done } = await reader.read();
15
+ if (done) break;
16
+ if (value === void 0) continue;
17
+ let srcOffset = 0;
18
+ while (srcOffset < value.length) {
19
+ const remainingCapacity = chunkSize - bufferWriteOffset;
20
+ const bytesToCopy = Math.min(
21
+ remainingCapacity,
22
+ value.length - srcOffset
23
+ );
24
+ buffer.set(
25
+ value.subarray(srcOffset, srcOffset + bytesToCopy),
26
+ bufferWriteOffset
27
+ );
28
+ bufferWriteOffset += bytesToCopy;
29
+ srcOffset += bytesToCopy;
30
+ if (bufferWriteOffset >= chunkSize) {
31
+ yield [idx++, buffer];
32
+ buffer = new Uint8Array(chunkSize);
33
+ bufferWriteOffset = 0;
34
+ }
35
+ }
36
+ }
37
+ } finally {
38
+ reader.releaseLock();
39
+ }
40
+ if (bufferWriteOffset > 0) {
41
+ yield [idx++, buffer.subarray(0, bufferWriteOffset)];
42
+ }
43
+ return;
44
+ }
45
+ const view = toUint8Array(input);
46
+ for (let offset = 0; offset < view.byteLength; offset += chunkSize) {
47
+ yield [
48
+ idx++,
49
+ view.subarray(offset, Math.min(offset + chunkSize, view.byteLength))
50
+ ];
51
+ }
52
+ }
53
+ function zeroPadBytes(buffer, desiredLength) {
54
+ if (buffer.byteLength === desiredLength) {
55
+ return buffer;
56
+ }
57
+ if (buffer.byteLength > desiredLength) {
58
+ return buffer.subarray(0, desiredLength);
59
+ }
60
+ const paddedBuffer = new Uint8Array(desiredLength);
61
+ paddedBuffer.set(buffer);
62
+ return paddedBuffer;
63
+ }
64
+ async function concatHashes(parts) {
65
+ const chunks = parts.map((part) => Hex.fromHexInput(part).toUint8Array());
66
+ const totalLength = chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0);
67
+ const combined = new Uint8Array(totalLength);
68
+ let offset = 0;
69
+ for (const chunk of chunks) {
70
+ combined.set(chunk, offset);
71
+ offset += chunk.byteLength;
72
+ }
73
+ return Hex.fromHexInput(
74
+ new Uint8Array(await crypto.subtle.digest("SHA-256", combined))
75
+ );
76
+ }
77
+ function isReadableStream(value) {
78
+ return typeof value === "object" && value !== null && "getReader" in value && typeof value.getReader === "function";
79
+ }
80
+ function toUint8Array(view) {
81
+ return view instanceof Uint8Array ? view : new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
82
+ }
83
+ function buildRequestUrl(path, baseUrl) {
84
+ const baseHasSlash = baseUrl.endsWith("/");
85
+ const safeBase = baseHasSlash ? baseUrl : `${baseUrl}/`;
86
+ const safePath = path.replace(/^\/+/, "");
87
+ return new URL(safePath, safeBase);
88
+ }
89
+ function getBlobNameSuffix(blobName) {
90
+ const parts = blobName.split("/");
91
+ return parts.slice(1).join("/") || "";
92
+ }
93
+ function normalizeAddress(address) {
94
+ return AccountAddress.from(address, { maxMissingChars: 63 });
95
+ }
10
96
  export {
11
97
  buildRequestUrl,
12
98
  concatHashes,
@@ -16,6 +16,7 @@ import 'graphql-request';
16
16
  import '../../core/operations/generated/sdk.js';
17
17
  import 'graphql';
18
18
  import '../../core/clients/ShelbyRPCClient.js';
19
+ import '../../core/rpc-responses.js';
19
20
  import '../../core/types/payments.js';
20
21
 
21
22
  declare class ShelbyNodeClient extends ShelbyClient {