@satoshai/kit 0.5.0 → 0.7.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.cts CHANGED
@@ -1,8 +1,63 @@
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
 
6
+ type BaseErrorType = BaseError & {
7
+ name: 'StacksKitError';
8
+ };
9
+ declare class BaseError extends Error {
10
+ name: string;
11
+ shortMessage: string;
12
+ constructor(shortMessage: string, options?: {
13
+ cause?: Error;
14
+ details?: string;
15
+ });
16
+ walk(fn?: (err: unknown) => boolean): unknown;
17
+ }
18
+ type WalletNotConnectedErrorType = WalletNotConnectedError & {
19
+ name: 'WalletNotConnectedError';
20
+ };
21
+ declare class WalletNotConnectedError extends BaseError {
22
+ name: string;
23
+ constructor();
24
+ }
25
+ type WalletNotFoundErrorType = WalletNotFoundError & {
26
+ name: 'WalletNotFoundError';
27
+ };
28
+ declare class WalletNotFoundError extends BaseError {
29
+ name: string;
30
+ wallet: string;
31
+ constructor({ wallet }: {
32
+ wallet: string;
33
+ });
34
+ }
35
+ type UnsupportedMethodErrorType = UnsupportedMethodError & {
36
+ name: 'UnsupportedMethodError';
37
+ };
38
+ declare class UnsupportedMethodError extends BaseError {
39
+ name: string;
40
+ method: string;
41
+ wallet: string;
42
+ constructor({ method, wallet }: {
43
+ method: string;
44
+ wallet: string;
45
+ });
46
+ }
47
+ type WalletRequestErrorType = WalletRequestError & {
48
+ name: 'WalletRequestError';
49
+ };
50
+ declare class WalletRequestError extends BaseError {
51
+ name: string;
52
+ method: string;
53
+ wallet: string;
54
+ constructor({ method, wallet, cause }: {
55
+ method: string;
56
+ wallet: string;
57
+ cause: Error;
58
+ });
59
+ }
60
+
6
61
  declare const SUPPORTED_STACKS_WALLETS: readonly ["xverse", "leather", "asigna", "fordefi", "wallet-connect", "okx"];
7
62
  type SupportedStacksWallet = (typeof SUPPORTED_STACKS_WALLETS)[number];
8
63
 
