Skip to content

Commit

Permalink
Remove CSL dependency from primitives (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpinter-iohk authored Dec 31, 2024
1 parent 50646dc commit 676a85b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 21 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions toolkit/cli/smart-contracts-commands/src/register.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{parse_partnerchain_public_keys, read_private_key_from_file};
use jsonrpsee::http_client::HttpClient;
use partner_chains_cardano_offchain::csl::MainchainPrivateKeyExt;
use partner_chains_cardano_offchain::{
await_tx::FixedDelayRetries,
register::{run_deregister, run_register},
Expand All @@ -8,8 +10,6 @@ use sidechain_domain::{
PermissionedCandidateData, SidechainSignature, UtxoId,
};

use crate::{parse_partnerchain_public_keys, read_private_key_from_file};

#[derive(Clone, Debug, clap::Parser)]
pub struct RegisterCmd {
#[clap(flatten)]
Expand Down
20 changes: 19 additions & 1 deletion toolkit/offchain/src/csl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ogmios_client::{
transactions::{OgmiosBudget, OgmiosEvaluateTransactionResponse},
types::{OgmiosUtxo, OgmiosValue},
};
use sidechain_domain::{NetworkType, UtxoId};
use sidechain_domain::{MainchainAddressHash, MainchainPrivateKey, NetworkType, UtxoId};

pub(crate) fn plutus_script_hash(script_bytes: &[u8], language: LanguageKind) -> [u8; 28] {
// Before hashing the script, we need to prepend with byte denoting the language.
Expand Down Expand Up @@ -256,6 +256,24 @@ impl UtxoIdExt for UtxoId {
}
}

pub trait MainchainPrivateKeyExt {
fn to_pub_key_hash(&self) -> MainchainAddressHash;
}

impl MainchainPrivateKeyExt for MainchainPrivateKey {
fn to_pub_key_hash(&self) -> MainchainAddressHash {
cardano_serialization_lib::PrivateKey::from_normal_bytes(&self.0)
.expect("Conversion cannot fail on valid MainchainPrivateKey values")
.to_public()
.hash()
.to_bytes()
.as_slice()
.try_into()
.map(MainchainAddressHash)
.expect("Conversion cannot fail as representation is the same")
}
}

pub(crate) struct TransactionContext {
/// This key is added as required signer and used to sign the transaction.
pub(crate) payment_key: PrivateKey,
Expand Down
1 change: 1 addition & 0 deletions toolkit/offchain/src/register.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::csl::MainchainPrivateKeyExt;
use crate::csl::{
get_first_validator_budget, InputsBuilderExt, OgmiosUtxoExt, TransactionBuilderExt,
TransactionContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::config::ServiceConfig;
use crate::io::IOContext;
use crate::prepare_configuration::prepare_cardano_params::prepare_cardano_params;
use crate::{config::config_fields, *};
use partner_chains_cardano_offchain::csl::MainchainPrivateKeyExt;
use partner_chains_cardano_offchain::init_governance::InitGovernance;
use partner_chains_cardano_offchain::scripts_data::GetScriptsData;
use sidechain_domain::{MainchainAddressHash, MainchainPrivateKey, PolicyId, UtxoId};
Expand Down
1 change: 1 addition & 0 deletions toolkit/partner-chains-cli/src/register/register3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::main_chain_follower::set_main_chain_follower_env;
use crate::ogmios::config::establish_ogmios_configuration;
use crate::CmdRun;
use clap::Parser;
use partner_chains_cardano_offchain::csl::MainchainPrivateKeyExt;
use partner_chains_cardano_offchain::register::Register;
use sidechain_domain::mainchain_epoch::{MainchainEpochConfig, MainchainEpochDerivation};
use sidechain_domain::*;
Expand Down
2 changes: 0 additions & 2 deletions toolkit/primitives/domain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ lazy_static = { workspace = true }
blake2b_simd = { workspace = true }
figment = { workspace = true, optional = true }
thiserror = { workspace = true, optional = true }
cardano-serialization-lib = { workspace = true, optional = true }

[dev-dependencies]
serde_json = { workspace = true }
Expand All @@ -39,7 +38,6 @@ std = [
"num-bigint/std",
"figment",
"thiserror",
"cardano-serialization-lib",
]
serde = [
"dep:serde",
Expand Down
15 changes: 0 additions & 15 deletions toolkit/primitives/domain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,6 @@ impl core::fmt::Debug for MainchainPrivateKey {
}
}

impl MainchainPrivateKey {
#[cfg(feature = "std")]
pub fn to_pub_key_hash(&self) -> MainchainAddressHash {
cardano_serialization_lib::PrivateKey::from_normal_bytes(&self.0)
.expect("Conversion cannot fail on valid MainchainPrivateKey values")
.to_public()
.hash()
.to_bytes()
.as_slice()
.try_into()
.map(MainchainAddressHash)
.expect("Conversion cannot fail as representation is the same")
}
}

impl TryFrom<Vec<u8>> for MainchainPublicKey {
type Error = &'static str;

Expand Down

0 comments on commit 676a85b

Please sign in to comment.