import { extractPublicKeyFromSecretKey, generateKeyPairFromSeed, sign, verify } from '@stablelib/ed25519';
import '../types/public-keys/public-key.js';
import '../types/public-keys/public-key-sr25519-value.js';
import '../types/public-keys/public-key-ed25519-value.js';
import '../types/public-keys/public-key-secp256k1-value.js';
import '../types/public-keys/public-key-x25519-value.js';
import '../types/signatures/signature-value.js';
import { SignatureEd25519 } from '../types/signatures/signature.js';
import { Ed25519VerKeyName } from '../vc/crypto/constants.js';
import '../utils/types/array.js';
import { normalizeToU8a, valueBytes } from '../utils/types/bytes.js';
import 'bs58';
import 'multiformats/bases/base58';
import 'varint';
import '../utils/encoding/ss-58.js';
import DockKeypair from './dock-keypair.js';
import '../types/generic/typed-enum.js';
import '../utils/types/iterable.js';
import '../utils/types/object.js';
import 'crypto';
import '../utils/interfaces.js';
import '../utils/assert.js';
import '../utils/error.js';
import '../utils/inheritance.js';
import '../utils/types/set.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 'blake2b';
import '../utils/types/string.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/generic/sized.js';
import '../utils/types/number.js';
import '../types/signatures/signature-ed25519-value.js';
import '../types/signatures/signature-secp256k1-value.js';
import '../types/signatures/signature-sr25519-value.js';

class Ed25519Keypair extends DockKeypair {
  static Signature = SignatureEd25519;

  static VerKeyType = 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 = generateKeyPairFromSeed(normalizeToU8a(seedOrPrivate));
        break;
      case 'private': {
        const secretKey = normalizeToU8a(seedOrPrivate);
        kp = {
          secretKey,
          publicKey: 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 sign(this.keyPair.secretKey, message);
  }

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

export { Ed25519Keypair as default };
//# sourceMappingURL=keypair-ed25519.js.map
