@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
|
@@ -1,360 +0,0 @@
|
|
|
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 {
|
|
7
|
-
generateNonce,
|
|
8
|
-
decodeJwt,
|
|
9
|
-
getExtendedEphemeralPublicKey,
|
|
10
|
-
generateRandomness,
|
|
11
|
-
} from "@mysten/sui/zklogin";
|
|
12
|
-
import { createStore } from "zustand";
|
|
13
|
-
import type { AuthProvider } from "../config/common.js";
|
|
14
|
-
import type { PartialZkLoginSignature, ZKLoginSignerState } from "../types.js";
|
|
15
|
-
import type { SuiClient } from "@mysten/sui/client";
|
|
16
|
-
import type { StoreApi, StateCreator } from "zustand";
|
|
17
|
-
|
|
18
|
-
export interface WalletAccount {
|
|
19
|
-
jwt: ReturnType<typeof decodeJwt> & {
|
|
20
|
-
email: string;
|
|
21
|
-
email_verified: boolean;
|
|
22
|
-
family_name?: string;
|
|
23
|
-
given_name?: string;
|
|
24
|
-
name?: string;
|
|
25
|
-
picture?: string;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface WalletState {
|
|
30
|
-
suiClient: SuiClient;
|
|
31
|
-
isConnected: boolean;
|
|
32
|
-
isLoading: boolean;
|
|
33
|
-
account: WalletAccount | null;
|
|
34
|
-
error: string | null;
|
|
35
|
-
network: string;
|
|
36
|
-
// zk/login state (kept in memory; secrets persisted in zkloginStorage only)
|
|
37
|
-
jwt: string | null;
|
|
38
|
-
decodedJwt: ReturnType<typeof decodeJwt> | null;
|
|
39
|
-
authProvider: AuthProvider | null;
|
|
40
|
-
ephemeralKeyPair: Ed25519Keypair | null;
|
|
41
|
-
suiAddress: string | null;
|
|
42
|
-
zkProof: PartialZkLoginSignature | null;
|
|
43
|
-
maxEpoch?: number | null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type WalletActions = {
|
|
47
|
-
// main flows
|
|
48
|
-
login: (provider: AuthProvider) => Promise<void>;
|
|
49
|
-
disconnect: () => Promise<void>;
|
|
50
|
-
getSigner: () => ZKLoginSignerState | null;
|
|
51
|
-
initFromStorage: () => Promise<void>;
|
|
52
|
-
|
|
53
|
-
// helpers
|
|
54
|
-
setError: (err: string | null) => void;
|
|
55
|
-
setLoading: (v: boolean) => void;
|
|
56
|
-
setNetwork: (n: string) => void;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export type WalletStore = WalletState & WalletActions;
|
|
60
|
-
|
|
61
|
-
export type WalletStoreConfig = {
|
|
62
|
-
suiClient: SuiClient;
|
|
63
|
-
oAuthClientId: string;
|
|
64
|
-
network?: string; // default 'testnet'
|
|
65
|
-
autoInit?: boolean; // call initFromStorage automatically on creation
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export function createWalletStore(
|
|
69
|
-
config: WalletStoreConfig,
|
|
70
|
-
): StoreApi<WalletStore> {
|
|
71
|
-
const {
|
|
72
|
-
suiClient,
|
|
73
|
-
oAuthClientId,
|
|
74
|
-
network = "testnet",
|
|
75
|
-
autoInit = true,
|
|
76
|
-
} = config;
|
|
77
|
-
|
|
78
|
-
const baseCreator: StateCreator<WalletStore> = (set, get) => ({
|
|
79
|
-
// state
|
|
80
|
-
suiClient,
|
|
81
|
-
isConnected: false,
|
|
82
|
-
isLoading: false,
|
|
83
|
-
account: null,
|
|
84
|
-
error: null,
|
|
85
|
-
network,
|
|
86
|
-
jwt: null,
|
|
87
|
-
decodedJwt: null,
|
|
88
|
-
authProvider: null,
|
|
89
|
-
ephemeralKeyPair: null,
|
|
90
|
-
suiAddress: null,
|
|
91
|
-
zkProof: null,
|
|
92
|
-
maxEpoch: null,
|
|
93
|
-
|
|
94
|
-
// actions
|
|
95
|
-
setError(err) {
|
|
96
|
-
set({ error: err });
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
setLoading(v) {
|
|
100
|
-
set({ isLoading: v });
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
setNetwork(n) {
|
|
104
|
-
set({ network: n });
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
async login(provider) {
|
|
108
|
-
try {
|
|
109
|
-
set({ isLoading: true, error: null, authProvider: provider });
|
|
110
|
-
|
|
111
|
-
// 1?? Generate ephemeral keypair and maxEpoch
|
|
112
|
-
const ephemeralKeyPair = new Ed25519Keypair();
|
|
113
|
-
const { epoch } = await suiClient.getLatestSuiSystemState();
|
|
114
|
-
const maxEpoch = Number(epoch) + 10;
|
|
115
|
-
const randomness = generateRandomness();
|
|
116
|
-
const nonce = generateNonce(
|
|
117
|
-
ephemeralKeyPair.getPublicKey(),
|
|
118
|
-
maxEpoch,
|
|
119
|
-
randomness,
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
const redirectUri = `${window.location.origin}/oauth-callback`;
|
|
123
|
-
const params = new URLSearchParams({
|
|
124
|
-
client_id: oAuthClientId,
|
|
125
|
-
redirect_uri: redirectUri,
|
|
126
|
-
response_type: "id_token",
|
|
127
|
-
scope: "openid profile email",
|
|
128
|
-
nonce,
|
|
129
|
-
});
|
|
130
|
-
const loginURL = `https://accounts.google.com/o/oauth2/v2/auth?${params}`;
|
|
131
|
-
|
|
132
|
-
const idToken = await new Promise<string>((resolve, reject) => {
|
|
133
|
-
const width = 500;
|
|
134
|
-
const height = 600;
|
|
135
|
-
const left = window.screenX + (window.innerWidth - width) / 2;
|
|
136
|
-
const top = window.screenY + (window.innerHeight - height) / 2;
|
|
137
|
-
|
|
138
|
-
const popup = window.open(
|
|
139
|
-
loginURL,
|
|
140
|
-
"oauth2-login",
|
|
141
|
-
`width=${width},height=${height},top=${top},left=${left}`,
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
if (!popup) return reject(new Error("Failed to open popup"));
|
|
145
|
-
|
|
146
|
-
let resolved = false;
|
|
147
|
-
|
|
148
|
-
// Listen for postMessage from the callback page
|
|
149
|
-
const messageHandler = (event: MessageEvent) => {
|
|
150
|
-
// Security: verify origin
|
|
151
|
-
if (event.origin !== window.location.origin) return;
|
|
152
|
-
if (event.data?.type !== "oauth-callback") return;
|
|
153
|
-
if (resolved) return;
|
|
154
|
-
|
|
155
|
-
resolved = true;
|
|
156
|
-
window.removeEventListener("message", messageHandler);
|
|
157
|
-
clearInterval(checkClosed);
|
|
158
|
-
|
|
159
|
-
if (event.data.error) {
|
|
160
|
-
return reject(new Error(event.data.error));
|
|
161
|
-
}
|
|
162
|
-
if (event.data.idToken) {
|
|
163
|
-
resolve(event.data.idToken);
|
|
164
|
-
} else {
|
|
165
|
-
reject(new Error("No ID token received"));
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
window.addEventListener("message", messageHandler);
|
|
170
|
-
|
|
171
|
-
// Check if popup was closed without completing auth
|
|
172
|
-
const checkClosed = setInterval(() => {
|
|
173
|
-
if (!popup || popup.closed) {
|
|
174
|
-
if (!resolved) {
|
|
175
|
-
resolved = true;
|
|
176
|
-
clearInterval(checkClosed);
|
|
177
|
-
window.removeEventListener("message", messageHandler);
|
|
178
|
-
reject(
|
|
179
|
-
new Error(
|
|
180
|
-
"Login popup closed before completing authentication",
|
|
181
|
-
),
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}, 1000);
|
|
186
|
-
|
|
187
|
-
// Timeout after 5 minutes
|
|
188
|
-
setTimeout(
|
|
189
|
-
() => {
|
|
190
|
-
if (!resolved) {
|
|
191
|
-
resolved = true;
|
|
192
|
-
clearInterval(checkClosed);
|
|
193
|
-
window.removeEventListener("message", messageHandler);
|
|
194
|
-
if (popup && !popup.closed) popup.close();
|
|
195
|
-
reject(new Error("Login timeout"));
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
5 * 60 * 1000,
|
|
199
|
-
);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
// 4?? Decode JWT
|
|
203
|
-
const decoded = decodeJwt(idToken);
|
|
204
|
-
|
|
205
|
-
// 5?? Persist ephemeral secret / salt / jwt / maxEpoch
|
|
206
|
-
zkloginStorage
|
|
207
|
-
.getState()
|
|
208
|
-
.setEphemeralSecretKey(
|
|
209
|
-
toBase64(
|
|
210
|
-
decodeSuiPrivateKey(ephemeralKeyPair.getSecretKey()).secretKey,
|
|
211
|
-
),
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
zkloginStorage.getState().setJWT(idToken);
|
|
215
|
-
zkloginStorage.getState().setMaxEpoch(maxEpoch);
|
|
216
|
-
|
|
217
|
-
const extendedEphemeralPublicKey = getExtendedEphemeralPublicKey(
|
|
218
|
-
ephemeralKeyPair.getPublicKey(),
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
const zkProofResponse = await createZkLoginProof({
|
|
222
|
-
jwt: idToken,
|
|
223
|
-
maxEpoch: String(maxEpoch),
|
|
224
|
-
extendedEphemeralPublicKey,
|
|
225
|
-
jwtRandomness: randomness,
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
if (!zkProofResponse?.result)
|
|
229
|
-
throw new Error(`Failed to get zkProof: ${zkProofResponse.error}`);
|
|
230
|
-
|
|
231
|
-
zkloginStorage
|
|
232
|
-
.getState()
|
|
233
|
-
.setZKProof(JSON.stringify(zkProofResponse.result.zkProof));
|
|
234
|
-
|
|
235
|
-
const suiAddress = zkProofResponse.result.suiAddress;
|
|
236
|
-
zkloginStorage.getState().setSuiAddress(suiAddress);
|
|
237
|
-
const account: WalletAccount = { jwt: decoded as any };
|
|
238
|
-
|
|
239
|
-
set({
|
|
240
|
-
jwt: idToken,
|
|
241
|
-
decodedJwt: decoded,
|
|
242
|
-
ephemeralKeyPair,
|
|
243
|
-
suiAddress,
|
|
244
|
-
zkProof: zkProofResponse.result.zkProof,
|
|
245
|
-
maxEpoch,
|
|
246
|
-
account,
|
|
247
|
-
isConnected: true,
|
|
248
|
-
isLoading: false,
|
|
249
|
-
error: null,
|
|
250
|
-
});
|
|
251
|
-
} catch (err: any) {
|
|
252
|
-
set({ error: err?.message ?? String(err), isLoading: false });
|
|
253
|
-
throw err;
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
|
-
|
|
257
|
-
async disconnect() {
|
|
258
|
-
try {
|
|
259
|
-
// reset zkloginStorage
|
|
260
|
-
zkloginStorage.getState().reset();
|
|
261
|
-
} catch {
|
|
262
|
-
// ignore storage errors
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
set({
|
|
266
|
-
jwt: null,
|
|
267
|
-
decodedJwt: null,
|
|
268
|
-
ephemeralKeyPair: null,
|
|
269
|
-
suiAddress: null,
|
|
270
|
-
zkProof: null,
|
|
271
|
-
maxEpoch: null,
|
|
272
|
-
account: null,
|
|
273
|
-
isConnected: false,
|
|
274
|
-
isLoading: false,
|
|
275
|
-
authProvider: null,
|
|
276
|
-
error: null,
|
|
277
|
-
});
|
|
278
|
-
},
|
|
279
|
-
|
|
280
|
-
getSigner() {
|
|
281
|
-
const {
|
|
282
|
-
jwt,
|
|
283
|
-
maxEpoch,
|
|
284
|
-
ephemeralKeyPair,
|
|
285
|
-
zkProof,
|
|
286
|
-
suiAddress,
|
|
287
|
-
decodedJwt,
|
|
288
|
-
} = get();
|
|
289
|
-
if (!jwt || !maxEpoch || !ephemeralKeyPair || !zkProof) return null;
|
|
290
|
-
return {
|
|
291
|
-
ephemeralKeyPair,
|
|
292
|
-
suiAddress,
|
|
293
|
-
decodedJwt,
|
|
294
|
-
zkProof,
|
|
295
|
-
maxEpoch,
|
|
296
|
-
} as ZKLoginSignerState;
|
|
297
|
-
},
|
|
298
|
-
|
|
299
|
-
async initFromStorage() {
|
|
300
|
-
try {
|
|
301
|
-
set({ isLoading: true });
|
|
302
|
-
const { epoch: currentEpoch } =
|
|
303
|
-
await suiClient.getLatestSuiSystemState();
|
|
304
|
-
|
|
305
|
-
const stored = {
|
|
306
|
-
jwt: zkloginStorage.getState().jwt,
|
|
307
|
-
maxEpoch: zkloginStorage.getState().maxEpoch,
|
|
308
|
-
ephemeralSecretKey: zkloginStorage.getState().ephemeralSecretKey,
|
|
309
|
-
zkProof: zkloginStorage.getState().zkProof,
|
|
310
|
-
suiAddress: zkloginStorage.getState().suiAddress,
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
if (
|
|
314
|
-
!stored.jwt ||
|
|
315
|
-
!stored.maxEpoch ||
|
|
316
|
-
!stored.ephemeralSecretKey ||
|
|
317
|
-
!stored.zkProof ||
|
|
318
|
-
!stored.suiAddress
|
|
319
|
-
) {
|
|
320
|
-
throw new Error("Missing required params");
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
if (Number(currentEpoch) >= Number(stored.maxEpoch))
|
|
324
|
-
throw new Error("Exceed maxEpoch");
|
|
325
|
-
|
|
326
|
-
const ephemeralKeyPair = Ed25519Keypair.fromSecretKey(
|
|
327
|
-
fromBase64(stored.ephemeralSecretKey),
|
|
328
|
-
);
|
|
329
|
-
const decoded = decodeJwt(stored.jwt);
|
|
330
|
-
const zkProofParsed = JSON.parse(stored.zkProof);
|
|
331
|
-
|
|
332
|
-
set({
|
|
333
|
-
jwt: stored.jwt,
|
|
334
|
-
decodedJwt: decoded,
|
|
335
|
-
ephemeralKeyPair,
|
|
336
|
-
suiAddress: stored.suiAddress,
|
|
337
|
-
zkProof: zkProofParsed,
|
|
338
|
-
maxEpoch: Number(stored.maxEpoch),
|
|
339
|
-
account: { jwt: decoded as any },
|
|
340
|
-
isConnected: true,
|
|
341
|
-
error: null,
|
|
342
|
-
});
|
|
343
|
-
} catch (err: any) {
|
|
344
|
-
set({ error: err?.message ?? String(err) });
|
|
345
|
-
}
|
|
346
|
-
set({ isLoading: false });
|
|
347
|
-
},
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
const store = createStore<WalletStore>()(baseCreator);
|
|
351
|
-
|
|
352
|
-
if (autoInit) {
|
|
353
|
-
store
|
|
354
|
-
.getState()
|
|
355
|
-
.initFromStorage()
|
|
356
|
-
.catch(() => {});
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
return store;
|
|
360
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { createStore } from "zustand";
|
|
2
|
-
import { persist, createJSONStorage } from "zustand/middleware";
|
|
3
|
-
import type { WalrusStakingState, WalrusSystemState } from "../config/types.js";
|
|
4
|
-
import type { SealClient } from "@mysten/seal";
|
|
5
|
-
import type { WalrusClient } from "@mysten/walrus";
|
|
6
|
-
import type { StateCreator, StoreApi } from "zustand";
|
|
7
|
-
import type { StateStorage } from "zustand/middleware";
|
|
8
|
-
|
|
9
|
-
export type WalrusStore = {
|
|
10
|
-
walrusClient: WalrusClient;
|
|
11
|
-
sealClient: SealClient;
|
|
12
|
-
walrusStakingState?: WalrusStakingState;
|
|
13
|
-
walrusSystemState?: WalrusSystemState;
|
|
14
|
-
isLoading: boolean;
|
|
15
|
-
error?: string | null;
|
|
16
|
-
|
|
17
|
-
// actions
|
|
18
|
-
init: () => Promise<void>;
|
|
19
|
-
refreshWalrusState: () => Promise<void>;
|
|
20
|
-
setError: (err?: string | null) => void;
|
|
21
|
-
setStakingState: (state?: WalrusStakingState) => void;
|
|
22
|
-
setSystemState: (state?: WalrusSystemState) => void;
|
|
23
|
-
|
|
24
|
-
// NEW SETTERS
|
|
25
|
-
setWalrusClient: (c: WalrusClient) => void;
|
|
26
|
-
setSealClient: (c: SealClient) => void;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type WalrusStoreConfig = {
|
|
30
|
-
walrusClient: WalrusClient;
|
|
31
|
-
sealClient: SealClient;
|
|
32
|
-
storage?: StateStorage;
|
|
33
|
-
storageKey?: string;
|
|
34
|
-
autoInit?: boolean;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export function createWalrusStore(
|
|
38
|
-
config: WalrusStoreConfig,
|
|
39
|
-
): StoreApi<WalrusStore> {
|
|
40
|
-
const {
|
|
41
|
-
walrusClient,
|
|
42
|
-
sealClient,
|
|
43
|
-
storage,
|
|
44
|
-
storageKey = "walrus-store",
|
|
45
|
-
autoInit = true,
|
|
46
|
-
} = config;
|
|
47
|
-
|
|
48
|
-
const baseStore: StateCreator<WalrusStore, [], [], WalrusStore> = (
|
|
49
|
-
set,
|
|
50
|
-
get,
|
|
51
|
-
) => ({
|
|
52
|
-
walrusClient,
|
|
53
|
-
sealClient,
|
|
54
|
-
walrusStakingState: undefined,
|
|
55
|
-
walrusSystemState: undefined,
|
|
56
|
-
isLoading: false,
|
|
57
|
-
error: null,
|
|
58
|
-
|
|
59
|
-
setWalrusClient(c) {
|
|
60
|
-
set(() => ({ walrusClient: c }));
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
setSealClient(c) {
|
|
64
|
-
set(() => ({ sealClient: c }));
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
setError(err) {
|
|
68
|
-
set(() => ({ error: err ?? null }));
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
setStakingState(state) {
|
|
72
|
-
set(() => ({ walrusStakingState: state }));
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
setSystemState(state) {
|
|
76
|
-
set(() => ({ walrusSystemState: state }));
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
async refreshWalrusState() {
|
|
80
|
-
const client = get().walrusClient;
|
|
81
|
-
if (!client) {
|
|
82
|
-
set(() => ({ error: "WalrusClient not initialized" }));
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
set(() => ({ isLoading: true, error: null }));
|
|
88
|
-
const walrusStakingState = await client.stakingState();
|
|
89
|
-
const walrusSystemState = await client.systemState();
|
|
90
|
-
set(() => ({ walrusStakingState, walrusSystemState }));
|
|
91
|
-
} catch (e: any) {
|
|
92
|
-
set(() => ({ error: e instanceof Error ? e.message : String(e) }));
|
|
93
|
-
} finally {
|
|
94
|
-
set(() => ({ isLoading: false }));
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
async init() {
|
|
99
|
-
await get().refreshWalrusState();
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
if (storage) {
|
|
104
|
-
return createStore<WalrusStore>()(
|
|
105
|
-
persist(baseStore, {
|
|
106
|
-
name: storageKey,
|
|
107
|
-
storage: createJSONStorage(() => storage),
|
|
108
|
-
partialize: () => ({}),
|
|
109
|
-
}),
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const store = createStore<WalrusStore>()(baseStore);
|
|
114
|
-
|
|
115
|
-
if (autoInit) store.getState().init();
|
|
116
|
-
|
|
117
|
-
return store;
|
|
118
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { create } from "zustand";
|
|
2
|
-
import { persist, createJSONStorage } from "zustand/middleware";
|
|
3
|
-
|
|
4
|
-
export interface ZKLoginStorage {
|
|
5
|
-
jwt: string | null;
|
|
6
|
-
suiAddress: string | null;
|
|
7
|
-
maxEpoch: number | null;
|
|
8
|
-
expiresAt: number | null;
|
|
9
|
-
ephemeralSecretKey: string | null;
|
|
10
|
-
zkProof: string | null;
|
|
11
|
-
|
|
12
|
-
setSuiAddress: (suiAddress: string) => void;
|
|
13
|
-
setMaxEpoch: (maxEpoch: number) => void;
|
|
14
|
-
setExpiresAt: (expiresAt: number) => void;
|
|
15
|
-
setJWT: (jwt: string) => void;
|
|
16
|
-
setEphemeralSecretKey: (key: string) => void;
|
|
17
|
-
setZKProof: (proof: string) => void;
|
|
18
|
-
reset: () => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const zkloginStorage = create<ZKLoginStorage>()(
|
|
22
|
-
persist(
|
|
23
|
-
(set) => ({
|
|
24
|
-
jwt: null,
|
|
25
|
-
suiAddress: null,
|
|
26
|
-
maxEpoch: null,
|
|
27
|
-
expiresAt: null,
|
|
28
|
-
ephemeralSecretKey: null,
|
|
29
|
-
zkProof: null,
|
|
30
|
-
|
|
31
|
-
setSuiAddress: (suiAddress: string) => set({ suiAddress }),
|
|
32
|
-
setMaxEpoch: (maxEpoch: number) => set({ maxEpoch }),
|
|
33
|
-
setExpiresAt: (expiresAt: number) => set({ expiresAt }),
|
|
34
|
-
setJWT: (jwt: string) => set({ jwt }),
|
|
35
|
-
setEphemeralSecretKey: (ephemeralSecretKey: string) =>
|
|
36
|
-
set({ ephemeralSecretKey }),
|
|
37
|
-
setZKProof: (zkProof: string) => set({ zkProof }),
|
|
38
|
-
reset: () =>
|
|
39
|
-
set({
|
|
40
|
-
jwt: null,
|
|
41
|
-
suiAddress: null,
|
|
42
|
-
maxEpoch: null,
|
|
43
|
-
expiresAt: null,
|
|
44
|
-
ephemeralSecretKey: null,
|
|
45
|
-
zkProof: null,
|
|
46
|
-
}),
|
|
47
|
-
}),
|
|
48
|
-
{
|
|
49
|
-
name: "zklogin-storage", // localStorage key
|
|
50
|
-
storage: createJSONStorage(() => localStorage),
|
|
51
|
-
},
|
|
52
|
-
),
|
|
53
|
-
);
|
package/src/types.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
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
|
-
|
|
6
|
-
export type SuiNetwork = "mainnet" | "testnet";
|
|
7
|
-
// Auth
|
|
8
|
-
export type PartialZkLoginSignature = Omit<
|
|
9
|
-
Parameters<typeof getZkLoginSignature>["0"]["inputs"],
|
|
10
|
-
"addressSeed"
|
|
11
|
-
>;
|
|
12
|
-
|
|
13
|
-
export interface ZKLoginSignerState {
|
|
14
|
-
ephemeralKeyPair: Ed25519Keypair | null;
|
|
15
|
-
suiAddress: string | null;
|
|
16
|
-
decodedJwt: ReturnType<typeof decodeJwt> | null;
|
|
17
|
-
zkProof: PartialZkLoginSignature | null;
|
|
18
|
-
maxEpoch: number | null;
|
|
19
|
-
}
|
|
20
|
-
// Sui
|
|
21
|
-
export interface SponsoredGasParams {
|
|
22
|
-
gaslessTransactionBytes: string;
|
|
23
|
-
senderAddress: string;
|
|
24
|
-
gasBudget?: string;
|
|
25
|
-
gasPrice?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface GenerateSaltRequest {
|
|
29
|
-
sub: string;
|
|
30
|
-
iss: string;
|
|
31
|
-
aud: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface GenerateSaltResponse {
|
|
35
|
-
salt: string;
|
|
36
|
-
saltInt: string;
|
|
37
|
-
deviceId: string | null;
|
|
38
|
-
timestamp: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type SponsoredGasResponse =
|
|
42
|
-
| {
|
|
43
|
-
jsonrpc: string;
|
|
44
|
-
result: {
|
|
45
|
-
txBytes: string;
|
|
46
|
-
txDigest: string;
|
|
47
|
-
signature: string;
|
|
48
|
-
expireAtTime: number;
|
|
49
|
-
};
|
|
50
|
-
id: number;
|
|
51
|
-
error?: never; // explicitly forbid error here
|
|
52
|
-
}
|
|
53
|
-
| {
|
|
54
|
-
jsonrpc: string;
|
|
55
|
-
error: {
|
|
56
|
-
code: number;
|
|
57
|
-
message: string;
|
|
58
|
-
data?: {
|
|
59
|
-
details?: string;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
id: number;
|
|
63
|
-
result?: never; // explicitly forbid result here
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export interface ReserveGasRequest {
|
|
67
|
-
gas_budget: number;
|
|
68
|
-
reserve_duration_secs: number;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface ReserveGasResponse {
|
|
72
|
-
result: ReserveGasResult | null;
|
|
73
|
-
error: string | null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface ReserveGasResult {
|
|
77
|
-
sponsor_address: string;
|
|
78
|
-
reservation_id: string;
|
|
79
|
-
gas_coins: SuiObjectRef[];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface ExecuteSponsoredTxRequest {
|
|
83
|
-
reservation_id: string;
|
|
84
|
-
tx_bytes: string;
|
|
85
|
-
user_sig: string;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface ExecuteSponsoredTxResponse {
|
|
89
|
-
effects: TransactionEffects | null;
|
|
90
|
-
error: string | null;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export type PlatformIdentifiers = Record<PlatformType, string>;
|
|
94
|
-
|
|
95
|
-
export interface ZkLoginProofParams {
|
|
96
|
-
jwt: string;
|
|
97
|
-
maxEpoch: string;
|
|
98
|
-
extendedEphemeralPublicKey: string;
|
|
99
|
-
jwtRandomness: string;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface ZkLoginProofResponse {
|
|
103
|
-
id: number;
|
|
104
|
-
result?: {
|
|
105
|
-
zkProof: PartialZkLoginSignature;
|
|
106
|
-
suiAddress: string; // Add this line
|
|
107
|
-
};
|
|
108
|
-
error?: {
|
|
109
|
-
code: number;
|
|
110
|
-
message: string;
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface TierPlan {
|
|
115
|
-
name: string;
|
|
116
|
-
price: number;
|
|
117
|
-
duration: number;
|
|
118
|
-
storage: number;
|
|
119
|
-
features: string[];
|
|
120
|
-
}
|
package/tsconfig.json
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|