Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
136 changes: 136 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint-and-typecheck:
name: Lint & Type Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing version SHA


- name: Setup pnpm
uses: pnpm/action-setup@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

with:
version: 9

- name: Setup Node.js
uses: actions/setup-node@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

with:
node-version: "20"
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Build SDK
run: pnpm sdk:build

- name: Type check SDK
run: pnpm sdk:build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate task ?


- name: Type check Next.js
run: pnpm next:check-types

- name: Type check Hardhat
run: pnpm hardhat:check-types

- name: Lint Next.js
run: pnpm next:lint

- name: Lint Hardhat
run: pnpm hardhat:lint

test-sdk:
name: SDK Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem


- name: Setup pnpm
uses: pnpm/action-setup@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

with:
version: 9

- name: Setup Node.js
uses: actions/setup-node@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

with:
node-version: "20"
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Build SDK
run: pnpm sdk:build

- name: Run SDK tests
run: pnpm sdk:test

test-hardhat:
name: Hardhat Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem


- name: Setup pnpm
uses: pnpm/action-setup@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

with:
version: 9

- name: Setup Node.js
uses: actions/setup-node@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

with:
node-version: "20"
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Compile contracts
run: pnpm compile

- name: Run Hardhat tests
run: pnpm test

build:
name: Build
runs-on: ubuntu-latest
needs: [lint-and-typecheck]
env:
NEXT_PUBLIC_ALCHEMY_API_KEY: ${{ secrets.NEXT_PUBLIC_ALCHEMY_API_KEY }}
NEXT_PUBLIC_PRIVY_APP_ID: ${{ secrets.NEXT_PUBLIC_PRIVY_APP_ID }}
steps:
- name: Checkout
uses: actions/checkout@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem


- name: Setup pnpm
uses: pnpm/action-setup@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

with:
version: 9

- name: Setup Node.js
uses: actions/setup-node@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

with:
node-version: "20"
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Build SDK
run: pnpm sdk:build

