Skip to content

Commit

Permalink
fix: lowercase addresses (#173)
Browse files Browse the repository at this point in the history
* fix: lowercase addresses

* chore: format

* chore: refactor and fix errors

---------

Co-authored-by: Chris Smith <[email protected]>
  • Loading branch information
Elyniss and chris13524 authored Feb 9, 2024
1 parent cf06689 commit 58c4b14
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build = "build.rs"

[dependencies]
wc = { git = "https://github.com/WalletConnect/utils-rs.git", tag = "v0.7.0", features = ["geoip", "geoblock"] }
relay_rpc = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.26.0", features = ["cacao"] }
relay_rpc = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.26.1", features = ["cacao"] }

aws-config = "0.56"
aws-sdk-s3 = "0.31"
Expand Down
2 changes: 2 additions & 0 deletions src/handlers/identity/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ pub async fn handler(
error
})?;

// Note to future: accounts can have both ERC-55 and lowercase variants, with duplicates. Make sure these are merged/treated as the same account
// See for context: https://github.com/WalletConnect/keys-server/pull/173
state
.keys_persitent_storage
.create_account_if_not_exists_and_add_identity_key(
Expand Down
53 changes: 40 additions & 13 deletions src/stores/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,51 @@ impl KeysPersistentStorage for MongoPersistentStorage {
account: &str,
identity_key: &str,
) -> Result<(), StoreError> {
let filter = doc! {
"account": &account,
let err = || {
Err(StoreError::NotFound(
"Account".to_string(),
account.to_string(),
))
};

let update = doc! {
"$pull": {
"identities" : {
"identity_key": &identity_key,
async fn query(
db: &Database,
account: &str,
identity_key: &str,
) -> wither::Result<Option<MongoKeys>> {
let filter = doc! {
"account": account,
};

let update = doc! {
"$pull": {
"identities" : {
"identity_key": identity_key,
}
}
}
};
};

match MongoKeys::find_one_and_update(&self.db, filter, update, None).await? {
MongoKeys::find_one_and_update(db, filter, update, None).await
}

match query(&self.db, account, identity_key).await? {
Some(_) => Ok(()),
None => Err(StoreError::NotFound(
"Account".to_string(),
account.to_string(),
)),
None => {
// Note to future: accounts can have both ERC-55 and lowercase variants, with duplicates. Make sure these are merged/treated as the same account
// See for context: https://github.com/WalletConnect/keys-server/pull/173

// Checking if eip155 so we don't try to lowercase accounts from other chains that were
// not affected (and may have different case-sensitivity rules)
if account.starts_with("eip155") {
let lowercase_account = account.to_lowercase();
match query(&self.db, &lowercase_account, identity_key).await? {
Some(_) => Ok(()),
None => err(),
}
} else {
err()
}
}
}
}

Expand Down

0 comments on commit 58c4b14

Please sign in to comment.