Skip to content

Commit

Permalink
soroban-cli: upgrade ed25519-dalek to version 2.0.0 (#984)
Browse files Browse the repository at this point in the history
* update dalek dependency to use dalek 2.0.0

* clippy
  • Loading branch information
tsachiherman authored Sep 22, 2023
1 parent 3e201ad commit b5b0b78
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 114 deletions.
80 changes: 13 additions & 67 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion cmd/soroban-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ rand = "0.8.5"
wasmparser = { workspace = true }
sha2 = { workspace = true }
csv = "1.1.6"
ed25519-dalek = "1.0.1"
ed25519-dalek = "2.0.0"
jsonrpsee-http-client = "0.20.1"
jsonrpsee-core = "0.20.1"
hyper = "0.14.27"
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-cli/src/commands/config/identity/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Cmd {
Ok(())
}

pub fn private_key(&self) -> Result<ed25519_dalek::Keypair, Error> {
pub fn private_key(&self) -> Result<ed25519_dalek::SigningKey, Error> {
Ok(if let Some(name) = &self.name {
self.locator.read_identity(name)?
} else {
Expand All @@ -46,7 +46,7 @@ impl Cmd {

pub fn public_key(&self) -> Result<stellar_strkey::ed25519::PublicKey, Error> {
Ok(stellar_strkey::ed25519::PublicKey::from_payload(
self.private_key()?.public.as_bytes(),
self.private_key()?.verifying_key().as_bytes(),
)?)
}
}
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct Args {
}

impl Args {
pub fn key_pair(&self) -> Result<ed25519_dalek::Keypair, Error> {
pub fn key_pair(&self) -> Result<ed25519_dalek::SigningKey, Error> {
let key = if let Some(source_account) = &self.source_account {
self.account(source_account)?
} else {
Expand Down
6 changes: 3 additions & 3 deletions cmd/soroban-cli/src/commands/config/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ impl Secret {
pub fn public_key(&self, index: Option<usize>) -> Result<PublicKey, Error> {
let key = self.key_pair(index)?;
Ok(stellar_strkey::ed25519::PublicKey::from_payload(
key.public.as_bytes(),
key.verifying_key().as_bytes(),
)?)
}

pub fn key_pair(&self, index: Option<usize>) -> Result<ed25519_dalek::Keypair, Error> {
Ok(utils::into_key_pair(&self.private_key(index)?)?)
pub fn key_pair(&self, index: Option<usize>) -> Result<ed25519_dalek::SigningKey, Error> {
Ok(utils::into_signing_key(&self.private_key(index)?))
}

pub fn from_seed(seed: Option<&str>) -> Result<Self, Error> {
Expand Down
5 changes: 3 additions & 2 deletions cmd/soroban-cli/src/commands/contract/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ impl Cmd {
let ledgers_to_expire = self.ledgers_to_expire();

// Get the account sequence number
let public_strkey = stellar_strkey::ed25519::PublicKey(key.public.to_bytes()).to_string();
let public_strkey =
stellar_strkey::ed25519::PublicKey(key.verifying_key().to_bytes()).to_string();
let account_details = client.get_account(&public_strkey).await?;
let sequence: i64 = account_details.seq_num.into();

let tx = Transaction {
source_account: MuxedAccount::Ed25519(Uint256(key.public.to_bytes())),
source_account: MuxedAccount::Ed25519(Uint256(key.verifying_key().to_bytes())),
fee: self.fee.fee,
seq_num: SequenceNumber(sequence + 1),
cond: Preconditions::None,
Expand Down
9 changes: 5 additions & 4 deletions cmd/soroban-cli/src/commands/contract/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ impl Cmd {
let key = self.config.key_pair()?;

// Get the account sequence number
let public_strkey = stellar_strkey::ed25519::PublicKey(key.public.to_bytes()).to_string();
let public_strkey =
stellar_strkey::ed25519::PublicKey(key.verifying_key().to_bytes()).to_string();

let account_details = client.get_account(&public_strkey).await?;
let sequence: i64 = account_details.seq_num.into();
Expand All @@ -197,10 +198,10 @@ fn build_create_contract_tx(
fee: u32,
network_passphrase: &str,
salt: [u8; 32],
key: &ed25519_dalek::Keypair,
key: &ed25519_dalek::SigningKey,
) -> Result<(Transaction, Hash), Error> {
let source_account = AccountId(PublicKey::PublicKeyTypeEd25519(
key.public.to_bytes().into(),
key.verifying_key().to_bytes().into(),
));

let contract_id_preimage = ContractIdPreimage::Address(ContractIdPreimageFromAddress {
Expand All @@ -220,7 +221,7 @@ fn build_create_contract_tx(
}),
};
let tx = Transaction {
source_account: MuxedAccount::Ed25519(Uint256(key.public.to_bytes())),
source_account: MuxedAccount::Ed25519(Uint256(key.verifying_key().to_bytes())),
fee,
seq_num: SequenceNumber(sequence),
cond: Preconditions::None,
Expand Down
11 changes: 7 additions & 4 deletions cmd/soroban-cli/src/commands/contract/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ impl Cmd {
let key = self.config.key_pair()?;

// Get the account sequence number
let public_strkey = stellar_strkey::ed25519::PublicKey(key.public.to_bytes()).to_string();
let public_strkey =
stellar_strkey::ed25519::PublicKey(key.verifying_key().to_bytes()).to_string();
let account_details = client.get_account(&public_strkey).await?;
let sequence: i64 = account_details.seq_num.into();

Expand Down Expand Up @@ -137,20 +138,22 @@ pub(crate) fn build_install_contract_code_tx(
source_code: Vec<u8>,
sequence: i64,
fee: u32,
key: &ed25519_dalek::Keypair,
key: &ed25519_dalek::SigningKey,
) -> Result<(Transaction, Hash), XdrError> {
let hash = utils::contract_hash(&source_code)?;

let op = Operation {
source_account: Some(MuxedAccount::Ed25519(Uint256(key.public.to_bytes()))),
source_account: Some(MuxedAccount::Ed25519(Uint256(
key.verifying_key().to_bytes(),
))),
body: OperationBody::InvokeHostFunction(InvokeHostFunctionOp {
host_function: HostFunction::UploadContractWasm(source_code.try_into()?),
auth: VecM::default(),
}),
};

let tx = Transaction {
source_account: MuxedAccount::Ed25519(Uint256(key.public.to_bytes())),
source_account: MuxedAccount::Ed25519(Uint256(key.verifying_key().to_bytes())),
fee,
seq_num: SequenceNumber(sequence),
cond: Preconditions::None,
Expand Down
15 changes: 8 additions & 7 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::str::FromStr;
use std::{fmt::Debug, fs, io, rc::Rc};

use clap::{arg, command, value_parser, Parser};
use ed25519_dalek::Keypair;
use ed25519_dalek::SigningKey;
use heck::ToKebabCase;
use soroban_env_host::e2e_invoke::{get_ledger_changes, ExpirationEntryMap};
use soroban_env_host::xdr::ReadXdr;
Expand Down Expand Up @@ -173,7 +173,7 @@ impl Cmd {
&self,
contract_id: [u8; 32],
spec_entries: &[ScSpecEntry],
) -> Result<(String, Spec, InvokeContractArgs, Vec<Keypair>), Error> {
) -> Result<(String, Spec, InvokeContractArgs, Vec<SigningKey>), Error> {
let spec = Spec(Some(spec_entries.to_vec()));
let mut cmd = clap::Command::new(self.contract_id.clone())
.no_binary_name(true)
Expand All @@ -189,7 +189,7 @@ impl Cmd {

let func = spec.find_function(function)?;
// create parsed_args in same order as the inputs to func
let mut signers: Vec<Keypair> = vec![];
let mut signers: Vec<SigningKey> = vec![];
let parsed_args = func
.inputs
.iter()
Expand Down Expand Up @@ -291,7 +291,8 @@ impl Cmd {
let key = self.config.key_pair()?;

// Get the account sequence number
let public_strkey = stellar_strkey::ed25519::PublicKey(key.public.to_bytes()).to_string();
let public_strkey =
stellar_strkey::ed25519::PublicKey(key.verifying_key().to_bytes()).to_string();
let account_details = client.get_account(&public_strkey).await?;
let sequence: i64 = account_details.seq_num.into();

Expand Down Expand Up @@ -348,7 +349,7 @@ impl Cmd {

// Create source account, adding it to the ledger if not already present.
let source_account = AccountId(PublicKey::PublicKeyTypeEd25519(Uint256(
self.config.key_pair()?.public.to_bytes(),
self.config.key_pair()?.verifying_key().to_bytes(),
)));
let source_account_ledger_key = LedgerKey::Account(LedgerKeyAccount {
account_id: source_account.clone(),
Expand Down Expand Up @@ -536,7 +537,7 @@ fn build_invoke_contract_tx(
parameters: InvokeContractArgs,
sequence: i64,
fee: u32,
key: &Keypair,
key: &SigningKey,
) -> Result<Transaction, Error> {
let op = Operation {
source_account: None,
Expand All @@ -546,7 +547,7 @@ fn build_invoke_contract_tx(
}),
};
Ok(Transaction {
source_account: MuxedAccount::Ed25519(Uint256(key.public.to_bytes())),
source_account: MuxedAccount::Ed25519(Uint256(key.verifying_key().to_bytes())),
fee,
seq_num: SequenceNumber(sequence),
cond: Preconditions::None,
Expand Down
Loading

0 comments on commit b5b0b78

Please sign in to comment.