Offline Transaction Signing (OTS) 0.1.0
Loading...
Searching...
No Matches
ots::Wallet Class Reference

provides all offline wallet functionality More...

#include <ots.hpp>

Collaboration diagram for ots::Wallet:

Public Member Functions

uint64_t height () const noexcept
 The block height on creation of the wallet.
 
Address address (uint32_t account=0, uint32_t index=0) const noexcept
 Generate/lookup address in wallet.
 
std::vector< Addressaccounts (uint32_t max=10, uint32_t offset=0) const noexcept
 Gives a list of accounts (e.g. for a address browser)
 
std::vector< AddresssubAddresses (uint32_t account=0, uint32_t max=10, uint32_t offset=0) const noexcept
 Gives a list of subaddresses for a given account.
 
bool hasAddress (const std::string &address, uint32_t maxAccountDepth=0, uint32_t maxIndexDepth=0) const noexcept
 check if the address string is a valid monero address and then if the address belongs to the wallet
 
bool hasAddress (const Address &address, uint32_t maxAccountDepth=0, uint32_t maxIndexDepth=0) const noexcept
 check if the address belongs to the wallet
 
std::pair< uint32_t, uint32_t > addressIndex (const std::string &address, uint32_t maxAccountDepth=0, uint32_t maxIndexDepth=0) const
 check if the address string is a valid monero address and give the account and subindex
 
std::pair< uint32_t, uint32_t > addressIndex (const Address &address, uint32_t maxAccountDepth=0, uint32_t maxIndexDepth=0) const
 get the account and subindex of a address in the wallet
 
WipeableString secretViewKey () const noexcept
 The Secret View Key.
 
WipeableString publicViewKey () const noexcept
 The Public View Key.
 
WipeableString secretSpendKey () const noexcept
 The Secret Spend Key.
 
WipeableString publicSpendKey () const noexcept
 The Public Spend Key.
 
uint64_t importOutputs (const std::string &outputs)
 import the output, previous exported from the view only wallet
 
WipeableString exportKeyImages () const
 export key images after outputs are imported
 
TxDescription describeTransaction (const std::string &unsignedTransaction) const
 Gives a whole picture of the unsigned transaction.
 
std::vector< TxWarningcheckTransaction (const std::string &unsignedTransaction) const
 Gives a warnings if any for the unsigned transaction.
 
std::vector< TxWarningcheckTransaction (const TxDescription &description) const noexcept
 Gives a warnings if any for the unsigned transaction.
 
std::string signTransaction (const std::string &unsignedTransaction) const
 Sign a provided unsigned transaction.
 
std::string signData (const std::string &data) const noexcept
 Sign a provided string.
 
std::string signData (const std::string &data, const std::pair< uint32_t, uint32_t > &index) const
 sign a message with subindex address of the wallet
 
std::string signData (const std::string &data, const Address &address) const
 sign a message with the provided address of the wallet
 
std::string signData (const std::string &data, const std::string &address) const
 sign a message with the provided address of the wallet
 
bool verifyData (const std::string &data, const std::pair< uint32_t, uint32_t > &index, const std::string &signature, bool legacyFallback=false) const
 Verify a signed message.
 
bool verifyData (const std::string &data, const std::string &signature, bool legacyFallback=false) const
 Verify a signed message, for the wallet address.
 
 Wallet (const std::array< unsigned char, 32 > &key, uint64_t height, const Network network) noexcept
 Create a offline Wallet from a secret key.
 
 Wallet (const KeyStore &key, uint64_t height, const Network network) noexcept
 Create a offline Wallet from a secret key.
 
 Wallet (const Account &account, const KeyStore &key, uint64_t height, const Network network) noexcept
 Create a offline Wallet from a secret key.
 

Static Public Member Functions

static bool verifyData (const std::string &data, const std::string &address, const std::string &signature, bool legacyFallback=false)
 Verify a signed message.
 
static bool verifyData (const std::string &data, const Address &address, const std::string &signature, bool legacyFallback=false)
 Verify a signed message.
 

Protected Attributes

std::unique_ptr< KeyStore, KeyStoreDeleterm_key
 
std::unique_ptr< Account, AccountDeleterm_account
 
Network m_network
 
uint64_t m_height = 0
 

Detailed Description

provides all offline wallet functionality

Constructor & Destructor Documentation

◆ Wallet() [1/3]

ots::Wallet::Wallet ( const std::array< unsigned char, 32 > &  key,
uint64_t  height,
const Network  network 
)
noexcept

Create a offline Wallet from a secret key.

Parameters
keyprovided as insecure std::array, will be stored in the keystore, make sure to wipe the provided variable after creating the Wallet
heightrestore height of the wallet
networkthe network of the wallet

◆ Wallet() [2/3]

ots::Wallet::Wallet ( const KeyStore key,
uint64_t  height,
const Network  network 
)
noexcept

Create a offline Wallet from a secret key.

Parameters
keyprovide the key via a secret key Storage
heightrestore height of the wallet
networkthe network of the wallet

