nem-trezor is a typescript / node.js npm module that adds trezor functionalities to nem-library.
For the module to work you will need a trezor device connected to the system and trezor trezor-bridge should be running (or the chrome extension).
The library only works in a browser environment because of the way trezor is implemented, if executed in a node script environment it will throw an exception.
to install the npm module on your typescript or node project run:
npm install nem-trezor --save
the module is made to work together with nem-library, so you should install that too:
npm install firstname.lastname@example.org --save
it is important that 1.0.5 is installed since it needs to be the same version than the one in nem-trezor
The module exports a class TrezorAccount, that is made to be as similar to the Account class in nem-library as possible. It allows to use trezor accounts to sign transactions. Unencrypting messages is not possible right now but may be in the future. Also the way that encrypted messages are sent is different from the way it is done in nem-library, since trezor encrypts messages at the same time that it signs and serializes the transaction.
Here are some examples of the basic usage of the module:
Sending a Transfer Transaction
;;// 0. This function will bootstrap both the internal nem-library for nem-trezor and the local one// if the local version of nem-library and the one in nem-trezor don't match then this will give problemsNEMLibrary.bootstrapNetworkTypes.TEST_NET;;// 1. Get the first account of the trezor device. Change the number for different accounts. This will prompt a confirmation on the device.TrezorAccount.getAccount0.flatMap// Announce the transaction to the network.flatMaptransactionHttp.announceTransactionsignedTransaction// Print the response.subscribeconsole.logresponse,console.errorerr;
Sending an encrypted message
For sending an encrypted message (only valid for transfer transactions), we will pass the public key of the receiver to the signTransaction function:
// steps 1 and 2 are the same as before// 3. Sign, serialize, and encrypt the transaction from the trezor device. This will prompt for confirmation on the device.account.signTransactiontrans, "<receiver_public_key>"// Announce the transaction to the network.flatMaptransactionHttp.announceTransactionsignedTransaction// Print the response.subscribeconsole.logresponse,console.errorerr;