Skip to content

01. Examples

Lukas.J.Han edited this page Dec 15, 2023 · 1 revision
  • Issuing a SD JWT
import sdjwt, { DisclosureFrame } from '@hopae/sd-jwt';

const { privateKey, publicKey } = createKeyPair();
  const claims = {
    firstname: 'John',
    lastname: 'Doe',
    ssn: '123-45-6789',
    id: '1234',
  };
  const disclosureFrame: DisclosureFrame<typeof claims> = {
    _sd: ['firstname', 'id'],
  };
  const encodedSdjwt = await sdjwt.issue(claims, privateKey, disclosureFrame);
  console.log('encodedSdjwt:', encodedSdjwt);
  • Presenting a SD JWT
import sdjwt from '@hopae/sd-jwt';

const presentationFrame = ['firstname', 'id'];
const presentedSDJwt = await sdjwt.present(encodedSdjwt, presentationFrame);
console.log('presentedSDJwt:', presentedSDJwt);
  • Verifying a SD JWT
const requiredClaimKeys = ['firstname', 'id'];
const verified = await sdjwt.verify(
  encodedSdjwt,
  publicKey,
  requiredClaimKeys,
);
console.log('verified:', verified);

NOTE: async/await is part of ECMAScript 2017 and is not supported in Internet Explorer and older browsers, so use with caution.

Clone this wiki locally