Skip to content

Commit

Permalink
chore: use SmartAccount for registration
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahschwartz committed Sep 19, 2024
1 parent 4971f7b commit 0adba6b
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions code/webauthn/frontend/utils/tx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DEFAULT_GAS_PER_PUBDATA_LIMIT, getPaymasterParams } from 'zksync-ethers/build/utils';
import { EIP712Signer, type Wallet, type Provider, utils, type types } from 'zksync-ethers';
import { type Wallet, type Provider, type types, SmartAccount } from 'zksync-ethers';
import { ethers } from 'ethers';
import accountAbiJSON from '../../contracts/artifacts-zk/contracts/Account.sol/Account.json';

Expand Down Expand Up @@ -43,20 +43,8 @@ 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 signedTxHash = EIP712Signer.getSignedDigest(registerTx);
const signingKey: ethers.utils.SigningKey = new ethers.utils.SigningKey(wallet.privateKey);
const walletSignature = signingKey.signDigest(signedTxHash);
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();
const smartAccount = new SmartAccount({ address: account, secret: wallet.privateKey }, provider);
await smartAccount.sendTransaction(registerTx);
} catch (error) {
console.error('Error:', error);
}
Expand Down

0 comments on commit 0adba6b

Please sign in to comment.