@siacentral/ledgerjs-sia
Version:
Ledger hardware wallet Siacoin API.
105 lines • 4.78 kB
TypeScript
import type Transport from "@ledgerhq/hw-transport";
import { Buffer } from 'buffer';
type TransportFactory = () => Promise<Transport>;
interface VerifyResponse {
address: string;
publicKey: string;
}
/**
* Sia
*
* @example
* import Sia from '@siacentral/ledgerjs-sia';
* const sia = new Sia(transport)
*/
export default class Sia {
transport: Transport;
constructor(transport: Transport, scrambleKey?: string);
/**
* open connects a transport, ensures the Sia app is running, and returns a
* ready Sia instance. If the app is not already open it is launched from the
* dashboard; the device disconnects and reconnects when an app opens, so the
* transport is recreated via the provided factory until the app is ready.
* @param createTransport {TransportFactory} creates a transport, e.g. () => TransportWebHID.create()
* @param scrambleKey {string} the scramble key for the Sia app
* @returns {Sia} a Sia instance bound to a transport with the Sia app open
*/
static open(createTransport: TransportFactory, scrambleKey?: string): Promise<Sia>;
/**
* connectWebHID connects to a Ledger over WebHID (USB), launching the Sia
* app from the dashboard if it isn't already open, and returns a ready Sia
* instance.
* @param scrambleKey {string} the scramble key for the Sia app
* @returns {Sia} a Sia instance with the Sia app open
*/
static connectWebHID(scrambleKey?: string): Promise<Sia>;
/**
* connectBLE connects to a Ledger over Web Bluetooth, launching the Sia app
* from the dashboard if it isn't already open, and returns a ready Sia
* instance.
* @param scrambleKey {string} the scramble key for the Sia app
* @returns {Sia} a Sia instance with the Sia app open
*/
static connectBLE(scrambleKey?: string): Promise<Sia>;
/**
* supportedTransports returns the transport methods available in the current
* environment. Web Bluetooth is excluded on Brave, which does not reliably
* support it.
* @returns {Array<'hid' | 'ble'>} the supported transport methods
*/
static supportedTransports(): Promise<Array<'hid' | 'ble'>>;
/**
* exchangeTxnHash sends an encoded transaction to the device in 255-byte
* chunks and returns the response with the trailing status word stripped.
*/
private exchangeTxnHash;
/**
* openApp launches the Sia app from the device's dashboard. The device
* disconnects and reconnects when the app opens, so the transport must be
* re-created before issuing further commands.
*/
openApp(): Promise<void>;
/**
* getVersion returns the version of the Sia app
*
* @returns {string} the current version of the Sia app.
*/
getVersion(): Promise<string>;
/**
* getPublicKey returns the public key and standard Sia address for
* the provided public key index. The user will be asked to verify the
* public key on the display. A standard address is defined as an address
* having 1 public key, requiring 1 signature, and no timelock.
* @param index {number} the index of the public key
* @returns {VerifyResponse} the public key and standard address
*/
getPublicKey(index: number): Promise<VerifyResponse>;
/**
* getAddress returns the public key and standard Sia address for
* the provided public key index. The user will be asked to verify the
* address on the display. A standard address is defined as an address
* having 1 public key, requiring 1 signature, and no timelock.
* @param index {number} the index of the public key
* @returns {VerifyResponse} the public key and standard address
*/
getAddress(index: number): Promise<VerifyResponse>;
/**
* signV2Transaction signs the v2 transaction with the provided key
* @param encodedTxn {Buffer} a sia encoded (V2TransactionSemantics) v2 transaction
* @param sigIndex {number} the index of the signature to sign
* @param keyIndex {number} the index of the key to sign with
* @param changeIndex {number} the index of the key used for the change output
* @returns {string} the hex encoded signature
*/
signV2Transaction(encodedTxn: Buffer, sigIndex: number, keyIndex: number, changeIndex: number): Promise<string>;
/**
* signHash signs a 32-byte hash with the private key at the provided index
* @param sigHash {Buffer} the 32-byte hash to sign
* @param keyIndex {number} the index of the key to sign with
* @returns {string} the hex encoded signature
*/
signHash(sigHash: Buffer, keyIndex: number): Promise<string>;
close(): Promise<void>;
}
export {};
//# sourceMappingURL=sia.d.ts.map