- name: Build Next.js
run: pnpm next:build
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ packages/*/.env
packages/*/.turbo
packages/*/coverage
tmp*
.vscode
.vscode
CLAUDE.md
.claude
28 changes: 16 additions & 12 deletions packages/fhevm-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "src/index.ts",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./src/index.ts",
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./core": {
"types": "./src/core/index.ts",
"types": "./dist/core/index.d.ts",
"default": "./dist/core/index.js"
},
"./storage": {
"types": "./src/storage/index.ts",
"types": "./dist/storage/index.d.ts",
"default": "./dist/storage/index.js"
},
"./types": {
"types": "./src/fhevmTypes.ts",
"types": "./dist/fhevmTypes.d.ts",
"default": "./dist/fhevmTypes.js"
},
"./react": {
"types": "./src/react/index.ts",
"types": "./dist/react/index.d.ts",
"default": "./dist/react/index.js"
}
},
Expand All @@ -36,19 +36,23 @@
"test:watch": "vitest"
},
"dependencies": {
"idb": "^8.0.3"
"idb": "^8.0.3",
"@zama-fhe/relayer-sdk": "0.4.0-4",
"ethers": "^6.13.4"
},
"peerDependencies": {
"@fhevm/mock-utils": "^0.1.0",
"@zama-fhe/relayer-sdk": "^0.2.0",
"ethers": "^6.13.4",
"react": "^18.0.0 || ^19.0.0"
"@fhevm/mock-utils": "^0.3.0-4",
"react": ">=16.8.0"
},
"peerDependenciesMeta": {
"react": {
"optional": true
}
},
"devDependencies": {
"@types/node": "~18.19.50",
"@types/react": "~19.0.7",
"@vitest/coverage-v8": "2.1.9",
"@zama-fhe/relayer-sdk": "0.2.0",
"ethers": "^6.13.7",
"fake-indexeddb": "~6.0.0",
"jsdom": "^27.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/fhevm-sdk/src/fhevmTypes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { FhevmInstance as _FhevmInstance } from "@zama-fhe/relayer-sdk/bundle";
import type { HandleContractPair as _HandleContractPair } from "@zama-fhe/relayer-sdk/bundle";
import type { DecryptedResults as _DecryptedResults } from "@zama-fhe/relayer-sdk/bundle";
import type { FhevmInstanceConfig as _FhevmInstanceConfig } from "@zama-fhe/relayer-sdk/web";
import type { UserDecryptResults as _UserDecryptResults } from "@zama-fhe/relayer-sdk/bundle";
import type { FhevmInstanceConfig as _FhevmInstanceConfig } from "@zama-fhe/relayer-sdk/bundle";

export type FhevmInstance = _FhevmInstance;
export type FhevmInstanceConfig = _FhevmInstanceConfig;
export type HandleContractPair = _HandleContractPair;
export type DecryptedResults = _DecryptedResults;
export type UserDecryptResults = _UserDecryptResults;

export type FhevmDecryptionSignatureType = {
publicKey: string;
Expand Down
55 changes: 28 additions & 27 deletions packages/fhevm-sdk/src/internal/PublicKeyStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ async function _getDB(): Promise<IDBPDatabase<PublicParamsDB> | undefined> {
return __dbPromise;
}

type FhevmInstanceConfigPublicKey = {
data: Uint8Array | null;
id: string | null;
// Types that match @zama-fhe/relayer-sdk v0.4 FhevmPkeConfigType
type FhevmPublicKeyType = {
data: Uint8Array;
id: string;
};

type FhevmInstanceConfigPublicParams = {
"2048": {
publicParamsId: string;
publicParams: Uint8Array;
};
type FhevmPkeCrsType = {
publicParams: Uint8Array;
publicParamsId: string;
};

type FhevmPkeCrsByCapacityType = {
2048: FhevmPkeCrsType;
};

function assertFhevmStoredPublicKey(
Expand Down Expand Up @@ -110,12 +113,12 @@ function assertFhevmStoredPublicParams(
}

export async function publicKeyStorageGet(aclAddress: `0x${string}`): Promise<{
publicKey?: FhevmInstanceConfigPublicKey;
publicParams: FhevmInstanceConfigPublicParams | null;
publicKey?: FhevmPublicKeyType;
publicParams?: FhevmPkeCrsByCapacityType;
}> {
const db = await _getDB();
if (!db) {
return { publicParams: null };
return {};
}

let storedPublicKey: FhevmStoredPublicKey | null = null;
Expand All @@ -140,27 +143,25 @@ export async function publicKeyStorageGet(aclAddress: `0x${string}`): Promise<{
//
}

const publicKeyData = storedPublicKey?.publicKey;
const publicKeyId = storedPublicKey?.publicKeyId;
const publicParams = storedPublicParams
? {
"2048": storedPublicParams,
}
: null;
const result: {
publicKey?: FhevmPublicKeyType;
publicParams?: FhevmPkeCrsByCapacityType;
} = {};

let publicKey: FhevmInstanceConfigPublicKey | undefined = undefined;
if (storedPublicKey) {
result.publicKey = {
id: storedPublicKey.publicKeyId,
data: storedPublicKey.publicKey,
};
}

if (publicKeyId && publicKeyData) {
publicKey = {
id: publicKeyId,
data: publicKeyData,
if (storedPublicParams) {
result.publicParams = {
2048: storedPublicParams,
};
}

return {
...(publicKey !== undefined && { publicKey }),
publicParams,
};
return result;
}

export async function publicKeyStorageSet(
Expand Down
24 changes: 20 additions & 4 deletions packages/fhevm-sdk/src/internal/RelayerSDKLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,30 @@ export class RelayerSDKLoader {
`script[src="${SDK_CDN_URL}"]`
);
if (existingScript) {
if (!isFhevmWindowType(window, this._trace)) {
// Script tag exists — it may still be loading
if (isFhevmWindowType(window, this._trace)) {
resolve();
return;
}
// Wait for the existing script to finish loading
existingScript.addEventListener("load", () => {
if (isFhevmWindowType(window, this._trace)) {
resolve();
} else {
reject(
new Error(
"RelayerSDKLoader: window object does not contain a valid relayerSDK object."
)
);
}
});
existingScript.addEventListener("error", () => {
reject(
new Error(
"RelayerSDKLoader: window object does not contain a valid relayerSDK object."
`RelayerSDKLoader: Failed to load Relayer SDK from ${SDK_CDN_URL}`
)
);
}
resolve();
});
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/fhevm-sdk/src/internal/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const SDK_CDN_URL =
"https://cdn.zama.ai/relayer-sdk-js/0.2.0/relayer-sdk-js.umd.cjs";
"https://cdn.zama.org/relayer-sdk-js/0.4.0-4/relayer-sdk-js.umd.cjs";
2 changes: 2 additions & 0 deletions packages/fhevm-sdk/src/internal/fhevm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,11 @@ export const createFhevmInstance = async (parameters: {

const config: FhevmInstanceConfig = {
...relayerSDK.SepoliaConfig,
relayerUrl: `${relayerSDK.SepoliaConfig.relayerUrl}/v2`,
network: providerOrUrl,
publicKey: pub.publicKey,
publicParams: pub.publicParams,
relayerRouteVersion: 2
};

// notify that state === "creating"
Expand Down
Loading
Loading