browser-evm-signer 0.1.1 → 0.1.3

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.
Files changed (2) hide show
  1. package/README.md +141 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # browser-evm-signer
2
+
3
+ [![npm version](https://img.shields.io/npm/v/browser-evm-signer)](https://www.npmjs.com/package/browser-evm-signer)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ **Sign EVM transactions from Node.js using your browser wallet.** No private keys in your code — ever.
7
+
8
+ Most blockchain libraries require you to paste a private key or mnemonic into your app. `browser-evm-signer` takes a different approach: it opens your actual browser wallet (MetaMask, Rabby, etc.) for every signing action. You review and approve each transaction just like any dapp interaction.
9
+
10
+ | Connect Wallet | Send Transaction | Sign Message |
11
+ |:-:|:-:|:-:|
12
+ | ![Connect Wallet](https://raw.githubusercontent.com/nikicat/mcp-wallet-signer/master/packages/browser-evm-signer/docs/screenshots/connect-wallet.png) | ![Send Transaction](https://raw.githubusercontent.com/nikicat/mcp-wallet-signer/master/packages/browser-evm-signer/docs/screenshots/send-transaction.png) | ![Sign Message](https://raw.githubusercontent.com/nikicat/mcp-wallet-signer/master/packages/browser-evm-signer/docs/screenshots/sign-message.png) |
13
+
14
+ ## Why?
15
+
16
+ - **No private keys in code** — keys stay in your browser wallet, never touch your server
17
+ - **User approves every action** — connect, send, sign all require explicit browser approval
18
+ - **Works with any EIP-6963 wallet** — MetaMask, Rabby, Coinbase Wallet, and more
19
+ - **First-class [viem](https://viem.sh) support** — drop-in transport and account adapters
20
+ - **8 chains built-in** — Ethereum, Polygon, Arbitrum, Optimism, Base, Avalanche, BNB, Sepolia
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ npm install browser-evm-signer viem
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ```ts
31
+ import { WalletSigner } from "browser-evm-signer";
32
+
33
+ const signer = new WalletSigner();
34
+
35
+ // Opens your browser — connect your wallet
36
+ const { address } = await signer.connectWallet();
37
+ console.log("Connected:", address);
38
+
39
+ // Opens your browser — approve the transaction
40
+ const { txHash } = await signer.sendTransaction({
41
+ to: "0xRecipient...",
42
+ value: "1000000000000000000", // 1 ETH in wei
43
+ });
44
+ console.log("Sent:", txHash);
45
+
46
+ // Opens your browser — approve the signature
47
+ const { signature } = await signer.signMessage({ message: "Hello world" });
48
+ console.log("Signed:", signature);
49
+
50
+ await signer.shutdown();
51
+ ```
52
+
53
+ Every method that touches your wallet opens a browser window with an approval page. Nothing happens without your explicit consent.
54
+
55
+ ## viem Integration
56
+
57
+ Use `connectWalletViem` to get a viem-compatible account and transport — then use the standard viem `WalletClient` API:
58
+
59
+ ```ts
60
+ import { createWalletClient } from "viem";
61
+ import { mainnet } from "viem/chains";
62
+ import { WalletSigner, connectWalletViem } from "browser-evm-signer";
63
+
64
+ const signer = new WalletSigner();
65
+ const { account, transport } = await connectWalletViem(signer);
66
+
67
+ const client = createWalletClient({ account, chain: mainnet, transport });
68
+
69
+ // Standard viem API — transactions route through your browser wallet
70
+ const hash = await client.sendTransaction({ to: "0x...", value: 1n });
71
+ ```
72
+
73
+ ## How It Works
74
+
75
+ ```
76
+ Your Node.js app Browser
77
+ ──────────────── ───────
78
+ signer.sendTransaction(...)
79
+
80
+ ├─► Starts local HTTP server
81
+ ├─► Opens browser to approval page ──► Wallet approval UI
82
+ │ │
83
+ │ Waits for user action... User reviews & approves
84
+ │ │
85
+ ◄─── Result returned ◄──────────────────┘
86
+
87
+ └─► { txHash: "0x..." }
88
+ ```
89
+
90
+ 1. Your code calls a signing method
91
+ 2. A local HTTP server spins up and opens a browser page
92
+ 3. The page discovers your wallet via [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963) and shows the approval UI
93
+ 4. You approve (or reject) in your wallet
94
+ 5. The result flows back to your Node.js code
95
+
96
+ ## API Reference
97
+
98
+ ### `WalletSigner`
99
+
100
+ ```ts
101
+ const signer = new WalletSigner({
102
+ port: 3847, // HTTP server port (default: 3847, env: EVM_MCP_PORT)
103
+ defaultChainId: 1, // Default chain ID (default: 1, env: EVM_MCP_DEFAULT_CHAIN)
104
+ openBrowser: true, // true | false | custom (url) => void function
105
+ });
106
+ ```
107
+
108
+ | Method | Description | Opens Browser |
109
+ |--------|-------------|:---:|
110
+ | `connectWallet(options?)` | Connect wallet, get address | Yes |
111
+ | `sendTransaction(params)` | Send ETH or call a contract | Yes |
112
+ | `signMessage(params)` | Sign a message (personal_sign) | Yes |
113
+ | `signTypedData(params)` | Sign EIP-712 typed data | Yes |
114
+ | `getBalance(params)` | Read ETH balance via RPC | No |
115
+ | `start()` | Start HTTP server explicitly | No |
116
+ | `shutdown()` | Stop server, cancel pending requests | No |
117
+
118
+ ### `connectWalletViem(signer, options?)`
119
+
120
+ Returns `{ account, transport }` for use with viem's `createWalletClient`.
121
+
122
+ ### `walletSignerTransport(signer, options?)`
123
+
124
+ Creates a viem custom transport. Wallet methods go through the browser; read methods go to RPC.
125
+
126
+ ## Supported Chains
127
+
128
+ | Chain | ID |
129
+ |-------|---:|
130
+ | Ethereum | 1 |
131
+ | Sepolia | 11155111 |
132
+ | Polygon | 137 |
133
+ | Arbitrum One | 42161 |
134
+ | Optimism | 10 |
135
+ | Base | 8453 |
136
+ | Avalanche | 43114 |
137
+ | BNB Smart Chain | 56 |
138
+
139
+ ## License
140
+
141
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-evm-signer",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Route EVM transactions to browser wallets for signing — standalone library, no MCP dependency",
5
5
  "keywords": [
6
6
  "wallet",