Skip to content

Commit

Permalink
Apply some minor recommendations for the did:key method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ingrid Kamga committed Sep 25, 2023
1 parent 2bb7d2f commit dfca8ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions did-utils/src/methods/did_key/alg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub enum Algorithm {

use Algorithm::*;

// See:
// - https://w3c-ccg.github.io/did-method-key/#signature-method-creation-algorithm
// - https://w3c-ccg.github.io/did-method-key/#encryption-method-creation-algorithm
impl Algorithm {
pub fn muticodec_prefix(&self) -> [u8; 2] {
match self {
Expand Down
3 changes: 2 additions & 1 deletion did-utils/src/methods/did_key/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl DIDKeyMethod {
return Err(DIDResolutionError::InvalidDid);
}

// See https://w3c-ccg.github.io/did-method-key/#format
let multibase_value = did.strip_prefix("did:key:").unwrap();
let (base, multicodec) = multibase::decode(multibase_value).map_err(|_| DIDResolutionError::InvalidDid)?;

Expand Down Expand Up @@ -194,7 +195,7 @@ impl DIDKeyMethod {
return Err(DIDResolutionError::InternalError);
}

let raw_public_key_bytes: [u8; 32] = raw_public_key_bytes.try_into().unwrap();
let raw_public_key_bytes: [u8; 32] = raw_public_key_bytes.try_into().map_err(|_| DIDResolutionError::InvalidPublicKeyLength)?;
let ed25519_keypair = Ed25519KeyPair::from_public_key(&raw_public_key_bytes).map_err(|_| DIDResolutionError::InternalError)?;
let x25519_keypair = ed25519_keypair.get_x25519().map_err(|_| DIDResolutionError::InternalError)?;

Expand Down

0 comments on commit dfca8ad

Please sign in to comment.