forked from lthn/blockchain
asset owner eth signer support for currency_format_utils and wallet2
This commit is contained in:
parent
fa4a2680f9
commit
27ecfad1d6
5 changed files with 42 additions and 43 deletions
|
|
@ -2192,6 +2192,8 @@ namespace currency
|
|||
hsc.add_scalar(crypto::scalar_t(ado.descriptor.total_max_supply));
|
||||
hsc.add_scalar(crypto::scalar_t(ado.descriptor.decimal_point));
|
||||
hsc.add_pub_key(ado.descriptor.owner);
|
||||
if (ado.descriptor.owner_eth_pub_key.has_value())
|
||||
hsc.add_eth_pub_key(ado.descriptor.owner_eth_pub_key.value());
|
||||
crypto::hash h = hsc.calc_hash_no_reduce();
|
||||
|
||||
// this hash function needs to be computationally expensive (s.a. the whitepaper)
|
||||
|
|
@ -2244,7 +2246,8 @@ namespace currency
|
|||
// asset_control_key = Hs(CRYPTO_HDS_ASSET_CONTROL_KEY, 8 * tx_key.sec * sender_account_keys.account_address.spend_public_key, 0)
|
||||
// ado.descriptor.owner = asset_control_key * G
|
||||
|
||||
ado.descriptor.owner = sender_account_keys.account_address.spend_public_key;
|
||||
if (!ado.descriptor.owner_eth_pub_key.has_value())
|
||||
ado.descriptor.owner = sender_account_keys.account_address.spend_public_key;
|
||||
|
||||
CHECK_AND_ASSERT_MES(get_or_calculate_asset_id(ado, &gen_context.ao_asset_id_pt, &gen_context.ao_asset_id), false, "get_or_calculate_asset_id failed");
|
||||
|
||||
|
|
@ -2334,24 +2337,6 @@ namespace currency
|
|||
if (ftp.pevents_dispatcher) ftp.pevents_dispatcher->RAISE_DEBUG_EVENT(wde_construct_tx_handle_asset_descriptor_operation_before_seal{ &ado });
|
||||
|
||||
ftp.need_to_generate_ado_proof = true;
|
||||
/*
|
||||
//seal it with owners signature
|
||||
crypto::signature sig = currency::null_sig;
|
||||
crypto::hash h = get_signature_hash_for_asset_operation(ado);
|
||||
if (ftp.pthirdparty_sign_handler)
|
||||
{
|
||||
bool r = ftp.pthirdparty_sign_handler->sign(h, ftp.ado_current_asset_owner, sig);
|
||||
CHECK_AND_ASSERT_MES(r, false, "asset thirparty sign failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
crypto::public_key pub_k = currency::null_pkey;
|
||||
crypto::secret_key_to_public_key(sender_account_keys.spend_secret_key, pub_k);
|
||||
CHECK_AND_ASSERT_MES(ftp.ado_current_asset_owner == pub_k, false, "asset owner key not matched with provided private key for asset operation signing");
|
||||
crypto::generate_signature(h, pub_k, account_keys.spend_secret_key, sig);
|
||||
}
|
||||
ado.opt_proof = sig;
|
||||
*/
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -2784,22 +2769,30 @@ namespace currency
|
|||
}
|
||||
if(ftp.need_to_generate_ado_proof)
|
||||
{
|
||||
asset_operation_ownership_proof aoop = AUTO_VAL_INIT(aoop);
|
||||
|
||||
if (ftp.pthirdparty_sign_handler)
|
||||
if (ftp.p_eth_signer)
|
||||
{
|
||||
//ask third party to generate proof
|
||||
r = ftp.pthirdparty_sign_handler->sign(tx_prefix_hash, ftp.ado_current_asset_owner, aoop.gss);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to sign ado by thirdparty");
|
||||
// third party generates eth proof
|
||||
CHECKED_GET_SPECIFIC_VARIANT(ftp.asset_owner, const crypto::eth_public_key, asset_owner_pubkey_eth, false);
|
||||
asset_operation_ownership_proof_eth aoop_eth{};
|
||||
r = ftp.p_eth_signer->sign(tx_prefix_hash, asset_owner_pubkey_eth, aoop_eth.eth_sig);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to sign ado by 3rd party eth signer");
|
||||
// instant verification
|
||||
r = crypto::verify_eth_signature(tx_prefix_hash, asset_owner_pubkey_eth, aoop_eth.eth_sig);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Ado by 3rd party eth signer has been incorrectly signed");
|
||||
if (ftp.pevents_dispatcher) ftp.pevents_dispatcher->RAISE_DEBUG_EVENT(wde_construct_tx_after_asset_ownership_eth_proof_generated{ &aoop_eth });
|
||||
tx.proofs.emplace_back(aoop_eth);
|
||||
}
|
||||
else
|
||||
{
|
||||
//generate signature by wallet account
|
||||
r = crypto::generate_schnorr_sig(tx_prefix_hash, ftp.ado_current_asset_owner, sender_account_keys.spend_secret_key, aoop.gss);
|
||||
// generic Shnorr signature (signing with the spend secret key)
|
||||
CHECKED_GET_SPECIFIC_VARIANT(ftp.asset_owner, const crypto::public_key, asset_owner_pubkey, false);
|
||||
// generate signature by wallet account
|
||||
asset_operation_ownership_proof aoop = AUTO_VAL_INIT(aoop);
|
||||
r = crypto::generate_schnorr_sig(tx_prefix_hash, asset_owner_pubkey, sender_account_keys.spend_secret_key, aoop.gss);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to sign ado proof");
|
||||
if (ftp.pevents_dispatcher) ftp.pevents_dispatcher->RAISE_DEBUG_EVENT(wde_construct_tx_after_asset_ownership_proof_generated{ &aoop });
|
||||
tx.proofs.emplace_back(aoop);
|
||||
}
|
||||
if (ftp.pevents_dispatcher) ftp.pevents_dispatcher->RAISE_DEBUG_EVENT(wde_construct_tx_after_asset_ownership_proof_generated{ &aoop });
|
||||
tx.proofs.emplace_back(aoop);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -139,11 +139,13 @@ namespace currency
|
|||
bool hltc_our_out_is_before_expiration;
|
||||
};
|
||||
|
||||
struct thirdparty_sign_handler
|
||||
struct asset_eth_signer_i
|
||||
{
|
||||
virtual bool sign(const crypto::hash& h, const crypto::public_key& owner_public_key, crypto::generic_schnorr_sig& sig);
|
||||
virtual bool sign(const crypto::hash& h, const crypto::eth_public_key& asset_owner, crypto::eth_signature& sig) = 0;
|
||||
};
|
||||
|
||||
typedef boost::variant<crypto::public_key, crypto::eth_public_key> asset_owner_key_v;
|
||||
|
||||
struct finalize_tx_param
|
||||
{
|
||||
uint64_t unlock_time;
|
||||
|
|
@ -166,8 +168,8 @@ namespace currency
|
|||
tx_generation_context gen_context{}; // solely for consolidated txs
|
||||
|
||||
//crypto::secret_key asset_control_key = currency::null_skey;
|
||||
crypto::public_key ado_current_asset_owner = null_pkey;
|
||||
thirdparty_sign_handler* pthirdparty_sign_handler = nullptr;
|
||||
asset_owner_key_v asset_owner;
|
||||
asset_eth_signer_i* p_eth_signer = nullptr;
|
||||
mutable bool need_to_generate_ado_proof = false;
|
||||
|
||||
|
||||
|
|
@ -191,7 +193,7 @@ namespace currency
|
|||
{
|
||||
FIELD(gen_context);
|
||||
}
|
||||
FIELD(ado_current_asset_owner)
|
||||
FIELD(asset_owner)
|
||||
FIELD(need_to_generate_ado_proof)
|
||||
END_SERIALIZE()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5403,7 +5403,7 @@ void wallet2::emit_asset(const crypto::public_key asset_id, std::vector<currency
|
|||
ctp.dsts = destinations;
|
||||
ctp.extra.push_back(asset_emmit_info);
|
||||
ctp.need_at_least_1_zc = true;
|
||||
ctp.ado_current_asset_owner = rsp.asset_descriptor.owner;
|
||||
ctp.asset_owner = rsp.asset_descriptor.owner;
|
||||
//ctp.asset_deploy_control_key = own_asset_entry_it->second.control_key;
|
||||
|
||||
for(auto& dst : ctp.dsts)
|
||||
|
|
@ -5432,7 +5432,7 @@ void wallet2::update_asset(const crypto::public_key asset_id, const currency::as
|
|||
currency::asset_descriptor_base adb = AUTO_VAL_INIT(adb);
|
||||
bool r = this->daemon_get_asset_info(asset_id, adb);
|
||||
CHECK_AND_ASSERT_THROW_MES(r, "Failed to get asset info from daemon");
|
||||
ctp.ado_current_asset_owner = adb.owner;
|
||||
ctp.asset_owner = adb.owner;
|
||||
|
||||
finalized_tx ft = AUTO_VAL_INIT(ft);
|
||||
this->transfer(ctp, ft, true, nullptr);
|
||||
|
|
@ -5454,7 +5454,7 @@ void wallet2::transfer_asset_ownership(const crypto::public_key asset_id, const
|
|||
asset_update_info.opt_asset_id = asset_id;
|
||||
asset_update_info.descriptor.owner = new_owner;
|
||||
construct_tx_param ctp = get_default_construct_tx_param();
|
||||
ctp.ado_current_asset_owner = adb.owner;
|
||||
ctp.asset_owner = adb.owner;
|
||||
ctp.extra.push_back(asset_update_info);
|
||||
|
||||
finalized_tx ft = AUTO_VAL_INIT(ft);
|
||||
|
|
@ -5488,7 +5488,7 @@ void wallet2::burn_asset(const crypto::public_key asset_id, uint64_t amount_to_b
|
|||
construct_tx_param ctp = get_default_construct_tx_param();
|
||||
ctp.extra.push_back(asset_burn_info);
|
||||
ctp.need_at_least_1_zc = true;
|
||||
ctp.ado_current_asset_owner = rsp.asset_descriptor.owner;
|
||||
ctp.asset_owner = rsp.asset_descriptor.owner;
|
||||
ctp.dsts.push_back(dst_to_burn);
|
||||
|
||||
finalized_tx ft = AUTO_VAL_INIT(ft);
|
||||
|
|
@ -7599,8 +7599,8 @@ bool wallet2::prepare_transaction(construct_tx_param& ctp, currency::finalize_tx
|
|||
|
||||
const currency::transaction& tx_for_mode_separate = msc.tx_for_mode_separate;
|
||||
assets_selection_context needed_money_map = get_needed_money(ctp.fee, ctp.dsts);
|
||||
ftp.ado_current_asset_owner = ctp.ado_current_asset_owner;
|
||||
ftp.pthirdparty_sign_handler = ctp.pthirdparty_sign_handler;
|
||||
ftp.asset_owner = ctp.asset_owner;
|
||||
ftp.p_eth_signer = ctp.p_eth_signer;
|
||||
//
|
||||
// TODO @#@# need to do refactoring over this part to support hidden amounts and asset_id
|
||||
//
|
||||
|
|
|
|||
|
|
@ -224,9 +224,9 @@ namespace tools
|
|||
bool shuffle = false;
|
||||
bool create_utxo_defragmentation_tx = false;
|
||||
bool need_at_least_1_zc = false;
|
||||
//crypto::secret_key asset_deploy_control_key = currency::null_skey;
|
||||
currency::thirdparty_sign_handler* pthirdparty_sign_handler = nullptr;
|
||||
crypto::public_key ado_current_asset_owner = currency::null_pkey;
|
||||
|
||||
currency::asset_eth_signer_i* p_eth_signer = nullptr;
|
||||
currency::asset_owner_key_v asset_owner = currency::null_pkey;
|
||||
};
|
||||
|
||||
struct mode_separate_context
|
||||
|
|
|
|||
|
|
@ -30,3 +30,7 @@ struct wde_construct_tx_after_asset_ownership_proof_generated
|
|||
currency::asset_operation_ownership_proof* pownership_proof;
|
||||
};
|
||||
|
||||
struct wde_construct_tx_after_asset_ownership_eth_proof_generated
|
||||
{
|
||||
currency::asset_operation_ownership_proof_eth* pownership_proof_eth;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue