Skip to content

Commit 1812b38

Browse files
cpb8010MexicanAce
andauthored
feat: new passkey signature format (#58)
* feat: new passkey signature format includes the credential id, which is hopefully available * fix: update to include credential id on creation Also update contracts locally * chore: update to latest contracts * fix: update lockfile from contract dep change * fix: import for utils * fix: update signature format tests It doesn't look correct visually, but it's mocked on both ends so it's not super clear on what it's testing * feat: attempt to use new dynamic contract addresses When deploying the contracts, it should create the file, blocking the build * fix: provide an example file Can have a different test to make sure this gets updated or put the contract build step into the other builds * fix: add create2 to nft deploy Try encoding the local contracts directly instead of via env vars doesn't appear to work locally... * fix: encode passkey id as bytes This was correct on creation, but wrong on signing * chore: update to latest contract * fix: update hardcoded signatures for passkey view This was super tough to find and would have been a compile error had we imported the abi directly from the contracts! This is something I'm going to look into so we don't lose our minds * fix: remove debugging changes You just have to know that the quest address is added via .env.local so the object in the config isn't used * feat: attempt to import abi automatically Having to manually update the ABI kinda defeats the point of type safety, but it's clear the auto-generated one doesn't play nice with the existing file so more work will be necessary to update it so it's compatible * fix: use view function to get key Picks up a fix from the publish function for the correct abi * fix: remove publish from CI It looks like nuxt builds don't like the poorly formatted json, so instead of trying to pretty print the abi automatically we'll rely on the editor tools to do this. At the very least the publish step is documented? * fix: update import names problem was not the file format, but the file name change * fix: use pnpm run build instead of build CI is behaving strange? * fix: use correct contract branch * fix: pull contract directory in CI This explains why the build was failing * feat: setup local node for deploy This should be fine because we aren't actually using it * [wip] Add application metadata (#82) * feat: provide auth-server metadata Can be helpful for custom auth-server implementions that want extra data * fix: use a record instead of an array of records There's not really much extra flexibility here, so just keep it simple * fix: update demo app with new metadata format * Update packages/auth-server/components/session/Metadata.vue --------- Co-authored-by: Nicolas Villanueva <1890113+MexicanAce@users.noreply.github.com> * fix: update to breaking factory change This was already fixed during guardian module work * fix: update ABI breaking name and argument changes were not published Added publish step to readme * fix: update new variable name now automatically checked via types! * fix: update test mock The log parsing format is broken because the return type changed, but regenerating the log format is non-trival so that can be updated later. introducing #84 * fix: update account id length Updating the tests to match --------- Co-authored-by: Nicolas Villanueva <1890113+MexicanAce@users.noreply.github.com>
1 parent 24e4495 commit 1812b38

File tree

30 files changed

+885
-304
lines changed

30 files changed

+885
-304
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ jobs:
4141
run: pnpm install -r --frozen-lockfile
4242
working-directory: packages/contracts
4343

44-
- name: Build SDK
45-
run: pnpm nx build sdk
46-
4744
- name: Build contracts
4845
run: pnpm build
4946
working-directory: packages/contracts
5047

5148
- name: Deploy contracts
52-
run: pnpm run deploy
49+
run: pnpm run deploy --file ../auth-server/stores/local-node.json
5350
working-directory: packages/contracts
5451

52+
- name: Build SDK
53+
run: pnpm nx build sdk
54+
5555
- name: Install zksync-foundry
5656
run: |
5757
wget -qc https://github.com/matter-labs/foundry-zksync/releases/download/nightly/foundry_nightly_linux_amd64.tar.gz -O - | tar -xz
@@ -115,17 +115,17 @@ jobs:
115115
run: pnpm install -r --frozen-lockfile
116116
working-directory: packages/contracts
117117

118-
- name: Build SDK
119-
run: pnpm nx build sdk
120-
121118
- name: Build contracts
122119
run: pnpm build
123120
working-directory: packages/contracts
124121

125122
- name: Deploy contracts
126-
run: pnpm run deploy
123+
run: pnpm run deploy --file ../auth-server/stores/local-node.json
127124
working-directory: packages/contracts
128125

126+
- name: Build SDK
127+
run: pnpm nx build sdk
128+
129129
- name: Deploy NFT contracts
130130
run: pnpm nx deploy:local nft-quest-contracts
131131

.github/workflows/deploy-auth-server.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v4 # v4
20+
with:
21+
submodules: recursive
2022

2123
- name: Setup pnpm
2224
uses: pnpm/action-setup@v4
@@ -29,6 +31,23 @@ jobs:
2931
node-version: lts/Iron
3032
cache: 'pnpm'
3133

34+
# SDK depends on contracts
35+
- name: Install contract dependencies
36+
run: pnpm install -r --frozen-lockfile
37+
working-directory: packages/contracts
38+
39+
- name: Build contracts
40+
run: pnpm run build
41+
working-directory: packages/contracts
42+
43+
# Local node to have target for deploy
44+
- name: Era Test Node Action
45+
uses: dutterbutter/anvil-zksync-action@v1.1.0
46+
47+
- name: Deploy contracts
48+
run: pnpm run deploy --file ../auth-server/stores/local-node.json
49+
working-directory: packages/contracts
50+
3251
- name: Install dependencies
3352
run: pnpm install -r --frozen-lockfile
3453

.github/workflows/deploy-nft-quest.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v4 # v4
20+
with:
21+
submodules: recursive
2022

2123
- name: Setup pnpm
2224
uses: pnpm/action-setup@v4
@@ -32,6 +34,23 @@ jobs:
3234
- name: Install dependencies
3335
run: pnpm install -r --frozen-lockfile
3436

37+
# SDK depends on contracts
38+
- name: Install contract dependencies
39+
run: pnpm install -r --frozen-lockfile
40+
working-directory: packages/contracts
41+
42+
- name: Build contracts
43+
run: pnpm build
44+
working-directory: packages/contracts
45+
46+
# Local node to have target for deploy
47+
- name: Era Test Node Action
48+
uses: dutterbutter/anvil-zksync-action@v1.1.0
49+
50+
- name: Deploy contracts
51+
run: pnpm run deploy --file ../auth-server/stores/local-node.json
52+
working-directory: packages/contracts
53+
3554
- name: Build apps
3655
run: pnpm nx build nft-quest
3756

.github/workflows/deploy-package.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414

1515
steps:
1616
- uses: actions/checkout@v4
17+
with:
18+
submodules: recursive
1719

1820
- name: Setup pnpm
1921
uses: pnpm/action-setup@v4
@@ -29,6 +31,23 @@ jobs:
2931
- name: Install dependencies
3032
run: pnpm install -r --frozen-lockfile
3133

34+
# SDK depends on contracts
35+
- name: Install contract dependencies
36+
run: pnpm install -r --frozen-lockfile
37+
working-directory: packages/contracts
38+
39+
- name: Build contracts
40+
run: pnpm build
41+
working-directory: packages/contracts
42+
43+
# Local node to have target for deploy
44+
- name: Era Test Node Action
45+
uses: dutterbutter/anvil-zksync-action@v1.1.0
46+
47+
- name: Deploy contracts
48+
run: pnpm run deploy --file ../auth-server/stores/local-node.json
49+
working-directory: packages/contracts
50+
3251
- name: Build the package
3352
run: pnpm nx build sdk
3453

.github/workflows/deploy-preview.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
output_urls: "${{ steps.preview_deploy.outputs.urls }}"
1919
steps:
2020
- uses: actions/checkout@v4 # v4
21+
with:
22+
submodules: recursive
2123

2224
- name: Setup pnpm
2325
uses: pnpm/action-setup@v4
@@ -30,6 +32,23 @@ jobs:
3032
node-version: lts/Iron
3133
cache: 'pnpm'
3234

35+
# SDK depends on contracts
36+
- name: Install contract dependencies
37+
run: pnpm install -r --frozen-lockfile
38+
working-directory: packages/contracts
39+
40+
- name: Build contracts
41+
run: pnpm run build
42+
working-directory: packages/contracts
43+
44+
# Local node to have target for deploy
45+
- name: Era Test Node Action
46+
uses: dutterbutter/anvil-zksync-action@v1.1.0
47+
48+
- name: Deploy contracts
49+
run: pnpm run deploy --file ../auth-server/stores/local-node.json
50+
working-directory: packages/contracts
51+
3352
- name: Install dependencies
3453
run: pnpm install -r --frozen-lockfile
3554

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ This monorepo is comprised of the following packages, products, and examples:
143143
# Compile and deploy contracts
144144
cd packages/contracts
145145
pnpm build
146-
pnpm run deploy
146+
pnpm --dir packages/contracts run publish ../sdk/src/abi
147+
pnpm --dir packages/contracts run deploy --file ../auth-server/stores/local-node.json
147148
```
148149

149150
6. Start the demo application:

examples/nft-quest-contracts/deploy/deploy.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export default async function (hre: HardhatRuntimeEnvironment) {
1717
console.log("PAYMASTER CONTRACT: ", await paymasterContract.getAddress());
1818

1919
if (hre.network.config.ethNetwork.includes("localhost")) {
20+
const nftQuestAddress = await nftContract.getAddress();
21+
const paymasterContractAddress = await paymasterContract.getAddress();
22+
2023
// Update the .env.local file with the contract addresses for NFT Quest app
2124
const envFilePath = path.join(__dirname, "../../nft-quest/.env.local");
2225

@@ -25,10 +28,8 @@ export default async function (hre: HardhatRuntimeEnvironment) {
2528
fs.writeFileSync(envFilePath, "", { encoding: "utf8" });
2629
console.log(`.env.local file has been created at ${envFilePath}`);
2730
}
28-
const nftContractAddress = await nftContract.getAddress();
29-
const paymasterContractAddress = await paymasterContract.getAddress();
3031

31-
const envContent = `NUXT_PUBLIC_CONTRACTS_NFT=${nftContractAddress}\nNUXT_PUBLIC_CONTRACTS_PAYMASTER=${paymasterContractAddress}\n`;
32+
const envContent = `NUXT_PUBLIC_CONTRACTS_NFT=${nftQuestAddress}\nNUXT_PUBLIC_CONTRACTS_PAYMASTER=${paymasterContractAddress}\n`;
3233

3334
fs.writeFileSync(envFilePath, envContent, { encoding: "utf8" });
3435
console.log(`.env.local file has been updated at ${envFilePath}`);

examples/nft-quest-contracts/deploy/utils.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Deployer } from "@matterlabs/hardhat-zksync";
55
import dotenv from "dotenv";
66
import { ethers } from "ethers";
77
import * as hre from "hardhat";
8-
import { Provider, Wallet } from "zksync-ethers";
8+
import { ContractFactory, Provider, utils, Wallet } from "zksync-ethers";
99

1010
// Load env file
1111
dotenv.config();
@@ -105,23 +105,33 @@ export const deployContract = async (contractArtifactName: string, constructorAr
105105
await verifyEnoughBalance(wallet, deploymentFee);
106106

107107
// Deploy the contract to ZKsync
108-
const contract = await deployer.deploy(artifact, constructorArguments);
108+
const salt = ethers.hexlify("0x" + "0".repeat(64));
109+
const create2Deployer = new ContractFactory(artifact.abi, artifact.bytecode, wallet, "create2");
110+
const encodedArgs = create2Deployer.interface.encodeDeploy(constructorArguments);
111+
const bytecodeHash = utils.hashBytecode(artifact.bytecode);
112+
const standardCreate2Address = utils.create2Address(wallet.address, bytecodeHash, salt, constructorArguments ? encodedArgs : "0x");
113+
const accountCode = await wallet.provider.getCode(standardCreate2Address);
114+
if (accountCode != "0x") {
115+
log(`Contract ${contractArtifactName} already exists!`);
116+
return new ethers.Contract(standardCreate2Address, artifact.abi, wallet);
117+
}
118+
119+
const contract = await (constructorArguments ? create2Deployer.deploy(...constructorArguments, { customData: { salt } }) : create2Deployer.deploy({ customData: { salt } }));
109120
const address = await contract.getAddress();
110-
const constructorArgs = contract.interface.encodeDeploy(constructorArguments);
111121
const fullContractSource = `${artifact.sourceName}:${artifact.contractName}`;
112122

113123
// Display contract deployment info
114124
log(`\n"${artifact.contractName}" was successfully deployed:`);
115125
log(` - Contract address: ${address}`);
116126
log(` - Contract source: ${fullContractSource}`);
117-
log(` - Encoded constructor arguments: ${constructorArgs}\n`);
127+
log(` - Encoded constructor arguments: ${encodedArgs}\n`);
118128

119129
if (!options?.noVerify && hre.network.config.verifyURL) {
120130
log(`Requesting contract verification...`);
121131
await verifyContract({
122132
address,
123133
contract: fullContractSource,
124-
constructorArguments: constructorArgs,
134+
constructorArguments: encodedArgs,
125135
bytecode: artifact.bytecode,
126136
});
127137
}

packages/auth-server/components/session/row/Row.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<script setup lang="ts">
5656
import { HandRaisedIcon } from "@heroicons/vue/24/outline";
5757
import type { Hash } from "viem";
58-
import { SessionKeyModuleAbi } from "zksync-sso/abi";
58+
import { SessionKeyValidatorAbi } from "zksync-sso/abi";
5959
import { type SessionConfig, type SessionState, SessionStatus } from "zksync-sso/utils";
6060
6161
const props = defineProps<{
@@ -100,7 +100,7 @@ const {
100100
const client = getPublicClient({ chainId: defaultChain.id });
101101
const res = await client.readContract({
102102
address: contractsByChain[defaultChain.id].session,
103-
abi: SessionKeyModuleAbi,
103+
abi: SessionKeyValidatorAbi,
104104
functionName: "sessionState",
105105
args: [address.value!, props.session],
106106
});

packages/auth-server/composables/useAccountCreate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const useAccountCreate = (_chainId: MaybeRef<SupportedChainId>) => {
3535
const deployerClient = getThrowAwayClient({ chainId: chainId.value });
3636

3737
const deployedAccount = await deployAccount(deployerClient, {
38+
credentialId,
3839
credentialPublicKey,
3940
uniqueAccountId: credentialId,
4041
contracts: contractsByChain[chainId.value],

0 commit comments

Comments
 (0)