mirror of
https://github.com/eosswedenorg/libantelope
synced 2026-06-18 04:20:03 +02:00
Initial Commit
This commit is contained in:
commit
137d5cbe31
22 changed files with 1168 additions and 0 deletions
39
include/libeosio/WIF.h
Normal file
39
include/libeosio/WIF.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 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.
|
||||
*/
|
||||
#ifndef LIBEOSIO_WIF_H
|
||||
#define LIBEOSIO_WIF_H
|
||||
|
||||
#include <libeosio/types.h>
|
||||
|
||||
namespace libeosio {
|
||||
|
||||
std::string wif_priv_encode(ec_privkey_t priv);
|
||||
|
||||
std::string wif_pub_encode(ec_pubkey_t pub);
|
||||
|
||||
void wif_print_key(const struct ec_keypair *key);
|
||||
|
||||
} // namespace libeosio
|
||||
|
||||
#endif /* LIBEOSIO_WIF_H */
|
||||
46
include/libeosio/base58.h
Normal file
46
include/libeosio/base58.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 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.
|
||||
*/
|
||||
#ifndef LIBEOSIO_BASE58_H
|
||||
#define LIBEOSIO_BASE58_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace libeosio {
|
||||
|
||||
std::string base58_encode(const std::string& str);
|
||||
std::string base58_encode(const std::vector<unsigned char>& vch);
|
||||
std::string base58_encode(const unsigned char* pbegin, const unsigned char* pend);
|
||||
|
||||
bool is_base58(char ch);
|
||||
|
||||
// Returns std::string::npos if the string contains only base58 characters
|
||||
// Otherwise the position of the first non base58 character is returned.
|
||||
size_t is_base58(const std::string& str);
|
||||
|
||||
std::string& base58_strip(std::string& str);
|
||||
|
||||
} //namespace eoskeygen
|
||||
|
||||
#endif /* LIBEOSIO_BASE58_H */
|
||||
54
include/libeosio/checksum.h
Normal file
54
include/libeosio/checksum.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 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.
|
||||
*/
|
||||
#ifndef LIBEOSIO_CHECKSUM_H
|
||||
#define LIBEOSIO_CHECKSUM_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <array>
|
||||
#include <libeosio/hash.h>
|
||||
|
||||
namespace libeosio {
|
||||
|
||||
#define CHECKSUM_SIZE 4
|
||||
|
||||
typedef std::array<unsigned char, CHECKSUM_SIZE> checksum_t;
|
||||
|
||||
template <typename T, T* (*F)(const unsigned char *, std::size_t, T*)>
|
||||
inline checksum_t checksum(const unsigned char* data, std::size_t len) {
|
||||
checksum_t crc;
|
||||
T hash;
|
||||
|
||||
F(data, len, &hash);
|
||||
std::memcpy(crc.data(), &hash, crc.size());
|
||||
return crc;
|
||||
}
|
||||
|
||||
#define checksum_sha256 checksum<sha256_t, sha256>
|
||||
#define checksum_sha256d checksum<sha256_t, sha256d>
|
||||
#define checksum_ripemd160 checksum<ripemd160_t, ripemd160>
|
||||
|
||||
} // namespace libeosio
|
||||
|
||||
#endif /* LIBEOSIO_CHECKSUM_H */
|
||||
39
include/libeosio/ec.h
Normal file
39
include/libeosio/ec.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 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.
|
||||
*/
|
||||
#ifndef LIBEOSIO_EC_H
|
||||
#define LIBEOSIO_EC_H
|
||||
|
||||
#include <libeosio/types.h>
|
||||
|
||||
namespace libeosio {
|
||||
|
||||
/**
|
||||
* Generates a keypair using the secp256k1 curve.
|
||||
* public key is in compressed format.
|
||||
*/
|
||||
int ec_generate_key(struct ec_keypair *pair);
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
||||
#endif /* LIBEOSIO_EC_H */
|
||||
41
include/libeosio/hash.h
Normal file
41
include/libeosio/hash.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 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.
|
||||
*/
|
||||
#ifndef LIBEOSIO_HASH_H
|
||||
#define LIBEOSIO_HASH_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <libeosio/types.h>
|
||||
|
||||
namespace libeosio {
|
||||
|
||||
sha256_t* sha256(const unsigned char *data, std::size_t len, sha256_t* out);
|
||||
|
||||
// sha256 double.
|
||||
sha256_t* sha256d(const unsigned char *data, std::size_t len, sha256_t* out);
|
||||
|
||||
ripemd160_t* ripemd160(const unsigned char *data, std::size_t len, ripemd160_t* out);
|
||||
|
||||
} // namespace libeosio
|
||||
|
||||
#endif /* LIBEOSIO_HASH_H */
|
||||
55
include/libeosio/types.h
Normal file
55
include/libeosio/types.h
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 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.
|
||||
*/
|
||||
#ifndef LIBEOSIO_TYPES_H
|
||||
#define LIBEOSIO_TYPES_H
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace libeosio {
|
||||
|
||||
#define EC_PRIVKEY_SIZE 32
|
||||
|
||||
/*
|
||||
* Compressed format!
|
||||
* z||x, where byte z specifies which (of the 2) solutions of the quadratic equation y is.
|
||||
* Each cordinate is 32 bytes.
|
||||
*/
|
||||
#define EC_PUBKEY_SIZE (32 + 1)
|
||||
|
||||
typedef std::array<unsigned char, EC_PRIVKEY_SIZE> ec_privkey_t;
|
||||
typedef std::array<unsigned char, EC_PUBKEY_SIZE> ec_pubkey_t;
|
||||
|
||||
struct ec_keypair {
|
||||
ec_privkey_t secret;
|
||||
ec_pubkey_t pub;
|
||||
};
|
||||
|
||||
// Hashes.
|
||||
|
||||
typedef struct { unsigned char data[20]; } ripemd160_t;
|
||||
typedef struct { unsigned char data[32]; } sha256_t;
|
||||
|
||||
} // namespace libeosio
|
||||
|
||||
#endif /* LIBEOSIO_TYPES_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue