mirror of
https://github.com/0xbow-io/privacy-pools-core.git
synced 2026-01-09 01:17:58 -05:00
chore: update relayer with sdk package (#82)
This commit is contained in:
5
.github/workflows/circuits.yml
vendored
5
.github/workflows/circuits.yml
vendored
@@ -43,6 +43,11 @@ jobs:
|
||||
- name: Print Circom version
|
||||
run: circom --version
|
||||
|
||||
- name: Setup .npmrc file
|
||||
run: |
|
||||
echo "@defi-wonderland:registry=https://npm.pkg.github.com" > .npmrc
|
||||
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PKG_REGISTRY_TOKEN }}" >> .npmrc
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn
|
||||
|
||||
|
||||
26
.github/workflows/contracts.yml
vendored
26
.github/workflows/contracts.yml
vendored
@@ -38,6 +38,11 @@ jobs:
|
||||
node-version: 20.x
|
||||
cache: "yarn"
|
||||
|
||||
- name: Setup .npmrc file
|
||||
run: |
|
||||
echo "@defi-wonderland:registry=https://npm.pkg.github.com" > .npmrc
|
||||
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PKG_REGISTRY_TOKEN }}" >> .npmrc
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --frozen-lockfile --network-concurrency 1
|
||||
|
||||
@@ -65,6 +70,12 @@ jobs:
|
||||
node-version: 20.x
|
||||
cache: "yarn"
|
||||
|
||||
- name: Setup .npmrc file
|
||||
run: |
|
||||
echo "@defi-wonderland:registry=https://npm.pkg.github.com" > .npmrc
|
||||
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PKG_REGISTRY_TOKEN }}" >> .npmrc
|
||||
working-directory: .
|
||||
|
||||
- name: Install root dependencies
|
||||
run: yarn --frozen-lockfile --network-concurrency 1
|
||||
working-directory: .
|
||||
@@ -105,6 +116,11 @@ jobs:
|
||||
node-version: 20.x
|
||||
cache: "yarn"
|
||||
|
||||
- name: Setup .npmrc file
|
||||
run: |
|
||||
echo "@defi-wonderland:registry=https://npm.pkg.github.com" > .npmrc
|
||||
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PKG_REGISTRY_TOKEN }}" >> .npmrc
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --frozen-lockfile --network-concurrency 1
|
||||
|
||||
@@ -136,6 +152,11 @@ jobs:
|
||||
node-version: 20.x
|
||||
cache: "yarn"
|
||||
|
||||
- name: Setup .npmrc file
|
||||
run: |
|
||||
echo "@defi-wonderland:registry=https://npm.pkg.github.com" > .npmrc
|
||||
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PKG_REGISTRY_TOKEN }}" >> .npmrc
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --frozen-lockfile --network-concurrency 1
|
||||
|
||||
@@ -162,6 +183,11 @@ jobs:
|
||||
- name: Install Yarn
|
||||
run: npm install -g yarn
|
||||
|
||||
- name: Setup .npmrc file
|
||||
run: |
|
||||
echo "@defi-wonderland:registry=https://npm.pkg.github.com" > .npmrc
|
||||
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PKG_REGISTRY_TOKEN }}" >> .npmrc
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --frozen-lockfile --network-concurrency 1
|
||||
|
||||
|
||||
16
.github/workflows/relayer.yml
vendored
16
.github/workflows/relayer.yml
vendored
@@ -27,11 +27,15 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Build sdk
|
||||
run: cd ../sdk && yarn install && yarn build
|
||||
- name: Setup .npmrc file
|
||||
run: |
|
||||
echo "@defi-wonderland:registry=https://npm.pkg.github.com" > .npmrc
|
||||
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PKG_REGISTRY_TOKEN }}" >> .npmrc
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --frozen-lockfile --network-concurrency 1
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Run Build
|
||||
run: yarn build
|
||||
@@ -51,11 +55,15 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Build sdk
|
||||
run: cd ../sdk && yarn install && yarn build
|
||||
- name: Setup .npmrc file
|
||||
run: |
|
||||
echo "@defi-wonderland:registry=https://npm.pkg.github.com" > .npmrc
|
||||
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PKG_REGISTRY_TOKEN }}" >> .npmrc
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Run tests with coverage
|
||||
run: yarn test:cov
|
||||
|
||||
10
.github/workflows/sdk.yml
vendored
10
.github/workflows/sdk.yml
vendored
@@ -27,6 +27,11 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Setup .npmrc file
|
||||
run: |
|
||||
echo "@defi-wonderland:registry=https://npm.pkg.github.com" > .npmrc
|
||||
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PKG_REGISTRY_TOKEN }}" >> .npmrc
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --frozen-lockfile --network-concurrency 1
|
||||
|
||||
@@ -45,6 +50,11 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Setup .npmrc file
|
||||
run: |
|
||||
echo "@defi-wonderland:registry=https://npm.pkg.github.com" > .npmrc
|
||||
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PKG_REGISTRY_TOKEN }}" >> .npmrc
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
"packages/sdk",
|
||||
"packages/relayer"
|
||||
],
|
||||
"scripts": {
|
||||
"docker:build:relayer": "docker build -f packages/relayer/Dockerfile -t privacy-pool/relayer ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "7.18.0",
|
||||
"@typescript-eslint/parser": "7.18.0",
|
||||
|
||||
4
packages/relayer/.gitignore
vendored
4
packages/relayer/.gitignore
vendored
@@ -1 +1,5 @@
|
||||
**/dist
|
||||
.npmrc
|
||||
|
||||
## Relayer configuration file
|
||||
config.json
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
FROM node:23 AS sdk-builder
|
||||
WORKDIR /build
|
||||
COPY ./package.json ./yarn.lock ./tsconfig.base.json .
|
||||
COPY ./packages/sdk/package.json ./packages/sdk/tsconfig.build.json ./packages/sdk/
|
||||
RUN yarn install
|
||||
COPY ./packages/sdk/configs/ ./packages/sdk/configs/
|
||||
COPY ./packages/sdk/src/ ./packages/sdk/src/
|
||||
RUN cd ./packages/sdk && yarn install && yarn build
|
||||
FROM node:23
|
||||
|
||||
FROM sdk-builder AS final
|
||||
COPY ./packages/relayer/package.json ./packages/relayer/tsconfig.build.json ./packages/relayer/
|
||||
WORKDIR /build
|
||||
RUN yarn global add typescript
|
||||
|
||||
# Copy package files
|
||||
COPY package.json .npmrc tsconfig.build.json config.json ./
|
||||
RUN yarn install
|
||||
COPY ./packages/relayer/src/ ./packages/relayer/src/
|
||||
RUN cd ./packages/relayer && yarn install && yarn build
|
||||
WORKDIR packages/relayer
|
||||
EXPOSE 3000:3000
|
||||
ENTRYPOINT ["node", "./dist/src/index.js"]
|
||||
|
||||
COPY src/ ./src/
|
||||
RUN yarn build
|
||||
|
||||
EXPOSE 3000
|
||||
CMD ["node", "dist/src/index.js"]
|
||||
|
||||
@@ -3,11 +3,11 @@ services:
|
||||
network_mode: host
|
||||
user: 1000:1000
|
||||
build:
|
||||
context: ../../
|
||||
dockerfile: packages/relayer/Dockerfile
|
||||
context: .
|
||||
dockerfile: ./Dockerfile
|
||||
volumes:
|
||||
- /tmp/pp_relayer.sqlite:/pp_relayer.sqlite
|
||||
- ./config.example.json:/build/packages/relayer/config.json
|
||||
- ./config.example.json:/build/config.json
|
||||
- ../circuits/artifacts:/build/node_modules/@defi-wonderland/privacy-pool-core-sdk/dist/node/artifacts
|
||||
ports:
|
||||
- "3000:3000" # HOST:CONTAINER
|
||||
|
||||
@@ -28,10 +28,12 @@
|
||||
"lint": "eslint \"{src,test}/**/*.{js,ts,json}\"",
|
||||
"lint:fix": "eslint \"{src,test}/**/*.{js,ts,json}\" --fix",
|
||||
"test": "vitest run --config vitest.config.ts --passWithNoTests",
|
||||
"test:cov": "vitest run --config vitest.config.ts --coverage"
|
||||
"test:cov": "vitest run --config vitest.config.ts --coverage",
|
||||
"docker:build": "docker-compose build",
|
||||
"docker:run": "docker-compose up"
|
||||
},
|
||||
"dependencies": {
|
||||
"@defi-wonderland/privacy-pool-core-sdk": "0.1.0",
|
||||
"@defi-wonderland/privacy-pool-core-sdk": "0.0.0-6d725b16",
|
||||
"ajv": "8.17.1",
|
||||
"body-parser": "1.20.3",
|
||||
"express": "4.21.2",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Hash } from "@defi-wonderland/privacy-pool-core-sdk";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import { getAddress } from "viem";
|
||||
import { ValidationError } from "../../exceptions/base.exception.js";
|
||||
@@ -22,9 +21,9 @@ function relayRequestBodyToWithdrawalPayload(
|
||||
): WithdrawalPayload {
|
||||
const proof = { ...body.proof, protocol: "groth16", curve: "bn128" };
|
||||
const publicSignals = body.publicSignals;
|
||||
const scope = BigInt(body.scope);
|
||||
const withdrawal = {
|
||||
processooor: getAddress(body.withdrawal.processooor),
|
||||
scope: BigInt(body.withdrawal.scope) as Hash,
|
||||
data: body.withdrawal.data as `0x{string}`,
|
||||
};
|
||||
const wp = {
|
||||
@@ -33,6 +32,7 @@ function relayRequestBodyToWithdrawalPayload(
|
||||
publicSignals,
|
||||
},
|
||||
withdrawal,
|
||||
scope,
|
||||
};
|
||||
return wp;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,6 @@ export interface WithdrawPublicSignals {
|
||||
export interface WithdrawalRelayerPayload {
|
||||
/** Relayer address (0xAdDrEsS) */
|
||||
processooor: string;
|
||||
/** Relayer scope (bigint as string) */
|
||||
scope: string;
|
||||
/** Transaction data (hex encoded) */
|
||||
data: string;
|
||||
}
|
||||
@@ -56,6 +54,8 @@ export interface RelayRequestBody {
|
||||
publicSignals: string[];
|
||||
/** Proof details */
|
||||
proof: ProofRelayerPayload;
|
||||
/** Pool scope */
|
||||
scope: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,6 +64,7 @@ export interface RelayRequestBody {
|
||||
export interface WithdrawalPayload {
|
||||
readonly proof: WithdrawalProof;
|
||||
readonly withdrawal: Withdrawal;
|
||||
readonly scope: bigint;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
Withdrawal,
|
||||
WithdrawalProof,
|
||||
SDKError,
|
||||
type Hash,
|
||||
} from "@defi-wonderland/privacy-pool-core-sdk";
|
||||
import { Address } from "viem";
|
||||
import {
|
||||
@@ -74,8 +75,8 @@ export class SdkProvider implements SdkProviderInterface {
|
||||
* @param {Withdrawal} withdrawal - The withdrawal object.
|
||||
* @returns {string} - The calculated context.
|
||||
*/
|
||||
calculateContext(withdrawal: Withdrawal): string {
|
||||
return calculateContext(withdrawal);
|
||||
calculateContext(withdrawal: Withdrawal, scope: bigint): string {
|
||||
return calculateContext(withdrawal, scope as Hash);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,10 +11,9 @@ const relayRequestSchema: JSONSchemaType<RelayRequestBody> = {
|
||||
type: "object",
|
||||
properties: {
|
||||
processooor: { type: "string" },
|
||||
scope: { type: "string" },
|
||||
data: { type: "string", pattern: "0x[0-9a-fA-F]+" },
|
||||
},
|
||||
required: ["processooor", "scope", "data"],
|
||||
required: ["processooor", "data"],
|
||||
},
|
||||
publicSignals: {
|
||||
type: "array",
|
||||
@@ -41,8 +40,9 @@ const relayRequestSchema: JSONSchemaType<RelayRequestBody> = {
|
||||
},
|
||||
required: ["pi_a", "pi_b", "pi_c"],
|
||||
},
|
||||
scope: { type: "string" },
|
||||
},
|
||||
required: ["withdrawal", "proof", "publicSignals"],
|
||||
required: ["withdrawal", "proof", "publicSignals", "scope"],
|
||||
} as const;
|
||||
|
||||
export const validateRelayRequestBody = ajv.compile(relayRequestSchema);
|
||||
|
||||
@@ -142,7 +142,7 @@ export class PrivacyPoolRelayer {
|
||||
}
|
||||
|
||||
const withdrawalContext = BigInt(
|
||||
this.sdkProvider.calculateContext(wp.withdrawal),
|
||||
this.sdkProvider.calculateContext(wp.withdrawal, wp.scope),
|
||||
);
|
||||
if (proofSignals.context !== withdrawalContext) {
|
||||
throw WithdrawalValidationError.contextMismatch(
|
||||
@@ -150,9 +150,7 @@ export class PrivacyPoolRelayer {
|
||||
);
|
||||
}
|
||||
|
||||
const { assetAddress } = await this.sdkProvider.scopeData(
|
||||
wp.withdrawal.scope,
|
||||
);
|
||||
const { assetAddress } = await this.sdkProvider.scopeData(wp.scope);
|
||||
const MIN_WITHDRAW_DEFAULT = 100_000n;
|
||||
const minWithdrawAmount =
|
||||
WITHDRAW_AMOUNTS[assetAddress] ?? MIN_WITHDRAW_DEFAULT;
|
||||
|
||||
@@ -10,7 +10,7 @@ export interface SdkProviderInterface {
|
||||
broadcastWithdrawal(
|
||||
withdrawalPayload: WithdrawalPayload,
|
||||
): Promise<{ hash: string }>;
|
||||
calculateContext(withdrawal: Withdrawal): string;
|
||||
calculateContext(withdrawal: Withdrawal, scope: bigint): string;
|
||||
scopeData(
|
||||
scope: bigint,
|
||||
): Promise<{ poolAddress: Address; assetAddress: Address }>;
|
||||
|
||||
@@ -121,19 +121,19 @@ describe("PrivacyPoolRelayer", () => {
|
||||
const withdrawalPayload: WithdrawalPayload = {
|
||||
withdrawal: {
|
||||
processooor: ENTRYPOINT_ADDRESS_TEST,
|
||||
scope: 0x5c0fen, // correct == 0n
|
||||
data: dataCorrect,
|
||||
},
|
||||
proof: {
|
||||
proof: "" as WithdrawalProof,
|
||||
publicSignals: PUBLIC_SIGNALS_TEST,
|
||||
},
|
||||
scope: BigInt(0x5c0fen), // correct == 0n
|
||||
};
|
||||
await expect(() =>
|
||||
service.validateWithdrawal(withdrawalPayload),
|
||||
).rejects.toThrowError(
|
||||
WithdrawalValidationError.contextMismatch(
|
||||
'Context mismatch: expected "1f9bd92c080e8d7b883a75bf2da8e2832a8041e320facaf301ca87abc544e5db", got "85bb30f63789e69035080816ae268a74e87b221245153876134a3f39e04b799".',
|
||||
'Context mismatch: expected "2ccc7ebae3d6e0489846523cad0cef023986027fc089dc4ce57f9ed644c5f185", got "85bb30f63789e69035080816ae268a74e87b221245153876134a3f39e04b799".',
|
||||
),
|
||||
);
|
||||
});
|
||||
@@ -141,16 +141,18 @@ describe("PrivacyPoolRelayer", () => {
|
||||
it("raises withdrawn value too small", async () => {
|
||||
const publicSignals = [...PUBLIC_SIGNALS_TEST];
|
||||
publicSignals[2] = 100n;
|
||||
publicSignals[7] =
|
||||
10793626036679745516481859563284572555060983750341001924900435534433131367129n;
|
||||
const withdrawalPayload: WithdrawalPayload = {
|
||||
withdrawal: {
|
||||
processooor: ENTRYPOINT_ADDRESS_TEST,
|
||||
scope: 0n,
|
||||
data: dataCorrect,
|
||||
},
|
||||
proof: {
|
||||
proof: "" as WithdrawalProof,
|
||||
publicSignals,
|
||||
},
|
||||
scope: 0n,
|
||||
};
|
||||
|
||||
vi.spyOn(Config, "WITHDRAW_AMOUNTS", "get").mockReturnValue({
|
||||
@@ -175,16 +177,20 @@ describe("PrivacyPoolRelayer", () => {
|
||||
});
|
||||
|
||||
it("validates with no issues", async () => {
|
||||
const publicSignals = PUBLIC_SIGNALS_TEST;
|
||||
publicSignals[7] =
|
||||
10793626036679745516481859563284572555060983750341001924900435534433131367129n;
|
||||
|
||||
const withdrawalPayload: WithdrawalPayload = {
|
||||
withdrawal: {
|
||||
processooor: ENTRYPOINT_ADDRESS_TEST,
|
||||
scope: 0n,
|
||||
data: dataCorrect,
|
||||
},
|
||||
proof: {
|
||||
proof: "" as WithdrawalProof,
|
||||
publicSignals: PUBLIC_SIGNALS_TEST,
|
||||
publicSignals: publicSignals,
|
||||
},
|
||||
scope: 0n,
|
||||
};
|
||||
vi.spyOn(Config, "WITHDRAW_AMOUNTS", "get").mockReturnValue({
|
||||
[ASSET_ADDRESS_TEST]: 50n,
|
||||
@@ -205,14 +211,15 @@ describe("PrivacyPoolRelayer", () => {
|
||||
const withdrawalPayload: WithdrawalPayload = {
|
||||
withdrawal: {
|
||||
processooor: ENTRYPOINT_ADDRESS_TEST,
|
||||
scope: 0n,
|
||||
data: dataCorrect,
|
||||
},
|
||||
proof: {
|
||||
proof: "" as WithdrawalProof,
|
||||
publicSignals: PUBLIC_SIGNALS_TEST,
|
||||
},
|
||||
scope: 0n,
|
||||
};
|
||||
|
||||
const dbMock = createDbMock();
|
||||
const sdkProviderMock = createSdkProviderMock();
|
||||
|
||||
@@ -243,13 +250,13 @@ describe("PrivacyPoolRelayer", () => {
|
||||
const withdrawalPayload: WithdrawalPayload = {
|
||||
withdrawal: {
|
||||
processooor: ENTRYPOINT_ADDRESS_TEST,
|
||||
scope: 0n,
|
||||
data: dataCorrect,
|
||||
},
|
||||
proof: {
|
||||
proof: "" as WithdrawalProof,
|
||||
publicSignals: PUBLIC_SIGNALS_TEST,
|
||||
},
|
||||
scope: 0n,
|
||||
};
|
||||
|
||||
it("when verification fails", async () => {
|
||||
|
||||
@@ -1,11 +1,30 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"declarationMap": true,
|
||||
"declaration": true,
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist", "test"]
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"declarationMap": true,
|
||||
"declaration": true,
|
||||
"outDir": "dist",
|
||||
/* Base Options: */
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"target": "es2022",
|
||||
"allowJs": true,
|
||||
"resolveJsonModule": true,
|
||||
"moduleDetection": "force",
|
||||
"isolatedModules": true,
|
||||
"verbatimModuleSyntax": false,
|
||||
/* Strictness */
|
||||
"strict": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"useUnknownInCatchVariables": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noImplicitOverride": true,
|
||||
/* If transpiling with TypeScript: */
|
||||
"module": "NodeNext",
|
||||
"sourceMap": true,
|
||||
/* If your code doesn't run in the DOM: */
|
||||
"lib": ["es2022"]
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist", "test"]
|
||||
}
|
||||
|
||||
11
yarn.lock
11
yarn.lock
@@ -351,6 +351,17 @@
|
||||
solc-typed-ast "18.1.6"
|
||||
yargs "17.7.2"
|
||||
|
||||
"@defi-wonderland/privacy-pool-core-sdk@0.0.0-6d725b16":
|
||||
version "0.0.0-6d725b16"
|
||||
resolved "https://npm.pkg.github.com/download/@defi-wonderland/privacy-pool-core-sdk/0.0.0-6d725b16/8d562f2c1126716a45cb74159670372239d3b977#8d562f2c1126716a45cb74159670372239d3b977"
|
||||
integrity sha512-BZwBzEM+40zthjjZZ/b6+niKEn57NKyGR8PnhYbIsy1TuKYKjtDhGUbpWA9rJFF+kN3pAILzatlYWy38MTH26Q==
|
||||
dependencies:
|
||||
"@types/snarkjs" "0.7.9"
|
||||
"@zk-kit/lean-imt" "2.2.2"
|
||||
maci-crypto "2.5.0"
|
||||
snarkjs "0.7.5"
|
||||
viem "2.22.14"
|
||||
|
||||
"@esbuild/aix-ppc64@0.24.2":
|
||||
version "0.24.2"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/aix-ppc64/-/aix-ppc64-0.24.2.tgz#38848d3e25afe842a7943643cbcd387cc6e13461"
|
||||
|
||||
Reference in New Issue
Block a user