Skip to content

Commit 61ecbd7

Browse files
authored
feat: multi domain passkeys (#124)
1 parent 2432787 commit 61ecbd7

Some content is hidden

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

49 files changed

+1068
-630
lines changed

.github/workflows/ci-swift.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Swift CI
33
on:
44
push:
55
paths:
6+
- 'packages/contracts/**'
67
- 'packages/sdk-platforms/**'
78

89
jobs:
@@ -17,12 +18,6 @@ jobs:
1718
- uses: actions/checkout@v4
1819
with:
1920
submodules: recursive
20-
- name: Checkout specific contracts submodule version
21-
run: |
22-
cd packages/contracts
23-
git fetch origin debug-logs:refs/remotes/origin/debug-logs
24-
git checkout origin/debug-logs # Rust/Swift SDK depends on an old version of contracts
25-
cd ../..
2621

2722
- name: Run sccache-cache
2823
uses: mozilla-actions/sccache-action@v0.0.4
@@ -78,12 +73,12 @@ jobs:
7873
run: cargo run --bin cli -- deploy-contracts
7974
working-directory: packages/sdk-platforms/rust/zksync-sso
8075

81-
- name: Select Xcode 16.1
82-
run: sudo xcode-select -s /Applications/Xcode_16.1.app
76+
- name: Select Xcode 16.3
77+
run: sudo xcode-select -s /Applications/Xcode_16.3.app
8378

8479
- name: Select Simulator
8580
run: |
86-
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)
81+
UDID=$(xcrun simctl list devices | awk '/-- iOS 18.4 --/{flag=1; next} /--/{flag=0} flag' | grep "iPhone 16 Pro" | awk -F '[()]' '{print $2}' | head -1)
8782
if [ -z "$UDID" ]; then
8883
echo "Simulator not found!" >&2
8984
exit 1

packages/sdk-platforms/rust/zksync-sso/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resolver = "2"
55
[workspace.package]
66
version = "0.1.0"
77
edition = "2024"
8-
rust-version = "1.85"
8+
rust-version = "1.86"
99
license = "Apache-2.0"
1010

1111
[workspace.dependencies]

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use eyre::Result;
2-
use sdk::{api::utils::deploy_contracts, config::Config};
2+
use sdk::{
3+
api::utils::deploy_contracts,
4+
config::{Config, deploy_wallet::DeployWallet},
5+
};
36
use std::{fs, path::PathBuf};
47
use url::Url;
58

