@onekeyfe/hardware-cli 1.1.27-alpha.40 → 1.1.27-alpha.5

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
@@ -5,30 +5,6 @@ const commander_1 = require("commander");
5
5
  const sdk_1 = require("./sdk");
6
6
  const session_1 = require("./session");
7
7
  const chains_1 = require("./chains");
8
- function extractPassphraseSession(payload) {
9
- if (typeof payload === 'string') {
10
- return { passphraseState: payload };
11
- }
12
- if (!payload || typeof payload !== 'object') {
13
- return {};
14
- }
15
- const statePayload = payload;
16
- let passphraseState;
17
- if (typeof statePayload.passphrase_state === 'string') {
18
- passphraseState = statePayload.passphrase_state;
19
- }
20
- else if (typeof statePayload.passphraseState === 'string') {
21
- passphraseState = statePayload.passphraseState;
22
- }
23
- let sessionId;
24
- if (typeof statePayload.session_id === 'string') {
25
- sessionId = statePayload.session_id;
26
- }
27
- else if (typeof statePayload.sessionId === 'string') {
28
- sessionId = statePayload.sessionId;
29
- }
30
- return { passphraseState, sessionId };
31
- }
32
8
  const program = new commander_1.Command();
33
9
  program
34
10
  .name('onekey-hw')
@@ -561,14 +537,7 @@ sessionCmd
561
537
  outputResult(globalOpts, psResult);
562
538
  return;
563
539
  }
564
- const { passphraseState, sessionId: passphraseSessionId } = extractPassphraseSession(psResult.payload);
565
- if (!passphraseState) {
566
- outputResult(globalOpts, {
567
- success: false,
568
- payload: { error: 'getPassphraseState did not return passphraseState' },
569
- });
570
- return;
571
- }
540
+ const passphraseState = psResult.payload;
572
541
  // 4. Get address to verify + extract deviceId
573
542
  const addrResult = await sdk.evmGetAddress(connectId, device.deviceId || '', {
574
543
  path: "m/44'/60'/0'/0/0",
@@ -591,7 +560,7 @@ sessionCmd
591
560
  });
592
561
  const featPayload = featResult?.success ? featResult.payload : undefined;
593
562
  const deviceId = featPayload?.device_id || device.deviceId || '';
594
- const sessionId = passphraseSessionId || featPayload?.session_id || '';
563
+ const sessionId = featPayload?.session_id || '';
595
564
  // 6. Save to keychain
596
565
  if (passphraseState && deviceId && sessionId) {
597
566
  await (0, session_1.saveSessionToKeychain)(deviceId, passphraseState, sessionId);
@@ -722,7 +691,6 @@ globalOpts) {
722
691
  // getFeatures failures here are non-fatal — we fall through to Step 3
723
692
  // which will fail with a clearer error if the device is truly unreachable.
724
693
  let deviceId = device.features?.device_id || device.deviceId || '';
725
- let deviceType = device.features?.onekey_device_type;
726
694
  let unlocked = device.features?.unlocked;
727
695
  let passphraseProtection = device.features?.passphrase_protection;
728
696
  if (!deviceId || unlocked == null || passphraseProtection == null) {
@@ -730,7 +698,6 @@ globalOpts) {
730
698
  const featResult = await sdk.getFeatures(connectId);
731
699
  if (featResult?.success && featResult.payload) {
732
700
  deviceId = featResult.payload.device_id || deviceId;
733
- deviceType = featResult.payload.onekey_device_type || deviceType;
734
701
  unlocked = featResult.payload.unlocked;
735
702
  passphraseProtection = featResult.payload.passphrase_protection;
736
703
  }
@@ -756,7 +723,7 @@ globalOpts) {
756
723
  globalOpts.deviceId = deviceId;
757
724
  }
758
725
  // ── Step 4: Check passphrase protection ──────────────────────────
759
- if (passphraseProtection === false && deviceType !== 'pro2' && deviceType !== 'PRO2') {
726
+ if (passphraseProtection === false) {
760
727
  return undefined;
761
728
  }
762
729
  // ── Step 5: Try keychain session reuse ───────────────────────────
@@ -775,10 +742,7 @@ globalOpts) {
775
742
  useEmptyPassphrase: false,
776
743
  });
777
744
  if (psResult.success && psResult.payload) {
778
- const { passphraseState, sessionId: passphraseSessionId } = extractPassphraseSession(psResult.payload);
779
- if (!passphraseState) {
780
- return undefined;
781
- }
745
+ const passphraseState = psResult.payload;
782
746
  globalOpts.passphraseState = passphraseState;
783
747
  // Save session to keychain for next invocation.
784
748
  //
@@ -791,7 +755,7 @@ globalOpts) {
791
755
  passphraseState,
792
756
  skipPassphraseCheck: true,
793
757
  });
794
- const sessionId = passphraseSessionId || (featAfter?.success ? featAfter.payload?.session_id : undefined);
758
+ const sessionId = featAfter?.success ? featAfter.payload?.session_id : undefined;
795
759
  if (sessionId) {
796
760
  await (0, session_1.saveSessionToKeychain)(deviceId, passphraseState, sessionId);
797
761
  await (0, session_1.preloadSessionFromKeychain)(deviceId);
package/jest.config.js CHANGED
@@ -1,5 +1,4 @@
1
1
  module.exports = {
2
2
  preset: '../../jest.config.js',
3
3
  testEnvironment: 'node',
4
- modulePathIgnorePatterns: ['node_modules', '<rootDir>/dist'],
5
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hardware-cli",
3
- "version": "1.1.27-alpha.40",
3
+ "version": "1.1.27-alpha.5",
4
4
  "description": "OneKey hardware wallet CLI for testing device communication",
5
5
  "author": "OneKey",
6
6
  "license": "Apache-2.0",
@@ -30,11 +30,11 @@
30
30
  "test": "jest"
31
31
  },
32
32
  "dependencies": {
33
- "@onekeyfe/hd-common-connect-sdk": "1.1.27-alpha.40",
34
- "@onekeyfe/hd-core": "1.1.27-alpha.40",
35
- "@onekeyfe/hd-shared": "1.1.27-alpha.40",
36
- "@onekeyfe/hd-transport-usb": "1.1.27-alpha.40",
33
+ "@onekeyfe/hd-common-connect-sdk": "1.1.27-alpha.5",
34
+ "@onekeyfe/hd-core": "1.1.27-alpha.5",
35
+ "@onekeyfe/hd-shared": "1.1.27-alpha.5",
36
+ "@onekeyfe/hd-transport-usb": "1.1.27-alpha.5",
37
37
  "commander": "^12.0.0"
38
38
  },
39
- "gitHead": "484f6253dd8c776fc4037f5da171c8f2226baea6"
39
+ "gitHead": "0c7353e097121596ad4076a531a473408471674c"
40
40
  }
package/src/cli.ts CHANGED
@@ -25,41 +25,6 @@ import type {
25
25
  /** SearchDevice enriched with features fetched after discovery */
26
26
  type EnrichedSearchDevice = SearchDevice & { features?: Features };
27
27
 
28
- function extractPassphraseSession(payload: unknown): {
29
- passphraseState?: string;
30
- sessionId?: string;
31
- } {
32
- if (typeof payload === 'string') {
33
- return { passphraseState: payload };
34
- }
35
- if (!payload || typeof payload !== 'object') {
36
- return {};
37
- }
38
-
39
- const statePayload = payload as {
40
- passphrase_state?: unknown;
41
- passphraseState?: unknown;
42
- session_id?: unknown;
43
- sessionId?: unknown;
44
- };
45
-
46
- let passphraseState: string | undefined;
47
- if (typeof statePayload.passphrase_state === 'string') {
48
- passphraseState = statePayload.passphrase_state;
49
- } else if (typeof statePayload.passphraseState === 'string') {
50
- passphraseState = statePayload.passphraseState;
51
- }
52
-
53
- let sessionId: string | undefined;
54
- if (typeof statePayload.session_id === 'string') {
55
- sessionId = statePayload.session_id;
56
- } else if (typeof statePayload.sessionId === 'string') {
57
- sessionId = statePayload.sessionId;
58
- }
59
-
60
- return { passphraseState, sessionId };
61
- }
62
-
63
28
  const program = new Command();
64
29
 
65
30
  program
@@ -722,16 +687,7 @@ sessionCmd
722
687
  outputResult(globalOpts, psResult);
723
688
  return;
724
689
  }
