

import { Hasher } from "../../../crypto/hashes/Hasher.mjs";
import { JsonTransformer } from "../../../utils/JsonTransformer.mjs";
import "../../../utils/index.mjs";
import { BaseRecord } from "../../../storage/BaseRecord.mjs";
import { uuid } from "../../../utils/uuid.mjs";
import "../../../crypto/index.mjs";
import { decodeSdJwtVc } from "../decodeSdJwtVc.mjs";
import { decodeSdJwtSync } from "@sd-jwt/decode";

//#region src/modules/sd-jwt-vc/repository/SdJwtVcRecord.ts
var SdJwtVcRecord = class SdJwtVcRecord extends BaseRecord {
	constructor(props) {
		super();
		this.type = SdJwtVcRecord.type;
		if (props) {
			this.id = props.id ?? uuid();
			this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date();
			this.compactSdJwtVc = props.compactSdJwtVc;
			this.typeMetadata = props.typeMetadata;
			this._tags = props.tags ?? {};
		}
	}
	get sdJwtVc() {
		return decodeSdJwtVc(this.compactSdJwtVc, this.typeMetadata);
	}
	getTags() {
		const sdjwt = decodeSdJwtSync(this.compactSdJwtVc, Hasher.hash);
		const vct = sdjwt.jwt.payload.vct;
		const sdAlg = sdjwt.jwt.payload._sd_alg;
		const alg = sdjwt.jwt.header.alg;
		return {
			...this._tags,
			vct,
			sdAlg: sdAlg ?? "sha-256",
			alg
		};
	}
	clone() {
		return JsonTransformer.fromJSON(JsonTransformer.toJSON(this), this.constructor);
	}
	/**
	* credential is convenience method added to all credential records
	*/
	get credential() {
		return decodeSdJwtVc(this.compactSdJwtVc, this.typeMetadata);
	}
	/**
	* encoded is convenience method added to all credential records
	*/
	get encoded() {
		return this.compactSdJwtVc;
	}
};
SdJwtVcRecord.type = "SdJwtVcRecord";

//#endregion
export { SdJwtVcRecord };
//# sourceMappingURL=SdJwtVcRecord.mjs.map