@mysten-incubation/dev-wallet 0.3.0 → 0.4.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/CHANGELOG.md +76 -2
- package/dist/_virtual/{_@oxc-project_runtime@0.127.0/helpers → _@oxc-project_runtime@0.135.0/helpers/esm}/decorate.mjs +1 -1
- package/dist/adapters/base-adapter.d.mts.map +1 -1
- package/dist/adapters/base-adapter.mjs.map +1 -1
- package/dist/adapters/build-managed-account.mjs.map +1 -1
- package/dist/adapters/devstack-adapter.d.mts.map +1 -1
- package/dist/adapters/devstack-adapter.mjs.map +1 -1
- package/dist/adapters/devstack-paths.d.mts.map +1 -1
- package/dist/adapters/devstack-paths.mjs.map +1 -1
- package/dist/adapters/fork-relay.d.mts.map +1 -1
- package/dist/adapters/fork-relay.mjs.map +1 -1
- package/dist/adapters/idb-store.mjs.map +1 -1
- package/dist/adapters/in-memory-adapter.d.mts.map +1 -1
- package/dist/adapters/in-memory-adapter.mjs.map +1 -1
- package/dist/adapters/passkey-adapter.d.mts.map +1 -1
- package/dist/adapters/passkey-adapter.mjs.map +1 -1
- package/dist/adapters/remote-cli-adapter.d.mts.map +1 -1
- package/dist/adapters/remote-cli-adapter.mjs.map +1 -1
- package/dist/adapters/webcrypto-adapter.d.mts.map +1 -1
- package/dist/adapters/webcrypto-adapter.mjs.map +1 -1
- package/dist/bin/cli.mjs.map +1 -1
- package/dist/client/dev-wallet-client.d.mts.map +1 -1
- package/dist/client/dev-wallet-client.mjs.map +1 -1
- package/dist/client/request-handler.d.mts.map +1 -1
- package/dist/client/request-handler.mjs.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/inject/index.d.mts +61 -0
- package/dist/inject/index.d.mts.map +1 -0
- package/dist/inject/index.mjs +67 -0
- package/dist/inject/index.mjs.map +1 -0
- package/dist/react/components.d.mts +6 -8
- package/dist/react/components.d.mts.map +1 -1
- package/dist/react/components.mjs.map +1 -1
- package/dist/react/context.d.mts +2 -3
- package/dist/react/context.d.mts.map +1 -1
- package/dist/react/context.mjs.map +1 -1
- package/dist/react/useDevWallet.d.mts +3 -11
- package/dist/react/useDevWallet.d.mts.map +1 -1
- package/dist/react/useDevWallet.mjs +14 -36
- package/dist/react/useDevWallet.mjs.map +1 -1
- package/dist/server/cli-signing-middleware.d.mts.map +1 -1
- package/dist/server/cli-signing-middleware.mjs.map +1 -1
- package/dist/standalone/assets/base-adapter-DET6CP7z.js +1 -0
- package/dist/standalone/assets/in-memory-adapter-CX7xym4e.js +1 -0
- package/dist/standalone/assets/main-CuOnBmaa.js +7 -0
- package/dist/standalone/assets/webcrypto-adapter-CUQmbHDy.js +1 -0
- package/dist/standalone/bookmarklet.js +5 -5
- package/dist/standalone/index.html +2 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/ui/copy-controller.mjs.map +1 -1
- package/dist/ui/dev-wallet-account-selector.d.mts +2 -3
- package/dist/ui/dev-wallet-account-selector.d.mts.map +1 -1
- package/dist/ui/dev-wallet-account-selector.mjs +1 -1
- package/dist/ui/dev-wallet-account-selector.mjs.map +1 -1
- package/dist/ui/dev-wallet-accounts.d.mts +2 -3
- package/dist/ui/dev-wallet-accounts.d.mts.map +1 -1
- package/dist/ui/dev-wallet-accounts.mjs +1 -1
- package/dist/ui/dev-wallet-accounts.mjs.map +1 -1
- package/dist/ui/dev-wallet-balances.d.mts +2 -3
- package/dist/ui/dev-wallet-balances.d.mts.map +1 -1
- package/dist/ui/dev-wallet-balances.mjs +1 -1
- package/dist/ui/dev-wallet-balances.mjs.map +1 -1
- package/dist/ui/dev-wallet-connect.d.mts +2 -3
- package/dist/ui/dev-wallet-connect.d.mts.map +1 -1
- package/dist/ui/dev-wallet-connect.mjs +1 -1
- package/dist/ui/dev-wallet-connect.mjs.map +1 -1
- package/dist/ui/dev-wallet-dropdown.d.mts +2 -3
- package/dist/ui/dev-wallet-dropdown.d.mts.map +1 -1
- package/dist/ui/dev-wallet-dropdown.mjs +1 -1
- package/dist/ui/dev-wallet-dropdown.mjs.map +1 -1
- package/dist/ui/dev-wallet-fork-panel.d.mts +2 -3
- package/dist/ui/dev-wallet-fork-panel.d.mts.map +1 -1
- package/dist/ui/dev-wallet-fork-panel.mjs +1 -1
- package/dist/ui/dev-wallet-fork-panel.mjs.map +1 -1
- package/dist/ui/dev-wallet-network-badge.d.mts +2 -3
- package/dist/ui/dev-wallet-network-badge.d.mts.map +1 -1
- package/dist/ui/dev-wallet-network-badge.mjs +1 -1
- package/dist/ui/dev-wallet-network-badge.mjs.map +1 -1
- package/dist/ui/dev-wallet-new-account.d.mts +2 -3
- package/dist/ui/dev-wallet-new-account.d.mts.map +1 -1
- package/dist/ui/dev-wallet-new-account.mjs +1 -1
- package/dist/ui/dev-wallet-new-account.mjs.map +1 -1
- package/dist/ui/dev-wallet-objects.d.mts +2 -3
- package/dist/ui/dev-wallet-objects.d.mts.map +1 -1
- package/dist/ui/dev-wallet-objects.mjs +1 -1
- package/dist/ui/dev-wallet-objects.mjs.map +1 -1
- package/dist/ui/dev-wallet-panel.d.mts +2 -3
- package/dist/ui/dev-wallet-panel.d.mts.map +1 -1
- package/dist/ui/dev-wallet-panel.mjs +1 -1
- package/dist/ui/dev-wallet-panel.mjs.map +1 -1
- package/dist/ui/dev-wallet-popup.d.mts +2 -3
- package/dist/ui/dev-wallet-popup.d.mts.map +1 -1
- package/dist/ui/dev-wallet-popup.mjs +1 -1
- package/dist/ui/dev-wallet-popup.mjs.map +1 -1
- package/dist/ui/dev-wallet-settings.d.mts +2 -3
- package/dist/ui/dev-wallet-settings.d.mts.map +1 -1
- package/dist/ui/dev-wallet-settings.mjs +1 -1
- package/dist/ui/dev-wallet-settings.mjs.map +1 -1
- package/dist/ui/dev-wallet-signing-modal.d.mts +2 -3
- package/dist/ui/dev-wallet-signing-modal.d.mts.map +1 -1
- package/dist/ui/dev-wallet-signing-modal.mjs +1 -1
- package/dist/ui/dev-wallet-signing-modal.mjs.map +1 -1
- package/dist/ui/dev-wallet-signing.d.mts +2 -3
- package/dist/ui/dev-wallet-signing.d.mts.map +1 -1
- package/dist/ui/dev-wallet-signing.mjs +2 -1
- package/dist/ui/dev-wallet-signing.mjs.map +1 -1
- package/dist/ui/dev-wallet-standalone.d.mts +2 -3
- package/dist/ui/dev-wallet-standalone.d.mts.map +1 -1
- package/dist/ui/dev-wallet-standalone.mjs +1 -1
- package/dist/ui/dev-wallet-standalone.mjs.map +1 -1
- package/dist/ui/dev-wallet-tab-bar.d.mts +1 -2
- package/dist/ui/dev-wallet-tab-bar.d.mts.map +1 -1
- package/dist/ui/dev-wallet-tab-bar.mjs +1 -1
- package/dist/ui/dev-wallet-tab-bar.mjs.map +1 -1
- package/dist/ui/mount.mjs.map +1 -1
- package/dist/ui/styles.mjs.map +1 -1
- package/dist/ui/transaction-analyzer.mjs.map +1 -1
- package/dist/ui/utils.d.mts.map +1 -1
- package/dist/ui/utils.mjs.map +1 -1
- package/dist/ui/wallet-controller.mjs.map +1 -1
- package/dist/wallet/constants.d.mts.map +1 -1
- package/dist/wallet/constants.mjs.map +1 -1
- package/dist/wallet/dev-wallet.d.mts +19 -0
- package/dist/wallet/dev-wallet.d.mts.map +1 -1
- package/dist/wallet/dev-wallet.mjs +58 -2
- package/dist/wallet/dev-wallet.mjs.map +1 -1
- package/dist/wallet/initializer.d.mts.map +1 -1
- package/dist/wallet/initializer.mjs +10 -26
- package/dist/wallet/initializer.mjs.map +1 -1
- package/dist/wallet/mount-and-register.d.mts +44 -0
- package/dist/wallet/mount-and-register.d.mts.map +1 -0
- package/dist/wallet/mount-and-register.mjs +46 -0
- package/dist/wallet/mount-and-register.mjs.map +1 -0
- package/dist/wallet/signing.d.mts.map +1 -1
- package/dist/wallet/signing.mjs.map +1 -1
- package/package.json +26 -22
- package/src/index.ts +5 -0
- package/src/inject/index.ts +200 -0
- package/src/react/useDevWallet.ts +26 -71
- package/src/ui/dev-wallet-signing.ts +2 -0
- package/src/wallet/dev-wallet.ts +75 -2
- package/src/wallet/initializer.ts +16 -42
- package/src/wallet/mount-and-register.ts +93 -0
- package/dist/standalone/assets/in-memory-adapter-qRkNfj9O.js +0 -1
- package/dist/standalone/assets/main-DDltQnzR.js +0 -3954
- package/dist/standalone/assets/webcrypto-adapter-FejcrL9x.js +0 -1
|
@@ -6,7 +6,8 @@ import type { WalletIcon } from '@mysten/wallet-standard';
|
|
|
6
6
|
|
|
7
7
|
import type { DevWalletDockStyle } from '../ui/dev-wallet-panel.js';
|
|
8
8
|
import type { SignerAdapter } from '../types.js';
|
|
9
|
-
import { DevWallet,
|
|
9
|
+
import type { DevWallet, AutoApprovePolicy } from './dev-wallet.js';
|
|
10
|
+
import { mountAndRegisterDevWallet } from './mount-and-register.js';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Configuration for the dev wallet initializer.
|
|
@@ -66,26 +67,6 @@ export function devWalletInitializer(config: DevWalletInitializerConfig): {
|
|
|
66
67
|
return {
|
|
67
68
|
id: 'dev-wallet-initializer',
|
|
68
69
|
async initialize({ networks, getClient }) {
|
|
69
|
-
const { autoInitialize = true, createInitialAccount = true, mountUI = false } = config;
|
|
70
|
-
|
|
71
|
-
// Initialize adapters
|
|
72
|
-
if (autoInitialize) {
|
|
73
|
-
await Promise.all(config.adapters.map((a) => a.initialize()));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Create initial account if needed
|
|
77
|
-
if (createInitialAccount) {
|
|
78
|
-
const hasAccounts = config.adapters.some((a) => a.getAccounts().length > 0);
|
|
79
|
-
if (!hasAccounts) {
|
|
80
|
-
const creatableAdapter = config.adapters.find(
|
|
81
|
-
(a) => a.createAccount && a.getAccounts().length === 0,
|
|
82
|
-
);
|
|
83
|
-
if (creatableAdapter?.createAccount) {
|
|
84
|
-
await creatableAdapter.createAccount({ label: 'Dev Account' });
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
70
|
// Map dApp Kit networks to DevWallet format.
|
|
90
71
|
// DevWallet needs a Record<string, string> of network name → URL, but
|
|
91
72
|
// the clientFactory we provide delegates to getClient, so the URLs are
|
|
@@ -95,7 +76,13 @@ export function devWalletInitializer(config: DevWalletInitializerConfig): {
|
|
|
95
76
|
networkUrls[network] = `dapp-kit://${network}`;
|
|
96
77
|
}
|
|
97
78
|
|
|
98
|
-
|
|
79
|
+
// Delegate the construct → init-adapter → mount-UI → register → dispose
|
|
80
|
+
// sequence to the shared core helper; this initializer only supplies the
|
|
81
|
+
// dApp-Kit-sourced networks + client factory and the `onWalletCreated`
|
|
82
|
+
// hook. `createInitialAccount`/`autoInitialize` default to TRUE here (the
|
|
83
|
+
// initializer's historical behavior — its adapters start empty); `mountUI`
|
|
84
|
+
// defaults to FALSE (dApp Kit typically renders its own connect UI).
|
|
85
|
+
const { dispose } = await mountAndRegisterDevWallet({
|
|
99
86
|
adapters: config.adapters,
|
|
100
87
|
networks: networkUrls,
|
|
101
88
|
name: config.name,
|
|
@@ -103,28 +90,15 @@ export function devWalletInitializer(config: DevWalletInitializerConfig): {
|
|
|
103
90
|
autoApprove: config.autoApprove,
|
|
104
91
|
autoConnect: config.autoConnect,
|
|
105
92
|
clientFactory: (network) => getClient(network),
|
|
93
|
+
autoInitialize: config.autoInitialize ?? true,
|
|
94
|
+
createInitialAccount: config.createInitialAccount ?? true,
|
|
95
|
+
mountUI: config.mountUI ?? false,
|
|
96
|
+
dockStyle: config.dockStyle,
|
|
97
|
+
container: config.container,
|
|
98
|
+
onWalletCreated: config.onWalletCreated,
|
|
106
99
|
});
|
|
107
100
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// Mount UI if requested
|
|
111
|
-
let unmountUI: (() => void) | undefined;
|
|
112
|
-
if (mountUI && typeof document !== 'undefined') {
|
|
113
|
-
const { mountDevWallet } = await import('../ui/mount.js');
|
|
114
|
-
unmountUI = mountDevWallet(wallet, {
|
|
115
|
-
container: config.container,
|
|
116
|
-
dockStyle: config.dockStyle,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const unregister = wallet.register();
|
|
121
|
-
return {
|
|
122
|
-
unregister() {
|
|
123
|
-
unmountUI?.();
|
|
124
|
-
unregister();
|
|
125
|
-
wallet.destroy();
|
|
126
|
-
},
|
|
127
|
-
};
|
|
101
|
+
return { unregister: dispose };
|
|
128
102
|
},
|
|
129
103
|
};
|
|
130
104
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { DevWalletDockStyle } from '../ui/dev-wallet-panel.js';
|
|
5
|
+
import { DevWallet, type DevWalletConfig } from './dev-wallet.js';
|
|
6
|
+
|
|
7
|
+
export interface MountAndRegisterDevWalletOptions extends DevWalletConfig {
|
|
8
|
+
/** Call `adapter.initialize()` on every adapter before registering. Defaults to true. */
|
|
9
|
+
autoInitialize?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Create an initial account after initialization when no adapter has any
|
|
12
|
+
* accounts (uses the first adapter that supports `createAccount`). Defaults
|
|
13
|
+
* to false — most managed/remote adapters (devstack, CLI) bring their own
|
|
14
|
+
* accounts and must NOT have a throwaway one fabricated.
|
|
15
|
+
*/
|
|
16
|
+
createInitialAccount?: boolean;
|
|
17
|
+
/** Mount the floating wallet drawer UI (no-op when `document` is undefined). Defaults to true. */
|
|
18
|
+
mountUI?: boolean;
|
|
19
|
+
/** Floating dock presentation when `mountUI` is true. */
|
|
20
|
+
dockStyle?: DevWalletDockStyle;
|
|
21
|
+
/** Container element for the UI drawer. Defaults to `document.body`. */
|
|
22
|
+
container?: HTMLElement;
|
|
23
|
+
/** Called with the `DevWallet` once constructed, before the UI is mounted
|
|
24
|
+
* and the wallet is registered. */
|
|
25
|
+
onWalletCreated?: (wallet: DevWallet) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface MountAndRegisterDevWalletResult {
|
|
29
|
+
readonly wallet: DevWallet;
|
|
30
|
+
/** Unmount the UI, unregister from wallet-standard, and destroy the wallet (+ adapters). */
|
|
31
|
+
readonly dispose: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Construct a {@link DevWallet} from adapters, initialize the adapters, mount
|
|
36
|
+
* the drawer UI, register it with the wallet-standard registry, and return the
|
|
37
|
+
* wallet plus a single `dispose()` that tears all of that down again.
|
|
38
|
+
*
|
|
39
|
+
* This is the imperative "bring a dev wallet up on the page" path shared by the
|
|
40
|
+
* React hook (`useDevWallet`), the dApp-Kit initializer (`devWalletInitializer`),
|
|
41
|
+
* and the devstack page-register entry (`src/inject`). Those call sites only
|
|
42
|
+
* differ in HOW they obtain `adapters` / `networks` — the construct → init →
|
|
43
|
+
* mount → register → dispose sequence is identical, so it lives here once.
|
|
44
|
+
*/
|
|
45
|
+
export async function mountAndRegisterDevWallet(
|
|
46
|
+
options: MountAndRegisterDevWalletOptions,
|
|
47
|
+
): Promise<MountAndRegisterDevWalletResult> {
|
|
48
|
+
const {
|
|
49
|
+
autoInitialize = true,
|
|
50
|
+
createInitialAccount = false,
|
|
51
|
+
mountUI = true,
|
|
52
|
+
dockStyle,
|
|
53
|
+
container,
|
|
54
|
+
onWalletCreated,
|
|
55
|
+
...walletConfig
|
|
56
|
+
} = options;
|
|
57
|
+
|
|
58
|
+
if (autoInitialize) {
|
|
59
|
+
await Promise.all(walletConfig.adapters.map((a) => a.initialize()));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (createInitialAccount) {
|
|
63
|
+
const hasAccounts = walletConfig.adapters.some((a) => a.getAccounts().length > 0);
|
|
64
|
+
if (!hasAccounts) {
|
|
65
|
+
const creatableAdapter = walletConfig.adapters.find(
|
|
66
|
+
(a) => a.createAccount && a.getAccounts().length === 0,
|
|
67
|
+
);
|
|
68
|
+
if (creatableAdapter?.createAccount) {
|
|
69
|
+
await creatableAdapter.createAccount({ label: 'Dev Account' });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const wallet = new DevWallet(walletConfig);
|
|
75
|
+
onWalletCreated?.(wallet);
|
|
76
|
+
|
|
77
|
+
let unmountUI: (() => void) | undefined;
|
|
78
|
+
if (mountUI && typeof document !== 'undefined') {
|
|
79
|
+
const { mountDevWallet } = await import('../ui/mount.js');
|
|
80
|
+
unmountUI = mountDevWallet(wallet, { container, dockStyle });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const unregister = wallet.register();
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
wallet,
|
|
87
|
+
dispose() {
|
|
88
|
+
unmountUI?.();
|
|
89
|
+
unregister();
|
|
90
|
+
wallet.destroy();
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
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};
|