-
Notifications
You must be signed in to change notification settings - Fork 18
feat(swift sdk): swift sdk implementation #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/sdk-platforms/rust/zksync-sso/crates/cli/src/deploy_contracts.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(()) | ||
| } |
40 changes: 40 additions & 0 deletions
40
packages/sdk-platforms/rust/zksync-sso/crates/cli/src/handle_cli.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
9
packages/sdk-platforms/rust/zksync-sso/crates/cli/src/main.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.