import DockKeypair from './dock-keypair.js';
import { DidKey } from '../types/did/onchain/did-key.js';
import VerificationMethodRefOrIdentRef from '../types/did/document/verification-method-ref-or-ident-ref.js';
import '../utils/types/array.js';
import 'crypto';
import { ensureInstanceOf } from '../utils/inheritance.js';
import 'bs58';
import 'multiformats/bases/base58';
import 'varint';
import '../utils/encoding/ss-58.js';
import { DidMethodKey } from '../types/did/onchain/typed-did/index.js';
import '../utils/types/bytes.js';
import '../utils/interfaces.js';
import '../utils/assert.js';
import '../utils/error.js';
import '../utils/types/string.js';
import '../utils/types/iterable.js';
import '../utils/types/object.js';
import '../types/generic/typed-enum.js';
import '../types/generic/with-base.js';
import '../types/generic/with-catch-null.js';
import '../types/generic/with-eq.js';
import '../types/generic/any-of.js';
import '../types/generic/with-from.js';
import '../types/generic/with-from-json-bytes.js';
import '../types/generic/typed-null.js';
import '../types/generic/create-placeholder.js';
import '../types/generic/typed-bytes.js';
import '../types/generic/typed-string.js';
import '../types/generic/typed-array.js';
import '../types/generic/typed-tuple.js';
import '../types/generic/typed-number.js';
import '../types/generic/typed-set.js';
import '../types/generic/typed-map.js';
import '../types/generic/typed-struct.js';
import 'uuid';
import 'js-sha256';
import '../types/public-keys/public-key.js';
import '../types/public-keys/public-key-x25519-value.js';
import '../types/generic/sized.js';
import '../utils/types/number.js';
import '../types/public-keys/public-key-ed25519-value.js';
import '../vc/crypto/constants.js';
import '../types/public-keys/public-key-secp256k1-value.js';
import '../types/public-keys/public-key-sr25519-value.js';
import '../types/offchain-signatures/params/index.js';
import '../types/offchain-signatures/params/value.js';
import '../types/generic/option.js';
import '../types/offchain-signatures/curve-type.js';
import '../types/offchain-signatures/params/id.js';
import '../types/generic/typed-uuid.js';
import '../types/generic/with-from-dock-id.js';
import '../types/offchain-signatures/public-keys/index.js';
import '../types/generic/with-prop.js';
import '../types/generic/with-props.js';
import '../vc/crypto/Bls12381BBDT16KeyPairDock2024.js';
import '@docknetwork/crypto-wasm-ts';
import '../vc/crypto/common/DockCryptoKeyPair.js';
import '../vc/crypto/Bls12381BBDT16MACDock2024.js';
import '@docknetwork/crypto-wasm-ts/lib/index.js';
import '../vc/crypto/common/DockCryptoSignature.js';
import 'jsonld-signatures';
import 'json-stringify-deterministic';
import 'semver/preload.js';
import '../vc/crypto/common/CustomLinkedDataSignature.js';
import 'base64url';
import 'jsonld';
import '../types/did/document/verification-method-ref.js';
import '../types/generic/with-qualifier.js';
import '../types/generic/utils.js';
import '../types/generic/typed-bytes-array.js';
import '../types/did/onchain/typed-did/cheqd-did.js';
import '../types/did/onchain/constants.js';
import '../vc/jws.js';
import '../vc/crypto/Bls12381BBDT16MACProofDock2024.js';
import '../vc/crypto/common/DockCryptoSignatureProof.js';
import '../vc/crypto/Bls12381BBSKeyPairDock2023.js';
import '../vc/crypto/Bls12381BBSSignatureDock2022.js';
import '../vc/crypto/Bls12381G2KeyPairDock2022.js';
import '../vc/crypto/Bls12381BBSSignatureDock2023.js';
import '../vc/crypto/Bls12381BBSSignatureProofDock2022.js';
import '../vc/crypto/Bls12381BBSSignatureProofDock2023.js';
import '../vc/crypto/Bls12381BDDT16KeyPairDock2024.js';
import '../vc/crypto/Bls12381BDDT16MACDock2024.js';
import '../vc/crypto/Bls12381BDDT16MACProofDock2024.js';
import '../vc/crypto/Bls12381PSKeyPairDock2023.js';
import '../vc/crypto/Bls12381PSSignatureDock2023.js';
import '../vc/crypto/Bls12381PSSignatureProofDock2023.js';
import '@juanelas/base64';
import './keypair-secp256k1.js';
import 'elliptic';
import '../types/signatures/signature-value.js';
import '../types/signatures/signature.js';
import '../types/signatures/signature-ed25519-value.js';
import '../types/signatures/signature-secp256k1-value.js';
import '../types/signatures/signature-sr25519-value.js';
import '@stablelib/ed25519';
import '@transmute/json-web-signature';
import '../types/offchain-signatures/public-keys/value.js';
import '../types/offchain-signatures/public-keys/ref.js';
import '../types/did/onchain/typed-did/dock-did-value.js';
import '../types/did/onchain/typed-did/signature.js';
import '../types/offchain-signatures/public-keys/id.js';
import '../types/did/onchain/verification-relationship.js';
import '../types/did/document/ident-ref.js';
import '../utils/types/set.js';
import 'blake2b';
import '../types/did/onchain/typed-did/did-method-key/did-method-key-public-key.js';
import '../utils/encoding/base-58-btc.js';
import '../types/did/onchain/typed-did/did-method-key/did-method-key-signature.js';

