@zk-jwt/jwt-status-list
Version:
Implementation based on https://datatracker.ietf.org/doc/draft-ietf-oauth-status-list/
123 lines (118 loc) • 3.13 kB
text/typescript
import { JwtPayload } from '@zk-jwt/types';
/**
* Reference to a status list entry.
*/
interface StatusListEntry {
idx: number;
uri: string;
}
/**
* Payload for a JWT
*/
interface JWTwithStatusListPayload extends JwtPayload {
status: {
status_list: StatusListEntry;
};
}
/**
* Payload for a JWT with a status list.
*/
interface StatusListJWTPayload extends JwtPayload {
ttl?: number;
status_list: {
bits: BitsPerStatus;
lst: string;
};
}
/**
* BitsPerStatus type.
*/
type BitsPerStatus = 1 | 2 | 4 | 8;
/**
* Header parameters for a JWT.
*/
type StatusListJWTHeaderParameters = {
alg: string;
typ: 'statuslist+jwt';
[key: string]: unknown;
};
/**
* StatusListManager is a class that manages a list of statuses with variable bit size.
*/
declare class StatusList {
private _statusList;
private bitsPerStatus;
private totalStatuses;
/**
* Create a new StatusListManager instance.
* @param statusList
* @param bitsPerStatus
*/
constructor(statusList: number[], bitsPerStatus: BitsPerStatus);
/**
* Get the status list.
*/
get statusList(): number[];
/**
* Get the number of statuses.
* @returns
*/
getBitsPerStatus(): BitsPerStatus;
/**
* Get the status at a specific index.
* @param index
*/
getStatus(index: number): number;
/**
* Set the status at a specific index.
* @param index
* @param value
*/
setStatus(index: number, value: number): void;
/**
* Compress the status list.
*/
compressStatusList(): string;
/**
* Decompress the compressed status list and return a new StatusList instance.
* @param compressed
* @param bitsPerStatus
*/
static decompressStatusList(compressed: string, bitsPerStatus: BitsPerStatus): StatusList;
/**
* Encode the status list into a byte array.
* @returns
**/
encodeStatusList(): Uint8Array;
/**
* Decode the byte array into a status list.
* @param byteArray
* @param bitsPerStatus
* @returns
*/
private static decodeStatusList;
}
/**
* Adds the status list to the payload and header of a JWT.
* @param list
* @param payload
* @param header
* @returns The header and payload with the status list added.
*/
declare function createHeaderAndPayload(list: StatusList, payload: JwtPayload, header: StatusListJWTHeaderParameters): {
header: StatusListJWTHeaderParameters;
payload: JwtPayload;
};
/**
* Get the status list from a JWT, but do not verify the signature.
* @param jwt
* @returns
*/
declare function getListFromStatusListJWT(jwt: string): StatusList;
/**
* Get the status list entry from a JWT, but do not verify the signature.
* @param jwt
* @returns
*/
declare function getStatusListFromJWT(jwt: string): StatusListEntry;
export { type BitsPerStatus, type JWTwithStatusListPayload, StatusList, type StatusListEntry, type StatusListJWTHeaderParameters, type StatusListJWTPayload, createHeaderAndPayload, getListFromStatusListJWT, getStatusListFromJWT };