]> git.codecow.com Git - libnemo.git/commitdiff
Check for transient user activation earlier to include Ledger wallets.
authorChris Duncan <chris@codecow.com>
Tue, 12 May 2026 20:24:41 +0000 (13:24 -0700)
committerChris Duncan <chris@codecow.com>
Tue, 12 May 2026 20:24:41 +0000 (13:24 -0700)
src/lib/wallet/sign.ts

index 9a69cb0fd48ba7185387facbc8ca1a3f8cbdedca..cf1aa9d14744a0402904cf19e0d6a717eb37f668 100644 (file)
@@ -9,6 +9,12 @@ import { Wallet } from '../wallet'
 
 export async function _signBlock (wallet: Wallet, vault: Vault, index: number, address: string, block: Block, frontier?: Block): Promise<Block>
 export async function _signBlock (wallet: Wallet, vault: Vault, index: unknown, address: unknown, block: unknown, frontier?: unknown): Promise<Block | string> {
+       if (navigator.userActivation?.isActive === false) {
+               throw new DOMException(
+                       'Signing request was blocked due to lack of user activation',
+                       'NotAllowedError'
+               )
+       }
        try {
                if (typeof index !== 'number') {
                        throw new TypeError('Index must be a number', { cause: index })
@@ -32,12 +38,6 @@ export async function _signBlock (wallet: Wallet, vault: Vault, index: unknown,
                        }
                        block.signature = await Ledger.sign(index, block)
                } else {
-                       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',
                                index,
@@ -53,6 +53,12 @@ export async function _signBlock (wallet: Wallet, vault: Vault, index: unknown,
 
 export async function _signData (wallet: Wallet, vault: Vault, index: number, address: string, data: string): Promise<string>
 export async function _signData (wallet: Wallet, vault: Vault, index: unknown, address: unknown, data: unknown): Promise<string> {
+       if (navigator.userActivation?.isActive === false) {
+               throw new DOMException(
+                       'Signing request was blocked due to lack of user activation',
+                       'NotAllowedError'
+               )
+       }
        try {
                if (typeof index !== 'number') {
                        throw new TypeError('Index must be a number', { cause: index })
@@ -66,12 +72,6 @@ export async function _signData (wallet: Wallet, vault: Vault, index: unknown, a
                if (wallet.type === 'Ledger') {
                        return Ledger.sign(index, data)
                }
-               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',
                        index,