Skip to content
Merged
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
4 changes: 3 additions & 1 deletion .github/workflows/ci-rn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ on:
- main
paths:
- 'packages/sdk-platforms/react-native/react-native-zksync-sso/**'
- '.github/workflows/ci-rn.yml'
pull_request:
branches:
- main
paths:
- 'packages/sdk-platforms/react-native/react-native-zksync-sso/**'
- '.github/workflows/ci-rn.yml'

jobs:
build:
Expand Down Expand Up @@ -97,7 +99,7 @@ jobs:
x86_64-apple-ios

- name: Install cargo-ndk
run: cargo install cargo-ndk
run: cargo install cargo-ndk --version 3.5.4

- name: Select Xcode 16.3
run: sudo xcode-select -s /Applications/Xcode_16.3.app
Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/ci-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Rust CI

on:
push:
paths:
- 'packages/contracts/**'
- 'packages/sdk-platforms/**'
- '.github/workflows/ci-rust.yml'

jobs:
rust-sdk:
name: Rust SDK - latest
runs-on: ubuntu-latest
strategy:
matrix:
config:
- debug
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.4

- name: Install Rust
run: |
rustup update stable && rustup default stable
rustup toolchain install nightly

- name: Run rustfmt
run: |
rustup component add rustfmt --toolchain nightly
cargo +nightly fmt --all -- --check
working-directory: packages/sdk-platforms/rust/zksync-sso

- name: Install Anvil ZKsync Manually
run: |
SCRIPT_PATH=".github/workflows/scripts/install-anvil-zksync.sh"
chmod +x "$SCRIPT_PATH"
bash "$SCRIPT_PATH"

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9.11.0

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: lts/Iron
cache: pnpm

- name: Install dependencies
run: pnpm install -r --frozen-lockfile

- name: Install contract dependencies
run: pnpm install -r --frozen-lockfile
working-directory: packages/contracts

- name: Build contracts
run: pnpm build
working-directory: packages/contracts

- name: Run clippy
run: |
rustup component add clippy --toolchain stable
cargo clippy --all-targets -- -D warnings
working-directory: packages/sdk-platforms/rust/zksync-sso

- name: Run rust tests
run: cargo test
working-directory: packages/sdk-platforms/rust/zksync-sso
21 changes: 3 additions & 18 deletions .github/workflows/ci-swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- 'packages/contracts/**'
- 'packages/sdk-platforms/**'
- '.github/workflows/ci-swift.yml'

jobs:
swift-sdk:
Expand All @@ -25,19 +26,12 @@ jobs:
- name: Install Rust
run: |
rustup update stable && rustup default stable
rustup toolchain install nightly

- name: Run rustfmt
run: |
rustup component add rustfmt --toolchain nightly
cargo +nightly fmt --all -- --check
working-directory: packages/sdk-platforms/rust/zksync-sso

- name: Install Anvil ZKsync Manually
run: |
SCRIPT_PATH=".github/workflows/scripts/install-anvil-zksync.sh"
chmod +x "$SCRIPT_PATH"
sh "$SCRIPT_PATH"
bash "$SCRIPT_PATH"

- name: Setup pnpm
uses: pnpm/action-setup@v4
Expand All @@ -61,16 +55,6 @@ jobs:
run: pnpm build
working-directory: packages/contracts

- name: Run clippy
run: |
rustup component add clippy --toolchain stable
cargo clippy --all-targets -- -D warnings
working-directory: packages/sdk-platforms/rust/zksync-sso

- name: Run rust tests
run: cargo test
working-directory: packages/sdk-platforms/rust/zksync-sso

- name: Start anvil-zksync node
run: |
anvil-zksync --cache=none run > anvil-zksync.log 2>&1 &
Expand Down Expand Up @@ -99,6 +83,7 @@ jobs:
fi
echo "Simulator UDID: $UDID"
echo "SIMULATOR_UDID=$UDID" >> $GITHUB_ENV