725
- const { passphraseState, sessionId: passphraseSessionId } = extractPassphraseSession(
726
- psResult.payload
727
- );
728
- if (!passphraseState) {
729
- outputResult(globalOpts, {
730
- success: false,
731
- payload: { error: 'getPassphraseState did not return passphraseState' },
732
- });
733
- return;
734
- }
690
+ const passphraseState = psResult.payload;
735
691
 
736
692
  // 4. Get address to verify + extract deviceId
737
693
  const addrResult = await sdk.evmGetAddress(connectId, device.deviceId || '', {
@@ -756,7 +712,7 @@ sessionCmd
756
712
  });
757
713
  const featPayload = featResult?.success ? featResult.payload : undefined;
758
714
  const deviceId = featPayload?.device_id || device.deviceId || '';
759
- const sessionId = passphraseSessionId || featPayload?.session_id || '';
715
+ const sessionId = featPayload?.session_id || '';
760
716
 
761
717
  // 6. Save to keychain
762
718
  if (passphraseState && deviceId && sessionId) {
@@ -913,7 +869,6 @@ async function prepareSession(
913
869
  deviceId?: string;
914
870
  features?: {
915
871
  device_id?: string;
916
- onekey_device_type?: string;
917
872
  session_id?: string;
918
873
  passphrase_protection?: boolean | null;
919
874
  unlocked?: boolean | null;
@@ -928,7 +883,6 @@ async function prepareSession(
928
883
  // getFeatures failures here are non-fatal — we fall through to Step 3
929
884
  // which will fail with a clearer error if the device is truly unreachable.
930
885
  let deviceId = device.features?.device_id || device.deviceId || '';
931
- let deviceType = device.features?.onekey_device_type;
932
886
  let unlocked = device.features?.unlocked;
933
887
  let passphraseProtection = device.features?.passphrase_protection;
934
888
 
@@ -937,7 +891,6 @@ async function prepareSession(
937
891
  const featResult = await sdk.getFeatures(connectId);
938
892
  if (featResult?.success && featResult.payload) {
939
893
  deviceId = featResult.payload.device_id || deviceId;
940
- deviceType = featResult.payload.onekey_device_type || deviceType;
941
894
  unlocked = featResult.payload.unlocked;
942
895
  passphraseProtection = featResult.payload.passphrase_protection;
943
896
  }
@@ -965,7 +918,7 @@ async function prepareSession(
965
918
  }
966
919
 
967
920
  // ── Step 4: Check passphrase protection ──────────────────────────
968
- if (passphraseProtection === false && deviceType !== 'pro2' && deviceType !== 'PRO2') {
921
+ if (passphraseProtection === false) {
969
922
  return undefined;
970
923
  }
971
924
 
@@ -987,12 +940,7 @@ async function prepareSession(
987
940
  });
988
941
 
989
942
  if (psResult.success && psResult.payload) {
990
- const { passphraseState, sessionId: passphraseSessionId } = extractPassphraseSession(
991
- psResult.payload
992
- );
993
- if (!passphraseState) {
994
- return undefined;
995
- }
943
+ const passphraseState = psResult.payload;
996
944
  globalOpts.passphraseState = passphraseState;
997
945
 
998
946
  // Save session to keychain for next invocation.
@@ -1006,8 +954,7 @@ async function prepareSession(
1006
954
  passphraseState,
1007
955
  skipPassphraseCheck: true,
1008
956
  });
1009
- const sessionId =
1010
- passphraseSessionId || (featAfter?.success ? featAfter.payload?.session_id : undefined);
957
+ const sessionId = featAfter?.success ? featAfter.payload?.session_id : undefined;
1011
958
  if (sessionId) {
1012
959
  await saveSessionToKeychain(deviceId, passphraseState, sessionId);
1013
960
  await preloadSessionFromKeychain(deviceId);