2 #include "ypc/common/endian.h"
3 #include "ypc/core_t/analyzer/helper/parser_type_traits.h"
4 #include "ypc/core_t/analyzer/var/enclave_hash_var.h"
5 #include "ypc/core_t/analyzer/var/encrypted_param_var.h"
6 #include "ypc/core_t/analyzer/var/request_key_var.h"
7 #include "ypc/core_t/analyzer/var/result_var.h"
8 #include "ypc/stbox/ebyte.h"
9 #include "ypc/stbox/stx_status.h"
13 template <
typename Crypto>
23 uint32_t generate_result() {
26 crypto::gen_private_key(skey);
28 crypto::generate_pkey_from_skey(skey, pkey);
30 auto rs = result_var::m_result;
32 auto status = crypto::encrypt_message_with_prefix(
33 pkey, rs, utc::crypto_prefix_arbitrary, m_encrypted_result_str);
35 if (status != stbox::stx_status::success) {
36 LOG(ERROR) <<
"error for encrypt_message: " << status;
41 crypto::hash_256(m_encrypted_result_str, hash_m);
44 status = crypto::generate_pkey_from_skey(m_private_key, pkey_a);
46 status = crypto::encrypt_message_with_prefix(
47 pkey_a, skey, utc::crypto_prefix_arbitrary, m_encrypted_c);
49 if (status != stbox::stx_status::success) {
50 LOG(ERROR) <<
"error for encrypt_message: " << status;
54 stbox::bytes cost_gas_str(
sizeof(m_cost_gas));
55 memcpy((uint8_t *)&cost_gas_str[0], (uint8_t *)&m_cost_gas,
57 ypc::utc::endian_swap(cost_gas_str);
60 m_encrypted_param + m_data_hash + m_enclave_hash + cost_gas_str;
62 LOG(INFO) <<
"cost message to sign: " << cost_msg;
65 crypto::sign_message(m_private_key, cost_msg, m_cost_signature_str);
66 if (status != stbox::stx_status::success) {
67 LOG(ERROR) <<
"error for sign cost: " << status;
71 auto msg = m_encrypted_c + hash_m + m_encrypted_param + m_data_hash +
72 cost_gas_str + m_enclave_hash;
74 LOG(INFO) <<
"result message to sign: " << msg;
77 LOG(INFO) <<
"sign with private key: " << m_private_key;
79 status = crypto::sign_message(m_private_key, msg, m_result_signature_str);
81 return static_cast<uint32_t
>(status);
83 nt<stbox::bytes>::offchain_result_package_t get_result_pkg() {
85 typename ntt::offchain_result_package_t pkg;
86 pkg.set<ntt::encrypted_result>(m_encrypted_result_str);
87 pkg.set<ntt::data_hash>(data_hash_var::m_data_hash);
88 pkg.set<ntt::result_signature>(m_result_signature_str);
89 pkg.set<ntt::cost_signature>(m_cost_signature_str);
90 pkg.set<ntt::result_encrypt_key>(m_encrypted_c);
94 uint32_t get_analyze_result(uint8_t *result, uint32_t size) {
96 auto pkg = get_result_pkg();
98 ff::net::marshaler lm(ff::net::marshaler::length_retriver);
100 if (size != lm.get_length()) {
101 return stbox::stx_status::out_buffer_length_error;
103 ff::net::marshaler ld((
char *)result, size, ff::net::marshaler::serializer);
105 return stbox::stx_status::success;
108 uint32_t get_analyze_result_size() {
109 auto pkg = get_result_pkg();
110 ff::net::marshaler lm(ff::net::marshaler::length_retriver);
112 return lm.get_length();
116 stbox::bytes m_encrypted_c;
117 stbox::bytes m_encrypted_result_str;
118 stbox::bytes m_cost_signature_str;
119 stbox::bytes m_result_signature_str;
122 template <
typename Crypto>
126 constexpr
static uint32_t value = ypc::utc::offchain_result_parser;