-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Martin/zkpassport demo #8059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mverzilli
wants to merge
11
commits into
Uniswap:main
Choose a base branch
from
mverzilli:martin/zkpassport-demo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Martin/zkpassport demo #8059
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3d27f59
feat: Gate Toucan auctions with ZKPassport policy verification
mverzilli 0b2aebd
ci: Deploy the demo to Vercel with a basic-auth gate
mverzilli 72c5a05
ci: Route gateway calls through the same-origin proxy in demo builds
mverzilli 60cf303
feat: Encode CCA bids on-chain when the liquidity backend is unreachable
mverzilli ae620fb
feat: Assemble auction launches on-chain via the liquidity-launcher SDK
mverzilli 22cd582
fix: Resolve the ZKPassport gate over sessionless public RPC
mverzilli 4cd3934
fix: Point the sepolia gate at the popup-domain attest registry
mverzilli 958fae1
fix: Navigate to the receipt-derived auction address after launch
mverzilli 2dc16b4
fix: Skip the backend bid dry-run when bids are encoded on-chain
mverzilli 68f6de8
feat(web): Open ZKPassport verification via the hosted verify-popup p…
mverzilli bdb7c50
Open the ZKPassport popup as a tab and let it choose the mint account
mverzilli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/usr/bin/env node | ||
| // Injects a basic-auth edge middleware into a Vercel Build Output API v3 | ||
| // bundle (.vercel/output) after the build, so the demo deployment is gated | ||
| // without touching any app code. The gate only engages when the Vercel | ||
| // project defines BASIC_AUTH_CREDENTIALS ("user:pass"); without it the | ||
| // middleware passes every request through. | ||
| import { mkdirSync, readFileSync, writeFileSync } from 'node:fs' | ||
| import { resolve } from 'node:path' | ||
|
|
||
| const outputDir = process.argv[2] | ||
| if (!outputDir) { | ||
| console.error('Usage: inject-basic-auth.mjs <path to .vercel/output>') | ||
| process.exit(1) | ||
| } | ||
|
|
||
| const configPath = resolve(outputDir, 'config.json') | ||
| const config = JSON.parse(readFileSync(configPath, 'utf8')) | ||
|
|
||
| // The middleware route must come first so it runs before the static | ||
| // filesystem handler and the serverless function routes. | ||
| if (!config.routes?.some((route) => route.middlewarePath === '_middleware')) { | ||
| config.routes = [ | ||
| { src: '/(.*)', middlewarePath: '_middleware', continue: true }, | ||
| ...(config.routes ?? []), | ||
| ] | ||
| } | ||
| writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`) | ||
|
|
||
| const middlewareSource = `export default function middleware(request) { | ||
| const credentials = process.env.BASIC_AUTH_CREDENTIALS | ||
| if (!credentials) { | ||
| return new Response(null, { headers: { 'x-middleware-next': '1' } }) | ||
| } | ||
| const header = request.headers.get('authorization') ?? '' | ||
| const [scheme, token, ...rest] = header.split(' ') | ||
| const authorized = | ||
| Boolean(scheme && token) && | ||
| rest.length === 0 && | ||
| scheme.toLowerCase() === 'basic' && | ||
| token === btoa(credentials) | ||
| if (authorized) { | ||
| return new Response(null, { headers: { 'x-middleware-next': '1' } }) | ||
| } | ||
| return new Response('Authentication required', { | ||
| status: 401, | ||
| headers: { 'WWW-Authenticate': 'Basic realm="uniswap-zkpassport-demo"' }, | ||
| }) | ||
| } | ||
| ` | ||
|
|
||
| const funcDir = resolve(outputDir, 'functions/_middleware.func') | ||
| mkdirSync(funcDir, { recursive: true }) | ||
| writeFileSync( | ||
| resolve(funcDir, '.vc-config.json'), | ||
| `${JSON.stringify( | ||
| { runtime: 'edge', entrypoint: 'index.js', envVarsInUse: ['BASIC_AUTH_CREDENTIALS'] }, | ||
| null, | ||
| 2, | ||
| )}\n`, | ||
| ) | ||
| writeFileSync(resolve(funcDir, 'index.js'), middlewareSource) | ||
|
|
||
| console.log(`[inject-basic-auth] Edge middleware injected into ${outputDir}`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # Builds the web app and ships it to Vercel as a prebuilt deployment. | ||
| # Lives only on the ZKPassport demo branch; requires repo secrets | ||
| # VERCEL_TOKEN, VERCEL_ORG_ID, VERCEL_PROJECT_ID and repo variables | ||
| # ZKPASSPORT_POPUP_URL, ZKPASSPORT_CREATE_POLICY_URL. Optional repo | ||
| # variables ZKPASSPORT_ATTEST_REGISTRY_SEPOLIA and | ||
| # ZKPASSPORT_ATTEST_DEPLOY_BLOCK_SEPOLIA override the registry baked | ||
| # into apps/web ZkPassport/config.ts without a commit (set both, then | ||
| # re-run this workflow). | ||
| name: Deploy demo to Vercel | ||
|
|
||
| on: | ||
| push: | ||
| branches: [martin/zkpassport-demo] | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: deploy-demo | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 45 | ||
| env: | ||
| VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | ||
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version-file: .nvmrc | ||
|
|
||
| - uses: oven-sh/setup-bun@v2 | ||
| with: | ||
| bun-version: 1.3.14 | ||
|
|
||
| - name: Check required configuration | ||
| env: | ||
| POPUP_URL: ${{ vars.ZKPASSPORT_POPUP_URL }} | ||
| CREATE_POLICY_URL: ${{ vars.ZKPASSPORT_CREATE_POLICY_URL }} | ||
| run: | | ||
| test -n "$POPUP_URL" || { echo "Repo variable ZKPASSPORT_POPUP_URL is not set"; exit 1; } | ||
| test -n "$CREATE_POLICY_URL" || { echo "Repo variable ZKPASSPORT_CREATE_POLICY_URL is not set"; exit 1; } | ||
|
|
||
| - name: Install dependencies | ||
| run: bun install --frozen-lockfile | ||
|
|
||
| # Values here are not secrets: a placeholder WalletConnect id (extension | ||
| # wallets work without a real one), blanked Privy ids so the provider is | ||
| # skipped, and the public demo URLs. | ||
| - name: Write env overrides | ||
| working-directory: apps/web | ||
| env: | ||
| POPUP_URL: ${{ vars.ZKPASSPORT_POPUP_URL }} | ||
| CREATE_POLICY_URL: ${{ vars.ZKPASSPORT_CREATE_POLICY_URL }} | ||
| ATTEST_REGISTRY: ${{ vars.ZKPASSPORT_ATTEST_REGISTRY_SEPOLIA }} | ||
| ATTEST_DEPLOY_BLOCK: ${{ vars.ZKPASSPORT_ATTEST_DEPLOY_BLOCK_SEPOLIA }} | ||
| run: | | ||
| cat > .env.override <<EOF | ||
| WALLETCONNECT_PROJECT_ID="walletconnect_project_id" | ||
| PRIVY_APP_ID="" | ||
| PRIVY_CLIENT_ID="" | ||
| ENABLE_ENTRY_GATEWAY_PROXY="true" | ||
| ZKPASSPORT_ONCHAIN_BIDS="true" | ||
| ZKPASSPORT_ONCHAIN_LAUNCH="true" | ||
| ZKPASSPORT_POPUP_URL="$POPUP_URL" | ||
| ZKPASSPORT_CREATE_POLICY_URL="$CREATE_POLICY_URL" | ||
| EOF | ||
| # An empty define would win over the ?? fallback in config.ts, so | ||
| # only write the registry override when the variable is set. | ||
| if [ -n "$ATTEST_REGISTRY" ]; then | ||
| echo "ZKPASSPORT_ATTEST_REGISTRY_SEPOLIA=\"$ATTEST_REGISTRY\"" >> .env.override | ||
| fi | ||
| if [ -n "$ATTEST_DEPLOY_BLOCK" ]; then | ||
| echo "ZKPASSPORT_ATTEST_DEPLOY_BLOCK_SEPOLIA=\"$ATTEST_DEPLOY_BLOCK\"" >> .env.override | ||
| fi | ||
|
|
||
| - name: Build | ||
| env: | ||
| SKIP_CONFIG_PULL: "true" | ||
| run: bunx nx run @universe/web:build:vercel | ||
|
|
||
| - name: Inject basic-auth middleware | ||
| run: node .github/scripts/inject-basic-auth.mjs apps/web/.vercel/output | ||
|
|
||
| - name: Deploy | ||
| working-directory: apps/web | ||
| env: | ||
| VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | ||
| run: bunx vercel deploy --prebuilt --prod --token="$VERCEL_TOKEN" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "files": [] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "files": [] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "files": [] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semgrep identified an issue in your code:
An action sourced from a third-party repository on GitHub is not pinned to a full length commit SHA. Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps mitigate the risk of a bad actor adding a backdoor to the action's repository, as they would need to generate a SHA-1 collision for a valid Git object payload. Github, foundry, and uniswap made github actions are exempt.
To resolve this comment:
✨ Commit fix suggestion
View step-by-step instructions
v2release ofoven-sh/setup-bunfrom its official repository or release tag.- uses: oven-sh/setup-bun@<40-character-commit-sha> # v2bun-version: 1.3.14unchanged so the workflow continues to install the intended Bun version.💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasonsAlternatively, triage in Semgrep AppSec Platform to ignore the finding created by third-party-action-not-pinned-to-commit-sha-foundry-allowed.
You can view more details about this finding in the Semgrep AppSec Platform.