@zing-protocol/zing-sdk 0.0.1 → 0.0.2

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 +14 -6
  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
package/src/bcs.ts DELETED
@@ -1,139 +0,0 @@
1
- import { bcs, TypeTagSerializer } from "@mysten/sui/bcs";
2
- import {
3
- fromBase64,
4
- normalizeStructTag,
5
- parseStructTag,
6
- SUI_FRAMEWORK_ADDRESS,
7
- SUI_SYSTEM_ADDRESS,
8
- } from "@mysten/sui/utils";
9
- import { blobIdFromInt, blobIdToInt } from "@mysten/walrus";
10
- import type { ObjectOwner } from "@mysten/sui/client";
11
-
12
- function compareBcsBytes(a: Uint8Array, b: Uint8Array) {
13
- // sort by length first, because bcs bytes prefix length
14
- if (a.length !== b.length) {
15
- return a.length - b.length;
16
- }
17
-
18
- for (let i = 0; i < a.length; i++) {
19
- if (a[i] !== b[i]) {
20
- return a[i] - b[i];
21
- }
22
- }
23
-
24
- return 0;
25
- }
26
-
27
- export const BlobId = bcs.u256().transform({
28
- input: (blobId: string | bigint) =>
29
- typeof blobId === "string" ? blobIdToInt(blobId) : blobId,
30
- output: (id: string) => blobIdFromInt(id),
31
- });
32
-
33
- export const QuiltPatchId = bcs.struct("QuiltPatchId", {
34
- quiltId: BlobId,
35
- patchId: bcs.struct("InternalQuiltPatchId", {
36
- version: bcs.u8(),
37
- startIndex: bcs.u16(),
38
- endIndex: bcs.u16(),
39
- }),
40
- });
41
- export const QuiltPatchTags = bcs.map(bcs.string(), bcs.string()).transform({
42
- // tags is a BTreeMap, so we need to sort entries before serializing
43
- input: (tags: Record<string, string> | Map<string, string>) =>
44
- new Map(
45
- [...(tags instanceof Map ? tags : Object.entries(tags))].sort(
46
- ([a], [b]) =>
47
- compareBcsBytes(
48
- bcs.string().serialize(a).toBytes(),
49
- bcs.string().serialize(b).toBytes(),
50
- ),
51
- ),
52
- ),
53
- output: (tags: Map<string, string>) => Object.fromEntries(tags),
54
- });
55
- export const QuiltPatchV1 = bcs.struct("QuiltPatchV1", {
56
- endIndex: bcs.u16(),
57
- identifier: bcs.string(),
58
- tags: QuiltPatchTags,
59
- });
60
- export const QuiltIndexV1 = bcs.struct("QuiltIndexV1", {
61
- patches: bcs.vector(QuiltPatchV1),
62
- });
63
-
64
- export const MoveObjectType = bcs.enum("MoveObjectType", {
65
- Other: bcs.StructTag,
66
- GasCoin: null,
67
- StakedSui: null,
68
- Coin: bcs.TypeTag,
69
- });
70
-
71
- export const SuiMoveObject = bcs.struct("SuiMoveObject", {
72
- data: bcs.enum("Data", {
73
- MoveObject: bcs.struct("MoveObject", {
74
- type: MoveObjectType.transform({
75
- input: (objectType: string): typeof MoveObjectType.$inferType => {
76
- const structTag = parseStructTag(objectType);
77
-
78
- if (
79
- structTag.address === SUI_FRAMEWORK_ADDRESS &&
80
- structTag.module === "coin" &&
81
- structTag.name === "Coin" &&
82
- typeof structTag.typeParams[0] === "object"
83
- ) {
84
- const innerStructTag = structTag.typeParams[0];
85
- if (
86
- innerStructTag.address === SUI_FRAMEWORK_ADDRESS &&
87
- innerStructTag.module === "sui" &&
88
- innerStructTag.name === "SUI"
89
- ) {
90
- return { GasCoin: true, $kind: "GasCoin" };
91
- }
92
- return { Coin: normalizeStructTag(innerStructTag), $kind: "Coin" };
93
- } else if (
94
- structTag.address === SUI_SYSTEM_ADDRESS &&
95
- structTag.module === "staking_pool" &&
96
- structTag.name === "StakedSui"
97
- ) {
98
- return { StakedSui: true, $kind: "StakedSui" };
99
- }
100
- return {
101
- Other: {
102
- ...structTag,
103
- typeParams: structTag.typeParams.map((typeParam) =>
104
- TypeTagSerializer.parseFromStr(normalizeStructTag(typeParam)),
105
- ),
106
- },
107
- $kind: "Other",
108
- };
109
- },
110
- }),
111
- hasPublicTransfer: bcs.bool(),
112
- version: bcs.u64(),
113
- contents: bcs.byteVector().transform({ input: fromBase64 }),
114
- }),
115
- }),
116
- owner: bcs.Owner.transform({
117
- input: (objectOwner: ObjectOwner) => {
118
- if (objectOwner === "Immutable") {
119
- return { Immutable: null };
120
- } else if ("Shared" in objectOwner) {
121
- return {
122
- Shared: {
123
- initialSharedVersion: objectOwner.Shared.initial_shared_version,
124
- },
125
- };
126
- } else if ("ConsensusAddressOwner" in objectOwner) {
127
- return {
128
- ConsensusAddressOwner: {
129
- owner: objectOwner.ConsensusAddressOwner.owner,
130
- startVersion: objectOwner.ConsensusAddressOwner.start_version,
131
- },
132
- };
133
- }
134
- return objectOwner;
135
- },
136
- }),
137
- previousTransaction: bcs.ObjectDigest,
138
- storageRebate: bcs.u64(),
139
- });
@@ -1,557 +0,0 @@
1
- import { burnOrSendPositiveCoin } from "../_generated/zing_framework/coin_utils.js";
2
- import {
3
- deleteArticle,
4
- donate,
5
- purchaseStorageTier,
6
- setMonthlySubscriptionFee,
7
- subscribeToStudio,
8
- updateArticleSubscriptionLevel,
9
- } from "../_generated/zing_studio/app.js";
10
- import { addReferralToStudio } from "../_generated/zing_studio/referral.js";
11
- import { shareStorageSpace } from "../_generated/zing_studio/storage.js";
12
- import {
13
- _new as newStudio,
14
- sealApproveStudioOwner,
15
- shareStudio,
16
- } from "../_generated/zing_studio/studio.js";
17
- import { getConfig } from "../config/index.js";
18
- import {
19
- getDerivedMembershipID,
20
- getDerivedStorageID,
21
- getDerivedStudioID,
22
- getDerivedWorksID,
23
- getIdentifierByAddress,
24
- getIdentifierInfoByIdentifier,
25
- getMember,
26
- getMembers,
27
- getStorageSpace,
28
- getStorageTreasury,
29
- getStudio,
30
- getWork,
31
- getWorks,
32
- } from "../getters.js";
33
- import { importFileKey } from "../mutations/seal.js";
34
- import { signPersonalMessage } from "../mutations/signer.js";
35
- import { SessionKey } from "@mysten/seal";
36
- import { Transaction, coinWithBalance } from "@mysten/sui/transactions";
37
- import { fromHex } from "@mysten/sui/utils";
38
- import type {
39
- PurchaseStorageTierParams,
40
- SetMonthlySubscriptionFeeParams,
41
- SubscribeParams,
42
- } from "./types.js";
43
- import type { CoinSymbol, PlatformType, WorkType } from "../config/index.js";
44
- import type { Config, WalrusSystemState } from "../config/types.js";
45
- import type { SuiNetwork, ZKLoginSignerState } from "../types.js";
46
- import type { SealClient } from "@mysten/seal";
47
- import type { SuiGrpcClient } from "@mysten/sui/grpc";
48
- import type { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
49
-
50
- interface Params {
51
- network: SuiNetwork;
52
- suiGrpcClient: SuiGrpcClient;
53
- suiJsonRpcClient: SuiJsonRpcClient;
54
- gasPoolBearerToken: string;
55
- }
56
-
57
- export class ZingClient {
58
- suiGrpcClient: SuiGrpcClient;
59
- suiJsonRpcClient: SuiJsonRpcClient;
60
- network: SuiNetwork;
61
- config: Config;
62
- gasPoolBearerToken: string;
63
-
64
- constructor({
65
- network,
66
- suiGrpcClient,
67
- suiJsonRpcClient,
68
- gasPoolBearerToken,
69
- }: Params) {
70
- this.suiGrpcClient = suiGrpcClient;
71
- this.suiJsonRpcClient = suiJsonRpcClient;
72
- this.network = network || "testnet";
73
- this.config = getConfig(network);
74
- this.gasPoolBearerToken = gasPoolBearerToken;
75
- }
76
-
77
- public getConfig() {
78
- return this.config;
79
- }
80
-
81
- // Getters
82
- getDerivedStudioID(address: string): string {
83
- return getDerivedStudioID(
84
- this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF.objectId,
85
- address,
86
- );
87
- }
88
-
89
- getDerivedStorageID(address: string) {
90
- return getDerivedStorageID(
91
- this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF.objectId,
92
- address,
93
- );
94
- }
95
-
96
- getDerivedWorksID(address: string) {
97
- return getDerivedWorksID(
98
- this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF.objectId,
99
- address,
100
- );
101
- }
102
-
103
- getDerivedMembershipID(address: string) {
104
- return getDerivedMembershipID(
105
- this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF.objectId,
106
- address,
107
- );
108
- }
109
-
110
- async getIdentifierByAddress(platform: PlatformType, address: string) {
111
- return getIdentifierByAddress(
112
- this.suiGrpcClient,
113
- this.config.zing.IDENTITY_PLATFORMS[platform]
114
- .IDENTITY_MANAGER_ADDRESS_TO_IDENTIFIER_DF_ID,
115
- address,
116
- );
117
- }
118
-
119
- async getIdentifierInfoByIdentifier(
120
- platform: PlatformType,
121
- identifier: string,
122
- ) {
123
- return getIdentifierInfoByIdentifier(
124
- this.suiGrpcClient,
125
- this.config.zing.IDENTITY_PLATFORMS[platform]
126
- .IDENTITY_MANAGER_IDENTIFIER_INFO_DF_ID,
127
- identifier,
128
- );
129
- }
130
-
131
- // async getDonationByIdentifier(identifier: string) {
132
- // const donations = await getDonationByIdentifier(
133
- // this.suiGrpcClient,
134
- // this.config.zing.DONATIONS_TABLE_DF_ID,
135
- // identifier,
136
- // );
137
- //
138
- // return Object.keys(this.config.coins).reduce(
139
- // (acc, coinSymbol) => {
140
- // const symbol = coinSymbol as CoinSymbol;
141
- // const donation = donations?.contents.find(
142
- // (c) => c.key.name === this.config.coins[symbol],
143
- // );
144
- // if (donation) acc[symbol] = donation.value;
145
- // return acc;
146
- // },
147
- // {} as Record<CoinSymbol, string>,
148
- // );
149
- // }
150
-
151
- async getStudio(owner: string) {
152
- return getStudio(this.suiGrpcClient, this.getDerivedStudioID(owner));
153
- }
154
-
155
- async getStorageSpace(owner: string) {
156
- return getStorageSpace(this.suiGrpcClient, this.getDerivedStorageID(owner));
157
- }
158
-
159
- async getStorageTreasury() {
160
- return getStorageTreasury(
161
- this.suiGrpcClient,
162
- this.config.zing.ZING_STORAGE_TREASURY_SHARED_OBJECT_REF.objectId,
163
- );
164
- }
165
-
166
- async getMember(owner: string, member: string) {
167
- return getMember(
168
- this.suiGrpcClient,
169
- this.getDerivedMembershipID(owner),
170
- member,
171
- );
172
- }
173
-
174
- async getMembers(owner: string, cursor?: string, limit = 20) {
175
- return getMembers(
176
- this.suiGrpcClient,
177
- this.getDerivedMembershipID(owner),
178
- cursor,
179
- limit,
180
- );
181
- }
182
-
183
- async getWork(
184
- walrusSystem: WalrusSystemState,
185
- workId: string,
186
- workType?: WorkType,
187
- ) {
188
- return getWork(
189
- this.suiGrpcClient,
190
- walrusSystem,
191
- workId,
192
- workType ? this.config.zing.ZING_WORKS_TYPE[workType] : undefined,
193
- );
194
- }
195
-
196
- async getWorks(
197
- walrusSystem: WalrusSystemState,
198
- owner: string,
199
- workType?: WorkType,
200
- cursor?: string,
201
- limit = 20,
202
- ) {
203
- return getWorks(
204
- this.suiGrpcClient,
205
- walrusSystem,
206
- this.getDerivedWorksID(owner),
207
- workType ? this.config.zing.ZING_WORKS_TYPE[workType] : undefined,
208
- cursor,
209
- limit,
210
- );
211
- }
212
-
213
- async getBalance(owner: string, coinSymbol: CoinSymbol) {
214
- return this.suiGrpcClient.stateService
215
- .getBalance({
216
- owner,
217
- coinType: this.config.coins[coinSymbol],
218
- })
219
- .then((res) => res.response);
220
- }
221
-
222
- async getSessionKey(signer: ZKLoginSignerState, owner: string) {
223
- const { suiAddress, ephemeralKeyPair, decodedJwt, zkProof, maxEpoch } =
224
- signer;
225
- if (
226
- !suiAddress ||
227
- !ephemeralKeyPair ||
228
- !decodedJwt ||
229
- !zkProof ||
230
- !maxEpoch
231
- ) {
232
- throw new Error("Missing required wallet data for session key creation");
233
- }
234
-
235
- const sessionKey = await SessionKey.create({
236
- address: owner,
237
- packageId: this.config.zing.ZING_STUDIO_V0_PACKAGE_ADDRESS,
238
- ttlMin: 10,
239
- suiClient: this.suiJsonRpcClient,
240
- });
241
- const message = sessionKey.getPersonalMessage();
242
- const { zkLoginSignature } = await signPersonalMessage(signer, message);
243
-
244
- sessionKey.setPersonalMessageSignature(zkLoginSignature);
245
-
246
- return sessionKey;
247
- }
248
-
249
- async buildSealApproveTransactionBytes(owner: string) {
250
- const tx = new Transaction();
251
- // codegen didn't generate interface for entry fun
252
- const studioId = this.getDerivedStudioID(owner);
253
-
254
- tx.add(
255
- sealApproveStudioOwner({
256
- package: this.config.zing.ZING_STUDIO_PACKAGE_ADDRESS,
257
- arguments: {
258
- id: tx.pure.vector("u8", fromHex(studioId)),
259
- config: tx.sharedObjectRef(
260
- this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF,
261
- ),
262
- self: tx.object(studioId),
263
- },
264
- }),
265
- );
266
-
267
- return tx.build({
268
- client: this.suiJsonRpcClient,
269
- onlyTransactionKind: true,
270
- });
271
- }
272
-
273
- async getFileKey(
274
- sealClient: SealClient,
275
- sessionKey: SessionKey,
276
- owner: string,
277
- encryptedFileKeyBytes: number[],
278
- ) {
279
- const txBytes = await this.buildSealApproveTransactionBytes(owner);
280
- const decryptedKey = await sealClient.decrypt({
281
- data: new Uint8Array(encryptedFileKeyBytes),
282
- sessionKey,
283
- txBytes,
284
- });
285
- return await importFileKey(decryptedKey);
286
- }
287
-
288
- // --- Transaction Builders ---
289
-
290
- /**
291
- * Constructs the transaction for subscribing to a studio.
292
- * Does not execute; returns the Transaction object to be signed.
293
- */
294
- public subscribeToStudioTransaction({
295
- sender,
296
- creatorAddress,
297
- subscriptionAmount,
298
- level,
299
- }: SubscribeParams) {
300
- return (tx: Transaction) => {
301
- const usdcCoin = tx.add(
302
- coinWithBalance({
303
- type: this.config.coins.USDC,
304
- balance: subscriptionAmount,
305
- useGasCoin: false,
306
- }),
307
- );
308
-
309
- const studioId = this.getDerivedStudioID(creatorAddress);
310
-
311
- tx.add(
312
- subscribeToStudio({
313
- package: this.config.zing.ZING_STUDIO_PACKAGE_ADDRESS,
314
- typeArguments: [this.config.coins.USDC],
315
- arguments: {
316
- studio: tx.object(studioId),
317
- treasury: tx.sharedObjectRef(
318
- this.config.zing.ZING_TREASURY_SHARED_OBJECT_REF,
319
- ),
320
- subscriptionLevel: tx.pure.u8(level),
321
- payment: usdcCoin,
322
- config: tx.sharedObjectRef(
323
- this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF,
324
- ),
325
- },
326
- }),
327
- );
328
-
329
- tx.add(
330
- burnOrSendPositiveCoin({
331
- package: this.config.zing.ZING_FRAMEWORK_PACKAGE_ADDRESS,
332
- typeArguments: [this.config.coins.USDC],
333
- arguments: {
334
- coin: usdcCoin,
335
- recipient: tx.pure.address(sender),
336
- },
337
- }),
338
- );
339
- };
340
- }
341
-
342
- public purchaseStorageTierTransaction({
343
- sender,
344
- objs,
345
- newTierIdx,
346
- balance,
347
- referrer,
348
- }: PurchaseStorageTierParams) {
349
- return (tx: Transaction) => {
350
- const [studio, storageSpace] =
351
- objs === null
352
- ? tx.add(
353
- newStudio({
354
- package: this.config.zing.ZING_STUDIO_PACKAGE_ADDRESS,
355
- arguments: [
356
- tx.sharedObjectRef({
357
- ...this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF,
358
- mutable: true,
359
- }), // mutable for new derived Object
360
- ],
361
- }),
362
- )
363
- : [tx.object(objs.studioId), tx.object(objs.storageSpaceId)];
364
-
365
- if (objs == null && referrer !== null && sender !== referrer) {
366
- tx.add(
367
- addReferralToStudio({
368
- package: this.config.zing.ZING_STUDIO_PACKAGE_ADDRESS,
369
- arguments: {
370
- studio,
371
- config: tx.sharedObjectRef(
372
- this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF,
373
- ),
374
- referrer,
375
- },
376
- }),
377
- );
378
- }
379
-
380
- const usdcCoin = tx.add(
381
- coinWithBalance({
382
- type: this.config.coins.USDC,
383
- balance,
384
- useGasCoin: false,
385
- }),
386
- );
387
-
388
- tx.add(
389
- purchaseStorageTier({
390
- package: this.config.zing.ZING_STUDIO_PACKAGE_ADDRESS,
391
- typeArguments: [this.config.coins.USDC],
392
- arguments: {
393
- config: tx.sharedObjectRef(
394
- this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF,
395
- ),
396
- studio,
397
- treasury: tx.sharedObjectRef(
398
- this.config.zing.ZING_TREASURY_SHARED_OBJECT_REF,
399
- ),
400
- walrusSystem: tx.sharedObjectRef(
401
- this.config.walrus.WALRUS_SYSTEM_SHARED_OBJECT_REF,
402
- ),
403
- storageTreasury: tx.sharedObjectRef(
404
- this.config.zing.ZING_STORAGE_TREASURY_SHARED_OBJECT_REF,
405
- ),
406
- storageSpace,
407
- newTierIdx: tx.pure.u8(newTierIdx),
408
- payment: usdcCoin,
409
- },
410
- }),
411
- );
412
-
413
- if (objs === null) {
414
- tx.add(
415
- shareStudio({
416
- package: this.config.zing.ZING_STUDIO_PACKAGE_ADDRESS,
417
- arguments: [studio],
418
- }),
419
- );
420
-
421
- tx.add(
422
- shareStorageSpace({
423
- package: this.config.zing.ZING_STUDIO_PACKAGE_ADDRESS,
424
- arguments: [storageSpace],
425
- }),
426
- );
427
- }
428
-
429
- tx.add(
430
- burnOrSendPositiveCoin({
431
- package: this.config.zing.ZING_FRAMEWORK_PACKAGE_ADDRESS,
432
- typeArguments: [this.config.coins.USDC],
433
- arguments: {
434
- coin: usdcCoin,
435
- recipient: tx.pure.address(sender),
436
- },
437
- }),
438
- );
439
- };
440
- }
441
-
442
- public setMonthlySubscriptionFeeTransaction({
443
- sender,
444
- monthlyFee,
445
- level,
446
- }: SetMonthlySubscriptionFeeParams) {
447
- return (tx: Transaction) => {
448
- tx.add(
449
- setMonthlySubscriptionFee({
450
- package: this.config.zing.ZING_STUDIO_PACKAGE_ADDRESS,
451
- arguments: {
452
- config: tx.sharedObjectRef(
453
- this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF,
454
- ),
455
- studio: tx.object(this.getDerivedStudioID(sender)),
456
- level: tx.pure.u8(level),
457
- monthlySubscriptionFee: tx.pure.u64(monthlyFee),
458
- },
459
- }),
460
- );
461
- };
462
- }
463
-
464
- public updateArticleSubscriptionLevelTransaction({
465
- sender,
466
- articleId,
467
- subscriptionLevel,
468
- }: {
469
- sender: string;
470
- articleId: string;
471
- subscriptionLevel: null | number;
472
- }) {
473
- return (tx: Transaction) => {
474
- tx.add(
475
- updateArticleSubscriptionLevel({
476
- package: this.config.zing.ZING_STUDIO_PACKAGE_ADDRESS,
477
- arguments: {
478
- config: tx.sharedObjectRef(
479
- this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF,
480
- ),
481
- studio: tx.object(this.getDerivedStudioID(sender)),
482
- walrusSystem: tx.sharedObjectRef(
483
- this.config.walrus.WALRUS_SYSTEM_SHARED_OBJECT_REF,
484
- ),
485
- articleId: tx.pure.id(articleId),
486
- subscriptionLevel: tx.pure.option("u8", subscriptionLevel),
487
- },
488
- }),
489
- );
490
- };
491
- }
492
-
493
- public deleteArticleTransaction({
494
- sender,
495
- articleId,
496
- }: {
497
- sender: string;
498
- articleId: string;
499
- }) {
500
- return (tx: Transaction) => {
501
- tx.add(
502
- deleteArticle({
503
- package: this.config.zing.ZING_STUDIO_PACKAGE_ADDRESS,
504
- arguments: {
505
- config: tx.sharedObjectRef(
506
- this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF,
507
- ),
508
- studio: tx.object(this.getDerivedStudioID(sender)),
509
- storageSpace: tx.object(this.getDerivedStorageID(sender)),
510
- walrusSystem: tx.sharedObjectRef(
511
- this.config.walrus.WALRUS_SYSTEM_SHARED_OBJECT_REF,
512
- ),
513
- articleId: tx.pure.id(articleId),
514
- },
515
- }),
516
- );
517
- };
518
- }
519
-
520
- public donateTransaction({
521
- recipient,
522
- message,
523
- value,
524
- }: {
525
- recipient: string;
526
- message: string;
527
- value: number;
528
- }) {
529
- return (tx: Transaction) => {
530
- const usdcCoin = tx.add(
531
- coinWithBalance({
532
- type: this.config.coins.USDC,
533
- balance: value,
534
- useGasCoin: false,
535
- }),
536
- );
537
-
538
- tx.add(
539
- donate({
540
- package: this.config.zing.ZING_STUDIO_PACKAGE_ADDRESS,
541
- typeArguments: [this.config.coins.USDC],
542
- arguments: {
543
- config: tx.sharedObjectRef(
544
- this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF,
545
- ),
546
- studio: tx.object(this.getDerivedStudioID(recipient)),
547
- treasury: tx.sharedObjectRef(
548
- this.config.zing.ZING_TREASURY_SHARED_OBJECT_REF,
549
- ),
550
- message: tx.pure.string(message),
551
- donation: usdcCoin,
552
- },
553
- }),
554
- );
555
- };
556
- }
557
- }
@@ -1,28 +0,0 @@
1
- import type { Transaction } from "@mysten/sui/transactions";
2
-
3
- export type TransactionBuilderFn<TParams> = (
4
- tx: Transaction,
5
- params: TParams,
6
- ) => void;
7
- export interface SubscribeParams {
8
- sender: string;
9
- creatorAddress: string;
10
- subscriptionAmount: number;
11
- level: number;
12
- }
13
- export interface PurchaseStorageTierParams {
14
- sender: string;
15
- objs: null | {
16
- studioId: string;
17
- storageSpaceId: string;
18
- };
19
- newTierIdx: number;
20
- referrer: string | null;
21
- balance: number;
22
- }
23
-
24
- export interface SetMonthlySubscriptionFeeParams {
25
- sender: string;
26
- monthlyFee: number;
27
- level: number;
28
- }