◆ Wallet() [3/3]

ots::Wallet::Wallet ( const Account account,
const KeyStore key,
uint64_t  height,
const Network  network 
)
noexcept

Create a offline Wallet from a secret key.

Parameters
accountprovides the internal workings of the wallet
keyprovide the key via a secret key Storage
heightrestore height of the wallet
networkthe network of the wallet

Member Function Documentation

◆ accounts()

std::vector< Address > ots::Wallet::accounts ( uint32_t  max = 10,
uint32_t  offset = 0 
) const
noexcept

Gives a list of accounts (e.g. for a address browser)

Parameters
maxmaximum entries returned, which should be always be return, except if index + max < max(uint32_t)
offsetfirst account to return
Returns
the list of the addresses which represent the account (subaddress index 0)
See also
https://docs.getmonero.org/public-address/subaddress

◆ address()

Address ots::Wallet::address ( uint32_t  account = 0,
uint32_t  index = 0 
) const
noexcept

Generate/lookup address in wallet.

Parameters
account0 is the default account and wallet itself
indexstarting from 0 is the index of the subaddress in the account
Returns
Standard address for account 0 and index 0 else the subaddress

◆ addressIndex() [1/2]

std::pair< uint32_t, uint32_t > ots::Wallet::addressIndex ( const Address address,
uint32_t  maxAccountDepth = 0,
uint32_t  maxIndexDepth = 0 
) const

get the account and subindex of a address in the wallet

Parameters
addressthe string containing supposingly a monero address
Exceptions
ots::exception::address::Invalidif the address is not valid
ots::exception::wallet::AddressNotFoundif the address is not in the wallet
Returns
first number is the account, second number the index

◆ addressIndex() [2/2]

std::pair< uint32_t, uint32_t > ots::Wallet::addressIndex ( const std::string &  address,
uint32_t  maxAccountDepth = 0,
uint32_t  maxIndexDepth = 0 
) const

check if the address string is a valid monero address and give the account and subindex

Parameters
addressthe string containing supposingly a monero address
Exceptions
ots::exception::address::Invalidif the address is not valid
ots::exception::wallet::AddressNotFoundif the address is not in the wallet
Returns
first number is the account, second number the index

◆ checkTransaction() [1/2]

std::vector< TxWarning > ots::Wallet::checkTransaction ( const std::string &  unsignedTransaction) const

Gives a warnings if any for the unsigned transaction.

Parameters
unsignedTransactionunsigned transaction string
Exceptions
ots::exception::tx::Invalidif the provided transaction is invalid
Returns
a list of warnings

◆ checkTransaction() [2/2]

std::vector< TxWarning > ots::Wallet::checkTransaction ( const TxDescription description) const
noexcept

Gives a warnings if any for the unsigned transaction.

Parameters
descriptionTransaction Description object
Returns
a list of warnings

◆ describeTransaction()

TxDescription ots::Wallet::describeTransaction ( const std::string &  unsignedTransaction) const

Gives a whole picture of the unsigned transaction.

Parameters
unsignedTransactionunsigned transaction string
Exceptions
ots::exception::tx::Invalidif the provided transaction is invalid
Returns
a Transaction Description

◆ exportKeyImages()

WipeableString ots::Wallet::exportKeyImages ( ) const

export key images after outputs are imported

Returns
key images for the provided outputs
Exceptions
ots::exception::wallet::ExportKeyImagesif there are no key images, probably because no outputs are imported
Note
the key images are needed by the view only wallet to create an unsigned transaction

◆ hasAddress() [1/2]

bool ots::Wallet::hasAddress ( const Address address,
uint32_t  maxAccountDepth = 0,
uint32_t  maxIndexDepth = 0 
) const
noexcept

check if the address belongs to the wallet

Parameters
addressthe monero address
Returns
true if the address belongs to the wallet

◆ hasAddress() [2/2]

bool ots::Wallet::hasAddress ( const std::string &  address,
uint32_t  maxAccountDepth = 0,
uint32_t  maxIndexDepth = 0 
) const
noexcept

check if the address string is a valid monero address and then if the address belongs to the wallet

Parameters
addressthe string containing supposingly a monero address
Returns
false if the address is not valid or not belong to the wallet, otherwise true

◆ height()

uint64_t ots::Wallet::height ( ) const
inlinenoexcept

The block height on creation of the wallet.

Returns
(estimated or user provided) restore block height, worst case is 0, from the beginning of the block chain
Note
For the library itself meaningless, because of it's offline character, but is important for information to the view only wallet.

◆ importOutputs()

uint64_t ots::Wallet::importOutputs ( const std::string &  outputs)

import the output, previous exported from the view only wallet

Returns
count of imported outputs
Exceptions
ots::exception::wallet::ImportOutputsif provides outputs are not valid
Note
the outputs are needed to export the key images
See also
Wallet::importOutputs()

◆ publicSpendKey()

