Compare commits
41 Commits
feature/is
...
01839d9c47
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01839d9c47 | ||
|
|
9eef2ea602 | ||
| a182aa534b | |||
| a388100262 | |||
| dd3cabf816 | |||
|
|
235e5e7fa7 | ||
|
|
be06bd8f0c | ||
|
|
a72359432b | ||
|
|
2bdb547995 | ||
| 834228b572 | |||
|
|
813993f17c | ||
| 5f01d9f111 | |||
|
|
d78af3ec80 | ||
| 753fb5658a | |||
| bdb2031d46 | |||
| 25ecaee128 | |||
|
|
ff4b5ee24d | ||
|
|
ca6e9054f9 | ||
| 09c52b2519 | |||
| 1fb9fade51 | |||
| bc04482fb5 | |||
|
|
045328f3b9 | ||
|
|
576fe3ab15 | ||
|
|
35bb6b9806 | ||
|
|
e56e15e34c | ||
|
|
cc69ce39ed | ||
|
|
9476724284 | ||
|
|
9246959777 | ||
|
|
0f6daf3200 | ||
|
|
435669b6b6 | ||
|
|
f75a258125 | ||
|
|
4d120e5ea9 | ||
|
|
57959b70c3 | ||
|
|
7a7f9c5135 | ||
|
|
8c071ae508 | ||
|
|
a3c2b8227a | ||
|
|
f9f3e7b85a | ||
| 812fc01a98 | |||
|
|
811c125cb9 | ||
|
|
3005813f2c | ||
|
|
5565e76796 |
@@ -12,6 +12,10 @@ const { refreshBalances, getProvider } = require("../shared/balances");
|
|||||||
const { debugFetch } = require("../shared/log");
|
const { debugFetch } = require("../shared/log");
|
||||||
const { decryptWithPassword } = require("../shared/vault");
|
const { decryptWithPassword } = require("../shared/vault");
|
||||||
const { getSignerForAddress } = require("../shared/wallet");
|
const { getSignerForAddress } = require("../shared/wallet");
|
||||||
|
const {
|
||||||
|
isPhishingDomain,
|
||||||
|
updatePhishingList,
|
||||||
|
} = require("../shared/phishingDomains");
|
||||||
|
|
||||||
const storageApi =
|
const storageApi =
|
||||||
typeof browser !== "undefined"
|
typeof browser !== "undefined"
|
||||||
@@ -571,6 +575,10 @@ async function backgroundRefresh() {
|
|||||||
|
|
||||||
setInterval(backgroundRefresh, BACKGROUND_REFRESH_INTERVAL);
|
setInterval(backgroundRefresh, BACKGROUND_REFRESH_INTERVAL);
|
||||||
|
|
||||||
|
// Fetch the MetaMask eth-phishing-detect domain blocklist on startup.
|
||||||
|
// Refreshes every 24 hours automatically.
|
||||||
|
updatePhishingList();
|
||||||
|
|
||||||
// When approval window is closed without a response, treat as rejection
|
// When approval window is closed without a response, treat as rejection
|
||||||
if (windowsApi && windowsApi.onRemoved) {
|
if (windowsApi && windowsApi.onRemoved) {
|
||||||
windowsApi.onRemoved.addListener((windowId) => {
|
windowsApi.onRemoved.addListener((windowId) => {
|
||||||
@@ -643,6 +651,8 @@ runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
|||||||
resp.type = "sign";
|
resp.type = "sign";
|
||||||
resp.signParams = approval.signParams;
|
resp.signParams = approval.signParams;
|
||||||
}
|
}
|
||||||
|
// Flag if the requesting domain is on the phishing blocklist.
|
||||||
|
resp.isPhishingDomain = isPhishingDomain(approval.hostname);
|
||||||
sendResponse(resp);
|
sendResponse(resp);
|
||||||
} else {
|
} else {
|
||||||
sendResponse(null);
|
sendResponse(null);
|
||||||
|
|||||||
@@ -56,37 +56,105 @@
|
|||||||
< Back
|
< Back
|
||||||
</button>
|
</button>
|
||||||
<h2 class="font-bold mb-2">Add Wallet</h2>
|
<h2 class="font-bold mb-2">Add Wallet</h2>
|
||||||
<p class="mb-2">
|
|
||||||
Enter your 12 or 24 word recovery phrase below, or click the
|
<!-- Mode selector tabs -->
|
||||||
button to roll the die for a new one.
|
<div
|
||||||
</p>
|
class="flex border-b border-border mb-3"
|
||||||
<div class="mb-1 flex justify-end">
|
id="add-wallet-tabs"
|
||||||
|
>
|
||||||
<button
|
<button
|
||||||
id="btn-generate-phrase"
|
id="tab-mnemonic"
|
||||||
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer text-xs"
|
class="px-3 py-1.5 cursor-pointer text-xs font-bold border border-border border-b-bg bg-bg -mb-px"
|
||||||
title="Generate a random recovery phrase"
|
|
||||||
>
|
>
|
||||||
[⚀]
|
From Phrase
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
id="tab-privkey"
|
||||||
|
class="px-3 py-1.5 cursor-pointer text-xs text-muted border border-dashed border-border-light border-b-transparent -mb-px hover:bg-fg hover:text-bg"
|
||||||
|
>
|
||||||
|
From Key
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
id="tab-xprv"
|
||||||
|
class="px-3 py-1.5 cursor-pointer text-xs text-muted border border-dashed border-border-light border-b-transparent -mb-px hover:bg-fg hover:text-bg"
|
||||||
|
>
|
||||||
|
From xprv
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
|
||||||
<textarea
|
<!-- Mnemonic form section -->
|
||||||
id="wallet-mnemonic"
|
<div id="add-wallet-section-mnemonic">
|
||||||
rows="3"
|
<p class="mb-2">
|
||||||
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg resize-y"
|
Enter your 12 or 24 word recovery phrase below, or click
|
||||||
placeholder="word word word ..."
|
the button to roll the die for a new one.
|
||||||
></textarea>
|
</p>
|
||||||
|
<div class="mb-1 flex justify-end">
|
||||||
|
<button
|
||||||
|
id="btn-generate-phrase"
|
||||||
|
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer text-xs"
|
||||||
|
title="Generate a random recovery phrase"
|
||||||
|
>
|
||||||
|
[⚀]
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<textarea
|
||||||
|
id="wallet-mnemonic"
|
||||||
|
rows="3"
|
||||||
|
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg resize-y"
|
||||||
|
placeholder="word word word ..."
|
||||||
|
></textarea>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
id="add-wallet-phrase-warning"
|
||||||
|
class="text-xs mb-2 border border-border border-dashed p-2"
|
||||||
|
style="visibility: hidden"
|
||||||
|
>
|
||||||
|
Write these words down and keep them safe. Anyone with
|
||||||
|
them can take your funds; if you lose them, your wallet
|
||||||
|
is gone.
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
|
||||||
id="add-wallet-phrase-warning"
|
<!-- Private key form section -->
|
||||||
class="text-xs mb-2 border border-border border-dashed p-2 hidden"
|
<div id="add-wallet-section-privkey" class="hidden">
|
||||||
>
|
<p class="mb-2">
|
||||||
Write these words down and keep them safe. Anyone with them
|
Paste your private key below. This wallet will have a
|
||||||
can take your funds; if you lose them, your wallet is gone.
|
single address.
|
||||||
|
</p>
|
||||||
|
<div class="mb-2">
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="import-private-key"
|
||||||
|
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
||||||
|
placeholder="0x..."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Extended key (xprv) form section -->
|
||||||
|
<div id="add-wallet-section-xprv" class="hidden">
|
||||||
|
<p class="mb-2">
|
||||||
|
Paste your extended private key (xprv) below. This will
|
||||||
|
import the HD wallet and scan for used addresses.
|
||||||
|
</p>
|
||||||
|
<div class="mb-2">
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="import-xprv-key"
|
||||||
|
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
||||||
|
placeholder="xprv..."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Shared password fields -->
|
||||||
<div class="mb-2" id="add-wallet-password-section">
|
<div class="mb-2" id="add-wallet-password-section">
|
||||||
<label class="block mb-1">Choose a password</label>
|
<label class="block mb-1">Choose a password</label>
|
||||||
<p class="text-xs text-muted mb-1">
|
<p
|
||||||
|
class="text-xs text-muted mb-1"
|
||||||
|
id="add-wallet-password-hint"
|
||||||
|
>
|
||||||
This password encrypts your recovery phrase on this
|
This password encrypts your recovery phrase on this
|
||||||
device. You will need it to send funds.
|
device. You will need it to send funds.
|
||||||
</p>
|
</p>
|
||||||
@@ -107,64 +175,6 @@
|
|||||||
<button
|
<button
|
||||||
id="btn-add-wallet-confirm"
|
id="btn-add-wallet-confirm"
|
||||||
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer"
|
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer"
|
||||||
>
|
|
||||||
Add
|
|
||||||
</button>
|
|
||||||
<div class="mt-3 text-xs text-muted">
|
|
||||||
Have a private key instead?
|
|
||||||
<button
|
|
||||||
id="btn-add-wallet-import-key"
|
|
||||||
class="underline cursor-pointer bg-transparent border-none text-fg text-xs font-mono p-0"
|
|
||||||
>
|
|
||||||
Import private key
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- ============ IMPORT PRIVATE KEY ============ -->
|
|
||||||
<div id="view-import-key" class="view hidden">
|
|
||||||
<button
|
|
||||||
id="btn-import-key-back"
|
|
||||||
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer mb-2"
|
|
||||||
>
|
|
||||||
< Back
|
|
||||||
</button>
|
|
||||||
<h2 class="font-bold mb-2">Import Private Key</h2>
|
|
||||||
<p class="mb-2">
|
|
||||||
Paste your private key below. This wallet will have a single
|
|
||||||
address.
|
|
||||||
</p>
|
|
||||||
<div class="mb-2">
|
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
id="import-private-key"
|
|
||||||
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
|
||||||
placeholder="0x..."
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="mb-2" id="import-key-password-section">
|
|
||||||
<label class="block mb-1">Choose a password</label>
|
|
||||||
<p class="text-xs text-muted mb-1">
|
|
||||||
This password encrypts your private key on this device.
|
|
||||||
You will need it to send funds.
|
|
||||||
</p>
|
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
id="import-key-password"
|
|
||||||
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="mb-2" id="import-key-password-confirm-section">
|
|
||||||
<label class="block mb-1">Confirm password</label>
|
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
id="import-key-password-confirm"
|
|
||||||
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
id="btn-import-key-confirm"
|
|
||||||
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer"
|
|
||||||
>
|
>
|
||||||
Import
|
Import
|
||||||
</button>
|
</button>
|
||||||
@@ -175,7 +185,7 @@
|
|||||||
<!-- active address headline -->
|
<!-- active address headline -->
|
||||||
<div
|
<div
|
||||||
id="total-value"
|
id="total-value"
|
||||||
class="text-2xl font-bold min-h-[2rem]"
|
class="text-2xl font-bold min-h-[2rem] text-fg"
|
||||||
></div>
|
></div>
|
||||||
<div
|
<div
|
||||||
id="total-value-sub"
|
id="total-value-sub"
|
||||||
@@ -366,7 +376,8 @@
|
|||||||
</p>
|
</p>
|
||||||
<div
|
<div
|
||||||
id="export-privkey-flash"
|
id="export-privkey-flash"
|
||||||
class="text-xs mb-2 hidden"
|
class="text-xs mb-2 min-h-[1.25rem]"
|
||||||
|
style="visibility: hidden"
|
||||||
></div>
|
></div>
|
||||||
<div id="export-privkey-password-section" class="mb-2">
|
<div id="export-privkey-password-section" class="mb-2">
|
||||||
<label class="block mb-1">Password</label>
|
<label class="block mb-1">Password</label>
|
||||||
@@ -570,16 +581,59 @@
|
|||||||
<div class="text-xs text-muted mb-1">Your balance</div>
|
<div class="text-xs text-muted mb-1">Your balance</div>
|
||||||
<div id="confirm-balance" class="text-xs"></div>
|
<div id="confirm-balance" class="text-xs"></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="confirm-fee" class="mb-3 hidden">
|
<div id="confirm-fee" class="mb-3" style="visibility: hidden">
|
||||||
<div class="text-xs text-muted mb-1">
|
<div class="text-xs text-muted mb-1">
|
||||||
Estimated network fee
|
Estimated network fee
|
||||||
</div>
|
</div>
|
||||||
<div id="confirm-fee-amount" class="text-xs"></div>
|
<div id="confirm-fee-amount" class="text-xs"></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="confirm-warnings" class="mb-2 hidden"></div>
|
<div
|
||||||
|
id="confirm-warnings"
|
||||||
|
class="mb-2"
|
||||||
|
style="visibility: hidden"
|
||||||
|
></div>
|
||||||
|
<div
|
||||||
|
id="confirm-recipient-warning"
|
||||||
|
class="mb-2"
|
||||||
|
style="visibility: hidden"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="border border-red-500 border-dashed p-2 text-xs font-bold text-red-500"
|
||||||
|
>
|
||||||
|
WARNING: The recipient address has ZERO transaction
|
||||||
|
history. This may indicate a fresh or unused address.
|
||||||
|
Double-check the address before sending.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
id="confirm-contract-warning"
|
||||||
|
class="mb-2"
|
||||||
|
style="visibility: hidden"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="border border-red-500 border-dashed p-2 text-xs font-bold text-red-500"
|
||||||
|
>
|
||||||
|
WARNING: The recipient is a smart contract. Sending ETH
|
||||||
|
or tokens directly to a contract may result in permanent
|
||||||
|
loss of funds.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
id="confirm-burn-warning"
|
||||||
|
class="mb-2"
|
||||||
|
style="visibility: hidden"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="border border-red-500 border-dashed p-2 text-xs font-bold text-red-500"
|
||||||
|
>
|
||||||
|
WARNING: This is a known null/burn address. Funds sent
|
||||||
|
here are permanently destroyed and cannot be recovered.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
id="confirm-errors"
|
id="confirm-errors"
|
||||||
class="mb-2 border border-border border-dashed p-2 hidden"
|
class="mb-2 border border-border border-dashed p-2"
|
||||||
|
style="visibility: hidden; min-height: 1.25rem"
|
||||||
></div>
|
></div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<label class="block mb-1 text-xs">Password</label>
|
<label class="block mb-1 text-xs">Password</label>
|
||||||
@@ -592,6 +646,7 @@
|
|||||||
<div
|
<div
|
||||||
id="confirm-tx-password-error"
|
id="confirm-tx-password-error"
|
||||||
class="text-xs mb-2 min-h-[1.25rem]"
|
class="text-xs mb-2 min-h-[1.25rem]"
|
||||||
|
style="visibility: hidden"
|
||||||
></div>
|
></div>
|
||||||
<button
|
<button
|
||||||
id="btn-confirm-send"
|
id="btn-confirm-send"
|
||||||
@@ -706,7 +761,8 @@
|
|||||||
</button>
|
</button>
|
||||||
<div
|
<div
|
||||||
id="receive-erc20-warning"
|
id="receive-erc20-warning"
|
||||||
class="text-xs border border-border border-dashed p-2 mt-3 hidden"
|
class="text-xs border border-border border-dashed p-2 mt-3"
|
||||||
|
style="visibility: hidden"
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -734,7 +790,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
id="add-token-info"
|
id="add-token-info"
|
||||||
class="text-xs text-muted mb-2 hidden"
|
class="text-xs text-muted mb-2 min-h-[1.25rem]"
|
||||||
|
style="visibility: hidden"
|
||||||
></div>
|
></div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<label class="block mb-1 text-xs text-muted"
|
<label class="block mb-1 text-xs text-muted"
|
||||||
@@ -792,7 +849,7 @@
|
|||||||
<div class="bg-well p-3 mx-1 mb-3">
|
<div class="bg-well p-3 mx-1 mb-3">
|
||||||
<h3 class="font-bold mb-1">Display</h3>
|
<h3 class="font-bold mb-1">Display</h3>
|
||||||
<label
|
<label
|
||||||
class="text-xs flex items-center gap-1 cursor-pointer"
|
class="text-xs flex items-center gap-1 cursor-pointer mb-2"
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
@@ -800,6 +857,17 @@
|
|||||||
/>
|
/>
|
||||||
Show tracked tokens with zero balance
|
Show tracked tokens with zero balance
|
||||||
</label>
|
</label>
|
||||||
|
<div class="text-xs flex items-center gap-1">
|
||||||
|
<label for="settings-theme">Theme:</label>
|
||||||
|
<select
|
||||||
|
id="settings-theme"
|
||||||
|
class="border border-border p-1 bg-bg text-fg text-xs cursor-pointer"
|
||||||
|
>
|
||||||
|
<option value="system">System</option>
|
||||||
|
<option value="light">Light</option>
|
||||||
|
<option value="dark">Dark</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-well p-3 mx-1 mb-3">
|
<div class="bg-well p-3 mx-1 mb-3">
|
||||||
@@ -881,6 +949,12 @@
|
|||||||
/>
|
/>
|
||||||
<span class="text-xs text-muted">gwei</span>
|
<span class="text-xs text-muted">gwei</span>
|
||||||
</div>
|
</div>
|
||||||
|
<label
|
||||||
|
class="text-xs flex items-center gap-1 cursor-pointer mb-1"
|
||||||
|
>
|
||||||
|
<input type="checkbox" id="settings-utc-timestamps" />
|
||||||
|
UTC Timestamps
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-well p-3 mx-1 mb-3">
|
<div class="bg-well p-3 mx-1 mb-3">
|
||||||
@@ -916,7 +990,8 @@
|
|||||||
</p>
|
</p>
|
||||||
<div
|
<div
|
||||||
id="delete-wallet-flash"
|
id="delete-wallet-flash"
|
||||||
class="text-xs text-red-500 mb-2 hidden"
|
class="text-xs text-red-500 mb-2 min-h-[1.25rem]"
|
||||||
|
style="visibility: hidden"
|
||||||
></div>
|
></div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<label class="block mb-1">Password</label>
|
<label class="block mb-1">Password</label>
|
||||||
@@ -991,7 +1066,8 @@
|
|||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
id="settings-addtoken-info"
|
id="settings-addtoken-info"
|
||||||
class="text-xs text-muted mt-1 hidden"
|
class="text-xs text-muted mt-1 min-h-[1.25rem]"
|
||||||
|
style="visibility: hidden"
|
||||||
></div>
|
></div>
|
||||||
<button
|
<button
|
||||||
id="btn-settings-addtoken-manual"
|
id="btn-settings-addtoken-manual"
|
||||||
@@ -1073,6 +1149,20 @@
|
|||||||
<!-- ============ TRANSACTION APPROVAL ============ -->
|
<!-- ============ TRANSACTION APPROVAL ============ -->
|
||||||
<div id="view-approve-tx" class="view hidden">
|
<div id="view-approve-tx" class="view hidden">
|
||||||
<h2 class="font-bold mb-2">Transaction Request</h2>
|
<h2 class="font-bold mb-2">Transaction Request</h2>
|
||||||
|
<div
|
||||||
|
id="approve-tx-phishing-warning"
|
||||||
|
class="mb-3 p-2 text-xs font-bold hidden"
|
||||||
|
style="
|
||||||
|
background: #fee2e2;
|
||||||
|
color: #991b1b;
|
||||||
|
border: 2px solid #dc2626;
|
||||||
|
border-radius: 6px;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
⚠️ PHISHING WARNING: This site is on MetaMask's phishing
|
||||||
|
blocklist. This transaction may steal your funds. Proceed
|
||||||
|
with extreme caution.
|
||||||
|
</div>
|
||||||
<p class="mb-2">
|
<p class="mb-2">
|
||||||
<span id="approve-tx-hostname" class="font-bold"></span>
|
<span id="approve-tx-hostname" class="font-bold"></span>
|
||||||
wants to send a transaction.
|
wants to send a transaction.
|
||||||
@@ -1117,7 +1207,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
id="approve-tx-error"
|
id="approve-tx-error"
|
||||||
class="text-xs mb-2 border border-border border-dashed p-1 min-h-[1.25rem] hidden"
|
class="text-xs mb-2 border border-border border-dashed p-1 min-h-[1.25rem]"
|
||||||
|
style="visibility: hidden"
|
||||||
></div>
|
></div>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<button
|
<button
|
||||||
@@ -1138,6 +1229,20 @@
|
|||||||
<!-- ============ SIGNATURE APPROVAL ============ -->
|
<!-- ============ SIGNATURE APPROVAL ============ -->
|
||||||
<div id="view-approve-sign" class="view hidden">
|
<div id="view-approve-sign" class="view hidden">
|
||||||
<h2 class="font-bold mb-2">Signature Request</h2>
|
<h2 class="font-bold mb-2">Signature Request</h2>
|
||||||
|
<div
|
||||||
|
id="approve-sign-phishing-warning"
|
||||||
|
class="mb-3 p-2 text-xs font-bold hidden"
|
||||||
|
style="
|
||||||
|
background: #fee2e2;
|
||||||
|
color: #991b1b;
|
||||||
|
border: 2px solid #dc2626;
|
||||||
|
border-radius: 6px;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
⚠️ PHISHING WARNING: This site is on MetaMask's phishing
|
||||||
|
blocklist. Signing this message may authorize theft of your
|
||||||
|
funds. Proceed with extreme caution.
|
||||||
|
</div>
|
||||||
<p class="mb-2">
|
<p class="mb-2">
|
||||||
<span id="approve-sign-hostname" class="font-bold"></span>
|
<span id="approve-sign-hostname" class="font-bold"></span>
|
||||||
wants you to sign a message.
|
wants you to sign a message.
|
||||||
@@ -1145,8 +1250,10 @@
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
id="approve-sign-danger-warning"
|
id="approve-sign-danger-warning"
|
||||||
class="hidden mb-3 p-2 text-xs font-bold"
|
class="mb-3 p-2 text-xs font-bold"
|
||||||
style="
|
style="
|
||||||
|
visibility: hidden;
|
||||||
|
min-height: 1.25rem;
|
||||||
background: #fee2e2;
|
background: #fee2e2;
|
||||||
color: #991b1b;
|
color: #991b1b;
|
||||||
border: 2px solid #dc2626;
|
border: 2px solid #dc2626;
|
||||||
@@ -1183,7 +1290,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
id="approve-sign-error"
|
id="approve-sign-error"
|
||||||
class="text-xs mb-2 border border-border border-dashed p-1 min-h-[1.25rem] hidden"
|
class="text-xs mb-2 border border-border border-dashed p-1 min-h-[1.25rem]"
|
||||||
|
style="visibility: hidden"
|
||||||
></div>
|
></div>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<button
|
<button
|
||||||
@@ -1204,6 +1312,20 @@
|
|||||||
<!-- ============ SITE APPROVAL ============ -->
|
<!-- ============ SITE APPROVAL ============ -->
|
||||||
<div id="view-approve-site" class="view hidden">
|
<div id="view-approve-site" class="view hidden">
|
||||||
<h2 class="font-bold mb-2">Connection Request</h2>
|
<h2 class="font-bold mb-2">Connection Request</h2>
|
||||||
|
<div
|
||||||
|
id="approve-site-phishing-warning"
|
||||||
|
class="mb-3 p-2 text-xs font-bold hidden"
|
||||||
|
style="
|
||||||
|
background: #fee2e2;
|
||||||
|
color: #991b1b;
|
||||||
|
border: 2px solid #dc2626;
|
||||||
|
border-radius: 6px;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
⚠️ PHISHING WARNING: This site is on MetaMask's phishing
|
||||||
|
blocklist. Connecting your wallet may result in loss of
|
||||||
|
funds. Proceed with extreme caution.
|
||||||
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<p class="mb-2">
|
<p class="mb-2">
|
||||||
<span id="approve-hostname" class="font-bold"></span>
|
<span id="approve-hostname" class="font-bold"></span>
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ const { state, saveState, loadState } = require("../shared/state");
|
|||||||
const { refreshPrices } = require("../shared/prices");
|
const { refreshPrices } = require("../shared/prices");
|
||||||
const { refreshBalances } = require("../shared/balances");
|
const { refreshBalances } = require("../shared/balances");
|
||||||
const { $, showView } = require("./views/helpers");
|
const { $, showView } = require("./views/helpers");
|
||||||
|
const { applyTheme } = require("./theme");
|
||||||
|
|
||||||
const home = require("./views/home");
|
const home = require("./views/home");
|
||||||
const welcome = require("./views/welcome");
|
const welcome = require("./views/welcome");
|
||||||
const addWallet = require("./views/addWallet");
|
const addWallet = require("./views/addWallet");
|
||||||
const importKey = require("./views/importKey");
|
|
||||||
const addressDetail = require("./views/addressDetail");
|
const addressDetail = require("./views/addressDetail");
|
||||||
const addressToken = require("./views/addressToken");
|
const addressToken = require("./views/addressToken");
|
||||||
const send = require("./views/send");
|
const send = require("./views/send");
|
||||||
@@ -54,7 +54,6 @@ const ctx = {
|
|||||||
renderWalletList,
|
renderWalletList,
|
||||||
doRefreshAndRender,
|
doRefreshAndRender,
|
||||||
showAddWalletView: () => addWallet.show(),
|
showAddWalletView: () => addWallet.show(),
|
||||||
showImportKeyView: () => importKey.show(),
|
|
||||||
showAddressDetail: () => addressDetail.show(),
|
showAddressDetail: () => addressDetail.show(),
|
||||||
showAddressToken: () => addressToken.show(),
|
showAddressToken: () => addressToken.show(),
|
||||||
showAddTokenView: () => addToken.show(),
|
showAddTokenView: () => addToken.show(),
|
||||||
@@ -178,6 +177,7 @@ async function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await loadState();
|
await loadState();
|
||||||
|
applyTheme(state.theme);
|
||||||
|
|
||||||
// Auto-default active address
|
// Auto-default active address
|
||||||
if (
|
if (
|
||||||
@@ -217,7 +217,6 @@ async function init() {
|
|||||||
|
|
||||||
welcome.init(ctx);
|
welcome.init(ctx);
|
||||||
addWallet.init(ctx);
|
addWallet.init(ctx);
|
||||||
importKey.init(ctx);
|
|
||||||
home.init(ctx);
|
home.init(ctx);
|
||||||
addressDetail.init(ctx);
|
addressDetail.init(ctx);
|
||||||
addressToken.init(ctx);
|
addressToken.init(ctx);
|
||||||
|
|||||||
@@ -15,7 +15,32 @@
|
|||||||
--color-section: #dddddd;
|
--color-section: #dddddd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html.dark {
|
||||||
|
--color-bg: #000000;
|
||||||
|
--color-fg: #ffffff;
|
||||||
|
--color-muted: #aaaaaa;
|
||||||
|
--color-border: #ffffff;
|
||||||
|
--color-border-light: #444444;
|
||||||
|
--color-hover: #222222;
|
||||||
|
--color-well: #1a1a1a;
|
||||||
|
--color-danger-well: #2a0a0a;
|
||||||
|
--color-section: #2a2a2a;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
width: 396px;
|
width: 396px;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Copy-flash feedback: inverts colors then fades back */
|
||||||
|
.copy-flash-active {
|
||||||
|
background-color: var(--color-fg) !important;
|
||||||
|
color: var(--color-bg) !important;
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.copy-flash-fade {
|
||||||
|
transition:
|
||||||
|
background-color 225ms ease-out,
|
||||||
|
color 225ms ease-out;
|
||||||
|
}
|
||||||
|
|||||||
33
src/popup/theme.js
Normal file
33
src/popup/theme.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
// Theme management: applies light/dark class to <html> based on preference.
|
||||||
|
|
||||||
|
let mediaQuery = null;
|
||||||
|
let mediaHandler = null;
|
||||||
|
|
||||||
|
function applyTheme(theme) {
|
||||||
|
// Clean up previous system listener
|
||||||
|
if (mediaQuery && mediaHandler) {
|
||||||
|
mediaQuery.removeEventListener("change", mediaHandler);
|
||||||
|
mediaHandler = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (theme === "dark") {
|
||||||
|
document.documentElement.classList.add("dark");
|
||||||
|
} else if (theme === "light") {
|
||||||
|
document.documentElement.classList.remove("dark");
|
||||||
|
} else {
|
||||||
|
// system
|
||||||
|
mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||||
|
const update = () => {
|
||||||
|
if (mediaQuery.matches) {
|
||||||
|
document.documentElement.classList.add("dark");
|
||||||
|
} else {
|
||||||
|
document.documentElement.classList.remove("dark");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mediaHandler = update;
|
||||||
|
mediaQuery.addEventListener("change", update);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { applyTheme };
|
||||||
@@ -7,7 +7,8 @@ const { log } = require("../../shared/log");
|
|||||||
|
|
||||||
function show() {
|
function show() {
|
||||||
$("add-token-address").value = "";
|
$("add-token-address").value = "";
|
||||||
$("add-token-info").classList.add("hidden");
|
$("add-token-info").textContent = "";
|
||||||
|
$("add-token-info").style.visibility = "hidden";
|
||||||
const list = $("common-token-list");
|
const list = $("common-token-list");
|
||||||
list.innerHTML = getTopTokens(25)
|
list.innerHTML = getTopTokens(25)
|
||||||
.map(
|
.map(
|
||||||
@@ -45,7 +46,7 @@ function init(ctx) {
|
|||||||
}
|
}
|
||||||
const infoEl = $("add-token-info");
|
const infoEl = $("add-token-info");
|
||||||
infoEl.textContent = "Looking up token...";
|
infoEl.textContent = "Looking up token...";
|
||||||
infoEl.classList.remove("hidden");
|
infoEl.style.visibility = "visible";
|
||||||
log.debugf("Looking up token contract", contractAddr);
|
log.debugf("Looking up token contract", contractAddr);
|
||||||
try {
|
try {
|
||||||
const info = await lookupTokenInfo(contractAddr, state.rpcUrl);
|
const info = await lookupTokenInfo(contractAddr, state.rpcUrl);
|
||||||
@@ -63,7 +64,8 @@ function init(ctx) {
|
|||||||
const detail = e.shortMessage || e.message || String(e);
|
const detail = e.shortMessage || e.message || String(e);
|
||||||
log.errorf("Token lookup failed for", contractAddr, detail);
|
log.errorf("Token lookup failed for", contractAddr, detail);
|
||||||
showFlash(detail);
|
showFlash(detail);
|
||||||
infoEl.classList.add("hidden");
|
infoEl.textContent = "";
|
||||||
|
infoEl.style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,114 +3,299 @@ const {
|
|||||||
generateMnemonic,
|
generateMnemonic,
|
||||||
hdWalletFromMnemonic,
|
hdWalletFromMnemonic,
|
||||||
isValidMnemonic,
|
isValidMnemonic,
|
||||||
|
addressFromPrivateKey,
|
||||||
|
hdWalletFromXprv,
|
||||||
|
isValidXprv,
|
||||||
} = require("../../shared/wallet");
|
} = require("../../shared/wallet");
|
||||||
const { encryptWithPassword } = require("../../shared/vault");
|
const { encryptWithPassword } = require("../../shared/vault");
|
||||||
const { state, saveState } = require("../../shared/state");
|
const { state, saveState } = require("../../shared/state");
|
||||||
const { scanForAddresses } = require("../../shared/balances");
|
const { scanForAddresses } = require("../../shared/balances");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if an address already exists in ANY wallet (hd, xprv, or key).
|
||||||
|
* Returns the wallet object if found, or undefined.
|
||||||
|
*/
|
||||||
|
function findWalletByAddress(addr) {
|
||||||
|
const lower = addr.toLowerCase();
|
||||||
|
return state.wallets.find((w) =>
|
||||||
|
w.addresses.some((a) => a.address.toLowerCase() === lower),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if an xpub already exists in any HD-type wallet (hd or xprv).
|
||||||
|
* Returns the wallet object if found, or undefined.
|
||||||
|
*/
|
||||||
|
function findWalletByXpub(xpub) {
|
||||||
|
return state.wallets.find((w) => w.xpub && w.xpub === xpub);
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentMode = "mnemonic";
|
||||||
|
|
||||||
|
const MODES = ["mnemonic", "privkey", "xprv"];
|
||||||
|
|
||||||
|
const PASSWORD_HINTS = {
|
||||||
|
mnemonic:
|
||||||
|
"This password encrypts your recovery phrase on this device. You will need it to send funds.",
|
||||||
|
privkey:
|
||||||
|
"This password encrypts your private key on this device. You will need it to send funds.",
|
||||||
|
xprv: "This password encrypts your key on this device. You will need it to send funds.",
|
||||||
|
};
|
||||||
|
|
||||||
|
function switchMode(mode) {
|
||||||
|
currentMode = mode;
|
||||||
|
for (const m of MODES) {
|
||||||
|
$("add-wallet-section-" + m).classList.toggle("hidden", m !== mode);
|
||||||
|
const tab = $("tab-" + m);
|
||||||
|
const isActive = m === mode;
|
||||||
|
// Active: bold, solid border on top/sides, no bottom border (connects to content)
|
||||||
|
tab.classList.toggle("font-bold", isActive);
|
||||||
|
tab.classList.toggle("border-solid", isActive);
|
||||||
|
tab.classList.toggle("border-border", isActive);
|
||||||
|
tab.classList.toggle("border-b-bg", isActive);
|
||||||
|
tab.classList.toggle("bg-bg", isActive);
|
||||||
|
// Inactive: muted text, dashed border on top/sides, transparent bottom, hover invert
|
||||||
|
tab.classList.toggle("text-muted", !isActive);
|
||||||
|
tab.classList.toggle("border-dashed", !isActive);
|
||||||
|
tab.classList.toggle("border-border-light", !isActive);
|
||||||
|
tab.classList.toggle("border-b-transparent", !isActive);
|
||||||
|
tab.classList.toggle("hover:bg-fg", !isActive);
|
||||||
|
tab.classList.toggle("hover:text-bg", !isActive);
|
||||||
|
}
|
||||||
|
$("add-wallet-password-hint").textContent = PASSWORD_HINTS[mode];
|
||||||
|
}
|
||||||
|
|
||||||
function show() {
|
function show() {
|
||||||
$("wallet-mnemonic").value = "";
|
$("wallet-mnemonic").value = "";
|
||||||
|
$("import-private-key").value = "";
|
||||||
|
$("import-xprv-key").value = "";
|
||||||
$("add-wallet-password").value = "";
|
$("add-wallet-password").value = "";
|
||||||
$("add-wallet-password-confirm").value = "";
|
$("add-wallet-password-confirm").value = "";
|
||||||
$("add-wallet-phrase-warning").classList.add("hidden");
|
$("add-wallet-phrase-warning").style.visibility = "hidden";
|
||||||
|
switchMode("mnemonic");
|
||||||
showView("add-wallet");
|
showView("add-wallet");
|
||||||
}
|
}
|
||||||
|
|
||||||
function init(ctx) {
|
function validatePassword() {
|
||||||
$("btn-generate-phrase").addEventListener("click", () => {
|
const pw = $("add-wallet-password").value;
|
||||||
$("wallet-mnemonic").value = generateMnemonic();
|
const pw2 = $("add-wallet-password-confirm").value;
|
||||||
$("add-wallet-phrase-warning").classList.remove("hidden");
|
if (!pw) {
|
||||||
});
|
showFlash("Please choose a password.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (pw.length < 12) {
|
||||||
|
showFlash("Password must be at least 12 characters.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (pw !== pw2) {
|
||||||
|
showFlash("Passwords do not match.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return pw;
|
||||||
|
}
|
||||||
|
|
||||||
$("btn-add-wallet-confirm").addEventListener("click", async () => {
|
async function importMnemonic(ctx) {
|
||||||
const mnemonic = $("wallet-mnemonic").value.trim();
|
const mnemonic = $("wallet-mnemonic").value.trim();
|
||||||
if (!mnemonic) {
|
if (!mnemonic) {
|
||||||
showFlash(
|
showFlash("Enter a recovery phrase or press the die to generate one.");
|
||||||
"Enter a recovery phrase or press the die to generate one.",
|
return;
|
||||||
);
|
}
|
||||||
return;
|
const words = mnemonic.split(/\s+/);
|
||||||
}
|
if (words.length !== 12 && words.length !== 24) {
|
||||||
const words = mnemonic.split(/\s+/);
|
showFlash(
|
||||||
if (words.length !== 12 && words.length !== 24) {
|
"Recovery phrase must be 12 or 24 words. You entered " +
|
||||||
showFlash(
|
words.length +
|
||||||
"Recovery phrase must be 12 or 24 words. You entered " +
|
".",
|
||||||
words.length +
|
|
||||||
".",
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!isValidMnemonic(mnemonic)) {
|
|
||||||
showFlash("Invalid recovery phrase. Check for typos.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const pw = $("add-wallet-password").value;
|
|
||||||
const pw2 = $("add-wallet-password-confirm").value;
|
|
||||||
if (!pw) {
|
|
||||||
showFlash("Please choose a password.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (pw.length < 12) {
|
|
||||||
showFlash("Password must be at least 12 characters.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (pw !== pw2) {
|
|
||||||
showFlash("Passwords do not match.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { xpub, firstAddress } = hdWalletFromMnemonic(mnemonic);
|
|
||||||
const duplicate = state.wallets.find(
|
|
||||||
(w) =>
|
|
||||||
w.type === "hd" &&
|
|
||||||
w.addresses[0] &&
|
|
||||||
w.addresses[0].address.toLowerCase() ===
|
|
||||||
firstAddress.toLowerCase(),
|
|
||||||
);
|
);
|
||||||
if (duplicate) {
|
return;
|
||||||
showFlash(
|
}
|
||||||
"This recovery phrase is already added (" +
|
if (!isValidMnemonic(mnemonic)) {
|
||||||
duplicate.name +
|
showFlash("Invalid recovery phrase. Check for typos.");
|
||||||
").",
|
return;
|
||||||
);
|
}
|
||||||
return;
|
const pw = validatePassword();
|
||||||
}
|
if (!pw) return;
|
||||||
const encrypted = await encryptWithPassword(mnemonic, pw);
|
const { xpub, firstAddress } = hdWalletFromMnemonic(mnemonic);
|
||||||
const walletNum = state.wallets.length + 1;
|
const xpubDup = findWalletByXpub(xpub);
|
||||||
const wallet = {
|
if (xpubDup) {
|
||||||
type: "hd",
|
showFlash(
|
||||||
name: "Wallet " + walletNum,
|
"This recovery phrase is already added (" + xpubDup.name + ").",
|
||||||
xpub: xpub,
|
);
|
||||||
encryptedSecret: encrypted,
|
return;
|
||||||
nextIndex: 1,
|
}
|
||||||
addresses: [
|
const addrDup = findWalletByAddress(firstAddress);
|
||||||
{ address: firstAddress, balance: "0.0000", tokenBalances: [] },
|
if (addrDup) {
|
||||||
],
|
showFlash("Address already exists in wallet (" + addrDup.name + ").");
|
||||||
};
|
return;
|
||||||
state.wallets.push(wallet);
|
}
|
||||||
state.hasWallet = true;
|
const encrypted = await encryptWithPassword(mnemonic, pw);
|
||||||
|
const walletNum = state.wallets.length + 1;
|
||||||
|
const wallet = {
|
||||||
|
type: "hd",
|
||||||
|
name: "Wallet " + walletNum,
|
||||||
|
xpub: xpub,
|
||||||
|
encryptedSecret: encrypted,
|
||||||
|
nextIndex: 1,
|
||||||
|
addresses: [
|
||||||
|
{ address: firstAddress, balance: "0.0000", tokenBalances: [] },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
state.wallets.push(wallet);
|
||||||
|
state.hasWallet = true;
|
||||||
|
await saveState();
|
||||||
|
ctx.renderWalletList();
|
||||||
|
showView("main");
|
||||||
|
|
||||||
|
// Scan for used HD addresses beyond index 0.
|
||||||
|
showFlash("Scanning for addresses...", 30000);
|
||||||
|
const scan = await scanForAddresses(xpub, state.rpcUrl);
|
||||||
|
if (scan.addresses.length > 1) {
|
||||||
|
wallet.addresses = scan.addresses.map((a) => ({
|
||||||
|
address: a.address,
|
||||||
|
balance: "0.0000",
|
||||||
|
tokenBalances: [],
|
||||||
|
}));
|
||||||
|
wallet.nextIndex = scan.nextIndex;
|
||||||
await saveState();
|
await saveState();
|
||||||
ctx.renderWalletList();
|
ctx.renderWalletList();
|
||||||
showView("main");
|
showFlash("Found " + scan.addresses.length + " addresses.");
|
||||||
|
} else {
|
||||||
|
showFlash("Ready.", 1000);
|
||||||
|
}
|
||||||
|
|
||||||
// Scan for used HD addresses beyond index 0.
|
ctx.doRefreshAndRender();
|
||||||
showFlash("Scanning for addresses...", 30000);
|
}
|
||||||
const scan = await scanForAddresses(xpub, state.rpcUrl);
|
|
||||||
if (scan.addresses.length > 1) {
|
|
||||||
wallet.addresses = scan.addresses.map((a) => ({
|
|
||||||
address: a.address,
|
|
||||||
balance: "0.0000",
|
|
||||||
tokenBalances: [],
|
|
||||||
}));
|
|
||||||
wallet.nextIndex = scan.nextIndex;
|
|
||||||
await saveState();
|
|
||||||
ctx.renderWalletList();
|
|
||||||
showFlash("Found " + scan.addresses.length + " addresses.");
|
|
||||||
} else {
|
|
||||||
showFlash("Ready.", 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.doRefreshAndRender();
|
async function importPrivateKey(ctx) {
|
||||||
|
const key = $("import-private-key").value.trim();
|
||||||
|
if (!key) {
|
||||||
|
showFlash("Please enter your private key.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let addr;
|
||||||
|
try {
|
||||||
|
addr = addressFromPrivateKey(key);
|
||||||
|
} catch (e) {
|
||||||
|
showFlash("Invalid private key.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const pw = validatePassword();
|
||||||
|
if (!pw) return;
|
||||||
|
const duplicate = findWalletByAddress(addr);
|
||||||
|
if (duplicate) {
|
||||||
|
showFlash(
|
||||||
|
"This address already exists in wallet (" + duplicate.name + ").",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const encrypted = await encryptWithPassword(key, pw);
|
||||||
|
const walletNum = state.wallets.length + 1;
|
||||||
|
state.wallets.push({
|
||||||
|
type: "key",
|
||||||
|
name: "Wallet " + walletNum,
|
||||||
|
encryptedSecret: encrypted,
|
||||||
|
addresses: [{ address: addr, balance: "0.0000", tokenBalances: [] }],
|
||||||
|
});
|
||||||
|
state.hasWallet = true;
|
||||||
|
await saveState();
|
||||||
|
ctx.renderWalletList();
|
||||||
|
showView("main");
|
||||||
|
|
||||||
|
ctx.doRefreshAndRender();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function importXprvKey(ctx) {
|
||||||
|
const xprv = $("import-xprv-key").value.trim();
|
||||||
|
if (!xprv) {
|
||||||
|
showFlash("Please enter your extended private key.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isValidXprv(xprv)) {
|
||||||
|
showFlash("Invalid extended private key.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = hdWalletFromXprv(xprv);
|
||||||
|
} catch (e) {
|
||||||
|
showFlash("Invalid extended private key.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { xpub, firstAddress } = result;
|
||||||
|
const xpubDup = findWalletByXpub(xpub);
|
||||||
|
if (xpubDup) {
|
||||||
|
showFlash("This key is already added (" + xpubDup.name + ").");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const addrDup = findWalletByAddress(firstAddress);
|
||||||
|
if (addrDup) {
|
||||||
|
showFlash("Address already exists in wallet (" + addrDup.name + ").");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const pw = validatePassword();
|
||||||
|
if (!pw) return;
|
||||||
|
const encrypted = await encryptWithPassword(xprv, pw);
|
||||||
|
const walletNum = state.wallets.length + 1;
|
||||||
|
const wallet = {
|
||||||
|
type: "xprv",
|
||||||
|
name: "Wallet " + walletNum,
|
||||||
|
xpub: xpub,
|
||||||
|
encryptedSecret: encrypted,
|
||||||
|
nextIndex: 1,
|
||||||
|
addresses: [
|
||||||
|
{ address: firstAddress, balance: "0.0000", tokenBalances: [] },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
state.wallets.push(wallet);
|
||||||
|
state.hasWallet = true;
|
||||||
|
await saveState();
|
||||||
|
ctx.renderWalletList();
|
||||||
|
showView("main");
|
||||||
|
|
||||||
|
// Scan for used HD addresses beyond index 0.
|
||||||
|
showFlash("Scanning for addresses...", 30000);
|
||||||
|
const scan = await scanForAddresses(xpub, state.rpcUrl);
|
||||||
|
if (scan.addresses.length > 1) {
|
||||||
|
wallet.addresses = scan.addresses.map((a) => ({
|
||||||
|
address: a.address,
|
||||||
|
balance: "0.0000",
|
||||||
|
tokenBalances: [],
|
||||||
|
}));
|
||||||
|
wallet.nextIndex = scan.nextIndex;
|
||||||
|
await saveState();
|
||||||
|
ctx.renderWalletList();
|
||||||
|
showFlash("Found " + scan.addresses.length + " addresses.");
|
||||||
|
} else {
|
||||||
|
showFlash("Ready.", 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.doRefreshAndRender();
|
||||||
|
}
|
||||||
|
|
||||||
|
function init(ctx) {
|
||||||
|
// Tab click handlers
|
||||||
|
$("tab-mnemonic").addEventListener("click", () => switchMode("mnemonic"));
|
||||||
|
$("tab-privkey").addEventListener("click", () => switchMode("privkey"));
|
||||||
|
$("tab-xprv").addEventListener("click", () => switchMode("xprv"));
|
||||||
|
|
||||||
|
// Generate mnemonic
|
||||||
|
$("btn-generate-phrase").addEventListener("click", () => {
|
||||||
|
$("wallet-mnemonic").value = generateMnemonic();
|
||||||
|
$("add-wallet-phrase-warning").style.visibility = "visible";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Import / confirm
|
||||||
|
$("btn-add-wallet-confirm").addEventListener("click", async () => {
|
||||||
|
if (currentMode === "mnemonic") {
|
||||||
|
await importMnemonic(ctx);
|
||||||
|
} else if (currentMode === "privkey") {
|
||||||
|
await importPrivateKey(ctx);
|
||||||
|
} else if (currentMode === "xprv") {
|
||||||
|
await importXprvKey(ctx);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Back button
|
||||||
$("btn-add-wallet-back").addEventListener("click", () => {
|
$("btn-add-wallet-back").addEventListener("click", () => {
|
||||||
if (!state.hasWallet) {
|
if (!state.hasWallet) {
|
||||||
showView("welcome");
|
showView("welcome");
|
||||||
@@ -119,11 +304,6 @@ function init(ctx) {
|
|||||||
showView("main");
|
showView("main");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("btn-add-wallet-import-key").addEventListener(
|
|
||||||
"click",
|
|
||||||
ctx.showImportKeyView,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { init, show };
|
module.exports = { init, show };
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const {
|
|||||||
$,
|
$,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
|
flashCopyFeedback,
|
||||||
balanceLinesForAddress,
|
balanceLinesForAddress,
|
||||||
addressDotHtml,
|
addressDotHtml,
|
||||||
addressTitle,
|
addressTitle,
|
||||||
@@ -94,18 +95,39 @@ function show() {
|
|||||||
function isoDate(timestamp) {
|
function isoDate(timestamp) {
|
||||||
const d = new Date(timestamp * 1000);
|
const d = new Date(timestamp * 1000);
|
||||||
const pad = (n) => String(n).padStart(2, "0");
|
const pad = (n) => String(n).padStart(2, "0");
|
||||||
|
if (state.utcTimestamps) {
|
||||||
|
return (
|
||||||
|
d.getUTCFullYear() +
|
||||||
|
"-" +
|
||||||
|
pad(d.getUTCMonth() + 1) +
|
||||||
|
"-" +
|
||||||
|
pad(d.getUTCDate()) +
|
||||||
|
"T" +
|
||||||
|
pad(d.getUTCHours()) +
|
||||||
|
":" +
|
||||||
|
pad(d.getUTCMinutes()) +
|
||||||
|
":" +
|
||||||
|
pad(d.getUTCSeconds()) +
|
||||||
|
"Z"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const offsetMin = -d.getTimezoneOffset();
|
||||||
|
const sign = offsetMin >= 0 ? "+" : "-";
|
||||||
|
const absOff = Math.abs(offsetMin);
|
||||||
|
const tzStr = sign + pad(Math.floor(absOff / 60)) + ":" + pad(absOff % 60);
|
||||||
return (
|
return (
|
||||||
d.getFullYear() +
|
d.getFullYear() +
|
||||||
"-" +
|
"-" +
|
||||||
pad(d.getMonth() + 1) +
|
pad(d.getMonth() + 1) +
|
||||||
"-" +
|
"-" +
|
||||||
pad(d.getDate()) +
|
pad(d.getDate()) +
|
||||||
" " +
|
"T" +
|
||||||
pad(d.getHours()) +
|
pad(d.getHours()) +
|
||||||
":" +
|
":" +
|
||||||
pad(d.getMinutes()) +
|
pad(d.getMinutes()) +
|
||||||
":" +
|
":" +
|
||||||
pad(d.getSeconds())
|
pad(d.getSeconds()) +
|
||||||
|
tzStr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,6 +263,7 @@ function init(_ctx) {
|
|||||||
if (addr) {
|
if (addr) {
|
||||||
navigator.clipboard.writeText(addr);
|
navigator.clipboard.writeText(addr);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
|
flashCopyFeedback($("address-full"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -310,8 +333,8 @@ function init(_ctx) {
|
|||||||
$("export-privkey-address").textContent = addr.address;
|
$("export-privkey-address").textContent = addr.address;
|
||||||
$("export-privkey-address").dataset.full = addr.address;
|
$("export-privkey-address").dataset.full = addr.address;
|
||||||
$("export-privkey-password").value = "";
|
$("export-privkey-password").value = "";
|
||||||
$("export-privkey-flash").classList.add("hidden");
|
|
||||||
$("export-privkey-flash").textContent = "";
|
$("export-privkey-flash").textContent = "";
|
||||||
|
$("export-privkey-flash").style.visibility = "hidden";
|
||||||
$("export-privkey-password-section").classList.remove("hidden");
|
$("export-privkey-password-section").classList.remove("hidden");
|
||||||
$("export-privkey-result").classList.add("hidden");
|
$("export-privkey-result").classList.add("hidden");
|
||||||
$("export-privkey-value").textContent = "";
|
$("export-privkey-value").textContent = "";
|
||||||
@@ -322,7 +345,7 @@ function init(_ctx) {
|
|||||||
const password = $("export-privkey-password").value;
|
const password = $("export-privkey-password").value;
|
||||||
if (!password) {
|
if (!password) {
|
||||||
$("export-privkey-flash").textContent = "Password is required.";
|
$("export-privkey-flash").textContent = "Password is required.";
|
||||||
$("export-privkey-flash").classList.remove("hidden");
|
$("export-privkey-flash").style.visibility = "visible";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const btn = $("btn-export-privkey-confirm");
|
const btn = $("btn-export-privkey-confirm");
|
||||||
@@ -343,10 +366,10 @@ function init(_ctx) {
|
|||||||
$("export-privkey-password-section").classList.add("hidden");
|
$("export-privkey-password-section").classList.add("hidden");
|
||||||
$("export-privkey-value").textContent = privateKey;
|
$("export-privkey-value").textContent = privateKey;
|
||||||
$("export-privkey-result").classList.remove("hidden");
|
$("export-privkey-result").classList.remove("hidden");
|
||||||
$("export-privkey-flash").classList.add("hidden");
|
$("export-privkey-flash").style.visibility = "hidden";
|
||||||
} catch {
|
} catch {
|
||||||
$("export-privkey-flash").textContent = "Wrong password.";
|
$("export-privkey-flash").textContent = "Wrong password.";
|
||||||
$("export-privkey-flash").classList.remove("hidden");
|
$("export-privkey-flash").style.visibility = "visible";
|
||||||
} finally {
|
} finally {
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
btn.classList.remove("text-muted");
|
btn.classList.remove("text-muted");
|
||||||
@@ -358,6 +381,7 @@ function init(_ctx) {
|
|||||||
if (key) {
|
if (key) {
|
||||||
navigator.clipboard.writeText(key);
|
navigator.clipboard.writeText(key);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
|
flashCopyFeedback($("export-privkey-value"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -366,6 +390,7 @@ function init(_ctx) {
|
|||||||
if (full) {
|
if (full) {
|
||||||
navigator.clipboard.writeText(full);
|
navigator.clipboard.writeText(full);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
|
flashCopyFeedback($("export-privkey-address"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const {
|
|||||||
$,
|
$,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
|
flashCopyFeedback,
|
||||||
addressDotHtml,
|
addressDotHtml,
|
||||||
addressTitle,
|
addressTitle,
|
||||||
escapeHtml,
|
escapeHtml,
|
||||||
@@ -47,18 +48,39 @@ function etherscanAddressLink(address) {
|
|||||||
function isoDate(timestamp) {
|
function isoDate(timestamp) {
|
||||||
const d = new Date(timestamp * 1000);
|
const d = new Date(timestamp * 1000);
|
||||||
const pad = (n) => String(n).padStart(2, "0");
|
const pad = (n) => String(n).padStart(2, "0");
|
||||||
|
if (state.utcTimestamps) {
|
||||||
|
return (
|
||||||
|
d.getUTCFullYear() +
|
||||||
|
"-" +
|
||||||
|
pad(d.getUTCMonth() + 1) +
|
||||||
|
"-" +
|
||||||
|
pad(d.getUTCDate()) +
|
||||||
|
"T" +
|
||||||
|
pad(d.getUTCHours()) +
|
||||||
|
":" +
|
||||||
|
pad(d.getUTCMinutes()) +
|
||||||
|
":" +
|
||||||
|
pad(d.getUTCSeconds()) +
|
||||||
|
"Z"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const offsetMin = -d.getTimezoneOffset();
|
||||||
|
const sign = offsetMin >= 0 ? "+" : "-";
|
||||||
|
const absOff = Math.abs(offsetMin);
|
||||||
|
const tzStr = sign + pad(Math.floor(absOff / 60)) + ":" + pad(absOff % 60);
|
||||||
return (
|
return (
|
||||||
d.getFullYear() +
|
d.getFullYear() +
|
||||||
"-" +
|
"-" +
|
||||||
pad(d.getMonth() + 1) +
|
pad(d.getMonth() + 1) +
|
||||||
"-" +
|
"-" +
|
||||||
pad(d.getDate()) +
|
pad(d.getDate()) +
|
||||||
" " +
|
"T" +
|
||||||
pad(d.getHours()) +
|
pad(d.getHours()) +
|
||||||
":" +
|
":" +
|
||||||
pad(d.getMinutes()) +
|
pad(d.getMinutes()) +
|
||||||
":" +
|
":" +
|
||||||
pad(d.getSeconds())
|
pad(d.getSeconds()) +
|
||||||
|
tzStr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,6 +339,7 @@ function init(_ctx) {
|
|||||||
if (addr) {
|
if (addr) {
|
||||||
navigator.clipboard.writeText(addr);
|
navigator.clipboard.writeText(addr);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
|
flashCopyFeedback($("address-token-full"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -325,6 +348,7 @@ function init(_ctx) {
|
|||||||
if (copyEl) {
|
if (copyEl) {
|
||||||
navigator.clipboard.writeText(copyEl.dataset.copy);
|
navigator.clipboard.writeText(copyEl.dataset.copy);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
|
flashCopyFeedback(copyEl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -373,6 +397,7 @@ function init(_ctx) {
|
|||||||
copyEl.addEventListener("click", () => {
|
copyEl.addEventListener("click", () => {
|
||||||
navigator.clipboard.writeText(copyEl.dataset.copy);
|
navigator.clipboard.writeText(copyEl.dataset.copy);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
|
flashCopyFeedback(copyEl);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
updateSendBalance();
|
updateSendBalance();
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const { ERC20_ABI } = require("../../shared/constants");
|
|||||||
const { TOKEN_BY_ADDRESS } = require("../../shared/tokenList");
|
const { TOKEN_BY_ADDRESS } = require("../../shared/tokenList");
|
||||||
const txStatus = require("./txStatus");
|
const txStatus = require("./txStatus");
|
||||||
const uniswap = require("../../shared/uniswap");
|
const uniswap = require("../../shared/uniswap");
|
||||||
|
const { isPhishingDomain } = require("../../shared/phishingDomains");
|
||||||
|
|
||||||
const runtime =
|
const runtime =
|
||||||
typeof browser !== "undefined" ? browser.runtime : chrome.runtime;
|
typeof browser !== "undefined" ? browser.runtime : chrome.runtime;
|
||||||
@@ -155,7 +156,24 @@ function decodeCalldata(data, toAddress) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showPhishingWarning(elementId, hostname, isPhishing) {
|
||||||
|
const el = $(elementId);
|
||||||
|
if (!el) return;
|
||||||
|
// Check both the flag from background and a local re-check
|
||||||
|
if (isPhishing || isPhishingDomain(hostname)) {
|
||||||
|
el.classList.remove("hidden");
|
||||||
|
} else {
|
||||||
|
el.classList.add("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function showTxApproval(details) {
|
function showTxApproval(details) {
|
||||||
|
showPhishingWarning(
|
||||||
|
"approve-tx-phishing-warning",
|
||||||
|
details.hostname,
|
||||||
|
details.isPhishingDomain,
|
||||||
|
);
|
||||||
|
|
||||||
const toAddr = details.txParams.to;
|
const toAddr = details.txParams.to;
|
||||||
const token = toAddr ? TOKEN_BY_ADDRESS.get(toAddr.toLowerCase()) : null;
|
const token = toAddr ? TOKEN_BY_ADDRESS.get(toAddr.toLowerCase()) : null;
|
||||||
const ethValue = formatEther(details.txParams.value || "0");
|
const ethValue = formatEther(details.txParams.value || "0");
|
||||||
@@ -269,7 +287,7 @@ function showTxApproval(details) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$("approve-tx-password").value = "";
|
$("approve-tx-password").value = "";
|
||||||
$("approve-tx-error").classList.add("hidden");
|
hideError("approve-tx-error");
|
||||||
|
|
||||||
showView("approve-tx");
|
showView("approve-tx");
|
||||||
}
|
}
|
||||||
@@ -323,6 +341,12 @@ function formatTypedDataHtml(jsonStr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function showSignApproval(details) {
|
function showSignApproval(details) {
|
||||||
|
showPhishingWarning(
|
||||||
|
"approve-sign-phishing-warning",
|
||||||
|
details.hostname,
|
||||||
|
details.isPhishingDomain,
|
||||||
|
);
|
||||||
|
|
||||||
const sp = details.signParams;
|
const sp = details.signParams;
|
||||||
|
|
||||||
$("approve-sign-hostname").textContent = details.hostname;
|
$("approve-sign-hostname").textContent = details.hostname;
|
||||||
@@ -351,10 +375,10 @@ function showSignApproval(details) {
|
|||||||
if (warningEl) {
|
if (warningEl) {
|
||||||
if (sp.dangerWarning) {
|
if (sp.dangerWarning) {
|
||||||
warningEl.textContent = sp.dangerWarning;
|
warningEl.textContent = sp.dangerWarning;
|
||||||
warningEl.classList.remove("hidden");
|
warningEl.style.visibility = "visible";
|
||||||
} else {
|
} else {
|
||||||
warningEl.textContent = "";
|
warningEl.textContent = "";
|
||||||
warningEl.classList.add("hidden");
|
warningEl.style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,6 +406,12 @@ function show(id) {
|
|||||||
showSignApproval(details);
|
showSignApproval(details);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Site connection approval
|
||||||
|
showPhishingWarning(
|
||||||
|
"approve-site-phishing-warning",
|
||||||
|
details.hostname,
|
||||||
|
details.isPhishingDomain,
|
||||||
|
);
|
||||||
$("approve-hostname").textContent = details.hostname;
|
$("approve-hostname").textContent = details.hostname;
|
||||||
$("approve-address").innerHTML = approvalAddressHtml(
|
$("approve-address").innerHTML = approvalAddressHtml(
|
||||||
state.activeAddress,
|
state.activeAddress,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const {
|
|||||||
hideError,
|
hideError,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
|
flashCopyFeedback,
|
||||||
addressTitle,
|
addressTitle,
|
||||||
addressDotHtml,
|
addressDotHtml,
|
||||||
escapeHtml,
|
escapeHtml,
|
||||||
@@ -24,9 +25,11 @@ const { getSignerForAddress } = require("../../shared/wallet");
|
|||||||
const { decryptWithPassword } = require("../../shared/vault");
|
const { decryptWithPassword } = require("../../shared/vault");
|
||||||
const { formatUsd, getPrice } = require("../../shared/prices");
|
const { formatUsd, getPrice } = require("../../shared/prices");
|
||||||
const { getProvider } = require("../../shared/balances");
|
const { getProvider } = require("../../shared/balances");
|
||||||
const { isScamAddress } = require("../../shared/scamlist");
|
const {
|
||||||
const { hasZeroTransactionHistory } = require("../../shared/transactions");
|
getLocalWarnings,
|
||||||
const { ERC20_ABI } = require("../../shared/constants");
|
getFullWarnings,
|
||||||
|
} = require("../../shared/addressWarnings");
|
||||||
|
const { ERC20_ABI, isBurnAddress } = require("../../shared/constants");
|
||||||
const { log } = require("../../shared/log");
|
const { log } = require("../../shared/log");
|
||||||
const makeBlockie = require("ethereum-blockies-base64");
|
const makeBlockie = require("ethereum-blockies-base64");
|
||||||
const txStatus = require("./txStatus");
|
const txStatus = require("./txStatus");
|
||||||
@@ -118,6 +121,7 @@ function show(txInfo) {
|
|||||||
copyEl.onclick = () => {
|
copyEl.onclick = () => {
|
||||||
navigator.clipboard.writeText(copyEl.dataset.copy);
|
navigator.clipboard.writeText(copyEl.dataset.copy);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
|
flashCopyFeedback(copyEl);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -166,28 +170,23 @@ function show(txInfo) {
|
|||||||
$("confirm-balance").textContent = valueWithUsd(bal + " ETH", balUsd);
|
$("confirm-balance").textContent = valueWithUsd(bal + " ETH", balUsd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for warnings
|
// Check for warnings (synchronous local checks)
|
||||||
const warnings = [];
|
const localWarnings = getLocalWarnings(txInfo.to, {
|
||||||
if (isScamAddress(txInfo.to)) {
|
fromAddress: txInfo.from,
|
||||||
warnings.push(
|
});
|
||||||
"This address is on a known scam/fraud list. Do not send funds to this address.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (txInfo.to.toLowerCase() === txInfo.from.toLowerCase()) {
|
|
||||||
warnings.push("You are sending to your own address.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const warningsEl = $("confirm-warnings");
|
const warningsEl = $("confirm-warnings");
|
||||||
if (warnings.length > 0) {
|
if (localWarnings.length > 0) {
|
||||||
warningsEl.innerHTML = warnings
|
warningsEl.innerHTML = localWarnings
|
||||||
.map(
|
.map(
|
||||||
(w) =>
|
(w) =>
|
||||||
`<div class="border border-border border-dashed p-2 mb-1 text-xs font-bold">WARNING: ${w}</div>`,
|
`<div class="border border-border border-dashed p-2 mb-1 text-xs font-bold">WARNING: ${w.message}</div>`,
|
||||||
)
|
)
|
||||||
.join("");
|
.join("");
|
||||||
warningsEl.classList.remove("hidden");
|
warningsEl.style.visibility = "visible";
|
||||||
} else {
|
} else {
|
||||||
warningsEl.classList.add("hidden");
|
warningsEl.innerHTML = "";
|
||||||
|
warningsEl.style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for errors
|
// Check for errors
|
||||||
@@ -225,11 +224,12 @@ function show(txInfo) {
|
|||||||
errorsEl.innerHTML = errors
|
errorsEl.innerHTML = errors
|
||||||
.map((e) => `<div class="text-xs">${e}</div>`)
|
.map((e) => `<div class="text-xs">${e}</div>`)
|
||||||
.join("");
|
.join("");
|
||||||
errorsEl.classList.remove("hidden");
|
errorsEl.style.visibility = "visible";
|
||||||
sendBtn.disabled = true;
|
sendBtn.disabled = true;
|
||||||
sendBtn.classList.add("text-muted");
|
sendBtn.classList.add("text-muted");
|
||||||
} else {
|
} else {
|
||||||
errorsEl.classList.add("hidden");
|
errorsEl.innerHTML = "";
|
||||||
|
errorsEl.style.visibility = "hidden";
|
||||||
sendBtn.disabled = false;
|
sendBtn.disabled = false;
|
||||||
sendBtn.classList.remove("text-muted");
|
sendBtn.classList.remove("text-muted");
|
||||||
}
|
}
|
||||||
@@ -239,11 +239,21 @@ function show(txInfo) {
|
|||||||
hideError("confirm-tx-password-error");
|
hideError("confirm-tx-password-error");
|
||||||
|
|
||||||
// Gas estimate — show placeholder then fetch async
|
// Gas estimate — show placeholder then fetch async
|
||||||
$("confirm-fee").classList.remove("hidden");
|
$("confirm-fee").style.visibility = "visible";
|
||||||
$("confirm-fee-amount").textContent = "Estimating...";
|
$("confirm-fee-amount").textContent = "Estimating...";
|
||||||
state.viewData = { pendingTx: txInfo };
|
state.viewData = { pendingTx: txInfo };
|
||||||
showView("confirm-tx");
|
showView("confirm-tx");
|
||||||
|
|
||||||
|
// Reset async warnings to hidden (space always reserved, no layout shift)
|
||||||
|
$("confirm-recipient-warning").style.visibility = "hidden";
|
||||||
|
$("confirm-contract-warning").style.visibility = "hidden";
|
||||||
|
$("confirm-burn-warning").style.visibility = "hidden";
|
||||||
|
|
||||||
|
// Show burn warning via reserved element (in addition to inline warning)
|
||||||
|
if (isBurnAddress(txInfo.to)) {
|
||||||
|
$("confirm-burn-warning").style.visibility = "visible";
|
||||||
|
}
|
||||||
|
|
||||||
estimateGas(txInfo);
|
estimateGas(txInfo);
|
||||||
checkRecipientHistory(txInfo);
|
checkRecipientHistory(txInfo);
|
||||||
}
|
}
|
||||||
@@ -289,20 +299,22 @@ async function estimateGas(txInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkRecipientHistory(txInfo) {
|
async function checkRecipientHistory(txInfo) {
|
||||||
const isNew = await hasZeroTransactionHistory(
|
try {
|
||||||
txInfo.to,
|
const provider = getProvider(state.rpcUrl);
|
||||||
state.blockscoutUrl,
|
const asyncWarnings = await getFullWarnings(txInfo.to, provider, {
|
||||||
);
|
fromAddress: txInfo.from,
|
||||||
if (!isNew) return;
|
});
|
||||||
|
for (const w of asyncWarnings) {
|
||||||
const warningsEl = $("confirm-warnings");
|
if (w.type === "contract") {
|
||||||
const warningHtml =
|
$("confirm-contract-warning").style.visibility = "visible";
|
||||||
`<div class="border border-red-500 border-dashed p-2 mb-1 text-xs font-bold text-red-500">` +
|
}
|
||||||
`WARNING: This address has ZERO transaction history. ` +
|
if (w.type === "new-address") {
|
||||||
`It has never sent or received any funds. ` +
|
$("confirm-recipient-warning").style.visibility = "visible";
|
||||||
`Double-check the address before sending.</div>`;
|
}
|
||||||
warningsEl.innerHTML = warningHtml + warningsEl.innerHTML;
|
}
|
||||||
warningsEl.classList.remove("hidden");
|
} catch (e) {
|
||||||
|
log.errorf("recipient history check failed:", e.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function init(ctx) {
|
function init(ctx) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ function show(walletIdx) {
|
|||||||
wallet.name || "Wallet " + (walletIdx + 1);
|
wallet.name || "Wallet " + (walletIdx + 1);
|
||||||
$("delete-wallet-password").value = "";
|
$("delete-wallet-password").value = "";
|
||||||
$("delete-wallet-flash").textContent = "";
|
$("delete-wallet-flash").textContent = "";
|
||||||
$("delete-wallet-flash").classList.add("hidden");
|
$("delete-wallet-flash").style.visibility = "hidden";
|
||||||
showView("delete-wallet-confirm");
|
showView("delete-wallet-confirm");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,14 +29,14 @@ function init(_ctx) {
|
|||||||
if (!pw) {
|
if (!pw) {
|
||||||
$("delete-wallet-flash").textContent =
|
$("delete-wallet-flash").textContent =
|
||||||
"Please enter your password.";
|
"Please enter your password.";
|
||||||
$("delete-wallet-flash").classList.remove("hidden");
|
$("delete-wallet-flash").style.visibility = "visible";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleteWalletIndex === null) {
|
if (deleteWalletIndex === null) {
|
||||||
$("delete-wallet-flash").textContent =
|
$("delete-wallet-flash").textContent =
|
||||||
"No wallet selected for deletion.";
|
"No wallet selected for deletion.";
|
||||||
$("delete-wallet-flash").classList.remove("hidden");
|
$("delete-wallet-flash").style.visibility = "visible";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ function init(_ctx) {
|
|||||||
await decryptWithPassword(wallet.encryptedSecret, pw);
|
await decryptWithPassword(wallet.encryptedSecret, pw);
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
$("delete-wallet-flash").textContent = "Wrong password.";
|
$("delete-wallet-flash").textContent = "Wrong password.";
|
||||||
$("delete-wallet-flash").classList.remove("hidden");
|
$("delete-wallet-flash").style.visibility = "visible";
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
btn.classList.remove("text-muted");
|
btn.classList.remove("text-muted");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ const { state, saveState } = require("../../shared/state");
|
|||||||
const VIEWS = [
|
const VIEWS = [
|
||||||
"welcome",
|
"welcome",
|
||||||
"add-wallet",
|
"add-wallet",
|
||||||
"import-key",
|
|
||||||
"main",
|
"main",
|
||||||
"address",
|
"address",
|
||||||
"address-token",
|
"address-token",
|
||||||
@@ -41,11 +40,13 @@ function $(id) {
|
|||||||
function showError(id, msg) {
|
function showError(id, msg) {
|
||||||
const el = $(id);
|
const el = $(id);
|
||||||
el.textContent = msg;
|
el.textContent = msg;
|
||||||
el.classList.remove("hidden");
|
el.style.visibility = "visible";
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideError(id) {
|
function hideError(id) {
|
||||||
$(id).classList.add("hidden");
|
const el = $(id);
|
||||||
|
el.textContent = "";
|
||||||
|
el.style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
|
|
||||||
function showView(name) {
|
function showView(name) {
|
||||||
@@ -227,18 +228,39 @@ function formatAddressHtml(address, ensName, maxLen, title) {
|
|||||||
function isoDate(timestamp) {
|
function isoDate(timestamp) {
|
||||||
const d = new Date(timestamp * 1000);
|
const d = new Date(timestamp * 1000);
|
||||||
const pad = (n) => String(n).padStart(2, "0");
|
const pad = (n) => String(n).padStart(2, "0");
|
||||||
|
if (state.utcTimestamps) {
|
||||||
|
return (
|
||||||
|
d.getUTCFullYear() +
|
||||||
|
"-" +
|
||||||
|
pad(d.getUTCMonth() + 1) +
|
||||||
|
"-" +
|
||||||
|
pad(d.getUTCDate()) +
|
||||||
|
"T" +
|
||||||
|
pad(d.getUTCHours()) +
|
||||||
|
":" +
|
||||||
|
pad(d.getUTCMinutes()) +
|
||||||
|
":" +
|
||||||
|
pad(d.getUTCSeconds()) +
|
||||||
|
"Z"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const offsetMin = -d.getTimezoneOffset();
|
||||||
|
const sign = offsetMin >= 0 ? "+" : "-";
|
||||||
|
const absOff = Math.abs(offsetMin);
|
||||||
|
const tzStr = sign + pad(Math.floor(absOff / 60)) + ":" + pad(absOff % 60);
|
||||||
return (
|
return (
|
||||||
d.getFullYear() +
|
d.getFullYear() +
|
||||||
"-" +
|
"-" +
|
||||||
pad(d.getMonth() + 1) +
|
pad(d.getMonth() + 1) +
|
||||||
"-" +
|
"-" +
|
||||||
pad(d.getDate()) +
|
pad(d.getDate()) +
|
||||||
" " +
|
"T" +
|
||||||
pad(d.getHours()) +
|
pad(d.getHours()) +
|
||||||
":" +
|
":" +
|
||||||
pad(d.getMinutes()) +
|
pad(d.getMinutes()) +
|
||||||
":" +
|
":" +
|
||||||
pad(d.getSeconds())
|
pad(d.getSeconds()) +
|
||||||
|
tzStr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,12 +281,26 @@ function timeAgo(timestamp) {
|
|||||||
return years + " year" + (years !== 1 ? "s" : "") + " ago";
|
return years + " year" + (years !== 1 ? "s" : "") + " ago";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function flashCopyFeedback(el) {
|
||||||
|
if (!el) return;
|
||||||
|
el.classList.remove("copy-flash-fade");
|
||||||
|
el.classList.add("copy-flash-active");
|
||||||
|
setTimeout(() => {
|
||||||
|
el.classList.remove("copy-flash-active");
|
||||||
|
el.classList.add("copy-flash-fade");
|
||||||
|
setTimeout(() => {
|
||||||
|
el.classList.remove("copy-flash-fade");
|
||||||
|
}, 275);
|
||||||
|
}, 75);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
$,
|
$,
|
||||||
showError,
|
showError,
|
||||||
hideError,
|
hideError,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
|
flashCopyFeedback,
|
||||||
balanceLine,
|
balanceLine,
|
||||||
balanceLinesForAddress,
|
balanceLinesForAddress,
|
||||||
addressColor,
|
addressColor,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const {
|
|||||||
$,
|
$,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
|
flashCopyFeedback,
|
||||||
balanceLinesForAddress,
|
balanceLinesForAddress,
|
||||||
isoDate,
|
isoDate,
|
||||||
timeAgo,
|
timeAgo,
|
||||||
@@ -85,9 +86,10 @@ function renderActiveAddress() {
|
|||||||
el.innerHTML =
|
el.innerHTML =
|
||||||
`<span class="underline decoration-dashed cursor-pointer" id="active-addr-copy">${dot}${escapeHtml(addr)}</span>` +
|
`<span class="underline decoration-dashed cursor-pointer" id="active-addr-copy">${dot}${escapeHtml(addr)}</span>` +
|
||||||
`<a href="${link}" target="_blank" rel="noopener" class="inline-flex items-center">${EXT_ICON}</a>`;
|
`<a href="${link}" target="_blank" rel="noopener" class="inline-flex items-center">${EXT_ICON}</a>`;
|
||||||
$("active-addr-copy").addEventListener("click", () => {
|
$("active-addr-copy").addEventListener("click", (e) => {
|
||||||
navigator.clipboard.writeText(addr);
|
navigator.clipboard.writeText(addr);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
|
flashCopyFeedback(e.currentTarget);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
el.textContent = "";
|
el.textContent = "";
|
||||||
@@ -239,7 +241,7 @@ function render(ctx) {
|
|||||||
html += `<div>`;
|
html += `<div>`;
|
||||||
html += `<div class="flex justify-between items-center bg-section py-1 px-2" style="margin:0 -0.5rem">`;
|
html += `<div class="flex justify-between items-center bg-section py-1 px-2" style="margin:0 -0.5rem">`;
|
||||||
html += `<span class="font-bold cursor-pointer wallet-name underline decoration-dashed" data-wallet="${wi}">${wallet.name}</span>`;
|
html += `<span class="font-bold cursor-pointer wallet-name underline decoration-dashed" data-wallet="${wi}">${wallet.name}</span>`;
|
||||||
if (wallet.type === "hd") {
|
if (wallet.type === "hd" || wallet.type === "xprv") {
|
||||||
html += `<button class="btn-add-address border border-border px-1 hover:bg-fg hover:text-bg cursor-pointer text-xs" data-wallet="${wi}" title="Add another address to this wallet">+</button>`;
|
html += `<button class="btn-add-address border border-border px-1 hover:bg-fg hover:text-bg cursor-pointer text-xs" data-wallet="${wi}" title="Add another address to this wallet">+</button>`;
|
||||||
}
|
}
|
||||||
html += `</div>`;
|
html += `</div>`;
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
const { $, showView, showFlash } = require("./helpers");
|
|
||||||
const { addressFromPrivateKey } = require("../../shared/wallet");
|
|
||||||
const { encryptWithPassword } = require("../../shared/vault");
|
|
||||||
const { state, saveState } = require("../../shared/state");
|
|
||||||
|
|
||||||
function show() {
|
|
||||||
$("import-private-key").value = "";
|
|
||||||
$("import-key-password").value = "";
|
|
||||||
$("import-key-password-confirm").value = "";
|
|
||||||
showView("import-key");
|
|
||||||
}
|
|
||||||
|
|
||||||
function init(ctx) {
|
|
||||||
$("btn-import-key-confirm").addEventListener("click", async () => {
|
|
||||||
const key = $("import-private-key").value.trim();
|
|
||||||
if (!key) {
|
|
||||||
showFlash("Please enter your private key.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let addr;
|
|
||||||
try {
|
|
||||||
addr = addressFromPrivateKey(key);
|
|
||||||
} catch (e) {
|
|
||||||
showFlash("Invalid private key.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const pw = $("import-key-password").value;
|
|
||||||
const pw2 = $("import-key-password-confirm").value;
|
|
||||||
if (!pw) {
|
|
||||||
showFlash("Please choose a password.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (pw.length < 12) {
|
|
||||||
showFlash("Password must be at least 12 characters.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (pw !== pw2) {
|
|
||||||
showFlash("Passwords do not match.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const encrypted = await encryptWithPassword(key, pw);
|
|
||||||
const walletNum = state.wallets.length + 1;
|
|
||||||
state.wallets.push({
|
|
||||||
type: "key",
|
|
||||||
name: "Wallet " + walletNum,
|
|
||||||
encryptedSecret: encrypted,
|
|
||||||
addresses: [
|
|
||||||
{ address: addr, balance: "0.0000", tokenBalances: [] },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
state.hasWallet = true;
|
|
||||||
await saveState();
|
|
||||||
ctx.renderWalletList();
|
|
||||||
showView("main");
|
|
||||||
|
|
||||||
ctx.doRefreshAndRender();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("btn-import-key-back").addEventListener("click", () => {
|
|
||||||
if (!state.hasWallet) {
|
|
||||||
showView("welcome");
|
|
||||||
} else {
|
|
||||||
ctx.renderWalletList();
|
|
||||||
showView("main");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { init, show };
|
|
||||||
@@ -2,6 +2,7 @@ const {
|
|||||||
$,
|
$,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
|
flashCopyFeedback,
|
||||||
formatAddressHtml,
|
formatAddressHtml,
|
||||||
addressTitle,
|
addressTitle,
|
||||||
} = require("./helpers");
|
} = require("./helpers");
|
||||||
@@ -52,19 +53,21 @@ function show() {
|
|||||||
"This is an ERC-20 token. Only send " +
|
"This is an ERC-20 token. Only send " +
|
||||||
symbol +
|
symbol +
|
||||||
" on the Ethereum network to this address. Sending tokens on other networks will result in permanent loss.";
|
" on the Ethereum network to this address. Sending tokens on other networks will result in permanent loss.";
|
||||||
warningEl.classList.remove("hidden");
|
warningEl.style.visibility = "visible";
|
||||||
} else {
|
} else {
|
||||||
warningEl.classList.add("hidden");
|
warningEl.textContent = "";
|
||||||
|
warningEl.style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
showView("receive");
|
showView("receive");
|
||||||
}
|
}
|
||||||
|
|
||||||
function init(ctx) {
|
function init(ctx) {
|
||||||
$("receive-address-block").addEventListener("click", () => {
|
$("receive-address-block").addEventListener("click", (e) => {
|
||||||
const addr = $("receive-address-block").dataset.full;
|
const addr = $("receive-address-block").dataset.full;
|
||||||
if (addr) {
|
if (addr) {
|
||||||
navigator.clipboard.writeText(addr);
|
navigator.clipboard.writeText(addr);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
|
flashCopyFeedback(e.currentTarget);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -73,6 +76,7 @@ function init(ctx) {
|
|||||||
if (addr) {
|
if (addr) {
|
||||||
navigator.clipboard.writeText(addr);
|
navigator.clipboard.writeText(addr);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
|
flashCopyFeedback($("receive-address-block"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const { $, showView, showFlash, escapeHtml } = require("./helpers");
|
const { $, showView, showFlash, escapeHtml } = require("./helpers");
|
||||||
|
const { applyTheme } = require("../theme");
|
||||||
const { state, saveState } = require("../../shared/state");
|
const { state, saveState } = require("../../shared/state");
|
||||||
const { ETHEREUM_MAINNET_CHAIN_ID } = require("../../shared/constants");
|
const { ETHEREUM_MAINNET_CHAIN_ID } = require("../../shared/constants");
|
||||||
const { log, debugFetch } = require("../../shared/log");
|
const { log, debugFetch } = require("../../shared/log");
|
||||||
@@ -214,6 +215,13 @@ function init(ctx) {
|
|||||||
await saveState();
|
await saveState();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("settings-theme").value = state.theme;
|
||||||
|
$("settings-theme").addEventListener("change", async () => {
|
||||||
|
state.theme = $("settings-theme").value;
|
||||||
|
await saveState();
|
||||||
|
applyTheme(state.theme);
|
||||||
|
});
|
||||||
|
|
||||||
$("settings-hide-low-holders").checked = state.hideLowHolderTokens;
|
$("settings-hide-low-holders").checked = state.hideLowHolderTokens;
|
||||||
$("settings-hide-low-holders").addEventListener("change", async () => {
|
$("settings-hide-low-holders").addEventListener("change", async () => {
|
||||||
state.hideLowHolderTokens = $("settings-hide-low-holders").checked;
|
state.hideLowHolderTokens = $("settings-hide-low-holders").checked;
|
||||||
@@ -241,6 +249,12 @@ function init(ctx) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("settings-utc-timestamps").checked = state.utcTimestamps;
|
||||||
|
$("settings-utc-timestamps").addEventListener("change", async () => {
|
||||||
|
state.utcTimestamps = $("settings-utc-timestamps").checked;
|
||||||
|
await saveState();
|
||||||
|
});
|
||||||
|
|
||||||
$("btn-main-add-wallet").addEventListener("click", ctx.showAddWalletView);
|
$("btn-main-add-wallet").addEventListener("click", ctx.showAddWalletView);
|
||||||
|
|
||||||
$("btn-settings-add-token").addEventListener(
|
$("btn-settings-add-token").addEventListener(
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ function renderDropdown() {
|
|||||||
|
|
||||||
function show() {
|
function show() {
|
||||||
$("settings-addtoken-address").value = "";
|
$("settings-addtoken-address").value = "";
|
||||||
$("settings-addtoken-info").classList.add("hidden");
|
$("settings-addtoken-info").textContent = "";
|
||||||
|
$("settings-addtoken-info").style.visibility = "hidden";
|
||||||
renderTop10();
|
renderTop10();
|
||||||
renderDropdown();
|
renderDropdown();
|
||||||
showView("settings-addtoken");
|
showView("settings-addtoken");
|
||||||
@@ -129,7 +130,7 @@ function init(_ctx) {
|
|||||||
}
|
}
|
||||||
const infoEl = $("settings-addtoken-info");
|
const infoEl = $("settings-addtoken-info");
|
||||||
infoEl.textContent = "Looking up token...";
|
infoEl.textContent = "Looking up token...";
|
||||||
infoEl.classList.remove("hidden");
|
infoEl.style.visibility = "visible";
|
||||||
log.debugf("Looking up token contract", addr);
|
log.debugf("Looking up token contract", addr);
|
||||||
try {
|
try {
|
||||||
const info = await lookupTokenInfo(addr, state.rpcUrl);
|
const info = await lookupTokenInfo(addr, state.rpcUrl);
|
||||||
@@ -143,7 +144,8 @@ function init(_ctx) {
|
|||||||
await saveState();
|
await saveState();
|
||||||
showFlash("Added " + info.symbol);
|
showFlash("Added " + info.symbol);
|
||||||
$("settings-addtoken-address").value = "";
|
$("settings-addtoken-address").value = "";
|
||||||
infoEl.classList.add("hidden");
|
infoEl.textContent = "";
|
||||||
|
infoEl.style.visibility = "hidden";
|
||||||
renderTop10();
|
renderTop10();
|
||||||
renderDropdown();
|
renderDropdown();
|
||||||
ctx.doRefreshAndRender();
|
ctx.doRefreshAndRender();
|
||||||
@@ -151,7 +153,8 @@ function init(_ctx) {
|
|||||||
const detail = e.shortMessage || e.message || String(e);
|
const detail = e.shortMessage || e.message || String(e);
|
||||||
log.errorf("Token lookup failed for", addr, detail);
|
log.errorf("Token lookup failed for", addr, detail);
|
||||||
showFlash(detail);
|
showFlash(detail);
|
||||||
infoEl.classList.add("hidden");
|
infoEl.textContent = "";
|
||||||
|
infoEl.style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const {
|
|||||||
$,
|
$,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
|
flashCopyFeedback,
|
||||||
addressDotHtml,
|
addressDotHtml,
|
||||||
addressTitle,
|
addressTitle,
|
||||||
escapeHtml,
|
escapeHtml,
|
||||||
@@ -158,8 +159,9 @@ function render() {
|
|||||||
loadCalldata(tx.hash, tx.to);
|
loadCalldata(tx.hash, tx.to);
|
||||||
}
|
}
|
||||||
|
|
||||||
$("tx-detail-time").textContent =
|
const isoStr = isoDate(tx.timestamp);
|
||||||
isoDate(tx.timestamp) + " (" + timeAgo(tx.timestamp) + ")";
|
$("tx-detail-time").innerHTML =
|
||||||
|
copyableHtml(isoStr) + " (" + escapeHtml(timeAgo(tx.timestamp)) + ")";
|
||||||
$("tx-detail-status").textContent = tx.isError ? "Failed" : "Success";
|
$("tx-detail-status").textContent = tx.isError ? "Failed" : "Success";
|
||||||
showView("transaction");
|
showView("transaction");
|
||||||
|
|
||||||
@@ -170,6 +172,7 @@ function render() {
|
|||||||
el.onclick = () => {
|
el.onclick = () => {
|
||||||
navigator.clipboard.writeText(el.dataset.copy);
|
navigator.clipboard.writeText(el.dataset.copy);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
|
flashCopyFeedback(el);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -247,6 +250,7 @@ async function loadCalldata(txHash, toAddress) {
|
|||||||
el.onclick = () => {
|
el.onclick = () => {
|
||||||
navigator.clipboard.writeText(el.dataset.copy);
|
navigator.clipboard.writeText(el.dataset.copy);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
|
flashCopyFeedback(el);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const {
|
|||||||
$,
|
$,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
|
flashCopyFeedback,
|
||||||
addressDotHtml,
|
addressDotHtml,
|
||||||
addressTitle,
|
addressTitle,
|
||||||
escapeHtml,
|
escapeHtml,
|
||||||
@@ -59,6 +60,16 @@ function txHashHtml(hash) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function blockNumberHtml(blockNumber) {
|
||||||
|
const num = String(blockNumber);
|
||||||
|
const link = `https://etherscan.io/block/${num}`;
|
||||||
|
const extLink = `<a href="${link}" target="_blank" rel="noopener" class="inline-flex items-center">${EXT_ICON}</a>`;
|
||||||
|
return (
|
||||||
|
`<span class="underline decoration-dashed cursor-pointer" data-copy="${escapeHtml(num)}">${escapeHtml(num)}</span>` +
|
||||||
|
extLink
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function attachCopyHandlers(viewId) {
|
function attachCopyHandlers(viewId) {
|
||||||
document
|
document
|
||||||
.getElementById(viewId)
|
.getElementById(viewId)
|
||||||
@@ -67,6 +78,7 @@ function attachCopyHandlers(viewId) {
|
|||||||
el.onclick = () => {
|
el.onclick = () => {
|
||||||
navigator.clipboard.writeText(el.dataset.copy);
|
navigator.clipboard.writeText(el.dataset.copy);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
|
flashCopyFeedback(el);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -189,7 +201,7 @@ function renderSuccess() {
|
|||||||
$("success-tx-to").innerHTML = toAddressHtml(d.to);
|
$("success-tx-to").innerHTML = toAddressHtml(d.to);
|
||||||
}
|
}
|
||||||
|
|
||||||
$("success-tx-block").textContent = String(d.blockNumber);
|
$("success-tx-block").innerHTML = blockNumberHtml(d.blockNumber);
|
||||||
$("success-tx-hash").innerHTML = txHashHtml(d.hash);
|
$("success-tx-hash").innerHTML = txHashHtml(d.hash);
|
||||||
|
|
||||||
// Show decoded calldata details if present
|
// Show decoded calldata details if present
|
||||||
|
|||||||
109
src/shared/addressWarnings.js
Normal file
109
src/shared/addressWarnings.js
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
// Address warning module.
|
||||||
|
// Provides local and async (RPC-based) warning checks for Ethereum addresses.
|
||||||
|
// Returns arrays of {type, message, severity} objects.
|
||||||
|
|
||||||
|
const { isScamAddress } = require("./scamlist");
|
||||||
|
const { isBurnAddress } = require("./constants");
|
||||||
|
const { checkEtherscanLabel } = require("./etherscanLabels");
|
||||||
|
const { log } = require("./log");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check an address against local-only lists (scam, burn, self-send).
|
||||||
|
* Synchronous — no network calls.
|
||||||
|
*
|
||||||
|
* @param {string} address - The target address to check.
|
||||||
|
* @param {object} [options] - Optional context.
|
||||||
|
* @param {string} [options.fromAddress] - Sender address (for self-send check).
|
||||||
|
* @returns {Array<{type: string, message: string, severity: string}>}
|
||||||
|
*/
|
||||||
|
function getLocalWarnings(address, options = {}) {
|
||||||
|
const warnings = [];
|
||||||
|
const addr = address.toLowerCase();
|
||||||
|
|
||||||
|
if (isScamAddress(addr)) {
|
||||||
|
warnings.push({
|
||||||
|
type: "scam",
|
||||||
|
message:
|
||||||
|
"This address is on a known scam/fraud list. Do not send funds to this address.",
|
||||||
|
severity: "critical",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isBurnAddress(addr)) {
|
||||||
|
warnings.push({
|
||||||
|
type: "burn",
|
||||||
|
message:
|
||||||
|
"This is a known null/burn address. Funds sent here are permanently destroyed and cannot be recovered.",
|
||||||
|
severity: "critical",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.fromAddress && addr === options.fromAddress.toLowerCase()) {
|
||||||
|
warnings.push({
|
||||||
|
type: "self-send",
|
||||||
|
message: "You are sending to your own address.",
|
||||||
|
severity: "warning",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return warnings;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check an address against local lists AND via RPC queries.
|
||||||
|
* Async — performs network calls to check contract status and tx history.
|
||||||
|
*
|
||||||
|
* @param {string} address - The target address to check.
|
||||||
|
* @param {object} provider - An ethers.js provider instance.
|
||||||
|
* @param {object} [options] - Optional context.
|
||||||
|
* @param {string} [options.fromAddress] - Sender address (for self-send check).
|
||||||
|
* @returns {Promise<Array<{type: string, message: string, severity: string}>>}
|
||||||
|
*/
|
||||||
|
async function getFullWarnings(address, provider, options = {}) {
|
||||||
|
const warnings = getLocalWarnings(address, options);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const code = await provider.getCode(address);
|
||||||
|
if (code && code !== "0x") {
|
||||||
|
warnings.push({
|
||||||
|
type: "contract",
|
||||||
|
message:
|
||||||
|
"This address is a smart contract, not a regular wallet.",
|
||||||
|
severity: "warning",
|
||||||
|
});
|
||||||
|
// If it's a contract, skip the tx count check — contracts
|
||||||
|
// may legitimately have zero inbound EOA transactions.
|
||||||
|
return warnings;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.errorf("contract check failed:", e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const txCount = await provider.getTransactionCount(address);
|
||||||
|
if (txCount === 0) {
|
||||||
|
warnings.push({
|
||||||
|
type: "new-address",
|
||||||
|
message:
|
||||||
|
"This address has never sent a transaction. Double-check it is correct.",
|
||||||
|
severity: "info",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.errorf("tx count check failed:", e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Etherscan label check (best-effort async — network failures are silent).
|
||||||
|
try {
|
||||||
|
const etherscanWarning = await checkEtherscanLabel(address);
|
||||||
|
if (etherscanWarning) {
|
||||||
|
warnings.push(etherscanWarning);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.errorf("etherscan label check failed:", e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return warnings;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { getLocalWarnings, getFullWarnings };
|
||||||
@@ -20,6 +20,19 @@ const ERC20_ABI = [
|
|||||||
"function approve(address spender, uint256 amount) returns (bool)",
|
"function approve(address spender, uint256 amount) returns (bool)",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Known null/burn addresses that permanently destroy funds.
|
||||||
|
const BURN_ADDRESSES = new Set([
|
||||||
|
"0x0000000000000000000000000000000000000000",
|
||||||
|
"0x0000000000000000000000000000000000000001",
|
||||||
|
"0x000000000000000000000000000000000000dead",
|
||||||
|
"0xdead000000000000000000000000000000000000",
|
||||||
|
"0x00000000000000000000000000000000deadbeef",
|
||||||
|
]);
|
||||||
|
|
||||||
|
function isBurnAddress(address) {
|
||||||
|
return BURN_ADDRESSES.has(address.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
DEBUG,
|
DEBUG,
|
||||||
DEBUG_MNEMONIC,
|
DEBUG_MNEMONIC,
|
||||||
@@ -28,4 +41,6 @@ module.exports = {
|
|||||||
DEFAULT_BLOCKSCOUT_URL,
|
DEFAULT_BLOCKSCOUT_URL,
|
||||||
BIP44_ETH_PATH,
|
BIP44_ETH_PATH,
|
||||||
ERC20_ABI,
|
ERC20_ABI,
|
||||||
|
BURN_ADDRESSES,
|
||||||
|
isBurnAddress,
|
||||||
};
|
};
|
||||||
|
|||||||
102
src/shared/etherscanLabels.js
Normal file
102
src/shared/etherscanLabels.js
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
// Etherscan address label lookup via page scraping.
|
||||||
|
// Extension users make the requests directly to Etherscan — no proxy needed.
|
||||||
|
// This is a best-effort enrichment: network failures return null silently.
|
||||||
|
|
||||||
|
const ETHERSCAN_BASE = "https://etherscan.io/address/";
|
||||||
|
|
||||||
|
// Patterns in the page title that indicate a flagged address.
|
||||||
|
// Title format: "Fake_Phishing184810 | Address: 0x... | Etherscan"
|
||||||
|
const PHISHING_LABEL_PATTERNS = [/^Fake_Phishing/i, /^Phish:/i, /^Exploiter/i];
|
||||||
|
|
||||||
|
// Patterns in the page body that indicate a scam/phishing warning.
|
||||||
|
const SCAM_BODY_PATTERNS = [
|
||||||
|
/used in a\s+(?:\w+\s+)?phishing scam/i,
|
||||||
|
/used in a\s+(?:\w+\s+)?scam/i,
|
||||||
|
/wallet\s+drainer/i,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the Etherscan address page HTML to extract label info.
|
||||||
|
* Exported for unit testing (no fetch needed).
|
||||||
|
*
|
||||||
|
* @param {string} html - Raw HTML of the Etherscan address page.
|
||||||
|
* @returns {{ label: string|null, isPhishing: boolean, warning: string|null }}
|
||||||
|
*/
|
||||||
|
function parseEtherscanPage(html) {
|
||||||
|
// Extract <title> content
|
||||||
|
const titleMatch = html.match(/<title[^>]*>([^<]+)<\/title>/i);
|
||||||
|
let label = null;
|
||||||
|
let isPhishing = false;
|
||||||
|
let warning = null;
|
||||||
|
|
||||||
|
if (titleMatch) {
|
||||||
|
const title = titleMatch[1].trim();
|
||||||
|
// Title: "LABEL | Address: 0x... | Etherscan" or "Address: 0x... | Etherscan"
|
||||||
|
const labelMatch = title.match(/^(.+?)\s*\|\s*Address:/);
|
||||||
|
if (labelMatch) {
|
||||||
|
const candidate = labelMatch[1].trim();
|
||||||
|
// Only treat as a label if it's not just "Address" (unlabeled addresses)
|
||||||
|
if (candidate.toLowerCase() !== "address") {
|
||||||
|
label = candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check label against phishing patterns
|
||||||
|
if (label) {
|
||||||
|
for (const pat of PHISHING_LABEL_PATTERNS) {
|
||||||
|
if (pat.test(label)) {
|
||||||
|
isPhishing = true;
|
||||||
|
warning = `Etherscan labels this address as "${label}" (Phish/Hack).`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check page body for scam warning banners
|
||||||
|
if (!isPhishing) {
|
||||||
|
for (const pat of SCAM_BODY_PATTERNS) {
|
||||||
|
if (pat.test(html)) {
|
||||||
|
isPhishing = true;
|
||||||
|
warning = label
|
||||||
|
? `Etherscan labels this address as "${label}" and reports it was used in a scam.`
|
||||||
|
: "Etherscan reports this address was flagged for phishing/scam activity.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { label, isPhishing, warning };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch an address page from Etherscan and check for scam/phishing labels.
|
||||||
|
* Returns a warning object if the address is flagged, or null.
|
||||||
|
* Network failures return null silently (best-effort check).
|
||||||
|
*
|
||||||
|
* @param {string} address - Ethereum address to check.
|
||||||
|
* @returns {Promise<{type: string, message: string, severity: string}|null>}
|
||||||
|
*/
|
||||||
|
async function checkEtherscanLabel(address) {
|
||||||
|
try {
|
||||||
|
const resp = await fetch(ETHERSCAN_BASE + address, {
|
||||||
|
headers: { Accept: "text/html" },
|
||||||
|
});
|
||||||
|
if (!resp.ok) return null;
|
||||||
|
const html = await resp.text();
|
||||||
|
const result = parseEtherscanPage(html);
|
||||||
|
if (result.isPhishing) {
|
||||||
|
return {
|
||||||
|
type: "etherscan-phishing",
|
||||||
|
message: result.warning,
|
||||||
|
severity: "critical",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch {
|
||||||
|
// Network errors are expected — Etherscan may rate-limit or block.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { parseEtherscanPage, checkEtherscanLabel };
|
||||||
133
src/shared/phishingDomains.js
Normal file
133
src/shared/phishingDomains.js
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
// Domain-based phishing detection using MetaMask's eth-phishing-detect blocklist.
|
||||||
|
// Fetches the blocklist at runtime, caches it in memory, and checks hostnames.
|
||||||
|
//
|
||||||
|
// The blocklist source:
|
||||||
|
// https://github.com/MetaMask/eth-phishing-detect (src/config.json)
|
||||||
|
//
|
||||||
|
// The config uses { blacklist: [...], whitelist: [...], fuzzylist: [...] }.
|
||||||
|
// We check exact hostname and parent-domain matches against the blacklist,
|
||||||
|
// with whitelist overrides.
|
||||||
|
|
||||||
|
const BLOCKLIST_URL =
|
||||||
|
"https://raw.githubusercontent.com/MetaMask/eth-phishing-detect/main/src/config.json";
|
||||||
|
|
||||||
|
const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
||||||
|
|
||||||
|
let blacklistSet = new Set();
|
||||||
|
let whitelistSet = new Set();
|
||||||
|
let lastFetchTime = 0;
|
||||||
|
let fetchPromise = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a pre-parsed config into the in-memory sets.
|
||||||
|
* Used for testing and for loading from cache.
|
||||||
|
*
|
||||||
|
* @param {{ blacklist?: string[], whitelist?: string[] }} config
|
||||||
|
*/
|
||||||
|
function loadConfig(config) {
|
||||||
|
blacklistSet = new Set(
|
||||||
|
(config.blacklist || []).map((d) => d.toLowerCase()),
|
||||||
|
);
|
||||||
|
whitelistSet = new Set(
|
||||||
|
(config.whitelist || []).map((d) => d.toLowerCase()),
|
||||||
|
);
|
||||||
|
lastFetchTime = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate hostname variants for subdomain matching.
|
||||||
|
* "sub.evil.com" yields ["sub.evil.com", "evil.com"].
|
||||||
|
*
|
||||||
|
* @param {string} hostname
|
||||||
|
* @returns {string[]}
|
||||||
|
*/
|
||||||
|
function hostnameVariants(hostname) {
|
||||||
|
const h = hostname.toLowerCase();
|
||||||
|
const variants = [h];
|
||||||
|
const parts = h.split(".");
|
||||||
|
// Parent domains: a.b.c.d -> b.c.d, c.d
|
||||||
|
for (let i = 1; i < parts.length - 1; i++) {
|
||||||
|
variants.push(parts.slice(i).join("."));
|
||||||
|
}
|
||||||
|
return variants;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a hostname is on the phishing blocklist.
|
||||||
|
* Checks exact hostname and all parent domains.
|
||||||
|
* Whitelisted domains are never flagged.
|
||||||
|
*
|
||||||
|
* @param {string} hostname - The hostname to check.
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function isPhishingDomain(hostname) {
|
||||||
|
if (!hostname) return false;
|
||||||
|
const variants = hostnameVariants(hostname);
|
||||||
|
// Whitelist takes priority
|
||||||
|
for (const v of variants) {
|
||||||
|
if (whitelistSet.has(v)) return false;
|
||||||
|
}
|
||||||
|
for (const v of variants) {
|
||||||
|
if (blacklistSet.has(v)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the latest blocklist from the MetaMask repo.
|
||||||
|
* De-duplicates concurrent fetches. Results are cached for CACHE_TTL_MS.
|
||||||
|
*
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async function updatePhishingList() {
|
||||||
|
// Skip if recently fetched
|
||||||
|
if (Date.now() - lastFetchTime < CACHE_TTL_MS && blacklistSet.size > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-duplicate concurrent calls
|
||||||
|
if (fetchPromise) return fetchPromise;
|
||||||
|
|
||||||
|
fetchPromise = (async () => {
|
||||||
|
try {
|
||||||
|
const resp = await fetch(BLOCKLIST_URL);
|
||||||
|
if (!resp.ok) throw new Error("HTTP " + resp.status);
|
||||||
|
const config = await resp.json();
|
||||||
|
loadConfig(config);
|
||||||
|
} catch {
|
||||||
|
// Silently fail — we'll retry next time.
|
||||||
|
} finally {
|
||||||
|
fetchPromise = null;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
return fetchPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current blocklist size (for diagnostics).
|
||||||
|
*
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
function getBlocklistSize() {
|
||||||
|
return blacklistSet.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset internal state (for testing).
|
||||||
|
*/
|
||||||
|
function _reset() {
|
||||||
|
blacklistSet = new Set();
|
||||||
|
whitelistSet = new Set();
|
||||||
|
lastFetchTime = 0;
|
||||||
|
fetchPromise = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
isPhishingDomain,
|
||||||
|
updatePhishingList,
|
||||||
|
loadConfig,
|
||||||
|
getBlocklistSize,
|
||||||
|
hostnameVariants,
|
||||||
|
_reset,
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -23,8 +23,10 @@ const DEFAULT_STATE = {
|
|||||||
hideFraudContracts: true,
|
hideFraudContracts: true,
|
||||||
hideDustTransactions: true,
|
hideDustTransactions: true,
|
||||||
dustThresholdGwei: 100000,
|
dustThresholdGwei: 100000,
|
||||||
|
utcTimestamps: false,
|
||||||
fraudContracts: [],
|
fraudContracts: [],
|
||||||
tokenHolderCache: {},
|
tokenHolderCache: {},
|
||||||
|
theme: "system",
|
||||||
};
|
};
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
@@ -53,8 +55,10 @@ async function saveState() {
|
|||||||
hideFraudContracts: state.hideFraudContracts,
|
hideFraudContracts: state.hideFraudContracts,
|
||||||
hideDustTransactions: state.hideDustTransactions,
|
hideDustTransactions: state.hideDustTransactions,
|
||||||
dustThresholdGwei: state.dustThresholdGwei,
|
dustThresholdGwei: state.dustThresholdGwei,
|
||||||
|
utcTimestamps: state.utcTimestamps,
|
||||||
fraudContracts: state.fraudContracts,
|
fraudContracts: state.fraudContracts,
|
||||||
tokenHolderCache: state.tokenHolderCache,
|
tokenHolderCache: state.tokenHolderCache,
|
||||||
|
theme: state.theme,
|
||||||
currentView: state.currentView,
|
currentView: state.currentView,
|
||||||
selectedWallet: state.selectedWallet,
|
selectedWallet: state.selectedWallet,
|
||||||
selectedAddress: state.selectedAddress,
|
selectedAddress: state.selectedAddress,
|
||||||
@@ -108,8 +112,11 @@ async function loadState() {
|
|||||||
saved.dustThresholdGwei !== undefined
|
saved.dustThresholdGwei !== undefined
|
||||||
? saved.dustThresholdGwei
|
? saved.dustThresholdGwei
|
||||||
: 100000;
|
: 100000;
|
||||||
|
state.utcTimestamps =
|
||||||
|
saved.utcTimestamps !== undefined ? saved.utcTimestamps : false;
|
||||||
state.fraudContracts = saved.fraudContracts || [];
|
state.fraudContracts = saved.fraudContracts || [];
|
||||||
state.tokenHolderCache = saved.tokenHolderCache || {};
|
state.tokenHolderCache = saved.tokenHolderCache || {};
|
||||||
|
state.theme = saved.theme || "system";
|
||||||
state.currentView = saved.currentView || null;
|
state.currentView = saved.currentView || null;
|
||||||
state.selectedWallet =
|
state.selectedWallet =
|
||||||
saved.selectedWallet !== undefined ? saved.selectedWallet : null;
|
saved.selectedWallet !== undefined ? saved.selectedWallet : null;
|
||||||
|
|||||||
@@ -251,40 +251,4 @@ function filterTransactions(txs, filters = {}) {
|
|||||||
return { transactions: filtered, newFraudContracts: newFraud };
|
return { transactions: filtered, newFraudContracts: newFraud };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
module.exports = { fetchRecentTransactions, filterTransactions };
|
||||||
* Check whether an address has any on-chain transaction history.
|
|
||||||
* Returns true if the address has zero normal transactions AND zero
|
|
||||||
* token transfers on the configured Blockscout instance.
|
|
||||||
* Returns false on network errors (fail-open: don't block sends).
|
|
||||||
*/
|
|
||||||
async function hasZeroTransactionHistory(address, blockscoutUrl) {
|
|
||||||
try {
|
|
||||||
const resp = await debugFetch(
|
|
||||||
blockscoutUrl + "/addresses/" + address + "/transactions?limit=1",
|
|
||||||
);
|
|
||||||
if (!resp.ok) return false;
|
|
||||||
const json = await resp.json();
|
|
||||||
if ((json.items || []).length > 0) return false;
|
|
||||||
|
|
||||||
// Also check token transfers — an address may have only received
|
|
||||||
// ERC-20 tokens without any native ETH transactions.
|
|
||||||
const ttResp = await debugFetch(
|
|
||||||
blockscoutUrl +
|
|
||||||
"/addresses/" +
|
|
||||||
address +
|
|
||||||
"/token-transfers?type=ERC-20&limit=1",
|
|
||||||
);
|
|
||||||
if (!ttResp.ok) return false;
|
|
||||||
const ttJson = await ttResp.json();
|
|
||||||
return (ttJson.items || []).length === 0;
|
|
||||||
} catch (e) {
|
|
||||||
log.errorf("hasZeroTransactionHistory check failed:", e.message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
fetchRecentTransactions,
|
|
||||||
filterTransactions,
|
|
||||||
hasZeroTransactionHistory,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -24,6 +24,26 @@ function hdWalletFromMnemonic(mnemonic) {
|
|||||||
return { xpub, firstAddress };
|
return { xpub, firstAddress };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hdWalletFromXprv(xprv) {
|
||||||
|
const root = HDNodeWallet.fromExtendedKey(xprv);
|
||||||
|
if (!root.privateKey) {
|
||||||
|
throw new Error("Not an extended private key (xprv).");
|
||||||
|
}
|
||||||
|
const node = root.derivePath("44'/60'/0'/0");
|
||||||
|
const xpub = node.neuter().extendedKey;
|
||||||
|
const firstAddress = node.deriveChild(0).address;
|
||||||
|
return { xpub, firstAddress };
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidXprv(key) {
|
||||||
|
try {
|
||||||
|
const node = HDNodeWallet.fromExtendedKey(key);
|
||||||
|
return !!node.privateKey;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function addressFromPrivateKey(key) {
|
function addressFromPrivateKey(key) {
|
||||||
const w = new Wallet(key);
|
const w = new Wallet(key);
|
||||||
return w.address;
|
return w.address;
|
||||||
@@ -38,6 +58,11 @@ function getSignerForAddress(walletData, addrIndex, decryptedSecret) {
|
|||||||
);
|
);
|
||||||
return node.deriveChild(addrIndex);
|
return node.deriveChild(addrIndex);
|
||||||
}
|
}
|
||||||
|
if (walletData.type === "xprv") {
|
||||||
|
const root = HDNodeWallet.fromExtendedKey(decryptedSecret);
|
||||||
|
const node = root.derivePath("44'/60'/0'/0");
|
||||||
|
return node.deriveChild(addrIndex);
|
||||||
|
}
|
||||||
return new Wallet(decryptedSecret);
|
return new Wallet(decryptedSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +74,8 @@ module.exports = {
|
|||||||
generateMnemonic,
|
generateMnemonic,
|
||||||
deriveAddressFromXpub,
|
deriveAddressFromXpub,
|
||||||
hdWalletFromMnemonic,
|
hdWalletFromMnemonic,
|
||||||
|
hdWalletFromXprv,
|
||||||
|
isValidXprv,
|
||||||
addressFromPrivateKey,
|
addressFromPrivateKey,
|
||||||
getSignerForAddress,
|
getSignerForAddress,
|
||||||
isValidMnemonic,
|
isValidMnemonic,
|
||||||
|
|||||||
100
tests/etherscanLabels.test.js
Normal file
100
tests/etherscanLabels.test.js
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
const { parseEtherscanPage } = require("../src/shared/etherscanLabels");
|
||||||
|
|
||||||
|
describe("etherscanLabels", () => {
|
||||||
|
describe("parseEtherscanPage", () => {
|
||||||
|
test("detects Fake_Phishing label in title", () => {
|
||||||
|
const html = `<html><head><title>Fake_Phishing184810 | Address: 0x00000c07...3ea470000 | Etherscan</title></head><body></body></html>`;
|
||||||
|
const result = parseEtherscanPage(html);
|
||||||
|
expect(result.label).toBe("Fake_Phishing184810");
|
||||||
|
expect(result.isPhishing).toBe(true);
|
||||||
|
expect(result.warning).toContain("Fake_Phishing184810");
|
||||||
|
expect(result.warning).toContain("Phish/Hack");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("detects Fake_Phishing with different number", () => {
|
||||||
|
const html = `<html><head><title>Fake_Phishing5169 | Address: 0x3e0defb8...99a7a8a74 | Etherscan</title></head><body></body></html>`;
|
||||||
|
const result = parseEtherscanPage(html);
|
||||||
|
expect(result.label).toBe("Fake_Phishing5169");
|
||||||
|
expect(result.isPhishing).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("detects Exploiter label", () => {
|
||||||
|
const html = `<html><head><title>Exploiter 42 | Address: 0xabcdef...1234 | Etherscan</title></head><body></body></html>`;
|
||||||
|
const result = parseEtherscanPage(html);
|
||||||
|
expect(result.label).toBe("Exploiter 42");
|
||||||
|
expect(result.isPhishing).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("detects scam warning in body text", () => {
|
||||||
|
const html =
|
||||||
|
`<html><head><title>Address: 0xabcdef...1234 | Etherscan</title></head>` +
|
||||||
|
`<body>There are reports that this address was used in a Phishing scam.</body></html>`;
|
||||||
|
const result = parseEtherscanPage(html);
|
||||||
|
expect(result.label).toBeNull();
|
||||||
|
expect(result.isPhishing).toBe(true);
|
||||||
|
expect(result.warning).toContain("phishing/scam");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("detects scam warning with label in body", () => {
|
||||||
|
const html =
|
||||||
|
`<html><head><title>SomeScammer | Address: 0xabcdef...1234 | Etherscan</title></head>` +
|
||||||
|
`<body>There are reports that this address was used in a scam.</body></html>`;
|
||||||
|
const result = parseEtherscanPage(html);
|
||||||
|
expect(result.label).toBe("SomeScammer");
|
||||||
|
expect(result.isPhishing).toBe(true);
|
||||||
|
expect(result.warning).toContain("SomeScammer");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns clean result for legitimate address", () => {
|
||||||
|
const html = `<html><head><title>vitalik.eth | Address: 0xd8dA6BF2...37aA96045 | Etherscan</title></head><body>Overview</body></html>`;
|
||||||
|
const result = parseEtherscanPage(html);
|
||||||
|
expect(result.label).toBe("vitalik.eth");
|
||||||
|
expect(result.isPhishing).toBe(false);
|
||||||
|
expect(result.warning).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns clean result for unlabeled address", () => {
|
||||||
|
const html = `<html><head><title>Address: 0x1234567890...abcdef | Etherscan</title></head><body>Overview</body></html>`;
|
||||||
|
const result = parseEtherscanPage(html);
|
||||||
|
expect(result.label).toBeNull();
|
||||||
|
expect(result.isPhishing).toBe(false);
|
||||||
|
expect(result.warning).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("handles exchange labels correctly (not phishing)", () => {
|
||||||
|
const html = `<html><head><title>Coinbase 10 | Address: 0xa9d1e08c...b81d3e43 | Etherscan</title></head><body>Overview</body></html>`;
|
||||||
|
const result = parseEtherscanPage(html);
|
||||||
|
expect(result.label).toBe("Coinbase 10");
|
||||||
|
expect(result.isPhishing).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("handles contract names correctly (not phishing)", () => {
|
||||||
|
const html = `<html><head><title>Beacon Deposit Contract | Address: 0x00000000...03d7705Fa | Etherscan</title></head><body>Overview</body></html>`;
|
||||||
|
const result = parseEtherscanPage(html);
|
||||||
|
expect(result.label).toBe("Beacon Deposit Contract");
|
||||||
|
expect(result.isPhishing).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("handles empty HTML gracefully", () => {
|
||||||
|
const result = parseEtherscanPage("");
|
||||||
|
expect(result.label).toBeNull();
|
||||||
|
expect(result.isPhishing).toBe(false);
|
||||||
|
expect(result.warning).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("handles malformed title tag", () => {
|
||||||
|
const html = `<html><head><title></title></head><body></body></html>`;
|
||||||
|
const result = parseEtherscanPage(html);
|
||||||
|
expect(result.label).toBeNull();
|
||||||
|
expect(result.isPhishing).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("detects wallet drainer warning", () => {
|
||||||
|
const html =
|
||||||
|
`<html><head><title>Address: 0xabc...def | Etherscan</title></head>` +
|
||||||
|
`<body>This is a known wallet drainer contract.</body></html>`;
|
||||||
|
const result = parseEtherscanPage(html);
|
||||||
|
expect(result.isPhishing).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
166
tests/phishingDomains.test.js
Normal file
166
tests/phishingDomains.test.js
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
const {
|
||||||
|
isPhishingDomain,
|
||||||
|
loadConfig,
|
||||||
|
getBlocklistSize,
|
||||||
|
hostnameVariants,
|
||||||
|
_reset,
|
||||||
|
} = require("../src/shared/phishingDomains");
|
||||||
|
|
||||||
|
// Reset state before each test to avoid cross-test contamination.
|
||||||
|
beforeEach(() => {
|
||||||
|
_reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("phishingDomains", () => {
|
||||||
|
describe("hostnameVariants", () => {
|
||||||
|
test("returns exact hostname plus parent domains", () => {
|
||||||
|
const variants = hostnameVariants("sub.evil.com");
|
||||||
|
expect(variants).toEqual(["sub.evil.com", "evil.com"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns just the hostname for a bare domain", () => {
|
||||||
|
const variants = hostnameVariants("example.com");
|
||||||
|
expect(variants).toEqual(["example.com"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("handles deep subdomain chains", () => {
|
||||||
|
const variants = hostnameVariants("a.b.c.d.com");
|
||||||
|
expect(variants).toEqual([
|
||||||
|
"a.b.c.d.com",
|
||||||
|
"b.c.d.com",
|
||||||
|
"c.d.com",
|
||||||
|
"d.com",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("lowercases hostnames", () => {
|
||||||
|
const variants = hostnameVariants("Evil.COM");
|
||||||
|
expect(variants).toEqual(["evil.com"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("loadConfig + isPhishingDomain", () => {
|
||||||
|
test("detects exact blacklisted domain", () => {
|
||||||
|
loadConfig({
|
||||||
|
blacklist: ["evil-phishing.com", "scam-swap.xyz"],
|
||||||
|
whitelist: [],
|
||||||
|
});
|
||||||
|
expect(isPhishingDomain("evil-phishing.com")).toBe(true);
|
||||||
|
expect(isPhishingDomain("scam-swap.xyz")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns false for clean domains", () => {
|
||||||
|
loadConfig({
|
||||||
|
blacklist: ["evil-phishing.com"],
|
||||||
|
whitelist: [],
|
||||||
|
});
|
||||||
|
expect(isPhishingDomain("etherscan.io")).toBe(false);
|
||||||
|
expect(isPhishingDomain("uniswap.org")).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("detects subdomain of blacklisted domain", () => {
|
||||||
|
loadConfig({
|
||||||
|
blacklist: ["evil-phishing.com"],
|
||||||
|
whitelist: [],
|
||||||
|
});
|
||||||
|
expect(isPhishingDomain("app.evil-phishing.com")).toBe(true);
|
||||||
|
expect(isPhishingDomain("sub.app.evil-phishing.com")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("whitelist overrides blacklist", () => {
|
||||||
|
loadConfig({
|
||||||
|
blacklist: ["metamask.io"],
|
||||||
|
whitelist: ["metamask.io"],
|
||||||
|
});
|
||||||
|
expect(isPhishingDomain("metamask.io")).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("whitelist on parent domain overrides blacklist", () => {
|
||||||
|
loadConfig({
|
||||||
|
blacklist: ["sub.legit.com"],
|
||||||
|
whitelist: ["legit.com"],
|
||||||
|
});
|
||||||
|
expect(isPhishingDomain("sub.legit.com")).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("case-insensitive matching", () => {
|
||||||
|
loadConfig({
|
||||||
|
blacklist: ["Evil-Phishing.COM"],
|
||||||
|
whitelist: [],
|
||||||
|
});
|
||||||
|
expect(isPhishingDomain("evil-phishing.com")).toBe(true);
|
||||||
|
expect(isPhishingDomain("EVIL-PHISHING.COM")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns false for empty/null hostname", () => {
|
||||||
|
loadConfig({
|
||||||
|
blacklist: ["evil.com"],
|
||||||
|
whitelist: [],
|
||||||
|
});
|
||||||
|
expect(isPhishingDomain("")).toBe(false);
|
||||||
|
expect(isPhishingDomain(null)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getBlocklistSize reflects loaded config", () => {
|
||||||
|
loadConfig({
|
||||||
|
blacklist: ["a.com", "b.com", "c.com"],
|
||||||
|
whitelist: ["d.com"],
|
||||||
|
});
|
||||||
|
expect(getBlocklistSize()).toBe(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("handles config with no blacklist/whitelist keys", () => {
|
||||||
|
loadConfig({});
|
||||||
|
expect(isPhishingDomain("anything.com")).toBe(false);
|
||||||
|
expect(getBlocklistSize()).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("re-loading config replaces previous data", () => {
|
||||||
|
loadConfig({
|
||||||
|
blacklist: ["old-scam.com"],
|
||||||
|
whitelist: [],
|
||||||
|
});
|
||||||
|
expect(isPhishingDomain("old-scam.com")).toBe(true);
|
||||||
|
|
||||||
|
loadConfig({
|
||||||
|
blacklist: ["new-scam.com"],
|
||||||
|
whitelist: [],
|
||||||
|
});
|
||||||
|
expect(isPhishingDomain("old-scam.com")).toBe(false);
|
||||||
|
expect(isPhishingDomain("new-scam.com")).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("real-world MetaMask blocklist patterns", () => {
|
||||||
|
test("detects known phishing domains from MetaMask list", () => {
|
||||||
|
loadConfig({
|
||||||
|
blacklist: [
|
||||||
|
"uniswap-trade.web.app",
|
||||||
|
"hopprotocol.pro",
|
||||||
|
"blast-pools.pages.dev",
|
||||||
|
],
|
||||||
|
whitelist: [],
|
||||||
|
});
|
||||||
|
expect(isPhishingDomain("uniswap-trade.web.app")).toBe(true);
|
||||||
|
expect(isPhishingDomain("hopprotocol.pro")).toBe(true);
|
||||||
|
expect(isPhishingDomain("blast-pools.pages.dev")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("does not flag legitimate domains whitelisted by MetaMask", () => {
|
||||||
|
loadConfig({
|
||||||
|
blacklist: ["opensea.pro"],
|
||||||
|
whitelist: [
|
||||||
|
"opensea.io",
|
||||||
|
"metamask.io",
|
||||||
|
"etherscan.io",
|
||||||
|
"opensea.pro",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
expect(isPhishingDomain("opensea.io")).toBe(false);
|
||||||
|
expect(isPhishingDomain("metamask.io")).toBe(false);
|
||||||
|
expect(isPhishingDomain("etherscan.io")).toBe(false);
|
||||||
|
// opensea.pro is both blacklisted and whitelisted — whitelist wins
|
||||||
|
expect(isPhishingDomain("opensea.pro")).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user