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

fix: lowercase addresses #173

Merged
merged 3 commits into from
Feb 9, 2024
Merged
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
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
Loading