WipeableString ots::Wallet::publicSpendKey ( ) const
noexcept

The Public Spend Key.

Returns
the wallet public spend key

◆ publicViewKey()

WipeableString ots::Wallet::publicViewKey ( ) const
noexcept

The Public View Key.

Returns
the wallet public view key

◆ secretSpendKey()

WipeableString ots::Wallet::secretSpendKey ( ) const
noexcept

The Secret Spend Key.

Returns
the wallet secret spend key

◆ secretViewKey()

WipeableString ots::Wallet::secretViewKey ( ) const
noexcept

The Secret View Key.

Returns
the wallet secret view key

◆ signData() [1/4]

std::string ots::Wallet::signData ( const std::string &  data) const
noexcept

Sign a provided string.

Parameters
dataString of the message to sign
Returns
signature of the message

◆ signData() [2/4]

std::string ots::Wallet::signData ( const std::string &  data,
const Address address 
) const

sign a message with the provided address of the wallet

Parameters
datathe message to sign
addressthe address of the wallet
Returns
the signature of the message
Exceptions
ots::exception::address::Invalidif the address is not valid
ots::exception::BufferOverflowExceptionif tools:write_varint fails in Account::hashData() (should not happen)

◆ signData() [3/4]

std::string ots::Wallet::signData ( const std::string &  data,
const std::pair< uint32_t, uint32_t > &  index 
) const

sign a message with subindex address of the wallet

Parameters
datathe message to sign
indexthe account and index to sign with
Returns
the signature of the message
Exceptions
ots::exception::BufferOverflowExceptionif tools:write_varint fails in Account::hashData() (should not happen)

◆ signData() [4/4]

std::string ots::Wallet::signData ( const std::string &  data,
const std::string &  address 
) const

sign a message with the provided address of the wallet

Parameters
datathe message to sign
addressthe address of the wallet
Returns
the signature of the message
Exceptions
ots::exception::address::Invalidif the address is not valid
ots::exception::BufferOverflowExceptionif tools:write_varint fails in Account::hashData() (should not happen)

◆ signTransaction()

std::string ots::Wallet::signTransaction ( const std::string &  unsignedTransaction) const

Sign a provided unsigned transaction.

Parameters
unsignedTransactionunsigned transaction string
Exceptions
ots::exception::tx::Invalidif the provided transaction is invalid
Returns
a signed transaction

◆ subAddresses()

std::vector< Address > ots::Wallet::subAddresses ( uint32_t  account = 0,
uint32_t  max = 10,
uint32_t  offset = 0 
) const
noexcept

Gives a list of subaddresses for a given account.

Parameters
accountindex of the account, 0 is the wallet itself
maxmaximum entries returned, which should be always be return, except if index + max < max(uint32_t)
offsetfirst subindex to return
Returns
the list of the addresses which represent subaddresses of the account (subaddress index 0 is the account itself)

◆ verifyData() [1/4]

bool ots::Wallet::verifyData ( const std::string &  data,
const Address address,
const std::string &  signature,
bool  legacyFallback = false 
)
static

Verify a signed message.

Parameters
dataString of the message to sign
addresspublic Monero address
signaturefor the message
legacyFallbackif true, will try to verify with legacy signature
Exceptions
ots::exception::address::Invalidif the address is not valid
Returns
true if the signature is valid

◆ verifyData() [2/4]

bool ots::Wallet::verifyData ( const std::string &  data,
const std::pair< uint32_t, uint32_t > &  index,
const std::string &  signature,
bool  legacyFallback = false 
) const

Verify a signed message.

Parameters
dataString of the message to sign
addressindex of the account and subaddress
signaturefor the message
legacyFallbackif true, will try to verify with legacy signature
Exceptions
ots::exception::address::Invalidif the address is not valid
Returns
true if the signature is valid

◆ verifyData() [3/4]

bool ots::Wallet::verifyData ( const std::string &  data,
const std::string &  address,
const std::string &  signature,
bool  legacyFallback = false 
)
static

Verify a signed message.

Parameters
dataString of the message to sign
addresspublic Monero address as string
signaturefor the message
Exceptions
ots::exception::address::Invalidif the address is not valid
Returns
true if the signature is valid

◆ verifyData() [4/4]

bool ots::Wallet::verifyData ( const std::string &  data,
const std::string &  signature,
bool  legacyFallback = false 
) const

Verify a signed message, for the wallet address.

Parameters
dataString of the message to sign
signaturefor the message
legacyFallbackif true, will try to verify with legacy signature
Exceptions
ots::exception::address::Invalidif the address is not valid
Returns
true if the signature is valid

Member Data Documentation

◆ m_account

std::unique_ptr<Account, AccountDeleter> ots::Wallet::m_account
protected

◆ m_height

uint64_t ots::Wallet::m_height = 0
protected

◆ m_key

std::unique_ptr<KeyStore, KeyStoreDeleter> ots::Wallet::m_key
protected

◆ m_network

Network ots::Wallet::m_network
protected

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