@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
48 lines • 1.65 kB
JavaScript
import TransportWebHID from '@ledgerhq/hw-transport-webhid';
import AppEth from '@ledgerhq/hw-app-eth';
import { TypedDataUtils } from 'eth-sig-util';
import { LedgerWebHid } from '../../base_wallet/ledger';
import { EvmWallet } from '../EvmWallet';
export class LedgerEthWebHid extends LedgerWebHid {
_transport;
_app;
getWallet() {
return new 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 = TypedDataUtils.hashStruct('EIP712Domain', data.domain, data.types).toString('hex');
const hashStructMessageHex = 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 TransportWebHID.create();
this._app = new AppEth(this._transport);
return this._app;
}
async cleanUp() {
this._app = undefined;
await this._transport?.close();
}
}
//# sourceMappingURL=LedgerEthWebHid.js.map