@zing-protocol/zing-sdk 0.0.1 → 0.0.3

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 (227) hide show
  1. package/dist/_generated/index.js +6 -0
  2. package/dist/_generated/utils/index.d.ts +12 -0
  3. package/dist/_generated/utils/index.js +135 -0
  4. package/dist/_generated/zing_framework/coin_utils.d.ts +15 -0
  5. package/dist/_generated/zing_framework/coin_utils.js +19 -0
  6. package/dist/_generated/zing_framework/deps/sui/object.d.ts +8 -0
  7. package/{src/_generated/zing_governance/deps/sui/object.ts → dist/_generated/zing_framework/deps/sui/object.js} +4 -7
  8. package/dist/_generated/zing_framework/derived_object_bag.d.ts +166 -0
  9. package/dist/_generated/zing_framework/derived_object_bag.js +221 -0
  10. package/dist/_generated/zing_framework/derived_table.d.ts +153 -0
  11. package/dist/_generated/zing_framework/derived_table.js +200 -0
  12. package/dist/_generated/zing_governance/admin.d.ts +20 -0
  13. package/dist/_generated/zing_governance/admin.js +26 -0
  14. package/dist/_generated/zing_governance/deps/sui/object.d.ts +8 -0
  15. package/{src/_generated/zing_identity/deps/sui/object.ts → dist/_generated/zing_governance/deps/sui/object.js} +4 -7
  16. package/dist/_generated/zing_governance/treasury.d.ts +56 -0
  17. package/dist/_generated/zing_governance/treasury.js +78 -0
  18. package/dist/_generated/zing_identity/config.d.ts +87 -0
  19. package/dist/_generated/zing_identity/config.js +98 -0
  20. package/{src/_generated/zing_studio/deps/std/type_name.ts → dist/_generated/zing_identity/deps/std/type_name.d.ts} +3 -11
  21. package/dist/_generated/zing_identity/deps/std/type_name.js +22 -0
  22. package/dist/_generated/zing_identity/deps/sui/object.d.ts +8 -0
  23. package/{src/_generated/zing_studio/deps/sui/object.ts → dist/_generated/zing_identity/deps/sui/object.js} +4 -7
  24. package/dist/_generated/zing_identity/deps/sui/object_table.d.ts +12 -0
  25. package/{src/_generated/zing_identity/deps/sui/object_table.ts → dist/_generated/zing_identity/deps/sui/object_table.js} +7 -10
  26. package/dist/_generated/zing_identity/deps/sui/table.d.ts +12 -0
  27. package/{src/_generated/zing_studio/deps/sui/table.ts → dist/_generated/zing_identity/deps/sui/table.js} +7 -10
  28. package/{src/_generated/zing_identity/deps/sui/vec_set.ts → dist/_generated/zing_identity/deps/sui/vec_set.d.ts} +3 -14
  29. package/dist/_generated/zing_identity/deps/sui/vec_set.js +22 -0
  30. package/dist/_generated/zing_identity/ecdsa.d.ts +81 -0
  31. package/dist/_generated/zing_identity/ecdsa.js +87 -0
  32. package/dist/_generated/zing_identity/identity.d.ts +262 -0
  33. package/dist/_generated/zing_identity/identity.js +294 -0
  34. package/dist/_generated/zing_identity/reclaim.d.ts +356 -0
  35. package/dist/_generated/zing_identity/reclaim.js +414 -0
  36. package/dist/_generated/zing_studio/app.d.ts +351 -0
  37. package/dist/_generated/zing_studio/app.js +451 -0
  38. package/dist/_generated/zing_studio/article.d.ts +331 -0
  39. package/dist/_generated/zing_studio/article.js +331 -0
  40. package/dist/_generated/zing_studio/config.d.ts +203 -0
  41. package/dist/_generated/zing_studio/config.js +233 -0
  42. package/{src/_generated/zing_identity/deps/std/type_name.ts → dist/_generated/zing_studio/deps/std/type_name.d.ts} +3 -11
  43. package/dist/_generated/zing_studio/deps/std/type_name.js +22 -0
  44. package/dist/_generated/zing_studio/deps/sui/bag.d.ts +12 -0
  45. package/{src/_generated/zing_studio/deps/sui/bag.ts → dist/_generated/zing_studio/deps/sui/bag.js} +7 -10
  46. package/dist/_generated/zing_studio/deps/sui/balance.d.ts +12 -0
  47. package/{src/_generated/zing_studio/deps/sui/balance.ts → dist/_generated/zing_studio/deps/sui/balance.js} +4 -7
  48. package/dist/_generated/zing_studio/deps/sui/coin.d.ts +12 -0
  49. package/{src/_generated/zing_studio/deps/sui/coin.ts → dist/_generated/zing_studio/deps/sui/coin.js} +5 -8
  50. package/dist/_generated/zing_studio/deps/sui/dynamic_field.d.ts +126 -0
  51. package/dist/_generated/zing_studio/deps/sui/dynamic_field.js +140 -0
  52. package/dist/_generated/zing_studio/deps/sui/object.d.ts +8 -0
  53. package/{src/_generated/zing_framework/deps/sui/object.ts → dist/_generated/zing_studio/deps/sui/object.js} +4 -7
  54. package/dist/_generated/zing_studio/deps/sui/table.d.ts +12 -0
  55. package/{src/_generated/zing_identity/deps/sui/table.ts → dist/_generated/zing_studio/deps/sui/table.js} +7 -10
  56. package/dist/_generated/zing_studio/deps/sui/vec_map.d.ts +30 -0
  57. package/{src/_generated/zing_studio/deps/sui/vec_map.ts → dist/_generated/zing_studio/deps/sui/vec_map.js} +15 -21
  58. package/{src/_generated/zing_studio/deps/sui/vec_set.ts → dist/_generated/zing_studio/deps/sui/vec_set.d.ts} +3 -14
  59. package/dist/_generated/zing_studio/deps/sui/vec_set.js +22 -0
  60. package/dist/_generated/zing_studio/deps/walrus/blob.d.ts +20 -0
  61. package/{src/_generated/zing_studio/deps/walrus/blob.ts → dist/_generated/zing_studio/deps/walrus/blob.js} +11 -12
  62. package/dist/_generated/zing_studio/deps/walrus/events.d.ts +83 -0
  63. package/dist/_generated/zing_studio/deps/walrus/events.js +122 -0
  64. package/dist/_generated/zing_studio/deps/walrus/metadata.d.ts +71 -0
  65. package/dist/_generated/zing_studio/deps/walrus/metadata.js +73 -0
  66. package/dist/_generated/zing_studio/deps/walrus/storage_resource.d.ts +12 -0
  67. package/{src/_generated/zing_studio/deps/walrus/storage_resource.ts → dist/_generated/zing_studio/deps/walrus/storage_resource.js} +7 -8
  68. package/dist/_generated/zing_studio/deps/zing_framework/derived_object_bag.d.ts +12 -0
  69. package/{src/_generated/zing_studio/deps/zing_framework/derived_object_bag.ts → dist/_generated/zing_studio/deps/zing_framework/derived_object_bag.js} +7 -8
  70. package/dist/_generated/zing_studio/deps/zing_framework/derived_table.d.ts +12 -0
  71. package/{src/_generated/zing_studio/deps/zing_framework/derived_table.ts → dist/_generated/zing_studio/deps/zing_framework/derived_table.js} +7 -8
  72. package/dist/_generated/zing_studio/donation.d.ts +24 -0
  73. package/{src/_generated/zing_studio/donation.ts → dist/_generated/zing_studio/donation.js} +7 -8
  74. package/dist/_generated/zing_studio/enclave.d.ts +187 -0
  75. package/dist/_generated/zing_studio/enclave.js +231 -0
  76. package/dist/_generated/zing_studio/nitro_attestation.d.ts +148 -0
  77. package/dist/_generated/zing_studio/nitro_attestation.js +183 -0
  78. package/dist/_generated/zing_studio/referral.d.ts +166 -0
  79. package/dist/_generated/zing_studio/referral.js +224 -0
  80. package/dist/_generated/zing_studio/storage.d.ts +327 -0
  81. package/dist/_generated/zing_studio/storage.js +365 -0
  82. package/dist/_generated/zing_studio/studio.d.ts +282 -0
  83. package/dist/_generated/zing_studio/studio.js +360 -0
  84. package/dist/bcs.d.ts +61 -0
  85. package/dist/bcs.js +109 -0
  86. package/dist/client/index.d.ts +228 -0
  87. package/dist/client/index.js +296 -0
  88. package/dist/client/types.d.ts +23 -0
  89. package/dist/client/types.js +1 -0
  90. package/dist/components/index.js +3 -0
  91. package/dist/components/wallet-provider.d.ts +7 -0
  92. package/dist/components/wallet-provider.js +33 -0
  93. package/dist/components/walrus-provider.d.ts +31 -0
  94. package/dist/components/walrus-provider.js +71 -0
  95. package/dist/components/zing-provider.d.ts +15 -0
  96. package/dist/components/zing-provider.js +22 -0
  97. package/dist/config/common.d.ts +23 -0
  98. package/dist/config/common.js +61 -0
  99. package/dist/config/index.d.ts +8 -0
  100. package/dist/config/index.js +28 -0
  101. package/dist/config/mainnet.d.ts +6 -0
  102. package/dist/config/mainnet.js +80 -0
  103. package/dist/config/testnet.d.ts +6 -0
  104. package/dist/config/testnet.js +81 -0
  105. package/dist/config/types.d.ts +49 -0
  106. package/dist/config/types.js +1 -0
  107. package/dist/const.d.ts +4 -0
  108. package/dist/const.js +25 -0
  109. package/dist/getters.d.ts +228 -0
  110. package/dist/getters.js +317 -0
  111. package/{src/hooks/index.ts → dist/hooks/index.d.ts} +2 -3
  112. package/dist/hooks/index.js +9 -0
  113. package/dist/hooks/useGetStudio.d.ts +26 -0
  114. package/dist/hooks/useGetStudio.js +17 -0
  115. package/dist/hooks/useGetTierPlan.d.ts +7 -0
  116. package/dist/hooks/useGetTierPlan.js +85 -0
  117. package/dist/hooks/useReclaim.d.ts +12 -0
  118. package/dist/hooks/useReclaim.js +87 -0
  119. package/dist/hooks/useSignAndExecuteTransaction.d.ts +6 -0
  120. package/dist/hooks/useSignAndExecuteTransaction.js +40 -0
  121. package/dist/hooks/useSignPersonalMessage.d.ts +8 -0
  122. package/dist/hooks/useSignPersonalMessage.js +21 -0
  123. package/dist/hooks/useZingInfiniteQueries.d.ts +75 -0
  124. package/dist/hooks/useZingInfiniteQueries.js +28 -0
  125. package/dist/hooks/useZingMutation.d.ts +35 -0
  126. package/dist/hooks/useZingMutation.js +37 -0
  127. package/dist/hooks/useZingQueries.d.ts +127 -0
  128. package/dist/hooks/useZingQueries.js +37 -0
  129. package/dist/hooks/useZingQuery.d.ts +147 -0
  130. package/dist/hooks/useZingQuery.js +34 -0
  131. package/{src/index.ts → dist/index.d.ts} +2 -3
  132. package/dist/index.js +9 -0
  133. package/dist/lib/utils/colorful-logger.d.ts +2 -0
  134. package/dist/lib/utils/colorful-logger.js +23 -0
  135. package/dist/lib/utils/const.d.ts +25 -0
  136. package/dist/lib/utils/const.js +25 -0
  137. package/dist/lib/utils/helpers.d.ts +10 -0
  138. package/dist/lib/utils/helpers.js +49 -0
  139. package/dist/lib/utils/index.js +4 -0
  140. package/dist/lib/utils/init-app-with-shadow.d.ts +6 -0
  141. package/dist/lib/utils/init-app-with-shadow.js +28 -0
  142. package/dist/lib/utils/quilt.d.ts +61 -0
  143. package/dist/lib/utils/quilt.js +194 -0
  144. package/dist/lib/utils/reclaim.d.ts +29 -0
  145. package/dist/lib/utils/reclaim.js +88 -0
  146. package/dist/lib/utils/types.d.ts +5 -0
  147. package/dist/lib/utils/types.js +1 -0
  148. package/dist/mutations/index.js +3 -0
  149. package/dist/mutations/seal.d.ts +12 -0
  150. package/dist/mutations/seal.js +41 -0
  151. package/dist/mutations/signer.d.ts +10 -0
  152. package/dist/mutations/signer.js +176 -0
  153. package/dist/mutations/walrus.d.ts +98 -0
  154. package/dist/mutations/walrus.js +488 -0
  155. package/dist/stores/index.js +3 -0
  156. package/dist/stores/walletStore.d.ts +48 -0
  157. package/dist/stores/walletStore.js +232 -0
  158. package/dist/stores/walrusStore.d.ts +28 -0
  159. package/dist/stores/walrusStore.js +61 -0
  160. package/dist/stores/zkloginStore.d.ts +28 -0
  161. package/dist/stores/zkloginStore.js +27 -0
  162. package/dist/types.d.ts +99 -0
  163. package/dist/types.js +1 -0
  164. package/package.json +18 -10
  165. package/src/_generated/utils/index.ts +0 -181
  166. package/src/_generated/zing_framework/coin_utils.ts +0 -41
  167. package/src/_generated/zing_framework/derived_object_bag.ts +0 -400
  168. package/src/_generated/zing_framework/derived_table.ts +0 -366
  169. package/src/_generated/zing_governance/admin.ts +0 -47
  170. package/src/_generated/zing_governance/treasury.ts +0 -134
  171. package/src/_generated/zing_identity/config.ts +0 -191
  172. package/src/_generated/zing_identity/ecdsa.ts +0 -166
  173. package/src/_generated/zing_identity/identity.ts +0 -661
  174. package/src/_generated/zing_identity/reclaim.ts +0 -803
  175. package/src/_generated/zing_studio/app.ts +0 -855
  176. package/src/_generated/zing_studio/article.ts +0 -598
  177. package/src/_generated/zing_studio/config.ts +0 -475
  178. package/src/_generated/zing_studio/deps/sui/dynamic_field.ts +0 -272
  179. package/src/_generated/zing_studio/deps/walrus/events.ts +0 -124
  180. package/src/_generated/zing_studio/deps/walrus/metadata.ts +0 -137
  181. package/src/_generated/zing_studio/enclave.ts +0 -466
  182. package/src/_generated/zing_studio/nitro_attestation.ts +0 -308
  183. package/src/_generated/zing_studio/referral.ts +0 -447
  184. package/src/_generated/zing_studio/storage.ts +0 -664
  185. package/src/_generated/zing_studio/studio.ts +0 -682
  186. package/src/bcs.ts +0 -139
  187. package/src/client/index.ts +0 -557
  188. package/src/client/types.ts +0 -28
  189. package/src/components/wallet-provider.tsx +0 -53
  190. package/src/components/walrus-provider.tsx +0 -212
  191. package/src/components/zing-provider.tsx +0 -54
  192. package/src/config/common.ts +0 -82
  193. package/src/config/index.ts +0 -45
  194. package/src/config/mainnet.ts +0 -109
  195. package/src/config/testnet.ts +0 -111
  196. package/src/config/types.ts +0 -69
  197. package/src/const.ts +0 -32
  198. package/src/getters.ts +0 -523
  199. package/src/hooks/useGetStudio.ts +0 -22
  200. package/src/hooks/useGetTierPlan.ts +0 -115
  201. package/src/hooks/useReclaim.ts +0 -165
  202. package/src/hooks/useSignAndExecuteTransaction.ts +0 -57
  203. package/src/hooks/useSignPersonalMessage.ts +0 -28
  204. package/src/hooks/useZingInfiniteQueries.ts +0 -92
  205. package/src/hooks/useZingMutation.ts +0 -66
  206. package/src/hooks/useZingQueries.ts +0 -107
  207. package/src/hooks/useZingQuery.ts +0 -88
  208. package/src/lib/utils/colorful-logger.ts +0 -27
  209. package/src/lib/utils/const.ts +0 -25
  210. package/src/lib/utils/helpers.ts +0 -78
  211. package/src/lib/utils/init-app-with-shadow.ts +0 -42
  212. package/src/lib/utils/quilt.ts +0 -317
  213. package/src/lib/utils/reclaim.ts +0 -148
  214. package/src/lib/utils/types.ts +0 -14
  215. package/src/mutations/seal.ts +0 -78
  216. package/src/mutations/signer.ts +0 -241
  217. package/src/mutations/walrus.ts +0 -862
  218. package/src/stores/walletStore.ts +0 -360
  219. package/src/stores/walrusStore.ts +0 -118
  220. package/src/stores/zkloginStore.ts +0 -53
  221. package/src/types.ts +0 -120
  222. package/tsconfig.json +0 -12
  223. /package/{src/_generated/index.js → dist/_generated/index.d.ts} +0 -0
  224. /package/{src/components/index.ts → dist/components/index.d.ts} +0 -0
  225. /package/{src/lib/utils/index.ts → dist/lib/utils/index.d.ts} +0 -0
  226. /package/{src/mutations/index.ts → dist/mutations/index.d.ts} +0 -0
  227. /package/{src/stores/index.ts → dist/stores/index.d.ts} +0 -0