@@ -116,7 +171,59 @@ declare const useSignMessage: () => {
116
171
  signMessageAsync: (variables: SignMessageVariables) => Promise<SignMessageData>;
117
172
  reset: () => void;
118
173
  data: SignMessageData | undefined;
119
- error: Error | null;
174
+ error: BaseError | null;
175
+ isError: boolean;
176
+ isIdle: boolean;
177
+ isPending: boolean;
178
+ isSuccess: boolean;
179
+ status: MutationStatus;
180
+ };
181
+
182
+ interface SignStructuredMessageVariables {
183
+ message: ClarityValue;
184
+ domain: TupleCV;
185
+ }
186
+ interface SignStructuredMessageData {
187
+ publicKey: string;
188
+ signature: string;
189
+ }
190
+ interface SignStructuredMessageOptions {
191
+ onSuccess?: (data: SignStructuredMessageData) => void;
192
+ onError?: (error: Error) => void;
193
+ onSettled?: (data: SignStructuredMessageData | undefined, error: Error | null) => void;
194
+ }
195
+ declare const useSignStructuredMessage: () => {
196
+ signStructuredMessage: (variables: SignStructuredMessageVariables, options?: SignStructuredMessageOptions) => void;
197
+ signStructuredMessageAsync: (variables: SignStructuredMessageVariables) => Promise<SignStructuredMessageData>;
198
+ reset: () => void;
199
+ data: SignStructuredMessageData | undefined;
200
+ error: BaseError | null;
201
+ isError: boolean;
202
+ isIdle: boolean;
203
+ isPending: boolean;
204
+ isSuccess: boolean;
205
+ status: MutationStatus;
206
+ };
207
+
208
+ interface SignTransactionVariables {
209
+ transaction: string;
210
+ broadcast?: boolean;
211
+ }
212
+ interface SignTransactionData {
213
+ transaction: string;
214
+ txid?: string;
215
+ }
216
+ interface SignTransactionOptions {
217
+ onSuccess?: (data: SignTransactionData) => void;
218
+ onError?: (error: Error) => void;
219
+ onSettled?: (data: SignTransactionData | undefined, error: Error | null) => void;
220
+ }
221
+ declare const useSignTransaction: () => {
222
+ signTransaction: (variables: SignTransactionVariables, options?: SignTransactionOptions) => void;
223
+ signTransactionAsync: (variables: SignTransactionVariables) => Promise<SignTransactionData>;
224
+ reset: () => void;
225
+ data: SignTransactionData | undefined;
226
+ error: BaseError | null;
120
227
  isError: boolean;
121
228
  isIdle: boolean;
122
229
  isPending: boolean;
@@ -141,7 +248,7 @@ declare const useTransferSTX: () => {
141
248
  transferSTXAsync: (variables: TransferSTXVariables) => Promise<string>;
142
249
  reset: () => void;
143
250
  data: string | undefined;
144
- error: Error | null;
251
+ error: BaseError | null;
145
252
  isError: boolean;
146
253
  isIdle: boolean;
147
254
  isPending: boolean;
@@ -202,7 +309,7 @@ declare const useWriteContract: () => {
202
309
  writeContractAsync: WriteContractAsyncFn;
203
310
  reset: () => void;
204
311
  data: string | undefined;
205
- error: Error | null;
312
+ error: BaseError | null;
206
313
  isError: boolean;
207
314
  isIdle: boolean;
208
315
  isPending: boolean;
@@ -243,4 +350,4 @@ declare function createContractConfig<const TAbi extends ClarityAbi>(config: {
243
350
  contract: string;
244
351
  };
245
352
 
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 };
353
+ export { BaseError, type BaseErrorType, 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, UnsupportedMethodError, type UnsupportedMethodErrorType, type UntypedWriteContractVariables, type WalletConnectMetadata, type WalletContextValue, type WalletInfo, WalletNotConnectedError, type WalletNotConnectedErrorType, WalletNotFoundError, type WalletNotFoundErrorType, WalletRequestError, type WalletRequestErrorType, type WalletState, type WriteContractOptions, type WriteContractVariables, createContractConfig, getLocalStorageWallet, getNetworkFromAddress, getStacksWallets, useAddress, useBnsName, useConnect, useDisconnect, useSignMessage, useSignStructuredMessage, useSignTransaction, useTransferSTX, useWallets, useWriteContract };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,63 @@
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
 
6
+ type BaseErrorType = BaseError & {
7
+ name: 'StacksKitError';
8
+ };
9
+ declare class BaseError extends Error {
10
+ name: string;
11
+ shortMessage: string;
12
+ constructor(shortMessage: string, options?: {
13
+ cause?: Error;
14
+ details?: string;
15
+ });
16
+ walk(fn?: (err: unknown) => boolean): unknown;
17
+ }
18
+ type WalletNotConnectedErrorType = WalletNotConnectedError & {
19
+ name: 'WalletNotConnectedError';
20
+ };
21
+ declare class WalletNotConnectedError extends BaseError {
22
+ name: string;
23
+ constructor();
24
+ }
25
+ type WalletNotFoundErrorType = WalletNotFoundError & {
26
+ name: 'WalletNotFoundError';
27
+ };
28
+ declare class WalletNotFoundError extends BaseError {
29
+ name: string;
30
+ wallet: string;
31
+ constructor({ wallet }: {
32
+ wallet: string;
33
+ });
34
+ }
35
+ type UnsupportedMethodErrorType = UnsupportedMethodError & {
36
+ name: 'UnsupportedMethodError';
37
+ };
38
+ declare class UnsupportedMethodError extends BaseError {
39
+ name: string;
40
+ method: string;
41
+ wallet: string;
42
+ constructor({ method, wallet }: {
43
+ method: string;
44
+ wallet: string;
45
+ });
46
+ }
47
+ type WalletRequestErrorType = WalletRequestError & {
48
+ name: 'WalletRequestError';
49
+ };
50
+ declare class WalletRequestError extends BaseError {
51
+ name: string;
52
+ method: string;
53
+ wallet: string;
54
+ constructor({ method, wallet, cause }: {
55
+ method: string;
56
+ wallet: string;
57
+ cause: Error;
58
+ });
59
+ }
60
+
6
61
  declare const SUPPORTED_STACKS_WALLETS: readonly ["xverse", "leather", "asigna", "fordefi", "wallet-connect", "okx"];
7
62
  type SupportedStacksWallet = (typeof SUPPORTED_STACKS_WALLETS)[number];
8
63
 
@@ -116,7 +171,59 @@ declare const useSignMessage: () => {
116
171
  signMessageAsync: (variables: SignMessageVariables) => Promise<SignMessageData>;
117
172
  reset: () => void;
118
173
  data: SignMessageData | undefined;
119
- error: Error | null;
174
+ error: BaseError | null;
175
+ isError: boolean;
176
+ isIdle: boolean;
177
+ isPending: boolean;
178
+ isSuccess: boolean;
179
+ status: MutationStatus;
180
+ };
181
+
182
+ interface SignStructuredMessageVariables {
183
+ message: ClarityValue;
184
+ domain: TupleCV;
185
+ }
186
+ interface SignStructuredMessageData {
187
+ publicKey: string;
188
+ signature: string;
189
+ }
190
+ interface SignStructuredMessageOptions {
191
+ onSuccess?: (data: SignStructuredMessageData) => void;
192
+ onError?: (error: Error) => void;
193
+ onSettled?: (data: SignStructuredMessageData | undefined, error: Error | null) => void;
194
+ }
195
+ declare const useSignStructuredMessage: () => {
196
+ signStructuredMessage: (variables: SignStructuredMessageVariables, options?: SignStructuredMessageOptions) => void;
197
+ signStructuredMessageAsync: (variables: SignStructuredMessageVariables) => Promise<SignStructuredMessageData>;
198
+ reset: () => void;
199
+ data: SignStructuredMessageData | undefined;
200
+ error: BaseError | null;
201
+ isError: boolean;
202
+ isIdle: boolean;
203
+ isPending: boolean;
204
+ isSuccess: boolean;
205
+ status: MutationStatus;
206
+ };
207
+
208
+ interface SignTransactionVariables {
209
+ transaction: string;
210
+ broadcast?: boolean;
211
+ }
212
+ interface SignTransactionData {
213
+ transaction: string;
214
+ txid?: string;
215
+ }
216
+ interface SignTransactionOptions {
217
+ onSuccess?: (data: SignTransactionData) => void;
218
+ onError?: (error: Error) => void;
219
+ onSettled?: (data: SignTransactionData | undefined, error: Error | null) => void;
220
+ }
221
+ declare const useSignTransaction: () => {
222
+ signTransaction: (variables: SignTransactionVariables, options?: SignTransactionOptions) => void;
223
+ signTransactionAsync: (variables: SignTransactionVariables) => Promise<SignTransactionData>;
224
+ reset: () => void;
225
+ data: SignTransactionData | undefined;
226
+ error: BaseError | null;
120
227
  isError: boolean;
121
228
  isIdle: boolean;
122
229
  isPending: boolean;
@@ -141,7 +248,7 @@ declare const useTransferSTX: () => {
141
248
  transferSTXAsync: (variables: TransferSTXVariables) => Promise<string>;
142
249
  reset: () => void;
143
250
  data: string | undefined;
144
- error: Error | null;
251
+ error: BaseError | null;
145
252
  isError: boolean;
146
253
  isIdle: boolean;
147
254
  isPending: boolean;
@@ -202,7 +309,7 @@ declare const useWriteContract: () => {
202
309
  writeContractAsync: WriteContractAsyncFn;
203
310
  reset: () => void;
204
311
  data: string | undefined;
205
- error: Error | null;
312
+ error: BaseError | null;
206
313
  isError: boolean;
207
314
  isIdle: boolean;
208
315
  isPending: boolean;
@@ -243,4 +350,4 @@ declare function createContractConfig<const TAbi extends ClarityAbi>(config: {
243
350
  contract: string;
244
351
  };
245
352
 
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 };
353
+ export { BaseError, type BaseErrorType, 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, UnsupportedMethodError, type UnsupportedMethodErrorType, type UntypedWriteContractVariables, type WalletConnectMetadata, type WalletContextValue, type WalletInfo, WalletNotConnectedError, type WalletNotConnectedErrorType, WalletNotFoundError, type WalletNotFoundErrorType, WalletRequestError, type WalletRequestErrorType, 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
@@ -4,6 +4,69 @@ import { jsx } from 'react/jsx-runtime';
4
4
  import { PostConditionMode, postConditionToHex, cvToHex, noneCV, contractPrincipalCV, standardPrincipalCV, boolCV, intCV, uintCV, bufferCV, stringAsciiCV, stringUtf8CV, someCV, listCV, tupleCV } from '@stacks/transactions';
5
5
  import { getPrimaryName } from 'bns-v2-sdk';
6
6
 
7
+ // src/errors.ts
8
+ var BaseError = class extends Error {
9
+ name = "StacksKitError";
10
+ shortMessage;
11
+ constructor(shortMessage, options) {
12
+ const message = [
13
+ shortMessage,
14
+ options?.details && `Details: ${options.details}`
15
+ ].filter(Boolean).join("\n\n");
16
+ super(message, options?.cause ? { cause: options.cause } : void 0);
17
+ this.shortMessage = shortMessage;
18
+ }
19
+ walk(fn) {
20
+ return walk(this, fn);
21
+ }
22
+ };
23
+ function walk(err, fn) {
24
+ if (fn?.(err)) return err;
25
+ if (err && typeof err === "object" && "cause" in err) {
26
+ return walk(err.cause, fn);
27
+ }
28
+ return err;
29
+ }
30
+ var WalletNotConnectedError = class extends BaseError {
31
+ name = "WalletNotConnectedError";
32
+ constructor() {
33
+ super("Wallet is not connected");
34
+ }
35
+ };
36
+ var WalletNotFoundError = class extends BaseError {
37
+ name = "WalletNotFoundError";
38
+ wallet;
39
+ constructor({ wallet }) {
40
+ super(`${wallet} wallet not found`, {
41
+ details: "The wallet extension may not be installed."
42
+ });
43
+ this.wallet = wallet;
44
+ }
45
+ };
46
+ var UnsupportedMethodError = class extends BaseError {
47
+ name = "UnsupportedMethodError";
48
+ method;
49
+ wallet;
50
+ constructor({ method, wallet }) {
51
+ super(`${method} is not supported by ${wallet} wallet`);
52
+ this.method = method;
53
+ this.wallet = wallet;
54
+ }
55
+ };
56
+ var WalletRequestError = class extends BaseError {
57
+ name = "WalletRequestError";
58
+ method;
59
+ wallet;
60
+ constructor({ method, wallet, cause }) {
61
+ super(`${wallet} wallet request failed`, {
62
+ cause,
63
+ details: cause.message
64
+ });
65
+ this.method = method;
66
+ this.wallet = wallet;
67
+ }
68
+ };
69
+
7
70
  // src/constants/stacks-provider-mapping.ts
8
71
  var STACKS_TO_STACKS_CONNECT_PROVIDERS = {
9
72
  xverse: "XverseProviders.BitcoinProvider",
@@ -683,7 +746,7 @@ var useSignMessage = () => {
683
746
  const signMessageAsync = useCallback(
684
747
  async (variables) => {
685
748
  if (!isConnected) {
686
- throw new Error("Wallet is not connected");
749
+ throw new WalletNotConnectedError();
687
750
  }
688
751
  setStatus("pending");
689
752
  setError(null);
@@ -692,7 +755,7 @@ var useSignMessage = () => {
692
755
  let result;
693
756
  if (provider === "okx") {
694
757
  if (!window.okxwallet) {
695
- throw new Error("OKX wallet not found");
758
+ throw new WalletNotFoundError({ wallet: "OKX" });
696
759
  }
697
760
  result = await window.okxwallet.stacks.signMessage({
698
761
  message: variables.message
@@ -709,7 +772,11 @@ var useSignMessage = () => {
709
772
  setStatus("success");
710
773
  return result;
711
774
  } catch (err) {
712
- const error2 = err instanceof Error ? err : new Error(String(err));
775
+ const error2 = err instanceof BaseError ? err : new WalletRequestError({
776
+ method: "stx_signMessage",
777
+ wallet: provider ?? "unknown",
778
+ cause: err instanceof Error ? err : new Error(String(err))
779
+ });
713
780
  setError(error2);
714
781
  setStatus("error");
715
782
  throw error2;
@@ -750,6 +817,163 @@ var useSignMessage = () => {
750
817
  [signMessage, signMessageAsync, reset, data, error, status]
751
818
  );
752
819
  };
820
+ var useSignStructuredMessage = () => {
821
+ const { isConnected, provider } = useAddress();
822
+ const [data, setData] = useState(
823
+ void 0
824
+ );
825
+ const [error, setError] = useState(null);
826
+ const [status, setStatus] = useState("idle");
827
+ const signStructuredMessageAsync = useCallback(
828
+ async (variables) => {
829
+ if (!isConnected) {
830
+ throw new WalletNotConnectedError();
831
+ }
832
+ if (provider === "okx") {
833
+ throw new UnsupportedMethodError({
834
+ method: "stx_signStructuredMessage",
835
+ wallet: "OKX"
836
+ });
837
+ }
838
+ setStatus("pending");
839
+ setError(null);
840
+ setData(void 0);
841
+ try {
842
+ const result = await request("stx_signStructuredMessage", {
843
+ message: variables.message,
844
+ domain: variables.domain
845
+ });
846
+ setData(result);
847
+ setStatus("success");
848
+ return result;
849
+ } catch (err) {
850
+ const error2 = err instanceof BaseError ? err : new WalletRequestError({
851
+ method: "stx_signStructuredMessage",
852
+ wallet: provider ?? "unknown",
853
+ cause: err instanceof Error ? err : new Error(String(err))
854
+ });
855
+ setError(error2);
856
+ setStatus("error");
857
+ throw error2;
858
+ }
859
+ },
860
+ [isConnected, provider]
861
+ );
862
+ const signStructuredMessage = useCallback(
863
+ (variables, options) => {
864
+ signStructuredMessageAsync(variables).then((data2) => {
865
+ options?.onSuccess?.(data2);
866
+ options?.onSettled?.(data2, null);
867
+ }).catch((error2) => {
868
+ options?.onError?.(error2);
869
+ options?.onSettled?.(void 0, error2);
870
+ });
871
+ },
872
+ [signStructuredMessageAsync]
873
+ );
874
+ const reset = useCallback(() => {
875
+ setData(void 0);
876
+ setError(null);
877
+ setStatus("idle");
878
+ }, []);
879
+ return useMemo(
880
+ () => ({
881
+ signStructuredMessage,
882
+ signStructuredMessageAsync,
883
+ reset,
884
+ data,
885
+ error,
886
+ isError: status === "error",
887
+ isIdle: status === "idle",
888
+ isPending: status === "pending",
889
+ isSuccess: status === "success",
890
+ status
891
+ }),
892
+ [
893
+ signStructuredMessage,
894
+ signStructuredMessageAsync,
895
+ reset,
896
+ data,
897
+ error,
898
+ status
899
+ ]
900
+ );
901
+ };
902
+ var useSignTransaction = () => {
903
+ const { isConnected, provider } = useAddress();
904
+ const [data, setData] = useState(void 0);
905
+ const [error, setError] = useState(null);
906
+ const [status, setStatus] = useState("idle");
907
+ const signTransactionAsync = useCallback(
908
+ async (variables) => {
909
+ if (!isConnected) {
910
+ throw new WalletNotConnectedError();
911
+ }
912
+ if (provider === "okx") {
913
+ throw new UnsupportedMethodError({
914
+ method: "stx_signTransaction",
915
+ wallet: "OKX"
916
+ });
917
+ }
918
+ setStatus("pending");
919
+ setError(null);
920
+ setData(void 0);
921
+ try {
922
+ const result = await request("stx_signTransaction", {
923
+ transaction: variables.transaction,
924
+ ...variables.broadcast !== void 0 && {
925
+ broadcast: variables.broadcast
926
+ }
927
+ });
928
+ setData(result);
929
+ setStatus("success");
930
+ return result;
931
+ } catch (err) {
932
+ const error2 = err instanceof BaseError ? err : new WalletRequestError({
933
+ method: "stx_signTransaction",
934
+ wallet: provider ?? "unknown",
935
+ cause: err instanceof Error ? err : new Error(String(err))
936
+ });
937
+ setError(error2);
938
+ setStatus("error");
939
+ throw error2;
940
+ }
941
+ },
942
+ [isConnected, provider]
943
+ );
944
+ const signTransaction = useCallback(
945
+ (variables, options) => {
946
+ signTransactionAsync(variables).then((data2) => {
947
+ options?.onSuccess?.(data2);
948
+ options?.onSettled?.(data2, null);
949
+ }).catch((error2) => {
950
+ options?.onError?.(error2);
951
+ options?.onSettled?.(void 0, error2);
952
+ });
953
+ },
954
+ [signTransactionAsync]
955
+ );
956
+ const reset = useCallback(() => {
957
+ setData(void 0);
958
+ setError(null);
959
+ setStatus("idle");
960
+ }, []);
961
+ return useMemo(
962
+ () => ({
963
+ signTransaction,
964
+ signTransactionAsync,
965
+ reset,
966
+ data,
967
+ error,
968
+ isError: status === "error",
969
+ isIdle: status === "idle",
970
+ isPending: status === "pending",
971
+ isSuccess: status === "success",
972
+ status
973
+ }),
974
+ [signTransaction, signTransactionAsync, reset, data, error, status]
975
+ );
976
+ };
753
977
 
754
978
  // src/utils/get-network-from-address.ts
755
979
  var getNetworkFromAddress = (address) => {
@@ -771,7 +995,7 @@ var useTransferSTX = () => {
771
995
  const transferSTXAsync = useCallback(
772
996
  async (variables) => {
773
997
  if (!isConnected || !address) {
774
- throw new Error("Wallet is not connected");
998
+ throw new WalletNotConnectedError();
775
999
  }
776
1000
  setStatus("pending");
777
1001
  setError(null);
@@ -779,7 +1003,7 @@ var useTransferSTX = () => {
779
1003
  try {
780
1004
  if (provider === "okx") {
781
1005
  if (!window.okxwallet) {
782
- throw new Error("OKX wallet not found");
1006
+ throw new WalletNotFoundError({ wallet: "OKX" });
783
1007
  }
784
1008
  const response2 = await window.okxwallet.stacks.signTransaction({
785
1009
  txType: "token_transfer",
@@ -814,7 +1038,11 @@ var useTransferSTX = () => {
814
1038
  setStatus("success");
815
1039
  return response.txid;
816
1040
  } catch (err) {
817
- const error2 = err instanceof Error ? err : new Error(String(err));
1041
+ const error2 = err instanceof BaseError ? err : new WalletRequestError({
1042
+ method: "stx_transferStx",
1043
+ wallet: provider ?? "unknown",
1044
+ cause: err instanceof Error ? err : new Error(String(err))
1045
+ });
818
1046
  setError(error2);
819
1047
  setStatus("error");
820
1048
  throw error2;
@@ -1002,7 +1230,7 @@ var useWriteContract = () => {
1002
1230
  const writeContractAsync = useCallback(
1003
1231
  async (variables) => {
1004
1232
  if (!isConnected || !address) {
1005
- throw new Error("Wallet is not connected");
1233
+ throw new WalletNotConnectedError();
1006
1234
  }
1007
1235
  setStatus("pending");
1008
1236
  setError(null);
@@ -1011,7 +1239,7 @@ var useWriteContract = () => {
1011
1239
  try {
1012
1240
  if (provider === "okx") {
1013
1241
  if (!window.okxwallet) {
1014
- throw new Error("OKX wallet not found");
1242
+ throw new WalletNotFoundError({ wallet: "OKX" });
1015
1243
  }
1016
1244
  const response2 = await window.okxwallet.stacks.signTransaction({
1017
1245
  contractAddress: variables.address,
@@ -1046,7 +1274,11 @@ var useWriteContract = () => {
1046
1274
  setStatus("success");
1047
1275
  return response.txid;
1048
1276
  } catch (err) {
1049
- const error2 = err instanceof Error ? err : new Error(String(err));
1277
+ const error2 = err instanceof BaseError ? err : new WalletRequestError({
1278
+ method: "stx_callContract",
1279
+ wallet: provider ?? "unknown",
1280
+ cause: err instanceof Error ? err : new Error(String(err))
1281
+ });
1050
1282
  setError(error2);
1051
1283
  setStatus("error");
1052
1284
  throw error2;
@@ -1131,6 +1363,6 @@ function createContractConfig(config) {
1131
1363
  return config;
1132
1364
  }
1133
1365
 
1134
- export { SUPPORTED_STACKS_WALLETS, StacksWalletProvider, createContractConfig, getLocalStorageWallet, getNetworkFromAddress, getStacksWallets, useAddress, useBnsName, useConnect, useDisconnect, useSignMessage, useTransferSTX, useWallets, useWriteContract };
1366
+ export { BaseError, SUPPORTED_STACKS_WALLETS, StacksWalletProvider, UnsupportedMethodError, WalletNotConnectedError, WalletNotFoundError, WalletRequestError, createContractConfig, getLocalStorageWallet, getNetworkFromAddress, getStacksWallets, useAddress, useBnsName, useConnect, useDisconnect, useSignMessage, useSignStructuredMessage, useSignTransaction, useTransferSTX, useWallets, useWriteContract };
1135
1367
  //# sourceMappingURL=index.js.map
1136
1368
  //# sourceMappingURL=index.js.map