Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ import { IssueSDJWT } from './types.js';
import { base64encode, combineSDJWT } from './helpers.js';
import { IssueSDJWTError } from './errors.js';

/**
* Issues a new Selectively Disclosable JWT (SD-JWT).
*
* Packs the provided payload based on the disclosureFrame,
* adds the `_sd_alg` claim (derived from the `hash.alg` option) to indicate
* the hashing algorithm used for disclosures.
* @param header The JWT header object.
* @param payload The JWT payload object containing the claims.
* @param disclosureFrame An object defining which claims in the payload should be made selectively disclosable.
* @param options Options for issuing the SD-JWT.
* @param options.signer An asynchronous function that takes the protected header and payload, and returns the signature.
* @param options.hash An object containing the hash algorithm information.
* @param options.hash.alg A string representing the hash algorithm used for disclosures (e.g., "sha-256"). This will be added as the _sd_alg claim.
* @param options.hash.callback An asynchronous function that takes data and returns its hash.
* @param options.generateSalt An optional function to generate a salt for disclosures. If not provided, a default salt generator will be used.
* @param options.cnf An optional object representing the confirmation method claim (e.g., for key binding).
* @returns A Promise that resolves to the compact representation of the SD-JWT (a string).
* @throws {IssueSDJWTError} If the signer or hasher callback is missing or not a function.
* */
export const issueSDJWT: IssueSDJWT = async (header, payload, disclosureFrame, { signer, hash, generateSalt, cnf }) => {
if (!signer || typeof signer !== 'function') {
throw new IssueSDJWTError('Signer function is required');
Expand Down