-
Notifications
You must be signed in to change notification settings - Fork 123
feat: tx sign and new signer
#1590
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
26 commits
Select commit
Hold shift + click to select a range
bf88e36
feat: `tx sign` and new traits for signing
willemneal df58864
refactor(tx): test
willemneal 58630c3
Merge remote-tracking branch 'origin/main' into feat/tx_sign
willemneal a0cc592
fix: simplify sign_with
willemneal c705666
Apply suggestions from code review
willemneal 00aaedc
fix: address PR review
willemneal 8745dc5
Merge remote-tracking branch 'origin/main' into feat/tx_sign
willemneal ada184f
Merge remote-tracking branch 'origin/main' into feat/tx_sign
willemneal 00d989a
fix: remove unneeded arg
willemneal c36f788
rename Transaction trait to SignTx and collapse traits
leighmcculloch 1470057
rename account to key
leighmcculloch 70837be
update docs
leighmcculloch bf7f88d
flatten layer of one liner
leighmcculloch c2a7cc2
undo move transaction_hash, remove trait
leighmcculloch df299e8
undo change
leighmcculloch 9beed05
rename Stellar error to Signer
leighmcculloch d3e22cc
move StellarSigner and eliminate trait
leighmcculloch ded7eba
handle instead of panic on error
leighmcculloch 015435b
move types into signer and replace existing signing logic
leighmcculloch baf7036
address clippy
leighmcculloch f3fbff7
lab.stellar.org
leighmcculloch d56fa09
clippy
leighmcculloch 25102a0
remove unnecessary trim
leighmcculloch 02245e7
fix e2e test run and tweak
leighmcculloch 376c464
remove deadcode
leighmcculloch 1db4b5a
remove sign with lab
leighmcculloch 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
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
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,45 @@ | ||
| use crate::{ | ||
| commands::global, | ||
| config::{locator, network, sign_with}, | ||
| xdr::{self, Limits, WriteXdr}, | ||
| }; | ||
|
|
||
| #[derive(thiserror::Error, Debug)] | ||
| pub enum Error { | ||
| #[error(transparent)] | ||
| XdrArgs(#[from] super::xdr::Error), | ||
| #[error(transparent)] | ||
| Network(#[from] network::Error), | ||
| #[error(transparent)] | ||
| Locator(#[from] locator::Error), | ||
| #[error(transparent)] | ||
| SignWith(#[from] sign_with::Error), | ||
| #[error(transparent)] | ||
| Xdr(#[from] xdr::Error), | ||
| } | ||
|
|
||
| #[derive(Debug, clap::Parser, Clone)] | ||
| #[group(skip)] | ||
| pub struct Cmd { | ||
| #[command(flatten)] | ||
| pub sign_with: sign_with::Args, | ||
| #[command(flatten)] | ||
| pub network: network::Args, | ||
| #[command(flatten)] | ||
| pub locator: locator::Args, | ||
| } | ||
|
|
||
| impl Cmd { | ||
| #[allow(clippy::unused_async)] | ||
| pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> { | ||
| let tx_env = super::xdr::tx_envelope_from_stdin()?; | ||
| let tx_env_signed = self.sign_with.sign_tx_env( | ||
| tx_env, | ||
| &self.locator, | ||
| &self.network.get(&self.locator)?, | ||
| global_args.quiet, | ||
| )?; | ||
| println!("{}", tx_env_signed.to_xdr_base64(Limits::none())?); | ||
| 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
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
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,53 @@ | ||
| use crate::{signer, xdr::TransactionEnvelope}; | ||
| use clap::arg; | ||
|
|
||
| use super::{ | ||
| locator, | ||
| network::{self, Network}, | ||
| secret, | ||
| }; | ||
|
|
||
| #[derive(thiserror::Error, Debug)] | ||
| pub enum Error { | ||
| #[error(transparent)] | ||
| Network(#[from] network::Error), | ||
| #[error(transparent)] | ||
| Signer(#[from] signer::Error), | ||
| #[error(transparent)] | ||
| Secret(#[from] secret::Error), | ||
| #[error(transparent)] | ||
| Locator(#[from] locator::Error), | ||
| #[error(transparent)] | ||
| Rpc(#[from] soroban_rpc::Error), | ||
| #[error("No sign with key provided")] | ||
| NoSignWithKey, | ||
| #[error(transparent)] | ||
| StrKey(#[from] stellar_strkey::DecodeError), | ||
| } | ||
|
|
||
| #[derive(Debug, clap::Args, Clone, Default)] | ||
| #[group(skip)] | ||
| pub struct Args { | ||
| /// Sign with a local key. Can be an identity (--sign-with-key alice), a secret key (--sign-with-key SC36…), or a seed phrase (--sign-with-key "kite urban…"). If using seed phrase, `--hd-path` defaults to the `0` path. | ||
| #[arg(long, env = "STELLAR_SIGN_WITH_KEY")] | ||
| pub sign_with_key: Option<String>, | ||
|
|
||
| #[arg(long, requires = "sign_with_key")] | ||
| /// If using a seed phrase to sign, sets which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` | ||
| pub hd_path: Option<usize>, | ||
| } | ||
|
|
||
| impl Args { | ||
| pub fn sign_tx_env( | ||
| &self, | ||
| tx: TransactionEnvelope, | ||
| locator: &locator::Args, | ||
| network: &Network, | ||
| quiet: bool, | ||
| ) -> Result<TransactionEnvelope, Error> { | ||
| let key_or_name = self.sign_with_key.as_deref().ok_or(Error::NoSignWithKey)?; | ||
| let secret = locator.key(key_or_name)?; | ||
| let signer = secret.signer(self.hd_path, quiet)?; | ||
| Ok(signer.sign_tx_env(tx, network)?) | ||
| } | ||
| } | ||
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.
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.