Skip to content

Commit

Permalink
fixup! Implement EIP-712-based linked data proof type
Browse files Browse the repository at this point in the history
Fix using without Eip712Method2021/keccak-hash
  • Loading branch information
clehner committed Feb 24, 2021
1 parent a160cad commit bfc0f47
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,14 @@ impl From<BlockchainAccountIdVerifyError> for Error {
}
}

#[cfg(feature = "keccak-hash")]
impl From<TypedDataConstructionError> for Error {
fn from(err: TypedDataConstructionError) -> Error {
Error::TypedDataConstruction(err)
}
}

#[cfg(feature = "keccak-hash")]
impl From<TypedDataHashError> for Error {
fn from(err: TypedDataHashError) -> Error {
Error::TypedDataHash(err)
Expand Down
6 changes: 6 additions & 0 deletions src/ldp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl ProofPreparation {
"EcdsaSecp256k1RecoverySignature2020" => {
EcdsaSecp256k1RecoverySignature2020::complete(self, signature).await
}
#[cfg(feature = "keccak-hash")]
"Eip712Signature2021" => Eip712Signature2021::complete(self, signature).await,
_ => Err(Error::ProofTypeNotImplemented),
}
Expand Down Expand Up @@ -175,6 +176,7 @@ impl LinkedDataProofs {
x509_thumbprint_sha256: _,
} if ec_params.curve == Some("secp256k1".to_string()) => {
if algorithm.as_ref() == Some(&Algorithm::ES256KR) {
#[cfg(feature = "keccak-hash")]
if let Some(ref vm) = options.verification_method {
if vm.ends_with("#Eip712Method2021") {
return Eip712Signature2021::sign(document, options, &key).await;
Expand Down Expand Up @@ -217,6 +219,7 @@ impl LinkedDataProofs {
return EcdsaSecp256k1Signature2019::prepare(document, options, public_key).await
}
Algorithm::ES256KR => {
#[cfg(feature = "keccak-hash")]
if let Some(ref vm) = options.verification_method {
if vm.ends_with("#Eip712Method2021") {
return Eip712Signature2021::prepare(document, options, public_key).await;
Expand Down Expand Up @@ -251,6 +254,7 @@ impl LinkedDataProofs {
"EcdsaSecp256k1RecoverySignature2020" => {
EcdsaSecp256k1RecoverySignature2020::verify(proof, document, resolver).await
}
#[cfg(feature = "keccak-hash")]
"Eip712Signature2021" => Eip712Signature2021::verify(proof, document, resolver).await,
_ => Err(Error::ProofTypeNotImplemented),
}
Expand Down Expand Up @@ -678,8 +682,10 @@ impl ProofSuite for Ed25519BLAKE2BDigestSize20Base58CheckEncodedSignature2021 {
}
}

#[cfg(feature = "keccak-hash")]
pub struct Eip712Signature2021;
#[async_trait]
#[cfg(feature = "keccak-hash")]
impl ProofSuite for Eip712Signature2021 {
async fn sign(
document: &(dyn LinkedDataDocument + Sync),
Expand Down
1 change: 1 addition & 0 deletions src/vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@ mod tests {
let preparation = vc.prepare_proof(&public_key, &issue_options).await.unwrap();
let signing_input = match preparation.signing_input {
crate::ldp::SigningInput::Bytes(ref bytes) => bytes,
#[allow(unreachable_patterns)]
_ => panic!("Unexpected signing input type"),
};
let sig = crate::jws::sign_bytes(algorithm, &signing_input, &key).unwrap();
Expand Down

0 comments on commit bfc0f47

Please sign in to comment.