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

64 lines (63 loc) • 2.02 kB
import { JsonTransformer } from "../../../utils/JsonTransformer.mjs"; import "../../../utils/index.mjs"; import { BaseRecord } from "../../../storage/BaseRecord.mjs"; import { uuid } from "../../../utils/uuid.mjs"; import "../../../utils/credentialUseTypes.mjs"; import { Mdoc } from "../Mdoc.mjs"; //#region src/modules/mdoc/repository/MdocRecord.ts var MdocRecord = class MdocRecord extends BaseRecord { /** * Only here for class transformation. If base64Url is set we transform * it to the new mdocs array format */ set base64Url(base64Url) { this.credentialInstances = [{ issuerSignedBase64Url: base64Url }]; } constructor(props) { super(); this.type = MdocRecord.type; this.multiInstanceState = "SingleInstanceUsed"; if (props) { this.id = props.id ?? uuid(); this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date(); this.credentialInstances = props.credentialInstances; this.multiInstanceState = this.credentialInstances.length === 1 ? "SingleInstanceUnused" : "MultiInstanceFirstUnused"; this._tags = props.tags ?? {}; } } get firstCredential() { const mdoc = Mdoc.fromBase64Url(this.credentialInstances[0].issuerSignedBase64Url); mdoc.deviceKeyId = this.credentialInstances[0].kmsKeyId ?? mdoc.deviceKey?.legacyKeyId; return mdoc; } static fromMdoc(mdoc) { return new MdocRecord({ credentialInstances: [{ issuerSignedBase64Url: mdoc.base64Url, kmsKeyId: mdoc.deviceKeyId }] }); } getTags() { const mdoc = this.firstCredential; const docType = mdoc.docType; const alg = mdoc.alg; return { ...this._tags, docType, alg, multiInstanceState: this.multiInstanceState }; } clone() { return JsonTransformer.fromJSON(JsonTransformer.toJSON(this), this.constructor); } /** * encoded is convenience method added to all credential records */ get encoded() { return this.credentialInstances[0].issuerSignedBase64Url; } }; MdocRecord.type = "MdocRecord"; //#endregion export { MdocRecord }; //# sourceMappingURL=MdocRecord.mjs.map