'use strict';

var b58 = require('bs58');
var base64 = require('@juanelas/base64');
var vc_crypto_constants = require('./constants.cjs');
var vc_crypto_Ed25519VerificationKey2018 = require('./Ed25519VerificationKey2018.cjs');
var utils_encoding_multibase = require('../../utils/encoding/multibase.cjs');
require('../../utils/types/bytes.cjs');
require('crypto');
require('../../utils/interfaces.cjs');
require('../../utils/assert.cjs');
require('../../utils/error.cjs');
require('../../utils/types/string.cjs');
require('../../utils/types/iterable.cjs');
require('../../utils/types/object.cjs');
require('../../utils/inheritance.cjs');
require('../../utils/types/set.cjs');
require('../../keypairs/keypair-ed25519.cjs');
require('@stablelib/ed25519');
require('../../types/public-keys/public-key.cjs');
require('../../types/generic/typed-enum.cjs');
require('../../utils/types/array.cjs');
require('multiformats/bases/base58');
require('varint');
require('../../utils/encoding/ss-58.cjs');
require('blake2b');
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('../../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/public-keys/public-key-x25519-value.cjs');
require('../../types/generic/sized.cjs');
require('../../utils/types/number.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-sr25519-value.cjs');
require('../../types/signatures/signature-value.cjs');
require('../../types/signatures/signature.cjs');
require('../../types/signatures/signature-ed25519-value.cjs');
require('../../types/signatures/signature-secp256k1-value.cjs');
require('../../types/signatures/signature-sr25519-value.cjs');
require('../../keypairs/dock-keypair.cjs');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var b58__default = /*#__PURE__*/_interopDefault(b58);
var base64__namespace = /*#__PURE__*/_interopNamespace(base64);

class Ed25519VerificationKey2020 extends vc_crypto_Ed25519VerificationKey2018 {
  /**
   * Construct the public key object from the verification method
   * @param verificationMethod
   * @returns {Ed25519VerificationKey2020}
   */
  static from(verificationMethod) {
    const isEd25519Type = verificationMethod.type.indexOf(vc_crypto_constants.Ed255192020VerKeyName) !== -1
      || verificationMethod.type.indexOf(vc_crypto_constants.Ed25519VerKeyName) !== -1;
    if (!verificationMethod.type || !isEd25519Type) {
      throw new Error(
        `verification method should have type ${vc_crypto_constants.Ed255192020VerKeyName} - got: ${verificationMethod.type}`,
      );
    }

    if (verificationMethod.publicKeyBase58) {
      return new this(b58__default.default.decode(verificationMethod.publicKeyBase58));
    }

    if (verificationMethod.publicKeyBase64) {
      return new this(base64__namespace.decode(verificationMethod.publicKeyBase64));
    }

    const secMultibase = verificationMethod['sec:publicKeyMultibase'];
    const multiBase = verificationMethod.publicKeyMultibase || (
      typeof secMultibase === 'object'
        ? secMultibase['@value']
        : secMultibase
    );

    if (multiBase) {
      return new this(utils_encoding_multibase.decodeFromMultibase(multiBase).slice(2));
    }

    throw new Error(
      `Unsupported signature encoding for ${vc_crypto_constants.Ed255192020VerKeyName}`,
    );
  }

  // NOTE: Ed255192020 has the same cryptography as Ed255192018, so we inherit the verifier methods
}

module.exports = Ed25519VerificationKey2020;
//# sourceMappingURL=Ed25519VerificationKey2020.cjs.map
