@@ -31,6 +31,14 @@ export interface EvmServerWalletConfig {
3131/**
3232 * Creates a server-side EVM wallet adapter backed by a private key.
3333 * Returns no Provider — server wallets have no UI layer.
34+ *
35+ * @precondition config.privateKey is a valid hex-encoded private key
36+ * @precondition config.chain is a valid viem Chain
37+ * @postcondition returned adapter.chainType === 'evm'
38+ * @postcondition returned bundle has no Provider (server wallets have no UI)
39+ * @invariant adapter.chainType never changes after construction
40+ * @invariant adapter.supportedChains never changes after construction
41+ * @invariant getStatus().connected === true (always connected)
3442 */
3543export function createEvmServerWallet ( config : EvmServerWalletConfig ) : WalletAdapterBundle {
3644 const account = privateKeyToAccount ( config . privateKey )
@@ -58,6 +66,13 @@ export function createEvmServerWallet(config: EvmServerWalletConfig): WalletAdap
5866 } ,
5967 } ,
6068
69+ /**
70+ * No-op connect — server wallet is always connected via private key.
71+ *
72+ * @precondition none
73+ * @postcondition returns WalletConnection with the private key account
74+ * @postcondition result.accounts.length === 1
75+ */
6176 async connect ( _options ?: ConnectOptions ) : Promise < WalletConnection > {
6277 return {
6378 accounts : [ account . address ] ,
@@ -66,7 +81,12 @@ export function createEvmServerWallet(config: EvmServerWalletConfig): WalletAdap
6681 }
6782 } ,
6883
69- // Server wallet is always connected — reconnect() always returns a connection, never null.
84+ /**
85+ * Always returns a connection — server wallet is always connected.
86+ *
87+ * @precondition none
88+ * @postcondition always returns WalletConnection (never null)
89+ */
7090 async reconnect ( ) : Promise < WalletConnection | null > {
7191 return {
7292 accounts : [ account . address ] ,
@@ -75,10 +95,24 @@ export function createEvmServerWallet(config: EvmServerWalletConfig): WalletAdap
7595 }
7696 } ,
7797
98+ /**
99+ * No-op — private key wallet is always connected and cannot be disconnected.
100+ *
101+ * @precondition none
102+ * @postcondition getStatus().connected remains true
103+ */
78104 async disconnect ( ) : Promise < void > {
79105 // no-op: private key wallet is always connected
80106 } ,
81107
108+ /**
109+ * Returns wallet status — always connected for server wallets.
110+ *
111+ * @precondition none
112+ * @postcondition connected === true
113+ * @postcondition activeAccount === the private key's derived address
114+ * @invariant status never changes for a private key wallet
115+ */
82116 getStatus ( ) : WalletStatus {
83117 return {
84118 connected : true ,
@@ -88,6 +122,13 @@ export function createEvmServerWallet(config: EvmServerWalletConfig): WalletAdap
88122 }
89123 } ,
90124
125+ /**
126+ * Emits current status immediately; no further changes occur for a server wallet.
127+ *
128+ * @precondition none
129+ * @postcondition listener fires once with current (always-connected) status
130+ * @returns unsubscribe function (no-op — status never changes)
131+ */
91132 onStatusChange ( listener : ( status : WalletStatus ) => void ) : ( ) => void {
92133 // Emit current status immediately so callers receive initial state without polling.
93134 listener ( {
@@ -101,6 +142,12 @@ export function createEvmServerWallet(config: EvmServerWalletConfig): WalletAdap
101142 }
102143 } ,
103144
145+ /**
146+ * Signs an arbitrary message with the server wallet's private key.
147+ *
148+ * @precondition none (server wallet is always connected)
149+ * @postcondition result.address matches the private key's derived address
150+ */
104151 async signMessage ( input : SignMessageInput ) : Promise < SignatureResult > {
105152 const message = input . message instanceof Uint8Array ? { raw : input . message } : input . message
106153 const signature = await walletClient . signMessage ( { message } as Parameters <
@@ -109,6 +156,12 @@ export function createEvmServerWallet(config: EvmServerWalletConfig): WalletAdap
109156 return { signature, address : account . address }
110157 } ,
111158
159+ /**
160+ * Signs EIP-712 typed data with the server wallet's private key.
161+ *
162+ * @precondition none (server wallet is always connected)
163+ * @postcondition result.address matches the private key's derived address
164+ */
112165 async signTypedData ( input : SignTypedDataInput ) : Promise < SignatureResult > {
113166 const signature = await walletClient . signTypedData ( {
114167 domain : input . domain ,
@@ -119,10 +172,22 @@ export function createEvmServerWallet(config: EvmServerWalletConfig): WalletAdap
119172 return { signature, address : account . address }
120173 } ,
121174
175+ /**
176+ * Returns the viem WalletClient — always available for server wallets.
177+ *
178+ * @precondition none
179+ * @postcondition always returns the WalletClient (never null)
180+ */
122181 async getSigner ( ) : Promise < ChainSigner | null > {
123182 return walletClient
124183 } ,
125184
185+ /**
186+ * Always throws — server wallets are bound to a single chain.
187+ *
188+ * @precondition none
189+ * @throws {CapabilityNotSupportedError } always (switchChain not supported)
190+ */
126191 async switchChain ( _chainId : string | number ) : Promise < void > {
127192 throw new CapabilityNotSupportedError ( 'switchChain' )
128193 } ,
0 commit comments