Skip to content

Commit

Permalink
feat: encode keypair on init for icp
Browse files Browse the repository at this point in the history
  • Loading branch information
frdomovic committed Dec 3, 2024
1 parent 0c79573 commit d3f7878
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/context/config/src/client/env/proxy/types/icp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl Into<ProposalWithApprovals> for ICProposalWithApprovals {
impl From<ICProposalWithApprovals> for Option<ProposalWithApprovals> {
fn from(value: ICProposalWithApprovals) -> Self {
Some(ProposalWithApprovals {
proposal_id: Repr::from(repr::Repr::new(
proposal_id: Repr::from(Repr::new(
ProposalId::from_bytes(|bytes| {
bytes.copy_from_slice(&value.proposal_id.0);
Ok(32)
Expand Down
13 changes: 6 additions & 7 deletions crates/context/config/src/client/protocol/icp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,20 @@ impl AssociatedTransport for IcpTransport<'_> {
#[serde(try_from = "serde_creds::Credentials")]
pub struct Credentials {
pub account_id: Principal,
pub public_key: Vec<u8>,
pub secret_key: SigningKey,
pub public_key: String,
pub secret_key: String,
}

mod serde_creds {
use candid::Principal;
use ed25519_consensus::SigningKey;
use serde::{Deserialize, Serialize};
use thiserror::Error;

#[derive(Debug, Deserialize, Serialize)]
pub struct Credentials {
account_id: Principal,
public_key: Vec<u8>,
secret_key: SigningKey,
public_key: String,
secret_key: String,
}

#[derive(Copy, Clone, Debug, Error)]
Expand All @@ -67,7 +66,7 @@ mod serde_creds {
pub struct NetworkConfig {
pub rpc_url: Url,
pub account_id: Principal,
pub secret_key: SigningKey,
pub secret_key: String,
}

#[derive(Debug)]
Expand All @@ -79,7 +78,7 @@ pub struct IcpConfig<'a> {
struct Network {
client: Agent,
account_id: Principal,
secret_key: SigningKey,
secret_key: String,
}

#[derive(Clone, Debug)]
Expand Down
7 changes: 4 additions & 3 deletions crates/merod/src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use calimero_store::Store;
use clap::{Parser, ValueEnum};
use ed25519_consensus::SigningKey as IcpSigningKey;
use eyre::{bail, Result as EyreResult, WrapErr};
use hex::encode;
use ic_agent::export::Principal;
use ic_agent::identity::{BasicIdentity, Identity};
use libp2p::identity::Keypair;
Expand Down Expand Up @@ -326,7 +327,7 @@ fn generate_local_signer(
Ok(ClientLocalSigner {
rpc_url,
credentials: Credentials::Near(near_protocol::Credentials {
account_id: hex::encode(account_id).parse()?,
account_id: encode(account_id).parse()?,
public_key,
secret_key,
}),
Expand Down Expand Up @@ -359,8 +360,8 @@ fn generate_local_signer(
rpc_url,
credentials: Credentials::Icp(icp_protocol::Credentials {
account_id,
public_key,
secret_key: signing_key,
public_key: encode(&account_id),
secret_key: encode(&signing_key),
}),
})
}
Expand Down

0 comments on commit d3f7878

Please sign in to comment.