libraries/eosiolib/core/eosio/crypto.hpp
Detailed Description
Copyright: defined in eos/LICENSE
Source code
#pragma once
#include "fixed_bytes.hpp"
#include "varint.hpp"
#include "serialize.hpp"
#include <array>
namespace eosio {
using ecc_public_key = std::array<char, 33>;
struct webauthn_public_key {
enum class user_presence_t : uint8_t {
USER_PRESENCE_NONE,
USER_PRESENCE_PRESENT,
USER_PRESENCE_VERIFIED
};
ecc_public_key key;
user_presence_t user_presence;
std::string rpid;
friend bool operator == ( const webauthn_public_key& a, const webauthn_public_key& b ) {
return std::tie(a.key,a.user_presence,a.rpid) == std::tie(b.key,b.user_presence,b.rpid);
}
friend bool operator != ( const webauthn_public_key& a, const webauthn_public_key& b ) {
return std::tie(a.key,a.user_presence,a.rpid) != std::tie(b.key,b.user_presence,b.rpid);
}
friend bool operator < ( const webauthn_public_key& a, const webauthn_public_key& b ) {
return std::tie(a.key,a.user_presence,a.rpid) < std::tie(b.key,b.user_presence,b.rpid);
}
friend bool operator <= ( const webauthn_public_key& a, const webauthn_public_key& b ) {
return std::tie(a.key,a.user_presence,a.rpid) <= std::tie(b.key,b.user_presence,b.rpid);
}
friend bool operator > ( const webauthn_public_key& a, const webauthn_public_key& b ) {
return std::tie(a.key,a.user_presence,a.rpid) > std::tie(b.key,b.user_presence,b.rpid);
}
friend bool operator >= ( const webauthn_public_key& a, const webauthn_public_key& b ) {
return std::tie(a.key,a.user_presence,a.rpid) >= std::tie(b.key,b.user_presence,b.rpid);
}
};
using public_key = std::variant<ecc_public_key, ecc_public_key, webauthn_public_key>;
template<typename DataStream>
inline DataStream& operator<<(DataStream& ds, const eosio::webauthn_public_key& pubkey) {
ds << pubkey.key << pubkey.user_presence << pubkey.rpid;
return ds;
}
template<typename DataStream>
inline DataStream& operator>>(DataStream& ds, eosio::webauthn_public_key& pubkey) {
ds >> pubkey.key >> pubkey.user_presence >> pubkey.rpid;
return ds;
}
using ecc_signature = std::array<char, 65>;
struct webauthn_signature {
ecc_signature compact_signature;
std::vector<uint8_t> auth_data;
std::string client_json;
friend bool operator == ( const webauthn_signature& a, const webauthn_signature& b ) {
return std::tie(a.compact_signature,a.auth_data,a.client_json) == std::tie(b.compact_signature,b.auth_data,b.client_json);
}
friend bool operator != ( const webauthn_signature& a, const webauthn_signature& b ) {
return std::tie(a.compact_signature,a.auth_data,a.client_json) != std::tie(b.compact_signature,b.auth_data,b.client_json);
}
};
using signature = std::variant<ecc_signature, ecc_signature, webauthn_signature>;
template<typename DataStream>
inline DataStream& operator<<(DataStream& ds, const eosio::webauthn_signature& sig) {
ds << sig.compact_signature << sig.auth_data << sig.client_json;
return ds;
}
template<typename DataStream>
inline DataStream& operator>>(DataStream& ds, eosio::webauthn_signature& sig) {
ds >> sig.compact_signature >> sig.auth_data >> sig.client_json;
return ds;
}
void assert_sha256( const char* data, uint32_t length, const eosio::checksum256& hash );
void assert_sha1( const char* data, uint32_t length, const eosio::checksum160& hash );
void assert_sha512( const char* data, uint32_t length, const eosio::checksum512& hash );
void assert_ripemd160( const char* data, uint32_t length, const eosio::checksum160& hash );
eosio::checksum256 sha256( const char* data, uint32_t length );
eosio::checksum160 sha1( const char* data, uint32_t length );
eosio::checksum512 sha512( const char* data, uint32_t length );
eosio::checksum160 ripemd160( const char* data, uint32_t length );
eosio::public_key recover_key( const eosio::checksum256& digest, const eosio::signature& sig );
void assert_recover_key( const eosio::checksum256& digest, const eosio::signature& sig, const eosio::public_key& pubkey );
}
Updated on 2022-12-05 at 15:38:08 +0000