spruceid / cacao-rs

5 stars 1 forks source link

Fix compilation #2

Closed clehner closed 2 years ago

clehner commented 2 years ago
diff --git a/src/lib.rs b/src/lib.rs
index 87d79c3..6c93807 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -81,6 +81,8 @@ pub enum VerificationError {
     Crypto,
     #[error("Normalisation of verification input failed")]
     Serialization,
+    #[error("Time error")]
+    Time,
     #[error("Missing Payload Verification Material")]
     MissingVerificationMaterial,
     #[error("Not Currently Valid")]
diff --git a/src/siwe.rs b/src/siwe.rs
index 76923bd..c63ed10 100644
--- a/src/siwe.rs
+++ b/src/siwe.rs
@@ -24,6 +24,7 @@ impl From<SVE> for VerificationError {
         match e {
             SVE::Crypto(_) | SVE::Signer => Self::Crypto,
             SVE::Serialization(_) => Self::Serialization,
+            SVE::Time => Self::Time,
         }
     }
 }
@@ -42,7 +43,7 @@ impl TryInto<Message> for Payload {
             address,
             chain_id,
             statement: self.statement,
-            uri: self.aud,
+            uri: self.aud.into(),
             version: self.version.into(),
             nonce: self.nonce,
             issued_at: self.iat,
@@ -66,7 +67,7 @@ impl From<Message> for Payload {
             .parse()
             .unwrap(),
             statement: m.statement,
-            aud: m.uri,
+            aud: m.uri.try_into().unwrap(),
             version: m.version.into(),
             nonce: m.nonce,
             iat: m.issued_at,
@@ -94,7 +95,7 @@ impl SignatureScheme for SignInWithEthereum {
             .clone()
             .try_into()
             .map_err(|_| VerificationError::MissingVerificationMaterial)?;
-        m.verify_eip191(sig.s)?;
+        m.verify_eip191(&sig.s)?;
         Ok(())
     }
 }
clehner commented 2 years ago

Note: aud: m.uri.try_into().unwrap(), fails when the URI is a did:key verification method DID URL. e.g.

thread 'tests::[...]' panicked at 'called `Result::unwrap()` on an `Err` value: CreationError { source: RiString("did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp#z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp"), error: Error(()) }', /home/cel/src/cacao-rs/src/siwe.rs:72:35
clehner commented 2 years ago

Fixed in #6, including allowing verification method DID URL in uri.