@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
@@ -1,115 +0,0 @@
1
- import { useZingQuery } from "./useZingQuery.js";
2
- import { useMemo } from "react";
3
- import type { TierPlan } from "../types.js";
4
-
5
- const tierInfos: Record<number, { name: string; features: string[] }> = {
6
- 0: {
7
- name: "Basic",
8
- features: ["Post/Article publishing", "Image protection"],
9
- },
10
- 1: {
11
- name: "Premium",
12
- features: [
13
- "Larger storage size",
14
- "Comments for post",
15
- "Analytics dashboard",
16
- ],
17
- },
18
- // 2: {
19
- // name: "Premium+",
20
- // features: [
21
- // "Advanced publishing",
22
- // "Priority support",
23
- // "Unlimited platforms",
24
- // "Analytics dashboard",
25
- // ],
26
- // },
27
- };
28
-
29
- export function useGetTierPlan() {
30
- const { data: storageTreasury, isPending } = useZingQuery(
31
- {
32
- method: "getStorageTreasury",
33
- params: [],
34
- },
35
- {
36
- staleTime: 0,
37
- refetchOnMount: "always",
38
- refetchOnWindowFocus: false,
39
- },
40
- );
41
-
42
- return useMemo((): {
43
- tierPlans: Record<number, TierPlan>;
44
- storageByEpoch: Record<number, number>;
45
- walTreasury: string;
46
- isLoading: boolean;
47
- } => {
48
- if (isPending || !storageTreasury) {
49
- return {
50
- tierPlans: {},
51
- storageByEpoch: {},
52
- walTreasury: "0",
53
- isLoading: isPending,
54
- };
55
- }
56
-
57
- if (
58
- !storageTreasury.tier_plan ||
59
- !Array.isArray(storageTreasury.tier_plan.contents) ||
60
- storageTreasury.tier_plan.contents.length === 0
61
- ) {
62
- return {
63
- tierPlans: {},
64
- storageByEpoch: {},
65
- walTreasury: storageTreasury.wal_treasury?.balance?.value || "0",
66
- isLoading: isPending,
67
- };
68
- }
69
-
70
- const tierPlans = storageTreasury.tier_plan.contents.reduce<
71
- Record<number, TierPlan>
72
- >(
73
- (acc, tier) => {
74
- const tierIndex = Number(tier.key);
75
- const info = tierInfos?.[tierIndex];
76
-
77
- if (!info) {
78
- return acc;
79
- }
80
-
81
- acc[tierIndex] = {
82
- name: info.name,
83
- duration: tier.value.duration_days,
84
- price: Number(tier.value.price),
85
- storage: Number(tier.value.storage_limit),
86
- features: info.features,
87
- };
88
-
89
- return acc;
90
- },
91
- {} as Record<number, TierPlan>,
92
- );
93
-
94
- // Process storageByEpoch
95
- const storageByEpoch =
96
- storageTreasury.storages_by_epoch?.contents?.reduce<
97
- Record<number, number>
98
- >((acc, storage) => {
99
- const epoch = Number(storage.key);
100
- const size = Number(storage.value.storage_size);
101
- acc[epoch] = size;
102
- return acc;
103
- }, {}) || {};
104
-
105
- // Get walTreasury balance
106
- const walTreasury = storageTreasury.wal_treasury?.balance?.value || "0";
107
-
108
- return {
109
- tierPlans,
110
- storageByEpoch,
111
- walTreasury,
112
- isLoading: isPending,
113
- };
114
- }, [storageTreasury, isPending]);
115
- }
@@ -1,165 +0,0 @@
1
- import { useSignAndExecuteTransaction } from "./useSignAndExecuteTransaction.js";
2
- import {
3
- commitProof,
4
- revealAndVerifyProof,
5
- } from "../_generated/zing_identity/reclaim.js";
6
- import { useZingClient } from "../components/zing-provider.js";
7
- import {
8
- hexToBytes,
9
- textToBytes,
10
- generateCommitmentHash,
11
- generateCommitNonce,
12
- } from "../lib/utils/reclaim.js";
13
- import { bcs } from "@mysten/sui/bcs";
14
- import { Transaction } from "@mysten/sui/transactions";
15
- import { useMutation } from "@tanstack/react-query";
16
- import sha3 from "js-sha3";
17
- import type { PlatformType } from "../config/common.js";
18
- import type { ReclaimProof } from "../lib/utils/reclaim.js";
19
- import type { SuiClient } from "@mysten/sui/client";
20
-
21
- interface CommitProofParams {
22
- suiClient: SuiClient;
23
- walletAddress: string;
24
- platform: PlatformType;
25
- proof: ReclaimProof;
26
- gasPoolBearerToken: string;
27
- }
28
-
29
- export function useCommitProof() {
30
- const { mutateAsync: signAndExecuteTransaction } =
31
- useSignAndExecuteTransaction();
32
- const zingClient = useZingClient();
33
- const config = zingClient.config;
34
-
35
- return useMutation({
36
- mutationFn: async ({
37
- suiClient,
38
- walletAddress,
39
- platform,
40
- proof,
41
- gasPoolBearerToken,
42
- }: CommitProofParams) => {
43
- const nonce = generateCommitNonce(walletAddress, proof.identifier);
44
- const commitmentHash = generateCommitmentHash(proof, nonce);
45
- const identifierHash = hexToBytes(
46
- sha3.keccak256(textToBytes(proof.identifier)),
47
- );
48
-
49
- const identityPlatform = config.zing.IDENTITY_PLATFORMS[platform];
50
- const commitProofTransaction = new Transaction();
51
-
52
- commitProofTransaction.add(
53
- commitProof({
54
- package: config.zing.ZING_IDENTITY_PACKAGE_ADDRESS,
55
- typeArguments: [identityPlatform.PLATFORM_TYPE],
56
- arguments: {
57
- self: commitProofTransaction.sharedObjectRef(
58
- identityPlatform.RECLAIM_MANAGER_SHARED_OBJECT_REF,
59
- ),
60
- config: commitProofTransaction.sharedObjectRef(
61
- config.zing.ZING_IDENTITY_CONFIG_SHARED_OBJECT_REF,
62
- ),
63
- commitmentHash: commitProofTransaction.pure(
64
- bcs.vector(bcs.u8()).serialize(commitmentHash),
65
- ),
66
- identifierHash: commitProofTransaction.pure(
67
- bcs.vector(bcs.u8()).serialize(identifierHash),
68
- ),
69
- },
70
- }),
71
- );
72
-
73
- const commitTransactionResponse = await signAndExecuteTransaction({
74
- transaction: commitProofTransaction,
75
- });
76
- if (!commitTransactionResponse) throw new Error("fail to commit proof");
77
-
78
- const commitTransactionObjectChanges = (
79
- await suiClient.waitForTransaction({
80
- digest: commitTransactionResponse.transactionDigest,
81
- options: {
82
- showObjectChanges: true,
83
- },
84
- })
85
- ).objectChanges;
86
- if (!commitTransactionObjectChanges)
87
- throw new Error("fail to commit proof");
88
-
89
- const commitment = commitTransactionObjectChanges.find(
90
- (objChanges) =>
91
- objChanges.type === "created" &&
92
- objChanges.objectType === config.zing.PROOF_COMMITMENT_TYPE,
93
- );
94
-
95
- if (!commitment || commitment.type !== "created")
96
- throw new Error("fail to commit proof");
97
-
98
- const revealTransaction = new Transaction();
99
-
100
- const [signers, proofObj] = revealTransaction.add(
101
- revealAndVerifyProof({
102
- package: config.zing.ZING_IDENTITY_PACKAGE_ADDRESS,
103
- typeArguments: [identityPlatform.PLATFORM_TYPE],
104
- arguments: {
105
- self: revealTransaction.sharedObjectRef(
106
- identityPlatform.RECLAIM_MANAGER_SHARED_OBJECT_REF,
107
- ),
108
- config: revealTransaction.sharedObjectRef(
109
- config.zing.ZING_IDENTITY_CONFIG_SHARED_OBJECT_REF,
110
- ),
111
- commitmentId: revealTransaction.pure.id(commitment.objectId),
112
- provider: revealTransaction.pure.string(proof.claimData.provider),
113
- parameters: revealTransaction.pure.string(
114
- proof.claimData.parameters,
115
- ),
116
- context: revealTransaction.pure.string(proof.claimData.context),
117
- identifier: revealTransaction.pure.string(
118
- proof.claimData.identifier,
119
- ),
120
- owner: revealTransaction.pure.string(proof.claimData.owner),
121
- epoch: revealTransaction.pure.string(
122
- proof.claimData.epoch.toString(),
123
- ),
124
- timestampS: revealTransaction.pure.u64(proof.claimData.timestampS),
125
- signatures: revealTransaction.pure(
126
- bcs
127
- .vector(bcs.vector(bcs.u8()))
128
- .serialize(
129
- proof.signatures.map((sig) => hexToBytes(sig.substring(2))),
130
- ),
131
- ),
132
- nonce: revealTransaction.pure(
133
- bcs.vector(bcs.u8()).serialize(nonce),
134
- ),
135
- },
136
- }),
137
- );
138
-
139
- console.log({ signers });
140
-
141
- // Call extract parameters customizaed functions; this interface should identical for different platforms
142
- revealTransaction.moveCall({
143
- target: identityPlatform.PLATFORM_UPDATE_PROOF_TARGET,
144
- arguments: [
145
- // IdentityManager
146
- revealTransaction.sharedObjectRef(
147
- identityPlatform.IDENTITY_MANAGER_SHARED_OBJECT_REF,
148
- ),
149
- // IdentityConfig
150
- revealTransaction.sharedObjectRef(
151
- config.zing.ZING_IDENTITY_CONFIG_SHARED_OBJECT_REF,
152
- ),
153
- proofObj,
154
- ],
155
- });
156
-
157
- const transactionResponse = await signAndExecuteTransaction({
158
- transaction: revealTransaction,
159
- });
160
- console.log({ transactionResponse });
161
-
162
- return transactionResponse;
163
- },
164
- });
165
- }
@@ -1,57 +0,0 @@
1
- import { useWalletStore } from "../components/wallet-provider.js";
2
- import { signAndExecuteGasPoolTransaction } from "../mutations/signer.js";
3
- import { useMutation } from "@tanstack/react-query";
4
- import type { Transaction } from "@mysten/sui/transactions";
5
-
6
- interface SignAndExecuteTransactionParams {
7
- transaction: Transaction;
8
- }
9
-
10
- const GAS_POOL_OWNER =
11
- "0x3198c7da350bf15c48fc598e5b03a0b6e13356801c71b4d1a18b92b09966e5da";
12
-
13
- export const useSignAndExecuteTransaction = () => {
14
- const getSigner = useWalletStore((s) => s.getSigner);
15
- const suiClient = useWalletStore((s) => s.suiClient);
16
-
17
- return useMutation({
18
- mutationFn: async ({ transaction }: SignAndExecuteTransactionParams) => {
19
- const signer = getSigner();
20
- if (!signer) {
21
- throw new Error("Wallet not properly initialized");
22
- }
23
- if (!signer.suiAddress) {
24
- throw new Error("Signer suiAddress not properly initialized");
25
- }
26
-
27
- // for Debug usage
28
- transaction.setSender(signer.suiAddress);
29
- transaction.setGasOwner(GAS_POOL_OWNER);
30
- const dryRunResponse = await suiClient.dryRunTransactionBlock({
31
- transactionBlock: await transaction.build({ client: suiClient }),
32
- });
33
-
34
- console.log({ dryRunResponse });
35
-
36
- if (dryRunResponse.effects.status.status === "success") {
37
- const effects = await signAndExecuteGasPoolTransaction(
38
- signer,
39
- suiClient,
40
- transaction,
41
- );
42
-
43
- // TODO: handle error message by code
44
-
45
- if (!effects) throw new Error("fail to get Transaction Effects");
46
-
47
- return effects;
48
- } else {
49
- return null;
50
- }
51
- },
52
- onError: (error, variables) => {
53
- console.log({ transaction: variables.transaction });
54
- console.error("Transaction execution failed:", error);
55
- },
56
- });
57
- };
@@ -1,28 +0,0 @@
1
- import { useWalletStore } from "../components/wallet-provider.js";
2
- import { signPersonalMessage } from "../mutations/signer.js";
3
- import { useMutation } from "@tanstack/react-query";
4
-
5
- interface SignPersonalMessageParams {
6
- message: Uint8Array;
7
- }
8
-
9
- export const useSignPersonalMessage = () => {
10
- const getSigner = useWalletStore((s) => s.getSigner);
11
-
12
- return useMutation({
13
- mutationFn: async ({ message }: SignPersonalMessageParams) => {
14
- const signer = getSigner();
15
- if (!signer) {
16
- throw new Error("Wallet not properly initialized");
17
- }
18
- if (!signer.suiAddress) {
19
- throw new Error("Signer suiAddress not properly initialized");
20
- }
21
-
22
- return await signPersonalMessage(signer, message);
23
- },
24
- onError: (error) => {
25
- console.error("Sign Personal Message failed:", error);
26
- },
27
- });
28
- };
@@ -1,92 +0,0 @@
1
- import { useZingClient } from "../components/zing-provider.js";
2
- import { useInfiniteQuery } from "@tanstack/react-query";
3
- import type { ZingClient } from "../client/index.js";
4
- import type { SuiNetwork } from "../types.js";
5
- import type {
6
- UseInfiniteQueryOptions,
7
- InfiniteData,
8
- } from "@tanstack/react-query";
9
-
10
- const zingInfiniteQueryMethodMap = (zingClient: ZingClient) => ({
11
- getMembers: zingClient.getMembers.bind(zingClient),
12
- getWorks: zingClient.getWorks.bind(zingClient),
13
- });
14
-
15
- type ZingInfiniteQueryMethods = ReturnType<typeof zingInfiniteQueryMethodMap>;
16
-
17
- type ExtractParams<T> = T extends (...args: infer P) => any ? P : never;
18
- type InfiniteMethodParamsMap = {
19
- [K in keyof ZingInfiniteQueryMethods]: ExtractParams<
20
- ZingInfiniteQueryMethods[K]
21
- >;
22
- };
23
-
24
- type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
25
-
26
- type ExtractReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
27
- type UseZingInfiniteQueryParams<K extends keyof InfiniteMethodParamsMap> = {
28
- method: K;
29
- params: InfiniteMethodParamsMap[K];
30
- limit?: number;
31
- };
32
-
33
- type ExtraInfiniteQueryOptions<TData = unknown> = Partial<
34
- Pick<
35
- UseInfiniteQueryOptions<
36
- TData,
37
- Error,
38
- InfiniteData<TData>,
39
- readonly unknown[],
40
- string | undefined
41
- >,
42
- "enabled" | "gcTime" | "staleTime" | "retry"
43
- >
44
- >;
45
- export type InfiniteMethodReturnMap = {
46
- [K in keyof ZingInfiniteQueryMethods]: UnwrapPromise<
47
- ExtractReturnType<ZingInfiniteQueryMethods[K]>
48
- >;
49
- };
50
-
51
- export function getZingInfiniteQueryKey<
52
- K extends keyof ZingInfiniteQueryMethods,
53
- >(
54
- network: SuiNetwork,
55
- method: K,
56
- memo: string[],
57
- ): readonly [string, K, string[]] {
58
- return [network, method, memo] as const;
59
- }
60
-
61
- export function useZingInfiniteQuery<K extends keyof InfiniteMethodParamsMap>(
62
- input: UseZingInfiniteQueryParams<K>,
63
- options: ExtraInfiniteQueryOptions<InfiniteMethodReturnMap[K]> = {},
64
- memo: string[] = [],
65
- ) {
66
- const zingClient = useZingClient();
67
- const methodMap = zingInfiniteQueryMethodMap(zingClient);
68
- const { method, params, limit = 20 } = input;
69
-
70
- return useInfiniteQuery<
71
- InfiniteMethodReturnMap[K],
72
- Error,
73
- InfiniteData<InfiniteMethodReturnMap[K]>,
74
- readonly unknown[],
75
- string | undefined
76
- >({
77
- queryKey: [zingClient.network, method, memo],
78
- queryFn: async ({ pageParam }) => {
79
- const fn = methodMap[method as keyof typeof methodMap];
80
- // Call the function with spread params, cursor, and limit
81
- return (fn as any)(...params, pageParam, limit) as Promise<
82
- InfiniteMethodReturnMap[K]
83
- >;
84
- },
85
- initialPageParam: undefined as string | undefined,
86
- getNextPageParam: (lastPage) => {
87
- const nextCursor = (lastPage as any)?.nextCursor;
88
- return nextCursor ?? undefined; // Convert null to undefined
89
- },
90
- ...options,
91
- });
92
- }
@@ -1,66 +0,0 @@
1
- import { useSignAndExecuteTransaction } from "./useSignAndExecuteTransaction.js";
2
- import { useZingClient } from "../components/zing-provider.js";
3
- import { Transaction } from "@mysten/sui/transactions";
4
- import { useMutation } from "@tanstack/react-query";
5
- import type { ZingClient } from "../client/index.js";
6
- import type { TransactionEffects } from "@mysten/sui/client";
7
-
8
- // Only allows Transaction methods
9
- const zingMutationMethodMap = (zingClient: ZingClient) => ({
10
- subscribeToStudioTransaction:
11
- zingClient.subscribeToStudioTransaction.bind(zingClient),
12
- purchaseStorageTierTransaction:
13
- zingClient.purchaseStorageTierTransaction.bind(zingClient),
14
- setMonthlySubscriptionFeeTransaction:
15
- zingClient.setMonthlySubscriptionFeeTransaction.bind(zingClient),
16
- updateArticleSubscriptionLevelTransaction:
17
- zingClient.updateArticleSubscriptionLevelTransaction.bind(zingClient),
18
- deleteArticleTransaction:
19
- zingClient.deleteArticleTransaction.bind(zingClient),
20
- donateTransaction: zingClient.donateTransaction.bind(zingClient),
21
- });
22
-
23
- type ZingMutationMethods = ReturnType<typeof zingMutationMethodMap>;
24
-
25
- type ExtractParams<T> = T extends (arg: infer P) => any ? P : never;
26
-
27
- type MethodParamsMap = {
28
- [K in keyof ZingMutationMethods]: ExtractParams<ZingMutationMethods[K]>;
29
- };
30
-
31
- type UseZingMutationParams = {
32
- [K in keyof ZingMutationMethods]: {
33
- method: K;
34
- params: MethodParamsMap[K];
35
- };
36
- }[keyof ZingMutationMethods];
37
-
38
- export function useZingMutation() {
39
- const zingClient = useZingClient();
40
- const methodMap = zingMutationMethodMap(zingClient);
41
- const { mutateAsync: signAndExecute } = useSignAndExecuteTransaction();
42
-
43
- return useMutation<TransactionEffects | null, Error, UseZingMutationParams>({
44
- mutationFn: async ({ method, params }) => {
45
- const tx = new Transaction();
46
-
47
- const builderFn = methodMap[method] as any;
48
-
49
- // builderFn receives a structured params object, not an array
50
- const buildTx = builderFn(params);
51
-
52
- buildTx(tx);
53
-
54
- return signAndExecute({
55
- transaction: tx,
56
- });
57
- },
58
- onSuccess: async (effects) => {
59
- if (effects?.transactionDigest) {
60
- await zingClient.suiJsonRpcClient.waitForTransaction({
61
- digest: effects.transactionDigest,
62
- });
63
- }
64
- },
65
- });
66
- }
@@ -1,107 +0,0 @@
1
- import { useZingClient } from "../components/zing-provider.js";
2
- import { useQueries } from "@tanstack/react-query";
3
- import type { ZingClient } from "../client/index.js";
4
- import type { UseQueryOptions } from "@tanstack/react-query";
5
-
6
- // ---------------------------------------------
7
- // Method map (shared with useZingQuery)
8
- // ---------------------------------------------
9
- const zingQueryMethodMap = (zingClient: ZingClient) => ({
10
- getIdentifierByAddress: zingClient.getIdentifierByAddress.bind(zingClient),
11
- getIdentifierInfoByIdentifier:
12
- zingClient.getIdentifierInfoByIdentifier.bind(zingClient),
13
- getStudio: zingClient.getStudio.bind(zingClient),
14
- getStorageSpace: zingClient.getStorageSpace.bind(zingClient),
15
- getStorageTreasury: zingClient.getStorageTreasury.bind(zingClient),
16
- getMember: zingClient.getMember.bind(zingClient),
17
- getBalance: zingClient.getBalance.bind(zingClient),
18
- });
19
-
20
- type ZingQueryMethods = ReturnType<typeof zingQueryMethodMap>;
21
- type ExtractParams<T> = T extends (...args: infer P) => any ? P : never;
22
- type MethodParamsMap = {
23
- [K in keyof ZingQueryMethods]: ExtractParams<ZingQueryMethods[K]>;
24
- };
25
- type ExtractReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
26
- type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
27
- type MethodReturnMap = {
28
- [K in keyof ZingQueryMethods]: UnwrapPromise<
29
- ExtractReturnType<ZingQueryMethods[K]>
30
- >;
31
- };
32
-
33
- // ---------------------------------------------
34
- // useZingQueries types
35
- // ---------------------------------------------
36
- type ZingQueryConfig = {
37
- [K in keyof ZingQueryMethods]: {
38
- method: K;
39
- params: MethodParamsMap[K];
40
- } & Omit<
41
- UseQueryOptions<
42
- MethodReturnMap[K],
43
- Error,
44
- MethodReturnMap[K],
45
- readonly unknown[]
46
- >,
47
- "queryKey" | "queryFn"
48
- >;
49
- }[keyof ZingQueryMethods];
50
-
51
- type UseZingQueriesOptions<
52
- T extends readonly ZingQueryConfig[],
53
- TCombinedResult = QueriesResults<T>,
54
- > = {
55
- queries: readonly [...T];
56
- combine?: (results: QueriesResults<T>) => TCombinedResult;
57
- };
58
-
59
- // Helper type to extract query results
60
- type QueryResult<T> = T extends { method: infer K; params: any }
61
- ? K extends keyof ZingQueryMethods
62
- ? {
63
- data: MethodReturnMap[K] | undefined;
64
- error: Error | null;
65
- isLoading: boolean;
66
- isError: boolean;
67
- isSuccess: boolean;
68
- status: "pending" | "error" | "success";
69
- fetchStatus: "fetching" | "paused" | "idle";
70
- }
71
- : never
72
- : never;
73
-
74
- type QueriesResults<T extends readonly ZingQueryConfig[]> = {
75
- [K in keyof T]: QueryResult<T[K]>;
76
- };
77
-
78
- // ---------------------------------------------
79
- // Hook
80
- // ---------------------------------------------
81
- export function useZingQueries<
82
- T extends readonly ZingQueryConfig[],
83
- TCombinedResult = QueriesResults<T>,
84
- >(options: UseZingQueriesOptions<T, TCombinedResult>): TCombinedResult {
85
- const zingClient = useZingClient();
86
- const methodMap = zingQueryMethodMap(zingClient);
87
-
88
- const queryConfigs = options.queries.map((queryConfig) => {
89
- const { method, params, ...queryOptions } = queryConfig;
90
-
91
- return {
92
- queryKey: [zingClient.network, method, params] as const,
93
- queryFn: async () => {
94
- const fn = methodMap[method];
95
- return (fn as (...args: any[]) => any)(...(params as any[]));
96
- },
97
- ...queryOptions,
98
- } as const;
99
- }) as any;
100
-
101
- const results = useQueries({
102
- queries: queryConfigs,
103
- combine: options.combine as any,
104
- } as any);
105
-
106
- return results as TCombinedResult;
107
- }