@usebutr/evm 0.2.0 → 0.2.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.
- package/dist/index.d.ts +1 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +523 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainBase, PlatformDiscoverer, WalletAdapter, WalletCapabilities } from "@usebutr/core";
|
|
1
|
+
import { ChainBase, PlatformDiscoverer, WalletAdapter, WalletCapabilities, bytesToHexPrefixed as bytesToHex, hexToBytes } from "@usebutr/core";
|
|
2
2
|
|
|
3
3
|
//#region src/eip1193.d.ts
|
|
4
4
|
/**
|
|
@@ -66,13 +66,6 @@ type DiscoverOptions = {
|
|
|
66
66
|
declare const discoverEvmAdapters: (onAdapter: AdapterCallback, options?: DiscoverOptions) => (() => void);
|
|
67
67
|
//#endregion
|
|
68
68
|
//#region src/eip6963-adapter.d.ts
|
|
69
|
-
/**
|
|
70
|
-
* Convert a hex string (with or without `0x` prefix) into a Uint8Array.
|
|
71
|
-
* Odd-length strings are not supported; EIP-1193 returns canonical
|
|
72
|
-
* even-length hex.
|
|
73
|
-
*/
|
|
74
|
-
declare const hexToBytes: (hex: string) => Uint8Array;
|
|
75
|
-
declare const bytesToHex: (bytes: Uint8Array) => string;
|
|
76
69
|
declare const chainIdHexToDecimal: (hex: string) => string;
|
|
77
70
|
declare const chainIdDecimalToHex: (dec: string) => string;
|
|
78
71
|
/** Pure 18-decimal wei → ether formatter. Trims trailing zeros so
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/eip1193.ts","../src/eip6963.ts","../src/eip6963-adapter.ts","../src/injected.ts","../src/chains.ts","../src/capabilities.ts","../src/discoverer.ts","../src/signer-augmentation.ts"],"mappings":";;;;;;;;;;;;;KAWK,kBAAA;EACH,MAAA;EACA,MAAA,GAAS,aAAa;AAAA;AAAA,KAGnB,eAAA,OAAsB,IAAA,EAAM,aAAa;AAAA,KAEzC,eAAA;EACH,EAAA,CAAG,KAAA,UAAe,QAAA,EAAU,eAAA;EAC5B,cAAA,CAAe,KAAA,UAAe,QAAA,EAAU,eAAA;EACxC,OAAA,CAAQ,IAAA,EAAM,kBAAA,GAAqB,OAAA;AAAA;AAAA,KAGhC,mBAAA;EAJqC,8DAMxC,IAAA,UALmC;EAOnC,IAAA;EAP0C;;EAU1C,IAAA,UAZ4B;EAc5B,IAAA;AAAA;AAAA,KAGG,qBAAA;EACH,IAAA,EAAM,mBAAA;EACN,QAAA,EAAU,eAAe;AAAA;AAAA,KAGtB,oBAAA,GAAuB,WAAW,CAAC,qBAAA;;;cCpClC,cAAA;AAAA,cACA,aAAA;AAAA,KAED,eAAA,IAAmB,OAAA,EAAS,aAAA,EAAe,IAAA,EAAM,mBAAmB;AAAA,KAEpE,eAAA;EDGmB;;;ECCtB,MAAA,GAAS,WAAW;AAAA;ADDE;AAAA;;;;AAGsB;AAAA;;;;;;;;;;;;AAHtB,cCwClB,mBAAA,GACJ,SAAA,EAAW,eAAA,EACX,OAAA,GAAS,eAAoB
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/eip1193.ts","../src/eip6963.ts","../src/eip6963-adapter.ts","../src/injected.ts","../src/chains.ts","../src/capabilities.ts","../src/discoverer.ts","../src/signer-augmentation.ts"],"mappings":";;;;;;;;;;;;;KAWK,kBAAA;EACH,MAAA;EACA,MAAA,GAAS,aAAa;AAAA;AAAA,KAGnB,eAAA,OAAsB,IAAA,EAAM,aAAa;AAAA,KAEzC,eAAA;EACH,EAAA,CAAG,KAAA,UAAe,QAAA,EAAU,eAAA;EAC5B,cAAA,CAAe,KAAA,UAAe,QAAA,EAAU,eAAA;EACxC,OAAA,CAAQ,IAAA,EAAM,kBAAA,GAAqB,OAAA;AAAA;AAAA,KAGhC,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;;;;;;;;;;;;;cCnBI,aAAA,EAAe,kBASpB;;;;;;;;;;;;;YCXW,iBAAA;IACR,GAAA,EAAK,eAAe;EAAA;AAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,524 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { bytesToHexPrefixed as bytesToHex, hexToBytes, sanitizeIcon } from "@usebutr/core";
|
|
2
|
+
|
|
3
|
+
//#region src/capabilities.ts
|
|
4
|
+
const EIP6963_RDNS_WITH_REQUEST_ACCOUNTS = new Set(["io.metamask"]);
|
|
5
|
+
const resolveEip6963Capabilities = (input) => ({
|
|
6
|
+
getBalance: true,
|
|
7
|
+
getTransactionReceipt: true,
|
|
8
|
+
requestAccounts: EIP6963_RDNS_WITH_REQUEST_ACCOUNTS.has(input.rdns),
|
|
9
|
+
sendTransaction: true,
|
|
10
|
+
signIn: false,
|
|
11
|
+
signMessage: true,
|
|
12
|
+
signTransaction: false,
|
|
13
|
+
subscribe: true,
|
|
14
|
+
switchAccount: false,
|
|
15
|
+
switchChain: true
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/eip6963-adapter.ts
|
|
20
|
+
const HEX_PREFIX = "0x";
|
|
21
|
+
const ETH_DECIMALS = 18n;
|
|
22
|
+
const ETH_UNIT = 10n ** ETH_DECIMALS;
|
|
23
|
+
const chainIdHexToDecimal = (hex) => BigInt(hex).toString(10);
|
|
24
|
+
const chainIdDecimalToHex = (dec) => `${HEX_PREFIX}${BigInt(dec).toString(16)}`;
|
|
25
|
+
/** Pure 18-decimal wei → ether formatter. Trims trailing zeros so
|
|
26
|
+
* `1.0` stays `1` and `1.5` stays `1.5`. */
|
|
27
|
+
const formatEther = (wei) => {
|
|
28
|
+
const integer = wei / ETH_UNIT;
|
|
29
|
+
const remainder = wei % ETH_UNIT;
|
|
30
|
+
if (remainder === 0n) return integer.toString();
|
|
31
|
+
const fraction = remainder.toString().padStart(Number(ETH_DECIMALS), "0").replace(/* @__PURE__ */ new RegExp("0+$", "v"), "");
|
|
32
|
+
return fraction.length > 0 ? `${integer}.${fraction}` : integer.toString();
|
|
33
|
+
};
|
|
34
|
+
/** General-purpose `value / 10^decimals` formatter that trims trailing
|
|
35
|
+
* zeros. Mirrors `formatEther` but for arbitrary token decimals. */
|
|
36
|
+
const formatTokenUnits = (raw, decimals) => {
|
|
37
|
+
if (decimals === 0) return raw.toString();
|
|
38
|
+
const unit = 10n ** BigInt(decimals);
|
|
39
|
+
const integer = raw / unit;
|
|
40
|
+
const remainder = raw % unit;
|
|
41
|
+
if (remainder === 0n) return integer.toString();
|
|
42
|
+
const fraction = remainder.toString().padStart(decimals, "0").replace(/* @__PURE__ */ new RegExp("0+$", "v"), "");
|
|
43
|
+
return fraction.length > 0 ? `${integer}.${fraction}` : integer.toString();
|
|
44
|
+
};
|
|
45
|
+
const ERC20_BALANCE_OF_SELECTOR = "0x70a08231";
|
|
46
|
+
const ERC20_DECIMALS_SELECTOR = "0x313ce567";
|
|
47
|
+
const ERC20_SYMBOL_SELECTOR = "0x95d89b41";
|
|
48
|
+
const padAddressForCall = (address) => address.replace(/* @__PURE__ */ new RegExp("^0x", "v"), "").toLowerCase().padStart(64, "0");
|
|
49
|
+
/**
|
|
50
|
+
* Decode an ABI-encoded `string` return value. Layout:
|
|
51
|
+
* bytes 0–31 : offset to the data (always 0x20 for a single string)
|
|
52
|
+
* bytes 32–63 : string length (big-endian uint256)
|
|
53
|
+
* bytes 64+ : UTF-8 bytes, right-padded to a 32-byte boundary
|
|
54
|
+
*
|
|
55
|
+
* Some non-standard tokens (early MakerDAO, etc.) return a `bytes32`
|
|
56
|
+
* directly instead of a length-prefixed string; the fallback strips
|
|
57
|
+
* trailing nulls and decodes the raw bytes.
|
|
58
|
+
*/
|
|
59
|
+
const decodeAbiString = (hex) => {
|
|
60
|
+
const clean = hex.startsWith(HEX_PREFIX) ? hex.slice(2) : hex;
|
|
61
|
+
if (clean.length === 0) return "";
|
|
62
|
+
if (clean.length >= 128) {
|
|
63
|
+
const lengthHex = clean.slice(64, 128);
|
|
64
|
+
const length = Number(BigInt(`0x${lengthHex}`));
|
|
65
|
+
if (length > 0 && clean.length >= 128 + length * 2) {
|
|
66
|
+
const dataHex = clean.slice(128, 128 + length * 2);
|
|
67
|
+
return new TextDecoder().decode(hexToBytes(dataHex));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const buf = hexToBytes(clean.slice(0, 64));
|
|
71
|
+
let end = buf.length;
|
|
72
|
+
while (end > 0 && buf[end - 1] === 0) end -= 1;
|
|
73
|
+
return new TextDecoder().decode(buf.subarray(0, end));
|
|
74
|
+
};
|
|
75
|
+
const buildEvmChain = (chainIdHex, walletName) => {
|
|
76
|
+
const reference = chainIdHexToDecimal(chainIdHex);
|
|
77
|
+
return {
|
|
78
|
+
id: `eip155:${reference}`,
|
|
79
|
+
name: walletName,
|
|
80
|
+
namespace: "eip155",
|
|
81
|
+
reference
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
const buildEvmAccount = (address, chain) => ({
|
|
85
|
+
chain,
|
|
86
|
+
id: `${chain.id}:${address.toLowerCase()}`,
|
|
87
|
+
walletAddress: address
|
|
88
|
+
});
|
|
89
|
+
/**
|
|
90
|
+
* Adapt an EIP-1193 provider (announced via EIP-6963) into a butr
|
|
91
|
+
* `WalletAdapter`. The returned adapter covers the full `Connector +
|
|
92
|
+
* Wallet` surface; consumers can pass it through `createConnector` like
|
|
93
|
+
* any hand-written adapter.
|
|
94
|
+
*
|
|
95
|
+
* **Caveats**
|
|
96
|
+
*
|
|
97
|
+
* - `disconnect` calls `wallet_revokePermissions`. Many wallets don't
|
|
98
|
+
* implement that method and silently ignore the call. The reducer
|
|
99
|
+
* will still mark the wallet as disconnected on butr's side; the
|
|
100
|
+
* wallet's own auto-reconnect heuristic may or may not honour it.
|
|
101
|
+
* - `switchAccount` is intentionally unimplemented because EIP-1193 has
|
|
102
|
+
* no silent "use address X" RPC. The active account is whichever one
|
|
103
|
+
* the wallet exposes first; the user changes it through the wallet's
|
|
104
|
+
* own UI. butr's `subscribe` bridge auto-updates the pool entry when
|
|
105
|
+
* `accountsChanged` fires. Call `requestAccounts` if you want the
|
|
106
|
+
* wallet to expose more accounts.
|
|
107
|
+
* - `getBalance()` returns the native ETH balance with symbol `"ETH"`
|
|
108
|
+
* regardless of which EVM chain the wallet is currently on. Consumers
|
|
109
|
+
* that target multiple EVM chains should overlay the symbol via
|
|
110
|
+
* their own logic.
|
|
111
|
+
* - `getBalance(tokenAddress)` reads the ERC20 balance for the active
|
|
112
|
+
* account on the currently-connected chain. The token's own
|
|
113
|
+
* `decimals()` and `symbol()` are queried for accurate formatting;
|
|
114
|
+
* if `symbol()` is non-standard (bytes32) it's decoded as best-
|
|
115
|
+
* effort. Routed through `eth_call` on the wallet's own provider
|
|
116
|
+
* — the demo doesn't ship a separate RPC.
|
|
117
|
+
* - `getSigner` returns the raw EIP-1193 provider. Wrap it in viem's
|
|
118
|
+
* `createWalletClient` or ethers' `BrowserProvider` at the call site.
|
|
119
|
+
*/
|
|
120
|
+
const buildEvmAdapter = (info, provider) => {
|
|
121
|
+
return {
|
|
122
|
+
capabilities: resolveEip6963Capabilities({ rdns: info.rdns }),
|
|
123
|
+
chainPlatform: "evm",
|
|
124
|
+
async connect(opts) {
|
|
125
|
+
if (opts?.silent) {
|
|
126
|
+
if ((await provider.request({ method: "eth_accounts" })).length === 0) throw new Error("No authorized accounts for silent reconnect");
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
await provider.request({ method: "eth_requestAccounts" });
|
|
130
|
+
},
|
|
131
|
+
async disconnect() {
|
|
132
|
+
try {
|
|
133
|
+
await provider.request({
|
|
134
|
+
method: "wallet_revokePermissions",
|
|
135
|
+
params: [{ eth_accounts: {} }]
|
|
136
|
+
});
|
|
137
|
+
} catch {}
|
|
138
|
+
},
|
|
139
|
+
async getAccount() {
|
|
140
|
+
const accounts = await provider.request({ method: "eth_accounts" });
|
|
141
|
+
if (accounts.length === 0) return null;
|
|
142
|
+
const chain = buildEvmChain(await provider.request({ method: "eth_chainId" }), info.name);
|
|
143
|
+
const first = accounts[0];
|
|
144
|
+
if (!first) return null;
|
|
145
|
+
return buildEvmAccount(first, chain);
|
|
146
|
+
},
|
|
147
|
+
async getAccounts() {
|
|
148
|
+
const accounts = await provider.request({ method: "eth_accounts" });
|
|
149
|
+
if (accounts.length === 0) return [];
|
|
150
|
+
const chain = buildEvmChain(await provider.request({ method: "eth_chainId" }), info.name);
|
|
151
|
+
return accounts.map((addr) => buildEvmAccount(addr, chain));
|
|
152
|
+
},
|
|
153
|
+
async getBalance(mint) {
|
|
154
|
+
const first = (await provider.request({ method: "eth_accounts" }))[0];
|
|
155
|
+
if (!first) throw new Error("No connected account");
|
|
156
|
+
if (!mint) {
|
|
157
|
+
const balanceHex = await provider.request({
|
|
158
|
+
method: "eth_getBalance",
|
|
159
|
+
params: [first, "latest"]
|
|
160
|
+
});
|
|
161
|
+
const value = BigInt(balanceHex);
|
|
162
|
+
return {
|
|
163
|
+
decimals: Number(ETH_DECIMALS),
|
|
164
|
+
formatted: formatEther(value),
|
|
165
|
+
symbol: "ETH",
|
|
166
|
+
value
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const balanceCallData = `${ERC20_BALANCE_OF_SELECTOR}${padAddressForCall(first)}`;
|
|
170
|
+
const [balanceHex, decimalsHex, symbolHex] = await Promise.all([
|
|
171
|
+
provider.request({
|
|
172
|
+
method: "eth_call",
|
|
173
|
+
params: [{
|
|
174
|
+
data: balanceCallData,
|
|
175
|
+
to: mint
|
|
176
|
+
}, "latest"]
|
|
177
|
+
}),
|
|
178
|
+
provider.request({
|
|
179
|
+
method: "eth_call",
|
|
180
|
+
params: [{
|
|
181
|
+
data: ERC20_DECIMALS_SELECTOR,
|
|
182
|
+
to: mint
|
|
183
|
+
}, "latest"]
|
|
184
|
+
}),
|
|
185
|
+
provider.request({
|
|
186
|
+
method: "eth_call",
|
|
187
|
+
params: [{
|
|
188
|
+
data: ERC20_SYMBOL_SELECTOR,
|
|
189
|
+
to: mint
|
|
190
|
+
}, "latest"]
|
|
191
|
+
})
|
|
192
|
+
]);
|
|
193
|
+
const value = BigInt(balanceHex);
|
|
194
|
+
const decimals = Number(BigInt(decimalsHex));
|
|
195
|
+
const symbol = decodeAbiString(symbolHex);
|
|
196
|
+
return {
|
|
197
|
+
decimals,
|
|
198
|
+
formatted: formatTokenUnits(value, decimals),
|
|
199
|
+
symbol,
|
|
200
|
+
value
|
|
201
|
+
};
|
|
202
|
+
},
|
|
203
|
+
getSigner() {
|
|
204
|
+
return Promise.resolve(provider);
|
|
205
|
+
},
|
|
206
|
+
async getTransactionReceipt(tx) {
|
|
207
|
+
const receipt = await provider.request({
|
|
208
|
+
method: "eth_getTransactionReceipt",
|
|
209
|
+
params: [tx]
|
|
210
|
+
});
|
|
211
|
+
if (!receipt) return { status: "Pending" };
|
|
212
|
+
return { status: receipt.status === "0x1" ? "Success" : "Error" };
|
|
213
|
+
},
|
|
214
|
+
icon: sanitizeIcon(info.icon),
|
|
215
|
+
id: info.rdns,
|
|
216
|
+
name: info.name,
|
|
217
|
+
async requestAccounts() {
|
|
218
|
+
try {
|
|
219
|
+
await provider.request({
|
|
220
|
+
method: "wallet_requestPermissions",
|
|
221
|
+
params: [{ eth_accounts: {} }]
|
|
222
|
+
});
|
|
223
|
+
} catch (error) {
|
|
224
|
+
const err = error;
|
|
225
|
+
const outerCode = err?.code;
|
|
226
|
+
const innerCode = err?.data?.originalError?.code;
|
|
227
|
+
if (outerCode === 4200 || outerCode === -32601 || outerCode === -32603 || innerCode === 4200 || innerCode === -32601 || innerCode === -32604) {
|
|
228
|
+
await provider.request({ method: "eth_requestAccounts" });
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
async sendTx(tx, account) {
|
|
235
|
+
const txWithFrom = account ? {
|
|
236
|
+
...tx,
|
|
237
|
+
from: account.walletAddress
|
|
238
|
+
} : tx;
|
|
239
|
+
return await provider.request({
|
|
240
|
+
method: "eth_sendTransaction",
|
|
241
|
+
params: [txWithFrom]
|
|
242
|
+
});
|
|
243
|
+
},
|
|
244
|
+
async sendTxToChain(tx, targetChainIdDecimal, account, cb) {
|
|
245
|
+
const current = await provider.request({ method: "eth_chainId" });
|
|
246
|
+
const targetHex = chainIdDecimalToHex(targetChainIdDecimal);
|
|
247
|
+
if (current.toLowerCase() !== targetHex.toLowerCase()) {
|
|
248
|
+
await provider.request({
|
|
249
|
+
method: "wallet_switchEthereumChain",
|
|
250
|
+
params: [{ chainId: targetHex }]
|
|
251
|
+
});
|
|
252
|
+
cb?.();
|
|
253
|
+
}
|
|
254
|
+
const txWithFrom = account ? {
|
|
255
|
+
...tx,
|
|
256
|
+
from: account.walletAddress
|
|
257
|
+
} : tx;
|
|
258
|
+
return await provider.request({
|
|
259
|
+
method: "eth_sendTransaction",
|
|
260
|
+
params: [txWithFrom]
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
async signMessage(msg, account) {
|
|
264
|
+
let signer = account?.walletAddress;
|
|
265
|
+
if (!signer) signer = (await provider.request({ method: "eth_accounts" }))[0];
|
|
266
|
+
if (!signer) throw new Error("No connected account");
|
|
267
|
+
return {
|
|
268
|
+
signature: hexToBytes(await provider.request({
|
|
269
|
+
method: "personal_sign",
|
|
270
|
+
params: [bytesToHex(msg), signer]
|
|
271
|
+
})),
|
|
272
|
+
signedMessage: msg
|
|
273
|
+
};
|
|
274
|
+
},
|
|
275
|
+
subscribe(listener) {
|
|
276
|
+
const onAccountsChanged = (...args) => {
|
|
277
|
+
const accs = args[0];
|
|
278
|
+
if (accs.length === 0) {
|
|
279
|
+
listener({ type: "disconnected" });
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
provider.request({ method: "eth_chainId" }).then((chainIdHex) => {
|
|
283
|
+
const chain = buildEvmChain(chainIdHex, info.name);
|
|
284
|
+
const accounts = accs.map((addr) => buildEvmAccount(addr, chain));
|
|
285
|
+
const first = accounts[0];
|
|
286
|
+
if (!first) return;
|
|
287
|
+
listener({
|
|
288
|
+
account: first,
|
|
289
|
+
accounts,
|
|
290
|
+
type: "accountChanged"
|
|
291
|
+
});
|
|
292
|
+
}).catch(() => {});
|
|
293
|
+
};
|
|
294
|
+
const onChainChanged = (...args) => {
|
|
295
|
+
const chainIdHex = args[0];
|
|
296
|
+
provider.request({ method: "eth_accounts" }).then((accounts) => {
|
|
297
|
+
const accs = accounts;
|
|
298
|
+
if (accs.length === 0) return;
|
|
299
|
+
const chain = buildEvmChain(chainIdHex, info.name);
|
|
300
|
+
const built = accs.map((addr) => buildEvmAccount(addr, chain));
|
|
301
|
+
const first = built[0];
|
|
302
|
+
if (!first) return;
|
|
303
|
+
listener({
|
|
304
|
+
account: first,
|
|
305
|
+
accounts: built,
|
|
306
|
+
type: "accountChanged"
|
|
307
|
+
});
|
|
308
|
+
}).catch(() => {});
|
|
309
|
+
};
|
|
310
|
+
const onDisconnect = () => {
|
|
311
|
+
listener({ type: "disconnected" });
|
|
312
|
+
};
|
|
313
|
+
const onConnect = () => {
|
|
314
|
+
Promise.all([provider.request({ method: "eth_accounts" }), provider.request({ method: "eth_chainId" })]).then(([accountsRaw, chainIdHex]) => {
|
|
315
|
+
const accs = accountsRaw;
|
|
316
|
+
if (accs.length === 0) return;
|
|
317
|
+
const chain = buildEvmChain(chainIdHex, info.name);
|
|
318
|
+
const built = accs.map((addr) => buildEvmAccount(addr, chain));
|
|
319
|
+
const first = built[0];
|
|
320
|
+
if (!first) return;
|
|
321
|
+
listener({
|
|
322
|
+
account: first,
|
|
323
|
+
accounts: built,
|
|
324
|
+
type: "accountChanged"
|
|
325
|
+
});
|
|
326
|
+
}).catch(() => {});
|
|
327
|
+
};
|
|
328
|
+
provider.on("accountsChanged", onAccountsChanged);
|
|
329
|
+
provider.on("chainChanged", onChainChanged);
|
|
330
|
+
provider.on("connect", onConnect);
|
|
331
|
+
provider.on("disconnect", onDisconnect);
|
|
332
|
+
return () => {
|
|
333
|
+
provider.removeListener("accountsChanged", onAccountsChanged);
|
|
334
|
+
provider.removeListener("chainChanged", onChainChanged);
|
|
335
|
+
provider.removeListener("connect", onConnect);
|
|
336
|
+
provider.removeListener("disconnect", onDisconnect);
|
|
337
|
+
};
|
|
338
|
+
},
|
|
339
|
+
async switchChain(chain) {
|
|
340
|
+
await provider.request({
|
|
341
|
+
method: "wallet_switchEthereumChain",
|
|
342
|
+
params: [{ chainId: chainIdDecimalToHex(chain.reference) }]
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/eip6963.ts
|
|
350
|
+
const ANNOUNCE_EVENT = "eip6963:announceProvider";
|
|
351
|
+
const REQUEST_EVENT = "eip6963:requestProvider";
|
|
352
|
+
const resolveTarget = (target) => {
|
|
353
|
+
if (target) return target;
|
|
354
|
+
const candidate = globalThis.window;
|
|
355
|
+
if (!candidate || typeof candidate.addEventListener !== "function") return null;
|
|
356
|
+
return candidate;
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
* Subscribe to EIP-6963 wallet announcements. Spec:
|
|
360
|
+
* https://eips.ethereum.org/EIPS/eip-6963
|
|
361
|
+
*
|
|
362
|
+
* Flow:
|
|
363
|
+
* 1. Page registers a listener for `eip6963:announceProvider`.
|
|
364
|
+
* 2. Page dispatches `eip6963:requestProvider` to kick wallets that
|
|
365
|
+
* have already loaded.
|
|
366
|
+
* 3. Wallets that load later still dispatch their own announcement
|
|
367
|
+
* when they boot, so the listener stays attached for the lifetime
|
|
368
|
+
* of the discovery session.
|
|
369
|
+
* 4. Dedup by `info.rdns` — wallets occasionally re-announce, and
|
|
370
|
+
* `info.uuid` is regenerated per page load so it's not stable.
|
|
371
|
+
*
|
|
372
|
+
* Returns an unsubscribe function that removes the listener.
|
|
373
|
+
* In non-browser environments (SSR, tests with no window) returns
|
|
374
|
+
* a noop unsubscribe and never fires the callback.
|
|
375
|
+
*/
|
|
376
|
+
const discoverEvmAdapters = (onAdapter, options = {}) => {
|
|
377
|
+
const target = resolveTarget(options.target);
|
|
378
|
+
if (!target) return () => {};
|
|
379
|
+
const seen = /* @__PURE__ */ new Set();
|
|
380
|
+
const handler = (event) => {
|
|
381
|
+
const detail = event.detail;
|
|
382
|
+
if (!detail || !detail.info || !detail.provider) return;
|
|
383
|
+
const { info, provider } = detail;
|
|
384
|
+
if (typeof info.rdns !== "string" || info.rdns.length === 0) return;
|
|
385
|
+
if (seen.has(info.rdns)) return;
|
|
386
|
+
seen.add(info.rdns);
|
|
387
|
+
onAdapter(buildEvmAdapter(info, provider), info);
|
|
388
|
+
};
|
|
389
|
+
target.addEventListener(ANNOUNCE_EVENT, handler);
|
|
390
|
+
target.dispatchEvent(new Event(REQUEST_EVENT));
|
|
391
|
+
return () => {
|
|
392
|
+
target.removeEventListener(ANNOUNCE_EVENT, handler);
|
|
393
|
+
};
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
//#endregion
|
|
397
|
+
//#region src/injected.ts
|
|
398
|
+
/**
|
|
399
|
+
* Generic wallet icon (a stylised purse SVG, ~600 bytes). Used as
|
|
400
|
+
* the fallback icon when an injected provider has no EIP-6963 info.
|
|
401
|
+
* Inline rather than a network fetch so the picker doesn't flicker.
|
|
402
|
+
*/
|
|
403
|
+
const GENERIC_INJECTED_ICON = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSJjdXJyZW50Q29sb3IiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNMjEgMTJWN0g1YTIgMiAwIDAgMSAwLTQgaDE0djQiLz48cGF0aCBkPSJNMyA1djE0YTIgMiAwIDAgMCAyIDJoMTZ2LTVNMjEgMTIgaC0zYTIgMiAwIDAgMC0yIDJ2MGEyIDIgMCAwIDAgMiAyaDN6Ii8+PC9zdmc+";
|
|
404
|
+
const DEFAULT_SETTLE_MS = 150;
|
|
405
|
+
const readEthereum = (target) => {
|
|
406
|
+
const host = target === void 0 ? typeof window === "undefined" ? null : window : target;
|
|
407
|
+
if (!host) return null;
|
|
408
|
+
const eth = host.ethereum;
|
|
409
|
+
if (!eth || typeof eth.request !== "function") return null;
|
|
410
|
+
return eth;
|
|
411
|
+
};
|
|
412
|
+
/**
|
|
413
|
+
* Last-resort discovery path for EVM wallets that DON'T announce via
|
|
414
|
+
* EIP-6963. Most modern wallets (MetaMask, Rabby, Coinbase, Phantom,
|
|
415
|
+
* Brave, etc.) do announce, so the standards-based path
|
|
416
|
+
* (`discoverEvmAdapters`) covers them. This module catches the long
|
|
417
|
+
* tail: regional wallets (KuCoin, Bitget, BitKeep, Okto, Frontier)
|
|
418
|
+
* and older builds that only expose `window.ethereum`.
|
|
419
|
+
*
|
|
420
|
+
* **Coordination**: the fallback waits `settleMs` (default 150ms)
|
|
421
|
+
* after subscription, then consults `hasAnyEip6963Adapter` if
|
|
422
|
+
* provided. If any EIP-6963 adapter has already been registered, we
|
|
423
|
+
* skip emission — assume the same wallet is also speaking standards
|
|
424
|
+
* and we'd just be duplicating. If no EIP-6963 adapter showed up but
|
|
425
|
+
* `window.ethereum` does, we emit a generic adapter.
|
|
426
|
+
*
|
|
427
|
+
* The emitted adapter has `rdns: "injected:legacy"` so consumers can
|
|
428
|
+
* distinguish it from EIP-6963 adapters in the picker UI.
|
|
429
|
+
*/
|
|
430
|
+
const discoverInjectedAdapter = (onAdapter, options = {}) => {
|
|
431
|
+
const settleMs = options.settleMs ?? DEFAULT_SETTLE_MS;
|
|
432
|
+
let cancelled = false;
|
|
433
|
+
const timer = setTimeout(() => {
|
|
434
|
+
if (cancelled) return;
|
|
435
|
+
if (options.hasAnyEip6963Adapter?.()) return;
|
|
436
|
+
const provider = readEthereum(options.target);
|
|
437
|
+
if (!provider) return;
|
|
438
|
+
onAdapter(buildEvmAdapter({
|
|
439
|
+
icon: GENERIC_INJECTED_ICON,
|
|
440
|
+
name: "Browser wallet",
|
|
441
|
+
rdns: "injected:legacy",
|
|
442
|
+
uuid: "injected:legacy"
|
|
443
|
+
}, provider));
|
|
444
|
+
}, settleMs);
|
|
445
|
+
return () => {
|
|
446
|
+
cancelled = true;
|
|
447
|
+
clearTimeout(timer);
|
|
448
|
+
};
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region src/chains.ts
|
|
453
|
+
/**
|
|
454
|
+
* Common EVM chain registry keyed by CAIP-2 id. Useful for chain-
|
|
455
|
+
* switcher UIs. butr itself doesn't read this — `Connector.switchChain`
|
|
456
|
+
* accepts any `ChainBase`.
|
|
457
|
+
*/
|
|
458
|
+
const EVM_CHAINS = {
|
|
459
|
+
arbitrum: {
|
|
460
|
+
id: "eip155:42161",
|
|
461
|
+
name: "Arbitrum One",
|
|
462
|
+
namespace: "eip155",
|
|
463
|
+
reference: "42161"
|
|
464
|
+
},
|
|
465
|
+
base: {
|
|
466
|
+
id: "eip155:8453",
|
|
467
|
+
name: "Base",
|
|
468
|
+
namespace: "eip155",
|
|
469
|
+
reference: "8453"
|
|
470
|
+
},
|
|
471
|
+
bsc: {
|
|
472
|
+
id: "eip155:56",
|
|
473
|
+
name: "BNB Smart Chain",
|
|
474
|
+
namespace: "eip155",
|
|
475
|
+
reference: "56"
|
|
476
|
+
},
|
|
477
|
+
ethereum: {
|
|
478
|
+
id: "eip155:1",
|
|
479
|
+
name: "Ethereum",
|
|
480
|
+
namespace: "eip155",
|
|
481
|
+
reference: "1"
|
|
482
|
+
},
|
|
483
|
+
optimism: {
|
|
484
|
+
id: "eip155:10",
|
|
485
|
+
name: "Optimism",
|
|
486
|
+
namespace: "eip155",
|
|
487
|
+
reference: "10"
|
|
488
|
+
},
|
|
489
|
+
polygon: {
|
|
490
|
+
id: "eip155:137",
|
|
491
|
+
name: "Polygon",
|
|
492
|
+
namespace: "eip155",
|
|
493
|
+
reference: "137"
|
|
494
|
+
},
|
|
495
|
+
sepolia: {
|
|
496
|
+
id: "eip155:11155111",
|
|
497
|
+
name: "Sepolia",
|
|
498
|
+
namespace: "eip155",
|
|
499
|
+
reference: "11155111"
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
const EVM_CHAINS_LIST = Object.values(EVM_CHAINS);
|
|
503
|
+
|
|
504
|
+
//#endregion
|
|
505
|
+
//#region src/discoverer.ts
|
|
506
|
+
/**
|
|
507
|
+
* EVM's `PlatformDiscoverer`: EIP-6963 announcements primary, with the
|
|
508
|
+
* legacy `window.ethereum` injected fallback wired to defer until
|
|
509
|
+
* EIP-6963 has had a chance to fire.
|
|
510
|
+
*
|
|
511
|
+
* Consumers using `@usebutr/wallets`'s `autoDiscovery()` get this
|
|
512
|
+
* wired in automatically. Direct consumers who don't want the
|
|
513
|
+
* injected fallback build their own discovery source from
|
|
514
|
+
* `discoverEvmAdapters` alone.
|
|
515
|
+
*/
|
|
516
|
+
const evmDiscoverer = {
|
|
517
|
+
fallback: { subscribe: (onAdapter, opts) => discoverInjectedAdapter(onAdapter, { hasAnyEip6963Adapter: opts.hasAnyPrimaryAdapter }) },
|
|
518
|
+
platform: "evm",
|
|
519
|
+
subscribe: discoverEvmAdapters
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
//#endregion
|
|
523
|
+
export { ANNOUNCE_EVENT, EIP6963_RDNS_WITH_REQUEST_ACCOUNTS, EVM_CHAINS, EVM_CHAINS_LIST, GENERIC_INJECTED_ICON, REQUEST_EVENT, buildEvmAdapter, bytesToHex, chainIdDecimalToHex, chainIdHexToDecimal, discoverEvmAdapters, discoverInjectedAdapter, evmDiscoverer, formatEther, hexToBytes, resolveEip6963Capabilities };
|
|
2
524
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["announce"],"sources":["../src/capabilities.ts","../src/eip6963-adapter.ts","../src/eip6963.ts","../src/injected.ts","../src/chains.ts","../src/discoverer.ts"],"sourcesContent":["import type { WalletCapabilities } from \"@usebutr/core\";\n\n// Allow-list of EIP-6963 wallets whose `wallet_requestPermissions` call\n// actually surfaces a fresh account-picker UI (the spec intent).\n// Every other tested wallet either rejects the method (Phantom EVM,\n// Coinbase Wallet) or silently returns the existing accounts (Rabby,\n// OKX, Binance, Backpack EVM), making the affordance a no-op.\n//\n// Listed by EIP-6963 `rdns`. Add a wallet here only after verifying\n// against the real install that calling `requestAccounts` surfaces a\n// picker. The capability flag gates UI affordances — `requestAccounts`\n// stays callable on every adapter for consumers with wallet-specific\n// flows.\nconst EIP6963_RDNS_WITH_REQUEST_ACCOUNTS = new Set<string>([\n \"io.metamask\", // MetaMask — verified May 2026\n]);\n\ntype Eip6963CapabilityInput = { rdns: string };\n\nconst resolveEip6963Capabilities = (input: Eip6963CapabilityInput): WalletCapabilities => ({\n getBalance: true,\n getTransactionReceipt: true,\n requestAccounts: EIP6963_RDNS_WITH_REQUEST_ACCOUNTS.has(input.rdns),\n sendTransaction: true,\n // SIWS is Solana-only.\n signIn: false,\n signMessage: true,\n // EVM adapters don't expose a standalone signTransaction (most\n // wallets reject eth_signTransaction); use sendTx.\n signTransaction: false,\n subscribe: true,\n // EIP-1193 has no silent \"use address X\" RPC.\n switchAccount: false,\n switchChain: true,\n});\n\nexport type { Eip6963CapabilityInput };\nexport { EIP6963_RDNS_WITH_REQUEST_ACCOUNTS, resolveEip6963Capabilities };\n","import type { Account, ChainBase, WalletAdapter } from \"@usebutr/core\";\nimport { sanitizeIcon } from \"@usebutr/core\";\n\nimport { resolveEip6963Capabilities } from \"./capabilities\";\nimport type { Eip1193Listener, Eip1193Provider, Eip6963ProviderInfo } from \"./eip1193\";\n\nconst HEX_PREFIX = \"0x\";\nconst ETH_DECIMALS = 18n;\nconst ETH_UNIT = 10n ** ETH_DECIMALS;\n\n/**\n * Convert a hex string (with or without `0x` prefix) into a Uint8Array.\n * Odd-length strings are not supported; EIP-1193 returns canonical\n * even-length hex.\n */\nconst hexToBytes = (hex: string): Uint8Array => {\n const clean = hex.startsWith(HEX_PREFIX) ? hex.slice(2) : hex;\n const out = new Uint8Array(clean.length / 2);\n for (let i = 0; i < out.length; i += 1) {\n out[i] = Number.parseInt(clean.slice(i * 2, i * 2 + 2), 16);\n }\n return out;\n};\n\nconst bytesToHex = (bytes: Uint8Array): string => {\n let hex = HEX_PREFIX;\n for (const byte of bytes) {\n hex += byte.toString(16).padStart(2, \"0\");\n }\n return hex;\n};\n\nconst chainIdHexToDecimal = (hex: string): string => BigInt(hex).toString(10);\nconst chainIdDecimalToHex = (dec: string): string => `${HEX_PREFIX}${BigInt(dec).toString(16)}`;\n\n/** Pure 18-decimal wei → ether formatter. Trims trailing zeros so\n * `1.0` stays `1` and `1.5` stays `1.5`. */\nconst formatEther = (wei: bigint): string => {\n const integer = wei / ETH_UNIT;\n const remainder = wei % ETH_UNIT;\n if (remainder === 0n) {\n return integer.toString();\n }\n const fraction = remainder.toString().padStart(Number(ETH_DECIMALS), \"0\").replace(/0+$/v, \"\");\n return fraction.length > 0 ? `${integer}.${fraction}` : integer.toString();\n};\n\n/** General-purpose `value / 10^decimals` formatter that trims trailing\n * zeros. Mirrors `formatEther` but for arbitrary token decimals. */\nconst formatTokenUnits = (raw: bigint, decimals: number): string => {\n if (decimals === 0) {\n return raw.toString();\n }\n const unit = 10n ** BigInt(decimals);\n const integer = raw / unit;\n const remainder = raw % unit;\n if (remainder === 0n) {\n return integer.toString();\n }\n const fraction = remainder.toString().padStart(decimals, \"0\").replace(/0+$/v, \"\");\n return fraction.length > 0 ? `${integer}.${fraction}` : integer.toString();\n};\n\n// ERC20 function selectors (first 4 bytes of keccak256 of the\n// signature). Hard-coding avoids pulling in an ABI encoder.\nconst ERC20_BALANCE_OF_SELECTOR = \"0x70a08231\";\nconst ERC20_DECIMALS_SELECTOR = \"0x313ce567\";\nconst ERC20_SYMBOL_SELECTOR = \"0x95d89b41\";\n\nconst padAddressForCall = (address: string): string =>\n address.replace(/^0x/v, \"\").toLowerCase().padStart(64, \"0\");\n\n/**\n * Decode an ABI-encoded `string` return value. Layout:\n * bytes 0–31 : offset to the data (always 0x20 for a single string)\n * bytes 32–63 : string length (big-endian uint256)\n * bytes 64+ : UTF-8 bytes, right-padded to a 32-byte boundary\n *\n * Some non-standard tokens (early MakerDAO, etc.) return a `bytes32`\n * directly instead of a length-prefixed string; the fallback strips\n * trailing nulls and decodes the raw bytes.\n */\nconst decodeAbiString = (hex: string): string => {\n const clean = hex.startsWith(HEX_PREFIX) ? hex.slice(2) : hex;\n if (clean.length === 0) {\n return \"\";\n }\n // Length-prefixed string (standard ERC20)\n if (clean.length >= 128) {\n const lengthHex = clean.slice(64, 128);\n const length = Number(BigInt(`0x${lengthHex}`));\n if (length > 0 && clean.length >= 128 + length * 2) {\n const dataHex = clean.slice(128, 128 + length * 2);\n return new TextDecoder().decode(hexToBytes(dataHex));\n }\n }\n // bytes32 fallback — trim trailing zero bytes.\n const buf = hexToBytes(clean.slice(0, 64));\n let end = buf.length;\n while (end > 0 && buf[end - 1] === 0) {\n end -= 1;\n }\n return new TextDecoder().decode(buf.subarray(0, end));\n};\n\nconst buildEvmChain = (chainIdHex: string, walletName: string): ChainBase => {\n const reference = chainIdHexToDecimal(chainIdHex);\n return {\n id: `eip155:${reference}`,\n // We don't ship a chain-id → name table because that's a\n // domain decision (mainnet, sepolia, base, polygon, …). Consumers\n // overlay their own name via structural typing if needed.\n name: walletName,\n namespace: \"eip155\",\n reference,\n };\n};\n\nconst buildEvmAccount = (address: string, chain: ChainBase): Account => ({\n chain,\n id: `${chain.id}:${address.toLowerCase()}`,\n walletAddress: address,\n});\n\n/**\n * Adapt an EIP-1193 provider (announced via EIP-6963) into a butr\n * `WalletAdapter`. The returned adapter covers the full `Connector +\n * Wallet` surface; consumers can pass it through `createConnector` like\n * any hand-written adapter.\n *\n * **Caveats**\n *\n * - `disconnect` calls `wallet_revokePermissions`. Many wallets don't\n * implement that method and silently ignore the call. The reducer\n * will still mark the wallet as disconnected on butr's side; the\n * wallet's own auto-reconnect heuristic may or may not honour it.\n * - `switchAccount` is intentionally unimplemented because EIP-1193 has\n * no silent \"use address X\" RPC. The active account is whichever one\n * the wallet exposes first; the user changes it through the wallet's\n * own UI. butr's `subscribe` bridge auto-updates the pool entry when\n * `accountsChanged` fires. Call `requestAccounts` if you want the\n * wallet to expose more accounts.\n * - `getBalance()` returns the native ETH balance with symbol `\"ETH\"`\n * regardless of which EVM chain the wallet is currently on. Consumers\n * that target multiple EVM chains should overlay the symbol via\n * their own logic.\n * - `getBalance(tokenAddress)` reads the ERC20 balance for the active\n * account on the currently-connected chain. The token's own\n * `decimals()` and `symbol()` are queried for accurate formatting;\n * if `symbol()` is non-standard (bytes32) it's decoded as best-\n * effort. Routed through `eth_call` on the wallet's own provider\n * — the demo doesn't ship a separate RPC.\n * - `getSigner` returns the raw EIP-1193 provider. Wrap it in viem's\n * `createWalletClient` or ethers' `BrowserProvider` at the call site.\n */\nconst buildEvmAdapter = (info: Eip6963ProviderInfo, provider: Eip1193Provider): WalletAdapter => {\n return {\n capabilities: resolveEip6963Capabilities({ rdns: info.rdns }),\n chainPlatform: \"evm\",\n\n async connect(opts) {\n if (opts?.silent) {\n // EIP-1193 has no silent variant of `eth_requestAccounts`. The\n // closest non-interactive probe is `eth_accounts`, which returns\n // the already-authorized set without a prompt. Empty → reject so\n // hydration drops the stale entry instead of restoring nothing.\n const accounts = (await provider.request({\n method: \"eth_accounts\",\n })) as Array<string>;\n if (accounts.length === 0) {\n throw new Error(\"No authorized accounts for silent reconnect\");\n }\n return;\n }\n await provider.request({ method: \"eth_requestAccounts\" });\n },\n\n async disconnect() {\n try {\n await provider.request({\n method: \"wallet_revokePermissions\",\n params: [{ eth_accounts: {} }],\n });\n } catch {\n // Many wallets don't implement wallet_revokePermissions yet —\n // not a failure.\n }\n },\n\n async getAccount() {\n const accounts = (await provider.request({ method: \"eth_accounts\" })) as Array<string>;\n if (accounts.length === 0) {\n return null;\n }\n const chainIdHex = (await provider.request({ method: \"eth_chainId\" })) as string;\n const chain = buildEvmChain(chainIdHex, info.name);\n const first = accounts[0];\n if (!first) {\n return null;\n }\n return buildEvmAccount(first, chain);\n },\n\n async getAccounts() {\n const accounts = (await provider.request({ method: \"eth_accounts\" })) as Array<string>;\n if (accounts.length === 0) {\n return [];\n }\n const chainIdHex = (await provider.request({ method: \"eth_chainId\" })) as string;\n const chain = buildEvmChain(chainIdHex, info.name);\n return accounts.map((addr) => buildEvmAccount(addr, chain));\n },\n\n async getBalance(mint) {\n const accounts = (await provider.request({ method: \"eth_accounts\" })) as Array<string>;\n const first = accounts[0];\n if (!first) {\n throw new Error(\"No connected account\");\n }\n if (!mint) {\n // Native ETH path.\n const balanceHex = (await provider.request({\n method: \"eth_getBalance\",\n params: [first, \"latest\"],\n })) as string;\n const value = BigInt(balanceHex);\n return {\n decimals: Number(ETH_DECIMALS),\n formatted: formatEther(value),\n symbol: \"ETH\",\n value,\n };\n }\n // ERC20 path. Three `eth_call`s in parallel — the wallet's RPC\n // handles them locally so we don't need an external provider.\n const balanceCallData = `${ERC20_BALANCE_OF_SELECTOR}${padAddressForCall(first)}`;\n const [balanceHex, decimalsHex, symbolHex] = (await Promise.all([\n provider.request({\n method: \"eth_call\",\n params: [{ data: balanceCallData, to: mint }, \"latest\"],\n }),\n provider.request({\n method: \"eth_call\",\n params: [{ data: ERC20_DECIMALS_SELECTOR, to: mint }, \"latest\"],\n }),\n provider.request({\n method: \"eth_call\",\n params: [{ data: ERC20_SYMBOL_SELECTOR, to: mint }, \"latest\"],\n }),\n ])) as [string, string, string];\n const value = BigInt(balanceHex);\n const decimals = Number(BigInt(decimalsHex));\n const symbol = decodeAbiString(symbolHex);\n return {\n decimals,\n formatted: formatTokenUnits(value, decimals),\n symbol,\n value,\n };\n },\n\n getSigner() {\n // Consumers cast this to a viem WalletClient / ethers\n // BrowserProvider / their preferred wrapper.\n return Promise.resolve(provider);\n },\n\n async getTransactionReceipt(tx) {\n const receipt = (await provider.request({\n method: \"eth_getTransactionReceipt\",\n params: [tx],\n })) as { status: string } | null;\n if (!receipt) {\n return { status: \"Pending\" };\n }\n return { status: receipt.status === \"0x1\" ? \"Success\" : \"Error\" };\n },\n\n icon: sanitizeIcon(info.icon),\n id: info.rdns,\n name: info.name,\n\n async requestAccounts() {\n // Preferred path: EIP-2255 `wallet_requestPermissions` reopens\n // the wallet's account-picker UI so the user can grant new\n // accounts. In practice, MetaMask is the only major EVM wallet\n // that actually surfaces a fresh picker — Rabby / OKX / Binance\n // / Backpack silently return existing accounts; Phantom EVM and\n // Coinbase Wallet reject with `method not supported`. The\n // `capabilities` layer (`EIP6963_RDNS_WITH_REQUEST_ACCOUNTS` in\n // `capabilities.ts`) gates the\n // demo button so users only see it where it'll do something\n // visible; this method stays callable for consumers with\n // wallet-specific flows.\n //\n // Fallback: rejecting wallets get routed through\n // `eth_requestAccounts`, which at least doesn't throw. It won't\n // reopen the picker but surfaces newly-added accounts on the\n // next read.\n try {\n await provider.request({\n method: \"wallet_requestPermissions\",\n params: [{ eth_accounts: {} }],\n });\n } catch (error: unknown) {\n const err = error as { code?: number; data?: { originalError?: { code?: number } } } | null;\n const outerCode = err?.code;\n const innerCode = err?.data?.originalError?.code;\n const isMethodNotSupported =\n outerCode === 4200 || // EIP-1474 \"method not supported\"\n outerCode === -32_601 || // JSON-RPC \"method not found\"\n outerCode === -32_603 || // JSON-RPC \"internal error\" (Coinbase wraps -32604 here)\n innerCode === 4200 ||\n innerCode === -32_601 ||\n innerCode === -32_604; // Coinbase's custom \"method not supported\"\n if (isMethodNotSupported) {\n await provider.request({ method: \"eth_requestAccounts\" });\n return;\n }\n throw error;\n }\n },\n\n async sendTx(tx, account) {\n const txWithFrom = account\n ? { ...(tx as Record<string, unknown>), from: account.walletAddress }\n : tx;\n const hash = (await provider.request({\n method: \"eth_sendTransaction\",\n params: [txWithFrom],\n })) as string;\n return hash;\n },\n\n async sendTxToChain(tx, targetChainIdDecimal, account, cb) {\n const current = (await provider.request({ method: \"eth_chainId\" })) as string;\n const targetHex = chainIdDecimalToHex(targetChainIdDecimal);\n if (current.toLowerCase() !== targetHex.toLowerCase()) {\n await provider.request({\n method: \"wallet_switchEthereumChain\",\n params: [{ chainId: targetHex }],\n });\n cb?.();\n }\n const txWithFrom = account\n ? { ...(tx as Record<string, unknown>), from: account.walletAddress }\n : tx;\n const hash = (await provider.request({\n method: \"eth_sendTransaction\",\n params: [txWithFrom],\n })) as string;\n return hash;\n },\n\n async signMessage(msg, account) {\n // Default to the first exposed account when the caller doesn't\n // specify one. MetaMask requires the address to be one currently\n // exposed via `eth_requestAccounts`; pass any address from\n // `ConnectedWallet.accounts` to sign with a non-active one.\n let signer = account?.walletAddress;\n if (!signer) {\n const accounts = (await provider.request({ method: \"eth_accounts\" })) as Array<string>;\n signer = accounts[0];\n }\n if (!signer) {\n throw new Error(\"No connected account\");\n }\n const signatureHex = (await provider.request({\n method: \"personal_sign\",\n params: [bytesToHex(msg), signer],\n })) as string;\n return { signature: hexToBytes(signatureHex), signedMessage: msg };\n },\n\n subscribe(listener) {\n const onAccountsChanged: Eip1193Listener = (...args) => {\n const accs = args[0] as Array<string>;\n if (accs.length === 0) {\n listener({ type: \"disconnected\" });\n return;\n }\n // Forward the FULL accounts array — `accountsChanged` reflects\n // the wallet's current exposure set, not an incremental add.\n // The runtime mirrors this list verbatim into the pool entry,\n // so single-account-exposure wallets (Phantom EVM) don't end\n // up with stale, non-signable addresses lingering in the array.\n void provider\n .request({ method: \"eth_chainId\" })\n // oxlint-disable-next-line promise/prefer-await-to-then -- callback context, not async\n .then((chainIdHex) => {\n const chain = buildEvmChain(chainIdHex as string, info.name);\n const accounts = accs.map((addr) => buildEvmAccount(addr, chain));\n const first = accounts[0];\n if (!first) {\n return undefined;\n }\n listener({ account: first, accounts, type: \"accountChanged\" });\n return undefined;\n })\n // oxlint-disable-next-line promise/prefer-await-to-then -- callback context, not async\n .catch(() => {\n // Drop silently — next event will retry the read.\n });\n };\n\n const onChainChanged: Eip1193Listener = (...args) => {\n const chainIdHex = args[0] as string;\n void provider\n .request({ method: \"eth_accounts\" })\n // oxlint-disable-next-line promise/prefer-await-to-then -- callback context, not async\n .then((accounts) => {\n const accs = accounts as Array<string>;\n if (accs.length === 0) {\n return undefined;\n }\n const chain = buildEvmChain(chainIdHex, info.name);\n const built = accs.map((addr) => buildEvmAccount(addr, chain));\n const first = built[0];\n if (!first) {\n return undefined;\n }\n listener({ account: first, accounts: built, type: \"accountChanged\" });\n return undefined;\n })\n // oxlint-disable-next-line promise/prefer-await-to-then -- callback context, not async\n .catch(() => {\n // Drop silently.\n });\n };\n\n const onDisconnect: Eip1193Listener = () => {\n listener({ type: \"disconnected\" });\n };\n\n // EIP-1193 `connect` fires when the provider (re)connects to a\n // chain — e.g. the wallet comes back after being unreachable.\n // Re-read accounts + chain and resync the pool entry; state is\n // otherwise only derived from `accountsChanged`/`chainChanged`.\n const onConnect: Eip1193Listener = () => {\n void Promise.all([\n provider.request({ method: \"eth_accounts\" }),\n provider.request({ method: \"eth_chainId\" }),\n ])\n // oxlint-disable-next-line promise/prefer-await-to-then -- callback context, not async\n .then(([accountsRaw, chainIdHex]) => {\n const accs = accountsRaw as Array<string>;\n if (accs.length === 0) {\n return undefined;\n }\n const chain = buildEvmChain(chainIdHex as string, info.name);\n const built = accs.map((addr) => buildEvmAccount(addr, chain));\n const first = built[0];\n if (!first) {\n return undefined;\n }\n listener({ account: first, accounts: built, type: \"accountChanged\" });\n return undefined;\n })\n // oxlint-disable-next-line promise/prefer-await-to-then -- callback context, not async\n .catch(() => {\n // Drop silently — a later event will resync.\n });\n };\n\n provider.on(\"accountsChanged\", onAccountsChanged);\n provider.on(\"chainChanged\", onChainChanged);\n provider.on(\"connect\", onConnect);\n provider.on(\"disconnect\", onDisconnect);\n\n return () => {\n provider.removeListener(\"accountsChanged\", onAccountsChanged);\n provider.removeListener(\"chainChanged\", onChainChanged);\n provider.removeListener(\"connect\", onConnect);\n provider.removeListener(\"disconnect\", onDisconnect);\n };\n },\n\n async switchChain(chain) {\n await provider.request({\n method: \"wallet_switchEthereumChain\",\n params: [{ chainId: chainIdDecimalToHex(chain.reference) }],\n });\n },\n };\n};\n\nexport {\n buildEvmAdapter,\n bytesToHex,\n chainIdDecimalToHex,\n chainIdHexToDecimal,\n formatEther,\n hexToBytes,\n};\n","import type { WalletAdapter } from \"@usebutr/core\";\n\nimport type { Eip6963AnnounceEvent, Eip6963ProviderInfo } from \"./eip1193\";\nimport { buildEvmAdapter } from \"./eip6963-adapter\";\n\nconst ANNOUNCE_EVENT = \"eip6963:announceProvider\";\nconst REQUEST_EVENT = \"eip6963:requestProvider\";\n\ntype AdapterCallback = (adapter: WalletAdapter, info: Eip6963ProviderInfo) => void;\n\ntype DiscoverOptions = {\n /** Event target to listen on. Defaults to `window` in browser/RN/\n * SSR'd environments; tests can pass a fresh `new EventTarget()` to\n * exercise the discovery loop without a DOM. */\n target?: EventTarget;\n};\n\nconst resolveTarget = (target?: EventTarget): EventTarget | null => {\n if (target) {\n return target;\n }\n // Use globalThis.window when present and EventTarget-shaped. Some\n // test environments inject a `window` stub that isn't a real\n // EventTarget; in that case fall back to null so callers short-circuit\n // rather than throw on `.addEventListener`.\n const candidate = (globalThis as { window?: unknown }).window;\n if (\n !candidate ||\n typeof (candidate as { addEventListener?: unknown }).addEventListener !== \"function\"\n ) {\n return null;\n }\n return candidate as EventTarget;\n};\n\n/**\n * Subscribe to EIP-6963 wallet announcements. Spec:\n * https://eips.ethereum.org/EIPS/eip-6963\n *\n * Flow:\n * 1. Page registers a listener for `eip6963:announceProvider`.\n * 2. Page dispatches `eip6963:requestProvider` to kick wallets that\n * have already loaded.\n * 3. Wallets that load later still dispatch their own announcement\n * when they boot, so the listener stays attached for the lifetime\n * of the discovery session.\n * 4. Dedup by `info.rdns` — wallets occasionally re-announce, and\n * `info.uuid` is regenerated per page load so it's not stable.\n *\n * Returns an unsubscribe function that removes the listener.\n * In non-browser environments (SSR, tests with no window) returns\n * a noop unsubscribe and never fires the callback.\n */\nconst discoverEvmAdapters = (\n onAdapter: AdapterCallback,\n options: DiscoverOptions = {},\n): (() => void) => {\n const target = resolveTarget(options.target);\n if (!target) {\n return () => {};\n }\n\n const seen = new Set<string>();\n const handler = (event: Event) => {\n const announce = event as Eip6963AnnounceEvent;\n const detail = announce.detail;\n if (!detail || !detail.info || !detail.provider) {\n return;\n }\n const { info, provider } = detail;\n if (typeof info.rdns !== \"string\" || info.rdns.length === 0) {\n return;\n }\n if (seen.has(info.rdns)) {\n return;\n }\n seen.add(info.rdns);\n onAdapter(buildEvmAdapter(info, provider), info);\n };\n\n target.addEventListener(ANNOUNCE_EVENT, handler);\n target.dispatchEvent(new Event(REQUEST_EVENT));\n\n return () => {\n target.removeEventListener(ANNOUNCE_EVENT, handler);\n };\n};\n\nexport { ANNOUNCE_EVENT, REQUEST_EVENT, discoverEvmAdapters };\n","import type { WalletAdapter } from \"@usebutr/core\";\n\nimport type { Eip1193Provider, Eip6963ProviderInfo } from \"./eip1193\";\nimport { buildEvmAdapter } from \"./eip6963-adapter\";\n\n/**\n * Generic wallet icon (a stylised purse SVG, ~600 bytes). Used as\n * the fallback icon when an injected provider has no EIP-6963 info.\n * Inline rather than a network fetch so the picker doesn't flicker.\n */\nconst GENERIC_INJECTED_ICON =\n \"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSJjdXJyZW50Q29sb3IiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNMjEgMTJWN0g1YTIgMiAwIDAgMSAwLTQgaDE0djQiLz48cGF0aCBkPSJNMyA1djE0YTIgMiAwIDAgMCAyIDJoMTZ2LTVNMjEgMTIgaC0zYTIgMiAwIDAgMC0yIDJ2MGEyIDIgMCAwIDAgMiAyaDN6Ii8+PC9zdmc+\";\n\nconst DEFAULT_SETTLE_MS = 150;\n\ntype InjectedDiscoveryOptions = {\n /**\n * Predicate the fallback consults before emitting — if any EIP-6963\n * adapter has been registered by the time the settle timer fires,\n * the injected fallback is skipped (the wallet is already covered\n * via the standards path; we don't want a duplicate).\n *\n * `discoverWalletAdapters` wires this to the shared `seen` set so\n * the dedupe is automatic. Callers using `discoverInjectedAdapter`\n * directly should pass their own check or omit it (always emit).\n */\n hasAnyEip6963Adapter?: () => boolean;\n /**\n * How long to wait for EIP-6963 announcements before falling back\n * to `window.ethereum`. Most wallets announce within the first\n * frame; 150ms is a conservative settle window that keeps the\n * picker responsive while giving slow announcements time to land.\n */\n settleMs?: number;\n /** Override the global `window` reference (tests, iframes). */\n target?: { ethereum?: unknown } | null;\n};\n\nconst readEthereum = (target: InjectedDiscoveryOptions[\"target\"]): Eip1193Provider | null => {\n // Resolve the host object: use the caller's override if given, otherwise\n // fall back to the global window (or null in SSR environments).\n const globalWindow =\n typeof window === \"undefined\" ? null : (window as unknown as { ethereum?: unknown });\n const host = target === undefined ? globalWindow : target;\n if (!host) {\n return null;\n }\n const eth = (host as { ethereum?: unknown }).ethereum;\n if (!eth || typeof (eth as { request?: unknown }).request !== \"function\") {\n return null;\n }\n return eth as Eip1193Provider;\n};\n\n/**\n * Last-resort discovery path for EVM wallets that DON'T announce via\n * EIP-6963. Most modern wallets (MetaMask, Rabby, Coinbase, Phantom,\n * Brave, etc.) do announce, so the standards-based path\n * (`discoverEvmAdapters`) covers them. This module catches the long\n * tail: regional wallets (KuCoin, Bitget, BitKeep, Okto, Frontier)\n * and older builds that only expose `window.ethereum`.\n *\n * **Coordination**: the fallback waits `settleMs` (default 150ms)\n * after subscription, then consults `hasAnyEip6963Adapter` if\n * provided. If any EIP-6963 adapter has already been registered, we\n * skip emission — assume the same wallet is also speaking standards\n * and we'd just be duplicating. If no EIP-6963 adapter showed up but\n * `window.ethereum` does, we emit a generic adapter.\n *\n * The emitted adapter has `rdns: \"injected:legacy\"` so consumers can\n * distinguish it from EIP-6963 adapters in the picker UI.\n */\nconst discoverInjectedAdapter = (\n onAdapter: (adapter: WalletAdapter) => void,\n options: InjectedDiscoveryOptions = {},\n): (() => void) => {\n const settleMs = options.settleMs ?? DEFAULT_SETTLE_MS;\n let cancelled = false;\n const timer = setTimeout(() => {\n if (cancelled) {\n return;\n }\n if (options.hasAnyEip6963Adapter?.()) {\n return;\n }\n const provider = readEthereum(options.target);\n if (!provider) {\n return;\n }\n const info: Eip6963ProviderInfo = {\n icon: GENERIC_INJECTED_ICON,\n name: \"Browser wallet\",\n rdns: \"injected:legacy\",\n uuid: \"injected:legacy\",\n };\n onAdapter(buildEvmAdapter(info, provider));\n }, settleMs);\n\n return () => {\n cancelled = true;\n clearTimeout(timer);\n };\n};\n\nexport type { InjectedDiscoveryOptions };\nexport { GENERIC_INJECTED_ICON, discoverInjectedAdapter };\n","import type { ChainBase } from \"@usebutr/core\";\n\n/**\n * Common EVM chain registry keyed by CAIP-2 id. Useful for chain-\n * switcher UIs. butr itself doesn't read this — `Connector.switchChain`\n * accepts any `ChainBase`.\n */\nconst EVM_CHAINS = {\n arbitrum: {\n id: \"eip155:42161\",\n name: \"Arbitrum One\",\n namespace: \"eip155\",\n reference: \"42161\",\n },\n base: { id: \"eip155:8453\", name: \"Base\", namespace: \"eip155\", reference: \"8453\" },\n bsc: { id: \"eip155:56\", name: \"BNB Smart Chain\", namespace: \"eip155\", reference: \"56\" },\n ethereum: { id: \"eip155:1\", name: \"Ethereum\", namespace: \"eip155\", reference: \"1\" },\n optimism: { id: \"eip155:10\", name: \"Optimism\", namespace: \"eip155\", reference: \"10\" },\n polygon: { id: \"eip155:137\", name: \"Polygon\", namespace: \"eip155\", reference: \"137\" },\n sepolia: { id: \"eip155:11155111\", name: \"Sepolia\", namespace: \"eip155\", reference: \"11155111\" },\n} as const satisfies Record<string, ChainBase>;\n\nconst EVM_CHAINS_LIST: ReadonlyArray<ChainBase> = Object.values(EVM_CHAINS);\n\nexport { EVM_CHAINS, EVM_CHAINS_LIST };\n","import type { PlatformDiscoverer } from \"@usebutr/core\";\n\nimport { discoverEvmAdapters } from \"./eip6963\";\nimport { discoverInjectedAdapter } from \"./injected\";\n\n/**\n * EVM's `PlatformDiscoverer`: EIP-6963 announcements primary, with the\n * legacy `window.ethereum` injected fallback wired to defer until\n * EIP-6963 has had a chance to fire.\n *\n * Consumers using `@usebutr/wallets`'s `autoDiscovery()` get this\n * wired in automatically. Direct consumers who don't want the\n * injected fallback build their own discovery source from\n * `discoverEvmAdapters` alone.\n */\nconst evmDiscoverer: PlatformDiscoverer = {\n fallback: {\n subscribe: (onAdapter, opts) =>\n discoverInjectedAdapter(onAdapter, {\n hasAnyEip6963Adapter: opts.hasAnyPrimaryAdapter,\n }),\n },\n platform: \"evm\",\n subscribe: discoverEvmAdapters,\n};\n\nexport { evmDiscoverer };\n"],"mappings":"6CAaA,MAAM,EAAqC,IAAI,IAAY,CACzD,aACF,CAAC,EAIK,EAA8B,IAAuD,CACzF,WAAY,GACZ,sBAAuB,GACvB,gBAAiB,EAAmC,IAAI,EAAM,IAAI,EAClE,gBAAiB,GAEjB,OAAQ,GACR,YAAa,GAGb,gBAAiB,GACjB,UAAW,GAEX,cAAe,GACf,YAAa,EACf,GC3BM,EAAe,IACf,EAAW,KAAO,EAOlB,EAAc,GAA4B,CAC9C,IAAM,EAAQ,EAAI,WAAW,IAAU,EAAI,EAAI,MAAM,CAAC,EAAI,EACpD,EAAM,IAAI,WAAW,EAAM,OAAS,CAAC,EAC3C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAI,OAAQ,GAAK,EACnC,EAAI,GAAK,OAAO,SAAS,EAAM,MAAM,EAAI,E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,cAAe,KAAM,OAAQ,UAAW,SAAU,UAAW,MAAO,EAChF,IAAK,CAAE,GAAI,YAAa,KAAM,kBAAmB,UAAW,SAAU,UAAW,IAAK,EACtF,SAAU,CAAE,GAAI,WAAY,KAAM,WAAY,UAAW,SAAU,UAAW,GAAI,EAClF,SAAU,CAAE,GAAI,YAAa,KAAM,WAAY,UAAW,SAAU,UAAW,IAAK,EACpF,QAAS,CAAE,GAAI,aAAc,KAAM,UAAW,UAAW,SAAU,UAAW,KAAM,EACpF,QAAS,CAAE,GAAI,kBAAmB,KAAM,UAAW,UAAW,SAAU,UAAW,UAAW,CAChG,EAEM,EAA4C,OAAO,OAAO,CAAU,ECPpE,EAAoC,CACxC,SAAU,CACR,WAAY,EAAW,IACrB,EAAwB,EAAW,CACjC,qBAAsB,EAAK,oBAC7B,CAAC,CACL,EACA,SAAU,MACV,UAAW,CACb"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["announce"],"sources":["../src/capabilities.ts","../src/eip6963-adapter.ts","../src/eip6963.ts","../src/injected.ts","../src/chains.ts","../src/discoverer.ts"],"sourcesContent":["import type { WalletCapabilities } from \"@usebutr/core\";\n\n// Allow-list of EIP-6963 wallets whose `wallet_requestPermissions` call\n// actually surfaces a fresh account-picker UI (the spec intent).\n// Every other tested wallet either rejects the method (Phantom EVM,\n// Coinbase Wallet) or silently returns the existing accounts (Rabby,\n// OKX, Binance, Backpack EVM), making the affordance a no-op.\n//\n// Listed by EIP-6963 `rdns`. Add a wallet here only after verifying\n// against the real install that calling `requestAccounts` surfaces a\n// picker. The capability flag gates UI affordances — `requestAccounts`\n// stays callable on every adapter for consumers with wallet-specific\n// flows.\nconst EIP6963_RDNS_WITH_REQUEST_ACCOUNTS = new Set<string>([\n \"io.metamask\", // MetaMask — verified May 2026\n]);\n\ntype Eip6963CapabilityInput = { rdns: string };\n\nconst resolveEip6963Capabilities = (input: Eip6963CapabilityInput): WalletCapabilities => ({\n getBalance: true,\n getTransactionReceipt: true,\n requestAccounts: EIP6963_RDNS_WITH_REQUEST_ACCOUNTS.has(input.rdns),\n sendTransaction: true,\n // SIWS is Solana-only.\n signIn: false,\n signMessage: true,\n // EVM adapters don't expose a standalone signTransaction (most\n // wallets reject eth_signTransaction); use sendTx.\n signTransaction: false,\n subscribe: true,\n // EIP-1193 has no silent \"use address X\" RPC.\n switchAccount: false,\n switchChain: true,\n});\n\nexport type { Eip6963CapabilityInput };\nexport { EIP6963_RDNS_WITH_REQUEST_ACCOUNTS, resolveEip6963Capabilities };\n","import type { Account, ChainBase, WalletAdapter } from \"@usebutr/core\";\n// EVM uses 0x-prefixed hex; alias the shared prefixed variant to the\n// existing local name to keep the package's public `bytesToHex`/`hexToBytes`\n// contract (and the \"0xdeadbeef\" test) identical.\nimport { bytesToHexPrefixed as bytesToHex, hexToBytes, sanitizeIcon } from \"@usebutr/core\";\n\nimport { resolveEip6963Capabilities } from \"./capabilities\";\nimport type { Eip1193Listener, Eip1193Provider, Eip6963ProviderInfo } from \"./eip1193\";\n\nconst HEX_PREFIX = \"0x\";\nconst ETH_DECIMALS = 18n;\nconst ETH_UNIT = 10n ** ETH_DECIMALS;\n\nconst chainIdHexToDecimal = (hex: string): string => BigInt(hex).toString(10);\nconst chainIdDecimalToHex = (dec: string): string => `${HEX_PREFIX}${BigInt(dec).toString(16)}`;\n\n/** Pure 18-decimal wei → ether formatter. Trims trailing zeros so\n * `1.0` stays `1` and `1.5` stays `1.5`. */\nconst formatEther = (wei: bigint): string => {\n const integer = wei / ETH_UNIT;\n const remainder = wei % ETH_UNIT;\n if (remainder === 0n) {\n return integer.toString();\n }\n const fraction = remainder.toString().padStart(Number(ETH_DECIMALS), \"0\").replace(/0+$/v, \"\");\n return fraction.length > 0 ? `${integer}.${fraction}` : integer.toString();\n};\n\n/** General-purpose `value / 10^decimals` formatter that trims trailing\n * zeros. Mirrors `formatEther` but for arbitrary token decimals. */\nconst formatTokenUnits = (raw: bigint, decimals: number): string => {\n if (decimals === 0) {\n return raw.toString();\n }\n const unit = 10n ** BigInt(decimals);\n const integer = raw / unit;\n const remainder = raw % unit;\n if (remainder === 0n) {\n return integer.toString();\n }\n const fraction = remainder.toString().padStart(decimals, \"0\").replace(/0+$/v, \"\");\n return fraction.length > 0 ? `${integer}.${fraction}` : integer.toString();\n};\n\n// ERC20 function selectors (first 4 bytes of keccak256 of the\n// signature). Hard-coding avoids pulling in an ABI encoder.\nconst ERC20_BALANCE_OF_SELECTOR = \"0x70a08231\";\nconst ERC20_DECIMALS_SELECTOR = \"0x313ce567\";\nconst ERC20_SYMBOL_SELECTOR = \"0x95d89b41\";\n\nconst padAddressForCall = (address: string): string =>\n address.replace(/^0x/v, \"\").toLowerCase().padStart(64, \"0\");\n\n/**\n * Decode an ABI-encoded `string` return value. Layout:\n * bytes 0–31 : offset to the data (always 0x20 for a single string)\n * bytes 32–63 : string length (big-endian uint256)\n * bytes 64+ : UTF-8 bytes, right-padded to a 32-byte boundary\n *\n * Some non-standard tokens (early MakerDAO, etc.) return a `bytes32`\n * directly instead of a length-prefixed string; the fallback strips\n * trailing nulls and decodes the raw bytes.\n */\nconst decodeAbiString = (hex: string): string => {\n const clean = hex.startsWith(HEX_PREFIX) ? hex.slice(2) : hex;\n if (clean.length === 0) {\n return \"\";\n }\n // Length-prefixed string (standard ERC20)\n if (clean.length >= 128) {\n const lengthHex = clean.slice(64, 128);\n const length = Number(BigInt(`0x${lengthHex}`));\n if (length > 0 && clean.length >= 128 + length * 2) {\n const dataHex = clean.slice(128, 128 + length * 2);\n return new TextDecoder().decode(hexToBytes(dataHex));\n }\n }\n // bytes32 fallback — trim trailing zero bytes.\n const buf = hexToBytes(clean.slice(0, 64));\n let end = buf.length;\n while (end > 0 && buf[end - 1] === 0) {\n end -= 1;\n }\n return new TextDecoder().decode(buf.subarray(0, end));\n};\n\nconst buildEvmChain = (chainIdHex: string, walletName: string): ChainBase => {\n const reference = chainIdHexToDecimal(chainIdHex);\n return {\n id: `eip155:${reference}`,\n name: walletName,\n namespace: \"eip155\",\n reference,\n };\n};\n\nconst buildEvmAccount = (address: string, chain: ChainBase): Account => ({\n chain,\n id: `${chain.id}:${address.toLowerCase()}`,\n walletAddress: address,\n});\n\n/**\n * Adapt an EIP-1193 provider (announced via EIP-6963) into a butr\n * `WalletAdapter`. The returned adapter covers the full `Connector +\n * Wallet` surface; consumers can pass it through `createConnector` like\n * any hand-written adapter.\n *\n * **Caveats**\n *\n * - `disconnect` calls `wallet_revokePermissions`. Many wallets don't\n * implement that method and silently ignore the call. The reducer\n * will still mark the wallet as disconnected on butr's side; the\n * wallet's own auto-reconnect heuristic may or may not honour it.\n * - `switchAccount` is intentionally unimplemented because EIP-1193 has\n * no silent \"use address X\" RPC. The active account is whichever one\n * the wallet exposes first; the user changes it through the wallet's\n * own UI. butr's `subscribe` bridge auto-updates the pool entry when\n * `accountsChanged` fires. Call `requestAccounts` if you want the\n * wallet to expose more accounts.\n * - `getBalance()` returns the native ETH balance with symbol `\"ETH\"`\n * regardless of which EVM chain the wallet is currently on. Consumers\n * that target multiple EVM chains should overlay the symbol via\n * their own logic.\n * - `getBalance(tokenAddress)` reads the ERC20 balance for the active\n * account on the currently-connected chain. The token's own\n * `decimals()` and `symbol()` are queried for accurate formatting;\n * if `symbol()` is non-standard (bytes32) it's decoded as best-\n * effort. Routed through `eth_call` on the wallet's own provider\n * — the demo doesn't ship a separate RPC.\n * - `getSigner` returns the raw EIP-1193 provider. Wrap it in viem's\n * `createWalletClient` or ethers' `BrowserProvider` at the call site.\n */\nconst buildEvmAdapter = (info: Eip6963ProviderInfo, provider: Eip1193Provider): WalletAdapter => {\n return {\n capabilities: resolveEip6963Capabilities({ rdns: info.rdns }),\n chainPlatform: \"evm\",\n\n async connect(opts) {\n if (opts?.silent) {\n // EIP-1193 has no silent variant of `eth_requestAccounts`. The\n // closest non-interactive probe is `eth_accounts`, which returns\n // the already-authorized set without a prompt. Empty → reject so\n // hydration drops the stale entry instead of restoring nothing.\n const accounts = (await provider.request({\n method: \"eth_accounts\",\n })) as Array<string>;\n if (accounts.length === 0) {\n throw new Error(\"No authorized accounts for silent reconnect\");\n }\n return;\n }\n await provider.request({ method: \"eth_requestAccounts\" });\n },\n\n async disconnect() {\n try {\n await provider.request({\n method: \"wallet_revokePermissions\",\n params: [{ eth_accounts: {} }],\n });\n } catch {\n // Many wallets don't implement wallet_revokePermissions yet —\n // not a failure.\n }\n },\n\n async getAccount() {\n const accounts = (await provider.request({ method: \"eth_accounts\" })) as Array<string>;\n if (accounts.length === 0) {\n return null;\n }\n const chainIdHex = (await provider.request({ method: \"eth_chainId\" })) as string;\n const chain = buildEvmChain(chainIdHex, info.name);\n const first = accounts[0];\n if (!first) {\n return null;\n }\n return buildEvmAccount(first, chain);\n },\n\n async getAccounts() {\n const accounts = (await provider.request({ method: \"eth_accounts\" })) as Array<string>;\n if (accounts.length === 0) {\n return [];\n }\n const chainIdHex = (await provider.request({ method: \"eth_chainId\" })) as string;\n const chain = buildEvmChain(chainIdHex, info.name);\n return accounts.map((addr) => buildEvmAccount(addr, chain));\n },\n\n async getBalance(mint) {\n const accounts = (await provider.request({ method: \"eth_accounts\" })) as Array<string>;\n const first = accounts[0];\n if (!first) {\n throw new Error(\"No connected account\");\n }\n if (!mint) {\n // Native ETH path.\n const balanceHex = (await provider.request({\n method: \"eth_getBalance\",\n params: [first, \"latest\"],\n })) as string;\n const value = BigInt(balanceHex);\n return {\n decimals: Number(ETH_DECIMALS),\n formatted: formatEther(value),\n symbol: \"ETH\",\n value,\n };\n }\n // ERC20 path. Three `eth_call`s in parallel — the wallet's RPC\n // handles them locally so we don't need an external provider.\n const balanceCallData = `${ERC20_BALANCE_OF_SELECTOR}${padAddressForCall(first)}`;\n const [balanceHex, decimalsHex, symbolHex] = (await Promise.all([\n provider.request({\n method: \"eth_call\",\n params: [{ data: balanceCallData, to: mint }, \"latest\"],\n }),\n provider.request({\n method: \"eth_call\",\n params: [{ data: ERC20_DECIMALS_SELECTOR, to: mint }, \"latest\"],\n }),\n provider.request({\n method: \"eth_call\",\n params: [{ data: ERC20_SYMBOL_SELECTOR, to: mint }, \"latest\"],\n }),\n ])) as [string, string, string];\n const value = BigInt(balanceHex);\n const decimals = Number(BigInt(decimalsHex));\n const symbol = decodeAbiString(symbolHex);\n return {\n decimals,\n formatted: formatTokenUnits(value, decimals),\n symbol,\n value,\n };\n },\n\n getSigner() {\n // Consumers cast this to a viem WalletClient / ethers\n // BrowserProvider / their preferred wrapper.\n return Promise.resolve(provider);\n },\n\n async getTransactionReceipt(tx) {\n const receipt = (await provider.request({\n method: \"eth_getTransactionReceipt\",\n params: [tx],\n })) as { status: string } | null;\n if (!receipt) {\n return { status: \"Pending\" };\n }\n return { status: receipt.status === \"0x1\" ? \"Success\" : \"Error\" };\n },\n\n icon: sanitizeIcon(info.icon),\n id: info.rdns,\n name: info.name,\n\n async requestAccounts() {\n // Preferred path: EIP-2255 `wallet_requestPermissions` reopens\n // the wallet's account-picker UI so the user can grant new\n // accounts. In practice, MetaMask is the only major EVM wallet\n // that actually surfaces a fresh picker — Rabby / OKX / Binance\n // / Backpack silently return existing accounts; Phantom EVM and\n // Coinbase Wallet reject with `method not supported`. The\n // `capabilities` layer (`EIP6963_RDNS_WITH_REQUEST_ACCOUNTS` in\n // `capabilities.ts`) gates the\n // demo button so users only see it where it'll do something\n // visible; this method stays callable for consumers with\n // wallet-specific flows.\n //\n // Fallback: rejecting wallets get routed through\n // `eth_requestAccounts`, which at least doesn't throw. It won't\n // reopen the picker but surfaces newly-added accounts on the\n // next read.\n try {\n await provider.request({\n method: \"wallet_requestPermissions\",\n params: [{ eth_accounts: {} }],\n });\n } catch (error: unknown) {\n const err = error as { code?: number; data?: { originalError?: { code?: number } } } | null;\n const outerCode = err?.code;\n const innerCode = err?.data?.originalError?.code;\n const isMethodNotSupported =\n outerCode === 4200 || // EIP-1474 \"method not supported\"\n outerCode === -32_601 || // JSON-RPC \"method not found\"\n outerCode === -32_603 || // JSON-RPC \"internal error\" (Coinbase wraps -32604 here)\n innerCode === 4200 ||\n innerCode === -32_601 ||\n innerCode === -32_604; // Coinbase's custom \"method not supported\"\n if (isMethodNotSupported) {\n await provider.request({ method: \"eth_requestAccounts\" });\n return;\n }\n throw error;\n }\n },\n\n async sendTx(tx, account) {\n const txWithFrom = account\n ? { ...(tx as Record<string, unknown>), from: account.walletAddress }\n : tx;\n const hash = (await provider.request({\n method: \"eth_sendTransaction\",\n params: [txWithFrom],\n })) as string;\n return hash;\n },\n\n async sendTxToChain(tx, targetChainIdDecimal, account, cb) {\n const current = (await provider.request({ method: \"eth_chainId\" })) as string;\n const targetHex = chainIdDecimalToHex(targetChainIdDecimal);\n if (current.toLowerCase() !== targetHex.toLowerCase()) {\n await provider.request({\n method: \"wallet_switchEthereumChain\",\n params: [{ chainId: targetHex }],\n });\n cb?.();\n }\n const txWithFrom = account\n ? { ...(tx as Record<string, unknown>), from: account.walletAddress }\n : tx;\n const hash = (await provider.request({\n method: \"eth_sendTransaction\",\n params: [txWithFrom],\n })) as string;\n return hash;\n },\n\n async signMessage(msg, account) {\n // Default to the first exposed account when the caller doesn't\n // specify one. MetaMask requires the address to be one currently\n // exposed via `eth_requestAccounts`; pass any address from\n // `ConnectedWallet.accounts` to sign with a non-active one.\n let signer = account?.walletAddress;\n if (!signer) {\n const accounts = (await provider.request({ method: \"eth_accounts\" })) as Array<string>;\n signer = accounts[0];\n }\n if (!signer) {\n throw new Error(\"No connected account\");\n }\n const signatureHex = (await provider.request({\n method: \"personal_sign\",\n params: [bytesToHex(msg), signer],\n })) as string;\n return { signature: hexToBytes(signatureHex), signedMessage: msg };\n },\n\n subscribe(listener) {\n const onAccountsChanged: Eip1193Listener = (...args) => {\n const accs = args[0] as Array<string>;\n if (accs.length === 0) {\n listener({ type: \"disconnected\" });\n return;\n }\n // Forward the FULL accounts array — `accountsChanged` reflects\n // the wallet's current exposure set, not an incremental add.\n // The runtime mirrors this list verbatim into the pool entry,\n // so single-account-exposure wallets (Phantom EVM) don't end\n // up with stale, non-signable addresses lingering in the array.\n void provider\n .request({ method: \"eth_chainId\" })\n // oxlint-disable-next-line promise/prefer-await-to-then -- callback context, not async\n .then((chainIdHex) => {\n const chain = buildEvmChain(chainIdHex as string, info.name);\n const accounts = accs.map((addr) => buildEvmAccount(addr, chain));\n const first = accounts[0];\n if (!first) {\n return undefined;\n }\n listener({ account: first, accounts, type: \"accountChanged\" });\n return undefined;\n })\n // oxlint-disable-next-line promise/prefer-await-to-then -- callback context, not async\n .catch(() => {\n // Drop silently — next event will retry the read.\n });\n };\n\n const onChainChanged: Eip1193Listener = (...args) => {\n const chainIdHex = args[0] as string;\n void provider\n .request({ method: \"eth_accounts\" })\n // oxlint-disable-next-line promise/prefer-await-to-then -- callback context, not async\n .then((accounts) => {\n const accs = accounts as Array<string>;\n if (accs.length === 0) {\n return undefined;\n }\n const chain = buildEvmChain(chainIdHex, info.name);\n const built = accs.map((addr) => buildEvmAccount(addr, chain));\n const first = built[0];\n if (!first) {\n return undefined;\n }\n listener({ account: first, accounts: built, type: \"accountChanged\" });\n return undefined;\n })\n // oxlint-disable-next-line promise/prefer-await-to-then -- callback context, not async\n .catch(() => {\n // Drop silently.\n });\n };\n\n const onDisconnect: Eip1193Listener = () => {\n listener({ type: \"disconnected\" });\n };\n\n // EIP-1193 `connect` fires when the provider (re)connects to a\n // chain — e.g. the wallet comes back after being unreachable.\n // Re-read accounts + chain and resync the pool entry; state is\n // otherwise only derived from `accountsChanged`/`chainChanged`.\n const onConnect: Eip1193Listener = () => {\n void Promise.all([\n provider.request({ method: \"eth_accounts\" }),\n provider.request({ method: \"eth_chainId\" }),\n ])\n // oxlint-disable-next-line promise/prefer-await-to-then -- callback context, not async\n .then(([accountsRaw, chainIdHex]) => {\n const accs = accountsRaw as Array<string>;\n if (accs.length === 0) {\n return undefined;\n }\n const chain = buildEvmChain(chainIdHex as string, info.name);\n const built = accs.map((addr) => buildEvmAccount(addr, chain));\n const first = built[0];\n if (!first) {\n return undefined;\n }\n listener({ account: first, accounts: built, type: \"accountChanged\" });\n return undefined;\n })\n // oxlint-disable-next-line promise/prefer-await-to-then -- callback context, not async\n .catch(() => {\n // Drop silently — a later event will resync.\n });\n };\n\n provider.on(\"accountsChanged\", onAccountsChanged);\n provider.on(\"chainChanged\", onChainChanged);\n provider.on(\"connect\", onConnect);\n provider.on(\"disconnect\", onDisconnect);\n\n return () => {\n provider.removeListener(\"accountsChanged\", onAccountsChanged);\n provider.removeListener(\"chainChanged\", onChainChanged);\n provider.removeListener(\"connect\", onConnect);\n provider.removeListener(\"disconnect\", onDisconnect);\n };\n },\n\n async switchChain(chain) {\n await provider.request({\n method: \"wallet_switchEthereumChain\",\n params: [{ chainId: chainIdDecimalToHex(chain.reference) }],\n });\n },\n };\n};\n\nexport {\n buildEvmAdapter,\n bytesToHex,\n chainIdDecimalToHex,\n chainIdHexToDecimal,\n formatEther,\n hexToBytes,\n};\n","import type { WalletAdapter } from \"@usebutr/core\";\n\nimport type { Eip6963AnnounceEvent, Eip6963ProviderInfo } from \"./eip1193\";\nimport { buildEvmAdapter } from \"./eip6963-adapter\";\n\nconst ANNOUNCE_EVENT = \"eip6963:announceProvider\";\nconst REQUEST_EVENT = \"eip6963:requestProvider\";\n\ntype AdapterCallback = (adapter: WalletAdapter, info: Eip6963ProviderInfo) => void;\n\ntype DiscoverOptions = {\n /** Event target to listen on. Defaults to `window` in browser/RN/\n * SSR'd environments; tests can pass a fresh `new EventTarget()` to\n * exercise the discovery loop without a DOM. */\n target?: EventTarget;\n};\n\nconst resolveTarget = (target?: EventTarget): EventTarget | null => {\n if (target) {\n return target;\n }\n // Use globalThis.window when present and EventTarget-shaped. Some\n // test environments inject a `window` stub that isn't a real\n // EventTarget; in that case fall back to null so callers short-circuit\n // rather than throw on `.addEventListener`.\n const candidate = (globalThis as { window?: unknown }).window;\n if (\n !candidate ||\n typeof (candidate as { addEventListener?: unknown }).addEventListener !== \"function\"\n ) {\n return null;\n }\n return candidate as EventTarget;\n};\n\n/**\n * Subscribe to EIP-6963 wallet announcements. Spec:\n * https://eips.ethereum.org/EIPS/eip-6963\n *\n * Flow:\n * 1. Page registers a listener for `eip6963:announceProvider`.\n * 2. Page dispatches `eip6963:requestProvider` to kick wallets that\n * have already loaded.\n * 3. Wallets that load later still dispatch their own announcement\n * when they boot, so the listener stays attached for the lifetime\n * of the discovery session.\n * 4. Dedup by `info.rdns` — wallets occasionally re-announce, and\n * `info.uuid` is regenerated per page load so it's not stable.\n *\n * Returns an unsubscribe function that removes the listener.\n * In non-browser environments (SSR, tests with no window) returns\n * a noop unsubscribe and never fires the callback.\n */\nconst discoverEvmAdapters = (\n onAdapter: AdapterCallback,\n options: DiscoverOptions = {},\n): (() => void) => {\n const target = resolveTarget(options.target);\n if (!target) {\n return () => {};\n }\n\n const seen = new Set<string>();\n const handler = (event: Event) => {\n const announce = event as Eip6963AnnounceEvent;\n const detail = announce.detail;\n if (!detail || !detail.info || !detail.provider) {\n return;\n }\n const { info, provider } = detail;\n if (typeof info.rdns !== \"string\" || info.rdns.length === 0) {\n return;\n }\n if (seen.has(info.rdns)) {\n return;\n }\n seen.add(info.rdns);\n onAdapter(buildEvmAdapter(info, provider), info);\n };\n\n target.addEventListener(ANNOUNCE_EVENT, handler);\n target.dispatchEvent(new Event(REQUEST_EVENT));\n\n return () => {\n target.removeEventListener(ANNOUNCE_EVENT, handler);\n };\n};\n\nexport { ANNOUNCE_EVENT, REQUEST_EVENT, discoverEvmAdapters };\n","import type { WalletAdapter } from \"@usebutr/core\";\n\nimport type { Eip1193Provider, Eip6963ProviderInfo } from \"./eip1193\";\nimport { buildEvmAdapter } from \"./eip6963-adapter\";\n\n/**\n * Generic wallet icon (a stylised purse SVG, ~600 bytes). Used as\n * the fallback icon when an injected provider has no EIP-6963 info.\n * Inline rather than a network fetch so the picker doesn't flicker.\n */\nconst GENERIC_INJECTED_ICON =\n \"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSJjdXJyZW50Q29sb3IiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNMjEgMTJWN0g1YTIgMiAwIDAgMSAwLTQgaDE0djQiLz48cGF0aCBkPSJNMyA1djE0YTIgMiAwIDAgMCAyIDJoMTZ2LTVNMjEgMTIgaC0zYTIgMiAwIDAgMC0yIDJ2MGEyIDIgMCAwIDAgMiAyaDN6Ii8+PC9zdmc+\";\n\nconst DEFAULT_SETTLE_MS = 150;\n\ntype InjectedDiscoveryOptions = {\n /**\n * Predicate the fallback consults before emitting — if any EIP-6963\n * adapter has been registered by the time the settle timer fires,\n * the injected fallback is skipped (the wallet is already covered\n * via the standards path; we don't want a duplicate).\n *\n * `discoverWalletAdapters` wires this to the shared `seen` set so\n * the dedupe is automatic. Callers using `discoverInjectedAdapter`\n * directly should pass their own check or omit it (always emit).\n */\n hasAnyEip6963Adapter?: () => boolean;\n /**\n * How long to wait for EIP-6963 announcements before falling back\n * to `window.ethereum`. Most wallets announce within the first\n * frame; 150ms is a conservative settle window that keeps the\n * picker responsive while giving slow announcements time to land.\n */\n settleMs?: number;\n /** Override the global `window` reference (tests, iframes). */\n target?: { ethereum?: unknown } | null;\n};\n\nconst readEthereum = (target: InjectedDiscoveryOptions[\"target\"]): Eip1193Provider | null => {\n // Resolve the host object: use the caller's override if given, otherwise\n // fall back to the global window (or null in SSR environments).\n const globalWindow =\n typeof window === \"undefined\" ? null : (window as unknown as { ethereum?: unknown });\n const host = target === undefined ? globalWindow : target;\n if (!host) {\n return null;\n }\n const eth = (host as { ethereum?: unknown }).ethereum;\n if (!eth || typeof (eth as { request?: unknown }).request !== \"function\") {\n return null;\n }\n return eth as Eip1193Provider;\n};\n\n/**\n * Last-resort discovery path for EVM wallets that DON'T announce via\n * EIP-6963. Most modern wallets (MetaMask, Rabby, Coinbase, Phantom,\n * Brave, etc.) do announce, so the standards-based path\n * (`discoverEvmAdapters`) covers them. This module catches the long\n * tail: regional wallets (KuCoin, Bitget, BitKeep, Okto, Frontier)\n * and older builds that only expose `window.ethereum`.\n *\n * **Coordination**: the fallback waits `settleMs` (default 150ms)\n * after subscription, then consults `hasAnyEip6963Adapter` if\n * provided. If any EIP-6963 adapter has already been registered, we\n * skip emission — assume the same wallet is also speaking standards\n * and we'd just be duplicating. If no EIP-6963 adapter showed up but\n * `window.ethereum` does, we emit a generic adapter.\n *\n * The emitted adapter has `rdns: \"injected:legacy\"` so consumers can\n * distinguish it from EIP-6963 adapters in the picker UI.\n */\nconst discoverInjectedAdapter = (\n onAdapter: (adapter: WalletAdapter) => void,\n options: InjectedDiscoveryOptions = {},\n): (() => void) => {\n const settleMs = options.settleMs ?? DEFAULT_SETTLE_MS;\n let cancelled = false;\n const timer = setTimeout(() => {\n if (cancelled) {\n return;\n }\n if (options.hasAnyEip6963Adapter?.()) {\n return;\n }\n const provider = readEthereum(options.target);\n if (!provider) {\n return;\n }\n const info: Eip6963ProviderInfo = {\n icon: GENERIC_INJECTED_ICON,\n name: \"Browser wallet\",\n rdns: \"injected:legacy\",\n uuid: \"injected:legacy\",\n };\n onAdapter(buildEvmAdapter(info, provider));\n }, settleMs);\n\n return () => {\n cancelled = true;\n clearTimeout(timer);\n };\n};\n\nexport type { InjectedDiscoveryOptions };\nexport { GENERIC_INJECTED_ICON, discoverInjectedAdapter };\n","import type { ChainBase } from \"@usebutr/core\";\n\n/**\n * Common EVM chain registry keyed by CAIP-2 id. Useful for chain-\n * switcher UIs. butr itself doesn't read this — `Connector.switchChain`\n * accepts any `ChainBase`.\n */\nconst EVM_CHAINS = {\n arbitrum: {\n id: \"eip155:42161\",\n name: \"Arbitrum One\",\n namespace: \"eip155\",\n reference: \"42161\",\n },\n base: { id: \"eip155:8453\", name: \"Base\", namespace: \"eip155\", reference: \"8453\" },\n bsc: { id: \"eip155:56\", name: \"BNB Smart Chain\", namespace: \"eip155\", reference: \"56\" },\n ethereum: { id: \"eip155:1\", name: \"Ethereum\", namespace: \"eip155\", reference: \"1\" },\n optimism: { id: \"eip155:10\", name: \"Optimism\", namespace: \"eip155\", reference: \"10\" },\n polygon: { id: \"eip155:137\", name: \"Polygon\", namespace: \"eip155\", reference: \"137\" },\n sepolia: { id: \"eip155:11155111\", name: \"Sepolia\", namespace: \"eip155\", reference: \"11155111\" },\n} as const satisfies Record<string, ChainBase>;\n\nconst EVM_CHAINS_LIST: ReadonlyArray<ChainBase> = Object.values(EVM_CHAINS);\n\nexport { EVM_CHAINS, EVM_CHAINS_LIST };\n","import type { PlatformDiscoverer } from \"@usebutr/core\";\n\nimport { discoverEvmAdapters } from \"./eip6963\";\nimport { discoverInjectedAdapter } from \"./injected\";\n\n/**\n * EVM's `PlatformDiscoverer`: EIP-6963 announcements primary, with the\n * legacy `window.ethereum` injected fallback wired to defer until\n * EIP-6963 has had a chance to fire.\n *\n * Consumers using `@usebutr/wallets`'s `autoDiscovery()` get this\n * wired in automatically. Direct consumers who don't want the\n * injected fallback build their own discovery source from\n * `discoverEvmAdapters` alone.\n */\nconst evmDiscoverer: PlatformDiscoverer = {\n fallback: {\n subscribe: (onAdapter, opts) =>\n discoverInjectedAdapter(onAdapter, {\n hasAnyEip6963Adapter: opts.hasAnyPrimaryAdapter,\n }),\n },\n platform: \"evm\",\n subscribe: discoverEvmAdapters,\n};\n\nexport { evmDiscoverer };\n"],"mappings":";;;AAaA,MAAM,qCAAqC,IAAI,IAAY,CACzD,aACF,CAAC;AAID,MAAM,8BAA8B,WAAuD;CACzF,YAAY;CACZ,uBAAuB;CACvB,iBAAiB,mCAAmC,IAAI,MAAM,IAAI;CAClE,iBAAiB;CAEjB,QAAQ;CACR,aAAa;CAGb,iBAAiB;CACjB,WAAW;CAEX,eAAe;CACf,aAAa;AACf;;;;ACzBA,MAAM,aAAa;AACnB,MAAM,eAAe;AACrB,MAAM,WAAW,OAAO;AAExB,MAAM,uBA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.2.2",
|
|
4
4
|
"description": "EIP-1193 / EIP-6963 / injected wallet discovery + adapters for butr.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Pedro Filho <pedro@filho.me>",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@usebutr/core": "0.
|
|
28
|
+
"@usebutr/core": "0.4.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"typescript": "^6.0.3",
|