UNPKG

jsonld-signatures-merkleproof2019

Version:

A jsonld signature implementation to support MerkleProof2019 verification in Verifiable Credential context

55 lines (54 loc) 2.94 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = assertProofValidity; const VerifierError_1 = __importDefault(require("../models/VerifierError")); const getText_1 = __importDefault(require("../helpers/getText")); function assertProofPurposeValidity({ expectedProofPurpose, proof, issuer }) { var _a; if (proof.proofPurpose !== expectedProofPurpose) { throw new VerifierError_1.default('assertProofValidity', (0, getText_1.default)('errors', 'assertProofValidityPurposeVerifier') .replace('${expectedProofPurpose}', expectedProofPurpose) .replace('${proof.proofPurpose}', proof.proofPurpose)); } if (issuer && !((_a = issuer[expectedProofPurpose]) === null || _a === void 0 ? void 0 : _a.includes(proof.verificationMethod))) { throw new VerifierError_1.default('assertProofValidity', (0, getText_1.default)('errors', 'assertProofValidityPurposeIssuerKey') .replace('${proof.verificationMethod}', proof.verificationMethod) .replace('${expectedProofPurpose}', expectedProofPurpose)); } if (expectedProofPurpose === 'authentication' && !proof.domain) { // TODO: return actual warning console.warn('No domain found in proof, but it is recommended for authentication purposes'); } } function assertProofDomain({ expectedDomain, proof, expectedChallenge }) { if (!expectedDomain.includes(proof.domain)) { throw new VerifierError_1.default('assertProofValidity', (0, getText_1.default)('errors', 'assertProofValidityDomainVerifier') .replace('${expectedDomain}', expectedDomain.join(', ')) .replace('${proof.domain}', proof.domain)); } if (proof.domain && !proof.challenge) { // TODO: return actual warning console.warn('No challenge found in proof, but it is recommended for domain verification'); } if (proof.challenge && proof.challenge !== expectedChallenge) { throw new VerifierError_1.default('assertProofValidity', (0, getText_1.default)('errors', 'assertProofValidityInvalidChallenge')); } } function assertProofValidity({ expectedProofPurpose, expectedDomain, expectedChallenge, proof, issuer }) { if (!proof.proofPurpose) { throw new VerifierError_1.default('assertProofValidity', (0, getText_1.default)('errors', 'assertProofValidityNoProofPurpose')); } if (!proof.created) { throw new VerifierError_1.default('assertProofValidity', (0, getText_1.default)('errors', 'assertProofValidityNoCreated')); } if (proof.proofPurpose) { assertProofPurposeValidity({ expectedProofPurpose, proof, issuer }); } if (proof.domain) { assertProofDomain({ expectedDomain, proof, expectedChallenge }); } return true; }