-
Notifications
You must be signed in to change notification settings - Fork 243
feat: add more trezor paths, export path type #710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 7 commits
96a0984
dd5709c
cca3fcd
4d029f1
47ff858
1cabb24
59dc545
39569a6
95c33f0
8b2069e
80bbc5c
a888bf2
4bd0a69
2c07681
7832092
de1b0c0
4c27c77
e03aa94
c38a9ad
c1d9b91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,85 @@ | ||
| # @enkryptcom/hw-wallets | ||
|
|
||
| ## v0.0.12 | ||
|
|
||
| ## Hardware wallet manager for enkrypt | ||
|
|
||
| ### Getting started | ||
|
|
||
| #### Minimum Node version | ||
|
|
||
| `node v20` | ||
|
|
||
| #### Installation | ||
|
|
||
| NPM: `npm install @enkryptcom/hw-wallets @enkryptcom/types` | ||
| Yarn: `yarn add @enkryptcom/hw-wallets @enkryptcom/types` | ||
| PNPM `pnpm add @enkryptcom/hw-wallets @enkryptcom/types` | ||
|
|
||
| ### How to use | ||
|
|
||
| 1. Create an instance of `HWwalletManager` | ||
|
|
||
| ``` | ||
| import HWwalletManager from @enkryptcom/hw-wallets | ||
|
|
||
| const hwManager = new HWwalletManager() | ||
| ``` | ||
|
|
||
| 2. Call methods within class, passing network names and providers. Class automatically handles which wallet to use. | ||
|
|
||
| ### API | ||
|
|
||
| #### `getAddress(options: getAddressRequest): Promise<AddressResponse>` | ||
|
|
||
| Returns wallet address based off of the path provided in the `getAddressRequest`. | ||
|
|
||
| #### `signPersonalMessage(options: SignMessageRequest): Promise<string>` | ||
|
|
||
| Signs personal message. | ||
|
|
||
| #### `signTransaction(options: SignTransactionRequest): Promise<string>` | ||
|
|
||
| Returns an RPC sign you can then add to a transaction object. | ||
|
|
||
| #### `getSupportedPaths(options: isConnectedRequest): Promise<PathType[]>` | ||
|
|
||
| Returns supported paths based on options provided. | ||
|
|
||
| #### `isNetworkSupported(networkName: NetworkNames): boolean` | ||
|
|
||
| Checks network name support. | ||
|
|
||
| #### `isConnected(options: isConnectedRequest): Promise<boolean>` | ||
|
|
||
| Checks connection status. | ||
|
|
||
| #### `close(): Promise<void>` | ||
|
|
||
| Closes all HW wallet connections | ||
|
|
||
| ### Types | ||
|
|
||
| `NetworkNames`: https://github.com/enkryptcom/enKrypt/blob/main/packages/types/src/networks.ts#L1 | ||
| `getAddressRequest`: https://github.com/enkryptcom/enKrypt/blob/main/packages/hw-wallets/src/types.ts#L74 | ||
| `AddressResponse`: https://github.com/enkryptcom/enKrypt/blob/main/packages/hw-wallets/src/types.ts#L31 | ||
| `SignMessageRequest`: https://github.com/enkryptcom/enKrypt/blob/main/packages/hw-wallets/src/types.ts#L54 | ||
| `SignTransactionRequest`: https://github.com/enkryptcom/enKrypt/blob/main/packages/hw-wallets/src/types.ts#L65 | ||
| `isConnectedRequest`: https://github.com/enkryptcom/enKrypt/blob/main/packages/hw-wallets/src/types.ts#L78 | ||
|
|
||
| ### Adding more paths | ||
|
|
||
| Navigate to `src/configs.ts` and add your new derivation path at the bottom. | ||
| Make sure to follow the configuration in that file. | ||
| Import path in the corresponding `Trezor` provider `config.ts`. | ||
| See `src/trezor/ethereum/configs.ts` for example. | ||
|
|
||
| NOTE: `Ledger` can't have any paths as each paths are defined by the corresponding app. | ||
|
|
||
| ### Notes | ||
|
|
||
| Connection request to hardware wallet actually happens on `getAddress()` request. | ||
|
|
||
| #### For Vue devs | ||
|
|
||
| `ref/reactive` will mess with how Vue compiles these classes because of how Vue utilizes proxies. If you want to store an instance into a ref or reactive, use [`makeRaw`](https://vuejs.org/api/reactivity-advanced#markraw). |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||
| import type Transport from "@ledgerhq/hw-transport"; | ||||||||||||||||||||
| import webUsbTransport from "@ledgerhq/hw-transport-webusb"; | ||||||||||||||||||||
| import bleTransport from '@ledgerhq/hw-transport-web-ble'; | ||||||||||||||||||||
| import ledgerService from "@ledgerhq/hw-app-eth/lib/services/ledger"; | ||||||||||||||||||||
| import { HWwalletCapabilities, NetworkNames } from "@enkryptcom/types"; | ||||||||||||||||||||
| import EthApp from "@ledgerhq/hw-app-eth"; | ||||||||||||||||||||
|
|
@@ -34,17 +35,31 @@ class LedgerEthereum implements HWWalletProvider { | |||||||||||||||||||
|
|
||||||||||||||||||||
| async init(): Promise<boolean> { | ||||||||||||||||||||
| if (!this.transport) { | ||||||||||||||||||||
| const support = await webUsbTransport.isSupported(); | ||||||||||||||||||||
| if (support) { | ||||||||||||||||||||
| this.transport = await webUsbTransport.openConnected().then((res) => { | ||||||||||||||||||||
| if (!res) return webUsbTransport.create(); | ||||||||||||||||||||
| return res; | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| return Promise.reject( | ||||||||||||||||||||
| new Error("ledger-ethereum: webusb is not supported"), | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| try { | ||||||||||||||||||||
| const BLEsupport = await bleTransport.isSupported(); | ||||||||||||||||||||
| if (BLEsupport) { | ||||||||||||||||||||
| const transport = await bleTransport.create(); | ||||||||||||||||||||
| transport.on("disconnect", () => { // connection wasnt succesful | ||||||||||||||||||||
| this.transport = null; | ||||||||||||||||||||
| }) | ||||||||||||||||||||
| this.transport = transport; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| } catch { | ||||||||||||||||||||
| const support = await webUsbTransport.isSupported(); | ||||||||||||||||||||
| if (support) { | ||||||||||||||||||||
| this.transport = await webUsbTransport.openConnected().then((res) => { | ||||||||||||||||||||
| if (!res) return webUsbTransport.create(); | ||||||||||||||||||||
| return res; | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| } else { | ||||||||||||||||||||
| return Promise.reject( | ||||||||||||||||||||
| new Error("ledger-ethereum: webusb is not supported"), | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
gamalielhere marked this conversation as resolved.
Outdated
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| } | ||||||||||||||||||||
| return true; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
@@ -142,7 +157,7 @@ class LedgerEthereum implements HWWalletProvider { | |||||||||||||||||||
|
|
||||||||||||||||||||
| close(): Promise<void> { | ||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-empty-function | ||||||||||||||||||||
| return this.transport.close().catch(() => {}); | ||||||||||||||||||||
| return this.transport.close().catch(() => { }); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
171
to
174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevent If transport setup fails and Guard the call (same pattern as other Ledger classes): close(): Promise<void> {
- // eslint-disable-next-line @typescript-eslint/no-empty-function
- return this.transport.close().catch(() => { });
+ if (!this.transport) return Promise.resolve();
+ return this.transport.close().catch(() => undefined);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
| isConnected(networkName: NetworkNames): Promise<boolean> { | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: enkryptcom/enKrypt
Length of output: 1532
🏁 Script executed:
Repository: enkryptcom/enKrypt
Length of output: 382
Update hw-wallets/.nvmrc to align with Node >=20 requirement.
The package.json correctly specifies
engines.node: ">=20"and this is documented in the README. However,packages/hw-wallets/.nvmrccontainslts/fermium(Node 14), which creates a developer experience issue—tools like nvm will override to Node 14 despite the package requiring Node >=20. Update this file tov20or higher to match the enforced constraint.🤖 Prompt for AI Agents