UNPKG

@tronlink/core

Version:

The library serves as a core module within TronLink Extension, which provides low-level wallet functionality for both Tron and Ethereum networks, primary features includes account generation and transaction signing

55 lines 2.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LedgerEthWebHid = void 0; const hw_transport_webhid_1 = __importDefault(require("@ledgerhq/hw-transport-webhid")); const hw_app_eth_1 = __importDefault(require("@ledgerhq/hw-app-eth")); const eth_sig_util_1 = require("eth-sig-util"); const ledger_1 = require("../../base_wallet/ledger"); const EvmWallet_1 = require("../EvmWallet"); class LedgerEthWebHid extends ledger_1.LedgerWebHid { _transport; _app; getWallet() { return new EvmWallet_1.EvmWallet(); } async signTransaction(transaction, path) { try { await this.makeApp(); const response = await this._app.clearSignTransaction(path, transaction, { nft: true, externalPlugins: true, erc20: true, }); return response; } finally { await this.cleanUp(); } } async signTypedData(data, path) { try { await this.makeApp(); const domainSeparatorHex = eth_sig_util_1.TypedDataUtils.hashStruct('EIP712Domain', data.domain, data.types).toString('hex'); const hashStructMessageHex = eth_sig_util_1.TypedDataUtils.hashStruct(data.primaryType, data.message, data.types).toString('hex'); const response = await this._app.signEIP712HashedMessage(path, domainSeparatorHex, hashStructMessageHex); return response; } finally { await this.cleanUp(); } } async makeApp() { this._transport = await hw_transport_webhid_1.default.create(); this._app = new hw_app_eth_1.default(this._transport); return this._app; } async cleanUp() { this._app = undefined; await this._transport?.close(); } } exports.LedgerEthWebHid = LedgerEthWebHid; //# sourceMappingURL=LedgerEthWebHid.js.map