@onekeyfe/hd-core 1.2.2-alpha.3 → 1.2.2-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.2-alpha.3",
3
+ "version": "1.2.2-alpha.5",
4
4
  "description": "Core processes and APIs for communicating with OneKey hardware devices.",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,8 +25,8 @@
25
25
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@onekeyfe/hd-shared": "1.2.2-alpha.3",
29
- "@onekeyfe/hd-transport": "1.2.2-alpha.3",
28
+ "@onekeyfe/hd-shared": "1.2.2-alpha.5",
29
+ "@onekeyfe/hd-transport": "1.2.2-alpha.5",
30
30
  "axios": "1.15.2",
31
31
  "bignumber.js": "^9.0.2",
32
32
  "buffer": "^6.0.3",
@@ -46,5 +46,5 @@
46
46
  "@types/w3c-web-usb": "^1.0.10",
47
47
  "@types/web-bluetooth": "^0.0.21"
48
48
  },
49
- "gitHead": "4efa66df8851607586d0ae6a431a63404beff51b"
49
+ "gitHead": "82503995b10dd1e293941594239423e3c640973b"
50
50
  }
@@ -160,7 +160,6 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
160
160
  const session = isProtocolV2
161
161
  ? await getProtocolV2WalletSession(this.device, {
162
162
  onlyMainPin: true,
163
- deriveCardano: this.payload.deriveCardano,
164
163
  selectMainWalletBeforeRestore:
165
164
  !hasAuthoritativeProtocolV2WalletStatus(state) ||
166
165
  state.status.unlockedAttachPin === true,
@@ -225,7 +224,6 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
225
224
  const session = isProtocolV2
226
225
  ? await getProtocolV2WalletSession(this.device, {
227
226
  expectedPassphraseState: this.params.passphraseState,
228
- deriveCardano: this.payload.deriveCardano,
229
227
  })
230
228
  : await getPassphraseStateWithRefreshDeviceInfo(this.device, {
231
229
  expectPassphraseState: this.params.passphraseState,
@@ -257,7 +255,6 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
257
255
  ...(readCurrentAttachPinSession
258
256
  ? { readCurrentAttachPinSession: true }
259
257
  : { forceWalletSelection: true }),
260
- deriveCardano: this.payload.deriveCardano,
261
258
  })
262
259
  : await getPassphraseStateWithRefreshDeviceInfo(this.device, { initSession: true });
263
260
  const refreshedState = isProtocolV2
@@ -393,8 +393,8 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
393
393
  // the root fingerprint, so each nested chain method must resume the
394
394
  // requested standard or hidden wallet before sending its device command.
395
395
  const useEmptyPassphrase = this.payload.useEmptyPassphrase === true;
396
- // false would AskPassphrase with [Standard] only and permanently drop Cardano
397
- // from a reused session. Omit the flag for non-Cardano nested methods.
396
+ // Nested Cardano methods opt in to [Standard, Cardano] if Ask rebuilds.
397
+ // Other chains stay Standard-only.
398
398
  const deriveCardano = method.name.startsWith('cardano') ? true : undefined;
399
399
  const shouldResumeWalletSession = useEmptyPassphrase || !!this.payload.passphraseState;
400
400
  if (this.device.isProtocolV2() && shouldResumeWalletSession) {
package/src/core/index.ts CHANGED
@@ -105,8 +105,10 @@ function resolveDeriveCardano(method: BaseMethod): boolean | undefined {
105
105
  if (method.name.startsWith('cardano')) {
106
106
  return true;
107
107
  }
108
- if (typeof method.payload?.deriveCardano === 'boolean') {
109
- return method.payload.deriveCardano;
108
+ // V1 Initialize only sends derive_cardano on an explicit true.
109
+ // V2 AskPassphrase maps true to [Standard, Cardano] and anything else to [Standard].
110
+ if (method.payload?.deriveCardano === true) {
111
+ return true;
110
112
  }
111
113
  return undefined;
112
114
  }
@@ -12334,6 +12334,11 @@
12334
12334
  "btc_test_address": {
12335
12335
  "type": "string",
12336
12336
  "id": 2
12337
+ },
12338
+ "seed_domains": {
12339
+ "rule": "repeated",
12340
+ "type": "DeviceSessionSeedDomain",
12341
+ "id": 3
12337
12342
  }
12338
12343
  }
12339
12344
  },
@@ -12847,57 +12852,36 @@
12847
12852
  },
12848
12853
  "reserved": [[2, 2], "placeholder"]
12849
12854
  },
