Verifiable credential helper library for Alberta Digital Wallet.
- SD-JWT decoding and validation utilities.
- OpenID Federation 1.0 entity discovery with strict schema validation.
- JSON schemas copied into
distfor runtime validation and external use.
npm install @abgov/verifiable-credentials
# or
yarn add @abgov/verifiable-credentialsimport {
decodeSDJWT,
isSDJWTExpired,
discoverFederationEntity,
resolveAlbertaWallet,
} from "@abgov/verifiable-credentials";import { resolveAlbertaWallet } from "@abgov/verifiable-credentials";
const resolved = resolveAlbertaWallet({
ec,
sdjwt,
});
console.log(resolved.albertaCredentialIssuer);
console.log(resolved.credentialConfiguration);
console.log(resolved.walletCardDisplayTemplate);Resolution behavior:
- Detects Alberta issuer entity type from
ec.metadatausing JSON schema validation. - Matches config by issuer:
sdjwt.iss === credential_issuer. - Matches config by type for
VCSDJWTusingvct. - Matches config by type for
SDJWTusingtype.
import { decodeSDJWT } from "@abgov/verifiable-credentials";
const result = await decodeSDJWT(sdJwtToken);
if (result.valid) {
console.log(result.data);
console.log(result.disclosures);
} else {
console.error(result.error);
}import type { ValidationOptions } from "@abgov/verifiable-credentials";
const options: ValidationOptions = {
verifySignature: true,
checkExpiration: true,
validateDisclosureHashes: true,
signingKeyResolver: async (iss, kid, alg) => {
// Provide a public key for signature validation.
throw new Error("implement key resolution");
},
};sd-jwtvc+sd-jwt
- RSA:
RS256,RS384,RS512 - ECDSA:
ES256,ES384,ES512
src/sdjwt/README.md
import { discoverFederationEntity } from "@abgov/verifiable-credentials";
const result = await discoverFederationEntity(
{
entityId: "https://wallet.example.org",
trustAnchors: ["https://ta.example.org"],
},
{},
);
if (result.valid) {
console.log(result.data?.metadata);
} else {
console.error(result.error?.code, result.error?.message);
}The discovery result returns metadata from the subject entity configuration and a validated trust chain.
Discovery errors are returned as typed codes (InvalidInput, NetworkError, InvalidJwtType, SchemaValidationFailed, TrustChainInvalid, Unsupported) via result.error?.code.
local: trust-chain construction viafederation_fetch_endpoint.
src/openid-federation/README.md
Schema files are copied into the package build output:
dist/sdjwt/schemas/sd-jwt-v1.jsondist/sdjwt/schemas/vc+sd-jwt-v1.jsondist/openid-federation/schemas/entity-statement-v1.jsondist/openid-federation/schemas/endpoint-error-v1.jsondist/alberta-wallet/schemas/card-display-v1.jsondist/alberta-wallet/schemas/alberta-credential-issuer-v1.json
corepack enable
yarn install
# Activate conventional commit template
git config commit.template .gitmessageyarn buildBuild steps:
- Clean
dist. - Compile TypeScript (ESM) and declarations.
- Copy schema files to
dist/sdjwt/schemas,dist/openid-federation/schemas, anddist/alberta-wallet/schemas.
yarn test
yarn test:watch
yarn test:coverageyarn lint
yarn lint:fixFormatting is enforced with Prettier (config in .prettierrc) and is also surfaced through ESLint via eslint-plugin-prettier.
yarn format
yarn format:checkyarn packReleases are managed by release-please.
- Merge PR(s) with conventional commit PR titles to
main. - release-please opens a Release PR with the next version and CHANGELOG.
- Merge the Release PR when ready to cut a release.
- The publish workflow fires automatically and publishes to registry.npmjs.org.
See CONTRIBUTING.md for full details.
See CONTRIBUTING.md.
MIT License. See LICENSE for details.