Skip to content

Commit a8c8895

Browse files
committed
feat: sessions swift demo
1 parent 9a834cd commit a8c8895

File tree

104 files changed

+4452
-1000
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+4452
-1000
lines changed

.github/workflows/ci-rust.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Rust CI
2+
3+
on:
4+
push:
5+
paths:
6+
- 'packages/contracts/**'
7+
- 'packages/sdk-platforms/**'
8+
- '.github/workflows/ci-rust.yml'
9+
10+
jobs:
11+
rust-sdk:
12+
name: Rust SDK - latest
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
config:
17+
- debug
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
submodules: recursive
22+
23+
- name: Run sccache-cache
24+
uses: mozilla-actions/sccache-action@v0.0.4
25+
26+
- name: Install Rust
27+
run: |
28+
rustup update stable && rustup default stable
29+
rustup toolchain install nightly
30+
31+
- name: Run rustfmt
32+
run: |
33+
rustup component add rustfmt --toolchain nightly
34+
cargo +nightly fmt --all -- --check
35+
working-directory: packages/sdk-platforms/rust/zksync-sso
36+
37+
- name: Install Anvil ZKsync Manually
38+
run: |
39+
SCRIPT_PATH=".github/workflows/scripts/install-anvil-zksync.sh"
40+
chmod +x "$SCRIPT_PATH"
41+
bash "$SCRIPT_PATH"
42+
43+
- name: Setup pnpm
44+
uses: pnpm/action-setup@v4
45+
with:
46+
version: 9.11.0
47+
48+
- name: Use Node.js
49+
uses: actions/setup-node@v4
50+
with:
51+
node-version: lts/Iron
52+
cache: pnpm
53+
54+
- name: Install dependencies
55+
run: pnpm install -r --frozen-lockfile
56+
57+
- name: Install contract dependencies
58+
run: pnpm install -r --frozen-lockfile
59+
working-directory: packages/contracts
60+
61+
- name: Build contracts
62+
run: pnpm build
63+
working-directory: packages/contracts
64+
65+
- name: Run clippy
66+
run: |
67+
rustup component add clippy --toolchain stable
68+
cargo clippy --all-targets -- -D warnings
69+
working-directory: packages/sdk-platforms/rust/zksync-sso
70+
71+
- name: Run rust tests
72+
run: cargo test
73+
working-directory: packages/sdk-platforms/rust/zksync-sso

.github/workflows/ci-swift.yml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
paths:
66
- 'packages/contracts/**'
77
- 'packages/sdk-platforms/**'
8+
- '.github/workflows/ci-swift.yml'
89

910
jobs:
1011
swift-sdk:
@@ -25,19 +26,12 @@ jobs:
2526
- name: Install Rust
2627
run: |
2728
rustup update stable && rustup default stable
28-
rustup toolchain install nightly
29-
30-
- name: Run rustfmt
31-
run: |
32-
rustup component add rustfmt --toolchain nightly
33-
cargo +nightly fmt --all -- --check
34-
working-directory: packages/sdk-platforms/rust/zksync-sso
3529
3630
- name: Install Anvil ZKsync Manually
3731
run: |
3832
SCRIPT_PATH=".github/workflows/scripts/install-anvil-zksync.sh"
3933
chmod +x "$SCRIPT_PATH"
40-
sh "$SCRIPT_PATH"
34+
bash "$SCRIPT_PATH"
4135
4236
- name: Setup pnpm
4337
uses: pnpm/action-setup@v4
@@ -61,16 +55,6 @@ jobs:
6155
run: pnpm build
6256
working-directory: packages/contracts
6357

