@expede we've being trying to integrate rs-ucan into a system that need to make use of web crypto and ran up against sync API design
|
pub trait DidSigner { |
|
/// The associated DID type. |
|
type Did: Did + Clone; |
|
|
|
/// Get the associated DID. |
|
fn did(&self) -> &Self::Did; |
|
|
|
/// Get the associated signer instance. |
|
fn signer(&self) -> &<<Self::Did as Did>::VarsigConfig as Sign>::Signer; |
|
} |
|
pub trait Sign: Verify { |
|
/// The signing key. |
|
type Signer: Signer<Self::Signature>; |
|
|
|
/// Signing errors. |
|
type SignError: Error; |
|
|
|
/// Synchronously sign a payload. |
|
/// |
|
/// # Errors |
|
/// |
|
/// If encoding or signing fails, a `SignerError` is returned. |
|
#[allow(clippy::type_complexity)] |
|
#[tracing::instrument(skip_all)] |
|
fn try_sign<T, C: Codec<T>>( |
|
&self, |
|
codec: &C, |
|
signer: &Self::Signer, |
|
payload: &T, |
|
) -> Result<(Self::Signature, Vec<u8>), SignerError<C::EncodingError, Self::SignError>> { |
|
let mut buffer = Vec::new(); |
|
codec |
|
.encode_payload(payload, &mut buffer) |
|
.map_err(SignerError::EncodingError)?; |
|
let sig = signer |
|
.try_sign(&buffer) |
|
.map_err(SignerError::SigningError)?; |
|
Ok((sig, buffer)) |
|
} |
|
} |
I do see there is also async Sign variant
|
pub trait AsyncSign: Verify { |
But as far as I can tell it isn't integrated anywhere and I'm not sure complexity of of having a sync / async split is worth it.
@expede we've being trying to integrate rs-ucan into a system that need to make use of web crypto and ran up against sync API design
rs-ucan/ucan/src/did.rs
Lines 26 to 35 in c4d1cb7
rs-ucan/varsig/src/signer.rs
Lines 11 to 40 in c4d1cb7
I do see there is also async Sign variant
rs-ucan/varsig/src/signer.rs
Line 43 in c4d1cb7
But as far as I can tell it isn't integrated anywhere and I'm not sure complexity of of having a sync / async split is worth it.