Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: missing support for defi-wallet (fix #469) #471

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions extra-cpp-bindings/src/wallectconnectregistry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,6 @@ mod test {
assert_eq!(wallets.len(), 20);
}

#[test]
fn test_fetch_new_no_cache() {
let reg = Registry::fetch_new(None);
assert!(reg.is_ok());
}

#[test]
fn test_fetch_new_with_cache() {
let mut dir = std::env::temp_dir();
let tmpfile = format!("{}.json", uuid::Uuid::new_v4());
dir.push(tmpfile);
println!("{:?}", dir);

let reg = Registry::fetch_new(Some(dir.clone()));
assert!(reg.is_ok());

let reg = Registry::load_cached(Some(dir));
assert!(reg.is_ok());
}

#[test]
fn test_load_cached() {
let reg = Registry::load_cached(Some(PathBuf::from("./not_exists.json")));
Expand Down
2 changes: 0 additions & 2 deletions integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,5 @@ $PWD/demo/build/examples/get_tokens_blocking
$PWD/demo/build/examples/get_token_transfers_blocking
$PWD/demo/build/examples/create_payment
$PWD/demo/build/examples/wallet_connect
$PWD/demo/build/examples/get_token_holders
$PWD/demo/build/examples/new_wallet
$PWD/demo/build/examples/restore_wallet
$PWD/demo/build/examples/get_wallet
2 changes: 1 addition & 1 deletion wallet-connect/examples/web3_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
chainid: CHAIN_ID.parse::<u64>()?,
gas_limit: "21000".into(),
gas_price: "1000000000".into(),
nonce: "0".into(),
nonce: "".into(),
web3api_url: "".into(),
},
to: TO_ADDRESS.into(),
Expand Down
1 change: 0 additions & 1 deletion wallet-connect/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ mod aead;
/// wrapper around the symmetric key
mod key;

pub use aead::*;
pub use key::*;
27 changes: 27 additions & 0 deletions wallet-connect/src/v2/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use async_trait::async_trait;
use ethers::prelude::PendingTransaction;
use ethers::types::transaction::eip2718::TypedTransaction;
use ethers::types::BlockId;
use ethers::types::U256;
use ethers::{
prelude::{
Address, Bytes, JsonRpcClient, Middleware, MiddlewareError, NameOrAddress, Provider,
Expand Down Expand Up @@ -242,6 +243,21 @@ fn append_hex(s: String) -> String {
}
}

// tx_bytes is 32 bytes, for defi-wallet , it's txhash
fn make_defiwallet_signature(tx_bytes: &[u8]) -> Option<Signature> {
// print hex of tx_bytes
if tx_bytes.len() == 32 {
let r = U256::from_big_endian(tx_bytes);
let s = U256::zero();
let v = 0;
// r: 32 bytes, s: 32bytes, v: 1 bytes
let sig = Signature { r, s, v };
Some(sig)
} else {
None
}
}

#[async_trait]
impl Middleware for WCMiddleware<Provider<Client>> {
type Error = WCError<Provider<Client>>;
Expand All @@ -268,6 +284,9 @@ impl Middleware for WCMiddleware<Provider<Client>> {
}
if let Some(data) = tx.data() {
tx_obj.insert("data", format!("0x{}", hex::encode(data)));
} else {
// need for defi wallet, otherwise user rejection error
tx_obj.insert("data", "0x".to_string());
}
if let Some(gas) = tx.gas() {
// gas not working for webwallet
Expand Down Expand Up @@ -299,6 +318,14 @@ impl Middleware for WCMiddleware<Provider<Client>> {
))));
}

if tx_rlp.as_raw().len() == 32 {
// It's not RLP-encoded
return make_defiwallet_signature(tx_rlp.as_raw()).ok_or_else(|| {
WCError::ClientError(ClientError::Eyre(eyre!(
"failed to decode defiwallet tx-hash signature"
)))
});
}
let first_byte = tx_rlp.as_raw()[0];
// TODO: check that the decoded request matches the typed transaction content here? or a new `sign_transaction` function that returns both request+signature?
if first_byte <= 0x7f {
Expand Down
2 changes: 1 addition & 1 deletion wallet-connect/src/v2/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl JsonRpcClient for Connector {
.required_namespaces
.eip155
.chains
.get(0)
.first()
.map(ToOwned::to_owned)
.unwrap_or_else(|| "eip155:25".to_owned());
// release the lock
Expand Down
2 changes: 1 addition & 1 deletion wallet-connect/src/v2/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub struct WcSessionProposeResponse {
pub struct WcSessionSettle {
relay: Relay,
pub namespaces: Namespaces,
#[serde(rename = "requiredNamespaces")]
#[serde(rename = "requiredNamespaces", default)]
required_namespaces: RequiredNamespaces,
pub controller: Peer,
expiry: i64,
Expand Down
Loading