64-
- name: Run clippy
65-
run: |
66-
rustup component add clippy --toolchain stable
67-
cargo clippy --all-targets -- -D warnings
68-
working-directory: packages/sdk-platforms/rust/zksync-sso
69-
70-
- name: Run rust tests
71-
run: cargo test
72-
working-directory: packages/sdk-platforms/rust/zksync-sso
73-
7458
- name: Start anvil-zksync node
7559
run: |
7660
anvil-zksync --cache=none run > anvil-zksync.log 2>&1 &
@@ -99,6 +83,7 @@ jobs:
9983
fi
10084
echo "Simulator UDID: $UDID"
10185
echo "SIMULATOR_UDID=$UDID" >> $GITHUB_ENV
86+
10287
- name: Install swiftformat
10388
run: brew install swiftformat
10489

.github/workflows/scripts/install-anvil-zksync.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,23 @@ set -euo pipefail
44

55
REPO_URL="https://github.com/matter-labs/anvil-zksync.git"
66
RELEASE_VERSION="v0.6.3"
7-
RELEASE_FILE_NAME="anvil-zksync-${RELEASE_VERSION}-aarch64-apple-darwin.tar.gz"
7+
8+
# Detect platform
9+
if [[ "$OSTYPE" == "darwin"* ]]; then
10+
RELEASE_FILE_NAME="anvil-zksync-${RELEASE_VERSION}-aarch64-apple-darwin.tar.gz"
11+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
12+
ARCH=$(uname -m)
13+
if [[ "$ARCH" == "x86_64" ]]; then
14+
RELEASE_FILE_NAME="anvil-zksync-${RELEASE_VERSION}-x86_64-unknown-linux-gnu.tar.gz"
15+
else
16+
echo "Error: Unsupported Linux architecture: $ARCH" >&2
17+
exit 1
18+
fi
19+
else
20+
echo "Error: Unsupported OS: $OSTYPE" >&2
21+
exit 1
22+
fi
23+
824
RELEASE_URL="https://github.com/matter-labs/anvil-zksync/releases/download/${RELEASE_VERSION}/${RELEASE_FILE_NAME}"
925
INSTALL_DIR="/usr/local/bin"
1026
TEMP_DIR="$(mktemp -d)"
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"contracts": {
3-
"accountFactory": "0xda635aa336e8f5c1c3c19e6a0db6d601fa1e3e05",
3+
"accountFactory": "0x7452d866cdbf84762b77a99849f00c26daaf2da8",
44
"passkey": "0xa472581ea2aca6e6bd8ea6cca95d3e1297aa5ae3",
5-
"session": "0x6e2eef457e8a4dc33f6259ff0a933a2f94d64a8e",
6-
"accountPaymaster": "0x18d0069ac0e0431f2af792ec425950427b775f1d",
7-
"recovery": "0xe72da237538a1854535e9565dbee0b414f382698"
5+
"session": "0x11f853c85e282a542d8ee8f9cdd8fe6ce61badf1",
6+
"accountPaymaster": "0x3ec8307648f31c494caeab625e5f2c99bfbaa560",
7+
"recovery": "0x3a34dab058fd71b2fb0d9d9e7d3dd205f9072fc3"
88
},
99
"nodeUrl": "http://localhost:8011/",
1010
"deployWallet": {
11-
"privateKeyHex": "f1010e4119b26f6ceccb5a42b8dc6b2a10650d4f5943e4eb8285951aba264b6c"
11+
"privateKeyHex": "0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a"
1212
}
1313
}

