C++ API Documentation
Generated from zkapputilslib version 1.2.1-1 (commit 56b075d).
This file contains the C++ API to the the Zymkey Application Utilities library, libzkAppUtilsClassCPP. Systems intending to run such applications require that the libzkapputils-c++ package be installed.
This class facilitates writing user space applications which use Zymkey to perform cryptographic operations, such as:
- Signing of payloads using ECDSA
- Verification of payloads that were signed using Zymkey
- Exporting the public key that matches Zymkey’s private key
- “Locking” and “unlocking” data objects
- Generating random data Additionally, there are functions for changing the I2C address (I2C units only), setting tap sensitivity and controlling the LED.
Developers wishing to build applications which utilize the libzkAppUtilsClassCPP library should additionally install the libzkapputils-c++-dev package, which contains the necessary development files for the Zymkey’s C++ library. To install this package on a system that does not need to run the applications (e.g. a Docker container or when cross compiling on another architecture), use apt install --no-install-recommends libzkapputils-c++-dev. This will prevent apt from installing the Zymkey’s zkifc driver daemon.
Usage:
#include <zymkey/zkAppUtilsClass.h>
To add libzkAppUtilsClassCPP as a dependency of a CMake-based project, add the following lines to your project’s CMakeLists.txt:
find_package(zkAppUtilsCXX REQUIRED)
target_link_libraries(${target_name} zkAppUtilsCXX::zkAppUtilsClassCPP)
Statically linking to the library is also supported within CMake by way of the zkAppUtilsCXX::zkAppUtilsClassCPP_static library target.
Projects may alternatively import the library dependency via pkg-config:
CFLAGS="$(pkg-config --cflags zkapputils-c++)"
LDFLAGS="$(pkg-config --libs zkapputils-c++)"
Typedefs
byteArray
typedef
typedef std::vector<uint8_t> zkAppUtils::byteArrayintArray
typedef
typedef std::vector<int> zkAppUtils::intArrayClasses
zkAppUtils::commonException
class
Inherits from std::exception.
Public Functions
commonException
function
zkAppUtils::commonException::commonException(std::string status)Parameters
statusstd::string- A string which described the verbose exception
~commonException
function
inline virtual zkAppUtils::commonException::~commonException()what
function
const char * zkAppUtils::commonException::what() constzkAppUtils::timeoutException
class
Inherits from std::exception.
Public Functions
timeoutException
function
zkAppUtils::timeoutException::timeoutException(std::string status)Parameters
statusstd::string- A string which described the verbose exception
~timeoutException
function
inline virtual zkAppUtils::timeoutException::~timeoutException()what
function
const char * zkAppUtils::timeoutException::what() constzkAppUtils::recoveryStrategyBaseType
class
Protected Members
recoveryStrategy
variable protected
ZK_RECOVERY_STRATEGY zkAppUtils::recoveryStrategyBaseType::recoveryStrategyvariant
variable protected
std::string zkAppUtils::recoveryStrategyBaseType::variantPublic Functions
recoveryStrategyBaseType
function
zkAppUtils::recoveryStrategyBaseType::recoveryStrategyBaseType(const std::string &key_variant="")Parameters
key_variantconst std::string & default""- The key variant (only “cardano” is supported, for ed25519).
~recoveryStrategyBaseType
function
zkAppUtils::recoveryStrategyBaseType::~recoveryStrategyBaseType()getRecoveryStrategy
function
inline ZK_RECOVERY_STRATEGY zkAppUtils::recoveryStrategyBaseType::getRecoveryStrategy() constsetVariant
function
inline void zkAppUtils::recoveryStrategyBaseType::setVariant(const std::string &key_variant)Parameters
key_variantconst std::string &
getVariant
function
inline std::string zkAppUtils::recoveryStrategyBaseType::getVariant() constgetPassPhrase
function
inline virtual std::string zkAppUtils::recoveryStrategyBaseType::getPassPhrase() constzkAppUtils::recoveryStrategyBIP39
class
Inherits from zkAppUtils::recoveryStrategyBaseType.
Public Functions
recoveryStrategyBIP39
function
zkAppUtils::recoveryStrategyBIP39::recoveryStrategyBIP39(const std::string &passphrase="", const std::string &key_variant="")Parameters
passphraseconst std::string & default""- Base 64 encoded passphrase; empty for none.
key_variantconst std::string & default""- The key variant (only “cardano” is supported, for ed25519).
~recoveryStrategyBIP39
function
zkAppUtils::recoveryStrategyBIP39::~recoveryStrategyBIP39()setPassPhrase
function
inline void zkAppUtils::recoveryStrategyBIP39::setPassPhrase(const std::string &passphrase)Parameters
passphraseconst std::string &
getPassPhrase
function
inline std::string zkAppUtils::recoveryStrategyBIP39::getPassPhrase() constzkAppUtils::recoveryStrategySLIP39
class
Inherits from zkAppUtils::recoveryStrategyBaseType.
Public Functions
recoveryStrategySLIP39
function
zkAppUtils::recoveryStrategySLIP39::recoveryStrategySLIP39(int group_count, int group_threshold, int iteration_exponent, const std::string &passphrase="", const std::string &key_variant="")Parameters
group_countint- Total number of groups to generate (max 14).
group_thresholdint- Number of groups needed to restore the master seed.
iteration_exponentint- The higher the exponent, the more PBKDF2 hashing is done (0-5).
passphraseconst std::string & default""- Base 64 encoded passphrase; empty for none.
key_variantconst std::string & default""- The key variant (only “cardano” is supported, for ed25519).
~recoveryStrategySLIP39
function
zkAppUtils::recoveryStrategySLIP39::~recoveryStrategySLIP39()setPassPhrase
function
inline void zkAppUtils::recoveryStrategySLIP39::setPassPhrase(const std::string &passphrase)Parameters
passphraseconst std::string &
getPassPhrase
function
inline std::string zkAppUtils::recoveryStrategySLIP39::getPassPhrase() constsetGroupCount
function
inline void zkAppUtils::recoveryStrategySLIP39::setGroupCount(int group_count)Parameters
group_countint
getGroupCount
function
inline int zkAppUtils::recoveryStrategySLIP39::getGroupCount() constsetGroupThreshold
function
inline void zkAppUtils::recoveryStrategySLIP39::setGroupThreshold(int group_threshold)Parameters
group_thresholdint
getGroupThreshold
function
inline int zkAppUtils::recoveryStrategySLIP39::getGroupThreshold() constsetIterationExponent
function
inline void zkAppUtils::recoveryStrategySLIP39::setIterationExponent(int iteration_exponent)Parameters
iteration_exponentint
getIterationExponent
function
inline int zkAppUtils::recoveryStrategySLIP39::getIterationExponent() constzkAppUtils::accelData
struct
Public Members
x
variable
double zkAppUtils::accelData::xy
variable
double zkAppUtils::accelData::yz
variable
double zkAppUtils::accelData::ztapDirX
variable
int zkAppUtils::accelData::tapDirXtapDirY
variable
int zkAppUtils::accelData::tapDirYtapDirZ
variable
int zkAppUtils::accelData::tapDirZzkAppUtils::zkClass
class
Zymkey Context
zkClass
function
zkAppUtils::zkClass::zkClass()Throws
zkAppUtilsException- upon error
~zkClass
function
virtual zkAppUtils::zkClass::~zkClass()Random Number Generation
createRandDataFile
function
void zkAppUtils::zkClass::createRandDataFile(std::string &dst_filename, int rdata_sz)Parameters
dst_filenamestd::string &- A string containing the absolute path to the file where random data is written
rdata_szint- The number of random bytes to generate
Throws
zkAppUtilsException- upon error
getRandBytes
function
zkAppUtils::byteArray * zkAppUtils::zkClass::getRandBytes(int rdata_sz)Parameters
rdata_szint- The number of random bytes to generate
Returns
- zkAppUtils::byteArray *
- A pointer to container with the random bytes
Throws
zkAppUtilsException- upon error
Lock Data
lockData
function
void zkAppUtils::zkClass::lockData(const std::string &src_pt_filename, const std::string &dst_ct_filename, bool use_shared_key=false)Parameters
src_pt_filenameconst std::string &- Absolute path to source plaintext file
dst_ct_filenameconst std::string &- Absolute path to destination file which will contain locked data object
use_shared_keybool defaultfalse- Determines whether one-way or shared key is used for locking. Default = false.
Throws
zkAppUtilsException- upon error
lockData
function
void zkAppUtils::zkClass::lockData(const byteArray &src_pt_data, const std::string &dst_ct_filename, bool use_shared_key=false)Parameters
src_pt_dataconst byteArray &- Unsigned byte container which holds source plaintext data
dst_ct_filenameconst std::string &- Absolute path to destination file which will contain locked data object
use_shared_keybool defaultfalse- Determines whether one-way or shared key is used for locking. Default = false.
Throws
zkAppUtilsException- upon error
lockData
function
zkAppUtils::byteArray * zkAppUtils::zkClass::lockData(const std::string &src_pt_filename, bool use_shared_key=false)Parameters
src_pt_filenameconst std::string &- Absolute path to source plaintext file
use_shared_keybool defaultfalse- Determines whether one-way or shared key is used for locking. Default = false.
Returns
- zkAppUtils::byteArray *
- Byte container with locked data
Throws
zkAppUtilsException- upon error
lockData
function
zkAppUtils::byteArray * zkAppUtils::zkClass::lockData(const byteArray &src_pt_data, bool use_shared_key=false)Parameters
src_pt_dataconst byteArray &- Unsigned byte container which holds source plaintext data
use_shared_keybool defaultfalse- Determines whether one-way or shared key is used for locking. Default = false.
Returns
- zkAppUtils::byteArray *
- Byte container with locked data
Throws
zkAppUtilsException- upon error
Unlock Data
unlockData
function
void zkAppUtils::zkClass::unlockData(const std::string &src_ct_filename, const std::string &dst_pt_filename, bool use_shared_key=false)Parameters
src_ct_filenameconst std::string &- Absolute path to source file which contains locked data object
dst_pt_filenameconst std::string &- Absolute path to destination file which will contain unlocked plaintext data
use_shared_keybool defaultfalse- Determines whether one-way or shared key is used for locking. Default = false.
Throws
zkAppUtilsException- upon error
unlockData
function
void zkAppUtils::zkClass::unlockData(const byteArray &src_ct_data, const std::string &dst_pt_filename, bool use_shared_key=false)Parameters
src_ct_dataconst byteArray &- Unsigned byte container which holds locked data object
dst_pt_filenameconst std::string &- Absolute path to destination file which will contain unlocked plaintext data
use_shared_keybool defaultfalse- Determines whether one-way or shared key is used for locking. Default = false.
Throws
zkAppUtilsException- upon error
unlockData
function
zkAppUtils::byteArray * zkAppUtils::zkClass::unlockData(const std::string &src_ct_filename, bool use_shared_key=false)Parameters
src_ct_filenameconst std::string &- Absolute path to source file which contains locked data object
use_shared_keybool defaultfalse- Determines whether one-way or shared key is used for locking. Default = false.
Returns
- zkAppUtils::byteArray *
- Byte container with plaintext data
Throws
zkAppUtilsException- upon error
unlockData
function
zkAppUtils::byteArray * zkAppUtils::zkClass::unlockData(const byteArray &src_ct_bytes, bool use_shared_key=false)Parameters
src_ct_bytesconst byteArray &- Unsigned byte container which holds locked data object
use_shared_keybool defaultfalse- Determines whether one-way or shared key is used for locking. Default = false.
Returns
- zkAppUtils::byteArray *
- Byte container with plaintext data
Throws
zkAppUtilsException- upon error
ECDSA
genECDSASigFromDigest
function
zkAppUtils::byteArray * zkAppUtils::zkClass::genECDSASigFromDigest(byteArray &digest, int slot=0)Parameters
digestbyteArray &- Currently, this should be a SHA256 digest
slotint default0- The key slot to use for verification.
Returns
- zkAppUtils::byteArray *
- Byte container with binary signature
Throws
zkAppUtilsException- upon error
genECDSASigFromDigest
function
zkAppUtils::byteArray * zkAppUtils::zkClass::genECDSASigFromDigest(byteArray &digest, uint8_t &recovery_id, int slot=0)Parameters
digestbyteArray &- Currently, this should be a SHA256 digest
recovery_iduint8_t &- [Output]Returns recovery id value needed for ethereum key recovery.
slotint default0- The key slot to use for verification.
Returns
- zkAppUtils::byteArray *
- Byte container with binary signature
Throws
zkAppUtilsException- upon error
verifyECDSASigFromDigest
function
bool zkAppUtils::zkClass::verifyECDSASigFromDigest(byteArray &digest, byteArray &sig, int pub_key_slot=0, bool pub_key_is_foreign=false)Parameters
digestbyteArray &- Currently, this should be a SHA256 digest
sigbyteArray &- The signature to verify
pub_key_slotint default0- The key slot to use for verification.
pub_key_is_foreignbool defaultfalse- If false, the normal key store is referenced. Otherwise, the foreign public key store is referenced.
Returns
- bool
- true = signature verification passed, false = signature verification failed
ECDH and KDF
doRawECDH
function
zkAppUtils::byteArray * zkAppUtils::zkClass::doRawECDH(int slot, byteArray &peer_pubkey)Parameters
slotint- The key slot to use for the local key. If this parameter is -1, the ephemeral key is used.
peer_pubkeybyteArray &- The peer public key.
Returns
- zkAppUtils::byteArray *
- Byte container with pre master secret
doRawECDHWithIntPeerPubkey
function
zkAppUtils::byteArray * zkAppUtils::zkClass::doRawECDHWithIntPeerPubkey(int slot, int peer_pubkey_slot, bool peer_pubkey_slot_is_foreign)Parameters
slotint- The key slot to use for the local key. If this parameter is -1, the ephemeral key is used.
peer_pubkey_slotint- The peer public key slot where the peer public key is to be found.
peer_pubkey_slot_is_foreignbool- If true, the peer public key slot is found in the foreign public keyring.
Returns
- zkAppUtils::byteArray *
- Byte container with pre master secret
doECDHAndKDF
function
zkAppUtils::byteArray * zkAppUtils::zkClass::doECDHAndKDF(ZK_ECDH_KDF_TYPE kdf_type, int slot, byteArray &peer_pubkey, byteArray &salt, byteArray &info, int num_iterations, int derived_key_sz)Parameters
kdf_typeZK_ECDH_KDF_TYPE- The key derivation function to use (ZK_ECDH_KDF_TYPE).
slotint- The key slot to use for the local key. If this parameter is -1, the ephemeral key is used.
peer_pubkeybyteArray &- The peer public key.
saltbyteArray &- The salt to use for the selected KDF.
infobyteArray &- The info field to use for RFC 5869. Ignored for PBKDF2.
num_iterationsint- Number of iterations to carry out (PBKDF only)
derived_key_szint- The desired number of bytes to return for the KDF. For RFC 5869, this value must be less than 8160 bytes (SHA256) or 16320 (SHA512).
Returns
- zkAppUtils::byteArray *
- Byte container with pre master secret.
doECDHAndKDFWithIntPeerPubkey
function
zkAppUtils::byteArray * zkAppUtils::zkClass::doECDHAndKDFWithIntPeerPubkey(ZK_ECDH_KDF_TYPE kdf_type, int slot, int peer_pubkey_slot, bool peer_pubkey_slot_is_foreign, byteArray &salt, byteArray &info, int num_iterations, int derived_key_sz)Parameters
kdf_typeZK_ECDH_KDF_TYPE- The key derivation function to use (ZK_ECDH_KDF_TYPE).
slotint- The key slot to use for the local key. If this parameter is -1, the ephemeral key is used.
peer_pubkey_slotint- The peer public key slot where the peer public key is to be found.
peer_pubkey_slot_is_foreignbool- If true, the peer public key slot is found in the foreign public keyring.
saltbyteArray &- The salt to use for the selected KDF.
infobyteArray &- The info field to use for RFC 5869. Ignored for PBKDF2.
num_iterationsint- Number of iterations to carry out (PBKDF only)
derived_key_szint- The desired number of bytes to return for the KDF. For RFC 5869, this value must be less than 8160 bytes (SHA256) or 16320 (SHA512).
Returns
- zkAppUtils::byteArray *
- Byte container with pre master secret.
Key Management
saveECDSAPubKey2File
function
void zkAppUtils::zkClass::saveECDSAPubKey2File(std::string dst_filename, int slot=0)Parameters
dst_filenamestd::string- Absolute location where the PEM formatted file is to be stored
slotint default0- Reserved for future use
Throws
zkAppUtilsException- upon error
exportPubKey2File
function
void zkAppUtils::zkClass::exportPubKey2File(std::string dst_filename, int pubkey_slot=0, bool slot_is_foreign=false)Parameters
dst_filenamestd::string- Filename where PEM formatted public key is to be stored.
pubkey_slotint default0- The key slot to retrieve. Zymkey and HSM4 have slots 0, 1, and 2.
slot_is_foreignbool defaultfalse- If true, designates the pubkey slot to come from the foreign keystore. (Supported Devices: ZYMKEY5, HSM60, HSM64, HSM6, Secure Compute Module)
Throws
zkAppUtilsException- upon error
getECDSAPubKey
function
zkAppUtils::byteArray * zkAppUtils::zkClass::getECDSAPubKey(int slot=0)Parameters
slotint default0- Reserved for future use.
Returns
- zkAppUtils::byteArray *
- Byte container with binary public key
Throws
zkAppUtilsException- upon error
exportPubKey
function
zkAppUtils::byteArray * zkAppUtils::zkClass::exportPubKey(int pubkey_slot=0, bool slot_is_foreign=0)Parameters
pubkey_slotint default0- The key slot to retrieve. Zymkey and HSM4 have slots 0, 1, and 2.
slot_is_foreignbool default0- If true, designates the pubkey slot to come from the foreign keystore. (Supported Devices: ZYMKEY5, HSM60, HSM64, HSM6, Secure Compute Module)
Throws
zkAppUtilsException- upon error
getAllocSlotsList
function
intArray * zkAppUtils::zkClass::getAllocSlotsList(bool foreign_key_pool)Parameters
foreign_key_poolbool- (input) if true, retrieve allocation list of the foreign keys
Returns
- intArray *
- Array of the allocated keys.
storeForeignPubKey
function
int zkAppUtils::zkClass::storeForeignPubKey(ZK_EC_KEY_TYPE pk_type, byteArray &pk)Parameters
pk_typeZK_EC_KEY_TYPE- The type of the public key. {ZK_NISTP256, ZK_SECP256R1 = ZK_NISTP256, ZK_SECP256K1}
pkbyteArray &- Public key to store.
Returns
- int
- Allocated slot number in foreign key store, less than 0 for failure.
Throws
zkAppUtilsException- upon error
disablePubKeyExport
function
void zkAppUtils::zkClass::disablePubKeyExport(int pubkey_slot, bool slot_is_foreign=false)Parameters
pubkey_slotint- The key slot to disable pubkey export on.
slot_is_foreignbool defaultfalse- The slot parameter refers to a slot in the foreign keyring.
Throws
zkAppUtilsException- upon error
genKeyPair
function
int zkAppUtils::zkClass::genKeyPair(ZK_EC_KEY_TYPE type)Parameters
typeZK_EC_KEY_TYPE- The type of key to generate (ZK_EC_KEY_TYPE). {ZK_NISTP256, ZK_SECP256R1 = ZK_NISTP256, ZK_SECP256K1}
Returns
- int
- Allocated slot number if successful, less than 0 for failure.
Throws
zkAppUtilsException- upon error
genEphemeralKeyPair
function
void zkAppUtils::zkClass::genEphemeralKeyPair(ZK_EC_KEY_TYPE type)Parameters
typeZK_EC_KEY_TYPE- The type of key to generate (ZK_EC_KEY_TYPE). {ZK_NISTP256, ZK_SECP256R1 = ZK_NISTP256, ZK_SECP256K1}
Throws
zkAppUtilsException- upon error
removeKey
function
void zkAppUtils::zkClass::removeKey(int slot, bool slot_is_foreign=false)Parameters
slotint- The slot
slot_is_foreignbool defaultfalse- The slot parameter refers to a slot in the foreign keyring.
Throws
zkAppUtilsException- upon error
invalidateEphemeralKey
function
void zkAppUtils::zkClass::invalidateEphemeralKey()Throws
zkAppUtilsException- upon error
Digital Wallet (BIP32/39/44)
genWalletMasterSeed
function
int zkAppUtils::zkClass::genWalletMasterSeed(ZK_EC_KEY_TYPE type, std::string &wallet_name, const recoveryStrategyBaseType &recovery_strategy=recoveryStrategyBaseType(), const byteArray &master_generator_key=byteArray())Parameters
typeZK_EC_KEY_TYPE- The type of key to generate (ZK_EC_KEY_TYPE). {ZK_NISTP256, ZK_SECP256R1 = ZK_NISTP256, ZK_SECP256K1, ZK_ED25519, ZK_X25519}
wallet_namestd::string &- An ASCII string which contains the name of the wallet.
recovery_strategyconst recoveryStrategyBaseType & defaultrecoveryStrategyBaseType()- The recovery strategy object for returning BIP39 or SLIP39 (starts a SLIP39 session instead of a one shot). Also contains key variants and passphrases. Defaults to no recovery strategy.
master_generator_keyconst byteArray & defaultbyteArray()- The master generator key used to help generate the master seed (bip32). Defaults to empty string
Returns
- int
- The slot the master seed was allocated to.
genWalletMasterSeed
function
int zkAppUtils::zkClass::genWalletMasterSeed(ZK_EC_KEY_TYPE type, std::string &wallet_name, const recoveryStrategyBIP39 &recovery_strategy, std::string *mnemonic_str, const byteArray &master_generator_key=byteArray())Parameters
typeZK_EC_KEY_TYPE- The type of key to generate (ZK_EC_KEY_TYPE).
wallet_namestd::string &- An ASCII string which contains the name of the wallet.
recovery_strategyconst recoveryStrategyBIP39 &- The BIP39 passphrase and key variant.
mnemonic_strstd::string *- (output) The BIP39 mnemonic sentence for recovering the master seed.
master_generator_keyconst byteArray & defaultbyteArray()- The master generator key used to help generate the master seed (bip32). Defaults to empty string
Returns
- int
- The slot the master seed was allocated to.
genWalletMasterSeed
function
int zkAppUtils::zkClass::genWalletMasterSeed(ZK_EC_KEY_TYPE type, std::string &wallet_name, const recoveryStrategySLIP39 &recovery_strategy, const byteArray &master_generator_key=byteArray())Parameters
typeZK_EC_KEY_TYPE- The type of key to generate (ZK_EC_KEY_TYPE).
wallet_namestd::string &- An ASCII string which contains the name of the wallet.
recovery_strategyconst recoveryStrategySLIP39 &- The SLIP39 group layout, iteration exponent, passphrase and key variant.
master_generator_keyconst byteArray & defaultbyteArray()- The master generator key used to help generate the master seed (bip32). Defaults to empty string
Returns
- int
- 0 when the SLIP39 session is open.
Throws
zkAppUtilsException- upon error
setGenSLIP39GroupInfo
function
int zkAppUtils::zkClass::setGenSLIP39GroupInfo(int group_index, int member_count, int member_threshold)Parameters
group_indexint- The index of the group to generate shards from. Index starts at 0.
member_countint- The total amount of member shards in this group to generate.
member_thresholdint- The number of member shards needed to recreate this group in recovery.
Returns
- int
- 0 if successful on configuring the active group, less than 0 for failure.
addGenSLIP39Member
function
int zkAppUtils::zkClass::addGenSLIP39Member(std::string passphrase, std::string *mnemonic_str)Parameters
passphrasestd::string- Password for the shard. Can be empty string.
mnemonic_strstd::string *- (output) The mnemonic sentence of the shard.
Returns
- int
- 0 if successful on configuring the active group, less than 0 for failure.
cancelSLIP39Session
function
int zkAppUtils::zkClass::cancelSLIP39Session()Returns
- int
- 0 if successful on configuring the active group, less than 0 for failure.
genOverSightWallet
function
int zkAppUtils::zkClass::genOverSightWallet(ZK_EC_KEY_TYPE type, byteArray &public_key, byteArray &chain_code, std::string &node_address, std::string &wallet_name, std::string &variant)Parameters
typeZK_EC_KEY_TYPE- The type of key to generate (ZK_EC_KEY_TYPE). {ZK_NISTP256, ZK_SECP256R1 = ZK_NISTP256, ZK_SECP256K1, ZK_ED25519, ZK_X25519}
public_keybyteArray &- The public_key of the last hardened node of the address.
chain_codebyteArray &- The chain_code of the last hardened node of the address.
node_addressstd::string &- The node_address being derived from.
wallet_namestd::string &- An ASCII string which contains the name of the wallet.
variantstd::string &- The key type variant to generate. Currently only “cardano” for ed25519 is supported.
Returns
- int
- The slot the oversight wallet was allocated to.
genWalletChildKey
function
int zkAppUtils::zkClass::genWalletChildKey(int parent_key_slot, uint32_t index, bool is_hardened, bool return_chain_code, byteArray *chain_code)Parameters
parent_key_slotint- The parent key slot to base the child key derivation on.
indexuint32_t- The index of the child seed. This determines the node address as well as the outcome of the key generation.
is_hardenedbool- If true, a hardened key is generated.
return_chain_codebool- If true, exports the chain code. Must be exported from a hardened node.
chain_codebyteArray *- (output) Allocated chain_code if it was asked for.
Returns
- int
- Allocated slot number if successful, less than 0 for failure.
Throws
zkAppUtilsException- upon error
restoreWalletMasterSeedFromMnemonic
function
int zkAppUtils::zkClass::restoreWalletMasterSeedFromMnemonic(ZK_EC_KEY_TYPE type, std::string &wallet_name, byteArray &master_generator_key, recoveryStrategyBIP39 &recovery_strategy, std::string &mnemonic_str)Parameters
typeZK_EC_KEY_TYPE- The type of key to generate (ZK_KEY_TYPE). {ZK_NISTP256, ZK_SECP256R1 = ZK_NISTP256, ZK_SECP256K1}
wallet_namestd::string &- An ASCII string which contains the name of the wallet.
master_generator_keybyteArray &- The master generator key used to help generate the master seed.
recovery_strategyrecoveryStrategyBIP39 &- The recovery strategy used. Contains the passphrases and key variant to recover from.
mnemonic_strstd::string &- The mnemonic sentence to recover the master seed with. (Not used for SLIP39)
Returns
- int
- Allocated slot number if successful, less than 0 for failure.
Throws
zkAppUtilsException- upon error
restoreWalletMasterSeedFromMnemonic
function
int zkAppUtils::zkClass::restoreWalletMasterSeedFromMnemonic(ZK_EC_KEY_TYPE type, std::string &wallet_name, byteArray &master_generator_key, recoveryStrategySLIP39 &recovery_strategy)Parameters
typeZK_EC_KEY_TYPE- The type of key to restore (ZK_EC_KEY_TYPE).
wallet_namestd::string &- An ASCII string which contains the name of the wallet.
master_generator_keybyteArray &- The master generator key used to help generate the master seed.
recovery_strategyrecoveryStrategySLIP39 &- The SLIP39 passphrase and key variant to recover from.
Returns
- int
- The result of opening the session; less than 0 for failure.
addRestoreSLIP39Mnemonic
function
int zkAppUtils::zkClass::addRestoreSLIP39Mnemonic(std::string passphrase, std::string mnemonic_sentence)Parameters
passphrasestd::string- The passphrase that was attached to the shard.
mnemonic_sentencestd::string- (output) The twenty-four word sentence mnemonic shard.
Returns
- int
- allocated slot number when all shards required are fed in, less than 0 for no change.
getWalletNodeAddrFromKeySlot
function
int zkAppUtils::zkClass::getWalletNodeAddrFromKeySlot(int slot, std::string *out_node_addr, std::string *out_wallet_name=NULL)Parameters
slotint- (input) A key slot number that is part of a digital wallet.
out_node_addrstd::string *- (output) A pointer to a string which will contain the node address in ASCII.
out_wallet_namestd::string * defaultNULL- (output) A pointer to a string which will contain the wallet name in ASCII. If NULL, this parameter will not be retrieved.
Returns
- int
- The master seed key slot.
Throws
zkAppUtilsException- upon error
getWalletKeySlotFromNodeAddr
function
int zkAppUtils::zkClass::getWalletKeySlotFromNodeAddr(std::string &node_addr, std::string &wallet_name, int master_seed_slot)Parameters
node_addrstd::string &- (input) A pointer which contains the node address in ASCII.
wallet_namestd::string &- (input) A pointer which contains the wallet name in ASCII, used to identify the wallet identity. If desired, this parameter can be NULL and the master_seed_slot parameter can be specified instead.
master_seed_slotint- (input) The master seed slot. Can be used to specify the wallet identity instead of the wallet name.
Returns
- int
- The associated key slot.
Throws
zkAppUtilsException- upon error
LED Control
ledOff
function
void zkAppUtils::zkClass::ledOff()Throws
zkAppUtilsException- upon error
ledOn
function
void zkAppUtils::zkClass::ledOn()Throws
zkAppUtilsException- upon error
ledFlash
function
void zkAppUtils::zkClass::ledFlash(uint32_t on_ms, uint32_t off_ms=0, uint32_t num_flashes=0)Parameters
on_msuint32_t- Number of milliseconds that the LED will be on during a flash cycle
off_msuint32_t default0- Number of milliseconds that the LED will be off during a flash cycle
num_flashesuint32_t default0- Number of flash cycles to execute. 0 = infinite.
Throws
zkAppUtilsException- upon error
Administrative
setI2CAddr
function
void zkAppUtils::zkClass::setI2CAddr(int addr)Parameters
addrint- The i2c address to set. Upon successful change, the Zymkey will reset itself. However, if the address is the same as the current setting, the Zymkey will not reset. Valid address ranges are 0x30 - 0x37 and 0x60 - 0x67.
Throws
zkAppUtilsException- upon error
Time
getTime
function
uint32_t zkAppUtils::zkClass::getTime(bool precise_time=false)Parameters
precise_timebool defaultfalse- (input) If true, this API returns the time after the next second falls. This means that the caller could be blocked up to one second. If false, the API returns immediately with the current time reading.
Returns
- uint32_t
- The time in seconds from the epoch (Jan. 1, 1970).
Throws
zkAppUtilsException- upon error
Accelerometer
setTapSensitivity
function
void zkAppUtils::zkClass::setTapSensitivity(float pct, ZK_ACCEL_AXIS_TYPE axis=ZK_ACCEL_AXIS_ALL)Parameters
pctfloat- Sensitivity expressed in percentage. 0% = off, 100% = maximum.
axisZK_ACCEL_AXIS_TYPE defaultZK_ACCEL_AXIS_ALL- X, Y, Z or all (default).
Throws
zkAppUtilsException- upon error
waitForTap
function
void zkAppUtils::zkClass::waitForTap(uint32_t timeout_ms)Parameters
timeout_msuint32_t- (input) The maximum amount of time in milliseconds to wait for a tap event to arrive.
Throws
zkAppUtilsTimeoutException- upon timeout or zkAppUtilsException upon other errors
getAccelerometerData
function
void zkAppUtils::zkClass::getAccelerometerData(accelData &accel_data)Parameters
accel_dataaccelData &- (output) The current accelerometer data and tap information
Throws
zkAppUtilsException- upon error
Binding Management
lockBinding
function
void zkAppUtils::zkClass::lockBinding()Throws
zkAppUtilsException- upon error
getCurrentBindingInfo
function
void zkAppUtils::zkClass::getCurrentBindingInfo(bool &binding_is_locked, bool &is_bound)Parameters
binding_is_lockedbool &- (output) Binary value which expresses the current binding lock state.
is_boundbool &- (output) Binary value which expresses the current bind state.
Throws
zkAppUtilsException- upon error
Perimeter Detect
setPerimeterEventAction
function
void zkAppUtils::zkClass::setPerimeterEventAction(int channel, uint32_t action_flags)This function specifies the action to take when a perimeter breach event occurs. The possible actions are any combination of:
- Notify host
- Zymkey self-destruct
Parameters
channelint- (input) The channel (0 or 1) that the action flags will be applied to.
action_flagsuint32_t(input) The actions to apply to the perimeter event channel:
- Notify (ZK_PERIMETER_EVENT_ACTION_NOTIFY)
- Self-destruct (ZK_PERIMETER_EVENT_ACTION_SELF_DESTRUCT)
Throws
zkAppUtilsException- upon error
setDigitalPerimeterDetectLPPeriod
function
void zkAppUtils::zkClass::setDigitalPerimeterDetectLPPeriod(int lp_period)Parameters
lp_periodint- (input) low power period in microseconds
Returns
- void
- void.
Throws
zkAppUtilsException- upon error
setDigitalPerimeterDetectLPMaxBits
function
void zkAppUtils::zkClass::setDigitalPerimeterDetectLPMaxBits(int max_num_bits)Parameters
max_num_bitsint- (input) max number of bits
Returns
- void
- void.
Throws
zkAppUtilsException- upon error
setDigitalPerimeterDetectDelays
function
void zkAppUtils::zkClass::setDigitalPerimeterDetectDelays(int min_delay_ns, int max_delay_ns)Parameters
min_delay_nsint- (input) minimum delay in nanoseconds
max_delay_nsint- (input) maximum delay in nanoseconds
Returns
- void
- void.
Throws
zkAppUtilsException- upon error
waitForPerimeterEvent
function
void zkAppUtils::zkClass::waitForPerimeterEvent(uint32_t timeout_ms)Parameters
timeout_msuint32_t- (input) The maximum amount of time in milliseconds to wait for a perimeter event to arrive.
Throws
zkAppUtilsException- upon error
getPerimeterDetectInfo
function
void zkAppUtils::zkClass::getPerimeterDetectInfo(uint32_t **timestamp_sec, int &num_timestamps)Parameters
timestamp_secuint32_t **- (output) The timestamps for when any events occurred. The index in this array corresponds to the channel number used by zkSetPerimeterEventAction. A 0 value means no breach has occurred on this channel. This array is allocated by this routine and so it must be freed by the caller.
num_timestampsint &- (output) The number of timestamps in the returned array
Throws
zkAppUtilsException- upon error
clearPerimeterDetectEvents
function
void zkAppUtils::zkClass::clearPerimeterDetectEvents()Throws
zkAppUtilsException- upon error
getModelNumberString
function
std::string * zkAppUtils::zkClass::getModelNumberString()Returns
- std::string *
- A pointer to a string containing the Zymkey model number.
Throws
zkAppUtilsException- upon error
getFirmwareVersionString
function
std::string * zkAppUtils::zkClass::getFirmwareVersionString()Returns
- std::string *
- A pointer to a string containing the Zymkey firmware version.
Throws
zkAppUtilsException- upon error
getSerialNumberString
function
std::string * zkAppUtils::zkClass::getSerialNumberString()Returns
- std::string *
- A pointer to a string containing the Zymkey serial number.
Throws
zkAppUtilsException- upon error
Module Info
getCPUTemp
function
float zkAppUtils::zkClass::getCPUTemp()Returns
- float
- The CPU temp as a float.
Throws
zkAppUtilsException- upon error
getAUXTemp
function
float zkAppUtils::zkClass::getAUXTemp(int index=0)Parameters
indexint default0
Returns
- float
- The CPU temp as a float.
Throws
zkAppUtilsException- upon error
getRTCDrift
function
float zkAppUtils::zkClass::getRTCDrift()Returns
- float
- The RTC drift as a float.
Throws
zkAppUtilsException- upon error
getBatteryVoltage
function
float zkAppUtils::zkClass::getBatteryVoltage()Returns
- float
- the battery voltage as a float.
Throws
zkAppUtilsException- upon error
Battery Voltage Monitor
setBatteryVoltageAction
function
void zkAppUtils::zkClass::setBatteryVoltageAction(ZK_THRESHOLD_ACTION_TYPE action)This function specifies the action to take when the battery voltage falls below the threshold set by zkSetBatteryVoltageThreshold. If this function is never called, do nothing is default. There are three actions:
- Do nothing
- Go to sleep until battery is replaced
- Self-destruct
Parameters
actionZK_THRESHOLD_ACTION_TYPE(input) The action to apply, specify one of the ZK_THRESHOLD_ACTION_TYPE:
- Do nothing (ZK_ACTION_NONE)
- Sleep (ZK_ACTION_SLEEP)
- Self-destruct (ZK_ACTION_SELF_DESTRUCT)
Throws
zkAppUtilsException- upon error
setBatteryVoltageThreshold
function
void zkAppUtils::zkClass::setBatteryVoltageThreshold(float threshold)Parameters
thresholdfloat- (input) The threshold in Volts.
Throws
zkAppUtilsException- upon error
CPU Temperature Monitor
setCPUTempAction
function
void zkAppUtils::zkClass::setCPUTempAction(ZK_THRESHOLD_ACTION_TYPE action)This function specifies the action to take when the HSM CPU temperature falls below the threshold set by zkSetCPULowTempThreshold, or rises above the threshold set by zkSetCPUHighTempThreshold. There are two actions to apply:
- Do nothing
- Self-destruct
Parameters
actionZK_THRESHOLD_ACTION_TYPE(input) The action to apply, used it’s named constant from ZK_THRESHOLD_ACTION_TYPE:
- Do nothing (ZK_ACTION_NONE)
- Self-destruct (ZK_ACTION_SELF_DESTRUCT)
Throws
zkAppUtilsException- upon error
setCPULowTempThreshold
function
void zkAppUtils::zkClass::setCPULowTempThreshold(float threshold)Parameters
thresholdfloat- (input) The threshold in celsius.
Throws
zkAppUtilsException- upon error
setCPUHighTempThreshold
function
void zkAppUtils::zkClass::setCPUHighTempThreshold(float threshold)Parameters
thresholdfloat- (input) The threshold in celsius.
Returns
- void
- 0 for success, less than 0 for failure.
setSupervisedBootPolicy
function
void zkAppUtils::zkClass::setSupervisedBootPolicy(int policy_id)Parameters
policy_idint(input) The actions to apply to the Supervised boot process:
- 0 Do Nothing (ZK_SUPBOOT_FAIL_NO_ACTION)
- 1 Self-Destruct (ZK_SUPBOOT_FAIL_DESTROY)
- 2 Hold Chip in Reset (ZK_SUPBOOT_FAIL_HOLD_RESET)
Returns
- void
- 0 for success, less than 0 for failure.
addOrUpdateSupervisedBootFile
function
void zkAppUtils::zkClass::addOrUpdateSupervisedBootFile(std::string file_path, int slot=15)Parameters
file_pathstd::string- (input) The file to be signed and checked by Supervised boot.
slotint default15- (input) The slot to sign the file with. Defaults to 15, if no slot 15, defaults to 0.
Returns
- void
- 0 for success, less than 0 for failure.
removeSupervisedBootFile
function
void zkAppUtils::zkClass::removeSupervisedBootFile(std::string file_path)Parameters
file_pathstd::string- (input) The file to be removed from the Supervised boot manifest.
Returns
- void
- 0 for success, less than 0 for failure.
getSupervisedBootFileManifest
function
std::string * zkAppUtils::zkClass::getSupervisedBootFileManifest()Returns
- std::string *
- The file manifest that is checked by Supervised boot.
Public Functions
enableSelfRestart
function
void zkAppUtils::zkClass::enableSelfRestart(bool enabled, int waitSec, int maxNumRestart)Parameters
enabledbool- (input) Enable/disable.
waitSecint- (input) Time in seconds to wait before attempting restart.
maxNumRestartint- (input) Maximum number of restarts to attempt.
Throws
commonException- upon error.