UNPKG

@metamask/eth-ledger-bridge-keyring

Version:

A MetaMask compatible keyring, for ledger hardware wallets

58 lines 1.98 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MetaMaskLedgerHwAppEth = void 0; const hw_app_eth_1 = __importDefault(require("@ledgerhq/hw-app-eth")); const buffer_1 = require("buffer"); class MetaMaskLedgerHwAppEth extends hw_app_eth_1.default { constructor() { super(...arguments); this.mainAppName = 'BOLOS'; this.ethAppName = 'Ethereum'; this.transportEncoding = 'ascii'; } /** * Method to open ethereum application on ledger device. * */ async openEthApp() { await this.transport.send(0xe0, 0xd8, 0x00, 0x00, buffer_1.Buffer.from(this.ethAppName, this.transportEncoding)); } /** * Method to close all running application on ledger device. * */ async closeApps() { await this.transport.send(0xb0, 0xa7, 0x00, 0x00); } /** * Method to retrieve the name and version of the running application in ledger device. * * @returns An object contains appName and version. */ async getAppNameAndVersion() { const response = await this.transport.send(0xb0, 0x01, 0x00, 0x00); if (response[0] !== 1) { throw new Error('Incorrect format return from getAppNameAndVersion.'); } let i = 1; const nameLength = response[i] ?? 0; i += 1; const appName = response .slice(i, (i += nameLength)) .toString(this.transportEncoding); const versionLength = response[i] ?? 0; i += 1; const version = response .slice(i, (i += versionLength)) .toString(this.transportEncoding); return { appName, version, }; } } exports.MetaMaskLedgerHwAppEth = MetaMaskLedgerHwAppEth; //# sourceMappingURL=ledger-hw-app.cjs.map