Update siwe-rs package to version 0.3.0
This commit is contained in:
parent
d090363698
commit
75a4dec009
3 changed files with 12 additions and 8 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -2786,8 +2786,9 @@ checksum = "cbce6d4507c7e4a3962091436e56e95290cb71fa302d0d270e32130b75fbff27"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "siwe"
|
name = "siwe"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
source = "git+https://github.com/silverpill/siwe-rs?rev=6589eb6fdcffbfb9ee2880906014f5cf71f0f441#6589eb6fdcffbfb9ee2880906014f5cf71f0f441"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "86f2d8ae2d4ae58df46e173aa496562ea857ac6a4f0d435ed30fcd19da0aaa79"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"hex",
|
"hex",
|
||||||
|
|
|
@ -63,7 +63,7 @@ serde_yaml = "0.8.17"
|
||||||
# Used to calculate SHA2 hashes
|
# Used to calculate SHA2 hashes
|
||||||
sha2 = "0.9.5"
|
sha2 = "0.9.5"
|
||||||
# Used to verify EIP-4361 signatures
|
# Used to verify EIP-4361 signatures
|
||||||
siwe = { git = "https://github.com/silverpill/siwe-rs", rev = "6589eb6fdcffbfb9ee2880906014f5cf71f0f441" }
|
siwe = "0.3.0"
|
||||||
# Used for creating error types
|
# Used for creating error types
|
||||||
thiserror = "1.0.24"
|
thiserror = "1.0.24"
|
||||||
# Async runtime
|
# Async runtime
|
||||||
|
|
|
@ -14,22 +14,25 @@ pub fn verify_eip4361_signature(
|
||||||
login_message: &str,
|
login_message: &str,
|
||||||
) -> Result<String, ValidationError> {
|
) -> Result<String, ValidationError> {
|
||||||
let message: Message = message.parse()
|
let message: Message = message.parse()
|
||||||
.map_err(|_| ValidationError("invalid EIP4361 message"))?;
|
.map_err(|_| ValidationError("invalid EIP-4361 message"))?;
|
||||||
let signature_bytes = <[u8; 65]>::from_hex(signature.trim_start_matches("0x"))
|
let signature_bytes = <[u8; 65]>::from_hex(signature.trim_start_matches("0x"))
|
||||||
.map_err(|_| ValidationError("invalid signature string"))?;
|
.map_err(|_| ValidationError("invalid signature string"))?;
|
||||||
message.verify(signature_bytes)
|
|
||||||
.map_err(|_| ValidationError("invalid signature"))?;
|
|
||||||
if message.domain != instance_host {
|
if message.domain != instance_host {
|
||||||
return Err(ValidationError("domain doesn't match instance host"));
|
return Err(ValidationError("domain doesn't match instance host"));
|
||||||
};
|
};
|
||||||
let statement = message.statement
|
let statement = message.statement.as_ref()
|
||||||
.ok_or(ValidationError("statement is missing"))?;
|
.ok_or(ValidationError("statement is missing"))?;
|
||||||
if statement != login_message {
|
if statement != login_message {
|
||||||
return Err(ValidationError("statement doesn't match login message"));
|
return Err(ValidationError("statement doesn't match login message"));
|
||||||
};
|
};
|
||||||
|
if !message.valid_now() {
|
||||||
|
return Err(ValidationError("message is not currently valid"));
|
||||||
|
};
|
||||||
if message.not_before.is_some() || message.expiration_time.is_some() {
|
if message.not_before.is_some() || message.expiration_time.is_some() {
|
||||||
return Err(ValidationError("message shouldn't have expiration time"));
|
return Err(ValidationError("message shouldn't have expiration time"));
|
||||||
};
|
};
|
||||||
|
message.verify_eip191(&signature_bytes)
|
||||||
|
.map_err(|_| ValidationError("invalid signature"))?;
|
||||||
// Return wallet address in lower case
|
// Return wallet address in lower case
|
||||||
let wallet_address = address_to_string(H160(message.address));
|
let wallet_address = address_to_string(H160(message.address));
|
||||||
Ok(wallet_address)
|
Ok(wallet_address)
|
||||||
|
@ -70,6 +73,6 @@ Issued At: 2022-02-14T22:27:35.500Z";
|
||||||
message, signature,
|
message, signature,
|
||||||
INSTANCE_HOST, LOGIN_MESSAGE,
|
INSTANCE_HOST, LOGIN_MESSAGE,
|
||||||
).unwrap_err();
|
).unwrap_err();
|
||||||
assert_eq!(error.to_string(), "invalid EIP4361 message");
|
assert_eq!(error.to_string(), "invalid EIP-4361 message");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue