-
Notifications
You must be signed in to change notification settings - Fork 242
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 all 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,84 @@ | ||
| # @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. | ||
|
|
||
| ### Notes | ||
|
|
||
| Connection request to hardware wallet actually happens on `getAddress()` request. | ||
| `Ledger` can't have any paths as each paths are defined by the corresponding app. | ||
|
|
||
| #### 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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -170,7 +170,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> { | ||||||||||||||||||||
|
|
@@ -191,4 +191,4 @@ class LedgerEthereum implements HWWalletProvider { | |||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export default LedgerEthereum; | ||||||||||||||||||||
| export default LedgerEthereum; | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -94,7 +94,7 @@ class LedgerSolana 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
95
to
98
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. Handle the no-transport case before calling When initialization never bound a transport (e.g., both BLE and WebUSB unsupported), Add a simple guard: 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> { | ||||||||||||||||||||
|
|
@@ -110,4 +110,4 @@ class LedgerSolana implements HWWalletProvider { | |||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export default LedgerSolana; | ||||||||||||||||||||
| export default LedgerSolana; | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,7 @@ class LedgerSubstrate 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
81
to
84
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. Guard
Use a guard (or optional chaining) so 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);
}🤖 Prompt for AI Agents |
||
|
|
||
| isConnected(networkName: NetworkNames): Promise<boolean> { | ||
|
|
@@ -128,4 +128,4 @@ class LedgerSubstrate implements HWWalletProvider { | |
| } | ||
| } | ||
|
|
||
| export default LedgerSubstrate; | ||
| export default LedgerSubstrate; | ||
Uh oh!
There was an error while loading. Please reload this page.