From a758bf0029bba7b0df140bde2450009bb0d0a6be Mon Sep 17 00:00:00 2001 From: Sarah Schwartz <58856580+sarahschwartz@users.noreply.github.com> Date: Tue, 24 Sep 2024 13:21:50 -0600 Subject: [PATCH] fix: revert register changes --- code/webauthn/frontend/utils/tx.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/code/webauthn/frontend/utils/tx.ts b/code/webauthn/frontend/utils/tx.ts index 806c529b..0150d6a5 100644 --- a/code/webauthn/frontend/utils/tx.ts +++ b/code/webauthn/frontend/utils/tx.ts @@ -1,7 +1,8 @@ import { DEFAULT_GAS_PER_PUBDATA_LIMIT, getPaymasterParams } from 'zksync-ethers/build/utils'; -import { type Wallet, type Provider, type types, SmartAccount } from 'zksync-ethers'; +import { type Wallet, type Provider, type types, utils } from 'zksync-ethers'; import { ethers } from 'ethers'; import accountAbiJSON from '../../contracts/artifacts-zk/contracts/Account.sol/Account.json'; +import { getDataToSign } from './webauthn'; export async function getTransaction(to: string, from: string, value: string, data: string, provider: Provider) { const gasPrice = await provider.getGasPrice(); @@ -43,9 +44,21 @@ export async function registerKeyInAccount(pubKey: string, account: string, prov const data = contract.interface.encodeFunctionData('updateR1Owner', [pubKey]); const transferAmount = '0'; const registerTx = await getTransaction(account, account, transferAmount, data, provider); - const smartAccount = new SmartAccount({ address: account, secret: wallet.privateKey }, provider); - await smartAccount.sendTransaction(registerTx); + const dataToSign = getDataToSign(registerTx); + const signingKey: ethers.utils.SigningKey = new ethers.utils.SigningKey(wallet.privateKey); + const walletSignature = signingKey.signDigest(dataToSign); + const sig = ethers.utils.joinSignature(walletSignature); + const signature = ethers.utils.concat([sig]); + + registerTx.customData = { + ...registerTx.customData, + customSignature: signature, + }; + + const finalTx = utils.serialize(registerTx); + const sentTx = await provider.sendTransaction(finalTx); + await sentTx.wait(); } catch (error) { - console.error('Error:', error); + console.error('Error registering key in account:', error); } }