packages/sdk-platforms/rust/zksync-sso/crates/cli/src/deploy_contracts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub async fn deploy_contracts_and_update_example_configs(
2020
println!(" ExampleAuthServerPaymaster: {}", contracts.account_paymaster);
2121
println!(" Recovery: {}", contracts.recovery);
2222

23-
let deploy_wallet = Some(DeployWallet::random());
23+
let deploy_wallet = Some(DeployWallet::rich_wallet());
2424
let config = Config::new(contracts, node_url.clone(), deploy_wallet);
2525

2626
for path in config_paths {

packages/sdk-platforms/rust/zksync-sso/crates/ffi/src/account.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ mod balance;
22
mod deployment;
33
mod fetch;
44
mod fund;
5+
mod owners;
56
mod send;
67
mod session;
78
mod transaction;
9+
mod validators;
810

911
#[derive(Debug, Clone, uniffi::Record)]
1012
pub struct Account {

packages/sdk-platforms/rust/zksync-sso/crates/ffi/src/account/deployment.rs

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
use crate::config;
2+
use sdk::api::{
3+
account::{
4+
passkey::{
5+
passkey_parameters::PasskeyParameters as SdkPasskeyParameters,
6+
rp_id::{AndroidRpId as SdkAndroidRpId, RpId as SdkRpId},
7+
},
8+
session::decode_session_config,
9+
},
10+
utils::parse_address,
11+
};
212

313
#[derive(Debug, uniffi::Record)]
414
pub struct AndroidRpId {
515
pub origin: String,
616
pub rp_id: String,
717
}
818

9-
impl From<AndroidRpId> for sdk::api::account::deployment::AndroidRpId {
19+
impl From<AndroidRpId> for SdkAndroidRpId {
1020
fn from(android_rp_id: AndroidRpId) -> Self {
11-
sdk::api::account::deployment::AndroidRpId {
21+
SdkAndroidRpId {
1222
origin: android_rp_id.origin,
1323
rp_id: android_rp_id.rp_id,
1424
}
@@ -45,16 +55,12 @@ impl RpId {
4555
}
4656
}
4757

48-
impl From<RpId> for sdk::api::account::deployment::RpId {
58+
impl From<RpId> for SdkRpId {
4959
fn from(rp_id: RpId) -> Self {
5060
match rp_id {
51-
RpId::Apple(rp_id) => {
52-
sdk::api::account::deployment::RpId::Apple(rp_id)
53-
}
61+
RpId::Apple(rp_id) => SdkRpId::Apple(rp_id),
5462
RpId::Android(android_rp_id) => {
55-
sdk::api::account::deployment::RpId::Android(
56-
android_rp_id.into(),
57-
)
63+
SdkRpId::Android(android_rp_id.into())
5864
}
5965
}
6066
}
@@ -68,11 +74,9 @@ pub struct PasskeyParameters {
6874
pub rp_id: RpId,
6975
}
7076

71-
impl From<PasskeyParameters>
72-
for sdk::api::account::deployment::PasskeyParameters
73-
{
77+
impl From<PasskeyParameters> for SdkPasskeyParameters {
7478
fn from(passkey_parameters: PasskeyParameters) -> Self {
75-
sdk::api::account::deployment::PasskeyParameters {
79+
SdkPasskeyParameters {
7680
credential_raw_attestation_object: passkey_parameters
7781
.credential_raw_attestation_object,
7882
credential_raw_client_data_json: passkey_parameters
@@ -103,15 +107,44 @@ pub enum DeployAccountError {
103107

104108
#[error("Account already deployed")]
105109
AccountAlreadyDeployed,
110+
111+
#[error("Invalid session config: {0}")]
112+
InvalidSessionConfig(String),
113+
114+
#[error("Invalid K1 owners: {0}")]
115+
InvalidK1Owners(String),
106116
}
107117

108118
#[uniffi::export(async_runtime = "tokio")]
109119
pub async fn deploy_account(
110120
passkey_parameters: PasskeyParameters,
121+
initial_k1_owners: Option<Vec<String>>,
122+
initial_session_config_json: Option<String>,
111123
config: config::Config,
112124
) -> Result<super::Account, DeployAccountError> {
125+
let initial_k1_owners = initial_k1_owners
126+
.map(|k1_owners| {
127+
k1_owners
128+
.into_iter()
129+
.map(|k1_owner| parse_address(&k1_owner))
130+
.collect::<Result<Vec<_>, _>>()
131+
})
132+
.transpose()
133+
.map_err(|e| DeployAccountError::InvalidK1Owners(e.to_string()))?;
134+
135+
let initial_session = initial_session_config_json
136+
.map(|session_config| {
137+
decode_session_config(&session_config).map_err(|e| {
138+
DeployAccountError::InvalidSessionConfig(e.to_string())
139+
})
140+
})
141+
.transpose()
142+
.map_err(|e| DeployAccountError::InvalidSessionConfig(e.to_string()))?;
143+
113144
sdk::api::account::deployment::deploy_account(
114145
passkey_parameters.into(),
146+
initial_k1_owners,
147+
initial_session,
115148
&(config.try_into()
116149
as Result<sdk::config::Config, config::ConfigError>)
117150
.map_err(|e: config::ConfigError| {
@@ -127,11 +160,34 @@ pub async fn deploy_account(
127160
pub async fn deploy_account_with_unique_id(
128161
passkey_parameters: PasskeyParameters,
129162
unique_account_id: String,
163+
initial_k1_owners: Option<Vec<String>>,
164+
initial_session_config_json: Option<String>,
130165
config: config::Config,
131166
) -> Result<super::Account, DeployAccountError> {
167+
let initial_k1_owners = initial_k1_owners
168+
.map(|k1_owners| {
169+
k1_owners
170+
.into_iter()
171+
.map(|k1_owner| parse_address(&k1_owner))
172+
.collect::<Result<Vec<_>, _>>()
173+
})
174+
.transpose()
175+
.map_err(|e| DeployAccountError::InvalidK1Owners(e.to_string()))?;
176+
177+
let initial_session = initial_session_config_json
178+
.map(|session_config| {
179+
decode_session_config(&session_config).map_err(|e| {
180+
DeployAccountError::InvalidSessionConfig(e.to_string())
181+
})
182+
})
183+
.transpose()
184+
.map_err(|e| DeployAccountError::InvalidSessionConfig(e.to_string()))?;
185+
132186
sdk::api::account::deployment::deploy_account_with_unique_id(
133187
passkey_parameters.into(),
134188
unique_account_id,
189+
initial_k1_owners,
190+
initial_session,
135191
&(config.try_into()
136192
as Result<sdk::config::Config, config::ConfigError>)
137193
.map_err(|e: config::ConfigError| {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use crate::config;
2+
use sdk::api::{
3+
account::owners::is_k1_owner as is_k1_owner_sdk, utils::parse_address,
4+
};
5+
6+
#[derive(Debug, uniffi::Record)]
7+
pub struct IsK1OwnerArgs {
8+
pub account: String,
9+
pub owner_address: String,
10+
}
11+
12+
#[derive(Debug, thiserror::Error, uniffi::Error)]
13+
pub enum IsK1OwnerError {
14+
#[error("{0}")]
15+
IsK1Owner(String),
16+
#[error("Invalid address: {0}")]
17+
InvalidAccountAddress(String),
18+
#[error("Invalid owner address: {0}")]
19+
InvalidOwnerAddress(String),
20+
#[error("Invalid config: {0}")]
21+
InvalidConfig(String),
22+
}
23+
24+
#[uniffi::export(async_runtime = "tokio")]
25+
pub async fn is_k1_owner(
26+
args: IsK1OwnerArgs,
27+
config: config::Config,
28+
) -> Result<bool, IsK1OwnerError> {
29+
let account = parse_address(&args.account)
30+
.map_err(|e| IsK1OwnerError::InvalidAccountAddress(e.to_string()))?;
31+
let owner_address = parse_address(&args.owner_address)
32+
.map_err(|e| IsK1OwnerError::InvalidOwnerAddress(e.to_string()))?;
33+
let result = is_k1_owner_sdk(
34+
account,
35+
owner_address,
36+
&(config.try_into()
37+
as Result<sdk::config::Config, config::ConfigError>)
38+
.map_err(|e: config::ConfigError| {
39+
IsK1OwnerError::InvalidConfig(e.to_string())
40+
})?,
41+
)
42+
.await
43+
.map_err(|e| IsK1OwnerError::IsK1Owner(e.to_string()))?;
44+
Ok(result)
45+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
pub mod client;
22
pub mod create;
3+
pub mod hash;
4+
pub mod revoke;
5+
pub mod state;

0 commit comments

Comments
 (0)