fix: explain a stored non-master xprv wallet instead of throwing at signing time (closes #234)
All checks were successful
check / check (push) Successful in 28s
All checks were successful
check / check (push) Successful in 28s
An xprv wallet imported before non-master keys were refused holds a key whose depth is greater than zero. Its addresses were derived by applying the Ethereum path beneath that key, so they are not the addresses the key produces under the standard path, and signing for them now throws — on the send screen, with no explanation. Detect it at wallet-list render time instead. An xprv wallet stores the neutered node four levels below the imported key, so a master import stores a depth-4 xpub and a depth-d import stores depth d + 4; the stored xpub is therefore an exact read on the imported key's depth and needs no password. The wallet list renders a named explanation under the wallet's name, the "+" button is withheld, and send, dapp transaction approval, dapp message signing and private-key export all refuse before asking for a password. getSignerForAddress remains the backstop and now says why in a sentence. The copy states what is true and nothing more: the addresses do descend from the key that was imported, so it neither promises the funds are safe nor implies anything was lost. The wallet is not deleted or rewritten.
This commit is contained in:
@@ -21,6 +21,7 @@ const { ERC20_ABI } = require("../../shared/constants");
|
||||
const { TOKEN_BY_ADDRESS } = require("../../shared/tokenList");
|
||||
const { decryptWithPassword } = require("../../shared/vault");
|
||||
const { getSignerForAddress } = require("../../shared/wallet");
|
||||
const { walletDefect } = require("../../shared/walletDefects");
|
||||
const { getProvider } = require("../../shared/balances");
|
||||
const txStatus = require("./txStatus");
|
||||
const uniswap = require("../../shared/uniswap");
|
||||
@@ -280,6 +281,7 @@ function showTxApproval(details) {
|
||||
|
||||
showView("approve-tx");
|
||||
attachCopyHandlers("view-approve-tx");
|
||||
gateOnWalletDefect("approve-tx-error", "btn-approve-tx");
|
||||
}
|
||||
|
||||
function decodeHexMessage(hex) {
|
||||
@@ -379,6 +381,7 @@ function showSignApproval(details) {
|
||||
|
||||
showView("approve-sign");
|
||||
attachCopyHandlers("view-approve-sign");
|
||||
gateOnWalletDefect("approve-sign-error", "btn-approve-sign");
|
||||
}
|
||||
|
||||
function show(id) {
|
||||
@@ -431,6 +434,20 @@ function setSignButtonBusy(busy) {
|
||||
$("btn-approve-sign").classList.toggle("text-muted", busy);
|
||||
}
|
||||
|
||||
// Say so on the approval screen itself, and disable the approve button, when
|
||||
// the active address belongs to a wallet whose keys cannot be derived. Without
|
||||
// this the screen would take a password and fail after deriving it. Reject
|
||||
// stays available; the wallet is not touched. Returns true when it gated.
|
||||
function gateOnWalletDefect(errorId, buttonId) {
|
||||
const active = findActiveWallet();
|
||||
const defect = active ? walletDefect(active.wallet) : null;
|
||||
if (!defect) return false;
|
||||
showError(errorId, defect.shortMessage);
|
||||
$(buttonId).disabled = true;
|
||||
$(buttonId).classList.add("text-muted");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Locate the wallet and the address index owning the currently active
|
||||
// address. Returns null when no wallet holds it.
|
||||
function findActiveWallet() {
|
||||
@@ -492,6 +509,14 @@ function init(ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
const defect = walletDefect(active.wallet);
|
||||
if (defect) {
|
||||
password = null;
|
||||
showError("approve-tx-error", defect.shortMessage);
|
||||
setTxButtonBusy(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Decrypt here, in the popup. The password must never cross the
|
||||
// extension messaging boundary; only the signed transaction does.
|
||||
let decryptedSecret;
|
||||
@@ -583,6 +608,14 @@ function init(ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
const defect = walletDefect(active.wallet);
|
||||
if (defect) {
|
||||
password = null;
|
||||
showError("approve-sign-error", defect.shortMessage);
|
||||
setSignButtonBusy(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Decrypt here, in the popup. The password must never cross the
|
||||
// extension messaging boundary; only the signature does.
|
||||
let decryptedSecret;
|
||||
|
||||
Reference in New Issue
Block a user