@metamask/eth-trezor-keyring
Version:
A MetaMask compatible keyring, for trezor hardware wallets
48 lines • 1.7 kB
JavaScript
function $importDefault(module) {
if (module === null || module === void 0 ? void 0 : module.__esModule) {
return module.default;
}
return module;
}
import $TrezorConnect from "@trezor/connect-web";
const { DEVICE_EVENT, DEVICE } = $TrezorConnect;
const TrezorConnect = $importDefault($TrezorConnect);
export class TrezorConnectBridge {
constructor() {
this.trezorConnectInitiated = false;
}
async init(settings) {
TrezorConnect.on(DEVICE_EVENT, (event) => {
var _a;
if (event.type !== DEVICE.CONNECT) {
return;
}
this.model = (_a = event.payload.features) === null || _a === void 0 ? void 0 : _a.model;
});
if (this.trezorConnectInitiated) {
return;
}
await TrezorConnect.init(settings);
this.trezorConnectInitiated = true;
}
async dispose() {
// This removes the Trezor Connect iframe from the DOM
// This method is not well documented, but the code it calls can be seen
// here: https://github.com/trezor/connect/blob/dec4a56af8a65a6059fb5f63fa3c6690d2c37e00/src/js/iframe/builder.js#L181
TrezorConnect.dispose();
return Promise.resolve();
}
getPublicKey(params) {
return TrezorConnect.getPublicKey(params);
}
ethereumSignTransaction(params) {
return TrezorConnect.ethereumSignTransaction(params);
}
ethereumSignMessage(params) {
return TrezorConnect.ethereumSignMessage(params);
}
ethereumSignTypedData(params) {
return TrezorConnect.ethereumSignTypedData(params);
}
}
//# sourceMappingURL=trezor-connect-bridge.mjs.map