Skip to content

Async signer / verifier support #181

@Gozala

Description

@Gozala

@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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions