Crate ehsm

Source
Expand description

§ehsm

ehsm is a rust integration library to use the non-PKCS11 functions from the ehsm shared library. Use this crate in conjunction with the pkcs11 crate.

§Examples

§Importing a key from the binary seed

    use ehsm::*;
    let lib_name = ehsm_library_name();
    let ehsm = EHSMContext::new(lib_name.as_path())
        .expect("Failed to load ehsm library functions");
    let session = get_logged_in_session(&ctx, SU_PIN,0,None,None)
        .expect("Failed to get session");
    ehsm.import_bitcoin_key(session,
                            &hex::decode("000102030405060708090a0b0c0d0e0f").unwrap())
        .expect("Failed to import key");

§Retrieving a public key at the specified BIP32 path

// empty index vector is the root key or "m"
// for "m/0", just add 0 to indexes, i.e. indexes.push(0) etc. to build the BIP32 path
let mut indexes: Vec<u32> = Vec::new();
// main net
let net: u32 = 0x0488B21Eu32;
let xpub = ehsm.get_bitcoin_pub(session, &indexes, net).expect("Failed to get btc pub");

§Signing a hash with the private key at the specified BIP32 path

// empty index vector is the root key or "m"
// for "m/0", just add 0 to indexes, i.e. indexes.push(0) etc. to build the BIP32 path
let mut indexes: Vec<u32> = Vec::new();
let sig = ehsm.sign_bitcoin_hash(session,&vec![0;32],&indexes).expect("Failed to sign hash");

Structs§

EHSMContext

Constants§

BTC_KEY_NOT_FOUND

Functions§

ehsm_library_name
A utility function to retrieve the library name from the EHSM_LIBRARY environment variable or default path
get_logged_in_session
A utility function to open a session and log-in

Type Aliases§

u32GetBitcoinPub
u32HasBitcoinKey
u32ImportBitcoinKey
u32SignBitcoinHash