'use strict';

var ed25519 = require('@stablelib/ed25519');
require('../types/public-keys/public-key.cjs');
require('../types/public-keys/public-key-sr25519-value.cjs');
require('../types/public-keys/public-key-ed25519-value.cjs');
require('../types/public-keys/public-key-secp256k1-value.cjs');
require('../types/public-keys/public-key-x25519-value.cjs');
require('../types/signatures/signature-value.cjs');
var types_signatures_signature = require('../types/signatures/signature.cjs');
var vc_crypto_constants = require('../vc/crypto/constants.cjs');
require('../utils/types/array.cjs');
var utils_types_bytes = require('../utils/types/bytes.cjs');
require('bs58');
require('multiformats/bases/base58');
require('varint');
require('../utils/encoding/ss-58.cjs');
var keypairs_dockKeypair = require('./dock-keypair.cjs');
require('../types/generic/typed-enum.cjs');
require('../utils/types/iterable.cjs');
require('../utils/types/object.cjs');
require('crypto');
require('../utils/interfaces.cjs');
require('../utils/assert.cjs');
require('../utils/error.cjs');
require('../utils/inheritance.cjs');
require('../utils/types/set.cjs');
require('../types/generic/with-base.cjs');
require('../types/generic/with-catch-null.cjs');
require('../types/generic/with-eq.cjs');
require('../types/generic/any-of.cjs');
require('../types/generic/with-from.cjs');
require('blake2b');
require('../utils/types/string.cjs');
require('../types/generic/with-from-json-bytes.cjs');
require('../types/generic/typed-null.cjs');
require('../types/generic/create-placeholder.cjs');
require('../types/generic/typed-bytes.cjs');
require('../types/generic/typed-string.cjs');
require('../types/generic/typed-array.cjs');
require('../types/generic/typed-tuple.cjs');
require('../types/generic/typed-number.cjs');
require('../types/generic/typed-set.cjs');
require('../types/generic/typed-map.cjs');
require('../types/generic/typed-struct.cjs');
require('uuid');
require('js-sha256');
require('../types/generic/sized.cjs');
require('../utils/types/number.cjs');
require('../types/signatures/signature-ed25519-value.cjs');
require('../types/signatures/signature-secp256k1-value.cjs');
require('../types/signatures/signature-sr25519-value.cjs');

class Ed25519Keypair extends keypairs_dockKeypair {
  static Signature = types_signatures_signature.SignatureEd25519;

  static VerKeyType = vc_crypto_constants.Ed25519VerKeyName;

  static SeedSize = 32;

  /**
   *
   * Instantiates new `Ed25519Keypair` from the provided source.
   * It can have one of two types: "seed" or "private".
   *
   * @param {Uint8Array} seedOrPrivate
   * @param {"seed"|"private"} sourceType
   */
  constructor(seedOrPrivate, sourceType = 'seed') {
    let kp;
    switch (sourceType) {
      case 'seed':
        kp = ed25519.generateKeyPairFromSeed(utils_types_bytes.normalizeToU8a(seedOrPrivate));
        break;
      case 'private': {
        const secretKey = utils_types_bytes.normalizeToU8a(seedOrPrivate);
        kp = {
          secretKey,
          publicKey: ed25519.extractPublicKeyFromSecretKey(secretKey),
        };
        break;
      }
      default:
        throw new Error(
          `Unsupported source type: \`${sourceType}\`, it must be either "seed" or "private"`,
        );
    }

    super(kp);
  }

  _publicKey() {
    return this.keyPair.publicKey;
  }

  privateKey() {
    return this.keyPair.secretKey;
  }

  _sign(message) {
    return ed25519.sign(this.keyPair.secretKey, message);
  }

  static verify(message, signature, publicKey) {
    return ed25519.verify(utils_types_bytes.valueBytes(publicKey), message, utils_types_bytes.valueBytes(signature));
  }
}

module.exports = Ed25519Keypair;
//# sourceMappingURL=keypair-ed25519.cjs.map
