Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::wallet::soft_wallet Class Referencefinal

#include <wallet.hpp>

Inheritance diagram for sysio::wallet::soft_wallet:
Collaboration diagram for sysio::wallet::soft_wallet:

Public Member Functions

 soft_wallet (const wallet_data &initial_data)
 
 ~soft_wallet ()
 
bool copy_wallet_file (string destination_filename)
 
string get_wallet_filename () const
 
private_key_type get_private_key (public_key_type pubkey) const override
 
pair< public_key_type, private_key_typeget_private_key_from_password (string account, string role, string password) const
 
bool is_new () const
 
bool is_locked () const override
 
void lock () override
 
void unlock (string password) override
 
void check_password (string password) override
 
void set_password (string password) override
 
map< public_key_type, private_key_typelist_keys () override
 
flat_set< public_key_typelist_public_keys () override
 
bool load_wallet_file (string wallet_filename="")
 
void save_wallet_file (string wallet_filename="")
 
void set_wallet_filename (string wallet_filename)
 
bool import_key (string wif_key) override
 
bool remove_key (string key) override
 
string create_key (string key_type) override
 
std::optional< signature_typetry_sign_digest (const digest_type digest, const public_key_type public_key) override
 
void encrypt_keys ()
 
- Public Member Functions inherited from sysio::wallet::wallet_api
virtual ~wallet_api ()
 

Public Attributes

std::shared_ptr< detail::soft_wallet_implmy
 

Detailed Description

This wallet assumes it is connected to the database server with a high-bandwidth, low-latency connection and performs minimal caching.

Definition at line 29 of file wallet.hpp.

Constructor & Destructor Documentation

◆ soft_wallet()

sysio::wallet::soft_wallet::soft_wallet ( const wallet_data & initial_data)

Definition at line 266 of file wallet.cpp.

267 : my(new detail::soft_wallet_impl(*this, initial_data))
268{}
std::shared_ptr< detail::soft_wallet_impl > my
Definition wallet.hpp:182

◆ ~soft_wallet()

sysio::wallet::soft_wallet::~soft_wallet ( )

Definition at line 270 of file wallet.cpp.

270{}

Member Function Documentation

◆ check_password()

void sysio::wallet::soft_wallet::check_password ( string password)
overridevirtual

Checks the password of the wallet

Validates the password on a wallet even if the wallet is already unlocked, throws if bad password given.

Parameters
passwordthe password previously set with set_password()

Implements sysio::wallet::wallet_api.

Definition at line 363 of file wallet.cpp.

364{ try {
365 FC_ASSERT(password.size() > 0);
366 auto pw = fc::sha512::hash(password.c_str(), password.size());
367 vector<char> decrypted = fc::aes_decrypt(pw, my->_wallet.cipher_keys);
368 auto pk = fc::raw::unpack<plain_keys>(decrypted);
369 FC_ASSERT(pk.checksum == pw);
370} SYS_RETHROW_EXCEPTIONS(chain::wallet_invalid_password_exception,
371 "Invalid password for wallet: \"${wallet_name}\"", ("wallet_name", get_wallet_filename())) }
#define SYS_RETHROW_EXCEPTIONS(exception_type, FORMAT,...)
static sha512 hash(const char *d, uint32_t dlen)
Definition sha512.cpp:37
string get_wallet_filename() const
Definition wallet.cpp:277
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
void unpack(Stream &s, std::deque< T > &value)
Definition raw.hpp:540
unsigned aes_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext)
Definition aes.cpp:208
Here is the call graph for this function:

◆ copy_wallet_file()

bool sysio::wallet::soft_wallet::copy_wallet_file ( string destination_filename)

Definition at line 272 of file wallet.cpp.

273{
274 return my->copy_wallet_file(destination_filename);
275}

◆ create_key()

string sysio::wallet::soft_wallet::create_key ( string key_type)
overridevirtual

Creates a key within the wallet to be used to sign transactions by an account.

example: create_key K1

Parameters
key_typethe key type to create. May be empty to allow wallet to pick appropriate/"best" key type

Implements sysio::wallet::wallet_api.

Definition at line 306 of file wallet.cpp.

307{
308 SYS_ASSERT(!is_locked(), wallet_locked_exception, "Unable to create key on a locked wallet");
309
310 string ret = my->create_key(key_type);
312 return ret;
313}
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
bool is_locked() const override
Definition wallet.cpp:325
void save_wallet_file(string wallet_filename="")
Definition wallet.cpp:320
CK_RV ret
struct @108 key_type
Here is the call graph for this function:

◆ encrypt_keys()

void sysio::wallet::soft_wallet::encrypt_keys ( )

Definition at line 335 of file wallet.cpp.

336{
337 my->encrypt_keys();
338}
Here is the caller graph for this function:

