Skip to content

Commit

Permalink
fix: no statement format (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 authored Aug 22, 2023
1 parent ad4a145 commit 55d74d5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
4 changes: 2 additions & 2 deletions relay_rpc/src/auth/cacao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ impl Cacao {

pub fn caip122_message(&self, chain_name: &str) -> Result<String, CacaoError> {
let mut message = format!(
"{} wants you to sign in with your {} account:\n{}\n",
"{} wants you to sign in with your {} account:\n{}\n\n",
self.p.domain,
chain_name,
self.p.address()?
);

if let Some(statement) = &self.p.statement {
write!(message, "\n{}\n", statement)?;
write!(message, "{}\n", statement)?;
}

write!(
Expand Down
39 changes: 37 additions & 2 deletions relay_rpc/src/auth/cacao/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn verify_success() {
"t": "eip4361"
},
"p": {
"iss": "did:pkh:eip155:1:0xf457f233ab23f863cabc383ebb37b29d8929a17a",
"iss": "did:pkh:eip155:1:0x262f4f5DC82ad9b803680F07Da7d901D4F71d8D1",
"domain": "http://10.0.2.2:8080",
"aud": "http://10.0.2.2:8080",
"version": "1",
Expand All @@ -20,10 +20,45 @@ fn verify_success() {
},
"s": {
"t": "eip191",
"s": "0x1b39982707c70c95f4676e7386052a07b47ecc073b3e9cf47b64b579687d3f68181d48fa9e926ad591ba6954f1a70c597d0772a800bed5fa906384fcd83bcf4f1b"
"s": "0xf2f0e5dc8875ef1e3d40472078b06ebe4af5fc832e464338996fb0d3134cde7613bc36416519e8dd8959655f0e89c6b7a9de55f7c95f43e8d2240f89939ed7171c"
}
} "#;
let cacao: Cacao = serde_json::from_str(cacao_serialized).unwrap();
println!("{}", cacao.siwe_message().unwrap());
let result = cacao.verify();
assert!(result.is_ok());
assert!(result.map_err(|_| false).unwrap());

let identity_key = cacao.p.identity_key();
assert!(identity_key.is_ok());
}

/// Test that we can verify a Cacao with a statement
#[test]
fn verify_success_statement() {
let cacao_serialized = r#"{
"h": {
"t": "eip4361"
},
"p": {
"iss": "did:pkh:eip155:1:0x262f4f5DC82ad9b803680F07Da7d901D4F71d8D1",
"domain": "http://10.0.2.2:8080",
"aud": "http://10.0.2.2:8080",
"statement": "Test statement",
"version": "1",
"nonce": "[B@c3772c7",
"iat": "2023-01-17T12:15:05+01:00",
"resources": [
"did:key:z6MkkG9nM8ksS37sq5mgeoCn5kihLkWANcm9pza5WTkq3tWZ"
]
},
"s": {
"t": "eip191",
"s": "0xafedb7505846dc691a4f3f70266624a91a232d68ec61454f4426e016bcb0483773296097687429c47af82b5bf16324ec4ede13e67aee5b4597c9d34b3af0e3681c"
}
} "#;
let cacao: Cacao = serde_json::from_str(cacao_serialized).unwrap();
println!("{}", cacao.siwe_message().unwrap());
let result = cacao.verify();
assert!(result.is_ok());
assert!(result.map_err(|_| false).unwrap());
Expand Down

0 comments on commit 55d74d5

Please sign in to comment.