Skip to content

Use new stellar-xdr auth functionality for iterating auths #374

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
30 changes: 4 additions & 26 deletions multisig_1_of_n_account/stellar-cli-sign-auth-ed25519/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
publish = false

[dependencies]
stellar-xdr = { version = "22.2.0", features = ["base64", "serde"] }
stellar-xdr = { version = "*", features = ["base64", "serde"], git = "https://github.com/stellar/rs-stellar-xdr", branch = "authsiter" }
serde_json = "1.0.140"
ed25519-dalek = { version = "1.0.1" }
hex = "0.4.3"
Expand Down
31 changes: 7 additions & 24 deletions multisig_1_of_n_account/stellar-cli-sign-auth-ed25519/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use clap::Parser;
use ed25519_dalek::{Keypair, Signer};
use sha2::{Digest, Sha256};
use stellar_xdr::curr::{
Hash, HashIdPreimage, HashIdPreimageSorobanAuthorization, Limited, Limits, OperationBody,
ReadXdr, ScBytes, ScMap, ScSymbol, ScVal, SorobanCredentials, TransactionEnvelope, WriteXdr,
Hash, HashIdPreimage, HashIdPreimageSorobanAuthorization, Limited, Limits, ReadXdr, ScBytes,
ScMap, ScSymbol, ScVal, SorobanCredentials, TransactionEnvelope, WriteXdr,
};

#[derive(Parser, Debug, Clone)]
Expand Down Expand Up @@ -52,31 +52,14 @@ fn main() -> Result<(), Box<dyn Error>> {
Limits::none(),
))?;

// Extract mutable references to the parts of the auths that are needed for signing.
let auths = match &mut txe {
TransactionEnvelope::Tx(e) => {
e.tx.operations
.iter_mut()
.filter_map(|op| match &mut op.body {
OperationBody::InvokeHostFunction(op) => Some(op.auth.iter_mut().filter_map(
|auth| match &mut auth.credentials {
SorobanCredentials::Address(creds) => {
Some((&mut auth.root_invocation, creds))
}
_ => None,
},
)),
_ => None,
})
.flatten()
}
_ => Err("Unsupported transaction envelope")?,
};

// Sign each auth.
// TODO:It would be wise to only sign auths matching the contract address that are intended to
// sign for, or to ask the user to confirm each auth.
for (invocation, creds) in auths {
for auth in txe.auths_mut() {
let (invocation, creds) = match &mut auth.credentials {
SorobanCredentials::Address(creds) => (&mut auth.root_invocation, creds),
_ => continue,
};
eprintln!(
"Authorizing:\n{}\n{}",
serde_json::to_string_pretty(invocation)?,
Expand Down
Loading