'use strict';

var types_generic_typedEnum = require('../../generic/typed-enum.cjs');
require('../../generic/typed-bytes.cjs');
require('../../generic/typed-string.cjs');
var types_generic_typedArray = require('../../generic/typed-array.cjs');
require('../../generic/typed-tuple.cjs');
require('../../generic/typed-null.cjs');
require('../../../utils/types/array.cjs');
require('crypto');
require('bs58');
require('multiformats/bases/base58');
require('varint');
require('../../../utils/encoding/ss-58.cjs');
require('../../generic/typed-number.cjs');
require('../../generic/typed-set.cjs');
var types_generic_typedMap = require('../../generic/typed-map.cjs');
var types_generic_typedStruct = require('../../generic/typed-struct.cjs');
require('uuid');
require('js-sha256');
require('../../public-keys/public-key.cjs');
var types_publicKeys_publicKeySr25519Value = require('../../public-keys/public-key-sr25519-value.cjs');
var types_publicKeys_publicKeyEd25519Value = require('../../public-keys/public-key-ed25519-value.cjs');
var types_publicKeys_publicKeySecp256k1Value = require('../../public-keys/public-key-secp256k1-value.cjs');
var types_publicKeys_publicKeyX25519Value = require('../../public-keys/public-key-x25519-value.cjs');
require('../../offchain-signatures/params/index.cjs');
require('../../offchain-signatures/public-keys/index.cjs');
require('../../offchain-signatures/curve-type.cjs');
var types_did_onchain_verificationRelationship = require('./verification-relationship.cjs');
require('../../../vc/crypto/Bls12381BBDT16KeyPairDock2024.cjs');
require('../../../vc/crypto/Bls12381BBDT16MACDock2024.cjs');
require('../../../vc/crypto/Bls12381BBDT16MACProofDock2024.cjs');
require('../../../vc/crypto/Bls12381BBSKeyPairDock2023.cjs');
require('../../../vc/crypto/Bls12381BBSSignatureDock2022.cjs');
require('../../../vc/crypto/Bls12381BBSSignatureDock2023.cjs');
require('../../../vc/crypto/Bls12381BBSSignatureProofDock2022.cjs');
require('../../../vc/crypto/Bls12381BBSSignatureProofDock2023.cjs');
require('../../../vc/crypto/Bls12381BDDT16KeyPairDock2024.cjs');
require('../../../vc/crypto/Bls12381BDDT16MACDock2024.cjs');
require('../../../vc/crypto/Bls12381BDDT16MACProofDock2024.cjs');
require('../../../vc/crypto/Bls12381G2KeyPairDock2022.cjs');
require('../../../vc/crypto/Bls12381PSKeyPairDock2023.cjs');
require('../../../vc/crypto/Bls12381PSSignatureDock2023.cjs');
require('../../../vc/crypto/Bls12381PSSignatureProofDock2023.cjs');
var vc_crypto_constants = require('../../../vc/crypto/constants.cjs');
require('@juanelas/base64');
require('../../../keypairs/keypair-secp256k1.cjs');
require('../../../vc/crypto/common/CustomLinkedDataSignature.cjs');
require('@stablelib/ed25519');
require('../../signatures/signature-value.cjs');
require('../../signatures/signature.cjs');
require('../../../keypairs/dock-keypair.cjs');
require('@transmute/json-web-signature');
var types_did_document_verificationMethodRef = require('../document/verification-method-ref.cjs');
var types_offchainSignatures_publicKeys_value = require('../../offchain-signatures/public-keys/value.cjs');
require('../../../utils/types/iterable.cjs');
require('../../../utils/types/object.cjs');
require('../../../utils/interfaces.cjs');
require('../../../utils/assert.cjs');
require('../../../utils/error.cjs');
require('../../../utils/inheritance.cjs');
require('../../../utils/types/set.cjs');
require('../../generic/with-base.cjs');
require('../../../utils/types/bytes.cjs');
require('../../../utils/types/string.cjs');
require('../../generic/with-catch-null.cjs');
require('../../generic/with-eq.cjs');
require('../../generic/any-of.cjs');
require('../../generic/with-from.cjs');
require('../../generic/with-from-json-bytes.cjs');
require('../../generic/create-placeholder.cjs');
require('blake2b');
require('../../generic/sized.cjs');
require('../../../utils/types/number.cjs');
require('../../offchain-signatures/params/value.cjs');
require('../../generic/option.cjs');
require('../../offchain-signatures/params/id.cjs');
require('../../generic/typed-uuid.cjs');
require('../../generic/with-from-dock-id.cjs');
require('./typed-did/index.cjs');
require('./typed-did/did-method-key/did-method-key-public-key.cjs');
require('../../../utils/encoding/base-58-btc.cjs');
require('../../generic/with-qualifier.cjs');
require('./constants.cjs');
require('./typed-did/signature.cjs');
require('./typed-did/did-method-key/did-method-key-signature.cjs');
require('../../signatures/signature-ed25519-value.cjs');
require('../../signatures/signature-secp256k1-value.cjs');
require('./typed-did/dock-did-value.cjs');
require('../../generic/utils.cjs');
require('../../generic/typed-bytes-array.cjs');
require('./typed-did/cheqd-did.cjs');
require('../../generic/with-prop.cjs');
require('../../generic/with-props.cjs');
require('../../offchain-signatures/public-keys/ref.cjs');
require('../../offchain-signatures/public-keys/id.cjs');
require('@docknetwork/crypto-wasm-ts');
require('../../../vc/crypto/common/DockCryptoKeyPair.cjs');
require('@docknetwork/crypto-wasm-ts/lib/index.js');
require('../../../vc/crypto/common/DockCryptoSignature.cjs');
require('jsonld-signatures');
require('json-stringify-deterministic');
require('semver/preload.js');
require('../../../vc/crypto/common/DockCryptoSignatureProof.cjs');
require('elliptic');
require('base64url');
require('jsonld');
require('../../../vc/jws.cjs');
require('../../signatures/signature-sr25519-value.cjs');

