@zing-protocol/zing-sdk 0.0.12 → 0.0.14

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.
@@ -364,3 +364,18 @@ export interface BurnOrKeepPositiveCoinOptions {
364
364
  typeArguments: [string];
365
365
  }
366
366
  export declare function burnOrKeepPositiveCoin(options: BurnOrKeepPositiveCoinOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
367
+ export interface PayoutArguments {
368
+ treasury: RawTransactionArgument<string>;
369
+ coin: RawTransactionArgument<string>;
370
+ recipient: RawTransactionArgument<string>;
371
+ }
372
+ export interface PayoutOptions {
373
+ package?: string;
374
+ arguments: PayoutArguments | [
375
+ treasury: RawTransactionArgument<string>,
376
+ coin: RawTransactionArgument<string>,
377
+ recipient: RawTransactionArgument<string>
378
+ ];
379
+ typeArguments: [string];
380
+ }
381
+ export declare function payout(options: PayoutOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
@@ -472,3 +472,19 @@ export function burnOrKeepPositiveCoin(options) {
472
472
  typeArguments: options.typeArguments,
473
473
  });
474
474
  }
475
+ export function payout(options) {
476
+ const packageAddress = options.package ?? "@local-pkg/zing_studio";
477
+ const argumentsTypes = [
478
+ `${packageAddress}::treasury::Treasury`,
479
+ `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${options.typeArguments[0]}>`,
480
+ "address",
481
+ ];
482
+ const parameterNames = ["treasury", "coin", "recipient"];
483
+ return (tx) => tx.moveCall({
484
+ package: packageAddress,
485
+ module: "app",
486
+ function: "payout",
487
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
488
+ typeArguments: options.typeArguments,
489
+ });
490
+ }
@@ -267,7 +267,7 @@ export declare class ZingClient {
267
267
  };
268
268
  }[]>;
269
269
  getBalance(owner: string, coinSymbol: CoinSymbol): Promise<import("node_modules/@mysten/sui/dist/esm/grpc/proto/sui/rpc/v2/state_service.js").GetBalanceResponse>;
270
- getSessionKey(signer: ZKLoginSignerState, owner: string): Promise<SessionKey>;
270
+ getSessionKey(saltServerUrl: string, signer: ZKLoginSignerState, owner: string): Promise<SessionKey>;
271
271
  buildSealApproveTransactionBytes(owner: string): Promise<Uint8Array<ArrayBuffer>>;
272
272
  getFileKey(sealClient: SealClient, sessionKey: SessionKey, owner: string, encryptedFileKeyBytes: number[]): Promise<CryptoKey>;
273
273
  subscribeToStudioTransaction({ sender, creatorAddress, subscriptionAmount, level, }: SubscribeParams): (tx: Transaction) => void;
@@ -98,7 +98,7 @@ export class ZingClient {
98
98
  })
99
99
  .then((res) => res.response);
100
100
  }
