trezor-wallet / Readme • Contributing • Changelog
Easy Trezor wallet support for Stellar applications.
(Weekly updates: Reddit, Twitter, Keybase, Telegram)
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.
- 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 install cosmic-plus-trezor-wallet
In your HTML page:
<script src="./bower_components/cosmic-plus-trezor-wallet/trezor-wallet.js"></script>
In your HTML page:
<script src="https://cdn.cosmic.plus/trezor-wallet@1.x"></script>
Note: For production release it is advised to serve your copy of the library.
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.
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'
).
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
Close the connection with the Trezor device, or stop waiting for one in case a connection has not been established yet.
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.
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.
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 numberlength
: Number (default: 1) - Number of account to be listed.
Function to execute on each connection.
Function to execute on each disconnection.
PublicKey of the connected account.
Derivation path of the connected account. (default: m/44'/148'/0'
)
Organization: Cosmic.plus | @GitHub | @NPM