UNPKG

@ledgerhq/hw-app-str

Version:
175 lines (109 loc) 6.42 kB
<img src="https://user-images.githubusercontent.com/4631227/191834116-59cf590e-25cc-4956-ae5c-812ea464f324.png" height="100" /> [GitHub](https://github.com/LedgerHQ/ledger-live/), [Ledger Devs Discord](https://developers.ledger.com/discord-pro), [Developer Portal](https://developers.ledger.com/) ## @ledgerhq/hw-app-str Ledger Hardware Wallet Stellar JavaScript bindings. *** ## Are you adding Ledger support to your software wallet? You may be using this package to communicate with the Stellar Nano App. For a smooth and quick integration: * See the developers’ documentation on the [Developer Portal](https://developers.ledger.com/docs/transport/overview/) and * Go on [Discord](https://developers.ledger.com/discord-pro/) to chat with developer support and the developer community. *** ## Errors handling All functions may throw an error, it's important to handle the errors properly. We have written corresponding classes for exceptions that developers should actively handle, you can find them in the [API](#api) section. *** ## API <!-- Generated by documentation.js. Update this documentation by updating the source code. --> #### Table of Contents * [StellarHashSigningNotEnabledError](#stellarhashsigningnotenablederror) * [StellarDataParsingFailedError](#stellardataparsingfailederror) * [StellarUserRefusedError](#stellaruserrefusederror) * [StellarDataTooLargeError](#stellardatatoolargeerror) * [Str](#str) * [Parameters](#parameters) * [Examples](#examples) * [getAppConfiguration](#getappconfiguration) * [Examples](#examples-1) * [getPublicKey](#getpublickey) * [Parameters](#parameters-1) * [Examples](#examples-2) * [signTransaction](#signtransaction) * [Parameters](#parameters-2) * [Examples](#examples-3) * [signSorobanAuthorization](#signsorobanauthorization) * [Parameters](#parameters-3) * [Examples](#examples-4) * [signHash](#signhash) * [Parameters](#parameters-4) * [Examples](#examples-5) ### StellarHashSigningNotEnabledError Error thrown when hash signing is not enabled on the device. ### StellarDataParsingFailedError Error thrown when data parsing fails. For example, when parsing the transaction fails, this error is thrown. ### StellarUserRefusedError Error thrown when the user refuses the request on the device. ### StellarDataTooLargeError Error thrown when the data is too large to be processed by the device. ### Str Stellar API #### Parameters * `transport` **Transport** a transport for sending commands to a device * `scrambleKey` a scramble key (optional, default `"l0v"`) #### Examples ```javascript import Str from "@ledgerhq/hw-app-str"; const str = new Str(transport) ``` #### getAppConfiguration Get Stellar application configuration. ##### Examples ```javascript str.getAppConfiguration().then(o => o.version) ``` Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{version: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), hashSigningEnabled: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean), maxDataSize: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?}>** an object with the application configuration, including the version, whether hash signing is enabled, and the maximum data size in bytes that the device can sign. #### getPublicKey Get Stellar raw public key for a given BIP 32 path. ##### Parameters * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format * `display` if true, the device will ask the user to confirm the address on the device, if false, it will return the raw public key directly (optional, default `false`) ##### Examples ```javascript str.getPublicKey("44'/148'/0'").then(o => o.rawPublicKey) ``` Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{rawPublicKey: [Buffer](https://nodejs.org/api/buffer.html)}>** an object with the raw ed25519 public key. If you want to convert it to string, you can use [StrKey.encodeEd25519PublicKey](https://stellar.github.io/js-stellar-base/StrKey.html#.encodeEd25519PublicKey) #### signTransaction Sign a Stellar transaction. ##### Parameters * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format * `transaction` **[Buffer](https://nodejs.org/api/buffer.html)** [signature base](https://stellar.github.io/js-stellar-base/Transaction.html#signatureBase) of the transaction to sign ##### Examples ```javascript str.signTransaction("44'/148'/0'", signatureBase).then(o => o.signature) ``` Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{signature: [Buffer](https://nodejs.org/api/buffer.html)}>** an object with the signature #### signSorobanAuthorization Sign a Stellar Soroban authorization. ##### Parameters * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format * `hashIdPreimage` **[Buffer](https://nodejs.org/api/buffer.html)** the [Soroban authorization hashIdPreimage](https://github.com/stellar/stellar-xdr/blob/1a04392432dacc0092caaeae22a600ea1af3c6a5/Stellar-transaction.x#L702-L709) to sign ##### Examples ```javascript str.signSorobanAuthorization("44'/148'/0'", hashIdPreimage).then(o => o.signature) ``` Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{signature: [Buffer](https://nodejs.org/api/buffer.html)}>** an object with the signature #### signHash Sign a hash. ##### Parameters * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format * `hash` **[Buffer](https://nodejs.org/api/buffer.html)** the hash to sign ##### Examples ```javascript str.signHash("44'/148'/0'", hash).then(o => o.signature) ``` Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{signature: [Buffer](https://nodejs.org/api/buffer.html)}>** an object with the signature