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
65 changes: 63 additions & 2 deletions .github/workflows/ci-swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,70 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Checkout specific contracts submodule version
run: |
cd packages/contracts
git fetch origin debug-logs:refs/remotes/origin/debug-logs
git checkout origin/debug-logs # Rust/Swift SDK depends on an old version of contracts
cd ../..

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.4
- run: rustup update stable && rustup default stable

- name: Install Rust
run: rustup update stable && rustup default stable

- name: Install Anvil ZKsync Manually
run: |
SCRIPT_PATH=".github/workflows/scripts/install-anvil-zksync.sh"
chmod +x "$SCRIPT_PATH"
sh "$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 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 &
# Wait a few seconds to ensure the node starts
sleep 5
# Verify it's running
if ! pgrep -f "anvil-zksync"; then
echo "Error: anvil-zksync failed to start"
cat anvil-zksync.log
exit 1
fi

- name: Deploy contracts and create Swift config
run: cargo run --bin cli -- deploy-contracts
working-directory: packages/sdk-platforms/rust/zksync-sso

- name: Select Xcode 16.1
run: sudo xcode-select -s /Applications/Xcode_16.1.app

- name: Select Simulator
run: |
UDID=$(xcrun simctl list devices | awk '/-- iOS 18.1 --/{flag=1; next} /--/{flag=0} flag' | grep "iPhone 16 Pro" | awk -F '[()]' '{print $2}' | head -1)
Expand All @@ -33,8 +92,10 @@ jobs:
echo "SIMULATOR_UDID=$UDID" >> $GITHUB_ENV
- name: Install swiftformat
run: brew install swiftformat

- name: Build bindings
run: sh packages/sdk-platforms/rust/zksync-sso/crates/ffi/build-swift-framework.sh
run: sh packages/sdk-platforms/rust/zksync-sso/crates/ffi/build-swift-framework-ios-ci.sh

- name: Build & test Swift SDK
run: |
xcodebuild test \
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/scripts/install-anvil-zksync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -euo pipefail

REPO_URL="https://github.com/matter-labs/anvil-zksync.git"
RELEASE_VERSION="v0.3.2"
RELEASE_FILE_NAME="anvil-zksync-${RELEASE_VERSION}-aarch64-apple-darwin.tar.gz"
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)"

curl -L "$RELEASE_URL" -o "$TEMP_DIR/$RELEASE_FILE_NAME"

echo "Extracting anvil-zksync..."
tar -xzf "$TEMP_DIR/$RELEASE_FILE_NAME" -C "$INSTALL_DIR"

rm -rf "$TEMP_DIR"

echo "Verifying anvil-zksync installation..."
if command -v anvil-zksync >/dev/null 2>&1; then
echo "anvil-zksync installed successfully!"
anvil-zksync --version
else
echo "Error: anvil-zksync not found in PATH" >&2
exit 1
fi
40 changes: 40 additions & 0 deletions packages/sdk-platforms/rust/zksync-sso/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,43 @@ rust-version = "1.83"
license = "Apache-2.0"

[workspace.dependencies]

# Alloy
alloy = { version = "0.11.0", default-features = false, features = [
"rlp",
"serde",
"rpc-types",
"signer-local",
"reqwest",
"contract",
"eip712",
] }
alloy-zksync = { git = "https://github.com/jackpooleyml/alloy-zksync", rev = "e96bb14e3ca6c3a8031e59494cf05fcedd12f07a" }

# Http
url = "2.5.4"

# Serialization
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

# Async
tokio = { version = "1.43.0", features = ["full"] }
async-trait = "0.1"
futures = "0.3"

# Error handling
eyre = "0.6"
thiserror = "2.0.11"

# Randomness
rand = "0.9"

# Hex
hex = "0.4"

# i18n
icu = { version = "1.5.0", features = ["default", "serde", "std"] }
icu_decimal = { version = "1.5.0", features = ["default"] }
fixed_decimal = "0.5.6"
fixed = "1.28.0"
6 changes: 6 additions & 0 deletions packages/sdk-platforms/rust/zksync-sso/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# TODOs

