

const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
const require_CredoError = require('../error/CredoError.js');
require('../error/index.js');
require('../agent/index.js');
require('../utils/buffer.js');
const require_MessageValidator = require('../utils/MessageValidator.js');
const require_JsonTransformer = require('../utils/JsonTransformer.js');
require('../utils/index.js');
const require_KeyManagementApi = require('../modules/kms/KeyManagementApi.js');
require('../modules/kms/index.js');
const require_VerificationMethod = require('../modules/dids/domain/verificationMethod/VerificationMethod.js');
const require_keyDidMapping = require('../modules/dids/domain/key-type/keyDidMapping.js');
require('../modules/dids/index.js');
const require_LdKeyPair = require('../modules/vc/data-integrity/models/LdKeyPair.js');
let buffer_index_js = require("buffer/index.js");
buffer_index_js = require_rolldown_runtime.__toESM(buffer_index_js);

//#region src/crypto/KmsKeyPair.ts
function createKmsKeyPairClass(agentContext) {
	return class KmsKeyPair extends require_LdKeyPair.LdKeyPair {
		constructor(options) {
			super(options);
			this.type = "KmsKeyPair";
			this.publicJwk = options.publicJwk;
		}
		static async generate() {
			throw new Error("Not implemented");
		}
		fingerprint() {
			throw new Error("Method not implemented.");
		}
		verifyFingerprint(_fingerprint) {
			throw new Error("Method not implemented.");
		}
		static async from(verificationMethod) {
			const vMethod = require_JsonTransformer.JsonTransformer.fromJSON(verificationMethod, require_VerificationMethod.VerificationMethod);
			require_MessageValidator.MessageValidator.validateSync(vMethod);
			const publicJwk = require_keyDidMapping.getPublicJwkFromVerificationMethod(vMethod);
			return new KmsKeyPair({
				id: vMethod.id,
				controller: vMethod.controller,
				publicJwk
			});
		}
		/**
		* This method returns a wrapped wallet.sign method. The method is being wrapped so we can covert between Uint8Array and Buffer. This is to make it compatible with the external signature libraries.
		*/
		signer() {
			const wrappedSign = async (data) => {
				if (Array.isArray(data.data)) throw new require_CredoError.CredoError("Signing array of data entries is not supported");
				return (await agentContext.dependencyManager.resolve(require_KeyManagementApi.KeyManagementApi).sign({
					data: data.data,
					keyId: this.publicJwk.keyId,
					algorithm: this.publicJwk.signatureAlgorithm
				})).signature;
			};
			return { sign: wrappedSign.bind(this) };
		}
		/**
		* This method returns a wrapped wallet.verify method. The method is being wrapped so we can covert between Uint8Array and Buffer. This is to make it compatible with the external signature libraries.
		*/
		verifier() {
			const wrappedVerify = async (data) => {
				if (Array.isArray(data.data)) throw new require_CredoError.CredoError("Verifying array of data entries is not supported");
				const { verified } = await agentContext.dependencyManager.resolve(require_KeyManagementApi.KeyManagementApi).verify({
					data: data.data,
					signature: buffer_index_js.Buffer.from(data.signature),
					key: { publicJwk: this.publicJwk.toJson() },
					algorithm: this.publicJwk.signatureAlgorithm
				});
				return verified;
			};
			return { verify: wrappedVerify.bind(this) };
		}
		get publicKeyBuffer() {
			const publicKey = this.publicJwk.publicKey;
			if (publicKey.kty === "RSA") throw new require_CredoError.CredoError(`kty 'RSA' not supported for publicKeyBuffer`);
			return publicKey.publicKey;
		}
	};
}

//#endregion
exports.createKmsKeyPairClass = createKmsKeyPairClass;