From 6793762fbb91e8e5a8ad72326ef1d9c380e2dd49 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sat, 25 Mar 2023 15:24:49 +0100 Subject: [PATCH] Adding src/wif/legacy.cpp --- src/wif/legacy.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/wif/legacy.cpp diff --git a/src/wif/legacy.cpp b/src/wif/legacy.cpp new file mode 100644 index 0000000..47a8251 --- /dev/null +++ b/src/wif/legacy.cpp @@ -0,0 +1,48 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 EOS Sw/eden + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "codec.hpp" + +namespace libeosio { namespace internal { + +void pub_encoder_legacy(const ec_pubkey_t& key, unsigned char *buf) { + + checksum_t check = checksum_ripemd160(key.data(), EC_PUBKEY_SIZE); + + memcpy(buf, key.data(), EC_PUBKEY_SIZE); + memcpy(buf + EC_PUBKEY_SIZE, check.data(), check.size()); +} + +bool pub_decoder_legacy(const std::vector& buf, ec_pubkey_t& key) { + + if (!checksum_validate(buf.data(), buf.size())) { + return false; + } + + memcpy(key.data(), buf.data(), EC_PUBKEY_SIZE); + return true; +} + +}} // namespace libeosio::internal \ No newline at end of file