◆ get_private_key()

private_key_type sysio::wallet::soft_wallet::get_private_key ( public_key_type pubkey) const
overridevirtual

Get the WIF private key corresponding to a public key. The private key must already be in the wallet.

Implements sysio::wallet::wallet_api.

Definition at line 394 of file wallet.cpp.

395{
396 return my->get_private_key( pubkey );
397}
CK_BYTE_PTR pubkey

◆ get_private_key_from_password()

pair< public_key_type, private_key_type > sysio::wallet::soft_wallet::get_private_key_from_password ( string account,
string role,
string password ) const
Parameters
role- active | owner | posting | memo

Definition at line 403 of file wallet.cpp.

403 {
404 auto seed = account + role + password;
405 SYS_ASSERT( seed.size(), wallet_exception, "seed should not be empty" );
406 auto secret = fc::sha256::hash( seed.c_str(), seed.size() );
408 return std::make_pair( priv.get_public_key(), priv );
409}
const uint8_t password[]
Definition attest.c:39
static private_key regenerate(const typename KeyType::data_type &data)
static sha256 hash(const char *d, uint32_t dlen)
Definition sha256.cpp:44
Here is the call graph for this function:

◆ get_wallet_filename()

string sysio::wallet::soft_wallet::get_wallet_filename ( ) const

Returns the current wallet filename.

This is the filename that will be used when automatically saving the wallet.

See also
set_wallet_filename()
Returns
the wallet filename

Definition at line 277 of file wallet.cpp.

278{
279 return my->get_wallet_filename();
280}
Here is the caller graph for this function:

◆ import_key()

bool sysio::wallet::soft_wallet::import_key ( string wif_key)
overridevirtual

Imports a WIF Private Key into the wallet to be used to sign transactions by an account.

example: import_key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

Parameters
wif_keythe WIF Private Key to import

Implements sysio::wallet::wallet_api.

Definition at line 282 of file wallet.cpp.

283{
284 SYS_ASSERT(!is_locked(), wallet_locked_exception, "Unable to import key on a locked wallet");
285
286 if( my->import_key(wif_key) )
287 {
289 return true;
290 }
291 return false;
292}
Here is the call graph for this function:

◆ is_locked()

bool sysio::wallet::soft_wallet::is_locked ( ) const
overridevirtual

Checks whether the wallet is locked (is unable to use its private keys).

This state can be changed by calling lock() or unlock().

Returns
true if the wallet is locked

Implements sysio::wallet::wallet_api.

Definition at line 325 of file wallet.cpp.

326{
327 return my->is_locked();
328}
Here is the caller graph for this function:

◆ is_new()

bool sysio::wallet::soft_wallet::is_new ( ) const

Checks whether the wallet has just been created and has not yet had a password set.

Calling set_password will transition the wallet to the locked state.

Returns
true if the wallet is new

Definition at line 330 of file wallet.cpp.

331{
332 return my->_wallet.cipher_keys.size() == 0;
333}
Here is the caller graph for this function:

◆ list_keys()

map< public_key_type, private_key_type > sysio::wallet::soft_wallet::list_keys ( )
overridevirtual

Dumps all private keys owned by the wallet.

The keys are printed in WIF format. You can import these keys into another wallet using import_key()

Returns
a map containing the private keys, indexed by their public key

Implements sysio::wallet::wallet_api.

Definition at line 381 of file wallet.cpp.

382{
383 SYS_ASSERT(!is_locked(), wallet_locked_exception, "Unable to list public keys of a locked wallet");
384 return my->_keys;
385}
Here is the call graph for this function:

◆ list_public_keys()

flat_set< public_key_type > sysio::wallet::soft_wallet::list_public_keys ( )
overridevirtual

Dumps all public keys owned by the wallet.

Returns
a vector containing the public keys

Implements sysio::wallet::wallet_api.

Definition at line 387 of file wallet.cpp.

387 {
388 SYS_ASSERT(!is_locked(), wallet_locked_exception, "Unable to list private keys of a locked wallet");
389 flat_set<public_key_type> keys;
390 boost::copy(my->_keys | boost::adaptors::map_keys, std::inserter(keys, keys.end()));
391 return keys;
392}
Here is the call graph for this function:

◆ load_wallet_file()

bool sysio::wallet::soft_wallet::load_wallet_file ( string wallet_filename = "")

Loads a specified Graphene wallet.

The current wallet is closed before the new wallet is loaded.

Warning
This does not change the filename that will be used for future wallet writes, so this may cause you to overwrite your original wallet unless you also call set_wallet_filename()
Parameters
wallet_filenamethe filename of the wallet JSON file to load. If wallet_filename is empty, it reloads the existing wallet file
Returns
true if the specified wallet is loaded