[ ] Move `fund` method to seperate module
[ ] Use paymaster for deployement rather than rich wallet
[ ] Consider using the `log` crate for debug logging
[ ] Change passkey attestation to `direct`
5 changes: 5 additions & 0 deletions packages/sdk-platforms/rust/zksync-sso/crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ rust-version.workspace = true
license.workspace = true

[dependencies]
clap = { version = "4.5.1", features = ["derive"] }
sdk = { path = "../sdk" }
url = { workspace = true }
tokio = { workspace = true }
eyre = { workspace = true }
serde_json = { workspace = true }
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use eyre::Result;
use sdk::{config::Config, utils::deployment_utils::deploy_contracts};
use std::{fs, path::PathBuf};
use url::Url;

pub async fn deploy_contracts_and_update_swift_config(
node_url: Url,
config_path: Option<PathBuf>,
) -> Result<()> {
println!("Deploying contracts to node: {}", node_url);

let contracts = deploy_contracts(node_url.clone()).await?;
println!("Contracts deployed successfully:");
println!(" AAFactory: {}", contracts.account_factory);
println!(" WebAuthValidator: {}", contracts.passkey);
println!(" SessionKeyValidator: {}", contracts.session);
println!(" ExampleAuthServerPaymaster: {}", contracts.account_paymaster);

let config_path =
config_path.unwrap_or_else(Config::get_default_swift_config_path);
println!("\nWriting config to path: {:?}", config_path);

let config = Config::new(contracts, node_url);
config.write_json(&config_path)?;

println!("\nVerifying written config:");
let written_json = fs::read_to_string(&config_path)?;
println!("Written JSON content:\n{}", written_json);

let written_config: Config = serde_json::from_str(&written_json)?;
println!("\nParsed config verification:");
println!(" Node URL: {}", written_config.node_url);
println!(" AAFactory: {}", written_config.contracts.account_factory);
println!(" WebAuthValidator: {}", written_config.contracts.passkey);
println!(" SessionKeyValidator: {}", written_config.contracts.session);
println!(
" ExampleAuthServerPaymaster: {}",
written_config.contracts.account_paymaster
);

println!("\nSuccessfully updated and verified Swift config values");
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use clap::{Parser, Subcommand};
use std::path::PathBuf;
use url::Url;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}

#[derive(Subcommand)]
enum Commands {
/// Deploy contracts and update Swift config values
DeployContracts {
/// The URL of the zkSync node (defaults to http://localhost:8011/)
#[arg(long, default_value = "http://localhost:8011/")]
node_url: Url,

/// Path to write the config file (defaults to swift/ZKsyncSSO/Sources/ZKsyncSSO/Config/config.json)
#[arg(long)]
config_path: Option<PathBuf>,
},
}

pub async fn handle_cli() -> eyre::Result<()> {
let cli = Cli::parse();

match cli.command {
Commands::DeployContracts { node_url, config_path } => {
super::deploy_contracts::deploy_contracts_and_update_swift_config(
node_url,
config_path,
)
.await?;
}
}

Ok(())
}
2 changes: 2 additions & 0 deletions packages/sdk-platforms/rust/zksync-sso/crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod deploy_contracts;
pub mod handle_cli;
9 changes: 7 additions & 2 deletions packages/sdk-platforms/rust/zksync-sso/crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
fn main() {
println!("{}", format!("{}", sdk::add(1, 1)));
use cli::handle_cli::handle_cli;

#[tokio::main]
async fn main() -> eyre::Result<()> {
handle_cli().await?;

Ok(())
}
14 changes: 13 additions & 1 deletion packages/sdk-platforms/rust/zksync-sso/crates/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@ license.workspace = true
crate-type = ["staticlib"]

[dependencies]
uniffi = { version = "0.28.3", features = ["cli"] }
uniffi = { version = "0.28.3", features = ["cli", "tokio"] }
sdk = { path = "../sdk" }

# Serialization
serde = { workspace = true }
serde_json = { workspace = true }

# Async
tokio = { workspace = true }
futures = { workspace = true }

# Error handling
eyre = { workspace = true }
thiserror = { workspace = true }

[build-dependencies]
uniffi = { version = "0.28.3", features = ["build", "cli"] }
Loading
Loading