validateAndGetSecp256k1OrEd25519 static method

IPublicKey<IVerifiyingParams> validateAndGetSecp256k1OrEd25519(
  1. List<int> pubKey
)

Validate and get a secp256k1 or Ed25519 public key.

Implementation

static IPublicKey validateAndGetSecp256k1OrEd25519(List<int> pubKey) {
  if (pubKey.length == EcdsaKeysConst.pubKeyUncompressedByteLen) {
    return _validateAndGetGenericKey(pubKey, CryptoKeyType.secp256k1);
  }
  if (pubKey.length == Ed25519KeysConst.pubKeyByteLen) {
    return _validateAndGetGenericKey(pubKey, CryptoKeyType.ed25519);
  }
  if (pubKey.length == EcdsaKeysConst.pubKeyCompressedByteLen) {
    if (pubKey[0] == Ed25519KeysConst.pubKeyPrefixInt) {
      return _validateAndGetGenericKey(pubKey, CryptoKeyType.ed25519);
    }
    return _validateAndGetGenericKey(pubKey, CryptoKeyType.secp256k1);
  }

  throw CoreErrors.addressKeyValidationFailed(
    reason: "Invalid Secp256k1 or ED25519 public key.",
  );
}