Compare commits

...

3 Commits

Author SHA1 Message Date
gulliver 6f1ce5e984 introduced and used bigint datatype 2022-12-19 23:11:02 +01:00
gittiver 0d3ffa0e5d Create FUNDING.yml 2022-12-19 23:10:01 +01:00
Gulliver 24adaebd07 updated github actions to cross-platform build and added action for github pages 2022-12-19 23:09:53 +01:00
11 changed files with 306 additions and 139 deletions

13
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,13 @@
# These are supported funding model platforms
github: [gittiver] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View File

@ -1,4 +1,4 @@
name: CMake name: Build and test (cmake based build)
on: on:
push: push:
@ -15,24 +15,42 @@ jobs:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage. # You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Prepare dependencies - name: Prepare dependencies
run: sudo apt-get update && sudo apt-get install -yq libboost-system-dev libboost-date-time-dev cmake graphviz doxygen run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get update && \
sudo apt-get install -yq \
libboost-system-dev \
libboost-date-time-dev \
cmake \
graphviz doxygen
elif [ "$RUNNER_OS" == "Windows" ]; then
choco install boost-msvc-14.3 graphviz doxygen.install
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install boost graphviz doxygen
else
echo "$RUNNER_OS not supported"
exit 1
fi
shell: bash
- name: Configure CMake - name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. run: cmake -B build
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type shell: bash
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Build - name: Build
# Build your program with the given configuration # Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} run: cmake --build build --config ${{env.BUILD_TYPE}}
shell: bash
- name: Test - name: Test
working-directory: ${{github.workspace}}/build working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration. # Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}} run: ctest -C ${{env.BUILD_TYPE}}

29
.github/workflows/doxygen-gh-pages.yml vendored Normal file
View File

@ -0,0 +1,29 @@
name: Deploy Doxygen results to Github Pages
on:
push:
branches:
- main
permissions:
contents: write
jobs:
build-and-deploy:
concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Prepare dependencies
run: sudo apt-get update && sudo apt-get install -yq libboost-system-dev libboost-date-time-dev cmake graphviz doxygen
- name: configure
run: cmake -B build -S . -DEXPATPP_BUILD_DOCS=ON
- name: clean generated docs dir
run: rm -rf build/html
- name: build
run: cmake --build build --target doc
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: build/html # The folder the action should deploy.

View File

@ -9,7 +9,7 @@ if(POLICY CMP0077)
endif() endif()
if (MSVC) if (MSVC)
add_compile_options(/W4 /WX) add_compile_options(/W4)
else() else()
add_compile_options(-Wall -Wextra -pedantic) add_compile_options(-Wall -Wextra -pedantic)
endif() endif()
@ -71,7 +71,7 @@ doxygen_add_docs(
) )
# build common library # build common library
set(LIB_SOURCES src/model.cpp src/model.hpp) set(LIB_SOURCES src/model.cpp src/model.hpp src/big_int.hpp src/big_int.cpp)
add_library(oc-mint-lib ${LIB_SOURCES}) add_library(oc-mint-lib ${LIB_SOURCES})
target_link_libraries(oc-mint-lib PUBLIC Crow::Crow) target_link_libraries(oc-mint-lib PUBLIC Crow::Crow)
target_include_directories(oc-mint-lib PUBLIC ${expected_SOURCE_DIR}/include src) target_include_directories(oc-mint-lib PUBLIC ${expected_SOURCE_DIR}/include src)
@ -80,7 +80,7 @@ add_executable(oc-mint src/main.cpp)
target_link_libraries(oc-mint PRIVATE oc-mint-lib INTERFACE tl::expected::expected) target_link_libraries(oc-mint PRIVATE oc-mint-lib INTERFACE tl::expected::expected)
## these are unittests that can be run on any platform ## these are unittests that can be run on any platform
add_executable(tests test/test.cpp) add_executable(tests test/test_big_int.cpp test/test.cpp)
target_link_libraries(tests target_link_libraries(tests
oc-mint-lib oc-mint-lib
Catch2::Catch2WithMain) Catch2::Catch2WithMain)