Definition at line 315 of file wallet.cpp.

316{
317 return my->load_wallet_file( wallet_filename );
318}

◆ lock()

void sysio::wallet::soft_wallet::lock ( )
overridevirtual

Locks the wallet immediately.

Implements sysio::wallet::wallet_api.

Definition at line 340 of file wallet.cpp.

341{ try {
342 SYS_ASSERT( !is_locked(), wallet_locked_exception, "Unable to lock a locked wallet" );
343 encrypt_keys();
344 for( auto key : my->_keys )
345 key.second = private_key_type();
346
347 my->_keys.clear();
348 my->_checksum = fc::sha512();
#define FC_CAPTURE_AND_RETHROW(...)
fc::crypto::private_key private_key_type
Definition types.hpp:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_key()

bool sysio::wallet::soft_wallet::remove_key ( string key)
overridevirtual

Removes a key from the wallet.

example: remove_key SYS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV

Parameters
keythe Public Key to remove

Implements sysio::wallet::wallet_api.

Definition at line 294 of file wallet.cpp.

295{
296 SYS_ASSERT(!is_locked(), wallet_locked_exception, "Unable to remove key from a locked wallet");
297
298 if( my->remove_key(key) )
299 {
301 return true;
302 }
303 return false;
304}
Here is the call graph for this function:

◆ save_wallet_file()

void sysio::wallet::soft_wallet::save_wallet_file ( string wallet_filename = "")

Saves the current wallet to the given filename.

Warning
This does not change the wallet filename that will be used for future writes, so think of this function as 'Save a Copy As...' instead of 'Save As...'. Use set_wallet_filename() to make the filename persist.
Parameters
wallet_filenamethe filename of the new wallet JSON file to create or overwrite. If wallet_filename is empty, save to the current filename.

Definition at line 320 of file wallet.cpp.

321{
322 my->save_wallet_file( wallet_filename );
323}
Here is the caller graph for this function:

◆ set_password()

void sysio::wallet::soft_wallet::set_password ( string password)
overridevirtual

Sets a new password on the wallet.

The wallet must be either 'new' or 'unlocked' to execute this command.

Implements sysio::wallet::wallet_api.

Definition at line 373 of file wallet.cpp.

374{
375 if( !is_new() )
376 SYS_ASSERT( !is_locked(), wallet_locked_exception, "The wallet must be unlocked before the password can be set" );
377 my->_checksum = fc::sha512::hash( password.c_str(), password.size() );
378 lock();
379}
void lock() override
Definition wallet.cpp:340
Here is the call graph for this function:

◆ set_wallet_filename()

void sysio::wallet::soft_wallet::set_wallet_filename ( string wallet_filename)

Sets the wallet filename used for future writes.

This does not trigger a save, it only changes the default filename that will be used the next time a save is triggered.

Parameters
wallet_filenamethe new filename to use for future saves

Definition at line 411 of file wallet.cpp.

412{
413 my->_wallet_filename = wallet_filename;
414}

◆ try_sign_digest()

std::optional< signature_type > sysio::wallet::soft_wallet::try_sign_digest ( const digest_type digest,
const public_key_type public_key )
overridevirtual

Returns a signature given the digest and public_key, if this wallet can sign via that public key

Implements sysio::wallet::wallet_api.

Definition at line 399 of file wallet.cpp.

399 {
400 return my->try_sign_digest(digest, public_key);
401}
fc::sha256 digest(const T &value)
Definition digest.hpp:9
Here is the call graph for this function:

◆ unlock()

void sysio::wallet::soft_wallet::unlock ( string password)
overridevirtual

Unlocks the wallet.

The wallet remain unlocked until the lock is called or the program exits.

Parameters
passwordthe password previously set with set_password()

Implements sysio::wallet::wallet_api.

Definition at line 351 of file wallet.cpp.

352{ try {
353 FC_ASSERT(password.size() > 0);
354 auto pw = fc::sha512::hash(password.c_str(), password.size());
355 vector<char> decrypted = fc::aes_decrypt(pw, my->_wallet.cipher_keys);
356 auto pk = fc::raw::unpack<plain_keys>(decrypted);
357 FC_ASSERT(pk.checksum == pw);
358 my->_keys = std::move(pk.keys);
359 my->_checksum = pk.checksum;
360} SYS_RETHROW_EXCEPTIONS(chain::wallet_invalid_password_exception,
361 "Invalid password for wallet: \"${wallet_name}\"", ("wallet_name", get_wallet_filename())) }
Here is the call graph for this function:

Member Data Documentation

◆ my

std::shared_ptr<detail::soft_wallet_impl> sysio::wallet::soft_wallet::my

Definition at line 182 of file wallet.hpp.


The documentation for this class was generated from the following files: