@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.
- package/dist/_generated/index.js +6 -0
- package/dist/_generated/utils/index.d.ts +12 -0
- package/dist/_generated/utils/index.js +135 -0
- package/dist/_generated/zing_framework/coin_utils.d.ts +15 -0
- package/dist/_generated/zing_framework/coin_utils.js +19 -0
- package/dist/_generated/zing_framework/deps/sui/object.d.ts +8 -0
- package/{src/_generated/zing_governance/deps/sui/object.ts → dist/_generated/zing_framework/deps/sui/object.js} +4 -7
- package/dist/_generated/zing_framework/derived_object_bag.d.ts +166 -0
- package/dist/_generated/zing_framework/derived_object_bag.js +221 -0
- package/dist/_generated/zing_framework/derived_table.d.ts +153 -0
- package/dist/_generated/zing_framework/derived_table.js +200 -0
- package/dist/_generated/zing_governance/admin.d.ts +20 -0
- package/dist/_generated/zing_governance/admin.js +26 -0
- package/dist/_generated/zing_governance/deps/sui/object.d.ts +8 -0
- package/{src/_generated/zing_identity/deps/sui/object.ts → dist/_generated/zing_governance/deps/sui/object.js} +4 -7
- package/dist/_generated/zing_governance/treasury.d.ts +56 -0
- package/dist/_generated/zing_governance/treasury.js +78 -0
- package/dist/_generated/zing_identity/config.d.ts +87 -0
- package/dist/_generated/zing_identity/config.js +98 -0
- package/{src/_generated/zing_studio/deps/std/type_name.ts → dist/_generated/zing_identity/deps/std/type_name.d.ts} +3 -11
- package/dist/_generated/zing_identity/deps/std/type_name.js +22 -0
- package/dist/_generated/zing_identity/deps/sui/object.d.ts +8 -0
- package/{src/_generated/zing_studio/deps/sui/object.ts → dist/_generated/zing_identity/deps/sui/object.js} +4 -7
- package/dist/_generated/zing_identity/deps/sui/object_table.d.ts +12 -0
- package/{src/_generated/zing_identity/deps/sui/object_table.ts → dist/_generated/zing_identity/deps/sui/object_table.js} +7 -10
- package/dist/_generated/zing_identity/deps/sui/table.d.ts +12 -0
- package/{src/_generated/zing_studio/deps/sui/table.ts → dist/_generated/zing_identity/deps/sui/table.js} +7 -10
- package/{src/_generated/zing_identity/deps/sui/vec_set.ts → dist/_generated/zing_identity/deps/sui/vec_set.d.ts} +3 -14
- package/dist/_generated/zing_identity/deps/sui/vec_set.js +22 -0
- package/dist/_generated/zing_identity/ecdsa.d.ts +81 -0
- package/dist/_generated/zing_identity/ecdsa.js +87 -0
- package/dist/_generated/zing_identity/identity.d.ts +262 -0
- package/dist/_generated/zing_identity/identity.js +294 -0
- package/dist/_generated/zing_identity/reclaim.d.ts +356 -0
- package/dist/_generated/zing_identity/reclaim.js +414 -0
- package/dist/_generated/zing_studio/app.d.ts +351 -0
- package/dist/_generated/zing_studio/app.js +451 -0
- package/dist/_generated/zing_studio/article.d.ts +331 -0
- package/dist/_generated/zing_studio/article.js +331 -0
- package/dist/_generated/zing_studio/config.d.ts +203 -0
- package/dist/_generated/zing_studio/config.js +233 -0
- package/{src/_generated/zing_identity/deps/std/type_name.ts → dist/_generated/zing_studio/deps/std/type_name.d.ts} +3 -11
- package/dist/_generated/zing_studio/deps/std/type_name.js +22 -0
- package/dist/_generated/zing_studio/deps/sui/bag.d.ts +12 -0
- package/{src/_generated/zing_studio/deps/sui/bag.ts → dist/_generated/zing_studio/deps/sui/bag.js} +7 -10
- package/dist/_generated/zing_studio/deps/sui/balance.d.ts +12 -0
- package/{src/_generated/zing_studio/deps/sui/balance.ts → dist/_generated/zing_studio/deps/sui/balance.js} +4 -7
- package/dist/_generated/zing_studio/deps/sui/coin.d.ts +12 -0
- package/{src/_generated/zing_studio/deps/sui/coin.ts → dist/_generated/zing_studio/deps/sui/coin.js} +5 -8
- package/dist/_generated/zing_studio/deps/sui/dynamic_field.d.ts +126 -0
- package/dist/_generated/zing_studio/deps/sui/dynamic_field.js +140 -0
- package/dist/_generated/zing_studio/deps/sui/object.d.ts +8 -0
- package/{src/_generated/zing_framework/deps/sui/object.ts → dist/_generated/zing_studio/deps/sui/object.js} +4 -7
- package/dist/_generated/zing_studio/deps/sui/table.d.ts +12 -0
- package/{src/_generated/zing_identity/deps/sui/table.ts → dist/_generated/zing_studio/deps/sui/table.js} +7 -10
- package/dist/_generated/zing_studio/deps/sui/vec_map.d.ts +30 -0
- package/{src/_generated/zing_studio/deps/sui/vec_map.ts → dist/_generated/zing_studio/deps/sui/vec_map.js} +15 -21
- package/{src/_generated/zing_studio/deps/sui/vec_set.ts → dist/_generated/zing_studio/deps/sui/vec_set.d.ts} +3 -14
- package/dist/_generated/zing_studio/deps/sui/vec_set.js +22 -0
- package/dist/_generated/zing_studio/deps/walrus/blob.d.ts +20 -0
- package/{src/_generated/zing_studio/deps/walrus/blob.ts → dist/_generated/zing_studio/deps/walrus/blob.js} +11 -12
- package/dist/_generated/zing_studio/deps/walrus/events.d.ts +83 -0
- package/dist/_generated/zing_studio/deps/walrus/events.js +122 -0
- package/dist/_generated/zing_studio/deps/walrus/metadata.d.ts +71 -0
- package/dist/_generated/zing_studio/deps/walrus/metadata.js +73 -0
- package/dist/_generated/zing_studio/deps/walrus/storage_resource.d.ts +12 -0
- package/{src/_generated/zing_studio/deps/walrus/storage_resource.ts → dist/_generated/zing_studio/deps/walrus/storage_resource.js} +7 -8
- package/dist/_generated/zing_studio/deps/zing_framework/derived_object_bag.d.ts +12 -0
- 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
- package/dist/_generated/zing_studio/deps/zing_framework/derived_table.d.ts +12 -0
- package/{src/_generated/zing_studio/deps/zing_framework/derived_table.ts → dist/_generated/zing_studio/deps/zing_framework/derived_table.js} +7 -8
- package/dist/_generated/zing_studio/donation.d.ts +24 -0
- package/{src/_generated/zing_studio/donation.ts → dist/_generated/zing_studio/donation.js} +7 -8
- package/dist/_generated/zing_studio/enclave.d.ts +187 -0
- package/dist/_generated/zing_studio/enclave.js +231 -0
- package/dist/_generated/zing_studio/nitro_attestation.d.ts +148 -0
- package/dist/_generated/zing_studio/nitro_attestation.js +183 -0
- package/dist/_generated/zing_studio/referral.d.ts +166 -0
- package/dist/_generated/zing_studio/referral.js +224 -0
- package/dist/_generated/zing_studio/storage.d.ts +327 -0
- package/dist/_generated/zing_studio/storage.js +365 -0
- package/dist/_generated/zing_studio/studio.d.ts +282 -0
- package/dist/_generated/zing_studio/studio.js +360 -0
- package/dist/bcs.d.ts +61 -0
- package/dist/bcs.js +109 -0
- package/dist/client/index.d.ts +228 -0
- package/dist/client/index.js +296 -0
- package/dist/client/types.d.ts +23 -0
- package/dist/client/types.js +1 -0
- package/dist/components/index.js +3 -0
- package/dist/components/wallet-provider.d.ts +7 -0
- package/dist/components/wallet-provider.js +33 -0
- package/dist/components/walrus-provider.d.ts +31 -0
- package/dist/components/walrus-provider.js +71 -0
- package/dist/components/zing-provider.d.ts +15 -0
- package/dist/components/zing-provider.js +22 -0
- package/dist/config/common.d.ts +23 -0
- package/dist/config/common.js +61 -0
- package/dist/config/index.d.ts +8 -0
- package/dist/config/index.js +28 -0
- package/dist/config/mainnet.d.ts +6 -0
- package/dist/config/mainnet.js +80 -0
- package/dist/config/testnet.d.ts +6 -0
- package/dist/config/testnet.js +81 -0
- package/dist/config/types.d.ts +49 -0
- package/dist/config/types.js +1 -0
- package/dist/const.d.ts +4 -0
- package/dist/const.js +25 -0
- package/dist/getters.d.ts +228 -0
- package/dist/getters.js +317 -0
- package/{src/hooks/index.ts → dist/hooks/index.d.ts} +2 -3
- package/dist/hooks/index.js +9 -0
- package/dist/hooks/useGetStudio.d.ts +26 -0
- package/dist/hooks/useGetStudio.js +17 -0
- package/dist/hooks/useGetTierPlan.d.ts +7 -0
- package/dist/hooks/useGetTierPlan.js +85 -0
- package/dist/hooks/useReclaim.d.ts +12 -0
- package/dist/hooks/useReclaim.js +87 -0
- package/dist/hooks/useSignAndExecuteTransaction.d.ts +6 -0
- package/dist/hooks/useSignAndExecuteTransaction.js +40 -0
- package/dist/hooks/useSignPersonalMessage.d.ts +8 -0
- package/dist/hooks/useSignPersonalMessage.js +21 -0
- package/dist/hooks/useZingInfiniteQueries.d.ts +75 -0
- package/dist/hooks/useZingInfiniteQueries.js +28 -0
- package/dist/hooks/useZingMutation.d.ts +35 -0
- package/dist/hooks/useZingMutation.js +37 -0
- package/dist/hooks/useZingQueries.d.ts +127 -0
- package/dist/hooks/useZingQueries.js +37 -0
- package/dist/hooks/useZingQuery.d.ts +147 -0
- package/dist/hooks/useZingQuery.js +34 -0
- package/{src/index.ts → dist/index.d.ts} +2 -3
- package/dist/index.js +9 -0
- package/dist/lib/utils/colorful-logger.d.ts +2 -0
- package/dist/lib/utils/colorful-logger.js +23 -0
- package/dist/lib/utils/const.d.ts +25 -0
- package/dist/lib/utils/const.js +25 -0
- package/dist/lib/utils/helpers.d.ts +10 -0
- package/dist/lib/utils/helpers.js +49 -0
- package/dist/lib/utils/index.js +4 -0
- package/dist/lib/utils/init-app-with-shadow.d.ts +6 -0
- package/dist/lib/utils/init-app-with-shadow.js +28 -0
- package/dist/lib/utils/quilt.d.ts +61 -0
- package/dist/lib/utils/quilt.js +194 -0
- package/dist/lib/utils/reclaim.d.ts +29 -0
- package/dist/lib/utils/reclaim.js +88 -0
- package/dist/lib/utils/types.d.ts +5 -0
- package/dist/lib/utils/types.js +1 -0
- package/dist/mutations/index.js +3 -0
- package/dist/mutations/seal.d.ts +12 -0
- package/dist/mutations/seal.js +41 -0
- package/dist/mutations/signer.d.ts +10 -0
- package/dist/mutations/signer.js +176 -0
- package/dist/mutations/walrus.d.ts +98 -0
- package/dist/mutations/walrus.js +488 -0
- package/dist/stores/index.js +3 -0
- package/dist/stores/walletStore.d.ts +48 -0
- package/dist/stores/walletStore.js +232 -0
- package/dist/stores/walrusStore.d.ts +28 -0
- package/dist/stores/walrusStore.js +61 -0
- package/dist/stores/zkloginStore.d.ts +28 -0
- package/dist/stores/zkloginStore.js +27 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.js +1 -0
- package/package.json +18 -10
- package/src/_generated/utils/index.ts +0 -181
- package/src/_generated/zing_framework/coin_utils.ts +0 -41
- package/src/_generated/zing_framework/derived_object_bag.ts +0 -400
- package/src/_generated/zing_framework/derived_table.ts +0 -366
- package/src/_generated/zing_governance/admin.ts +0 -47
- package/src/_generated/zing_governance/treasury.ts +0 -134
- package/src/_generated/zing_identity/config.ts +0 -191
- package/src/_generated/zing_identity/ecdsa.ts +0 -166
- package/src/_generated/zing_identity/identity.ts +0 -661
- package/src/_generated/zing_identity/reclaim.ts +0 -803
- package/src/_generated/zing_studio/app.ts +0 -855
- package/src/_generated/zing_studio/article.ts +0 -598
- package/src/_generated/zing_studio/config.ts +0 -475
- package/src/_generated/zing_studio/deps/sui/dynamic_field.ts +0 -272
- package/src/_generated/zing_studio/deps/walrus/events.ts +0 -124
- package/src/_generated/zing_studio/deps/walrus/metadata.ts +0 -137
- package/src/_generated/zing_studio/enclave.ts +0 -466
- package/src/_generated/zing_studio/nitro_attestation.ts +0 -308
- package/src/_generated/zing_studio/referral.ts +0 -447
- package/src/_generated/zing_studio/storage.ts +0 -664
- package/src/_generated/zing_studio/studio.ts +0 -682
- package/src/bcs.ts +0 -139
- package/src/client/index.ts +0 -557
- package/src/client/types.ts +0 -28
- package/src/components/wallet-provider.tsx +0 -53
- package/src/components/walrus-provider.tsx +0 -212
- package/src/components/zing-provider.tsx +0 -54
- package/src/config/common.ts +0 -82
- package/src/config/index.ts +0 -45
- package/src/config/mainnet.ts +0 -109
- package/src/config/testnet.ts +0 -111
- package/src/config/types.ts +0 -69
- package/src/const.ts +0 -32
- package/src/getters.ts +0 -523
- package/src/hooks/useGetStudio.ts +0 -22
- package/src/hooks/useGetTierPlan.ts +0 -115
- package/src/hooks/useReclaim.ts +0 -165
- package/src/hooks/useSignAndExecuteTransaction.ts +0 -57
- package/src/hooks/useSignPersonalMessage.ts +0 -28
- package/src/hooks/useZingInfiniteQueries.ts +0 -92
- package/src/hooks/useZingMutation.ts +0 -66
- package/src/hooks/useZingQueries.ts +0 -107
- package/src/hooks/useZingQuery.ts +0 -88
- package/src/lib/utils/colorful-logger.ts +0 -27
- package/src/lib/utils/const.ts +0 -25
- package/src/lib/utils/helpers.ts +0 -78
- package/src/lib/utils/init-app-with-shadow.ts +0 -42
- package/src/lib/utils/quilt.ts +0 -317
- package/src/lib/utils/reclaim.ts +0 -148
- package/src/lib/utils/types.ts +0 -14
- package/src/mutations/seal.ts +0 -78
- package/src/mutations/signer.ts +0 -241
- package/src/mutations/walrus.ts +0 -862
- package/src/stores/walletStore.ts +0 -360
- package/src/stores/walrusStore.ts +0 -118
- package/src/stores/zkloginStore.ts +0 -53
- package/src/types.ts +0 -120
- package/tsconfig.json +0 -12
- /package/{src/_generated/index.js → dist/_generated/index.d.ts} +0 -0
- /package/{src/components/index.ts → dist/components/index.d.ts} +0 -0
- /package/{src/lib/utils/index.ts → dist/lib/utils/index.d.ts} +0 -0
- /package/{src/mutations/index.ts → dist/mutations/index.d.ts} +0 -0
- /package/{src/stores/index.ts → dist/stores/index.d.ts} +0 -0
package/dist/getters.js
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { TypeName } from "./_generated/zing_identity/deps/std/type_name.js";
|
|
2
|
+
import { IdentifierInfo } from "./_generated/zing_identity/identity.js";
|
|
3
|
+
import { Article, PublishArticleEvent, } from "./_generated/zing_studio/article.js";
|
|
4
|
+
import { Field } from "./_generated/zing_studio/deps/sui/dynamic_field.js";
|
|
5
|
+
import { VecMap } from "./_generated/zing_studio/deps/sui/vec_map.js";
|
|
6
|
+
import { BlobRegistered } from "./_generated/zing_studio/deps/walrus/events.js";
|
|
7
|
+
import { StorageSpace, StorageTreasury, } from "./_generated/zing_studio/storage.js";
|
|
8
|
+
import { Member, Studio } from "./_generated/zing_studio/studio.js";
|
|
9
|
+
import { QuiltPatchId, SuiMoveObject } from "./bcs.js";
|
|
10
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
11
|
+
import { deriveDynamicFieldID, deriveObjectID, fromBase64, normalizeStructTag, toBase64, } from "@mysten/sui/utils";
|
|
12
|
+
// Walrus
|
|
13
|
+
const DIGEST_LEN = 32;
|
|
14
|
+
const BLOB_ID_LEN = 32;
|
|
15
|
+
// Zing
|
|
16
|
+
export function getDerivedStudioID(studioConfigId, address) {
|
|
17
|
+
return deriveObjectID(studioConfigId, "address", bcs.Address.serialize(address).toBytes());
|
|
18
|
+
}
|
|
19
|
+
export function getDerivedStorageID(studioConfigId, address) {
|
|
20
|
+
const studioId = getDerivedStudioID(studioConfigId, address);
|
|
21
|
+
const key = new TextEncoder().encode("storage");
|
|
22
|
+
return deriveObjectID(studioId, "vector<u8>", bcs.vector(bcs.u8()).serialize(key).toBytes());
|
|
23
|
+
}
|
|
24
|
+
export function getDerivedWorksID(studioConfigId, address) {
|
|
25
|
+
const studioId = getDerivedStudioID(studioConfigId, address);
|
|
26
|
+
const key = new TextEncoder().encode("works");
|
|
27
|
+
return deriveObjectID(studioId, "vector<u8>", bcs.vector(bcs.u8()).serialize(key).toBytes());
|
|
28
|
+
}
|
|
29
|
+
export function getDerivedMembershipID(studioConfigId, address) {
|
|
30
|
+
const studioId = getDerivedStudioID(studioConfigId, address);
|
|
31
|
+
const key = new TextEncoder().encode("membership");
|
|
32
|
+
return deriveObjectID(studioId, "vector<u8>", bcs.vector(bcs.u8()).serialize(key).toBytes());
|
|
33
|
+
}
|
|
34
|
+
export async function getIdentifierByAddress(suiGrpcClient, addressToIdentifierDynamicFieldId, address) {
|
|
35
|
+
const dfObjectId = deriveDynamicFieldID(addressToIdentifierDynamicFieldId, "address", bcs.Address.serialize(address).toBytes());
|
|
36
|
+
const res = await suiGrpcClient.ledgerService.getObject({
|
|
37
|
+
objectId: dfObjectId,
|
|
38
|
+
readMask: {
|
|
39
|
+
paths: ["bcs"],
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
if (!res.response.object?.bcs?.value) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const suiMoveObject = SuiMoveObject.parse(res.response.object.bcs.value);
|
|
46
|
+
const field = Field(bcs.Address, bcs.String).parse(suiMoveObject.data.MoveObject.contents);
|
|
47
|
+
return field.value;
|
|
48
|
+
}
|
|
49
|
+
export async function getIdentifierInfoByIdentifier(suiGrpcClient, identifierInfoDynamicFieldId, identifier) {
|
|
50
|
+
const dfObjectId = deriveDynamicFieldID(identifierInfoDynamicFieldId, "0x1::ascii::String", bcs.Address.serialize(identifier).toBytes());
|
|
51
|
+
const res = await suiGrpcClient.ledgerService.getObject({
|
|
52
|
+
objectId: dfObjectId,
|
|
53
|
+
readMask: {
|
|
54
|
+
paths: ["bcs"],
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
if (!res.response.object?.bcs?.value) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const suiMoveObject = SuiMoveObject.parse(res.response.object.bcs.value);
|
|
61
|
+
const field = Field(bcs.String, IdentifierInfo).parse(suiMoveObject.data.MoveObject.contents);
|
|
62
|
+
return field.value;
|
|
63
|
+
}
|
|
64
|
+
export async function getDonationByIdentifier(suiGrpcClient, donationTableId, identifier) {
|
|
65
|
+
const dfObjectId = deriveDynamicFieldID(donationTableId, "0x1::ascii::String", bcs.Address.serialize(identifier).toBytes());
|
|
66
|
+
const res = await suiGrpcClient.ledgerService.getObject({
|
|
67
|
+
objectId: dfObjectId,
|
|
68
|
+
readMask: {
|
|
69
|
+
paths: ["bcs"],
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
if (!res.response.object?.bcs?.value) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const suiMoveObject = SuiMoveObject.parse(res.response.object.bcs.value);
|
|
76
|
+
const field = Field(bcs.String, VecMap(TypeName, bcs.U64)).parse(suiMoveObject.data.MoveObject.contents);
|
|
77
|
+
return field.value;
|
|
78
|
+
}
|
|
79
|
+
export async function getStudio(suiGrpcClient, studioId) {
|
|
80
|
+
try {
|
|
81
|
+
const res = await suiGrpcClient.ledgerService.getObject({
|
|
82
|
+
objectId: studioId,
|
|
83
|
+
readMask: {
|
|
84
|
+
paths: ["bcs"],
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
if (!res.response.object?.bcs?.value) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const suiMoveObject = SuiMoveObject.parse(res.response.object.bcs.value);
|
|
91
|
+
return Studio.parse(suiMoveObject.data.MoveObject.contents);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.error(error);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export async function getStorageSpace(suiGrpcClient, storageSpaceId) {
|
|
99
|
+
try {
|
|
100
|
+
const res = await suiGrpcClient.ledgerService.getObject({
|
|
101
|
+
objectId: storageSpaceId,
|
|
102
|
+
readMask: {
|
|
103
|
+
paths: ["bcs"],
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
if (!res.response.object?.bcs?.value) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
const suiMoveObject = SuiMoveObject.parse(res.response.object.bcs.value);
|
|
110
|
+
return StorageSpace.parse(suiMoveObject.data.MoveObject.contents);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.error(error);
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export async function getStorageTreasury(suiGrpcClient, storageTreasuryId) {
|
|
118
|
+
const res = await suiGrpcClient.ledgerService.getObject({
|
|
119
|
+
objectId: storageTreasuryId,
|
|
120
|
+
readMask: {
|
|
121
|
+
paths: ["bcs"],
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
if (!res.response.object?.bcs?.value) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const suiMoveObject = SuiMoveObject.parse(res.response.object.bcs.value);
|
|
128
|
+
return StorageTreasury.parse(suiMoveObject.data.MoveObject.contents);
|
|
129
|
+
}
|
|
130
|
+
export async function getMember(suiGrpcClient, membershipTableId, member) {
|
|
131
|
+
const dfObjectId = deriveDynamicFieldID(membershipTableId, "address", bcs.Address.serialize(member).toBytes());
|
|
132
|
+
const res = await suiGrpcClient.ledgerService.getObject({
|
|
133
|
+
objectId: dfObjectId,
|
|
134
|
+
readMask: {
|
|
135
|
+
paths: ["bcs"],
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
if (!res.response.object?.bcs?.value) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
const suiMoveObject = SuiMoveObject.parse(res.response.object.bcs.value);
|
|
142
|
+
const field = Field(bcs.Address, Member).parse(suiMoveObject.data.MoveObject.contents);
|
|
143
|
+
return field.value;
|
|
144
|
+
}
|
|
145
|
+
export async function getMembers(suiGrpcClient, membershipTableId, cursor, limit = 20) {
|
|
146
|
+
const res = await suiGrpcClient.stateService.listDynamicFields({
|
|
147
|
+
parent: membershipTableId,
|
|
148
|
+
pageToken: cursor ? fromBase64(cursor) : undefined,
|
|
149
|
+
pageSize: limit,
|
|
150
|
+
readMask: {
|
|
151
|
+
paths: ["field_object.bcs"],
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
const data = res.response.dynamicFields.map((df) => {
|
|
155
|
+
if (!df.fieldObject?.bcs?.value)
|
|
156
|
+
throw new Error("Wrong readMask for reading members");
|
|
157
|
+
const suiMoveObject = SuiMoveObject.parse(df.fieldObject.bcs.value);
|
|
158
|
+
// Wrapped in dynamicFields
|
|
159
|
+
const field = Field(bcs.Address, Member).parse(suiMoveObject.data.MoveObject.contents);
|
|
160
|
+
return {
|
|
161
|
+
member: field.name,
|
|
162
|
+
level: field.value.level,
|
|
163
|
+
expiredAt: field.value.expired_at,
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
data,
|
|
168
|
+
nextCursor: res.response.nextPageToken
|
|
169
|
+
? toBase64(res.response.nextPageToken)
|
|
170
|
+
: undefined,
|
|
171
|
+
hasNextPage: res.response.nextPageToken !== undefined,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export async function getWork(suiGrpcClient, walrusSystem, workId, workType) {
|
|
175
|
+
const res = await suiGrpcClient.ledgerService.getObject({
|
|
176
|
+
objectId: workId,
|
|
177
|
+
readMask: {
|
|
178
|
+
paths: ["bcs"],
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
if (!res.response.object?.bcs?.value) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
const suiMoveObject = SuiMoveObject.parse(res.response.object.bcs.value);
|
|
185
|
+
const type = suiMoveObject.data.MoveObject
|
|
186
|
+
.type;
|
|
187
|
+
if (type.$kind !== "Other" ||
|
|
188
|
+
normalizeStructTag(type.Other) !== workType)
|
|
189
|
+
return null;
|
|
190
|
+
return Article.parse(suiMoveObject.data.MoveObject.contents);
|
|
191
|
+
}
|
|
192
|
+
export async function getWorks(suiGrpcClient, walrusSystem, workTableId, workType, cursor, limit = 20) {
|
|
193
|
+
const res = await suiGrpcClient.stateService.listDynamicFields({
|
|
194
|
+
parent: workTableId,
|
|
195
|
+
pageToken: cursor ? fromBase64(cursor) : undefined,
|
|
196
|
+
pageSize: limit,
|
|
197
|
+
readMask: {
|
|
198
|
+
paths: ["child_object"],
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
const works = res.response.dynamicFields.map((df) => {
|
|
202
|
+
if (!df.childObject?.contents?.value)
|
|
203
|
+
throw new Error("Wrong readMask for reading members");
|
|
204
|
+
// Wrapped in dynamicObjectFields
|
|
205
|
+
const objectType = df.childObject.objectType;
|
|
206
|
+
if (objectType !== workType)
|
|
207
|
+
return null;
|
|
208
|
+
return Article.parse(df.childObject.contents.value);
|
|
209
|
+
});
|
|
210
|
+
const data = works
|
|
211
|
+
.filter((d) => {
|
|
212
|
+
if (!d || d.blobs.length === 0 || d.deleted)
|
|
213
|
+
return false;
|
|
214
|
+
const minEndEpoch = Math.min(...d.blobs.map((b) => b.storage.end_epoch));
|
|
215
|
+
return minEndEpoch > walrusSystem.committee.epoch;
|
|
216
|
+
})
|
|
217
|
+
.sort((a, b) => Number(b.created_at) - Number(a.created_at));
|
|
218
|
+
console.log({ getWorksData: data });
|
|
219
|
+
return {
|
|
220
|
+
data,
|
|
221
|
+
nextCursor: res.response.nextPageToken
|
|
222
|
+
? toBase64(res.response.nextPageToken)
|
|
223
|
+
: undefined,
|
|
224
|
+
hasNextPage: res.response.nextPageToken !== undefined,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
export async function getPublishedArticleAndBlobId(suiGrpcClient, suiClient, walrusClient, digest, blobRegisteredEventType, publishArticleEventType) {
|
|
228
|
+
// suiGrpcClient waitForTransaction calling core.getTransaction which is broken
|
|
229
|
+
await suiClient.waitForTransaction({
|
|
230
|
+
digest,
|
|
231
|
+
});
|
|
232
|
+
if (!digest)
|
|
233
|
+
throw new Error("fail to get transaction hash");
|
|
234
|
+
const res = await suiGrpcClient.ledgerService.getTransaction({
|
|
235
|
+
digest,
|
|
236
|
+
readMask: {
|
|
237
|
+
paths: ["events"],
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
const blobRegisteredEvent = res.response.transaction?.events?.events?.find((e) => e.contents?.name === blobRegisteredEventType);
|
|
241
|
+
const publishArticleEvent = res.response.transaction?.events?.events?.find((e) => e.contents?.name === publishArticleEventType);
|
|
242
|
+
if (!blobRegisteredEvent || !blobRegisteredEvent.contents?.value) {
|
|
243
|
+
throw new Error("fail to get blobRegisteredEvent");
|
|
244
|
+
}
|
|
245
|
+
if (!publishArticleEvent || !publishArticleEvent.contents?.value) {
|
|
246
|
+
throw new Error("fail to get publishArticleEvent");
|
|
247
|
+
}
|
|
248
|
+
const blobObjectId = BlobRegistered.parse(blobRegisteredEvent.contents?.value).object_id;
|
|
249
|
+
const parsedPublishArticleEvent = PublishArticleEvent.parse(publishArticleEvent.contents.value);
|
|
250
|
+
return { parsedPublishArticleEvent, blobObjectId };
|
|
251
|
+
}
|
|
252
|
+
export function encodeQuiltPatchId(id) {
|
|
253
|
+
return urlSafeBase64(QuiltPatchId.serialize(id).toBytes());
|
|
254
|
+
}
|
|
255
|
+
export function urlSafeBase64(bytes) {
|
|
256
|
+
return toBase64(bytes).replace(/=*$/, "").replace("+", "-").replace("/", "_");
|
|
257
|
+
}
|
|
258
|
+
export function getMaxFaultyNodes(nShards) {
|
|
259
|
+
return Math.floor((nShards - 1) / 3);
|
|
260
|
+
}
|
|
261
|
+
export function decodingSafetyLimit(nShards, encodingType) {
|
|
262
|
+
switch (encodingType) {
|
|
263
|
+
case "RedStuff":
|
|
264
|
+
return Math.min(5, Math.floor(getMaxFaultyNodes(nShards) / 5));
|
|
265
|
+
case "RS2":
|
|
266
|
+
return 0;
|
|
267
|
+
default:
|
|
268
|
+
throw new Error(`Encountered unknown encoding type of ${encodingType}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
export function signersToBitmap(signers, committeeSize) {
|
|
272
|
+
const bitmapSize = Math.ceil(committeeSize / 8);
|
|
273
|
+
const bitmap = new Uint8Array(bitmapSize);
|
|
274
|
+
for (const signer of signers) {
|
|
275
|
+
const byteIndex = Math.floor(signer / 8);
|
|
276
|
+
const bitIndex = signer % 8;
|
|
277
|
+
bitmap[byteIndex] |= 1 << bitIndex;
|
|
278
|
+
}
|
|
279
|
+
return bitmap;
|
|
280
|
+
}
|
|
281
|
+
export function getSourceSymbols(nShards, encodingType = "RS2") {
|
|
282
|
+
const safetyLimit = decodingSafetyLimit(nShards, encodingType);
|
|
283
|
+
const maxFaulty = getMaxFaultyNodes(nShards);
|
|
284
|
+
const minCorrect = nShards - maxFaulty;
|
|
285
|
+
return {
|
|
286
|
+
primarySymbols: minCorrect - maxFaulty - safetyLimit,
|
|
287
|
+
secondarySymbols: minCorrect - safetyLimit,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Calculate the encoded sliver size.
|
|
292
|
+
* This matches the Walrus SDK's encodedSliverSize function.
|
|
293
|
+
*/
|
|
294
|
+
export function encodedSliverSize(unencodedLength, nShards, encodingType = "RS2") {
|
|
295
|
+
const { primarySymbols, secondarySymbols } = getSourceSymbols(nShards, encodingType);
|
|
296
|
+
// Calculate symbol size with proper rounding
|
|
297
|
+
let symbolSize = Math.floor((Math.max(unencodedLength, 1) - 1) / (primarySymbols * secondarySymbols)) + 1;
|
|
298
|
+
// RS2 requires even symbol sizes
|
|
299
|
+
if (encodingType === "RS2" && symbolSize % 2 === 1) {
|
|
300
|
+
symbolSize = symbolSize + 1;
|
|
301
|
+
}
|
|
302
|
+
const singleShardSize = (primarySymbols + secondarySymbols) * symbolSize;
|
|
303
|
+
console.log("encodedSliverSize breakdown:", {
|
|
304
|
+
unencodedLength,
|
|
305
|
+
primarySymbols,
|
|
306
|
+
secondarySymbols,
|
|
307
|
+
calculatedSymbolSize: symbolSize,
|
|
308
|
+
singleShardSize,
|
|
309
|
+
totalSliverSize: singleShardSize * nShards,
|
|
310
|
+
});
|
|
311
|
+
return singleShardSize * nShards;
|
|
312
|
+
}
|
|
313
|
+
export function encodedBlobLength(unencodedLength, nShards, encodingType = "RS2") {
|
|
314
|
+
const sliverSize = encodedSliverSize(unencodedLength, nShards, encodingType);
|
|
315
|
+
const metadata = nShards * DIGEST_LEN * 2 + BLOB_ID_LEN;
|
|
316
|
+
return nShards * metadata + sliverSize;
|
|
317
|
+
}
|
|
@@ -7,8 +7,7 @@ export * from "./useZingQueries.js";
|
|
|
7
7
|
export * from "./useZingInfiniteQueries.js";
|
|
8
8
|
export * from "./useGetTierPlan.js";
|
|
9
9
|
export * from "./useSignPersonalMessage.js";
|
|
10
|
-
|
|
11
10
|
export type InfiniteQueryResult<TData> = {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
pages: TData[];
|
|
12
|
+
pageParams: number[];
|
|
14
13
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./useSignAndExecuteTransaction.js";
|
|
2
|
+
export * from "./useReclaim.js";
|
|
3
|
+
export * from "./useGetStudio.js";
|
|
4
|
+
export * from "./useZingMutation.js";
|
|
5
|
+
export * from "./useZingQuery.js";
|
|
6
|
+
export * from "./useZingQueries.js";
|
|
7
|
+
export * from "./useZingInfiniteQueries.js";
|
|
8
|
+
export * from "./useGetTierPlan.js";
|
|
9
|
+
export * from "./useSignPersonalMessage.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare function useGetStudio(suiAddress?: string): import("@tanstack/react-query").UseQueryResult<{
|
|
2
|
+
id: {
|
|
3
|
+
id: string;
|
|
4
|
+
};
|
|
5
|
+
owner: string;
|
|
6
|
+
period: string[];
|
|
7
|
+
monthly_subscription_fee: {
|
|
8
|
+
contents: {
|
|
9
|
+
key: number;
|
|
10
|
+
value: string;
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
membership: {
|
|
14
|
+
id: {
|
|
15
|
+
id: string;
|
|
16
|
+
};
|
|
17
|
+
size: string;
|
|
18
|
+
};
|
|
19
|
+
works: {
|
|
20
|
+
id: {
|
|
21
|
+
id: string;
|
|
22
|
+
};
|
|
23
|
+
size: string;
|
|
24
|
+
};
|
|
25
|
+
encrypted_file_key: number[] | null;
|
|
26
|
+
} | null, Error>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useZingQuery } from "./useZingQuery.js";
|
|
2
|
+
export function useGetStudio(suiAddress) {
|
|
3
|
+
return useZingQuery({
|
|
4
|
+
method: "getStudio",
|
|
5
|
+
params: [suiAddress || ""],
|
|
6
|
+
}, {
|
|
7
|
+
enabled: !!suiAddress,
|
|
8
|
+
retry: (failureCount, error) => {
|
|
9
|
+
if (error instanceof Error && error.message.includes("notExists")) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return failureCount < 1;
|
|
13
|
+
},
|
|
14
|
+
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
15
|
+
gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)
|
|
16
|
+
}, [suiAddress || ""]);
|
|
17
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useZingQuery } from "./useZingQuery.js";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
const tierInfos = {
|
|
4
|
+
0: {
|
|
5
|
+
name: "Basic",
|
|
6
|
+
features: ["Post/Article publishing", "Image protection"],
|
|
7
|
+
},
|
|
8
|
+
1: {
|
|
9
|
+
name: "Premium",
|
|
10
|
+
features: [
|
|
11
|
+
"Larger storage size",
|
|
12
|
+
"Comments for post",
|
|
13
|
+
"Analytics dashboard",
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
// 2: {
|
|
17
|
+
// name: "Premium+",
|
|
18
|
+
// features: [
|
|
19
|
+
// "Advanced publishing",
|
|
20
|
+
// "Priority support",
|
|
21
|
+
// "Unlimited platforms",
|
|
22
|
+
// "Analytics dashboard",
|
|
23
|
+
// ],
|
|
24
|
+
// },
|
|
25
|
+
};
|
|
26
|
+
export function useGetTierPlan() {
|
|
27
|
+
const { data: storageTreasury, isPending } = useZingQuery({
|
|
28
|
+
method: "getStorageTreasury",
|
|
29
|
+
params: [],
|
|
30
|
+
}, {
|
|
31
|
+
staleTime: 0,
|
|
32
|
+
refetchOnMount: "always",
|
|
33
|
+
refetchOnWindowFocus: false,
|
|
34
|
+
});
|
|
35
|
+
return useMemo(() => {
|
|
36
|
+
if (isPending || !storageTreasury) {
|
|
37
|
+
return {
|
|
38
|
+
tierPlans: {},
|
|
39
|
+
storageByEpoch: {},
|
|
40
|
+
walTreasury: "0",
|
|
41
|
+
isLoading: isPending,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (!storageTreasury.tier_plan ||
|
|
45
|
+
!Array.isArray(storageTreasury.tier_plan.contents) ||
|
|
46
|
+
storageTreasury.tier_plan.contents.length === 0) {
|
|
47
|
+
return {
|
|
48
|
+
tierPlans: {},
|
|
49
|
+
storageByEpoch: {},
|
|
50
|
+
walTreasury: storageTreasury.wal_treasury?.balance?.value || "0",
|
|
51
|
+
isLoading: isPending,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const tierPlans = storageTreasury.tier_plan.contents.reduce((acc, tier) => {
|
|
55
|
+
const tierIndex = Number(tier.key);
|
|
56
|
+
const info = tierInfos?.[tierIndex];
|
|
57
|
+
if (!info) {
|
|
58
|
+
return acc;
|
|
59
|
+
}
|
|
60
|
+
acc[tierIndex] = {
|
|
61
|
+
name: info.name,
|
|
62
|
+
duration: tier.value.duration_days,
|
|
63
|
+
price: Number(tier.value.price),
|
|
64
|
+
storage: Number(tier.value.storage_limit),
|
|
65
|
+
features: info.features,
|
|
66
|
+
};
|
|
67
|
+
return acc;
|
|
68
|
+
}, {});
|
|
69
|
+
// Process storageByEpoch
|
|
70
|
+
const storageByEpoch = storageTreasury.storages_by_epoch?.contents?.reduce((acc, storage) => {
|
|
71
|
+
const epoch = Number(storage.key);
|
|
72
|
+
const size = Number(storage.value.storage_size);
|
|
73
|
+
acc[epoch] = size;
|
|
74
|
+
return acc;
|
|
75
|
+
}, {}) || {};
|
|
76
|
+
// Get walTreasury balance
|
|
77
|
+
const walTreasury = storageTreasury.wal_treasury?.balance?.value || "0";
|
|
78
|
+
return {
|
|
79
|
+
tierPlans,
|
|
80
|
+
storageByEpoch,
|
|
81
|
+
walTreasury,
|
|
82
|
+
isLoading: isPending,
|
|
83
|
+
};
|
|
84
|
+
}, [storageTreasury, isPending]);
|
|
85
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PlatformType } from "../config/common.js";
|
|
2
|
+
import type { ReclaimProof } from "../lib/utils/reclaim.js";
|
|
3
|
+
import type { SuiClient } from "@mysten/sui/client";
|
|
4
|
+
interface CommitProofParams {
|
|
5
|
+
suiClient: SuiClient;
|
|
6
|
+
walletAddress: string;
|
|
7
|
+
platform: PlatformType;
|
|
8
|
+
proof: ReclaimProof;
|
|
9
|
+
gasPoolBearerToken: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function useCommitProof(): import("@tanstack/react-query").UseMutationResult<any, Error, CommitProofParams, unknown>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { useSignAndExecuteTransaction } from "./useSignAndExecuteTransaction.js";
|
|
2
|
+
import { commitProof, revealAndVerifyProof, } from "../_generated/zing_identity/reclaim.js";
|
|
3
|
+
import { useZingClient } from "../components/zing-provider.js";
|
|
4
|
+
import { hexToBytes, textToBytes, generateCommitmentHash, generateCommitNonce, } from "../lib/utils/reclaim.js";
|
|
5
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
6
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
7
|
+
import { useMutation } from "@tanstack/react-query";
|
|
8
|
+
import sha3 from "js-sha3";
|
|
9
|
+
export function useCommitProof() {
|
|
10
|
+
const { mutateAsync: signAndExecuteTransaction } = useSignAndExecuteTransaction();
|
|
11
|
+
const zingClient = useZingClient();
|
|
12
|
+
const config = zingClient.config;
|
|
13
|
+
return useMutation({
|
|
14
|
+
mutationFn: async ({ suiClient, walletAddress, platform, proof, gasPoolBearerToken, }) => {
|
|
15
|
+
const nonce = generateCommitNonce(walletAddress, proof.identifier);
|
|
16
|
+
const commitmentHash = generateCommitmentHash(proof, nonce);
|
|
17
|
+
const identifierHash = hexToBytes(sha3.keccak256(textToBytes(proof.identifier)));
|
|
18
|
+
const identityPlatform = config.zing.IDENTITY_PLATFORMS[platform];
|
|
19
|
+
const commitProofTransaction = new Transaction();
|
|
20
|
+
commitProofTransaction.add(commitProof({
|
|
21
|
+
package: config.zing.ZING_IDENTITY_PACKAGE_ADDRESS,
|
|
22
|
+
typeArguments: [identityPlatform.PLATFORM_TYPE],
|
|
23
|
+
arguments: {
|
|
24
|
+
self: commitProofTransaction.sharedObjectRef(identityPlatform.RECLAIM_MANAGER_SHARED_OBJECT_REF),
|
|
25
|
+
config: commitProofTransaction.sharedObjectRef(config.zing.ZING_IDENTITY_CONFIG_SHARED_OBJECT_REF),
|
|
26
|
+
commitmentHash: commitProofTransaction.pure(bcs.vector(bcs.u8()).serialize(commitmentHash)),
|
|
27
|
+
identifierHash: commitProofTransaction.pure(bcs.vector(bcs.u8()).serialize(identifierHash)),
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
const commitTransactionResponse = await signAndExecuteTransaction({
|
|
31
|
+
transaction: commitProofTransaction,
|
|
32
|
+
});
|
|
33
|
+
if (!commitTransactionResponse)
|
|
34
|
+
throw new Error("fail to commit proof");
|
|
35
|
+
const commitTransactionObjectChanges = (await suiClient.waitForTransaction({
|
|
36
|
+
digest: commitTransactionResponse.transactionDigest,
|
|
37
|
+
options: {
|
|
38
|
+
showObjectChanges: true,
|
|
39
|
+
},
|
|
40
|
+
})).objectChanges;
|
|
41
|
+
if (!commitTransactionObjectChanges)
|
|
42
|
+
throw new Error("fail to commit proof");
|
|
43
|
+
const commitment = commitTransactionObjectChanges.find((objChanges) => objChanges.type === "created" &&
|
|
44
|
+
objChanges.objectType === config.zing.PROOF_COMMITMENT_TYPE);
|
|
45
|
+
if (!commitment || commitment.type !== "created")
|
|
46
|
+
throw new Error("fail to commit proof");
|
|
47
|
+
const revealTransaction = new Transaction();
|
|
48
|
+
const [signers, proofObj] = revealTransaction.add(revealAndVerifyProof({
|
|
49
|
+
package: config.zing.ZING_IDENTITY_PACKAGE_ADDRESS,
|
|
50
|
+
typeArguments: [identityPlatform.PLATFORM_TYPE],
|
|
51
|
+
arguments: {
|
|
52
|
+
self: revealTransaction.sharedObjectRef(identityPlatform.RECLAIM_MANAGER_SHARED_OBJECT_REF),
|
|
53
|
+
config: revealTransaction.sharedObjectRef(config.zing.ZING_IDENTITY_CONFIG_SHARED_OBJECT_REF),
|
|
54
|
+
commitmentId: revealTransaction.pure.id(commitment.objectId),
|
|
55
|
+
provider: revealTransaction.pure.string(proof.claimData.provider),
|
|
56
|
+
parameters: revealTransaction.pure.string(proof.claimData.parameters),
|
|
57
|
+
context: revealTransaction.pure.string(proof.claimData.context),
|
|
58
|
+
identifier: revealTransaction.pure.string(proof.claimData.identifier),
|
|
59
|
+
owner: revealTransaction.pure.string(proof.claimData.owner),
|
|
60
|
+
epoch: revealTransaction.pure.string(proof.claimData.epoch.toString()),
|
|
61
|
+
timestampS: revealTransaction.pure.u64(proof.claimData.timestampS),
|
|
62
|
+
signatures: revealTransaction.pure(bcs
|
|
63
|
+
.vector(bcs.vector(bcs.u8()))
|
|
64
|
+
.serialize(proof.signatures.map((sig) => hexToBytes(sig.substring(2))))),
|
|
65
|
+
nonce: revealTransaction.pure(bcs.vector(bcs.u8()).serialize(nonce)),
|
|
66
|
+
},
|
|
67
|
+
}));
|
|
68
|
+
console.log({ signers });
|
|
69
|
+
// Call extract parameters customizaed functions; this interface should identical for different platforms
|
|
70
|
+
revealTransaction.moveCall({
|
|
71
|
+
target: identityPlatform.PLATFORM_UPDATE_PROOF_TARGET,
|
|
72
|
+
arguments: [
|
|
73
|
+
// IdentityManager
|
|
74
|
+
revealTransaction.sharedObjectRef(identityPlatform.IDENTITY_MANAGER_SHARED_OBJECT_REF),
|
|
75
|
+
// IdentityConfig
|
|
76
|
+
revealTransaction.sharedObjectRef(config.zing.ZING_IDENTITY_CONFIG_SHARED_OBJECT_REF),
|
|
77
|
+
proofObj,
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
const transactionResponse = await signAndExecuteTransaction({
|
|
81
|
+
transaction: revealTransaction,
|
|
82
|
+
});
|
|
83
|
+
console.log({ transactionResponse });
|
|
84
|
+
return transactionResponse;
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Transaction } from "@mysten/sui/transactions";
|
|
2
|
+
interface SignAndExecuteTransactionParams {
|
|
3
|
+
transaction: Transaction;
|
|
4
|
+
}
|
|
5
|
+
export declare const useSignAndExecuteTransaction: () => import("@tanstack/react-query").UseMutationResult<any, Error, SignAndExecuteTransactionParams, unknown>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useWalletStore } from "../components/wallet-provider.js";
|
|
2
|
+
import { signAndExecuteGasPoolTransaction } from "../mutations/signer.js";
|
|
3
|
+
import { useMutation } from "@tanstack/react-query";
|
|
4
|
+
const GAS_POOL_OWNER = "0x3198c7da350bf15c48fc598e5b03a0b6e13356801c71b4d1a18b92b09966e5da";
|
|
5
|
+
export const useSignAndExecuteTransaction = () => {
|
|
6
|
+
const getSigner = useWalletStore((s) => s.getSigner);
|
|
7
|
+
const suiClient = useWalletStore((s) => s.suiClient);
|
|
8
|
+
return useMutation({
|
|
9
|
+
mutationFn: async ({ transaction }) => {
|
|
10
|
+
const signer = getSigner();
|
|
11
|
+
if (!signer) {
|
|
12
|
+
throw new Error("Wallet not properly initialized");
|
|
13
|
+
}
|
|
14
|
+
if (!signer.suiAddress) {
|
|
15
|
+
throw new Error("Signer suiAddress not properly initialized");
|
|
16
|
+
}
|
|
17
|
+
// for Debug usage
|
|
18
|
+
transaction.setSender(signer.suiAddress);
|
|
19
|
+
transaction.setGasOwner(GAS_POOL_OWNER);
|
|
20
|
+
const dryRunResponse = await suiClient.dryRunTransactionBlock({
|
|
21
|
+
transactionBlock: await transaction.build({ client: suiClient }),
|
|
22
|
+
});
|
|
23
|
+
console.log({ dryRunResponse });
|
|
24
|
+
if (dryRunResponse.effects.status.status === "success") {
|
|
25
|
+
const effects = await signAndExecuteGasPoolTransaction(signer, suiClient, transaction);
|
|
26
|
+
// TODO: handle error message by code
|
|
27
|
+
if (!effects)
|
|
28
|
+
throw new Error("fail to get Transaction Effects");
|
|
29
|
+
return effects;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
onError: (error, variables) => {
|
|
36
|
+
console.log({ transaction: variables.transaction });
|
|
37
|
+
console.error("Transaction execution failed:", error);
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface SignPersonalMessageParams {
|
|
2
|
+
message: Uint8Array;
|
|
3
|
+
}
|
|
4
|
+
export declare const useSignPersonalMessage: () => import("@tanstack/react-query").UseMutationResult<{
|
|
5
|
+
zkLoginSignature: any;
|
|
6
|
+
bytes: Uint8Array<ArrayBuffer>;
|
|
7
|
+
}, Error, SignPersonalMessageParams, unknown>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useWalletStore } from "../components/wallet-provider.js";
|
|
2
|
+
import { signPersonalMessage } from "../mutations/signer.js";
|
|
3
|
+
import { useMutation } from "@tanstack/react-query";
|
|
4
|
+
export const useSignPersonalMessage = () => {
|
|
5
|
+
const getSigner = useWalletStore((s) => s.getSigner);
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutationFn: async ({ message }) => {
|
|
8
|
+
const signer = getSigner();
|
|
9
|
+
if (!signer) {
|
|
10
|
+
throw new Error("Wallet not properly initialized");
|
|
11
|
+
}
|
|
12
|
+
if (!signer.suiAddress) {
|
|
13
|
+
throw new Error("Signer suiAddress not properly initialized");
|
|
14
|
+
}
|
|
15
|
+
return await signPersonalMessage(signer, message);
|
|
16
|
+
},
|
|
17
|
+
onError: (error) => {
|
|
18
|
+
console.error("Sign Personal Message failed:", error);
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
};
|