Skip to content
Easy Trezor wallet support for Stellar applications (build)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitattributes
AUTHORS.md
CHANGELOG.md
CONTRIBUTING.md
LICENSE.md
README.md
bower.json
package-lock.json
trezor-wallet.js
trezor-wallet.js.map

README.md

trezor-wallet / ReadmeContributingChangelog

Readme

Licence Dependencies Vulnerabilities Bundle Downloads

Easy Trezor wallet support for Stellar applications.

(Weekly updates: Reddit, Twitter, Keybase, Telegram)

Introduction

This library is a convenient wrapper around the official TrezorConnect library.

It provides a way to support Trezor devices with a few one-liners:

// Step 1: Connect
await trezorWallet.connect()

// Step 2: Get public key
const pubkey = trezorWallet.publicKey

// Step 3: Sign
await trezorWallet.sign(transaction)

This library is browser-only.

Beta Release

This is a beta release that is made public for testing purposes. While the library is stable & secure, several issues are still being worked out with Trezor teams.

A few operations & parameters are not supported yet. An explicit error message will get thrown if you try to sign a transaction including them:

  • Binary text memo containing NULL characters,
  • The manageData operation,
  • The manageBuyOffer operation

If you encounter an unexpected error, please play the game and fill an issue.

The public release will possibly contain one or more breaking changes. Please check the changelog before upgrading.

Installation

NPM/Yarn

  • NPM: npm install @cosmic-plus/trezor-wallet
  • Yarn: yarn add @cosmic-plus/trezor-wallet

In your script: const trezorWallet = require("@cosmic-plus/trezor-wallet")

Bower

bower install cosmic-plus-trezor-wallet

In your HTML page:

<script src="./bower_components/cosmic-plus-trezor-wallet/trezor-wallet.js"></script>

HTML

In your HTML page:

<script src="https://cdn.cosmic.plus/trezor-wallet@0.x"></script>

Note: For production release it is advised to serve your copy of the library.

Usage

Methods

trezorWallet.register(appUrl, email)

Registers yourself in the Trezor Connect Manifest. This provides them the ability to reach you in case of any required maintenance.

This subscription is mandatory and the library register the Cosmic.plus contact by default.

See: Trezor Connect Manifest

Param Type Description
appUrl String Application URL.
email String Developer email.

await trezorWallet.connect([account])

Waits for a connection with a Trezor wallet. If account is not provided, account 1 is used. The library will stop listening for a connection if trezorWallet.disconnect() is called.

Once the connection is established, you can use await trezorWallet.connect() again at any time to ensure the device is still connected.

When switching to another account, you can await trezorWallet.connect(new_account) without prior disconnection.

Note: To stay consistent with the way Trezor number accounts, account starts at 1 (derivation path: m/44'/148'/0').

Param Type Default Description
[account] Number | String 1 Either an account number (starts at 1) or a derivation path (e.g: m/44'/148'/0').

await trezorWallet.sign(transaction)

Prompts the user to accept transaction using the connected account of their Trezor device.

If the user accepts, adds the signature to transaction. Else, throws an error.

Param Type Description
transaction Transaction A StellarSdk Transaction

trezorWallet.disconnect()

Close the connection with the Trezor device, or stop waiting for one in case a connection has not been established yet.

trezorWallet.newAccount([horizon])

Connects the first unused account.

Note: merged accounts are considered as used.

Param Type Default Description
[horizon] String | Server &quot;https://horizon.stellar.org&quot; The Horizon server where to check for account existence. It can be either an URL or a StellarSdk.Server object.

trezorWallet.scan([params]) ⇒ Array

Scans the Trezor device for accounts that exist on params.horizon. The scanning stops after encountering params.attempts unused accounts.

Merged accounts are considered as existing accounts and will reset the params.attempts counter when encountered.

Returns an Array of Objects containing account number, publicKey, path, and state (either "open" or "merged").

Param Type Default Description
[params] Object Optional parameters.
[params.horizon] String | Server &quot;https://horizon.stellar.org&quot; The Horizon server where to check for account existence. It can be either an URL or a StellarSdk.Server object.
[params.attempts] Number 3 The number of empty accounts before scanning stops.
[params.includeMerged] Boolean false List merged accounts as well.

trezorWallet.getPublicKeys([start], [length]) ⇒ Array

Request multiple public keys from the Trezor device. The request will return length accounts, starting by start (minimum 1).

Returns an Array of Objects with properties account, publicKey, and path.

Param Type Default Description
[start] Number 1 Starting account number
[length] Number 1 Number of account to be listed.

Events

trezorWallet.onConnect : function

Function to execute on each connection.

trezorWallet.onDisconnect : function

Function to execute on each disconnection.

Members

trezorWallet.publicKey : String

PublicKey of the connected account.

trezorWallet.path : String

Derivation path of the connected account. (default: m/44'/148'/0')

Links

Organization: Cosmic.plus | @GitHub | @NPM

Follow: Reddit | Twitter | Medium | Codepen

Talk: Telegram | Keybase

You can’t perform that action at this time.