/**
 * Class representing either of possible DidKeys.
 * @class
 * @extends {TypedEnum}
 */
class DidKeyValue extends types_generic_typedEnum {
  static get VerKeyType() {
    return this.Class.VerKeyType;
  }
}

/**
 * Class representing Ed25519 PublicKey
 * @class
 * @extends {PublicKey}
 */
class DidKeyEd25519PublicKey extends DidKeyValue {
  static Type = 'ed25519';

  static Class = types_publicKeys_publicKeyEd25519Value;
}
/**
 * Class representing Secp256k1 PublicKey
 * @class
 * @extends {PublicKey}
 */
class DidKeySecp256k1PublicKey extends DidKeyValue {
  static Type = 'secp256k1';

  static Class = types_publicKeys_publicKeySecp256k1Value;
}
/**
 * Class representing Sr25519 PublicKey
 * @class
 * @extends {PublicKey}
 */
class DidKeySr25519PublicKey extends DidKeyValue {
  static Type = 'sr25519';

  static Class = types_publicKeys_publicKeySr25519Value;
}
/**
 * Class representing X25519 PublicKey
 * @class
 * @extends {PublicKey}
 */
class DidKeyX25519PublicKey extends DidKeyValue {
  static Type = 'x25519';

  static Class = types_publicKeys_publicKeyX25519Value;
}
class DidKeyBBSPublicKey extends DidKeyValue {
  static Class = types_offchainSignatures_publicKeys_value.BBSPublicKeyValue;

  static Type = 'bbs';

  static VerKeyType = vc_crypto_constants.Bls12381BBS23DockVerKeyName;
}
class DidKeyBBSPlusPublicKey extends DidKeyValue {
  static Class = types_offchainSignatures_publicKeys_value.BBSPlusPublicKeyValue;

  static Type = 'bbsPlus';

  static VerKeyType = vc_crypto_constants.Bls12381BBSDockVerKeyName;
}
class DidKeyPSPublicKey extends DidKeyValue {
  static Class = types_offchainSignatures_publicKeys_value.PSPublicKeyValue;

  static Type = 'ps';

  static VerKeyType = vc_crypto_constants.Bls12381PSDockVerKeyName;
}

DidKeyValue.bindVariants(
  DidKeyEd25519PublicKey,
  DidKeySecp256k1PublicKey,
  DidKeySr25519PublicKey,
  DidKeyX25519PublicKey,
  DidKeyBBSPublicKey,
  DidKeyBBSPlusPublicKey,
  DidKeyPSPublicKey,
);

const Signing = [
  DidKeyEd25519PublicKey,
  DidKeySr25519PublicKey,
  DidKeySecp256k1PublicKey,
];

const Assertion = [
  DidKeyBBSPublicKey,
  DidKeyBBSPlusPublicKey,
  DidKeyPSPublicKey,
];

class DidKey extends types_generic_typedStruct {
  static Classes = {
    publicKey: DidKeyValue,
    verRels: types_did_onchain_verificationRelationship.VerificationRelationship,
  };

  /**
   *
   * @param {DidKeyValue} pk
   * @param {VerificationRelationship} verRels
   */
  constructor(pk, verRels = new types_did_onchain_verificationRelationship.VerificationRelationship()) {
    const publicKey = DidKeyValue.from(pk);

    if (!+verRels) {
      if (
        Signing.some(
          (klass) => publicKey instanceof klass || publicKey instanceof klass.Class,
        )
      ) {
        verRels.setAllSigning();
      } else if (
        Assertion.some(
          (klass) => publicKey instanceof klass || publicKey instanceof klass.Class,
        )
      ) {
        verRels.setAssertion();
      } else {
        verRels.setKeyAgreement();
      }
    }

    super(publicKey, verRels);
  }

  static fromKeypair(keyPair, verRels) {
    return new this(keyPair.publicKey(), verRels);
  }

  isOffchain() {
    return Assertion.some((klass) => this.publicKey instanceof klass);
  }
}

class DidKeysList extends types_generic_typedArray {
  static Class = DidKey;
}

class DidKeys extends types_generic_typedMap {
  static KeyClass = types_did_document_verificationMethodRef.VerificationMethodRef;

  static ValueClass = DidKey;
}

exports.DidKey = DidKey;
exports.DidKeyBBSPlusPublicKey = DidKeyBBSPlusPublicKey;
exports.DidKeyBBSPublicKey = DidKeyBBSPublicKey;
exports.DidKeyEd25519PublicKey = DidKeyEd25519PublicKey;
exports.DidKeyPSPublicKey = DidKeyPSPublicKey;
exports.DidKeySecp256k1PublicKey = DidKeySecp256k1PublicKey;
exports.DidKeySr25519PublicKey = DidKeySr25519PublicKey;
exports.DidKeyValue = DidKeyValue;
exports.DidKeyX25519PublicKey = DidKeyX25519PublicKey;
exports.DidKeys = DidKeys;
exports.DidKeysList = DidKeysList;
//# sourceMappingURL=did-key.cjs.map
