Closed FrederikBolding closed 2 years ago
Even I am really looking forward to it.
WebHID
and WebUSB
can be exposed via endowments as long as the execution iframe has allow="hid 'src'"
.
However, the browser APIs will throw: Failed to execute 'requestDevice' on 'HID': Must be handling a user gesture to show a permission request.
, since the detection doesn't register a user action even when an actual user action triggers the snap.
Example code:
/* eslint-disable no-case-declarations */
const { DEFAULT_ETH, LedgerWallet } = require('@mycrypto/wallets');
module.exports.onRpcRequest = async ({ request }) => {
switch (request.method) {
case 'hello':
const ledger = new LedgerWallet();
const instance = await ledger.getWallet(DEFAULT_ETH, 0);
return instance.signMessage(request.params[0]);
default:
throw new Error('Method not found.');
}
};
We should investigate how the extension overcomes this in its existing hardware wallet integrations. Maybe @darkwing can shed some light.
@FrederikBolding please update this issue and document your findings.
To support hardware wallets as snaps we can expose WebHID
and WebUSB
via globals. However, we would need to initialize the hardware connection in the MetaMask extension by allowing the user to click a button, triggering a user gesture outside of a snap. After that is done the connection should be available to snaps.
This is the same way the extension is currently doing it. While we are still running snaps in iframes, this seems like the only option.
Likely to be
WebUSB
,WebHID
etc.