Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JWS and JWE to @web5/crypto #347

Open
frankhinek opened this issue Dec 11, 2023 · 0 comments
Open

Add JWS and JWE to @web5/crypto #347

frankhinek opened this issue Dec 11, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request package: crypto @web5/crypto package

Comments

@frankhinek
Copy link
Contributor

frankhinek commented Dec 11, 2023

Context

The @web5/crypto package currently contains type definitions and utility functions for a subset of JSON Object Signing and Encryption (JOSE) standards. JSON Web Key (JWK) is the base key format for the package, but it doesn't yet contain functionality for working with JSON Web Token (JWT), JSON Web Signature (JWS), or JSON Web Encryption (JWE).

Proposal

General Design Choices

  • Surface JOSE related types and concrete implementations in the @web5/crypto package. Other @web5 JS packages will import from this package.
  • Leverage existing high-quality, third-party OSS libraries when available to accelerate development but surface in an interface that is consistent with existing @web5 design patterns.

API Design

JSON Web Token (JWT)

export class Jwt {
  // Signature Operations
  sign(options: JwtSignOptions): Promise<string>;
  verify(options: JwtVerifyOptions): Promise<JwtVerifyResult>;

  // Cipher Operations
  encrypt(options: JwtEncryptOptions): Promise<string>;
  decrypt(options: JwtDecryptOptions): Promise<JwtDecryptResult>;
}

JSON Web Signature (JWS)

export class CompactJws {
  sign(options: ): Promise<string>
  verify(options: ): Promise<CompactVerifyResult>
}

export class FlattenedJws {
  sign(options: ): Promise<FlattenedJwsSigned>
  verify(options: ): Promise<FlattenedVerifyResult>
}

export class GeneralJws {
  sign(options: ): Promise<GeneralJwsSigned>
  verify(options: ): Promise<GeneralVerifyResult>
}

JSON Web Encryption (JWE)

export class CompactJwe {
  encrypt(options: ): Promise<string>
  decrypt(options: ): Promise<CompactDecryptResult>
}

export class FlattenedJwe {
  encrypt(options: ): Promise<FlattenedJweEncrypted>
  decrypt(options: ): Promise<FlattenedDecryptResult>
}

export class GeneralJwe {
  encrypt(options: ): Promise<GeneralJweEncrypted>
  decrypt(options: ): Promise<GeneralDecryptResult>
}

Associated Type Definitions

JWT

export interface JwtDecryptResult {
  /** JWE Protected Header */
  header: JweHeaderParams

  /** JWT Claims Set */
  payload: JwtPayload
}

export interface JwtVerifyResult {
  /** JWT Protected Header */
  header: JwtHeaderParams;

  /** JWT Claims Set */
  payload: JwtPayload;
}

JWS

export interface CompactVerifyResult {
  /** JWS Protected Header */
  header: JwsHeaderParams;

  /** JWS Payload. */
  payload: Uint8Array;
}

JWE

export interface CompactDecryptResult {
  /** JWE Protected Header */
  header: JweHeaderParams

  /** Plaintext */
  plaintext: Uint8Array
}
@frankhinek frankhinek added the enhancement New feature or request label Dec 11, 2023
@frankhinek frankhinek self-assigned this Dec 11, 2023
@frankhinek frankhinek added the package: crypto @web5/crypto package label Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request package: crypto @web5/crypto package
Projects
None yet
Development

No branches or pull requests

1 participant