UNPKG

@ledgerhq/hw-app-solana

Version:
169 lines (104 loc) 6.23 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-solana Ledger Hardware Wallet Solana JavaScript bindings. *** ## Are you adding Ledger support to your software wallet? You may be using this package to communicate with the Solana 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. *** ## Notes To run `speculos-smoke` test make sure [Speculos](https://github.com/LedgerHQ/speculos) running (apdu port 9999 and api rest endpoint <http://0.0.0.0:5000>) with [Solana app](https://github.com/LedgerHQ/app-solana) installed on it. Then run the command from root workspace: ```bash $ yarn run ts-node packages/hw-app-solana/tests/speculos-smoke.ts ``` ## Troubleshooting If ledger returns error `6808` - enable blind signature in settings (not needed for unit testing). ## API <!-- Generated by documentation.js. Update this documentation by updating the source code. --> #### Table of Contents * [Solana](#solana) * [Parameters](#parameters) * [Examples](#examples) * [getAddress](#getaddress) * [Parameters](#parameters-1) * [Examples](#examples-1) * [provideTrustedDynamicDescriptor](#providetrusteddynamicdescriptor) * [Parameters](#parameters-2) * [signTransaction](#signtransaction) * [Parameters](#parameters-3) * [Examples](#examples-2) * [signOffchainMessage](#signoffchainmessage) * [Parameters](#parameters-4) * [Examples](#examples-3) * [getAppConfiguration](#getappconfiguration) * [Examples](#examples-4) * [getChallenge](#getchallenge) * [provideTrustedName](#providetrustedname) * [Parameters](#parameters-5) ### Solana Solana API #### Parameters * `transport` **Transport** a transport for sending commands to a device * `scrambleKey` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a scramble key (optional, default `"solana_default_scramble_key"`) #### Examples ```javascript import Solana from "@ledgerhq/hw-app-solana"; const solana = new Solana(transport); ``` #### getAddress Get Solana address (public key) for a BIP32 path. Because Solana uses Ed25519 keypairs, as per SLIP-0010 all derivation-path indexes will be promoted to hardened indexes. ##### Parameters * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a BIP32 path * `display` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** flag to show display (optional, default `false`) ##### Examples ```javascript solana.getAddress("44'/501'/0'").then(r => r.address) ``` Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{address: [Buffer](https://nodejs.org/api/buffer.html)}>** an object with the address field #### provideTrustedDynamicDescriptor Provides trusted dynamic and signed coin metadata ##### Parameters * `data` **DescriptorInput** An object containing the descriptor and its signature from the CAL Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>**&#x20; #### signTransaction Sign a Solana transaction. ##### Parameters * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a BIP32 path * `txBuffer` **[Buffer](https://nodejs.org/api/buffer.html)** serialized transaction ##### Examples ```javascript solana.signTransaction("44'/501'/0'", txBuffer).then(r => r.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 field #### signOffchainMessage Sign a Solana off-chain message. ##### Parameters * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a BIP32 path * `msgBuffer` **[Buffer](https://nodejs.org/api/buffer.html)** serialized off-chain message ##### Examples ```javascript solana.signOffchainMessage("44'/501'/0'", msgBuffer).then(r => r.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 field #### getAppConfiguration Get application configuration. ##### Examples ```javascript solana.getAppConfiguration().then(r => r.version) ``` Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<AppConfig>** application config object #### getChallenge Method returning a 4 bytes TLV challenge as an hex string Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**&#x20; #### provideTrustedName Provides a trusted name to be displayed during transactions in place of the token address it is associated to. It shall be run just before a transaction involving the associated address that would be displayed on the device. ##### Parameters * `data` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a stringified buffer of some TLV encoded data to represent the trusted name Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>** a boolean