Skip to content

Commit

Permalink
Add new Verification method type (#1305)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucagiorgino authored Feb 29, 2024
1 parent 41105e5 commit f3ecfbb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion identity_verification/src/verification_method/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub enum MethodData {
PublicKeyBase58(String),
/// Verification Material in the JSON Web Key format.
PublicKeyJwk(Jwk),
/// Verification Material in CAIP-10 format.
/// [CAIP-10](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md)
BlockchainAccountId(String),
}

impl MethodData {
Expand All @@ -45,7 +48,7 @@ impl MethodData {
/// represented as a vector of bytes.
pub fn try_decode(&self) -> Result<Vec<u8>> {
match self {
Self::PublicKeyJwk(_) => Err(Error::InvalidMethodDataTransformation(
Self::PublicKeyJwk(_) | Self::BlockchainAccountId(_) => Err(Error::InvalidMethodDataTransformation(
"method data is not base encoded",
)),
Self::PublicKeyMultibase(input) => {
Expand Down Expand Up @@ -76,6 +79,7 @@ impl Debug for MethodData {
Self::PublicKeyJwk(inner) => f.write_fmt(format_args!("PublicKeyJwk({inner:#?})")),
Self::PublicKeyMultibase(inner) => f.write_fmt(format_args!("PublicKeyMultibase({inner})")),
Self::PublicKeyBase58(inner) => f.write_fmt(format_args!("PublicKeyBase58({inner})")),
Self::BlockchainAccountId(inner) => f.write_fmt(format_args!("BlockchainAccountId({inner})")),
}
}
}
5 changes: 5 additions & 0 deletions identity_verification/src/verification_method/method_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::error::Result;
const ED25519_VERIFICATION_KEY_2018_STR: &str = "Ed25519VerificationKey2018";
const X25519_KEY_AGREEMENT_KEY_2019_STR: &str = "X25519KeyAgreementKey2019";
const JSON_WEB_KEY_METHOD_TYPE: &str = "JsonWebKey";
const ECDSA_SECP256K1_RECOVERY_SIGNATURE_2020_STR: &str = "EcdsaSecp256k1RecoverySignature2020";

/// verification method types.
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
Expand All @@ -25,6 +26,9 @@ impl MethodType {
/// A verification method for use with JWT verification as prescribed by the [`Jwk`](::identity_jose::jwk::Jwk)
/// in the [`publicKeyJwk`](crate::MethodData::PublicKeyJwk) entry.
pub const JSON_WEB_KEY: Self = Self(Cow::Borrowed(JSON_WEB_KEY_METHOD_TYPE));
/// The `EcdsaSecp256k1RecoverySignature2020` method type.
pub const ECDSA_SECP256K1_RECOVERY_SIGNATURE_2020: Self =
Self(Cow::Borrowed(ECDSA_SECP256K1_RECOVERY_SIGNATURE_2020_STR));
}

impl MethodType {
Expand Down Expand Up @@ -54,6 +58,7 @@ impl FromStr for MethodType {
ED25519_VERIFICATION_KEY_2018_STR => Ok(Self::ED25519_VERIFICATION_KEY_2018),
X25519_KEY_AGREEMENT_KEY_2019_STR => Ok(Self::X25519_KEY_AGREEMENT_KEY_2019),
JSON_WEB_KEY_METHOD_TYPE => Ok(Self::JSON_WEB_KEY),
ECDSA_SECP256K1_RECOVERY_SIGNATURE_2020_STR => Ok(Self::ECDSA_SECP256K1_RECOVERY_SIGNATURE_2020),
_ => Ok(Self(Cow::Owned(string.to_owned()))),
}
}
Expand Down

0 comments on commit f3ecfbb

Please sign in to comment.