12850
- "ViewContentPreview": {
12855
+ "ViewData": {
12851
12856
  "fields": {
12852
- "content_key": {
12853
- "rule": "required",
12854
- "type": "uint32",
12855
- "id": 1
12856
- },
12857
12857
  "preview": {
12858
12858
  "rule": "required",
12859
12859
  "type": "bytes",
12860
- "id": 2
12860
+ "id": 1
12861
12861
  },
12862
12862
  "total_bytes": {
12863
+ "rule": "required",
12863
12864
  "type": "uint32",
12864
- "id": 3
12865
+ "id": 2
12865
12866
  }
12866
12867
  }
12867
12868
  },
12868
- "ViewContentEntry": {
12869
+ "ViewDataPage": {
12869
12870
  "fields": {
12870
- "entry_key": {
12871
+ "chunk": {
12871
12872
  "rule": "required",
12872
- "type": "uint32",
12873
+ "type": "bytes",
12873
12874
  "id": 1
12874
12875
  },
12875
- "value": {
12876
- "rule": "required",
12877
- "type": "bytes",
12878
- "id": 2
12879
- }
12880
- }
12881
- },
12882
- "ViewContentPage": {
12883
- "fields": {
12884
12876
  "page_index": {
12885
12877
  "rule": "required",
12886
12878
  "type": "uint32",
12887
- "id": 1
12879
+ "id": 2
12888
12880
  },
12889
12881
  "page_count": {
12890
12882
  "rule": "required",
12891
12883
  "type": "uint32",
12892
- "id": 2
12893
- },
12894
- "chunk": {
12895
- "type": "bytes",
12896
12884
  "id": 3
12897
- },
12898
- "entry": {
12899
- "type": "ViewContentEntry",
12900
- "id": 4
12901
12885
  }
12902
12886
  }
12903
12887
  },
@@ -12956,8 +12940,8 @@
12956
12940
  "type": "string",
12957
12941
  "id": 9
12958
12942
  },
12959
- "content": {
12960
- "type": "ViewContentPreview",
12943
+ "data": {
12944
+ "type": "ViewData",
12961
12945
  "id": 10
12962
12946
  },
12963
12947
  "custom_field": {
@@ -12981,10 +12965,6 @@
12981
12965
  "text_arg": {
12982
12966
  "type": "string",
12983
12967
  "id": 3
12984
- },
12985
- "cancellable": {
12986
- "type": "bool",
12987
- "id": 4
12988
12968
  }
12989
12969
  }
12990
12970
  },
@@ -13023,10 +13003,6 @@
13023
13003
  "chain_id": {
13024
13004
  "type": "uint32",
13025
13005
  "id": 8
13026
- },
13027
- "content": {
13028
- "type": "ViewContentPreview",
13029
- "id": 9
13030
13006
  }
13031
13007
  }
13032
13008
  },
@@ -63,16 +63,22 @@ const negotiateEventlessWalletSession = async (device: Device) => {
63
63
  const getDeviceSession = async (device: Device, request: DeviceSessionGet) =>
64
64
  device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
65
65
 
66
+ const STANDARD_SEED_DOMAINS = [DeviceSessionSeedDomain.SeedDomain_Standard];
67
+ const CARDANO_SEED_DOMAINS = [
68
+ DeviceSessionSeedDomain.SeedDomain_Standard,
69
+ DeviceSessionSeedDomain.SeedDomain_Cardano,
70
+ ];
71
+
66
72
  const buildDeviceSessionSeedDomains = (deriveCardano?: boolean): DeviceSessionSeedDomain[] =>
67
- deriveCardano === undefined
68
- ? []
69
- : [
70
- DeviceSessionSeedDomain.SeedDomain_Standard,
71
- ...(deriveCardano ? [DeviceSessionSeedDomain.SeedDomain_Cardano] : []),
72
- ];
73
-
74
- // Seed domains are applied when creating a passphrase session, not when reading/resuming one.
75
- // Current firmware rejects unknown DeviceSessionGet fields, including leftover seed_domains.
73
+ deriveCardano === true ? CARDANO_SEED_DOMAINS : STANDARD_SEED_DOMAINS;
74
+
75
+ const deviceSessionHasCardano = (message: { seed_domains?: DeviceSessionSeedDomain[] }) =>
76
+ Array.isArray(message.seed_domains) &&
77
+ message.seed_domains.includes(DeviceSessionSeedDomain.SeedDomain_Cardano);
78
+
79
+ // AskPassphrase.seed_domains selects which seeds to generate. DeviceSessionGet
80
+ // only resumes or reads the current session; firmware rejects unknown Get
81
+ // fields, including leftover seed_domains.
76
82
  const buildDeviceSessionGetRequest = ({
77
83
  sessionId,
78
84
  expectedPassphraseState,
@@ -459,6 +465,38 @@ export async function getProtocolV2WalletSession(
459
465
  }
460
466
  }
461
467
 
468
+ // DeviceSession.seed_domains reports what the SE already generated. Get
469
+ // cannot add Cardano, so a Cardano call on a Standard-only session must Ask again.
470
+ if (options?.deriveCardano === true && !deviceSessionHasCardano(message)) {
471
+ if (options?.resumeOnly) {
472
+ device.clearInternalState();
473
+ throw ERRORS.TypedError(HardwareErrorCode.WalletSessionInvalid);
474
+ }
475
+ resumed = false;
476
+ if (options?.onlyMainPin) {
477
+ await selectStandardWallet();
478
+ response = await getDeviceSession(device, buildDeviceSessionGetRequest());
479
+ } else {
480
+ response = await selectDeviceSession(
481
+ device,
482
+ expectedPassphraseState,
483
+ true,
484
+ markWalletStatusRefreshed
485
+ );
486
+ }
487
+ message = response.message;
488
+ try {
489
+ assertCompleteDeviceSession(message);
490
+ } catch (error) {
491
+ if (options?.onlyMainPin) {
492
+ device.clearStandardInternalState?.();
493
+ } else {
494
+ device.clearInternalState();
495
+ }
496
+ throw error;
497
+ }
498
+ }
499
+
462
500
  const internalStateArgs = [
463
501
  true,
464
502
  message.btc_test_address,