@@ -0,0 +1,49 @@
1
+ export const excludeValuesFromBaseArray = (baseArray, excludeArray) => baseArray.filter((value) => !excludeArray.includes(value));
2
+ export const sleep = async (time) => new Promise((r) => setTimeout(r, time));
3
+ export const formatDate = (date) => date.toLocaleDateString("en-US", {
4
+ year: "numeric",
5
+ month: "short",
6
+ day: "numeric",
7
+ });
8
+ export const formatBalance = (balance, decimal, digits = 4) => {
9
+ const normalizedBalance = Number(balance) / Math.pow(10, decimal);
10
+ const fixed = normalizedBalance.toFixed(digits);
11
+ return fixed.replace(/\.?0+$/, "");
12
+ };
13
+ export const formatTimeAgo = (date) => {
14
+ const now = new Date();
15
+ const diffInHours = Math.floor((now.getTime() - date.getTime()) / (1000 * 60 * 60));
16
+ if (diffInHours < 1)
17
+ return "Just now";
18
+ if (diffInHours < 24)
19
+ return `${diffInHours}h ago`;
20
+ if (diffInHours < 168)
21
+ return `${Math.floor(diffInHours / 24)}d ago`;
22
+ return formatDate(date);
23
+ };
24
+ export function formatDaysAuto(days) {
25
+ if (days < 30)
26
+ return `${days} day${days === 1 ? "" : "s"}`;
27
+ const months = days / 30;
28
+ if (months < 12) {
29
+ const rounded = Math.floor(months);
30
+ return `${rounded} month${rounded === 1 ? "" : "s"}`;
31
+ }
32
+ const years = Math.floor(days / 365);
33
+ return `${years} year${years === 1 ? "" : "s"}`;
34
+ }
35
+ export const formatBytes = (bytes) => {
36
+ if (bytes === 0)
37
+ return "0 B";
38
+ const k = 1024;
39
+ const sizes = ["B", "KB", "MB", "GB", "TB"];
40
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
41
+ return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;
42
+ };
43
+ export const getDaysRemaining = (comp) => {
44
+ const now = new Date();
45
+ const diffTime = comp - now.getTime();
46
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
47
+ return diffDays;
48
+ };
49
+ export const bytesToGB = (bytes) => bytes / (1024 * 1024 * 1024);
@@ -0,0 +1,4 @@
1
+ export * from "./helpers.js";
2
+ export * from "./reclaim.js";
3
+ export * from "./colorful-logger.js";
4
+ export * from "./init-app-with-shadow.js";
@@ -0,0 +1,6 @@
1
+ import type { ReactElement } from "react";
2
+ export declare const initAppWithShadow: ({ id, app, inlineCss, }: {
3
+ id: string;
4
+ inlineCss: string;
5
+ app: ReactElement;
6
+ }) => void;
@@ -0,0 +1,28 @@
1
+ import { createRoot } from "react-dom/client";
2
+ export const initAppWithShadow = ({ id, app, inlineCss, }) => {
3
+ const root = document.createElement("div");
4
+ root.id = id;
5
+ document.body.append(root);
6
+ const rootIntoShadow = document.createElement("div");
7
+ rootIntoShadow.id = `shadow-root-${id}`;
8
+ const shadowRoot = root.attachShadow({ mode: "open" });
9
+ if (navigator.userAgent.includes("Firefox")) {
10
+ /**
11
+ * In the firefox environment, adoptedStyleSheets cannot be used due to the bug
12
+ * @url https://bugzilla.mozilla.org/show_bug.cgi?id=1770592
13
+ *
14
+ * Injecting styles into the document, this may cause style conflicts with the host page
15
+ */
16
+ const styleElement = document.createElement("style");
17
+ styleElement.innerHTML = inlineCss;
18
+ shadowRoot.appendChild(styleElement);
19
+ }
20
+ else {
21
+ /** Inject styles into shadow dom */
22
+ const globalStyleSheet = new CSSStyleSheet();
23
+ globalStyleSheet.replaceSync(inlineCss);
24
+ shadowRoot.adoptedStyleSheets = [globalStyleSheet];
25
+ }
26
+ shadowRoot.appendChild(rootIntoShadow);
27
+ createRoot(rootIntoShadow).render(app);
28
+ };
@@ -0,0 +1,61 @@
1
+ import type { EncodingType } from "@mysten/walrus";
2
+ export interface QuiltSizeInput {
3
+ blobs: {
4
+ size: number;
5
+ identifier: string;
6
+ tags?: Record<string, string>;
7
+ }[];
8
+ numShards: number;
9
+ encodingType?: EncodingType;
10
+ }
11
+ export interface QuiltSizeResult {
12
+ quiltSize: number;
13
+ symbolSize: number;
14
+ numRows: number;
15
+ numColumns: number;
16
+ indexSize: number;
17
+ blobSizes: number[];
18
+ }
19
+ /**
20
+ * Finds the minimum symbol size needed to store blobs in a fixed number of columns.
21
+ * Each blob must be stored in consecutive columns exclusively.
22
+ *
23
+ * A binary search is used to find the minimum symbol size:
24
+ * 1. Compute the upper and lower bounds for the symbol size.
25
+ * 2. Check if the all the blobs can be fit into the quilt with the current symbol size.
26
+ * 3. Adjust the bounds based on the result and repeat until the symbol size is found.
27
+ *
28
+ * @param blobsSizes - Slice of blob lengths, including the index size as the first element.
29
+ * Note that the len of the blob_size should be between 1 and n_columns.
30
+ * @param nColumns - Number of columns available.
31
+ * @param nRows - Number of rows available.
32
+ * @param maxNumColumnsForQuiltIndex - The maximum number of columns that can be used to
33
+ * store the quilt index.
34
+ * @param encodingType - The encoding type to use.
35
+ *
36
+ * @returns The minimum symbol size needed.
37
+ **/
38
+ export declare function computeSymbolSize(blobsSizes: number[], nColumns: number, nRows: number, maxNumColumnsForQuiltIndex: number, encodingType?: EncodingType): number;
39
+ /**
40
+ * Calculate the quilt size without actually encoding the data.
41
+ * This is useful for estimating costs before uploading.
42
+ *
43
+ * @param input - Configuration with blob sizes, identifiers, tags, and encoding params
44
+ * @returns Information about the resulting quilt size and structure
45
+ */
46
+ export declare function calculateQuiltSize(input: QuiltSizeInput): QuiltSizeResult;
47
+ /**
48
+ * Calculate quilt size accounting for encryption overhead.
49
+ * AES-GCM adds 16 bytes of authentication tag.
50
+ *
51
+ * @param files - Array of files with original sizes
52
+ * @param numShards - Number of shards
53
+ * @param ivSize - Size of IV (typically 12 bytes for GCM)
54
+ * @param encodingType - Encoding type
55
+ * @returns Quilt size information
56
+ */
57
+ export declare function calculateEncryptedQuiltSize(files: Array<{
58
+ size: number;
59
+ identifier: string;
60
+ tags?: Record<string, string>;
61
+ }>, numShards: number, ivSize?: number, encodingType?: EncodingType): QuiltSizeResult;
@@ -0,0 +1,194 @@
1
+ import { QuiltIndexV1, QuiltPatchTags } from "../../bcs.js";
2
+ import { getSourceSymbols } from "../../getters.js";
3
+ import { bcs } from "@mysten/sui/bcs";
4
+ const MAX_NUM_SLIVERS_FOR_QUILT_INDEX = 10;
5
+ const QUILT_INDEX_SIZE_BYTES_LENGTH = 4;
6
+ const QUILT_VERSION_BYTES_LENGTH = 1;
7
+ const QUILT_INDEX_PREFIX_SIZE = QUILT_VERSION_BYTES_LENGTH + QUILT_INDEX_SIZE_BYTES_LENGTH;
8
+ const QUILT_PATCH_BLOB_HEADER_SIZE = 1 + 4 + 1; // bcs length of QuiltPatchBlobHeader
9
+ const BLOB_IDENTIFIER_SIZE_BYTES_LENGTH = 2;
10
+ const TAGS_SIZE_BYTES_LENGTH = 2;
11
+ const MAX_BLOB_IDENTIFIER_BYTES_LENGTH = (1 << (8 * BLOB_IDENTIFIER_SIZE_BYTES_LENGTH)) - 1;
12
+ const REQUIRED_ALIGNMENT_BY_ENCODING_TYPE = {
13
+ RS2: 2,
14
+ RedStuff: 2,
15
+ };
16
+ const MAX_SYMBOL_SIZE_BY_ENCODING_TYPE = {
17
+ RS2: 2 ** 16 - 1,
18
+ RedStuff: 2 ** 16 - 1,
19
+ };
20
+ function canBlobsFitIntoMatrix(blobsSizes, nColumns, columnSize) {
21
+ return (blobsSizes.reduce((acc, size) => acc + Math.ceil(size / columnSize), 0) <=
22
+ nColumns);
23
+ }
24
+ // Add these constants at the top of your quilt-size.ts file
25
+ const DIGEST_LEN = 32;
26
+ const BLOB_ID_LEN = 32;
27
+ /**
28
+ * Calculate the encoded blob length including all overhead.
29
+ * This matches the Walrus SDK's encodedBlobLength function.
30
+ */
31
+ function encodedBlobLength(unencodedLength, nShards, encodingType = "RS2") {
32
+ const sliverSize = encodedSliverSize(unencodedLength, nShards, encodingType);
33
+ const metadata = nShards * DIGEST_LEN * 2 + BLOB_ID_LEN;
34
+ return nShards * metadata + sliverSize;
35
+ }
36
+ /**
37
+ * Calculate the encoded sliver size.
38
+ * This matches the Walrus SDK's encodedSliverSize function.
39
+ */
40
+ function encodedSliverSize(unencodedLength, nShards, encodingType = "RS2") {
41
+ const { primarySymbols, secondarySymbols } = getSourceSymbols(nShards, encodingType);
42
+ let symbolSize = Math.floor((Math.max(unencodedLength, 1) - 1) / (primarySymbols * secondarySymbols)) + 1;
43
+ if (encodingType === "RS2" && symbolSize % 2 === 1) {
44
+ symbolSize = symbolSize + 1;
45
+ }
46
+ const singleShardSize = (primarySymbols + secondarySymbols) * symbolSize;
47
+ return singleShardSize * nShards;
48
+ }
49
+ /**
50
+ * Finds the minimum symbol size needed to store blobs in a fixed number of columns.
51
+ * Each blob must be stored in consecutive columns exclusively.
52
+ *
53
+ * A binary search is used to find the minimum symbol size:
54
+ * 1. Compute the upper and lower bounds for the symbol size.
55
+ * 2. Check if the all the blobs can be fit into the quilt with the current symbol size.
56
+ * 3. Adjust the bounds based on the result and repeat until the symbol size is found.
57
+ *
58
+ * @param blobsSizes - Slice of blob lengths, including the index size as the first element.
59
+ * Note that the len of the blob_size should be between 1 and n_columns.
60
+ * @param nColumns - Number of columns available.
61
+ * @param nRows - Number of rows available.
62
+ * @param maxNumColumnsForQuiltIndex - The maximum number of columns that can be used to
63
+ * store the quilt index.
64
+ * @param encodingType - The encoding type to use.
65
+ *
66
+ * @returns The minimum symbol size needed.
67
+ **/
68
+ export function computeSymbolSize(blobsSizes, nColumns, nRows, maxNumColumnsForQuiltIndex, encodingType = "RS2") {
69
+ if (blobsSizes.length > nColumns) {
70
+ throw new Error("Too many blobs, the number of blobs must be less than the number of columns");
71
+ }
72
+ if (blobsSizes.length === 0) {
73
+ throw new Error("No blobs provided");
74
+ }
75
+ let minVal = Math.max(blobsSizes.reduce((acc, size) => acc + size, 0) / (nColumns * nRows), blobsSizes[0] / (nRows * maxNumColumnsForQuiltIndex), Math.ceil(QUILT_INDEX_PREFIX_SIZE / nRows));
76
+ let maxVal = Math.ceil((Math.max(...blobsSizes) / (nColumns / blobsSizes.length)) * nRows);
77
+ while (minVal < maxVal) {
78
+ const mid = (minVal + maxVal) / 2;
79
+ if (canBlobsFitIntoMatrix(blobsSizes, nColumns, mid * nRows)) {
80
+ maxVal = mid;
81
+ }
82
+ else {
83
+ minVal = mid + 1;
84
+ }
85
+ }
86
+ const symbolSize = Math.ceil(minVal / REQUIRED_ALIGNMENT_BY_ENCODING_TYPE[encodingType]) *
87
+ REQUIRED_ALIGNMENT_BY_ENCODING_TYPE[encodingType];
88
+ if (!canBlobsFitIntoMatrix(blobsSizes, nColumns, symbolSize * nRows)) {
89
+ throw new Error("Quilt oversize");
90
+ }
91
+ if (symbolSize > MAX_SYMBOL_SIZE_BY_ENCODING_TYPE[encodingType]) {
92
+ throw new Error(`Quilt oversize: the resulting symbol size ${symbolSize} is larger than the maximum symbol size ${MAX_SYMBOL_SIZE_BY_ENCODING_TYPE[encodingType]}; remove some blobs`);
93
+ }
94
+ return symbolSize;
95
+ }
96
+ /**
97
+ * Calculate the quilt size without actually encoding the data.
98
+ * This is useful for estimating costs before uploading.
99
+ *
100
+ * @param input - Configuration with blob sizes, identifiers, tags, and encoding params
101
+ * @returns Information about the resulting quilt size and structure
102
+ */
103
+ export function calculateQuiltSize(input) {
104
+ const { blobs, numShards, encodingType = "RS2" } = input;
105
+ const { primarySymbols: nRows, secondarySymbols: nCols } = getSourceSymbols(numShards, encodingType);
106
+ // Sort blobs by identifier (same as encoding logic)
107
+ const sortedBlobs = [...blobs].sort((a, b) => a.identifier < b.identifier ? -1 : 1);
108
+ // Validate identifiers
109
+ const identifiers = new Set();
110
+ for (const blob of sortedBlobs) {
111
+ if (identifiers.has(blob.identifier)) {
112
+ throw new Error(`Duplicate blob identifier: ${blob.identifier}`);
113
+ }
114
+ if (blob.identifier.length > MAX_BLOB_IDENTIFIER_BYTES_LENGTH) {
115
+ throw new Error(`Blob identifier too long: ${blob.identifier}`);
116
+ }
117
+ identifiers.add(blob.identifier);
118
+ }
119
+ // Build index structure (same as encoding)
120
+ const index = {
121
+ patches: sortedBlobs.map((blob) => ({
122
+ startIndex: 0,
123
+ endIndex: 0,
124
+ identifier: blob.identifier,
125
+ tags: blob.tags ?? {},
126
+ })),
127
+ };
128
+ // Calculate index size
129
+ const indexSize = QUILT_INDEX_PREFIX_SIZE + QuiltIndexV1.serialize(index).toBytes().length;
130
+ // Calculate metadata sizes
131
+ const blobMetadataSizes = sortedBlobs.map((blob) => {
132
+ const identifierBytes = bcs.string().serialize(blob.identifier).toBytes();
133
+ let metadataSize = QUILT_PATCH_BLOB_HEADER_SIZE +
134
+ BLOB_IDENTIFIER_SIZE_BYTES_LENGTH +
135
+ identifierBytes.length;
136
+ if (blob.tags && Object.keys(blob.tags).length > 0) {
137
+ const tagsBytes = QuiltPatchTags.serialize(blob.tags).toBytes();
138
+ metadataSize += TAGS_SIZE_BYTES_LENGTH + tagsBytes.length;
139
+ }
140
+ return metadataSize;
141
+ });
142
+ // Calculate total blob sizes (metadata + content)
143
+ const blobSizes = [
144
+ indexSize,
145
+ ...sortedBlobs.map((blob, i) => blobMetadataSizes[i] + blob.size),
146
+ ];
147
+ // Compute symbol size
148
+ const symbolSize = computeSymbolSize(blobSizes, nCols, nRows, MAX_NUM_SLIVERS_FOR_QUILT_INDEX, encodingType);
149
+ const columnSize = symbolSize * nRows;
150
+ // Calculate how many columns are actually used
151
+ const indexColumnsNeeded = Math.ceil(indexSize / columnSize);
152
+ let currentColumn = indexColumnsNeeded;
153
+ for (const blobSize of blobSizes.slice(1)) {
154
+ // Skip index (it's first in blobSizes)
155
+ const columnsNeeded = Math.ceil(blobSize / columnSize);
156
+ currentColumn += columnsNeeded;
157
+ }
158
+ // The actual unencoded size is based on COLUMNS USED, not all columns
159
+ // Each column is columnSize bytes tall
160
+ const actualUnencodedQuiltSize = currentColumn * columnSize;
161
+ // Now use the ACTUAL size for encoding calculation
162
+ const encodedQuiltSize = encodedBlobLength(actualUnencodedQuiltSize, numShards, encodingType);
163
+ return {
164
+ quiltSize: encodedQuiltSize,
165
+ symbolSize,
166
+ numRows: nRows,
167
+ numColumns: nCols,
168
+ indexSize,
169
+ blobSizes,
170
+ };
171
+ }
172
+ /**
173
+ * Calculate quilt size accounting for encryption overhead.
174
+ * AES-GCM adds 16 bytes of authentication tag.
175
+ *
176
+ * @param files - Array of files with original sizes
177
+ * @param numShards - Number of shards
178
+ * @param ivSize - Size of IV (typically 12 bytes for GCM)
179
+ * @param encodingType - Encoding type
180
+ * @returns Quilt size information
181
+ */
182
+ export function calculateEncryptedQuiltSize(files, numShards, ivSize = 12, encodingType) {
183
+ const GCM_TAG_SIZE = 16; // AES-GCM authentication tag
184
+ return calculateQuiltSize({
185
+ blobs: files.map((file) => ({
186
+ // Account for IV + encrypted data + GCM tag
187
+ size: ivSize + file.size + GCM_TAG_SIZE,
188
+ identifier: file.identifier,
189
+ tags: file.tags,
190
+ })),
191
+ numShards,
192
+ encodingType,
193
+ });
194
+ }
@@ -0,0 +1,29 @@
1
+ export declare function hexToBytes(hex: string): Uint8Array;
2
+ export declare function bytesToHex(bytes: Uint8Array): string;
3
+ export declare function textToBytes(text: string): Uint8Array;
4
+ export declare function bytesToText(bytes: Uint8Array): string;
5
+ export declare function startVerification({ reclaimAppId, reclaimAppSecret, reclaimProviderId, }: {
6
+ reclaimAppId: string;
7
+ reclaimAppSecret: string;
8
+ reclaimProviderId: string;
9
+ }): Promise<unknown>;
10
+ export declare function generateCommitNonce(userAddress: string, claimIdentifier: string): number[];
11
+ export declare function generateCommitmentHash(proof: ReclaimProof, nonce: number[]): Uint8Array<ArrayBufferLike>;
12
+ export type ReclaimProof = {
13
+ identifier: string;
14
+ claimData: {
15
+ provider: string;
16
+ parameters: string;
17
+ owner: string;
18
+ timestampS: number;
19
+ context: string;
20
+ identifier: string;
21
+ epoch: number;
22
+ };
23
+ signatures: string[];
24
+ witnesses: {
25
+ id: string;
26
+ url: string;
27
+ }[];
28
+ publicData: string | null;
29
+ };
@@ -0,0 +1,88 @@
1
+ import { ClaimInfo, SignedClaim, } from "../../_generated/zing_identity/reclaim.js";
2
+ import { bcs } from "@mysten/sui/bcs";
3
+ import { ReclaimProofRequest } from "@reclaimprotocol/js-sdk";
4
+ import sha3 from "js-sha3";
5
+ export function hexToBytes(hex) {
6
+ return new Uint8Array(hex.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
7
+ }
8
+ export function bytesToHex(bytes) {
9
+ return Array.from(bytes)
10
+ .map((byte) => byte.toString(16).padStart(2, "0"))
11
+ .join("");
12
+ }
13
+ export function textToBytes(text) {
14
+ return new TextEncoder().encode(text);
15
+ }
16
+ // Uint8Array ? String
17
+ export function bytesToText(bytes) {
18
+ return new TextDecoder().decode(bytes);
19
+ }
20
+ export async function startVerification({ reclaimAppId, reclaimAppSecret, reclaimProviderId, }) {
21
+ try {
22
+ // Initialize the Reclaim SDK with your credentials
23
+ const reclaimProofRequest = await ReclaimProofRequest.init(reclaimAppId, reclaimAppSecret, reclaimProviderId);
24
+ reclaimProofRequest.setModalOptions({ modalPopupTimer: 3 }); // 3min
25
+ // Trigger the verification session
26
+ await reclaimProofRequest.triggerReclaimFlow();
27
+ // Start listening for proof submissions and return a promise
28
+ const proofs = await new Promise((resolve, reject) => {
29
+ reclaimProofRequest.startSession({
30
+ onSuccess: (proofs) => {
31
+ console.log("Verification successful:", proofs);
32
+ resolve(proofs);
33
+ },
34
+ onError: (error) => {
35
+ console.error("Verification failed", error);
36
+ reject(error);
37
+ },
38
+ });
39
+ });
40
+ return proofs;
41
+ }
42
+ catch (error) {
43
+ console.error("Error starting verification:", error);
44
+ throw error;
45
+ }
46
+ }
47
+ export function generateCommitNonce(userAddress, claimIdentifier) {
48
+ // Use the same random data as in Move function
49
+ const randomBytes = crypto.getRandomValues(new Uint8Array(32));
50
+ // Encode user address as BCS (32 bytes for address type)
51
+ const addressBytes = bcs.Address.serialize(userAddress).toBytes();
52
+ // Encode claim identifier as BCS address (32 bytes for address type)
53
+ const identifierBytes = bcs.Address.serialize(claimIdentifier).toBytes();
54
+ // Combine: random + userAddress + identifier (no timestamp to match Move logic)
55
+ const combined = new Uint8Array(randomBytes.length + addressBytes.length + identifierBytes.length);
56
+ let offset = 0;
57
+ combined.set(randomBytes, offset);
58
+ offset += randomBytes.length;
59
+ combined.set(addressBytes, offset);
60
+ offset += addressBytes.length;
61
+ combined.set(identifierBytes, offset);
62
+ return Array.from(combined);
63
+ }
64
+ export function generateCommitmentHash(proof, nonce) {
65
+ const claimInfoBytes = ClaimInfo.serialize({
66
+ provider: proof.claimData.provider,
67
+ parameters: proof.claimData.parameters,
68
+ context: proof.claimData.context,
69
+ }).toBytes(); // checked
70
+ const signedClaimBytes = SignedClaim.serialize({
71
+ claim: {
72
+ identifier: proof.claimData.identifier,
73
+ owner: proof.claimData.owner,
74
+ epoch: proof.claimData.epoch.toString(),
75
+ timestamp_s: proof.claimData.timestampS.toString(),
76
+ },
77
+ signatures: proof.signatures.map((sig) => hexToBytes(sig.substring(2))),
78
+ }).toBytes();
79
+ const combined = new Uint8Array(claimInfoBytes.length + signedClaimBytes.length + nonce.length);
80
+ let offset = 0;
81
+ combined.set(claimInfoBytes, offset);
82
+ offset += claimInfoBytes.length;
83
+ combined.set(signedClaimBytes, offset);
84
+ offset += signedClaimBytes.length;
85
+ combined.set(nonce, offset);
86
+ // Convert Uint8Array -> Buffer before hashing
87
+ return hexToBytes(sha3.keccak256(combined));
88
+ }
@@ -0,0 +1,5 @@
1
+ import type { COLORS } from "./const.js";
2
+ import type { TupleToUnion } from "type-fest";
3
+ export type * from "type-fest";
4
+ export type ColorType = "success" | "info" | "error" | "warning" | keyof typeof COLORS;
5
+ export type ExcludeValuesFromBaseArrayType<B extends string[], E extends (string | number)[]> = Exclude<TupleToUnion<B>, TupleToUnion<E>>[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from "./walrus.js";
2
+ export * from "./signer.js";
3
+ export * from "./seal.js";
@@ -0,0 +1,12 @@
1
+ export declare function createFileKey(): Promise<Uint8Array>;
2
+ export declare function importFileKey(raw: Uint8Array | ArrayBuffer): Promise<CryptoKey>;
3
+ /**
4
+ * Encrypt data using AES-256-GCM.
5
+ * @returns {Uint8Array} Concatenated [IV | ciphertext]
6
+ */
7
+ export declare function encryptData(key: CryptoKey, data: ArrayBuffer | Uint8Array, iv: Uint8Array): Promise<Uint8Array>;
8
+ /**
9
+ * Decrypt data using AES-256-GCM.
10
+ * Input must be the combined [IV | ciphertext] format.
11
+ */
12
+ export declare function decryptData(key: CryptoKey, encrypted: ArrayBuffer | Uint8Array): Promise<Uint8Array>;
@@ -0,0 +1,41 @@
1
+ export async function createFileKey() {
2
+ // Generate AES-GCM key
3
+ const key = await crypto.subtle.generateKey({ name: "AES-GCM", length: 256 }, true, // extractable (so we can export)
4
+ ["encrypt", "decrypt"]);
5
+ // Export as raw bytes
6
+ const rawKey = await crypto.subtle.exportKey("raw", key);
7
+ return new Uint8Array(rawKey); // 32 bytes (256 bits)
8
+ }
9
+ export async function importFileKey(raw) {
10
+ // Convert to Uint8Array and create a clean copy
11
+ const keyBytes = raw instanceof Uint8Array ? raw : new Uint8Array(raw);
12
+ const cleanBytes = new Uint8Array(keyBytes);
13
+ return crypto.subtle.importKey("raw", cleanBytes, { name: "AES-GCM" }, false, ["encrypt", "decrypt"]);
14
+ }
15
+ /**
16
+ * Encrypt data using AES-256-GCM.
17
+ * @returns {Uint8Array} Concatenated [IV | ciphertext]
18
+ */
19
+ export async function encryptData(key, data, iv) {
20
+ const encoded = data instanceof Uint8Array ? data : new Uint8Array(data);
21
+ const cleanEncoded = new Uint8Array(encoded);
22
+ const cleanivBytes = new Uint8Array(iv);
23
+ const ciphertext = new Uint8Array(await crypto.subtle.encrypt({ name: "AES-GCM", iv: cleanivBytes }, key, cleanEncoded));
24
+ // Combine IV + ciphertext for easy storage
25
+ const combined = new Uint8Array(iv.length + ciphertext.length);
26
+ combined.set(iv);
27
+ combined.set(ciphertext, iv.length);
28
+ return combined;
29
+ }
30
+ /**
31
+ * Decrypt data using AES-256-GCM.
32
+ * Input must be the combined [IV | ciphertext] format.
33
+ */
34
+ export async function decryptData(key, encrypted) {
35
+ const bytes = encrypted instanceof Uint8Array ? encrypted : new Uint8Array(encrypted);
36
+ const iv = bytes.slice(0, 12);
37
+ const ciphertext = bytes.slice(12);
38
+ console.log({ iv, ciphertext });
39
+ const plaintext = await crypto.subtle.decrypt({ name: "AES-GCM", iv }, key, ciphertext);
40
+ return new Uint8Array(plaintext);
41
+ }
@@ -0,0 +1,10 @@
1
+ import type { ZkLoginProofParams, ZkLoginProofResponse, ZKLoginSignerState } from "../types.js";
2
+ import type { SuiClient } from "@mysten/sui/client";
3
+ import type { Transaction } from "@mysten/sui/transactions";
4
+ export declare function getSigner(suiClient: SuiClient): Promise<ZKLoginSignerState>;
5
+ export declare function signAndExecuteGasPoolTransaction(signer: ZKLoginSignerState, suiClient: SuiClient, tx: Transaction, gasBudget?: number, reserveDurationSecs?: number): Promise<any>;
6
+ export declare function signPersonalMessage(signer: ZKLoginSignerState, message: Uint8Array): Promise<{
7
+ zkLoginSignature: any;
8
+ bytes: Uint8Array<ArrayBuffer>;
9
+ }>;
10
+ export declare function createZkLoginProof(params: ZkLoginProofParams): Promise<ZkLoginProofResponse>;