browser-evm-signer 0.1.0 → 0.1.2

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