Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tooling-e2e-tests/ts_sdk_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ scenario() {
RELAYER_URL=${RELAYER_URL} \
TESTNET_PRIVATE_KEY=${TS_SDK_PRIVATE_KEY} \
TOKEN_CONTRACT_ADDRESSES=${TOKEN_CONTRACT_ADDRESSES} \
CRYPTO_CLIENT_TYPE=${CRYPTO_CLIENT_TYPE:-"wasm-full"} \
PROVER_SERVER_URL=${PROVER_SERVER_URL:-""} \
CHECK_NITRO_ATTESTATION=${CHECK_NITRO_ATTESTATION:-"false"} \
pnpm playwright test --config ${PLAYWRIGHT_CONFIG} ${PLAYWRIGHT_SHARDS}

cd "${ROOT_DIR}"
Expand Down
3 changes: 2 additions & 1 deletion ts/shielder-sdk-tests/playwright.multithreaded.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineConfig({
...baseConfig,
webServer: {
...baseConfig.webServer,
command: "VITE_PUBLIC_THREADS=max pnpm vite"
command:
"VITE_CRYPTO_CLIENT_TYPE=${CRYPTO_CLIENT_TYPE} VITE_PROVER_SERVER_URL=${PROVER_SERVER_URL} VITE_CHECK_NITRO_ATTESTATION=${CHECK_NITRO_ATTESTATION} VITE_PUBLIC_THREADS=max pnpm vite"
}
});
3 changes: 2 additions & 1 deletion ts/shielder-sdk-tests/playwright.singlethreaded.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineConfig({
...baseConfig,
webServer: {
...baseConfig.webServer,
command: "VITE_PUBLIC_THREADS=1 pnpm vite"
command:
"VITE_CRYPTO_CLIENT_TYPE=${CRYPTO_CLIENT_TYPE} VITE_PROVER_SERVER_URL=${PROVER_SERVER_URL} VITE_CHECK_NITRO_ATTESTATION=${CHECK_NITRO_ATTESTATION} VITE_PUBLIC_THREADS=1 pnpm vite"
}
});
13 changes: 13 additions & 0 deletions ts/shielder-sdk-tests/tests/envConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ export const tokenContractAddresses = process.env.TOKEN_CONTRACT_ADDRESSES
: (() => {
throw new Error("TOKEN_CONTRACT_ADDRESSES env not defined");
})();
export const cryptoClientType = process.env.CRYPTO_CLIENT_TYPE
? (process.env.CRYPTO_CLIENT_TYPE as "wasm-full" | "wasm-light")
: (() => {
throw new Error("CRYPTO_CLIENT_TYPE env not defined");
})();
export const proverServerUrl =
process.env.PROVER_SERVER_URL ??
(() => {
throw new Error("PROVER_SERVER_URL env not defined");
})();
export const checkNitroAttestation =
process.env.CHECK_NITRO_ATTESTATION === "true" ||
(cryptoClientType === "wasm-light" ? true : false);

export const getChainConfig = () => {
return {
Expand Down
49 changes: 11 additions & 38 deletions ts/shielder-sdk-tests/web/EntryPoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ import {
type ShielderClientConfig
} from "@cardinal-cryptography/shielder-sdk";
import type { CryptoClient } from "@cardinal-cryptography/shielder-sdk-crypto";
import { initWasmWorker } from "@cardinal-cryptography/shielder-sdk-crypto-wasm";
// import { initWasmWorker } from "@cardinal-cryptography/shielder-sdk-crypto-wasm-light";
import type { GlobalConfigFixture } from "@tests/playwrightFixtures/globalConfig";
import {
type ShielderTestFixture,
setupShielderTest
} from "./fixtures/shielderTest/setup";

import newAccountParamsUrl from "@cardinal-cryptography/shielder-sdk-crypto-wasm/keys/new_account/params.bin?url";
import newAccountPkUrl from "@cardinal-cryptography/shielder-sdk-crypto-wasm/keys/new_account/pk.bin?url";
import depositParamsUrl from "@cardinal-cryptography/shielder-sdk-crypto-wasm/keys/deposit/params.bin?url";
import depositPkUrl from "@cardinal-cryptography/shielder-sdk-crypto-wasm/keys/deposit/pk.bin?url";
import withdrawParamsUrl from "@cardinal-cryptography/shielder-sdk-crypto-wasm/keys/withdraw/params.bin?url";
import withdrawPkUrl from "@cardinal-cryptography/shielder-sdk-crypto-wasm/keys/withdraw/pk.bin?url";
import { initFullWasm, initLightWasm } from "./cryptoClient";
import {
checkNitroAttestation,
cryptoClientType,
proverServerUrl
} from "./envConfig";

declare global {
interface Window {
Expand All @@ -46,43 +43,19 @@ declare global {
}
}

async function fetchArrayBuffer(url: string): Promise<Uint8Array> {
return await fetch(url).then((r) => r.bytes());
}

function EntryPoint() {
useEffect(() => {
const initialize = async () => {
const newAccountParams = await fetchArrayBuffer(newAccountParamsUrl);
const newAccountPk = await fetchArrayBuffer(newAccountPkUrl);
const depositParams = await fetchArrayBuffer(depositParamsUrl);
const depositPk = await fetchArrayBuffer(depositPkUrl);
const withdrawParams = await fetchArrayBuffer(withdrawParamsUrl);
const withdrawPk = await fetchArrayBuffer(withdrawPkUrl);
// test fixtures initialization
window.testFixtures = window.testFixtures || {};
window.testFixtures.setupHappyTest = setupShielderTest;
// Wasm crypto client initialization
window.wasmCryptoClient = window.wasmCryptoClient || {};
window.wasmCryptoClient.cryptoClient = initWasmWorker(
"multi",
{
paramsBuf: newAccountParams,
pkBuf: newAccountPk
},
{
paramsBuf: depositParams,
pkBuf: depositPk
},
{
paramsBuf: withdrawParams,
pkBuf: withdrawPk
}
);
// window.wasmCryptoClient.cryptoClient = initWasmWorker(
// "http://51.20.132.7:3000",
// true
// );
console.log("Initializing crypto client with type:", cryptoClientType);
window.wasmCryptoClient.cryptoClient =
cryptoClientType === "wasm-full"
? initFullWasm()
: initLightWasm(proverServerUrl!, checkNitroAttestation);
// Expose shielder utilities
window.shielder = window.shielder || {};
window.shielder.createShielderClient = createShielderClient;
Expand Down
46 changes: 46 additions & 0 deletions ts/shielder-sdk-tests/web/cryptoClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import newAccountParamsUrl from "@cardinal-cryptography/shielder-sdk-crypto-wasm/keys/new_account/params.bin?url";
import newAccountPkUrl from "@cardinal-cryptography/shielder-sdk-crypto-wasm/keys/new_account/pk.bin?url";
import depositParamsUrl from "@cardinal-cryptography/shielder-sdk-crypto-wasm/keys/deposit/params.bin?url";
import depositPkUrl from "@cardinal-cryptography/shielder-sdk-crypto-wasm/keys/deposit/pk.bin?url";
import withdrawParamsUrl from "@cardinal-cryptography/shielder-sdk-crypto-wasm/keys/withdraw/params.bin?url";
import withdrawPkUrl from "@cardinal-cryptography/shielder-sdk-crypto-wasm/keys/withdraw/pk.bin?url";

import { initWasmWorker as initFullWasmWorker } from "@cardinal-cryptography/shielder-sdk-crypto-wasm";

import { initWasmWorker as initLightWasmWorker } from "@cardinal-cryptography/shielder-sdk-crypto-wasm-light";

async function fetchArrayBuffer(url: string): Promise<Uint8Array> {
return await fetch(url).then((r) => r.bytes());
}

export async function initFullWasm() {
const newAccountParams = await fetchArrayBuffer(newAccountParamsUrl);
const newAccountPk = await fetchArrayBuffer(newAccountPkUrl);
const depositParams = await fetchArrayBuffer(depositParamsUrl);
const depositPk = await fetchArrayBuffer(depositPkUrl);
const withdrawParams = await fetchArrayBuffer(withdrawParamsUrl);
const withdrawPk = await fetchArrayBuffer(withdrawPkUrl);
console.log("Full Wasm crypto client initialized with params and keys");
return initFullWasmWorker(
"multi",
{
paramsBuf: newAccountParams,
pkBuf: newAccountPk
},
{
paramsBuf: depositParams,
pkBuf: depositPk
},
{
paramsBuf: withdrawParams,
pkBuf: withdrawPk
}
);
}

export async function initLightWasm(
proverServerUrl: string,
withoutAttestation: boolean
) {
return initLightWasmWorker(proverServerUrl, withoutAttestation);
}
6 changes: 6 additions & 0 deletions ts/shielder-sdk-tests/web/envConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const cryptoClientType =
(import.meta.env.VITE_CRYPTO_CLIENT_TYPE as "wasm-full" | "wasm-light") ||
"wasm-full";
export const proverServerUrl = import.meta.env.VITE_PROVER_SERVER_URL || "";
export const checkNitroAttestation =
import.meta.env.VITE_CHECK_NITRO_ATTESTATION === "true";
12 changes: 12 additions & 0 deletions ts/shielder-sdk-tests/web/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_CRYPTO_CLIENT_TYPE: "wasm-full" | "wasm-light";
readonly VITE_PROVER_SERVER_URL: string;
readonly VITE_CHECK_NITRO_ATTESTATION: string;
readonly VITE_PUBLIC_THREADS: string;
}

interface ImportMeta {
readonly env: ImportMetaEnv;
}
Loading