- name: Install swiftformat
run: brew install swiftformat

Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ on:
push:
branches:
- main
paths-ignore:
- 'packages/sdk-platforms/**'
- '.github/workflows/ci-swift.yml'
- '.github/workflows/ci-rust.yml'
- '.github/workflows/ci-rn.yml'
pull_request:
paths-ignore:
- 'packages/sdk-platforms/**'
- '.github/workflows/ci-swift.yml'
- '.github/workflows/ci-rust.yml'
- '.github/workflows/ci-rn.yml'
workflow_dispatch:

jobs:
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/scripts/install-anvil-zksync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@ set -euo pipefail

REPO_URL="https://github.com/matter-labs/anvil-zksync.git"
RELEASE_VERSION="v0.6.3"
RELEASE_FILE_NAME="anvil-zksync-${RELEASE_VERSION}-aarch64-apple-darwin.tar.gz"

# Detect platform
if [[ "$OSTYPE" == "darwin"* ]]; then
RELEASE_FILE_NAME="anvil-zksync-${RELEASE_VERSION}-aarch64-apple-darwin.tar.gz"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
ARCH=$(uname -m)
if [[ "$ARCH" == "x86_64" ]]; then
RELEASE_FILE_NAME="anvil-zksync-${RELEASE_VERSION}-x86_64-unknown-linux-gnu.tar.gz"
else
echo "Error: Unsupported Linux architecture: $ARCH" >&2
exit 1
fi
else
echo "Error: Unsupported OS: $OSTYPE" >&2
exit 1
fi

