@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.
- 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 +14 -6
- 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
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { zkloginStorage } from "./zkloginStore.js";
|
|
2
|
+
import { createZkLoginProof } from "../mutations/signer.js";
|
|
3
|
+
import { decodeSuiPrivateKey } from "@mysten/sui/cryptography";
|
|
4
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
5
|
+
import { fromBase64, toBase64 } from "@mysten/sui/utils";
|
|
6
|
+
import { generateNonce, decodeJwt, getExtendedEphemeralPublicKey, generateRandomness, } from "@mysten/sui/zklogin";
|
|
7
|
+
import { createStore } from "zustand";
|
|
8
|
+
export function createWalletStore(config) {
|
|
9
|
+
const { suiClient, oAuthClientId, network = "testnet", autoInit = true, } = config;
|
|
10
|
+
const baseCreator = (set, get) => ({
|
|
11
|
+
// state
|
|
12
|
+
suiClient,
|
|
13
|
+
isConnected: false,
|
|
14
|
+
isLoading: false,
|
|
15
|
+
account: null,
|
|
16
|
+
error: null,
|
|
17
|
+
network,
|
|
18
|
+
jwt: null,
|
|
19
|
+
decodedJwt: null,
|
|
20
|
+
authProvider: null,
|
|
21
|
+
ephemeralKeyPair: null,
|
|
22
|
+
suiAddress: null,
|
|
23
|
+
zkProof: null,
|
|
24
|
+
maxEpoch: null,
|
|
25
|
+
// actions
|
|
26
|
+
setError(err) {
|
|
27
|
+
set({ error: err });
|
|
28
|
+
},
|
|
29
|
+
setLoading(v) {
|
|
30
|
+
set({ isLoading: v });
|
|
31
|
+
},
|
|
32
|
+
setNetwork(n) {
|
|
33
|
+
set({ network: n });
|
|
34
|
+
},
|
|
35
|
+
async login(provider) {
|
|
36
|
+
try {
|
|
37
|
+
set({ isLoading: true, error: null, authProvider: provider });
|
|
38
|
+
// 1?? Generate ephemeral keypair and maxEpoch
|
|
39
|
+
const ephemeralKeyPair = new Ed25519Keypair();
|
|
40
|
+
const { epoch } = await suiClient.getLatestSuiSystemState();
|
|
41
|
+
const maxEpoch = Number(epoch) + 10;
|
|
42
|
+
const randomness = generateRandomness();
|
|
43
|
+
const nonce = generateNonce(ephemeralKeyPair.getPublicKey(), maxEpoch, randomness);
|
|
44
|
+
const redirectUri = `${window.location.origin}/oauth-callback`;
|
|
45
|
+
const params = new URLSearchParams({
|
|
46
|
+
client_id: oAuthClientId,
|
|
47
|
+
redirect_uri: redirectUri,
|
|
48
|
+
response_type: "id_token",
|
|
49
|
+
scope: "openid profile email",
|
|
50
|
+
nonce,
|
|
51
|
+
});
|
|
52
|
+
const loginURL = `https://accounts.google.com/o/oauth2/v2/auth?${params}`;
|
|
53
|
+
const idToken = await new Promise((resolve, reject) => {
|
|
54
|
+
const width = 500;
|
|
55
|
+
const height = 600;
|
|
56
|
+
const left = window.screenX + (window.innerWidth - width) / 2;
|
|
57
|
+
const top = window.screenY + (window.innerHeight - height) / 2;
|
|
58
|
+
const popup = window.open(loginURL, "oauth2-login", `width=${width},height=${height},top=${top},left=${left}`);
|
|
59
|
+
if (!popup)
|
|
60
|
+
return reject(new Error("Failed to open popup"));
|
|
61
|
+
let resolved = false;
|
|
62
|
+
// Listen for postMessage from the callback page
|
|
63
|
+
const messageHandler = (event) => {
|
|
64
|
+
// Security: verify origin
|
|
65
|
+
if (event.origin !== window.location.origin)
|
|
66
|
+
return;
|
|
67
|
+
if (event.data?.type !== "oauth-callback")
|
|
68
|
+
return;
|
|
69
|
+
if (resolved)
|
|
70
|
+
return;
|
|
71
|
+
resolved = true;
|
|
72
|
+
window.removeEventListener("message", messageHandler);
|
|
73
|
+
clearInterval(checkClosed);
|
|
74
|
+
if (event.data.error) {
|
|
75
|
+
return reject(new Error(event.data.error));
|
|
76
|
+
}
|
|
77
|
+
if (event.data.idToken) {
|
|
78
|
+
resolve(event.data.idToken);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
reject(new Error("No ID token received"));
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
window.addEventListener("message", messageHandler);
|
|
85
|
+
// Check if popup was closed without completing auth
|
|
86
|
+
const checkClosed = setInterval(() => {
|
|
87
|
+
if (!popup || popup.closed) {
|
|
88
|
+
if (!resolved) {
|
|
89
|
+
resolved = true;
|
|
90
|
+
clearInterval(checkClosed);
|
|
91
|
+
window.removeEventListener("message", messageHandler);
|
|
92
|
+
reject(new Error("Login popup closed before completing authentication"));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, 1000);
|
|
96
|
+
// Timeout after 5 minutes
|
|
97
|
+
setTimeout(() => {
|
|
98
|
+
if (!resolved) {
|
|
99
|
+
resolved = true;
|
|
100
|
+
clearInterval(checkClosed);
|
|
101
|
+
window.removeEventListener("message", messageHandler);
|
|
102
|
+
if (popup && !popup.closed)
|
|
103
|
+
popup.close();
|
|
104
|
+
reject(new Error("Login timeout"));
|
|
105
|
+
}
|
|
106
|
+
}, 5 * 60 * 1000);
|
|
107
|
+
});
|
|
108
|
+
// 4?? Decode JWT
|
|
109
|
+
const decoded = decodeJwt(idToken);
|
|
110
|
+
// 5?? Persist ephemeral secret / salt / jwt / maxEpoch
|
|
111
|
+
zkloginStorage
|
|
112
|
+
.getState()
|
|
113
|
+
.setEphemeralSecretKey(toBase64(decodeSuiPrivateKey(ephemeralKeyPair.getSecretKey()).secretKey));
|
|
114
|
+
zkloginStorage.getState().setJWT(idToken);
|
|
115
|
+
zkloginStorage.getState().setMaxEpoch(maxEpoch);
|
|
116
|
+
const extendedEphemeralPublicKey = getExtendedEphemeralPublicKey(ephemeralKeyPair.getPublicKey());
|
|
117
|
+
const zkProofResponse = await createZkLoginProof({
|
|
118
|
+
jwt: idToken,
|
|
119
|
+
maxEpoch: String(maxEpoch),
|
|
120
|
+
extendedEphemeralPublicKey,
|
|
121
|
+
jwtRandomness: randomness,
|
|
122
|
+
});
|
|
123
|
+
if (!zkProofResponse?.result)
|
|
124
|
+
throw new Error(`Failed to get zkProof: ${zkProofResponse.error}`);
|
|
125
|
+
zkloginStorage
|
|
126
|
+
.getState()
|
|
127
|
+
.setZKProof(JSON.stringify(zkProofResponse.result.zkProof));
|
|
128
|
+
const suiAddress = zkProofResponse.result.suiAddress;
|
|
129
|
+
zkloginStorage.getState().setSuiAddress(suiAddress);
|
|
130
|
+
const account = { jwt: decoded };
|
|
131
|
+
set({
|
|
132
|
+
jwt: idToken,
|
|
133
|
+
decodedJwt: decoded,
|
|
134
|
+
ephemeralKeyPair,
|
|
135
|
+
suiAddress,
|
|
136
|
+
zkProof: zkProofResponse.result.zkProof,
|
|
137
|
+
maxEpoch,
|
|
138
|
+
account,
|
|
139
|
+
isConnected: true,
|
|
140
|
+
isLoading: false,
|
|
141
|
+
error: null,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
set({ error: err?.message ?? String(err), isLoading: false });
|
|
146
|
+
throw err;
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
async disconnect() {
|
|
150
|
+
try {
|
|
151
|
+
// reset zkloginStorage
|
|
152
|
+
zkloginStorage.getState().reset();
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// ignore storage errors
|
|
156
|
+
}
|
|
157
|
+
set({
|
|
158
|
+
jwt: null,
|
|
159
|
+
decodedJwt: null,
|
|
160
|
+
ephemeralKeyPair: null,
|
|
161
|
+
suiAddress: null,
|
|
162
|
+
zkProof: null,
|
|
163
|
+
maxEpoch: null,
|
|
164
|
+
account: null,
|
|
165
|
+
isConnected: false,
|
|
166
|
+
isLoading: false,
|
|
167
|
+
authProvider: null,
|
|
168
|
+
error: null,
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
getSigner() {
|
|
172
|
+
const { jwt, maxEpoch, ephemeralKeyPair, zkProof, suiAddress, decodedJwt, } = get();
|
|
173
|
+
if (!jwt || !maxEpoch || !ephemeralKeyPair || !zkProof)
|
|
174
|
+
return null;
|
|
175
|
+
return {
|
|
176
|
+
ephemeralKeyPair,
|
|
177
|
+
suiAddress,
|
|
178
|
+
decodedJwt,
|
|
179
|
+
zkProof,
|
|
180
|
+
maxEpoch,
|
|
181
|
+
};
|
|
182
|
+
},
|
|
183
|
+
async initFromStorage() {
|
|
184
|
+
try {
|
|
185
|
+
set({ isLoading: true });
|
|
186
|
+
const { epoch: currentEpoch } = await suiClient.getLatestSuiSystemState();
|
|
187
|
+
const stored = {
|
|
188
|
+
jwt: zkloginStorage.getState().jwt,
|
|
189
|
+
maxEpoch: zkloginStorage.getState().maxEpoch,
|
|
190
|
+
ephemeralSecretKey: zkloginStorage.getState().ephemeralSecretKey,
|
|
191
|
+
zkProof: zkloginStorage.getState().zkProof,
|
|
192
|
+
suiAddress: zkloginStorage.getState().suiAddress,
|
|
193
|
+
};
|
|
194
|
+
if (!stored.jwt ||
|
|
195
|
+
!stored.maxEpoch ||
|
|
196
|
+
!stored.ephemeralSecretKey ||
|
|
197
|
+
!stored.zkProof ||
|
|
198
|
+
!stored.suiAddress) {
|
|
199
|
+
throw new Error("Missing required params");
|
|
200
|
+
}
|
|
201
|
+
if (Number(currentEpoch) >= Number(stored.maxEpoch))
|
|
202
|
+
throw new Error("Exceed maxEpoch");
|
|
203
|
+
const ephemeralKeyPair = Ed25519Keypair.fromSecretKey(fromBase64(stored.ephemeralSecretKey));
|
|
204
|
+
const decoded = decodeJwt(stored.jwt);
|
|
205
|
+
const zkProofParsed = JSON.parse(stored.zkProof);
|
|
206
|
+
set({
|
|
207
|
+
jwt: stored.jwt,
|
|
208
|
+
decodedJwt: decoded,
|
|
209
|
+
ephemeralKeyPair,
|
|
210
|
+
suiAddress: stored.suiAddress,
|
|
211
|
+
zkProof: zkProofParsed,
|
|
212
|
+
maxEpoch: Number(stored.maxEpoch),
|
|
213
|
+
account: { jwt: decoded },
|
|
214
|
+
isConnected: true,
|
|
215
|
+
error: null,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
set({ error: err?.message ?? String(err) });
|
|
220
|
+
}
|
|
221
|
+
set({ isLoading: false });
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
const store = createStore()(baseCreator);
|
|
225
|
+
if (autoInit) {
|
|
226
|
+
store
|
|
227
|
+
.getState()
|
|
228
|
+
.initFromStorage()
|
|
229
|
+
.catch(() => { });
|
|
230
|
+
}
|
|
231
|
+
return store;
|
|
232
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { WalrusStakingState, WalrusSystemState } from "../config/types.js";
|
|
2
|
+
import type { SealClient } from "@mysten/seal";
|
|
3
|
+
import type { WalrusClient } from "@mysten/walrus";
|
|
4
|
+
import type { StoreApi } from "zustand";
|
|
5
|
+
import type { StateStorage } from "zustand/middleware";
|
|
6
|
+
export type WalrusStore = {
|
|
7
|
+
walrusClient: WalrusClient;
|
|
8
|
+
sealClient: SealClient;
|
|
9
|
+
walrusStakingState?: WalrusStakingState;
|
|
10
|
+
walrusSystemState?: WalrusSystemState;
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
error?: string | null;
|
|
13
|
+
init: () => Promise<void>;
|
|
14
|
+
refreshWalrusState: () => Promise<void>;
|
|
15
|
+
setError: (err?: string | null) => void;
|
|
16
|
+
setStakingState: (state?: WalrusStakingState) => void;
|
|
17
|
+
setSystemState: (state?: WalrusSystemState) => void;
|
|
18
|
+
setWalrusClient: (c: WalrusClient) => void;
|
|
19
|
+
setSealClient: (c: SealClient) => void;
|
|
20
|
+
};
|
|
21
|
+
export type WalrusStoreConfig = {
|
|
22
|
+
walrusClient: WalrusClient;
|
|
23
|
+
sealClient: SealClient;
|
|
24
|
+
storage?: StateStorage;
|
|
25
|
+
storageKey?: string;
|
|
26
|
+
autoInit?: boolean;
|
|
27
|
+
};
|
|
28
|
+
export declare function createWalrusStore(config: WalrusStoreConfig): StoreApi<WalrusStore>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createStore } from "zustand";
|
|
2
|
+
import { persist, createJSONStorage } from "zustand/middleware";
|
|
3
|
+
export function createWalrusStore(config) {
|
|
4
|
+
const { walrusClient, sealClient, storage, storageKey = "walrus-store", autoInit = true, } = config;
|
|
5
|
+
const baseStore = (set, get) => ({
|
|
6
|
+
walrusClient,
|
|
7
|
+
sealClient,
|
|
8
|
+
walrusStakingState: undefined,
|
|
9
|
+
walrusSystemState: undefined,
|
|
10
|
+
isLoading: false,
|
|
11
|
+
error: null,
|
|
12
|
+
setWalrusClient(c) {
|
|
13
|
+
set(() => ({ walrusClient: c }));
|
|
14
|
+
},
|
|
15
|
+
setSealClient(c) {
|
|
16
|
+
set(() => ({ sealClient: c }));
|
|
17
|
+
},
|
|
18
|
+
setError(err) {
|
|
19
|
+
set(() => ({ error: err ?? null }));
|
|
20
|
+
},
|
|
21
|
+
setStakingState(state) {
|
|
22
|
+
set(() => ({ walrusStakingState: state }));
|
|
23
|
+
},
|
|
24
|
+
setSystemState(state) {
|
|
25
|
+
set(() => ({ walrusSystemState: state }));
|
|
26
|
+
},
|
|
27
|
+
async refreshWalrusState() {
|
|
28
|
+
const client = get().walrusClient;
|
|
29
|
+
if (!client) {
|
|
30
|
+
set(() => ({ error: "WalrusClient not initialized" }));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
set(() => ({ isLoading: true, error: null }));
|
|
35
|
+
const walrusStakingState = await client.stakingState();
|
|
36
|
+
const walrusSystemState = await client.systemState();
|
|
37
|
+
set(() => ({ walrusStakingState, walrusSystemState }));
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
set(() => ({ error: e instanceof Error ? e.message : String(e) }));
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
set(() => ({ isLoading: false }));
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
async init() {
|
|
47
|
+
await get().refreshWalrusState();
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
if (storage) {
|
|
51
|
+
return createStore()(persist(baseStore, {
|
|
52
|
+
name: storageKey,
|
|
53
|
+
storage: createJSONStorage(() => storage),
|
|
54
|
+
partialize: () => ({}),
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
const store = createStore()(baseStore);
|
|
58
|
+
if (autoInit)
|
|
59
|
+
store.getState().init();
|
|
60
|
+
return store;
|
|
61
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface ZKLoginStorage {
|
|
2
|
+
jwt: string | null;
|
|
3
|
+
suiAddress: string | null;
|
|
4
|
+
maxEpoch: number | null;
|
|
5
|
+
expiresAt: number | null;
|
|
6
|
+
ephemeralSecretKey: string | null;
|
|
7
|
+
zkProof: string | null;
|
|
8
|
+
setSuiAddress: (suiAddress: string) => void;
|
|
9
|
+
setMaxEpoch: (maxEpoch: number) => void;
|
|
10
|
+
setExpiresAt: (expiresAt: number) => void;
|
|
11
|
+
setJWT: (jwt: string) => void;
|
|
12
|
+
setEphemeralSecretKey: (key: string) => void;
|
|
13
|
+
setZKProof: (proof: string) => void;
|
|
14
|
+
reset: () => void;
|
|
15
|
+
}
|
|
16
|
+
export declare const zkloginStorage: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<ZKLoginStorage>, "setState" | "persist"> & {
|
|
17
|
+
setState(partial: ZKLoginStorage | Partial<ZKLoginStorage> | ((state: ZKLoginStorage) => ZKLoginStorage | Partial<ZKLoginStorage>), replace?: false | undefined): unknown;
|
|
18
|
+
setState(state: ZKLoginStorage | ((state: ZKLoginStorage) => ZKLoginStorage), replace: true): unknown;
|
|
19
|
+
persist: {
|
|
20
|
+
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<ZKLoginStorage, unknown, unknown>>) => void;
|
|
21
|
+
clearStorage: () => void;
|
|
22
|
+
rehydrate: () => Promise<void> | void;
|
|
23
|
+
hasHydrated: () => boolean;
|
|
24
|
+
onHydrate: (fn: (state: ZKLoginStorage) => void) => () => void;
|
|
25
|
+
onFinishHydration: (fn: (state: ZKLoginStorage) => void) => () => void;
|
|
26
|
+
getOptions: () => Partial<import("zustand/middleware").PersistOptions<ZKLoginStorage, unknown, unknown>>;
|
|
27
|
+
};
|
|
28
|
+
}>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
import { persist, createJSONStorage } from "zustand/middleware";
|
|
3
|
+
export const zkloginStorage = create()(persist((set) => ({
|
|
4
|
+
jwt: null,
|
|
5
|
+
suiAddress: null,
|
|
6
|
+
maxEpoch: null,
|
|
7
|
+
expiresAt: null,
|
|
8
|
+
ephemeralSecretKey: null,
|
|
9
|
+
zkProof: null,
|
|
10
|
+
setSuiAddress: (suiAddress) => set({ suiAddress }),
|
|
11
|
+
setMaxEpoch: (maxEpoch) => set({ maxEpoch }),
|
|
12
|
+
setExpiresAt: (expiresAt) => set({ expiresAt }),
|
|
13
|
+
setJWT: (jwt) => set({ jwt }),
|
|
14
|
+
setEphemeralSecretKey: (ephemeralSecretKey) => set({ ephemeralSecretKey }),
|
|
15
|
+
setZKProof: (zkProof) => set({ zkProof }),
|
|
16
|
+
reset: () => set({
|
|
17
|
+
jwt: null,
|
|
18
|
+
suiAddress: null,
|
|
19
|
+
maxEpoch: null,
|
|
20
|
+
expiresAt: null,
|
|
21
|
+
ephemeralSecretKey: null,
|
|
22
|
+
zkProof: null,
|
|
23
|
+
}),
|
|
24
|
+
}), {
|
|
25
|
+
name: "zklogin-storage", // localStorage key
|
|
26
|
+
storage: createJSONStorage(() => localStorage),
|
|
27
|
+
}));
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { PlatformType } from "./config/common.js";
|
|
2
|
+
import type { SuiObjectRef, TransactionEffects } from "@mysten/sui/client";
|
|
3
|
+
import type { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
4
|
+
import type { decodeJwt, getZkLoginSignature } from "@mysten/sui/zklogin";
|
|
5
|
+
export type SuiNetwork = "mainnet" | "testnet";
|
|
6
|
+
export type PartialZkLoginSignature = Omit<Parameters<typeof getZkLoginSignature>["0"]["inputs"], "addressSeed">;
|
|
7
|
+
export interface ZKLoginSignerState {
|
|
8
|
+
ephemeralKeyPair: Ed25519Keypair | null;
|
|
9
|
+
suiAddress: string | null;
|
|
10
|
+
decodedJwt: ReturnType<typeof decodeJwt> | null;
|
|
11
|
+
zkProof: PartialZkLoginSignature | null;
|
|
12
|
+
maxEpoch: number | null;
|
|
13
|
+
}
|
|
14
|
+
export interface SponsoredGasParams {
|
|
15
|
+
gaslessTransactionBytes: string;
|
|
16
|
+
senderAddress: string;
|
|
17
|
+
gasBudget?: string;
|
|
18
|
+
gasPrice?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface GenerateSaltRequest {
|
|
21
|
+
sub: string;
|
|
22
|
+
iss: string;
|
|
23
|
+
aud: string;
|
|
24
|
+
}
|
|
25
|
+
export interface GenerateSaltResponse {
|
|
26
|
+
salt: string;
|
|
27
|
+
saltInt: string;
|
|
28
|
+
deviceId: string | null;
|
|
29
|
+
timestamp: string;
|
|
30
|
+
}
|
|
31
|
+
export type SponsoredGasResponse = {
|
|
32
|
+
jsonrpc: string;
|
|
33
|
+
result: {
|
|
34
|
+
txBytes: string;
|
|
35
|
+
txDigest: string;
|
|
36
|
+
signature: string;
|
|
37
|
+
expireAtTime: number;
|
|
38
|
+
};
|
|
39
|
+
id: number;
|
|
40
|
+
error?: never;
|
|
41
|
+
} | {
|
|
42
|
+
jsonrpc: string;
|
|
43
|
+
error: {
|
|
44
|
+
code: number;
|
|
45
|
+
message: string;
|
|
46
|
+
data?: {
|
|
47
|
+
details?: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
id: number;
|
|
51
|
+
result?: never;
|
|
52
|
+
};
|
|
53
|
+
export interface ReserveGasRequest {
|
|
54
|
+
gas_budget: number;
|
|
55
|
+
reserve_duration_secs: number;
|
|
56
|
+
}
|
|
57
|
+
export interface ReserveGasResponse {
|
|
58
|
+
result: ReserveGasResult | null;
|
|
59
|
+
error: string | null;
|
|
60
|
+
}
|
|
61
|
+
export interface ReserveGasResult {
|
|
62
|
+
sponsor_address: string;
|
|
63
|
+
reservation_id: string;
|
|
64
|
+
gas_coins: SuiObjectRef[];
|
|
65
|
+
}
|
|
66
|
+
export interface ExecuteSponsoredTxRequest {
|
|
67
|
+
reservation_id: string;
|
|
68
|
+
tx_bytes: string;
|
|
69
|
+
user_sig: string;
|
|
70
|
+
}
|
|
71
|
+
export interface ExecuteSponsoredTxResponse {
|
|
72
|
+
effects: TransactionEffects | null;
|
|
73
|
+
error: string | null;
|
|
74
|
+
}
|
|
75
|
+
export type PlatformIdentifiers = Record<PlatformType, string>;
|
|
76
|
+
export interface ZkLoginProofParams {
|
|
77
|
+
jwt: string;
|
|
78
|
+
maxEpoch: string;
|
|
79
|
+
extendedEphemeralPublicKey: string;
|
|
80
|
+
jwtRandomness: string;
|
|
81
|
+
}
|
|
82
|
+
export interface ZkLoginProofResponse {
|
|
83
|
+
id: number;
|
|
84
|
+
result?: {
|
|
85
|
+
zkProof: PartialZkLoginSignature;
|
|
86
|
+
suiAddress: string;
|
|
87
|
+
};
|
|
88
|
+
error?: {
|
|
89
|
+
code: number;
|
|
90
|
+
message: string;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export interface TierPlan {
|
|
94
|
+
name: string;
|
|
95
|
+
price: number;
|
|
96
|
+
duration: number;
|
|
97
|
+
storage: number;
|
|
98
|
+
features: string[];
|
|
99
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
"name": "@zing-protocol/zing-sdk",
|
|
3
3
|
"sideEffects": false,
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.0.
|
|
6
|
-
"main": "./
|
|
7
|
-
"types": "./
|
|
5
|
+
"version": "0.0.2",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
|
-
".":
|
|
10
|
-
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
11
13
|
},
|
|
12
14
|
"scripts": {
|
|
13
15
|
"build": "tsc",
|
|
@@ -33,5 +35,11 @@
|
|
|
33
35
|
"@types/react": "catalog:",
|
|
34
36
|
"@types/react-dom": "catalog:",
|
|
35
37
|
"@types/node": "catalog:"
|
|
36
|
-
}
|
|
38
|
+
},
|
|
39
|
+
"private": false,
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"README.md",
|
|
43
|
+
"LICENSE"
|
|
44
|
+
]
|
|
37
45
|
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
bcs,
|
|
3
|
-
TypeTagSerializer,
|
|
4
|
-
BcsStruct,
|
|
5
|
-
BcsEnum,
|
|
6
|
-
BcsTuple,
|
|
7
|
-
} from "@mysten/sui/bcs";
|
|
8
|
-
import { isArgument } from "@mysten/sui/transactions";
|
|
9
|
-
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
10
|
-
import type { BcsType, TypeTag } from "@mysten/sui/bcs";
|
|
11
|
-
import type { TransactionArgument } from "@mysten/sui/transactions";
|
|
12
|
-
|
|
13
|
-
const MOVE_STDLIB_ADDRESS = normalizeSuiAddress("0x1");
|
|
14
|
-
const SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress("0x2");
|
|
15
|
-
const SUI_SYSTEM_ADDRESS = normalizeSuiAddress("0x3");
|
|
16
|
-
|
|
17
|
-
function stringify(val: unknown) {
|
|
18
|
-
if (typeof val === "object") {
|
|
19
|
-
return JSON.stringify(val, (val: unknown) => val);
|
|
20
|
-
}
|
|
21
|
-
if (typeof val === "bigint") {
|
|
22
|
-
return val.toString();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return val;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type RawTransactionArgument<T> = T | TransactionArgument;
|
|
29
|
-
|
|
30
|
-
export function getPureBcsSchema(
|
|
31
|
-
typeTag: string | TypeTag,
|
|
32
|
-
): BcsType<any> | null {
|
|
33
|
-
const parsedTag =
|
|
34
|
-
typeof typeTag === "string"
|
|
35
|
-
? TypeTagSerializer.parseFromStr(typeTag)
|
|
36
|
-
: typeTag;
|
|
37
|
-
|
|
38
|
-
if ("u8" in parsedTag) {
|
|
39
|
-
return bcs.U8;
|
|
40
|
-
} else if ("u16" in parsedTag) {
|
|
41
|
-
return bcs.U16;
|
|
42
|
-
} else if ("u32" in parsedTag) {
|
|
43
|
-
return bcs.U32;
|
|
44
|
-
} else if ("u64" in parsedTag) {
|
|
45
|
-
return bcs.U64;
|
|
46
|
-
} else if ("u128" in parsedTag) {
|
|
47
|
-
return bcs.U128;
|
|
48
|
-
} else if ("u256" in parsedTag) {
|
|
49
|
-
return bcs.U256;
|
|
50
|
-
} else if ("address" in parsedTag) {
|
|
51
|
-
return bcs.Address;
|
|
52
|
-
} else if ("bool" in parsedTag) {
|
|
53
|
-
return bcs.Bool;
|
|
54
|
-
} else if ("vector" in parsedTag) {
|
|
55
|
-
const type = getPureBcsSchema(parsedTag.vector);
|
|
56
|
-
return type ? bcs.vector(type) : null;
|
|
57
|
-
} else if ("struct" in parsedTag) {
|
|
58
|
-
const structTag = parsedTag.struct;
|
|
59
|
-
const pkg = normalizeSuiAddress(parsedTag.struct.address);
|
|
60
|
-
|
|
61
|
-
if (pkg === MOVE_STDLIB_ADDRESS) {
|
|
62
|
-
if (
|
|
63
|
-
(structTag.module === "ascii" || structTag.module === "string") &&
|
|
64
|
-
structTag.name === "String"
|
|
65
|
-
) {
|
|
66
|
-
return bcs.String;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (structTag.module === "option" && structTag.name === "Option") {
|
|
70
|
-
const type = getPureBcsSchema(structTag.typeParams[0]!);
|
|
71
|
-
return type ? bcs.option(type) : null;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
pkg === SUI_FRAMEWORK_ADDRESS &&
|
|
77
|
-
structTag.module === "Object" &&
|
|
78
|
-
structTag.name === "ID"
|
|
79
|
-
) {
|
|
80
|
-
return bcs.Address;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function normalizeMoveArguments(
|
|
88
|
-
args: unknown[] | object,
|
|
89
|
-
argTypes: string[],
|
|
90
|
-
parameterNames?: string[],
|
|
91
|
-
) {
|
|
92
|
-
const argLen = Array.isArray(args) ? args.length : Object.keys(args).length;
|
|
93
|
-
if (parameterNames && argLen !== parameterNames.length) {
|
|
94
|
-
throw new Error(
|
|
95
|
-
`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`,
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const normalizedArgs: TransactionArgument[] = [];
|
|
100
|
-
|
|
101
|
-
let index = 0;
|
|
102
|
-
for (const [i, argType] of argTypes.entries()) {
|
|
103
|
-
if (argType === `${SUI_FRAMEWORK_ADDRESS}::deny_list::DenyList`) {
|
|
104
|
-
normalizedArgs.push((tx) => tx.object.denyList());
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (argType === `${SUI_FRAMEWORK_ADDRESS}::random::Random`) {
|
|
109
|
-
normalizedArgs.push((tx) => tx.object.random());
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (argType === `${SUI_FRAMEWORK_ADDRESS}::clock::Clock`) {
|
|
114
|
-
normalizedArgs.push((tx) => tx.object.clock());
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (argType === `${SUI_SYSTEM_ADDRESS}::sui_system::SuiSystemState`) {
|
|
119
|
-
normalizedArgs.push((tx) => tx.object.system());
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
let arg;
|
|
124
|
-
if (Array.isArray(args)) {
|
|
125
|
-
if (index >= args.length) {
|
|
126
|
-
throw new Error(
|
|
127
|
-
`Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`,
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
arg = args[index];
|
|
131
|
-
} else {
|
|
132
|
-
if (!parameterNames) {
|
|
133
|
-
throw new Error(`Expected arguments to be passed as an array`);
|
|
134
|
-
}
|
|
135
|
-
const name = parameterNames[index];
|
|
136
|
-
arg = args[name as keyof typeof args];
|
|
137
|
-
|
|
138
|
-
if (arg === undefined) {
|
|
139
|
-
throw new Error(`Parameter ${name} is required`);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
index += 1;
|
|
144
|
-
|
|
145
|
-
if (typeof arg === "function" || isArgument(arg)) {
|
|
146
|
-
normalizedArgs.push(arg as TransactionArgument);
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const type = argTypes[i]!;
|
|
151
|
-
const bcsType = getPureBcsSchema(type);
|
|
152
|
-
|
|
153
|
-
if (bcsType) {
|
|
154
|
-
const bytes = bcsType.serialize(arg as never);
|
|
155
|
-
normalizedArgs.push((tx) => tx.pure(bytes));
|
|
156
|
-
continue;
|
|
157
|
-
} else if (typeof arg === "string") {
|
|
158
|
-
normalizedArgs.push((tx) => tx.object(arg));
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
throw new Error(`Invalid argument ${stringify(arg)} for type ${type}`);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return normalizedArgs;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export class MoveStruct<
|
|
169
|
-
T extends Record<string, BcsType<any>>,
|
|
170
|
-
const Name extends string = string,
|
|
171
|
-
> extends BcsStruct<T, Name> {}
|
|
172
|
-
|
|
173
|
-
export class MoveEnum<
|
|
174
|
-
T extends Record<string, BcsType<any> | null>,
|
|
175
|
-
const Name extends string,
|
|
176
|
-
> extends BcsEnum<T, Name> {}
|
|
177
|
-
|
|
178
|
-
export class MoveTuple<
|
|
179
|
-
T extends readonly BcsType<any>[],
|
|
180
|
-
const Name extends string,
|
|
181
|
-
> extends BcsTuple<T, Name> {}
|