TBD54566975 / web5-rs

Apache License 2.0
8 stars 5 forks source link

Add support for detached compact JWS #167

Open KendallWeihe opened 3 months ago

KendallWeihe commented 3 months ago

We need to add support for detached content to our compact JWS implementation. Specifically, tbdex signatures make use of detached content.

Our CompactJws::sign function signature currently looks like this:

    pub fn sign(
        bearer_did: &BearerDid,
        key_selector: &KeySelector,
        header: &JwsHeader,
        payload: &[u8], // JSON string as a byte array, TODO add a doc comment for this
    ) -> Result<String, JwsError> {

Prior Art

AFAIK web5-js doesn't support detached compact JWS's, and instead tbdex-js creates the detached JWS

web5-kt inlines it as a function parameter

web5-go does support detached compact JWS's via an option parameter sent to the sign function

Proposal A

New function, sign_detached

pub fn sign_detached(
        bearer_did: &BearerDid,
        key_selector: &KeySelector,
        header: &JwsHeader,
        payload: &[u8], // JSON string as a byte array, TODO add a doc comment for this
    ) -> Result<String, JwsError> { 
    // ...call CompactJws::sign() and then splice out the payload from the string

Proposal B

Introduce a fifth parameter to CompactJws::sign called CompactJwsSignOptions which includes a single property pub detached: bool

pub struct CompactJwsSignOptions {
  pub detached: Option<bool>
}

// ...

    pub fn sign(
        bearer_did: &BearerDid,
        key_selector: &KeySelector,
        header: &JwsHeader,
        payload: &[u8], // JSON string as a byte array, TODO add a doc comment for this
        options: Option<CompactJwsSignOptions>
    ) -> Result<String, JwsError> { // ...

Proposal C

Introduce a fifth parameter to CompactJws::sign called detached of type bool

    pub fn sign(
        bearer_did: &BearerDid,
        key_selector: &KeySelector,
        header: &JwsHeader,
        payload: &[u8], // JSON string as a byte array, TODO add a doc comment for this
        detached: Option<bool>
    ) -> Result<String, JwsError> { // ...
KendallWeihe commented 3 months ago

I vote Proposal A