@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
67 lines (66 loc) • 2.99 kB
JavaScript
import { CredoError } from "../../../error/CredoError.mjs";
import "../../../error/index.mjs";
import { JsonTransformer } from "../../../utils/JsonTransformer.mjs";
import { DateTransformer } from "../../../utils/transformers.mjs";
import "../../../utils/index.mjs";
import __decorateMetadata from "../../../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorateMetadata.mjs";
import __decorate from "../../../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorate.mjs";
import { BaseRecord } from "../../../storage/BaseRecord.mjs";
import { uuid } from "../../../utils/uuid.mjs";
//#region src/modules/mdoc/repository/MdocVerificationSessionRecord.ts
/**
* A verification session for an mdoc presentation, currently the ISO/IEC TS 18013-7:2025 Annex C
* (`org-iso-mdoc`) DC API.
*
* The device response is never persisted. It contains the disclosed claims, and the caller already
* has it — for the DC API the exchange is synchronous, so the response is returned to the caller
* rather than delivered out of band.
*/
var MdocVerificationSessionRecord = class MdocVerificationSessionRecord extends BaseRecord {
constructor(props) {
super();
this.type = MdocVerificationSessionRecord.type;
if (props) {
this.id = props.id ?? uuid();
this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date();
this._tags = props.tags ?? {};
this.state = props.state;
this.errorMessage = props.errorMessage;
this.deviceRequestBase64Url = props.deviceRequestBase64Url;
this.deviceRequestDefinition = props.deviceRequestDefinition;
this.sessionTranscript = props.sessionTranscript;
this.sessionKeyId = props.sessionKeyId;
this.expiresAt = props.expiresAt;
}
}
/**
* The session transcript, asserted to be of a specific protocol.
*/
getSessionTranscript(type) {
if (this.sessionTranscript.type !== type) throw new CredoError(`MdocVerificationSessionRecord uses mdoc protocol ${this.sessionTranscript.type}, but ${type} was expected.`);
return this.sessionTranscript;
}
assertState(expectedStates) {
const states = Array.isArray(expectedStates) ? expectedStates : [expectedStates];
if (!states.includes(this.state)) throw new CredoError(`MdocVerificationSessionRecord is in invalid state ${this.state}. Valid states are: ${states.join(", ")}.`);
}
get isExpired() {
return this.expiresAt.getTime() < Date.now();
}
getTags() {
return {
...this._tags,
state: this.state,
sessionTranscriptType: this.sessionTranscript.type,
nonce: this.sessionTranscript.nonce
};
}
clone() {
return JsonTransformer.fromJSON(JsonTransformer.toJSON(this), this.constructor);
}
};
MdocVerificationSessionRecord.type = "MdocVerificationSessionRecord";
__decorate([DateTransformer(), __decorateMetadata("design:type", typeof Date === "undefined" ? Object : Date)], MdocVerificationSessionRecord.prototype, "expiresAt", void 0);
//#endregion
export { MdocVerificationSessionRecord };
//# sourceMappingURL=MdocVerificationSessionRecord.mjs.map