@mina-wallet-adapter/mina-ledger-js
Version:
JS API for Mina App (Ledger Nano S/X)
104 lines (100 loc) • 3.46 kB
TypeScript
import { Buffer } from 'buffer';
/**
* Transport mechanism.
* @see https://github.com/LedgerHQ/ledgerjs for all transport Available
*/
interface Transport {
/**
* Used in U2F to avoid different web apps to communicate with different ledger implementations
* @param {string} key
*/
setScrambleKey(key: string): void;
/**
* sends data to Ledger
* @param {number} cla
* @param {number} ins
* @param {number} p1
* @param {number} p2
* @param {Buffer} data
* @param {number[]} statusList Allowed status list.
* @returns {Promise<Buffer>}
*/
send(cla: number, ins: number, p1: number, p2: number, data?: Buffer, statusList?: number[]): Promise<Buffer>;
}
interface SignTransactionArgs {
txType: number;
senderAccount: number;
senderAddress: string;
receiverAddress: string;
amount: number;
fee: number;
nonce: number;
validUntil?: number;
memo?: string;
networkId: number;
}
interface BaseLedgerResponse {
returnCode: string;
statusText?: string;
message?: string;
}
interface GetAddressResponse extends BaseLedgerResponse {
publicKey?: string | null;
}
interface SignTransactionResponse extends BaseLedgerResponse {
signature?: string | null;
}
interface GetAppVersionResponse extends BaseLedgerResponse {
version?: string | null;
}
interface GetAppNameResponse extends BaseLedgerResponse {
name?: string;
version?: string | null;
}
declare enum Networks {
MAINNET = 1,
DEVNET = 0
}
declare enum TxType {
PAYMENT = 0,
DELEGATION = 4
}
/**
* Mina App API
*/
declare class MinaLedgerJS {
transport: Transport;
constructor(transport: Transport, scrambleKey?: string);
protected pad(n: number | string, width?: number, paddingValue?: number | string): string;
protected asciiToHex(str: string): string;
protected convertMemo(memo: string): string;
protected createTXApdu({ txType, senderAccount, senderAddress, receiverAddress, amount, fee, nonce, validUntil, memo, networkId, }: SignTransactionArgs): string;
/**
* Get Mina address for a given account number.
*
* @param account int of the account number
* @param display optionally enable or not the display
* @return an object with a publicKey
* @example
* const result = await Mina.getAddress(1);
* const { publicKey, returnCode } = result;
*/
getAddress(account?: number): Promise<GetAddressResponse>;
signTransaction({ txType, senderAccount, senderAddress, receiverAddress, amount, fee, nonce, validUntil, memo, networkId, }: SignTransactionArgs): Promise<SignTransactionResponse>;
/**
* get the version of the Mina app installed on the hardware device
* the version is returned from the installed app.
*
* @return an object with a version
*/
getAppVersion(): Promise<GetAppVersionResponse>;
/**
* get the name and version of the Mina app installed on the hardware device
* it can be used to ping the app and know the name of the running app.
* The name and version is returned from the Ledger firmware.
*
* @return an object with an app name and version
*/
getAppName(): Promise<GetAppNameResponse>;
}
export { BaseLedgerResponse, GetAddressResponse, GetAppNameResponse, GetAppVersionResponse, MinaLedgerJS, Networks, SignTransactionArgs, SignTransactionResponse, Transport, TxType };