101
- async getSessionKey(signer, owner) {
101
+ async getSessionKey(saltServerUrl, signer, owner) {
102
102
  const { suiAddress, ephemeralKeyPair, decodedJwt, zkProof, maxEpoch } = signer;
103
103
  if (!suiAddress ||
104
104
  !ephemeralKeyPair ||
@@ -114,7 +114,7 @@ export class ZingClient {
114
114
  suiClient: this.suiJsonRpcClient,
115
115
  });
116
116
  const message = sessionKey.getPersonalMessage();
117
- const { zkLoginSignature } = await signPersonalMessage(signer, message);
117
+ const { zkLoginSignature } = await signPersonalMessage(saltServerUrl, signer, message);
118
118
  sessionKey.setPersonalMessageSignature(zkLoginSignature);
119
119
  return sessionKey;
120
120
  }
@@ -1,6 +1,6 @@
1
1
  import type { WalletStore, WalletStoreConfig } from "../stores/walletStore.js";
2
2
  import type { PropsWithChildren } from "react";
3
- export declare function WalletProvider({ suiClient, oAuthClientId, network, autoInit, children, }: PropsWithChildren<WalletStoreConfig & {
3
+ export declare function WalletProvider({ suiClient, oAuthClientId, network, saltServerUrl, autoInit, children, }: PropsWithChildren<WalletStoreConfig & {
4
4
  network?: string;
5
5
  autoInit?: boolean;
6
6
  }>): import("react/jsx-runtime").JSX.Element;
@@ -4,13 +4,14 @@ import { createWalletStore } from "../stores/walletStore.js";
4
4
  import { createContext, useContext, useRef, useEffect } from "react";
5
5
  import { useStore } from "zustand";
6
6
  const WalletContext = createContext(null);
7
- export function WalletProvider({ suiClient, oAuthClientId, network, autoInit = true, children, }) {
7
+ export function WalletProvider({ suiClient, oAuthClientId, network, saltServerUrl, autoInit = true, children, }) {
8
8
  const storeRef = useRef(null);
9
9
  if (!storeRef.current) {
10
10
  storeRef.current = createWalletStore({
11
11
  suiClient,
12
12
  oAuthClientId,
13
13
  network,
14
+ saltServerUrl,
14
15
  autoInit,
15
16
  });
16
17
  }
@@ -22,7 +22,7 @@ export declare function useWalrusUpload(): (zingClient: ZingClient, fileKey: Cry
22
22
  "content-type": string;
23
23
  };
24
24
  size: number;
25
- }[], signer: ZKLoginSignerState, onProgress?: (stage: WalrusUploadFlowStage) => void) => Promise<typeof PublishArticleEvent.$inferType>;
25
+ }[], saltServerUrl: string, signer: ZKLoginSignerState, onProgress?: (stage: WalrusUploadFlowStage) => void) => Promise<typeof PublishArticleEvent.$inferType>;
26
26
  export declare function useWalrusQuiltSize(): (walrusSystem: WalrusSystemState, files: Array<{
27
27
  size: number;
28
28
  identifier: string;
@@ -27,7 +27,7 @@ export const WalrusProvider = ({ walrusClient, sealClient, children, autoInit =
27
27
  }
28
28
  // eslint-disable-next-line react-hooks/exhaustive-deps
29
29
  }, [store]);
30
- const uploadFile = useCallback(async (zingClient, fileKey, walrusSystem, walTreasury, storageByEpoch, walrusFiles, subscriptionLevel, metadata, signer, onProgress) => {
30
+ const uploadFile = useCallback(async (zingClient, fileKey, walrusSystem, walTreasury, storageByEpoch, walrusFiles, subscriptionLevel, metadata, saltServerUrl, signer, onProgress) => {
31
31
  const config = zingClient.config;
32
32
  return uploadFileToWalrus({
33
33
  zingStudioPackageId: config.zing.ZING_STUDIO_PACKAGE_ADDRESS,
@@ -38,7 +38,7 @@ export const WalrusProvider = ({ walrusClient, sealClient, children, autoInit =
38
38
  zingStorageTreasurySharedObjectRef: config.zing.ZING_STORAGE_TREASURY_SHARED_OBJECT_REF,
39
39
  blobRegisteredEventType: config.walrus.EVENT_TYPES.blobRegistered,
40
40
  publishArticleEventType: config.zing.EVENT_TYPES.publishArticleEvent,
41
- }, zingClient.suiGrpcClient, zingClient.suiJsonRpcClient, walrusClient, walrusSystem, walTreasury, storageByEpoch, fileKey, walrusFiles, subscriptionLevel, metadata, signer, onProgress);
41
+ }, zingClient.suiGrpcClient, zingClient.suiJsonRpcClient, walrusClient, walrusSystem, walTreasury, storageByEpoch, fileKey, walrusFiles, subscriptionLevel, metadata, saltServerUrl, signer, onProgress);
42
42
  }, [walrusClient]);
43
43
  const calculateQuiltSize = useCallback((walrusSystem, files, ivSize = 12) => {
44
44
  const numShards = walrusSystem.committee.n_shards;
package/dist/getters.d.ts CHANGED
@@ -261,6 +261,7 @@ export declare function getPublishedArticleAndBlobId(suiGrpcClient: SuiGrpcClien
261
261
  parsedPublishArticleEvent: {
262
262
  article_id: string;
263
263
  owner: string;
264
+ subscription_level: number | null;
264
265
  blob_ids: string[];
265
266
  blob_sizes: string[];
266
267
  blob_storage_sizes: string[];
package/dist/getters.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { TypeName } from "./_generated/zing_identity/deps/std/type_name.js";
2
2
  import { IdentifierInfo } from "./_generated/zing_identity/identity.js";
3
- import { Article, PublishArticleEvent, } from "./_generated/zing_studio/article.js";
3
+ import { Article, PublishArticleEventV1, } from "./_generated/zing_studio/article.js";
4
4
  import { Field } from "./_generated/zing_studio/deps/sui/dynamic_field.js";
5
5
  import { VecMap } from "./_generated/zing_studio/deps/sui/vec_map.js";
6
6
  import { BlobRegistered } from "./_generated/zing_studio/deps/walrus/events.js";
@@ -280,7 +280,7 @@ export async function getPublishedArticleAndBlobId(suiGrpcClient, suiClient, wal
280
280
  throw new Error("fail to get publishArticleEvent");
281
281
  }
282
282
  const blobObjectId = BlobRegistered.parse(blobRegisteredEvent.contents?.value).object_id;
283
- const parsedPublishArticleEvent = PublishArticleEvent.parse(publishArticleEvent.contents.value);
283
+ const parsedPublishArticleEvent = PublishArticleEventV1.parse(publishArticleEvent.contents.value);
284
284
  return { parsedPublishArticleEvent, blobObjectId };
285
285
  }
286
286
  export function encodeQuiltPatchId(id) {
@@ -5,6 +5,7 @@ const GAS_POOL_OWNER = "0x3198c7da350bf15c48fc598e5b03a0b6e13356801c71b4d1a18b92
5
5
  export const useSignAndExecuteTransaction = () => {
6
6
  const getSigner = useWalletStore((s) => s.getSigner);
7
7
  const suiClient = useWalletStore((s) => s.suiClient);
8
+ const saltServerUrl = useWalletStore((s) => s.saltServerUrl);
8
9
  return useMutation({
9
10
  mutationFn: async ({ transaction }) => {
10
11
  const signer = getSigner();
@@ -22,7 +23,7 @@ export const useSignAndExecuteTransaction = () => {
22
23
  });
23
24
  console.log({ dryRunResponse });
24
25
  if (dryRunResponse.effects.status.status === "success") {
25
- const effects = await signAndExecuteGasPoolTransaction(signer, suiClient, transaction);
26
+ const effects = await signAndExecuteGasPoolTransaction(saltServerUrl, signer, suiClient, transaction);
26
27
  // TODO: handle error message by code
27
28
  if (!effects)
28
29
  throw new Error("fail to get Transaction Effects");
@@ -3,6 +3,7 @@ import { signPersonalMessage } from "../mutations/signer.js";
3
3
  import { useMutation } from "@tanstack/react-query";
4
4
  export const useSignPersonalMessage = () => {
5
5
  const getSigner = useWalletStore((s) => s.getSigner);
6
+ const saltServerUrl = useWalletStore((s) => s.saltServerUrl);
6
7
  return useMutation({
7
8
  mutationFn: async ({ message }) => {
8
9
  const signer = getSigner();
@@ -12,7 +13,7 @@ export const useSignPersonalMessage = () => {
12
13
  if (!signer.suiAddress) {
13
14
  throw new Error("Signer suiAddress not properly initialized");
14
15
  }
15
- return await signPersonalMessage(signer, message);
16
+ return await signPersonalMessage(saltServerUrl, signer, message);
16
17
  },
17
18
  onError: (error) => {
18
19
  console.error("Sign Personal Message failed:", error);
@@ -2,9 +2,9 @@ import type { ZkLoginProofParams, ZkLoginProofResponse, ZKLoginSignerState } fro
2
2
  import type { SuiClient } from "@mysten/sui/client";
3
3
  import type { Transaction } from "@mysten/sui/transactions";
4
4
  export declare function getSigner(suiClient: SuiClient): Promise<ZKLoginSignerState>;
5
- export declare function signAndExecuteGasPoolTransaction(signer: ZKLoginSignerState, suiClient: SuiClient, tx: Transaction, gasBudget?: number, reserveDurationSecs?: number): Promise<any>;
6
- export declare function signPersonalMessage(signer: ZKLoginSignerState, message: Uint8Array): Promise<{
5
+ export declare function signAndExecuteGasPoolTransaction(saltServerUrl: string, signer: ZKLoginSignerState, suiClient: SuiClient, tx: Transaction, gasBudget?: number, reserveDurationSecs?: number): Promise<any>;
6
+ export declare function signPersonalMessage(saltServerUrl: string, signer: ZKLoginSignerState, message: Uint8Array): Promise<{
7
7
  zkLoginSignature: any;
8
8
  bytes: Uint8Array<ArrayBuffer>;
9
9
  }>;
10
- export declare function createZkLoginProof(params: ZkLoginProofParams): Promise<ZkLoginProofResponse>;
10
+ export declare function createZkLoginProof(saltServerUrl: string, params: ZkLoginProofParams): Promise<ZkLoginProofResponse>;
@@ -2,8 +2,6 @@ import { zkloginStorage } from "../stores/zkloginStore.js";
2
2
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
3
3
  import { fromBase64 } from "@mysten/sui/utils";
4
4
  import { decodeJwt } from "@mysten/sui/zklogin";
5
- const SALT_SERVER_BASE_URL = "https://salt-server-production.up.railway.app";
6
- // "http://localhost:3001";
7
5
  export async function getSigner(suiClient) {
8
6
  const zkLoginStorage = await zkloginStorage.getState();
9
7
  const { epoch: currentEpoch } = await suiClient.getLatestSuiSystemState();
@@ -39,7 +37,7 @@ export async function getSigner(suiClient) {
39
37
  maxEpoch: zkLoginStorage.maxEpoch,
40
38
  };
41
39
  }
42
- export async function signAndExecuteGasPoolTransaction(signer, suiClient, tx, gasBudget = 0.1 * 10 ** 9, reserveDurationSecs = 30) {
40
+ export async function signAndExecuteGasPoolTransaction(saltServerUrl, signer, suiClient, tx, gasBudget = 0.1 * 10 ** 9, reserveDurationSecs = 30) {
43
41
  const { ephemeralKeyPair, suiAddress, decodedJwt, zkProof, maxEpoch, jwtTokenString, } = signer;
44
42
  if (!ephemeralKeyPair || !suiAddress || !decodedJwt || !zkProof || !maxEpoch)
45
43
  return;
@@ -48,7 +46,7 @@ export async function signAndExecuteGasPoolTransaction(signer, suiClient, tx, ga
48
46
  throw new Error("JWT claims (sub, iss, aud) not found");
49
47
  }
50
48
  // Step 1: Request gas reservation from server
51
- const prepareResponse = await fetch(`${SALT_SERVER_BASE_URL}/prepare_tx`, {
49
+ const prepareResponse = await fetch(`${saltServerUrl}/prepare_tx`, {
52
50
  method: "POST",
53
51
  headers: {
54
52
  Authorization: `Bearer ${jwtTokenString}`,
@@ -77,7 +75,7 @@ export async function signAndExecuteGasPoolTransaction(signer, suiClient, tx, ga
77
75
  signer: ephemeralKeyPair,
78
76
  });
79
77
  // Step 5: Send to server for zkLogin signature generation and execution
80
- const executeResponse = await fetch(`${SALT_SERVER_BASE_URL}/execute_tx`, {
78
+ const executeResponse = await fetch(`${saltServerUrl}/execute_tx`, {
81
79
  method: "POST",
82
80
  headers: {
83
81
  Authorization: `Bearer ${jwtTokenString}`,
@@ -105,7 +103,7 @@ export async function signAndExecuteGasPoolTransaction(signer, suiClient, tx, ga
105
103
  throw error;
106
104
  }
107
105
  }
108
- export async function signPersonalMessage(signer, message) {
106
+ export async function signPersonalMessage(saltServerUrl, signer, message) {
109
107
  const { ephemeralKeyPair, decodedJwt, zkProof, maxEpoch, jwtTokenString } = signer;
110
108
  if (!ephemeralKeyPair || !decodedJwt || !zkProof || !maxEpoch) {
111
109
  throw new Error("Missing required params");
@@ -117,7 +115,7 @@ export async function signPersonalMessage(signer, message) {
117
115
  // Sign message with ephemeral key
118
116
  const { bytes, signature } = await ephemeralKeyPair.signPersonalMessage(message);
119
117
  // Convert bytes to base64 for transmission
120
- const response = await fetch(`${SALT_SERVER_BASE_URL}/sign_personal_message`, {
118
+ const response = await fetch(`${saltServerUrl}/sign_personal_message`, {
121
119
  method: "POST",
122
120
  headers: {
123
121
  Authorization: `Bearer ${jwtTokenString}`,
@@ -148,9 +146,9 @@ export async function signPersonalMessage(signer, message) {
148
146
  throw error;
149
147
  }
150
148
  }
151
- export async function createZkLoginProof(params) {
149
+ export async function createZkLoginProof(saltServerUrl, params) {
152
150
  try {
153
- const response = await fetch(`${SALT_SERVER_BASE_URL}/zklogin-proof`, {
151
+ const response = await fetch(`${saltServerUrl}/zklogin-proof`, {
154
152
  method: "POST",
155
153
  headers: {
156
154
  Authorization: `Bearer ${params.jwtTokenString}`,
@@ -40,6 +40,7 @@ export declare const zingWriteFlow: (config: ZingWriteFlowConfig, suiGrpcClient:
40
40
  upload: (options: WriteFilesFlowUploadOptions) => Promise<{
41
41
  article_id: string;
42
42
  owner: string;
43
+ subscription_level: number | null;
43
44
  blob_ids: string[];
44
45
  blob_sizes: string[];
45
46
  blob_storage_sizes: string[];
@@ -69,7 +70,7 @@ export declare function uploadFileToWalrus(zingWriteFlowConfig: ZingWriteFlowCon
69
70
  "content-type": string;
70
71
  };
71
72
  size: number;
72
- }[], signer: ZKLoginSignerState, onProgress?: (stage: WalrusUploadFlowStage) => void): Promise<typeof PublishArticleEvent.$inferType>;
73
+ }[], saltServerUrl: string, signer: ZKLoginSignerState, onProgress?: (stage: WalrusUploadFlowStage) => void): Promise<typeof PublishArticleEvent.$inferType>;
73
74
  export declare function downloadImagesFromMarkdown<T extends "blob" | "uint8array">(markdown: string, as?: T): Promise<{
74
75
  url: string;
75
76
  data: T extends "blob" ? Blob : Uint8Array;
@@ -295,7 +295,7 @@ export const zingWriteFlow = (config, suiGrpcClient, suiJsonRpcClient, walrusCli
295
295
  listFiles: async () => listFiles(getResults("certify", "listFiles")),
296
296
  };
297
297
  };
298
- export async function uploadFileToWalrus(zingWriteFlowConfig, suiGrpcClient, suiJsonRpcClient, walrusClient, walrusSystem, walTreasury, storageByEpoch, fileKey, walrusFiles, subscriptionLevel, metadata, signer, onProgress) {
298
+ export async function uploadFileToWalrus(zingWriteFlowConfig, suiGrpcClient, suiJsonRpcClient, walrusClient, walrusSystem, walTreasury, storageByEpoch, fileKey, walrusFiles, subscriptionLevel, metadata, saltServerUrl, signer, onProgress) {
299
299
  const report = (stage) => {
300
300
  if (onProgress)
301
301
  onProgress(stage);
@@ -319,7 +319,7 @@ export async function uploadFileToWalrus(zingWriteFlowConfig, suiGrpcClient, sui
319
319
  owner,
320
320
  deletable: true,
321
321
  });
322
- const registerTxEffects = await signAndExecuteGasPoolTransaction(signer, suiJsonRpcClient, registerTx);
322
+ const registerTxEffects = await signAndExecuteGasPoolTransaction(saltServerUrl, signer, suiJsonRpcClient, registerTx);
323
323
  if (!registerTxEffects?.transactionDigest)
324
324
  throw new Error("fail to execute register Blob transaction");
325
325
  const finalizedTransaction = await suiJsonRpcClient.waitForTransaction({
@@ -337,7 +337,7 @@ export async function uploadFileToWalrus(zingWriteFlowConfig, suiGrpcClient, sui
337
337
  async function handleCertify() {
338
338
  report("certify_blob");
339
339
  const certifyTx = flow.certify();
340
- const certifyTxEffects = await signAndExecuteGasPoolTransaction(signer, suiJsonRpcClient, certifyTx);
340
+ const certifyTxEffects = await signAndExecuteGasPoolTransaction(saltServerUrl, signer, suiJsonRpcClient, certifyTx);
341
341
  if (!certifyTxEffects?.transactionDigest)
342
342
  throw new Error("fail to execute certify Blob transaction");
343
343
  await suiJsonRpcClient.waitForTransaction({
@@ -21,6 +21,7 @@ export interface WalletState {
21
21
  account: WalletAccount | null;
22
22
  error: string | null;
23
23
  network: string;
24
+ saltServerUrl: string;
24
25
  jwtTokenString: string | null;
25
26
  decodedJwt: ReturnType<typeof decodeJwt> | null;
26
27
  authProvider: AuthProvider | null;
@@ -42,6 +43,7 @@ export type WalletStore = WalletState & WalletActions;
42
43
  export type WalletStoreConfig = {
43
44
  suiClient: SuiClient;
44
45
  oAuthClientId: string;
46
+ saltServerUrl: string;
45
47
  network?: string;
46
48
  autoInit?: boolean;
47
49
  };
@@ -15,6 +15,7 @@ export function createWalletStore(config) {
15
15
  account: null,
16
16
  error: null,
17
17
  network,
18
+ saltServerUrl: config.saltServerUrl,
18
19
  jwtTokenString: null,
19
20
  decodedJwt: null,
20
21
  authProvider: null,
@@ -114,7 +115,7 @@ export function createWalletStore(config) {
114
115
  zkloginStorage.getState().setJWT(idToken);
115
116
  zkloginStorage.getState().setMaxEpoch(maxEpoch);
116
117
  const extendedEphemeralPublicKey = getExtendedEphemeralPublicKey(ephemeralKeyPair.getPublicKey());
117
- const zkProofResponse = await createZkLoginProof({
118
+ const zkProofResponse = await createZkLoginProof(config.saltServerUrl, {
118
119
  jwtTokenString: idToken,
119
120
  maxEpoch: String(maxEpoch),
120
121
  extendedEphemeralPublicKey,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@zing-protocol/zing-sdk",
3
3
  "sideEffects": false,
4
4
  "type": "module",
5
- "version": "0.0.12",
5
+ "version": "0.0.14",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {