UNPKG

@klayr-did/klayr-verifiable-credentials

Version:

A library for working with W3C verifiable credentials (VC) and verifiable presentations (VP) using Klayr DID

23 lines 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCredentialsHash = exports.preprocessCredentials = void 0; const cryptography = require("@klayr/cryptography"); const credentials_context_1 = require("credentials-context"); const util_1 = require("./util"); const codec_1 = require("../codec"); function preprocessCredentials(credential) { credential['@context'] = (0, util_1.preprocessRequired)(credential['@context'], credentials_context_1.CREDENTIALS_CONTEXT_V1_URL); credential.type = (0, util_1.preprocessRequired)(credential.type, 'VerifiableCredential'); if (credential.issuanceDate === undefined) { credential.issuanceDate = new Date().toISOString(); } if (credential.id === undefined) { credential.id = `urn:sha256:${getCredentialsHash(credential).toString('hex')}`; } } exports.preprocessCredentials = preprocessCredentials; function getCredentialsHash(credential) { return cryptography.utils.hash((0, codec_1.encodeCredential)(credential)); } exports.getCredentialsHash = getCredentialsHash; //# sourceMappingURL=credentials.js.map