RELEASE_URL="https://github.com/matter-labs/anvil-zksync/releases/download/${RELEASE_VERSION}/${RELEASE_FILE_NAME}"
INSTALL_DIR="/usr/local/bin"
TEMP_DIR="$(mktemp -d)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"contracts": {
"accountFactory": "0xda635aa336e8f5c1c3c19e6a0db6d601fa1e3e05",
"accountFactory": "0x7452d866cdbf84762b77a99849f00c26daaf2da8",
"passkey": "0xa472581ea2aca6e6bd8ea6cca95d3e1297aa5ae3",
"session": "0x6e2eef457e8a4dc33f6259ff0a933a2f94d64a8e",
"accountPaymaster": "0x18d0069ac0e0431f2af792ec425950427b775f1d",
"recovery": "0xe72da237538a1854535e9565dbee0b414f382698"
"session": "0x11f853c85e282a542d8ee8f9cdd8fe6ce61badf1",
"accountPaymaster": "0x3ec8307648f31c494caeab625e5f2c99bfbaa560",
"recovery": "0x3a34dab058fd71b2fb0d9d9e7d3dd205f9072fc3"
},
"nodeUrl": "http://localhost:8011/",
"deployWallet": {
"privateKeyHex": "f1010e4119b26f6ceccb5a42b8dc6b2a10650d4f5943e4eb8285951aba264b6c"
"privateKeyHex": "0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub async fn deploy_contracts_and_update_example_configs(
println!(" ExampleAuthServerPaymaster: {}", contracts.account_paymaster);
println!(" Recovery: {}", contracts.recovery);

let deploy_wallet = Some(DeployWallet::random());
let deploy_wallet = Some(DeployWallet::rich_wallet());
let config = Config::new(contracts, node_url.clone(), deploy_wallet);

for path in config_paths {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ mod balance;
mod deployment;
mod fetch;
mod fund;
mod owners;
mod send;
mod session;
mod transaction;
mod validators;

#[derive(Debug, Clone, uniffi::Record)]
pub struct Account {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
use crate::config;
use sdk::api::{
account::{
passkey::{
passkey_parameters::PasskeyParameters as SdkPasskeyParameters,
rp_id::{AndroidRpId as SdkAndroidRpId, RpId as SdkRpId},
},
session::decode_session_config,
},
utils::parse_address,
};

#[derive(Debug, uniffi::Record)]
pub struct AndroidRpId {
pub origin: String,
pub rp_id: String,
}

impl From<AndroidRpId> for sdk::api::account::deployment::AndroidRpId {
impl From<AndroidRpId> for SdkAndroidRpId {
fn from(android_rp_id: AndroidRpId) -> Self {
sdk::api::account::deployment::AndroidRpId {
SdkAndroidRpId {
origin: android_rp_id.origin,
rp_id: android_rp_id.rp_id,
}
Expand Down Expand Up @@ -45,16 +55,12 @@ impl RpId {
}
}

impl From<RpId> for sdk::api::account::deployment::RpId {
impl From<RpId> for SdkRpId {
fn from(rp_id: RpId) -> Self {
match rp_id {
RpId::Apple(rp_id) => {
sdk::api::account::deployment::RpId::Apple(rp_id)
}
RpId::Apple(rp_id) => SdkRpId::Apple(rp_id),
RpId::Android(android_rp_id) => {
sdk::api::account::deployment::RpId::Android(
android_rp_id.into(),
)
SdkRpId::Android(android_rp_id.into())
}
}
}
Expand All @@ -68,11 +74,9 @@ pub struct PasskeyParameters {
pub rp_id: RpId,
}

impl From<PasskeyParameters>
for sdk::api::account::deployment::PasskeyParameters
{
impl From<PasskeyParameters> for SdkPasskeyParameters {
fn from(passkey_parameters: PasskeyParameters) -> Self {
sdk::api::account::deployment::PasskeyParameters {
SdkPasskeyParameters {
credential_raw_attestation_object: passkey_parameters
.credential_raw_attestation_object,
credential_raw_client_data_json: passkey_parameters
Expand Down Expand Up @@ -103,15 +107,44 @@ pub enum DeployAccountError {

#[error("Account already deployed")]
AccountAlreadyDeployed,

#[error("Invalid session config: {0}")]
InvalidSessionConfig(String),

#[error("Invalid K1 owners: {0}")]
InvalidK1Owners(String),
}

#[uniffi::export(async_runtime = "tokio")]
pub async fn deploy_account(
passkey_parameters: PasskeyParameters,
initial_k1_owners: Option<Vec<String>>,
initial_session_config_json: Option<String>,
config: config::Config,
) -> Result<super::Account, DeployAccountError> {
let initial_k1_owners = initial_k1_owners
.map(|k1_owners| {
k1_owners
.into_iter()
.map(|k1_owner| parse_address(&k1_owner))
.collect::<Result<Vec<_>, _>>()
})
.transpose()
.map_err(|e| DeployAccountError::InvalidK1Owners(e.to_string()))?;

let initial_session = initial_session_config_json
.map(|session_config| {
decode_session_config(&session_config).map_err(|e| {
DeployAccountError::InvalidSessionConfig(e.to_string())
})
})
.transpose()
.map_err(|e| DeployAccountError::InvalidSessionConfig(e.to_string()))?;

sdk::api::account::deployment::deploy_account(
passkey_parameters.into(),
initial_k1_owners,
initial_session,
&(config.try_into()
as Result<sdk::config::Config, config::ConfigError>)
.map_err(|e: config::ConfigError| {
Expand All @@ -127,11 +160,34 @@ pub async fn deploy_account(
pub async fn deploy_account_with_unique_id(
passkey_parameters: PasskeyParameters,
unique_account_id: String,
initial_k1_owners: Option<Vec<String>>,
initial_session_config_json: Option<String>,
config: config::Config,
) -> Result<super::Account, DeployAccountError> {
let initial_k1_owners = initial_k1_owners
.map(|k1_owners| {
k1_owners
.into_iter()
.map(|k1_owner| parse_address(&k1_owner))
.collect::<Result<Vec<_>, _>>()
})
.transpose()
.map_err(|e| DeployAccountError::InvalidK1Owners(e.to_string()))?;

let initial_session = initial_session_config_json
.map(|session_config| {
decode_session_config(&session_config).map_err(|e| {
DeployAccountError::InvalidSessionConfig(e.to_string())
})
})
.transpose()
.map_err(|e| DeployAccountError::InvalidSessionConfig(e.to_string()))?;

sdk::api::account::deployment::deploy_account_with_unique_id(
passkey_parameters.into(),
unique_account_id,
initial_k1_owners,
initial_session,
&(config.try_into()
as Result<sdk::config::Config, config::ConfigError>)
.map_err(|e: config::ConfigError| {
Expand Down
Loading
Loading