@mysten-incubation/dev-wallet 0.0.0 → 0.2.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/CHANGELOG.md +32 -0
- package/LICENSE +189 -0
- package/dist/_virtual/{_@oxc-project_runtime@0.107.0 → _@oxc-project_runtime@0.127.0}/helpers/decorate.mjs +2 -3
- package/dist/adapters/base-adapter.mjs +6 -7
- package/dist/adapters/base-adapter.mjs.map +1 -1
- package/dist/adapters/browser.d.mts +4 -1
- package/dist/adapters/browser.mjs +4 -2
- package/dist/adapters/build-managed-account.mjs +8 -10
- package/dist/adapters/build-managed-account.mjs.map +1 -1
- package/dist/adapters/devstack-adapter.d.mts +111 -0
- package/dist/adapters/devstack-adapter.d.mts.map +1 -0
- package/dist/adapters/devstack-adapter.mjs +224 -0
- package/dist/adapters/devstack-adapter.mjs.map +1 -0
- package/dist/adapters/devstack-paths.d.mts +12 -0
- package/dist/adapters/devstack-paths.d.mts.map +1 -0
- package/dist/adapters/devstack-paths.mjs +12 -0
- package/dist/adapters/devstack-paths.mjs.map +1 -0
- package/dist/adapters/fork-relay.d.mts +109 -0
- package/dist/adapters/fork-relay.d.mts.map +1 -0
- package/dist/adapters/fork-relay.mjs +208 -0
- package/dist/adapters/fork-relay.mjs.map +1 -0
- package/dist/adapters/idb-store.mjs +12 -16
- package/dist/adapters/idb-store.mjs.map +1 -1
- package/dist/adapters/in-memory-adapter.mjs +4 -10
- package/dist/adapters/in-memory-adapter.mjs.map +1 -1
- package/dist/adapters/passkey-adapter.mjs +4 -12
- package/dist/adapters/passkey-adapter.mjs.map +1 -1
- package/dist/adapters/remote-cli-adapter.mjs +37 -72
- package/dist/adapters/remote-cli-adapter.mjs.map +1 -1
- package/dist/adapters/webcrypto-adapter.mjs +2 -4
- package/dist/adapters/webcrypto-adapter.mjs.map +1 -1
- package/dist/bin/cli.mjs +9 -22
- package/dist/bin/cli.mjs.map +1 -1
- package/dist/client/dev-wallet-client.mjs +13 -28
- package/dist/client/dev-wallet-client.mjs.map +1 -1
- package/dist/client/index.mjs +1 -2
- package/dist/client/request-handler.mjs +36 -42
- package/dist/client/request-handler.mjs.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/react/components.d.mts +9 -9
- package/dist/react/components.d.mts.map +1 -1
- package/dist/react/components.mjs +2 -5
- package/dist/react/components.mjs.map +1 -1
- package/dist/react/context.d.mts +3 -3
- package/dist/react/context.d.mts.map +1 -1
- package/dist/react/context.mjs +3 -8
- package/dist/react/context.mjs.map +1 -1
- package/dist/react/index.mjs +1 -2
- package/dist/react/useDevWallet.d.mts +3 -0
- package/dist/react/useDevWallet.d.mts.map +1 -1
- package/dist/react/useDevWallet.mjs +9 -14
- package/dist/react/useDevWallet.mjs.map +1 -1
- package/dist/server/cli-signing-middleware.mjs +7 -20
- package/dist/server/cli-signing-middleware.mjs.map +1 -1
- package/dist/server/index.mjs +1 -2
- package/dist/standalone/assets/{in-memory-adapter-CBF4h2KD.js → in-memory-adapter-qRkNfj9O.js} +1 -1
- package/dist/standalone/assets/main-DDltQnzR.js +3954 -0
- package/dist/standalone/assets/{webcrypto-adapter-DysAubFb.js → webcrypto-adapter-FejcrL9x.js} +1 -1
- package/dist/standalone/index.html +11 -12
- package/dist/ui/copy-controller.mjs +3 -3
- package/dist/ui/copy-controller.mjs.map +1 -1
- package/dist/ui/dev-wallet-account-selector.d.mts +3 -4
- package/dist/ui/dev-wallet-account-selector.d.mts.map +1 -1
- package/dist/ui/dev-wallet-account-selector.mjs +48 -25
- package/dist/ui/dev-wallet-account-selector.mjs.map +1 -1
- package/dist/ui/dev-wallet-accounts.d.mts +9 -4
- package/dist/ui/dev-wallet-accounts.d.mts.map +1 -1
- package/dist/ui/dev-wallet-accounts.mjs +62 -140
- package/dist/ui/dev-wallet-accounts.mjs.map +1 -1
- package/dist/ui/dev-wallet-balances.d.mts +10 -3
- package/dist/ui/dev-wallet-balances.d.mts.map +1 -1
- package/dist/ui/dev-wallet-balances.mjs +241 -43
- package/dist/ui/dev-wallet-balances.mjs.map +1 -1
- package/dist/ui/dev-wallet-connect.d.mts +3 -3
- package/dist/ui/dev-wallet-connect.d.mts.map +1 -1
- package/dist/ui/dev-wallet-connect.mjs +24 -16
- package/dist/ui/dev-wallet-connect.mjs.map +1 -1
- package/dist/ui/dev-wallet-dropdown.d.mts +3 -3
- package/dist/ui/dev-wallet-dropdown.d.mts.map +1 -1
- package/dist/ui/dev-wallet-dropdown.mjs +37 -47
- package/dist/ui/dev-wallet-dropdown.mjs.map +1 -1
- package/dist/ui/dev-wallet-fork-panel.d.mts +43 -0
- package/dist/ui/dev-wallet-fork-panel.d.mts.map +1 -0
- package/dist/ui/dev-wallet-fork-panel.mjs +500 -0
- package/dist/ui/dev-wallet-fork-panel.mjs.map +1 -0
- package/dist/ui/dev-wallet-network-badge.d.mts +3 -4
- package/dist/ui/dev-wallet-network-badge.d.mts.map +1 -1
- package/dist/ui/dev-wallet-network-badge.mjs +52 -21
- package/dist/ui/dev-wallet-network-badge.mjs.map +1 -1
- package/dist/ui/dev-wallet-new-account.d.mts +3 -4
- package/dist/ui/dev-wallet-new-account.d.mts.map +1 -1
- package/dist/ui/dev-wallet-new-account.mjs +31 -105
- package/dist/ui/dev-wallet-new-account.mjs.map +1 -1
- package/dist/ui/dev-wallet-objects.d.mts +3 -3
- package/dist/ui/dev-wallet-objects.d.mts.map +1 -1
- package/dist/ui/dev-wallet-objects.mjs +76 -39
- package/dist/ui/dev-wallet-objects.mjs.map +1 -1
- package/dist/ui/dev-wallet-panel.d.mts +24 -4
- package/dist/ui/dev-wallet-panel.d.mts.map +1 -1
- package/dist/ui/dev-wallet-panel.mjs +247 -64
- package/dist/ui/dev-wallet-panel.mjs.map +1 -1
- package/dist/ui/dev-wallet-popup.d.mts +3 -5
- package/dist/ui/dev-wallet-popup.d.mts.map +1 -1
- package/dist/ui/dev-wallet-popup.mjs +19 -15
- package/dist/ui/dev-wallet-popup.mjs.map +1 -1
- package/dist/ui/dev-wallet-settings.d.mts +3 -4
- package/dist/ui/dev-wallet-settings.d.mts.map +1 -1
- package/dist/ui/dev-wallet-settings.mjs +149 -97
- package/dist/ui/dev-wallet-settings.mjs.map +1 -1
- package/dist/ui/dev-wallet-signing-modal.d.mts +11 -4
- package/dist/ui/dev-wallet-signing-modal.d.mts.map +1 -1
- package/dist/ui/dev-wallet-signing-modal.mjs +46 -18
- package/dist/ui/dev-wallet-signing-modal.mjs.map +1 -1
- package/dist/ui/dev-wallet-signing.d.mts +9 -3
- package/dist/ui/dev-wallet-signing.d.mts.map +1 -1
- package/dist/ui/dev-wallet-signing.mjs +119 -130
- package/dist/ui/dev-wallet-signing.mjs.map +1 -1
- package/dist/ui/dev-wallet-standalone.d.mts +8 -3
- package/dist/ui/dev-wallet-standalone.d.mts.map +1 -1
- package/dist/ui/dev-wallet-standalone.mjs +303 -38
- package/dist/ui/dev-wallet-standalone.mjs.map +1 -1
- package/dist/ui/dev-wallet-tab-bar.d.mts +13 -5
- package/dist/ui/dev-wallet-tab-bar.d.mts.map +1 -1
- package/dist/ui/dev-wallet-tab-bar.mjs +143 -82
- package/dist/ui/dev-wallet-tab-bar.mjs.map +1 -1
- package/dist/ui/index.d.mts +3 -2
- package/dist/ui/index.mjs +2 -2
- package/dist/ui/mount.d.mts +14 -1
- package/dist/ui/mount.d.mts.map +1 -1
- package/dist/ui/mount.mjs +5 -2
- package/dist/ui/mount.mjs.map +1 -1
- package/dist/ui/styles.mjs +428 -66
- package/dist/ui/styles.mjs.map +1 -1
- package/dist/ui/transaction-analyzer.mjs +19 -30
- package/dist/ui/transaction-analyzer.mjs.map +1 -1
- package/dist/ui/utils.d.mts +59 -0
- package/dist/ui/utils.d.mts.map +1 -0
- package/dist/ui/utils.mjs +42 -15
- package/dist/ui/utils.mjs.map +1 -1
- package/dist/ui/wallet-controller.mjs +89 -20
- package/dist/ui/wallet-controller.mjs.map +1 -1
- package/dist/wallet/constants.d.mts +9 -0
- package/dist/wallet/constants.d.mts.map +1 -0
- package/dist/wallet/constants.mjs +1 -1
- package/dist/wallet/dev-wallet.mjs +42 -99
- package/dist/wallet/dev-wallet.mjs.map +1 -1
- package/dist/wallet/initializer.d.mts +3 -0
- package/dist/wallet/initializer.d.mts.map +1 -1
- package/dist/wallet/initializer.mjs +9 -14
- package/dist/wallet/initializer.mjs.map +1 -1
- package/dist/wallet/signing.mjs +8 -21
- package/dist/wallet/signing.mjs.map +1 -1
- package/package.json +125 -123
- package/src/adapters/browser.ts +21 -0
- package/src/adapters/devstack-adapter.ts +342 -0
- package/src/adapters/devstack-paths.ts +16 -0
- package/src/adapters/fork-relay.ts +321 -0
- package/src/app/index.html +10 -11
- package/src/react/useDevWallet.ts +5 -1
- package/src/ui/dev-wallet-account-selector.ts +44 -17
- package/src/ui/dev-wallet-accounts.ts +87 -124
- package/src/ui/dev-wallet-balances.ts +248 -27
- package/src/ui/dev-wallet-connect.ts +19 -8
- package/src/ui/dev-wallet-dropdown.ts +7 -5
- package/src/ui/dev-wallet-fork-panel.ts +591 -0
- package/src/ui/dev-wallet-network-badge.ts +49 -10
- package/src/ui/dev-wallet-new-account.ts +21 -62
- package/src/ui/dev-wallet-objects.ts +59 -19
- package/src/ui/dev-wallet-panel.ts +261 -42
- package/src/ui/dev-wallet-popup.ts +12 -6
- package/src/ui/dev-wallet-settings.ts +159 -94
- package/src/ui/dev-wallet-signing-modal.ts +47 -7
- package/src/ui/dev-wallet-signing.ts +124 -97
- package/src/ui/dev-wallet-standalone.ts +310 -22
- package/src/ui/dev-wallet-tab-bar.ts +132 -70
- package/src/ui/index.ts +3 -0
- package/src/ui/mount.ts +23 -1
- package/src/ui/styles.ts +434 -58
- package/src/ui/utils.ts +66 -0
- package/src/ui/wallet-controller.ts +103 -5
- package/src/wallet/initializer.ts +7 -1
- package/dist/standalone/assets/main-VE4olb-Q.js +0 -2841
package/dist/react/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useDevWallet } from "./useDevWallet.mjs";
|
|
2
2
|
import { DevWalletContext, DevWalletProvider, useDevWalletInstance } from "./context.mjs";
|
|
3
3
|
import { DevWalletAccounts, DevWalletBalances, DevWalletNewAccount, DevWalletPanel, DevWalletSigning } from "./components.mjs";
|
|
4
|
-
|
|
5
|
-
export { DevWalletAccounts, DevWalletBalances, DevWalletContext, DevWalletNewAccount, DevWalletPanel, DevWalletProvider, DevWalletSigning, useDevWallet, useDevWalletInstance };
|
|
4
|
+
export { DevWalletAccounts, DevWalletBalances, DevWalletContext, DevWalletNewAccount, DevWalletPanel, DevWalletProvider, DevWalletSigning, useDevWallet, useDevWalletInstance };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DevWallet, DevWalletConfig } from "../wallet/dev-wallet.mjs";
|
|
2
|
+
import { DevWalletDockStyle } from "../ui/dev-wallet-panel.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/react/useDevWallet.d.ts
|
|
4
5
|
interface UseDevWalletOptions extends DevWalletConfig {
|
|
@@ -8,6 +9,8 @@ interface UseDevWalletOptions extends DevWalletConfig {
|
|
|
8
9
|
createInitialAccount?: boolean;
|
|
9
10
|
/** Whether to mount the floating wallet drawer UI. Defaults to true. */
|
|
10
11
|
mountUI?: boolean;
|
|
12
|
+
/** Floating dock presentation when `mountUI` is true. Defaults to `corner-pill`. */
|
|
13
|
+
dockStyle?: DevWalletDockStyle;
|
|
11
14
|
/** Container element for the UI drawer. Defaults to document.body. */
|
|
12
15
|
container?: HTMLElement;
|
|
13
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDevWallet.d.mts","names":[],"sources":["../../src/react/useDevWallet.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDevWallet.d.mts","names":[],"sources":["../../src/react/useDevWallet.ts"],"mappings":";;;;UASiB,mBAAA,SAA4B,eAAA;;EAE5C,cAAA;EAFoC;EAIpC,oBAAA;EAIY;EAFZ,OAAA;EAN4C;EAQ5C,SAAA,GAAY,kBAAA;EAR+C;EAU3D,SAAA,GAAY,WAAA;AAAA;AAAA,UAGI,kBAAA;EAChB,MAAA,EAAQ,SAAA;EANR;EAQA,KAAA,EAAO,KAAA;EANP;EAQA,OAAA;AAAA;;AALD;;;;;;;;;;;AAsBA;;iBAAgB,YAAA,CAAa,OAAA,EAAS,mBAAA,GAAsB,kBAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DevWallet } from "../wallet/dev-wallet.mjs";
|
|
2
2
|
import { mountDevWallet } from "../ui/mount.mjs";
|
|
3
3
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
-
|
|
5
4
|
//#region src/react/useDevWallet.ts
|
|
6
5
|
/**
|
|
7
6
|
* React hook that initializes a DevWallet, registers it with the wallet-standard
|
|
@@ -24,7 +23,7 @@ function useDevWallet(options) {
|
|
|
24
23
|
const optionsRef = useRef(options);
|
|
25
24
|
optionsRef.current = options;
|
|
26
25
|
useEffect(() => {
|
|
27
|
-
const { autoInitialize = true, createInitialAccount = true, mountUI = true, container, ...walletConfig } = optionsRef.current;
|
|
26
|
+
const { autoInitialize = true, createInitialAccount = true, mountUI = true, dockStyle, container, ...walletConfig } = optionsRef.current;
|
|
28
27
|
let cancelled = false;
|
|
29
28
|
let unregister;
|
|
30
29
|
let unmountUI;
|
|
@@ -37,24 +36,20 @@ function useDevWallet(options) {
|
|
|
37
36
|
return;
|
|
38
37
|
}
|
|
39
38
|
async function setup() {
|
|
40
|
-
if (autoInitialize)
|
|
41
|
-
await Promise.all(walletConfig.adapters.map((a) => a.initialize()));
|
|
42
|
-
}
|
|
39
|
+
if (autoInitialize) await Promise.all(walletConfig.adapters.map((a) => a.initialize()));
|
|
43
40
|
if (cancelled) return;
|
|
44
41
|
if (createInitialAccount) {
|
|
45
|
-
|
|
46
|
-
if (!hasAccounts) {
|
|
42
|
+
if (!walletConfig.adapters.some((a) => a.getAccounts().length > 0)) {
|
|
47
43
|
const creatableAdapter = walletConfig.adapters.find((a) => a.createAccount && a.getAccounts().length === 0);
|
|
48
|
-
if (creatableAdapter?.createAccount) {
|
|
49
|
-
await creatableAdapter.createAccount({ label: "Dev Account" });
|
|
50
|
-
}
|
|
44
|
+
if (creatableAdapter?.createAccount) await creatableAdapter.createAccount({ label: "Dev Account" });
|
|
51
45
|
}
|
|
52
46
|
}
|
|
53
47
|
if (cancelled) return;
|
|
54
48
|
unregister = devWallet.register();
|
|
55
|
-
if (mountUI && typeof document !== "undefined") {
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
if (mountUI && typeof document !== "undefined") unmountUI = mountDevWallet(devWallet, {
|
|
50
|
+
container,
|
|
51
|
+
dockStyle
|
|
52
|
+
});
|
|
58
53
|
if (!cancelled) {
|
|
59
54
|
setWallet(devWallet);
|
|
60
55
|
setLoading(false);
|
|
@@ -83,7 +78,7 @@ function useDevWallet(options) {
|
|
|
83
78
|
loading
|
|
84
79
|
]);
|
|
85
80
|
}
|
|
86
|
-
|
|
87
81
|
//#endregion
|
|
88
82
|
export { useDevWallet };
|
|
83
|
+
|
|
89
84
|
//# sourceMappingURL=useDevWallet.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDevWallet.mjs","names":[],"sources":["../../src/react/useDevWallet.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\n\nimport { mountDevWallet } from '../ui/mount.js';\nimport { DevWallet, type DevWalletConfig } from '../wallet/dev-wallet.js';\n\nexport interface UseDevWalletOptions extends DevWalletConfig {\n\t/** Whether to call adapter.initialize() automatically. Defaults to true. */\n\tautoInitialize?: boolean;\n\t/** Whether to create an initial account after initialization (if adapter supports it). Defaults to true. */\n\tcreateInitialAccount?: boolean;\n\t/** Whether to mount the floating wallet drawer UI. Defaults to true. */\n\tmountUI?: boolean;\n\t/** Container element for the UI drawer. Defaults to document.body. */\n\tcontainer?: HTMLElement;\n}\n\nexport interface UseDevWalletResult {\n\twallet: DevWallet | null;\n\t/** Initialization error, if any (e.g. IndexedDB quota exceeded, adapter failure). */\n\terror: Error | null;\n\t/** True while the wallet is being initialized. */\n\tloading: boolean;\n}\n\n/**\n * React hook that initializes a DevWallet, registers it with the wallet-standard\n * registry, and optionally mounts the wallet drawer UI.\n *\n * The adapters are captured on first render and used for the wallet's\n * lifetime. Pass stable references (created outside the component or via useMemo).\n *\n * @example\n * ```tsx\n * const adapters = useMemo(() => [new InMemorySignerAdapter()], []);\n *\n * const wallet = useDevWallet({ adapters, networks: { devnet: 'https://fullnode.devnet.sui.io:443' } });\n * ```\n */\nexport function useDevWallet(options: UseDevWalletOptions): UseDevWalletResult {\n\tconst [wallet, setWallet] = useState<DevWallet | null>(null);\n\tconst [error, setError] = useState<Error | null>(null);\n\tconst [loading, setLoading] = useState(true);\n\tconst optionsRef = useRef(options);\n\toptionsRef.current = options;\n\n\tuseEffect(() => {\n\t\tconst {\n\t\t\tautoInitialize = true,\n\t\t\tcreateInitialAccount = true,\n\t\t\tmountUI = true,\n\t\t\tcontainer,\n\t\t\t...walletConfig\n\t\t} = optionsRef.current;\n\n\t\tlet cancelled = false;\n\t\tlet unregister: (() => void) | undefined;\n\t\tlet unmountUI: (() => void) | undefined;\n\n\t\tlet devWallet: DevWallet;\n\t\ttry {\n\t\t\tdevWallet = new DevWallet(walletConfig);\n\t\t} catch (err) {\n\t\t\tsetError(err instanceof Error ? err : new Error(String(err)));\n\t\t\tsetLoading(false);\n\t\t\treturn;\n\t\t}\n\n\t\tasync function setup() {\n\t\t\tif (autoInitialize) {\n\t\t\t\tawait Promise.all(walletConfig.adapters.map((a) => a.initialize()));\n\t\t\t}\n\t\t\tif (cancelled) return;\n\n\t\t\tif (createInitialAccount) {\n\t\t\t\tconst hasAccounts = walletConfig.adapters.some((a) => a.getAccounts().length > 0);\n\t\t\t\tif (!hasAccounts) {\n\t\t\t\t\tconst creatableAdapter = walletConfig.adapters.find(\n\t\t\t\t\t\t(a) => a.createAccount && a.getAccounts().length === 0,\n\t\t\t\t\t);\n\t\t\t\t\tif (creatableAdapter?.createAccount) {\n\t\t\t\t\t\tawait creatableAdapter.createAccount({ label: 'Dev Account' });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (cancelled) return;\n\n\t\t\tunregister = devWallet.register();\n\n\t\t\tif (mountUI && typeof document !== 'undefined') {\n\t\t\t\tunmountUI = mountDevWallet(devWallet, { container });\n\t\t\t}\n\n\t\t\tif (!cancelled) {\n\t\t\t\tsetWallet(devWallet);\n\t\t\t\tsetLoading(false);\n\t\t\t}\n\t\t}\n\n\t\tsetup().catch((err) => {\n\t\t\tif (!cancelled) {\n\t\t\t\tsetError(err instanceof Error ? err : new Error(String(err)));\n\t\t\t\tsetLoading(false);\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t\tunmountUI?.();\n\t\t\tunregister?.();\n\t\t\tdevWallet.destroy();\n\t\t};\n\t}, []); // eslint-disable-line react-hooks/exhaustive-deps\n\n\treturn useMemo(() => ({ wallet, error, loading }), [wallet, error, loading]);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDevWallet.mjs","names":[],"sources":["../../src/react/useDevWallet.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\n\nimport { mountDevWallet } from '../ui/mount.js';\nimport type { DevWalletDockStyle } from '../ui/dev-wallet-panel.js';\nimport { DevWallet, type DevWalletConfig } from '../wallet/dev-wallet.js';\n\nexport interface UseDevWalletOptions extends DevWalletConfig {\n\t/** Whether to call adapter.initialize() automatically. Defaults to true. */\n\tautoInitialize?: boolean;\n\t/** Whether to create an initial account after initialization (if adapter supports it). Defaults to true. */\n\tcreateInitialAccount?: boolean;\n\t/** Whether to mount the floating wallet drawer UI. Defaults to true. */\n\tmountUI?: boolean;\n\t/** Floating dock presentation when `mountUI` is true. Defaults to `corner-pill`. */\n\tdockStyle?: DevWalletDockStyle;\n\t/** Container element for the UI drawer. Defaults to document.body. */\n\tcontainer?: HTMLElement;\n}\n\nexport interface UseDevWalletResult {\n\twallet: DevWallet | null;\n\t/** Initialization error, if any (e.g. IndexedDB quota exceeded, adapter failure). */\n\terror: Error | null;\n\t/** True while the wallet is being initialized. */\n\tloading: boolean;\n}\n\n/**\n * React hook that initializes a DevWallet, registers it with the wallet-standard\n * registry, and optionally mounts the wallet drawer UI.\n *\n * The adapters are captured on first render and used for the wallet's\n * lifetime. Pass stable references (created outside the component or via useMemo).\n *\n * @example\n * ```tsx\n * const adapters = useMemo(() => [new InMemorySignerAdapter()], []);\n *\n * const wallet = useDevWallet({ adapters, networks: { devnet: 'https://fullnode.devnet.sui.io:443' } });\n * ```\n */\nexport function useDevWallet(options: UseDevWalletOptions): UseDevWalletResult {\n\tconst [wallet, setWallet] = useState<DevWallet | null>(null);\n\tconst [error, setError] = useState<Error | null>(null);\n\tconst [loading, setLoading] = useState(true);\n\tconst optionsRef = useRef(options);\n\toptionsRef.current = options;\n\n\tuseEffect(() => {\n\t\tconst {\n\t\t\tautoInitialize = true,\n\t\t\tcreateInitialAccount = true,\n\t\t\tmountUI = true,\n\t\t\tdockStyle,\n\t\t\tcontainer,\n\t\t\t...walletConfig\n\t\t} = optionsRef.current;\n\n\t\tlet cancelled = false;\n\t\tlet unregister: (() => void) | undefined;\n\t\tlet unmountUI: (() => void) | undefined;\n\n\t\tlet devWallet: DevWallet;\n\t\ttry {\n\t\t\tdevWallet = new DevWallet(walletConfig);\n\t\t} catch (err) {\n\t\t\tsetError(err instanceof Error ? err : new Error(String(err)));\n\t\t\tsetLoading(false);\n\t\t\treturn;\n\t\t}\n\n\t\tasync function setup() {\n\t\t\tif (autoInitialize) {\n\t\t\t\tawait Promise.all(walletConfig.adapters.map((a) => a.initialize()));\n\t\t\t}\n\t\t\tif (cancelled) return;\n\n\t\t\tif (createInitialAccount) {\n\t\t\t\tconst hasAccounts = walletConfig.adapters.some((a) => a.getAccounts().length > 0);\n\t\t\t\tif (!hasAccounts) {\n\t\t\t\t\tconst creatableAdapter = walletConfig.adapters.find(\n\t\t\t\t\t\t(a) => a.createAccount && a.getAccounts().length === 0,\n\t\t\t\t\t);\n\t\t\t\t\tif (creatableAdapter?.createAccount) {\n\t\t\t\t\t\tawait creatableAdapter.createAccount({ label: 'Dev Account' });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (cancelled) return;\n\n\t\t\tunregister = devWallet.register();\n\n\t\t\tif (mountUI && typeof document !== 'undefined') {\n\t\t\t\tunmountUI = mountDevWallet(devWallet, { container, dockStyle });\n\t\t\t}\n\n\t\t\tif (!cancelled) {\n\t\t\t\tsetWallet(devWallet);\n\t\t\t\tsetLoading(false);\n\t\t\t}\n\t\t}\n\n\t\tsetup().catch((err) => {\n\t\t\tif (!cancelled) {\n\t\t\t\tsetError(err instanceof Error ? err : new Error(String(err)));\n\t\t\t\tsetLoading(false);\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t\tunmountUI?.();\n\t\t\tunregister?.();\n\t\t\tdevWallet.destroy();\n\t\t};\n\t}, []); // eslint-disable-line react-hooks/exhaustive-deps\n\n\treturn useMemo(() => ({ wallet, error, loading }), [wallet, error, loading]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4CA,SAAgB,aAAa,SAAkD;CAC9E,MAAM,CAAC,QAAQ,aAAa,SAA2B,KAAK;CAC5D,MAAM,CAAC,OAAO,YAAY,SAAuB,KAAK;CACtD,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,aAAa,OAAO,QAAQ;AAClC,YAAW,UAAU;AAErB,iBAAgB;EACf,MAAM,EACL,iBAAiB,MACjB,uBAAuB,MACvB,UAAU,MACV,WACA,WACA,GAAG,iBACA,WAAW;EAEf,IAAI,YAAY;EAChB,IAAI;EACJ,IAAI;EAEJ,IAAI;AACJ,MAAI;AACH,eAAY,IAAI,UAAU,aAAa;WAC/B,KAAK;AACb,YAAS,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,IAAI,CAAC,CAAC;AAC7D,cAAW,MAAM;AACjB;;EAGD,eAAe,QAAQ;AACtB,OAAI,eACH,OAAM,QAAQ,IAAI,aAAa,SAAS,KAAK,MAAM,EAAE,YAAY,CAAC,CAAC;AAEpE,OAAI,UAAW;AAEf,OAAI,sBAEH;QAAI,CADgB,aAAa,SAAS,MAAM,MAAM,EAAE,aAAa,CAAC,SAAS,EAC1E,EAAa;KACjB,MAAM,mBAAmB,aAAa,SAAS,MAC7C,MAAM,EAAE,iBAAiB,EAAE,aAAa,CAAC,WAAW,EACrD;AACD,SAAI,kBAAkB,cACrB,OAAM,iBAAiB,cAAc,EAAE,OAAO,eAAe,CAAC;;;AAIjE,OAAI,UAAW;AAEf,gBAAa,UAAU,UAAU;AAEjC,OAAI,WAAW,OAAO,aAAa,YAClC,aAAY,eAAe,WAAW;IAAE;IAAW;IAAW,CAAC;AAGhE,OAAI,CAAC,WAAW;AACf,cAAU,UAAU;AACpB,eAAW,MAAM;;;AAInB,SAAO,CAAC,OAAO,QAAQ;AACtB,OAAI,CAAC,WAAW;AACf,aAAS,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,IAAI,CAAC,CAAC;AAC7D,eAAW,MAAM;;IAEjB;AAEF,eAAa;AACZ,eAAY;AACZ,gBAAa;AACb,iBAAc;AACd,aAAU,SAAS;;IAElB,EAAE,CAAC;AAEN,QAAO,eAAe;EAAE;EAAQ;EAAO;EAAS,GAAG;EAAC;EAAQ;EAAO;EAAQ,CAAC"}
|
|
@@ -3,7 +3,6 @@ import { execFile } from "node:child_process";
|
|
|
3
3
|
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
import { Hono } from "hono";
|
|
6
|
-
|
|
7
6
|
//#region src/server/cli-signing-middleware.ts
|
|
8
7
|
const execFileAsync = promisify(execFile);
|
|
9
8
|
function isValidBase64(value) {
|
|
@@ -39,15 +38,11 @@ function createCliSigningMiddleware(options) {
|
|
|
39
38
|
`127.0.0.1:${port}`,
|
|
40
39
|
`[::1]:${port}`
|
|
41
40
|
]);
|
|
42
|
-
if (host && !allowedHosts.has(host)) {
|
|
43
|
-
return c.json({ error: "Requests must originate from localhost." }, 403);
|
|
44
|
-
}
|
|
41
|
+
if (host && !allowedHosts.has(host)) return c.json({ error: "Requests must originate from localhost." }, 403);
|
|
45
42
|
return await next();
|
|
46
43
|
});
|
|
47
44
|
app.use("/api/*", async (c, next) => {
|
|
48
|
-
if (!isAuthenticated(c.req.header("authorization"))) {
|
|
49
|
-
return c.json({ error: "Authentication required. Open the token URL from the terminal." }, 401);
|
|
50
|
-
}
|
|
45
|
+
if (!isAuthenticated(c.req.header("authorization"))) return c.json({ error: "Authentication required. Open the token URL from the terminal." }, 401);
|
|
51
46
|
return await next();
|
|
52
47
|
});
|
|
53
48
|
app.get("/api/v1/accounts", async (c) => {
|
|
@@ -67,21 +62,15 @@ function createCliSigningMiddleware(options) {
|
|
|
67
62
|
});
|
|
68
63
|
app.post("/api/v1/sign-transaction", async (c) => {
|
|
69
64
|
const contentLength = c.req.header("content-length");
|
|
70
|
-
if (contentLength && parseInt(contentLength, 10) > MAX_BODY_SIZE) {
|
|
71
|
-
return c.json({ error: "Request body too large" }, 413);
|
|
72
|
-
}
|
|
65
|
+
if (contentLength && parseInt(contentLength, 10) > MAX_BODY_SIZE) return c.json({ error: "Request body too large" }, 413);
|
|
73
66
|
let body;
|
|
74
67
|
try {
|
|
75
68
|
body = await c.req.json();
|
|
76
69
|
} catch {
|
|
77
70
|
return c.json({ error: "Invalid JSON body" }, 400);
|
|
78
71
|
}
|
|
79
|
-
if (typeof body.address !== "string" || !isValidSuiAddress(body.address)) {
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
if (!isValidBase64(body.txBytes)) {
|
|
83
|
-
return c.json({ error: "Invalid txBytes. Expected non-empty base64 string." }, 400);
|
|
84
|
-
}
|
|
72
|
+
if (typeof body.address !== "string" || !isValidSuiAddress(body.address)) return c.json({ error: "Invalid address format. Expected 0x-prefixed hex." }, 400);
|
|
73
|
+
if (!isValidBase64(body.txBytes)) return c.json({ error: "Invalid txBytes. Expected non-empty base64 string." }, 400);
|
|
85
74
|
try {
|
|
86
75
|
const { stdout } = await execFileAsync("sui", [
|
|
87
76
|
"keytool",
|
|
@@ -100,9 +89,7 @@ function createCliSigningMiddleware(options) {
|
|
|
100
89
|
} catch (err) {
|
|
101
90
|
const message = err instanceof Error ? err.message : String(err);
|
|
102
91
|
console.error("[dev-wallet] CLI signing error:", message);
|
|
103
|
-
if (message.includes("not found") || message.includes("Cannot find key")) {
|
|
104
|
-
return c.json({ error: `Address not found in keystore: ${body.address}` }, 404);
|
|
105
|
-
}
|
|
92
|
+
if (message.includes("not found") || message.includes("Cannot find key")) return c.json({ error: `Address not found in keystore: ${body.address}` }, 404);
|
|
106
93
|
return c.json({ error: "Signing failed due to a CLI error." }, 500);
|
|
107
94
|
}
|
|
108
95
|
});
|
|
@@ -111,7 +98,7 @@ function createCliSigningMiddleware(options) {
|
|
|
111
98
|
token
|
|
112
99
|
};
|
|
113
100
|
}
|
|
114
|
-
|
|
115
101
|
//#endregion
|
|
116
102
|
export { createCliSigningMiddleware };
|
|
103
|
+
|
|
117
104
|
//# sourceMappingURL=cli-signing-middleware.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-signing-middleware.mjs","names":[],"sources":["../../src/server/cli-signing-middleware.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { execFile } from 'node:child_process';\nimport { randomBytes, timingSafeEqual } from 'node:crypto';\nimport { promisify } from 'node:util';\n\nimport { isValidSuiAddress } from '@mysten/sui/utils';\nimport { Hono } from 'hono';\n\nconst execFileAsync = promisify(execFile);\n\nfunction isValidBase64(value: unknown): value is string {\n\tif (typeof value !== 'string' || value.length === 0) return false;\n\treturn /^[A-Za-z0-9+/]+=*$/.test(value) && value.length <= 1_000_000;\n}\n\nconst MAX_BODY_SIZE = 2 * 1024 * 1024; // 2 MB\n\nfunction generateToken(): string {\n\treturn randomBytes(32).toString('hex');\n}\n\nexport interface CliSigningMiddlewareOptions {\n\t/** The port the server is listening on, used for DNS rebinding protection. */\n\tport: number;\n}\n\nexport interface CliSigningMiddlewareResult {\n\tapp: Hono;\n\ttoken: string;\n}\n\n/**\n * Create a Hono sub-app that exposes signing endpoints backed by the `sui` CLI.\n *\n * Uses token-in-URL auth: a 256-bit random token is embedded in the URL printed\n * to the terminal and sent as `Authorization: Bearer <token>` on subsequent requests.\n * All CLI calls use `execFile` to prevent shell injection.\n */\nexport function createCliSigningMiddleware(\n\toptions: CliSigningMiddlewareOptions,\n): CliSigningMiddlewareResult {\n\tconst { port } = options;\n\tconst token = generateToken();\n\n\tfunction isAuthenticated(authHeader: string | undefined): boolean {\n\t\tif (!token) return false;\n\t\tif (!authHeader || !/^bearer /i.test(authHeader)) return false;\n\t\tconst provided = authHeader.slice(7);\n\t\tif (provided.length !== token.length) return false;\n\t\treturn timingSafeEqual(Buffer.from(provided), Buffer.from(token));\n\t}\n\n\tconst app = new Hono();\n\n\t// DNS rebinding protection — reject non-localhost hosts\n\tapp.use('*', async (c, next) => {\n\t\tconst host = c.req.header('host') ?? '';\n\t\tconst allowedHosts = new Set([`localhost:${port}`, `127.0.0.1:${port}`, `[::1]:${port}`]);\n\t\tif (host && !allowedHosts.has(host)) {\n\t\t\treturn c.json({ error: 'Requests must originate from localhost.' }, 403);\n\t\t}\n\t\treturn await next();\n\t});\n\n\t// Token authentication for API routes\n\tapp.use('/api/*', async (c, next) => {\n\t\tif (!isAuthenticated(c.req.header('authorization'))) {\n\t\t\treturn c.json(\n\t\t\t\t{ error: 'Authentication required. Open the token URL from the terminal.' },\n\t\t\t\t401,\n\t\t\t);\n\t\t}\n\t\treturn await next();\n\t});\n\n\t// GET /api/v1/accounts — list accounts from sui CLI keystore\n\tapp.get('/api/v1/accounts', async (c) => {\n\t\ttry {\n\t\t\tconst { stdout } = await execFileAsync('sui', ['keytool', 'list', '--json']);\n\t\t\tconst accounts = JSON.parse(stdout);\n\t\t\treturn c.json({ accounts });\n\t\t} catch (err) {\n\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\tconst isExecError = message.includes('ENOENT') || message.includes('not found');\n\t\t\treturn c.json(\n\t\t\t\t{\n\t\t\t\t\terror: isExecError\n\t\t\t\t\t\t? 'Failed to list accounts: sui CLI not found.'\n\t\t\t\t\t\t: 'Failed to list accounts.',\n\t\t\t\t},\n\t\t\t\t500,\n\t\t\t);\n\t\t}\n\t});\n\n\t// POST /api/v1/sign-transaction — sign BCS-serialized TransactionData\n\tapp.post('/api/v1/sign-transaction', async (c) => {\n\t\tconst contentLength = c.req.header('content-length');\n\t\tif (contentLength && parseInt(contentLength, 10) > MAX_BODY_SIZE) {\n\t\t\treturn c.json({ error: 'Request body too large' }, 413);\n\t\t}\n\n\t\tlet body: { address?: unknown; txBytes?: unknown };\n\t\ttry {\n\t\t\tbody = await c.req.json();\n\t\t} catch {\n\t\t\treturn c.json({ error: 'Invalid JSON body' }, 400);\n\t\t}\n\n\t\tif (typeof body.address !== 'string' || !isValidSuiAddress(body.address)) {\n\t\t\treturn c.json({ error: 'Invalid address format. Expected 0x-prefixed hex.' }, 400);\n\t\t}\n\n\t\tif (!isValidBase64(body.txBytes)) {\n\t\t\treturn c.json({ error: 'Invalid txBytes. Expected non-empty base64 string.' }, 400);\n\t\t}\n\n\t\ttry {\n\t\t\tconst { stdout } = await execFileAsync('sui', [\n\t\t\t\t'keytool',\n\t\t\t\t'sign',\n\t\t\t\t'--address',\n\t\t\t\tbody.address,\n\t\t\t\t'--data',\n\t\t\t\tbody.txBytes as string,\n\t\t\t\t'--json',\n\t\t\t]);\n\n\t\t\tconst result = JSON.parse(stdout);\n\t\t\treturn c.json({ suiSignature: result.suiSignature, digest: result.digest });\n\t\t} catch (err) {\n\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\tconsole.error('[dev-wallet] CLI signing error:', message);\n\n\t\t\tif (message.includes('not found') || message.includes('Cannot find key')) {\n\t\t\t\treturn c.json({ error: `Address not found in keystore: ${body.address}` }, 404);\n\t\t\t}\n\n\t\t\treturn c.json({ error: 'Signing failed due to a CLI error.' }, 500);\n\t\t}\n\t});\n\n\treturn { app, token };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli-signing-middleware.mjs","names":[],"sources":["../../src/server/cli-signing-middleware.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { execFile } from 'node:child_process';\nimport { randomBytes, timingSafeEqual } from 'node:crypto';\nimport { promisify } from 'node:util';\n\nimport { isValidSuiAddress } from '@mysten/sui/utils';\nimport { Hono } from 'hono';\n\nconst execFileAsync = promisify(execFile);\n\nfunction isValidBase64(value: unknown): value is string {\n\tif (typeof value !== 'string' || value.length === 0) return false;\n\treturn /^[A-Za-z0-9+/]+=*$/.test(value) && value.length <= 1_000_000;\n}\n\nconst MAX_BODY_SIZE = 2 * 1024 * 1024; // 2 MB\n\nfunction generateToken(): string {\n\treturn randomBytes(32).toString('hex');\n}\n\nexport interface CliSigningMiddlewareOptions {\n\t/** The port the server is listening on, used for DNS rebinding protection. */\n\tport: number;\n}\n\nexport interface CliSigningMiddlewareResult {\n\tapp: Hono;\n\ttoken: string;\n}\n\n/**\n * Create a Hono sub-app that exposes signing endpoints backed by the `sui` CLI.\n *\n * Uses token-in-URL auth: a 256-bit random token is embedded in the URL printed\n * to the terminal and sent as `Authorization: Bearer <token>` on subsequent requests.\n * All CLI calls use `execFile` to prevent shell injection.\n */\nexport function createCliSigningMiddleware(\n\toptions: CliSigningMiddlewareOptions,\n): CliSigningMiddlewareResult {\n\tconst { port } = options;\n\tconst token = generateToken();\n\n\tfunction isAuthenticated(authHeader: string | undefined): boolean {\n\t\tif (!token) return false;\n\t\tif (!authHeader || !/^bearer /i.test(authHeader)) return false;\n\t\tconst provided = authHeader.slice(7);\n\t\tif (provided.length !== token.length) return false;\n\t\treturn timingSafeEqual(Buffer.from(provided), Buffer.from(token));\n\t}\n\n\tconst app = new Hono();\n\n\t// DNS rebinding protection — reject non-localhost hosts\n\tapp.use('*', async (c, next) => {\n\t\tconst host = c.req.header('host') ?? '';\n\t\tconst allowedHosts = new Set([`localhost:${port}`, `127.0.0.1:${port}`, `[::1]:${port}`]);\n\t\tif (host && !allowedHosts.has(host)) {\n\t\t\treturn c.json({ error: 'Requests must originate from localhost.' }, 403);\n\t\t}\n\t\treturn await next();\n\t});\n\n\t// Token authentication for API routes\n\tapp.use('/api/*', async (c, next) => {\n\t\tif (!isAuthenticated(c.req.header('authorization'))) {\n\t\t\treturn c.json(\n\t\t\t\t{ error: 'Authentication required. Open the token URL from the terminal.' },\n\t\t\t\t401,\n\t\t\t);\n\t\t}\n\t\treturn await next();\n\t});\n\n\t// GET /api/v1/accounts — list accounts from sui CLI keystore\n\tapp.get('/api/v1/accounts', async (c) => {\n\t\ttry {\n\t\t\tconst { stdout } = await execFileAsync('sui', ['keytool', 'list', '--json']);\n\t\t\tconst accounts = JSON.parse(stdout);\n\t\t\treturn c.json({ accounts });\n\t\t} catch (err) {\n\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\tconst isExecError = message.includes('ENOENT') || message.includes('not found');\n\t\t\treturn c.json(\n\t\t\t\t{\n\t\t\t\t\terror: isExecError\n\t\t\t\t\t\t? 'Failed to list accounts: sui CLI not found.'\n\t\t\t\t\t\t: 'Failed to list accounts.',\n\t\t\t\t},\n\t\t\t\t500,\n\t\t\t);\n\t\t}\n\t});\n\n\t// POST /api/v1/sign-transaction — sign BCS-serialized TransactionData\n\tapp.post('/api/v1/sign-transaction', async (c) => {\n\t\tconst contentLength = c.req.header('content-length');\n\t\tif (contentLength && parseInt(contentLength, 10) > MAX_BODY_SIZE) {\n\t\t\treturn c.json({ error: 'Request body too large' }, 413);\n\t\t}\n\n\t\tlet body: { address?: unknown; txBytes?: unknown };\n\t\ttry {\n\t\t\tbody = await c.req.json();\n\t\t} catch {\n\t\t\treturn c.json({ error: 'Invalid JSON body' }, 400);\n\t\t}\n\n\t\tif (typeof body.address !== 'string' || !isValidSuiAddress(body.address)) {\n\t\t\treturn c.json({ error: 'Invalid address format. Expected 0x-prefixed hex.' }, 400);\n\t\t}\n\n\t\tif (!isValidBase64(body.txBytes)) {\n\t\t\treturn c.json({ error: 'Invalid txBytes. Expected non-empty base64 string.' }, 400);\n\t\t}\n\n\t\ttry {\n\t\t\tconst { stdout } = await execFileAsync('sui', [\n\t\t\t\t'keytool',\n\t\t\t\t'sign',\n\t\t\t\t'--address',\n\t\t\t\tbody.address,\n\t\t\t\t'--data',\n\t\t\t\tbody.txBytes as string,\n\t\t\t\t'--json',\n\t\t\t]);\n\n\t\t\tconst result = JSON.parse(stdout);\n\t\t\treturn c.json({ suiSignature: result.suiSignature, digest: result.digest });\n\t\t} catch (err) {\n\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\tconsole.error('[dev-wallet] CLI signing error:', message);\n\n\t\t\tif (message.includes('not found') || message.includes('Cannot find key')) {\n\t\t\t\treturn c.json({ error: `Address not found in keystore: ${body.address}` }, 404);\n\t\t\t}\n\n\t\t\treturn c.json({ error: 'Signing failed due to a CLI error.' }, 500);\n\t\t}\n\t});\n\n\treturn { app, token };\n}\n"],"mappings":"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"}
|
package/dist/server/index.mjs
CHANGED
package/dist/standalone/assets/{in-memory-adapter-CBF4h2KD.js → in-memory-adapter-qRkNfj9O.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as R,d as F,e as U,f as w,k as S,h as E,g as V,s as b,t as x,i as H,K as _,j as u,l as B,P as K,E as C,m as N,B as $,b as v}from"./main-
|
|
1
|
+
import{c as R,d as F,e as U,f as w,k as S,h as E,g as V,s as b,t as x,i as H,K as _,j as u,l as B,P as K,E as C,m as N,B as $,b as v}from"./main-DDltQnzR.js";function z(n,e,t,r){F(n);const i=U({dkLen:32,asyncTick:10},r),{c:s,dkLen:c,asyncTick:o}=i;if(w(s,"c"),w(c,"dkLen"),w(o,"asyncTick"),s<1)throw new Error("iterations (c) must be >= 1");const y=S(e,"password"),d=S(t,"salt"),p=new Uint8Array(c),f=E.create(n,y),a=f._cloneInto().update(d);return{c:s,dkLen:c,asyncTick:o,DK:p,PRF:f,PRFSalt:a}}function M(n,e,t,r,i){return n.destroy(),e.destroy(),r&&r.destroy(),V(i),t}function O(n,e,t,r){const{c:i,dkLen:s,DK:c,PRF:o,PRFSalt:y}=z(n,e,t,r);let d;const p=new Uint8Array(4),f=R(p),a=new Uint8Array(o.outputLen);for(let A=1,m=0;m<s;A++,m+=o.outputLen){const g=c.subarray(m,m+o.outputLen);f.setInt32(0,A,!1),(d=y._cloneInto(d)).update(p).digestInto(a),g.set(a.subarray(0,g.length));for(let k=1;k<i;k++){o._cloneInto(d).update(a).digestInto(a);for(let h=0;h<g.length;h++)g[h]^=a[h]}}return M(o,y,c,d,a)}function T(n){if(typeof n!="string")throw new TypeError("invalid mnemonic type: "+typeof n);return n.normalize("NFKD")}function j(n){const e=T(n),t=e.split(" ");if(![12,15,18,21,24].includes(t.length))throw new Error("Invalid mnemonic");return{nfkd:e,words:t}}const q=n=>T("mnemonic"+n);function W(n,e=""){return O(b,j(n).nfkd,q(e),{c:2048,dkLen:64})}function I(n){return!!new RegExp("^m\\/44'\\/784'\\/[0-9]+'\\/[0-9]+'\\/[0-9]+'+$").test(n)}function Y(n){return W(n,"")}function Z(n){return x(Y(n))}const G="ed25519 seed",J=2147483648,Q=new RegExp("^m(\\/[0-9]+')+$"),L=n=>n.replace("'",""),X=n=>{const e=E.create(b,new TextEncoder().encode(G)).update(H(n)).digest();return{key:e.slice(0,32),chainCode:e.slice(32)}},ee=({key:n,chainCode:e},t)=>{const r=new ArrayBuffer(4);new DataView(r).setUint32(0,t);const i=new Uint8Array(1+n.length+r.byteLength);i.set(new Uint8Array(1).fill(0)),i.set(n,1),i.set(new Uint8Array(r,0,r.byteLength),n.length+1);const s=E.create(b,e).update(i).digest();return{key:s.slice(0,32),chainCode:s.slice(32)}},te=n=>Q.test(n)?!n.split("/").slice(1).map(L).some(isNaN):!1,P=(n,e,t=J)=>{if(!te(n))throw new Error("Invalid derivation path");const{key:r,chainCode:i}=X(e);return n.split("/").slice(1).map(L).map(s=>parseInt(s,10)).reduce((s,c)=>ee(s,c+t),{key:r,chainCode:i})},D="m/44'/784'/0'/0'/0'";var ne=class l extends _{constructor(e){if(super(),e)this.keypair={publicKey:e.publicKey,secretKey:e.secretKey.slice(0,32)};else{const t=u.utils.randomSecretKey();this.keypair={publicKey:u.getPublicKey(t),secretKey:t}}}getKeyScheme(){return"ED25519"}static generate(){const e=u.utils.randomSecretKey();return new l({publicKey:u.getPublicKey(e),secretKey:e})}static fromSecretKey(e,t){if(typeof e=="string"){const s=B(e);if(s.scheme!=="ED25519")throw new Error(`Expected a ED25519 keypair, got ${s.scheme}`);return this.fromSecretKey(s.secretKey,t)}const r=e.length;if(r!==K)throw new Error(`Wrong secretKey size. Expected ${K} bytes, got ${r}.`);const i={publicKey:u.getPublicKey(e),secretKey:e};if(!t||!t.skipValidation){const s=new TextEncoder().encode("sui validation"),c=u.sign(s,e);if(!u.verify(c,s,i.publicKey))throw new Error("provided secretKey is invalid")}return new l(i)}getPublicKey(){return new C(this.keypair.publicKey)}getSecretKey(){return N(this.keypair.secretKey.slice(0,K),this.getKeyScheme())}async sign(e){return u.sign(e,this.keypair.secretKey)}static deriveKeypair(e,t){if(t==null&&(t=D),!I(t))throw new Error("Invalid derivation path");const{key:r}=P(t,Z(e));return l.fromSecretKey(r)}static deriveKeypairFromSeed(e,t){if(t==null&&(t=D),!I(t))throw new Error("Invalid derivation path");const r=typeof e=="string"?e:x(e),{key:i}=P(t,r);return l.fromSecretKey(i)}};class se extends ${constructor(){super(...arguments),this.id="in-memory",this.name="In-Memory Signer"}async initialize(){}async createAccount(e){const t=new ne,r=t.getPublicKey().toSuiAddress(),i=e?.label??this.getDefaultLabel(),s=v(t,r,i);return this.addAccount(s),s}async importAccount(e){const t=e.signer;if(!t)throw new Error("In-memory adapter requires a signer to import");const r=t.toSuiAddress(),i=this.getAccount(r);if(i)return i;const s=e.label??this.getDefaultLabel(),c=v(t,r,s);return this.addAccount(c),c}async renameAccount(e,t){return this._performRename(e,t)}async removeAccount(e){return this.removeAccountByAddress(e)}}export{se as InMemorySignerAdapter};
|