

import { JsonTransformer } from "../../../utils/JsonTransformer.mjs";
import { Hasher } from "../../../crypto/hashes/Hasher.mjs";
import "../../../utils/index.mjs";
import { BaseRecord } from "../../../storage/BaseRecord.mjs";
import { uuid } from "../../../utils/uuid.mjs";
import { CredentialMultiInstanceState } from "../../../utils/credentialUseTypes.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 {
	/**
	* Only here for class transformation. If compactSdJwtVc is set we transform
	* it to the new sdJwtVcs array format
	*/
	set compactSdJwtVc(compactSdJwtVc) {
		this.credentialInstances = [{ compactSdJwtVc }];
	}
	constructor(props) {
		super();
		this.type = SdJwtVcRecord.type;
		this.multiInstanceState = CredentialMultiInstanceState.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 ? CredentialMultiInstanceState.SingleInstanceUnused : CredentialMultiInstanceState.MultiInstanceFirstUnused;
			this.typeMetadata = props.typeMetadata;
			this._tags = props.tags ?? {};
		}
	}
	get firstCredential() {
		return {
			...decodeSdJwtVc(this.credentialInstances[0].compactSdJwtVc, this.typeMetadata),
			kmsKeyId: this.credentialInstances[0].kmsKeyId
		};
	}
	static fromSdJwtVc(sdJwtVc) {
		return new SdJwtVcRecord({
			credentialInstances: [{
				compactSdJwtVc: sdJwtVc.compact,
				kmsKeyId: sdJwtVc.kmsKeyId
			}],
			typeMetadata: sdJwtVc.typeMetadata
		});
	}
	getTags() {
		const sdjwt = decodeSdJwtSync(this.credentialInstances[0].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,
			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].compactSdJwtVc;
	}
};
SdJwtVcRecord.type = "SdJwtVcRecord";

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