27
src/big_int.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "big_int.hpp"
#include <iostream>
tl::expected<BigInt,BigInt::eError>
BigInt::from_string(const std::string& str) {
BigInt b;
std::cout << str << std::endl;
b.data = str;
return b;
}
BigInt BigInt::from_int(uint64_t value)
{
BigInt b;
b.data = std::to_string(value);
return b;
}
std::string BigInt::to_string() const
{
return data;
}
bool operator == (const BigInt& rhs, const BigInt& lhs)
{ return rhs.data == lhs.data; }

26
src/big_int.hpp Normal file
View File

@ -0,0 +1,26 @@
#ifndef BIG_INT_HPP
#define BIG_INT_HPP
#include <string>
#include "tl/expected.hpp"
struct BigInt {
BigInt() : data() {}
virtual ~BigInt() {}
enum class eError {
PARSE_ERROR
};
std::string data;
static tl::expected<BigInt,eError> from_string(const std::string& str);
static BigInt from_int(uint64_t value);
std::string to_string() const;
};
bool operator == (const BigInt& rhs, const BigInt& lhs);
#endif // #ifndef #ifndef BIG_INT_HPP

View File

@ -70,7 +70,8 @@ int main() {
ResponseMint res; ResponseMint res;
res.message_reference = req->message_reference; res.message_reference = req->message_reference;
auto minted = model->mint(req->transaction_reference, req->blinds); /// \todo change argument transaction_reference to bigint
auto minted = model->mint(req->transaction_reference.to_string(), req->blinds);
res.blind_signatures = minted; res.blind_signatures = minted;
res.status_code = crow::status::OK; res.status_code = crow::status::OK;

View File

@ -1,9 +1,11 @@
#include "model.hpp" #include "model.hpp"
#include "crow/json.h" #include "crow/json.h"
#include "tl/expected.hpp"
#define TO_JSON(name) r[#name] = name #define TO_JSON(name) r[#name]=name
#define TO_JSON_JSON(name) r[#name] = name.to_json() #define BIGINT_TO_JSON(name) r[#name]=name.to_string()
#define TO_JSON_ARRAY(name) r[#name] = list_to_json(name) #define TO_JSON_JSON(name) r[#name]=name.to_json()
#define TO_JSON_ARRAY(name) r[#name]=list_to_json(name)
template <class T> template <class T>
crow::json::wvalue list_to_json(const std::vector<T> &array) { crow::json::wvalue list_to_json(const std::vector<T> &array) {
@ -22,9 +24,9 @@ crow::json::wvalue list_to_json(const std::vector<unsigned int> &array) {
crow::json::wvalue PublicKey::to_json() const { crow::json::wvalue PublicKey::to_json() const {
crow::json::wvalue r; crow::json::wvalue r;
TO_JSON(modulus); BIGINT_TO_JSON(modulus);
TO_JSON(public_exponent); BIGINT_TO_JSON(public_exponent);
r["type"] = "rsa public key"; r["type"]="rsa public key";
return r; return r;
} }
@ -48,7 +50,7 @@ crow::json::wvalue CDD::to_json() const {
TO_JSON(currency_divisor); TO_JSON(currency_divisor);
TO_JSON(currency_name); TO_JSON(currency_name);
TO_JSON_ARRAY(denominations); TO_JSON_ARRAY(denominations);
TO_JSON(id); BIGINT_TO_JSON(id);
TO_JSON_ARRAY(info_service); TO_JSON_ARRAY(info_service);
TO_JSON(issuer_cipher_suite); TO_JSON(issuer_cipher_suite);
TO_JSON_JSON(issuer_public_master_key); TO_JSON_JSON(issuer_public_master_key);
@ -75,8 +77,8 @@ crow::json::wvalue MintKey::to_json() const {
TO_JSON(cdd_serial); TO_JSON(cdd_serial);
TO_JSON(coins_expiry_date); TO_JSON(coins_expiry_date);
TO_JSON(denomination); TO_JSON(denomination);
TO_JSON(id); BIGINT_TO_JSON(id);
TO_JSON(issuer_id); BIGINT_TO_JSON(issuer_id);
TO_JSON_JSON(public_mint_key); TO_JSON_JSON(public_mint_key);
TO_JSON(sign_coins_not_after); TO_JSON(sign_coins_not_after);
@ -177,8 +179,13 @@ RequestMKCs::from_string(const std::string &str) {
if (mint_key_ids.t() != crow::json::type::List) { if (mint_key_ids.t() != crow::json::type::List) {
return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE); return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE);
} else { } else {
for (auto k : mint_key_ids.lo()) { for (auto k: mint_key_ids.lo()) {
r.mint_key_ids.push_back(k.u()); auto kv = BigInt::from_string(k.s());
if (!kv.has_value()) {
return tl::make_unexpected(eError::JSON_PARSE_ERROR);
} else {
r.mint_key_ids.push_back(*kv);
}
} }
} }
return r; return r;
@ -194,23 +201,38 @@ crow::json::wvalue ResponseMKCs::to_json() const {
crow::json::wvalue Blind::to_json() const { crow::json::wvalue Blind::to_json() const {
crow::json::wvalue r; crow::json::wvalue r;
TO_JSON(blinded_payload_hash); BIGINT_TO_JSON(blinded_payload_hash);
TO_JSON(mint_key_id); BIGINT_TO_JSON(mint_key_id);
TO_JSON(reference); TO_JSON(reference);
r["type"] = "blinded payload hash"; r["type"] = "blinded payload hash";
return r; return r;
} }
tl::expected<Blind, eError> Blind::from_json(const crow::json::rvalue &json) { tl::expected<Blind, eError> Blind::from_json(const crow::json::rvalue &json) {
if (!(json.has("type") && json.has("blinded_payload_hash") && if (!(json.has("type")
json.has("mint_key_id") && json.has("reference"))) { && json.has("blinded_payload_hash")
&& json.has("mint_key_id")
&& json.has("reference"))) {
return tl::make_unexpected(eError::JSON_ERROR); return tl::make_unexpected(eError::JSON_ERROR);
} else if (json["type"] != "blinded payload hash") { } else if (json["type"] != "blinded payload hash") {
return tl::make_unexpected(eError::JSON_ERROR); return tl::make_unexpected(eError::JSON_ERROR);
} else { } else {
Blind r; Blind r;
r.blinded_payload_hash = json["blinded_payload_hash"].s();
r.mint_key_id = json["mint_key_id"].s(); auto hash = BigInt::from_string(json["blinded_payload_hash"].s());
if (!hash) {
std::cout << "invalid hash : " << json["blinded_payload_hash"].s()
<< std::endl;
return tl::make_unexpected(eError::JSON_PARSE_ERROR);
}
r.blinded_payload_hash = hash.value();
auto key_id = BigInt::from_string(json["mint_key_id"].s());
if (!key_id) {
printf("invalid key_id");
return tl::make_unexpected(eError::JSON_PARSE_ERROR);
}
r.mint_key_id = key_id.value();
r.reference = json["reference"].s(); r.reference = json["reference"].s();
return r; return r;
} }
@ -218,7 +240,7 @@ tl::expected<Blind, eError> Blind::from_json(const crow::json::rvalue &json) {
crow::json::wvalue BlindSignature::to_json() const { crow::json::wvalue BlindSignature::to_json() const {
crow::json::wvalue r; crow::json::wvalue r;
TO_JSON(blind_signature); BIGINT_TO_JSON(blind_signature);
TO_JSON(reference); TO_JSON(reference);
r["type"] = "blind signature"; r["type"] = "blind signature";
return r; return r;
@ -238,9 +260,13 @@ RequestMint::from_string(const std::string &str) {
return tl::make_unexpected(eError::JSON_ERROR); return tl::make_unexpected(eError::JSON_ERROR);
} else { } else {
RequestMint r; RequestMint r;
r.message_reference = json["message_reference"].u(); r.message_reference= json["message_reference"].u();
r.transaction_reference = json["transaction_reference"].s(); auto tr = BigInt::from_string(json["transaction_reference"].s());
if (json["blinds"].t() != crow::json::type::List) { if (!tr)
return tl::make_unexpected(eError::JSON_PARSE_ERROR);
r.transaction_reference = *tr;
if (json["blinds"].t()!=crow::json::type::List) {
return tl::make_unexpected(eError::JSON_WRONG_VALUE_TYPE); return tl::make_unexpected(eError::JSON_WRONG_VALUE_TYPE);
} }
@ -267,10 +293,10 @@ crow::json::wvalue Coin::Payload::to_json() const {
crow::json::wvalue r; crow::json::wvalue r;
TO_JSON(cdd_location); TO_JSON(cdd_location);
TO_JSON(denomination); TO_JSON(denomination);
TO_JSON(issuer_id); BIGINT_TO_JSON(issuer_id);
TO_JSON(mint_key_id); BIGINT_TO_JSON(mint_key_id);
TO_JSON(protocol_version); TO_JSON(protocol_version);
TO_JSON(serial); BIGINT_TO_JSON(serial);
r["type"] = "payload"; r["type"] = "payload";
return r; return r;
@ -297,10 +323,20 @@ Coin::Payload::from_json(const crow::json::rvalue &json) {
Coin::Payload payload; Coin::Payload payload;
payload.cdd_location = json["cdd_location"].s(); payload.cdd_location = json["cdd_location"].s();
payload.denomination = json["denomination"].u(); payload.denomination = json["denomination"].u();
payload.issuer_id = json["issuer_id"].s(); auto id = BigInt::from_string(json["issuer_id"].s());
payload.mint_key_id = json["mint_key_id"].s(); if (!id)
tl::make_unexpected(eError::JSON_PARSE_ERROR);
payload.issuer_id = *id;
id = BigInt::from_string(json["mint_key_id"].s());
if (!id)
tl::make_unexpected(eError::JSON_PARSE_ERROR);
payload.mint_key_id = *id;
payload.protocol_version = json["protocol_version"].s(); payload.protocol_version = json["protocol_version"].s();
payload.serial = json["serial"].s(); id = BigInt::from_string(json["serial"].s());
if (!id)
tl::make_unexpected(eError::JSON_PARSE_ERROR);
payload.serial = *id;
return payload; return payload;
} }
} }
@ -392,7 +428,10 @@ RequestResume::from_string(const std::string &str) {
} else { } else {
RequestResume r; RequestResume r;
r.message_reference = json["message_reference"].u(); r.message_reference = json["message_reference"].u();
r.transaction_reference = json["transaction_reference"].s(); auto tr = BigInt::from_string(json["transaction_reference"].s());
if (!tr)
return tl::make_unexpected(eError::JSON_PARSE_ERROR);
r.transaction_reference = *tr;
return r; return r;
} }
} }
@ -451,7 +490,7 @@ public:
return &m_cddc; return &m_cddc;
} }
std::vector<BlindSignature> mint(const std::string &transaction_reference, std::vector<BlindSignature> mint(const std::string& transaction_reference,
const std::vector<Blind> &blinds) override { const std::vector<Blind> &blinds) override {
std::vector<BlindSignature> res; std::vector<BlindSignature> res;
cout << __FUNCTION__ << "(" cout << __FUNCTION__ << "("
@ -462,7 +501,7 @@ public:
const std::vector<MintKeyCert> const std::vector<MintKeyCert>
getMKCs(const std::vector<unsigned int> &denominations, getMKCs(const std::vector<unsigned int> &denominations,
const std::vector<unsigned int> &mint_key_ids) override { const std::vector<BigInt> &mint_key_ids) override {
std::vector<MintKeyCert> res; std::vector<MintKeyCert> res;
cout << __FUNCTION__ << endl; cout << __FUNCTION__ << endl;
return res; return res;

View File

@ -9,10 +9,11 @@
#include "crow/json.h" #include "crow/json.h"
#include "tl/expected.hpp" #include "tl/expected.hpp"
#include "big_int.hpp"
struct PublicKey { struct PublicKey {
std::string modulus; //: "daaa63ddda38c189b8c49020c8276adbe0a695685a...", BigInt modulus; //: "daaa63ddda38c189b8c49020c8276adbe0a695685a...",
std::string public_exponent; //: 65537, BigInt public_exponent;//: 65537,
crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
}; };
@ -28,15 +29,16 @@ struct WeightedUrl {
struct CDD { struct CDD {
std::string additional_info; std::string additional_info;
time_t cdd_expiry_date; //: 2023-07-22T15:45:53.164685 time_t cdd_expiry_date;//: 2023-07-22T15:45:53.164685
std::string cdd_location; //: https://opencent.org, std::string cdd_location;//: https://opencent.org,
size_t cdd_serial; //: 1, size_t cdd_serial;//: 1,
time_t cdd_signing_date; //: 2022-07-22T15:45:53.164685, time_t cdd_signing_date;//: 2022-07-22T15:45:53.164685,
size_t currency_divisor; //: 100, size_t currency_divisor;//: 100,
std::string currency_name; //: OpenCent, std::string currency_name;//: OpenCent,
std::vector<unsigned> denominations; //: [1, 2, 5], std::vector<unsigned> denominations;//: [1, 2, 5],
std::string id; //: 23ed956e629ba35f0002eaf833ea436aea7db5c2, BigInt id;//: 23ed956e629ba35f0002eaf833ea436aea7db5c2,
std::vector<WeightedUrl> info_service;
std::vector<WeightedUrl> info_service;
/* eCipherSuite*/ std::string issuer_cipher_suite; //: RSA-SHA256-PSS-CHAUM82, /* eCipherSuite*/ std::string issuer_cipher_suite; //: RSA-SHA256-PSS-CHAUM82,
PublicKey PublicKey
issuer_public_master_key; //: { issuer_public_master_key; //: {
@ -63,9 +65,9 @@ struct CDDC {
struct MintKey { struct MintKey {
unsigned int cdd_serial; unsigned int cdd_serial;
std::string coins_expiry_date; //": "2023-10-30T15:45:53.164685", std::string coins_expiry_date; //": "2023-10-30T15:45:53.164685",
unsigned int denomination; //": 1, unsigned int denomination; //": 1,
std::string id; // "1ceb977bb531c65f133ab8b0d60862b17369d96", BigInt id; // "1ceb977bb531c65f133ab8b0d60862b17369d96",
std::string issuer_id; //": "23ed956e629ba35f0002eaf833ea436aea7db5c2", BigInt issuer_id; //": "23ed956e629ba35f0002eaf833ea436aea7db5c2",
PublicKey public_mint_key; PublicKey public_mint_key;
std::string sign_coins_not_after; std::string sign_coins_not_after;
@ -128,7 +130,7 @@ struct RequestMKCs {
std::vector<unsigned int> denominations; std::vector<unsigned int> denominations;
unsigned int message_reference; /// Client internal message reference. unsigned int message_reference; /// Client internal message reference.
/// (Integer) /// (Integer)
std::vector<unsigned int> mint_key_ids; std::vector<BigInt> mint_key_ids;
// "type": "request mint key certificates" // "type": "request mint key certificates"
static tl::expected<RequestMKCs, eError> from_string(const std::string &str); static tl::expected<RequestMKCs, eError> from_string(const std::string &str);
}; };
@ -140,15 +142,15 @@ struct ResponseMKCs : Response {
}; };
struct Blind { struct Blind {
std::string blinded_payload_hash; // bigint BigInt blinded_payload_hash; //bigint
std::string mint_key_id; // bigint BigInt mint_key_id; //bigint
std::string reference; std::string reference;
crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
static tl::expected<Blind, eError> from_json(const crow::json::rvalue &json); static tl::expected<Blind, eError> from_json(const crow::json::rvalue &json);
}; };
struct BlindSignature { struct BlindSignature {
std::string blind_signature; BigInt blind_signature;
std::string reference; std::string reference;
crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
}; };
@ -156,7 +158,7 @@ struct BlindSignature {
struct RequestMint { struct RequestMint {
unsigned int message_reference; /// Client internal message reference. unsigned int message_reference; /// Client internal message reference.
/// (Integer) /// (Integer)
std::string transaction_reference; BigInt transaction_reference;
std::vector<Blind> blinds; std::vector<Blind> blinds;
// "type": "request mint" // "type": "request mint"
static tl::expected<RequestMint, eError> from_string(const std::string &str); static tl::expected<RequestMint, eError> from_string(const std::string &str);
@ -172,14 +174,13 @@ struct Coin {
struct Payload { struct Payload {
std::string cdd_location; std::string cdd_location;
unsigned int denomination; unsigned int denomination;
std::string issuer_id; BigInt issuer_id;
std::string mint_key_id; BigInt mint_key_id;
std::string protocol_version; std::string protocol_version;
std::string serial; BigInt serial;
crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
static tl::expected<Payload, eError> static tl::expected<Payload,eError> from_json(const crow::json::rvalue& json);
from_json(const crow::json::rvalue &json);
}; };
Payload payload; Payload payload;
@ -213,7 +214,7 @@ struct ResponseDelay : Response {
struct RequestResume { struct RequestResume {
unsigned int message_reference; /// Client internal message reference. unsigned int message_reference; /// Client internal message reference.
/// (Integer) /// (Integer)
std::string transaction_reference; BigInt transaction_reference;
// "type": "request resume" // "type": "request resume"
static tl::expected<RequestResume, eError> static tl::expected<RequestResume, eError>
from_string(const std::string &str); from_string(const std::string &str);
@ -241,10 +242,10 @@ public:
virtual const std::vector<MintKeyCert> virtual const std::vector<MintKeyCert>
getMKCs(const std::vector<unsigned int> &denominations, getMKCs(const std::vector<unsigned int> &denominations,
const std::vector<unsigned int> &mint_key_ids) = 0; const std::vector<BigInt> &mint_key_ids) = 0;
virtual std::vector<BlindSignature> virtual std::vector<BlindSignature>
mint(const std::string &transaction_reference, mint(std::string const& transaction_reference,
const std::vector<Blind> &blinds) = 0; const std::vector<Blind> &blinds) = 0;
virtual bool redeem(const std::vector<Coin> &coins) = 0; virtual bool redeem(const std::vector<Coin> &coins) = 0;

View File

@ -2,15 +2,17 @@
#include "model.hpp" #include "model.hpp"
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
TEST_CASE("PublicKey::to_json", "[to_json]") { TEST_CASE( "PublicKey::to_json", "[to_json]" ) {
PublicKey k{"daaa63ddda38c189b8c49020c8276adbe0a695685a...", "65537"};
PublicKey k //{ BigInt::from_string("daaa63ddda38c189b8c49020c8276adbe0a695685a...").value(),
// BigInt::from_int(65537UL) };
;
auto json = k.to_json(); auto json = k.to_json();
REQUIRE(json["modulus"].dump() == "\"" + k.modulus + "\""); REQUIRE( json["modulus"].dump() == "\"" + k.modulus.to_string() + "\"" );
REQUIRE(json["public_exponent"].dump() == "\"" + k.public_exponent + "\""); REQUIRE( json["public_exponent"].dump() == "\"" + k.public_exponent.to_string()+"\"" );
REQUIRE(json["type"].dump() == "\"rsa public key\""); REQUIRE( json["type"].dump() == "\"rsa public key\"" );
REQUIRE(json.keys().size() == 3); REQUIRE( json.keys().size() == 3 );
} }
TEST_CASE("RequestCDDSerial::from_string", "[from_string]") { TEST_CASE("RequestCDDSerial::from_string", "[from_string]") {
@ -76,15 +78,14 @@ TEST_CASE("RequestCDDC::from_string", "[from_string]") {
TEST_CASE("RequestMKCs::from_string", "[from_string]") { TEST_CASE("RequestMKCs::from_string", "[from_string]") {
// good case // good case
auto res = auto res = RequestMKCs::from_string( "{"
RequestMKCs::from_string("{" "\"denominations\": [1, 2, 5],"
"\"denominations\": [1, 2, 5]," "\"message_reference\": 100002,"
"\"message_reference\": 100002," "\"mint_key_ids\": [],"
"\"mint_key_ids\": []," "\"type\": \"request mint key certificates\""
"\"type\": \"request mint key certificates\"" "}");
"}"); const std::vector<uint32_t> EXPECTED_DENOMINATIONS = {1,2,5};
const std::vector<uint32_t> EXPECTED_DENOMINATIONS = {1, 2, 5}; const std::vector<BigInt> EXPECTED_MINT_KEY_IDS = {};
const std::vector<uint32_t> EXPECTED_MINT_KEY_IDS = {};
REQUIRE(res.has_value() == true); REQUIRE(res.has_value() == true);
REQUIRE(res->denominations == EXPECTED_DENOMINATIONS); REQUIRE(res->denominations == EXPECTED_DENOMINATIONS);
@ -136,15 +137,15 @@ TEST_CASE("Blind::from_json", "[from_string]") {
"}"); "}");
auto res = Blind::from_json(good); auto res = Blind::from_json(good);
REQUIRE(res.has_value() == true); REQUIRE(res.has_value()==true);
REQUIRE(res->blinded_payload_hash == REQUIRE(res->blinded_payload_hash.to_string()==
"924edb672c3345492f38341ff86b57181da4c673ef..."); "924edb672c3345492f38341ff86b57181da4c673ef...");
REQUIRE(res->mint_key_id == "1ceb977bb531c65f133ab8b0d60862b17369d96"); REQUIRE(res->mint_key_id.to_string()=="1ceb977bb531c65f133ab8b0d60862b17369d96");
REQUIRE(res->reference == "a0"); REQUIRE(res->reference=="a0");
// bad cases // bad cases
// wrong_type["blinded_payload_hash"]= // wrong_type["blinded_payload_hash"]= "924edb672c3345492f38341ff86b57181da4c673ef...";
// "924edb672c3345492f38341ff86b57181da4c673ef..."; wrong_type["mint_key_id"]= // wrong_type["mint_key_id"]= "1ceb977bb531c65f133ab8b0d60862b17369d96";
// "1ceb977bb531c65f133ab8b0d60862b17369d96"; wrong_type["reference"] = "a0"; // wrong_type["reference"] = "a0";
// wrong_type["type"]= "wrong type"; // wrong_type["type"]= "wrong type";
// res = Blind::from_json(wrong_type); // res = Blind::from_json(wrong_type);
@ -152,39 +153,35 @@ TEST_CASE("Blind::from_json", "[from_string]") {
TEST_CASE("RequestMint::from_string", "[from_string]") { TEST_CASE("RequestMint::from_string", "[from_string]") {
// good case // good case
auto res = RequestMint::from_string( auto res = RequestMint::from_string( "{"
"{" "\"blinds\": ["
"\"blinds\": [" "{"
"{" "\"blinded_payload_hash\": \"924edb672c3345492f38341ff86b57181da4c673ef...\","
"\"blinded_payload_hash\": " "\"mint_key_id\": \"1ceb977bb531c65f133ab8b0d60862b17369d96\","
"\"924edb672c3345492f38341ff86b57181da4c673ef...\"," "\"reference\": \"a0\","
"\"mint_key_id\": \"1ceb977bb531c65f133ab8b0d60862b17369d96\"," "\"type\": \"blinded payload hash\""
"\"reference\": \"a0\"," "},"
"\"type\": \"blinded payload hash\"" "{"
"}," "\"blinded_payload_hash\": \"95db92e1c46ebea5edec5e508a831263de6fb78b4c...\","
"{" "\"mint_key_id\": \"f2864e5cd937dbaa4825e73a81062de162143682\","
"\"blinded_payload_hash\": " "\"reference\": \"a1\","
"\"95db92e1c46ebea5edec5e508a831263de6fb78b4c...\"," "\"type\": \"blinded payload hash\""
"\"mint_key_id\": \"f2864e5cd937dbaa4825e73a81062de162143682\"," "},"
"\"reference\": \"a1\"," "{"
"\"type\": \"blinded payload hash\"" "\"blinded_payload_hash\": \"10afac98ac43eb40e996c621d5db4d2238348e3f74...\","
"}," "\"mint_key_id\": \"897a16bf12bd9ba474ef7be0e3a53553a7b4ece8\","
"{" "\"reference\": \"a2\","
"\"blinded_payload_hash\": " "\"type\": \"blinded payload hash\""
"\"10afac98ac43eb40e996c621d5db4d2238348e3f74...\"," "}"
"\"mint_key_id\": \"897a16bf12bd9ba474ef7be0e3a53553a7b4ece8\"," "],"
"\"reference\": \"a2\"," "\"message_reference\": 100003,"
"\"type\": \"blinded payload hash\"" "\"transaction_reference\": \"b2221a58008a05a6c4647159c324c985\","
"}" "\"type\": \"request mint\""
"]," "}");
"\"message_reference\": 100003,"
"\"transaction_reference\": \"b2221a58008a05a6c4647159c324c985\","
"\"type\": \"request mint\""
"}");
REQUIRE(res.has_value() == true); REQUIRE(res.has_value()==true);
REQUIRE(res->message_reference == 100003); REQUIRE(res->message_reference==100003);
REQUIRE(res->transaction_reference == "b2221a58008a05a6c4647159c324c985"); REQUIRE(res->transaction_reference.to_string() == "b2221a58008a05a6c4647159c324c985");
/// \todo check blinds /// \todo check blinds
// bad cases // bad cases
@ -280,17 +277,16 @@ TEST_CASE("RequestRenew::from_string", "[from_string]") {
TEST_CASE("RequestResume::from_string", "[from_string]") { TEST_CASE("RequestResume::from_string", "[from_string]") {
// good case // good case
auto res = RequestResume::from_string( auto res = RequestResume::from_string( "{"
"{" "\"message_reference\": 100005,"
"\"message_reference\": 100005," "\"transaction_reference\": \"ad45f23d3b1a11df587fd2803bab6c39\","
"\"transaction_reference\": \"ad45f23d3b1a11df587fd2803bab6c39\"," "\"type\": \"request resume\""
"\"type\": \"request resume\"" "}");
"}");
REQUIRE(res.has_value() == true);
REQUIRE(res->message_reference == 100005);
REQUIRE(res->transaction_reference == "ad45f23d3b1a11df587fd2803bab6c39");
REQUIRE(res.has_value()==true);
REQUIRE(res->message_reference==100005);
REQUIRE(res->transaction_reference.to_string()=="ad45f23d3b1a11df587fd2803bab6c39");
// bad cases // bad cases
res = RequestResume::from_string(""); res = RequestResume::from_string("");
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);

17
test/test_big_int.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "big_int.hpp"
#include <catch2/catch_test_macros.hpp>
TEST_CASE("BigInt::from_string", "[big_int]") {
auto valid_hex = "aabbcc";
{
auto b = BigInt::from_string(valid_hex);
REQUIRE(b.has_value());
REQUIRE(b->data == valid_hex);
}
}
TEST_CASE("BigInt::from_int", "[big_int]") {
auto b = BigInt::from_int(0xaabbcc);
REQUIRE(b.data=="aabbcc");
}