@@ -15,12 +18,15 @@ pub async fn deploy_contracts_and_update_swift_config(
1518
println!(" WebAuthValidator: {}", contracts.passkey);
1619
println!(" SessionKeyValidator: {}", contracts.session);
1720
println!(" ExampleAuthServerPaymaster: {}", contracts.account_paymaster);
21+
println!(" Recovery: {}", contracts.recovery);
1822

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

23-
let config = Config::new(contracts, node_url);
27+
let deploy_wallet = DeployWallet::random();
28+
29+
let config = Config::new(contracts, node_url, deploy_wallet);
2430
config.write_json(&config_path)?;
2531

2632
println!("\nVerifying written config:");
@@ -37,6 +43,7 @@ pub async fn deploy_contracts_and_update_swift_config(
3743
" ExampleAuthServerPaymaster: {}",
3844
written_config.contracts.account_paymaster
3945
);
46+
println!(" Recovery: {}", written_config.contracts.recovery);
4047

4148
println!("\nSuccessfully updated and verified Swift config values");
4249
Ok(())

packages/sdk-platforms/rust/zksync-sso/crates/ffi/build-swift-framework-ios-ci.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,5 @@ cat <<EOT >> "$WRAPPER_PATH/$FRAMEWORK_LIBRARY_NAME.swift"
120120
121121
extension Config: Codable {}
122122
extension PasskeyContracts: Codable {}
123+
extension DeployWallet: Codable {}
123124
EOT

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ pub async fn deploy_account(
6767
pub async fn deploy_account_with_unique_id(
6868
passkey_parameters: PasskeyParameters,
6969
unique_account_id: String,
70-
secret_account_salt: String,
7170
config: config::Config,
7271
) -> Result<super::Account, DeployAccountError> {
7372
sdk::api::account::deployment::deploy_account_with_unique_id(
7473
passkey_parameters.into(),
7574
unique_account_id,
76-
secret_account_salt,
7775
&(config.try_into()
7876
as Result<sdk::config::Config, config::ConfigError>)
7977
.map_err(|e: config::ConfigError| {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ pub async fn fetch_account(
4747
#[uniffi::export(async_runtime = "tokio")]
4848
pub async fn get_account_by_user_id(
4949
unique_account_id: String,
50-
secret_account_salt: String,
5150
config: config::Config,
5251
) -> Result<super::Account, FetchAccountError> {
5352
sdk::api::account::fetch::get_account_by_user_id(
5453
unique_account_id,
55-
secret_account_salt,
5654
&(config.try_into()
5755
as Result<sdk::config::Config, config::ConfigError>)
5856
.map_err(|e: config::ConfigError| {

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl From<sdk::api::account::send::SendTransactionResult>
5858
}
5959

6060
type SignFn = Box<
61-
dyn Fn(&[u8]) -> BoxFuture<'static, Result<Vec<u8>, ()>>
61+
dyn Fn(&[u8]) -> BoxFuture<'static, Result<Vec<u8>, String>>
6262
+ Send
6363
+ Sync
6464
+ 'static,
@@ -70,17 +70,27 @@ pub async fn send_transaction(
7070
authenticator: Arc<dyn PasskeyAuthenticator + 'static>,
7171
config: config::Config,
7272
) -> Result<SendTransactionResult, SendTransactionError> {
73+
println!("XDB send_transaction - transaction: {:?}", transaction);
7374
let tx: sdk::api::account::transaction::Transaction =
7475
transaction.try_into()?;
7576

77+
println!("XDB send_transaction - tx: {:?}", tx);
78+
7679
let authenticator = authenticator.clone();
7780
let sign_message: SignFn = Box::new(
78-
move |message: &[u8]| -> BoxFuture<'static, Result<Vec<u8>, ()>> {
81+
move |message: &[u8]| -> BoxFuture<'static, Result<Vec<u8>, String>> {
7982
let message_owned = message.to_vec();
8083
let auth = authenticator.clone();
81-
Box::pin(
82-
async move { auth.sign_message(message_owned).map_err(|_| ()) },
83-
)
84+
println!(
85+
"XDB send_transaction - sign_message - message_owned: {:?}",
86+
message_owned
87+
);
88+
Box::pin(async move {
89+
println!(
90+
"XDB send_transaction - sign_message - sign_message closure"
91+
);
92+
auth.sign_message(message_owned).map_err(|e| e.to_string())
93+
})
8494
},
8595
);
8696

@@ -104,16 +114,24 @@ pub async fn send_transaction_async_signer(
104114
authenticator: Arc<dyn PasskeyAuthenticatorAsync + 'static>,
105115
config: config::Config,
106116
) -> Result<SendTransactionResult, SendTransactionError> {
117+
println!(
118+
"XDB send_transaction_async_signer - transaction: {:?}",
119+
transaction
120+
);
107121
let tx: sdk::api::account::transaction::Transaction =
108122
transaction.try_into()?;
109123

124+
println!("XDB send_transaction_async_signer - tx: {:?}", tx);
125+
110126
let authenticator = authenticator.clone();
111127
let sign_message: SignFn = Box::new(
112-
move |message: &[u8]| -> BoxFuture<'static, Result<Vec<u8>, ()>> {
128+
move |message: &[u8]| -> BoxFuture<'static, Result<Vec<u8>, String>> {
113129
let message_owned = message.to_vec();
114130
let auth = authenticator.clone();
115131
Box::pin(async move {
116-
auth.sign_message(message_owned).await.map_err(|_| ())
132+
auth.sign_message(message_owned)
133+
.await
134+
.map_err(|e| e.to_string())
117135
})
118136
},
119137
);

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
use sdk::config::{self, Config as SdkConfig};
1+
use sdk::config::{
2+
self, Config as SdkConfig, deploy_wallet::DeployWallet as SdkDeployWallet,
3+
};
24

35
#[derive(Debug, thiserror::Error, uniffi::Error)]
46
pub enum ConfigError {
57
#[error("Invalid contract address: {0}")]
68
InvalidContractAddress(String),
9+
#[error("Invalid deploy wallet: {0}")]
10+
InvalidDeployWallet(String),
711
#[error("Invalid node URL: {0}")]
812
InvalidNodeUrl(String),
913
#[error("Failed to write config file: {0}")]
@@ -16,12 +20,19 @@ pub struct PasskeyContracts {
1620
pub passkey: String,
1721
pub session: String,
1822
pub account_paymaster: String,
23+
pub recovery: String,
24+
}
25+
26+
#[derive(Debug, uniffi::Record)]
27+
pub struct DeployWallet {
28+
pub private_key_hex: String,
1929
}
2030

2131
#[derive(Debug, uniffi::Record)]
2232
pub struct Config {
2333
pub contracts: PasskeyContracts,
2434
pub node_url: String,
35+
pub deploy_wallet: DeployWallet,
2536
}
2637

2738
impl TryFrom<Config> for SdkConfig {
@@ -34,9 +45,14 @@ impl TryFrom<Config> for SdkConfig {
3445
&config.contracts.passkey,
3546
&config.contracts.session,
3647
&config.contracts.account_paymaster,
48+
&config.contracts.recovery,
3749
)
3850
.map_err(|e| ConfigError::InvalidContractAddress(e.to_string()))?,
3951
&config.node_url,
52+
SdkDeployWallet::try_from(
53+
config.deploy_wallet.private_key_hex.clone(),
54+
)
55+
.map_err(|e| ConfigError::InvalidDeployWallet(e.to_string()))?,
4056
)
4157
.map_err(|e| ConfigError::InvalidNodeUrl(e.to_string()))
4258
}
@@ -56,8 +72,15 @@ impl From<SdkConfig> for Config {
5672
.contracts
5773
.account_paymaster
5874
.to_string(),
75+
recovery: sdk_config.contracts.recovery.to_string(),
5976
},
6077
node_url: sdk_config.node_url.to_string(),
78+
deploy_wallet: DeployWallet {
79+
private_key_hex: sdk_config
80+
.deploy_wallet
81+
.private_key_hex
82+
.to_string(),
83+
},
6184
}
6285
}
6386
}

packages/sdk-platforms/rust/zksync-sso/crates/sdk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public-suffix = { git = "https://github.com/jackpooleyml/passkey-rs", branch = "
5353
# URL handling
5454
url = { workspace = true, features = ["serde"] }
5555

56+
# CBOR
5657
serde_cbor = "0.11"
5758
ciborium = { version = "^0.2.1", default-features = false }
5859
ciborium-io = { version = "^0.2.0", features = ["alloc"] }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ pub async fn get_balance(
1717
let provider = zksync_provider().on_http(config.node_url.clone());
1818

1919
let balance_uint = provider.get_balance(address).await?;
20+
println!("XDB get_balance - balance_uint: {:?}", balance_uint);
2021

2122
let money = Money::eth(balance_uint);
2223

2324
let formatter = MoneyFormatter::default().with_display_decimals(6);
25+
2426
let balance = formatter.format(&money);
2527

2628
let balance = GetAccountBalanceResult { balance };

0 commit comments

Comments
 (0)