npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nem-trezor

v1.1.0

Published

nem trezor library

Downloads

28

Readme

Nem Trezor

npm version License: MIT

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.

  1. Installation
  2. Usage

Installation

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 [email protected] --save

it is important that 1.0.5 is installed since it needs to be the same version than the one in nem-trezor

Usage

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

import { NEMLibrary, NetworkTypes, Transaction, TransferTransaction,
    TimeWindow, XEM, Address, TransactionHttp, PlainMessage} from 'nem-library';
import { TrezorAccount } from 'nem-trezor';

// 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 problems
NEMLibrary.bootstrap(NetworkTypes.TEST_NET);
const transactionHttp = new TransactionHttp();

// 1. Get the first account of the trezor device. Change the number for different accounts. This will prompt a confirmation on the device.
TrezorAccount.getAccount(0)
  .flatMap((account) => {
    console.log(account);
    // 2. Create Transaction object
    // For more information on Transaction types and their usage check out the nem-library documentation
    const trans: Transaction = TransferTransaction.create(
      TimeWindow.createWithDeadline(),
      new Address("TBEJ3L4MKNRZRY7PR5CO35746QRCR32AHE6UMTQN"),
      new XEM(10),
      PlainMessage.create("hello from trezor"),
    );
    // 3. Sign and serialize the transaction from the trezor device. This will prompt for confirmation on the device.
    return account.signTransaction(trans);
  })
  // Announce the transaction to the network
  .flatMap((signedTransaction) => transactionHttp.announceTransaction(signedTransaction))
  // Print the response
  .subscribe((response) => console.log(response), (err) => console.error(err));

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.signTransaction(trans, "<receiver_public_key>")
   // Announce the transaction to the network
  .flatMap((signedTransaction) => transactionHttp.announceTransaction(signedTransaction))
  // Print the response
  .subscribe((response) => console.log(response), (err) => console.error(err));