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

@cosmic-plus/trezor-wallet

v1.7.0

Published

Easy Trezor wallet support for Stellar applications

Downloads

22

Readme

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)

// Extra: Event handlers
trezorWallet.onConnect = connectionHandler
trezorWallet.onDisconnect = disconnectionHandler

This library is browser-only.

Known limitations

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 manageBuyOffer operation,
  • The pathPaymentStrictSend operation.

If you encounter an unexpected error, please fill an issue.

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>

CDN

In your HTML page:

<script src="https://cdn.cosmic.plus/[email protected]"></script>

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

Usage

Functions

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
Parameters:

  • 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(account) 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 numbers accounts, account starts at 1 (derivation path: m/44'/148'/0').

Parameters:

  • account: Number | String (default: 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.

Parameters:

  • 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.

Parameters:

  • horizon: String | Server (default: https://horizon.stellar.org) - 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").

Parameters:

  • params: Object - Optional parameters.
    • horizon: String | Server (default: https://horizon.stellar.org) - The Horizon server where to check for account existence. It can be either an URL or a StellarSdk.Server object.
    • attempts: Number (default: 3) - The number of empty accounts before scanning stops.
    • includeMerged: Boolean (default: 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.

Parameters:

  • start: Number (default: 1) - Starting account number
  • length: Number (default: 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