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

#include <se_wallet.hpp>

Inheritance diagram for sysio::wallet::se_wallet:
Collaboration diagram for sysio::wallet::se_wallet:

Public Member Functions

 se_wallet ()
 
 ~se_wallet ()
 
private_key_type get_private_key (public_key_type pubkey) const override
 
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 import_key (string wif_key) override
 
string create_key (string key_type) override
 
bool remove_key (string key) override
 
std::optional< signature_typetry_sign_digest (const digest_type digest, const public_key_type public_key) override
 
- Public Member Functions inherited from sysio::wallet::wallet_api
virtual ~wallet_api ()
 

Detailed Description

Definition at line 15 of file se_wallet.hpp.

Constructor & Destructor Documentation

◆ se_wallet()

sysio::wallet::se_wallet::se_wallet ( )

Definition at line 286 of file se_wallet.cpp.

286 : my(new detail::se_wallet_impl()) {
287 detail::check_signed();
288
289 //How to figure out of SE is available?!
290 char model[256];
291 size_t model_size = sizeof(model);
292 if(sysctlbyname("hw.model", model, &model_size, nullptr, 0) == 0) {
293 if(strncmp(model, "iMacPro", strlen("iMacPro")) == 0) {
294 my->populate_existing_keys();
295 return;
296 }
297 unsigned int major, minor;
298 if(sscanf(model, "MacBookPro%u,%u", &major, &minor) == 2) {
299 if((major >= 15) || (major >= 13 && minor >= 2)) {
300 my->populate_existing_keys();
301 return;
302 }
303 }
304 if(sscanf(model, "Macmini%u", &major) == 1 && major >= 8) {
305 my->populate_existing_keys();
306 return;
307 }
308 if(sscanf(model, "MacBookAir%u", &major) == 1 && major >= 8) {
309 my->populate_existing_keys();
310 return;
311 }
312 }
313
314 SYS_THROW(secure_enclave_exception, "Secure Enclave not supported on this hardware");
315}
#define SYS_THROW(exc_type, FORMAT,...)
uint8_t major
uint8_t minor

◆ ~se_wallet()

sysio::wallet::se_wallet::~se_wallet ( )

Definition at line 317 of file se_wallet.cpp.

317 {
318}

Member Function Documentation

◆ check_password()

void sysio::wallet::se_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 340 of file se_wallet.cpp.

340 {
341 //just leave this as a noop for now; remove_key from wallet_mgr calls through here
342}

◆ create_key()

string sysio::wallet::se_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 360 of file se_wallet.cpp.

360 {
361 SYS_ASSERT(key_type.empty() || key_type == "R1", chain::unsupported_key_type_exception, "Secure Enclave wallet only supports R1 keys");
362 return my->create().to_string();
363}
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
struct @108 key_type

◆ get_private_key()

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

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

Implements sysio::wallet::wallet_api.

Definition at line 320 of file se_wallet.cpp.

320 {
321 FC_THROW_EXCEPTION(chain::wallet_exception, "Obtaining private key for a key stored in Secure Enclave is impossible");
322}
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)

◆ import_key()

bool sysio::wallet::se_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 356 of file se_wallet.cpp.

356 {
357 FC_THROW_EXCEPTION(chain::wallet_exception, "It is not possible to import a key in to the Secure Enclave wallet");
358}

◆ is_locked()

bool sysio::wallet::se_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 324 of file se_wallet.cpp.

324 {
325 return my->locked;
326}
Here is the caller graph for this function:

◆ list_keys()

map< public_key_type, private_key_type > sysio::wallet::se_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 347 of file se_wallet.cpp.

347 {
348 FC_THROW_EXCEPTION(chain::wallet_exception, "Getting the private keys from the Secure Enclave wallet is impossible");
349}

◆ list_public_keys()

flat_set< public_key_type > sysio::wallet::se_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 350 of file se_wallet.cpp.

350 {
351 flat_set<public_key_type> keys;
352 boost::copy(my->_keys | boost::adaptors::map_keys, std::inserter(keys, keys.end()));
353 return keys;
354}

◆ lock()

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

Locks the wallet immediately

Implements sysio::wallet::wallet_api.

Definition at line 327 of file se_wallet.cpp.

327 {
328 SYS_ASSERT(!is_locked(), wallet_locked_exception, "You can not lock an already locked wallet");
329 my->locked = true;
330}
bool is_locked() const override
Here is the call graph for this function:

◆ remove_key()

bool sysio::wallet::se_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 365 of file se_wallet.cpp.

365 {
366 SYS_ASSERT(!is_locked(), wallet_locked_exception, "You can not remove a key from a locked wallet");
367 return my->remove_key(key);
368}
Here is the call graph for this function:

◆ set_password()

void sysio::wallet::se_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 343 of file se_wallet.cpp.

343 {
344 FC_THROW_EXCEPTION(chain::wallet_exception, "Secure Enclave wallet cannot have a password set");
345}

◆ try_sign_digest()

std::optional< signature_type > sysio::wallet::se_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 370 of file se_wallet.cpp.

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

◆ unlock()

void sysio::wallet::se_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 332 of file se_wallet.cpp.

332 {
333 promise<bool> prom;
334 future<bool> fut = prom.get_future();
335 macos_user_auth(detail::auth_callback, &prom, CFSTR("unlock your SYSIO wallet"));
336 if(!fut.get())
337 FC_THROW_EXCEPTION(chain::wallet_invalid_password_exception, "Local user authentication failed");
338 my->locked = false;
339}
void macos_user_auth(void(*cb)(int, void *), void *cb_userdata, CFStringRef message)
Here is the call graph for this function:

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