UNPKG

@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

100 lines (96 loc) • 4.82 kB
import { asArray, mapSingleOrArray } from "../../../../utils/array.mjs"; import { JsonTransformer } from "../../../../utils/JsonTransformer.mjs"; import { IsInstanceOrArrayOfInstances, IsUri } from "../../../../utils/validators.mjs"; import "../../../../utils/index.mjs"; import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs"; import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs"; import { CREDENTIALS_CONTEXT_V1_URL } from "../../constants.mjs"; import { IsCredentialJsonLdContext, IsCredentialType } from "../../validators.mjs"; import { W3cCredentialSchema } from "./W3cCredentialSchema.mjs"; import { W3cCredentialStatus } from "./W3cCredentialStatus.mjs"; import { IsW3cCredentialSubject, W3cCredentialSubject, W3cCredentialSubjectTransformer } from "./W3cCredentialSubject.mjs"; import { IsW3cIssuer, W3cIssuer, W3cIssuerTransformer } from "./W3cIssuer.mjs"; import { Expose, Type } from "class-transformer"; import { IsInstance, IsOptional, IsRFC3339, ValidateNested } from "class-validator"; //#region src/modules/vc/models/credential/W3cCredential.ts var _ref, _ref2, _ref3; var W3cCredential = class W3cCredential { constructor(options) { if (options) { this.context = options.context ?? [CREDENTIALS_CONTEXT_V1_URL]; this.id = options.id; this.type = options.type || ["VerifiableCredential"]; this.issuer = typeof options.issuer === "string" || options.issuer instanceof W3cIssuer ? options.issuer : new W3cIssuer(options.issuer); this.issuanceDate = options.issuanceDate; this.expirationDate = options.expirationDate; this.credentialSubject = mapSingleOrArray(options.credentialSubject, (subject) => subject instanceof W3cCredentialSubject ? subject : new W3cCredentialSubject(subject)); if (options.credentialStatus) this.credentialStatus = options.credentialStatus instanceof W3cCredentialStatus ? options.credentialStatus : new W3cCredentialStatus(options.credentialStatus); if (options.credentialSchema) this.credentialSchema = mapSingleOrArray(options.credentialSchema, (schema) => schema instanceof W3cCredentialSchema ? schema : new W3cCredentialSchema(schema)); } } get issuerId() { return this.issuer instanceof W3cIssuer ? this.issuer.id : this.issuer; } get credentialSchemaIds() { if (!this.credentialSchema) return []; if (Array.isArray(this.credentialSchema)) return this.credentialSchema.map((credentialSchema) => credentialSchema.id); return [this.credentialSchema.id]; } get credentialSubjectIds() { if (Array.isArray(this.credentialSubject)) return this.credentialSubject.map((credentialSubject) => credentialSubject.id).filter((v) => v !== void 0); return this.credentialSubject.id ? [this.credentialSubject.id] : []; } get contexts() { return asArray(this.context); } static fromJson(json) { return JsonTransformer.fromJSON(json, W3cCredential); } }; __decorate([ Expose({ name: "@context" }), IsCredentialJsonLdContext(), __decorateMetadata("design:type", typeof (_ref = typeof Array !== "undefined" && Array) === "function" ? _ref : Object) ], W3cCredential.prototype, "context", void 0); __decorate([ IsOptional(), IsUri(), __decorateMetadata("design:type", String) ], W3cCredential.prototype, "id", void 0); __decorate([IsCredentialType(), __decorateMetadata("design:type", typeof (_ref2 = typeof Array !== "undefined" && Array) === "function" ? _ref2 : Object)], W3cCredential.prototype, "type", void 0); __decorate([ W3cIssuerTransformer(), IsW3cIssuer(), __decorateMetadata("design:type", Object) ], W3cCredential.prototype, "issuer", void 0); __decorate([IsRFC3339(), __decorateMetadata("design:type", String)], W3cCredential.prototype, "issuanceDate", void 0); __decorate([ IsRFC3339(), IsOptional(), __decorateMetadata("design:type", String) ], W3cCredential.prototype, "expirationDate", void 0); __decorate([ IsW3cCredentialSubject({ each: true }), W3cCredentialSubjectTransformer(), __decorateMetadata("design:type", Object) ], W3cCredential.prototype, "credentialSubject", void 0); __decorate([ IsOptional(), Type(() => W3cCredentialSchema), ValidateNested({ each: true }), IsInstanceOrArrayOfInstances({ classType: W3cCredentialSchema, allowEmptyArray: true }), __decorateMetadata("design:type", Object) ], W3cCredential.prototype, "credentialSchema", void 0); __decorate([ IsOptional(), Type(() => W3cCredentialStatus), ValidateNested({ each: true }), IsInstance(W3cCredentialStatus), __decorateMetadata("design:type", typeof (_ref3 = typeof W3cCredentialStatus !== "undefined" && W3cCredentialStatus) === "function" ? _ref3 : Object) ], W3cCredential.prototype, "credentialStatus", void 0); //#endregion export { W3cCredential }; //# sourceMappingURL=W3cCredential.mjs.map