UNPKG

@web5/credentials

Version:
113 lines 3.37 kB
import { BearerDid } from '@web5/dids'; import type { JwtPayload, JwtHeaderParams } from '@web5/crypto'; import { UniversalResolver } from '@web5/dids'; /** * Represents the result of parsing a JWT (JSON Web Token). */ export type JwtParseResult = { /** * The decoded part of the JWT, which includes the verified results. * This contains the JWT's payload and other data that has been * validated against the JWT's signature to ensure its integrity and authenticity. */ decoded: JwtVerifyResult; /** * The encoded components of the JWT, including the header, payload, * and signature, each as a separate string. These are the raw, encoded * parts of the JWT as they were received or transmitted. */ encoded: { /** The encoded header of the JWT. */ header: string; /** The encoded payload of the JWT. */ payload: string; /** The encoded signature of the JWT. */ signature: string; }; }; /** * Result of verifying a JWT. */ export interface JwtVerifyResult { /** JWT Protected Header */ header: JwtHeaderParams; /** JWT Claims Set */ payload: JwtPayload; } /** * Parameters for parsing a JWT. * used in {@link Jwt.parse} */ export type ParseJwtOptions = { /** The JWT string to parse. */ jwt: string; }; /** * Parameters for signing a JWT. */ export type SignJwtOptions = { /** The DID of the signer. */ signerDid: BearerDid; /** The payload to sign. */ payload: JwtPayload; /** Overridable header parameters */ header?: { /** Type Header Parameter */ typ: string; }; }; /** * Parameters for verifying a JWT. */ export type VerifyJwtOptions = { /** The JWT string to verify. */ jwt: string; }; /** * Class for handling Compact JSON Web Tokens (JWTs). * This class provides methods to create, verify, and decode JWTs using various cryptographic algorithms. * More information on JWTs can be found [here](https://datatracker.ietf.org/doc/html/rfc7519) */ export declare class Jwt { /** * DID Resolver instance for resolving decentralized identifiers. */ static didResolver: UniversalResolver; /** * Creates a signed JWT. * * @example * ```ts * const jwt = await Jwt.sign({ signerDid: myDid, payload: myPayload }); * ``` * * @param options - Parameters for JWT creation including signer DID and payload. * @returns The compact JWT as a string. */ static sign(options: SignJwtOptions): Promise<string>; /** * Verifies a JWT. * * @example * ```ts * const verifiedJwt = await Jwt.verify({ jwt: myJwt }); * ``` * * @param options - Parameters for JWT verification * @returns Verified JWT information including signer DID, header, and payload. */ static verify(options: VerifyJwtOptions): Promise<JwtVerifyResult>; /** * Parses a JWT without verifying its signature. * * @example * ```ts * const { encoded: encodedJwt, decoded: decodedJwt } = Jwt.parse({ jwt: myJwt }); * ``` * * @param options - Parameters for JWT decoding, including the JWT string. * @returns both encoded and decoded JWT parts */ static parse(options: ParseJwtOptions): JwtParseResult; } //# sourceMappingURL=jwt.d.ts.map