@credo-ts/core
Version:
<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1
54 lines (53 loc) • 2.27 kB
JavaScript
import { CredoError } from "../../../error/CredoError.mjs";
import "../../../error/index.mjs";
import { MessageValidator } from "../../../utils/MessageValidator.mjs";
import { JsonTransformer } from "../../../utils/JsonTransformer.mjs";
import "../../../utils/index.mjs";
import "../models/ClaimFormat.mjs";
import { W3cV2Credential } from "../models/credential/W3cV2Credential.mjs";
//#region src/modules/vc/data-integrity/W3cV2DataIntegrityVerifiableCredential.ts
/**
* Represents a Verifiable Credential secured with Data Integrity proof(s).
*
* @see https://www.w3.org/TR/vc-data-integrity/
*/
var W3cV2DataIntegrityVerifiableCredential = class W3cV2DataIntegrityVerifiableCredential {
constructor(options) {
this.securedCredential = options.securedCredential;
this.resolvedCredential = JsonTransformer.fromJSON(options.securedCredential, W3cV2Credential, { validate: false });
this.validate();
}
static fromObject(credential) {
return new W3cV2DataIntegrityVerifiableCredential({ securedCredential: credential });
}
/**
* The JSON representation of this credential.
*/
get encoded() {
return JSON.stringify(this.securedCredential);
}
/**
* The {@link ClaimFormat} of the credential.
*
* For W3C VC Data Integrity credentials this is always `di_vc`.
*/
get claimFormat() {
return "di_vc";
}
/**
* Validates the credential and proof structure.
*/
validate() {
MessageValidator.validateSync(this.resolvedCredential);
const proof = this.securedCredential.proof;
if (!proof) throw new CredoError("The provided credential does not have a proof field.");
if (typeof proof !== "object") throw new CredoError("The proof field must be an object or array of objects.");
if (!Array.isArray(proof) && typeof proof === "object" && (!("type" in proof) || proof.type !== "DataIntegrityProof")) throw new CredoError("The proof must have type \"DataIntegrityProof\".");
if (Array.isArray(proof)) {
for (const p of proof) if (typeof p !== "object" || !("type" in p) || p.type !== "DataIntegrityProof") throw new CredoError("All proofs in the proof array must have type \"DataIntegrityProof\".");
}
}
};
//#endregion
export { W3cV2DataIntegrityVerifiableCredential };
//# sourceMappingURL=W3cV2DataIntegrityVerifiableCredential.mjs.map