@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
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { zkloginStorage } from "../stores/zkloginStore.js";
|
|
2
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
3
|
+
import { fromBase64 } from "@mysten/sui/utils";
|
|
4
|
+
import { decodeJwt } from "@mysten/sui/zklogin";
|
|
5
|
+
const SALT_SERVER_BASE_URL = "https://salt-server-production.up.railway.app";
|
|
6
|
+
export async function getSigner(suiClient) {
|
|
7
|
+
const zkLoginStorage = await zkloginStorage.getState();
|
|
8
|
+
const { epoch: currentEpoch } = await suiClient.getLatestSuiSystemState();
|
|
9
|
+
if (!zkLoginStorage?.jwt ||
|
|
10
|
+
!zkLoginStorage?.maxEpoch ||
|
|
11
|
+
!zkLoginStorage.ephemeralSecretKey ||
|
|
12
|
+
!zkLoginStorage.zkProof ||
|
|
13
|
+
!zkLoginStorage.suiAddress)
|
|
14
|
+
return {
|
|
15
|
+
ephemeralKeyPair: null,
|
|
16
|
+
suiAddress: null,
|
|
17
|
+
decodedJwt: null,
|
|
18
|
+
zkProof: null,
|
|
19
|
+
maxEpoch: null,
|
|
20
|
+
};
|
|
21
|
+
if (Number(currentEpoch) > zkLoginStorage.maxEpoch)
|
|
22
|
+
return {
|
|
23
|
+
ephemeralKeyPair: null,
|
|
24
|
+
suiAddress: null,
|
|
25
|
+
decodedJwt: null,
|
|
26
|
+
zkProof: null,
|
|
27
|
+
maxEpoch: null,
|
|
28
|
+
};
|
|
29
|
+
const ephemeralKeyPair = Ed25519Keypair.fromSecretKey(fromBase64(zkLoginStorage.ephemeralSecretKey));
|
|
30
|
+
return {
|
|
31
|
+
suiAddress: zkLoginStorage.suiAddress,
|
|
32
|
+
ephemeralKeyPair,
|
|
33
|
+
decodedJwt: decodeJwt(zkLoginStorage.jwt),
|
|
34
|
+
zkProof: JSON.parse(zkLoginStorage.zkProof),
|
|
35
|
+
maxEpoch: zkLoginStorage.maxEpoch,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export async function signAndExecuteGasPoolTransaction(signer, suiClient, tx, gasBudget = 0.1 * 10 ** 9, reserveDurationSecs = 30) {
|
|
39
|
+
const { ephemeralKeyPair, suiAddress, decodedJwt, zkProof, maxEpoch } = signer;
|
|
40
|
+
if (!ephemeralKeyPair || !suiAddress || !decodedJwt || !zkProof || !maxEpoch)
|
|
41
|
+
return;
|
|
42
|
+
try {
|
|
43
|
+
if (!decodedJwt.sub || !decodedJwt.iss || !decodedJwt.aud) {
|
|
44
|
+
throw new Error("JWT claims (sub, iss, aud) not found");
|
|
45
|
+
}
|
|
46
|
+
// Step 1: Request gas reservation from server
|
|
47
|
+
const prepareResponse = await fetch(`${SALT_SERVER_BASE_URL}/prepare_tx`, {
|
|
48
|
+
method: "POST",
|
|
49
|
+
headers: {
|
|
50
|
+
"Content-Type": "application/json",
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify({
|
|
53
|
+
sub: decodedJwt.sub,
|
|
54
|
+
iss: decodedJwt.iss,
|
|
55
|
+
aud: Array.isArray(decodedJwt.aud) ? decodedJwt.aud[0] : decodedJwt.aud,
|
|
56
|
+
gasBudget,
|
|
57
|
+
reserveDurationSecs,
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
60
|
+
if (!prepareResponse.ok) {
|
|
61
|
+
const errorData = await prepareResponse.json().catch(() => ({}));
|
|
62
|
+
throw new Error(errorData.error || `Server error: ${prepareResponse.statusText}`);
|
|
63
|
+
}
|
|
64
|
+
const prepareData = await prepareResponse.json();
|
|
65
|
+
if (!prepareData.result) {
|
|
66
|
+
throw new Error(`Failed to reserve gas: ${prepareData.error}`);
|
|
67
|
+
}
|
|
68
|
+
// Step 2: Set gas payment and sender
|
|
69
|
+
tx.setSender(suiAddress);
|
|
70
|
+
tx.setGasOwner(prepareData.result.sponsor_address);
|
|
71
|
+
tx.setGasPayment(prepareData.result.gas_coins);
|
|
72
|
+
// Step 4: Sign only the transaction bytes with ephemeral key
|
|
73
|
+
const { bytes, signature: ephemeralSignature } = await tx.sign({
|
|
74
|
+
client: suiClient,
|
|
75
|
+
signer: ephemeralKeyPair,
|
|
76
|
+
});
|
|
77
|
+
// Step 5: Send to server for zkLogin signature generation and execution
|
|
78
|
+
const executeResponse = await fetch(`${SALT_SERVER_BASE_URL}/execute_tx`, {
|
|
79
|
+
method: "POST",
|
|
80
|
+
headers: {
|
|
81
|
+
"Content-Type": "application/json",
|
|
82
|
+
},
|
|
83
|
+
body: JSON.stringify({
|
|
84
|
+
sub: decodedJwt.sub,
|
|
85
|
+
iss: decodedJwt.iss,
|
|
86
|
+
aud: Array.isArray(decodedJwt.aud) ? decodedJwt.aud[0] : decodedJwt.aud,
|
|
87
|
+
reservationId: prepareData.result.reservation_id,
|
|
88
|
+
txBytes: bytes,
|
|
89
|
+
ephemeralSignature,
|
|
90
|
+
maxEpoch,
|
|
91
|
+
zkProof,
|
|
92
|
+
}),
|
|
93
|
+
});
|
|
94
|
+
const executeData = await executeResponse.json().catch(() => ({}));
|
|
95
|
+
if (!executeResponse.ok) {
|
|
96
|
+
throw new Error(executeData.error || `Server error: ${executeResponse.statusText}`);
|
|
97
|
+
}
|
|
98
|
+
if (!executeData.effects) {
|
|
99
|
+
throw new Error(`Transaction execution failed: ${executeData.error || "Unknown error"}`);
|
|
100
|
+
}
|
|
101
|
+
return executeData.effects;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.error(error);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export async function signPersonalMessage(signer, message) {
|
|
109
|
+
const { ephemeralKeyPair, decodedJwt, zkProof, maxEpoch } = signer;
|
|
110
|
+
if (!ephemeralKeyPair || !decodedJwt || !zkProof || !maxEpoch) {
|
|
111
|
+
throw new Error("Missing required params");
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
if (!decodedJwt.sub || !decodedJwt.iss || !decodedJwt.aud) {
|
|
115
|
+
throw new Error("JWT claims (sub, iss, aud) not found");
|
|
116
|
+
}
|
|
117
|
+
// Sign message with ephemeral key
|
|
118
|
+
const { bytes, signature } = await ephemeralKeyPair.signPersonalMessage(message);
|
|
119
|
+
// Convert bytes to base64 for transmission
|
|
120
|
+
const response = await fetch(`${SALT_SERVER_BASE_URL}/sign_personal_message`, {
|
|
121
|
+
method: "POST",
|
|
122
|
+
headers: {
|
|
123
|
+
"Content-Type": "application/json",
|
|
124
|
+
},
|
|
125
|
+
body: JSON.stringify({
|
|
126
|
+
sub: decodedJwt.sub,
|
|
127
|
+
iss: decodedJwt.iss,
|
|
128
|
+
aud: Array.isArray(decodedJwt.aud)
|
|
129
|
+
? decodedJwt.aud[0]
|
|
130
|
+
: decodedJwt.aud,
|
|
131
|
+
messageBytes: bytes,
|
|
132
|
+
ephemeralSignature: signature,
|
|
133
|
+
maxEpoch,
|
|
134
|
+
zkProof,
|
|
135
|
+
}),
|
|
136
|
+
});
|
|
137
|
+
if (!response.ok) {
|
|
138
|
+
const errorData = await response.json().catch(() => ({}));
|
|
139
|
+
throw new Error(errorData.error || `Server error: ${response.statusText}`);
|
|
140
|
+
}
|
|
141
|
+
const data = await response.json();
|
|
142
|
+
if (!data.zkLoginSignature) {
|
|
143
|
+
throw new Error("Failed to generate zkLogin signature");
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
zkLoginSignature: data.zkLoginSignature,
|
|
147
|
+
bytes: fromBase64(data.bytes),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
console.error(error);
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export async function createZkLoginProof(params) {
|
|
156
|
+
try {
|
|
157
|
+
const response = await fetch(`${SALT_SERVER_BASE_URL}/zklogin-proof`, {
|
|
158
|
+
method: "POST",
|
|
159
|
+
headers: {
|
|
160
|
+
"Content-Type": "application/json",
|
|
161
|
+
},
|
|
162
|
+
body: JSON.stringify(params),
|
|
163
|
+
});
|
|
164
|
+
if (!response.ok) {
|
|
165
|
+
const errorData = await response.json().catch(() => ({}));
|
|
166
|
+
throw new Error(errorData.error || `HTTP ${response.status}`);
|
|
167
|
+
}
|
|
168
|
+
return await response.json();
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (error instanceof Error) {
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
throw new Error("Unknown error occurred");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
2
|
+
import type { PublishArticleEvent } from "../_generated/zing_studio/article.js";
|
|
3
|
+
import type { WalrusUploadFlowStage } from "../config/common.js";
|
|
4
|
+
import type { SharedObjectRef, WalrusSystemState } from "../config/types.js";
|
|
5
|
+
import type { ZKLoginSignerState } from "../types.js";
|
|
6
|
+
import type { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
7
|
+
import type { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
8
|
+
import type { CertifyBlobOptions, WalrusClient, WalrusFile, WriteFilesFlowOptions, WriteFilesFlowRegisterOptions, WriteFilesFlowUploadOptions } from "@mysten/walrus";
|
|
9
|
+
type ZingWriteFlowConfig = {
|
|
10
|
+
zingStudioPackageId: string;
|
|
11
|
+
zingStudioV0PackageId: string;
|
|
12
|
+
walrusPackageId: string;
|
|
13
|
+
zingStudioConfigSharedObjectRef: SharedObjectRef;
|
|
14
|
+
walrusSystemSharedObjectRef: SharedObjectRef;
|
|
15
|
+
zingStorageTreasurySharedObjectRef: SharedObjectRef;
|
|
16
|
+
blobRegisteredEventType: string;
|
|
17
|
+
publishArticleEventType: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function buildPublishArticleTransaction(config: ZingWriteFlowConfig, walrusSystem: WalrusSystemState, walTreasury: string, storageByEpoch: Record<number, number>, fileSize: number, owner: string, subscriptionLevel: null | number, blobId: string, rootHash: Uint8Array, articleMetadata: {
|
|
20
|
+
identifier: string;
|
|
21
|
+
tags: {
|
|
22
|
+
"content-type": string;
|
|
23
|
+
};
|
|
24
|
+
size: number;
|
|
25
|
+
}[], attributes: Record<string, string | null>, existingAttributes: Record<string, string> | null): (tx: Transaction) => void;
|
|
26
|
+
export declare function buildCertifyArticleBlobTransaction(config: {
|
|
27
|
+
zingStudioPackageId: string;
|
|
28
|
+
zingStudioConfigSharedObjectRef: SharedObjectRef;
|
|
29
|
+
walrusSystemSharedObjectRef: SharedObjectRef;
|
|
30
|
+
}, walrusClient: WalrusClient, owner: string, articleId: string, { blobId, blobObjectId, confirmations, certificate, deletable, }: CertifyBlobOptions): (tx: Transaction) => Promise<void>;
|
|
31
|
+
export declare const zingWriteFlow: (config: ZingWriteFlowConfig, suiGrpcClient: SuiGrpcClient, suiJsonRpcClient: SuiJsonRpcClient, walrusClient: WalrusClient, walrusSystem: WalrusSystemState, walTreasury: string, storageByEpoch: Record<number, number>, fileKey: CryptoKey, studioObjectId: string, owner: string, subscriptionLevel: null | number, articleMetadata: {
|
|
32
|
+
identifier: string;
|
|
33
|
+
tags: {
|
|
34
|
+
"content-type": string;
|
|
35
|
+
};
|
|
36
|
+
size: number;
|
|
37
|
+
}[], options: WriteFilesFlowOptions, withUploadRelayClient: boolean, blobRegisteredEventType: string, publishArticleEventType: string) => {
|
|
38
|
+
encode: () => Promise<void>;
|
|
39
|
+
register: (options: WriteFilesFlowRegisterOptions) => Transaction;
|
|
40
|
+
upload: (options: WriteFilesFlowUploadOptions) => Promise<{
|
|
41
|
+
article_id: string;
|
|
42
|
+
owner: string;
|
|
43
|
+
blob_ids: string[];
|
|
44
|
+
blob_sizes: string[];
|
|
45
|
+
blob_storage_sizes: string[];
|
|
46
|
+
blob_end_epochs: number[];
|
|
47
|
+
files: {
|
|
48
|
+
contents: {
|
|
49
|
+
key: string;
|
|
50
|
+
value: {
|
|
51
|
+
blob_index: string;
|
|
52
|
+
mime_type: string;
|
|
53
|
+
size: string;
|
|
54
|
+
};
|
|
55
|
+
}[];
|
|
56
|
+
};
|
|
57
|
+
timestamp_ms: string;
|
|
58
|
+
}>;
|
|
59
|
+
certify: () => Transaction;
|
|
60
|
+
listFiles: () => Promise<{
|
|
61
|
+
id: string;
|
|
62
|
+
blobId: string;
|
|
63
|
+
blobObjectId: string;
|
|
64
|
+
}[]>;
|
|
65
|
+
};
|
|
66
|
+
export declare function uploadFileToWalrus(zingWriteFlowConfig: ZingWriteFlowConfig, suiGrpcClient: SuiGrpcClient, suiJsonRpcClient: SuiJsonRpcClient, walrusClient: WalrusClient, walrusSystem: WalrusSystemState, walTreasury: string, storageByEpoch: Record<number, number>, fileKey: CryptoKey, walrusFiles: WalrusFile[], subscriptionLevel: null | number, metadata: {
|
|
67
|
+
identifier: string;
|
|
68
|
+
tags: {
|
|
69
|
+
"content-type": string;
|
|
70
|
+
};
|
|
71
|
+
size: number;
|
|
72
|
+
}[], signer: ZKLoginSignerState, gasPoolBearerToken: string, onProgress?: (stage: WalrusUploadFlowStage) => void): Promise<typeof PublishArticleEvent.$inferType>;
|
|
73
|
+
export declare function downloadImagesFromMarkdown<T extends "blob" | "uint8array">(markdown: string, as?: T): Promise<{
|
|
74
|
+
url: string;
|
|
75
|
+
data: T extends "blob" ? Blob : Uint8Array;
|
|
76
|
+
}[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Calculate the cost of storing a blob for a given a size and number of epochs.
|
|
79
|
+
*/
|
|
80
|
+
export declare function storageCost(systemState: WalrusSystemState, size: number, epochs: number): {
|
|
81
|
+
encodedSize: number;
|
|
82
|
+
storageCost: bigint;
|
|
83
|
+
writeCost: bigint;
|
|
84
|
+
totalCost: bigint;
|
|
85
|
+
};
|
|
86
|
+
export declare function storageUnitsFromSize(size: number): number;
|
|
87
|
+
/**
|
|
88
|
+
* Replace all base64 image URLs in markdown with asset identifiers (e.g. assets-0.png).
|
|
89
|
+
*
|
|
90
|
+
* @param markdown - the original markdown string containing data URLs
|
|
91
|
+
* @param assets - the array returned from downloadImagesFromMarkdown()
|
|
92
|
+
* @returns a new markdown string with data URLs replaced by identifiers
|
|
93
|
+
*/
|
|
94
|
+
export declare function replaceBase64ImagesWithIdentifiers(markdown: string, assets: {
|
|
95
|
+
url: string;
|
|
96
|
+
data: Blob | Uint8Array;
|
|
97
|
+
}[]): string;
|
|
98
|
+
export {};
|