aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet2.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-11-18 11:24:38 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-12-17 16:12:44 +0000
commit98db7ee467fb4f73ce5e748d4891326b84a4c93a (patch)
tree00f60b318f05fdc092ebf658c2bb9e64be95e8d1 /src/wallet/wallet2.cpp
parentwallet: use raw encrypted data in multisig import/export RPC (diff)
downloadmonero-98db7ee467fb4f73ce5e748d4891326b84a4c93a.tar.xz
wallet: factor multisig info parsing
Diffstat (limited to 'src/wallet/wallet2.cpp')
-rw-r--r--src/wallet/wallet2.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 635264d70..70180e080 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -2895,6 +2895,60 @@ std::string wallet2::make_multisig(const epee::wipeable_string &password,
return extra_multisig_info;
}
+std::string wallet2::make_multisig(const epee::wipeable_string &password,
+ const std::vector<std::string> &info,
+ uint32_t threshold)
+{
+ // parse all multisig info
+ std::vector<crypto::secret_key> secret_keys(info.size());
+ std::vector<crypto::public_key> public_keys(info.size());
+ for (size_t i = 0; i < info.size(); ++i)
+ {
+ THROW_WALLET_EXCEPTION_IF(!verify_multisig_info(info[i], secret_keys[i], public_keys[i]),
+ error::wallet_internal_error, "Bad multisig info: " + info[i]);
+ }
+
+ // remove duplicates
+ for (size_t i = 0; i < secret_keys.size(); ++i)
+ {
+ for (size_t j = i + 1; j < secret_keys.size(); ++j)
+ {
+ if (rct::sk2rct(secret_keys[i]) == rct::sk2rct(secret_keys[j]))
+ {
+ MDEBUG("Duplicate key found, ignoring");
+ secret_keys[j] = secret_keys.back();
+ public_keys[j] = public_keys.back();
+ secret_keys.pop_back();
+ public_keys.pop_back();
+ --j;
+ }
+ }
+ }
+
+ // people may include their own, weed it out
+ const crypto::secret_key local_skey = cryptonote::get_multisig_blinded_secret_key(get_account().get_keys().m_view_secret_key);
+ const crypto::public_key local_pkey = get_multisig_signer_public_key(get_account().get_keys().m_spend_secret_key);
+ for (size_t i = 0; i < secret_keys.size(); ++i)
+ {
+ if (secret_keys[i] == local_skey)
+ {
+ MDEBUG("Local key is present, ignoring");
+ secret_keys[i] = secret_keys.back();
+ public_keys[i] = public_keys.back();
+ secret_keys.pop_back();
+ public_keys.pop_back();
+ --i;
+ }
+ else
+ {
+ THROW_WALLET_EXCEPTION_IF(public_keys[i] == local_pkey, error::wallet_internal_error,
+ "Found local spend public key, but not local view secret key - something very weird");
+ }
+ }
+
+ return make_multisig(password, secret_keys, public_keys, threshold);
+}
+
bool wallet2::finalize_multisig(const epee::wipeable_string &password, std::unordered_set<crypto::public_key> pkeys, std::vector<crypto::public_key> signers)
{
CHECK_AND_ASSERT_THROW_MES(!pkeys.empty(), "empty pkeys");