constructuri and verifymessage skeleton
diff --git a/service/kv_service/c_validator.cpp b/service/kv_service/c_validator.cpp index e2b0db8..92a596a 100644 --- a/service/kv_service/c_validator.cpp +++ b/service/kv_service/c_validator.cpp
@@ -31,7 +31,8 @@ } /* - * TODO: Use actual BER/DER decoding functions from a cryptographic library + * TODO: Use actual BER/DER decoding functions from a cryptographic library and + * replace hardcoded numbers with names of ASN1 bits * * Example string: pGSAIB4t58gi0CHneoXjs358ykJTwUWGZkWkBo7DLZV64c2KgUDoeWkz2-KrjDXh5ulHa2t-WiF5TT4RnBhqrcXJulJ135i_ipXmtJkLUrsGy884eRNb2_LE8RU2CMtRe4J-3IYM * @@ -74,12 +75,29 @@ return ptr; } -void CValidator::ConstructURI() { - ; +/* + * TODO: Follow the steps according to + * https://perfect-sunstone-a3b.notion.site/NexRes-C-validation-369f5ad4ef074a1684dc227702a5c866 + */ +std::string CValidator::ConstructURI(std::string &public_key, std::string &signature) { + // TODO: DER encode the fingerprint content object + + // TODO: SHA256 hash the fingerprint content + + // TODO: Generate the fingerprint from the hash + std::string fingerprint = ""; + + return "ni:///sha-256;" + fingerprint + "?fpt=" + "ed25519-sha-256" + + "&cost=" + std::to_string(ED25519_CRYPTOGRAPHY_COST); } -void CValidator::VerifyMessage() { - ; +/* + * TODO: Follow the steps according to + * https://perfect-sunstone-a3b.notion.site/NexRes-C-validation-369f5ad4ef074a1684dc227702a5c866 + */ +bool CValidator::VerifyMessage(std::string &public_key, std::string &signature, + std::string &message) { + return true; } std::string CValidator::base64_add_padding(std::string data) { @@ -96,6 +114,14 @@ return encoded_data; } +std::string CValidator::base64_remove_padding(std::string data) { + int i = data.length() - 1; + while (i >= 0 && data[i] == '=') { + i--; + } + return data.substr(0, i+1); +} + std::string CValidator::CreateMessage(std::string& tx) { rapidjson::Document doc; doc.Parse(tx);
diff --git a/service/kv_service/c_validator.h b/service/kv_service/c_validator.h index bd4b806..60838e5 100644 --- a/service/kv_service/c_validator.h +++ b/service/kv_service/c_validator.h
@@ -12,16 +12,19 @@ class CValidator { public: - std::string CCFulfill(std::string& fulfillment); - std::unique_ptr<std::vector<std::string>> DERDecode(std::string& uri_bytes_str); - void ConstructURI(); - void VerifyMessage(); - std::string CreateMessage(std::string& tx); - void printHex(std::string& str); + std::string CCFulfill(std::string &fulfillment); + std::unique_ptr<std::vector<std::string>> DERDecode(std::string &uri_bytes_str); + std::string ConstructURI(std::string &public_key, std::string &signature); + bool VerifyMessage(std::string &public_key, std::string &signature, + std::string &message); + std::string CreateMessage(std::string &tx); + void printHex(std::string &str); private: std::string base64_add_padding(std::string data); - std::string SerializeMessage(std::string& tx); - void RemoveSignature(rapidjson::Document& doc); + std::string base64_remove_padding(std::string data); + std::string SerializeMessage(std::string &tx); + void RemoveSignature(rapidjson::Document &doc); const int PUBLIC_KEY_LENGTH = 32; const int SIGNATURE_LENGTH = 64; + const int ED25519_CRYPTOGRAPHY_COST = 131072; // 2^17 }; \ No newline at end of file
diff --git a/service/kv_service/c_validator_main.cpp b/service/kv_service/c_validator_main.cpp index 82da5d3..609e37a 100644 --- a/service/kv_service/c_validator_main.cpp +++ b/service/kv_service/c_validator_main.cpp
@@ -31,6 +31,8 @@ cval.printHex(public_key); + cval.ConstructURI(public_key, signature); + /* // std::string tx = "{\"inputs\":[{\"owners_before\":[\"C1CECot9umaqYvCjpt31GiKpYmsaGWQDdnHJjCv8yQiS\"],\"fulfills\":{\"transaction_id\":\"123415ca19849d95571e0d828102365f24bd322a54d6701e477d32a5bd009c6f\",\"output_index\":0},\"fulfillment\":\"pGSAIKN9QFdMwU21tgN2hzUd8pi75C8EsQ6LjnMjLssTKgivgUAmOHl2O1vsWN_bvPjoofVWyHf1p_thSJIUNCkfNStc748Rz37tMPT8NouEgjIvwgXpM1zOvA3TmzdoCjpaNm0N\"}]}"; std::string tx = "{ \"inputs\":[ { \"owners_before\":[ \"C1CECot9umaqYvCjpt31GiKpYmsaGWQDdnHJjCv8yQiS\" ], \"fulfills\":{ \"transaction_id\":\"123415ca19849d95571e0d828102365f24bd322a54d6701e477d32a5bd009c6f\", \"output_index\":0 }, \"fulfillment\":\"pGSAIKN9QFdMwU21tgN2hzUd8pi75C8EsQ6LjnMjLssTKgivgUAmOHl2O1vsWN_bvPjoofVWyHf1p_thSJIUNCkfNStc748Rz37tMPT8NouEgjIvwgXpM1zOvA3TmzdoCjpaNm0N\" } ], \"outputs\":[ { \"public_keys\":[ \"DeVmcDk2G9TDYUtuLsozEWs9eCNRfbgfxaCntdKYKxXE\" ], \"condition\":{ \"details\":{ \"type\":\"ed25519-sha-256\", \"public_key\":\"DeVmcDk2G9TDYUtuLsozEWs9eCNRfbgfxaCntdKYKxXE\" }, \"uri\":\"ni:///sha-256;koZKY5-hToyQh-71lMhRS4WdYKFyNagSXEeBKxbuZpM?fpt=ed25519-sha-256&cost=131072\" }, \"amount\":\"1\" } ], \"operation\":\"TRANSFER\", \"metadata\":null, \"asset\":{ \"id\":\"123415ca19849d95571e0d828102365f24bd322a54d6701e477d32a5bd009c6f\" }, \"version\":\"2.0\", \"id\":\"780b0c416519aac2137c143ed1929b8783c99df001d3660a4b29508fad58443b\" }";
diff --git a/service/kv_service/sdk_transaction.cpp b/service/kv_service/sdk_transaction.cpp index ede3896..6b3d317 100644 --- a/service/kv_service/sdk_transaction.cpp +++ b/service/kv_service/sdk_transaction.cpp
@@ -1,3 +1,9 @@ +/* + * WORK IN PROGRESS + * + * To be used with libcryptoconditions for SDK transaction validation + */ + #include "sdk_transaction.h" #include <cryptopp/files.h>
diff --git a/service/kv_service/sdk_transaction.h b/service/kv_service/sdk_transaction.h index ed0c8fe..1f15eb7 100644 --- a/service/kv_service/sdk_transaction.h +++ b/service/kv_service/sdk_transaction.h
@@ -1,3 +1,9 @@ +/* + * WORK IN PROGRESS + * + * To be used with libcryptoconditions for SDK transaction validation + */ + #pragma once #include <string>
diff --git a/service/kv_service/sdk_transaction_manager.cpp b/service/kv_service/sdk_transaction_manager.cpp index c373a62..1e844ad 100644 --- a/service/kv_service/sdk_transaction_manager.cpp +++ b/service/kv_service/sdk_transaction_manager.cpp
@@ -1,3 +1,10 @@ +/* + * WORK IN PROGRESS + * + * To be used with libcryptoconditions for SDK transaction validation + */ + + #include "sdk_transaction_manager.h" SDKTransactionManager::SDKTransactionManager() {
diff --git a/service/kv_service/sdk_transaction_manager.h b/service/kv_service/sdk_transaction_manager.h index 05506e7..0bed773 100644 --- a/service/kv_service/sdk_transaction_manager.h +++ b/service/kv_service/sdk_transaction_manager.h
@@ -1,3 +1,9 @@ +/* + * WORK IN PROGRESS + * + * To be used with libcryptoconditions for SDK transaction validation + */ + #pragma once #include <unordered_map>