diff --git a/packages/auth-server/composables/useRecoveryGuardian.ts b/packages/auth-server/composables/useRecoveryGuardian.ts index fc4de70..1edbfda 100644 --- a/packages/auth-server/composables/useRecoveryGuardian.ts +++ b/packages/auth-server/composables/useRecoveryGuardian.ts @@ -54,6 +54,29 @@ export const useRecoveryGuardian = () => { } } + const getRecoveryInProgress = ref(false); + const getRecoveryError = ref(null); + + async function getRecovery(account: Address) { + getRecoveryInProgress.value = true; + getRecoveryError.value = null; + + try { + const client = getPublicClient({ chainId: defaultChain.id }); + return await client.readContract({ + address: contractsByChain[defaultChain.id].recovery, + abi: GuardianRecoveryModuleAbi, + functionName: "pendingRecoveryData", + args: [account], + }); + } catch (err) { + getRecoveryError.value = err as Error; + return []; + } finally { + getRecoveryInProgress.value = false; + } + } + const { inProgress: proposeGuardianInProgress, error: proposeGuardianError, execute: proposeGuardian } = useAsync(async (address: Address) => { const client = getClient({ chainId: defaultChain.id }); const tx = await client.proposeGuardian({ @@ -91,6 +114,20 @@ export const useRecoveryGuardian = () => { return tx; }); + const { inProgress: initRecoveryInProgress, error: initRecoveryError, execute: initRecovery } = useAsync(async (account: Address, passKey: `0x${string}`, accountId: string) => { + const client = await getWalletClient({ chainId: defaultChain.id }); + const [address] = await client.getAddresses(); + + const tx = await client.writeContract({ + account: address, + address: contractsByChain[defaultChain.id].recovery, + abi: GuardianRecoveryModuleAbi, + functionName: "initRecovery", + args: [account, passKey, accountId], + }); + return tx; + }); + return { confirmGuardianInProgress, confirmGuardianError, @@ -101,6 +138,9 @@ export const useRecoveryGuardian = () => { removeGuardianInProgress, removeGuardianError, removeGuardian, + initRecoveryInProgress, + initRecoveryError, + initRecovery, getGuardedAccountsInProgress, getGuardedAccountsError, getGuardedAccounts, @@ -108,5 +148,8 @@ export const useRecoveryGuardian = () => { getGuardiansError, getGuardiansData, getGuardians, + getRecoveryInProgress, + getRecoveryError, + getRecovery, }; }; diff --git a/packages/auth-server/pages/recovery/guardian/(actions)/confirm-recovery.vue b/packages/auth-server/pages/recovery/guardian/(actions)/confirm-recovery.vue index 2e54639..10333b5 100644 --- a/packages/auth-server/pages/recovery/guardian/(actions)/confirm-recovery.vue +++ b/packages/auth-server/pages/recovery/guardian/(actions)/confirm-recovery.vue @@ -104,7 +104,8 @@ v-if="accountData.isConnected && !isSuccess" class="w-full lg:w-fit" :disabled="!isAccountGuardian" - @click="handleSuccess" + :loading="initRecoveryInProgress" + @click="confirmRecoveryAction" > Sign Recovery Transaction @@ -132,6 +133,8 @@ diff --git a/packages/sdk/src/abi/GuardianRecoveryModule.ts b/packages/sdk/src/abi/GuardianRecoveryModule.ts index 6b18b1b..1cda8ce 100644 --- a/packages/sdk/src/abi/GuardianRecoveryModule.ts +++ b/packages/sdk/src/abi/GuardianRecoveryModule.ts @@ -2,17 +2,22 @@ export const GuardianRecoveryModuleAbi = [ { inputs: [ { - internalType: "address", + internalType: "contract WebAuthValidator", name: "_webAuthValidator", type: "address", }, + { + internalType: "contract AAFactory", + name: "_aaFactory", + type: "address", + }, ], stateMutability: "nonpayable", type: "constructor", }, { inputs: [], - name: "CooldownPerionNotPassed", + name: "CooldownPeriodNotPassed", type: "error", }, { @@ -79,6 +84,19 @@ export const GuardianRecoveryModuleAbi = [ name: "RecoveryInitiated", type: "event", }, + { + inputs: [], + name: "aaFactory", + outputs: [ + { + internalType: "contract AAFactory", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, { inputs: [ { @@ -104,6 +122,11 @@ export const GuardianRecoveryModuleAbi = [ name: "isReady", type: "bool", }, + { + internalType: "uint64", + name: "addedAt", + type: "uint64", + }, ], stateMutability: "view", type: "function", @@ -128,10 +151,32 @@ export const GuardianRecoveryModuleAbi = [ type: "function", }, { - inputs: [], - name: "disable", - outputs: [], - stateMutability: "nonpayable", + inputs: [ + { + internalType: "string", + name: "accountId", + type: "string", + }, + ], + name: "checkRecoveryRequest", + outputs: [ + { + internalType: "address", + name: "account", + type: "address", + }, + { + internalType: "bool", + name: "ready", + type: "bool", + }, + { + internalType: "uint256", + name: "remainingTime", + type: "uint256", + }, + ], + stateMutability: "view", type: "function", }, { @@ -206,6 +251,11 @@ export const GuardianRecoveryModuleAbi = [ name: "isReady", type: "bool", }, + { + internalType: "uint64", + name: "addedAt", + type: "uint64", + }, ], internalType: "struct GuardianRecoveryValidator.Guardian[]", name: "", @@ -217,13 +267,23 @@ export const GuardianRecoveryModuleAbi = [ }, { inputs: [ + { + internalType: "address", + name: "accountToRecover", + type: "address", + }, { internalType: "bytes", - name: "initData", + name: "passkey", type: "bytes", }, + { + internalType: "string", + name: "accountId", + type: "string", + }, ], - name: "init", + name: "initRecovery", outputs: [], stateMutability: "nonpayable", type: "function", @@ -231,17 +291,30 @@ export const GuardianRecoveryModuleAbi = [ { inputs: [ { - internalType: "address", - name: "accountToRecover", + internalType: "contract WebAuthValidator", + name: "_webAuthValidator", type: "address", }, + { + internalType: "contract AAFactory", + name: "_aaFactory", + type: "address", + }, + ], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ { internalType: "bytes", - name: "passkey", + name: "", type: "bytes", }, ], - name: "initRecovery", + name: "onInstall", outputs: [], stateMutability: "nonpayable", type: "function", @@ -249,12 +322,12 @@ export const GuardianRecoveryModuleAbi = [ { inputs: [ { - internalType: "address", - name: "_webAuthValidator", - type: "address", + internalType: "bytes", + name: "", + type: "bytes", }, ], - name: "initialize", + name: "onUninstall", outputs: [], stateMutability: "nonpayable", type: "function", @@ -279,6 +352,11 @@ export const GuardianRecoveryModuleAbi = [ name: "timestamp", type: "uint256", }, + { + internalType: "string", + name: "accountId", + type: "string", + }, ], stateMutability: "view", type: "function", @@ -325,19 +403,19 @@ export const GuardianRecoveryModuleAbi = [ type: "bool", }, ], - stateMutability: "view", + stateMutability: "pure", type: "function", }, { inputs: [ { internalType: "bytes32", - name: "signedHash", + name: "", type: "bytes32", }, { internalType: "bytes", - name: "signature", + name: "", type: "bytes", }, ], @@ -349,19 +427,19 @@ export const GuardianRecoveryModuleAbi = [ type: "bool", }, ], - stateMutability: "view", + stateMutability: "pure", type: "function", }, { inputs: [ { internalType: "bytes32", - name: "signedHash", + name: "", type: "bytes32", }, { internalType: "bytes", - name: "signature", + name: "", type: "bytes", }, { @@ -468,7 +546,7 @@ export const GuardianRecoveryModuleAbi = [ name: "webAuthValidator", outputs: [ { - internalType: "address", + internalType: "contract WebAuthValidator", name: "", type: "address", }, diff --git a/packages/sdk/src/client/recovery/actions/recovery.ts b/packages/sdk/src/client/recovery/actions/recovery.ts index f5b75b3..4997eb8 100644 --- a/packages/sdk/src/client/recovery/actions/recovery.ts +++ b/packages/sdk/src/client/recovery/actions/recovery.ts @@ -105,6 +105,7 @@ export const removeGuardian = async < export type InitRecoveryArgs = { expectedOrigin: string | undefined; credentialPublicKey: Uint8Array; + accountId: string; contracts: { recovery: Address; // recovery module }; @@ -142,7 +143,7 @@ export const initRecovery = async < const callData = encodeFunctionData({ abi: GuardianRecoveryModuleAbi, functionName: "initRecovery", - args: [args.account, encodedPasskeyParameters], + args: [args.account, encodedPasskeyParameters, args.accountId], }); const sendTransactionArgs = {