@satoshai/kit 0.5.0 → 0.6.0

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { PostCondition, PostConditionMode, ClarityValue } from '@stacks/transactions';
2
+ import { ClarityValue, TupleCV, PostCondition, PostConditionMode } from '@stacks/transactions';
3
3
  import { ClarityAbi, ExtractAbiFunctionNames, Pretty, ExtractAbiFunction, ClarityAbiArgToPrimitiveTypeValue } from 'clarity-abitype';
4
4
  export { ClarityAbi } from 'clarity-abitype';
5
5
 
@@ -124,6 +124,58 @@ declare const useSignMessage: () => {
124
124
  status: MutationStatus;
125
125
  };
126
126
 
127
+ interface SignStructuredMessageVariables {
128
+ message: ClarityValue;
129
+ domain: TupleCV;
130
+ }
131
+ interface SignStructuredMessageData {
132
+ publicKey: string;
133
+ signature: string;
134
+ }
135
+ interface SignStructuredMessageOptions {
136
+ onSuccess?: (data: SignStructuredMessageData) => void;
137
+ onError?: (error: Error) => void;
138
+ onSettled?: (data: SignStructuredMessageData | undefined, error: Error | null) => void;
139
+ }
140
+ declare const useSignStructuredMessage: () => {
141
+ signStructuredMessage: (variables: SignStructuredMessageVariables, options?: SignStructuredMessageOptions) => void;
142
+ signStructuredMessageAsync: (variables: SignStructuredMessageVariables) => Promise<SignStructuredMessageData>;
143
+ reset: () => void;
144
+ data: SignStructuredMessageData | undefined;
145
+ error: Error | null;
146
+ isError: boolean;
147
+ isIdle: boolean;
148
+ isPending: boolean;
149
+ isSuccess: boolean;
150
+ status: MutationStatus;
151
+ };
152
+
153
+ interface SignTransactionVariables {
154
+ transaction: string;
155
+ broadcast?: boolean;
156
+ }
157
+ interface SignTransactionData {
158
+ transaction: string;
159
+ txid?: string;
160
+ }
161
+ interface SignTransactionOptions {
162
+ onSuccess?: (data: SignTransactionData) => void;
163
+ onError?: (error: Error) => void;
164
+ onSettled?: (data: SignTransactionData | undefined, error: Error | null) => void;
165
+ }
166
+ declare const useSignTransaction: () => {
167
+ signTransaction: (variables: SignTransactionVariables, options?: SignTransactionOptions) => void;
168
+ signTransactionAsync: (variables: SignTransactionVariables) => Promise<SignTransactionData>;
169
+ reset: () => void;
170
+ data: SignTransactionData | undefined;
171
+ error: Error | null;
172
+ isError: boolean;
173
+ isIdle: boolean;
174
+ isPending: boolean;
175
+ isSuccess: boolean;
176
+ status: MutationStatus;
177
+ };
178
+
127
179
  interface TransferSTXVariables {
128
180
  recipient: string;
129
181
  amount: bigint | number | string;
@@ -243,4 +295,4 @@ declare function createContractConfig<const TAbi extends ClarityAbi>(config: {
243
295
  contract: string;
244
296
  };
245
297
 
246
- export { type ConnectOptions, type MutationStatus, type PostConditionConfig, type PublicFunctionArgs, type PublicFunctionName, SUPPORTED_STACKS_WALLETS, type SignMessageData, type SignMessageOptions, type SignMessageVariables, type StacksChain, StacksWalletProvider, type StacksWallets, type SupportedStacksWallet, type TraitReference, type TransferSTXOptions, type TransferSTXVariables, type TypedWriteContractVariables, type UntypedWriteContractVariables, type WalletConnectMetadata, type WalletContextValue, type WalletInfo, type WalletState, type WriteContractOptions, type WriteContractVariables, createContractConfig, getLocalStorageWallet, getNetworkFromAddress, getStacksWallets, useAddress, useBnsName, useConnect, useDisconnect, useSignMessage, useTransferSTX, useWallets, useWriteContract };
298
+ export { type ConnectOptions, type MutationStatus, type PostConditionConfig, type PublicFunctionArgs, type PublicFunctionName, SUPPORTED_STACKS_WALLETS, type SignMessageData, type SignMessageOptions, type SignMessageVariables, type SignStructuredMessageData, type SignStructuredMessageOptions, type SignStructuredMessageVariables, type SignTransactionData, type SignTransactionOptions, type SignTransactionVariables, type StacksChain, StacksWalletProvider, type StacksWallets, type SupportedStacksWallet, type TraitReference, type TransferSTXOptions, type TransferSTXVariables, type TypedWriteContractVariables, type UntypedWriteContractVariables, type WalletConnectMetadata, type WalletContextValue, type WalletInfo, type WalletState, type WriteContractOptions, type WriteContractVariables, createContractConfig, getLocalStorageWallet, getNetworkFromAddress, getStacksWallets, useAddress, useBnsName, useConnect, useDisconnect, useSignMessage, useSignStructuredMessage, useSignTransaction, useTransferSTX, useWallets, useWriteContract };
package/dist/index.js CHANGED
@@ -750,6 +750,153 @@ var useSignMessage = () => {
750
750
  [signMessage, signMessageAsync, reset, data, error, status]
751
751
  );
752
752
  };
753
+ var useSignStructuredMessage = () => {
754
+ const { isConnected, provider } = useAddress();
755
+ const [data, setData] = useState(
756
+ void 0
757
+ );
758
+ const [error, setError] = useState(null);
759
+ const [status, setStatus] = useState("idle");
760
+ const signStructuredMessageAsync = useCallback(
761
+ async (variables) => {
762
+ if (!isConnected) {
763
+ throw new Error("Wallet is not connected");
764
+ }
765
+ if (provider === "okx") {
766
+ throw new Error(
767
+ "Structured message signing is not supported by OKX wallet"
768
+ );
769
+ }
770
+ setStatus("pending");
771
+ setError(null);
772
+ setData(void 0);
773
+ try {
774
+ const result = await request("stx_signStructuredMessage", {
775
+ message: variables.message,
776
+ domain: variables.domain
777
+ });
778
+ setData(result);
779
+ setStatus("success");
780
+ return result;
781
+ } catch (err) {
782
+ const error2 = err instanceof Error ? err : new Error(String(err));
783
+ setError(error2);
784
+ setStatus("error");
785
+ throw error2;
786
+ }
787
+ },
788
+ [isConnected, provider]
789
+ );
790
+ const signStructuredMessage = useCallback(
791
+ (variables, options) => {
792
+ signStructuredMessageAsync(variables).then((data2) => {
793
+ options?.onSuccess?.(data2);
794
+ options?.onSettled?.(data2, null);
795
+ }).catch((error2) => {
796
+ options?.onError?.(error2);
797
+ options?.onSettled?.(void 0, error2);
798
+ });
799
+ },
800
+ [signStructuredMessageAsync]
801
+ );
802
+ const reset = useCallback(() => {
803
+ setData(void 0);
804
+ setError(null);
805
+ setStatus("idle");
806
+ }, []);
807
+ return useMemo(
808
+ () => ({
809
+ signStructuredMessage,
810
+ signStructuredMessageAsync,
811
+ reset,
812
+ data,
813
+ error,
814
+ isError: status === "error",
815
+ isIdle: status === "idle",
816
+ isPending: status === "pending",
817
+ isSuccess: status === "success",
818
+ status
819
+ }),
820
+ [
821
+ signStructuredMessage,
822
+ signStructuredMessageAsync,
823
+ reset,
824
+ data,
825
+ error,
826
+ status
827
+ ]
828
+ );
829
+ };
830
+ var useSignTransaction = () => {
831
+ const { isConnected, provider } = useAddress();
832
+ const [data, setData] = useState(void 0);
833
+ const [error, setError] = useState(null);
834
+ const [status, setStatus] = useState("idle");
835
+ const signTransactionAsync = useCallback(
836
+ async (variables) => {
837
+ if (!isConnected) {
838
+ throw new Error("Wallet is not connected");
839
+ }
840
+ if (provider === "okx") {
841
+ throw new Error(
842
+ "Transaction signing is not supported by OKX wallet"
843
+ );
844
+ }
845
+ setStatus("pending");
846
+ setError(null);
847
+ setData(void 0);
848
+ try {
849
+ const result = await request("stx_signTransaction", {
850
+ transaction: variables.transaction,
851
+ ...variables.broadcast !== void 0 && {
852
+ broadcast: variables.broadcast
853
+ }
854
+ });
855
+ setData(result);
856
+ setStatus("success");
857
+ return result;
858
+ } catch (err) {
859
+ const error2 = err instanceof Error ? err : new Error(String(err));
860
+ setError(error2);
861
+ setStatus("error");
862
+ throw error2;
863
+ }
864
+ },
865
+ [isConnected, provider]
866
+ );
867
+ const signTransaction = useCallback(
868
+ (variables, options) => {
869
+ signTransactionAsync(variables).then((data2) => {
870
+ options?.onSuccess?.(data2);
871
+ options?.onSettled?.(data2, null);
872
+ }).catch((error2) => {
873
+ options?.onError?.(error2);
874
+ options?.onSettled?.(void 0, error2);
875
+ });
876
+ },
877
+ [signTransactionAsync]
878
+ );
879
+ const reset = useCallback(() => {
880
+ setData(void 0);
881
+ setError(null);
882
+ setStatus("idle");
883
+ }, []);
884
+ return useMemo(
885
+ () => ({
886
+ signTransaction,
887
+ signTransactionAsync,
888
+ reset,
889
+ data,
890
+ error,
891
+ isError: status === "error",
892
+ isIdle: status === "idle",
893
+ isPending: status === "pending",
894
+ isSuccess: status === "success",
895
+ status
896
+ }),
897
+ [signTransaction, signTransactionAsync, reset, data, error, status]
898
+ );
899
+ };
753
900
 
754
901
  // src/utils/get-network-from-address.ts
755
902
  var getNetworkFromAddress = (address) => {
@@ -1131,6 +1278,6 @@ function createContractConfig(config) {
1131
1278
  return config;
1132
1279
  }
1133
1280
 
1134
- export { SUPPORTED_STACKS_WALLETS, StacksWalletProvider, createContractConfig, getLocalStorageWallet, getNetworkFromAddress, getStacksWallets, useAddress, useBnsName, useConnect, useDisconnect, useSignMessage, useTransferSTX, useWallets, useWriteContract };
1281
+ export { SUPPORTED_STACKS_WALLETS, StacksWalletProvider, createContractConfig, getLocalStorageWallet, getNetworkFromAddress, getStacksWallets, useAddress, useBnsName, useConnect, useDisconnect, useSignMessage, useSignStructuredMessage, useSignTransaction, useTransferSTX, useWallets, useWriteContract };
1135
1282
  //# sourceMappingURL=index.js.map
1136
1283
  //# sourceMappingURL=index.js.map