2018-01-07 05:05:16 +00:00
// Copyright (c) 2014-2018, The Monero Project
2014-07-23 13:03:52 +00:00
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
2014-03-03 22:07:58 +00:00
2014-09-27 12:50:15 +00:00
/*!
* \ file simplewallet . cpp
*
* \ brief Source file that defines simple_wallet class .
*/
2014-03-03 22:07:58 +00:00
# include <thread>
2014-06-12 23:34:24 +00:00
# include <iostream>
2014-09-17 21:38:15 +00:00
# include <sstream>
2016-01-09 01:49:41 +00:00
# include <fstream>
2015-07-18 21:03:35 +00:00
# include <ctype.h>
2014-03-03 22:07:58 +00:00
# include <boost/lexical_cast.hpp>
# include <boost/program_options.hpp>
# include <boost/algorithm/string.hpp>
2015-07-14 19:28:25 +00:00
# include <boost/format.hpp>
2017-09-22 18:20:09 +00:00
# include <boost/regex.hpp>
2014-03-03 22:07:58 +00:00
# include "include_base_utils.h"
2015-07-14 19:28:25 +00:00
# include "common/i18n.h"
2014-03-03 22:07:58 +00:00
# include "common/command_line.h"
2014-03-20 11:46:11 +00:00
# include "common/util.h"
2016-12-16 03:06:50 +00:00
# include "common/dns_utils.h"
2017-03-29 23:22:16 +00:00
# include "common/base58.h"
2017-08-11 12:38:42 +00:00
# include "common/scoped_message_writer.h"
2014-03-03 22:07:58 +00:00
# include "cryptonote_protocol/cryptonote_protocol_handler.h"
# include "simplewallet.h"
2017-01-26 15:07:23 +00:00
# include "cryptonote_basic/cryptonote_format_utils.h"
2014-03-03 22:07:58 +00:00
# include "storages/http_abstract_invoke.h"
# include "rpc/core_rpc_server_commands_defs.h"
2014-06-04 22:59:47 +00:00
# include "crypto/crypto.h" // for crypto::secret_key definition
2014-09-23 11:34:04 +00:00
# include "mnemonics/electrum-words.h"
wallet: add a --generate-from-json flag
It takes a filename containing JSON data to generate a wallet.
The following fields are valid:
version: integer, should be 1
filename: string, path/filename for the newly created wallet
scan_from_height: 64 bit unsigned integer, optional
password: string, optional
viewkey: string, hex representation
spendkey: string, hex representation
seed: string, optional, list of words separated by spaces
Either seed or private keys should be given. If using private
keys, the spend key may be omitted (the wallet will not be
able to spend, but will see incoming transactions).
If scan_from_height is given, blocks below this height will not
be checked for transactions as an optimization.
2016-03-25 00:48:11 +00:00
# include "rapidjson/document.h"
2016-03-27 15:26:37 +00:00
# include "common/json_util.h"
2016-07-11 22:14:58 +00:00
# include "ringct/rctSigs.h"
2017-11-04 10:39:17 +00:00
# include "multisig/multisig.h"
2016-11-09 03:55:41 +00:00
# include "wallet/wallet_args.h"
2018-04-13 17:45:10 +00:00
# include "version.h"
2014-09-26 19:25:21 +00:00
# include <stdexcept>
2014-08-03 14:58:21 +00:00
2018-02-22 18:52:55 +00:00
# ifdef WIN32
# include <boost/locale.hpp>
# include <boost/filesystem.hpp>
# endif
2017-08-21 15:34:45 +00:00
# ifdef HAVE_READLINE
# include "readline_buffer.h"
# endif
2014-03-03 22:07:58 +00:00
using namespace std ;
using namespace epee ;
using namespace cryptonote ;
using boost : : lexical_cast ;
namespace po = boost : : program_options ;
2015-07-14 19:28:25 +00:00
typedef cryptonote : : simple_wallet sw ;
2014-03-03 22:07:58 +00:00
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
# undef MONERO_DEFAULT_LOG_CATEGORY
# define MONERO_DEFAULT_LOG_CATEGORY "wallet.simplewallet"
2014-03-03 22:07:58 +00:00
# define EXTENDED_LOGS_FILE "wallet_details.log"
2018-07-18 21:24:53 +00:00
# define DEFAULT_MIX 10
2014-03-03 22:07:58 +00:00
2018-07-18 21:24:53 +00:00
# define MIN_RING_SIZE 11 // Used to inform user about min ring size -- does not track actual protocol
2017-11-10 10:03:53 +00:00
2016-08-07 12:06:40 +00:00
# define LOCK_IDLE_SCOPE() \
bool auto_refresh_enabled = m_auto_refresh_enabled . load ( std : : memory_order_relaxed ) ; \
m_auto_refresh_enabled . store ( false , std : : memory_order_relaxed ) ; \
2016-04-20 23:11:11 +00:00
/* stop any background refresh, and take over */ \
m_wallet - > stop ( ) ; \
2016-08-07 12:06:40 +00:00
boost : : unique_lock < boost : : mutex > lock ( m_idle_mutex ) ; \
2018-08-12 12:49:32 +00:00
m_idle_cond . notify_all ( ) ; \
2016-04-20 23:11:11 +00:00
epee : : misc_utils : : auto_scope_leave_caller scope_exit_handler = epee : : misc_utils : : create_scope_leave_handler ( [ & ] ( ) { \
2016-08-07 12:06:40 +00:00
m_auto_refresh_enabled . store ( auto_refresh_enabled , std : : memory_order_relaxed ) ; \
2016-04-20 23:11:11 +00:00
} )
2018-07-08 20:12:33 +00:00
# define SCOPED_WALLET_UNLOCK() \
LOCK_IDLE_SCOPE ( ) ; \
boost : : optional < tools : : password_container > pwd_container = boost : : none ; \
if ( m_wallet - > ask_password ( ) & & ! m_wallet - > watch_only ( ) & & ! ( pwd_container = get_and_verify_password ( ) ) ) { return true ; } \
tools : : wallet_keys_unlocker unlocker ( * m_wallet , pwd_container ) ;
2016-06-15 22:37:13 +00:00
enum TransferType {
2018-09-16 14:28:59 +00:00
Transfer ,
2016-10-22 12:29:23 +00:00
TransferLocked ,
2016-06-15 22:37:13 +00:00
} ;
2014-03-03 22:07:58 +00:00
namespace
{
2017-10-07 03:40:27 +00:00
const std : : array < const char * const , 5 > allowed_priority_strings = { { " default " , " unimportant " , " normal " , " elevated " , " priority " } } ;
2016-11-09 03:55:41 +00:00
const auto arg_wallet_file = wallet_args : : arg_wallet_file ( ) ;
2016-08-24 00:03:36 +00:00
const command_line : : arg_descriptor < std : : string > arg_generate_new_wallet = { " generate-new-wallet " , sw : : tr ( " Generate new wallet and save it to <arg> " ) , " " } ;
2018-02-20 16:01:27 +00:00
const command_line : : arg_descriptor < std : : string > arg_generate_from_device = { " generate-from-device " , sw : : tr ( " Generate new wallet from device and save it to <arg> " ) , " " } ;
2016-02-27 11:53:11 +00:00
const command_line : : arg_descriptor < std : : string > arg_generate_from_view_key = { " generate-from-view-key " , sw : : tr ( " Generate incoming-only wallet from view key " ) , " " } ;
2017-10-09 23:31:46 +00:00
const command_line : : arg_descriptor < std : : string > arg_generate_from_spend_key = { " generate-from-spend-key " , sw : : tr ( " Generate deterministic wallet from spend key " ) , " " } ;
2016-02-27 11:53:11 +00:00
const command_line : : arg_descriptor < std : : string > arg_generate_from_keys = { " generate-from-keys " , sw : : tr ( " Generate wallet from private keys " ) , " " } ;
2017-07-28 23:41:24 +00:00
const command_line : : arg_descriptor < std : : string > arg_generate_from_multisig_keys = { " generate-from-multisig-keys " , sw : : tr ( " Generate a master wallet from multisig wallet keys " ) , " " } ;
2016-11-09 03:55:41 +00:00
const auto arg_generate_from_json = wallet_args : : arg_generate_from_json ( ) ;
2017-08-14 03:00:25 +00:00
const command_line : : arg_descriptor < std : : string > arg_mnemonic_language = { " mnemonic-language " , sw : : tr ( " Language for mnemonic " ) , " " } ;
2015-12-12 00:05:39 +00:00
const command_line : : arg_descriptor < std : : string > arg_electrum_seed = { " electrum-seed " , sw : : tr ( " Specify Electrum seed for wallet recovery/creation " ) , " " } ;
const command_line : : arg_descriptor < bool > arg_restore_deterministic_wallet = { " restore-deterministic-wallet " , sw : : tr ( " Recover wallet using Electrum-style mnemonic seed " ) , false } ;
2017-11-09 10:59:41 +00:00
const command_line : : arg_descriptor < bool > arg_restore_multisig_wallet = { " restore-multisig-wallet " , sw : : tr ( " Recover multisig wallet using Electrum-style mnemonic seed " ) , false } ;
2018-01-09 20:41:24 +00:00
const command_line : : arg_descriptor < bool > arg_non_deterministic = { " non-deterministic " , sw : : tr ( " Generate non-deterministic view and spend keys " ) , false } ;
2016-07-10 15:49:40 +00:00
const command_line : : arg_descriptor < bool > arg_allow_mismatched_daemon_version = { " allow-mismatched-daemon-version " , sw : : tr ( " Allow communicating with a daemon that uses a different RPC version " ) , false } ;
2016-04-15 18:10:20 +00:00
const command_line : : arg_descriptor < uint64_t > arg_restore_height = { " restore-height " , sw : : tr ( " Restore from specific blockchain height " ) , 0 } ;
2017-10-06 01:14:09 +00:00
const command_line : : arg_descriptor < bool > arg_do_not_relay = { " do-not-relay " , sw : : tr ( " The newly created transaction will not be relayed to the monero network " ) , false } ;
2018-02-25 16:59:52 +00:00
const command_line : : arg_descriptor < bool > arg_create_address_file = { " create-address-file " , sw : : tr ( " Create an address file for new wallets " ) , false } ;
2018-03-16 04:11:45 +00:00
const command_line : : arg_descriptor < std : : string > arg_subaddress_lookahead = { " subaddress-lookahead " , tools : : wallet2 : : tr ( " Set subaddress lookahead sizes to <major>:<minor> " ) , " " } ;
2018-03-17 22:46:41 +00:00
const command_line : : arg_descriptor < bool > arg_use_english_language_names = { " use-english-language-names " , sw : : tr ( " Display English language names " ) , false } ;
2014-03-03 22:07:58 +00:00
const command_line : : arg_descriptor < std : : vector < std : : string > > arg_command = { " command " , " " } ;
2017-10-28 15:09:13 +00:00
std : : string input_line ( const std : : string & prompt )
{
# ifdef HAVE_READLINE
rdln : : suspend_readline pause_readline ;
# endif
std : : cout < < prompt ;
std : : string buf ;
2018-09-19 12:39:01 +00:00
# ifdef _WIN32
buf = tools : : input_line_win ( ) ;
# else
2017-10-28 15:09:13 +00:00
std : : getline ( std : : cin , buf ) ;
2018-02-22 18:52:55 +00:00
# endif
2017-10-28 15:09:13 +00:00
return epee : : string_tools : : trim ( buf ) ;
}
2018-07-06 23:03:15 +00:00
epee : : wipeable_string input_secure_line ( const std : : string & prompt )
{
# ifdef HAVE_READLINE
rdln : : suspend_readline pause_readline ;
# endif
auto pwd_container = tools : : password_container : : prompt ( false , prompt . c_str ( ) , false ) ;
if ( ! pwd_container )
{
MERROR ( " Failed to read secure line " ) ;
return " " ;
}
epee : : wipeable_string buf = pwd_container - > password ( ) ;
buf . trim ( ) ;
return buf ;
}
2017-10-28 18:13:42 +00:00
boost : : optional < tools : : password_container > password_prompter ( const char * prompt , bool verify )
{
# ifdef HAVE_READLINE
rdln : : suspend_readline pause_readline ;
# endif
auto pwd_container = tools : : password_container : : prompt ( verify , prompt ) ;
if ( ! pwd_container )
{
2018-10-06 08:12:38 +00:00
tools : : fail_msg_writer ( ) < < sw : : tr ( " failed to read wallet password " ) ;
2017-10-28 18:13:42 +00:00
}
return pwd_container ;
}
boost : : optional < tools : : password_container > default_password_prompter ( bool verify )
{
2018-10-06 08:12:38 +00:00
return password_prompter ( verify ? sw : : tr ( " Enter a new password for the wallet " ) : sw : : tr ( " Wallet password " ) , verify ) ;
2017-10-28 18:13:42 +00:00
}
2014-04-02 16:00:17 +00:00
inline std : : string interpret_rpc_response ( bool ok , const std : : string & status )
2014-03-20 11:46:11 +00:00
{
2014-04-02 16:00:17 +00:00
std : : string err ;
if ( ok )
{
if ( status = = CORE_RPC_STATUS_BUSY )
{
2015-12-12 00:05:39 +00:00
err = sw : : tr ( " daemon is busy. Please try again later. " ) ;
2014-04-02 16:00:17 +00:00
}
else if ( status ! = CORE_RPC_STATUS_OK )
{
err = status ;
}
}
else
{
2015-12-12 00:05:39 +00:00
err = sw : : tr ( " possibly lost connection to daemon " ) ;
2014-04-02 16:00:17 +00:00
}
return err ;
}
2017-08-11 12:38:42 +00:00
tools : : scoped_message_writer success_msg_writer ( bool color = false )
2014-04-02 16:00:17 +00:00
{
2017-08-11 12:38:42 +00:00
return tools : : scoped_message_writer ( color ? console_color_green : console_color_default , false , std : : string ( ) , el : : Level : : Info ) ;
}
2014-04-02 16:00:17 +00:00
2017-08-11 12:38:42 +00:00
tools : : scoped_message_writer message_writer ( epee : : console_colors color = epee : : console_color_default , bool bright = false )
2014-04-02 16:00:17 +00:00
{
2017-08-11 12:38:42 +00:00
return tools : : scoped_message_writer ( color , bright ) ;
2014-03-20 11:46:11 +00:00
}
2014-03-03 22:07:58 +00:00
2017-08-11 12:38:42 +00:00
tools : : scoped_message_writer fail_msg_writer ( )
2014-03-20 11:46:11 +00:00
{
2017-08-11 12:38:42 +00:00
return tools : : scoped_message_writer ( console_color_red , true , sw : : tr ( " Error: " ) , el : : Level : : Error ) ;
2014-03-20 11:46:11 +00:00
}
2015-07-18 21:03:35 +00:00
2017-10-19 12:57:49 +00:00
bool parse_bool ( const std : : string & s , bool & result )
2015-07-18 21:03:35 +00:00
{
2016-11-26 02:07:45 +00:00
if ( s = = " 1 " | | command_line : : is_yes ( s ) )
2017-10-19 12:57:49 +00:00
{
result = true ;
return true ;
}
if ( s = = " 0 " | | command_line : : is_no ( s ) )
{
result = false ;
2015-07-18 21:03:35 +00:00
return true ;
2017-10-19 12:57:49 +00:00
}
2016-11-26 02:07:45 +00:00
boost : : algorithm : : is_iequal ignore_case { } ;
2017-10-19 12:57:49 +00:00
if ( boost : : algorithm : : equals ( " true " , s , ignore_case ) | | boost : : algorithm : : equals ( simple_wallet : : tr ( " true " ) , s , ignore_case ) )
{
result = true ;
2015-07-18 21:03:35 +00:00
return true ;
2017-10-19 12:57:49 +00:00
}
if ( boost : : algorithm : : equals ( " false " , s , ignore_case ) | | boost : : algorithm : : equals ( simple_wallet : : tr ( " false " ) , s , ignore_case ) )
{
result = false ;
2015-07-18 21:03:35 +00:00
return true ;
2017-10-19 12:57:49 +00:00
}
2016-11-26 02:07:45 +00:00
2015-07-18 21:03:35 +00:00
return false ;
}
2016-04-28 21:09:49 +00:00
2017-10-19 12:57:49 +00:00
template < typename F >
bool parse_bool_and_use ( const std : : string & s , F func )
{
bool r ;
if ( parse_bool ( s , r ) )
{
func ( r ) ;
return true ;
}
else
{
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " invalid argument: must be either 0/1, true/false, y/n, yes/no " ) ;
2017-10-19 12:57:49 +00:00
return false ;
}
}
2016-04-28 21:09:49 +00:00
const struct
{
const char * name ;
tools : : wallet2 : : RefreshType refresh_type ;
} refresh_type_names [ ] =
{
{ " full " , tools : : wallet2 : : RefreshFull } ,
{ " optimize-coinbase " , tools : : wallet2 : : RefreshOptimizeCoinbase } ,
{ " optimized-coinbase " , tools : : wallet2 : : RefreshOptimizeCoinbase } ,
{ " no-coinbase " , tools : : wallet2 : : RefreshNoCoinbase } ,
{ " default " , tools : : wallet2 : : RefreshDefault } ,
} ;
bool parse_refresh_type ( const std : : string & s , tools : : wallet2 : : RefreshType & refresh_type )
{
for ( size_t n = 0 ; n < sizeof ( refresh_type_names ) / sizeof ( refresh_type_names [ 0 ] ) ; + + n )
{
if ( s = = refresh_type_names [ n ] . name )
{
refresh_type = refresh_type_names [ n ] . refresh_type ;
return true ;
}
}
2016-11-09 03:55:41 +00:00
fail_msg_writer ( ) < < cryptonote : : simple_wallet : : tr ( " failed to parse refresh type " ) ;
2016-04-28 21:09:49 +00:00
return false ;
}
std : : string get_refresh_type_name ( tools : : wallet2 : : RefreshType type )
{
for ( size_t n = 0 ; n < sizeof ( refresh_type_names ) / sizeof ( refresh_type_names [ 0 ] ) ; + + n )
{
if ( type = = refresh_type_names [ n ] . refresh_type )
return refresh_type_names [ n ] . name ;
}
return " invalid " ;
}
2016-11-26 12:53:33 +00:00
std : : string get_version_string ( uint32_t version )
{
return boost : : lexical_cast < std : : string > ( version > > 16 ) + " . " + boost : : lexical_cast < std : : string > ( version & 0xffff ) ;
}
2017-07-27 10:28:53 +00:00
std : : string oa_prompter ( const std : : string & url , const std : : vector < std : : string > & addresses , bool dnssec_valid )
{
if ( addresses . empty ( ) )
return { } ;
// prompt user for confirmation.
// inform user of DNSSEC validation status as well.
std : : string dnssec_str ;
if ( dnssec_valid )
{
2018-10-06 08:12:38 +00:00
dnssec_str = sw : : tr ( " DNSSEC validation passed " ) ;
2017-07-27 10:28:53 +00:00
}
else
{
2018-10-06 08:12:38 +00:00
dnssec_str = sw : : tr ( " WARNING: DNSSEC validation was unsuccessful, this address may not be correct! " ) ;
2017-07-27 10:28:53 +00:00
}
std : : stringstream prompt ;
2018-10-06 08:12:38 +00:00
prompt < < sw : : tr ( " For URL: " ) < < url
2017-07-27 10:28:53 +00:00
< < " , " < < dnssec_str < < std : : endl
2018-10-06 08:12:38 +00:00
< < sw : : tr ( " Monero Address = " ) < < addresses [ 0 ]
2017-07-27 10:28:53 +00:00
< < std : : endl
2018-10-06 08:12:38 +00:00
< < sw : : tr ( " Is this OK? (Y/n) " )
2017-07-27 10:28:53 +00:00
;
// prompt the user for confirmation given the dns query and dnssec status
2017-10-28 18:13:42 +00:00
std : : string confirm_dns_ok = input_line ( prompt . str ( ) ) ;
2017-07-27 10:28:53 +00:00
if ( std : : cin . eof ( ) )
{
return { } ;
}
if ( ! command_line : : is_yes ( confirm_dns_ok ) )
{
2018-10-06 08:12:38 +00:00
std : : cout < < sw : : tr ( " you have cancelled the transfer request " ) < < std : : endl ;
2017-07-27 10:28:53 +00:00
return { } ;
}
return addresses [ 0 ] ;
}
2017-02-19 02:42:10 +00:00
bool parse_subaddress_indices ( const std : : string & arg , std : : set < uint32_t > & subaddr_indices )
{
subaddr_indices . clear ( ) ;
if ( arg . substr ( 0 , 6 ) ! = " index= " )
return false ;
std : : string subaddr_indices_str_unsplit = arg . substr ( 6 , arg . size ( ) - 6 ) ;
std : : vector < std : : string > subaddr_indices_str ;
boost : : split ( subaddr_indices_str , subaddr_indices_str_unsplit , boost : : is_any_of ( " , " ) ) ;
for ( const auto & subaddr_index_str : subaddr_indices_str )
{
uint32_t subaddr_index ;
if ( ! epee : : string_tools : : get_xtype_from_string ( subaddr_index , subaddr_index_str ) )
{
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " failed to parse index: " ) < < subaddr_index_str ;
2017-02-19 02:42:10 +00:00
subaddr_indices . clear ( ) ;
return false ;
}
subaddr_indices . insert ( subaddr_index ) ;
}
return true ;
}
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
2018-03-16 04:11:45 +00:00
boost : : optional < std : : pair < uint32_t , uint32_t > > parse_subaddress_lookahead ( const std : : string & str )
{
2018-06-04 07:54:35 +00:00
auto r = tools : : parse_subaddress_lookahead ( str ) ;
if ( ! r )
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " invalid format for subaddress lookahead; must be <major>:<minor> " ) ;
2018-06-04 07:54:35 +00:00
return r ;
2018-03-16 04:11:45 +00:00
}
2018-03-15 09:56:49 +00:00
void handle_transfer_exception ( const std : : exception_ptr & e , bool trusted_daemon )
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
{
2018-03-15 09:56:49 +00:00
bool warn_of_possible_attack = ! trusted_daemon ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
try
{
std : : rethrow_exception ( e ) ;
}
catch ( const tools : : error : : daemon_busy & )
{
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " daemon is busy. Please try again later. " ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : no_connection_to_daemon & )
{
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " no connection to daemon. Please make sure daemon is running. " ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : wallet_rpc_error & e )
{
LOG_ERROR ( " RPC error: " < < e . to_string ( ) ) ;
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " RPC error: " ) < < e . what ( ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
2018-08-13 16:18:32 +00:00
catch ( const tools : : error : : get_outs_error & e )
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
{
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " failed to get random outputs to mix: " ) < < e . what ( ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : not_enough_unlocked_money & e )
{
LOG_PRINT_L0 ( boost : : format ( " not enough money to transfer, available only %s, sent amount %s " ) %
print_money ( e . available ( ) ) %
print_money ( e . tx_amount ( ) ) ) ;
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " Not enough money in unlocked balance " ) ;
2018-03-15 09:56:49 +00:00
warn_of_possible_attack = false ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : not_enough_money & e )
{
LOG_PRINT_L0 ( boost : : format ( " not enough money to transfer, available only %s, sent amount %s " ) %
print_money ( e . available ( ) ) %
print_money ( e . tx_amount ( ) ) ) ;
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " Not enough money in unlocked balance " ) ;
2018-03-15 09:56:49 +00:00
warn_of_possible_attack = false ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : tx_not_possible & e )
{
LOG_PRINT_L0 ( boost : : format ( " not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee) " ) %
print_money ( e . available ( ) ) %
print_money ( e . tx_amount ( ) + e . fee ( ) ) %
print_money ( e . tx_amount ( ) ) %
print_money ( e . fee ( ) ) ) ;
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees, or trying to send more money than the unlocked balance, or not leaving enough for fees " ) ;
2018-03-15 09:56:49 +00:00
warn_of_possible_attack = false ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : not_enough_outs_to_mix & e )
{
auto writer = fail_msg_writer ( ) ;
2018-10-06 08:12:38 +00:00
writer < < sw : : tr ( " not enough outputs for specified ring size " ) < < " = " < < ( e . mixin_count ( ) + 1 ) < < " : " ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
for ( std : : pair < uint64_t , uint64_t > outs_for_amount : e . scanty_outs ( ) )
{
2018-10-06 08:12:38 +00:00
writer < < " \n " < < sw : : tr ( " output amount " ) < < " = " < < print_money ( outs_for_amount . first ) < < " , " < < sw : : tr ( " found outputs to use " ) < < " = " < < outs_for_amount . second ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
2018-10-06 08:12:38 +00:00
writer < < sw : : tr ( " Please use sweep_unmixable. " ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : tx_not_constructed & )
2018-10-06 08:12:38 +00:00
{
fail_msg_writer ( ) < < sw : : tr ( " transaction was not constructed " ) ;
2018-03-15 09:56:49 +00:00
warn_of_possible_attack = false ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : tx_rejected & e )
{
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < ( boost : : format ( sw : : tr ( " transaction %s was rejected by daemon with status: " ) ) % get_transaction_hash ( e . tx ( ) ) ) < < e . status ( ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
std : : string reason = e . reason ( ) ;
if ( ! reason . empty ( ) )
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " Reason: " ) < < reason ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : tx_sum_overflow & e )
{
fail_msg_writer ( ) < < e . what ( ) ;
2018-03-15 09:56:49 +00:00
warn_of_possible_attack = false ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : zero_destination & )
{
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " one of destinations is zero " ) ;
2018-03-15 09:56:49 +00:00
warn_of_possible_attack = false ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : tx_too_big & e )
{
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " failed to find a suitable way to split transactions " ) ;
2018-03-15 09:56:49 +00:00
warn_of_possible_attack = false ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : transfer_error & e )
{
LOG_ERROR ( " unknown transfer error: " < < e . to_string ( ) ) ;
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " unknown transfer error: " ) < < e . what ( ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : multisig_export_needed & e )
{
LOG_ERROR ( " Multisig error: " < < e . to_string ( ) ) ;
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " Multisig error: " ) < < e . what ( ) ;
2018-03-15 09:56:49 +00:00
warn_of_possible_attack = false ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const tools : : error : : wallet_internal_error & e )
{
LOG_ERROR ( " internal error: " < < e . to_string ( ) ) ;
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " internal error: " ) < < e . what ( ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( const std : : exception & e )
{
LOG_ERROR ( " unexpected error: " < < e . what ( ) ) ;
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " unexpected error: " ) < < e . what ( ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
2018-03-15 09:56:49 +00:00
if ( warn_of_possible_attack )
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " There was an error, which could mean the node may be trying to get you to retry creating a transaction, and zero in on which outputs you own. Or it could be a bona fide error. It may be prudent to disconnect from this node, and not try to send a transaction immediately. Alternatively, connect to another node so the original node cannot correlate information. " ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
2018-01-14 23:36:13 +00:00
bool check_file_overwrite ( const std : : string & filename )
{
boost : : system : : error_code errcode ;
if ( boost : : filesystem : : exists ( filename , errcode ) )
{
if ( boost : : ends_with ( filename , " .keys " ) )
{
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < boost : : format ( sw : : tr ( " File %s likely stores wallet private keys! Use a different file name. " ) ) % filename ;
2018-01-14 23:36:13 +00:00
return false ;
}
2018-10-06 08:12:38 +00:00
return command_line : : is_yes ( input_line ( ( boost : : format ( sw : : tr ( " File %s already exists. Are you sure to overwrite it? (Y/Yes/N/No): " ) ) % filename ) . str ( ) ) ) ;
2018-01-14 23:36:13 +00:00
}
return true ;
}
2018-07-08 20:12:33 +00:00
void print_secret_key ( const crypto : : secret_key & k )
{
static constexpr const char hex [ ] = u8 " 0123456789abcdef " ;
const uint8_t * ptr = ( const uint8_t * ) k . data ;
for ( size_t i = 0 , sz = sizeof ( k ) ; i < sz ; + + i )
{
putchar ( hex [ * ptr > > 4 ] ) ;
putchar ( hex [ * ptr & 15 ] ) ;
+ + ptr ;
}
}
2014-03-20 11:46:11 +00:00
}
2014-03-03 22:07:58 +00:00
2017-10-07 03:40:27 +00:00
bool parse_priority ( const std : : string & arg , uint32_t & priority )
{
auto priority_pos = std : : find (
allowed_priority_strings . begin ( ) ,
allowed_priority_strings . end ( ) ,
arg ) ;
if ( priority_pos ! = allowed_priority_strings . end ( ) ) {
priority = std : : distance ( allowed_priority_strings . begin ( ) , priority_pos ) ;
return true ;
}
return false ;
}
2014-03-03 22:07:58 +00:00
2018-08-15 12:15:39 +00:00
std : : string join_priority_strings ( const char * delimiter )
{
std : : string s ;
for ( size_t n = 0 ; n < allowed_priority_strings . size ( ) ; + + n )
{
if ( ! s . empty ( ) )
s + = delimiter ;
s + = allowed_priority_strings [ n ] ;
}
return s ;
}
2014-03-03 22:07:58 +00:00
std : : string simple_wallet : : get_commands_str ( )
{
std : : stringstream ss ;
2015-07-14 19:28:25 +00:00
ss < < tr ( " Commands: " ) < < ENDL ;
2014-03-03 22:07:58 +00:00
std : : string usage = m_cmd_binder . get_usage ( ) ;
boost : : replace_all ( usage , " \n " , " \n " ) ;
usage . insert ( 0 , " " ) ;
ss < < usage < < ENDL ;
return ss . str ( ) ;
}
2017-11-22 12:53:18 +00:00
std : : string simple_wallet : : get_command_usage ( const std : : vector < std : : string > & args )
{
std : : pair < std : : string , std : : string > documentation = m_cmd_binder . get_documentation ( args ) ;
std : : stringstream ss ;
if ( documentation . first . empty ( ) )
{
ss < < tr ( " Unknown command: " ) < < args . front ( ) ;
}
else
{
std : : string usage = documentation . second . empty ( ) ? args . front ( ) : documentation . first ;
std : : string description = documentation . second . empty ( ) ? documentation . first : documentation . second ;
usage . insert ( 0 , " " ) ;
ss < < tr ( " Command usage: " ) < < ENDL < < usage < < ENDL < < ENDL ;
boost : : replace_all ( description , " \n " , " \n " ) ;
description . insert ( 0 , " " ) ;
ss < < tr ( " Command description: " ) < < ENDL < < description < < ENDL ;
}
return ss . str ( ) ;
}
2014-08-05 06:53:30 +00:00
bool simple_wallet : : viewkey ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
2015-05-27 10:37:38 +00:00
// don't log
2018-07-08 20:12:33 +00:00
PAUSE_READLINE ( ) ;
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) ) {
std : : cout < < " secret: On device. Not available " < < std : : endl ;
} else {
2018-11-04 01:48:49 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2018-07-08 20:12:33 +00:00
printf ( " secret: " ) ;
print_secret_key ( m_wallet - > get_account ( ) . get_keys ( ) . m_view_secret_key ) ;
putchar ( ' \n ' ) ;
2018-02-20 16:01:27 +00:00
}
2016-11-13 17:24:53 +00:00
std : : cout < < " public: " < < string_tools : : pod_to_hex ( m_wallet - > get_account ( ) . get_keys ( ) . m_account_address . m_view_public_key ) < < std : : endl ;
2014-08-05 06:53:30 +00:00
return true ;
}
2015-05-20 00:08:37 +00:00
bool simple_wallet : : spendkey ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
2017-01-27 12:26:52 +00:00
if ( m_wallet - > watch_only ( ) )
{
fail_msg_writer ( ) < < tr ( " wallet is watch-only and has no spend key " ) ;
return true ;
}
2015-05-27 10:37:38 +00:00
// don't log
2018-07-08 20:12:33 +00:00
PAUSE_READLINE ( ) ;
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) ) {
std : : cout < < " secret: On device. Not available " < < std : : endl ;
} else {
2018-11-04 01:48:49 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2018-07-08 20:12:33 +00:00
printf ( " secret: " ) ;
print_secret_key ( m_wallet - > get_account ( ) . get_keys ( ) . m_spend_secret_key ) ;
putchar ( ' \n ' ) ;
2018-02-20 16:01:27 +00:00
}
2016-11-13 17:24:53 +00:00
std : : cout < < " public: " < < string_tools : : pod_to_hex ( m_wallet - > get_account ( ) . get_keys ( ) . m_account_address . m_spend_public_key ) < < std : : endl ;
2015-05-20 00:08:37 +00:00
return true ;
}
2017-08-06 15:51:40 +00:00
bool simple_wallet : : print_seed ( bool encrypted )
2014-08-01 13:40:18 +00:00
{
2014-12-06 09:48:33 +00:00
bool success = false ;
2018-07-06 23:03:15 +00:00
epee : : wipeable_string seed ;
2017-11-09 10:59:41 +00:00
bool ready , multisig ;
2014-11-06 22:36:36 +00:00
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2015-06-20 11:27:23 +00:00
if ( m_wallet - > watch_only ( ) )
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " wallet is watch-only and has no seed " ) ;
2015-06-20 11:27:23 +00:00
return true ;
}
2018-07-08 20:12:33 +00:00
2017-11-09 10:59:41 +00:00
multisig = m_wallet - > multisig ( & ready ) ;
if ( multisig )
{
if ( ! ready )
2017-08-06 15:51:40 +00:00
{
2017-11-09 10:59:41 +00:00
fail_msg_writer ( ) < < tr ( " wallet is multisig but not yet finalized " ) ;
return true ;
2017-08-06 15:51:40 +00:00
}
2017-11-09 10:59:41 +00:00
}
2018-11-04 01:48:49 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
if ( ! multisig & & ! m_wallet - > is_deterministic ( ) )
2017-11-09 10:59:41 +00:00
{
fail_msg_writer ( ) < < tr ( " wallet is non-deterministic and has no seed " ) ;
return true ;
}
2017-08-06 15:51:40 +00:00
2017-11-09 10:59:41 +00:00
epee : : wipeable_string seed_pass ;
if ( encrypted )
{
2018-07-07 10:09:59 +00:00
auto pwd_container = password_prompter ( tr ( " Enter optional seed offset passphrase, empty to see raw seed " ) , true ) ;
2017-11-09 10:59:41 +00:00
if ( std : : cin . eof ( ) | | ! pwd_container )
return true ;
seed_pass = pwd_container - > password ( ) ;
2014-11-06 22:36:36 +00:00
}
2017-11-09 10:59:41 +00:00
if ( multisig )
success = m_wallet - > get_multisig_seed ( seed , seed_pass ) ;
else if ( m_wallet - > is_deterministic ( ) )
success = m_wallet - > get_seed ( seed , seed_pass ) ;
2014-08-03 14:58:21 +00:00
if ( success )
2014-08-02 16:14:29 +00:00
{
2017-11-09 10:59:41 +00:00
print_seed ( seed ) ;
2014-08-02 16:14:29 +00:00
}
else
{
2017-11-09 10:59:41 +00:00
fail_msg_writer ( ) < < tr ( " Failed to retrieve seed " ) ;
2014-08-02 16:14:29 +00:00
}
2014-08-01 13:40:18 +00:00
return true ;
}
2017-08-06 15:51:40 +00:00
bool simple_wallet : : seed ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
return print_seed ( false ) ;
}
bool simple_wallet : : encrypted_seed ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
return print_seed ( true ) ;
}
2014-12-06 14:58:33 +00:00
bool simple_wallet : : seed_set_language ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( m_wallet - > multisig ( ) )
{
fail_msg_writer ( ) < < tr ( " wallet is multisig and has no seed " ) ;
return true ;
}
2015-06-20 11:27:23 +00:00
if ( m_wallet - > watch_only ( ) )
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " wallet is watch-only and has no seed " ) ;
2015-06-20 11:27:23 +00:00
return true ;
}
2018-07-08 20:12:33 +00:00
epee : : wipeable_string password ;
2014-12-06 14:58:33 +00:00
{
2018-07-08 20:12:33 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
if ( ! m_wallet - > is_deterministic ( ) )
{
fail_msg_writer ( ) < < tr ( " wallet is non-deterministic and has no seed " ) ;
2016-12-17 23:07:15 +00:00
return true ;
2018-07-08 20:12:33 +00:00
}
2014-12-06 14:58:33 +00:00
2018-07-08 20:12:33 +00:00
// we need the password, even if ask-password is unset
if ( ! pwd_container )
{
pwd_container = get_and_verify_password ( ) ;
if ( pwd_container = = boost : : none )
{
fail_msg_writer ( ) < < tr ( " Incorrect password " ) ;
return true ;
}
}
password = pwd_container - > password ( ) ;
2014-12-06 14:58:33 +00:00
}
2018-07-08 20:12:33 +00:00
std : : string mnemonic_language = get_mnemonic_language ( ) ;
if ( mnemonic_language . empty ( ) )
return true ;
m_wallet - > set_seed_language ( std : : move ( mnemonic_language ) ) ;
m_wallet - > rewrite ( m_wallet_file , password ) ;
2014-12-06 14:58:33 +00:00
return true ;
}
2017-01-27 07:12:18 +00:00
bool simple_wallet : : change_password ( const std : : vector < std : : string > & args )
{
const auto orig_pwd_container = get_and_verify_password ( ) ;
if ( orig_pwd_container = = boost : : none )
{
fail_msg_writer ( ) < < tr ( " Your original password was incorrect. " ) ;
2017-04-12 12:33:19 +00:00
return true ;
2017-01-27 07:12:18 +00:00
}
2017-03-05 14:52:38 +00:00
// prompts for a new password, pass true to verify the password
2017-10-28 18:13:42 +00:00
const auto pwd_container = default_password_prompter ( true ) ;
2018-02-01 20:32:30 +00:00
if ( ! pwd_container )
return true ;
2017-03-05 14:52:38 +00:00
2017-01-27 07:12:18 +00:00
try
{
2018-07-08 20:12:33 +00:00
m_wallet - > change_password ( m_wallet_file , orig_pwd_container - > password ( ) , pwd_container - > password ( ) ) ;
2017-01-27 07:12:18 +00:00
}
2017-02-02 20:56:31 +00:00
catch ( const tools : : error : : wallet_logic_error & e )
2017-01-27 07:12:18 +00:00
{
fail_msg_writer ( ) < < tr ( " Error with wallet rewrite: " ) < < e . what ( ) ;
2017-04-12 12:33:19 +00:00
return true ;
2017-01-27 07:12:18 +00:00
}
return true ;
}
2017-06-10 09:08:55 +00:00
bool simple_wallet : : payment_id ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
crypto : : hash payment_id ;
if ( args . size ( ) > 0 )
{
fail_msg_writer ( ) < < tr ( " usage: payment_id " ) ;
return true ;
}
payment_id = crypto : : rand < crypto : : hash > ( ) ;
success_msg_writer ( ) < < tr ( " Random payment ID: " ) < < payment_id ;
return true ;
}
2017-08-27 20:04:56 +00:00
bool simple_wallet : : print_fee_info ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
if ( ! try_connect_to_daemon ( ) )
{
fail_msg_writer ( ) < < tr ( " Cannot connect to daemon " ) ;
return true ;
}
2018-07-18 21:24:53 +00:00
const bool per_byte = m_wallet - > use_fork_rules ( HF_VERSION_PER_BYTE_FEE ) ;
const uint64_t base_fee = m_wallet - > get_base_fee ( ) ;
const char * base = per_byte ? " byte " : " kB " ;
const uint64_t typical_size = per_byte ? 2500 : 13 ;
const uint64_t size_granularity = per_byte ? 1 : 1024 ;
message_writer ( ) < < ( boost : : format ( tr ( " Current fee is %s %s per %s " ) ) % print_money ( base_fee ) % cryptonote : : get_unit ( cryptonote : : get_default_decimal_point ( ) ) % base ) . str ( ) ;
2017-08-27 20:04:56 +00:00
std : : vector < uint64_t > fees ;
for ( uint32_t priority = 1 ; priority < = 4 ; + + priority )
{
uint64_t mult = m_wallet - > get_fee_multiplier ( priority ) ;
2018-07-18 21:24:53 +00:00
fees . push_back ( base_fee * typical_size * mult ) ;
2017-08-27 20:04:56 +00:00
}
std : : vector < std : : pair < uint64_t , uint64_t > > blocks ;
try
{
2018-07-18 21:24:53 +00:00
uint64_t base_size = typical_size * size_granularity ;
blocks = m_wallet - > estimate_backlog ( base_size , base_size + size_granularity - 1 , fees ) ;
2017-08-27 20:04:56 +00:00
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " Error: failed to estimate backlog array size: " ) < < e . what ( ) ;
return true ;
}
if ( blocks . size ( ) ! = 4 )
{
fail_msg_writer ( ) < < tr ( " Error: bad estimated backlog array size " ) ;
return true ;
}
for ( uint32_t priority = 1 ; priority < = 4 ; + + priority )
{
uint64_t nblocks_low = blocks [ priority - 1 ] . first ;
uint64_t nblocks_high = blocks [ priority - 1 ] . second ;
if ( nblocks_low > 0 )
{
std : : string msg ;
if ( priority = = m_wallet - > get_default_priority ( ) | | ( m_wallet - > get_default_priority ( ) = = 0 & & priority = = 2 ) )
msg = tr ( " (current) " ) ;
uint64_t minutes_low = nblocks_low * DIFFICULTY_TARGET_V2 / 60 , minutes_high = nblocks_high * DIFFICULTY_TARGET_V2 / 60 ;
if ( nblocks_high = = nblocks_low )
message_writer ( ) < < ( boost : : format ( tr ( " %u block (%u minutes) backlog at priority %u%s " ) ) % nblocks_low % minutes_low % priority % msg ) . str ( ) ;
else
message_writer ( ) < < ( boost : : format ( tr ( " %u to %u block (%u to %u minutes) backlog at priority %u " ) ) % nblocks_low % nblocks_high % minutes_low % minutes_high % priority ) . str ( ) ;
}
else
message_writer ( ) < < tr ( " No backlog at priority " ) < < priority ;
}
return true ;
}
2017-05-28 11:18:51 +00:00
bool simple_wallet : : prepare_multisig ( const std : : vector < std : : string > & args )
{
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2017-05-28 11:18:51 +00:00
if ( m_wallet - > multisig ( ) )
{
fail_msg_writer ( ) < < tr ( " This wallet is already multisig " ) ;
return true ;
}
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( m_wallet - > watch_only ( ) )
{
fail_msg_writer ( ) < < tr ( " wallet is watch-only and cannot be made multisig " ) ;
return true ;
}
2017-05-28 11:18:51 +00:00
if ( m_wallet - > get_num_transfer_details ( ) )
{
fail_msg_writer ( ) < < tr ( " This wallet has been used before, please use a new wallet to create a multisig wallet " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2017-05-28 11:18:51 +00:00
std : : string multisig_info = m_wallet - > get_multisig_info ( ) ;
success_msg_writer ( ) < < multisig_info ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
success_msg_writer ( ) < < tr ( " Send this multisig info to all other participants, then use make_multisig <threshold> <info1> [<info2>...] with others' multisig info " ) ;
success_msg_writer ( ) < < tr ( " This includes the PRIVATE view key, so needs to be disclosed only to that multisig wallet's participants " ) ;
2017-05-28 11:18:51 +00:00
return true ;
}
bool simple_wallet : : make_multisig ( const std : : vector < std : : string > & args )
{
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2017-05-28 11:18:51 +00:00
if ( m_wallet - > multisig ( ) )
{
fail_msg_writer ( ) < < tr ( " This wallet is already multisig " ) ;
return true ;
}
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( m_wallet - > watch_only ( ) )
{
fail_msg_writer ( ) < < tr ( " wallet is watch-only and cannot be made multisig " ) ;
return true ;
}
2017-05-28 11:18:51 +00:00
if ( m_wallet - > get_num_transfer_details ( ) )
{
fail_msg_writer ( ) < < tr ( " This wallet has been used before, please use a new wallet to create a multisig wallet " ) ;
return true ;
}
if ( args . size ( ) < 2 )
{
fail_msg_writer ( ) < < tr ( " usage: make_multisig <threshold> <multisiginfo1> [<multisiginfo2>...] " ) ;
return true ;
}
// parse threshold
uint32_t threshold ;
if ( ! string_tools : : get_xtype_from_string ( threshold , args [ 0 ] ) )
{
fail_msg_writer ( ) < < tr ( " Invalid threshold " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
const auto orig_pwd_container = get_and_verify_password ( ) ;
if ( orig_pwd_container = = boost : : none )
{
fail_msg_writer ( ) < < tr ( " Your original password was incorrect. " ) ;
return true ;
}
2017-05-28 11:18:51 +00:00
LOCK_IDLE_SCOPE ( ) ;
try
{
2017-11-18 11:24:38 +00:00
auto local_args = args ;
local_args . erase ( local_args . begin ( ) ) ;
std : : string multisig_extra_info = m_wallet - > make_multisig ( orig_pwd_container - > password ( ) , local_args , threshold ) ;
2017-08-13 14:29:31 +00:00
if ( ! multisig_extra_info . empty ( ) )
{
success_msg_writer ( ) < < tr ( " Another step is needed " ) ;
success_msg_writer ( ) < < multisig_extra_info ;
2018-07-12 09:55:52 +00:00
success_msg_writer ( ) < < tr ( " Send this multisig info to all other participants, then use exchange_multisig_keys <info1> [<info2>...] with others' multisig info " ) ;
2017-08-13 14:29:31 +00:00
return true ;
}
2017-05-28 11:18:51 +00:00
}
catch ( const std : : exception & e )
{
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
fail_msg_writer ( ) < < tr ( " Error creating multisig: " ) < < e . what ( ) ;
2017-05-28 11:18:51 +00:00
return true ;
}
2017-11-18 11:24:38 +00:00
uint32_t total ;
2018-02-02 16:41:16 +00:00
if ( ! m_wallet - > multisig ( NULL , & threshold , & total ) )
{
fail_msg_writer ( ) < < tr ( " Error creating multisig: new wallet is not multisig " ) ;
return true ;
}
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
success_msg_writer ( ) < < std : : to_string ( threshold ) < < " / " < < total < < tr ( " multisig address: " )
2018-02-16 11:04:04 +00:00
< < m_wallet - > get_account ( ) . get_public_address_str ( m_wallet - > nettype ( ) ) ;
2017-05-28 11:18:51 +00:00
return true ;
}
2017-08-13 14:29:31 +00:00
bool simple_wallet : : finalize_multisig ( const std : : vector < std : : string > & args )
{
2017-10-01 13:06:54 +00:00
bool ready ;
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container = = boost : : none )
{
fail_msg_writer ( ) < < tr ( " Your original password was incorrect. " ) ;
return true ;
}
2017-10-01 13:06:54 +00:00
if ( ! m_wallet - > multisig ( & ready ) )
2017-08-13 14:29:31 +00:00
{
fail_msg_writer ( ) < < tr ( " This wallet is not multisig " ) ;
return true ;
}
2017-10-01 13:06:54 +00:00
if ( ready )
{
fail_msg_writer ( ) < < tr ( " This wallet is already finalized " ) ;
return true ;
}
2017-08-13 14:29:31 +00:00
2018-07-08 20:12:33 +00:00
LOCK_IDLE_SCOPE ( ) ;
2017-08-13 14:29:31 +00:00
if ( args . size ( ) < 2 )
{
fail_msg_writer ( ) < < tr ( " usage: finalize_multisig <multisiginfo1> [<multisiginfo2>...] " ) ;
return true ;
}
try
{
2018-07-08 20:12:33 +00:00
if ( ! m_wallet - > finalize_multisig ( pwd_container - > password ( ) , args ) )
2017-08-13 14:29:31 +00:00
{
fail_msg_writer ( ) < < tr ( " Failed to finalize multisig " ) ;
return true ;
}
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " Failed to finalize multisig: " ) < < e . what ( ) ;
return true ;
}
return true ;
}
2018-07-12 09:55:52 +00:00
bool simple_wallet : : exchange_multisig_keys ( const std : : vector < std : : string > & args ) {
bool ready ;
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
if ( ! m_wallet - > multisig ( & ready ) )
{
fail_msg_writer ( ) < < tr ( " This wallet is not multisig " ) ;
return true ;
}
if ( ready )
{
fail_msg_writer ( ) < < tr ( " This wallet is already finalized " ) ;
return true ;
}
const auto orig_pwd_container = get_and_verify_password ( ) ;
if ( orig_pwd_container = = boost : : none )
{
fail_msg_writer ( ) < < tr ( " Your original password was incorrect. " ) ;
return true ;
}
if ( args . size ( ) < 2 )
{
fail_msg_writer ( ) < < tr ( " usage: exchange_multisig_keys <multisiginfo1> [<multisiginfo2>...] " ) ;
return true ;
}
try
{
std : : string multisig_extra_info = m_wallet - > exchange_multisig_keys ( orig_pwd_container - > password ( ) , args ) ;
if ( ! multisig_extra_info . empty ( ) )
{
message_writer ( ) < < tr ( " Another step is needed " ) ;
message_writer ( ) < < multisig_extra_info ;
message_writer ( ) < < tr ( " Send this multisig info to all other participants, then use exchange_multisig_keys <info1> [<info2>...] with others' multisig info " ) ;
return true ;
} else {
uint32_t threshold , total ;
m_wallet - > multisig ( NULL , & threshold , & total ) ;
success_msg_writer ( ) < < tr ( " Multisig wallet has been successfully created. Current wallet type: " ) < < threshold < < " / " < < total ;
}
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " Failed to perform multisig keys exchange: " ) < < e . what ( ) ;
return true ;
}
return true ;
}
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
bool simple_wallet : : export_multisig ( const std : : vector < std : : string > & args )
{
2017-10-01 13:06:54 +00:00
bool ready ;
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2017-10-01 13:06:54 +00:00
if ( ! m_wallet - > multisig ( & ready ) )
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
{
fail_msg_writer ( ) < < tr ( " This wallet is not multisig " ) ;
return true ;
}
2017-10-01 13:06:54 +00:00
if ( ! ready )
{
fail_msg_writer ( ) < < tr ( " This multisig wallet is not yet finalized " ) ;
return true ;
}
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( args . size ( ) ! = 1 )
{
fail_msg_writer ( ) < < tr ( " usage: export_multisig_info <filename> " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
const std : : string filename = args [ 0 ] ;
2018-01-14 23:36:13 +00:00
if ( m_wallet - > confirm_export_overwrite ( ) & & ! check_file_overwrite ( filename ) )
return true ;
2018-11-04 01:48:49 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
try
{
2017-11-13 16:24:42 +00:00
cryptonote : : blobdata ciphertext = m_wallet - > export_multisig ( ) ;
bool r = epee : : file_io_utils : : save_string_to_file ( filename , ciphertext ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " failed to save file " ) < < filename ;
return true ;
}
}
catch ( const std : : exception & e )
{
LOG_ERROR ( " Error exporting multisig info: " < < e . what ( ) ) ;
fail_msg_writer ( ) < < tr ( " Error exporting multisig info: " ) < < e . what ( ) ;
return true ;
}
success_msg_writer ( ) < < tr ( " Multisig info exported to " ) < < filename ;
return true ;
}
bool simple_wallet : : import_multisig ( const std : : vector < std : : string > & args )
{
2017-10-01 13:06:54 +00:00
bool ready ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
uint32_t threshold , total ;
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2017-10-01 13:06:54 +00:00
if ( ! m_wallet - > multisig ( & ready , & threshold , & total ) )
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
{
fail_msg_writer ( ) < < tr ( " This wallet is not multisig " ) ;
return true ;
}
2017-10-01 13:06:54 +00:00
if ( ! ready )
{
fail_msg_writer ( ) < < tr ( " This multisig wallet is not yet finalized " ) ;
return true ;
}
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( args . size ( ) < threshold - 1 )
{
fail_msg_writer ( ) < < tr ( " usage: import_multisig_info <filename1> [<filename2>...] - one for each other participant " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
2017-11-13 16:24:42 +00:00
std : : vector < cryptonote : : blobdata > info ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
for ( size_t n = 0 ; n < args . size ( ) ; + + n )
{
const std : : string filename = args [ n ] ;
std : : string data ;
bool r = epee : : file_io_utils : : load_file_to_string ( filename , data ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " failed to read file " ) < < filename ;
return true ;
}
2017-11-13 16:24:42 +00:00
info . push_back ( std : : move ( data ) ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
2018-11-04 01:48:49 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
// all read and parsed, actually import
try
{
2018-07-08 20:12:33 +00:00
m_in_manual_refresh . store ( true , std : : memory_order_relaxed ) ;
epee : : misc_utils : : auto_scope_leave_caller scope_exit_handler = epee : : misc_utils : : create_scope_leave_handler ( [ & ] ( ) { m_in_manual_refresh . store ( false , std : : memory_order_relaxed ) ; } ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
size_t n_outputs = m_wallet - > import_multisig ( info ) ;
// Clear line "Height xxx of xxx"
std : : cout < < " \r \r " ;
success_msg_writer ( ) < < tr ( " Multisig info imported " ) ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " Failed to import multisig info: " ) < < e . what ( ) ;
return true ;
}
2018-08-10 12:15:40 +00:00
if ( m_wallet - > is_trusted_daemon ( ) )
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
{
try
{
m_wallet - > rescan_spent ( ) ;
}
catch ( const std : : exception & e )
{
message_writer ( ) < < tr ( " Failed to update spent status after importing multisig info: " ) < < e . what ( ) ;
}
}
else
{
message_writer ( ) < < tr ( " Untrusted daemon, spent status may be incorrect. Use a trusted daemon and run \" rescan_spent \" " ) ;
}
return true ;
}
bool simple_wallet : : accept_loaded_tx ( const tools : : wallet2 : : multisig_tx_set & txs )
{
std : : string extra_message ;
return accept_loaded_tx ( [ & txs ] ( ) { return txs . m_ptx . size ( ) ; } , [ & txs ] ( size_t n ) - > const tools : : wallet2 : : tx_construction_data & { return txs . m_ptx [ n ] . construction_data ; } , extra_message ) ;
}
bool simple_wallet : : sign_multisig ( const std : : vector < std : : string > & args )
{
2017-10-01 13:06:54 +00:00
bool ready ;
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2017-10-01 13:06:54 +00:00
if ( ! m_wallet - > multisig ( & ready ) )
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
{
fail_msg_writer ( ) < < tr ( " This is not a multisig wallet " ) ;
return true ;
}
2017-10-01 13:06:54 +00:00
if ( ! ready )
{
fail_msg_writer ( ) < < tr ( " This multisig wallet is not yet finalized " ) ;
return true ;
}
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( args . size ( ) ! = 1 )
{
fail_msg_writer ( ) < < tr ( " usage: sign_multisig <filename> " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
std : : string filename = args [ 0 ] ;
std : : vector < crypto : : hash > txids ;
uint32_t signers = 0 ;
try
{
bool r = m_wallet - > sign_multisig_tx_from_file ( filename , txids , [ & ] ( const tools : : wallet2 : : multisig_tx_set & tx ) { signers = tx . m_signers . size ( ) ; return accept_loaded_tx ( tx ) ; } ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Failed to sign multisig transaction " ) ;
return true ;
}
}
catch ( const tools : : error : : multisig_export_needed & e )
{
fail_msg_writer ( ) < < tr ( " Multisig error: " ) < < e . what ( ) ;
return true ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " Failed to sign multisig transaction: " ) < < e . what ( ) ;
return true ;
}
if ( txids . empty ( ) )
{
uint32_t threshold ;
2017-10-01 13:06:54 +00:00
m_wallet - > multisig ( NULL , & threshold ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
uint32_t signers_needed = threshold - signers - 1 ;
success_msg_writer ( true ) < < tr ( " Transaction successfully signed to file " ) < < filename < < " , "
< < signers_needed < < " more signer(s) needed " ;
return true ;
}
else
{
std : : string txids_as_text ;
for ( const auto & txid : txids )
{
if ( ! txids_as_text . empty ( ) )
txids_as_text + = ( " , " ) ;
txids_as_text + = epee : : string_tools : : pod_to_hex ( txid ) ;
}
success_msg_writer ( true ) < < tr ( " Transaction successfully signed to file " ) < < filename < < " , txid " < < txids_as_text ;
success_msg_writer ( true ) < < tr ( " It may be relayed to the network with submit_multisig " ) ;
}
return true ;
}
bool simple_wallet : : submit_multisig ( const std : : vector < std : : string > & args )
{
2017-10-01 13:06:54 +00:00
bool ready ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
uint32_t threshold ;
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2017-10-01 13:06:54 +00:00
if ( ! m_wallet - > multisig ( & ready , & threshold ) )
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
{
fail_msg_writer ( ) < < tr ( " This is not a multisig wallet " ) ;
return true ;
}
2017-10-01 13:06:54 +00:00
if ( ! ready )
{
fail_msg_writer ( ) < < tr ( " This multisig wallet is not yet finalized " ) ;
return true ;
}
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( args . size ( ) ! = 1 )
{
fail_msg_writer ( ) < < tr ( " usage: submit_multisig <filename> " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( ! try_connect_to_daemon ( ) )
return true ;
2018-11-04 01:48:49 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
std : : string filename = args [ 0 ] ;
try
{
tools : : wallet2 : : multisig_tx_set txs ;
bool r = m_wallet - > load_multisig_tx_from_file ( filename , txs , [ & ] ( const tools : : wallet2 : : multisig_tx_set & tx ) { return accept_loaded_tx ( tx ) ; } ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Failed to load multisig transaction from file " ) ;
return true ;
}
if ( txs . m_signers . size ( ) < threshold )
{
fail_msg_writer ( ) < < ( boost : : format ( tr ( " Multisig transaction signed by only %u signers, needs %u more signatures " ) )
% txs . m_signers . size ( ) % ( threshold - txs . m_signers . size ( ) ) ) . str ( ) ;
return true ;
}
// actually commit the transactions
for ( auto & ptx : txs . m_ptx )
{
m_wallet - > commit_tx ( ptx ) ;
success_msg_writer ( true ) < < tr ( " Transaction successfully submitted, transaction " ) < < get_transaction_hash ( ptx . tx ) < < ENDL
< < tr ( " You can check its status by using the `show_transfers` command. " ) ;
}
}
catch ( const std : : exception & e )
{
2018-08-10 12:15:40 +00:00
handle_transfer_exception ( std : : current_exception ( ) , m_wallet - > is_trusted_daemon ( ) ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
}
catch ( . . . )
{
LOG_ERROR ( " unknown error " ) ;
fail_msg_writer ( ) < < tr ( " unknown error " ) ;
}
return true ;
}
2017-10-07 20:20:28 +00:00
bool simple_wallet : : export_raw_multisig ( const std : : vector < std : : string > & args )
{
bool ready ;
uint32_t threshold ;
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2017-10-07 20:20:28 +00:00
if ( ! m_wallet - > multisig ( & ready , & threshold ) )
{
fail_msg_writer ( ) < < tr ( " This is not a multisig wallet " ) ;
return true ;
}
if ( ! ready )
{
fail_msg_writer ( ) < < tr ( " This multisig wallet is not yet finalized " ) ;
return true ;
}
if ( args . size ( ) ! = 1 )
{
fail_msg_writer ( ) < < tr ( " usage: export_raw_multisig <filename> " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
2017-10-07 20:20:28 +00:00
std : : string filename = args [ 0 ] ;
2018-01-14 23:36:13 +00:00
if ( m_wallet - > confirm_export_overwrite ( ) & & ! check_file_overwrite ( filename ) )
return true ;
2018-11-04 01:48:49 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2017-10-07 20:20:28 +00:00
try
{
tools : : wallet2 : : multisig_tx_set txs ;
bool r = m_wallet - > load_multisig_tx_from_file ( filename , txs , [ & ] ( const tools : : wallet2 : : multisig_tx_set & tx ) { return accept_loaded_tx ( tx ) ; } ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Failed to load multisig transaction from file " ) ;
return true ;
}
if ( txs . m_signers . size ( ) < threshold )
{
fail_msg_writer ( ) < < ( boost : : format ( tr ( " Multisig transaction signed by only %u signers, needs %u more signatures " ) )
% txs . m_signers . size ( ) % ( threshold - txs . m_signers . size ( ) ) ) . str ( ) ;
return true ;
}
// save the transactions
std : : string filenames ;
for ( auto & ptx : txs . m_ptx )
{
const crypto : : hash txid = cryptonote : : get_transaction_hash ( ptx . tx ) ;
const std : : string filename = std : : string ( " raw_multisig_monero_tx_ " ) + epee : : string_tools : : pod_to_hex ( txid ) ;
if ( ! filenames . empty ( ) )
filenames + = " , " ;
filenames + = filename ;
if ( ! epee : : file_io_utils : : save_string_to_file ( filename , cryptonote : : tx_to_blob ( ptx . tx ) ) )
{
fail_msg_writer ( ) < < tr ( " Failed to export multisig transaction to file " ) < < filename ;
return true ;
}
}
success_msg_writer ( ) < < tr ( " Saved exported multisig transaction file(s): " ) < < filenames ;
}
catch ( const std : : exception & e )
{
LOG_ERROR ( " unexpected error: " < < e . what ( ) ) ;
fail_msg_writer ( ) < < tr ( " unexpected error: " ) < < e . what ( ) ;
}
catch ( . . . )
{
LOG_ERROR ( " Unknown error " ) ;
fail_msg_writer ( ) < < tr ( " unknown error " ) ;
}
return true ;
}
2018-02-18 10:47:25 +00:00
bool simple_wallet : : print_ring ( const std : : vector < std : : string > & args )
{
crypto : : key_image key_image ;
2018-03-14 19:13:55 +00:00
crypto : : hash txid ;
2018-02-18 10:47:25 +00:00
if ( args . size ( ) ! = 1 )
{
2018-03-14 19:13:55 +00:00
fail_msg_writer ( ) < < tr ( " usage: print_ring <key_image|txid> " ) ;
2018-02-18 10:47:25 +00:00
return true ;
}
if ( ! epee : : string_tools : : hex_to_pod ( args [ 0 ] , key_image ) )
{
fail_msg_writer ( ) < < tr ( " Invalid key image " ) ;
return true ;
}
2018-03-14 19:13:55 +00:00
// this one will always work, they're all 32 byte hex
if ( ! epee : : string_tools : : hex_to_pod ( args [ 0 ] , txid ) )
{
fail_msg_writer ( ) < < tr ( " Invalid txid " ) ;
return true ;
}
2018-02-18 10:47:25 +00:00
std : : vector < uint64_t > ring ;
2018-03-14 19:13:55 +00:00
std : : vector < std : : pair < crypto : : key_image , std : : vector < uint64_t > > > rings ;
2018-02-18 10:47:25 +00:00
try
{
2018-02-27 08:30:59 +00:00
if ( m_wallet - > get_ring ( key_image , ring ) )
2018-03-14 19:13:55 +00:00
rings . push_back ( { key_image , ring } ) ;
else if ( ! m_wallet - > get_rings ( txid , rings ) )
2018-02-18 10:47:25 +00:00
{
2018-03-14 19:13:55 +00:00
fail_msg_writer ( ) < < tr ( " Key image either not spent, or spent with mixin 0 " ) ;
return true ;
2018-02-18 10:47:25 +00:00
}
2018-03-14 19:13:55 +00:00
for ( const auto & ring : rings )
2018-02-18 10:47:25 +00:00
{
2018-03-14 19:13:55 +00:00
std : : stringstream str ;
for ( const auto & x : ring . second )
str < < x < < " " ;
// do NOT translate this "absolute" below, the lin can be used as input to set_ring
success_msg_writer ( ) < < epee : : string_tools : : pod_to_hex ( ring . first ) < < " absolute " < < str . str ( ) ;
2018-02-18 10:47:25 +00:00
}
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " Failed to get key image ring: " ) < < e . what ( ) ;
}
return true ;
}
2018-02-28 18:26:06 +00:00
bool simple_wallet : : set_ring ( const std : : vector < std : : string > & args )
{
crypto : : key_image key_image ;
2018-04-01 08:18:27 +00:00
// try filename first
if ( args . size ( ) = = 1 )
{
if ( ! epee : : file_io_utils : : is_file_exist ( args [ 0 ] ) )
{
fail_msg_writer ( ) < < tr ( " File doesn't exist " ) ;
return true ;
}
char str [ 4096 ] ;
std : : unique_ptr < FILE , tools : : close_file > f ( fopen ( args [ 0 ] . c_str ( ) , " r " ) ) ;
if ( f )
{
while ( ! feof ( f . get ( ) ) )
{
if ( ! fgets ( str , sizeof ( str ) , f . get ( ) ) )
break ;
const size_t len = strlen ( str ) ;
if ( len > 0 & & str [ len - 1 ] = = ' \n ' )
str [ len - 1 ] = 0 ;
if ( ! str [ 0 ] )
continue ;
char key_image_str [ 65 ] , type_str [ 9 ] ;
int read_after_key_image = 0 , read = 0 ;
int fields = sscanf ( str , " %64[abcdefABCDEF0123456789] %n%8s %n " , key_image_str , & read_after_key_image , type_str , & read ) ;
if ( fields ! = 2 )
{
fail_msg_writer ( ) < < tr ( " Invalid ring specification: " ) < < str ;
continue ;
}
key_image_str [ 64 ] = 0 ;
type_str [ 8 ] = 0 ;
crypto : : key_image key_image ;
if ( read_after_key_image = = 0 | | ! epee : : string_tools : : hex_to_pod ( key_image_str , key_image ) )
{
fail_msg_writer ( ) < < tr ( " Invalid key image: " ) < < str ;
continue ;
}
if ( read = = read_after_key_image + 8 | | ( strcmp ( type_str , " absolute " ) & & strcmp ( type_str , " relative " ) ) )
{
fail_msg_writer ( ) < < tr ( " Invalid ring type, expected relative or abosolute: " ) < < str ;
continue ;
}
bool relative = ! strcmp ( type_str , " relative " ) ;
if ( read < 0 | | ( size_t ) read > strlen ( str ) )
{
fail_msg_writer ( ) < < tr ( " Error reading line: " ) < < str ;
continue ;
}
bool valid = true ;
std : : vector < uint64_t > ring ;
const char * ptr = str + read ;
while ( * ptr )
{
unsigned long offset ;
int elements = sscanf ( ptr , " %lu %n " , & offset , & read ) ;
if ( elements = = 0 | | read < = 0 | | ( size_t ) read > strlen ( str ) )
{
fail_msg_writer ( ) < < tr ( " Error reading line: " ) < < str ;
valid = false ;
break ;
}
ring . push_back ( offset ) ;
ptr + = read ;
}
if ( ! valid )
continue ;
if ( ring . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " Invalid ring: " ) < < str ;
continue ;
}
if ( relative )
{
for ( size_t n = 1 ; n < ring . size ( ) ; + + n )
{
if ( ring [ n ] < = 0 )
{
fail_msg_writer ( ) < < tr ( " Invalid relative ring: " ) < < str ;
valid = false ;
break ;
}
}
}
else
{
for ( size_t n = 1 ; n < ring . size ( ) ; + + n )
{
if ( ring [ n ] < = ring [ n - 1 ] )
{
fail_msg_writer ( ) < < tr ( " Invalid absolute ring: " ) < < str ;
valid = false ;
break ;
}
}
}
if ( ! valid )
continue ;
if ( ! m_wallet - > set_ring ( key_image , ring , relative ) )
fail_msg_writer ( ) < < tr ( " Failed to set ring for key image: " ) < < key_image < < " . " < < tr ( " Continuing. " ) ;
}
f . reset ( ) ;
}
return true ;
}
2018-02-28 18:26:06 +00:00
if ( args . size ( ) < 3 )
{
2018-04-01 08:18:27 +00:00
fail_msg_writer ( ) < < tr ( " usage: set_ring <filename> | ( <key_image> absolute|relative <index> [<index>...] ) " ) ;
2018-02-28 18:26:06 +00:00
return true ;
}
if ( ! epee : : string_tools : : hex_to_pod ( args [ 0 ] , key_image ) )
{
fail_msg_writer ( ) < < tr ( " Invalid key image " ) ;
return true ;
}
bool relative ;
if ( args [ 1 ] = = " absolute " )
{
relative = false ;
}
else if ( args [ 1 ] = = " relative " )
{
relative = true ;
}
else
{
fail_msg_writer ( ) < < tr ( " Missing absolute or relative keyword " ) ;
return true ;
}
std : : vector < uint64_t > ring ;
for ( size_t n = 2 ; n < args . size ( ) ; + + n )
{
ring . resize ( ring . size ( ) + 1 ) ;
if ( ! string_tools : : get_xtype_from_string ( ring . back ( ) , args [ n ] ) )
{
fail_msg_writer ( ) < < tr ( " invalid index: must be a strictly positive unsigned integer " ) ;
return true ;
}
if ( relative )
{
if ( ring . size ( ) > 1 & & ! ring . back ( ) )
{
fail_msg_writer ( ) < < tr ( " invalid index: must be a strictly positive unsigned integer " ) ;
return true ;
}
uint64_t sum = 0 ;
for ( uint64_t out : ring )
{
if ( out > std : : numeric_limits < uint64_t > : : max ( ) - sum )
{
fail_msg_writer ( ) < < tr ( " invalid index: indices wrap " ) ;
return true ;
}
sum + = out ;
}
}
else
{
if ( ring . size ( ) > 1 & & ring [ ring . size ( ) - 2 ] > = ring [ ring . size ( ) - 1 ] )
{
fail_msg_writer ( ) < < tr ( " invalid index: indices should be in strictly ascending order " ) ;
return true ;
}
}
}
if ( ! m_wallet - > set_ring ( key_image , ring , relative ) )
{
fail_msg_writer ( ) < < tr ( " failed to set ring " ) ;
return true ;
}
return true ;
}
2018-02-25 19:20:07 +00:00
bool simple_wallet : : blackball ( const std : : vector < std : : string > & args )
{
2018-08-29 16:57:12 +00:00
uint64_t amount = std : : numeric_limits < uint64_t > : : max ( ) , offset , num_offsets ;
2018-02-25 19:20:07 +00:00
if ( args . size ( ) = = 0 )
{
2018-10-18 18:05:51 +00:00
fail_msg_writer ( ) < < tr ( " usage: mark_output_spent <amount>/<offset> | <filename> [add] " ) ;
2018-02-25 19:20:07 +00:00
return true ;
}
try
{
2018-08-29 16:57:12 +00:00
if ( sscanf ( args [ 0 ] . c_str ( ) , " % " PRIu64 " /% " PRIu64 , & amount , & offset ) = = 2 )
2018-02-25 19:20:07 +00:00
{
2018-08-29 16:57:12 +00:00
m_wallet - > blackball_output ( std : : make_pair ( amount , offset ) ) ;
2018-02-25 19:20:07 +00:00
}
else if ( epee : : file_io_utils : : is_file_exist ( args [ 0 ] ) )
{
2018-08-29 16:57:12 +00:00
std : : vector < std : : pair < uint64_t , uint64_t > > outputs ;
char str [ 256 ] ;
2018-02-25 19:20:07 +00:00
std : : unique_ptr < FILE , tools : : close_file > f ( fopen ( args [ 0 ] . c_str ( ) , " r " ) ) ;
if ( f )
{
while ( ! feof ( f . get ( ) ) )
{
if ( ! fgets ( str , sizeof ( str ) , f . get ( ) ) )
break ;
const size_t len = strlen ( str ) ;
if ( len > 0 & & str [ len - 1 ] = = ' \n ' )
str [ len - 1 ] = 0 ;
if ( ! str [ 0 ] )
continue ;
2018-08-29 16:57:12 +00:00
if ( sscanf ( str , " @% " PRIu64 , & amount ) = = 1 )
2018-02-25 19:20:07 +00:00
{
2018-08-29 16:57:12 +00:00
continue ;
}
if ( amount = = std : : numeric_limits < uint64_t > : : max ( ) )
{
fail_msg_writer ( ) < < tr ( " First line is not an amount " ) ;
return true ;
}
if ( sscanf ( str , " % " PRIu64 " *% " PRIu64 , & offset , & num_offsets ) = = 2 & & num_offsets < = std : : numeric_limits < uint64_t > : : max ( ) - offset )
{
while ( num_offsets - - )
outputs . push_back ( std : : make_pair ( amount , offset + + ) ) ;
}
else if ( sscanf ( str , " % " PRIu64 , & offset ) = = 1 )
{
outputs . push_back ( std : : make_pair ( amount , offset ) ) ;
}
else
{
fail_msg_writer ( ) < < tr ( " Invalid output: " ) < < str ;
2018-02-25 19:20:07 +00:00
return true ;
}
}
f . reset ( ) ;
bool add = false ;
if ( args . size ( ) > 1 )
{
if ( args [ 1 ] ! = " add " )
{
fail_msg_writer ( ) < < tr ( " Bad argument: " ) + args [ 1 ] + " : " + tr ( " should be \" add \" " ) ;
return true ;
}
add = true ;
}
m_wallet - > set_blackballed_outputs ( outputs , add ) ;
}
else
{
fail_msg_writer ( ) < < tr ( " Failed to open file " ) ;
return true ;
}
}
else
{
2018-08-29 16:57:12 +00:00
fail_msg_writer ( ) < < tr ( " Invalid output key, and file doesn't exist " ) ;
2018-02-25 19:20:07 +00:00
return true ;
}
}
catch ( const std : : exception & e )
{
2018-10-18 18:05:51 +00:00
fail_msg_writer ( ) < < tr ( " Failed to mark output spent: " ) < < e . what ( ) ;
2018-02-25 19:20:07 +00:00
}
return true ;
}
bool simple_wallet : : unblackball ( const std : : vector < std : : string > & args )
{
2018-08-29 16:57:12 +00:00
std : : pair < uint64_t , uint64_t > output ;
2018-02-25 19:20:07 +00:00
if ( args . size ( ) ! = 1 )
{
2018-10-18 18:05:51 +00:00
fail_msg_writer ( ) < < tr ( " usage: mark_output_unspent <amount>/<offset> " ) ;
2018-02-25 19:20:07 +00:00
return true ;
}
2018-08-29 16:57:12 +00:00
if ( sscanf ( args [ 0 ] . c_str ( ) , " % " PRIu64 " /% " PRIu64 , & output . first , & output . second ) ! = 2 )
2018-02-25 19:20:07 +00:00
{
2018-08-29 16:57:12 +00:00
fail_msg_writer ( ) < < tr ( " Invalid output " ) ;
2018-02-25 19:20:07 +00:00
return true ;
}
try
{
m_wallet - > unblackball_output ( output ) ;
}
catch ( const std : : exception & e )
{
2018-10-18 18:05:51 +00:00
fail_msg_writer ( ) < < tr ( " Failed to mark output unspent: " ) < < e . what ( ) ;
2018-02-25 19:20:07 +00:00
}
return true ;
}
bool simple_wallet : : blackballed ( const std : : vector < std : : string > & args )
{
2018-08-29 16:57:12 +00:00
std : : pair < uint64_t , uint64_t > output ;
2018-02-25 19:20:07 +00:00
if ( args . size ( ) ! = 1 )
{
2018-10-18 18:05:51 +00:00
fail_msg_writer ( ) < < tr ( " usage: is_output_spent <amount>/<offset> " ) ;
2018-02-25 19:20:07 +00:00
return true ;
}
2018-08-29 16:57:12 +00:00
if ( sscanf ( args [ 0 ] . c_str ( ) , " % " PRIu64 " /% " PRIu64 , & output . first , & output . second ) ! = 2 )
2018-02-25 19:20:07 +00:00
{
2018-08-29 16:57:12 +00:00
fail_msg_writer ( ) < < tr ( " Invalid output " ) ;
2018-02-25 19:20:07 +00:00
return true ;
}
try
{
if ( m_wallet - > is_output_blackballed ( output ) )
2018-10-18 18:05:51 +00:00
message_writer ( ) < < tr ( " Spent: " ) < < output . first < < " / " < < output . second ;
2018-02-25 19:20:07 +00:00
else
2018-10-18 18:05:51 +00:00
message_writer ( ) < < tr ( " Not spent: " ) < < output . first < < " / " < < output . second ;
2018-02-25 19:20:07 +00:00
}
catch ( const std : : exception & e )
{
2018-10-18 18:05:51 +00:00
fail_msg_writer ( ) < < tr ( " Failed to check whether output is spent: " ) < < e . what ( ) ;
2018-02-25 19:20:07 +00:00
}
return true ;
}
2018-02-18 10:47:25 +00:00
bool simple_wallet : : save_known_rings ( const std : : vector < std : : string > & args )
{
try
{
LOCK_IDLE_SCOPE ( ) ;
2018-02-27 08:30:59 +00:00
m_wallet - > find_and_save_rings ( ) ;
2018-02-18 10:47:25 +00:00
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " Failed to save known rings: " ) < < e . what ( ) ;
}
return true ;
}
2018-04-13 17:45:10 +00:00
bool simple_wallet : : version ( const std : : vector < std : : string > & args )
{
message_writer ( ) < < " Monero ' " < < MONERO_RELEASE_NAME < < " ' (v " < < MONERO_VERSION_FULL < < " ) " ;
return true ;
}
2015-07-18 21:03:35 +00:00
bool simple_wallet : : set_always_confirm_transfers ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
2016-12-17 23:07:15 +00:00
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
2015-07-18 21:03:35 +00:00
{
2017-10-19 12:57:49 +00:00
parse_bool_and_use ( args [ 1 ] , [ & ] ( bool r ) {
m_wallet - > always_confirm_transfers ( r ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
} ) ;
2015-07-18 21:03:35 +00:00
}
return true ;
}
2016-12-23 12:04:54 +00:00
bool simple_wallet : : set_print_ring_members ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
2017-10-19 12:57:49 +00:00
parse_bool_and_use ( args [ 1 ] , [ & ] ( bool r ) {
m_wallet - > print_ring_members ( r ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
} ) ;
2016-12-23 12:04:54 +00:00
}
return true ;
}
2015-11-22 12:26:27 +00:00
bool simple_wallet : : set_store_tx_info ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
2015-08-24 20:50:45 +00:00
{
if ( m_wallet - > watch_only ( ) )
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " wallet is watch-only and cannot transfer " ) ;
2015-08-24 20:50:45 +00:00
return true ;
}
2016-08-01 00:48:53 +00:00
2016-12-17 23:07:15 +00:00
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
2015-08-24 20:50:45 +00:00
{
2017-10-19 12:57:49 +00:00
parse_bool_and_use ( args [ 1 ] , [ & ] ( bool r ) {
m_wallet - > store_tx_info ( r ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
} ) ;
2015-08-24 20:50:45 +00:00
}
return true ;
}
2017-07-31 06:50:41 +00:00
bool simple_wallet : : set_default_ring_size ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
2015-10-30 21:16:51 +00:00
{
if ( m_wallet - > watch_only ( ) )
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " wallet is watch-only and cannot transfer " ) ;
2015-10-30 21:16:51 +00:00
return true ;
}
try
{
if ( strchr ( args [ 1 ] . c_str ( ) , ' - ' ) )
{
2017-11-10 10:03:53 +00:00
fail_msg_writer ( ) < < tr ( " ring size must be an integer >= " ) < < MIN_RING_SIZE ;
2015-10-30 21:16:51 +00:00
return true ;
}
2017-07-31 06:50:41 +00:00
uint32_t ring_size = boost : : lexical_cast < uint32_t > ( args [ 1 ] ) ;
2017-11-10 10:03:53 +00:00
if ( ring_size < MIN_RING_SIZE & & ring_size ! = 0 )
2015-10-30 21:16:51 +00:00
{
2017-11-10 10:03:53 +00:00
fail_msg_writer ( ) < < tr ( " ring size must be an integer >= " ) < < MIN_RING_SIZE ;
2015-10-30 21:16:51 +00:00
return true ;
}
2016-08-01 00:48:53 +00:00
2018-03-31 13:20:48 +00:00
if ( ring_size ! = 0 & & ring_size ! = DEFAULT_MIX + 1 )
message_writer ( ) < < tr ( " WARNING: this is a non default ring size, which may harm your privacy. Default is recommended. " ) ;
2018-07-18 21:24:53 +00:00
else if ( ring_size = = DEFAULT_MIX )
message_writer ( ) < < tr ( " WARNING: from v8, ring size will be fixed and this setting will be ignored. " ) ;
2018-03-31 13:20:48 +00:00
2016-12-17 23:07:15 +00:00
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
2015-10-30 21:16:51 +00:00
{
2017-11-15 15:01:59 +00:00
m_wallet - > default_mixin ( ring_size > 0 ? ring_size - 1 : 0 ) ;
2016-12-17 23:07:15 +00:00
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
2015-10-30 21:16:51 +00:00
}
return true ;
}
catch ( const boost : : bad_lexical_cast & )
{
2017-11-10 10:03:53 +00:00
fail_msg_writer ( ) < < tr ( " ring size must be an integer >= " ) < < MIN_RING_SIZE ;
2015-10-30 21:16:51 +00:00
return true ;
}
catch ( . . . )
{
2017-07-31 06:50:41 +00:00
fail_msg_writer ( ) < < tr ( " could not change default ring size " ) ;
2015-10-30 21:16:51 +00:00
return true ;
}
}
2016-09-16 10:50:52 +00:00
bool simple_wallet : : set_default_priority ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
2016-06-22 21:21:30 +00:00
{
2018-08-15 12:15:39 +00:00
uint32_t priority = 0 ;
2016-06-22 21:21:30 +00:00
try
{
if ( strchr ( args [ 1 ] . c_str ( ) , ' - ' ) )
{
2018-08-15 12:15:39 +00:00
fail_msg_writer ( ) < < tr ( " priority must be either 0, 1, 2, 3, or 4, or one of: " ) < < join_priority_strings ( " , " ) ;
2016-06-22 21:21:30 +00:00
return true ;
}
if ( args [ 1 ] = = " 0 " )
{
2016-09-16 10:50:52 +00:00
priority = 0 ;
2016-06-22 21:21:30 +00:00
}
else
{
2018-08-15 12:15:39 +00:00
bool found = false ;
for ( size_t n = 0 ; n < allowed_priority_strings . size ( ) ; + + n )
2016-06-22 21:21:30 +00:00
{
2018-08-15 12:15:39 +00:00
if ( allowed_priority_strings [ n ] = = args [ 1 ] )
{
found = true ;
priority = n ;
}
}
if ( ! found )
{
priority = boost : : lexical_cast < int > ( args [ 1 ] ) ;
if ( priority < 1 | | priority > 4 )
{
fail_msg_writer ( ) < < tr ( " priority must be either 0, 1, 2, 3, or 4, or one of: " ) < < join_priority_strings ( " , " ) ;
return true ;
}
2016-06-22 21:21:30 +00:00
}
}
2016-08-01 00:48:53 +00:00
2016-12-17 23:07:15 +00:00
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
2016-06-22 21:21:30 +00:00
{
2016-12-17 23:07:15 +00:00
m_wallet - > set_default_priority ( priority ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
2016-06-22 21:21:30 +00:00
}
return true ;
}
catch ( const boost : : bad_lexical_cast & )
{
2018-08-15 12:15:39 +00:00
fail_msg_writer ( ) < < tr ( " priority must be either 0, 1, 2, 3, or 4, or one of: " ) < < join_priority_strings ( " , " ) ;
2016-06-22 21:21:30 +00:00
return true ;
}
catch ( . . . )
{
2016-09-16 10:50:52 +00:00
fail_msg_writer ( ) < < tr ( " could not change default priority " ) ;
2016-06-22 21:21:30 +00:00
return true ;
}
}
2015-11-28 12:38:58 +00:00
bool simple_wallet : : set_auto_refresh ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
2016-12-17 23:07:15 +00:00
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
2015-11-28 12:38:58 +00:00
{
2017-10-19 12:57:49 +00:00
parse_bool_and_use ( args [ 1 ] , [ & ] ( bool auto_refresh ) {
2018-06-18 20:03:51 +00:00
m_auto_refresh_enabled . store ( false , std : : memory_order_relaxed ) ;
2017-10-19 12:57:49 +00:00
m_wallet - > auto_refresh ( auto_refresh ) ;
m_idle_mutex . lock ( ) ;
m_auto_refresh_enabled . store ( auto_refresh , std : : memory_order_relaxed ) ;
m_idle_cond . notify_one ( ) ;
m_idle_mutex . unlock ( ) ;
2015-11-28 12:38:58 +00:00
2017-10-19 12:57:49 +00:00
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
} ) ;
2015-11-28 12:38:58 +00:00
}
return true ;
}
2015-12-05 21:44:25 +00:00
bool simple_wallet : : set_refresh_type ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
tools : : wallet2 : : RefreshType refresh_type ;
if ( ! parse_refresh_type ( args [ 1 ] , refresh_type ) )
{
return true ;
}
2016-08-01 00:48:53 +00:00
2016-12-17 23:07:15 +00:00
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
2015-12-05 21:44:25 +00:00
{
2016-12-17 23:07:15 +00:00
m_wallet - > set_refresh_type ( refresh_type ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
2015-12-05 21:44:25 +00:00
}
return true ;
}
2016-10-01 16:03:53 +00:00
bool simple_wallet : : set_confirm_missing_payment_id ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
2016-12-17 23:07:15 +00:00
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
2016-10-01 16:03:53 +00:00
{
2017-10-19 12:57:49 +00:00
parse_bool_and_use ( args [ 1 ] , [ & ] ( bool r ) {
m_wallet - > confirm_missing_payment_id ( r ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
} ) ;
2016-10-01 16:03:53 +00:00
}
return true ;
}
2017-01-27 12:26:52 +00:00
bool simple_wallet : : set_ask_password ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
2018-09-02 09:59:01 +00:00
tools : : wallet2 : : AskPasswordType ask = tools : : wallet2 : : AskPasswordToDecrypt ;
if ( args [ 1 ] = = " never " | | args [ 1 ] = = " 0 " )
ask = tools : : wallet2 : : AskPasswordNever ;
else if ( args [ 1 ] = = " action " | | args [ 1 ] = = " 1 " )
ask = tools : : wallet2 : : AskPasswordOnAction ;
else if ( args [ 1 ] = = " encrypt " | | args [ 1 ] = = " decrypt " | | args [ 1 ] = = " 2 " )
ask = tools : : wallet2 : : AskPasswordToDecrypt ;
else
{
fail_msg_writer ( ) < < tr ( " invalid argument: must be either 0/never, 1/action, or 2/encrypt/decrypt " ) ;
return true ;
}
const tools : : wallet2 : : AskPasswordType cur_ask = m_wallet - > ask_password ( ) ;
if ( ! m_wallet - > watch_only ( ) )
{
if ( cur_ask = = tools : : wallet2 : : AskPasswordToDecrypt & & ask ! = tools : : wallet2 : : AskPasswordToDecrypt )
m_wallet - > decrypt_keys ( pwd_container - > password ( ) ) ;
else if ( cur_ask ! = tools : : wallet2 : : AskPasswordToDecrypt & & ask = = tools : : wallet2 : : AskPasswordToDecrypt )
m_wallet - > encrypt_keys ( pwd_container - > password ( ) ) ;
}
m_wallet - > ask_password ( ask ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
2017-01-27 12:26:52 +00:00
}
return true ;
}
2017-03-01 22:27:27 +00:00
bool simple_wallet : : set_unit ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
const std : : string & unit = args [ 1 ] ;
unsigned int decimal_point = CRYPTONOTE_DISPLAY_DECIMAL_POINT ;
if ( unit = = " monero " )
decimal_point = CRYPTONOTE_DISPLAY_DECIMAL_POINT ;
else if ( unit = = " millinero " )
decimal_point = CRYPTONOTE_DISPLAY_DECIMAL_POINT - 3 ;
else if ( unit = = " micronero " )
decimal_point = CRYPTONOTE_DISPLAY_DECIMAL_POINT - 6 ;
else if ( unit = = " nanonero " )
decimal_point = CRYPTONOTE_DISPLAY_DECIMAL_POINT - 9 ;
else if ( unit = = " piconero " )
decimal_point = 0 ;
else
{
fail_msg_writer ( ) < < tr ( " invalid unit " ) ;
return true ;
}
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
2018-01-17 01:25:24 +00:00
cryptonote : : set_default_decimal_point ( decimal_point ) ;
2017-03-01 22:27:27 +00:00
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
}
return true ;
}
wallet: try to save large outputs when using an unneeded second input
When a single input is enough to satisfy a transfer, the code would
previously try to add a second input, to match the "canonical" makeup
of a transaction with two inputs and two outputs. This would cause
wallets to slowly merge outputs till all the monero ends up in a
single output, which causes trouble when making two transactions
one after the other, since change is locked for 10 blocks, and an
increasing portion of the remaining balance would end up locked on
each transaction.
There are two new settings (min-output-count and min-output-value)
which can control when to stop adding such unneeded second outputs.
The idea is that small "dust" outputs will still get added, but
larger ones will not.
Enable with, eg:
set min-output-count 10
set min-output-value 30
to avoid using an unneeded second output of 30 monero or more, if
there would be less than 10 such outputs left.
This does not invalidate any other reason why such outputs would
be used (ie, when they're really needed to satisfy a transfer, or
when randomly picked in the normal course of selection). This may
be improved in the future.
2017-03-24 20:58:02 +00:00
bool simple_wallet : : set_min_output_count ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
uint32_t count ;
if ( ! string_tools : : get_xtype_from_string ( count , args [ 1 ] ) )
{
fail_msg_writer ( ) < < tr ( " invalid count: must be an unsigned integer " ) ;
return true ;
}
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
m_wallet - > set_min_output_count ( count ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
}
return true ;
}
bool simple_wallet : : set_min_output_value ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
uint64_t value ;
if ( ! cryptonote : : parse_amount ( value , args [ 1 ] ) )
{
fail_msg_writer ( ) < < tr ( " invalid value " ) ;
return true ;
}
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
m_wallet - > set_min_output_value ( value ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
}
return true ;
}
2017-03-24 21:56:58 +00:00
bool simple_wallet : : set_merge_destinations ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
2017-10-19 12:57:49 +00:00
parse_bool_and_use ( args [ 1 ] , [ & ] ( bool r ) {
m_wallet - > merge_destinations ( r ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
} ) ;
2017-03-24 21:56:58 +00:00
}
return true ;
}
2017-08-26 15:23:54 +00:00
bool simple_wallet : : set_confirm_backlog ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
2017-10-19 12:57:49 +00:00
parse_bool_and_use ( args [ 1 ] , [ & ] ( bool r ) {
m_wallet - > confirm_backlog ( r ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
} ) ;
2017-08-26 15:23:54 +00:00
}
return true ;
}
2017-09-18 11:46:33 +00:00
bool simple_wallet : : set_confirm_backlog_threshold ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
uint32_t threshold ;
if ( ! string_tools : : get_xtype_from_string ( threshold , args [ 1 ] ) )
{
fail_msg_writer ( ) < < tr ( " invalid count: must be an unsigned integer " ) ;
return true ;
}
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
m_wallet - > set_confirm_backlog_threshold ( threshold ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
}
return true ;
}
2018-01-14 23:36:13 +00:00
bool simple_wallet : : set_confirm_export_overwrite ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
parse_bool_and_use ( args [ 1 ] , [ & ] ( bool r ) {
m_wallet - > confirm_export_overwrite ( r ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
} ) ;
}
return true ;
}
2017-10-08 09:14:44 +00:00
bool simple_wallet : : set_refresh_from_block_height ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
uint64_t height ;
if ( ! epee : : string_tools : : get_xtype_from_string ( height , args [ 1 ] ) )
{
fail_msg_writer ( ) < < tr ( " Invalid height " ) ;
return true ;
}
m_wallet - > set_refresh_from_block_height ( height ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
}
return true ;
}
2018-01-15 03:05:16 +00:00
bool simple_wallet : : set_auto_low_priority ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
parse_bool_and_use ( args [ 1 ] , [ & ] ( bool r ) {
m_wallet - > auto_low_priority ( r ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
} ) ;
}
return true ;
}
2018-02-19 10:23:23 +00:00
bool simple_wallet : : set_segregate_pre_fork_outputs ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
parse_bool_and_use ( args [ 1 ] , [ & ] ( bool r ) {
m_wallet - > segregate_pre_fork_outputs ( r ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
} ) ;
}
return true ;
}
bool simple_wallet : : set_key_reuse_mitigation2 ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
parse_bool_and_use ( args [ 1 ] , [ & ] ( bool r ) {
m_wallet - > key_reuse_mitigation2 ( r ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
} ) ;
}
return true ;
}
2018-03-16 04:11:45 +00:00
bool simple_wallet : : set_subaddress_lookahead ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
auto lookahead = parse_subaddress_lookahead ( args [ 1 ] ) ;
if ( lookahead )
{
m_wallet - > set_subaddress_lookahead ( lookahead - > first , lookahead - > second ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
}
}
return true ;
}
2018-03-13 19:38:52 +00:00
bool simple_wallet : : set_segregation_height ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
uint64_t height ;
if ( ! epee : : string_tools : : get_xtype_from_string ( height , args [ 1 ] ) )
{
fail_msg_writer ( ) < < tr ( " Invalid height " ) ;
return true ;
}
m_wallet - > segregation_height ( height ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
}
return true ;
}
2018-06-28 02:31:50 +00:00
bool simple_wallet : : set_ignore_fractional_outputs ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
const auto pwd_container = get_and_verify_password ( ) ;
if ( pwd_container )
{
parse_bool_and_use ( args [ 1 ] , [ & ] ( bool r ) {
m_wallet - > ignore_fractional_outputs ( r ) ;
m_wallet - > rewrite ( m_wallet_file , pwd_container - > password ( ) ) ;
} ) ;
}
return true ;
}
2014-03-20 11:46:11 +00:00
bool simple_wallet : : help ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
2014-03-03 22:07:58 +00:00
{
2017-11-22 12:53:18 +00:00
if ( args . empty ( ) )
{
success_msg_writer ( ) < < get_commands_str ( ) ;
}
else
{
success_msg_writer ( ) < < get_command_usage ( args ) ;
}
2014-03-03 22:07:58 +00:00
return true ;
}
simple_wallet : : simple_wallet ( )
2016-07-10 15:49:40 +00:00
: m_allow_mismatched_daemon_version ( false )
2014-04-02 16:00:17 +00:00
, m_refresh_progress_reporter ( * this )
2016-08-07 12:06:40 +00:00
, m_idle_run ( true )
, m_auto_refresh_enabled ( false )
2015-11-28 12:38:58 +00:00
, m_auto_refresh_refreshing ( false )
2015-11-29 13:02:01 +00:00
, m_in_manual_refresh ( false )
2017-02-19 02:42:10 +00:00
, m_current_subaddress_account ( 0 )
2014-03-03 22:07:58 +00:00
{
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " start_mining " ,
boost : : bind ( & simple_wallet : : start_mining , this , _1 ) ,
tr ( " start_mining [<number_of_threads>] [bg_mining] [ignore_battery] " ) ,
tr ( " Start mining in the daemon (bg_mining and ignore_battery are optional booleans). " ) ) ;
m_cmd_binder . set_handler ( " stop_mining " ,
boost : : bind ( & simple_wallet : : stop_mining , this , _1 ) ,
tr ( " Stop mining in the daemon. " ) ) ;
2017-09-22 18:20:09 +00:00
m_cmd_binder . set_handler ( " set_daemon " ,
boost : : bind ( & simple_wallet : : set_daemon , this , _1 ) ,
2018-06-05 09:45:01 +00:00
tr ( " set_daemon <host>[:<port>] [trusted|untrusted] " ) ,
2017-09-22 18:20:09 +00:00
tr ( " Set another daemon to connect to. " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " save_bc " ,
boost : : bind ( & simple_wallet : : save_bc , this , _1 ) ,
tr ( " Save the current blockchain data. " ) ) ;
m_cmd_binder . set_handler ( " refresh " ,
boost : : bind ( & simple_wallet : : refresh , this , _1 ) ,
tr ( " Synchronize the transactions and balance. " ) ) ;
m_cmd_binder . set_handler ( " balance " ,
boost : : bind ( & simple_wallet : : show_balance , this , _1 ) ,
tr ( " balance [detail] " ) ,
tr ( " Show the wallet's balance of the currently selected account. " ) ) ;
m_cmd_binder . set_handler ( " incoming_transfers " ,
boost : : bind ( & simple_wallet : : show_incoming_transfers , this , _1 ) ,
tr ( " incoming_transfers [available|unavailable] [verbose] [index=<N1>[,<N2>[,...]]] " ) ,
tr ( " Show the incoming transfers, all or filtered by availability and address index. " ) ) ;
m_cmd_binder . set_handler ( " payments " ,
boost : : bind ( & simple_wallet : : show_payments , this , _1 ) ,
tr ( " payments <PID_1> [<PID_2> ... <PID_N>] " ) ,
tr ( " Show the payments for the given payment IDs. " ) ) ;
m_cmd_binder . set_handler ( " bc_height " ,
boost : : bind ( & simple_wallet : : show_blockchain_height , this , _1 ) ,
tr ( " Show the blockchain height. " ) ) ;
2018-09-16 14:28:59 +00:00
m_cmd_binder . set_handler ( " transfer " , boost : : bind ( & simple_wallet : : transfer , this , _1 ) ,
2018-08-01 16:01:36 +00:00
tr ( " transfer [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] (<URI> | <address> <amount>) [<payment_id>] " ) ,
tr ( " Transfer <amount> to <address>. If the parameter \" index=<N1>[,<N2>,...] \" is specified, the wallet uses outputs received by addresses of those indices. If omitted, the wallet randomly chooses address indices to be used. In any case, it tries its best not to combine outputs across multiple addresses. <priority> is the priority of the transaction. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \" set priority \" ) is used. <ring_size> is the number of inputs to include for untraceability. Multiple payments can be made at once by adding URI_2 or <address_2> <amount_2> etcetera (before the payment ID, if it's included) " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " locked_transfer " ,
boost : : bind ( & simple_wallet : : locked_transfer , this , _1 ) ,
2018-08-01 16:01:36 +00:00
tr ( " locked_transfer [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] (<URI> | <addr> <amount>) <lockblocks> [<payment_id>] " ) ,
tr ( " Transfer <amount> to <address> and lock it for <lockblocks> (max. 1000000). If the parameter \" index=<N1>[,<N2>,...] \" is specified, the wallet uses outputs received by addresses of those indices. If omitted, the wallet randomly chooses address indices to be used. In any case, it tries its best not to combine outputs across multiple addresses. <priority> is the priority of the transaction. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \" set priority \" ) is used. <ring_size> is the number of inputs to include for untraceability. Multiple payments can be made at once by adding URI_2 or <address_2> <amount_2> etcetera (before the payment ID, if it's included) " ) ) ;
2018-04-13 01:13:24 +00:00
m_cmd_binder . set_handler ( " locked_sweep_all " ,
boost : : bind ( & simple_wallet : : locked_sweep_all , this , _1 ) ,
tr ( " locked_sweep_all [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] <address> <lockblocks> [<payment_id>] " ) ,
tr ( " Send all unlocked balance to an address and lock it for <lockblocks> (max. 1000000). If the parameter \" index<N1>[,<N2>,...] \" is specified, the wallet sweeps outputs received by those address indices. If omitted, the wallet randomly chooses an address index to be used. <priority> is the priority of the sweep. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \" set priority \" ) is used. <ring_size> is the number of inputs to include for untraceability. " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " sweep_unmixable " ,
boost : : bind ( & simple_wallet : : sweep_unmixable , this , _1 ) ,
tr ( " Send all unmixable outputs to yourself with ring_size 1 " ) ) ;
m_cmd_binder . set_handler ( " sweep_all " , boost : : bind ( & simple_wallet : : sweep_all , this , _1 ) ,
2018-05-06 08:38:47 +00:00
tr ( " sweep_all [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] [outputs=<N>] <address> [<payment_id>] " ) ,
tr ( " Send all unlocked balance to an address. If the parameter \" index<N1>[,<N2>,...] \" is specified, the wallet sweeps outputs received by those address indices. If omitted, the wallet randomly chooses an address index to be used. If the parameter \" outputs=<N> \" is specified and N > 0, wallet splits the transaction into N even outputs. " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " sweep_below " ,
boost : : bind ( & simple_wallet : : sweep_below , this , _1 ) ,
tr ( " sweep_below <amount_threshold> [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] <address> [<payment_id>] " ) ,
tr ( " Send all unlocked outputs below the threshold to an address. " ) ) ;
m_cmd_binder . set_handler ( " sweep_single " ,
boost : : bind ( & simple_wallet : : sweep_single , this , _1 ) ,
2018-05-06 08:38:47 +00:00
tr ( " sweep_single [<priority>] [<ring_size>] [outputs=<N>] <key_image> <address> [<payment_id>] " ) ,
2017-11-22 12:53:18 +00:00
tr ( " Send a single output of the given key image to an address without change. " ) ) ;
m_cmd_binder . set_handler ( " donate " ,
boost : : bind ( & simple_wallet : : donate , this , _1 ) ,
tr ( " donate [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] <amount> [<payment_id>] " ) ,
tr ( " Donate <amount> to the development team (donate.getmonero.org). " ) ) ;
m_cmd_binder . set_handler ( " sign_transfer " ,
boost : : bind ( & simple_wallet : : sign_transfer , this , _1 ) ,
2018-05-31 23:45:20 +00:00
tr ( " sign_transfer [export_raw] " ) ,
tr ( " Sign a transaction from a file. If the parameter \" export_raw \" is specified, transaction raw hex data suitable for the daemon RPC /sendrawtransaction is exported. " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " submit_transfer " ,
boost : : bind ( & simple_wallet : : submit_transfer , this , _1 ) ,
tr ( " Submit a signed transaction from a file. " ) ) ;
m_cmd_binder . set_handler ( " set_log " ,
boost : : bind ( & simple_wallet : : set_log , this , _1 ) ,
tr ( " set_log <level>|{+,-,}<categories> " ) ,
tr ( " Change the current log detail (level must be <0-4>). " ) ) ;
m_cmd_binder . set_handler ( " account " ,
boost : : bind ( & simple_wallet : : account , this , _1 ) ,
2017-12-15 03:08:36 +00:00
tr ( " account \n "
" account new <label text with white spaces allowed> \n "
" account switch <index> \n "
" account label <index> <label text with white spaces allowed> \n "
" account tag <tag_name> <account_index_1> [<account_index_2> ...] \n "
" account untag <account_index_1> [<account_index_2> ...] \n "
" account tag_description <tag_name> <description> " ) ,
tr ( " If no arguments are specified, the wallet shows all the existing accounts along with their balances. \n "
" If the \" new \" argument is specified, the wallet creates a new account with its label initialized by the provided label text (which can be empty). \n "
" If the \" switch \" argument is specified, the wallet switches to the account specified by <index>. \n "
" If the \" label \" argument is specified, the wallet sets the label of the account specified by <index> to the provided label text. \n "
" If the \" tag \" argument is specified, a tag <tag_name> is assigned to the specified accounts <account_index_1>, <account_index_2>, .... \n "
" If the \" untag \" argument is specified, the tags assigned to the specified accounts <account_index_1>, <account_index_2> ..., are removed. \n "
" If the \" tag_description \" argument is specified, the tag <tag_name> is assigned an arbitrary text <description>. " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " address " ,
boost : : bind ( & simple_wallet : : print_address , this , _1 ) ,
tr ( " address [ new <label text with white spaces allowed> | all | <index_min> [<index_max>] | label <index> <label text with white spaces allowed>] " ) ,
2018-03-01 11:36:19 +00:00
tr ( " If no arguments are specified or <index> is specified, the wallet shows the default or specified address. If \" all \" is specified, the wallet shows all the existing addresses in the currently selected account. If \" new \" is specified, the wallet creates a new address with the provided label text (which can be empty). If \" label \" is specified, the wallet sets the label of the address specified by <index> to the provided label text. " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " integrated_address " ,
boost : : bind ( & simple_wallet : : print_integrated_address , this , _1 ) ,
tr ( " integrated_address [<payment_id> | <address>] " ) ,
tr ( " Encode a payment ID into an integrated address for the current wallet public address (no argument uses a random payment ID), or decode an integrated address to standard address and payment ID " ) ) ;
m_cmd_binder . set_handler ( " address_book " ,
boost : : bind ( & simple_wallet : : address_book , this , _1 ) ,
tr ( " address_book [(add ((<address> [pid <id>])|<integrated address>) [<description possibly with whitespaces>])|(delete <index>)] " ) ,
tr ( " Print all entries in the address book, optionally adding/deleting an entry to/from it. " ) ) ;
m_cmd_binder . set_handler ( " save " ,
boost : : bind ( & simple_wallet : : save , this , _1 ) ,
tr ( " Save the wallet data. " ) ) ;
m_cmd_binder . set_handler ( " save_watch_only " ,
boost : : bind ( & simple_wallet : : save_watch_only , this , _1 ) ,
tr ( " Save a watch-only keys file. " ) ) ;
m_cmd_binder . set_handler ( " viewkey " ,
boost : : bind ( & simple_wallet : : viewkey , this , _1 ) ,
tr ( " Display the private view key. " ) ) ;
m_cmd_binder . set_handler ( " spendkey " ,
boost : : bind ( & simple_wallet : : spendkey , this , _1 ) ,
tr ( " Display the private spend key. " ) ) ;
m_cmd_binder . set_handler ( " seed " ,
boost : : bind ( & simple_wallet : : seed , this , _1 ) ,
tr ( " Display the Electrum-style mnemonic seed " ) ) ;
m_cmd_binder . set_handler ( " set " ,
boost : : bind ( & simple_wallet : : set_variable , this , _1 ) ,
tr ( " set <option> [<value>] " ) ,
tr ( " Available options: \n "
" seed language \n "
" Set the wallet's seed language. \n "
" always-confirm-transfers <1|0> \n "
" Whether to confirm unsplit txes. \n "
" print-ring-members <1|0> \n "
" Whether to print detailed information about ring members during confirmation. \n "
" store-tx-info <1|0> \n "
" Whether to store outgoing tx info (destination address, payment ID, tx secret key) for future reference. \n "
" default-ring-size <n> \n "
2018-10-10 15:03:38 +00:00
" Set the default ring size (obsolete). \n "
2017-11-22 12:53:18 +00:00
" auto-refresh <1|0> \n "
" Whether to automatically synchronize new blocks from the daemon. \n "
" refresh-type <full|optimize-coinbase|no-coinbase|default> \n "
" Set the wallet's refresh behaviour. \n "
" priority [0|1|2|3|4] \n "
2018-06-13 10:49:49 +00:00
" Set the fee to default/unimportant/normal/elevated/priority. \n "
2017-11-22 12:53:18 +00:00
" confirm-missing-payment-id <1|0> \n "
2018-09-02 09:59:01 +00:00
" ask-password <0|1|2 (or never|action|decrypt)> \n "
2017-11-22 12:53:18 +00:00
" unit <monero|millinero|micronero|nanonero|piconero> \n "
" Set the default monero (sub-)unit. \n "
" min-outputs-count [n] \n "
" Try to keep at least that many outputs of value at least min-outputs-value. \n "
" min-outputs-value [n] \n "
" Try to keep at least min-outputs-count outputs of at least that value. \n "
" merge-destinations <1|0> \n "
" Whether to merge multiple payments to the same destination address. \n "
" confirm-backlog <1|0> \n "
" Whether to warn if there is transaction backlog. \n "
" confirm-backlog-threshold [n] \n "
" Set a threshold for confirm-backlog to only warn if the transaction backlog is greater than n blocks. \n "
" refresh-from-block-height [n] \n "
2018-01-15 03:05:16 +00:00
" Set the height before which to ignore blocks. \n "
" auto-low-priority <1|0> \n "
2018-02-19 10:23:23 +00:00
" Whether to automatically use the low priority fee level when it's safe to do so. \n "
" segregate-pre-fork-outputs <1|0> \n "
" Set this if you intend to spend outputs on both Monero AND a key reusing fork. \n "
" key-reuse-mitigation2 <1|0> \n "
2018-03-16 04:11:45 +00:00
" Set this if you are not sure whether you will spend on a key reusing Monero fork later. \n "
" subaddress-lookahead <major>:<minor> \n "
2018-03-13 19:38:52 +00:00
" Set the lookahead sizes for the subaddress hash table. \n "
" Set this if you are not sure whether you will spend on a key reusing Monero fork later. \n "
" segregation-height <n> \n "
" Set to the height of a key reusing fork you want to use, 0 to use default. " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " encrypted_seed " ,
boost : : bind ( & simple_wallet : : encrypted_seed , this , _1 ) ,
tr ( " Display the encrypted Electrum-style mnemonic seed. " ) ) ;
m_cmd_binder . set_handler ( " rescan_spent " ,
boost : : bind ( & simple_wallet : : rescan_spent , this , _1 ) ,
tr ( " Rescan the blockchain for spent outputs. " ) ) ;
m_cmd_binder . set_handler ( " get_tx_key " ,
boost : : bind ( & simple_wallet : : get_tx_key , this , _1 ) ,
tr ( " get_tx_key <txid> " ) ,
tr ( " Get the transaction key (r) for a given <txid>. " ) ) ;
2018-07-29 12:29:56 +00:00
m_cmd_binder . set_handler ( " set_tx_key " ,
boost : : bind ( & simple_wallet : : set_tx_key , this , _1 ) ,
tr ( " set_tx_key <txid> <tx_key> " ) ,
tr ( " Set the transaction key (r) for a given <txid> in case the tx was made by some other device or 3rd party wallet. " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " check_tx_key " ,
boost : : bind ( & simple_wallet : : check_tx_key , this , _1 ) ,
tr ( " check_tx_key <txid> <txkey> <address> " ) ,
tr ( " Check the amount going to <address> in <txid>. " ) ) ;
2018-01-11 14:14:13 +00:00
m_cmd_binder . set_handler ( " get_tx_proof " ,
2017-11-22 12:53:18 +00:00
boost : : bind ( & simple_wallet : : get_tx_proof , this , _1 ) ,
2018-01-11 14:14:13 +00:00
tr ( " get_tx_proof <txid> <address> [<message>] " ) ,
2017-11-22 12:53:18 +00:00
tr ( " Generate a signature proving funds sent to <address> in <txid>, optionally with a challenge string <message>, using either the transaction secret key (when <address> is not your wallet's address) or the view secret key (otherwise), which does not disclose the secret key. " ) ) ;
m_cmd_binder . set_handler ( " check_tx_proof " ,
boost : : bind ( & simple_wallet : : check_tx_proof , this , _1 ) ,
tr ( " check_tx_proof <txid> <address> <signature_file> [<message>] " ) ,
tr ( " Check the proof for funds going to <address> in <txid> with the challenge string <message> if any. " ) ) ;
m_cmd_binder . set_handler ( " get_spend_proof " ,
boost : : bind ( & simple_wallet : : get_spend_proof , this , _1 ) ,
tr ( " get_spend_proof <txid> [<message>] " ) ,
tr ( " Generate a signature proving that you generated <txid> using the spend secret key, optionally with a challenge string <message>. " ) ) ;
m_cmd_binder . set_handler ( " check_spend_proof " ,
boost : : bind ( & simple_wallet : : check_spend_proof , this , _1 ) ,
tr ( " check_spend_proof <txid> <signature_file> [<message>] " ) ,
tr ( " Check a signature proving that the signer generated <txid>, optionally with a challenge string <message>. " ) ) ;
2017-12-28 13:50:10 +00:00
m_cmd_binder . set_handler ( " get_reserve_proof " ,
boost : : bind ( & simple_wallet : : get_reserve_proof , this , _1 ) ,
tr ( " get_reserve_proof (all|<amount>) [<message>] " ) ,
tr ( " Generate a signature proving that you own at least this much, optionally with a challenge string <message>. \n "
" If 'all' is specified, you prove the entire sum of all of your existing accounts' balances. \n "
" Otherwise, you prove the reserve of the smallest possible amount above <amount> available in your current account. " ) ) ;
m_cmd_binder . set_handler ( " check_reserve_proof " ,
boost : : bind ( & simple_wallet : : check_reserve_proof , this , _1 ) ,
tr ( " check_reserve_proof <address> <signature_file> [<message>] " ) ,
tr ( " Check a signature proving that the owner of <address> holds at least this much, optionally with a challenge string <message>. " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " show_transfers " ,
boost : : bind ( & simple_wallet : : show_transfers , this , _1 ) ,
2018-07-19 16:49:15 +00:00
tr ( " show_transfers [in|out|pending|failed|pool|coinbase] [index=<N1>[,<N2>,...]] [<min_height> [<max_height>]] " ) ,
2018-10-18 09:14:15 +00:00
// Seemingly broken formatting to compensate for the backslash before the quotes.
tr ( " Show the incoming/outgoing transfers within an optional height range. \n \n "
" Output format: \n "
" In or Coinbase: Block Number, \" block \" | \" in \" , Time, Amount, Transaction Hash, Payment ID, Subaddress Index, \" - \" , Note \n "
" Out: Block Number, \" out \" , Time, Amount*, Transaction Hash, Payment ID, Fee, Destinations, Input addresses**, \" - \" , Note \n "
" Pool: \" pool \" , \" in \" , Time, Amount, Transaction Hash, Payment Id, Subaddress Index, \" - \" , Note, Double Spend Note \n "
" Pending or Failed: \" failed \" | \" pending \" , \" out \" , Time, Amount*, Transaction Hash, Payment ID, Fee, Input addresses**, \" - \" , Note \n \n "
" * Excluding change and fee. \n "
" ** Set of address indices used as inputs in this transfer. " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " unspent_outputs " ,
boost : : bind ( & simple_wallet : : unspent_outputs , this , _1 ) ,
tr ( " unspent_outputs [index=<N1>[,<N2>,...]] [<min_amount> [<max_amount>]] " ) ,
tr ( " Show the unspent outputs of a specified address within an optional amount range. " ) ) ;
m_cmd_binder . set_handler ( " rescan_bc " ,
boost : : bind ( & simple_wallet : : rescan_blockchain , this , _1 ) ,
2018-08-07 12:48:04 +00:00
tr ( " Rescan the blockchain from scratch, losing any information which can not be recovered from the blockchain itself. " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " set_tx_note " ,
boost : : bind ( & simple_wallet : : set_tx_note , this , _1 ) ,
tr ( " set_tx_note <txid> [free text note] " ) ,
tr ( " Set an arbitrary string note for a <txid>. " ) ) ;
m_cmd_binder . set_handler ( " get_tx_note " ,
boost : : bind ( & simple_wallet : : get_tx_note , this , _1 ) ,
tr ( " get_tx_note <txid> " ) ,
tr ( " Get a string note for a txid. " ) ) ;
m_cmd_binder . set_handler ( " set_description " ,
boost : : bind ( & simple_wallet : : set_description , this , _1 ) ,
tr ( " set_description [free text note] " ) ,
tr ( " Set an arbitrary description for the wallet. " ) ) ;
m_cmd_binder . set_handler ( " get_description " ,
boost : : bind ( & simple_wallet : : get_description , this , _1 ) ,
tr ( " Get the description of the wallet. " ) ) ;
m_cmd_binder . set_handler ( " status " ,
boost : : bind ( & simple_wallet : : status , this , _1 ) ,
tr ( " Show the wallet's status. " ) ) ;
m_cmd_binder . set_handler ( " wallet_info " ,
boost : : bind ( & simple_wallet : : wallet_info , this , _1 ) ,
tr ( " Show the wallet's information. " ) ) ;
m_cmd_binder . set_handler ( " sign " ,
boost : : bind ( & simple_wallet : : sign , this , _1 ) ,
tr ( " sign <file> " ) ,
tr ( " Sign the contents of a file. " ) ) ;
m_cmd_binder . set_handler ( " verify " ,
boost : : bind ( & simple_wallet : : verify , this , _1 ) ,
tr ( " verify <filename> <address> <signature> " ) ,
tr ( " Verify a signature on the contents of a file. " ) ) ;
m_cmd_binder . set_handler ( " export_key_images " ,
boost : : bind ( & simple_wallet : : export_key_images , this , _1 ) ,
tr ( " export_key_images <file> " ) ,
tr ( " Export a signed set of key images to a <file>. " ) ) ;
m_cmd_binder . set_handler ( " import_key_images " ,
boost : : bind ( & simple_wallet : : import_key_images , this , _1 ) ,
tr ( " import_key_images <file> " ) ,
tr ( " Import a signed key images list and verify their spent status. " ) ) ;
2018-08-23 22:50:31 +00:00
m_cmd_binder . set_handler ( " hw_reconnect " ,
boost : : bind ( & simple_wallet : : hw_reconnect , this , _1 ) ,
tr ( " hw_reconnect " ) ,
tr ( " Attempts to reconnect HW wallet. " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " export_outputs " ,
boost : : bind ( & simple_wallet : : export_outputs , this , _1 ) ,
tr ( " export_outputs <file> " ) ,
tr ( " Export a set of outputs owned by this wallet. " ) ) ;
m_cmd_binder . set_handler ( " import_outputs " ,
boost : : bind ( & simple_wallet : : import_outputs , this , _1 ) ,
tr ( " import_outputs <file> " ) ,
tr ( " Import a set of outputs owned by this wallet. " ) ) ;
m_cmd_binder . set_handler ( " show_transfer " ,
boost : : bind ( & simple_wallet : : show_transfer , this , _1 ) ,
tr ( " show_transfer <txid> " ) ,
tr ( " Show information about a transfer to/from this address. " ) ) ;
m_cmd_binder . set_handler ( " password " ,
boost : : bind ( & simple_wallet : : change_password , this , _1 ) ,
tr ( " Change the wallet's password. " ) ) ;
m_cmd_binder . set_handler ( " payment_id " ,
boost : : bind ( & simple_wallet : : payment_id , this , _1 ) ,
tr ( " Generate a new random full size payment id. These will be unencrypted on the blockchain, see integrated_address for encrypted short payment ids. " ) ) ;
m_cmd_binder . set_handler ( " fee " ,
boost : : bind ( & simple_wallet : : print_fee_info , this , _1 ) ,
tr ( " Print the information about the current fee and transaction backlog. " ) ) ;
2017-05-28 11:18:51 +00:00
m_cmd_binder . set_handler ( " prepare_multisig " , boost : : bind ( & simple_wallet : : prepare_multisig , this , _1 ) ,
tr ( " Export data needed to create a multisig wallet " ) ) ;
m_cmd_binder . set_handler ( " make_multisig " , boost : : bind ( & simple_wallet : : make_multisig , this , _1 ) ,
tr ( " make_multisig <threshold> <string1> [<string>...] " ) ,
tr ( " Turn this wallet into a multisig wallet " ) ) ;
2017-08-13 14:29:31 +00:00
m_cmd_binder . set_handler ( " finalize_multisig " ,
boost : : bind ( & simple_wallet : : finalize_multisig , this , _1 ) ,
tr ( " finalize_multisig <string> [<string>...] " ) ,
tr ( " Turn this wallet into a multisig wallet, extra step for N-1/N wallets " ) ) ;
2018-07-12 09:55:52 +00:00
m_cmd_binder . set_handler ( " exchange_multisig_keys " ,
boost : : bind ( & simple_wallet : : exchange_multisig_keys , this , _1 ) ,
tr ( " exchange_multisig_keys <string> [<string>...] " ) ,
tr ( " Performs extra multisig keys exchange rounds. Needed for arbitrary M/N multisig wallets " ) ) ;
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
m_cmd_binder . set_handler ( " export_multisig_info " ,
boost : : bind ( & simple_wallet : : export_multisig , this , _1 ) ,
2017-12-26 13:57:08 +00:00
tr ( " export_multisig_info <filename> " ) ,
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
tr ( " Export multisig info for other participants " ) ) ;
m_cmd_binder . set_handler ( " import_multisig_info " ,
boost : : bind ( & simple_wallet : : import_multisig , this , _1 ) ,
2017-12-26 13:57:08 +00:00
tr ( " import_multisig_info <filename> [<filename>...] " ) ,
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
tr ( " Import multisig info from other participants " ) ) ;
m_cmd_binder . set_handler ( " sign_multisig " ,
boost : : bind ( & simple_wallet : : sign_multisig , this , _1 ) ,
tr ( " sign_multisig <filename> " ) ,
tr ( " Sign a multisig transaction from a file " ) ) ;
m_cmd_binder . set_handler ( " submit_multisig " ,
boost : : bind ( & simple_wallet : : submit_multisig , this , _1 ) ,
tr ( " submit_multisig <filename> " ) ,
tr ( " Submit a signed multisig transaction from a file " ) ) ;
2017-10-07 20:20:28 +00:00
m_cmd_binder . set_handler ( " export_raw_multisig_tx " ,
boost : : bind ( & simple_wallet : : export_raw_multisig , this , _1 ) ,
2017-12-26 13:57:08 +00:00
tr ( " export_raw_multisig_tx <filename> " ) ,
2017-10-07 20:20:28 +00:00
tr ( " Export a signed multisig transaction to a file " ) ) ;
2018-02-18 10:47:25 +00:00
m_cmd_binder . set_handler ( " print_ring " ,
boost : : bind ( & simple_wallet : : print_ring , this , _1 ) ,
2018-03-14 19:13:55 +00:00
tr ( " print_ring <key_image> | <txid> " ) ,
tr ( " Print the ring(s) used to spend a given key image or transaction (if the ring size is > 1) " ) ) ;
2018-02-28 18:26:06 +00:00
m_cmd_binder . set_handler ( " set_ring " ,
boost : : bind ( & simple_wallet : : set_ring , this , _1 ) ,
2018-04-01 08:18:27 +00:00
tr ( " set_ring <filename> | ( <key_image> absolute|relative <index> [<index>...] ) " ) ,
2018-02-28 18:26:06 +00:00
tr ( " Set the ring used for a given key image, so it can be reused in a fork " ) ) ;
2018-02-18 10:47:25 +00:00
m_cmd_binder . set_handler ( " save_known_rings " ,
boost : : bind ( & simple_wallet : : save_known_rings , this , _1 ) ,
tr ( " save_known_rings " ) ,
tr ( " Save known rings to the shared rings database " ) ) ;
2018-10-18 18:05:51 +00:00
m_cmd_binder . set_handler ( " mark_output_spent " ,
2018-02-25 19:20:07 +00:00
boost : : bind ( & simple_wallet : : blackball , this , _1 ) ,
2018-10-18 18:05:51 +00:00
tr ( " mark_output_spent <amount>/<offset> | <filename> [add] " ) ,
tr ( " Mark output(s) as spent so they never get selected as fake outputs in a ring " ) ) ;
m_cmd_binder . set_handler ( " mark_output_unspent " ,
2018-02-25 19:20:07 +00:00
boost : : bind ( & simple_wallet : : unblackball , this , _1 ) ,
2018-10-18 18:05:51 +00:00
tr ( " mark_output_unspent <amount>/<offset> " ) ,
tr ( " Marks an output as unspent so it may get selected as a fake output in a ring " ) ) ;
m_cmd_binder . set_handler ( " is_output_spent " ,
2018-02-25 19:20:07 +00:00
boost : : bind ( & simple_wallet : : blackballed , this , _1 ) ,
2018-10-18 18:05:51 +00:00
tr ( " is_output_spent <amount>/<offset> " ) ,
tr ( " Checks whether an output is marked as spent " ) ) ;
2018-04-13 17:45:10 +00:00
m_cmd_binder . set_handler ( " version " ,
boost : : bind ( & simple_wallet : : version , this , _1 ) ,
tr ( " version " ) ,
tr ( " Returns version information " ) ) ;
2017-11-22 12:53:18 +00:00
m_cmd_binder . set_handler ( " help " ,
boost : : bind ( & simple_wallet : : help , this , _1 ) ,
tr ( " help [<command>] " ) ,
tr ( " Show the help section or the documentation about a <command>. " ) ) ;
2014-03-03 22:07:58 +00:00
}
//----------------------------------------------------------------------------------------------------
2014-12-06 14:58:33 +00:00
bool simple_wallet : : set_variable ( const std : : vector < std : : string > & args )
{
if ( args . empty ( ) )
{
2018-03-17 22:46:41 +00:00
std : : string seed_language = m_wallet - > get_seed_language ( ) ;
if ( m_use_english_language_names )
seed_language = crypto : : ElectrumWords : : get_english_name_for ( seed_language ) ;
2018-08-15 12:15:39 +00:00
std : : string priority_string = " invalid " ;
uint32_t priority = m_wallet - > get_default_priority ( ) ;
if ( priority < allowed_priority_strings . size ( ) )
priority_string = allowed_priority_strings [ priority ] ;
2018-09-02 09:59:01 +00:00
std : : string ask_password_string = " invalid " ;
switch ( m_wallet - > ask_password ( ) )
{
case tools : : wallet2 : : AskPasswordNever : ask_password_string = " never " ; break ;
case tools : : wallet2 : : AskPasswordOnAction : ask_password_string = " action " ; break ;
case tools : : wallet2 : : AskPasswordToDecrypt : ask_password_string = " decrypt " ; break ;
}
2018-03-17 22:46:41 +00:00
success_msg_writer ( ) < < " seed = " < < seed_language ;
2016-04-28 21:09:49 +00:00
success_msg_writer ( ) < < " always-confirm-transfers = " < < m_wallet - > always_confirm_transfers ( ) ;
2016-12-23 12:04:54 +00:00
success_msg_writer ( ) < < " print-ring-members = " < < m_wallet - > print_ring_members ( ) ;
2016-04-28 21:09:49 +00:00
success_msg_writer ( ) < < " store-tx-info = " < < m_wallet - > store_tx_info ( ) ;
2017-07-31 06:50:41 +00:00
success_msg_writer ( ) < < " default-ring-size = " < < ( m_wallet - > default_mixin ( ) ? m_wallet - > default_mixin ( ) + 1 : 0 ) ;
2016-04-28 21:09:49 +00:00
success_msg_writer ( ) < < " auto-refresh = " < < m_wallet - > auto_refresh ( ) ;
success_msg_writer ( ) < < " refresh-type = " < < get_refresh_type_name ( m_wallet - > get_refresh_type ( ) ) ;
2018-08-15 12:15:39 +00:00
success_msg_writer ( ) < < " priority = " < < priority < < " ( " < < priority_string < < " ) " ;
2016-10-01 16:03:53 +00:00
success_msg_writer ( ) < < " confirm-missing-payment-id = " < < m_wallet - > confirm_missing_payment_id ( ) ;
2018-09-02 09:59:01 +00:00
success_msg_writer ( ) < < " ask-password = " < < m_wallet - > ask_password ( ) < < " ( " < < ask_password_string < < " ) " ;
2018-01-17 01:25:24 +00:00
success_msg_writer ( ) < < " unit = " < < cryptonote : : get_unit ( cryptonote : : get_default_decimal_point ( ) ) ;
wallet: try to save large outputs when using an unneeded second input
When a single input is enough to satisfy a transfer, the code would
previously try to add a second input, to match the "canonical" makeup
of a transaction with two inputs and two outputs. This would cause
wallets to slowly merge outputs till all the monero ends up in a
single output, which causes trouble when making two transactions
one after the other, since change is locked for 10 blocks, and an
increasing portion of the remaining balance would end up locked on
each transaction.
There are two new settings (min-output-count and min-output-value)
which can control when to stop adding such unneeded second outputs.
The idea is that small "dust" outputs will still get added, but
larger ones will not.
Enable with, eg:
set min-output-count 10
set min-output-value 30
to avoid using an unneeded second output of 30 monero or more, if
there would be less than 10 such outputs left.
This does not invalidate any other reason why such outputs would
be used (ie, when they're really needed to satisfy a transfer, or
when randomly picked in the normal course of selection). This may
be improved in the future.
2017-03-24 20:58:02 +00:00
success_msg_writer ( ) < < " min-outputs-count = " < < m_wallet - > get_min_output_count ( ) ;
success_msg_writer ( ) < < " min-outputs-value = " < < cryptonote : : print_money ( m_wallet - > get_min_output_value ( ) ) ;
2017-03-24 21:56:58 +00:00
success_msg_writer ( ) < < " merge-destinations = " < < m_wallet - > merge_destinations ( ) ;
2017-08-26 15:23:54 +00:00
success_msg_writer ( ) < < " confirm-backlog = " < < m_wallet - > confirm_backlog ( ) ;
2017-09-18 11:46:33 +00:00
success_msg_writer ( ) < < " confirm-backlog-threshold = " < < m_wallet - > get_confirm_backlog_threshold ( ) ;
2018-01-14 23:36:13 +00:00
success_msg_writer ( ) < < " confirm-export-overwrite = " < < m_wallet - > confirm_export_overwrite ( ) ;
2017-10-08 09:14:44 +00:00
success_msg_writer ( ) < < " refresh-from-block-height = " < < m_wallet - > get_refresh_from_block_height ( ) ;
2018-01-15 03:05:16 +00:00
success_msg_writer ( ) < < " auto-low-priority = " < < m_wallet - > auto_low_priority ( ) ;
2018-02-19 10:23:23 +00:00
success_msg_writer ( ) < < " segregate-pre-fork-outputs = " < < m_wallet - > segregate_pre_fork_outputs ( ) ;
success_msg_writer ( ) < < " key-reuse-mitigation2 = " < < m_wallet - > key_reuse_mitigation2 ( ) ;
2018-03-16 04:11:45 +00:00
const std : : pair < size_t , size_t > lookahead = m_wallet - > get_subaddress_lookahead ( ) ;
success_msg_writer ( ) < < " subaddress-lookahead = " < < lookahead . first < < " : " < < lookahead . second ;
2018-03-13 19:38:52 +00:00
success_msg_writer ( ) < < " segregation-height = " < < m_wallet - > segregation_height ( ) ;
2018-06-28 02:31:50 +00:00
success_msg_writer ( ) < < " ignore-fractional-outputs = " < < m_wallet - > ignore_fractional_outputs ( ) ;
2018-08-23 22:50:31 +00:00
success_msg_writer ( ) < < " device_name = " < < m_wallet - > device_name ( ) ;
2014-12-06 14:58:33 +00:00
return true ;
}
else
{
2017-03-26 16:52:36 +00:00
# define CHECK_SIMPLE_VARIABLE(name, f, help) do \
if ( args [ 0 ] = = name ) { \
if ( args . size ( ) < = 1 ) \
{ \
fail_msg_writer ( ) < < " set " < < # name < < " : " < < tr ( " needs an argument " ) < < " ( " < < help < < " ) " ; \
return true ; \
} \
else \
{ \
f ( args ) ; \
return true ; \
} \
} while ( 0 )
2014-12-06 14:58:33 +00:00
if ( args [ 0 ] = = " seed " )
{
if ( args . size ( ) = = 1 )
{
2015-07-14 19:28:25 +00:00
fail_msg_writer ( ) < < tr ( " set seed: needs an argument. available options: language " ) ;
2014-12-06 14:58:33 +00:00
return true ;
}
else if ( args [ 1 ] = = " language " )
{
2016-12-25 23:50:37 +00:00
seed_set_language ( args ) ;
2014-12-06 14:58:33 +00:00
return true ;
}
}
2017-03-26 16:52:36 +00:00
CHECK_SIMPLE_VARIABLE ( " always-confirm-transfers " , set_always_confirm_transfers , tr ( " 0 or 1 " ) ) ;
CHECK_SIMPLE_VARIABLE ( " print-ring-members " , set_print_ring_members , tr ( " 0 or 1 " ) ) ;
CHECK_SIMPLE_VARIABLE ( " store-tx-info " , set_store_tx_info , tr ( " 0 or 1 " ) ) ;
2017-11-10 10:03:53 +00:00
CHECK_SIMPLE_VARIABLE ( " default-ring-size " , set_default_ring_size , tr ( " integer >= " ) < < MIN_RING_SIZE ) ;
2017-03-26 16:52:36 +00:00
CHECK_SIMPLE_VARIABLE ( " auto-refresh " , set_auto_refresh , tr ( " 0 or 1 " ) ) ;
CHECK_SIMPLE_VARIABLE ( " refresh-type " , set_refresh_type , tr ( " full (slowest, no assumptions); optimize-coinbase (fast, assumes the whole coinbase is paid to a single address); no-coinbase (fastest, assumes we receive no coinbase transaction), default (same as optimize-coinbase) " ) ) ;
2018-08-15 12:15:39 +00:00
CHECK_SIMPLE_VARIABLE ( " priority " , set_default_priority , tr ( " 0, 1, 2, 3, or 4, or one of " ) < < join_priority_strings ( " , " ) ) ;
2017-03-26 16:52:36 +00:00
CHECK_SIMPLE_VARIABLE ( " confirm-missing-payment-id " , set_confirm_missing_payment_id , tr ( " 0 or 1 " ) ) ;
2018-09-02 09:59:01 +00:00
CHECK_SIMPLE_VARIABLE ( " ask-password " , set_ask_password , tr ( " 0|1|2 (or never|action|decrypt) " ) ) ;
2017-06-23 12:01:04 +00:00
CHECK_SIMPLE_VARIABLE ( " unit " , set_unit , tr ( " monero, millinero, micronero, nanonero, piconero " ) ) ;
2017-03-26 16:52:36 +00:00
CHECK_SIMPLE_VARIABLE ( " min-outputs-count " , set_min_output_count , tr ( " unsigned integer " ) ) ;
CHECK_SIMPLE_VARIABLE ( " min-outputs-value " , set_min_output_value , tr ( " amount " ) ) ;
CHECK_SIMPLE_VARIABLE ( " merge-destinations " , set_merge_destinations , tr ( " 0 or 1 " ) ) ;
2017-08-26 15:23:54 +00:00
CHECK_SIMPLE_VARIABLE ( " confirm-backlog " , set_confirm_backlog , tr ( " 0 or 1 " ) ) ;
2017-09-18 11:46:33 +00:00
CHECK_SIMPLE_VARIABLE ( " confirm-backlog-threshold " , set_confirm_backlog_threshold , tr ( " unsigned integer " ) ) ;
2018-01-14 23:36:13 +00:00
CHECK_SIMPLE_VARIABLE ( " confirm-export-overwrite " , set_confirm_export_overwrite , tr ( " 0 or 1 " ) ) ;
2017-10-08 09:14:44 +00:00
CHECK_SIMPLE_VARIABLE ( " refresh-from-block-height " , set_refresh_from_block_height , tr ( " block height " ) ) ;
2018-01-15 03:05:16 +00:00
CHECK_SIMPLE_VARIABLE ( " auto-low-priority " , set_auto_low_priority , tr ( " 0 or 1 " ) ) ;
2018-02-19 10:23:23 +00:00
CHECK_SIMPLE_VARIABLE ( " segregate-pre-fork-outputs " , set_segregate_pre_fork_outputs , tr ( " 0 or 1 " ) ) ;
CHECK_SIMPLE_VARIABLE ( " key-reuse-mitigation2 " , set_key_reuse_mitigation2 , tr ( " 0 or 1 " ) ) ;
2018-03-16 04:11:45 +00:00
CHECK_SIMPLE_VARIABLE ( " subaddress-lookahead " , set_subaddress_lookahead , tr ( " <major>:<minor> " ) ) ;
2018-03-13 19:38:52 +00:00
CHECK_SIMPLE_VARIABLE ( " segregation-height " , set_segregation_height , tr ( " unsigned integer " ) ) ;
2018-06-28 02:31:50 +00:00
CHECK_SIMPLE_VARIABLE ( " ignore-fractional-outputs " , set_ignore_fractional_outputs , tr ( " 0 or 1 " ) ) ;
2014-12-06 14:58:33 +00:00
}
2015-07-14 19:28:25 +00:00
fail_msg_writer ( ) < < tr ( " set: unrecognized argument(s) " ) ;
2014-12-06 14:58:33 +00:00
return true ;
}
2015-12-05 21:44:25 +00:00
2014-12-06 14:58:33 +00:00
//----------------------------------------------------------------------------------------------------
2014-03-03 22:07:58 +00:00
bool simple_wallet : : set_log ( const std : : vector < std : : string > & args )
{
2017-09-22 16:54:58 +00:00
if ( args . size ( ) > 1 )
2014-03-03 22:07:58 +00:00
{
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
fail_msg_writer ( ) < < tr ( " usage: set_log <log_level_number_0-4> | <categories> " ) ;
2014-03-03 22:07:58 +00:00
return true ;
}
2018-04-15 15:33:22 +00:00
if ( ! args . empty ( ) )
{
uint16_t level = 0 ;
if ( epee : : string_tools : : get_xtype_from_string ( level , args [ 0 ] ) )
{
if ( 4 < level )
{
fail_msg_writer ( ) < < tr ( " wrong number range, use: set_log <log_level_number_0-4> | <categories> " ) ;
return true ;
}
mlog_set_log_level ( level ) ;
}
else
{
mlog_set_log ( args [ 0 ] . c_str ( ) ) ;
}
}
2017-09-22 16:54:58 +00:00
success_msg_writer ( ) < < " New log categories: " < < mlog_get_categories ( ) ;
2014-03-03 22:07:58 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
2014-05-03 16:19:43 +00:00
bool simple_wallet : : ask_wallet_create_if_needed ( )
{
2016-10-11 01:45:21 +00:00
LOG_PRINT_L3 ( " simple_wallet::ask_wallet_create_if_needed() started " ) ;
2014-05-03 16:19:43 +00:00
std : : string wallet_path ;
2016-10-11 01:45:21 +00:00
std : : string confirm_creation ;
bool wallet_name_valid = false ;
2014-05-03 16:19:43 +00:00
bool keys_file_exists ;
2014-05-25 17:06:40 +00:00
bool wallet_file_exists ;
2014-12-11 10:47:24 +00:00
2016-10-11 01:45:21 +00:00
do {
LOG_PRINT_L3 ( " User asked to specify wallet file name. " ) ;
2017-10-28 18:13:42 +00:00
wallet_path = input_line (
2016-12-13 01:53:28 +00:00
tr ( m_restoring ? " Specify a new wallet file name for your restored wallet (e.g., MyWallet). \n "
" Wallet file name (or Ctrl-C to quit): " :
" Specify wallet file name (e.g., MyWallet). If the wallet doesn't exist, it will be created. \n "
" Wallet file name (or Ctrl-C to quit): " )
2016-10-11 01:45:21 +00:00
) ;
if ( std : : cin . eof ( ) )
{
LOG_ERROR ( " Unexpected std::cin.eof() - Exited simple_wallet::ask_wallet_create_if_needed() " ) ;
return false ;
}
if ( ! tools : : wallet2 : : wallet_valid_path_format ( wallet_path ) )
{
fail_msg_writer ( ) < < tr ( " Wallet name not valid. Please try again or use Ctrl-C to quit. " ) ;
wallet_name_valid = false ;
}
else
{
tools : : wallet2 : : wallet_exists ( wallet_path , keys_file_exists , wallet_file_exists ) ;
LOG_PRINT_L3 ( " wallet_path: " < < wallet_path < < " " ) ;
LOG_PRINT_L3 ( " keys_file_exists: " < < std : : boolalpha < < keys_file_exists < < std : : noboolalpha
< < " wallet_file_exists: " < < std : : boolalpha < < wallet_file_exists < < std : : noboolalpha ) ;
2014-06-09 00:04:32 +00:00
2016-10-11 01:45:21 +00:00
if ( ( keys_file_exists | | wallet_file_exists ) & & ( ! m_generate_new . empty ( ) | | m_restoring ) )
{
fail_msg_writer ( ) < < tr ( " Attempting to generate or restore wallet, but specified file(s) exist. Exiting to not risk overwriting. " ) ;
return false ;
}
if ( wallet_file_exists & & keys_file_exists ) //Yes wallet, yes keys
{
success_msg_writer ( ) < < tr ( " Wallet and key files found, loading... " ) ;
m_wallet_file = wallet_path ;
return true ;
}
else if ( ! wallet_file_exists & & keys_file_exists ) //No wallet, yes keys
{
success_msg_writer ( ) < < tr ( " Key file found but not wallet file. Regenerating... " ) ;
m_wallet_file = wallet_path ;
return true ;
}
else if ( wallet_file_exists & & ! keys_file_exists ) //Yes wallet, no keys
{
fail_msg_writer ( ) < < tr ( " Key file not found. Failed to open wallet: " ) < < " \" " < < wallet_path < < " \" . Exiting. " ;
return false ;
}
else if ( ! wallet_file_exists & & ! keys_file_exists ) //No wallet, no keys
{
2017-08-06 11:28:00 +00:00
bool ok = true ;
if ( ! m_restoring )
2016-10-11 01:45:21 +00:00
{
2017-08-06 11:28:00 +00:00
message_writer ( ) < < tr ( " No wallet found with that name. Confirm creation of new wallet named: " ) < < wallet_path ;
2017-10-28 18:13:42 +00:00
confirm_creation = input_line ( tr ( " (Y/Yes/N/No): " ) ) ;
2017-08-06 11:28:00 +00:00
if ( std : : cin . eof ( ) )
{
LOG_ERROR ( " Unexpected std::cin.eof() - Exited simple_wallet::ask_wallet_create_if_needed() " ) ;
return false ;
}
ok = command_line : : is_yes ( confirm_creation ) ;
2016-10-11 01:45:21 +00:00
}
2017-08-06 11:28:00 +00:00
if ( ok )
2016-10-11 01:45:21 +00:00
{
success_msg_writer ( ) < < tr ( " Generating new wallet... " ) ;
m_generate_new = wallet_path ;
return true ;
}
}
}
} while ( ! wallet_name_valid ) ;
2014-05-03 16:19:43 +00:00
2016-10-11 01:45:21 +00:00
LOG_ERROR ( " Failed out of do-while loop in ask_wallet_create_if_needed() " ) ;
return false ;
2014-05-03 16:19:43 +00:00
}
2014-10-19 09:09:45 +00:00
/*!
* \ brief Prints the seed with a nice message
* \ param seed seed to print
*/
2018-07-06 23:03:15 +00:00
void simple_wallet : : print_seed ( const epee : : wipeable_string & seed )
2014-10-19 09:09:45 +00:00
{
2017-11-28 16:22:26 +00:00
success_msg_writer ( true ) < < " \n " < < tr ( " NOTE: the following 25 words can be used to recover access to your wallet. "
" Write them down and store them somewhere safe and secure. Please do not store them in "
2015-07-14 19:28:25 +00:00
" your email or on file storage services outside of your immediate control. \n " ) ;
2015-05-27 10:37:38 +00:00
// don't log
2018-07-06 23:03:15 +00:00
int space_index = 0 ;
size_t len = seed . size ( ) ;
for ( const char * ptr = seed . data ( ) ; len - - ; + + ptr )
{
if ( * ptr = = ' ' )
{
if ( space_index = = 15 | | space_index = = 7 )
putchar ( ' \n ' ) ;
else
putchar ( * ptr ) ;
+ + space_index ;
}
else
putchar ( * ptr ) ;
}
putchar ( ' \n ' ) ;
fflush ( stdout ) ;
2014-10-19 09:09:45 +00:00
}
2014-05-03 16:19:43 +00:00
//----------------------------------------------------------------------------------------------------
2018-07-06 23:03:15 +00:00
static bool might_be_partial_seed ( const epee : : wipeable_string & words )
2017-04-16 10:52:30 +00:00
{
2018-07-06 23:03:15 +00:00
std : : vector < epee : : wipeable_string > seed ;
2017-04-16 10:52:30 +00:00
2018-07-06 23:03:15 +00:00
words . split ( seed ) ;
2017-04-16 10:52:30 +00:00
return seed . size ( ) < 24 ;
}
//----------------------------------------------------------------------------------------------------
2014-03-03 22:07:58 +00:00
bool simple_wallet : : init ( const boost : : program_options : : variables_map & vm )
{
2018-07-06 23:03:15 +00:00
epee : : misc_utils : : auto_scope_leave_caller scope_exit_handler = epee : : misc_utils : : create_scope_leave_handler ( [ & ] ( ) {
m_electrum_seed . wipe ( ) ;
} ) ;
2018-02-16 11:04:04 +00:00
const bool testnet = tools : : wallet2 : : has_testnet_option ( vm ) ;
const bool stagenet = tools : : wallet2 : : has_stagenet_option ( vm ) ;
if ( testnet & & stagenet )
{
fail_msg_writer ( ) < < tr ( " Can't specify more than one of --testnet and --stagenet " ) ;
return false ;
}
const network_type nettype = testnet ? TESTNET : stagenet ? STAGENET : MAINNET ;
2018-07-06 23:03:15 +00:00
epee : : wipeable_string multisig_keys ;
2017-11-09 10:59:41 +00:00
2015-11-22 19:03:10 +00:00
if ( ! handle_command_line ( vm ) )
return false ;
2014-03-03 22:07:58 +00:00
2018-02-20 16:01:27 +00:00
if ( ( ! m_generate_new . empty ( ) ) + ( ! m_wallet_file . empty ( ) ) + ( ! m_generate_from_device . empty ( ) ) + ( ! m_generate_from_view_key . empty ( ) ) + ( ! m_generate_from_spend_key . empty ( ) ) + ( ! m_generate_from_keys . empty ( ) ) + ( ! m_generate_from_multisig_keys . empty ( ) ) + ( ! m_generate_from_json . empty ( ) ) > 1 )
2014-04-02 16:00:17 +00:00
{
2018-02-20 16:01:27 +00:00
fail_msg_writer ( ) < < tr ( " can't specify more than one of --generate-new-wallet= \" wallet_name \" , --wallet-file= \" wallet_name \" , --generate-from-view-key= \" wallet_name \" , --generate-from-spend-key= \" wallet_name \" , --generate-from-keys= \" wallet_name \" , --generate-from-multisig-keys= \" wallet_name \" , --generate-from-json= \" jsonfilename \" and --generate-from-device= \" wallet_name \" " ) ;
2014-06-08 22:59:02 +00:00
return false ;
}
2018-02-20 16:01:27 +00:00
else if ( m_generate_new . empty ( ) & & m_wallet_file . empty ( ) & & m_generate_from_device . empty ( ) & & m_generate_from_view_key . empty ( ) & & m_generate_from_spend_key . empty ( ) & & m_generate_from_keys . empty ( ) & & m_generate_from_multisig_keys . empty ( ) & & m_generate_from_json . empty ( ) )
2014-06-08 22:59:02 +00:00
{
if ( ! ask_wallet_create_if_needed ( ) ) return false ;
2014-04-02 16:00:17 +00:00
}
2014-03-03 22:07:58 +00:00
2016-08-09 23:54:20 +00:00
if ( ! m_generate_new . empty ( ) | | m_restoring )
2014-03-03 22:07:58 +00:00
{
2018-03-16 04:11:45 +00:00
if ( ! m_subaddress_lookahead . empty ( ) & & ! parse_subaddress_lookahead ( m_subaddress_lookahead ) )
return false ;
2014-10-02 12:45:18 +00:00
std : : string old_language ;
2014-06-04 22:59:47 +00:00
// check for recover flag. if present, require electrum word list (only recovery option for now).
2017-11-09 10:59:41 +00:00
if ( m_restore_deterministic_wallet | | m_restore_multisig_wallet )
2014-06-04 22:59:47 +00:00
{
2014-06-09 00:04:32 +00:00
if ( m_non_deterministic )
{
2017-11-09 10:59:41 +00:00
fail_msg_writer ( ) < < tr ( " can't specify both --restore-deterministic-wallet or --restore-multisig-wallet and --non-deterministic " ) ;
2014-06-09 00:04:32 +00:00
return false ;
}
2017-06-07 14:46:59 +00:00
if ( ! m_wallet_file . empty ( ) )
{
2017-11-09 10:59:41 +00:00
if ( m_restore_multisig_wallet )
fail_msg_writer ( ) < < tr ( " --restore-multisig-wallet uses --generate-new-wallet, not --wallet-file " ) ;
else
fail_msg_writer ( ) < < tr ( " --restore-deterministic-wallet uses --generate-new-wallet, not --wallet-file " ) ;
2017-06-07 14:46:59 +00:00
return false ;
}
2014-06-09 00:04:32 +00:00
2014-06-04 22:59:47 +00:00
if ( m_electrum_seed . empty ( ) )
{
2017-11-09 10:59:41 +00:00
if ( m_restore_multisig_wallet )
2014-06-08 22:59:02 +00:00
{
2018-07-06 23:03:15 +00:00
const char * prompt = " Specify multisig seed " ;
m_electrum_seed = input_secure_line ( prompt ) ;
2017-11-09 10:59:41 +00:00
if ( std : : cin . eof ( ) )
return false ;
if ( m_electrum_seed . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " specify a recovery parameter with the --electrum-seed= \" multisig seed here \" " ) ;
return false ;
}
}
else
{
m_electrum_seed = " " ;
do
2017-04-16 10:52:30 +00:00
{
2018-07-06 23:03:15 +00:00
const char * prompt = m_electrum_seed . empty ( ) ? " Specify Electrum seed " : " Electrum seed continued " ;
epee : : wipeable_string electrum_seed = input_secure_line ( prompt ) ;
2017-11-09 10:59:41 +00:00
if ( std : : cin . eof ( ) )
return false ;
if ( electrum_seed . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " specify a recovery parameter with the --electrum-seed= \" words list here \" " ) ;
return false ;
}
2018-07-06 23:03:15 +00:00
m_electrum_seed + = electrum_seed ;
m_electrum_seed + = ' ' ;
2017-11-09 10:59:41 +00:00
} while ( might_be_partial_seed ( m_electrum_seed ) ) ;
}
2014-06-04 22:59:47 +00:00
}
2014-06-09 00:04:32 +00:00
2017-11-09 10:59:41 +00:00
if ( m_restore_multisig_wallet )
2014-06-04 22:59:47 +00:00
{
2018-07-06 23:03:15 +00:00
const boost : : optional < epee : : wipeable_string > parsed = m_electrum_seed . parse_hexstr ( ) ;
if ( ! parsed )
2017-11-09 10:59:41 +00:00
{
fail_msg_writer ( ) < < tr ( " Multisig seed failed verification " ) ;
return false ;
}
2018-07-06 23:03:15 +00:00
multisig_keys = * parsed ;
2017-11-09 10:59:41 +00:00
}
else
{
if ( ! crypto : : ElectrumWords : : words_to_bytes ( m_electrum_seed , m_recovery_key , old_language ) )
{
fail_msg_writer ( ) < < tr ( " Electrum-style word list failed verification " ) ;
return false ;
}
2014-06-04 22:59:47 +00:00
}
2017-08-06 15:51:40 +00:00
2018-07-07 10:09:59 +00:00
auto pwd_container = password_prompter ( tr ( " Enter seed offset passphrase, empty if none " ) , false ) ;
2017-08-06 15:51:40 +00:00
if ( std : : cin . eof ( ) | | ! pwd_container )
return false ;
2017-11-25 14:50:15 +00:00
epee : : wipeable_string seed_pass = pwd_container - > password ( ) ;
2017-08-06 15:51:40 +00:00
if ( ! seed_pass . empty ( ) )
2017-11-09 10:59:41 +00:00
{
if ( m_restore_multisig_wallet )
{
crypto : : secret_key key ;
crypto : : cn_slow_hash ( seed_pass . data ( ) , seed_pass . size ( ) , ( crypto : : hash & ) key ) ;
sc_reduce32 ( ( unsigned char * ) key . data ) ;
2018-07-06 23:03:15 +00:00
multisig_keys = m_wallet - > decrypt < epee : : wipeable_string > ( std : : string ( multisig_keys . data ( ) , multisig_keys . size ( ) ) , key , true ) ;
2017-11-09 10:59:41 +00:00
}
else
m_recovery_key = cryptonote : : decrypt_key ( m_recovery_key , seed_pass ) ;
}
2014-06-04 22:59:47 +00:00
}
2018-07-30 11:39:05 +00:00
epee : : wipeable_string password ;
2015-06-20 11:31:53 +00:00
if ( ! m_generate_from_view_key . empty ( ) )
{
2016-11-09 03:55:41 +00:00
m_wallet_file = m_generate_from_view_key ;
2016-02-27 11:53:11 +00:00
// parse address
2017-10-28 18:13:42 +00:00
std : : string address_string = input_line ( " Standard address: " ) ;
2016-03-29 16:52:45 +00:00
if ( std : : cin . eof ( ) )
return false ;
2016-02-27 11:53:11 +00:00
if ( address_string . empty ( ) ) {
fail_msg_writer ( ) < < tr ( " No data supplied, cancelled " ) ;
2015-06-20 11:31:53 +00:00
return false ;
}
2017-02-19 02:42:10 +00:00
cryptonote : : address_parse_info info ;
2018-02-16 11:04:04 +00:00
if ( ! get_account_address_from_str ( info , nettype , address_string ) )
2015-06-20 11:31:53 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " failed to parse address " ) ;
2015-06-20 11:31:53 +00:00
return false ;
}
2017-02-19 02:42:10 +00:00
if ( info . is_subaddress )
{
fail_msg_writer ( ) < < tr ( " This address is a subaddress which cannot be used here. " ) ;
return false ;
}
2015-06-20 11:31:53 +00:00
// parse view secret key
2018-08-27 08:44:15 +00:00
epee : : wipeable_string viewkey_string = input_secure_line ( " Secret view key: " ) ;
2016-03-29 16:52:45 +00:00
if ( std : : cin . eof ( ) )
return false ;
2016-02-27 11:53:11 +00:00
if ( viewkey_string . empty ( ) ) {
fail_msg_writer ( ) < < tr ( " No data supplied, cancelled " ) ;
return false ;
}
2018-08-27 08:44:15 +00:00
crypto : : secret_key viewkey ;
2018-10-12 12:54:17 +00:00
if ( ! viewkey_string . hex_to_pod ( unwrap ( unwrap ( viewkey ) ) ) )
2015-06-20 11:31:53 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " failed to parse view key secret key " ) ;
2015-06-20 11:31:53 +00:00
return false ;
}
2016-08-01 00:48:53 +00:00
m_wallet_file = m_generate_from_view_key ;
2015-06-20 11:31:53 +00:00
2016-02-05 22:41:45 +00:00
// check the view key matches the given address
crypto : : public_key pkey ;
if ( ! crypto : : secret_key_to_public_key ( viewkey , pkey ) ) {
fail_msg_writer ( ) < < tr ( " failed to verify view key secret key " ) ;
return false ;
}
2017-02-19 02:42:10 +00:00
if ( info . address . m_view_public_key ! = pkey ) {
2016-02-05 22:41:45 +00:00
fail_msg_writer ( ) < < tr ( " view key does not match standard address " ) ;
2015-06-20 11:31:53 +00:00
return false ;
}
2018-07-30 11:39:05 +00:00
auto r = new_wallet ( vm , info . address , boost : : none , viewkey ) ;
2015-11-29 22:24:15 +00:00
CHECK_AND_ASSERT_MES ( r , false , tr ( " account creation failed " ) ) ;
2018-07-30 11:39:05 +00:00
password = * r ;
2015-06-20 11:31:53 +00:00
}
2017-10-09 23:31:46 +00:00
else if ( ! m_generate_from_spend_key . empty ( ) )
{
m_wallet_file = m_generate_from_spend_key ;
// parse spend secret key
2018-08-27 08:44:15 +00:00
epee : : wipeable_string spendkey_string = input_secure_line ( " Secret spend key: " ) ;
2017-10-09 23:31:46 +00:00
if ( std : : cin . eof ( ) )
return false ;
if ( spendkey_string . empty ( ) ) {
fail_msg_writer ( ) < < tr ( " No data supplied, cancelled " ) ;
return false ;
}
2018-08-27 08:44:15 +00:00
if ( ! spendkey_string . hex_to_pod ( unwrap ( unwrap ( m_recovery_key ) ) ) )
2017-10-09 23:31:46 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse spend key secret key " ) ;
return false ;
}
2018-07-30 11:39:05 +00:00
auto r = new_wallet ( vm , m_recovery_key , true , false , " " ) ;
2017-10-09 23:31:46 +00:00
CHECK_AND_ASSERT_MES ( r , false , tr ( " account creation failed " ) ) ;
2018-07-30 11:39:05 +00:00
password = * r ;
2017-10-09 23:31:46 +00:00
}
2016-02-22 22:10:55 +00:00
else if ( ! m_generate_from_keys . empty ( ) )
{
2016-11-09 03:55:41 +00:00
m_wallet_file = m_generate_from_keys ;
2015-06-20 11:31:53 +00:00
// parse address
2017-10-28 18:13:42 +00:00
std : : string address_string = input_line ( " Standard address: " ) ;
2016-03-29 16:52:45 +00:00
if ( std : : cin . eof ( ) )
return false ;
2016-02-27 11:53:11 +00:00
if ( address_string . empty ( ) ) {
fail_msg_writer ( ) < < tr ( " No data supplied, cancelled " ) ;
2016-02-22 22:10:55 +00:00
return false ;
}
2017-02-19 02:42:10 +00:00
cryptonote : : address_parse_info info ;
2018-02-16 11:04:04 +00:00
if ( ! get_account_address_from_str ( info , nettype , address_string ) )
2015-06-20 11:31:53 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " failed to parse address " ) ;
2015-06-20 11:31:53 +00:00
return false ;
}
2017-02-19 02:42:10 +00:00
if ( info . is_subaddress )
{
fail_msg_writer ( ) < < tr ( " This address is a subaddress which cannot be used here. " ) ;
return false ;
}
2015-06-20 11:31:53 +00:00
2016-02-22 22:10:55 +00:00
// parse spend secret key
2018-08-27 08:44:15 +00:00
epee : : wipeable_string spendkey_string = input_secure_line ( " Secret spend key: " ) ;
2016-03-29 16:52:45 +00:00
if ( std : : cin . eof ( ) )
return false ;
2016-02-27 11:53:11 +00:00
if ( spendkey_string . empty ( ) ) {
fail_msg_writer ( ) < < tr ( " No data supplied, cancelled " ) ;
return false ;
}
2018-08-27 08:44:15 +00:00
crypto : : secret_key spendkey ;
if ( ! spendkey_string . hex_to_pod ( unwrap ( unwrap ( spendkey ) ) ) )
2016-02-22 22:10:55 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse spend key secret key " ) ;
return false ;
}
2015-06-20 11:31:53 +00:00
// parse view secret key
2018-08-27 08:44:15 +00:00
epee : : wipeable_string viewkey_string = input_secure_line ( " Secret view key: " ) ;
2016-03-29 16:52:45 +00:00
if ( std : : cin . eof ( ) )
return false ;
2016-02-27 11:53:11 +00:00
if ( viewkey_string . empty ( ) ) {
fail_msg_writer ( ) < < tr ( " No data supplied, cancelled " ) ;
return false ;
}
2018-08-27 08:44:15 +00:00
crypto : : secret_key viewkey ;
if ( ! viewkey_string . hex_to_pod ( unwrap ( unwrap ( viewkey ) ) ) )
2015-06-20 11:31:53 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " failed to parse view key secret key " ) ;
2015-06-20 11:31:53 +00:00
return false ;
}
2016-08-01 00:48:53 +00:00
m_wallet_file = m_generate_from_keys ;
2015-06-20 11:31:53 +00:00
2016-02-22 22:10:55 +00:00
// check the spend and view keys match the given address
2016-02-05 22:41:45 +00:00
crypto : : public_key pkey ;
2016-02-22 22:10:55 +00:00
if ( ! crypto : : secret_key_to_public_key ( spendkey , pkey ) ) {
fail_msg_writer ( ) < < tr ( " failed to verify spend key secret key " ) ;
return false ;
}
2017-02-19 02:42:10 +00:00
if ( info . address . m_spend_public_key ! = pkey ) {
2016-02-22 22:10:55 +00:00
fail_msg_writer ( ) < < tr ( " spend key does not match standard address " ) ;
return false ;
}
2016-02-05 22:41:45 +00:00
if ( ! crypto : : secret_key_to_public_key ( viewkey , pkey ) ) {
fail_msg_writer ( ) < < tr ( " failed to verify view key secret key " ) ;
return false ;
}
2017-02-19 02:42:10 +00:00
if ( info . address . m_view_public_key ! = pkey ) {
2016-02-05 22:41:45 +00:00
fail_msg_writer ( ) < < tr ( " view key does not match standard address " ) ;
return false ;
}
2018-07-30 11:39:05 +00:00
auto r = new_wallet ( vm , info . address , spendkey , viewkey ) ;
2015-11-29 22:24:15 +00:00
CHECK_AND_ASSERT_MES ( r , false , tr ( " account creation failed " ) ) ;
2018-07-30 11:39:05 +00:00
password = * r ;
2015-06-20 11:31:53 +00:00
}
2017-07-28 23:41:24 +00:00
// Asks user for all the data required to merge secret keys from multisig wallets into one master wallet, which then gets full control of the multisig wallet. The resulting wallet will be the same as any other regular wallet.
else if ( ! m_generate_from_multisig_keys . empty ( ) )
{
m_wallet_file = m_generate_from_multisig_keys ;
unsigned int multisig_m ;
unsigned int multisig_n ;
// parse multisig type
2017-10-28 18:13:42 +00:00
std : : string multisig_type_string = input_line ( " Multisig type (input as M/N with M <= N and M > 1): " ) ;
2017-07-28 23:41:24 +00:00
if ( std : : cin . eof ( ) )
return false ;
if ( multisig_type_string . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " No data supplied, cancelled " ) ;
return false ;
}
if ( sscanf ( multisig_type_string . c_str ( ) , " %u/%u " , & multisig_m , & multisig_n ) ! = 2 )
{
2017-07-29 11:49:12 +00:00
fail_msg_writer ( ) < < tr ( " Error: expected M/N, but got: " ) < < multisig_type_string ;
2017-07-28 23:41:24 +00:00
return false ;
}
if ( multisig_m < = 1 | | multisig_m > multisig_n )
{
2017-07-29 11:49:12 +00:00
fail_msg_writer ( ) < < tr ( " Error: expected N > 1 and N <= M, but got: " ) < < multisig_type_string ;
2017-07-28 23:41:24 +00:00
return false ;
}
if ( multisig_m ! = multisig_n )
{
2017-07-29 11:49:12 +00:00
fail_msg_writer ( ) < < tr ( " Error: M/N is currently unsupported. " ) ;
2017-07-28 23:41:24 +00:00
return false ;
}
2017-07-29 11:49:12 +00:00
message_writer ( ) < < boost : : format ( tr ( " Generating master wallet from %u of %u multisig wallet keys " ) ) % multisig_m % multisig_n ;
2017-07-28 23:41:24 +00:00
// parse multisig address
2017-10-28 18:13:42 +00:00
std : : string address_string = input_line ( " Multisig wallet address: " ) ;
2017-07-28 23:41:24 +00:00
if ( std : : cin . eof ( ) )
return false ;
if ( address_string . empty ( ) ) {
fail_msg_writer ( ) < < tr ( " No data supplied, cancelled " ) ;
return false ;
}
2017-02-19 02:42:10 +00:00
cryptonote : : address_parse_info info ;
2018-02-16 11:04:04 +00:00
if ( ! get_account_address_from_str ( info , nettype , address_string ) )
2017-07-28 23:41:24 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse address " ) ;
return false ;
}
// parse secret view key
2018-08-27 08:44:15 +00:00
epee : : wipeable_string viewkey_string = input_secure_line ( " Secret view key: " ) ;
2017-07-28 23:41:24 +00:00
if ( std : : cin . eof ( ) )
return false ;
if ( viewkey_string . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " No data supplied, cancelled " ) ;
return false ;
}
2018-08-27 08:44:15 +00:00
crypto : : secret_key viewkey ;
if ( ! viewkey_string . hex_to_pod ( unwrap ( unwrap ( viewkey ) ) ) )
2017-07-28 23:41:24 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse secret view key " ) ;
return false ;
}
// check that the view key matches the given address
crypto : : public_key pkey ;
if ( ! crypto : : secret_key_to_public_key ( viewkey , pkey ) )
{
fail_msg_writer ( ) < < tr ( " failed to verify secret view key " ) ;
return false ;
}
2017-02-19 02:42:10 +00:00
if ( info . address . m_view_public_key ! = pkey )
2017-07-28 23:41:24 +00:00
{
fail_msg_writer ( ) < < tr ( " view key does not match standard address " ) ;
return false ;
}
// parse multisig spend keys
crypto : : secret_key spendkey ;
// parsing N/N
if ( multisig_m = = multisig_n )
{
std : : vector < crypto : : secret_key > multisig_secret_spendkeys ( multisig_n ) ;
2018-08-27 08:44:15 +00:00
epee : : wipeable_string spendkey_string ;
2017-07-28 23:41:24 +00:00
cryptonote : : blobdata spendkey_data ;
// get N secret spend keys from user
for ( unsigned int i = 0 ; i < multisig_n ; + + i )
{
2018-08-27 08:44:15 +00:00
spendkey_string = input_secure_line ( tr ( ( boost : : format ( tr ( " Secret spend key (%u of %u): " ) ) % ( i + 1 ) % multisig_m ) . str ( ) . c_str ( ) ) ) ;
2017-07-28 23:41:24 +00:00
if ( std : : cin . eof ( ) )
return false ;
if ( spendkey_string . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " No data supplied, cancelled " ) ;
return false ;
}
2018-08-27 08:44:15 +00:00
if ( ! spendkey_string . hex_to_pod ( unwrap ( unwrap ( multisig_secret_spendkeys [ i ] ) ) ) )
2017-07-28 23:41:24 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse spend key secret key " ) ;
return false ;
}
}
// sum the spend keys together to get the master spend key
spendkey = multisig_secret_spendkeys [ 0 ] ;
for ( unsigned int i = 1 ; i < multisig_n ; + + i )
2017-07-29 11:49:12 +00:00
sc_add ( reinterpret_cast < unsigned char * > ( & spendkey ) , reinterpret_cast < unsigned char * > ( & spendkey ) , reinterpret_cast < unsigned char * > ( & multisig_secret_spendkeys [ i ] ) ) ;
2017-07-28 23:41:24 +00:00
}
// parsing M/N
else
{
2017-07-29 11:49:12 +00:00
fail_msg_writer ( ) < < tr ( " Error: M/N is currently unsupported " ) ;
2017-07-28 23:41:24 +00:00
return false ;
}
// check that the spend key matches the given address
if ( ! crypto : : secret_key_to_public_key ( spendkey , pkey ) )
{
fail_msg_writer ( ) < < tr ( " failed to verify spend key secret key " ) ;
return false ;
}
2017-02-19 02:42:10 +00:00
if ( info . address . m_spend_public_key ! = pkey )
2017-07-28 23:41:24 +00:00
{
fail_msg_writer ( ) < < tr ( " spend key does not match standard address " ) ;
return false ;
}
// create wallet
2018-07-30 11:39:05 +00:00
auto r = new_wallet ( vm , info . address , spendkey , viewkey ) ;
2017-07-28 23:41:24 +00:00
CHECK_AND_ASSERT_MES ( r , false , tr ( " account creation failed " ) ) ;
2018-07-30 11:39:05 +00:00
password = * r ;
2017-07-28 23:41:24 +00:00
}
wallet: add a --generate-from-json flag
It takes a filename containing JSON data to generate a wallet.
The following fields are valid:
version: integer, should be 1
filename: string, path/filename for the newly created wallet
scan_from_height: 64 bit unsigned integer, optional
password: string, optional
viewkey: string, hex representation
spendkey: string, hex representation
seed: string, optional, list of words separated by spaces
Either seed or private keys should be given. If using private
keys, the spend key may be omitted (the wallet will not be
able to spend, but will see incoming transactions).
If scan_from_height is given, blocks below this height will not
be checked for transactions as an optimization.
2016-03-25 00:48:11 +00:00
else if ( ! m_generate_from_json . empty ( ) )
{
2017-10-28 22:04:24 +00:00
try
{
2018-10-01 11:18:50 +00:00
auto rc = tools : : wallet2 : : make_from_json ( vm , false , m_generate_from_json , password_prompter ) ;
m_wallet = std : : move ( rc . first ) ;
password = rc . second . password ( ) ;
2018-09-19 19:55:38 +00:00
m_wallet_file = m_wallet - > path ( ) ;
2017-10-28 22:04:24 +00:00
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < e . what ( ) ;
return false ;
}
2016-11-13 02:55:08 +00:00
if ( ! m_wallet )
wallet: add a --generate-from-json flag
It takes a filename containing JSON data to generate a wallet.
The following fields are valid:
version: integer, should be 1
filename: string, path/filename for the newly created wallet
scan_from_height: 64 bit unsigned integer, optional
password: string, optional
viewkey: string, hex representation
spendkey: string, hex representation
seed: string, optional, list of words separated by spaces
Either seed or private keys should be given. If using private
keys, the spend key may be omitted (the wallet will not be
able to spend, but will see incoming transactions).
If scan_from_height is given, blocks below this height will not
be checked for transactions as an optimization.
2016-03-25 00:48:11 +00:00
return false ;
}
2018-02-20 16:01:27 +00:00
else if ( ! m_generate_from_device . empty ( ) )
{
m_wallet_file = m_generate_from_device ;
// create wallet
2018-08-23 22:50:31 +00:00
auto r = new_wallet ( vm ) ;
2018-02-20 16:01:27 +00:00
CHECK_AND_ASSERT_MES ( r , false , tr ( " account creation failed " ) ) ;
2018-07-30 11:39:05 +00:00
password = * r ;
2018-03-22 21:52:33 +00:00
// if no block_height is specified, assume its a new account and start it "now"
if ( m_wallet - > get_refresh_from_block_height ( ) = = 0 ) {
{
tools : : scoped_message_writer wrt = tools : : msg_writer ( ) ;
wrt < < tr ( " No restore height is specified. " ) ;
wrt < < tr ( " Assumed you are creating a new account, restore will be done from current estimated blockchain height. " ) ;
wrt < < tr ( " Use --restore-height if you want to restore an already setup account from a specific height " ) ;
}
std : : string confirm = input_line ( tr ( " Is this okay? (Y/Yes/N/No): " ) ) ;
if ( std : : cin . eof ( ) | | ! command_line : : is_yes ( confirm ) )
CHECK_AND_ASSERT_MES ( false , false , tr ( " account creation aborted " ) ) ;
m_wallet - > set_refresh_from_block_height ( m_wallet - > estimate_blockchain_height ( ) - 1 ) ;
m_wallet - > explicit_refresh_from_block_height ( true ) ;
m_restore_height = m_wallet - > get_refresh_from_block_height ( ) ;
}
2018-02-20 16:01:27 +00:00
}
2015-06-20 11:31:53 +00:00
else
{
2017-06-07 14:46:59 +00:00
if ( m_generate_new . empty ( ) ) {
fail_msg_writer ( ) < < tr ( " specify a wallet path with --generate-new-wallet (not --wallet-file) " ) ;
return false ;
}
2016-11-09 03:55:41 +00:00
m_wallet_file = m_generate_new ;
2018-07-30 11:39:05 +00:00
boost : : optional < epee : : wipeable_string > r ;
2017-11-09 10:59:41 +00:00
if ( m_restore_multisig_wallet )
r = new_wallet ( vm , multisig_keys , old_language ) ;
else
r = new_wallet ( vm , m_recovery_key , m_restore_deterministic_wallet , m_non_deterministic , old_language ) ;
2015-11-29 22:24:15 +00:00
CHECK_AND_ASSERT_MES ( r , false , tr ( " account creation failed " ) ) ;
2018-07-30 11:39:05 +00:00
password = * r ;
2015-06-20 11:31:53 +00:00
}
2018-03-16 02:55:31 +00:00
2018-03-22 21:52:33 +00:00
if ( m_restoring & & m_generate_from_json . empty ( ) & & m_generate_from_device . empty ( ) )
2018-03-16 02:55:31 +00:00
{
m_wallet - > explicit_refresh_from_block_height ( ! command_line : : is_arg_defaulted ( vm , arg_restore_height ) ) ;
}
2018-01-23 14:42:11 +00:00
if ( ! m_wallet - > explicit_refresh_from_block_height ( ) & & m_restoring )
2016-12-25 08:18:15 +00:00
{
uint32_t version ;
bool connected = try_connect_to_daemon ( false , & version ) ;
while ( true )
{
std : : string heightstr ;
if ( ! connected | | version < MAKE_CORE_RPC_VERSION ( 1 , 6 ) )
2017-10-28 18:13:42 +00:00
heightstr = input_line ( " Restore from specific blockchain height (optional, default 0): " ) ;
2016-12-25 08:18:15 +00:00
else
2017-10-28 18:13:42 +00:00
heightstr = input_line ( " Restore from specific blockchain height (optional, default 0), \n or alternatively from specific date (YYYY-MM-DD): " ) ;
2016-12-25 08:18:15 +00:00
if ( std : : cin . eof ( ) )
return false ;
if ( heightstr . empty ( ) )
{
m_restore_height = 0 ;
break ;
}
try
{
m_restore_height = boost : : lexical_cast < uint64_t > ( heightstr ) ;
break ;
}
catch ( const boost : : bad_lexical_cast & )
{
if ( ! connected | | version < MAKE_CORE_RPC_VERSION ( 1 , 6 ) )
{
fail_msg_writer ( ) < < tr ( " bad m_restore_height parameter: " ) < < heightstr ;
continue ;
}
if ( heightstr . size ( ) ! = 10 | | heightstr [ 4 ] ! = ' - ' | | heightstr [ 7 ] ! = ' - ' )
{
fail_msg_writer ( ) < < tr ( " date format must be YYYY-MM-DD " ) ;
continue ;
}
uint16_t year ;
uint8_t month ; // 1, 2, ..., 12
uint8_t day ; // 1, 2, ..., 31
try
{
year = boost : : lexical_cast < uint16_t > ( heightstr . substr ( 0 , 4 ) ) ;
2018-01-19 07:54:14 +00:00
// lexical_cast<uint8_t> won't work because uint8_t is treated as character type
2016-12-25 08:18:15 +00:00
month = boost : : lexical_cast < uint16_t > ( heightstr . substr ( 5 , 2 ) ) ;
day = boost : : lexical_cast < uint16_t > ( heightstr . substr ( 8 , 2 ) ) ;
m_restore_height = m_wallet - > get_blockchain_height_by_date ( year , month , day ) ;
success_msg_writer ( ) < < tr ( " Restore height is: " ) < < m_restore_height ;
2017-10-28 18:13:42 +00:00
std : : string confirm = input_line ( tr ( " Is this okay? (Y/Yes/N/No): " ) ) ;
2016-12-25 08:18:15 +00:00
if ( std : : cin . eof ( ) )
return false ;
if ( command_line : : is_yes ( confirm ) )
break ;
}
catch ( const boost : : bad_lexical_cast & )
{
fail_msg_writer ( ) < < tr ( " bad m_restore_height parameter: " ) < < heightstr ;
}
catch ( const std : : runtime_error & e )
{
fail_msg_writer ( ) < < e . what ( ) ;
}
}
}
}
2017-09-29 18:06:14 +00:00
if ( m_restoring )
2017-11-16 23:00:06 +00:00
{
uint64_t estimate_height = m_wallet - > estimate_blockchain_height ( ) ;
if ( m_restore_height > = estimate_height )
{
success_msg_writer ( ) < < tr ( " Restore height " ) < < m_restore_height < < ( " is not yet reached. The current estimated height is " ) < < estimate_height ;
std : : string confirm = input_line ( tr ( " Still apply restore height? (Y/Yes/N/No): " ) ) ;
if ( std : : cin . eof ( ) | | command_line : : is_no ( confirm ) )
m_restore_height = 0 ;
}
2017-09-29 18:06:14 +00:00
m_wallet - > set_refresh_from_block_height ( m_restore_height ) ;
2017-11-16 23:00:06 +00:00
}
2018-07-30 11:39:05 +00:00
m_wallet - > rewrite ( m_wallet_file , password ) ;
2014-03-03 22:07:58 +00:00
}
else
{
2016-11-09 03:55:41 +00:00
assert ( ! m_wallet_file . empty ( ) ) ;
2018-03-16 04:11:45 +00:00
if ( ! m_subaddress_lookahead . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " can't specify --subaddress-lookahead and --wallet-file at the same time " ) ;
return false ;
}
2016-11-09 03:55:41 +00:00
bool r = open_wallet ( vm ) ;
2015-12-12 00:05:39 +00:00
CHECK_AND_ASSERT_MES ( r , false , tr ( " failed to open account " ) ) ;
2014-03-03 22:07:58 +00:00
}
2017-06-19 23:33:15 +00:00
if ( ! m_wallet )
{
fail_msg_writer ( ) < < tr ( " wallet is null " ) ;
return false ;
}
2016-12-08 20:01:24 +00:00
2018-08-10 12:15:40 +00:00
if ( ! m_wallet - > is_trusted_daemon ( ) )
2017-09-22 21:19:22 +00:00
message_writer ( ) < < ( boost : : format ( tr ( " Warning: using an untrusted daemon at %s, privacy will be lessened " ) ) % m_wallet - > get_daemon_address ( ) ) . str ( ) ;
2018-03-21 14:29:49 +00:00
if ( m_wallet - > get_ring_database ( ) . empty ( ) )
fail_msg_writer ( ) < < tr ( " Failed to initialize ring database: privacy enhancing features will be inactive " ) ;
2016-11-09 03:55:41 +00:00
m_wallet - > callback ( this ) ;
2017-05-28 12:17:32 +00:00
2014-03-03 22:07:58 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : deinit ( )
{
if ( ! m_wallet . get ( ) )
return true ;
return close_wallet ( ) ;
}
//----------------------------------------------------------------------------------------------------
2015-11-22 19:03:10 +00:00
bool simple_wallet : : handle_command_line ( const boost : : program_options : : variables_map & vm )
2014-03-03 22:07:58 +00:00
{
2014-06-09 00:04:32 +00:00
m_wallet_file = command_line : : get_arg ( vm , arg_wallet_file ) ;
m_generate_new = command_line : : get_arg ( vm , arg_generate_new_wallet ) ;
2018-02-20 16:01:27 +00:00
m_generate_from_device = command_line : : get_arg ( vm , arg_generate_from_device ) ;
2015-06-20 11:31:53 +00:00
m_generate_from_view_key = command_line : : get_arg ( vm , arg_generate_from_view_key ) ;
2017-10-09 23:31:46 +00:00
m_generate_from_spend_key = command_line : : get_arg ( vm , arg_generate_from_spend_key ) ;
2016-02-22 22:10:55 +00:00
m_generate_from_keys = command_line : : get_arg ( vm , arg_generate_from_keys ) ;
2017-07-28 23:41:24 +00:00
m_generate_from_multisig_keys = command_line : : get_arg ( vm , arg_generate_from_multisig_keys ) ;
wallet: add a --generate-from-json flag
It takes a filename containing JSON data to generate a wallet.
The following fields are valid:
version: integer, should be 1
filename: string, path/filename for the newly created wallet
scan_from_height: 64 bit unsigned integer, optional
password: string, optional
viewkey: string, hex representation
spendkey: string, hex representation
seed: string, optional, list of words separated by spaces
Either seed or private keys should be given. If using private
keys, the spend key may be omitted (the wallet will not be
able to spend, but will see incoming transactions).
If scan_from_height is given, blocks below this height will not
be checked for transactions as an optimization.
2016-03-25 00:48:11 +00:00
m_generate_from_json = command_line : : get_arg ( vm , arg_generate_from_json ) ;
2017-08-14 03:00:25 +00:00
m_mnemonic_language = command_line : : get_arg ( vm , arg_mnemonic_language ) ;
2014-06-09 00:04:32 +00:00
m_electrum_seed = command_line : : get_arg ( vm , arg_electrum_seed ) ;
m_restore_deterministic_wallet = command_line : : get_arg ( vm , arg_restore_deterministic_wallet ) ;
2017-11-09 10:59:41 +00:00
m_restore_multisig_wallet = command_line : : get_arg ( vm , arg_restore_multisig_wallet ) ;
2014-06-09 00:04:32 +00:00
m_non_deterministic = command_line : : get_arg ( vm , arg_non_deterministic ) ;
2016-07-10 15:49:40 +00:00
m_allow_mismatched_daemon_version = command_line : : get_arg ( vm , arg_allow_mismatched_daemon_version ) ;
2016-04-15 18:10:20 +00:00
m_restore_height = command_line : : get_arg ( vm , arg_restore_height ) ;
2017-10-06 01:14:09 +00:00
m_do_not_relay = command_line : : get_arg ( vm , arg_do_not_relay ) ;
2018-03-16 04:11:45 +00:00
m_subaddress_lookahead = command_line : : get_arg ( vm , arg_subaddress_lookahead ) ;
2018-03-17 22:46:41 +00:00
m_use_english_language_names = command_line : : get_arg ( vm , arg_use_english_language_names ) ;
2016-08-09 23:54:20 +00:00
m_restoring = ! m_generate_from_view_key . empty ( ) | |
2017-10-09 23:31:46 +00:00
! m_generate_from_spend_key . empty ( ) | |
2016-08-09 23:54:20 +00:00
! m_generate_from_keys . empty ( ) | |
2017-07-28 23:41:24 +00:00
! m_generate_from_multisig_keys . empty ( ) | |
2016-08-09 23:54:20 +00:00
! m_generate_from_json . empty ( ) | |
2018-02-20 16:01:27 +00:00
! m_generate_from_device . empty ( ) | |
2017-11-09 10:59:41 +00:00
m_restore_deterministic_wallet | |
m_restore_multisig_wallet ;
2015-11-22 19:03:10 +00:00
return true ;
2014-03-03 22:07:58 +00:00
}
//----------------------------------------------------------------------------------------------------
2016-12-23 12:04:54 +00:00
bool simple_wallet : : try_connect_to_daemon ( bool silent , uint32_t * version )
2014-03-03 22:07:58 +00:00
{
2016-12-23 12:04:54 +00:00
uint32_t version_ = 0 ;
if ( ! version )
version = & version_ ;
if ( ! m_wallet - > check_connection ( version ) )
2014-03-03 22:07:58 +00:00
{
2016-07-10 15:49:40 +00:00
if ( ! silent )
2016-11-09 03:55:41 +00:00
fail_msg_writer ( ) < < tr ( " wallet failed to connect to daemon: " ) < < m_wallet - > get_daemon_address ( ) < < " . " < <
2016-07-10 15:49:40 +00:00
tr ( " Daemon either is not started or wrong port was passed. "
2017-09-22 18:20:09 +00:00
" Please make sure daemon is running or change the daemon address using the 'set_daemon' command. " ) ;
2016-07-10 15:49:40 +00:00
return false ;
}
2016-12-23 12:04:54 +00:00
if ( ! m_allow_mismatched_daemon_version & & ( ( * version > > 16 ) ! = CORE_RPC_VERSION_MAJOR ) )
2016-07-10 15:49:40 +00:00
{
if ( ! silent )
2016-12-23 12:04:54 +00:00
fail_msg_writer ( ) < < boost : : format ( tr ( " Daemon uses a different RPC major version (%u) than the wallet (%u): %s. Either update one of them, or use --allow-mismatched-daemon-version. " ) ) % ( * version > > 16 ) % CORE_RPC_VERSION_MAJOR % m_wallet - > get_daemon_address ( ) ;
2014-03-20 11:46:11 +00:00
return false ;
2014-03-03 22:07:58 +00:00
}
2014-03-20 11:46:11 +00:00
return true ;
2014-03-03 22:07:58 +00:00
}
2014-06-04 22:59:47 +00:00
2014-09-27 12:50:15 +00:00
/*!
* \ brief Gets the word seed language from the user .
*
* User is asked to choose from a list of supported languages .
*
* \ return The chosen language .
*/
2014-09-25 12:34:30 +00:00
std : : string simple_wallet : : get_mnemonic_language ( )
{
2018-07-22 10:28:11 +00:00
std : : vector < std : : string > language_list_self , language_list_english ;
const std : : vector < std : : string > & language_list = m_use_english_language_names ? language_list_english : language_list_self ;
2014-09-25 12:34:30 +00:00
std : : string language_choice ;
int language_number = - 1 ;
2018-07-22 10:28:11 +00:00
crypto : : ElectrumWords : : get_language_list ( language_list_self , false ) ;
crypto : : ElectrumWords : : get_language_list ( language_list_english , true ) ;
2015-07-14 19:28:25 +00:00
std : : cout < < tr ( " List of available languages for your wallet's seed: " ) < < std : : endl ;
2018-03-17 22:46:41 +00:00
std : : cout < < tr ( " If your display freezes, exit blind with ^C, then run again with --use-english-language-names " ) < < std : : endl ;
2014-09-25 12:34:30 +00:00
int ii ;
2018-07-22 10:28:11 +00:00
std : : vector < std : : string > : : const_iterator it ;
2014-09-25 12:34:30 +00:00
for ( it = language_list . begin ( ) , ii = 0 ; it ! = language_list . end ( ) ; it + + , ii + + )
{
std : : cout < < ii < < " : " < < * it < < std : : endl ;
}
while ( language_number < 0 )
{
2017-10-28 18:13:42 +00:00
language_choice = input_line ( tr ( " Enter the number corresponding to the language of your choice: " ) ) ;
2016-03-29 16:52:45 +00:00
if ( std : : cin . eof ( ) )
return std : : string ( ) ;
2014-09-25 12:34:30 +00:00
try
{
language_number = std : : stoi ( language_choice ) ;
2014-10-02 12:45:18 +00:00
if ( ! ( ( language_number > = 0 ) & & ( static_cast < unsigned int > ( language_number ) < language_list . size ( ) ) ) )
2014-09-25 12:34:30 +00:00
{
language_number = - 1 ;
2018-01-09 21:37:30 +00:00
fail_msg_writer ( ) < < tr ( " invalid language choice entered. Please try again. \n " ) ;
2014-09-25 12:34:30 +00:00
}
}
2017-03-18 12:56:07 +00:00
catch ( const std : : exception & e )
2014-09-25 12:34:30 +00:00
{
2018-01-09 21:37:30 +00:00
fail_msg_writer ( ) < < tr ( " invalid language choice entered. Please try again. \n " ) ;
2014-09-25 12:34:30 +00:00
}
}
2018-07-22 10:28:11 +00:00
return language_list_self [ language_number ] ;
2014-09-25 12:34:30 +00:00
}
2016-12-17 23:07:15 +00:00
//----------------------------------------------------------------------------------------------------
boost : : optional < tools : : password_container > simple_wallet : : get_and_verify_password ( ) const
{
2017-10-28 18:13:42 +00:00
auto pwd_container = default_password_prompter ( m_wallet_file . empty ( ) ) ;
2016-12-17 23:07:15 +00:00
if ( ! pwd_container )
return boost : : none ;
2014-09-25 12:34:30 +00:00
2016-12-17 23:07:15 +00:00
if ( ! m_wallet - > verify_password ( pwd_container - > password ( ) ) )
{
fail_msg_writer ( ) < < tr ( " invalid password " ) ;
return boost : : none ;
}
return pwd_container ;
}
2014-03-03 22:07:58 +00:00
//----------------------------------------------------------------------------------------------------
2018-07-30 11:39:05 +00:00
boost : : optional < epee : : wipeable_string > simple_wallet : : new_wallet ( const boost : : program_options : : variables_map & vm ,
2016-11-09 03:55:41 +00:00
const crypto : : secret_key & recovery_key , bool recover , bool two_random , const std : : string & old_language )
2014-03-03 22:07:58 +00:00
{
2018-07-08 20:12:33 +00:00
auto rc = tools : : wallet2 : : make_new ( vm , false , password_prompter ) ;
2016-11-09 03:55:41 +00:00
m_wallet = std : : move ( rc . first ) ;
if ( ! m_wallet )
{
2018-07-30 11:39:05 +00:00
return { } ;
2016-11-09 03:55:41 +00:00
}
2018-07-30 11:39:05 +00:00
epee : : wipeable_string password = rc . second . password ( ) ;
2016-11-09 03:55:41 +00:00
2018-03-16 04:11:45 +00:00
if ( ! m_subaddress_lookahead . empty ( ) )
{
auto lookahead = parse_subaddress_lookahead ( m_subaddress_lookahead ) ;
assert ( lookahead ) ;
m_wallet - > set_subaddress_lookahead ( lookahead - > first , lookahead - > second ) ;
}
2014-10-18 17:31:43 +00:00
bool was_deprecated_wallet = m_restore_deterministic_wallet & & ( ( old_language = = crypto : : ElectrumWords : : old_language_name ) | |
crypto : : ElectrumWords : : get_is_old_style_seed ( m_electrum_seed ) ) ;
std : : string mnemonic_language = old_language ;
2017-08-14 03:00:25 +00:00
std : : vector < std : : string > language_list ;
crypto : : ElectrumWords : : get_language_list ( language_list ) ;
if ( mnemonic_language . empty ( ) & & std : : find ( language_list . begin ( ) , language_list . end ( ) , m_mnemonic_language ) ! = language_list . end ( ) )
{
mnemonic_language = m_mnemonic_language ;
}
2014-12-06 09:48:33 +00:00
// Ask for seed language if:
// it's a deterministic wallet AND
2017-08-14 03:00:25 +00:00
// a seed language is not already specified AND
2014-12-06 09:48:33 +00:00
// (it is not a wallet restore OR if it was a deprecated wallet
// that was earlier used before this restore)
2018-02-25 03:44:10 +00:00
if ( ( ! two_random ) & & ( mnemonic_language . empty ( ) | | mnemonic_language = = crypto : : ElectrumWords : : old_language_name ) & & ( ! m_restore_deterministic_wallet | | was_deprecated_wallet ) )
2014-10-18 17:31:43 +00:00
{
if ( was_deprecated_wallet )
{
// The user had used an older version of the wallet with old style mnemonics.
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
message_writer ( console_color_green , false ) < < " \n " < < tr ( " You had been using "
2015-07-14 19:28:25 +00:00
" a deprecated version of the wallet. Please use the new seed that we provide. \n " ) ;
2014-10-18 17:31:43 +00:00
}
mnemonic_language = get_mnemonic_language ( ) ;
2016-03-29 16:52:45 +00:00
if ( mnemonic_language . empty ( ) )
2018-07-30 11:39:05 +00:00
return { } ;
2014-10-18 17:31:43 +00:00
}
m_wallet - > set_seed_language ( mnemonic_language ) ;
2014-06-06 18:18:11 +00:00
2018-02-25 16:59:52 +00:00
bool create_address_file = command_line : : get_arg ( vm , arg_create_address_file ) ;
2014-06-06 18:18:11 +00:00
crypto : : secret_key recovery_val ;
2014-04-02 16:00:17 +00:00
try
{
2018-02-25 16:59:52 +00:00
recovery_val = m_wallet - > generate ( m_wallet_file , std : : move ( rc . second ) . password ( ) , recovery_key , recover , two_random , create_address_file ) ;
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
message_writer ( console_color_white , true ) < < tr ( " Generated new wallet: " )
2018-02-16 11:04:04 +00:00
< < m_wallet - > get_account ( ) . get_public_address_str ( m_wallet - > nettype ( ) ) ;
2018-07-08 20:12:33 +00:00
PAUSE_READLINE ( ) ;
std : : cout < < tr ( " View key: " ) ;
print_secret_key ( m_wallet - > get_account ( ) . get_keys ( ) . m_view_secret_key ) ;
putchar ( ' \n ' ) ;
2014-04-02 16:00:17 +00:00
}
catch ( const std : : exception & e )
{
2015-07-14 19:28:25 +00:00
fail_msg_writer ( ) < < tr ( " failed to generate new wallet: " ) < < e . what ( ) ;
2018-07-30 11:39:05 +00:00
return { } ;
2014-04-02 16:00:17 +00:00
}
2014-03-03 22:07:58 +00:00
2014-06-06 18:18:11 +00:00
// convert rng value to electrum-style word list
2018-07-06 23:03:15 +00:00
epee : : wipeable_string electrum_words ;
2014-09-25 12:34:30 +00:00
2014-10-02 12:45:18 +00:00
crypto : : ElectrumWords : : bytes_to_words ( recovery_val , electrum_words , mnemonic_language ) ;
2014-06-06 18:18:11 +00:00
2014-04-02 16:00:17 +00:00
success_msg_writer ( ) < <
" ********************************************************************** \n " < <
2015-12-12 00:05:39 +00:00
tr ( " Your wallet has been generated! \n "
2017-12-17 17:33:43 +00:00
" To start synchronizing with the daemon, use the \" refresh \" command. \n "
" Use the \" help \" command to see the list of available commands. \n "
2017-11-22 12:53:18 +00:00
" Use \" help <command> \" to see a command's documentation. \n "
2017-12-17 17:33:43 +00:00
" Always use the \" exit \" command when closing monero-wallet-cli to save \n "
" your current session's state. Otherwise, you might need to synchronize \n "
2015-12-12 00:05:39 +00:00
" your wallet again (your wallet keys are NOT at risk in any case). \n " )
2014-06-10 00:04:56 +00:00
;
if ( ! two_random )
{
2014-10-19 09:09:45 +00:00
print_seed ( electrum_words ) ;
2014-06-10 00:04:56 +00:00
}
success_msg_writer ( ) < < " ********************************************************************** " ;
2018-07-30 11:39:05 +00:00
return std : : move ( password ) ;
2014-03-03 22:07:58 +00:00
}
//----------------------------------------------------------------------------------------------------
2018-07-30 11:39:05 +00:00
boost : : optional < epee : : wipeable_string > simple_wallet : : new_wallet ( const boost : : program_options : : variables_map & vm ,
2016-11-09 03:55:41 +00:00
const cryptonote : : account_public_address & address , const boost : : optional < crypto : : secret_key > & spendkey ,
const crypto : : secret_key & viewkey )
2015-06-20 11:31:53 +00:00
{
2018-07-08 20:12:33 +00:00
auto rc = tools : : wallet2 : : make_new ( vm , false , password_prompter ) ;
2016-11-09 03:55:41 +00:00
m_wallet = std : : move ( rc . first ) ;
if ( ! m_wallet )
2015-06-20 11:31:53 +00:00
{
2018-07-30 11:39:05 +00:00
return { } ;
2015-06-20 11:31:53 +00:00
}
2018-07-30 11:39:05 +00:00
epee : : wipeable_string password = rc . second . password ( ) ;
2018-03-16 04:11:45 +00:00
if ( ! m_subaddress_lookahead . empty ( ) )
{
auto lookahead = parse_subaddress_lookahead ( m_subaddress_lookahead ) ;
assert ( lookahead ) ;
m_wallet - > set_subaddress_lookahead ( lookahead - > first , lookahead - > second ) ;
}
2016-04-29 05:02:55 +00:00
if ( m_restore_height )
m_wallet - > set_refresh_from_block_height ( m_restore_height ) ;
2016-02-22 22:10:55 +00:00
2018-02-25 16:59:52 +00:00
bool create_address_file = command_line : : get_arg ( vm , arg_create_address_file ) ;
2016-02-22 22:10:55 +00:00
try
{
2016-11-09 03:55:41 +00:00
if ( spendkey )
{
2018-02-25 16:59:52 +00:00
m_wallet - > generate ( m_wallet_file , std : : move ( rc . second ) . password ( ) , address , * spendkey , viewkey , create_address_file ) ;
2016-11-09 03:55:41 +00:00
}
else
{
2018-02-25 16:59:52 +00:00
m_wallet - > generate ( m_wallet_file , std : : move ( rc . second ) . password ( ) , address , viewkey , create_address_file ) ;
2016-11-09 03:55:41 +00:00
}
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
message_writer ( console_color_white , true ) < < tr ( " Generated new wallet: " )
2018-02-16 11:04:04 +00:00
< < m_wallet - > get_account ( ) . get_public_address_str ( m_wallet - > nettype ( ) ) ;
2016-02-22 22:10:55 +00:00
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " failed to generate new wallet: " ) < < e . what ( ) ;
2018-07-30 11:39:05 +00:00
return { } ;
2016-02-22 22:10:55 +00:00
}
2018-07-30 11:39:05 +00:00
return std : : move ( password ) ;
2018-02-20 16:01:27 +00:00
}
//----------------------------------------------------------------------------------------------------
2018-08-23 22:50:31 +00:00
boost : : optional < epee : : wipeable_string > simple_wallet : : new_wallet ( const boost : : program_options : : variables_map & vm )
{
2018-07-08 20:12:33 +00:00
auto rc = tools : : wallet2 : : make_new ( vm , false , password_prompter ) ;
2018-02-20 16:01:27 +00:00
m_wallet = std : : move ( rc . first ) ;
if ( ! m_wallet )
{
2018-07-30 11:39:05 +00:00
return { } ;
2018-02-20 16:01:27 +00:00
}
2018-07-30 11:39:05 +00:00
epee : : wipeable_string password = rc . second . password ( ) ;
2018-03-16 04:11:45 +00:00
if ( ! m_subaddress_lookahead . empty ( ) )
{
auto lookahead = parse_subaddress_lookahead ( m_subaddress_lookahead ) ;
assert ( lookahead ) ;
m_wallet - > set_subaddress_lookahead ( lookahead - > first , lookahead - > second ) ;
}
2018-02-20 16:01:27 +00:00
if ( m_restore_height )
m_wallet - > set_refresh_from_block_height ( m_restore_height ) ;
2018-08-23 22:50:31 +00:00
auto device_desc = tools : : wallet2 : : device_name_option ( vm ) ;
2018-02-20 16:01:27 +00:00
try
{
2018-09-03 11:13:23 +00:00
bool create_address_file = command_line : : get_arg ( vm , arg_create_address_file ) ;
2018-08-23 22:50:31 +00:00
m_wallet - > restore ( m_wallet_file , std : : move ( rc . second ) . password ( ) , device_desc . empty ( ) ? " Ledger " : device_desc , create_address_file ) ;
2018-03-22 21:52:33 +00:00
message_writer ( console_color_white , true ) < < tr ( " Generated new wallet on hw device: " )
2018-02-16 11:04:04 +00:00
< < m_wallet - > get_account ( ) . get_public_address_str ( m_wallet - > nettype ( ) ) ;
2018-02-20 16:01:27 +00:00
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " failed to generate new wallet: " ) < < e . what ( ) ;
2018-07-30 11:39:05 +00:00
return { } ;
2018-02-20 16:01:27 +00:00
}
2018-07-30 11:39:05 +00:00
return std : : move ( password ) ;
2017-11-09 10:59:41 +00:00
}
//----------------------------------------------------------------------------------------------------
2018-07-30 11:39:05 +00:00
boost : : optional < epee : : wipeable_string > simple_wallet : : new_wallet ( const boost : : program_options : : variables_map & vm ,
2018-07-06 23:03:15 +00:00
const epee : : wipeable_string & multisig_keys , const std : : string & old_language )
2017-11-09 10:59:41 +00:00
{
2018-07-08 20:12:33 +00:00
auto rc = tools : : wallet2 : : make_new ( vm , false , password_prompter ) ;
2017-11-09 10:59:41 +00:00
m_wallet = std : : move ( rc . first ) ;
if ( ! m_wallet )
{
2018-07-30 11:39:05 +00:00
return { } ;
2017-11-09 10:59:41 +00:00
}
2018-07-30 11:39:05 +00:00
epee : : wipeable_string password = rc . second . password ( ) ;
2017-11-09 10:59:41 +00:00
2018-03-16 04:11:45 +00:00
if ( ! m_subaddress_lookahead . empty ( ) )
{
auto lookahead = parse_subaddress_lookahead ( m_subaddress_lookahead ) ;
assert ( lookahead ) ;
m_wallet - > set_subaddress_lookahead ( lookahead - > first , lookahead - > second ) ;
}
2017-11-09 10:59:41 +00:00
std : : string mnemonic_language = old_language ;
std : : vector < std : : string > language_list ;
crypto : : ElectrumWords : : get_language_list ( language_list ) ;
if ( mnemonic_language . empty ( ) & & std : : find ( language_list . begin ( ) , language_list . end ( ) , m_mnemonic_language ) ! = language_list . end ( ) )
{
mnemonic_language = m_mnemonic_language ;
}
m_wallet - > set_seed_language ( mnemonic_language ) ;
2018-02-25 16:59:52 +00:00
bool create_address_file = command_line : : get_arg ( vm , arg_create_address_file ) ;
2017-11-09 10:59:41 +00:00
try
{
2018-02-25 16:59:52 +00:00
m_wallet - > generate ( m_wallet_file , std : : move ( rc . second ) . password ( ) , multisig_keys , create_address_file ) ;
2017-11-09 10:59:41 +00:00
bool ready ;
uint32_t threshold , total ;
if ( ! m_wallet - > multisig ( & ready , & threshold , & total ) | | ! ready )
{
fail_msg_writer ( ) < < tr ( " failed to generate new mutlisig wallet " ) ;
2018-07-30 11:39:05 +00:00
return { } ;
2017-11-09 10:59:41 +00:00
}
message_writer ( console_color_white , true ) < < boost : : format ( tr ( " Generated new %u/%u multisig wallet: " ) ) % threshold % total
2018-02-16 11:04:04 +00:00
< < m_wallet - > get_account ( ) . get_public_address_str ( m_wallet - > nettype ( ) ) ;
2017-11-09 10:59:41 +00:00
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " failed to generate new wallet: " ) < < e . what ( ) ;
2018-07-30 11:39:05 +00:00
return { } ;
2017-11-09 10:59:41 +00:00
}
2018-07-30 11:39:05 +00:00
return std : : move ( password ) ;
2016-02-22 22:10:55 +00:00
}
//----------------------------------------------------------------------------------------------------
2016-11-09 03:55:41 +00:00
bool simple_wallet : : open_wallet ( const boost : : program_options : : variables_map & vm )
2014-03-03 22:07:58 +00:00
{
2016-11-09 03:55:41 +00:00
if ( ! tools : : wallet2 : : wallet_valid_path_format ( m_wallet_file ) )
2014-12-11 10:47:24 +00:00
{
2016-11-09 03:55:41 +00:00
fail_msg_writer ( ) < < tr ( " wallet file path not valid: " ) < < m_wallet_file ;
2014-12-11 10:47:24 +00:00
return false ;
}
2018-03-24 15:13:21 +00:00
bool keys_file_exists ;
bool wallet_file_exists ;
tools : : wallet2 : : wallet_exists ( m_wallet_file , keys_file_exists , wallet_file_exists ) ;
if ( ! keys_file_exists )
{
fail_msg_writer ( ) < < tr ( " Key file not found. Failed to open wallet " ) ;
return false ;
}
2017-11-25 14:50:15 +00:00
epee : : wipeable_string password ;
2014-04-02 16:00:17 +00:00
try
{
2018-07-08 20:12:33 +00:00
auto rc = tools : : wallet2 : : make_from_file ( vm , false , m_wallet_file , password_prompter ) ;
2016-11-09 03:55:41 +00:00
m_wallet = std : : move ( rc . first ) ;
2017-11-25 14:50:15 +00:00
password = std : : move ( std : : move ( rc . second ) . password ( ) ) ;
2016-11-09 03:55:41 +00:00
if ( ! m_wallet )
{
return false ;
}
2017-05-28 11:18:51 +00:00
std : : string prefix ;
2017-10-01 13:06:54 +00:00
bool ready ;
2017-05-28 11:18:51 +00:00
uint32_t threshold , total ;
if ( m_wallet - > watch_only ( ) )
prefix = tr ( " Opened watch-only wallet " ) ;
2017-10-01 13:06:54 +00:00
else if ( m_wallet - > multisig ( & ready , & threshold , & total ) )
prefix = ( boost : : format ( tr ( " Opened %u/%u multisig wallet%s " ) ) % threshold % total % ( ready ? " " : " (not yet finalized) " ) ) . str ( ) ;
2017-05-28 11:18:51 +00:00
else
prefix = tr ( " Opened wallet " ) ;
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
message_writer ( console_color_white , true ) < <
2018-02-16 11:04:04 +00:00
prefix < < " : " < < m_wallet - > get_account ( ) . get_public_address_str ( m_wallet - > nettype ( ) ) ;
2018-02-20 16:01:27 +00:00
if ( m_wallet - > get_account ( ) . get_device ( ) ) {
message_writer ( console_color_white , true ) < < " Wallet is on device: " < < m_wallet - > get_account ( ) . get_device ( ) . get_name ( ) ;
}
2014-10-18 17:31:43 +00:00
// If the wallet file is deprecated, we should ask for mnemonic language again and store
// everything in the new format.
2014-12-06 09:48:33 +00:00
// NOTE: this is_deprecated() refers to the wallet file format before becoming JSON. It does not refer to the "old english" seed words form of "deprecated" used elsewhere.
if ( m_wallet - > is_deprecated ( ) )
2014-10-18 17:31:43 +00:00
{
2018-07-08 20:12:33 +00:00
bool is_deterministic ;
{
SCOPED_WALLET_UNLOCK ( ) ;
is_deterministic = m_wallet - > is_deterministic ( ) ;
}
if ( is_deterministic )
2014-12-06 09:48:33 +00:00
{
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
message_writer ( console_color_green , false ) < < " \n " < < tr ( " You had been using "
2015-07-14 19:28:25 +00:00
" a deprecated version of the wallet. Please proceed to upgrade your wallet. \n " ) ;
2014-12-06 09:48:33 +00:00
std : : string mnemonic_language = get_mnemonic_language ( ) ;
2016-03-29 16:52:45 +00:00
if ( mnemonic_language . empty ( ) )
return false ;
2014-12-06 09:48:33 +00:00
m_wallet - > set_seed_language ( mnemonic_language ) ;
m_wallet - > rewrite ( m_wallet_file , password ) ;
// Display the seed
2018-07-06 23:03:15 +00:00
epee : : wipeable_string seed ;
2014-12-06 09:48:33 +00:00
m_wallet - > get_seed ( seed ) ;
print_seed ( seed ) ;
}
else
{
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
message_writer ( console_color_green , false ) < < " \n " < < tr ( " You had been using "
2015-07-14 19:28:25 +00:00
" a deprecated version of the wallet. Your wallet file format is being upgraded now. \n " ) ;
2016-11-09 03:55:41 +00:00
m_wallet - > rewrite ( m_wallet_file , password ) ;
2014-12-06 09:48:33 +00:00
}
2014-10-18 17:31:43 +00:00
}
2014-04-02 16:00:17 +00:00
}
catch ( const std : : exception & e )
{
2015-07-14 19:28:25 +00:00
fail_msg_writer ( ) < < tr ( " failed to load wallet: " ) < < e . what ( ) ;
2017-09-09 10:34:45 +00:00
if ( m_wallet )
{
// only suggest removing cache if the password was actually correct
bool password_is_correct = false ;
try
{
password_is_correct = m_wallet - > verify_password ( password ) ;
}
catch ( . . . ) { } // guard against I/O errors
if ( password_is_correct )
fail_msg_writer ( ) < < boost : : format ( tr ( " You may want to remove the file \" %s \" and try again " ) ) % m_wallet_file ;
}
2014-04-02 16:00:17 +00:00
return false ;
}
success_msg_writer ( ) < <
" ********************************************************************** \n " < <
2017-12-17 17:33:43 +00:00
tr ( " Use the \" help \" command to see the list of available commands. \n " ) < <
2017-11-22 12:53:18 +00:00
tr ( " Use \" help <command> \" to see a command's documentation. \n " ) < <
2014-04-02 16:00:17 +00:00
" ********************************************************************** " ;
2014-03-03 22:07:58 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : close_wallet ( )
{
2016-08-07 12:06:40 +00:00
if ( m_idle_run . load ( std : : memory_order_relaxed ) )
2015-11-28 12:38:58 +00:00
{
2016-08-07 12:06:40 +00:00
m_idle_run . store ( false , std : : memory_order_relaxed ) ;
2015-11-29 13:02:01 +00:00
m_wallet - > stop ( ) ;
{
2016-08-07 12:06:40 +00:00
boost : : unique_lock < boost : : mutex > lock ( m_idle_mutex ) ;
m_idle_cond . notify_one ( ) ;
2015-11-29 13:02:01 +00:00
}
2016-08-07 12:06:40 +00:00
m_idle_thread . join ( ) ;
2015-11-28 12:38:58 +00:00
}
2014-03-03 22:07:58 +00:00
bool r = m_wallet - > deinit ( ) ;
2014-04-02 16:00:17 +00:00
if ( ! r )
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " failed to deinitialize wallet " ) ;
2014-04-02 16:00:17 +00:00
return false ;
}
try
{
m_wallet - > store ( ) ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < e . what ( ) ;
return false ;
}
2014-03-03 22:07:58 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : save ( const std : : vector < std : : string > & args )
{
2014-04-02 16:00:17 +00:00
try
{
2016-08-07 12:06:40 +00:00
LOCK_IDLE_SCOPE ( ) ;
2014-04-02 16:00:17 +00:00
m_wallet - > store ( ) ;
2015-07-14 19:28:25 +00:00
success_msg_writer ( ) < < tr ( " Wallet data saved " ) ;
2014-04-02 16:00:17 +00:00
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < e . what ( ) ;
}
2014-03-03 22:07:58 +00:00
return true ;
}
2015-05-31 14:34:55 +00:00
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : save_watch_only ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( m_wallet - > multisig ( ) )
{
fail_msg_writer ( ) < < tr ( " wallet is multisig and cannot save a watch-only version " ) ;
return true ;
}
2018-02-20 02:25:20 +00:00
const auto pwd_container = password_prompter ( tr ( " Password for new watch-only wallet " ) , true ) ;
2015-06-12 15:45:29 +00:00
2016-12-17 23:07:15 +00:00
if ( ! pwd_container )
2015-05-31 14:34:55 +00:00
{
2015-07-14 19:28:25 +00:00
fail_msg_writer ( ) < < tr ( " failed to read wallet password " ) ;
2015-06-12 15:45:29 +00:00
return true ;
}
2015-05-31 14:34:55 +00:00
2018-03-07 13:54:18 +00:00
try
{
std : : string new_keys_filename ;
m_wallet - > write_watch_only_wallet ( m_wallet_file , pwd_container - > password ( ) , new_keys_filename ) ;
success_msg_writer ( ) < < tr ( " Watch only wallet saved as: " ) < < new_keys_filename ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " Failed to save watch only wallet: " ) < < e . what ( ) ;
return true ;
}
2015-05-31 14:34:55 +00:00
return true ;
}
2014-03-03 22:07:58 +00:00
//----------------------------------------------------------------------------------------------------
2014-03-20 11:46:11 +00:00
bool simple_wallet : : start_mining ( const std : : vector < std : : string > & args )
2014-03-03 22:07:58 +00:00
{
2018-08-10 12:15:40 +00:00
if ( ! m_wallet - > is_trusted_daemon ( ) )
2015-10-11 23:04:57 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " this command requires a trusted daemon. Enable with --trusted-daemon " ) ;
2015-10-11 23:04:57 +00:00
return true ;
}
2014-03-20 11:46:11 +00:00
if ( ! try_connect_to_daemon ( ) )
return true ;
2014-03-03 22:07:58 +00:00
2017-06-19 23:33:15 +00:00
if ( ! m_wallet )
{
fail_msg_writer ( ) < < tr ( " wallet is null " ) ;
return true ;
}
2017-02-21 16:29:38 +00:00
COMMAND_RPC_START_MINING : : request req = AUTO_VAL_INIT ( req ) ;
2018-02-16 11:04:04 +00:00
req . miner_address = m_wallet - > get_account ( ) . get_public_address_str ( m_wallet - > nettype ( ) ) ;
2014-03-20 11:46:11 +00:00
2014-04-07 15:02:15 +00:00
bool ok = true ;
2017-02-21 16:29:38 +00:00
size_t arg_size = args . size ( ) ;
2017-10-19 12:57:49 +00:00
if ( arg_size > = 3 )
{
if ( ! parse_bool_and_use ( args [ 2 ] , [ & ] ( bool r ) { req . ignore_battery = r ; } ) )
return true ;
}
if ( arg_size > = 2 )
{
if ( ! parse_bool_and_use ( args [ 1 ] , [ & ] ( bool r ) { req . do_background_mining = r ; } ) )
return true ;
}
2017-02-21 16:29:38 +00:00
if ( arg_size > = 1 )
2014-03-20 11:46:11 +00:00
{
2014-07-01 17:01:44 +00:00
uint16_t num = 1 ;
2014-04-07 15:02:15 +00:00
ok = string_tools : : get_xtype_from_string ( num , args [ 0 ] ) ;
2018-05-08 23:09:14 +00:00
ok = ok & & 1 < = num ;
2014-03-20 11:46:11 +00:00
req . threads_count = num ;
}
else
{
2017-02-21 16:29:38 +00:00
req . threads_count = 1 ;
2014-04-07 15:02:15 +00:00
}
if ( ! ok )
{
2018-05-08 23:09:14 +00:00
fail_msg_writer ( ) < < tr ( " invalid arguments. Please use start_mining [<number_of_threads>] [do_bg_mining] [ignore_battery] " ) ;
2014-03-20 11:46:11 +00:00
return true ;
2014-03-03 22:07:58 +00:00
}
2014-03-20 11:46:11 +00:00
2014-03-03 22:07:58 +00:00
COMMAND_RPC_START_MINING : : response res ;
2018-02-16 01:19:39 +00:00
bool r = m_wallet - > invoke_http_json ( " /start_mining " , req , res ) ;
2014-04-02 16:00:17 +00:00
std : : string err = interpret_rpc_response ( r , res . status ) ;
2014-03-20 11:46:11 +00:00
if ( err . empty ( ) )
2015-07-14 19:28:25 +00:00
success_msg_writer ( ) < < tr ( " Mining started in daemon " ) ;
2014-03-20 11:46:11 +00:00
else
2015-07-14 19:28:25 +00:00
fail_msg_writer ( ) < < tr ( " mining has NOT been started: " ) < < err ;
2014-03-03 22:07:58 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
2014-03-20 11:46:11 +00:00
bool simple_wallet : : stop_mining ( const std : : vector < std : : string > & args )
2014-03-03 22:07:58 +00:00
{
2014-03-20 11:46:11 +00:00
if ( ! try_connect_to_daemon ( ) )
return true ;
2014-03-03 22:07:58 +00:00
2017-06-19 23:33:15 +00:00
if ( ! m_wallet )
{
fail_msg_writer ( ) < < tr ( " wallet is null " ) ;
return true ;
}
2018-02-20 16:01:27 +00:00
2014-03-03 22:07:58 +00:00
COMMAND_RPC_STOP_MINING : : request req ;
COMMAND_RPC_STOP_MINING : : response res ;
2018-02-16 01:19:39 +00:00
bool r = m_wallet - > invoke_http_json ( " /stop_mining " , req , res ) ;
2014-04-02 16:00:17 +00:00
std : : string err = interpret_rpc_response ( r , res . status ) ;
2014-03-20 11:46:11 +00:00
if ( err . empty ( ) )
2015-07-14 19:28:25 +00:00
success_msg_writer ( ) < < tr ( " Mining stopped in daemon " ) ;
2014-03-20 11:46:11 +00:00
else
2015-07-14 19:28:25 +00:00
fail_msg_writer ( ) < < tr ( " mining has NOT been stopped: " ) < < err ;
2014-03-03 22:07:58 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
2017-09-22 18:20:09 +00:00
bool simple_wallet : : set_daemon ( const std : : vector < std : : string > & args )
{
std : : string daemon_url ;
if ( args . size ( ) < 1 )
{
fail_msg_writer ( ) < < tr ( " missing daemon URL argument " ) ;
return true ;
}
boost : : regex rgx ( " ^(.*://)?([A-Za-z0-9 \\ - \\ .]+)(:[0-9]+)? " ) ;
boost : : cmatch match ;
// If user input matches URL regex
if ( boost : : regex_match ( args [ 0 ] . c_str ( ) , match , rgx ) )
{
if ( match . length ( ) < 4 )
{
fail_msg_writer ( ) < < tr ( " Unexpected array length - Exited simple_wallet::set_daemon() " ) ;
return true ;
}
// If no port has been provided, use the default from config
if ( ! match [ 3 ] . length ( ) )
{
2018-06-11 03:16:29 +00:00
int daemon_port = get_config ( m_wallet - > nettype ( ) ) . RPC_DEFAULT_PORT ;
2017-09-22 18:20:09 +00:00
daemon_url = match [ 1 ] + match [ 2 ] + std : : string ( " : " ) + std : : to_string ( daemon_port ) ;
} else {
daemon_url = args [ 0 ] ;
}
LOCK_IDLE_SCOPE ( ) ;
2018-08-25 05:22:26 +00:00
m_wallet - > init ( daemon_url ) ;
2018-06-05 09:45:01 +00:00
if ( args . size ( ) = = 2 )
{
if ( args [ 1 ] = = " trusted " )
2018-08-10 12:15:40 +00:00
m_wallet - > set_trusted_daemon ( true ) ;
2018-06-05 09:45:01 +00:00
else if ( args [ 1 ] = = " untrusted " )
2018-08-10 12:15:40 +00:00
m_wallet - > set_trusted_daemon ( false ) ;
2018-06-05 09:45:01 +00:00
else
{
fail_msg_writer ( ) < < tr ( " Expected trusted or untrusted, got " ) < < args [ 1 ] < < " : assuming untrusted " ;
2018-08-10 12:15:40 +00:00
m_wallet - > set_trusted_daemon ( false ) ;
2018-06-05 09:45:01 +00:00
}
}
else
{
2018-08-10 12:15:40 +00:00
m_wallet - > set_trusted_daemon ( false ) ;
2018-06-05 09:45:01 +00:00
try
{
if ( tools : : is_local_address ( m_wallet - > get_daemon_address ( ) ) )
{
MINFO ( tr ( " Daemon is local, assuming trusted " ) ) ;
2018-08-10 12:15:40 +00:00
m_wallet - > set_trusted_daemon ( true ) ;
2018-06-05 09:45:01 +00:00
}
}
catch ( const std : : exception & e ) { }
}
2018-08-10 12:15:40 +00:00
success_msg_writer ( ) < < boost : : format ( " Daemon set to %s, %s " ) % daemon_url % ( m_wallet - > is_trusted_daemon ( ) ? tr ( " trusted " ) : tr ( " untrusted " ) ) ;
2017-09-22 18:20:09 +00:00
} else {
fail_msg_writer ( ) < < tr ( " This does not seem to be a valid daemon URL. " ) ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2014-05-15 22:21:43 +00:00
bool simple_wallet : : save_bc ( const std : : vector < std : : string > & args )
{
if ( ! try_connect_to_daemon ( ) )
return true ;
2017-06-19 23:33:15 +00:00
if ( ! m_wallet )
{
fail_msg_writer ( ) < < tr ( " wallet is null " ) ;
return true ;
}
2014-05-15 22:21:43 +00:00
COMMAND_RPC_SAVE_BC : : request req ;
COMMAND_RPC_SAVE_BC : : response res ;
2018-02-16 01:19:39 +00:00
bool r = m_wallet - > invoke_http_json ( " /save_bc " , req , res ) ;
2014-05-15 22:21:43 +00:00
std : : string err = interpret_rpc_response ( r , res . status ) ;
if ( err . empty ( ) )
2015-07-14 19:28:25 +00:00
success_msg_writer ( ) < < tr ( " Blockchain saved " ) ;
2014-05-15 22:21:43 +00:00
else
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " blockchain can't be saved: " ) < < err ;
2014-05-15 22:21:43 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
2014-04-02 16:00:17 +00:00
void simple_wallet : : on_new_block ( uint64_t height , const cryptonote : : block & block )
{
2015-11-28 12:38:58 +00:00
if ( ! m_auto_refresh_refreshing )
m_refresh_progress_reporter . update ( height , false ) ;
2014-04-02 16:00:17 +00:00
}
//----------------------------------------------------------------------------------------------------
2017-02-19 02:42:10 +00:00
void simple_wallet : : on_money_received ( uint64_t height , const crypto : : hash & txid , const cryptonote : : transaction & tx , uint64_t amount , const cryptonote : : subaddress_index & subaddr_index )
2014-04-02 16:00:17 +00:00
{
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
message_writer ( console_color_green , false ) < < " \r " < <
2015-07-14 19:28:25 +00:00
tr ( " Height " ) < < height < < " , " < <
2017-02-19 02:42:10 +00:00
tr ( " txid " ) < < txid < < " , " < <
2017-11-15 17:51:28 +00:00
print_money ( amount ) < < " , " < <
2017-02-19 02:42:10 +00:00
tr ( " idx " ) < < subaddr_index ;
2018-07-06 17:14:08 +00:00
const uint64_t warn_height = m_wallet - > nettype ( ) = = TESTNET ? 1000000 : m_wallet - > nettype ( ) = = STAGENET ? 50000 : 1650000 ;
if ( height > = warn_height )
{
std : : vector < tx_extra_field > tx_extra_fields ;
parse_tx_extra ( tx . extra , tx_extra_fields ) ; // failure ok
tx_extra_nonce extra_nonce ;
if ( find_tx_extra_field_by_type ( tx_extra_fields , extra_nonce ) )
{
crypto : : hash8 payment_id8 = crypto : : null_hash8 ;
2018-09-29 20:13:16 +00:00
crypto : : hash payment_id = crypto : : null_hash ;
2018-07-06 17:14:08 +00:00
if ( get_encrypted_payment_id_from_tx_extra_nonce ( extra_nonce . nonce , payment_id8 ) )
message_writer ( ) < <
tr ( " NOTE: this transaction uses an encrypted payment ID: consider using subaddresses instead " ) ;
2018-09-29 20:13:16 +00:00
else if ( get_payment_id_from_tx_extra_nonce ( extra_nonce . nonce , payment_id ) )
2018-07-06 17:14:08 +00:00
message_writer ( console_color_red , false ) < <
tr ( " WARNING: this transaction uses an unencrypted payment ID: consider using subaddresses instead " ) ;
}
}
2015-11-28 12:38:58 +00:00
if ( m_auto_refresh_refreshing )
m_cmd_binder . print_prompt ( ) ;
else
m_refresh_progress_reporter . update ( height , true ) ;
2014-04-02 16:00:17 +00:00
}
//----------------------------------------------------------------------------------------------------
2017-02-19 02:42:10 +00:00
void simple_wallet : : on_unconfirmed_money_received ( uint64_t height , const crypto : : hash & txid , const cryptonote : : transaction & tx , uint64_t amount , const cryptonote : : subaddress_index & subaddr_index )
2017-01-12 17:23:23 +00:00
{
// Not implemented in CLI wallet
}
//----------------------------------------------------------------------------------------------------
2017-02-19 02:42:10 +00:00
void simple_wallet : : on_money_spent ( uint64_t height , const crypto : : hash & txid , const cryptonote : : transaction & in_tx , uint64_t amount , const cryptonote : : transaction & spend_tx , const cryptonote : : subaddress_index & subaddr_index )
2014-04-02 16:00:17 +00:00
{
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
message_writer ( console_color_magenta , false ) < < " \r " < <
2015-07-14 19:28:25 +00:00
tr ( " Height " ) < < height < < " , " < <
2017-02-19 02:42:10 +00:00
tr ( " txid " ) < < txid < < " , " < <
tr ( " spent " ) < < print_money ( amount ) < < " , " < <
tr ( " idx " ) < < subaddr_index ;
2015-11-28 12:38:58 +00:00
if ( m_auto_refresh_refreshing )
m_cmd_binder . print_prompt ( ) ;
else
m_refresh_progress_reporter . update ( height , true ) ;
2014-04-02 16:00:17 +00:00
}
//----------------------------------------------------------------------------------------------------
2017-02-27 20:26:17 +00:00
void simple_wallet : : on_skip_transaction ( uint64_t height , const crypto : : hash & txid , const cryptonote : : transaction & tx )
2014-05-03 16:19:43 +00:00
{
}
//----------------------------------------------------------------------------------------------------
2018-07-08 20:12:33 +00:00
boost : : optional < epee : : wipeable_string > simple_wallet : : on_get_password ( const char * reason )
{
// can't ask for password from a background thread
if ( ! m_in_manual_refresh . load ( std : : memory_order_relaxed ) )
{
2018-09-14 08:26:05 +00:00
message_writer ( console_color_red , false ) < < boost : : format ( tr ( " Password needed (%s) - use the refresh command " ) ) % reason ;
2018-07-08 20:12:33 +00:00
m_cmd_binder . print_prompt ( ) ;
return boost : : none ;
}
# ifdef HAVE_READLINE
rdln : : suspend_readline pause_readline ;
# endif
std : : string msg = tr ( " Enter password " ) ;
if ( reason & & * reason )
msg + = std : : string ( " ( " ) + reason + " ) " ;
auto pwd_container = tools : : password_container : : prompt ( false , msg . c_str ( ) ) ;
if ( ! pwd_container )
{
MERROR ( " Failed to read password " ) ;
return boost : : none ;
}
return pwd_container - > password ( ) ;
}
//----------------------------------------------------------------------------------------------------
2017-02-19 02:42:10 +00:00
bool simple_wallet : : refresh_main ( uint64_t start_height , bool reset , bool is_init )
2014-03-03 22:07:58 +00:00
{
2018-03-22 02:56:04 +00:00
if ( ! try_connect_to_daemon ( is_init ) )
2014-03-20 11:46:11 +00:00
return true ;
2014-03-03 22:07:58 +00:00
2016-08-07 12:06:40 +00:00
LOCK_IDLE_SCOPE ( ) ;
2015-11-29 13:02:01 +00:00
2015-12-30 12:58:15 +00:00
if ( reset )
m_wallet - > rescan_blockchain ( false ) ;
2017-08-21 15:34:45 +00:00
# ifdef HAVE_READLINE
rdln : : suspend_readline pause_readline ;
# endif
2015-07-14 19:28:25 +00:00
message_writer ( ) < < tr ( " Starting refresh... " ) ;
2014-08-01 08:17:50 +00:00
2015-10-27 09:05:07 +00:00
uint64_t fetched_blocks = 0 ;
2014-04-02 16:00:17 +00:00
bool ok = false ;
std : : ostringstream ss ;
try
2014-03-20 11:46:11 +00:00
{
2015-11-29 13:02:01 +00:00
m_in_manual_refresh . store ( true , std : : memory_order_relaxed ) ;
2016-04-20 23:11:11 +00:00
epee : : misc_utils : : auto_scope_leave_caller scope_exit_handler = epee : : misc_utils : : create_scope_leave_handler ( [ & ] ( ) { m_in_manual_refresh . store ( false , std : : memory_order_relaxed ) ; } ) ;
2018-08-10 12:15:40 +00:00
m_wallet - > refresh ( m_wallet - > is_trusted_daemon ( ) , start_height , fetched_blocks ) ;
2014-04-02 16:00:17 +00:00
ok = true ;
// Clear line "Height xxx of xxx"
std : : cout < < " \r \r " ;
2015-07-14 19:28:25 +00:00
success_msg_writer ( true ) < < tr ( " Refresh done, blocks received: " ) < < fetched_blocks ;
2017-02-19 02:42:10 +00:00
if ( is_init )
print_accounts ( ) ;
2016-04-20 23:11:11 +00:00
show_balance_unlocked ( ) ;
2014-03-20 11:46:11 +00:00
}
2014-04-02 16:00:17 +00:00
catch ( const tools : : error : : daemon_busy & )
{
2015-12-12 00:05:39 +00:00
ss < < tr ( " daemon is busy. Please try again later. " ) ;
2014-04-02 16:00:17 +00:00
}
catch ( const tools : : error : : no_connection_to_daemon & )
{
2015-12-12 00:05:39 +00:00
ss < < tr ( " no connection to daemon. Please make sure daemon is running. " ) ;
2014-04-02 16:00:17 +00:00
}
catch ( const tools : : error : : wallet_rpc_error & e )
{
2015-12-12 00:05:39 +00:00
LOG_ERROR ( " RPC error: " < < e . to_string ( ) ) ;
2015-07-14 19:28:25 +00:00
ss < < tr ( " RPC error: " ) < < e . what ( ) ;
2014-04-02 16:00:17 +00:00
}
catch ( const tools : : error : : refresh_error & e )
{
LOG_ERROR ( " refresh error: " < < e . to_string ( ) ) ;
2015-12-12 00:05:39 +00:00
ss < < tr ( " refresh error: " ) < < e . what ( ) ;
2014-04-02 16:00:17 +00:00
}
catch ( const tools : : error : : wallet_internal_error & e )
2014-03-20 11:46:11 +00:00
{
2014-04-02 16:00:17 +00:00
LOG_ERROR ( " internal error: " < < e . to_string ( ) ) ;
2015-07-14 19:28:25 +00:00
ss < < tr ( " internal error: " ) < < e . what ( ) ;
2014-03-20 11:46:11 +00:00
}
2014-04-02 16:00:17 +00:00
catch ( const std : : exception & e )
{
LOG_ERROR ( " unexpected error: " < < e . what ( ) ) ;
2015-07-14 19:28:25 +00:00
ss < < tr ( " unexpected error: " ) < < e . what ( ) ;
2014-04-02 16:00:17 +00:00
}
catch ( . . . )
{
2015-12-12 00:05:39 +00:00
LOG_ERROR ( " unknown error " ) ;
2015-07-14 19:28:25 +00:00
ss < < tr ( " unknown error " ) ;
2014-04-02 16:00:17 +00:00
}
if ( ! ok )
{
2015-07-14 19:28:25 +00:00
fail_msg_writer ( ) < < tr ( " refresh failed: " ) < < ss . str ( ) < < " . " < < tr ( " Blocks received: " ) < < fetched_blocks ;
2014-04-02 16:00:17 +00:00
}
2014-03-03 22:07:58 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
2015-12-30 12:58:15 +00:00
bool simple_wallet : : refresh ( const std : : vector < std : : string > & args )
{
uint64_t start_height = 0 ;
if ( ! args . empty ( ) ) {
try
{
start_height = boost : : lexical_cast < uint64_t > ( args [ 0 ] ) ;
}
catch ( const boost : : bad_lexical_cast & )
{
start_height = 0 ;
}
}
return refresh_main ( start_height , false ) ;
}
//----------------------------------------------------------------------------------------------------
2017-02-19 02:42:10 +00:00
bool simple_wallet : : show_balance_unlocked ( bool detailed )
2014-03-03 22:07:58 +00:00
{
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
std : : string extra ;
if ( m_wallet - > has_multisig_partial_key_images ( ) )
extra = tr ( " (Some owned outputs have partial key images - import_multisig_info needed) " ) ;
2018-04-19 02:17:45 +00:00
else if ( m_wallet - > has_unknown_key_images ( ) )
extra + = tr ( " (Some owned outputs have missing key images - import_key_images needed) " ) ;
2017-02-19 02:42:10 +00:00
success_msg_writer ( ) < < tr ( " Currently selected account: [ " ) < < m_current_subaddress_account < < tr ( " ] " ) < < m_wallet - > get_subaddress_label ( { m_current_subaddress_account , 0 } ) ;
2017-12-15 03:08:36 +00:00
const std : : string tag = m_wallet - > get_account_tags ( ) . second [ m_current_subaddress_account ] ;
success_msg_writer ( ) < < tr ( " Tag: " ) < < ( tag . empty ( ) ? std : : string { tr ( " (No tag assigned) " ) } : tag ) ;
2017-02-19 02:42:10 +00:00
success_msg_writer ( ) < < tr ( " Balance: " ) < < print_money ( m_wallet - > balance ( m_current_subaddress_account ) ) < < " , "
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
< < tr ( " unlocked balance: " ) < < print_money ( m_wallet - > unlocked_balance ( m_current_subaddress_account ) ) < < extra ;
2017-02-19 02:42:10 +00:00
std : : map < uint32_t , uint64_t > balance_per_subaddress = m_wallet - > balance_per_subaddress ( m_current_subaddress_account ) ;
std : : map < uint32_t , uint64_t > unlocked_balance_per_subaddress = m_wallet - > unlocked_balance_per_subaddress ( m_current_subaddress_account ) ;
if ( ! detailed | | balance_per_subaddress . empty ( ) )
return true ;
success_msg_writer ( ) < < tr ( " Balance per address: " ) ;
success_msg_writer ( ) < < boost : : format ( " %15s %21s %21s %7s %21s " ) % tr ( " Address " ) % tr ( " Balance " ) % tr ( " Unlocked balance " ) % tr ( " Outputs " ) % tr ( " Label " ) ;
std : : vector < tools : : wallet2 : : transfer_details > transfers ;
m_wallet - > get_transfers ( transfers ) ;
for ( const auto & i : balance_per_subaddress )
{
cryptonote : : subaddress_index subaddr_index = { m_current_subaddress_account , i . first } ;
std : : string address_str = m_wallet - > get_subaddress_as_str ( subaddr_index ) . substr ( 0 , 6 ) ;
uint64_t num_unspent_outputs = std : : count_if ( transfers . begin ( ) , transfers . end ( ) , [ & subaddr_index ] ( const tools : : wallet2 : : transfer_details & td ) { return ! td . m_spent & & td . m_subaddr_index = = subaddr_index ; } ) ;
success_msg_writer ( ) < < boost : : format ( tr ( " %8u %6s %21s %21s %7u %21s " ) ) % i . first % address_str % print_money ( i . second ) % print_money ( unlocked_balance_per_subaddress [ i . first ] ) % num_unspent_outputs % m_wallet - > get_subaddress_label ( subaddr_index ) ;
}
2014-03-03 22:07:58 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
2016-04-20 23:11:11 +00:00
bool simple_wallet : : show_balance ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
2017-02-19 02:42:10 +00:00
if ( args . size ( ) > 1 | | ( args . size ( ) = = 1 & & args [ 0 ] ! = " detail " ) )
{
fail_msg_writer ( ) < < tr ( " usage: balance [detail] " ) ;
return true ;
}
2016-08-07 12:06:40 +00:00
LOCK_IDLE_SCOPE ( ) ;
2017-02-19 02:42:10 +00:00
show_balance_unlocked ( args . size ( ) = = 1 ) ;
2016-04-20 23:11:11 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
2014-03-20 11:46:11 +00:00
bool simple_wallet : : show_incoming_transfers ( const std : : vector < std : : string > & args )
2014-03-03 22:07:58 +00:00
{
2017-02-19 02:42:10 +00:00
if ( args . size ( ) > 3 )
{
fail_msg_writer ( ) < < tr ( " usage: incoming_transfers [available|unavailable] [verbose] [index=<N>] " ) ;
return true ;
}
auto local_args = args ;
2016-08-07 12:06:40 +00:00
LOCK_IDLE_SCOPE ( ) ;
2016-04-20 23:11:11 +00:00
2014-04-02 16:00:17 +00:00
bool filter = false ;
bool available = false ;
2016-11-13 18:20:46 +00:00
bool verbose = false ;
2017-02-19 02:42:10 +00:00
if ( local_args . size ( ) > 0 )
2014-04-02 16:00:17 +00:00
{
2017-02-19 02:42:10 +00:00
if ( local_args [ 0 ] = = " available " )
2014-04-02 16:00:17 +00:00
{
filter = true ;
available = true ;
2017-02-19 02:42:10 +00:00
local_args . erase ( local_args . begin ( ) ) ;
2014-04-02 16:00:17 +00:00
}
2017-02-19 02:42:10 +00:00
else if ( local_args [ 0 ] = = " unavailable " )
2014-04-02 16:00:17 +00:00
{
filter = true ;
available = false ;
2017-02-19 02:42:10 +00:00
local_args . erase ( local_args . begin ( ) ) ;
2016-11-13 18:20:46 +00:00
}
2014-04-02 16:00:17 +00:00
}
2017-02-19 02:42:10 +00:00
if ( local_args . size ( ) > 0 & & local_args [ 0 ] = = " verbose " )
{
verbose = true ;
local_args . erase ( local_args . begin ( ) ) ;
}
2014-04-02 16:00:17 +00:00
2017-06-22 12:15:18 +00:00
PAUSE_READLINE ( ) ;
2017-02-19 02:42:10 +00:00
std : : set < uint32_t > subaddr_indices ;
if ( local_args . size ( ) > 0 & & local_args [ 0 ] . substr ( 0 , 6 ) = = " index= " )
{
if ( ! parse_subaddress_indices ( local_args [ 0 ] , subaddr_indices ) )
return true ;
2017-12-21 02:39:32 +00:00
local_args . erase ( local_args . begin ( ) ) ;
}
if ( local_args . size ( ) > 0 )
{
fail_msg_writer ( ) < < tr ( " usage: incoming_transfers [available|unavailable] [verbose] [index=<N>] " ) ;
return true ;
2017-02-19 02:42:10 +00:00
}
2014-04-02 16:00:17 +00:00
tools : : wallet2 : : transfer_container transfers ;
m_wallet - > get_transfers ( transfers ) ;
bool transfers_found = false ;
for ( const auto & td : transfers )
{
if ( ! filter | | available ! = td . m_spent )
{
2017-02-19 02:42:10 +00:00
if ( m_current_subaddress_account ! = td . m_subaddr_index . major | | ( ! subaddr_indices . empty ( ) & & subaddr_indices . count ( td . m_subaddr_index . minor ) = = 0 ) )
continue ;
2014-04-02 16:00:17 +00:00
if ( ! transfers_found )
{
2016-11-13 18:20:46 +00:00
std : : string verbose_string ;
if ( verbose )
verbose_string = ( boost : : format ( " %68s%68s " ) % tr ( " pubkey " ) % tr ( " key image " ) ) . str ( ) ;
2017-02-19 02:42:10 +00:00
message_writer ( ) < < boost : : format ( " %21s%8s%12s%8s%16s%68s%16s%s " ) % tr ( " amount " ) % tr ( " spent " ) % tr ( " unlocked " ) % tr ( " ringct " ) % tr ( " global index " ) % tr ( " tx id " ) % tr ( " addr index " ) % verbose_string ;
2014-04-02 16:00:17 +00:00
transfers_found = true ;
}
2016-11-13 18:20:46 +00:00
std : : string verbose_string ;
if ( verbose )
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
verbose_string = ( boost : : format ( " %68s%68s " ) % td . get_public_key ( ) % ( td . m_key_image_known ? epee : : string_tools : : pod_to_hex ( td . m_key_image ) : td . m_key_image_partial ? ( epee : : string_tools : : pod_to_hex ( td . m_key_image ) + " /p " ) : std : : string ( 64 , ' ? ' ) ) ) . str ( ) ;
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
message_writer ( td . m_spent ? console_color_magenta : console_color_green , false ) < <
2017-02-19 02:42:10 +00:00
boost : : format ( " %21s%8s%12s%8s%16u%68s%16u%s " ) %
2015-07-14 19:28:25 +00:00
print_money ( td . amount ( ) ) %
2015-11-29 22:24:15 +00:00
( td . m_spent ? tr ( " T " ) : tr ( " F " ) ) %
2016-06-15 22:37:13 +00:00
( m_wallet - > is_transfer_unlocked ( td ) ? tr ( " unlocked " ) : tr ( " locked " ) ) %
( td . is_rct ( ) ? tr ( " RingCT " ) : tr ( " - " ) ) %
2015-07-14 19:28:25 +00:00
td . m_global_output_index %
2016-11-13 18:20:46 +00:00
td . m_txid %
2017-02-19 02:42:10 +00:00
td . m_subaddr_index . minor %
2016-11-13 18:20:46 +00:00
verbose_string ;
2014-04-02 16:00:17 +00:00
}
}
if ( ! transfers_found )
{
if ( ! filter )
{
2015-07-14 19:28:25 +00:00
success_msg_writer ( ) < < tr ( " No incoming transfers " ) ;
2014-04-02 16:00:17 +00:00
}
else if ( available )
{
2015-07-14 19:28:25 +00:00
success_msg_writer ( ) < < tr ( " No incoming available transfers " ) ;
2014-04-02 16:00:17 +00:00
}
else
{
2015-07-14 19:28:25 +00:00
success_msg_writer ( ) < < tr ( " No incoming unavailable transfers " ) ;
2014-04-02 16:00:17 +00:00
}
}
2014-03-03 22:07:58 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
2014-05-03 16:19:43 +00:00
bool simple_wallet : : show_payments ( const std : : vector < std : : string > & args )
{
if ( args . empty ( ) )
{
2018-01-09 21:37:30 +00:00
fail_msg_writer ( ) < < tr ( " expected at least one payment ID " ) ;
2014-05-03 16:19:43 +00:00
return true ;
}
2016-08-07 12:06:40 +00:00
LOCK_IDLE_SCOPE ( ) ;
2016-04-20 23:11:11 +00:00
2017-06-22 12:15:18 +00:00
PAUSE_READLINE ( ) ;
2017-02-19 02:42:10 +00:00
message_writer ( ) < < boost : : format ( " %68s%68s%12s%21s%16s%16s " ) %
tr ( " payment " ) % tr ( " transaction " ) % tr ( " height " ) % tr ( " amount " ) % tr ( " unlock time " ) % tr ( " addr index " ) ;
2014-05-03 16:19:43 +00:00
bool payments_found = false ;
for ( std : : string arg : args )
{
crypto : : hash payment_id ;
2014-06-01 22:22:42 +00:00
if ( tools : : wallet2 : : parse_payment_id ( arg , payment_id ) )
2014-05-03 16:19:43 +00:00
{
std : : list < tools : : wallet2 : : payment_details > payments ;
m_wallet - > get_payments ( payment_id , payments ) ;
if ( payments . empty ( ) )
{
2015-07-14 19:28:25 +00:00
success_msg_writer ( ) < < tr ( " No payments with id " ) < < payment_id ;
2014-05-03 16:19:43 +00:00
continue ;
}
for ( const tools : : wallet2 : : payment_details & pd : payments )
{
if ( ! payments_found )
{
payments_found = true ;
}
success_msg_writer ( true ) < <
2017-02-19 02:42:10 +00:00
boost : : format ( " %68s%68s%12s%21s%16s%16s " ) %
2015-07-14 19:28:25 +00:00
payment_id %
pd . m_tx_hash %
pd . m_block_height %
print_money ( pd . m_amount ) %
2017-02-19 02:42:10 +00:00
pd . m_unlock_time %
pd . m_subaddr_index . minor ;
2014-05-03 16:19:43 +00:00
}
}
else
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " payment ID has invalid format, expected 16 or 64 character hex string: " ) < < arg ;
2014-05-03 16:19:43 +00:00
}
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2014-03-20 11:46:11 +00:00
uint64_t simple_wallet : : get_daemon_blockchain_height ( std : : string & err )
2014-03-03 22:07:58 +00:00
{
2016-11-09 03:55:41 +00:00
if ( ! m_wallet )
{
throw std : : runtime_error ( " simple_wallet null wallet " ) ;
}
2018-06-30 21:06:09 +00:00
return m_wallet - > get_daemon_blockchain_height ( err ) ;
2014-03-03 22:07:58 +00:00
}
//----------------------------------------------------------------------------------------------------
2014-03-20 11:46:11 +00:00
bool simple_wallet : : show_blockchain_height ( const std : : vector < std : : string > & args )
2014-03-03 22:07:58 +00:00
{
2014-03-20 11:46:11 +00:00
if ( ! try_connect_to_daemon ( ) )
return true ;
2014-03-03 22:07:58 +00:00
2014-03-20 11:46:11 +00:00
std : : string err ;
uint64_t bc_height = get_daemon_blockchain_height ( err ) ;
if ( err . empty ( ) )
2014-04-02 16:00:17 +00:00
success_msg_writer ( ) < < bc_height ;
2014-03-03 22:07:58 +00:00
else
2015-07-14 19:28:25 +00:00
fail_msg_writer ( ) < < tr ( " failed to get blockchain height: " ) < < err ;
2014-03-03 22:07:58 +00:00
return true ;
}
2015-08-11 14:14:44 +00:00
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : rescan_spent ( const std : : vector < std : : string > & args )
{
2018-08-10 12:15:40 +00:00
if ( ! m_wallet - > is_trusted_daemon ( ) )
2015-10-11 18:45:59 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " this command requires a trusted daemon. Enable with --trusted-daemon " ) ;
2015-10-11 18:45:59 +00:00
return true ;
}
2015-08-11 14:14:44 +00:00
if ( ! try_connect_to_daemon ( ) )
return true ;
try
{
2016-08-07 12:06:40 +00:00
LOCK_IDLE_SCOPE ( ) ;
2015-08-11 14:14:44 +00:00
m_wallet - > rescan_spent ( ) ;
}
catch ( const tools : : error : : daemon_busy & )
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " daemon is busy. Please try again later. " ) ;
2015-08-11 14:14:44 +00:00
}
catch ( const tools : : error : : no_connection_to_daemon & )
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " no connection to daemon. Please make sure daemon is running. " ) ;
2015-08-11 14:14:44 +00:00
}
catch ( const tools : : error : : is_key_image_spent_error & )
{
fail_msg_writer ( ) < < tr ( " failed to get spent status " ) ;
}
catch ( const tools : : error : : wallet_rpc_error & e )
{
2015-12-12 00:05:39 +00:00
LOG_ERROR ( " RPC error: " < < e . to_string ( ) ) ;
2015-08-11 14:14:44 +00:00
fail_msg_writer ( ) < < tr ( " RPC error: " ) < < e . what ( ) ;
}
catch ( const std : : exception & e )
{
LOG_ERROR ( " unexpected error: " < < e . what ( ) ) ;
fail_msg_writer ( ) < < tr ( " unexpected error: " ) < < e . what ( ) ;
}
catch ( . . . )
{
2015-12-12 00:05:39 +00:00
LOG_ERROR ( " unknown error " ) ;
2015-08-11 14:14:44 +00:00
fail_msg_writer ( ) < < tr ( " unknown error " ) ;
}
2014-06-15 21:20:16 +00:00
2015-08-11 14:14:44 +00:00
return true ;
}
2014-03-03 22:07:58 +00:00
//----------------------------------------------------------------------------------------------------
2016-12-23 12:04:54 +00:00
bool simple_wallet : : print_ring_members ( const std : : vector < tools : : wallet2 : : pending_tx > & ptx_vector , std : : ostream & ostr )
{
uint32_t version ;
if ( ! try_connect_to_daemon ( false , & version ) )
{
fail_msg_writer ( ) < < tr ( " failed to connect to the daemon " ) ;
return false ;
}
// available for RPC version 1.4 or higher
2017-01-18 07:11:18 +00:00
if ( version < MAKE_CORE_RPC_VERSION ( 1 , 4 ) )
2016-12-23 12:04:54 +00:00
return true ;
std : : string err ;
uint64_t blockchain_height = get_daemon_blockchain_height ( err ) ;
if ( ! err . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " failed to get blockchain height: " ) < < err ;
return false ;
}
// for each transaction
for ( size_t n = 0 ; n < ptx_vector . size ( ) ; + + n )
{
const cryptonote : : transaction & tx = ptx_vector [ n ] . tx ;
const tools : : wallet2 : : tx_construction_data & construction_data = ptx_vector [ n ] . construction_data ;
ostr < < boost : : format ( tr ( " \n Transaction %llu/%llu: txid=%s " ) ) % ( n + 1 ) % ptx_vector . size ( ) % cryptonote : : get_transaction_hash ( tx ) ;
// for each input
2018-03-01 09:35:12 +00:00
std : : vector < uint64_t > spent_key_height ( tx . vin . size ( ) ) ;
2016-12-23 12:04:54 +00:00
std : : vector < crypto : : hash > spent_key_txid ( tx . vin . size ( ) ) ;
for ( size_t i = 0 ; i < tx . vin . size ( ) ; + + i )
{
if ( tx . vin [ i ] . type ( ) ! = typeid ( cryptonote : : txin_to_key ) )
continue ;
const cryptonote : : txin_to_key & in_key = boost : : get < cryptonote : : txin_to_key > ( tx . vin [ i ] ) ;
2018-03-01 09:35:12 +00:00
const tools : : wallet2 : : transfer_details & td = m_wallet - > get_transfer_details ( construction_data . selected_transfers [ i ] ) ;
const cryptonote : : tx_source_entry * sptr = NULL ;
for ( const auto & src : construction_data . sources )
if ( src . outputs [ src . real_output ] . second . dest = = td . get_public_key ( ) )
sptr = & src ;
if ( ! sptr )
{
fail_msg_writer ( ) < < tr ( " failed to find construction data for tx input " ) ;
return false ;
}
const cryptonote : : tx_source_entry & source = * sptr ;
2016-12-23 12:04:54 +00:00
ostr < < boost : : format ( tr ( " \n Input %llu/%llu: amount=%s " ) ) % ( i + 1 ) % tx . vin . size ( ) % print_money ( source . amount ) ;
// convert relative offsets of ring member keys into absolute offsets (indices) associated with the amount
std : : vector < uint64_t > absolute_offsets = cryptonote : : relative_output_offsets_to_absolute ( in_key . key_offsets ) ;
// get block heights from which those ring member keys originated
COMMAND_RPC_GET_OUTPUTS_BIN : : request req = AUTO_VAL_INIT ( req ) ;
req . outputs . resize ( absolute_offsets . size ( ) ) ;
for ( size_t j = 0 ; j < absolute_offsets . size ( ) ; + + j )
{
req . outputs [ j ] . amount = in_key . amount ;
req . outputs [ j ] . index = absolute_offsets [ j ] ;
}
COMMAND_RPC_GET_OUTPUTS_BIN : : response res = AUTO_VAL_INIT ( res ) ;
2018-02-16 01:19:39 +00:00
bool r = m_wallet - > invoke_http_bin ( " /get_outs.bin " , req , res ) ;
2016-12-23 12:04:54 +00:00
err = interpret_rpc_response ( r , res . status ) ;
if ( ! err . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " failed to get output: " ) < < err ;
return false ;
}
// make sure that returned block heights are less than blockchain height
for ( auto & res_out : res . outs )
{
if ( res_out . height > = blockchain_height )
{
fail_msg_writer ( ) < < tr ( " output key's originating block height shouldn't be higher than the blockchain height " ) ;
return false ;
}
}
ostr < < tr ( " \n Originating block heights: " ) ;
for ( size_t j = 0 ; j < absolute_offsets . size ( ) ; + + j )
ostr < < tr ( j = = source . real_output ? " * " : " " ) < < res . outs [ j ] . height ;
spent_key_height [ i ] = res . outs [ source . real_output ] . height ;
spent_key_txid [ i ] = res . outs [ source . real_output ] . txid ;
// visualize the distribution, using the code by moneroexamples onion-monero-viewer
const uint64_t resolution = 79 ;
std : : string ring_str ( resolution , ' _ ' ) ;
for ( size_t j = 0 ; j < absolute_offsets . size ( ) ; + + j )
{
uint64_t pos = ( res . outs [ j ] . height * resolution ) / blockchain_height ;
ring_str [ pos ] = ' o ' ;
}
uint64_t pos = ( res . outs [ source . real_output ] . height * resolution ) / blockchain_height ;
ring_str [ pos ] = ' * ' ;
ostr < < tr ( " \n | " ) < < ring_str < < tr ( " | \n " ) ;
}
// warn if rings contain keys originating from the same tx or temporally very close block heights
bool are_keys_from_same_tx = false ;
bool are_keys_from_close_height = false ;
for ( size_t i = 0 ; i < tx . vin . size ( ) ; + + i ) {
for ( size_t j = i + 1 ; j < tx . vin . size ( ) ; + + j )
{
if ( spent_key_txid [ i ] = = spent_key_txid [ j ] )
are_keys_from_same_tx = true ;
2018-03-01 09:35:12 +00:00
if ( std : : abs ( ( int64_t ) ( spent_key_height [ i ] - spent_key_height [ j ] ) ) < ( int64_t ) 5 )
2016-12-23 12:04:54 +00:00
are_keys_from_close_height = true ;
}
}
if ( are_keys_from_same_tx | | are_keys_from_close_height )
{
ostr
< < tr ( " \n Warning: Some input keys being spent are from " )
2017-06-23 12:01:04 +00:00
< < ( are_keys_from_same_tx ? tr ( " the same transaction " ) : tr ( " blocks that are temporally very close " ) )
2016-12-23 12:04:54 +00:00
< < tr ( " , which can break the anonymity of ring signature. Make sure this is intentional! " ) ;
}
ostr < < ENDL ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2016-06-15 22:37:13 +00:00
bool simple_wallet : : transfer_main ( int transfer_type , const std : : vector < std : : string > & args_ )
2014-03-03 22:07:58 +00:00
{
2017-02-19 02:42:10 +00:00
// "transfer [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] <address> <amount> [<payment_id>]"
2014-03-20 11:46:11 +00:00
if ( ! try_connect_to_daemon ( ) )
return true ;
2014-03-03 22:07:58 +00:00
2014-03-20 11:46:11 +00:00
std : : vector < std : : string > local_args = args_ ;
2017-02-19 02:42:10 +00:00
std : : set < uint32_t > subaddr_indices ;
if ( local_args . size ( ) > 0 & & local_args [ 0 ] . substr ( 0 , 6 ) = = " index= " )
{
if ( ! parse_subaddress_indices ( local_args [ 0 ] , subaddr_indices ) )
return true ;
local_args . erase ( local_args . begin ( ) ) ;
}
2017-10-07 03:40:27 +00:00
uint32_t priority = 0 ;
if ( local_args . size ( ) > 0 & & parse_priority ( local_args [ 0 ] , priority ) )
local_args . erase ( local_args . begin ( ) ) ;
2017-03-29 13:06:59 +00:00
2018-01-15 03:05:16 +00:00
priority = m_wallet - > adjust_priority ( priority ) ;
2017-09-08 10:36:49 +00:00
size_t fake_outs_count = 0 ;
2015-03-10 08:44:46 +00:00
if ( local_args . size ( ) > 0 ) {
2017-07-31 06:50:41 +00:00
size_t ring_size ;
if ( ! epee : : string_tools : : get_xtype_from_string ( ring_size , local_args [ 0 ] ) )
2015-03-10 08:44:46 +00:00
{
2015-10-30 21:16:51 +00:00
fake_outs_count = m_wallet - > default_mixin ( ) ;
if ( fake_outs_count = = 0 )
fake_outs_count = DEFAULT_MIX ;
2015-03-10 08:44:46 +00:00
}
2017-10-10 09:43:36 +00:00
else if ( ring_size = = 0 )
{
fail_msg_writer ( ) < < tr ( " Ring size must not be 0 " ) ;
return true ;
}
2015-03-10 08:44:46 +00:00
else
{
2017-07-31 06:50:41 +00:00
fake_outs_count = ring_size - 1 ;
2015-03-10 08:44:46 +00:00
local_args . erase ( local_args . begin ( ) ) ;
}
}
2017-10-10 09:33:17 +00:00
uint64_t adjusted_fake_outs_count = m_wallet - > adjust_mixin ( fake_outs_count ) ;
if ( adjusted_fake_outs_count > fake_outs_count )
{
fail_msg_writer ( ) < < ( boost : : format ( tr ( " ring size %u is too small, minimum is %u " ) ) % ( fake_outs_count + 1 ) % ( adjusted_fake_outs_count + 1 ) ) . str ( ) ;
return true ;
}
2018-07-18 21:24:53 +00:00
if ( adjusted_fake_outs_count < fake_outs_count )
{
fail_msg_writer ( ) < < ( boost : : format ( tr ( " ring size %u is too large, maximum is %u " ) ) % ( fake_outs_count + 1 ) % ( adjusted_fake_outs_count + 1 ) ) . str ( ) ;
return true ;
}
2015-03-10 08:44:46 +00:00
2018-08-01 16:01:36 +00:00
const size_t min_args = ( transfer_type = = TransferLocked ) ? 2 : 1 ;
2016-10-22 12:29:23 +00:00
if ( local_args . size ( ) < min_args )
2014-03-03 22:07:58 +00:00
{
2015-07-14 19:28:25 +00:00
fail_msg_writer ( ) < < tr ( " wrong number of arguments " ) ;
2015-03-10 08:44:46 +00:00
return true ;
2014-03-03 22:07:58 +00:00
}
2014-05-03 16:19:43 +00:00
std : : vector < uint8_t > extra ;
2015-06-11 08:44:13 +00:00
bool payment_id_seen = false ;
2018-08-01 16:01:36 +00:00
if ( ! local_args . empty ( ) )
2014-03-03 22:07:58 +00:00
{
2014-05-03 16:19:43 +00:00
std : : string payment_id_str = local_args . back ( ) ;
crypto : : hash payment_id ;
2018-08-01 16:01:36 +00:00
bool r = true ;
if ( tools : : wallet2 : : parse_long_payment_id ( payment_id_str , payment_id ) )
2014-03-03 22:07:58 +00:00
{
2014-05-03 16:19:43 +00:00
std : : string extra_nonce ;
2015-08-09 09:09:39 +00:00
set_payment_id_to_tx_extra_nonce ( extra_nonce , payment_id ) ;
2014-05-03 16:19:43 +00:00
r = add_extra_nonce_to_tx_extra ( extra , extra_nonce ) ;
2018-08-01 16:01:36 +00:00
local_args . pop_back ( ) ;
payment_id_seen = true ;
message_writer ( ) < < tr ( " Unencrypted payment IDs are bad for privacy: ask the recipient to use subaddresses instead " ) ;
2014-05-03 16:19:43 +00:00
}
2015-08-09 09:09:39 +00:00
else
{
crypto : : hash8 payment_id8 ;
2018-08-01 16:01:36 +00:00
if ( tools : : wallet2 : : parse_short_payment_id ( payment_id_str , payment_id8 ) )
2015-08-09 09:09:39 +00:00
{
std : : string extra_nonce ;
set_encrypted_payment_id_to_tx_extra_nonce ( extra_nonce , payment_id8 ) ;
r = add_extra_nonce_to_tx_extra ( extra , extra_nonce ) ;
2018-08-01 16:01:36 +00:00
local_args . pop_back ( ) ;
payment_id_seen = true ;
2015-08-09 09:09:39 +00:00
}
}
2014-05-03 16:19:43 +00:00
if ( ! r )
{
2018-08-01 16:01:36 +00:00
fail_msg_writer ( ) < < tr ( " payment id failed to encode " ) ;
2014-03-03 22:07:58 +00:00
return true ;
}
2014-05-03 16:19:43 +00:00
}
2014-03-20 11:46:11 +00:00
2016-10-22 12:29:23 +00:00
uint64_t locked_blocks = 0 ;
if ( transfer_type = = TransferLocked )
{
try
{
locked_blocks = boost : : lexical_cast < uint64_t > ( local_args . back ( ) ) ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " bad locked_blocks parameter: " ) < < " " < < local_args . back ( ) ;
return true ;
}
if ( locked_blocks > 1000000 )
{
fail_msg_writer ( ) < < tr ( " Locked blocks too high, max 1000000 (˜ 4 yrs) " ) ;
return true ;
}
local_args . pop_back ( ) ;
}
2014-05-03 16:19:43 +00:00
vector < cryptonote : : tx_destination_entry > dsts ;
2018-06-10 11:00:59 +00:00
size_t num_subaddresses = 0 ;
2018-08-01 16:01:36 +00:00
for ( size_t i = 0 ; i < local_args . size ( ) ; )
2014-05-03 16:19:43 +00:00
{
cryptonote : : tx_destination_entry de ;
2018-08-01 16:01:36 +00:00
cryptonote : : address_parse_info info ;
bool r = true ;
// check for a URI
std : : string address_uri , payment_id_uri , tx_description , recipient_name , error ;
std : : vector < std : : string > unknown_parameters ;
uint64_t amount = 0 ;
bool has_uri = m_wallet - > parse_uri ( local_args [ i ] , address_uri , payment_id_uri , amount , tx_description , recipient_name , unknown_parameters , error ) ;
if ( has_uri )
{
r = cryptonote : : get_account_address_from_str_or_url ( info , m_wallet - > nettype ( ) , address_uri , oa_prompter ) ;
if ( payment_id_uri . size ( ) = = 16 )
{
if ( ! tools : : wallet2 : : parse_short_payment_id ( payment_id_uri , info . payment_id ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse short payment ID from URI " ) ;
return true ;
}
info . has_payment_id = true ;
}
de . amount = amount ;
+ + i ;
}
else if ( i + 1 < local_args . size ( ) )
{
r = cryptonote : : get_account_address_from_str_or_url ( info , m_wallet - > nettype ( ) , local_args [ i ] , oa_prompter ) ;
bool ok = cryptonote : : parse_amount ( de . amount , local_args [ i + 1 ] ) ;
if ( ! ok | | 0 = = de . amount )
{
fail_msg_writer ( ) < < tr ( " amount is wrong: " ) < < local_args [ i ] < < ' ' < < local_args [ i + 1 ] < <
" , " < < tr ( " expected number from 0 to " ) < < print_money ( std : : numeric_limits < uint64_t > : : max ( ) ) ;
return true ;
}
i + = 2 ;
}
else
{
if ( boost : : starts_with ( local_args [ i ] , " monero: " ) )
fail_msg_writer ( ) < < tr ( " Invalid last argument: " ) < < local_args . back ( ) < < " : " < < error ;
else
fail_msg_writer ( ) < < tr ( " Invalid last argument: " ) < < local_args . back ( ) ;
return true ;
}
if ( ! r )
2017-02-08 14:04:48 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse address " ) ;
2016-04-19 20:20:27 +00:00
return true ;
2017-02-08 14:04:48 +00:00
}
2017-02-19 02:42:10 +00:00
de . addr = info . address ;
de . is_subaddress = info . is_subaddress ;
2018-06-10 11:00:59 +00:00
num_subaddresses + = info . is_subaddress ;
2014-03-20 11:46:11 +00:00
2018-08-01 16:01:36 +00:00
if ( info . has_payment_id | | ! payment_id_uri . empty ( ) )
2015-08-09 09:09:39 +00:00
{
if ( payment_id_seen )
{
2018-08-01 16:01:36 +00:00
fail_msg_writer ( ) < < tr ( " a single transaction cannot use more than one payment id " ) ;
2015-06-11 08:44:13 +00:00
return true ;
}
2018-08-01 16:01:36 +00:00
crypto : : hash payment_id ;
2015-08-09 09:09:39 +00:00
std : : string extra_nonce ;
2018-08-01 16:01:36 +00:00
if ( info . has_payment_id )
{
set_encrypted_payment_id_to_tx_extra_nonce ( extra_nonce , info . payment_id ) ;
}
else if ( tools : : wallet2 : : parse_payment_id ( payment_id_uri , payment_id ) )
{
set_payment_id_to_tx_extra_nonce ( extra_nonce , payment_id ) ;
message_writer ( ) < < tr ( " Unencrypted payment IDs are bad for privacy: ask the recipient to use subaddresses instead " ) ;
}
else
{
fail_msg_writer ( ) < < tr ( " failed to parse payment id, though it was detected " ) ;
return true ;
}
2015-08-09 09:09:39 +00:00
bool r = add_extra_nonce_to_tx_extra ( extra , extra_nonce ) ;
if ( ! r )
2015-06-11 08:44:13 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " failed to set up payment id, though it was decoded correctly " ) ;
2015-08-09 09:09:39 +00:00
return true ;
2015-06-11 08:44:13 +00:00
}
2016-10-01 16:03:53 +00:00
payment_id_seen = true ;
2015-06-11 08:44:13 +00:00
}
2014-03-03 22:07:58 +00:00
dsts . push_back ( de ) ;
}
2016-10-01 16:03:53 +00:00
// prompt is there is no payment id and confirmation is required
2018-06-10 11:00:59 +00:00
if ( ! payment_id_seen & & m_wallet - > confirm_missing_payment_id ( ) & & dsts . size ( ) > num_subaddresses )
2016-10-01 16:03:53 +00:00
{
2017-10-28 18:13:42 +00:00
std : : string accepted = input_line ( tr ( " No payment id is included with this transaction. Is this okay? (Y/Yes/N/No): " ) ) ;
2016-10-01 16:03:53 +00:00
if ( std : : cin . eof ( ) )
return true ;
2016-11-26 02:07:45 +00:00
if ( ! command_line : : is_yes ( accepted ) )
2016-10-01 16:03:53 +00:00
{
fail_msg_writer ( ) < < tr ( " transaction cancelled. " ) ;
return true ;
}
}
2018-10-10 20:01:04 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2014-04-02 16:00:17 +00:00
try
2014-03-03 22:07:58 +00:00
{
2014-06-17 22:15:21 +00:00
// figure out what tx will be necessary
2015-07-19 22:47:13 +00:00
std : : vector < tools : : wallet2 : : pending_tx > ptx_vector ;
2016-10-22 12:29:23 +00:00
uint64_t bc_height , unlock_block = 0 ;
std : : string err ;
2016-06-15 22:37:13 +00:00
switch ( transfer_type )
{
2016-10-22 12:29:23 +00:00
case TransferLocked :
bc_height = get_daemon_blockchain_height ( err ) ;
if ( ! err . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " failed to get blockchain height: " ) < < err ;
return true ;
}
unlock_block = bc_height + locked_blocks ;
2018-08-10 12:15:40 +00:00
ptx_vector = m_wallet - > create_transactions_2 ( dsts , fake_outs_count , unlock_block /* unlock_time */ , priority , extra , m_current_subaddress_account , subaddr_indices ) ;
2016-10-22 12:29:23 +00:00
break ;
2018-08-13 16:18:32 +00:00
default :
LOG_ERROR ( " Unknown transfer method, using default " ) ;
/* FALLTHRU */
2018-09-16 14:28:59 +00:00
case Transfer :
2018-08-10 12:15:40 +00:00
ptx_vector = m_wallet - > create_transactions_2 ( dsts , fake_outs_count , 0 /* unlock_time */ , priority , extra , m_current_subaddress_account , subaddr_indices ) ;
2016-06-15 22:37:13 +00:00
break ;
}
2014-06-17 22:15:21 +00:00
2017-03-18 11:43:13 +00:00
if ( ptx_vector . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " No outputs found, or daemon is not ready " ) ;
return true ;
}
2017-08-26 15:23:54 +00:00
// if we need to check for backlog, check the worst case tx
if ( m_wallet - > confirm_backlog ( ) )
{
std : : stringstream prompt ;
double worst_fee_per_byte = std : : numeric_limits < double > : : max ( ) ;
for ( size_t n = 0 ; n < ptx_vector . size ( ) ; + + n )
{
const uint64_t blob_size = cryptonote : : tx_to_blob ( ptx_vector [ n ] . tx ) . size ( ) ;
const double fee_per_byte = ptx_vector [ n ] . fee / ( double ) blob_size ;
if ( fee_per_byte < worst_fee_per_byte )
{
worst_fee_per_byte = fee_per_byte ;
}
}
try
{
2018-01-15 13:38:33 +00:00
std : : vector < std : : pair < uint64_t , uint64_t > > nblocks = m_wallet - > estimate_backlog ( { std : : make_pair ( worst_fee_per_byte , worst_fee_per_byte ) } ) ;
2017-08-27 20:04:56 +00:00
if ( nblocks . size ( ) ! = 1 )
{
prompt < < " Internal error checking for backlog. " < < tr ( " Is this okay anyway? (Y/Yes/N/No): " ) ;
}
else
{
2017-09-18 11:46:33 +00:00
if ( nblocks [ 0 ] . first > m_wallet - > get_confirm_backlog_threshold ( ) )
2018-01-06 15:04:04 +00:00
prompt < < ( boost : : format ( tr ( " There is currently a %u block backlog at that fee level. Is this okay? (Y/Yes/N/No): " ) ) % nblocks [ 0 ] . first ) . str ( ) ;
2017-08-27 20:04:56 +00:00
}
2017-08-26 15:23:54 +00:00
}
catch ( const std : : exception & e )
{
prompt < < tr ( " Failed to check for backlog: " ) < < e . what ( ) < < ENDL < < tr ( " Is this okay anyway? (Y/Yes/N/No): " ) ;
}
std : : string prompt_str = prompt . str ( ) ;
if ( ! prompt_str . empty ( ) )
{
2017-10-28 18:13:42 +00:00
std : : string accepted = input_line ( prompt_str ) ;
2017-08-26 15:23:54 +00:00
if ( std : : cin . eof ( ) )
return true ;
if ( ! command_line : : is_yes ( accepted ) )
{
fail_msg_writer ( ) < < tr ( " transaction cancelled. " ) ;
return true ;
}
}
}
2014-06-17 22:15:21 +00:00
// if more than one tx necessary, prompt user to confirm
2015-07-18 21:03:35 +00:00
if ( m_wallet - > always_confirm_transfers ( ) | | ptx_vector . size ( ) > 1 )
2014-06-17 22:15:21 +00:00
{
2016-11-13 12:12:22 +00:00
uint64_t total_sent = 0 ;
2015-07-18 21:03:35 +00:00
uint64_t total_fee = 0 ;
2016-04-18 02:57:47 +00:00
uint64_t dust_not_in_fee = 0 ;
uint64_t dust_in_fee = 0 ;
2015-07-18 21:03:35 +00:00
for ( size_t n = 0 ; n < ptx_vector . size ( ) ; + + n )
{
total_fee + = ptx_vector [ n ] . fee ;
2016-11-13 12:12:22 +00:00
for ( auto i : ptx_vector [ n ] . selected_transfers )
total_sent + = m_wallet - > get_transfer_details ( i ) . amount ( ) ;
total_sent - = ptx_vector [ n ] . change_dts . amount + ptx_vector [ n ] . fee ;
2016-04-18 02:57:47 +00:00
if ( ptx_vector [ n ] . dust_added_to_fee )
dust_in_fee + = ptx_vector [ n ] . dust ;
else
dust_not_in_fee + = ptx_vector [ n ] . dust ;
2015-07-18 21:03:35 +00:00
}
2016-04-18 02:57:47 +00:00
std : : stringstream prompt ;
2017-02-19 02:42:10 +00:00
for ( size_t n = 0 ; n < ptx_vector . size ( ) ; + + n )
{
prompt < < tr ( " \n Transaction " ) < < ( n + 1 ) < < " / " < < ptx_vector . size ( ) < < " : \n " ;
subaddr_indices . clear ( ) ;
for ( uint32_t i : ptx_vector [ n ] . construction_data . subaddr_indices )
subaddr_indices . insert ( i ) ;
for ( uint32_t i : subaddr_indices )
prompt < < boost : : format ( tr ( " Spending from address index %d \n " ) ) % i ;
if ( subaddr_indices . size ( ) > 1 )
prompt < < tr ( " WARNING: Outputs of multiple addresses are being used together, which might potentially compromise your privacy. \n " ) ;
}
2016-11-13 12:12:22 +00:00
prompt < < boost : : format ( tr ( " Sending %s. " ) ) % print_money ( total_sent ) ;
2016-02-20 11:17:28 +00:00
if ( ptx_vector . size ( ) > 1 )
{
2016-04-18 02:57:47 +00:00
prompt < < boost : : format ( tr ( " Your transaction needs to be split into %llu transactions. "
" This will result in a transaction fee being applied to each transaction, for a total fee of %s " ) ) %
( ( unsigned long long ) ptx_vector . size ( ) ) % print_money ( total_fee ) ;
2016-02-20 11:17:28 +00:00
}
else
{
2016-04-18 02:57:47 +00:00
prompt < < boost : : format ( tr ( " The transaction fee is %s " ) ) %
print_money ( total_fee ) ;
2016-02-20 11:17:28 +00:00
}
2016-04-18 02:57:47 +00:00
if ( dust_in_fee ! = 0 ) prompt < < boost : : format ( tr ( " , of which %s is dust from change " ) ) % print_money ( dust_in_fee ) ;
if ( dust_not_in_fee ! = 0 ) prompt < < tr ( " . " ) < < ENDL < < boost : : format ( tr ( " A total of %s from dust change will be sent to dust address " ) )
% print_money ( dust_not_in_fee ) ;
2016-10-22 12:29:23 +00:00
if ( transfer_type = = TransferLocked )
{
float days = locked_blocks / 720.0f ;
prompt < < boost : : format ( tr ( " . \n This transaction will unlock on block %llu, in approximately %s days (assuming 2 minutes per block) " ) ) % ( ( unsigned long long ) unlock_block ) % days ;
}
2016-12-23 12:04:54 +00:00
if ( m_wallet - > print_ring_members ( ) )
{
if ( ! print_ring_members ( ptx_vector , prompt ) )
return true ;
}
2018-03-31 13:20:48 +00:00
bool default_ring_size = true ;
for ( const auto & ptx : ptx_vector )
{
for ( const auto & vin : ptx . tx . vin )
{
if ( vin . type ( ) = = typeid ( txin_to_key ) )
{
const txin_to_key & in_to_key = boost : : get < txin_to_key > ( vin ) ;
if ( in_to_key . key_offsets . size ( ) ! = DEFAULT_MIX + 1 )
default_ring_size = false ;
}
}
}
if ( m_wallet - > confirm_non_default_ring_size ( ) & & ! default_ring_size )
{
prompt < < tr ( " WARNING: this is a non default ring size, which may harm your privacy. Default is recommended. " ) ;
}
2016-12-23 12:04:54 +00:00
prompt < < ENDL < < tr ( " Is this okay? (Y/Yes/N/No): " ) ;
2016-04-18 02:57:47 +00:00
2017-10-28 18:13:42 +00:00
std : : string accepted = input_line ( prompt . str ( ) ) ;
2016-03-29 16:52:45 +00:00
if ( std : : cin . eof ( ) )
return true ;
2016-11-26 02:07:45 +00:00
if ( ! command_line : : is_yes ( accepted ) )
2014-06-17 22:15:21 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " transaction cancelled. " ) ;
2014-06-17 22:15:21 +00:00
return true ;
}
}
// actually commit the transactions
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( m_wallet - > multisig ( ) )
{
bool r = m_wallet - > save_multisig_tx ( ptx_vector , " multisig_monero_tx " ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Failed to write transaction(s) to file " ) ;
}
else
{
success_msg_writer ( true ) < < tr ( " Unsigned transaction(s) successfully written to file: " ) < < " multisig_monero_tx " ;
}
}
else if ( m_wallet - > watch_only ( ) )
2016-09-26 22:11:10 +00:00
{
bool r = m_wallet - > save_tx ( ptx_vector , " unsigned_monero_tx " ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Failed to write transaction(s) to file " ) ;
}
else
{
success_msg_writer ( true ) < < tr ( " Unsigned transaction(s) successfully written to file: " ) < < " unsigned_monero_tx " ;
}
}
2017-10-06 01:14:09 +00:00
else
2014-06-17 22:15:21 +00:00
{
2017-10-06 01:14:09 +00:00
commit_or_save ( ptx_vector , m_do_not_relay ) ;
2014-06-17 22:15:21 +00:00
}
2014-04-02 16:00:17 +00:00
}
2017-10-11 08:04:36 +00:00
catch ( const std : : exception & e )
2015-05-30 08:13:52 +00:00
{
2018-08-10 12:15:40 +00:00
handle_transfer_exception ( std : : current_exception ( ) , m_wallet - > is_trusted_daemon ( ) ) ;
2015-05-30 08:13:52 +00:00
}
catch ( . . . )
{
2015-12-12 00:05:39 +00:00
LOG_ERROR ( " unknown error " ) ;
2015-07-14 19:28:25 +00:00
fail_msg_writer ( ) < < tr ( " unknown error " ) ;
2015-05-30 08:13:52 +00:00
}
return true ;
}
2015-07-19 22:47:13 +00:00
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : transfer ( const std : : vector < std : : string > & args_ )
{
2018-09-16 14:28:59 +00:00
return transfer_main ( Transfer , args_ ) ;
2016-06-15 22:37:13 +00:00
}
//----------------------------------------------------------------------------------------------------
2016-09-28 13:20:37 +00:00
bool simple_wallet : : locked_transfer ( const std : : vector < std : : string > & args_ )
{
2016-10-22 12:29:23 +00:00
return transfer_main ( TransferLocked , args_ ) ;
2015-05-30 08:13:52 +00:00
}
2015-07-19 22:47:13 +00:00
//----------------------------------------------------------------------------------------------------
2018-04-13 01:13:24 +00:00
bool simple_wallet : : locked_sweep_all ( const std : : vector < std : : string > & args_ )
{
return sweep_main ( 0 , true , args_ ) ;
}
//----------------------------------------------------------------------------------------------------
2016-09-28 13:20:37 +00:00
2016-03-26 21:15:47 +00:00
bool simple_wallet : : sweep_unmixable ( const std : : vector < std : : string > & args_ )
2015-05-30 08:13:52 +00:00
{
if ( ! try_connect_to_daemon ( ) )
return true ;
2018-07-08 20:12:33 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2015-05-30 08:13:52 +00:00
try
{
// figure out what tx will be necessary
2018-08-10 12:15:40 +00:00
auto ptx_vector = m_wallet - > create_unmixable_sweep_transactions ( ) ;
2016-03-26 21:15:47 +00:00
if ( ptx_vector . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " No unmixable outputs found " ) ;
return true ;
}
2015-05-30 08:13:52 +00:00
// give user total and fee, and prompt to confirm
2016-03-26 21:15:47 +00:00
uint64_t total_fee = 0 , total_unmixable = 0 ;
2015-05-30 08:13:52 +00:00
for ( size_t n = 0 ; n < ptx_vector . size ( ) ; + + n )
{
total_fee + = ptx_vector [ n ] . fee ;
2016-10-15 18:18:52 +00:00
for ( auto i : ptx_vector [ n ] . selected_transfers )
total_unmixable + = m_wallet - > get_transfer_details ( i ) . amount ( ) ;
2015-05-30 08:13:52 +00:00
}
2016-03-26 21:15:47 +00:00
std : : string prompt_str = tr ( " Sweeping " ) + print_money ( total_unmixable ) ;
2015-05-30 08:13:52 +00:00
if ( ptx_vector . size ( ) > 1 ) {
2016-12-13 01:53:28 +00:00
prompt_str = ( boost : : format ( tr ( " Sweeping %s in %llu transactions for a total fee of %s. Is this okay? (Y/Yes/N/No): " ) ) %
2016-03-26 21:15:47 +00:00
print_money ( total_unmixable ) %
2015-07-19 10:55:36 +00:00
( ( unsigned long long ) ptx_vector . size ( ) ) %
2015-07-14 19:28:25 +00:00
print_money ( total_fee ) ) . str ( ) ;
}
else {
2016-12-13 01:53:28 +00:00
prompt_str = ( boost : : format ( tr ( " Sweeping %s for a total fee of %s. Is this okay? (Y/Yes/N/No): " ) ) %
2016-03-26 21:15:47 +00:00
print_money ( total_unmixable ) %
2015-07-14 19:28:25 +00:00
print_money ( total_fee ) ) . str ( ) ;
2015-05-30 08:13:52 +00:00
}
2017-10-28 18:13:42 +00:00
std : : string accepted = input_line ( prompt_str ) ;
2016-03-29 16:52:45 +00:00
if ( std : : cin . eof ( ) )
return true ;
2016-11-26 02:07:45 +00:00
if ( ! command_line : : is_yes ( accepted ) )
2015-05-30 08:13:52 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " transaction cancelled. " ) ;
2015-05-30 08:13:52 +00:00
2016-04-19 20:20:27 +00:00
return true ;
}
// actually commit the transactions
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( m_wallet - > multisig ( ) )
{
bool r = m_wallet - > save_multisig_tx ( ptx_vector , " multisig_monero_tx " ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Failed to write transaction(s) to file " ) ;
}
else
{
success_msg_writer ( true ) < < tr ( " Unsigned transaction(s) successfully written to file: " ) < < " multisig_monero_tx " ;
}
}
else if ( m_wallet - > watch_only ( ) )
2016-09-26 22:11:10 +00:00
{
bool r = m_wallet - > save_tx ( ptx_vector , " unsigned_monero_tx " ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Failed to write transaction(s) to file " ) ;
}
else
{
success_msg_writer ( true ) < < tr ( " Unsigned transaction(s) successfully written to file: " ) < < " unsigned_monero_tx " ;
}
}
2017-10-06 01:14:09 +00:00
else
2016-04-19 20:20:27 +00:00
{
2017-10-06 01:14:09 +00:00
commit_or_save ( ptx_vector , m_do_not_relay ) ;
2016-04-19 20:20:27 +00:00
}
}
2018-06-12 03:44:40 +00:00
catch ( const tools : : error : : not_enough_unlocked_money & e )
{
fail_msg_writer ( ) < < tr ( " Not enough money in unlocked balance " ) ;
std : : string accepted = input_line ( ( boost : : format ( tr ( " Discarding %s of unmixable outputs that cannot be spent, which can be undone by \" rescan_spent \" . Is this okay? (Y/Yes/N/No): " ) ) % print_money ( e . available ( ) ) ) . str ( ) ) ;
if ( std : : cin . eof ( ) )
return true ;
if ( command_line : : is_yes ( accepted ) )
{
try
{
2018-08-10 12:15:40 +00:00
m_wallet - > discard_unmixable_outputs ( ) ;
2018-06-12 03:44:40 +00:00
} catch ( . . . ) { }
}
}
2017-10-11 08:04:36 +00:00
catch ( const std : : exception & e )
2016-04-19 20:20:27 +00:00
{
2018-08-10 12:15:40 +00:00
handle_transfer_exception ( std : : current_exception ( ) , m_wallet - > is_trusted_daemon ( ) ) ;
2016-04-19 20:20:27 +00:00
}
catch ( . . . )
{
LOG_ERROR ( " unknown error " ) ;
fail_msg_writer ( ) < < tr ( " unknown error " ) ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2018-04-13 01:13:24 +00:00
bool simple_wallet : : sweep_main ( uint64_t below , bool locked , const std : : vector < std : : string > & args_ )
2016-04-19 20:20:27 +00:00
{
2018-06-27 11:33:26 +00:00
auto print_usage = [ below ] ( )
{
2018-05-06 08:38:47 +00:00
fail_msg_writer ( ) < < boost : : format ( tr ( " usage: %s [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] [outputs=<N>] <address> [<payment_id>] " ) ) % ( below ? " sweep_below " : " sweep_all " ) ;
2018-06-27 11:33:26 +00:00
} ;
2017-11-03 03:49:26 +00:00
if ( args_ . size ( ) = = 0 )
{
fail_msg_writer ( ) < < tr ( " No address given " ) ;
2018-06-27 11:33:26 +00:00
print_usage ( ) ;
2017-11-03 03:49:26 +00:00
return true ;
}
2016-04-19 20:20:27 +00:00
if ( ! try_connect_to_daemon ( ) )
return true ;
std : : vector < std : : string > local_args = args_ ;
2017-02-19 02:42:10 +00:00
std : : set < uint32_t > subaddr_indices ;
if ( local_args . size ( ) > 0 & & local_args [ 0 ] . substr ( 0 , 6 ) = = " index= " )
{
if ( ! parse_subaddress_indices ( local_args [ 0 ] , subaddr_indices ) )
2018-06-27 11:33:26 +00:00
{
print_usage ( ) ;
2017-02-19 02:42:10 +00:00
return true ;
2018-06-27 11:33:26 +00:00
}
2017-02-19 02:42:10 +00:00
local_args . erase ( local_args . begin ( ) ) ;
}
2017-10-07 03:40:27 +00:00
uint32_t priority = 0 ;
if ( local_args . size ( ) > 0 & & parse_priority ( local_args [ 0 ] , priority ) )
local_args . erase ( local_args . begin ( ) ) ;
2018-01-15 03:05:16 +00:00
priority = m_wallet - > adjust_priority ( priority ) ;
2017-09-08 10:36:49 +00:00
size_t fake_outs_count = 0 ;
2016-04-19 20:20:27 +00:00
if ( local_args . size ( ) > 0 ) {
2017-07-31 06:50:41 +00:00
size_t ring_size ;
if ( ! epee : : string_tools : : get_xtype_from_string ( ring_size , local_args [ 0 ] ) )
2016-04-19 20:20:27 +00:00
{
fake_outs_count = m_wallet - > default_mixin ( ) ;
if ( fake_outs_count = = 0 )
fake_outs_count = DEFAULT_MIX ;
}
2017-10-10 09:43:36 +00:00
else if ( ring_size = = 0 )
{
fail_msg_writer ( ) < < tr ( " Ring size must not be 0 " ) ;
return true ;
}
2016-04-19 20:20:27 +00:00
else
{
2017-07-31 06:50:41 +00:00
fake_outs_count = ring_size - 1 ;
2016-04-19 20:20:27 +00:00
local_args . erase ( local_args . begin ( ) ) ;
}
}
2017-10-10 09:33:17 +00:00
uint64_t adjusted_fake_outs_count = m_wallet - > adjust_mixin ( fake_outs_count ) ;
if ( adjusted_fake_outs_count > fake_outs_count )
{
fail_msg_writer ( ) < < ( boost : : format ( tr ( " ring size %u is too small, minimum is %u " ) ) % ( fake_outs_count + 1 ) % ( adjusted_fake_outs_count + 1 ) ) . str ( ) ;
return true ;
}
2018-07-18 21:24:53 +00:00
if ( adjusted_fake_outs_count < fake_outs_count )
{
fail_msg_writer ( ) < < ( boost : : format ( tr ( " ring size %u is too large, maximum is %u " ) ) % ( fake_outs_count + 1 ) % ( adjusted_fake_outs_count + 1 ) ) . str ( ) ;
return true ;
}
2016-04-19 20:20:27 +00:00
2018-04-13 01:13:24 +00:00
uint64_t unlock_block = 0 ;
if ( locked ) {
uint64_t locked_blocks = 0 ;
if ( local_args . size ( ) < 2 ) {
fail_msg_writer ( ) < < tr ( " missing lockedblocks parameter " ) ;
return true ;
}
try
{
locked_blocks = boost : : lexical_cast < uint64_t > ( local_args [ 1 ] ) ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " bad locked_blocks parameter " ) ;
return true ;
}
if ( locked_blocks > 1000000 )
{
fail_msg_writer ( ) < < tr ( " Locked blocks too high, max 1000000 (˜ 4 yrs) " ) ;
return true ;
}
std : : string err ;
uint64_t bc_height = get_daemon_blockchain_height ( err ) ;
if ( ! err . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " failed to get blockchain height: " ) < < err ;
return true ;
}
unlock_block = bc_height + locked_blocks ;
local_args . erase ( local_args . begin ( ) + 1 ) ;
}
2018-05-06 08:38:47 +00:00
size_t outputs = 1 ;
if ( local_args . size ( ) > 0 & & local_args [ 0 ] . substr ( 0 , 8 ) = = " outputs= " )
{
if ( ! epee : : string_tools : : get_xtype_from_string ( outputs , local_args [ 0 ] . substr ( 8 ) ) )
{
fail_msg_writer ( ) < < tr ( " Failed to parse number of outputs " ) ;
return true ;
}
else if ( outputs < 1 )
{
fail_msg_writer ( ) < < tr ( " Amount of outputs should be greater than 0 " ) ;
return true ;
}
else
{
local_args . erase ( local_args . begin ( ) ) ;
}
}
2016-04-19 20:20:27 +00:00
std : : vector < uint8_t > extra ;
bool payment_id_seen = false ;
2018-04-13 01:13:24 +00:00
if ( local_args . size ( ) > = 2 )
2016-04-19 20:20:27 +00:00
{
std : : string payment_id_str = local_args . back ( ) ;
crypto : : hash payment_id ;
bool r = tools : : wallet2 : : parse_long_payment_id ( payment_id_str , payment_id ) ;
if ( r )
{
std : : string extra_nonce ;
set_payment_id_to_tx_extra_nonce ( extra_nonce , payment_id ) ;
r = add_extra_nonce_to_tx_extra ( extra , extra_nonce ) ;
2017-02-19 02:42:10 +00:00
payment_id_seen = true ;
2016-04-19 20:20:27 +00:00
}
else
{
crypto : : hash8 payment_id8 ;
r = tools : : wallet2 : : parse_short_payment_id ( payment_id_str , payment_id8 ) ;
if ( r )
{
std : : string extra_nonce ;
set_encrypted_payment_id_to_tx_extra_nonce ( extra_nonce , payment_id8 ) ;
r = add_extra_nonce_to_tx_extra ( extra , extra_nonce ) ;
2017-02-19 02:42:10 +00:00
payment_id_seen = true ;
2016-04-19 20:20:27 +00:00
}
}
2017-02-19 02:42:10 +00:00
if ( ! r & & local_args . size ( ) = = 3 )
2016-04-19 20:20:27 +00:00
{
fail_msg_writer ( ) < < tr ( " payment id has invalid format, expected 16 or 64 character hex string: " ) < < payment_id_str ;
2018-06-27 11:33:26 +00:00
print_usage ( ) ;
2016-04-19 20:20:27 +00:00
return true ;
}
2017-02-19 02:42:10 +00:00
if ( payment_id_seen )
local_args . pop_back ( ) ;
2016-04-19 20:20:27 +00:00
}
2017-02-19 02:42:10 +00:00
cryptonote : : address_parse_info info ;
2018-02-16 11:04:04 +00:00
if ( ! cryptonote : : get_account_address_from_str_or_url ( info , m_wallet - > nettype ( ) , local_args [ 0 ] , oa_prompter ) )
2017-02-08 14:04:48 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse address " ) ;
2018-06-27 11:33:26 +00:00
print_usage ( ) ;
2016-04-19 20:20:27 +00:00
return true ;
2017-02-08 14:04:48 +00:00
}
2016-04-19 20:20:27 +00:00
2017-02-19 02:42:10 +00:00
if ( info . has_payment_id )
2016-04-19 20:20:27 +00:00
{
if ( payment_id_seen )
{
fail_msg_writer ( ) < < tr ( " a single transaction cannot use more than one payment id: " ) < < local_args [ 0 ] ;
return true ;
}
std : : string extra_nonce ;
2017-02-19 02:42:10 +00:00
set_encrypted_payment_id_to_tx_extra_nonce ( extra_nonce , info . payment_id ) ;
2016-04-19 20:20:27 +00:00
bool r = add_extra_nonce_to_tx_extra ( extra , extra_nonce ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " failed to set up payment id, though it was decoded correctly " ) ;
return true ;
}
2016-10-01 16:03:53 +00:00
payment_id_seen = true ;
}
// prompt is there is no payment id and confirmation is required
2018-06-10 11:00:59 +00:00
if ( ! payment_id_seen & & m_wallet - > confirm_missing_payment_id ( ) & & ! info . is_subaddress )
2016-10-01 16:03:53 +00:00
{
2017-10-28 18:13:42 +00:00
std : : string accepted = input_line ( tr ( " No payment id is included with this transaction. Is this okay? (Y/Yes/N/No): " ) ) ;
2016-10-01 16:03:53 +00:00
if ( std : : cin . eof ( ) )
return true ;
2016-11-26 02:07:45 +00:00
if ( ! command_line : : is_yes ( accepted ) )
2016-10-01 16:03:53 +00:00
{
fail_msg_writer ( ) < < tr ( " transaction cancelled. " ) ;
return true ;
}
2016-04-19 20:20:27 +00:00
}
2018-07-08 20:12:33 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2017-06-30 08:33:37 +00:00
2016-04-19 20:20:27 +00:00
try
{
// figure out what tx will be necessary
2018-05-06 08:38:47 +00:00
auto ptx_vector = m_wallet - > create_transactions_all ( below , info . address , info . is_subaddress , outputs , fake_outs_count , unlock_block /* unlock_time */ , priority , extra , m_current_subaddress_account , subaddr_indices ) ;
2016-04-19 20:20:27 +00:00
if ( ptx_vector . empty ( ) )
{
2017-03-18 11:43:13 +00:00
fail_msg_writer ( ) < < tr ( " No outputs found, or daemon is not ready " ) ;
2016-04-19 20:20:27 +00:00
return true ;
}
// give user total and fee, and prompt to confirm
uint64_t total_fee = 0 , total_sent = 0 ;
for ( size_t n = 0 ; n < ptx_vector . size ( ) ; + + n )
{
total_fee + = ptx_vector [ n ] . fee ;
2016-10-15 18:18:52 +00:00
for ( auto i : ptx_vector [ n ] . selected_transfers )
total_sent + = m_wallet - > get_transfer_details ( i ) . amount ( ) ;
2016-04-19 20:20:27 +00:00
}
2016-12-23 12:04:54 +00:00
std : : ostringstream prompt ;
2017-02-19 02:42:10 +00:00
for ( size_t n = 0 ; n < ptx_vector . size ( ) ; + + n )
{
prompt < < tr ( " \n Transaction " ) < < ( n + 1 ) < < " / " < < ptx_vector . size ( ) < < " : \n " ;
subaddr_indices . clear ( ) ;
for ( uint32_t i : ptx_vector [ n ] . construction_data . subaddr_indices )
subaddr_indices . insert ( i ) ;
for ( uint32_t i : subaddr_indices )
prompt < < boost : : format ( tr ( " Spending from address index %d \n " ) ) % i ;
if ( subaddr_indices . size ( ) > 1 )
prompt < < tr ( " WARNING: Outputs of multiple addresses are being used together, which might potentially compromise your privacy. \n " ) ;
}
if ( m_wallet - > print_ring_members ( ) & & ! print_ring_members ( ptx_vector , prompt ) )
2016-12-23 12:04:54 +00:00
return true ;
2016-04-19 20:20:27 +00:00
if ( ptx_vector . size ( ) > 1 ) {
2016-12-23 12:04:54 +00:00
prompt < < boost : : format ( tr ( " Sweeping %s in %llu transactions for a total fee of %s. Is this okay? (Y/Yes/N/No): " ) ) %
2016-04-19 20:20:27 +00:00
print_money ( total_sent ) %
( ( unsigned long long ) ptx_vector . size ( ) ) %
2016-12-23 12:04:54 +00:00
print_money ( total_fee ) ;
2016-04-19 20:20:27 +00:00
}
else {
2018-01-06 15:04:04 +00:00
prompt < < boost : : format ( tr ( " Sweeping %s for a total fee of %s. Is this okay? (Y/Yes/N/No): " ) ) %
2016-04-19 20:20:27 +00:00
print_money ( total_sent ) %
2016-12-23 12:04:54 +00:00
print_money ( total_fee ) ;
2016-04-19 20:20:27 +00:00
}
2017-10-28 18:13:42 +00:00
std : : string accepted = input_line ( prompt . str ( ) ) ;
2016-04-19 20:20:27 +00:00
if ( std : : cin . eof ( ) )
return true ;
2016-11-26 02:07:45 +00:00
if ( ! command_line : : is_yes ( accepted ) )
2016-04-19 20:20:27 +00:00
{
fail_msg_writer ( ) < < tr ( " transaction cancelled. " ) ;
2015-05-30 08:13:52 +00:00
return true ;
}
// actually commit the transactions
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( m_wallet - > multisig ( ) )
{
bool r = m_wallet - > save_multisig_tx ( ptx_vector , " multisig_monero_tx " ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Failed to write transaction(s) to file " ) ;
}
else
{
success_msg_writer ( true ) < < tr ( " Unsigned transaction(s) successfully written to file: " ) < < " multisig_monero_tx " ;
}
}
else if ( m_wallet - > watch_only ( ) )
2016-09-26 22:11:10 +00:00
{
bool r = m_wallet - > save_tx ( ptx_vector , " unsigned_monero_tx " ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Failed to write transaction(s) to file " ) ;
}
else
{
success_msg_writer ( true ) < < tr ( " Unsigned transaction(s) successfully written to file: " ) < < " unsigned_monero_tx " ;
}
}
2017-10-06 01:14:09 +00:00
else
2015-05-30 08:13:52 +00:00
{
2017-10-06 01:14:09 +00:00
commit_or_save ( ptx_vector , m_do_not_relay ) ;
2015-05-30 08:13:52 +00:00
}
}
2014-04-02 16:00:17 +00:00
catch ( const std : : exception & e )
{
2018-08-10 12:15:40 +00:00
handle_transfer_exception ( std : : current_exception ( ) , m_wallet - > is_trusted_daemon ( ) ) ;
2014-04-02 16:00:17 +00:00
}
catch ( . . . )
{
2015-12-12 00:05:39 +00:00
LOG_ERROR ( " unknown error " ) ;
2017-10-11 01:32:06 +00:00
fail_msg_writer ( ) < < tr ( " unknown error " ) ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : sweep_single ( const std : : vector < std : : string > & args_ )
{
if ( ! try_connect_to_daemon ( ) )
return true ;
std : : vector < std : : string > local_args = args_ ;
2018-01-15 03:05:16 +00:00
uint32_t priority = 0 ;
if ( local_args . size ( ) > 0 & & parse_priority ( local_args [ 0 ] , priority ) )
local_args . erase ( local_args . begin ( ) ) ;
priority = m_wallet - > adjust_priority ( priority ) ;
2017-10-11 01:32:06 +00:00
size_t fake_outs_count = 0 ;
if ( local_args . size ( ) > 0 ) {
size_t ring_size ;
if ( ! epee : : string_tools : : get_xtype_from_string ( ring_size , local_args [ 0 ] ) )
{
fake_outs_count = m_wallet - > default_mixin ( ) ;
if ( fake_outs_count = = 0 )
fake_outs_count = DEFAULT_MIX ;
}
2018-07-18 21:24:53 +00:00
else if ( ring_size = = 0 )
{
fail_msg_writer ( ) < < tr ( " Ring size must not be 0 " ) ;
return true ;
}
2017-10-11 01:32:06 +00:00
else
{
fake_outs_count = ring_size - 1 ;
local_args . erase ( local_args . begin ( ) ) ;
}
}
2018-07-18 21:24:53 +00:00
uint64_t adjusted_fake_outs_count = m_wallet - > adjust_mixin ( fake_outs_count ) ;
if ( adjusted_fake_outs_count > fake_outs_count )
{
fail_msg_writer ( ) < < ( boost : : format ( tr ( " ring size %u is too small, minimum is %u " ) ) % ( fake_outs_count + 1 ) % ( adjusted_fake_outs_count + 1 ) ) . str ( ) ;
return true ;
}
if ( adjusted_fake_outs_count < fake_outs_count )
{
fail_msg_writer ( ) < < ( boost : : format ( tr ( " ring size %u is too large, maximum is %u " ) ) % ( fake_outs_count + 1 ) % ( adjusted_fake_outs_count + 1 ) ) . str ( ) ;
return true ;
}
2017-10-11 01:32:06 +00:00
2018-05-06 08:38:47 +00:00
size_t outputs = 1 ;
if ( local_args . size ( ) > 0 & & local_args [ 0 ] . substr ( 0 , 8 ) = = " outputs= " )
{
if ( ! epee : : string_tools : : get_xtype_from_string ( outputs , local_args [ 0 ] . substr ( 8 ) ) )
{
fail_msg_writer ( ) < < tr ( " Failed to parse number of outputs " ) ;
return true ;
}
else if ( outputs < 1 )
{
fail_msg_writer ( ) < < tr ( " Amount of outputs should be greater than 0 " ) ;
return true ;
}
else
{
local_args . erase ( local_args . begin ( ) ) ;
}
}
2017-10-11 01:32:06 +00:00
std : : vector < uint8_t > extra ;
bool payment_id_seen = false ;
if ( local_args . size ( ) = = 3 )
{
crypto : : hash payment_id ;
crypto : : hash8 payment_id8 ;
std : : string extra_nonce ;
if ( tools : : wallet2 : : parse_long_payment_id ( local_args . back ( ) , payment_id ) )
{
set_payment_id_to_tx_extra_nonce ( extra_nonce , payment_id ) ;
}
else if ( tools : : wallet2 : : parse_short_payment_id ( local_args . back ( ) , payment_id8 ) )
{
set_encrypted_payment_id_to_tx_extra_nonce ( extra_nonce , payment_id8 ) ;
}
else
{
fail_msg_writer ( ) < < tr ( " failed to parse Payment ID " ) ;
return true ;
}
if ( ! add_extra_nonce_to_tx_extra ( extra , extra_nonce ) )
{
fail_msg_writer ( ) < < tr ( " failed to set up payment id, though it was decoded correctly " ) ;
return true ;
}
local_args . pop_back ( ) ;
payment_id_seen = true ;
}
if ( local_args . size ( ) ! = 2 )
{
2018-05-06 08:38:47 +00:00
fail_msg_writer ( ) < < tr ( " usage: sweep_single [<priority>] [<ring_size>] [outputs=<N>] <key_image> <address> [<payment_id>] " ) ;
2017-10-11 01:32:06 +00:00
return true ;
}
crypto : : key_image ki ;
if ( ! epee : : string_tools : : hex_to_pod ( local_args [ 0 ] , ki ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse key image " ) ;
return true ;
}
cryptonote : : address_parse_info info ;
2018-02-16 11:04:04 +00:00
if ( ! cryptonote : : get_account_address_from_str_or_url ( info , m_wallet - > nettype ( ) , local_args [ 1 ] , oa_prompter ) )
2017-10-11 01:32:06 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse address " ) ;
return true ;
}
if ( info . has_payment_id )
{
if ( payment_id_seen )
{
fail_msg_writer ( ) < < tr ( " a single transaction cannot use more than one payment id: " ) < < local_args [ 0 ] ;
return true ;
}
std : : string extra_nonce ;
set_encrypted_payment_id_to_tx_extra_nonce ( extra_nonce , info . payment_id ) ;
if ( ! add_extra_nonce_to_tx_extra ( extra , extra_nonce ) )
{
fail_msg_writer ( ) < < tr ( " failed to set up payment id, though it was decoded correctly " ) ;
return true ;
}
payment_id_seen = true ;
}
// prompt if there is no payment id and confirmation is required
2018-06-10 11:00:59 +00:00
if ( ! payment_id_seen & & m_wallet - > confirm_missing_payment_id ( ) & & ! info . is_subaddress )
2017-10-11 01:32:06 +00:00
{
2017-11-15 11:37:18 +00:00
std : : string accepted = input_line ( tr ( " No payment id is included with this transaction. Is this okay? (Y/Yes/N/No): " ) ) ;
2017-10-11 01:32:06 +00:00
if ( std : : cin . eof ( ) )
return true ;
if ( ! command_line : : is_yes ( accepted ) )
{
fail_msg_writer ( ) < < tr ( " transaction cancelled. " ) ;
// would like to return false, because no tx made, but everything else returns true
// and I don't know what returning false might adversely affect. *sigh*
return true ;
}
}
2018-11-04 01:48:49 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2017-10-11 01:32:06 +00:00
try
{
// figure out what tx will be necessary
2018-05-06 08:38:47 +00:00
auto ptx_vector = m_wallet - > create_transactions_single ( ki , info . address , info . is_subaddress , outputs , fake_outs_count , 0 /* unlock_time */ , priority , extra ) ;
2017-10-11 01:32:06 +00:00
if ( ptx_vector . empty ( ) )
{
fail_msg_writer ( ) < < tr ( " No outputs found " ) ;
return true ;
}
if ( ptx_vector . size ( ) > 1 )
{
fail_msg_writer ( ) < < tr ( " Multiple transactions are created, which is not supposed to happen " ) ;
return true ;
}
2017-12-11 22:36:58 +00:00
if ( ptx_vector [ 0 ] . selected_transfers . size ( ) ! = 1 )
2017-10-11 01:32:06 +00:00
{
2017-12-11 22:36:58 +00:00
fail_msg_writer ( ) < < tr ( " The transaction uses multiple or no inputs, which is not supposed to happen " ) ;
2017-10-11 01:32:06 +00:00
return true ;
}
// give user total and fee, and prompt to confirm
uint64_t total_fee = ptx_vector [ 0 ] . fee ;
uint64_t total_sent = m_wallet - > get_transfer_details ( ptx_vector [ 0 ] . selected_transfers . front ( ) ) . amount ( ) ;
std : : ostringstream prompt ;
if ( ! print_ring_members ( ptx_vector , prompt ) )
return true ;
2018-01-06 15:04:04 +00:00
prompt < < boost : : format ( tr ( " Sweeping %s for a total fee of %s. Is this okay? (Y/Yes/N/No): " ) ) %
2017-10-11 01:32:06 +00:00
print_money ( total_sent ) %
print_money ( total_fee ) ;
2017-11-15 11:37:18 +00:00
std : : string accepted = input_line ( prompt . str ( ) ) ;
2017-10-11 01:32:06 +00:00
if ( std : : cin . eof ( ) )
return true ;
if ( ! command_line : : is_yes ( accepted ) )
{
fail_msg_writer ( ) < < tr ( " transaction cancelled. " ) ;
return true ;
}
// actually commit the transactions
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( m_wallet - > multisig ( ) )
{
bool r = m_wallet - > save_multisig_tx ( ptx_vector , " multisig_monero_tx " ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Failed to write transaction(s) to file " ) ;
}
else
{
success_msg_writer ( true ) < < tr ( " Unsigned transaction(s) successfully written to file: " ) < < " multisig_monero_tx " ;
}
}
else if ( m_wallet - > watch_only ( ) )
2017-10-11 01:32:06 +00:00
{
bool r = m_wallet - > save_tx ( ptx_vector , " unsigned_monero_tx " ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Failed to write transaction(s) to file " ) ;
}
else
{
success_msg_writer ( true ) < < tr ( " Unsigned transaction(s) successfully written to file: " ) < < " unsigned_monero_tx " ;
}
}
else
{
m_wallet - > commit_tx ( ptx_vector [ 0 ] ) ;
success_msg_writer ( true ) < < tr ( " Money successfully sent, transaction: " ) < < get_transaction_hash ( ptx_vector [ 0 ] . tx ) ;
}
}
catch ( const std : : exception & e )
{
2018-08-10 12:15:40 +00:00
handle_transfer_exception ( std : : current_exception ( ) , m_wallet - > is_trusted_daemon ( ) ) ;
2017-10-11 01:32:06 +00:00
}
catch ( . . . )
{
LOG_ERROR ( " unknown error " ) ;
2015-07-14 19:28:25 +00:00
fail_msg_writer ( ) < < tr ( " unknown error " ) ;
2014-03-03 22:07:58 +00:00
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2017-04-16 16:46:01 +00:00
bool simple_wallet : : sweep_all ( const std : : vector < std : : string > & args_ )
{
2018-04-13 01:13:24 +00:00
return sweep_main ( 0 , false , args_ ) ;
2017-04-16 16:46:01 +00:00
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : sweep_below ( const std : : vector < std : : string > & args_ )
{
uint64_t below = 0 ;
if ( args_ . size ( ) < 1 )
{
2018-01-09 21:37:30 +00:00
fail_msg_writer ( ) < < tr ( " missing threshold amount " ) ;
2017-04-16 16:46:01 +00:00
return true ;
}
if ( ! cryptonote : : parse_amount ( below , args_ [ 0 ] ) )
{
fail_msg_writer ( ) < < tr ( " invalid amount threshold " ) ;
return true ;
}
2018-04-13 01:13:24 +00:00
return sweep_main ( below , false , std : : vector < std : : string > ( + + args_ . begin ( ) , args_ . end ( ) ) ) ;
2017-04-16 16:46:01 +00:00
}
//----------------------------------------------------------------------------------------------------
2016-12-14 11:44:09 +00:00
bool simple_wallet : : donate ( const std : : vector < std : : string > & args_ )
{
2018-02-16 11:04:04 +00:00
if ( m_wallet - > nettype ( ) ! = cryptonote : : MAINNET )
2017-12-20 17:12:22 +00:00
{
2018-02-16 11:04:04 +00:00
fail_msg_writer ( ) < < tr ( " donations are not enabled on the testnet or on the stagenet " ) ;
2017-12-20 17:12:22 +00:00
return true ;
}
2016-12-14 11:44:09 +00:00
std : : vector < std : : string > local_args = args_ ;
2017-02-19 02:42:10 +00:00
if ( local_args . empty ( ) | | local_args . size ( ) > 5 )
2016-12-14 11:44:09 +00:00
{
2017-02-19 02:42:10 +00:00
fail_msg_writer ( ) < < tr ( " usage: donate [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] <amount> [<payment_id>] " ) ;
2016-12-14 11:44:09 +00:00
return true ;
}
std : : string amount_str ;
std : : string payment_id_str ;
2017-02-19 02:42:10 +00:00
// get payment id and pop
2016-12-14 11:44:09 +00:00
crypto : : hash payment_id ;
crypto : : hash8 payment_id8 ;
if ( tools : : wallet2 : : parse_long_payment_id ( local_args . back ( ) , payment_id ) | |
tools : : wallet2 : : parse_short_payment_id ( local_args . back ( ) , payment_id8 ) )
{
payment_id_str = local_args . back ( ) ;
local_args . pop_back ( ) ;
}
2017-02-19 02:42:10 +00:00
// get amount and pop
amount_str = local_args . back ( ) ;
local_args . pop_back ( ) ;
// push back address, amount, payment id
2018-01-04 14:33:20 +00:00
local_args . push_back ( MONERO_DONATION_ADDR ) ;
2016-12-14 11:44:09 +00:00
local_args . push_back ( amount_str ) ;
if ( ! payment_id_str . empty ( ) )
local_args . push_back ( payment_id_str ) ;
2018-06-20 19:57:23 +00:00
message_writer ( ) < < ( boost : : format ( tr ( " Donating %s %s to The Monero Project (donate.getmonero.org or %s). " ) ) % amount_str % cryptonote : : get_unit ( cryptonote : : get_default_decimal_point ( ) ) % MONERO_DONATION_ADDR ) . str ( ) ;
2018-09-16 14:28:59 +00:00
transfer ( local_args ) ;
2016-12-17 03:37:20 +00:00
return true ;
2016-12-14 11:44:09 +00:00
}
//----------------------------------------------------------------------------------------------------
2016-11-15 21:22:04 +00:00
bool simple_wallet : : accept_loaded_tx ( const std : : function < size_t ( ) > get_num_txes , const std : : function < const tools : : wallet2 : : tx_construction_data & ( size_t ) > & get_tx , const std : : string & extra_message )
2016-09-26 22:11:10 +00:00
{
// gather info to ask the user
uint64_t amount = 0 , amount_to_dests = 0 , change = 0 ;
2017-07-31 06:50:41 +00:00
size_t min_ring_size = ~ 0 ;
2017-02-19 02:42:10 +00:00
std : : unordered_map < cryptonote : : account_public_address , std : : pair < std : : string , uint64_t > > dests ;
2017-04-02 10:11:18 +00:00
int first_known_non_zero_change_index = - 1 ;
2017-07-24 12:10:42 +00:00
std : : string payment_id_string = " " ;
2016-10-30 10:49:22 +00:00
for ( size_t n = 0 ; n < get_num_txes ( ) ; + + n )
2016-09-26 22:11:10 +00:00
{
2016-10-30 10:49:22 +00:00
const tools : : wallet2 : : tx_construction_data & cd = get_tx ( n ) ;
2017-07-24 12:10:42 +00:00
std : : vector < tx_extra_field > tx_extra_fields ;
bool has_encrypted_payment_id = false ;
2017-09-10 16:35:59 +00:00
crypto : : hash8 payment_id8 = crypto : : null_hash8 ;
2017-07-24 12:10:42 +00:00
if ( cryptonote : : parse_tx_extra ( cd . extra , tx_extra_fields ) )
{
tx_extra_nonce extra_nonce ;
if ( find_tx_extra_field_by_type ( tx_extra_fields , extra_nonce ) )
{
crypto : : hash payment_id ;
if ( get_encrypted_payment_id_from_tx_extra_nonce ( extra_nonce . nonce , payment_id8 ) )
{
if ( ! payment_id_string . empty ( ) )
payment_id_string + = " , " ;
payment_id_string = std : : string ( " encrypted payment ID " ) + epee : : string_tools : : pod_to_hex ( payment_id8 ) ;
has_encrypted_payment_id = true ;
}
else if ( get_payment_id_from_tx_extra_nonce ( extra_nonce . nonce , payment_id ) )
{
if ( ! payment_id_string . empty ( ) )
payment_id_string + = " , " ;
payment_id_string = std : : string ( " unencrypted payment ID " ) + epee : : string_tools : : pod_to_hex ( payment_id ) ;
}
}
}
2016-09-26 22:11:10 +00:00
for ( size_t s = 0 ; s < cd . sources . size ( ) ; + + s )
{
amount + = cd . sources [ s ] . amount ;
2017-07-31 06:50:41 +00:00
size_t ring_size = cd . sources [ s ] . outputs . size ( ) ;
if ( ring_size < min_ring_size )
min_ring_size = ring_size ;
2016-09-26 22:11:10 +00:00
}
2016-10-25 20:19:47 +00:00
for ( size_t d = 0 ; d < cd . splitted_dsts . size ( ) ; + + d )
2016-09-26 22:11:10 +00:00
{
2016-10-25 20:19:47 +00:00
const tx_destination_entry & entry = cd . splitted_dsts [ d ] ;
2018-02-16 11:04:04 +00:00
std : : string address , standard_address = get_account_address_as_str ( m_wallet - > nettype ( ) , entry . is_subaddress , entry . addr ) ;
2017-02-19 02:42:10 +00:00
if ( has_encrypted_payment_id & & ! entry . is_subaddress )
2017-07-24 12:10:42 +00:00
{
2018-02-16 11:04:04 +00:00
address = get_account_integrated_address_as_str ( m_wallet - > nettype ( ) , entry . addr , payment_id8 ) ;
2017-07-24 12:10:42 +00:00
address + = std : : string ( " ( " + standard_address + " with encrypted payment id " + epee : : string_tools : : pod_to_hex ( payment_id8 ) + " ) " ) ;
}
else
address = standard_address ;
2017-02-19 02:42:10 +00:00
auto i = dests . find ( entry . addr ) ;
2016-09-26 22:11:10 +00:00
if ( i = = dests . end ( ) )
2017-02-19 02:42:10 +00:00
dests . insert ( std : : make_pair ( entry . addr , std : : make_pair ( address , entry . amount ) ) ) ;
2016-09-26 22:11:10 +00:00
else
2017-07-24 12:10:42 +00:00
i - > second . second + = entry . amount ;
2016-09-26 22:11:10 +00:00
amount_to_dests + = entry . amount ;
}
if ( cd . change_dts . amount > 0 )
{
2017-02-19 02:42:10 +00:00
auto it = dests . find ( cd . change_dts . addr ) ;
2016-10-25 20:19:47 +00:00
if ( it = = dests . end ( ) )
{
fail_msg_writer ( ) < < tr ( " Claimed change does not go to a paid address " ) ;
return false ;
}
2017-07-24 12:10:42 +00:00
if ( it - > second . second < cd . change_dts . amount )
2016-10-25 20:19:47 +00:00
{
fail_msg_writer ( ) < < tr ( " Claimed change is larger than payment to the change address " ) ;
return false ;
}
2017-04-02 10:11:18 +00:00
if ( cd . change_dts . amount > 0 )
2016-11-13 17:48:17 +00:00
{
2017-04-02 10:11:18 +00:00
if ( first_known_non_zero_change_index = = - 1 )
first_known_non_zero_change_index = n ;
if ( memcmp ( & cd . change_dts . addr , & get_tx ( first_known_non_zero_change_index ) . change_dts . addr , sizeof ( cd . change_dts . addr ) ) )
{
fail_msg_writer ( ) < < tr ( " Change goes to more than one address " ) ;
return false ;
}
2016-11-13 17:48:17 +00:00
}
change + = cd . change_dts . amount ;
2017-07-24 12:10:42 +00:00
it - > second . second - = cd . change_dts . amount ;
if ( it - > second . second = = 0 )
2017-02-19 02:42:10 +00:00
dests . erase ( cd . change_dts . addr ) ;
2016-09-26 22:11:10 +00:00
}
}
2017-07-24 12:10:42 +00:00
if ( payment_id_string . empty ( ) )
payment_id_string = " no payment ID " ;
2016-09-26 22:11:10 +00:00
std : : string dest_string ;
2018-01-15 18:47:11 +00:00
size_t n_dummy_outputs = 0 ;
2017-02-19 02:42:10 +00:00
for ( auto i = dests . begin ( ) ; i ! = dests . end ( ) ; )
2016-09-26 22:11:10 +00:00
{
2018-01-15 18:47:11 +00:00
if ( i - > second . second > 0 )
{
if ( ! dest_string . empty ( ) )
dest_string + = " , " ;
dest_string + = ( boost : : format ( tr ( " sending %s to %s " ) ) % print_money ( i - > second . second ) % i - > second . first ) . str ( ) ;
}
else
+ + n_dummy_outputs ;
2016-09-26 22:11:10 +00:00
+ + i ;
2018-01-15 18:47:11 +00:00
}
if ( n_dummy_outputs > 0 )
{
if ( ! dest_string . empty ( ) )
2016-09-26 22:11:10 +00:00
dest_string + = " , " ;
2018-01-15 18:47:11 +00:00
dest_string + = std : : to_string ( n_dummy_outputs ) + tr ( " dummy output(s) " ) ;
2016-09-26 22:11:10 +00:00
}
if ( dest_string . empty ( ) )
dest_string = tr ( " with no destinations " ) ;
2016-11-13 17:48:17 +00:00
std : : string change_string ;
if ( change > 0 )
{
2018-02-16 11:04:04 +00:00
std : : string address = get_account_address_as_str ( m_wallet - > nettype ( ) , get_tx ( 0 ) . subaddr_account > 0 , get_tx ( 0 ) . change_dts . addr ) ;
2016-11-13 17:48:17 +00:00
change_string + = ( boost : : format ( tr ( " %s change to %s " ) ) % print_money ( change ) % address ) . str ( ) ;
}
else
change_string + = tr ( " no change " ) ;
2016-09-26 22:11:10 +00:00
uint64_t fee = amount - amount_to_dests ;
2017-07-31 06:50:41 +00:00
std : : string prompt_str = ( boost : : format ( tr ( " Loaded %lu transactions, for %s, fee %s, %s, %s, with min ring size %lu, %s. %sIs this okay? (Y/Yes/N/No): " ) ) % ( unsigned long ) get_num_txes ( ) % print_money ( amount ) % print_money ( fee ) % dest_string % change_string % ( unsigned long ) min_ring_size % payment_id_string % extra_message ) . str ( ) ;
2017-10-28 18:13:42 +00:00
return command_line : : is_yes ( input_line ( prompt_str ) ) ;
2016-09-26 22:11:10 +00:00
}
//----------------------------------------------------------------------------------------------------
2016-10-30 10:49:22 +00:00
bool simple_wallet : : accept_loaded_tx ( const tools : : wallet2 : : unsigned_tx_set & txs )
{
2016-11-15 21:22:04 +00:00
std : : string extra_message ;
if ( ! txs . transfers . empty ( ) )
extra_message = ( boost : : format ( " %u outputs to import. " ) % ( unsigned ) txs . transfers . size ( ) ) . str ( ) ;
return accept_loaded_tx ( [ & txs ] ( ) { return txs . txes . size ( ) ; } , [ & txs ] ( size_t n ) - > const tools : : wallet2 : : tx_construction_data & { return txs . txes [ n ] ; } , extra_message ) ;
2016-10-30 10:49:22 +00:00
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : accept_loaded_tx ( const tools : : wallet2 : : signed_tx_set & txs )
{
2016-11-15 21:22:04 +00:00
std : : string extra_message ;
if ( ! txs . key_images . empty ( ) )
extra_message = ( boost : : format ( " %u key images to import. " ) % ( unsigned ) txs . key_images . size ( ) ) . str ( ) ;
return accept_loaded_tx ( [ & txs ] ( ) { return txs . ptx . size ( ) ; } , [ & txs ] ( size_t n ) - > const tools : : wallet2 : : tx_construction_data & { return txs . ptx [ n ] . construction_data ; } , extra_message ) ;
2016-10-30 10:49:22 +00:00
}
//----------------------------------------------------------------------------------------------------
2016-09-26 22:11:10 +00:00
bool simple_wallet : : sign_transfer ( const std : : vector < std : : string > & args_ )
{
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( m_wallet - > multisig ( ) )
{
fail_msg_writer ( ) < < tr ( " This is a multisig wallet, it can only sign with sign_multisig " ) ;
return true ;
}
2016-09-26 22:11:10 +00:00
if ( m_wallet - > watch_only ( ) )
{
fail_msg_writer ( ) < < tr ( " This is a watch only wallet " ) ;
return true ;
}
2018-05-31 23:45:20 +00:00
if ( args_ . size ( ) > 1 | | ( args_ . size ( ) = = 1 & & args_ [ 0 ] ! = " export_raw " ) )
2017-09-30 04:28:17 +00:00
{
2018-05-31 23:45:20 +00:00
fail_msg_writer ( ) < < tr ( " usage: sign_transfer [export_raw] " ) ;
2017-09-30 04:28:17 +00:00
return true ;
}
2018-07-08 20:12:33 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2017-09-30 04:28:17 +00:00
const bool export_raw = args_ . size ( ) = = 1 ;
2016-09-26 22:11:10 +00:00
2016-11-15 21:22:04 +00:00
std : : vector < tools : : wallet2 : : pending_tx > ptx ;
2016-09-26 22:11:10 +00:00
try
{
2017-09-30 04:28:17 +00:00
bool r = m_wallet - > sign_tx ( " unsigned_monero_tx " , " signed_monero_tx " , ptx , [ & ] ( const tools : : wallet2 : : unsigned_tx_set & tx ) { return accept_loaded_tx ( tx ) ; } , export_raw ) ;
2016-09-26 22:11:10 +00:00
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Failed to sign transaction " ) ;
return true ;
}
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " Failed to sign transaction: " ) < < e . what ( ) ;
return true ;
}
2016-11-15 21:22:04 +00:00
std : : string txids_as_text ;
for ( const auto & t : ptx )
{
if ( ! txids_as_text . empty ( ) )
txids_as_text + = ( " , " ) ;
txids_as_text + = epee : : string_tools : : pod_to_hex ( get_transaction_hash ( t . tx ) ) ;
}
success_msg_writer ( true ) < < tr ( " Transaction successfully signed to file " ) < < " signed_monero_tx " < < " , txid " < < txids_as_text ;
2017-09-30 04:28:17 +00:00
if ( export_raw )
{
std : : string rawfiles_as_text ;
for ( size_t i = 0 ; i < ptx . size ( ) ; + + i )
{
if ( i > 0 )
rawfiles_as_text + = " , " ;
rawfiles_as_text + = " signed_monero_tx_raw " + ( ptx . size ( ) = = 1 ? " " : ( " _ " + std : : to_string ( i ) ) ) ;
}
success_msg_writer ( true ) < < tr ( " Transaction raw hex data exported to " ) < < rawfiles_as_text ;
}
2016-09-26 22:11:10 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : submit_transfer ( const std : : vector < std : : string > & args_ )
{
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2016-09-26 22:11:10 +00:00
if ( ! try_connect_to_daemon ( ) )
return true ;
try
{
std : : vector < tools : : wallet2 : : pending_tx > ptx_vector ;
2016-10-30 10:49:22 +00:00
bool r = m_wallet - > load_tx ( " signed_monero_tx " , ptx_vector , [ & ] ( const tools : : wallet2 : : signed_tx_set & tx ) { return accept_loaded_tx ( tx ) ; } ) ;
2016-09-26 22:11:10 +00:00
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Failed to load transaction from file " ) ;
return true ;
}
2017-10-06 01:14:09 +00:00
commit_or_save ( ptx_vector , false ) ;
2016-09-26 22:11:10 +00:00
}
catch ( const std : : exception & e )
{
2018-08-10 12:15:40 +00:00
handle_transfer_exception ( std : : current_exception ( ) , m_wallet - > is_trusted_daemon ( ) ) ;
2016-09-26 22:11:10 +00:00
}
catch ( . . . )
{
LOG_ERROR ( " Unknown error " ) ;
fail_msg_writer ( ) < < tr ( " unknown error " ) ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2015-08-19 19:59:44 +00:00
bool simple_wallet : : get_tx_key ( const std : : vector < std : : string > & args_ )
{
std : : vector < std : : string > local_args = args_ ;
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2015-08-19 19:59:44 +00:00
if ( local_args . size ( ) ! = 1 ) {
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " usage: get_tx_key <txid> " ) ;
2015-08-19 19:59:44 +00:00
return true ;
}
2017-09-12 01:05:41 +00:00
crypto : : hash txid ;
if ( ! epee : : string_tools : : hex_to_pod ( local_args [ 0 ] , txid ) )
2015-08-19 19:59:44 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " failed to parse txid " ) ;
2017-04-12 12:33:19 +00:00
return true ;
2015-08-19 19:59:44 +00:00
}
2018-07-08 20:12:33 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2016-04-20 23:11:11 +00:00
2015-08-19 19:59:44 +00:00
crypto : : secret_key tx_key ;
2017-02-19 02:42:10 +00:00
std : : vector < crypto : : secret_key > additional_tx_keys ;
if ( m_wallet - > get_tx_key ( txid , tx_key , additional_tx_keys ) )
2015-08-19 19:59:44 +00:00
{
2017-09-12 01:05:41 +00:00
ostringstream oss ;
oss < < epee : : string_tools : : pod_to_hex ( tx_key ) ;
for ( size_t i = 0 ; i < additional_tx_keys . size ( ) ; + + i )
oss < < epee : : string_tools : : pod_to_hex ( additional_tx_keys [ i ] ) ;
success_msg_writer ( ) < < tr ( " Tx key: " ) < < oss . str ( ) ;
2015-08-19 19:59:44 +00:00
return true ;
}
else
{
2016-07-11 22:14:58 +00:00
fail_msg_writer ( ) < < tr ( " no tx keys found for this txid " ) ;
2015-08-19 19:59:44 +00:00
return true ;
}
}
//----------------------------------------------------------------------------------------------------
2018-07-29 12:29:56 +00:00
bool simple_wallet : : set_tx_key ( const std : : vector < std : : string > & args_ )
{
std : : vector < std : : string > local_args = args_ ;
if ( local_args . size ( ) ! = 2 ) {
fail_msg_writer ( ) < < tr ( " usage: set_tx_key <txid> <tx_key> " ) ;
return true ;
}
crypto : : hash txid ;
if ( ! epee : : string_tools : : hex_to_pod ( local_args [ 0 ] , txid ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse txid " ) ;
return true ;
}
crypto : : secret_key tx_key ;
std : : vector < crypto : : secret_key > additional_tx_keys ;
try
{
if ( ! epee : : string_tools : : hex_to_pod ( local_args [ 1 ] . substr ( 0 , 64 ) , tx_key ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse tx_key " ) ;
return true ;
}
while ( true )
{
local_args [ 1 ] = local_args [ 1 ] . substr ( 64 ) ;
if ( local_args [ 1 ] . empty ( ) )
break ;
additional_tx_keys . resize ( additional_tx_keys . size ( ) + 1 ) ;
if ( ! epee : : string_tools : : hex_to_pod ( local_args [ 1 ] . substr ( 0 , 64 ) , additional_tx_keys . back ( ) ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse tx_key " ) ;
return true ;
}
}
}
catch ( const std : : out_of_range & e )
{
fail_msg_writer ( ) < < tr ( " failed to parse tx_key " ) ;
return true ;
}
LOCK_IDLE_SCOPE ( ) ;
try
{
m_wallet - > set_tx_key ( txid , tx_key , additional_tx_keys ) ;
success_msg_writer ( ) < < tr ( " Tx key successfully stored. " ) ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " Failed to store tx key: " ) < < e . what ( ) ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2017-03-29 23:22:16 +00:00
bool simple_wallet : : get_tx_proof ( const std : : vector < std : : string > & args )
{
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2017-09-12 01:05:41 +00:00
if ( args . size ( ) ! = 2 & & args . size ( ) ! = 3 )
{
2018-01-11 14:14:13 +00:00
fail_msg_writer ( ) < < tr ( " usage: get_tx_proof <txid> <address> [<message>] " ) ;
2017-03-29 23:22:16 +00:00
return true ;
}
2017-09-12 01:05:41 +00:00
crypto : : hash txid ;
if ( ! epee : : string_tools : : hex_to_pod ( args [ 0 ] , txid ) )
2017-03-29 23:22:16 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse txid " ) ;
return true ;
}
2017-02-19 02:42:10 +00:00
cryptonote : : address_parse_info info ;
2018-02-16 11:04:04 +00:00
if ( ! cryptonote : : get_account_address_from_str_or_url ( info , m_wallet - > nettype ( ) , args [ 1 ] , oa_prompter ) )
2017-03-29 23:22:16 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse address " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2017-02-19 02:42:10 +00:00
2017-09-12 01:05:41 +00:00
try
2017-03-29 23:22:16 +00:00
{
2017-11-20 09:10:58 +00:00
std : : string sig_str = m_wallet - > get_tx_proof ( txid , info . address , info . is_subaddress , args . size ( ) = = 3 ? args [ 2 ] : " " ) ;
const std : : string filename = " monero_tx_proof " ;
if ( epee : : file_io_utils : : save_string_to_file ( filename , sig_str ) )
success_msg_writer ( ) < < tr ( " signature file saved to: " ) < < filename ;
2017-02-19 02:42:10 +00:00
else
2017-11-20 09:10:58 +00:00
fail_msg_writer ( ) < < tr ( " failed to save signature file " ) ;
2017-03-29 23:22:16 +00:00
}
2017-09-12 01:05:41 +00:00
catch ( const std : : exception & e )
2017-03-29 23:22:16 +00:00
{
2017-09-12 01:05:41 +00:00
fail_msg_writer ( ) < < tr ( " error: " ) < < e . what ( ) ;
2017-03-29 23:22:16 +00:00
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2015-10-11 23:13:05 +00:00
bool simple_wallet : : check_tx_key ( const std : : vector < std : : string > & args_ )
{
std : : vector < std : : string > local_args = args_ ;
if ( local_args . size ( ) ! = 3 ) {
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " usage: check_tx_key <txid> <txkey> <address> " ) ;
2015-10-11 23:13:05 +00:00
return true ;
}
if ( ! try_connect_to_daemon ( ) )
return true ;
2017-06-19 23:33:15 +00:00
if ( ! m_wallet )
{
fail_msg_writer ( ) < < tr ( " wallet is null " ) ;
return true ;
}
2017-09-12 01:05:41 +00:00
crypto : : hash txid ;
if ( ! epee : : string_tools : : hex_to_pod ( local_args [ 0 ] , txid ) )
2015-10-11 23:13:05 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " failed to parse txid " ) ;
2015-10-11 23:13:05 +00:00
return true ;
}
2017-09-12 01:05:41 +00:00
crypto : : secret_key tx_key ;
std : : vector < crypto : : secret_key > additional_tx_keys ;
if ( ! epee : : string_tools : : hex_to_pod ( local_args [ 1 ] . substr ( 0 , 64 ) , tx_key ) )
2015-10-11 23:13:05 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " failed to parse tx key " ) ;
2015-10-11 23:13:05 +00:00
return true ;
}
2017-09-12 01:05:41 +00:00
local_args [ 1 ] = local_args [ 1 ] . substr ( 64 ) ;
while ( ! local_args [ 1 ] . empty ( ) )
2016-07-11 22:14:58 +00:00
{
2017-09-12 01:05:41 +00:00
additional_tx_keys . resize ( additional_tx_keys . size ( ) + 1 ) ;
if ( ! epee : : string_tools : : hex_to_pod ( local_args [ 1 ] . substr ( 0 , 64 ) , additional_tx_keys . back ( ) ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse tx key " ) ;
return true ;
}
local_args [ 1 ] = local_args [ 1 ] . substr ( 64 ) ;
2016-07-11 22:14:58 +00:00
}
2015-10-11 23:13:05 +00:00
2017-02-19 02:42:10 +00:00
cryptonote : : address_parse_info info ;
2018-02-16 11:04:04 +00:00
if ( ! cryptonote : : get_account_address_from_str_or_url ( info , m_wallet - > nettype ( ) , local_args [ 2 ] , oa_prompter ) )
2015-10-11 23:13:05 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " failed to parse address " ) ;
2015-10-11 23:13:05 +00:00
return true ;
}
2017-09-12 01:05:41 +00:00
try
2015-10-11 23:13:05 +00:00
{
2017-09-12 01:05:41 +00:00
uint64_t received ;
bool in_pool ;
uint64_t confirmations ;
m_wallet - > check_tx_key ( txid , tx_key , additional_tx_keys , info . address , received , in_pool , confirmations ) ;
2015-10-11 23:13:05 +00:00
2017-09-12 01:05:41 +00:00
if ( received > 0 )
2015-10-11 23:13:05 +00:00
{
2018-02-16 11:04:04 +00:00
success_msg_writer ( ) < < get_account_address_as_str ( m_wallet - > nettype ( ) , info . is_subaddress , info . address ) < < " " < < tr ( " received " ) < < " " < < print_money ( received ) < < " " < < tr ( " in txid " ) < < " " < < txid ;
2017-09-12 01:05:41 +00:00
if ( in_pool )
2016-07-11 22:14:58 +00:00
{
2017-09-12 01:05:41 +00:00
success_msg_writer ( ) < < tr ( " WARNING: this transaction is not yet included in the blockchain! " ) ;
}
else
{
if ( confirmations ! = ( uint64_t ) - 1 )
2016-07-11 22:14:58 +00:00
{
2017-09-12 01:05:41 +00:00
success_msg_writer ( ) < < boost : : format ( tr ( " This transaction has %u confirmations " ) ) % confirmations ;
2016-07-11 22:14:58 +00:00
}
else
{
2017-09-12 01:05:41 +00:00
success_msg_writer ( ) < < tr ( " WARNING: failed to determine number of confirmations! " ) ;
2016-07-11 22:14:58 +00:00
}
}
2015-10-11 23:13:05 +00:00
}
2016-07-24 17:00:43 +00:00
else
{
2018-02-16 11:04:04 +00:00
fail_msg_writer ( ) < < get_account_address_as_str ( m_wallet - > nettype ( ) , info . is_subaddress , info . address ) < < " " < < tr ( " received nothing in txid " ) < < " " < < txid ;
2016-07-24 17:00:43 +00:00
}
}
2017-09-12 01:05:41 +00:00
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " error: " ) < < e . what ( ) ;
}
2015-10-11 23:13:05 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
2017-03-29 23:22:16 +00:00
bool simple_wallet : : check_tx_proof ( const std : : vector < std : : string > & args )
{
2017-09-12 01:05:41 +00:00
if ( args . size ( ) ! = 3 & & args . size ( ) ! = 4 ) {
fail_msg_writer ( ) < < tr ( " usage: check_tx_proof <txid> <address> <signature_file> [<message>] " ) ;
2017-03-29 23:22:16 +00:00
return true ;
}
if ( ! try_connect_to_daemon ( ) )
return true ;
// parse txid
2017-09-12 01:05:41 +00:00
crypto : : hash txid ;
if ( ! epee : : string_tools : : hex_to_pod ( args [ 0 ] , txid ) )
2017-03-29 23:22:16 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse txid " ) ;
return true ;
}
// parse address
2017-02-19 02:42:10 +00:00
cryptonote : : address_parse_info info ;
2018-02-16 11:04:04 +00:00
if ( ! cryptonote : : get_account_address_from_str_or_url ( info , m_wallet - > nettype ( ) , args [ 1 ] , oa_prompter ) )
2017-03-29 23:22:16 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse address " ) ;
return true ;
}
2017-09-12 01:05:41 +00:00
// read signature file
std : : string sig_str ;
if ( ! epee : : file_io_utils : : load_file_to_string ( args [ 2 ] , sig_str ) )
2017-03-29 23:22:16 +00:00
{
2017-09-12 01:05:41 +00:00
fail_msg_writer ( ) < < tr ( " failed to load signature file " ) ;
2017-03-29 23:22:16 +00:00
return true ;
}
2017-09-12 01:05:41 +00:00
try
2017-02-19 02:42:10 +00:00
{
2017-09-12 01:05:41 +00:00
uint64_t received ;
bool in_pool ;
uint64_t confirmations ;
if ( m_wallet - > check_tx_proof ( txid , info . address , info . is_subaddress , args . size ( ) = = 4 ? args [ 3 ] : " " , sig_str , received , in_pool , confirmations ) )
2017-02-19 02:42:10 +00:00
{
2017-09-12 01:05:41 +00:00
success_msg_writer ( ) < < tr ( " Good signature " ) ;
if ( received > 0 )
2017-02-19 02:42:10 +00:00
{
2018-02-16 11:04:04 +00:00
success_msg_writer ( ) < < get_account_address_as_str ( m_wallet - > nettype ( ) , info . is_subaddress , info . address ) < < " " < < tr ( " received " ) < < " " < < print_money ( received ) < < " " < < tr ( " in txid " ) < < " " < < txid ;
2017-09-12 01:05:41 +00:00
if ( in_pool )
{
success_msg_writer ( ) < < tr ( " WARNING: this transaction is not yet included in the blockchain! " ) ;
}
else
{
if ( confirmations ! = ( uint64_t ) - 1 )
{
success_msg_writer ( ) < < boost : : format ( tr ( " This transaction has %u confirmations " ) ) % confirmations ;
}
else
{
success_msg_writer ( ) < < tr ( " WARNING: failed to determine number of confirmations! " ) ;
}
}
}
else
{
2018-02-16 11:04:04 +00:00
fail_msg_writer ( ) < < get_account_address_as_str ( m_wallet - > nettype ( ) , info . is_subaddress , info . address ) < < " " < < tr ( " received nothing in txid " ) < < " " < < txid ;
2017-02-19 02:42:10 +00:00
}
}
2017-09-12 01:05:41 +00:00
else
{
fail_msg_writer ( ) < < tr ( " Bad signature " ) ;
}
2017-02-19 02:42:10 +00:00
}
2017-09-12 01:05:41 +00:00
catch ( const std : : exception & e )
2017-03-29 23:22:16 +00:00
{
2017-09-12 01:05:41 +00:00
fail_msg_writer ( ) < < tr ( " error: " ) < < e . what ( ) ;
2017-03-29 23:22:16 +00:00
}
2017-09-12 01:05:41 +00:00
return true ;
2017-03-29 23:22:16 +00:00
}
//----------------------------------------------------------------------------------------------------
2017-08-28 15:34:17 +00:00
bool simple_wallet : : get_spend_proof ( const std : : vector < std : : string > & args )
{
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2017-08-28 15:34:17 +00:00
if ( args . size ( ) ! = 1 & & args . size ( ) ! = 2 ) {
fail_msg_writer ( ) < < tr ( " usage: get_spend_proof <txid> [<message>] " ) ;
return true ;
}
if ( m_wallet - > watch_only ( ) )
{
fail_msg_writer ( ) < < tr ( " wallet is watch-only and cannot generate the proof " ) ;
return true ;
}
crypto : : hash txid ;
if ( ! epee : : string_tools : : hex_to_pod ( args [ 0 ] , txid ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse txid " ) ;
return true ;
}
if ( ! try_connect_to_daemon ( ) )
{
fail_msg_writer ( ) < < tr ( " failed to connect to the daemon " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2017-08-28 15:34:17 +00:00
try
{
const std : : string sig_str = m_wallet - > get_spend_proof ( txid , args . size ( ) = = 2 ? args [ 1 ] : " " ) ;
const std : : string filename = " monero_spend_proof " ;
if ( epee : : file_io_utils : : save_string_to_file ( filename , sig_str ) )
success_msg_writer ( ) < < tr ( " signature file saved to: " ) < < filename ;
else
fail_msg_writer ( ) < < tr ( " failed to save signature file " ) ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < e . what ( ) ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : check_spend_proof ( const std : : vector < std : : string > & args )
{
if ( args . size ( ) ! = 2 & & args . size ( ) ! = 3 ) {
fail_msg_writer ( ) < < tr ( " usage: check_spend_proof <txid> <signature_file> [<message>] " ) ;
return true ;
}
crypto : : hash txid ;
if ( ! epee : : string_tools : : hex_to_pod ( args [ 0 ] , txid ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse txid " ) ;
return true ;
}
if ( ! try_connect_to_daemon ( ) )
{
fail_msg_writer ( ) < < tr ( " failed to connect to the daemon " ) ;
return true ;
}
std : : string sig_str ;
if ( ! epee : : file_io_utils : : load_file_to_string ( args [ 1 ] , sig_str ) )
{
fail_msg_writer ( ) < < tr ( " failed to load signature file " ) ;
return true ;
}
try
{
if ( m_wallet - > check_spend_proof ( txid , args . size ( ) = = 3 ? args [ 2 ] : " " , sig_str ) )
success_msg_writer ( ) < < tr ( " Good signature " ) ;
else
fail_msg_writer ( ) < < tr ( " Bad signature " ) ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < e . what ( ) ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2017-12-28 13:50:10 +00:00
bool simple_wallet : : get_reserve_proof ( const std : : vector < std : : string > & args )
{
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2017-12-28 13:50:10 +00:00
if ( args . size ( ) ! = 1 & & args . size ( ) ! = 2 ) {
fail_msg_writer ( ) < < tr ( " usage: get_reserve_proof (all|<amount>) [<message>] " ) ;
return true ;
}
if ( m_wallet - > watch_only ( ) | | m_wallet - > multisig ( ) )
{
fail_msg_writer ( ) < < tr ( " The reserve proof can be generated only by a full wallet " ) ;
return true ;
}
boost : : optional < std : : pair < uint32_t , uint64_t > > account_minreserve ;
if ( args [ 0 ] ! = " all " )
{
account_minreserve = std : : pair < uint32_t , uint64_t > ( ) ;
account_minreserve - > first = m_current_subaddress_account ;
if ( ! cryptonote : : parse_amount ( account_minreserve - > second , args [ 0 ] ) )
{
fail_msg_writer ( ) < < tr ( " amount is wrong: " ) < < args [ 0 ] ;
return true ;
}
}
if ( ! try_connect_to_daemon ( ) )
{
fail_msg_writer ( ) < < tr ( " failed to connect to the daemon " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2017-12-28 13:50:10 +00:00
try
{
const std : : string sig_str = m_wallet - > get_reserve_proof ( account_minreserve , args . size ( ) = = 2 ? args [ 1 ] : " " ) ;
const std : : string filename = " monero_reserve_proof " ;
if ( epee : : file_io_utils : : save_string_to_file ( filename , sig_str ) )
success_msg_writer ( ) < < tr ( " signature file saved to: " ) < < filename ;
else
fail_msg_writer ( ) < < tr ( " failed to save signature file " ) ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < e . what ( ) ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : check_reserve_proof ( const std : : vector < std : : string > & args )
{
if ( args . size ( ) ! = 2 & & args . size ( ) ! = 3 ) {
fail_msg_writer ( ) < < tr ( " usage: check_reserve_proof <address> <signature_file> [<message>] " ) ;
return true ;
}
if ( ! try_connect_to_daemon ( ) )
{
fail_msg_writer ( ) < < tr ( " failed to connect to the daemon " ) ;
return true ;
}
cryptonote : : address_parse_info info ;
2018-02-16 11:04:04 +00:00
if ( ! cryptonote : : get_account_address_from_str_or_url ( info , m_wallet - > nettype ( ) , args [ 0 ] , oa_prompter ) )
2017-12-28 13:50:10 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse address " ) ;
return true ;
}
if ( info . is_subaddress )
{
fail_msg_writer ( ) < < tr ( " Address must not be a subaddress " ) ;
return true ;
}
std : : string sig_str ;
if ( ! epee : : file_io_utils : : load_file_to_string ( args [ 1 ] , sig_str ) )
{
fail_msg_writer ( ) < < tr ( " failed to load signature file " ) ;
return true ;
}
LOCK_IDLE_SCOPE ( ) ;
try
{
uint64_t total , spent ;
if ( m_wallet - > check_reserve_proof ( info . address , args . size ( ) = = 3 ? args [ 2 ] : " " , sig_str , total , spent ) )
{
success_msg_writer ( ) < < boost : : format ( tr ( " Good signature -- total: %s, spent: %s, unspent: %s " ) ) % print_money ( total ) % print_money ( spent ) % print_money ( total - spent ) ;
}
else
{
fail_msg_writer ( ) < < tr ( " Bad signature " ) ;
}
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < e . what ( ) ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2016-04-19 20:18:43 +00:00
static std : : string get_human_readable_timestamp ( uint64_t ts )
{
char buffer [ 64 ] ;
if ( ts < 1234567890 )
return " <unknown> " ;
time_t tt = ts ;
struct tm tm ;
2016-06-20 23:14:12 +00:00
# ifdef WIN32
gmtime_s ( & tm , & tt ) ;
# else
2016-04-19 20:18:43 +00:00
gmtime_r ( & tt , & tm ) ;
2016-06-20 23:14:12 +00:00
# endif
2016-04-19 20:18:43 +00:00
uint64_t now = time ( NULL ) ;
uint64_t diff = ts > now ? ts - now : now - ts ;
2018-04-16 02:23:15 +00:00
strftime ( buffer , sizeof ( buffer ) , " %Y-%m-%d %H:%M:%S " , & tm ) ;
2016-04-19 20:18:43 +00:00
return std : : string ( buffer ) ;
}
//----------------------------------------------------------------------------------------------------
2017-07-25 15:28:48 +00:00
static std : : string get_human_readable_timespan ( std : : chrono : : seconds seconds )
{
uint64_t ts = seconds . count ( ) ;
if ( ts < 60 )
2018-10-06 08:12:38 +00:00
return std : : to_string ( ts ) + sw : : tr ( " seconds " ) ;
2017-07-25 15:28:48 +00:00
if ( ts < 3600 )
2018-10-06 08:12:38 +00:00
return std : : to_string ( ( uint64_t ) ( ts / 60 ) ) + sw : : tr ( " minutes " ) ;
2017-07-25 15:28:48 +00:00
if ( ts < 3600 * 24 )
2018-10-06 08:12:38 +00:00
return std : : to_string ( ( uint64_t ) ( ts / 3600 ) ) + sw : : tr ( " hours " ) ;
2017-07-25 15:28:48 +00:00
if ( ts < 3600 * 24 * 30.5 )
2018-10-06 08:12:38 +00:00
return std : : to_string ( ( uint64_t ) ( ts / ( 3600 * 24 ) ) ) + sw : : tr ( " days " ) ;
2017-07-25 15:28:48 +00:00
if ( ts < 3600 * 24 * 365.25 )
2018-10-06 08:12:38 +00:00
return std : : to_string ( ( uint64_t ) ( ts / ( 3600 * 24 * 30.5 ) ) ) + sw : : tr ( " months " ) ;
return sw : : tr ( " a long time " ) ;
2017-07-25 15:28:48 +00:00
}
//----------------------------------------------------------------------------------------------------
2015-11-15 21:59:40 +00:00
bool simple_wallet : : show_transfers ( const std : : vector < std : : string > & args_ )
{
std : : vector < std : : string > local_args = args_ ;
bool in = true ;
bool out = true ;
2015-11-22 12:13:59 +00:00
bool pending = true ;
2016-01-30 13:26:57 +00:00
bool failed = true ;
2016-05-23 20:40:12 +00:00
bool pool = true ;
2018-07-19 16:49:15 +00:00
bool coinbase = true ;
2015-11-15 21:59:40 +00:00
uint64_t min_height = 0 ;
uint64_t max_height = ( uint64_t ) - 1 ;
2017-02-19 02:42:10 +00:00
boost : : optional < uint32_t > subaddr_index ;
2015-11-15 21:59:40 +00:00
2017-02-19 02:42:10 +00:00
if ( local_args . size ( ) > 4 ) {
2018-07-19 16:49:15 +00:00
fail_msg_writer ( ) < < tr ( " usage: show_transfers [in|out|all|pending|failed|coinbase] [index=<N1>[,<N2>,...]] [<min_height> [<max_height>]] " ) ;
2015-11-15 21:59:40 +00:00
return true ;
}
2016-08-07 12:06:40 +00:00
LOCK_IDLE_SCOPE ( ) ;
2016-04-29 13:26:14 +00:00
2015-11-15 21:59:40 +00:00
// optional in/out selector
if ( local_args . size ( ) > 0 ) {
if ( local_args [ 0 ] = = " in " | | local_args [ 0 ] = = " incoming " ) {
2016-01-30 13:26:57 +00:00
out = pending = failed = false ;
2015-11-15 21:59:40 +00:00
local_args . erase ( local_args . begin ( ) ) ;
}
else if ( local_args [ 0 ] = = " out " | | local_args [ 0 ] = = " outgoing " ) {
2018-07-19 16:49:15 +00:00
in = pool = coinbase = false ;
2015-11-15 21:59:40 +00:00
local_args . erase ( local_args . begin ( ) ) ;
}
2015-11-22 12:13:59 +00:00
else if ( local_args [ 0 ] = = " pending " ) {
2018-07-19 16:49:15 +00:00
in = out = failed = coinbase = false ;
2016-01-30 13:26:57 +00:00
local_args . erase ( local_args . begin ( ) ) ;
}
else if ( local_args [ 0 ] = = " failed " ) {
2018-07-19 16:49:15 +00:00
in = out = pending = pool = coinbase = false ;
2016-05-23 20:40:12 +00:00
local_args . erase ( local_args . begin ( ) ) ;
}
else if ( local_args [ 0 ] = = " pool " ) {
2018-07-19 16:49:15 +00:00
in = out = pending = failed = coinbase = false ;
local_args . erase ( local_args . begin ( ) ) ;
}
else if ( local_args [ 0 ] = = " coinbase " ) {
in = out = pending = failed = pool = false ;
coinbase = true ;
2015-11-22 12:13:59 +00:00
local_args . erase ( local_args . begin ( ) ) ;
}
2015-11-15 21:59:40 +00:00
else if ( local_args [ 0 ] = = " all " | | local_args [ 0 ] = = " both " ) {
local_args . erase ( local_args . begin ( ) ) ;
}
}
2017-02-19 02:42:10 +00:00
// subaddr_index
std : : set < uint32_t > subaddr_indices ;
if ( local_args . size ( ) > 0 & & local_args [ 0 ] . substr ( 0 , 6 ) = = " index= " )
{
if ( ! parse_subaddress_indices ( local_args [ 0 ] , subaddr_indices ) )
return true ;
local_args . erase ( local_args . begin ( ) ) ;
}
2015-11-15 21:59:40 +00:00
// min height
if ( local_args . size ( ) > 0 ) {
try {
min_height = boost : : lexical_cast < uint64_t > ( local_args [ 0 ] ) ;
}
2017-12-11 23:04:57 +00:00
catch ( const boost : : bad_lexical_cast & ) {
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " bad min_height parameter: " ) < < " " < < local_args [ 0 ] ;
2015-11-15 21:59:40 +00:00
return true ;
}
local_args . erase ( local_args . begin ( ) ) ;
}
// max height
if ( local_args . size ( ) > 0 ) {
try {
max_height = boost : : lexical_cast < uint64_t > ( local_args [ 0 ] ) ;
}
2017-12-11 23:04:57 +00:00
catch ( const boost : : bad_lexical_cast & ) {
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " bad max_height parameter: " ) < < " " < < local_args [ 0 ] ;
2015-11-15 21:59:40 +00:00
return true ;
}
local_args . erase ( local_args . begin ( ) ) ;
}
2018-07-19 16:49:15 +00:00
std : : multimap < uint64_t , std : : tuple < epee : : console_colors , std : : string , std : : string > > output ;
2015-11-15 21:59:40 +00:00
2017-06-22 12:15:18 +00:00
PAUSE_READLINE ( ) ;
2018-07-19 16:49:15 +00:00
if ( in | | coinbase ) {
2015-11-15 21:59:40 +00:00
std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : payment_details > > payments ;
2017-02-19 02:42:10 +00:00
m_wallet - > get_payments ( payments , min_height , max_height , m_current_subaddress_account , subaddr_indices ) ;
2015-11-15 21:59:40 +00:00
for ( std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : payment_details > > : : const_iterator i = payments . begin ( ) ; i ! = payments . end ( ) ; + + i ) {
const tools : : wallet2 : : payment_details & pd = i - > second ;
2018-07-19 16:49:15 +00:00
if ( ! pd . m_coinbase & & ! in )
continue ;
2015-11-15 21:59:40 +00:00
std : : string payment_id = string_tools : : pod_to_hex ( i - > first ) ;
if ( payment_id . substr ( 16 ) . find_first_not_of ( ' 0 ' ) = = std : : string : : npos )
payment_id = payment_id . substr ( 0 , 16 ) ;
2016-04-20 17:19:42 +00:00
std : : string note = m_wallet - > get_tx_note ( pd . m_tx_hash ) ;
2018-07-19 16:49:15 +00:00
const std : : string type = pd . m_coinbase ? tr ( " block " ) : tr ( " in " ) ;
output . insert ( std : : make_pair ( pd . m_block_height , std : : make_tuple ( epee : : console_color_green , type , ( boost : : format ( " %25.25s %20.20s %s %s %d %s %s " ) % get_human_readable_timestamp ( pd . m_timestamp ) % print_money ( pd . m_amount ) % string_tools : : pod_to_hex ( pd . m_tx_hash ) % payment_id % pd . m_subaddr_index . minor % " - " % note ) . str ( ) ) ) ) ;
2015-11-15 21:59:40 +00:00
}
}
2017-02-19 02:42:10 +00:00
auto print_subaddr_indices = [ ] ( const std : : set < uint32_t > & indices )
{
stringstream ss ;
bool first = true ;
for ( uint32_t i : indices )
{
ss < < ( first ? " " : " , " ) < < i ;
first = false ;
}
return ss . str ( ) ;
} ;
2015-11-15 21:59:40 +00:00
if ( out ) {
std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : confirmed_transfer_details > > payments ;
2017-02-19 02:42:10 +00:00
m_wallet - > get_payments_out ( payments , min_height , max_height , m_current_subaddress_account , subaddr_indices ) ;
2015-11-15 21:59:40 +00:00
for ( std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : confirmed_transfer_details > > : : const_iterator i = payments . begin ( ) ; i ! = payments . end ( ) ; + + i ) {
const tools : : wallet2 : : confirmed_transfer_details & pd = i - > second ;
2015-11-21 23:22:15 +00:00
uint64_t change = pd . m_change = = ( uint64_t ) - 1 ? 0 : pd . m_change ; // change may not be known
2016-11-02 23:11:30 +00:00
uint64_t fee = pd . m_amount_in - pd . m_amount_out ;
2015-11-22 12:13:59 +00:00
std : : string dests ;
for ( const auto & d : pd . m_dests ) {
if ( ! dests . empty ( ) )
dests + = " , " ;
2018-02-16 11:04:04 +00:00
dests + = get_account_address_as_str ( m_wallet - > nettype ( ) , d . is_subaddress , d . addr ) + " : " + print_money ( d . amount ) ;
2015-11-22 12:13:59 +00:00
}
std : : string payment_id = string_tools : : pod_to_hex ( i - > second . m_payment_id ) ;
if ( payment_id . substr ( 16 ) . find_first_not_of ( ' 0 ' ) = = std : : string : : npos )
payment_id = payment_id . substr ( 0 , 16 ) ;
2016-04-20 17:19:42 +00:00
std : : string note = m_wallet - > get_tx_note ( i - > first ) ;
2018-07-19 16:49:15 +00:00
output . insert ( std : : make_pair ( pd . m_block_height , std : : make_tuple ( epee : : console_color_magenta , tr ( " out " ) , ( boost : : format ( " %25.25s %20.20s %s %s %14.14s %s %s - %s " ) % get_human_readable_timestamp ( pd . m_timestamp ) % print_money ( pd . m_amount_in - change - fee ) % string_tools : : pod_to_hex ( i - > first ) % payment_id % print_money ( fee ) % dests % print_subaddr_indices ( pd . m_subaddr_indices ) % note ) . str ( ) ) ) ) ;
2015-11-15 21:59:40 +00:00
}
}
// print in and out sorted by height
2018-07-19 16:49:15 +00:00
for ( std : : multimap < uint64_t , std : : tuple < epee : : console_colors , std : : string , std : : string > > : : const_iterator i = output . begin ( ) ; i ! = output . end ( ) ; + + i ) {
message_writer ( std : : get < 0 > ( i - > second ) , false ) < <
2015-11-22 12:13:59 +00:00
boost : : format ( " %8.8llu %6.6s %s " ) %
2018-07-19 16:49:15 +00:00
( ( unsigned long long ) i - > first ) % std : : get < 1 > ( i - > second ) % std : : get < 2 > ( i - > second ) ;
2015-11-15 21:59:40 +00:00
}
2016-05-23 20:40:12 +00:00
if ( pool ) {
try
{
2018-07-08 20:12:33 +00:00
m_in_manual_refresh . store ( true , std : : memory_order_relaxed ) ;
epee : : misc_utils : : auto_scope_leave_caller scope_exit_handler = epee : : misc_utils : : create_scope_leave_handler ( [ & ] ( ) { m_in_manual_refresh . store ( false , std : : memory_order_relaxed ) ; } ) ;
2016-05-23 20:40:12 +00:00
m_wallet - > update_pool_state ( ) ;
2017-09-22 12:57:20 +00:00
std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : pool_payment_details > > payments ;
2017-02-19 02:42:10 +00:00
m_wallet - > get_unconfirmed_payments ( payments , m_current_subaddress_account , subaddr_indices ) ;
2017-09-22 12:57:20 +00:00
for ( std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : pool_payment_details > > : : const_iterator i = payments . begin ( ) ; i ! = payments . end ( ) ; + + i ) {
const tools : : wallet2 : : payment_details & pd = i - > second . m_pd ;
2016-05-23 20:40:12 +00:00
std : : string payment_id = string_tools : : pod_to_hex ( i - > first ) ;
if ( payment_id . substr ( 16 ) . find_first_not_of ( ' 0 ' ) = = std : : string : : npos )
payment_id = payment_id . substr ( 0 , 16 ) ;
std : : string note = m_wallet - > get_tx_note ( pd . m_tx_hash ) ;
2017-09-22 12:57:20 +00:00
std : : string double_spend_note ;
if ( i - > second . m_double_spend_seen )
double_spend_note = tr ( " [Double spend seen on the network: this transaction may or may not end up being mined] " ) ;
2018-04-16 02:23:15 +00:00
message_writer ( ) < < ( boost : : format ( " %8.8s %6.6s %25.25s %20.20s %s %s %d %s %s%s " ) % " pool " % " in " % get_human_readable_timestamp ( pd . m_timestamp ) % print_money ( pd . m_amount ) % string_tools : : pod_to_hex ( pd . m_tx_hash ) % payment_id % pd . m_subaddr_index . minor % " - " % note % double_spend_note ) . str ( ) ;
2016-05-23 20:40:12 +00:00
}
}
2017-02-19 02:42:10 +00:00
catch ( const std : : exception & e )
2016-05-23 20:40:12 +00:00
{
2017-02-19 02:42:10 +00:00
fail_msg_writer ( ) < < " Failed to get pool state: " < < e . what ( ) ;
2016-05-23 20:40:12 +00:00
}
}
2015-11-15 21:59:40 +00:00
// print unconfirmed last
2016-01-30 13:26:57 +00:00
if ( pending | | failed ) {
2015-11-15 21:59:40 +00:00
std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : unconfirmed_transfer_details > > upayments ;
2017-02-19 02:42:10 +00:00
m_wallet - > get_unconfirmed_payments_out ( upayments , m_current_subaddress_account , subaddr_indices ) ;
2015-11-15 21:59:40 +00:00
for ( std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : unconfirmed_transfer_details > > : : const_iterator i = upayments . begin ( ) ; i ! = upayments . end ( ) ; + + i ) {
const tools : : wallet2 : : unconfirmed_transfer_details & pd = i - > second ;
2016-06-15 22:37:13 +00:00
uint64_t amount = pd . m_amount_in ;
2016-11-02 23:11:30 +00:00
uint64_t fee = amount - pd . m_amount_out ;
2015-11-22 12:13:59 +00:00
std : : string payment_id = string_tools : : pod_to_hex ( i - > second . m_payment_id ) ;
if ( payment_id . substr ( 16 ) . find_first_not_of ( ' 0 ' ) = = std : : string : : npos )
payment_id = payment_id . substr ( 0 , 16 ) ;
2016-04-20 17:19:42 +00:00
std : : string note = m_wallet - > get_tx_note ( i - > first ) ;
2016-01-30 13:26:57 +00:00
bool is_failed = pd . m_state = = tools : : wallet2 : : unconfirmed_transfer_details : : failed ;
if ( ( failed & & is_failed ) | | ( ! is_failed & & pending ) ) {
2018-04-16 02:23:15 +00:00
message_writer ( ) < < ( boost : : format ( " %8.8s %6.6s %25.25s %20.20s %s %s %14.14s %s - %s " ) % ( is_failed ? tr ( " failed " ) : tr ( " pending " ) ) % tr ( " out " ) % get_human_readable_timestamp ( pd . m_timestamp ) % print_money ( amount - pd . m_change - fee ) % string_tools : : pod_to_hex ( i - > first ) % payment_id % print_money ( fee ) % print_subaddr_indices ( pd . m_subaddr_indices ) % note ) . str ( ) ;
2016-01-30 13:26:57 +00:00
}
2015-11-15 21:59:40 +00:00
}
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2016-12-24 05:31:19 +00:00
bool simple_wallet : : unspent_outputs ( const std : : vector < std : : string > & args_ )
{
2017-02-19 02:42:10 +00:00
if ( args_ . size ( ) > 3 )
{
fail_msg_writer ( ) < < tr ( " usage: unspent_outputs [index=<N1>[,<N2>,...]] [<min_amount> [<max_amount>]] " ) ;
2016-12-24 05:31:19 +00:00
return true ;
}
2017-02-19 02:42:10 +00:00
auto local_args = args_ ;
std : : set < uint32_t > subaddr_indices ;
2018-07-24 04:32:58 +00:00
if ( local_args . size ( ) > 0 & & local_args [ 0 ] . substr ( 0 , 6 ) = = " index= " )
2017-02-19 02:42:10 +00:00
{
if ( ! parse_subaddress_indices ( local_args [ 0 ] , subaddr_indices ) )
return true ;
local_args . erase ( local_args . begin ( ) ) ;
}
2016-12-24 05:31:19 +00:00
uint64_t min_amount = 0 ;
uint64_t max_amount = std : : numeric_limits < uint64_t > : : max ( ) ;
2017-02-19 02:42:10 +00:00
if ( local_args . size ( ) > 0 )
2016-12-24 05:31:19 +00:00
{
2017-02-19 02:42:10 +00:00
if ( ! cryptonote : : parse_amount ( min_amount , local_args [ 0 ] ) )
2016-12-24 05:31:19 +00:00
{
2017-02-19 02:42:10 +00:00
fail_msg_writer ( ) < < tr ( " amount is wrong: " ) < < local_args [ 0 ] ;
2016-12-24 05:31:19 +00:00
return true ;
}
2017-02-19 02:42:10 +00:00
local_args . erase ( local_args . begin ( ) ) ;
if ( local_args . size ( ) > 0 )
{
if ( ! cryptonote : : parse_amount ( max_amount , local_args [ 0 ] ) )
{
fail_msg_writer ( ) < < tr ( " amount is wrong: " ) < < local_args [ 0 ] ;
return true ;
}
local_args . erase ( local_args . begin ( ) ) ;
}
2016-12-24 05:31:19 +00:00
if ( min_amount > max_amount )
{
fail_msg_writer ( ) < < tr ( " <min_amount> should be smaller than <max_amount> " ) ;
return true ;
}
}
tools : : wallet2 : : transfer_container transfers ;
m_wallet - > get_transfers ( transfers ) ;
std : : map < uint64_t , tools : : wallet2 : : transfer_container > amount_to_tds ;
uint64_t min_height = std : : numeric_limits < uint64_t > : : max ( ) ;
uint64_t max_height = 0 ;
uint64_t found_min_amount = std : : numeric_limits < uint64_t > : : max ( ) ;
uint64_t found_max_amount = 0 ;
uint64_t count = 0 ;
for ( const auto & td : transfers )
{
uint64_t amount = td . amount ( ) ;
2017-12-13 10:09:42 +00:00
if ( td . m_spent | | amount < min_amount | | amount > max_amount | | td . m_subaddr_index . major ! = m_current_subaddress_account | | ( subaddr_indices . count ( td . m_subaddr_index . minor ) = = 0 & & ! subaddr_indices . empty ( ) ) )
2016-12-24 05:31:19 +00:00
continue ;
amount_to_tds [ amount ] . push_back ( td ) ;
if ( min_height > td . m_block_height ) min_height = td . m_block_height ;
if ( max_height < td . m_block_height ) max_height = td . m_block_height ;
if ( found_min_amount > amount ) found_min_amount = amount ;
if ( found_max_amount < amount ) found_max_amount = amount ;
+ + count ;
}
2017-02-19 02:42:10 +00:00
if ( amount_to_tds . empty ( ) )
{
success_msg_writer ( ) < < tr ( " There is no unspent output in the specified address " ) ;
return true ;
}
2016-12-24 05:31:19 +00:00
for ( const auto & amount_tds : amount_to_tds )
{
auto & tds = amount_tds . second ;
success_msg_writer ( ) < < tr ( " \n Amount: " ) < < print_money ( amount_tds . first ) < < tr ( " , number of keys: " ) < < tds . size ( ) ;
for ( size_t i = 0 ; i < tds . size ( ) ; )
{
std : : ostringstream oss ;
for ( size_t j = 0 ; j < 8 & & i < tds . size ( ) ; + + i , + + j )
oss < < tds [ i ] . m_block_height < < tr ( " " ) ;
success_msg_writer ( ) < < oss . str ( ) ;
}
}
success_msg_writer ( )
< < tr ( " \n Min block height: " ) < < min_height
< < tr ( " \n Max block height: " ) < < max_height
< < tr ( " \n Min amount found: " ) < < print_money ( found_min_amount )
< < tr ( " \n Max amount found: " ) < < print_money ( found_max_amount )
< < tr ( " \n Total count: " ) < < count ;
const size_t histogram_height = 10 ;
const size_t histogram_width = 50 ;
double bin_size = ( max_height - min_height + 1.0 ) / histogram_width ;
size_t max_bin_count = 0 ;
std : : vector < size_t > histogram ( histogram_width , 0 ) ;
for ( const auto & amount_tds : amount_to_tds )
{
for ( auto & td : amount_tds . second )
{
uint64_t bin_index = ( td . m_block_height - min_height + 1 ) / bin_size ;
if ( bin_index > = histogram_width )
bin_index = histogram_width - 1 ;
histogram [ bin_index ] + + ;
if ( max_bin_count < histogram [ bin_index ] )
max_bin_count = histogram [ bin_index ] ;
}
}
for ( size_t x = 0 ; x < histogram_width ; + + x )
{
double bin_count = histogram [ x ] ;
if ( max_bin_count > histogram_height )
bin_count * = histogram_height / ( double ) max_bin_count ;
if ( histogram [ x ] > 0 & & bin_count < 1.0 )
bin_count = 1.0 ;
histogram [ x ] = bin_count ;
}
std : : vector < std : : string > histogram_line ( histogram_height , std : : string ( histogram_width , ' ' ) ) ;
for ( size_t y = 0 ; y < histogram_height ; + + y )
{
for ( size_t x = 0 ; x < histogram_width ; + + x )
{
if ( y < histogram [ x ] )
histogram_line [ y ] [ x ] = ' * ' ;
}
}
double count_per_star = max_bin_count / ( double ) histogram_height ;
if ( count_per_star < 1 )
count_per_star = 1 ;
success_msg_writer ( )
< < tr ( " \n Bin size: " ) < < bin_size
< < tr ( " \n Outputs per *: " ) < < count_per_star ;
ostringstream histogram_str ;
histogram_str < < tr ( " count \n ^ \n " ) ;
for ( size_t y = histogram_height ; y > 0 ; - - y )
histogram_str < < tr ( " | " ) < < histogram_line [ y - 1 ] < < tr ( " | \n " ) ;
histogram_str
< < tr ( " + " ) < < std : : string ( histogram_width , ' - ' ) < < tr ( " +--> block height \n " )
< < tr ( " ^ " ) < < std : : string ( histogram_width - 2 , ' ' ) < < tr ( " ^ \n " )
< < tr ( " " ) < < min_height < < std : : string ( histogram_width - 8 , ' ' ) < < max_height ;
success_msg_writer ( ) < < histogram_str . str ( ) ;
return true ;
}
//----------------------------------------------------------------------------------------------------
2015-12-30 12:58:15 +00:00
bool simple_wallet : : rescan_blockchain ( const std : : vector < std : : string > & args_ )
{
2018-08-07 12:48:04 +00:00
message_writer ( ) < < tr ( " Warning: this will lose any information which can not be recovered from the blockchain. " ) ;
message_writer ( ) < < tr ( " This includes destination addresses, tx secret keys, tx notes, etc " ) ;
std : : string confirm = input_line ( tr ( " Rescan anyway ? (Y/Yes/N/No): " ) ) ;
if ( ! std : : cin . eof ( ) )
{
if ( ! command_line : : is_yes ( confirm ) )
return true ;
}
2015-12-30 12:58:15 +00:00
return refresh_main ( 0 , true ) ;
}
//----------------------------------------------------------------------------------------------------
2016-08-07 12:06:40 +00:00
void simple_wallet : : wallet_idle_thread ( )
2015-11-28 12:38:58 +00:00
{
while ( true )
{
2016-08-07 12:06:40 +00:00
boost : : unique_lock < boost : : mutex > lock ( m_idle_mutex ) ;
if ( ! m_idle_run . load ( std : : memory_order_relaxed ) )
2015-11-29 13:02:01 +00:00
break ;
2016-08-07 12:06:40 +00:00
// auto refresh
if ( m_auto_refresh_enabled )
2015-11-28 12:38:58 +00:00
{
2016-08-07 12:06:40 +00:00
m_auto_refresh_refreshing = true ;
try
{
uint64_t fetched_blocks ;
if ( try_connect_to_daemon ( true ) )
2018-08-10 12:15:40 +00:00
m_wallet - > refresh ( m_wallet - > is_trusted_daemon ( ) , 0 , fetched_blocks ) ;
2016-08-07 12:06:40 +00:00
}
catch ( . . . ) { }
m_auto_refresh_refreshing = false ;
2015-11-28 12:38:58 +00:00
}
2016-08-07 12:06:40 +00:00
if ( ! m_idle_run . load ( std : : memory_order_relaxed ) )
2015-11-28 12:38:58 +00:00
break ;
2016-08-07 12:06:40 +00:00
m_idle_cond . wait_for ( lock , boost : : chrono : : seconds ( 90 ) ) ;
2015-11-28 12:38:58 +00:00
}
}
//----------------------------------------------------------------------------------------------------
2017-08-02 13:44:42 +00:00
std : : string simple_wallet : : get_prompt ( ) const
{
2017-02-19 02:42:10 +00:00
std : : string addr_start = m_wallet - > get_subaddress_as_str ( { m_current_subaddress_account , 0 } ) . substr ( 0 , 6 ) ;
2017-08-02 13:44:42 +00:00
std : : string prompt = std : : string ( " [ " ) + tr ( " wallet " ) + " " + addr_start ;
2018-03-11 01:15:53 +00:00
if ( ! m_wallet - > check_connection ( NULL ) )
2017-08-02 13:44:42 +00:00
prompt + = tr ( " (no daemon) " ) ;
else if ( ! m_wallet - > is_synced ( ) )
prompt + = tr ( " (out of sync) " ) ;
prompt + = " ]: " ;
return prompt ;
}
//----------------------------------------------------------------------------------------------------
2014-03-03 22:07:58 +00:00
bool simple_wallet : : run ( )
{
2016-07-10 15:49:40 +00:00
// check and display warning, but go on anyway
try_connect_to_daemon ( ) ;
2017-02-19 02:42:10 +00:00
refresh_main ( 0 , false , true ) ;
2016-07-13 10:25:53 +00:00
2016-08-07 12:06:40 +00:00
m_auto_refresh_enabled = m_wallet - > auto_refresh ( ) ;
m_idle_thread = boost : : thread ( [ & ] { wallet_idle_thread ( ) ; } ) ;
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
message_writer ( console_color_green , false ) < < " Background refresh thread started " ;
2017-08-02 13:44:42 +00:00
return m_cmd_binder . run_handling ( [ this ] ( ) { return get_prompt ( ) ; } , " " ) ;
2014-03-20 11:46:11 +00:00
}
//----------------------------------------------------------------------------------------------------
void simple_wallet : : stop ( )
{
m_cmd_binder . stop_handling ( ) ;
2014-03-03 22:07:58 +00:00
}
//----------------------------------------------------------------------------------------------------
2017-02-19 02:42:10 +00:00
bool simple_wallet : : account ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
// Usage:
// account
// account new <label text with white spaces allowed>
// account switch <index>
// account label <index> <label text with white spaces allowed>
2017-12-15 03:08:36 +00:00
// account tag <tag_name> <account_index_1> [<account_index_2> ...]
// account untag <account_index_1> [<account_index_2> ...]
// account tag_description <tag_name> <description>
2017-02-19 02:42:10 +00:00
if ( args . empty ( ) )
{
// print all the existing accounts
LOCK_IDLE_SCOPE ( ) ;
print_accounts ( ) ;
return true ;
}
std : : vector < std : : string > local_args = args ;
std : : string command = local_args [ 0 ] ;
local_args . erase ( local_args . begin ( ) ) ;
if ( command = = " new " )
{
// create a new account and switch to it
std : : string label = boost : : join ( local_args , " " ) ;
if ( label . empty ( ) )
label = tr ( " (Untitled account) " ) ;
m_wallet - > add_subaddress_account ( label ) ;
m_current_subaddress_account = m_wallet - > get_num_subaddress_accounts ( ) - 1 ;
// update_prompt();
LOCK_IDLE_SCOPE ( ) ;
print_accounts ( ) ;
}
else if ( command = = " switch " & & local_args . size ( ) = = 1 )
{
// switch to the specified account
uint32_t index_major ;
if ( ! epee : : string_tools : : get_xtype_from_string ( index_major , local_args [ 0 ] ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse index: " ) < < local_args [ 0 ] ;
return true ;
}
if ( index_major > = m_wallet - > get_num_subaddress_accounts ( ) )
{
fail_msg_writer ( ) < < tr ( " specify an index between 0 and " ) < < ( m_wallet - > get_num_subaddress_accounts ( ) - 1 ) ;
return true ;
}
m_current_subaddress_account = index_major ;
// update_prompt();
show_balance ( ) ;
}
else if ( command = = " label " & & local_args . size ( ) > = 1 )
{
// set label of the specified account
uint32_t index_major ;
if ( ! epee : : string_tools : : get_xtype_from_string ( index_major , local_args [ 0 ] ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse index: " ) < < local_args [ 0 ] ;
return true ;
}
local_args . erase ( local_args . begin ( ) ) ;
std : : string label = boost : : join ( local_args , " " ) ;
try
{
m_wallet - > set_subaddress_label ( { index_major , 0 } , label ) ;
LOCK_IDLE_SCOPE ( ) ;
print_accounts ( ) ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < e . what ( ) ;
}
}
2017-12-15 03:08:36 +00:00
else if ( command = = " tag " & & local_args . size ( ) > = 2 )
{
const std : : string tag = local_args [ 0 ] ;
std : : set < uint32_t > account_indices ;
for ( size_t i = 1 ; i < local_args . size ( ) ; + + i )
{
uint32_t account_index ;
if ( ! epee : : string_tools : : get_xtype_from_string ( account_index , local_args [ i ] ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse index: " ) < < local_args [ i ] ;
return true ;
}
account_indices . insert ( account_index ) ;
}
try
{
m_wallet - > set_account_tag ( account_indices , tag ) ;
print_accounts ( tag ) ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < e . what ( ) ;
}
}
else if ( command = = " untag " & & local_args . size ( ) > = 1 )
{
std : : set < uint32_t > account_indices ;
for ( size_t i = 0 ; i < local_args . size ( ) ; + + i )
{
uint32_t account_index ;
if ( ! epee : : string_tools : : get_xtype_from_string ( account_index , local_args [ i ] ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse index: " ) < < local_args [ i ] ;
return true ;
}
account_indices . insert ( account_index ) ;
}
try
{
m_wallet - > set_account_tag ( account_indices , " " ) ;
print_accounts ( ) ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < e . what ( ) ;
}
}
else if ( command = = " tag_description " & & local_args . size ( ) > = 1 )
{
const std : : string tag = local_args [ 0 ] ;
std : : string description ;
if ( local_args . size ( ) > 1 )
{
local_args . erase ( local_args . begin ( ) ) ;
description = boost : : join ( local_args , " " ) ;
}
try
{
m_wallet - > set_account_tag_description ( tag , description ) ;
print_accounts ( tag ) ;
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < e . what ( ) ;
}
}
2017-02-19 02:42:10 +00:00
else
{
2017-12-15 03:08:36 +00:00
fail_msg_writer ( ) < < tr ( " usage: \n "
" account \n "
" account new <label text with white spaces allowed> \n "
" account switch <index> \n "
" account label <index> <label text with white spaces allowed> \n "
" account tag <tag_name> <account_index_1> [<account_index_2> ...] \n "
" account untag <account_index_1> [<account_index_2> ...] \n "
" account tag_description <tag_name> <description> " ) ;
2017-02-19 02:42:10 +00:00
}
return true ;
}
//----------------------------------------------------------------------------------------------------
void simple_wallet : : print_accounts ( )
{
2017-12-15 03:08:36 +00:00
const std : : pair < std : : map < std : : string , std : : string > , std : : vector < std : : string > > & account_tags = m_wallet - > get_account_tags ( ) ;
size_t num_untagged_accounts = m_wallet - > get_num_subaddress_accounts ( ) ;
for ( const std : : pair < std : : string , std : : string > & p : account_tags . first )
{
const std : : string & tag = p . first ;
print_accounts ( tag ) ;
num_untagged_accounts - = std : : count ( account_tags . second . begin ( ) , account_tags . second . end ( ) , tag ) ;
success_msg_writer ( ) < < " " ;
}
if ( num_untagged_accounts > 0 )
print_accounts ( " " ) ;
if ( num_untagged_accounts < m_wallet - > get_num_subaddress_accounts ( ) )
success_msg_writer ( ) < < tr ( " \n Grand total: \n Balance: " ) < < print_money ( m_wallet - > balance_all ( ) ) < < tr ( " , unlocked balance: " ) < < print_money ( m_wallet - > unlocked_balance_all ( ) ) ;
}
//----------------------------------------------------------------------------------------------------
void simple_wallet : : print_accounts ( const std : : string & tag )
{
const std : : pair < std : : map < std : : string , std : : string > , std : : vector < std : : string > > & account_tags = m_wallet - > get_account_tags ( ) ;
if ( tag . empty ( ) )
{
success_msg_writer ( ) < < tr ( " Untagged accounts: " ) ;
}
else
{
if ( account_tags . first . count ( tag ) = = 0 )
{
fail_msg_writer ( ) < < boost : : format ( tr ( " Tag %s is unregistered. " ) ) % tag ;
return ;
}
success_msg_writer ( ) < < tr ( " Accounts with tag: " ) < < tag ;
success_msg_writer ( ) < < tr ( " Tag's description: " ) < < account_tags . first . find ( tag ) - > second ;
}
2017-11-02 21:07:41 +00:00
success_msg_writer ( ) < < boost : : format ( " %15s %21s %21s %21s " ) % tr ( " Account " ) % tr ( " Balance " ) % tr ( " Unlocked balance " ) % tr ( " Label " ) ;
2017-12-15 03:08:36 +00:00
uint64_t total_balance = 0 , total_unlocked_balance = 0 ;
2017-02-19 02:42:10 +00:00
for ( uint32_t account_index = 0 ; account_index < m_wallet - > get_num_subaddress_accounts ( ) ; + + account_index )
{
2017-12-15 03:08:36 +00:00
if ( account_tags . second [ account_index ] ! = tag )
continue ;
2017-11-02 21:07:41 +00:00
success_msg_writer ( ) < < boost : : format ( tr ( " %c%8u %6s %21s %21s %21s " ) )
% ( m_current_subaddress_account = = account_index ? ' * ' : ' ' )
2017-02-19 02:42:10 +00:00
% account_index
% m_wallet - > get_subaddress_as_str ( { account_index , 0 } ) . substr ( 0 , 6 )
% print_money ( m_wallet - > balance ( account_index ) )
% print_money ( m_wallet - > unlocked_balance ( account_index ) )
% m_wallet - > get_subaddress_label ( { account_index , 0 } ) ;
2017-12-15 03:08:36 +00:00
total_balance + = m_wallet - > balance ( account_index ) ;
total_unlocked_balance + = m_wallet - > unlocked_balance ( account_index ) ;
2017-02-19 02:42:10 +00:00
}
success_msg_writer ( ) < < tr ( " ---------------------------------------------------------------------------------- " ) ;
2017-12-15 03:08:36 +00:00
success_msg_writer ( ) < < boost : : format ( tr ( " %15s %21s %21s " ) ) % " Total " % print_money ( total_balance ) % print_money ( total_unlocked_balance ) ;
2017-02-19 02:42:10 +00:00
}
//----------------------------------------------------------------------------------------------------
2014-04-02 16:00:17 +00:00
bool simple_wallet : : print_address ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
2014-03-03 22:07:58 +00:00
{
2017-02-19 02:42:10 +00:00
// Usage:
// address
// address new <label text with white spaces allowed>
// address all
// address <index_min> [<index_max>]
// address label <index> <label text with white spaces allowed>
std : : vector < std : : string > local_args = args ;
tools : : wallet2 : : transfer_container transfers ;
m_wallet - > get_transfers ( transfers ) ;
auto print_address_sub = [ this , & transfers ] ( uint32_t index )
{
bool used = std : : find_if (
transfers . begin ( ) , transfers . end ( ) ,
[ this , & index ] ( const tools : : wallet2 : : transfer_details & td ) {
return td . m_subaddr_index = = cryptonote : : subaddress_index { m_current_subaddress_account , index } ;
} ) ! = transfers . end ( ) ;
success_msg_writer ( ) < < index < < " " < < m_wallet - > get_subaddress_as_str ( { m_current_subaddress_account , index } ) < < " " < < ( index = = 0 ? tr ( " Primary address " ) : m_wallet - > get_subaddress_label ( { m_current_subaddress_account , index } ) ) < < " " < < ( used ? tr ( " (used) " ) : " " ) ;
} ;
uint32_t index = 0 ;
if ( local_args . empty ( ) )
{
print_address_sub ( index ) ;
}
else if ( local_args . size ( ) = = 1 & & local_args [ 0 ] = = " all " )
{
local_args . erase ( local_args . begin ( ) ) ;
for ( ; index < m_wallet - > get_num_subaddresses ( m_current_subaddress_account ) ; + + index )
print_address_sub ( index ) ;
}
else if ( local_args [ 0 ] = = " new " )
{
local_args . erase ( local_args . begin ( ) ) ;
std : : string label ;
if ( local_args . size ( ) > 0 )
label = boost : : join ( local_args , " " ) ;
if ( label . empty ( ) )
label = tr ( " (Untitled address) " ) ;
m_wallet - > add_subaddress ( m_current_subaddress_account , label ) ;
print_address_sub ( m_wallet - > get_num_subaddresses ( m_current_subaddress_account ) - 1 ) ;
}
else if ( local_args . size ( ) > = 2 & & local_args [ 0 ] = = " label " )
{
if ( ! epee : : string_tools : : get_xtype_from_string ( index , local_args [ 1 ] ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse index: " ) < < local_args [ 1 ] ;
return true ;
}
if ( index > = m_wallet - > get_num_subaddresses ( m_current_subaddress_account ) )
{
fail_msg_writer ( ) < < tr ( " specify an index between 0 and " ) < < ( m_wallet - > get_num_subaddresses ( m_current_subaddress_account ) - 1 ) ;
return true ;
}
local_args . erase ( local_args . begin ( ) ) ;
local_args . erase ( local_args . begin ( ) ) ;
std : : string label = boost : : join ( local_args , " " ) ;
m_wallet - > set_subaddress_label ( { m_current_subaddress_account , index } , label ) ;
print_address_sub ( index ) ;
}
else if ( local_args . size ( ) < = 2 & & epee : : string_tools : : get_xtype_from_string ( index , local_args [ 0 ] ) )
{
local_args . erase ( local_args . begin ( ) ) ;
uint32_t index_min = index ;
uint32_t index_max = index_min ;
if ( local_args . size ( ) > 0 )
{
if ( ! epee : : string_tools : : get_xtype_from_string ( index_max , local_args [ 0 ] ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse index: " ) < < local_args [ 0 ] ;
return true ;
}
local_args . erase ( local_args . begin ( ) ) ;
}
if ( index_max < index_min )
std : : swap ( index_min , index_max ) ;
if ( index_min > = m_wallet - > get_num_subaddresses ( m_current_subaddress_account ) )
{
fail_msg_writer ( ) < < tr ( " <index_min> is already out of bound " ) ;
return true ;
}
if ( index_max > = m_wallet - > get_num_subaddresses ( m_current_subaddress_account ) )
{
message_writer ( ) < < tr ( " <index_max> exceeds the bound " ) ;
index_max = m_wallet - > get_num_subaddresses ( m_current_subaddress_account ) - 1 ;
}
for ( index = index_min ; index < = index_max ; + + index )
print_address_sub ( index ) ;
}
else
{
fail_msg_writer ( ) < < tr ( " usage: address [ new <label text with white spaces allowed> | all | <index_min> [<index_max>] | label <index> <label text with white spaces allowed> ] " ) ;
}
2014-03-03 22:07:58 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
2015-06-11 08:44:13 +00:00
bool simple_wallet : : print_integrated_address ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
2015-08-09 09:09:39 +00:00
crypto : : hash8 payment_id ;
2015-06-11 22:25:12 +00:00
if ( args . size ( ) > 1 )
2015-06-11 08:44:13 +00:00
{
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " usage: integrated_address [payment ID] " ) ;
2015-06-11 22:25:12 +00:00
return true ;
}
if ( args . size ( ) = = 0 )
{
2017-11-22 16:20:11 +00:00
if ( m_current_subaddress_account ! = 0 )
{
fail_msg_writer ( ) < < tr ( " Integrated addresses can only be created for account 0 " ) ;
return true ;
}
2015-08-26 07:28:58 +00:00
payment_id = crypto : : rand < crypto : : hash8 > ( ) ;
2015-07-14 19:28:25 +00:00
success_msg_writer ( ) < < tr ( " Random payment ID: " ) < < payment_id ;
2018-02-16 11:04:04 +00:00
success_msg_writer ( ) < < tr ( " Matching integrated address: " ) < < m_wallet - > get_account ( ) . get_public_integrated_address_str ( payment_id , m_wallet - > nettype ( ) ) ;
2015-06-11 08:44:13 +00:00
return true ;
}
2015-08-09 09:09:39 +00:00
if ( tools : : wallet2 : : parse_short_payment_id ( args . back ( ) , payment_id ) )
2015-06-11 08:44:13 +00:00
{
2017-11-22 16:20:11 +00:00
if ( m_current_subaddress_account ! = 0 )
{
fail_msg_writer ( ) < < tr ( " Integrated addresses can only be created for account 0 " ) ;
return true ;
}
2018-02-16 11:04:04 +00:00
success_msg_writer ( ) < < m_wallet - > get_account ( ) . get_public_integrated_address_str ( payment_id , m_wallet - > nettype ( ) ) ;
2015-06-11 08:44:13 +00:00
return true ;
}
else {
2017-02-19 02:42:10 +00:00
address_parse_info info ;
2018-02-16 11:04:04 +00:00
if ( get_account_address_from_str ( info , m_wallet - > nettype ( ) , args . back ( ) ) )
2015-06-11 08:44:13 +00:00
{
2017-02-19 02:42:10 +00:00
if ( info . has_payment_id )
2015-06-11 08:44:13 +00:00
{
2017-02-19 02:42:10 +00:00
success_msg_writer ( ) < < boost : : format ( tr ( " Integrated address: %s, payment ID: %s " ) ) %
2018-02-16 11:04:04 +00:00
get_account_address_as_str ( m_wallet - > nettype ( ) , false , info . address ) % epee : : string_tools : : pod_to_hex ( info . payment_id ) ;
2015-06-11 08:44:13 +00:00
}
else
{
2018-02-16 11:04:04 +00:00
success_msg_writer ( ) < < ( info . is_subaddress ? tr ( " Subaddress: " ) : tr ( " Standard address: " ) ) < < get_account_address_as_str ( m_wallet - > nettype ( ) , info . is_subaddress , info . address ) ;
2015-06-11 08:44:13 +00:00
}
return true ;
}
}
2015-12-12 00:05:39 +00:00
fail_msg_writer ( ) < < tr ( " failed to parse payment ID or address " ) ;
2015-06-11 08:44:13 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
2016-12-21 03:05:29 +00:00
bool simple_wallet : : address_book ( const std : : vector < std : : string > & args /* = std::vector<std::string>()*/ )
{
if ( args . size ( ) = = 0 )
{
}
else if ( args . size ( ) = = 1 | | ( args [ 0 ] ! = " add " & & args [ 0 ] ! = " delete " ) )
{
fail_msg_writer ( ) < < tr ( " usage: address_book [(add (<address> [pid <long or short payment id>])|<integrated address> [<description possibly with whitespaces>])|(delete <index>)] " ) ;
return true ;
}
else if ( args [ 0 ] = = " add " )
{
2017-02-19 02:42:10 +00:00
cryptonote : : address_parse_info info ;
2018-02-16 11:04:04 +00:00
if ( ! cryptonote : : get_account_address_from_str_or_url ( info , m_wallet - > nettype ( ) , args [ 1 ] , oa_prompter ) )
2016-12-21 03:05:29 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse address " ) ;
return true ;
}
2017-10-10 14:47:08 +00:00
crypto : : hash payment_id = crypto : : null_hash ;
2016-12-21 03:05:29 +00:00
size_t description_start = 2 ;
2017-02-19 02:42:10 +00:00
if ( info . has_payment_id )
2016-12-21 03:05:29 +00:00
{
2017-02-19 02:42:10 +00:00
memcpy ( payment_id . data , info . payment_id . data , 8 ) ;
2016-12-21 03:05:29 +00:00
}
2017-02-19 02:42:10 +00:00
else if ( ! info . has_payment_id & & args . size ( ) > = 4 & & args [ 2 ] = = " pid " )
2016-12-21 03:05:29 +00:00
{
if ( tools : : wallet2 : : parse_long_payment_id ( args [ 3 ] , payment_id ) )
{
description_start + = 2 ;
}
2017-02-19 02:42:10 +00:00
else if ( tools : : wallet2 : : parse_short_payment_id ( args [ 3 ] , info . payment_id ) )
2016-12-21 03:05:29 +00:00
{
2017-02-19 02:42:10 +00:00
memcpy ( payment_id . data , info . payment_id . data , 8 ) ;
2016-12-21 03:05:29 +00:00
description_start + = 2 ;
}
else
{
fail_msg_writer ( ) < < tr ( " failed to parse payment ID " ) ;
return true ;
}
}
std : : string description ;
for ( size_t i = description_start ; i < args . size ( ) ; + + i )
{
if ( i > description_start )
description + = " " ;
description + = args [ i ] ;
}
2017-02-19 02:42:10 +00:00
m_wallet - > add_address_book_row ( info . address , payment_id , description , info . is_subaddress ) ;
2016-12-21 03:05:29 +00:00
}
else
{
size_t row_id ;
if ( ! epee : : string_tools : : get_xtype_from_string ( row_id , args [ 1 ] ) )
{
fail_msg_writer ( ) < < tr ( " failed to parse index " ) ;
return true ;
}
m_wallet - > delete_address_book_row ( row_id ) ;
}
auto address_book = m_wallet - > get_address_book ( ) ;
if ( address_book . empty ( ) )
{
success_msg_writer ( ) < < tr ( " Address book is empty. " ) ;
}
else
{
for ( size_t i = 0 ; i < address_book . size ( ) ; + + i ) {
auto & row = address_book [ i ] ;
success_msg_writer ( ) < < tr ( " Index: " ) < < i ;
2018-02-16 11:04:04 +00:00
success_msg_writer ( ) < < tr ( " Address: " ) < < get_account_address_as_str ( m_wallet - > nettype ( ) , row . m_is_subaddress , row . m_address ) ;
2016-12-21 03:05:29 +00:00
success_msg_writer ( ) < < tr ( " Payment ID: " ) < < row . m_payment_id ;
success_msg_writer ( ) < < tr ( " Description: " ) < < row . m_description < < " \n " ;
}
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2016-04-20 17:19:42 +00:00
bool simple_wallet : : set_tx_note ( const std : : vector < std : : string > & args )
{
if ( args . size ( ) = = 0 )
{
fail_msg_writer ( ) < < tr ( " usage: set_tx_note [txid] free text note " ) ;
return true ;
}
cryptonote : : blobdata txid_data ;
2017-02-14 19:35:44 +00:00
if ( ! epee : : string_tools : : parse_hexstr_to_binbuff ( args . front ( ) , txid_data ) | | txid_data . size ( ) ! = sizeof ( crypto : : hash ) )
2016-04-20 17:19:42 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse txid " ) ;
2017-04-12 12:33:19 +00:00
return true ;
2016-04-20 17:19:42 +00:00
}
crypto : : hash txid = * reinterpret_cast < const crypto : : hash * > ( txid_data . data ( ) ) ;
std : : string note = " " ;
for ( size_t n = 1 ; n < args . size ( ) ; + + n )
{
if ( n > 1 )
note + = " " ;
note + = args [ n ] ;
}
m_wallet - > set_tx_note ( txid , note ) ;
return true ;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : get_tx_note ( const std : : vector < std : : string > & args )
{
if ( args . size ( ) ! = 1 )
{
fail_msg_writer ( ) < < tr ( " usage: get_tx_note [txid] " ) ;
return true ;
}
cryptonote : : blobdata txid_data ;
2017-02-14 19:35:44 +00:00
if ( ! epee : : string_tools : : parse_hexstr_to_binbuff ( args . front ( ) , txid_data ) | | txid_data . size ( ) ! = sizeof ( crypto : : hash ) )
2016-04-20 17:19:42 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse txid " ) ;
2017-04-12 12:33:19 +00:00
return true ;
2016-04-20 17:19:42 +00:00
}
crypto : : hash txid = * reinterpret_cast < const crypto : : hash * > ( txid_data . data ( ) ) ;
std : : string note = m_wallet - > get_tx_note ( txid ) ;
if ( note . empty ( ) )
success_msg_writer ( ) < < " no note found " ;
else
success_msg_writer ( ) < < " note found: " < < note ;
return true ;
}
//----------------------------------------------------------------------------------------------------
2017-10-08 07:15:06 +00:00
bool simple_wallet : : set_description ( const std : : vector < std : : string > & args )
{
// 0 arguments allowed, for setting the description to empty string
std : : string description = " " ;
for ( size_t n = 0 ; n < args . size ( ) ; + + n )
{
if ( n > 0 )
description + = " " ;
description + = args [ n ] ;
}
m_wallet - > set_description ( description ) ;
return true ;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : get_description ( const std : : vector < std : : string > & args )
{
if ( args . size ( ) ! = 0 )
{
fail_msg_writer ( ) < < tr ( " usage: get_description " ) ;
return true ;
}
std : : string description = m_wallet - > get_description ( ) ;
if ( description . empty ( ) )
success_msg_writer ( ) < < tr ( " no description found " ) ;
else
success_msg_writer ( ) < < tr ( " description found: " ) < < description ;
return true ;
}
//----------------------------------------------------------------------------------------------------
2016-06-20 18:11:10 +00:00
bool simple_wallet : : status ( const std : : vector < std : : string > & args )
{
uint64_t local_height = m_wallet - > get_blockchain_current_height ( ) ;
2016-11-26 12:53:33 +00:00
uint32_t version = 0 ;
if ( ! m_wallet - > check_connection ( & version ) )
2016-06-20 18:11:10 +00:00
{
success_msg_writer ( ) < < " Refreshed " < < local_height < < " /?, no daemon connected " ;
return true ;
}
std : : string err ;
uint64_t bc_height = get_daemon_blockchain_height ( err ) ;
if ( err . empty ( ) )
{
bool synced = local_height = = bc_height ;
2016-11-26 12:53:33 +00:00
success_msg_writer ( ) < < " Refreshed " < < local_height < < " / " < < bc_height < < " , " < < ( synced ? " synced " : " syncing " )
< < " , daemon RPC v " < < get_version_string ( version ) ;
2016-06-20 18:11:10 +00:00
}
else
{
fail_msg_writer ( ) < < " Refreshed " < < local_height < < " /?, daemon connection error " ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2017-08-31 08:11:20 +00:00
bool simple_wallet : : wallet_info ( const std : : vector < std : : string > & args )
{
2017-10-06 10:24:46 +00:00
bool ready ;
uint32_t threshold , total ;
2018-03-16 03:22:45 +00:00
std : : string description = m_wallet - > get_description ( ) ;
if ( description . empty ( ) )
{
description = " <Not set> " ;
}
2017-08-31 16:01:15 +00:00
message_writer ( ) < < tr ( " Filename: " ) < < m_wallet - > get_wallet_file ( ) ;
2018-03-16 03:22:45 +00:00
message_writer ( ) < < tr ( " Description: " ) < < description ;
2018-02-16 11:04:04 +00:00
message_writer ( ) < < tr ( " Address: " ) < < m_wallet - > get_account ( ) . get_public_address_str ( m_wallet - > nettype ( ) ) ;
2017-10-06 10:24:46 +00:00
std : : string type ;
if ( m_wallet - > watch_only ( ) )
type = tr ( " Watch only " ) ;
else if ( m_wallet - > multisig ( & ready , & threshold , & total ) )
type = ( boost : : format ( tr ( " %u/%u multisig%s " ) ) % threshold % total % ( ready ? " " : " (not yet finalized) " ) ) . str ( ) ;
else
type = tr ( " Normal " ) ;
message_writer ( ) < < tr ( " Type: " ) < < type ;
2018-02-16 11:04:04 +00:00
message_writer ( ) < < tr ( " Network type: " ) < < (
m_wallet - > nettype ( ) = = cryptonote : : TESTNET ? tr ( " Testnet " ) :
m_wallet - > nettype ( ) = = cryptonote : : STAGENET ? tr ( " Stagenet " ) : tr ( " Mainnet " ) ) ;
2017-08-31 08:11:20 +00:00
return true ;
}
//----------------------------------------------------------------------------------------------------
2016-04-23 20:46:48 +00:00
bool simple_wallet : : sign ( const std : : vector < std : : string > & args )
{
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2016-04-23 20:46:48 +00:00
if ( args . size ( ) ! = 1 )
{
fail_msg_writer ( ) < < tr ( " usage: sign <filename> " ) ;
return true ;
}
if ( m_wallet - > watch_only ( ) )
{
fail_msg_writer ( ) < < tr ( " wallet is watch-only and cannot sign " ) ;
return true ;
}
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
if ( m_wallet - > multisig ( ) )
{
fail_msg_writer ( ) < < tr ( " This wallet is multisig and cannot sign " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
2016-04-23 20:46:48 +00:00
std : : string filename = args [ 0 ] ;
std : : string data ;
bool r = epee : : file_io_utils : : load_file_to_string ( filename , data ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " failed to read file " ) < < filename ;
return true ;
}
2018-11-04 01:48:49 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2016-04-23 20:46:48 +00:00
std : : string signature = m_wallet - > sign ( data ) ;
success_msg_writer ( ) < < signature ;
return true ;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : verify ( const std : : vector < std : : string > & args )
{
if ( args . size ( ) ! = 3 )
{
fail_msg_writer ( ) < < tr ( " usage: verify <filename> <address> <signature> " ) ;
return true ;
}
std : : string filename = args [ 0 ] ;
std : : string address_string = args [ 1 ] ;
std : : string signature = args [ 2 ] ;
std : : string data ;
bool r = epee : : file_io_utils : : load_file_to_string ( filename , data ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " failed to read file " ) < < filename ;
return true ;
}
2017-02-19 02:42:10 +00:00
cryptonote : : address_parse_info info ;
2018-02-16 11:04:04 +00:00
if ( ! cryptonote : : get_account_address_from_str_or_url ( info , m_wallet - > nettype ( ) , address_string , oa_prompter ) )
2016-04-23 20:46:48 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse address " ) ;
return true ;
}
2017-02-19 02:42:10 +00:00
r = m_wallet - > verify ( data , info . address , signature ) ;
2016-04-23 20:46:48 +00:00
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " Bad signature from " ) < < address_string ;
}
else
{
success_msg_writer ( ) < < tr ( " Good signature from " ) < < address_string ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2016-07-15 11:11:55 +00:00
bool simple_wallet : : export_key_images ( const std : : vector < std : : string > & args )
{
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2016-07-15 11:11:55 +00:00
if ( args . size ( ) ! = 1 )
{
fail_msg_writer ( ) < < tr ( " usage: export_key_images <filename> " ) ;
return true ;
}
if ( m_wallet - > watch_only ( ) )
{
fail_msg_writer ( ) < < tr ( " wallet is watch-only and cannot export key images " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
2016-07-15 11:11:55 +00:00
std : : string filename = args [ 0 ] ;
2018-01-14 23:36:13 +00:00
if ( m_wallet - > confirm_export_overwrite ( ) & & ! check_file_overwrite ( filename ) )
return true ;
2016-07-15 11:11:55 +00:00
2018-11-04 01:48:49 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2016-07-15 11:11:55 +00:00
try
{
2017-01-13 11:02:13 +00:00
if ( ! m_wallet - > export_key_images ( filename ) )
2016-07-15 11:11:55 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to save file " ) < < filename ;
return true ;
}
}
2017-03-18 12:56:07 +00:00
catch ( const std : : exception & e )
2016-07-15 11:11:55 +00:00
{
LOG_ERROR ( " Error exporting key images: " < < e . what ( ) ) ;
fail_msg_writer ( ) < < " Error exporting key images: " < < e . what ( ) ;
return true ;
}
success_msg_writer ( ) < < tr ( " Signed key images exported to " ) < < filename ;
return true ;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : import_key_images ( const std : : vector < std : : string > & args )
{
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2018-08-10 12:15:40 +00:00
if ( ! m_wallet - > is_trusted_daemon ( ) )
2017-08-11 09:16:30 +00:00
{
fail_msg_writer ( ) < < tr ( " this command requires a trusted daemon. Enable with --trusted-daemon " ) ;
return true ;
}
2016-07-15 11:11:55 +00:00
if ( args . size ( ) ! = 1 )
{
fail_msg_writer ( ) < < tr ( " usage: import_key_images <filename> " ) ;
return true ;
}
std : : string filename = args [ 0 ] ;
2017-12-20 14:21:50 +00:00
LOCK_IDLE_SCOPE ( ) ;
2016-07-15 11:11:55 +00:00
try
{
uint64_t spent = 0 , unspent = 0 ;
2017-01-13 11:02:13 +00:00
uint64_t height = m_wallet - > import_key_images ( filename , spent , unspent ) ;
if ( height > 0 )
{
success_msg_writer ( ) < < " Signed key images imported to height " < < height < < " , "
< < print_money ( spent ) < < " spent, " < < print_money ( unspent ) < < " unspent " ;
} else {
fail_msg_writer ( ) < < " Failed to import key images " ;
}
2016-07-15 11:11:55 +00:00
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < " Failed to import key images: " < < e . what ( ) ;
return true ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2018-08-23 22:50:31 +00:00
bool simple_wallet : : hw_reconnect ( const std : : vector < std : : string > & args )
{
if ( ! m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command only supported by HW wallet " ) ;
return true ;
}
LOCK_IDLE_SCOPE ( ) ;
try
{
bool r = m_wallet - > reconnect_device ( ) ;
if ( ! r ) {
fail_msg_writer ( ) < < tr ( " Failed to reconnect device " ) ;
}
}
catch ( const std : : exception & e )
{
fail_msg_writer ( ) < < tr ( " Failed to reconnect device: " ) < < tr ( e . what ( ) ) ;
return true ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2016-10-30 19:37:09 +00:00
bool simple_wallet : : export_outputs ( const std : : vector < std : : string > & args )
{
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2016-10-30 19:37:09 +00:00
if ( args . size ( ) ! = 1 )
{
fail_msg_writer ( ) < < tr ( " usage: export_outputs <filename> " ) ;
return true ;
}
2018-07-08 20:12:33 +00:00
2016-10-30 19:37:09 +00:00
std : : string filename = args [ 0 ] ;
2018-01-14 23:36:13 +00:00
if ( m_wallet - > confirm_export_overwrite ( ) & & ! check_file_overwrite ( filename ) )
return true ;
2016-10-30 19:37:09 +00:00
2018-11-04 01:48:49 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
2016-10-30 19:37:09 +00:00
try
{
wallet-rpc: watch-only and cold wallet features added
- unsigned_txset, signed_txset in transfer / submit_transfer / sign_transfer
- export_outputs, import_outputs
Squashed commits:
[f4d9f3d4] wallet-rpc: do_not_relay removed from submit_transfer
[5b16a86f] wallet-rpc: review-fix - method signature changes, renaming
[b7fbb10a] wallet-rpc: naming fixes (unsigned vs signed), consts renamed
[8c7d2727] wallet-rpc: sign_transfer added
[481d024a] wallet2: sign_tx splitted to work with strings and structs, more granular
[2a474db9] wallet-rpc: wallet2::load_unsigned_tx split to load from str, file
[b1e3a018] wallet-rpc: review fix, load_tx_from_str variable rename
[1f6373be] wallet-rpc: review fix: save_tx_to_{str,file}
[2a08eafc] wallet-rpc: review comments fixes
- redundant this removed from wallet2.cpp
- load_tx_from_str, load_tx_from_file
[43498052] wallet-rpc: submit_transfer added
[9c45d1ad] wallet-rpc: watch_only check, return unsigned_txset
[62831396] wallet2: added string variants to load_tx, save_tx
- analogously to save_multisig_tx
- required for monero-wallet-rpc to support watch-only wallet
2018-05-07 21:23:47 +00:00
std : : string data = m_wallet - > export_outputs_to_str ( ) ;
bool r = epee : : file_io_utils : : save_string_to_file ( filename , data ) ;
2016-10-30 19:37:09 +00:00
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " failed to save file " ) < < filename ;
return true ;
}
}
catch ( const std : : exception & e )
{
LOG_ERROR ( " Error exporting outputs: " < < e . what ( ) ) ;
fail_msg_writer ( ) < < " Error exporting outputs: " < < e . what ( ) ;
return true ;
}
success_msg_writer ( ) < < tr ( " Outputs exported to " ) < < filename ;
return true ;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : import_outputs ( const std : : vector < std : : string > & args )
{
2018-02-20 16:01:27 +00:00
if ( m_wallet - > key_on_device ( ) )
{
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
2016-10-30 19:37:09 +00:00
if ( args . size ( ) ! = 1 )
{
fail_msg_writer ( ) < < tr ( " usage: import_outputs <filename> " ) ;
return true ;
}
std : : string filename = args [ 0 ] ;
std : : string data ;
bool r = epee : : file_io_utils : : load_file_to_string ( filename , data ) ;
if ( ! r )
{
fail_msg_writer ( ) < < tr ( " failed to read file " ) < < filename ;
return true ;
}
try
{
2018-07-08 20:12:33 +00:00
SCOPED_WALLET_UNLOCK ( ) ;
wallet-rpc: watch-only and cold wallet features added
- unsigned_txset, signed_txset in transfer / submit_transfer / sign_transfer
- export_outputs, import_outputs
Squashed commits:
[f4d9f3d4] wallet-rpc: do_not_relay removed from submit_transfer
[5b16a86f] wallet-rpc: review-fix - method signature changes, renaming
[b7fbb10a] wallet-rpc: naming fixes (unsigned vs signed), consts renamed
[8c7d2727] wallet-rpc: sign_transfer added
[481d024a] wallet2: sign_tx splitted to work with strings and structs, more granular
[2a474db9] wallet-rpc: wallet2::load_unsigned_tx split to load from str, file
[b1e3a018] wallet-rpc: review fix, load_tx_from_str variable rename
[1f6373be] wallet-rpc: review fix: save_tx_to_{str,file}
[2a08eafc] wallet-rpc: review comments fixes
- redundant this removed from wallet2.cpp
- load_tx_from_str, load_tx_from_file
[43498052] wallet-rpc: submit_transfer added
[9c45d1ad] wallet-rpc: watch_only check, return unsigned_txset
[62831396] wallet2: added string variants to load_tx, save_tx
- analogously to save_multisig_tx
- required for monero-wallet-rpc to support watch-only wallet
2018-05-07 21:23:47 +00:00
size_t n_outputs = m_wallet - > import_outputs_from_str ( data ) ;
2016-10-30 19:37:09 +00:00
success_msg_writer ( ) < < boost : : lexical_cast < std : : string > ( n_outputs ) < < " outputs imported " ;
}
catch ( const std : : exception & e )
{
wallet-rpc: watch-only and cold wallet features added
- unsigned_txset, signed_txset in transfer / submit_transfer / sign_transfer
- export_outputs, import_outputs
Squashed commits:
[f4d9f3d4] wallet-rpc: do_not_relay removed from submit_transfer
[5b16a86f] wallet-rpc: review-fix - method signature changes, renaming
[b7fbb10a] wallet-rpc: naming fixes (unsigned vs signed), consts renamed
[8c7d2727] wallet-rpc: sign_transfer added
[481d024a] wallet2: sign_tx splitted to work with strings and structs, more granular
[2a474db9] wallet-rpc: wallet2::load_unsigned_tx split to load from str, file
[b1e3a018] wallet-rpc: review fix, load_tx_from_str variable rename
[1f6373be] wallet-rpc: review fix: save_tx_to_{str,file}
[2a08eafc] wallet-rpc: review comments fixes
- redundant this removed from wallet2.cpp
- load_tx_from_str, load_tx_from_file
[43498052] wallet-rpc: submit_transfer added
[9c45d1ad] wallet-rpc: watch_only check, return unsigned_txset
[62831396] wallet2: added string variants to load_tx, save_tx
- analogously to save_multisig_tx
- required for monero-wallet-rpc to support watch-only wallet
2018-05-07 21:23:47 +00:00
fail_msg_writer ( ) < < " Failed to import outputs " < < filename < < " : " < < e . what ( ) ;
2016-10-30 19:37:09 +00:00
return true ;
}
return true ;
}
//----------------------------------------------------------------------------------------------------
2017-01-08 13:57:24 +00:00
bool simple_wallet : : show_transfer ( const std : : vector < std : : string > & args )
{
if ( args . size ( ) ! = 1 )
{
fail_msg_writer ( ) < < tr ( " usage: show_transfer <txid> " ) ;
return true ;
}
cryptonote : : blobdata txid_data ;
2017-02-14 19:35:44 +00:00
if ( ! epee : : string_tools : : parse_hexstr_to_binbuff ( args . front ( ) , txid_data ) | | txid_data . size ( ) ! = sizeof ( crypto : : hash ) )
2017-01-08 13:57:24 +00:00
{
fail_msg_writer ( ) < < tr ( " failed to parse txid " ) ;
2017-04-12 12:33:19 +00:00
return true ;
2017-01-08 13:57:24 +00:00
}
crypto : : hash txid = * reinterpret_cast < const crypto : : hash * > ( txid_data . data ( ) ) ;
2017-07-25 15:28:48 +00:00
const uint64_t last_block_height = m_wallet - > get_blockchain_current_height ( ) ;
2017-01-08 13:57:24 +00:00
std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : payment_details > > payments ;
2017-11-06 02:49:20 +00:00
m_wallet - > get_payments ( payments , 0 , ( uint64_t ) - 1 , m_current_subaddress_account ) ;
2017-01-08 13:57:24 +00:00
for ( std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : payment_details > > : : const_iterator i = payments . begin ( ) ; i ! = payments . end ( ) ; + + i ) {
const tools : : wallet2 : : payment_details & pd = i - > second ;
if ( pd . m_tx_hash = = txid ) {
std : : string payment_id = string_tools : : pod_to_hex ( i - > first ) ;
if ( payment_id . substr ( 16 ) . find_first_not_of ( ' 0 ' ) = = std : : string : : npos )
payment_id = payment_id . substr ( 0 , 16 ) ;
success_msg_writer ( ) < < " Incoming transaction found " ;
success_msg_writer ( ) < < " txid: " < < txid ;
success_msg_writer ( ) < < " Height: " < < pd . m_block_height ;
success_msg_writer ( ) < < " Timestamp: " < < get_human_readable_timestamp ( pd . m_timestamp ) ;
success_msg_writer ( ) < < " Amount: " < < print_money ( pd . m_amount ) ;
success_msg_writer ( ) < < " Payment ID: " < < payment_id ;
2017-07-25 15:28:48 +00:00
if ( pd . m_unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER )
{
uint64_t bh = std : : max ( pd . m_unlock_time , pd . m_block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE ) ;
2018-06-02 12:06:41 +00:00
uint64_t last_block_reward = m_wallet - > get_last_block_reward ( ) ;
uint64_t suggested_threshold = last_block_reward ? ( pd . m_amount + last_block_reward - 1 ) / last_block_reward : 0 ;
2017-07-25 15:28:48 +00:00
if ( bh > = last_block_height )
success_msg_writer ( ) < < " Locked: " < < ( bh - last_block_height ) < < " blocks to unlock " ;
2018-06-02 12:06:41 +00:00
else if ( suggested_threshold > 0 )
success_msg_writer ( ) < < std : : to_string ( last_block_height - bh ) < < " confirmations ( " < < suggested_threshold < < " suggested threshold) " ;
2017-07-25 15:28:48 +00:00
else
success_msg_writer ( ) < < std : : to_string ( last_block_height - bh ) < < " confirmations " ;
}
else
{
uint64_t current_time = static_cast < uint64_t > ( time ( NULL ) ) ;
uint64_t threshold = current_time + ( m_wallet - > use_fork_rules ( 2 , 0 ) ? CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V2 : CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V1 ) ;
if ( threshold > = pd . m_unlock_time )
success_msg_writer ( ) < < " unlocked for " < < get_human_readable_timespan ( std : : chrono : : seconds ( threshold - pd . m_unlock_time ) ) ;
else
success_msg_writer ( ) < < " locked for " < < get_human_readable_timespan ( std : : chrono : : seconds ( pd . m_unlock_time - threshold ) ) ;
}
2017-02-19 02:42:10 +00:00
success_msg_writer ( ) < < " Address index: " < < pd . m_subaddr_index . minor ;
2017-01-08 13:57:24 +00:00
success_msg_writer ( ) < < " Note: " < < m_wallet - > get_tx_note ( txid ) ;
return true ;
}
}
std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : confirmed_transfer_details > > payments_out ;
2017-02-19 02:42:10 +00:00
m_wallet - > get_payments_out ( payments_out , 0 , ( uint64_t ) - 1 , m_current_subaddress_account ) ;
2017-01-08 13:57:24 +00:00
for ( std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : confirmed_transfer_details > > : : const_iterator i = payments_out . begin ( ) ; i ! = payments_out . end ( ) ; + + i ) {
if ( i - > first = = txid )
{
const tools : : wallet2 : : confirmed_transfer_details & pd = i - > second ;
uint64_t change = pd . m_change = = ( uint64_t ) - 1 ? 0 : pd . m_change ; // change may not be known
uint64_t fee = pd . m_amount_in - pd . m_amount_out ;
std : : string dests ;
for ( const auto & d : pd . m_dests ) {
if ( ! dests . empty ( ) )
dests + = " , " ;
2018-02-16 11:04:04 +00:00
dests + = get_account_address_as_str ( m_wallet - > nettype ( ) , d . is_subaddress , d . addr ) + " : " + print_money ( d . amount ) ;
2017-01-08 13:57:24 +00:00
}
std : : string payment_id = string_tools : : pod_to_hex ( i - > second . m_payment_id ) ;
if ( payment_id . substr ( 16 ) . find_first_not_of ( ' 0 ' ) = = std : : string : : npos )
payment_id = payment_id . substr ( 0 , 16 ) ;
success_msg_writer ( ) < < " Outgoing transaction found " ;
success_msg_writer ( ) < < " txid: " < < txid ;
success_msg_writer ( ) < < " Height: " < < pd . m_block_height ;
success_msg_writer ( ) < < " Timestamp: " < < get_human_readable_timestamp ( pd . m_timestamp ) ;
success_msg_writer ( ) < < " Amount: " < < print_money ( pd . m_amount_in - change - fee ) ;
success_msg_writer ( ) < < " Payment ID: " < < payment_id ;
success_msg_writer ( ) < < " Change: " < < print_money ( change ) ;
success_msg_writer ( ) < < " Fee: " < < print_money ( fee ) ;
success_msg_writer ( ) < < " Destinations: " < < dests ;
success_msg_writer ( ) < < " Note: " < < m_wallet - > get_tx_note ( txid ) ;
return true ;
}
}
try
{
m_wallet - > update_pool_state ( ) ;
2017-09-22 12:57:20 +00:00
std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : pool_payment_details > > pool_payments ;
2017-11-06 02:49:20 +00:00
m_wallet - > get_unconfirmed_payments ( pool_payments , m_current_subaddress_account ) ;
2017-09-22 12:57:20 +00:00
for ( std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : pool_payment_details > > : : const_iterator i = pool_payments . begin ( ) ; i ! = pool_payments . end ( ) ; + + i ) {
const tools : : wallet2 : : payment_details & pd = i - > second . m_pd ;
2017-01-08 13:57:24 +00:00
if ( pd . m_tx_hash = = txid )
{
std : : string payment_id = string_tools : : pod_to_hex ( i - > first ) ;
if ( payment_id . substr ( 16 ) . find_first_not_of ( ' 0 ' ) = = std : : string : : npos )
payment_id = payment_id . substr ( 0 , 16 ) ;
success_msg_writer ( ) < < " Unconfirmed incoming transaction found in the txpool " ;
success_msg_writer ( ) < < " txid: " < < txid ;
success_msg_writer ( ) < < " Timestamp: " < < get_human_readable_timestamp ( pd . m_timestamp ) ;
success_msg_writer ( ) < < " Amount: " < < print_money ( pd . m_amount ) ;
success_msg_writer ( ) < < " Payment ID: " < < payment_id ;
2017-02-19 02:42:10 +00:00
success_msg_writer ( ) < < " Address index: " < < pd . m_subaddr_index . minor ;
2017-01-08 13:57:24 +00:00
success_msg_writer ( ) < < " Note: " < < m_wallet - > get_tx_note ( txid ) ;
2017-09-22 12:57:20 +00:00
if ( i - > second . m_double_spend_seen )
success_msg_writer ( ) < < tr ( " Double spend seen on the network: this transaction may or may not end up being mined " ) ;
2017-01-08 13:57:24 +00:00
return true ;
}
}
}
catch ( . . . )
{
fail_msg_writer ( ) < < " Failed to get pool state " ;
}
std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : unconfirmed_transfer_details > > upayments ;
2017-11-06 02:49:20 +00:00
m_wallet - > get_unconfirmed_payments_out ( upayments , m_current_subaddress_account ) ;
2017-01-08 13:57:24 +00:00
for ( std : : list < std : : pair < crypto : : hash , tools : : wallet2 : : unconfirmed_transfer_details > > : : const_iterator i = upayments . begin ( ) ; i ! = upayments . end ( ) ; + + i ) {
if ( i - > first = = txid )
{
const tools : : wallet2 : : unconfirmed_transfer_details & pd = i - > second ;
uint64_t amount = pd . m_amount_in ;
uint64_t fee = amount - pd . m_amount_out ;
std : : string payment_id = string_tools : : pod_to_hex ( i - > second . m_payment_id ) ;
if ( payment_id . substr ( 16 ) . find_first_not_of ( ' 0 ' ) = = std : : string : : npos )
payment_id = payment_id . substr ( 0 , 16 ) ;
bool is_failed = pd . m_state = = tools : : wallet2 : : unconfirmed_transfer_details : : failed ;
success_msg_writer ( ) < < ( is_failed ? " Failed " : " Pending " ) < < " outgoing transaction found " ;
success_msg_writer ( ) < < " txid: " < < txid ;
success_msg_writer ( ) < < " Timestamp: " < < get_human_readable_timestamp ( pd . m_timestamp ) ;
success_msg_writer ( ) < < " Amount: " < < print_money ( amount - pd . m_change - fee ) ;
success_msg_writer ( ) < < " Payment ID: " < < payment_id ;
success_msg_writer ( ) < < " Change: " < < print_money ( pd . m_change ) ;
success_msg_writer ( ) < < " Fee: " < < print_money ( fee ) ;
success_msg_writer ( ) < < " Note: " < < m_wallet - > get_tx_note ( txid ) ;
return true ;
}
}
fail_msg_writer ( ) < < tr ( " Transaction ID not found " ) ;
return true ;
}
//----------------------------------------------------------------------------------------------------
2014-03-03 22:07:58 +00:00
bool simple_wallet : : process_command ( const std : : vector < std : : string > & args )
{
return m_cmd_binder . process_command_vec ( args ) ;
}
//----------------------------------------------------------------------------------------------------
2015-11-29 13:02:01 +00:00
void simple_wallet : : interrupt ( )
{
if ( m_in_manual_refresh . load ( std : : memory_order_relaxed ) )
{
m_wallet - > stop ( ) ;
}
else
{
stop ( ) ;
}
}
//----------------------------------------------------------------------------------------------------
2017-10-06 01:14:09 +00:00
void simple_wallet : : commit_or_save ( std : : vector < tools : : wallet2 : : pending_tx > & ptx_vector , bool do_not_relay )
{
size_t i = 0 ;
while ( ! ptx_vector . empty ( ) )
{
auto & ptx = ptx_vector . back ( ) ;
const crypto : : hash txid = get_transaction_hash ( ptx . tx ) ;
if ( do_not_relay )
{
cryptonote : : blobdata blob ;
tx_to_blob ( ptx . tx , blob ) ;
const std : : string blob_hex = epee : : string_tools : : buff_to_hex_nodelimer ( blob ) ;
const std : : string filename = " raw_monero_tx " + ( ptx_vector . size ( ) = = 1 ? " " : ( " _ " + std : : to_string ( i + + ) ) ) ;
if ( epee : : file_io_utils : : save_string_to_file ( filename , blob_hex ) )
success_msg_writer ( true ) < < tr ( " Transaction successfully saved to " ) < < filename < < tr ( " , txid " ) < < txid ;
else
fail_msg_writer ( ) < < tr ( " Failed to save transaction to " ) < < filename < < tr ( " , txid " ) < < txid ;
}
else
{
m_wallet - > commit_tx ( ptx ) ;
success_msg_writer ( true ) < < tr ( " Transaction successfully submitted, transaction " ) < < txid < < ENDL
< < tr ( " You can check its status by using the `show_transfers` command. " ) ;
}
// if no exception, remove element from vector
ptx_vector . pop_back ( ) ;
}
}
//----------------------------------------------------------------------------------------------------
2014-03-03 22:07:58 +00:00
int main ( int argc , char * argv [ ] )
{
2018-09-29 20:17:00 +00:00
TRY_ENTRY ( ) ;
2018-02-22 18:52:55 +00:00
# ifdef WIN32
// Activate UTF-8 support for Boost filesystem classes on Windows
std : : locale : : global ( boost : : locale : : generator ( ) . generate ( " " ) ) ;
boost : : filesystem : : path : : imbue ( std : : locale ( ) ) ;
# endif
2016-11-09 03:55:41 +00:00
po : : options_description desc_params ( wallet_args : : tr ( " Wallet options " ) ) ;
tools : : wallet2 : : init_options ( desc_params ) ;
2014-03-03 22:07:58 +00:00
command_line : : add_arg ( desc_params , arg_wallet_file ) ;
command_line : : add_arg ( desc_params , arg_generate_new_wallet ) ;
2018-02-20 16:01:27 +00:00
command_line : : add_arg ( desc_params , arg_generate_from_device ) ;
2015-06-20 11:31:53 +00:00
command_line : : add_arg ( desc_params , arg_generate_from_view_key ) ;
2017-10-09 23:31:46 +00:00
command_line : : add_arg ( desc_params , arg_generate_from_spend_key ) ;
2016-02-22 22:10:55 +00:00
command_line : : add_arg ( desc_params , arg_generate_from_keys ) ;
2017-07-28 23:41:24 +00:00
command_line : : add_arg ( desc_params , arg_generate_from_multisig_keys ) ;
wallet: add a --generate-from-json flag
It takes a filename containing JSON data to generate a wallet.
The following fields are valid:
version: integer, should be 1
filename: string, path/filename for the newly created wallet
scan_from_height: 64 bit unsigned integer, optional
password: string, optional
viewkey: string, hex representation
spendkey: string, hex representation
seed: string, optional, list of words separated by spaces
Either seed or private keys should be given. If using private
keys, the spend key may be omitted (the wallet will not be
able to spend, but will see incoming transactions).
If scan_from_height is given, blocks below this height will not
be checked for transactions as an optimization.
2016-03-25 00:48:11 +00:00
command_line : : add_arg ( desc_params , arg_generate_from_json ) ;
2017-08-14 03:00:25 +00:00
command_line : : add_arg ( desc_params , arg_mnemonic_language ) ;
2014-03-03 22:07:58 +00:00
command_line : : add_arg ( desc_params , arg_command ) ;
2015-05-27 11:01:18 +00:00
2014-06-08 22:59:02 +00:00
command_line : : add_arg ( desc_params , arg_restore_deterministic_wallet ) ;
2017-11-09 10:59:41 +00:00
command_line : : add_arg ( desc_params , arg_restore_multisig_wallet ) ;
2014-06-09 00:04:32 +00:00
command_line : : add_arg ( desc_params , arg_non_deterministic ) ;
2014-06-06 19:45:21 +00:00
command_line : : add_arg ( desc_params , arg_electrum_seed ) ;
2016-07-10 15:49:40 +00:00
command_line : : add_arg ( desc_params , arg_allow_mismatched_daemon_version ) ;
2016-04-15 18:10:20 +00:00
command_line : : add_arg ( desc_params , arg_restore_height ) ;
2017-10-06 01:14:09 +00:00
command_line : : add_arg ( desc_params , arg_do_not_relay ) ;
2018-02-25 16:59:52 +00:00
command_line : : add_arg ( desc_params , arg_create_address_file ) ;
2018-03-16 04:11:45 +00:00
command_line : : add_arg ( desc_params , arg_subaddress_lookahead ) ;
2018-03-17 22:46:41 +00:00
command_line : : add_arg ( desc_params , arg_use_english_language_names ) ;
2014-03-03 22:07:58 +00:00
po : : positional_options_description positional_options ;
positional_options . add ( arg_command . name , - 1 ) ;
2018-04-15 05:52:53 +00:00
boost : : optional < po : : variables_map > vm ;
bool should_terminate = false ;
std : : tie ( vm , should_terminate ) = wallet_args : : main (
2016-11-09 03:55:41 +00:00
argc , argv ,
" monero-wallet-cli [--wallet-file=<file>|--generate-new-wallet=<file>] [<COMMAND>] " ,
2018-06-08 20:28:11 +00:00
sw : : tr ( " This is the command line monero wallet. It needs to connect to a monero \n daemon to work correctly. \n WARNING: Do not reuse your Monero keys on another fork, UNLESS this fork has key reuse mitigations built in. Doing so will harm your privacy. " ) ,
2016-11-09 03:55:41 +00:00
desc_params ,
2017-02-26 22:59:46 +00:00
positional_options ,
2017-10-28 22:04:24 +00:00
[ ] ( const std : : string & s , bool emphasis ) { tools : : scoped_message_writer ( emphasis ? epee : : console_color_white : epee : : console_color_default , true ) < < s ; } ,
2017-02-26 22:59:46 +00:00
" monero-wallet-cli.log "
2016-11-09 03:55:41 +00:00
) ;
2015-07-14 19:28:25 +00:00
2016-11-09 03:55:41 +00:00
if ( ! vm )
2014-03-03 22:07:58 +00:00
{
2016-11-09 03:55:41 +00:00
return 1 ;
}
2014-03-03 22:07:58 +00:00
2018-04-15 05:52:53 +00:00
if ( should_terminate )
{
return 0 ;
}
2016-11-09 03:55:41 +00:00
cryptonote : : simple_wallet w ;
const bool r = w . init ( * vm ) ;
CHECK_AND_ASSERT_MES ( r , 1 , sw : : tr ( " Failed to initialize wallet " ) ) ;
wallet: add a --generate-from-json flag
It takes a filename containing JSON data to generate a wallet.
The following fields are valid:
version: integer, should be 1
filename: string, path/filename for the newly created wallet
scan_from_height: 64 bit unsigned integer, optional
password: string, optional
viewkey: string, hex representation
spendkey: string, hex representation
seed: string, optional, list of words separated by spaces
Either seed or private keys should be given. If using private
keys, the spend key may be omitted (the wallet will not be
able to spend, but will see incoming transactions).
If scan_from_height is given, blocks below this height will not
be checked for transactions as an optimization.
2016-03-25 00:48:11 +00:00
2016-11-09 03:55:41 +00:00
std : : vector < std : : string > command = command_line : : get_arg ( * vm , arg_command ) ;
if ( ! command . empty ( ) )
2014-04-02 16:00:17 +00:00
{
2017-12-27 02:47:39 +00:00
if ( ! w . process_command ( command ) )
2018-10-06 08:12:38 +00:00
fail_msg_writer ( ) < < sw : : tr ( " Unknown command: " ) < < command . front ( ) ;
2016-11-09 03:55:41 +00:00
w . stop ( ) ;
w . deinit ( ) ;
}
else
{
tools : : signal_handler : : install ( [ & w ] ( int type ) {
2018-02-01 20:32:30 +00:00
if ( tools : : password_container : : is_prompting . load ( ) )
{
// must be prompting for password so return and let the signal stop prompt
return ;
}
2016-03-12 14:05:25 +00:00
# ifdef WIN32
2016-11-09 03:55:41 +00:00
if ( type = = CTRL_C_EVENT )
2016-03-12 14:05:25 +00:00
# else
2016-11-09 03:55:41 +00:00
if ( type = = SIGINT )
2016-03-12 14:05:25 +00:00
# endif
2016-11-09 03:55:41 +00:00
{
// if we're pressing ^C when refreshing, just stop refreshing
w . interrupt ( ) ;
}
else
{
w . stop ( ) ;
}
} ) ;
w . run ( ) ;
2014-03-03 22:07:58 +00:00
2016-11-09 03:55:41 +00:00
w . deinit ( ) ;
2014-04-02 16:00:17 +00:00
}
2014-05-28 20:27:59 +00:00
return 0 ;
2018-09-29 20:17:00 +00:00
CATCH_ENTRY_L0 ( " main " , 1 ) ;
2014-03-03 22:07:58 +00:00
}