/**
 * A class representation of DID Keypair which includes a signing keypair and its associated verification method reference identifier.
 */
class DidKeypair {
  /**
   * Constructs a `DidKeypair` instance from the supplied keypair.
   *
   * @param {VerificationMethodRefOrIdentRef} keyRef - The reference of the verification method.
   * @param {DockKeypair} keyPair - Key pair provided.
   */
  constructor(keyRef, keyPair) {
    this.verificationMethodId = VerificationMethodRefOrIdentRef.from(keyRef);
    this.keyPair = ensureInstanceOf(keyPair, DockKeypair);
  }

  /**
   * Static function to create a `DidKeypair` instance from the provided keyPair.
   *
   * @param {DockKeypair} keyPair - Key pair provided.
   * @return The new instance of `DidKeypair`.
   */
  static didMethodKey(keyPair) {
    const did = DidMethodKey.fromKeypair(keyPair);

    return new this([did, did.asDidMethodKey.toEncodedString()], keyPair);
  }

  /**
   * Get the public key from the current key pair.
   *
   * @return The public key.
   */
  publicKey() {
    return this.keyPair.publicKey();
  }

  /**
   * Creates a new `DidKey` instance from the public key of the current key pair.
   *
   * @param {?number} verRels - Number indicating verification relationships.
   * @return The new instance of `DidKey`.
   */
  didKey(verRels) {
    return new DidKey(this.keyPair.publicKey(), verRels);
  }

  /**
   * Get the DID from the current verification method ID.
   *
   * @return The DID.
   */
  get did() {
    return this.verificationMethodId[0];
  }

  /**
   * Get the Key ID from the current verification method ID.
   *
   * @return The Key ID.
   */
  get keyId() {
    return this.verificationMethodId[1];
  }

  /**
   * Sign the provided message with the key pair.
   *
   * @param {Uint8Array} message - The message to sign.
   * @return The signature.
   */
  sign(message) {
    return this.keyPair.sign(message);
  }

  /**
   * Detects a key prefix from a key document
   *
   * @return The DidKeypair instance
   */
  static detectKeyPrefix(keyDocument) {
    if (typeof keyDocument.id === 'string') {
      return keyDocument.id.split('#')[1]?.split('-')[0] || 'keys';
    }
    return 'keys';
  }
}

export { DidKeypair as default };
//# sourceMappingURL=did-keypair.js.map
