From d9306878d04f3b78b877720c55dfc3e9329ef3ac Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 30 Apr 2026 12:32:41 -0700 Subject: [PATCH] Discard internal signature confirmation modal and leave it up to wallet. --- src/lib/wallet/sign.ts | 80 ++++++------------------------------------ 1 file changed, 10 insertions(+), 70 deletions(-) diff --git a/src/lib/wallet/sign.ts b/src/lib/wallet/sign.ts index 3bd35ea..96eb6e9 100644 --- a/src/lib/wallet/sign.ts +++ b/src/lib/wallet/sign.ts @@ -23,13 +23,11 @@ export async function _signData (wallet: Wallet, vault: Vault, index: unknown, a if (wallet.type === 'Ledger') { return await Ledger.sign(index, message[0]) } - const reqId = crypto.randomUUID() - const resId = await confirm(reqId, address, message) - if (resId === null) { - throw new Error('User rejected sign request') - } - if (reqId !== resId) { - throw new Error('Signing confirmation responded to wrong request') + if (navigator.userActivation?.isActive === false) { + throw new DOMException( + 'Signing request was blocked due to lack of user activation', + 'NotAllowedError' + ) } const { signature } = await vault.request({ action: 'sign', @@ -64,13 +62,11 @@ export async function _signBlock (wallet: Wallet, vault: Vault, index: unknown, } block.signature = await Ledger.sign(index, block) } else { - const reqId = crypto.randomUUID() - const resId = await confirm(reqId, address, block) - if (resId === null) { - throw new Error('User rejected sign request') - } - if (reqId !== resId) { - throw new Error('Signing confirmation responded to wrong request') + if (navigator.userActivation?.isActive === false) { + throw new DOMException( + 'Signing request was blocked due to lack of user activation', + 'NotAllowedError' + ) } const { signature } = await vault.request({ action: 'sign', @@ -83,59 +79,3 @@ export async function _signBlock (wallet: Wallet, vault: Vault, index: unknown, throw new Error(`Failed to sign block`, { cause: err }) } } - -async function confirm (id: string, address: string, message: Block | string[]): Promise { - if (!navigator.userActivation?.isActive) { - throw new DOMException( - 'Signing request was blocked due to lack of user activation', - 'NotAllowedError' - ) - } - BROWSER: return new Promise((resolve, reject) => { - const elementId = crypto.randomUUID() - const cssDialog = 'background-color:white !important;margin-top:auto !important;margin-right:auto !important;margin-bottom:auto !important;margin-left:auto !important;max-height:90vh !important;min-height:100px !important;min-width:100px !important;overflow-y:auto !important;opacity:1 !important;padding-top:0 !important;padding-right:0 !important;padding-bottom:0 !important;padding-left:0 !important;visibility:visible !important;z-index:2147483647 !important;' - const cssForm = 'background-color:white !important;display:block !important;margin-top:0 !important;margin-right:0 !important;margin-bottom:0 !important;margin-left:0 !important;min-height:100px !important;min-width:100px !important;opacity:1 !important;padding-top:0 !important;padding-right:0 !important;padding-bottom:0 !important;padding-left:0 !important;visibility:visible !important;' - const cssHeading = 'color:black !important;display:block !important;font-family:sans-serif !important;font-size=1rem !important;font-weight:bold !important;margin-top:1rem !important;margin-right:1rem !important;margin-bottom:1rem !important;margin-left:1rem !important;min-height:10px !important;min-width:10px !important;opacity:1 !important;padding-top:0 !important;padding-right:0 !important;padding-bottom:0 !important;padding-left:0 !important;position:initial !important;text-align:center !important;visibility:visible !important;' - const cssBody = 'color:grey !important;display:block !important;font-family:sans-serif !important;font-size:1rem !important;font-weight:normal !important;margin-top:1rem !important;margin-right:1rem !important;margin-bottom:0 !important;margin-left:1rem !important;min-height:10px !important;min-width:10px !important;opacity:1 !important;padding-top:0 !important;padding-right:0 !important;padding-bottom:0 !important;padding-left:0 !important;position:initial !important;visibility:visible !important;' - const cssCode = 'color:black !important;display:block !important;font-family:monospace !important;font-size=1rem !important;font-weight:normal !important;margin-top:0 !important;margin-right:1rem !important;margin-bottom:0 !important;margin-left:1rem !important;min-height:10px !important;min-width:10px !important;opacity:1 !important;padding-top:0 !important;padding-right:0 !important;padding-bottom:0 !important;padding-left:0 !important;position:initial !important;visibility:visible !important;white-space:pre-wrap !important;word-break:break-all !important;' - const cssButton = 'color:black !important;display:inline-block !important;font-family:sans-serif !important;font-size=1rem !important;font-weight:bold !important;margin-top:1rem !important;margin-right:1rem !important;margin-bottom:1rem !important;margin-left:1rem !important;min-height:10px !important;min-width:10px !important;opacity:1 !important;padding-top:1rem !important;padding-right:1rem !important;padding-bottom:1rem !important;padding-left:1rem !important;position:initial !important;text-align:center !important;visibility:visible !important;' - const dialog = document.createElement('dialog') - dialog.style.cssText = cssDialog - dialog.innerHTML = ` -
-

Review Transaction

-
-

Signing account

-

-			

Message to sign

-

-			
-

Sign transaction?

-
- - -
-
` - const addressElement = dialog.querySelector(`#address-${elementId}`) - const messageElement = dialog.querySelector(`#message-${elementId}`) - if (addressElement == null || messageElement == null) { - throw new DOMException('Failed to find signature confirmation dialog element') - } - addressElement.textContent = address - messageElement.textContent = JSON.stringify(message, null, 2) - dialog.addEventListener('close', (ev) => { - dialog.remove() - if (ev.isTrusted && navigator.userActivation?.isActive) { - resolve(dialog.returnValue === 'yes' ? id : null) - } else { - reject(new DOMException( - 'Signing request was blocked due to untrusted event', - 'NotAllowedError' - )) - } - }) - document.body.appendChild(dialog) - dialog.showModal() - }) - NODE: return id -} -- 2.47.3