Fix EIP-712 chainId dynamic resolution; improve add-wallet modal
- Replace hardcoded chainId:1 with per-chain EIP-712 domain (base→8453, etc.) - Add hyperliquide (chainId 998) as supported EVM chain - Auto-fill wallet address and chain from eth_requestAccounts + eth_chainId - Auto-pick unused color when adding wallet - Remove chain dropdown and address input; add readonly displays - Rename localStorage key to tracked_wallets
This commit is contained in:
37
verifier.js
37
verifier.js
@ -16,12 +16,34 @@ import { WalletManager } from './wallets.js';
|
||||
/* EIP-712 Domain */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
const EIP712_DOMAIN = {
|
||||
name: 'Anonymous Wallet Tracker',
|
||||
version: '1',
|
||||
chainId: 1,
|
||||
/* Chain name → numeric chainId for EIP-712 domain */
|
||||
const CHAIN_IDS = {
|
||||
ethereum: 1,
|
||||
base: 8453,
|
||||
arbitrum: 42161,
|
||||
optimism: 10,
|
||||
polygon: 137,
|
||||
avalanche: 43114,
|
||||
bsc: 56,
|
||||
fantom: 250,
|
||||
hyperliquide: 998,
|
||||
};
|
||||
|
||||
/**
|
||||
* Build the EIP-712 domain for a given chain.
|
||||
* @param {string} chain — chain name
|
||||
* @returns {object} Domain object
|
||||
*/
|
||||
function buildEIP712Domain(chain) {
|
||||
const normalChain = String(chain).toLowerCase();
|
||||
const chainId = CHAIN_IDS[normalChain] ?? 1;
|
||||
return {
|
||||
name: 'Anonymous Wallet Tracker',
|
||||
version: '1',
|
||||
chainId,
|
||||
};
|
||||
}
|
||||
|
||||
const EIP712_TYPES = {
|
||||
VerifyTracking: [
|
||||
{ name: 'action', type: 'string' },
|
||||
@ -126,7 +148,7 @@ export class WalletVerifier {
|
||||
address = await this._requestAccount();
|
||||
|
||||
/* ---- Step 2: Build EIP-712 payload ---- */
|
||||
const typedData = this._buildTypedData(address);
|
||||
const typedData = this._buildTypedData(address, chain);
|
||||
|
||||
/* ---- Step 3: Request signature ---- */
|
||||
signature = await this._requestSignature(address, typedData);
|
||||
@ -205,12 +227,13 @@ export class WalletVerifier {
|
||||
* Build the EIP-712 typed data payload.
|
||||
*
|
||||
* @param {string} address
|
||||
* @param {string} chain — chain name for domain chainId
|
||||
* @returns {object} Full typedData object (domain + types + message)
|
||||
*/
|
||||
_buildTypedData(address) {
|
||||
_buildTypedData(address, chain) {
|
||||
const message = this._buildMessageData(address);
|
||||
return {
|
||||
domain: EIP712_DOMAIN,
|
||||
domain: buildEIP712Domain(chain),
|
||||
types: {
|
||||
EIP712Domain: [
|
||||
{ name: 'name', type: 'string' },
|
||||
|
||||
Reference in New Issue
Block a user