Skip to content

Commit

Permalink
fix: revert register changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahschwartz committed Sep 24, 2024
1 parent 03f46dc commit a758bf0
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions code/webauthn/frontend/utils/tx.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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);
}
}

0 comments on commit a758bf0

Please sign in to comment.