@mysten/dapp-kit-react 1.1.0 → 2.0.1
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.mts +22 -40
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -55
- package/dist/index.mjs.map +1 -1
- package/dist/ui.d.mts +23 -0
- package/dist/ui.d.mts.map +1 -0
- package/dist/ui.mjs +38 -0
- package/dist/ui.mjs.map +1 -0
- package/dist/useDAppKit-LUp-KcgG.mjs +24 -0
- package/dist/useDAppKit-LUp-KcgG.mjs.map +1 -0
- package/docs/actions/connect-wallet.md +68 -0
- package/docs/actions/disconnect-wallet.md +37 -0
- package/docs/actions/sign-and-execute-transaction.md +95 -0
- package/docs/actions/sign-personal-message.md +57 -0
- package/docs/actions/sign-transaction.md +64 -0
- package/docs/actions/switch-account.md +36 -0
- package/docs/actions/switch-network.md +36 -0
- package/docs/dapp-kit-instance.md +163 -0
- package/docs/getting-started/create-dapp.md +151 -0
- package/docs/getting-started/next-js.md +162 -0
- package/docs/getting-started/react.md +170 -0
- package/docs/getting-started/vue.md +188 -0
- package/docs/index.md +70 -0
- package/docs/llms-index.md +34 -0
- package/docs/react/components/connect-button.md +42 -0
- package/docs/react/components/connect-modal.md +51 -0
- package/docs/react/components/index.md +13 -0
- package/docs/react/dapp-kit-provider.md +86 -0
- package/docs/react/hooks/index.md +25 -0
- package/docs/react/hooks/use-current-account.md +33 -0
- package/docs/react/hooks/use-current-client.md +36 -0
- package/docs/react/hooks/use-current-network.md +28 -0
- package/docs/react/hooks/use-current-wallet.md +36 -0
- package/docs/react/hooks/use-dapp-kit.md +100 -0
- package/docs/react/hooks/use-wallet-connection.md +48 -0
- package/docs/react/hooks/use-wallets.md +33 -0
- package/docs/state.md +168 -0
- package/docs/theming.md +196 -0
- package/docs/web-components/connect-button.md +87 -0
- package/docs/web-components/connect-modal.md +176 -0
- package/package.json +9 -2
- package/src/index.ts +0 -6
- package/src/ui.ts +8 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,38 +1,20 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _mysten_dapp_kit_core0 from "@mysten/dapp-kit-core";
|
|
2
2
|
import { DAppKit, DefaultExpectedDppKit, RegisteredDAppKit } from "@mysten/dapp-kit-core";
|
|
3
3
|
import * as react0 from "react";
|
|
4
|
-
import {
|
|
5
|
-
import * as
|
|
6
|
-
import { DAppKitConnectButton, DAppKitConnectModal } from "@mysten/dapp-kit-core/web";
|
|
7
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
|
+
import { PropsWithChildren } from "react";
|
|
5
|
+
import * as react_jsx_runtime1 from "react/jsx-runtime";
|
|
8
6
|
import * as nanostores0 from "nanostores";
|
|
9
7
|
export * from "@mysten/dapp-kit-core";
|
|
10
8
|
|
|
11
|
-
//#region src/components/ConnectButton.d.ts
|
|
12
|
-
type ConnectButtonProps = ComponentProps<typeof ConnectButtonComponent>;
|
|
13
|
-
declare const ConnectButtonComponent: _lit_react0.ReactWebComponent<DAppKitConnectButton, {}>;
|
|
14
|
-
declare function ConnectButton({
|
|
15
|
-
instance,
|
|
16
|
-
...props
|
|
17
|
-
}: ConnectButtonProps): react_jsx_runtime0.JSX.Element;
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/components/ConnectModal.d.ts
|
|
20
|
-
type ConnectModalProps = ComponentProps<typeof ConnectModalComponent>;
|
|
21
|
-
declare const ConnectModalComponent: _lit_react0.ReactWebComponent<DAppKitConnectModal, {}>;
|
|
22
|
-
declare function ConnectModal({
|
|
23
|
-
instance,
|
|
24
|
-
...props
|
|
25
|
-
}: ConnectModalProps): react_jsx_runtime0.JSX.Element;
|
|
26
|
-
//#endregion
|
|
27
9
|
//#region src/components/DAppKitProvider.d.ts
|
|
28
|
-
declare const DAppKitContext: react0.Context<
|
|
10
|
+
declare const DAppKitContext: react0.Context<_mysten_dapp_kit_core0.DAppKit<any, _mysten_dapp_kit_core0.ClientWithCoreApi> | null>;
|
|
29
11
|
type DAppKitProviderProps = PropsWithChildren<{
|
|
30
12
|
dAppKit: DefaultExpectedDppKit;
|
|
31
13
|
}>;
|
|
32
14
|
declare function DAppKitProvider({
|
|
33
15
|
dAppKit,
|
|
34
16
|
children
|
|
35
|
-
}: DAppKitProviderProps):
|
|
17
|
+
}: DAppKitProviderProps): react_jsx_runtime1.JSX.Element;
|
|
36
18
|
//#endregion
|
|
37
19
|
//#region src/hooks/useDAppKit.d.ts
|
|
38
20
|
declare function useDAppKit<TDAppKit extends DAppKit<any> = RegisteredDAppKit>(dAppKit?: TDAppKit): TDAppKit;
|
|
@@ -43,7 +25,7 @@ type UseWalletsOptions<TDAppKit extends DAppKit> = {
|
|
|
43
25
|
};
|
|
44
26
|
declare function useWallets<TDAppKit extends DAppKit<any> = RegisteredDAppKit>({
|
|
45
27
|
dAppKit
|
|
46
|
-
}?: UseWalletsOptions<TDAppKit>):
|
|
28
|
+
}?: UseWalletsOptions<TDAppKit>): _mysten_dapp_kit_core0.UiWallet[];
|
|
47
29
|
//#endregion
|
|
48
30
|
//#region src/hooks/useWalletConnection.d.ts
|
|
49
31
|
type UseWalletConnectionOptions<TDAppKit extends DAppKit<any>> = {
|
|
@@ -52,8 +34,17 @@ type UseWalletConnectionOptions<TDAppKit extends DAppKit<any>> = {
|
|
|
52
34
|
declare function useWalletConnection<TDAppKit extends DAppKit = RegisteredDAppKit>({
|
|
53
35
|
dAppKit
|
|
54
36
|
}?: UseWalletConnectionOptions<TDAppKit>): {
|
|
55
|
-
readonly wallet:
|
|
56
|
-
readonly account:
|
|
37
|
+
readonly wallet: null;
|
|
38
|
+
readonly account: null;
|
|
39
|
+
readonly status: "disconnected";
|
|
40
|
+
readonly supportedIntents: readonly [];
|
|
41
|
+
readonly isConnected: false;
|
|
42
|
+
readonly isConnecting: false;
|
|
43
|
+
readonly isReconnecting: false;
|
|
44
|
+
readonly isDisconnected: true;
|
|
45
|
+
} | {
|
|
46
|
+
readonly wallet: _mysten_dapp_kit_core0.UiWallet;
|
|
47
|
+
readonly account: _mysten_dapp_kit_core0.UiWalletAccount;
|
|
57
48
|
readonly status: "connected";
|
|
58
49
|
readonly supportedIntents: string[];
|
|
59
50
|
readonly isConnected: true;
|
|
@@ -70,23 +61,14 @@ declare function useWalletConnection<TDAppKit extends DAppKit = RegisteredDAppKi
|
|
|
70
61
|
readonly isReconnecting: false;
|
|
71
62
|
readonly isDisconnected: false;
|
|
72
63
|
} | {
|
|
73
|
-
readonly wallet:
|
|
74
|
-
readonly account:
|
|
64
|
+
readonly wallet: _mysten_dapp_kit_core0.UiWallet;
|
|
65
|
+
readonly account: _mysten_dapp_kit_core0.UiWalletAccount;
|
|
75
66
|
readonly status: "reconnecting";
|
|
76
67
|
readonly supportedIntents: string[];
|
|
77
68
|
readonly isConnected: false;
|
|
78
69
|
readonly isConnecting: false;
|
|
79
70
|
readonly isReconnecting: true;
|
|
80
71
|
readonly isDisconnected: false;
|
|
81
|
-
} | {
|
|
82
|
-
readonly wallet: null;
|
|
83
|
-
readonly account: null;
|
|
84
|
-
readonly status: "disconnected";
|
|
85
|
-
readonly supportedIntents: readonly [];
|
|
86
|
-
readonly isConnected: false;
|
|
87
|
-
readonly isConnecting: false;
|
|
88
|
-
readonly isReconnecting: false;
|
|
89
|
-
readonly isDisconnected: true;
|
|
90
72
|
};
|
|
91
73
|
//#endregion
|
|
92
74
|
//#region src/hooks/useCurrentAccount.d.ts
|
|
@@ -95,7 +77,7 @@ type UseCurrentAccountOptions<TDAppKit extends DAppKit> = {
|
|
|
95
77
|
};
|
|
96
78
|
declare function useCurrentAccount<TDAppKit extends DAppKit<any> = RegisteredDAppKit>({
|
|
97
79
|
dAppKit
|
|
98
|
-
}?: UseCurrentAccountOptions<TDAppKit>):
|
|
80
|
+
}?: UseCurrentAccountOptions<TDAppKit>): _mysten_dapp_kit_core0.UiWalletAccount | null;
|
|
99
81
|
//#endregion
|
|
100
82
|
//#region src/hooks/useCurrentWallet.d.ts
|
|
101
83
|
type UseCurrentWalletOptions<TDAppKit extends DAppKit> = {
|
|
@@ -103,7 +85,7 @@ type UseCurrentWalletOptions<TDAppKit extends DAppKit> = {
|
|
|
103
85
|
};
|
|
104
86
|
declare function useCurrentWallet<TDAppKit extends DAppKit<any> = RegisteredDAppKit>({
|
|
105
87
|
dAppKit
|
|
106
|
-
}?: UseCurrentWalletOptions<TDAppKit>):
|
|
88
|
+
}?: UseCurrentWalletOptions<TDAppKit>): _mysten_dapp_kit_core0.UiWallet | null;
|
|
107
89
|
//#endregion
|
|
108
90
|
//#region src/hooks/useCurrentClient.d.ts
|
|
109
91
|
type UseCurrentClientOptions<TDAppKit extends DAppKit<any>> = {
|
|
@@ -121,5 +103,5 @@ declare function useCurrentNetwork<TDAppKit extends DAppKit<any> = RegisteredDAp
|
|
|
121
103
|
dAppKit
|
|
122
104
|
}?: UseCurrentNetworkOptions<TDAppKit>): nanostores0.StoreValue<TDAppKit["stores"]["$currentNetwork"]>;
|
|
123
105
|
//#endregion
|
|
124
|
-
export {
|
|
106
|
+
export { DAppKitContext, DAppKitProvider, type DAppKitProviderProps, useCurrentAccount, useCurrentClient, useCurrentNetwork, useCurrentWallet, useDAppKit, useWalletConnection, useWallets };
|
|
125
107
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/components/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/components/DAppKitProvider.tsx","../src/hooks/useDAppKit.ts","../src/hooks/useWallets.ts","../src/hooks/useWalletConnection.ts","../src/hooks/useCurrentAccount.ts","../src/hooks/useCurrentWallet.ts","../src/hooks/useCurrentClient.ts","../src/hooks/useCurrentNetwork.ts"],"sourcesContent":[],"mappings":";;;;;;;;;cAOa,gBAAc,MAAA,CAAA,QAAA,sBAAA,CAAA,aAAoD,sBAAA,CAApD,iBAAA;KAEf,oBAAA,GAAuB;WACzB;;iBAGM,eAAA;;;GAAuC,uBAAoB,kBAAA,CAAA,GAAA,CAAA;;;iBCN3D,4BAA4B,eAAe,6BAA6B,WAAQ;;;KCApF,mCAAmC;YACpC;;iBAGK,4BAA4B,eAAe;;IAExD,kBAAkB,YAAD,sBAAA,CAAe,QAAA;;;KCNvB,4CAA4C;YAC7C;;iBAGK,qCAAqC,UAAU;;IAE5D,2BAA2B;;;;;;EHNjB,SAAA,YAAkE,EAAA,KAAA;EAAA,SAAA,cAApD,EAAA,KAAA;EAAA,SAAA,cAAA,EAAA,IAAA;CAAA,GAAA;EAAA,SAAA,MAAA,EGME,sBAAA,CAAA,QHNF;EAEf,SAAA,OAAA,wCAAuB;EAInB,SAAA,MAAA,EAAA,WAAe;EAAG,SAAA,gBAAA,EAAA,MAAA,EAAA;EAAS,SAAA,WAAA,EAAA,IAAA;EAAY,SAAA,YAAA,EAAA,KAAA;EAAoB,SAAA,cAAA,EAAA,KAAA;EAAA,SAAA,cAAA,EAAA,KAAA;;;;ECN3D,SAAA,MAAU,EAAA,YAAA;EAAkB,SAAA,gBAAA,EAAA,SAAA,EAAA;EAAe,SAAA,WAAA,EAAA,KAAA;EAA6B,SAAA,YAAA,EAAA,IAAA;EAAQ,SAAA,cAAA,EAAA,KAAA;EAAA,SAAA,cAAA,EAAA,KAAA;;;;ECApF,SAAA,MAAA,EAAA,cAAiB;EAIb,SAAA,gBAAU,EAAA,MAAA,EAAA;EAAkB,SAAA,WAAA,EAAA,KAAA;EAAe,SAAA,YAAA,EAAA,KAAA;EAC1D,SAAA,cAAA,EAAA,IAAA;EACoB,SAAA,cAAA,EAAA,KAAA;CAAlB;;;KEPS,0CAA0C;YAC3C;;iBAGK,mCAAmC,eAAe;;IAE/D,yBAAyB,YAAD,sBAAA,CAAe,eAAA;;;KCN9B,yCAAyC;YAC1C;;iBAGK,kCAAkC,eAAe;;IAE9D,wBAAwB,YAAD,sBAAA,CAAe,QAAA;;;KCL7B,yCAAyC;YAC1C;;iBAGK,kCAAkC,eAAe;;IAE9D,wBAAwB,YAEyB,WAAW;;;KCRnD,0CAA0C;YAC3C;;iBAGK,mCAAmC,eAAe;;IAE/D,yBAAyB,YAAc,WAAA,CAAA,WAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,61 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createContext, useContext } from "react";
|
|
3
|
-
import { createComponent } from "@lit/react";
|
|
4
|
-
import { DAppKitConnectButton, DAppKitConnectModal } from "@mysten/dapp-kit-core/web";
|
|
5
|
-
import { jsx } from "react/jsx-runtime";
|
|
1
|
+
import { n as DAppKitContext, r as DAppKitProvider, t as useDAppKit } from "./useDAppKit-LUp-KcgG.mjs";
|
|
6
2
|
import { useStore } from "@nanostores/react";
|
|
7
3
|
|
|
8
4
|
export * from "@mysten/dapp-kit-core"
|
|
9
5
|
|
|
10
|
-
//#region src/components/DAppKitProvider.tsx
|
|
11
|
-
const DAppKitContext = createContext(null);
|
|
12
|
-
function DAppKitProvider({ dAppKit, children }) {
|
|
13
|
-
return /* @__PURE__ */ jsx(DAppKitContext.Provider, {
|
|
14
|
-
value: dAppKit,
|
|
15
|
-
children
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/hooks/useDAppKit.ts
|
|
21
|
-
function useDAppKit(dAppKit) {
|
|
22
|
-
const contextValue = useContext(DAppKitContext);
|
|
23
|
-
if (dAppKit) return dAppKit;
|
|
24
|
-
if (!contextValue) throw new Error("Could not find DAppKitContext. Ensure that you have set up the `DAppKitProvider` component.");
|
|
25
|
-
return contextValue;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region src/components/ConnectButton.tsx
|
|
30
|
-
const ConnectButtonComponent = createComponent({
|
|
31
|
-
react: React,
|
|
32
|
-
tagName: "mysten-dapp-kit-connect-button",
|
|
33
|
-
elementClass: DAppKitConnectButton
|
|
34
|
-
});
|
|
35
|
-
function ConnectButton({ instance, ...props }) {
|
|
36
|
-
const dAppKit = useDAppKit(instance);
|
|
37
|
-
return /* @__PURE__ */ jsx(ConnectButtonComponent, {
|
|
38
|
-
...props,
|
|
39
|
-
instance: dAppKit
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region src/components/ConnectModal.tsx
|
|
45
|
-
const ConnectModalComponent = createComponent({
|
|
46
|
-
react: React,
|
|
47
|
-
tagName: "mysten-dapp-kit-connect-modal",
|
|
48
|
-
elementClass: DAppKitConnectModal
|
|
49
|
-
});
|
|
50
|
-
function ConnectModal({ instance, ...props }) {
|
|
51
|
-
const dAppKit = useDAppKit(instance);
|
|
52
|
-
return /* @__PURE__ */ jsx(ConnectModalComponent, {
|
|
53
|
-
...props,
|
|
54
|
-
instance: dAppKit
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
6
|
//#region src/hooks/useWallets.ts
|
|
60
7
|
function useWallets({ dAppKit } = {}) {
|
|
61
8
|
return useStore(useDAppKit(dAppKit).stores.$wallets);
|
|
@@ -92,5 +39,5 @@ function useCurrentNetwork({ dAppKit } = {}) {
|
|
|
92
39
|
}
|
|
93
40
|
|
|
94
41
|
//#endregion
|
|
95
|
-
export {
|
|
42
|
+
export { DAppKitContext, DAppKitProvider, useCurrentAccount, useCurrentClient, useCurrentNetwork, useCurrentWallet, useDAppKit, useWalletConnection, useWallets };
|
|
96
43
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/hooks/useWallets.ts","../src/hooks/useWalletConnection.ts","../src/hooks/useCurrentAccount.ts","../src/hooks/useCurrentWallet.ts","../src/hooks/useCurrentClient.ts","../src/hooks/useCurrentNetwork.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { DAppKit, RegisteredDAppKit } from '@mysten/dapp-kit-core';\nimport { useStore } from '@nanostores/react';\nimport { useDAppKit } from './useDAppKit.js';\n\nexport type UseWalletsOptions<TDAppKit extends DAppKit> = {\n\tdAppKit?: TDAppKit;\n};\n\nexport function useWallets<TDAppKit extends DAppKit<any> = RegisteredDAppKit>({\n\tdAppKit,\n}: UseWalletsOptions<TDAppKit> = {}) {\n\tconst instance = useDAppKit(dAppKit);\n\treturn useStore(instance.stores.$wallets);\n}\n","// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { DAppKit, RegisteredDAppKit } from '@mysten/dapp-kit-core';\nimport { useStore } from '@nanostores/react';\nimport { useDAppKit } from './useDAppKit.js';\n\nexport type UseWalletConnectionOptions<TDAppKit extends DAppKit<any>> = {\n\tdAppKit?: TDAppKit;\n};\n\nexport function useWalletConnection<TDAppKit extends DAppKit = RegisteredDAppKit>({\n\tdAppKit,\n}: UseWalletConnectionOptions<TDAppKit> = {}) {\n\tconst instance = useDAppKit(dAppKit);\n\treturn useStore(instance.stores.$connection);\n}\n","// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { DAppKit, RegisteredDAppKit } from '@mysten/dapp-kit-core';\nimport { useWalletConnection } from './useWalletConnection.js';\n\nexport type UseCurrentAccountOptions<TDAppKit extends DAppKit> = {\n\tdAppKit?: TDAppKit;\n};\n\nexport function useCurrentAccount<TDAppKit extends DAppKit<any> = RegisteredDAppKit>({\n\tdAppKit,\n}: UseCurrentAccountOptions<TDAppKit> = {}) {\n\tconst connection = useWalletConnection({ dAppKit });\n\treturn connection.account;\n}\n","// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { DAppKit, RegisteredDAppKit } from '@mysten/dapp-kit-core';\nimport { useWalletConnection } from './useWalletConnection.js';\n\nexport type UseCurrentWalletOptions<TDAppKit extends DAppKit> = {\n\tdAppKit?: TDAppKit;\n};\n\nexport function useCurrentWallet<TDAppKit extends DAppKit<any> = RegisteredDAppKit>({\n\tdAppKit,\n}: UseCurrentWalletOptions<TDAppKit> = {}) {\n\tconst connection = useWalletConnection({ dAppKit });\n\treturn connection.wallet;\n}\n","// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { DAppKit, RegisteredDAppKit } from '@mysten/dapp-kit-core';\nimport { useStore } from '@nanostores/react';\nimport { useDAppKit } from './useDAppKit.js';\n\nexport type UseCurrentClientOptions<TDAppKit extends DAppKit<any>> = {\n\tdAppKit?: TDAppKit;\n};\n\nexport function useCurrentClient<TDAppKit extends DAppKit<any> = RegisteredDAppKit>({\n\tdAppKit,\n}: UseCurrentClientOptions<TDAppKit> = {}) {\n\tconst instance = useDAppKit(dAppKit);\n\treturn useStore(instance.stores.$currentClient) as ReturnType<TDAppKit['getClient']>;\n}\n","// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { DAppKit, RegisteredDAppKit } from '@mysten/dapp-kit-core';\nimport { useDAppKit } from './useDAppKit.js';\nimport { useStore } from '@nanostores/react';\n\nexport type UseCurrentNetworkOptions<TDAppKit extends DAppKit> = {\n\tdAppKit?: TDAppKit;\n};\n\nexport function useCurrentNetwork<TDAppKit extends DAppKit<any> = RegisteredDAppKit>({\n\tdAppKit,\n}: UseCurrentNetworkOptions<TDAppKit> = {}) {\n\tconst instance = useDAppKit(dAppKit);\n\treturn useStore<TDAppKit['stores']['$currentNetwork']>(instance.stores.$currentNetwork);\n}\n"],"mappings":";;;;;;AAWA,SAAgB,WAA8D,EAC7E,YACgC,EAAE,EAAE;AAEpC,QAAO,SADU,WAAW,QAAQ,CACX,OAAO,SAAS;;;;;ACJ1C,SAAgB,oBAAkE,EACjF,YACyC,EAAE,EAAE;AAE7C,QAAO,SADU,WAAW,QAAQ,CACX,OAAO,YAAY;;;;;ACL7C,SAAgB,kBAAqE,EACpF,YACuC,EAAE,EAAE;AAE3C,QADmB,oBAAoB,EAAE,SAAS,CAAC,CACjC;;;;;ACJnB,SAAgB,iBAAoE,EACnF,YACsC,EAAE,EAAE;AAE1C,QADmB,oBAAoB,EAAE,SAAS,CAAC,CACjC;;;;;ACHnB,SAAgB,iBAAoE,EACnF,YACsC,EAAE,EAAE;AAE1C,QAAO,SADU,WAAW,QAAQ,CACX,OAAO,eAAe;;;;;ACJhD,SAAgB,kBAAqE,EACpF,YACuC,EAAE,EAAE;AAE3C,QAAO,SADU,WAAW,QAAQ,CAC4B,OAAO,gBAAgB"}
|
package/dist/ui.d.mts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ComponentProps } from "react";
|
|
2
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
|
+
import * as _lit_react0 from "@lit/react";
|
|
4
|
+
import { DAppKitConnectButton, DAppKitConnectModal } from "@mysten/dapp-kit-core/web";
|
|
5
|
+
|
|
6
|
+
//#region src/components/ConnectButton.d.ts
|
|
7
|
+
type ConnectButtonProps = ComponentProps<typeof ConnectButtonComponent>;
|
|
8
|
+
declare const ConnectButtonComponent: _lit_react0.ReactWebComponent<DAppKitConnectButton, {}>;
|
|
9
|
+
declare function ConnectButton({
|
|
10
|
+
instance,
|
|
11
|
+
...props
|
|
12
|
+
}: ConnectButtonProps): react_jsx_runtime0.JSX.Element;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/components/ConnectModal.d.ts
|
|
15
|
+
type ConnectModalProps = ComponentProps<typeof ConnectModalComponent>;
|
|
16
|
+
declare const ConnectModalComponent: _lit_react0.ReactWebComponent<DAppKitConnectModal, {}>;
|
|
17
|
+
declare function ConnectModal({
|
|
18
|
+
instance,
|
|
19
|
+
...props
|
|
20
|
+
}: ConnectModalProps): react_jsx_runtime0.JSX.Element;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ConnectButton, type ConnectButtonProps, ConnectModal, type ConnectModalProps };
|
|
23
|
+
//# sourceMappingURL=ui.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.d.mts","names":[],"sources":["../src/components/ConnectButton.tsx","../src/components/ConnectModal.tsx"],"sourcesContent":[],"mappings":";;;;;;KASY,kBAAA,GAAqB,sBAAsB;cAEjD,wBAAsB,WAAA,CAAA,kBAAA;iBAMZ,aAAA;;;GAAsC,qBAAkB,kBAAA,CAAA,GAAA,CAAA;;;KCR5D,iBAAA,GAAoB,sBAAsB;cAEhD,uBAAqB,WAAA,CAAA,kBAAA;iBAMX,YAAA;;;GAAqC,oBAAiB,kBAAA,CAAA,GAAA,CAAA"}
|
package/dist/ui.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { t as useDAppKit } from "./useDAppKit-LUp-KcgG.mjs";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { createComponent } from "@lit/react";
|
|
5
|
+
import { DAppKitConnectButton, DAppKitConnectModal } from "@mysten/dapp-kit-core/web";
|
|
6
|
+
|
|
7
|
+
//#region src/components/ConnectButton.tsx
|
|
8
|
+
const ConnectButtonComponent = createComponent({
|
|
9
|
+
react: React,
|
|
10
|
+
tagName: "mysten-dapp-kit-connect-button",
|
|
11
|
+
elementClass: DAppKitConnectButton
|
|
12
|
+
});
|
|
13
|
+
function ConnectButton({ instance, ...props }) {
|
|
14
|
+
const dAppKit = useDAppKit(instance);
|
|
15
|
+
return /* @__PURE__ */ jsx(ConnectButtonComponent, {
|
|
16
|
+
...props,
|
|
17
|
+
instance: dAppKit
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/components/ConnectModal.tsx
|
|
23
|
+
const ConnectModalComponent = createComponent({
|
|
24
|
+
react: React,
|
|
25
|
+
tagName: "mysten-dapp-kit-connect-modal",
|
|
26
|
+
elementClass: DAppKitConnectModal
|
|
27
|
+
});
|
|
28
|
+
function ConnectModal({ instance, ...props }) {
|
|
29
|
+
const dAppKit = useDAppKit(instance);
|
|
30
|
+
return /* @__PURE__ */ jsx(ConnectModalComponent, {
|
|
31
|
+
...props,
|
|
32
|
+
instance: dAppKit
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { ConnectButton, ConnectModal };
|
|
38
|
+
//# sourceMappingURL=ui.mjs.map
|
package/dist/ui.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.mjs","names":["ConnectButtonElement","ConnectModalElement"],"sources":["../src/components/ConnectButton.tsx","../src/components/ConnectModal.tsx"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport * as React from 'react';\nimport { createComponent } from '@lit/react';\nimport { DAppKitConnectButton as ConnectButtonElement } from '@mysten/dapp-kit-core/web';\nimport { useDAppKit } from '../hooks/useDAppKit.js';\nimport type { ComponentProps } from 'react';\n\nexport type ConnectButtonProps = ComponentProps<typeof ConnectButtonComponent>;\n\nconst ConnectButtonComponent = createComponent({\n\treact: React,\n\ttagName: 'mysten-dapp-kit-connect-button',\n\telementClass: ConnectButtonElement,\n});\n\nexport function ConnectButton({ instance, ...props }: ConnectButtonProps) {\n\tconst dAppKit = useDAppKit(instance);\n\treturn <ConnectButtonComponent {...props} instance={dAppKit} />;\n}\n","// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport * as React from 'react';\nimport { createComponent } from '@lit/react';\nimport { DAppKitConnectModal as ConnectModalElement } from '@mysten/dapp-kit-core/web';\nimport { useDAppKit } from '../hooks/useDAppKit.js';\nimport type { ComponentProps } from 'react';\n\nexport type ConnectModalProps = ComponentProps<typeof ConnectModalComponent>;\n\nconst ConnectModalComponent = createComponent({\n\treact: React,\n\ttagName: 'mysten-dapp-kit-connect-modal',\n\telementClass: ConnectModalElement,\n});\n\nexport function ConnectModal({ instance, ...props }: ConnectModalProps) {\n\tconst dAppKit = useDAppKit(instance);\n\treturn <ConnectModalComponent {...props} instance={dAppKit} />;\n}\n"],"mappings":";;;;;;;AAWA,MAAM,yBAAyB,gBAAgB;CAC9C,OAAO;CACP,SAAS;CACT,cAAcA;CACd,CAAC;AAEF,SAAgB,cAAc,EAAE,UAAU,GAAG,SAA6B;CACzE,MAAM,UAAU,WAAW,SAAS;AACpC,QAAO,oBAAC;EAAuB,GAAI;EAAO,UAAU;GAAW;;;;;ACRhE,MAAM,wBAAwB,gBAAgB;CAC7C,OAAO;CACP,SAAS;CACT,cAAcC;CACd,CAAC;AAEF,SAAgB,aAAa,EAAE,UAAU,GAAG,SAA4B;CACvE,MAAM,UAAU,WAAW,SAAS;AACpC,QAAO,oBAAC;EAAsB,GAAI;EAAO,UAAU;GAAW"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/components/DAppKitProvider.tsx
|
|
5
|
+
const DAppKitContext = createContext(null);
|
|
6
|
+
function DAppKitProvider({ dAppKit, children }) {
|
|
7
|
+
return /* @__PURE__ */ jsx(DAppKitContext.Provider, {
|
|
8
|
+
value: dAppKit,
|
|
9
|
+
children
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/hooks/useDAppKit.ts
|
|
15
|
+
function useDAppKit(dAppKit) {
|
|
16
|
+
const contextValue = useContext(DAppKitContext);
|
|
17
|
+
if (dAppKit) return dAppKit;
|
|
18
|
+
if (!contextValue) throw new Error("Could not find DAppKitContext. Ensure that you have set up the `DAppKitProvider` component.");
|
|
19
|
+
return contextValue;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { DAppKitContext as n, DAppKitProvider as r, useDAppKit as t };
|
|
24
|
+
//# sourceMappingURL=useDAppKit-LUp-KcgG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDAppKit-LUp-KcgG.mjs","names":[],"sources":["../src/components/DAppKitProvider.tsx","../src/hooks/useDAppKit.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { DefaultExpectedDppKit } from '@mysten/dapp-kit-core';\nimport { createContext } from 'react';\nimport type { PropsWithChildren } from 'react';\n\nexport const DAppKitContext = createContext<DefaultExpectedDppKit | null>(null);\n\nexport type DAppKitProviderProps = PropsWithChildren<{\n\tdAppKit: DefaultExpectedDppKit;\n}>;\n\nexport function DAppKitProvider({ dAppKit, children }: DAppKitProviderProps) {\n\treturn <DAppKitContext.Provider value={dAppKit}>{children}</DAppKitContext.Provider>;\n}\n","// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useContext } from 'react';\nimport { DAppKitContext } from '../components/DAppKitProvider.js';\nimport type { DAppKit, RegisteredDAppKit } from '@mysten/dapp-kit-core';\n\nexport function useDAppKit<TDAppKit extends DAppKit<any> = RegisteredDAppKit>(dAppKit?: TDAppKit) {\n\tconst contextValue = useContext(DAppKitContext);\n\n\tif (dAppKit) {\n\t\treturn dAppKit;\n\t}\n\n\tif (!contextValue) {\n\t\tthrow new Error(\n\t\t\t'Could not find DAppKitContext. Ensure that you have set up the `DAppKitProvider` component.',\n\t\t);\n\t}\n\n\treturn contextValue as TDAppKit;\n}\n"],"mappings":";;;;AAOA,MAAa,iBAAiB,cAA4C,KAAK;AAM/E,SAAgB,gBAAgB,EAAE,SAAS,YAAkC;AAC5E,QAAO,oBAAC,eAAe;EAAS,OAAO;EAAU;GAAmC;;;;;ACPrF,SAAgB,WAA8D,SAAoB;CACjG,MAAM,eAAe,WAAW,eAAe;AAE/C,KAAI,QACH,QAAO;AAGR,KAAI,CAAC,aACJ,OAAM,IAAI,MACT,8FACA;AAGF,QAAO"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Connect Wallet
|
|
2
|
+
|
|
3
|
+
> Programmatically connect to a Sui wallet
|
|
4
|
+
|
|
5
|
+
The dApp Kit SDK provides an action for wallet connection, allowing users to connect, disconnect,
|
|
6
|
+
and switch between wallets and accounts.
|
|
7
|
+
|
|
8
|
+
> The [Connect Button](../web-components/connect-button) Web Component provides a complete wallet
|
|
9
|
+
> connection UI.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
> Auto-connect is enabled by default and will attempt to restore the previous wallet connection on
|
|
14
|
+
> page reload. This provides a seamless user experience but can be
|
|
15
|
+
> [disabled](../dapp-kit-instance#disabling-auto-connect) if needed.
|
|
16
|
+
|
|
17
|
+
The `connectWallet` action prompts a wallet to connect and authorize accounts for your application:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
const dAppKit = createDAppKit({
|
|
21
|
+
/* config */
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Connect to a specific wallet
|
|
25
|
+
const result = await dAppKit.connectWallet({
|
|
26
|
+
wallet: myWallet, // UiWallet instance
|
|
27
|
+
account: myAccount, // Optional: specific account to select
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log('Connected accounts:', result.accounts);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Parameters
|
|
34
|
+
|
|
35
|
+
- **`wallet`** - The `UiWallet` instance to connect to
|
|
36
|
+
- **`account`** (optional) - A specific `UiWalletAccount` to set as the selected account. Defaults
|
|
37
|
+
to the first authorized account
|
|
38
|
+
|
|
39
|
+
## Return Value
|
|
40
|
+
|
|
41
|
+
Returns a `Promise` that resolves to an object containing:
|
|
42
|
+
|
|
43
|
+
- **`accounts`** - Array of authorized `UiWalletAccount` instances
|
|
44
|
+
|
|
45
|
+
## Example
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
const wallets = dAppKit.stores.$wallets.get();
|
|
49
|
+
|
|
50
|
+
const unsubscribe = dAppKit.stores.$connection.subscribe((connection) => {
|
|
51
|
+
if (connection.isConnected) {
|
|
52
|
+
console.log(`Connected account address: ${connection.account.address}`);
|
|
53
|
+
} else {
|
|
54
|
+
console.log({ connection });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (wallets.length > 0) {
|
|
59
|
+
try {
|
|
60
|
+
const { accounts } = await dAppKit.connectWallet({
|
|
61
|
+
wallet: wallets[0],
|
|
62
|
+
});
|
|
63
|
+
console.log('Available accounts:', accounts);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error('Connection failed:', error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Disconnect Wallet
|
|
2
|
+
|
|
3
|
+
> Programmatically disconnect from a Sui wallet
|
|
4
|
+
|
|
5
|
+
The `disconnectWallet` action terminates the connection with the currently connected wallet.
|
|
6
|
+
|
|
7
|
+
> The [Connect Button](../web-components/connect-button) Web Component provides a complete wallet
|
|
8
|
+
> connection UI.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
> **Note:** The disconnect action clears the connection state locally and attempts to notify the
|
|
13
|
+
> wallet. Even if the wallet notification fails, the local state is always cleared to ensure a clean
|
|
14
|
+
> disconnection.
|
|
15
|
+
>
|
|
16
|
+
> Note that wallets may or may not implement the `disconnect` feature. Calling `disconnectWallet`
|
|
17
|
+
> doesn't necessarily mean that the wallet accounts will be disconnected from the dApp within the
|
|
18
|
+
> wallet itself - this is determined by each wallet's implementation.
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
const dAppKit = createDAppKit({
|
|
22
|
+
/* config */
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
await dAppKit.disconnectWallet();
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Parameters
|
|
29
|
+
|
|
30
|
+
None.
|
|
31
|
+
|
|
32
|
+
## Return Value
|
|
33
|
+
|
|
34
|
+
Returns a `Promise` that resolves to `void` when the disconnection is complete.
|
|
35
|
+
|
|
36
|
+
> The action may throw `WalletNotConnectedError` if no wallet is connected. However, wallet-specific
|
|
37
|
+
> disconnect failures are logged but don't prevent the local connection state from being cleared.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Sign and Execute Transaction
|
|
2
|
+
|
|
3
|
+
> Sign and execute a transaction using the connected wallet
|
|
4
|
+
|
|
5
|
+
The `signAndExecuteTransaction` action prompts the connected wallet to sign and immediately execute
|
|
6
|
+
a transaction on the Sui network. This is the most common way to execute transactions in your dApp.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
const dAppKit = createDAppKit({
|
|
12
|
+
/* config */
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const tx = new Transaction();
|
|
16
|
+
// No need to manually set sender - it's done automatically
|
|
17
|
+
tx.transferObjects([coinWithBalance({ balance: 123 })], '0xrecipient...');
|
|
18
|
+
|
|
19
|
+
const result = await dAppKit.signAndExecuteTransaction({
|
|
20
|
+
transaction: tx,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (result.FailedTransaction) {
|
|
24
|
+
throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log('Transaction digest:', result.Transaction.digest);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Parameters
|
|
31
|
+
|
|
32
|
+
- **`transaction`** - `Transaction | string` - The transaction to sign and execute. Can be either a
|
|
33
|
+
Transaction instance or base64-encoded bcs bytes for the transaction.
|
|
34
|
+
- **`signal`** (optional) - `AbortSignal` - An abort signal to cancel the transaction request.
|
|
35
|
+
|
|
36
|
+
## Return Value
|
|
37
|
+
|
|
38
|
+
Returns a `Promise` that resolves to a `TransactionResult` discriminated union:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
type TransactionResult =
|
|
42
|
+
| { $kind: 'Transaction'; Transaction: Transaction }
|
|
43
|
+
| { $kind: 'FailedTransaction'; FailedTransaction: Transaction };
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The `Transaction` object contains:
|
|
47
|
+
|
|
48
|
+
- **`digest`** - `string` - The transaction digest (unique identifier for the executed transaction)
|
|
49
|
+
- **`signatures`** - `string[]` - The signatures as base64-encoded strings
|
|
50
|
+
- **`epoch`** - `string | null` - The epoch in which the transaction was executed
|
|
51
|
+
- **`status`** - `ExecutionStatus` - The execution status with `success: boolean` and
|
|
52
|
+
`error: string | null`
|
|
53
|
+
- **`effects`** - `TransactionEffects | null` - The parsed transaction effects (may be `null` if
|
|
54
|
+
effects parsing fails for unknown effect versions)
|
|
55
|
+
- **`transaction`** - `TransactionData` - The parsed transaction data
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const result = await dAppKit.signAndExecuteTransaction({ transaction });
|
|
59
|
+
|
|
60
|
+
if (result.FailedTransaction) {
|
|
61
|
+
console.error('Transaction failed:', result.FailedTransaction.status.error?.message);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Access the successful transaction results
|
|
66
|
+
const tx = result.Transaction;
|
|
67
|
+
console.log('Digest:', tx.digest);
|
|
68
|
+
console.log('Signatures:', tx.signatures);
|
|
69
|
+
console.log('Epoch:', tx.epoch);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Transaction Building
|
|
73
|
+
|
|
74
|
+
When passing a Transaction instance, the action automatically:
|
|
75
|
+
|
|
76
|
+
1. Sets the sender address if not already set
|
|
77
|
+
2. Builds the transaction using the current network's client
|
|
78
|
+
3. Converts it to the appropriate format for the wallet
|
|
79
|
+
4. Submits the transaction to the network
|
|
80
|
+
|
|
81
|
+
## Wallet Compatibility
|
|
82
|
+
|
|
83
|
+
- The action transparently handles both `sui:signAndExecuteTransaction` and
|
|
84
|
+
`sui:signAndExecuteTransactionBlock` wallet-standard features
|
|
85
|
+
- The wallet handles network submission and response
|
|
86
|
+
- Some wallets (Enoki, Enoki Connect, WalletConnect) may use the dApp Kit client and execute
|
|
87
|
+
transactions within the application as an implementation detail
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
// The action automatically detects and uses the appropriate method
|
|
91
|
+
// No special configuration needed
|
|
92
|
+
const result = await dAppKit.signAndExecuteTransaction({
|
|
93
|
+
transaction: tx,
|
|
94
|
+
});
|
|
95
|
+
```
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Sign Personal Message
|
|
2
|
+
|
|
3
|
+
> Sign an arbitrary message with the connected wallet
|
|
4
|
+
|
|
5
|
+
The `signPersonalMessage` action prompts the connected wallet to sign a personal message. This is
|
|
6
|
+
useful for authentication, proof of ownership, or other scenarios where you need cryptographic proof
|
|
7
|
+
that a user controls a specific account.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
const dAppKit = createDAppKit({
|
|
13
|
+
/* config */
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const message = new TextEncoder().encode('Please sign this message');
|
|
17
|
+
const result = await dAppKit.signPersonalMessage({
|
|
18
|
+
message,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
console.log('Message bytes:', result.bytes);
|
|
22
|
+
console.log('Signature:', result.signature);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Parameters
|
|
26
|
+
|
|
27
|
+
- **`message`** - `Uint8Array` - The message to sign as a byte array
|
|
28
|
+
|
|
29
|
+
## Return Value
|
|
30
|
+
|
|
31
|
+
Returns a `Promise` that resolves to an object containing:
|
|
32
|
+
|
|
33
|
+
- **`bytes`** - `string` - Base64 encoded message bytes
|
|
34
|
+
- **`signature`** - `string` - Base64 encoded signature
|
|
35
|
+
|
|
36
|
+
## Message Format
|
|
37
|
+
|
|
38
|
+
The message parameter must be a `Uint8Array`. Common patterns for creating byte arrays:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const textMessage = new TextEncoder().encode('Hello, Sui!');
|
|
42
|
+
await dAppKit.signPersonalMessage({ message: textMessage });
|
|
43
|
+
|
|
44
|
+
const jsonMessage = new TextEncoder().encode(
|
|
45
|
+
JSON.stringify({ action: 'sign', timestamp: Date.now() }),
|
|
46
|
+
);
|
|
47
|
+
await dAppKit.signPersonalMessage({ message: jsonMessage });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Security Considerations
|
|
51
|
+
|
|
52
|
+
### Message Content
|
|
53
|
+
|
|
54
|
+
- Always display the message content clearly to users before signing
|
|
55
|
+
- Avoid signing opaque or encoded data that users cannot understand
|
|
56
|
+
- Include human-readable prefixes for different message types
|
|
57
|
+
- Consider adding timestamps to prevent replay attacks
|