@onekeyfe/hd-core 1.2.2-alpha.1 → 1.2.2-alpha.2

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.
@@ -63,32 +63,37 @@ 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 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.
66
76
  const buildDeviceSessionGetRequest = ({
67
77
  sessionId,
68
78
  expectedPassphraseState,
69
- deriveCardano,
70
79
  }: {
71
80
  sessionId?: string;
72
81
  expectedPassphraseState?: string;
73
- deriveCardano?: boolean;
74
82
  } = {}): DeviceSessionGet => ({
75
83
  ...(sessionId ? { session_id: sessionId } : {}),
76
84
  ...(expectedPassphraseState ? { btc_test_address: expectedPassphraseState } : {}),
77
- seed_domains:
78
- deriveCardano === undefined
79
- ? []
80
- : [
81
- DeviceSessionSeedDomain.SeedDomain_Standard,
82
- ...(deriveCardano ? [DeviceSessionSeedDomain.SeedDomain_Cardano] : []),
83
- ],
84
85
  });
85
86
 
86
87
  const askDevicePassphrase = async (
87
88
  device: Device,
88
- requestPayload: DeviceSessionAskPassphrase,
89
+ requestPayload: Omit<DeviceSessionAskPassphrase, 'seed_domains'>,
90
+ deriveCardano?: boolean,
89
91
  onStatusRefreshed?: () => void
90
92
  ) => {
91
- await device.commands.typedCall('DeviceSessionAskPassphrase', 'Success', requestPayload);
93
+ await device.commands.typedCall('DeviceSessionAskPassphrase', 'Success', {
94
+ ...requestPayload,
95
+ seed_domains: buildDeviceSessionSeedDomains(deriveCardano),
96
+ });
92
97
  await refreshProtocolV2DeviceStatus(device);
93
98
  onStatusRefreshed?.();
94
99
  };
@@ -160,7 +165,7 @@ const selectDeviceSession = async (
160
165
  interaction: attachPinInteraction,
161
166
  });
162
167
  onStatusRefreshed?.();
163
- return getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano }));
168
+ return getDeviceSession(device, buildDeviceSessionGetRequest());
164
169
  }
165
170
 
166
171
  if (hasHostPassphrase) {
@@ -170,9 +175,10 @@ const selectDeviceSession = async (
170
175
  passphrase: hostPassphrase,
171
176
  on_device: false,
172
177
  },
178
+ deriveCardano,
173
179
  onStatusRefreshed
174
180
  );
175
- return getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano }));
181
+ return getDeviceSession(device, buildDeviceSessionGetRequest());
176
182
  }
177
183
 
178
184
  const passphraseOnDeviceInteraction = device.createProtocolV2UiPhaseMetadata?.(
@@ -183,8 +189,8 @@ const selectDeviceSession = async (
183
189
  ...metadata,
184
190
  ...(passphraseOnDeviceInteraction ? { interaction: passphraseOnDeviceInteraction } : {}),
185
191
  });
186
- await askDevicePassphrase(device, { on_device: true }, onStatusRefreshed);
187
- return getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano }));
192
+ await askDevicePassphrase(device, { on_device: true }, deriveCardano, onStatusRefreshed);
193
+ return getDeviceSession(device, buildDeviceSessionGetRequest());
188
194
  };
189
195
 
190
196
  export async function getProtocolV2WalletSession(
@@ -307,6 +313,7 @@ export async function getProtocolV2WalletSession(
307
313
  passphrase: '',
308
314
  on_device: false,
309
315
  },
316
+ options?.deriveCardano,
310
317
  markWalletStatusRefreshed
311
318
  );
312
319
  standardWalletSelected = true;
@@ -329,10 +336,7 @@ export async function getProtocolV2WalletSession(
329
336
  device.clearInternalState();
330
337
  throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckUnlockTypeError);
331
338
  }
332
- response = await getDeviceSession(
333
- device,
334
- buildDeviceSessionGetRequest({ deriveCardano: options?.deriveCardano })
335
- );
339
+ response = await getDeviceSession(device, buildDeviceSessionGetRequest());
336
340
  } else if (options?.onlyMainPin) {
337
341
  expectedPassphraseState = cachedStandardSession?.passphraseState;
338
342
  if (cachedStandardSession) {
@@ -345,7 +349,6 @@ export async function getProtocolV2WalletSession(
345
349
  buildDeviceSessionGetRequest({
346
350
  sessionId: cachedStandardSession.sessionId,
347
351
  expectedPassphraseState,
348
- deriveCardano: options?.deriveCardano,
349
352
  })
350
353
  );
351
354
  resumed = true;
@@ -360,10 +363,7 @@ export async function getProtocolV2WalletSession(
360
363
 
361
364
  if (!response) {
362
365
  await selectStandardWallet();
363
- response = await getDeviceSession(
364
- device,
365
- buildDeviceSessionGetRequest({ deriveCardano: options?.deriveCardano })
366
- );
366
+ response = await getDeviceSession(device, buildDeviceSessionGetRequest());
367
367
  }
368
368
  } else if (cachedSessionId && expectedPassphraseState) {
369
369
  try {
@@ -372,7 +372,6 @@ export async function getProtocolV2WalletSession(
372
372
  buildDeviceSessionGetRequest({
373
373
  sessionId: cachedSessionId,
374
374
  expectedPassphraseState,
375
- deriveCardano: options?.deriveCardano,
376
375
  })
377
376
  );
378
377
  resumed = true;
@@ -389,7 +388,6 @@ export async function getProtocolV2WalletSession(
389
388
  device,
390
389
  buildDeviceSessionGetRequest({
391
390
  expectedPassphraseState,
392
- deriveCardano: options?.deriveCardano,
393
391
  })
394
392
  );
395
393
  } catch (error) {
@@ -433,10 +431,7 @@ export async function getProtocolV2WalletSession(
433
431
  if (options?.onlyMainPin) {
434
432
  device.clearStandardInternalState?.();
435
433
  await selectStandardWallet();
436
- response = await getDeviceSession(
437
- device,
438
- buildDeviceSessionGetRequest({ deriveCardano: options?.deriveCardano })
439
- );
434
+ response = await getDeviceSession(device, buildDeviceSessionGetRequest());
440
435
  } else {
441
436
  device.clearInternalState();
442
437
  response = await selectDeviceSession(