Skip to content

Commit

Permalink
fix(graph-gateway): allow 0x prefix on secret keys (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus authored Nov 21, 2023
1 parent 4d74f07 commit 40c28f3
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions graph-gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::str::FromStr;
use std::time::Duration;
use std::{collections::BTreeMap, fmt, path::PathBuf};

use alloy_primitives::{Address, U256};
use alloy_primitives::{Address, B256, U256};
use graph_subscriptions::subscription_tier::{SubscriptionTier, SubscriptionTiers};
use prelude::UDecimal18;
use secp256k1::SecretKey;
use semver::Version;
use serde::Deserialize;
use serde_with::{serde_as, DisplayFromStr, FromInto};
use serde_with::{serde_as, DeserializeAs, DisplayFromStr, FromInto};
use toolshed::url::Url;

use crate::chains::ethereum;
Expand Down Expand Up @@ -154,11 +154,11 @@ impl From<KafkaConfig> for rdkafka::config::ClientConfig {
pub struct Scalar {
/// Scalar TAP verifier contract chain
pub chain_id: U256,
/// Mnemonic for legacy voucher signing
#[serde_as(as = "Option<DisplayFromStr>")]
/// Secret key for legacy voucher signing
#[serde_as(as = "Option<HiddenSecretKey>")]
pub legacy_signer: Option<Hidden<SecretKey>>,
/// Mnemonic for voucher signing
#[serde_as(as = "DisplayFromStr")]
/// Secret key for voucher signing
#[serde_as(as = "HiddenSecretKey")]
pub signer: Hidden<SecretKey>,
/// Scalar TAP verifier contract address
pub verifier: Address,
Expand Down Expand Up @@ -214,3 +214,16 @@ impl<T> Deref for Hidden<T> {
&self.0
}
}

struct HiddenSecretKey;
impl<'de> DeserializeAs<'de, Hidden<SecretKey>> for HiddenSecretKey {
fn deserialize_as<D>(deserializer: D) -> Result<Hidden<SecretKey>, D::Error>
where
D: serde::Deserializer<'de>,
{
let bytes = B256::deserialize(deserializer)?;
SecretKey::from_slice(bytes.as_slice())
.map(Hidden)
.map_err(serde::de::Error::custom)
}
}

0 comments on commit 40c28f3

Please sign in to comment.