@vdcs/jwt
Version:
JWT implementation in typescript
42 lines (37 loc) • 1.65 kB
TypeScript
type JWTResult = {
header: Record<string, unknown>;
payload: Record<string, unknown>;
};
type JWTOptions = {
header: Record<string, unknown>;
payload: Record<string, unknown>;
};
interface EcPublicJwk {
kty: 'EC';
crv: 'P-256';
x: string;
y: string;
kid?: string;
}
interface EcPrivateJwk extends EcPublicJwk {
d: string;
}
declare const signJWT: (options: JWTOptions, privateKey: Uint8Array | EcPrivateJwk) => string;
declare const decodeJWT: (compact: string) => JWTResult;
declare const verifyJWT: (compact: string, publicKey: Uint8Array | EcPublicJwk) => JWTResult;
declare const P256: {
generateKeyPair: () => {
privateKey: Uint8Array<ArrayBufferLike>;
publicKey: Uint8Array<ArrayBufferLike>;
};
privateKeyUint8ArrayToJwk: (privateKeyBytes: Uint8Array) => EcPrivateJwk;
privateKeyJwkToUint8Array: (jwk: EcPrivateJwk) => Uint8Array;
publicKeyUint8ArrayToJwk: (publicKeyBytes: Uint8Array) => EcPublicJwk;
publicKeyJwkToUint8Array: (jwk: EcPublicJwk, compressed?: boolean) => Uint8Array;
sign: (data: Uint8Array, privateKey: Uint8Array) => Uint8Array;
verify: (msgHash: Uint8Array, signature: Uint8Array, publicKey: Uint8Array) => boolean;
};
declare const bigIntTo32Bytes: (num: bigint) => Uint8Array;
declare const normalizePrivateKey: (privateKey: Uint8Array | EcPrivateJwk) => Uint8Array;
declare const normalizePublicKey: (publicKey: Uint8Array | EcPublicJwk) => Uint8Array;
export { type EcPrivateJwk, type EcPublicJwk, type JWTOptions, type JWTResult, P256, bigIntTo32Bytes, decodeJWT, normalizePrivateKey, normalizePublicKey, signJWT, verifyJWT };