Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4fd55f0f38 |
@@ -239,12 +239,8 @@ provide:
|
|||||||
`make check` stays non-mutating. Linting runs only in the container, because
|
`make check` stays non-mutating. Linting runs only in the container, because
|
||||||
an ESLint result that depends on whichever ESLint the host happens to have is
|
an ESLint result that depends on whichever ESLint the host happens to have is
|
||||||
not a result, so docker is required to lint.
|
not a result, so docker is required to lint.
|
||||||
- `script/fmt` — format all files (writes), on the host, with the `prettier`
|
- `script/fmt` — format all files (writes), on the host
|
||||||
that `script/bootstrap` installs in `node_modules/`; when that one is missing
|
- `script/fmt-check` — check formatting (read-only), on the host
|
||||||
it fails and says to run `script/bootstrap`, instead of using a `prettier`
|
|
||||||
from the `PATH`
|
|
||||||
- `script/fmt-check` — check formatting (read-only), on the host, with the same
|
|
||||||
`prettier` and the same refusal
|
|
||||||
- `script/check` — run `script/test`, `script/lint` and `script/fmt-check`
|
- `script/check` — run `script/test`, `script/lint` and `script/fmt-check`
|
||||||
- `script/check-censored` — assert the competitor name RULES.md bars appears
|
- `script/check-censored` — assert the competitor name RULES.md bars appears
|
||||||
nowhere in the working tree or under `dist/` outside its documented
|
nowhere in the working tree or under `dist/` outside its documented
|
||||||
@@ -2169,13 +2165,6 @@ view would leave a wallet one click from deletion.
|
|||||||
- Typed data that states no primary type, or one other than the type it
|
- Typed data that states no primary type, or one other than the type it
|
||||||
would be signed as, or that cannot be read → shown with the error line
|
would be signed as, or that cannot be read → shown with the error line
|
||||||
saying so and "Sign" disabled; only "Reject" remains
|
saying so and "Sign" disabled; only "Reject" remains
|
||||||
- Typed data whose domain `chainId` names a chain other than the active
|
|
||||||
network's → shown with the error line naming both chain ids and "Sign"
|
|
||||||
disabled; only "Reject" remains. EIP-712 asks for this, because the
|
|
||||||
signature is valid on the chain the domain names. Typed data with no
|
|
||||||
`chainId` is not refused. The background refuses such a signature too,
|
|
||||||
against the network active when the signature reaches it, and answers the
|
|
||||||
site with the same sentence
|
|
||||||
- A `personal_sign` or `eth_sign` message that is not hex (`0x` or `0X` and
|
- A `personal_sign` or `eth_sign` message that is not hex (`0x` or `0X` and
|
||||||
an even number of hex digits, the form ethers' `getBytes` reads when
|
an even number of hex digits, the form ethers' `getBytes` reads when
|
||||||
signing) → shown as plain text, with the error line "This message is plain
|
signing) → shown as plain text, with the error line "This message is plain
|
||||||
@@ -2668,8 +2657,7 @@ plaintext list of anyone's domain names.
|
|||||||
When a dApp on a blocklisted domain requests a wallet connection, transaction
|
When a dApp on a blocklisted domain requests a wallet connection, transaction
|
||||||
approval, or signature, the approval popup displays a prominent red warning
|
approval, or signature, the approval popup displays a prominent red warning
|
||||||
banner alerting the user. The domain checker matches exact hostnames and all
|
banner alerting the user. The domain checker matches exact hostnames and all
|
||||||
parent domains (subdomain matching), and checks a hostname written with a
|
parent domains (subdomain matching).
|
||||||
trailing dot (`name.`) as `name`.
|
|
||||||
|
|
||||||
#### Transaction Decoding
|
#### Transaction Decoding
|
||||||
|
|
||||||
|
|||||||
@@ -25,13 +25,6 @@ run_yarn() {
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
# Without the repo's own prettier, yarn runs whatever prettier is on
|
|
||||||
# the PATH, which may be a version that formats files differently.
|
|
||||||
if [ ! -x node_modules/.bin/prettier ]; then
|
|
||||||
echo "fmt: this repo's prettier is not installed in node_modules/," \
|
|
||||||
"so run script/bootstrap first." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "Formatting..."
|
echo "Formatting..."
|
||||||
run_yarn run fmt
|
run_yarn run fmt
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,13 +26,6 @@ run_yarn() {
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
# Without the repo's own prettier, yarn runs whatever prettier is on
|
|
||||||
# the PATH, which may be a version that formats files differently.
|
|
||||||
if [ ! -x node_modules/.bin/prettier ]; then
|
|
||||||
echo "fmt-check: this repo's prettier is not installed in" \
|
|
||||||
"node_modules/, so run script/bootstrap first." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "Checking formatting..."
|
echo "Checking formatting..."
|
||||||
run_yarn run fmt-check
|
run_yarn run fmt-check
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-23
@@ -22,7 +22,6 @@ const { debugFetch, log } = require("../shared/log");
|
|||||||
const {
|
const {
|
||||||
verifySignedTx,
|
verifySignedTx,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
typedDataChainRefusal,
|
|
||||||
failureIsRetryable,
|
failureIsRetryable,
|
||||||
describeTxFailure,
|
describeTxFailure,
|
||||||
sameAddress,
|
sameAddress,
|
||||||
@@ -633,9 +632,8 @@ function isExtensionSender(sender) {
|
|||||||
// had refused.
|
// had refused.
|
||||||
//
|
//
|
||||||
// TX and sign approvals do not decide here. They stay pending across a
|
// TX and sign approvals do not decide here. They stay pending across a
|
||||||
// disconnect. When their window closes, the windows.onRemoved listener below
|
// disconnect — the user can reopen the toolbar popup — and are rejected by the
|
||||||
// rejects them, unless an approved attempt is still running, in which case
|
// windows.onRemoved listener below.
|
||||||
// that attempt answers the page.
|
|
||||||
runtime.onConnect.addListener((port) => {
|
runtime.onConnect.addListener((port) => {
|
||||||
if (port.name.startsWith("approval:")) {
|
if (port.name.startsWith("approval:")) {
|
||||||
const id = port.name.split(":")[1];
|
const id = port.name.split(":")[1];
|
||||||
@@ -663,9 +661,7 @@ runtime.onConnect.addListener((port) => {
|
|||||||
const approval = pendingApprovals[id];
|
const approval = pendingApprovals[id];
|
||||||
if (approval) {
|
if (approval) {
|
||||||
if (approval.type === "tx" || approval.type === "sign") {
|
if (approval.type === "tx" || approval.type === "sign") {
|
||||||
// When its window closes, windows.onRemoved rejects it,
|
// Keep pending — user can reopen the toolbar popup
|
||||||
// unless an approved attempt is still running, in which
|
|
||||||
// case that attempt answers the page.
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
settleApproval(id, { approved: false, remember: false });
|
settleApproval(id, { approved: false, remember: false });
|
||||||
@@ -1767,8 +1763,7 @@ runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
|||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const s = await getState();
|
const activeAddress = await getActiveAddress();
|
||||||
const activeAddress = activeAddressOf(s);
|
|
||||||
// Same as the transaction path: the address the approval named
|
// Same as the transaction path: the address the approval named
|
||||||
// is the one that must have signed, and a switch since then is
|
// is the one that must have signed, and a switch since then is
|
||||||
// a refusal rather than a signature from another account.
|
// a refusal rather than a signature from another account.
|
||||||
@@ -1787,20 +1782,6 @@ runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
|||||||
signature,
|
signature,
|
||||||
approval.approvedFrom,
|
approval.approvedFrom,
|
||||||
);
|
);
|
||||||
// The sign screen refuses typed data whose domain names
|
|
||||||
// another chain. A signature for it that arrives anyway is
|
|
||||||
// refused here, against the network active now.
|
|
||||||
const sp = approval.signParams;
|
|
||||||
if (
|
|
||||||
sp.method === "eth_signTypedData_v4" ||
|
|
||||||
sp.method === "eth_signTypedData"
|
|
||||||
) {
|
|
||||||
const refusal = typedDataChainRefusal(
|
|
||||||
JSON.parse(sp.typedData).domain,
|
|
||||||
networkById(s.networkId),
|
|
||||||
);
|
|
||||||
if (refusal) throw new ApprovalMismatchError(refusal);
|
|
||||||
}
|
|
||||||
settleApproval(msg.id, { signature }, { holdsClaim: true });
|
settleApproval(msg.id, { signature }, { holdsClaim: true });
|
||||||
sendResponse({ signature });
|
sendResponse({ signature });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const {
|
|||||||
formatFee,
|
formatFee,
|
||||||
tokenLabel,
|
tokenLabel,
|
||||||
} = require("./helpers");
|
} = require("./helpers");
|
||||||
const { state, saveState, currentNetwork } = require("../../shared/state");
|
const { state, saveState } = require("../../shared/state");
|
||||||
const {
|
const {
|
||||||
networkById,
|
networkById,
|
||||||
networkByChainId,
|
networkByChainId,
|
||||||
@@ -46,10 +46,7 @@ const {
|
|||||||
const { decryptWithPassword } = require("../../shared/vault");
|
const { decryptWithPassword } = require("../../shared/vault");
|
||||||
const { getSignerForAddress } = require("../../shared/wallet");
|
const { getSignerForAddress } = require("../../shared/wallet");
|
||||||
const { walletDefect } = require("../../shared/walletDefects");
|
const { walletDefect } = require("../../shared/walletDefects");
|
||||||
const {
|
const { describeSigningFailure } = require("../../shared/approvalVerify");
|
||||||
describeSigningFailure,
|
|
||||||
typedDataChainRefusal,
|
|
||||||
} = require("../../shared/approvalVerify");
|
|
||||||
const txStatus = require("./txStatus");
|
const txStatus = require("./txStatus");
|
||||||
const uniswap = require("../../shared/uniswap");
|
const uniswap = require("../../shared/uniswap");
|
||||||
const { notify, runtimeApi, sendMessage } = require("../../shared/browserApi");
|
const { notify, runtimeApi, sendMessage } = require("../../shared/browserApi");
|
||||||
@@ -446,8 +443,7 @@ function signedPrimaryType(types) {
|
|||||||
// Why a signature request cannot be signed, as a sentence for the error line,
|
// Why a signature request cannot be signed, as a sentence for the error line,
|
||||||
// or null when it can. Only typed data is refused: the `primaryType` the page
|
// or null when it can. Only typed data is refused: the `primaryType` the page
|
||||||
// states has to be the type ethers will sign, or this screen would name one
|
// states has to be the type ethers will sign, or this screen would name one
|
||||||
// message while another is signed. Its domain may name no chain but the active
|
// message while another is signed.
|
||||||
// network's.
|
|
||||||
function typedDataRefusal(sp) {
|
function typedDataRefusal(sp) {
|
||||||
if (sp.method === "personal_sign" || sp.method === "eth_sign") return null;
|
if (sp.method === "personal_sign" || sp.method === "eth_sign") return null;
|
||||||
let data;
|
let data;
|
||||||
@@ -470,7 +466,7 @@ function typedDataRefusal(sp) {
|
|||||||
", so it cannot be signed."
|
", so it cannot be signed."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return typedDataChainRefusal(data.domain, currentNetwork());
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The largest amount a Permit2 allowance can hold, a uint160. Permit2 treats
|
// The largest amount a Permit2 allowance can hold, a uint160. Permit2 treats
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ const {
|
|||||||
accessListify,
|
accessListify,
|
||||||
formatEther,
|
formatEther,
|
||||||
getAddress,
|
getAddress,
|
||||||
getBigInt,
|
|
||||||
getBytes,
|
getBytes,
|
||||||
toQuantity,
|
toQuantity,
|
||||||
verifyMessage,
|
verifyMessage,
|
||||||
@@ -636,33 +635,6 @@ function verifySignature(signParams, signature, expectedFrom) {
|
|||||||
return recovered;
|
return recovered;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Why typed data cannot be signed while `network` is the active network, as a
|
|
||||||
// sentence, or null when it can. EIP-712 has a wallet refuse typed data whose
|
|
||||||
// domain names another chain, because the signature is valid on that chain.
|
|
||||||
// ethers signs no chain id when the domain's is null or absent, and reads any
|
|
||||||
// other with getBigInt(), so 1, "1" and "0x1" are the same chain here too.
|
|
||||||
function typedDataChainRefusal(domain, network) {
|
|
||||||
const chainId = domain?.chainId;
|
|
||||||
if (chainId === undefined || chainId === null) return null;
|
|
||||||
let named;
|
|
||||||
try {
|
|
||||||
named = getBigInt(chainId);
|
|
||||||
} catch {
|
|
||||||
return "This typed data cannot be read, so it cannot be signed.";
|
|
||||||
}
|
|
||||||
const active = getBigInt(network.chainId);
|
|
||||||
if (named === active) return null;
|
|
||||||
return (
|
|
||||||
"This typed data is for chain id " +
|
|
||||||
named +
|
|
||||||
", but the active network is " +
|
|
||||||
network.name +
|
|
||||||
" (chain id " +
|
|
||||||
active +
|
|
||||||
"), so it cannot be signed."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The stage a transaction approval failed at. Which stage it is decides
|
// The stage a transaction approval failed at. Which stage it is decides
|
||||||
// whether the approval survives the failure.
|
// whether the approval survives the failure.
|
||||||
const TX_STAGE_SIGN = "sign";
|
const TX_STAGE_SIGN = "sign";
|
||||||
@@ -824,7 +796,6 @@ function describeSigningFailure(response, fallbackMessage) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
verifySignedTx,
|
verifySignedTx,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
typedDataChainRefusal,
|
|
||||||
assertNoForbiddenFields,
|
assertNoForbiddenFields,
|
||||||
assertNothingUnchecked,
|
assertNothingUnchecked,
|
||||||
assertCanonicalBytes,
|
assertCanonicalBytes,
|
||||||
|
|||||||
@@ -110,14 +110,11 @@ function hashListed(hash) {
|
|||||||
* Generate hostname variants for subdomain matching.
|
* Generate hostname variants for subdomain matching.
|
||||||
* "sub.evil.com" yields ["sub.evil.com", "evil.com"].
|
* "sub.evil.com" yields ["sub.evil.com", "evil.com"].
|
||||||
*
|
*
|
||||||
* A trailing dot is dropped: "evil.com." is the fully qualified spelling of
|
|
||||||
* "evil.com", and the browser loads the same site from either.
|
|
||||||
*
|
|
||||||
* @param {string} hostname
|
* @param {string} hostname
|
||||||
* @returns {string[]}
|
* @returns {string[]}
|
||||||
*/
|
*/
|
||||||
function hostnameVariants(hostname) {
|
function hostnameVariants(hostname) {
|
||||||
const h = hostname.toLowerCase().replace(/\.$/, "");
|
const h = hostname.toLowerCase();
|
||||||
const variants = [h];
|
const variants = [h];
|
||||||
const parts = h.split(".");
|
const parts = h.split(".");
|
||||||
// Parent domains: a.b.c.d -> b.c.d, c.d
|
// Parent domains: a.b.c.d -> b.c.d, c.d
|
||||||
|
|||||||
@@ -36,13 +36,11 @@ const DEFECTS = {
|
|||||||
"derivation path beneath that key instead of from a master " +
|
"derivation path beneath that key instead of from a master " +
|
||||||
"key, so the addresses listed here are not the ones that key " +
|
"key, so the addresses listed here are not the ones that key " +
|
||||||
"produces under the standard path.",
|
"produces under the standard path.",
|
||||||
"Signing, sending and private key export are disabled for this " +
|
"Signing and sending are disabled for this wallet. The addresses " +
|
||||||
"wallet. Anything these addresses hold can be reached outside " +
|
"do descend from the extended private key you imported, so " +
|
||||||
"this wallet with the extended private key you imported, if " +
|
"anything they hold is still reachable by software that " +
|
||||||
"you kept a copy of it, or with the master extended private " +
|
"repeats the same non-standard derivation. Check them in a " +
|
||||||
"key or recovery phrase it came from, in software that " +
|
"block explorer before deciding what to do.",
|
||||||
"repeats the same non-standard derivation. Check the " +
|
|
||||||
"addresses in a block explorer before deciding what to do.",
|
|
||||||
"To see the addresses this key produces under the standard path, " +
|
"To see the addresses this key produces under the standard path, " +
|
||||||
"import the master extended private key, or the recovery " +
|
"import the master extended private key, or the recovery " +
|
||||||
"phrase it came from, as a new wallet. Nothing here has been " +
|
"phrase it came from, as a new wallet. Nothing here has been " +
|
||||||
|
|||||||
@@ -397,13 +397,7 @@ function loadBackground(options) {
|
|||||||
rpcResult = r;
|
rpcResult = r;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return {
|
return { result: () => rpcResult };
|
||||||
id: () =>
|
|
||||||
new URL(created[created.length - 1].url).searchParams.get(
|
|
||||||
"approval",
|
|
||||||
),
|
|
||||||
result: () => rpcResult,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A dApp asking to connect. The origin defaults to one the persisted
|
// A dApp asking to connect. The origin defaults to one the persisted
|
||||||
@@ -1490,55 +1484,6 @@ describe("what the approval is verified against", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Typed data whose domain names another chain is refused on the sign
|
|
||||||
// screen; a signature for it that reaches the background anyway is not
|
|
||||||
// handed to the page (https://git.eeqj.de/sneak/AutistMask/issues/519).
|
|
||||||
// TYPED_DATA names mainnet.
|
|
||||||
async function answerTypedData(bg, pending) {
|
|
||||||
const { domain, types, message } = JSON.parse(TYPED_DATA);
|
|
||||||
delete types.EIP712Domain;
|
|
||||||
const signature = await signer.signTypedData(domain, types, message);
|
|
||||||
const answer = bg.send(
|
|
||||||
{
|
|
||||||
type: "AUTISTMASK_SIGN_RESPONSE",
|
|
||||||
id: pending.id(),
|
|
||||||
approved: true,
|
|
||||||
signature,
|
|
||||||
},
|
|
||||||
{ url: bg.fromPopup.url },
|
|
||||||
);
|
|
||||||
await settle();
|
|
||||||
return { answer, signature };
|
|
||||||
}
|
|
||||||
|
|
||||||
test("typed data for the active chain is handed back signed", async () => {
|
|
||||||
const bg = loadBackground();
|
|
||||||
const pending = bg.requestTypedData();
|
|
||||||
await settle();
|
|
||||||
|
|
||||||
const { answer, signature } = await answerTypedData(bg, pending);
|
|
||||||
|
|
||||||
expect(answer.sendResponse).toHaveBeenCalledWith({ signature });
|
|
||||||
expect(pending.result()).toEqual({ result: signature });
|
|
||||||
});
|
|
||||||
|
|
||||||
test("typed data for another chain is refused, not handed back", async () => {
|
|
||||||
const bg = loadBackground();
|
|
||||||
bg.setNetwork(SEPOLIA);
|
|
||||||
const pending = bg.requestTypedData();
|
|
||||||
await settle();
|
|
||||||
|
|
||||||
const { answer } = await answerTypedData(bg, pending);
|
|
||||||
|
|
||||||
const refusal =
|
|
||||||
"This typed data is for chain id 1, but the active network is Sepolia Testnet (chain id 11155111), so it cannot be signed.";
|
|
||||||
expect(answer.sendResponse).toHaveBeenCalledWith({
|
|
||||||
error: refusal,
|
|
||||||
retryable: false,
|
|
||||||
});
|
|
||||||
expect(pending.result()).toEqual({ error: { message: refusal } });
|
|
||||||
});
|
|
||||||
|
|
||||||
test("a sign request from another address raises no approval at all", async () => {
|
test("a sign request from another address raises no approval at all", async () => {
|
||||||
const bg = loadBackground();
|
const bg = loadBackground();
|
||||||
const pending = bg.requestSign(other.address);
|
const pending = bg.requestSign(other.address);
|
||||||
@@ -1610,9 +1555,7 @@ describe("what the approval is verified against", () => {
|
|||||||
// personal_sign, and is answered as the JSON-RPC specification defines it:
|
// personal_sign, and is answered as the JSON-RPC specification defines it:
|
||||||
// with an EIP-191 personal message signature over the data, the same
|
// with an EIP-191 personal message signature over the data, the same
|
||||||
// signature personal_sign returns
|
// signature personal_sign returns
|
||||||
// (https://git.eeqj.de/sneak/AutistMask/issues/409). The signature below is
|
// (https://git.eeqj.de/sneak/AutistMask/issues/409).
|
||||||
// made by the test; that the sign screen makes the same one is tested in
|
|
||||||
// tests/ethSign.test.js.
|
|
||||||
describe("eth_sign", () => {
|
describe("eth_sign", () => {
|
||||||
test("is read address first, and returns a personal message signature over the data", async () => {
|
test("is read address first, and returns a personal message signature over the data", async () => {
|
||||||
const bg = loadBackground();
|
const bg = loadBackground();
|
||||||
|
|||||||
@@ -1,102 +0,0 @@
|
|||||||
// The sign screen signs an eth_sign request the way it signs personal_sign: as
|
|
||||||
// an EIP-191 personal message over the bytes of the data
|
|
||||||
// (https://git.eeqj.de/sneak/AutistMask/issues/409). Booted through the real
|
|
||||||
// popup entry point as the approval window. The background's half, which reads
|
|
||||||
// the address first and the data second and checks the signature, is tested in
|
|
||||||
// tests/backgroundApproval.test.js.
|
|
||||||
|
|
||||||
// Mocked so that no password has to be hashed: the stored secret decrypts to
|
|
||||||
// the test key below.
|
|
||||||
jest.mock("../src/shared/vault", () => ({
|
|
||||||
decryptWithPassword: jest.fn(),
|
|
||||||
encryptWithPassword: jest.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const { Wallet, getBytes } = require("ethers");
|
|
||||||
const {
|
|
||||||
bootPopup,
|
|
||||||
cleanupPopup,
|
|
||||||
unversionedValidProfile,
|
|
||||||
} = require("./support/popupBoot");
|
|
||||||
|
|
||||||
// A published test key, never used for real funds.
|
|
||||||
const SIGNER_KEY =
|
|
||||||
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d";
|
|
||||||
const signer = new Wallet(SIGNER_KEY);
|
|
||||||
// "Hello AutistMask", as the hex a page sends.
|
|
||||||
const MESSAGE = "0x48656c6c6f204175746973744d61736b";
|
|
||||||
const ORIGIN = "https://dapp.example";
|
|
||||||
|
|
||||||
afterEach(cleanupPopup);
|
|
||||||
|
|
||||||
test("the sign screen answers eth_sign with a personal message signature over the data", async () => {
|
|
||||||
const sent = [];
|
|
||||||
const page = await bootPopup(
|
|
||||||
unversionedValidProfile({
|
|
||||||
wallets: [
|
|
||||||
{
|
|
||||||
type: "key",
|
|
||||||
name: "Wallet 1",
|
|
||||||
encryptedSecret: "encrypted-key",
|
|
||||||
addresses: [
|
|
||||||
{
|
|
||||||
address: signer.address,
|
|
||||||
balance: "0.0000",
|
|
||||||
tokenBalances: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
activeAddress: signer.address,
|
|
||||||
allowedSites: { [signer.address]: [ORIGIN] },
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
search: "?approval=approval-1",
|
|
||||||
runtime: {
|
|
||||||
connect: () => ({ postMessage: () => {} }),
|
|
||||||
// Answered as the background answers: with the eth_sign
|
|
||||||
// approval this window was opened for, and by handing back
|
|
||||||
// the signature the popup sends.
|
|
||||||
sendMessage: (msg, reply) => {
|
|
||||||
sent.push(msg);
|
|
||||||
if (msg.type === "AUTISTMASK_GET_APPROVAL") {
|
|
||||||
reply({
|
|
||||||
type: "sign",
|
|
||||||
origin: ORIGIN,
|
|
||||||
isPhishingDomain: false,
|
|
||||||
approvedFrom: signer.address,
|
|
||||||
signParams: {
|
|
||||||
method: "eth_sign",
|
|
||||||
message: MESSAGE,
|
|
||||||
from: signer.address,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else if (msg.type === "AUTISTMASK_SIGN_RESPONSE") {
|
|
||||||
reply({ signature: msg.signature });
|
|
||||||
} else {
|
|
||||||
reply(undefined);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
globalThis.window.close = jest.fn();
|
|
||||||
const { decryptWithPassword } = require("../src/shared/vault");
|
|
||||||
decryptWithPassword.mockResolvedValue(SIGNER_KEY);
|
|
||||||
|
|
||||||
expect(page.visibleViews()).toEqual(["approve-sign"]);
|
|
||||||
page.node("approve-sign-password").value = "any password";
|
|
||||||
await page.click("btn-approve-sign");
|
|
||||||
|
|
||||||
expect(
|
|
||||||
sent.filter((msg) => msg.type === "AUTISTMASK_SIGN_RESPONSE"),
|
|
||||||
).toEqual([
|
|
||||||
{
|
|
||||||
type: "AUTISTMASK_SIGN_RESPONSE",
|
|
||||||
id: "approval-1",
|
|
||||||
approved: true,
|
|
||||||
signature: await signer.signMessage(getBytes(MESSAGE)),
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
expect(globalThis.window.close).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
@@ -89,12 +89,6 @@ describe("vendored blocklist", () => {
|
|||||||
expect(isPhishingDomain(LISTED[0].toUpperCase())).toBe(true);
|
expect(isPhishingDomain(LISTED[0].toUpperCase())).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("a hostname ending in a dot is the same host", () => {
|
|
||||||
expect(isPhishingDomain(LISTED[1] + ".")).toBe(true);
|
|
||||||
expect(isPhishingDomain("wallet." + LISTED[1] + ".")).toBe(true);
|
|
||||||
expect(isPhishingDomain(CLEAN[0] + ".")).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("returns false for an empty or missing hostname", () => {
|
test("returns false for an empty or missing hostname", () => {
|
||||||
expect(isPhishingDomain("")).toBe(false);
|
expect(isPhishingDomain("")).toBe(false);
|
||||||
expect(isPhishingDomain(null)).toBe(false);
|
expect(isPhishingDomain(null)).toBe(false);
|
||||||
@@ -139,13 +133,6 @@ describe("hostnameVariants", () => {
|
|||||||
test("lowercases hostnames", () => {
|
test("lowercases hostnames", () => {
|
||||||
expect(hostnameVariants("Evil.COM")).toEqual(["evil.com"]);
|
expect(hostnameVariants("Evil.COM")).toEqual(["evil.com"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("drops the trailing dot of a fully qualified hostname", () => {
|
|
||||||
expect(hostnameVariants("sub.evil.com.")).toEqual([
|
|
||||||
"sub.evil.com",
|
|
||||||
"evil.com",
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("domain hashing", () => {
|
describe("domain hashing", () => {
|
||||||
|
|||||||
@@ -240,7 +240,6 @@ function request(data) {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
state.trackedTokens = [];
|
state.trackedTokens = [];
|
||||||
state.wallets = [];
|
state.wallets = [];
|
||||||
state.networkId = "mainnet";
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("a token permission is warned about, naming spender and amount", () => {
|
describe("a token permission is warned about, naming spender and amount", () => {
|
||||||
@@ -533,66 +532,3 @@ describe("the sign screen refuses a mismatched primary type", () => {
|
|||||||
expect(node("btn-approve-sign").disabled).toBe(true);
|
expect(node("btn-approve-sign").disabled).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// EIP-712: a wallet refuses typed data whose domain names a chain other than
|
|
||||||
// the active one, because the signature is valid on the chain it names
|
|
||||||
// (https://git.eeqj.de/sneak/AutistMask/issues/519). The wallet is on Sepolia
|
|
||||||
// and the site asks for a mainnet USDC Permit.
|
|
||||||
describe("the sign screen refuses typed data for another chain", () => {
|
|
||||||
const REFUSAL =
|
|
||||||
"This typed data is for chain id 1, but the active network is Sepolia Testnet (chain id 11155111), so it cannot be signed.";
|
|
||||||
|
|
||||||
function withChainId(chainId) {
|
|
||||||
return { ...PERMIT, domain: { ...PERMIT.domain, chainId } };
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
decryptWithPassword.mockClear();
|
|
||||||
state.networkId = "sepolia";
|
|
||||||
});
|
|
||||||
|
|
||||||
test("another chain shows the error, with Sign disabled", async () => {
|
|
||||||
await openSignScreen(PERMIT);
|
|
||||||
expect(node("approve-sign-error").textContent).toBe(REFUSAL);
|
|
||||||
expect(node("btn-approve-sign").disabled).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Sign clicked anyway decrypts and signs nothing", async () => {
|
|
||||||
const sent = await openSignScreen(PERMIT);
|
|
||||||
node("approve-sign-password").value = "any password";
|
|
||||||
await click("btn-approve-sign");
|
|
||||||
|
|
||||||
expect(decryptWithPassword).not.toHaveBeenCalled();
|
|
||||||
expect(sent.map((msg) => msg.type)).not.toContain(
|
|
||||||
"AUTISTMASK_SIGN_RESPONSE",
|
|
||||||
);
|
|
||||||
expect(node("approve-sign-error").textContent).toBe(REFUSAL);
|
|
||||||
});
|
|
||||||
|
|
||||||
// ethers signs 1, "1" and "0x1" as the same chain id.
|
|
||||||
test("the chain id is refused in each form ethers signs", () => {
|
|
||||||
for (const chainId of [1, "1", "0x1"]) {
|
|
||||||
expect(typedDataRefusal(request(withChainId(chainId)))).toBe(
|
|
||||||
REFUSAL,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("a chain id that is not a number is refused", () => {
|
|
||||||
expect(typedDataRefusal(request(withChainId("mainnet")))).toBe(
|
|
||||||
"This typed data cannot be read, so it cannot be signed.",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("the active chain leaves Sign enabled", async () => {
|
|
||||||
await openSignScreen(withChainId("0xaa36a7"));
|
|
||||||
expect(node("approve-sign-error").textContent).toBe("");
|
|
||||||
expect(node("btn-approve-sign").disabled).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("no chain id leaves Sign enabled", async () => {
|
|
||||||
await openSignScreen(withChainId(undefined));
|
|
||||||
expect(node("approve-sign-error").textContent).toBe("");
|
|
||||||
expect(node("btn-approve-sign").disabled).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -153,18 +153,6 @@ describe("the explanatory copy", () => {
|
|||||||
expect(all).not.toMatch(/\blost\b|\bstolen\b|\bgone\b/i);
|
expect(all).not.toMatch(/\blost\b|\bstolen\b|\bgone\b/i);
|
||||||
});
|
});
|
||||||
|
|
||||||
// The wallet holds the imported key but will not export it, so the copy
|
|
||||||
// must name every key the user may hold that reaches the addresses
|
|
||||||
// outside it.
|
|
||||||
test("it names the keys that reach the addresses outside this wallet", () => {
|
|
||||||
const body = defect.paragraphs.join(" ");
|
|
||||||
|
|
||||||
expect(body).toMatch(/private key export are disabled/);
|
|
||||||
expect(body).toMatch(
|
|
||||||
/with the extended private key you imported, if you kept a copy of it, or with the master extended private key or recovery phrase it came from, in software that repeats the same non-standard derivation/,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("it says the wallet is not deleted and what the user can do", () => {
|
test("it says the wallet is not deleted and what the user can do", () => {
|
||||||
const body = defect.paragraphs.join(" ");
|
const body = defect.paragraphs.join(" ");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user