aboutsummaryrefslogtreecommitdiffstats
path: root/adenosine-pds/src/ucan_p256.rs
diff options
context:
space:
mode:
Diffstat (limited to 'adenosine-pds/src/ucan_p256.rs')
-rw-r--r--adenosine-pds/src/ucan_p256.rs19
1 files changed, 7 insertions, 12 deletions
diff --git a/adenosine-pds/src/ucan_p256.rs b/adenosine-pds/src/ucan_p256.rs
index 21e8a9a..b8b6cd2 100644
--- a/adenosine-pds/src/ucan_p256.rs
+++ b/adenosine-pds/src/ucan_p256.rs
@@ -11,11 +11,6 @@ use ucan::crypto::KeyMaterial;
pub use ucan::crypto::{did::P256_MAGIC_BYTES, JwtSignatureAlgorithm};
-pub fn bytes_to_p256_key(bytes: Vec<u8>) -> Result<Box<dyn KeyMaterial>> {
- let public_key = P256PublicKey::try_from(bytes.as_slice())?;
- Ok(Box::new(P256KeyMaterial(public_key, None)))
-}
-
#[derive(Clone)]
pub struct P256KeyMaterial(pub P256PublicKey, pub Option<P256PrivateKey>);
@@ -27,11 +22,7 @@ impl KeyMaterial for P256KeyMaterial {
}
async fn get_did(&self) -> Result<String> {
- let bytes = [
- P256_MAGIC_BYTES,
- &self.0.to_encoded_point(true).to_bytes().to_vec(),
- ]
- .concat();
+ let bytes = [P256_MAGIC_BYTES, &self.0.to_encoded_point(true).to_bytes()].concat();
Ok(format!("did:key:z{}", bs58::encode(bytes).into_string()))
}
@@ -55,8 +46,7 @@ impl KeyMaterial for P256KeyMaterial {
#[cfg(test)]
mod tests {
- use super::{bytes_to_p256_key, P256KeyMaterial, P256_MAGIC_BYTES};
- use p256::ecdsa::signature::{Signer, Verifier};
+ use super::{P256KeyMaterial, Result, P256_MAGIC_BYTES};
use p256::ecdsa::{SigningKey as P256PrivateKey, VerifyingKey as P256PublicKey};
use ucan::{
builder::UcanBuilder,
@@ -64,6 +54,11 @@ mod tests {
ucan::Ucan,
};
+ pub fn bytes_to_p256_key(bytes: Vec<u8>) -> Result<Box<dyn KeyMaterial>> {
+ let public_key = P256PublicKey::try_from(bytes.as_slice())?;
+ Ok(Box::new(P256KeyMaterial(public_key, None)))
+ }
+
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn it_can_sign_and_verify_a_ucan() {
let private_key = P256PrivateKey::random(&mut p256::elliptic_curve::rand_core::OsRng);