Skip to content

Commit

Permalink
chore: address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahschwartz committed Sep 24, 2024
1 parent 4603a61 commit 03f46dc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
16 changes: 14 additions & 2 deletions code/webauthn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This demo requires Google Chrome and a device that supports webauthn.

### Install Dependencies

Use node version `20.16.0`.
Run `npm install` in both the `frontend` and `contracts` folders.
Node version 20 is required.

### Start a local node

Expand All @@ -19,13 +19,25 @@ era_test_node run

### Deploying the Contracts

Make a `.env` file and add a private key for a [pre-configured rich wallet](https://docs.zksync.io/build/test-and-debug/in-memory-node#pre-configured-rich-wallets).

```env
WALLET_PRIVATE_KEY=<0x_YOUR_PRIVATE_KEY>
```

Deploy the AAFactory, paymaster, and NFT contracts:

```shell
npm run deploy
```

Once deployed, update the addresses in `frontend/utils/constants.ts`.
Once deployed, create a `frontend/.env.local` file based example in `frontend/.env.example` and add the deployed addresses.

```env
NEXT_PUBLIC_AA_FACTORY_ADDRESS=<0x_YOUR_AA_CONTRACT_ADDRESS>
NEXT_PUBLIC_NFT_CONTRACT_ADDRESS=<0x_YOUR_NFT_CONTRACT_ADDRESS>
NEXT_PUBLIC_PAYMASTER_ADDRESS=<0x_YOUR_PAYMASTER_CONTRACT_ADDRESS>
```

### Deploying a New Smart Account

Expand Down
25 changes: 13 additions & 12 deletions code/webauthn/contracts/deploy/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { utils, Wallet, Provider } from 'zksync-ethers';
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
import { Deployer } from '@matterlabs/hardhat-zksync';
// load env file
import dotenv from 'dotenv';
import { ethers } from 'ethers';
Expand All @@ -12,29 +11,31 @@ export default async function (hre: HardhatRuntimeEnvironment) {
// @ts-expect-error target config file which can be testnet or local
const provider = new Provider(hre.network.config.url);
const wallet = new Wallet(DEPLOYER_PRIVATE_KEY, provider);
const deployer = new Deployer(hre, wallet);

// deploy the AA Factory & test deploying an account
await deployAAFactory(deployer);
await deployAAFactory(hre.deployer);
// deploy the NFT contract
await deployMyNFT(deployer);
await deployMyNFT(hre.deployer);
// deploy the Paymaster contract
await deployPaymaster(deployer, wallet);
await deployPaymaster(hre.deployer, wallet);
}

async function deployAAFactory(deployer: Deployer) {
async function deployAAFactory(deployer: HardhatRuntimeEnvironment['deployer']) {
const factoryArtifact = await deployer.loadArtifact('AAFactory');
const aaArtifact = await deployer.loadArtifact('Account');

const factory = await deployer.deploy(factoryArtifact, [utils.hashBytecode(aaArtifact.bytecode)], undefined, [
aaArtifact.bytecode,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
] as any);
const factory = await deployer.deploy(
factoryArtifact,
[utils.hashBytecode(aaArtifact.bytecode)],
undefined,
undefined,
[aaArtifact.bytecode]
);
const factoryAddress = await factory.getAddress();
console.log(`AA factory address: ${factoryAddress}`);
}

async function deployMyNFT(deployer: Deployer) {
async function deployMyNFT(deployer: HardhatRuntimeEnvironment['deployer']) {
const artifact = await deployer.loadArtifact('MyNFT');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const constructorArguments: any[] = [];
Expand All @@ -46,7 +47,7 @@ async function deployMyNFT(deployer: Deployer) {
console.log('DONE MINTING');
}

async function deployPaymaster(deployer: Deployer, wallet: Wallet) {
async function deployPaymaster(deployer: HardhatRuntimeEnvironment['deployer'], wallet: Wallet) {
const artifact = await deployer.loadArtifact('GeneralPaymaster');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const constructorArguments: any[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: Learn how to sign transactions with WebAuthn.
- Make sure your machine satisfies the [system
requirements](https://github.com/matter-labs/era-compiler-solidity/tree/main#system-requirements).
- You should have the latest version of Google Chrome installed.
- You should have [Node.js](https://nodejs.org/en/download) installed.
- You should have [Node.js](https://nodejs.org/en/download) version `20.16.0` installed.
- You should have [`era_test_node`](https://docs.zksync.io/build/test-and-debug/in-memory-node#install-and-set-up-era_test_node) installed.
- If you aren't familiar with paymasters and smart accounts on ZKsync Era, check out the
[General Paymaster](https://docs.zksync.io/build/start-coding/zksync-101/paymaster) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ Finally, it calls the `callVerifier` function to call the `P256Verify` precompil

The `callVerifier` function encodes the input into the correct format and calls the `P256Verify` precompile.

If the returned output is empty, the validation evaluated to false.
If the returned output is empty, the precompile validation evaluated to false.
This means that the public key derived from the WebAuthn signature does not match the registered `r1Owner` public key.

The output data should be 1 (in 32 bytes format) if the signature verification process succeeds, or nothing if it fails.
Expand Down

0 comments on commit 03f46dc

Please sign in to comment.