Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
JayT106 committed Nov 8, 2024
1 parent 14d90d4 commit c85ff39
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 11 additions & 1 deletion core/node/da_clients/src/avail/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use zksync_da_client::{
};

use crate::avail::sdk::RawAvailClient;
use hex::FromHex;

/// An implementation of the `DataAvailabilityClient` trait that interacts with the Avail network.
#[derive(Debug, Clone)]
Expand All @@ -21,7 +22,16 @@ pub struct AvailClient {
impl AvailClient {
pub async fn new(config: AvailConfig, secrets: AvailSecrets) -> anyhow::Result<Self> {
let sdk_client = if secrets.private_key.is_some() {
RawAvailClient::new_with_gcs_seed(config.app_id, &secrets.private_key.unwrap()).await?
let pk = secrets.private_key.clone().unwrap();

let bytes = Vec::from_hex(pk).map_err(|e| anyhow::anyhow!("hex string convert failed: {}", e.to_string()))?;
if bytes.len() != 32 {
return Err(anyhow::anyhow!("Hex string must represent exactly 32 bytes."));
}
let mut array = [0u8; 32];
array.copy_from_slice(&bytes);

RawAvailClient::new_with_gcs_seed(config.app_id, array).await?
} else {
let seed_phrase = secrets
.seed_phrase
Expand Down
8 changes: 3 additions & 5 deletions core/node/da_clients/src/avail/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use parity_scale_codec::{Compact, Decode, Encode};
use scale_encode::EncodeAsFields;
use subxt_signer::{
bip39::Mnemonic,
sr25519::{Keypair, Signature},
sr25519::{Keypair, Seed, Signature},
};

use crate::avail::client::to_non_retriable_da_error;
Expand Down Expand Up @@ -47,10 +47,8 @@ impl RawAvailClient {
Ok(Self { app_id, keypair })
}

pub(crate) async fn new_with_gcs_seed(app_id: u32, seed: &str) -> anyhow::Result<Self> {
let bytes: [u8; 32] = seed.as_bytes().try_into().map_err(|_| anyhow::anyhow!("String must be exactly 32 bytes"))?;
let keypair = Keypair::from_seed(bytes)?;

pub(crate) async fn new_with_gcs_seed(app_id: u32, seed: Seed) -> anyhow::Result<Self> {
let keypair = Keypair::from_seed(seed)?;
Ok(Self { app_id, keypair })
}

Expand Down

0 comments on commit c85ff39

Please sign in to comment.