]> git.codecow.com Git - libnemo.git/commitdiff
Discard internal signature confirmation modal and leave it up to wallet.
authorChris Duncan <chris@zoso.dev>
Thu, 30 Apr 2026 19:32:41 +0000 (12:32 -0700)
committerChris Duncan <chris@zoso.dev>
Thu, 30 Apr 2026 19:32:41 +0000 (12:32 -0700)
src/lib/wallet/sign.ts

index 3bd35ea445fe61af701769c0891645f85c1aaaa8..96eb6e90571cfd901015fcbddfbc5c33df8d2728 100644 (file)
@@ -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<ArrayBuffer>({
                        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<ArrayBuffer>({
                                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<string | null> {
-       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 = `
-               <form method="dialog" style="${cssForm}">
-                       <p style="${cssHeading}">Review Transaction</p>
-                       <hr style="${cssBody}min-height:0 !important;"/>
-                       <p style="${cssBody}">Signing account</p>
-                       <pre style="${cssCode}" id="address-${elementId}"></pre>
-                       <p style="${cssBody}">Message to sign</p>
-                       <pre style="${cssCode}" id="message-${elementId}"></pre>
-                       <hr style="${cssBody}min-height:0 !important;"/>
-                       <p style="${cssHeading}">Sign transaction?</p>
-                       <div style="${cssHeading}">
-                               <button value="no" autofocus style="${cssButton}">NO, cancel</button>
-                               <button value="yes" style="${cssButton}font-weight:normal !important;">YES, sign</button>
-                       </div>
-               </form>`
-               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
-}