

const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.js');
const require_JsonTransformer = require('../../../utils/JsonTransformer.js');
const require_Hasher = require('../../../crypto/hashes/Hasher.js');
require('../../../utils/index.js');
const require_BaseRecord = require('../../../storage/BaseRecord.js');
const require_uuid = require('../../../utils/uuid.js');
const require_credentialUseTypes = require('../../../utils/credentialUseTypes.js');
require('../../../crypto/index.js');
const require_decodeSdJwtVc = require('../decodeSdJwtVc.js');
let __sd_jwt_decode = require("@sd-jwt/decode");

//#region src/modules/sd-jwt-vc/repository/SdJwtVcRecord.ts
var SdJwtVcRecord = class SdJwtVcRecord extends require_BaseRecord.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 = require_credentialUseTypes.CredentialMultiInstanceState.SingleInstanceUsed;
		if (props) {
			this.id = props.id ?? require_uuid.uuid();
			this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date();
			this.credentialInstances = props.credentialInstances;
			this.multiInstanceState = this.credentialInstances.length === 1 ? require_credentialUseTypes.CredentialMultiInstanceState.SingleInstanceUnused : require_credentialUseTypes.CredentialMultiInstanceState.MultiInstanceFirstUnused;
			this.typeMetadata = props.typeMetadata;
			this._tags = props.tags ?? {};
		}
	}
	get firstCredential() {
		return {
			...require_decodeSdJwtVc.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 = (0, __sd_jwt_decode.decodeSdJwtSync)(this.credentialInstances[0].compactSdJwtVc, require_Hasher.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 require_JsonTransformer.JsonTransformer.fromJSON(require_JsonTransformer.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
exports.SdJwtVcRecord = SdJwtVcRecord;