Skip to content

Commit

Permalink
fix tendermint pubkey derivation from walletconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Sep 23, 2024
1 parent e606ca4 commit d7b5a17
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ async fn get_walletconnect_pubkey(
})?;

let pubkey = match account.algo {
CosmosAccountAlgo::Secp256k1 => {
CosmosAccountAlgo::Secp256k1 | CosmosAccountAlgo::TendermintSecp256k1 => {
TendermintPublicKey::from_raw_secp256k1(&account.pubkey).ok_or("Invalid secp256k1 pubkey".to_owned())
},
}
Expand Down
1 change: 1 addition & 0 deletions mm2src/kdf_walletconnect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
async-trait = "0.1.52"
base64 = "0.21.2"
chrono = { version = "0.4.23", "features" = ["serde"] }
common = { path = "../common" }
derive_more = "0.99"
Expand Down
13 changes: 11 additions & 2 deletions mm2src/kdf_walletconnect/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{error::WalletConnectCtxError, WalletConnectCtx};
use base64::{engine::general_purpose, Engine};
use chrono::Utc;
use common::log::info;
use futures::StreamExt;
Expand All @@ -11,9 +12,11 @@ use serde_json::Value;
use super::WcRequestMethods;

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "lowercase")]
pub enum CosmosAccountAlgo {
#[serde(rename = "lowercase")]
Secp256k1,
#[serde(rename = "tendermint/PubKeySecp256k1")]
TendermintSecp256k1,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -54,7 +57,13 @@ where
.map(|n| n as u8)
})
.collect(),
_ => Err(serde::de::Error::custom("Pubkey must be an object or array")),
Value::String(data) => {
let data = general_purpose::STANDARD
.decode(data)
.map_err(|err| serde::de::Error::custom(err.to_string()))?;
Ok(data)
},
_ => Err(serde::de::Error::custom("Pubkey must be an string, object or array")),
}
}

Expand Down
1 change: 0 additions & 1 deletion mm2src/kdf_walletconnect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod metadata;
#[allow(unused)] mod pairing;
mod session;

use async_trait::async_trait;
use chain::{build_required_namespaces,
cosmos::{cosmos_get_accounts_impl, CosmosAccount},
SUPPORTED_CHAINS};
Expand Down

0 comments on commit d7b5a17

Please sign in to comment.