@exodus/hardware-wallets 1.5.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.7.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hardware-wallets@1.6.0...@exodus/hardware-wallets@1.7.0) (2024-11-13)
7
+
8
+ ### Features
9
+
10
+ - feat: add isAssetNameConnectedForWalletAccountSelector (#10416)
11
+
12
+ ## [1.6.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hardware-wallets@1.5.1...@exodus/hardware-wallets@1.6.0) (2024-10-22)
13
+
14
+ ### Features
15
+
16
+ - support cancelling an action on the ledger device ([#10105](https://github.com/ExodusMovement/exodus-hydra/issues/10105)) ([f1c1fbf](https://github.com/ExodusMovement/exodus-hydra/commit/f1c1fbff6ec70b7ddc68dd700ffb556b673b7a5a))
17
+
18
+ ### Bug Fixes
19
+
20
+ - catch xpub key identifier errrors ([#10124](https://github.com/ExodusMovement/exodus-hydra/issues/10124)) ([7cd681d](https://github.com/ExodusMovement/exodus-hydra/commit/7cd681deec14adfa9c3e7613f276f2745f1df441))
21
+
6
22
  ## [1.5.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hardware-wallets@1.5.0...@exodus/hardware-wallets@1.5.1) (2024-10-17)
7
23
 
8
24
  ### Bug Fixes
@@ -0,0 +1,11 @@
1
+ type WalletAccountName = string;
2
+ type AssetName = string;
3
+ export type WalletAccountNameToConnectedAssetNamesMap = Record<WalletAccountName, AssetName[]>;
4
+ export declare const createHardwareWalletConnectedAssetNamesAtom: ({ assetsModule, hardwareWalletPublicKeysAtom, walletAccountsAtom, }: any) => import("@exodus/atoms").ReadonlyAtom<unknown>;
5
+ export declare const hardwareWalletConnectedAssetNamesAtomDefinition: {
6
+ readonly id: "hardwareWalletConnectedAssetNamesAtom";
7
+ readonly type: "atom";
8
+ readonly factory: ({ assetsModule, hardwareWalletPublicKeysAtom, walletAccountsAtom, }: any) => import("@exodus/atoms").ReadonlyAtom<unknown>;
9
+ readonly dependencies: readonly ["hardwareWalletPublicKeysAtom", "assetsModule", "walletAccountsAtom"];
10
+ };
11
+ export {};
@@ -0,0 +1,43 @@
1
+ import { combine, compute } from '@exodus/atoms';
2
+ import { memoize } from '@exodus/basic-utils';
3
+ import { HARDENED_OFFSET } from '@exodus/bip32';
4
+ export const createHardwareWalletConnectedAssetNamesAtom = ({ assetsModule, hardwareWalletPublicKeysAtom, walletAccountsAtom, }) => {
5
+ const selector = memoize(({ hardwareWalletPublicKeys, walletAccounts }) => {
6
+ const result = Object.create(null);
7
+ const assets = assetsModule.getAssets();
8
+ for (const [walletAccountName, walletAccount] of Object.entries(walletAccounts)) {
9
+ if (!walletAccount.isHardware) {
10
+ continue;
11
+ }
12
+ const derivationPaths = Object.keys(hardwareWalletPublicKeys[walletAccountName] ?? Object.create(null));
13
+ if (derivationPaths.length === 0) {
14
+ continue;
15
+ }
16
+ const bip44Regex = /^m\/\d+'\/(\d+)'/u;
17
+ const bip44Values = new Set(derivationPaths
18
+ .map((path) => {
19
+ const match = path.match(bip44Regex);
20
+ return match ? match[1] : null;
21
+ })
22
+ .filter(Boolean));
23
+ const syncedAssetNames = Object.values(assets)
24
+ .filter((asset) => bip44Values.has(String(asset.baseAsset.bip44 - HARDENED_OFFSET)))
25
+ .map((asset) => asset.name);
26
+ result[walletAccountName] = syncedAssetNames;
27
+ }
28
+ return result;
29
+ }, (deps) => JSON.stringify(deps));
30
+ return compute({
31
+ atom: combine({
32
+ hardwareWalletPublicKeys: hardwareWalletPublicKeysAtom,
33
+ walletAccounts: walletAccountsAtom,
34
+ }),
35
+ selector,
36
+ });
37
+ };
38
+ export const hardwareWalletConnectedAssetNamesAtomDefinition = {
39
+ id: 'hardwareWalletConnectedAssetNamesAtom',
40
+ type: 'atom',
41
+ factory: createHardwareWalletConnectedAssetNamesAtom,
42
+ dependencies: ['hardwareWalletPublicKeysAtom', 'assetsModule', 'walletAccountsAtom'],
43
+ };
package/lib/index.d.ts CHANGED
@@ -36,6 +36,27 @@ declare const hardwareWallets: () => {
36
36
  readonly dependencies: readonly ["assetsModule", "logger", "ledgerDiscovery", "userInterface", "publicKeyStore", "wallet", "walletAccountsAtom", "walletAccounts"];
37
37
  readonly public: true;
38
38
  };
39
+ }, {
40
+ readonly definition: {
41
+ readonly id: "hardwareWalletConnectedAssetNamesAtom";
42
+ readonly type: "atom";
43
+ readonly factory: ({ assetsModule, hardwareWalletPublicKeysAtom, walletAccountsAtom, }: any) => import("libraries/atoms/lib/index.js").ReadonlyAtom<unknown>;
44
+ readonly dependencies: readonly ["hardwareWalletPublicKeysAtom", "assetsModule", "walletAccountsAtom"];
45
+ };
46
+ }, {
47
+ readonly definition: {
48
+ readonly id: "hardwareWalletsPlugin";
49
+ readonly type: "plugin";
50
+ readonly factory: ({ hardwareWalletConnectedAssetNamesAtom, port, }: {
51
+ hardwareWalletConnectedAssetNamesAtom: import("libraries/atoms/lib/index.js").Atom<import("./atoms/index.js").WalletAccountNameToConnectedAssetNamesMap>;
52
+ port: import("./shared/types.js").Port;
53
+ }) => {
54
+ onUnlock: () => void;
55
+ onLoad: () => void;
56
+ onStop: () => void;
57
+ };
58
+ readonly dependencies: readonly ["hardwareWalletConnectedAssetNamesAtom", "port"];
59
+ };
39
60
  }];
40
61
  };
41
62
  export type HardwareWalletsApi = ReturnType<typeof hardwareWalletsApiDefinition.factory>;
package/lib/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import hardwareWalletsApiDefinition from './api/index.js';
2
2
  import hardwareWalletsModuleDefinition from './module/hardware-wallets.js';
3
+ import { hardwareWalletConnectedAssetNamesAtomDefinition } from './atoms/index.js';
4
+ import hardwareWalletsPluginDefinition from './plugin/index.js';
3
5
  const hardwareWallets = () => {
4
6
  return {
5
7
  id: 'hardwareWallets',
@@ -10,6 +12,12 @@ const hardwareWallets = () => {
10
12
  {
11
13
  definition: hardwareWalletsModuleDefinition,
12
14
  },
15
+ {
16
+ definition: hardwareWalletConnectedAssetNamesAtomDefinition,
17
+ },
18
+ {
19
+ definition: hardwareWalletsPluginDefinition,
20
+ },
13
21
  ],
14
22
  };
15
23
  };
@@ -1,7 +1,7 @@
1
1
  import assert from 'minimalistic-assert';
2
2
  import { WalletAccount } from '@exodus/models';
3
3
  import Emitter from '@exodus/wild-emitter';
4
- import randomBytes from 'randombytes';
4
+ import { randomBytes } from '@exodus/crypto/randomBytes';
5
5
  import delay from 'delay';
6
6
  import { NoDeviceFoundError, UserRefusedError } from '@exodus/hw-common';
7
7
  export class HardwareWallets {
@@ -52,6 +52,7 @@ export class HardwareWallets {
52
52
  };
53
53
  const result = await Promise.race([approvePromise, runSign()]);
54
54
  if (typeof result === 'object' && result.tryAgain === false) {
55
+ device.cancelAction();
55
56
  throw new UserRefusedError(false);
56
57
  }
57
58
  this.#requestUserAction({ scenario: 'completed' });
@@ -183,28 +184,32 @@ export class HardwareWallets {
183
184
  });
184
185
  };
185
186
  #getXPUB = async ({ device, baseAsset, purpose, accountIndex, }) => {
186
- const keyIdentifier = baseAsset.api.getKeyIdentifier({
187
- compatibilityMode: 'ledger',
188
- purpose,
189
- accountIndex,
190
- chainIndex: undefined,
191
- addressIndex: undefined,
192
- });
193
- const { derivationPath } = keyIdentifier;
194
- const xpub = await device
195
- .getXPub({
196
- assetName: baseAsset.name,
197
- derivationPath,
198
- })
199
- .catch((error) => {
200
- if (error.name === 'XPubUnsupportedError') {
201
- this.#logger.warn(`Retrieving XPUBs for ${baseAsset.name} is not supported`, error);
187
+ try {
188
+ const keyIdentifier = baseAsset.api.getKeyIdentifier({
189
+ compatibilityMode: 'ledger',
190
+ purpose,
191
+ accountIndex,
192
+ chainIndex: undefined,
193
+ addressIndex: undefined,
194
+ });
195
+ const { derivationPath } = keyIdentifier;
196
+ const xpub = await device.getXPub({
197
+ assetName: baseAsset.name,
198
+ derivationPath,
199
+ });
200
+ if (xpub) {
201
+ return { keyIdentifier, xpub };
202
202
  }
203
- else {
204
- throw error;
203
+ return null;
204
+ }
205
+ catch (error) {
206
+ if (error.name === 'XPubUnsupportedError' ||
207
+ error.message.includes(`XPUB derivation is not allowed`)) {
208
+ this.#logger.warn(`Retrieving XPUBs for ${baseAsset.name} is not supported`, error);
209
+ return null;
205
210
  }
206
- });
207
- return xpub ? { keyIdentifier, xpub } : null;
211
+ throw error;
212
+ }
208
213
  };
209
214
  #getPublicKey = async ({ device, baseAsset, purpose, accountIndex, }) => {
210
215
  const keyIdentifier = baseAsset.api.getKeyIdentifier({
@@ -17,6 +17,7 @@ export interface HardwareSignerProvider {
17
17
  type Asset = {
18
18
  name: string;
19
19
  baseAsset: Asset;
20
+ bip44: number;
20
21
  api: {
21
22
  getKeyIdentifier(params: {
22
23
  purpose: number;
@@ -0,0 +1,17 @@
1
+ import type { Atom } from '@exodus/atoms';
2
+ import type { Port } from '../shared/types';
3
+ import type { WalletAccountNameToConnectedAssetNamesMap } from '../atoms/index.js';
4
+ declare const hardwareWalletsPluginDefinition: {
5
+ readonly id: "hardwareWalletsPlugin";
6
+ readonly type: "plugin";
7
+ readonly factory: ({ hardwareWalletConnectedAssetNamesAtom, port, }: {
8
+ hardwareWalletConnectedAssetNamesAtom: Atom<WalletAccountNameToConnectedAssetNamesMap>;
9
+ port: Port;
10
+ }) => {
11
+ onUnlock: () => void;
12
+ onLoad: () => void;
13
+ onStop: () => void;
14
+ };
15
+ readonly dependencies: readonly ["hardwareWalletConnectedAssetNamesAtom", "port"];
16
+ };
17
+ export default hardwareWalletsPluginDefinition;
@@ -0,0 +1,34 @@
1
+ import { createAtomObserver } from '@exodus/atoms';
2
+ const createHardwareWalletsPlugin = ({ hardwareWalletConnectedAssetNamesAtom, port, }) => {
3
+ const observers = [
4
+ createAtomObserver({
5
+ atom: hardwareWalletConnectedAssetNamesAtom,
6
+ port,
7
+ event: 'hardwareWalletConnectedAssetNames',
8
+ }),
9
+ ];
10
+ observers.forEach((observer) => observer.register());
11
+ const start = () => {
12
+ observers.forEach((observer) => observer.start());
13
+ };
14
+ const stop = () => {
15
+ observers.forEach((observer) => observer.unregister());
16
+ };
17
+ const onUnlock = () => {
18
+ start();
19
+ };
20
+ const onLoad = () => {
21
+ start();
22
+ };
23
+ const onStop = () => {
24
+ stop();
25
+ };
26
+ return { onUnlock, onLoad, onStop };
27
+ };
28
+ const hardwareWalletsPluginDefinition = {
29
+ id: 'hardwareWalletsPlugin',
30
+ type: 'plugin',
31
+ factory: createHardwareWalletsPlugin,
32
+ dependencies: ['hardwareWalletConnectedAssetNamesAtom', 'port'],
33
+ };
34
+ export default hardwareWalletsPluginDefinition;
@@ -0,0 +1,2 @@
1
+ declare const id = "hardwareWallets";
2
+ export default id;
@@ -0,0 +1,2 @@
1
+ const id = 'hardwareWallets';
2
+ export default id;
@@ -0,0 +1,22 @@
1
+ import { type HardwareWalletsState } from './initial-state.js';
2
+ declare const hardwareWalletsReduxDefinition: {
3
+ readonly id: "hardwareWallets";
4
+ readonly type: "redux-module";
5
+ readonly initialState: HardwareWalletsState;
6
+ readonly eventReducers: {
7
+ readonly hardwareWalletConnectedAssetNames: (state: HardwareWalletsState, payload: boolean) => {
8
+ walletAccountNameToConnectedAssetNamesMap: boolean;
9
+ };
10
+ };
11
+ readonly selectorDefinitions: {
12
+ readonly id: "isAssetNameConnectedForWalletAccount";
13
+ readonly selectorFactory: (selfSelector: any) => ({ walletAccountName, assetName }: {
14
+ walletAccountName: string;
15
+ assetName: string;
16
+ }) => import("reselect").OutputSelector<unknown, boolean, (res: HardwareWalletsState) => boolean>;
17
+ readonly dependencies: readonly [{
18
+ readonly selector: string;
19
+ }];
20
+ }[];
21
+ };
22
+ export default hardwareWalletsReduxDefinition;
@@ -0,0 +1,16 @@
1
+ import id from './id.js';
2
+ import initialState from './initial-state.js';
3
+ import selectorDefinitions from './selectors/index.js';
4
+ const hardwareWalletsReduxDefinition = {
5
+ id,
6
+ type: 'redux-module',
7
+ initialState,
8
+ eventReducers: {
9
+ hardwareWalletConnectedAssetNames: (state, payload) => ({
10
+ ...state,
11
+ walletAccountNameToConnectedAssetNamesMap: payload,
12
+ }),
13
+ },
14
+ selectorDefinitions,
15
+ };
16
+ export default hardwareWalletsReduxDefinition;
@@ -0,0 +1,6 @@
1
+ import type { WalletAccountNameToConnectedAssetNamesMap } from '../atoms/index.js';
2
+ export type HardwareWalletsState = {
3
+ walletAccountNameToConnectedAssetNamesMap: WalletAccountNameToConnectedAssetNamesMap;
4
+ };
5
+ declare const initialState: HardwareWalletsState;
6
+ export default initialState;
@@ -0,0 +1,4 @@
1
+ const initialState = {
2
+ walletAccountNameToConnectedAssetNamesMap: Object.create(null),
3
+ };
4
+ export default initialState;
@@ -0,0 +1,11 @@
1
+ declare const hardwareWalletsSelectors: {
2
+ readonly id: "isAssetNameConnectedForWalletAccount";
3
+ readonly selectorFactory: (selfSelector: any) => ({ walletAccountName, assetName }: {
4
+ walletAccountName: string;
5
+ assetName: string;
6
+ }) => import("reselect").OutputSelector<unknown, boolean, (res: import("../initial-state.js").HardwareWalletsState) => boolean>;
7
+ readonly dependencies: readonly [{
8
+ readonly selector: string;
9
+ }];
10
+ }[];
11
+ export default hardwareWalletsSelectors;
@@ -0,0 +1,3 @@
1
+ import isAssetNameConnectedForWalletAccountSelectorDefinition from './isAssetNameConnectedForWalletAccount.js';
2
+ const hardwareWalletsSelectors = [isAssetNameConnectedForWalletAccountSelectorDefinition];
3
+ export default hardwareWalletsSelectors;
@@ -0,0 +1,13 @@
1
+ import type { HardwareWalletsState } from '../initial-state.js';
2
+ type isAssetNameConnectedForWalletAccountParams = {
3
+ walletAccountName: string;
4
+ assetName: string;
5
+ };
6
+ declare const isAssetNameConnectedForWalletAccountSelectorDefinition: {
7
+ readonly id: "isAssetNameConnectedForWalletAccount";
8
+ readonly selectorFactory: (selfSelector: any) => ({ walletAccountName, assetName }: isAssetNameConnectedForWalletAccountParams) => import("reselect").OutputSelector<unknown, boolean, (res: HardwareWalletsState) => boolean>;
9
+ readonly dependencies: readonly [{
10
+ readonly selector: string;
11
+ }];
12
+ };
13
+ export default isAssetNameConnectedForWalletAccountSelectorDefinition;
@@ -0,0 +1,9 @@
1
+ import { MY_STATE } from '@exodus/redux-dependency-injection';
2
+ import { createSelector } from 'reselect';
3
+ const selectorFactory = (selfSelector) => ({ walletAccountName, assetName }) => createSelector(selfSelector, ({ walletAccountNameToConnectedAssetNamesMap }) => walletAccountNameToConnectedAssetNamesMap[walletAccountName]?.includes(assetName) ?? false);
4
+ const isAssetNameConnectedForWalletAccountSelectorDefinition = {
5
+ id: 'isAssetNameConnectedForWalletAccount',
6
+ selectorFactory,
7
+ dependencies: [{ selector: MY_STATE }],
8
+ };
9
+ export default isAssetNameConnectedForWalletAccountSelectorDefinition;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/hardware-wallets",
3
- "version": "1.5.1",
3
+ "version": "1.7.0",
4
4
  "description": "An Exodus SDK feature that provides a high level abstraction for interacting with hardware wallet devices",
5
5
  "author": "Exodus Movement, Inc.",
6
6
  "repository": {
@@ -28,21 +28,25 @@
28
28
  "prepublishOnly": "yarn run -T build --scope @exodus/hardware-wallets"
29
29
  },
30
30
  "dependencies": {
31
- "@exodus/hw-common": "^3.0.0",
31
+ "@exodus/atoms": "^9.0.0",
32
+ "@exodus/basic-utils": "^3.2.0",
33
+ "@exodus/bip32": "^3.3.0",
34
+ "@exodus/crypto": "^1.0.0-rc.18",
35
+ "@exodus/hw-common": "^3.1.0",
32
36
  "@exodus/models": "^12.0.1",
37
+ "@exodus/redux-dependency-injection": "^4.0.0",
33
38
  "@exodus/wild-emitter": "^1.1.0",
34
39
  "delay": "^5.0.0",
35
40
  "minimalistic-assert": "^1.0.1",
36
- "randombytes": "^2.1.0"
41
+ "reselect": "^3.0.1"
37
42
  },
38
43
  "devDependencies": {
39
- "@exodus/atoms": "^9.0.0",
40
- "@exodus/dependency-types": "^2.1.0",
44
+ "@exodus/dependency-types": "^2.1.1",
41
45
  "@exodus/key-identifier": "^1.3.0",
42
- "@exodus/logger": "^1.2.2",
43
- "@exodus/public-key-provider": "^3.0.0",
44
- "@types/randombytes": "^2.0.3",
45
- "p-defer": "^4.0.1"
46
+ "@exodus/logger": "^1.2.3",
47
+ "@exodus/public-key-provider": "^4.0.0",
48
+ "p-defer": "^4.0.1",
49
+ "redux": "^4.2.1"
46
50
  },
47
- "gitHead": "c74a9968861467c805398c25b4017985e976ba31"
51
+ "gitHead": "68e51f95fefb4e6f0135e71685337676790c665d"
48
52
  }