@onekeyfe/hardware-cli 1.2.0-alpha.34 → 1.2.0-alpha.35

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/dist/cli.js CHANGED
@@ -633,7 +633,14 @@ sessionCmd
633
633
  });
634
634
  return;
635
635
  }
636
- const device = searchResult.payload[0];
636
+ const device = (0, deviceSelection_1.selectSearchDevice)(searchResult.payload, globalOpts.connectId);
637
+ if (!device) {
638
+ outputResult(globalOpts, {
639
+ success: false,
640
+ payload: { error: 'No matching device found', code: 'NO_DEVICE' },
641
+ });
642
+ return;
643
+ }
637
644
  const connectId = device.connectId || globalOpts.connectId;
638
645
  // 2. Unlock if locked — getPassphraseState below talks to a live
639
646
  // device session, which a locked device will reject with an obscure
@@ -678,8 +685,7 @@ sessionCmd
678
685
  .description('Clear cached device session')
679
686
  .action(() => runCommand({}, async ({ sdk, globalOpts }) => {
680
687
  const searchResult = await sdk.searchDevices();
681
- const device = // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
682
- searchResult?.payload?.[0];
688
+ const device = (0, deviceSelection_1.selectSearchDevice)(searchResult?.payload ?? [], globalOpts.connectId);
683
689
  const deviceId = device?.deviceId || device?.features?.device_id;
684
690
  if (deviceId) {
685
691
  await (0, session_1.clearSessionFromKeychain)(deviceId);
@@ -1,3 +1,3 @@
1
1
  export declare function selectSearchDevice<T extends {
2
- connectId?: string;
2
+ connectId?: string | null;
3
3
  }>(devices: T[], preferredConnectId?: string): T | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hardware-cli",
3
- "version": "1.2.0-alpha.34",
3
+ "version": "1.2.0-alpha.35",
4
4
  "description": "OneKey hardware wallet CLI for testing device communication",
5
5
  "author": "OneKey",
6
6
  "license": "Apache-2.0",
@@ -31,12 +31,12 @@
31
31
  "test": "jest"
32
32
  },
33
33
  "dependencies": {
34
- "@onekeyfe/hd-common-connect-sdk": "1.2.0-alpha.34",
35
- "@onekeyfe/hd-core": "1.2.0-alpha.34",
36
- "@onekeyfe/hd-shared": "1.2.0-alpha.34",
37
- "@onekeyfe/hd-transport-usb": "1.2.0-alpha.34",
34
+ "@onekeyfe/hd-common-connect-sdk": "1.2.0-alpha.35",
35
+ "@onekeyfe/hd-core": "1.2.0-alpha.35",
36
+ "@onekeyfe/hd-shared": "1.2.0-alpha.35",
37
+ "@onekeyfe/hd-transport-usb": "1.2.0-alpha.35",
38
38
  "@stoprocent/noble": "2.3.16",
39
39
  "commander": "^12.0.0"
40
40
  },
41
- "gitHead": "07f10b4c9fab177da7c36d976ec18b075492b57f"
41
+ "gitHead": "638bd33030686c4a3321e4feb4924c3f9f5c81a8"
42
42
  }
package/src/cli.ts CHANGED
@@ -808,7 +808,17 @@ sessionCmd
808
808
  });
809
809
  return;
810
810
  }
811
- const device = searchResult.payload[0] as SearchDevice & { features?: Features };
811
+ const device = selectSearchDevice(
812
+ searchResult.payload as Array<SearchDevice & { features?: Features }>,
813
+ globalOpts.connectId
814
+ );
815
+ if (!device) {
816
+ outputResult(globalOpts, {
817
+ success: false,
818
+ payload: { error: 'No matching device found', code: 'NO_DEVICE' },
819
+ });
820
+ return;
821
+ }
812
822
  const connectId = device.connectId || globalOpts.connectId;
813
823
 
814
824
  // 2. Unlock if locked — getPassphraseState below talks to a live
@@ -860,8 +870,10 @@ sessionCmd
860
870
  .action(() =>
861
871
  runCommand({}, async ({ sdk, globalOpts }) => {
862
872
  const searchResult = await sdk.searchDevices();
863
- const device = // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
864
- (searchResult?.payload as any)?.[0];
873
+ const device = selectSearchDevice(
874
+ (searchResult?.payload as Array<SearchDevice & { features?: Features }>) ?? [],
875
+ globalOpts.connectId
876
+ );
865
877
  const deviceId = device?.deviceId || device?.features?.device_id;
866
878
  if (deviceId) {
867
879
  await clearSessionFromKeychain(deviceId);
@@ -1,4 +1,4 @@
1
- export function selectSearchDevice<T extends { connectId?: string }>(
1
+ export function selectSearchDevice<T extends { connectId?: string | null }>(
2
2
  devices: T[],
3
3
  preferredConnectId?: string
4
4
  ): T | undefined {