@onekeyfe/hd-core 1.2.0-alpha.43 → 1.2.0-alpha.44

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.
@@ -98,11 +98,14 @@ describe('openWalletSession', () => {
98
98
  deviceWalletSessionStore.clear();
99
99
  });
100
100
 
101
- test('reuses the authoritative Main wallet DeviceStatus', async () => {
101
+ test('selects the standard wallet explicitly when passphrase is enabled', async () => {
102
102
  const typedCall = jest.fn((request: string) => {
103
103
  if (request === 'ProtocolInfoRequest') {
104
104
  return { message: { version: 2 } };
105
105
  }
106
+ if (request === 'DeviceSessionAskPassphrase') {
107
+ return { message: {} };
108
+ }
106
109
  if (request === 'DeviceSessionGet') {
107
110
  return {
108
111
  message: {
@@ -125,6 +128,39 @@ describe('openWalletSession', () => {
125
128
  });
126
129
 
127
130
  expect(device.unlockDevice).not.toHaveBeenCalled();
131
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionAskPassphrase', 'Success', {
132
+ passphrase: '',
133
+ on_device: false,
134
+ });
135
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {
136
+ seed_domains: [],
137
+ });
138
+ });
139
+
140
+ test('opens the standard wallet directly when passphrase is disabled', async () => {
141
+ const typedCall = jest.fn((request: string) => {
142
+ if (request === 'ProtocolInfoRequest') {
143
+ return { message: { version: 2 } };
144
+ }
145
+ if (request === 'DeviceSessionGet') {
146
+ return {
147
+ message: {
148
+ btc_test_address: 'standard-state',
149
+ session_id: 'standard-session',
150
+ },
151
+ };
152
+ }
153
+ throw new Error(`Unexpected request: ${request}`);
154
+ });
155
+ const device = createDevice({ passphraseProtection: false, typedCall });
156
+
157
+ await getProtocolV2WalletSession(device as any, { onlyMainPin: true });
158
+
159
+ expect(typedCall).not.toHaveBeenCalledWith(
160
+ 'DeviceSessionAskPassphrase',
161
+ 'Success',
162
+ expect.anything()
163
+ );
128
164
  expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {
129
165
  seed_domains: [],
130
166
  });
@@ -135,6 +171,9 @@ describe('openWalletSession', () => {
135
171
  if (request === 'ProtocolInfoRequest') {
136
172
  return { message: { version: 2 } };
137
173
  }
174
+ if (request === 'DeviceSessionAskPassphrase') {
175
+ return { message: {} };
176
+ }
138
177
  if (request === 'DeviceSessionGet') {
139
178
  return {
140
179
  message: {
@@ -865,6 +904,7 @@ describe('openWalletSession', () => {
865
904
  const typedCall = jest
866
905
  .fn()
867
906
  .mockResolvedValueOnce({ message: { version: 2 } })
907
+ .mockResolvedValueOnce({ message: {} })
868
908
  .mockResolvedValueOnce({
869
909
  message: {
870
910
  btc_test_address: 'main-wallet-state',
@@ -887,11 +927,15 @@ describe('openWalletSession', () => {
887
927
  passphraseState: null,
888
928
  resumed: false,
889
929
  });
890
- expect(typedCall).toHaveBeenCalledTimes(2);
930
+ expect(typedCall).toHaveBeenCalledTimes(3);
891
931
  expect(typedCall).toHaveBeenCalledWith('ProtocolInfoRequest', 'ProtocolInfo', {
892
932
  eventless_wallet_session: true,
893
933
  });
894
934
  expect(device.unlockDevice).not.toHaveBeenCalled();
935
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionAskPassphrase', 'Success', {
936
+ passphrase: '',
937
+ on_device: false,
938
+ });
895
939
  expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {
896
940
  seed_domains: [],
897
941
  });
@@ -903,6 +947,7 @@ describe('openWalletSession', () => {
903
947
  const typedCall = jest
904
948
  .fn()
905
949
  .mockResolvedValueOnce({ message: { version: 2 } })
950
+ .mockResolvedValueOnce({ message: {} })
906
951
  .mockResolvedValueOnce({
907
952
  message: {
908
953
  btc_test_address: 'main-wallet-state',
@@ -954,6 +999,7 @@ describe('openWalletSession', () => {
954
999
  const typedCall = jest
955
1000
  .fn()
956
1001
  .mockResolvedValueOnce({ message: { version: 2 } })
1002
+ .mockResolvedValueOnce({ message: {} })
957
1003
  .mockResolvedValueOnce({
958
1004
  message: {
959
1005
  btc_test_address: 'main-wallet-state',
@@ -786,6 +786,9 @@ describe('Protocol V2 feature adapter', () => {
786
786
  if (request === 'DeviceStatusGet') {
787
787
  return { type: 'DeviceStatus', message: { unlocked: true } };
788
788
  }
789
+ if (request === 'DeviceSessionAskPassphrase') {
790
+ return { type: 'Success', message: {} };
791
+ }
789
792
  if (request === 'DeviceSessionGet') {
790
793
  return {
791
794
  type: 'DeviceSession',
@@ -819,6 +822,10 @@ describe('Protocol V2 feature adapter', () => {
819
822
  expect(typedCall).toHaveBeenCalledWith('DeviceSessionAskPin', 'Success', {
820
823
  type: DeviceSessionPinType.Main,
821
824
  });
825
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionAskPassphrase', 'Success', {
826
+ passphrase: '',
827
+ on_device: false,
828
+ });
822
829
  expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {
823
830
  seed_domains: [],
824
831
  });
@@ -854,6 +861,7 @@ describe('Protocol V2 feature adapter', () => {
854
861
  },
855
862
  };
856
863
  }
864
+ if (request === 'DeviceSessionAskPassphrase') return { message: {} };
857
865
  if (request === 'DeviceSessionGet') {
858
866
  return {
859
867
  message: {
@@ -870,6 +878,9 @@ describe('Protocol V2 feature adapter', () => {
870
878
  await getProtocolV2WalletSession(device, { onlyMainPin: true });
871
879
 
872
880
  expect(typedCall.mock.calls.filter(call => call[0] === 'DeviceSessionAskPin')).toHaveLength(1);
881
+ expect(
882
+ typedCall.mock.calls.filter(call => call[0] === 'DeviceSessionAskPassphrase')
883
+ ).toHaveLength(1);
873
884
  expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {
874
885
  seed_domains: [],
875
886
  });
@@ -918,6 +929,7 @@ describe('Protocol V2 feature adapter', () => {
918
929
  },
919
930
  };
920
931
  }
932
+ if (request === 'DeviceSessionAskPassphrase') return { message: {} };
921
933
  if (request === 'DeviceSessionAskPin') {
922
934
  return { type: 'Success', message: { message: 'PIN verified' } };
923
935
  }
@@ -1012,6 +1024,7 @@ describe('Protocol V2 feature adapter', () => {
1012
1024
  if (request === 'DeviceStatusGet') {
1013
1025
  return { message: { device_id: deviceId, unlocked: true, passphrase_enabled: true } };
1014
1026
  }
1027
+ if (request === 'DeviceSessionAskPassphrase') return { message: {} };
1015
1028
  if (request === 'DeviceSessionGet') {
1016
1029
  sessionGetCalls += 1;
1017
1030
  return {
@@ -2415,13 +2428,18 @@ describe('Protocol V2 feature adapter', () => {
2415
2428
  await expect(
2416
2429
  device.checkPassphraseStateSafety('stale-hidden-state', true, false)
2417
2430
  ).resolves.toBe(true);
2418
- expect(typedCall).toHaveBeenCalledTimes(2);
2431
+ expect(typedCall).toHaveBeenCalledTimes(4);
2419
2432
  expect(typedCall).toHaveBeenCalledWith('ProtocolInfoRequest', 'ProtocolInfo', {
2420
2433
  eventless_wallet_session: true,
2421
2434
  });
2422
2435
  expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {
2423
2436
  seed_domains: [],
2424
2437
  });
2438
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionAskPassphrase', 'Success', {
2439
+ passphrase: '',
2440
+ on_device: false,
2441
+ });
2442
+ expect(typedCall).toHaveBeenCalledWith('DeviceStatusGet', 'DeviceStatus', {});
2425
2443
  expect(typedCall).not.toHaveBeenCalledWith('DeviceSessionAskPin', 'Success', expect.anything());
2426
2444
  });
2427
2445
 
package/dist/index.js CHANGED
@@ -40428,7 +40428,7 @@ function getProtocolV2WalletSession(device, options) {
40428
40428
  : undefined;
40429
40429
  let response;
40430
40430
  let resumed = false;
40431
- let mainWalletSelected = (options === null || options === void 0 ? void 0 : options.onlyMainPin) === true &&
40431
+ let mainPinSelected = (options === null || options === void 0 ? void 0 : options.onlyMainPin) === true &&
40432
40432
  ((_d = device.features) === null || _d === void 0 ? void 0 : _d.unlocked) === true &&
40433
40433
  ((_e = device.features) === null || _e === void 0 ? void 0 : _e.unlockedAttachPin) === false;
40434
40434
  const clearCurrentWalletSession = () => {
@@ -40453,14 +40453,24 @@ function getProtocolV2WalletSession(device, options) {
40453
40453
  clearCurrentWalletSession();
40454
40454
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckUnlockTypeError);
40455
40455
  });
40456
- const selectMainWallet = (force = false) => __awaiter(this, void 0, void 0, function* () {
40457
- if (force || !mainWalletSelected) {
40456
+ const selectMainPin = (force = false) => __awaiter(this, void 0, void 0, function* () {
40457
+ if (force || !mainPinSelected) {
40458
40458
  yield device.unlockDevice(hdTransport.DeviceSessionPinType.Main, {
40459
40459
  source: 'wallet-session-coordinator',
40460
40460
  reason: expectedPassphraseState ? 'session-recovery' : 'open-wallet',
40461
40461
  deviceOnly: true,
40462
40462
  });
40463
- mainWalletSelected = true;
40463
+ mainPinSelected = true;
40464
+ }
40465
+ });
40466
+ const selectStandardWallet = () => __awaiter(this, void 0, void 0, function* () {
40467
+ var _l;
40468
+ yield selectMainPin();
40469
+ if (((_l = device.features) === null || _l === void 0 ? void 0 : _l.passphraseProtection) === true) {
40470
+ yield askDevicePassphrase(device, {
40471
+ passphrase: '',
40472
+ on_device: false,
40473
+ });
40464
40474
  }
40465
40475
  });
40466
40476
  if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
@@ -40468,7 +40478,7 @@ function getProtocolV2WalletSession(device, options) {
40468
40478
  if (cachedStandardSession) {
40469
40479
  try {
40470
40480
  if (options === null || options === void 0 ? void 0 : options.selectMainWalletBeforeRestore) {
40471
- yield selectMainWallet();
40481
+ yield selectMainPin();
40472
40482
  }
40473
40483
  response = yield getDeviceSession(device, buildDeviceSessionGetRequest({
40474
40484
  sessionId: cachedStandardSession.sessionId,
@@ -40486,7 +40496,7 @@ function getProtocolV2WalletSession(device, options) {
40486
40496
  }
40487
40497
  }
40488
40498
  if (!response) {
40489
- yield selectMainWallet();
40499
+ yield selectStandardWallet();
40490
40500
  response = yield getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano: options === null || options === void 0 ? void 0 : options.deriveCardano }));
40491
40501
  }
40492
40502
  }
@@ -40549,7 +40559,7 @@ function getProtocolV2WalletSession(device, options) {
40549
40559
  }
40550
40560
  if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
40551
40561
  (_h = device.clearStandardInternalState) === null || _h === void 0 ? void 0 : _h.call(device);
40552
- yield selectMainWallet(true);
40562
+ yield selectStandardWallet();
40553
40563
  response = yield getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano: options === null || options === void 0 ? void 0 : options.deriveCardano }));
40554
40564
  }
40555
40565
  else {
@@ -40591,7 +40601,7 @@ function getProtocolV2WalletSession(device, options) {
40591
40601
  return {
40592
40602
  passphraseState: message.btc_test_address,
40593
40603
  newSession: message.session_id,
40594
- unlockedAttachPin: mainWalletSelected ? false : undefined,
40604
+ unlockedAttachPin: mainPinSelected ? false : undefined,
40595
40605
  resumed,
40596
40606
  };
40597
40607
  });
@@ -1 +1 @@
1
- {"version":3,"file":"walletSession.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/walletSession.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAuBlD,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,0DAGjE;AAED,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,qCAGjE;AAED,wBAAsB,qCAAqC,CAAC,MAAM,EAAE,MAAM,oBAgBzE;AAsHD,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;;;;;GAmNF;AAED,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,MAAM,EACd,uBAAuB,EAAE,MAAM,EAC/B,aAAa,CAAC,EAAE,OAAO;;;;;GAOxB"}
1
+ {"version":3,"file":"walletSession.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/walletSession.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAuBlD,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,0DAGjE;AAED,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,qCAGjE;AAED,wBAAsB,qCAAqC,CAAC,MAAM,EAAE,MAAM,oBAgBzE;AAsHD,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;;;;;GA8NF;AAED,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,MAAM,EACd,uBAAuB,EAAE,MAAM,EAC/B,aAAa,CAAC,EAAE,OAAO;;;;;GAOxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.0-alpha.43",
3
+ "version": "1.2.0-alpha.44",
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.0-alpha.43",
29
- "@onekeyfe/hd-transport": "1.2.0-alpha.43",
28
+ "@onekeyfe/hd-shared": "1.2.0-alpha.44",
29
+ "@onekeyfe/hd-transport": "1.2.0-alpha.44",
30
30
  "axios": "1.15.2",
31
31
  "bignumber.js": "^9.0.2",
32
32
  "bytebuffer": "^5.0.1",
@@ -44,5 +44,5 @@
44
44
  "@types/w3c-web-usb": "^1.0.10",
45
45
  "@types/web-bluetooth": "^0.0.21"
46
46
  },
47
- "gitHead": "2ea7c9d60472502a272a57f808aed3773ccd84c4"
47
+ "gitHead": "6de180b61cd4a64f41cf4ffd32eeb8a1cc4e64e7"
48
48
  }
@@ -215,7 +215,7 @@ export async function getProtocolV2WalletSession(
215
215
  : undefined;
216
216
  let response;
217
217
  let resumed = false;
218
- let mainWalletSelected =
218
+ let mainPinSelected =
219
219
  options?.onlyMainPin === true &&
220
220
  device.features?.unlocked === true &&
221
221
  device.features?.unlockedAttachPin === false;
@@ -243,14 +243,25 @@ export async function getProtocolV2WalletSession(
243
243
  throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckUnlockTypeError);
244
244
  };
245
245
 
246
- const selectMainWallet = async (force = false) => {
247
- if (force || !mainWalletSelected) {
246
+ const selectMainPin = async (force = false) => {
247
+ if (force || !mainPinSelected) {
248
248
  await device.unlockDevice(DeviceSessionPinType.Main, {
249
249
  source: 'wallet-session-coordinator',
250
250
  reason: expectedPassphraseState ? 'session-recovery' : 'open-wallet',
251
251
  deviceOnly: true,
252
252
  });
253
- mainWalletSelected = true;
253
+ mainPinSelected = true;
254
+ }
255
+ };
256
+
257
+ const selectStandardWallet = async () => {
258
+ // Main PIN authenticates the device; an empty host passphrase selects the standard derivation.
259
+ await selectMainPin();
260
+ if (device.features?.passphraseProtection === true) {
261
+ await askDevicePassphrase(device, {
262
+ passphrase: '',
263
+ on_device: false,
264
+ });
254
265
  }
255
266
  };
256
267
 
@@ -259,7 +270,7 @@ export async function getProtocolV2WalletSession(
259
270
  if (cachedStandardSession) {
260
271
  try {
261
272
  if (options?.selectMainWalletBeforeRestore) {
262
- await selectMainWallet();
273
+ await selectMainPin();
263
274
  }
264
275
  response = await getDeviceSession(
265
276
  device,
@@ -280,7 +291,7 @@ export async function getProtocolV2WalletSession(
280
291
  }
281
292
 
282
293
  if (!response) {
283
- await selectMainWallet();
294
+ await selectStandardWallet();
284
295
  response = await getDeviceSession(
285
296
  device,
286
297
  buildDeviceSessionGetRequest({ deriveCardano: options?.deriveCardano })
@@ -348,7 +359,7 @@ export async function getProtocolV2WalletSession(
348
359
  }
349
360
  if (options?.onlyMainPin) {
350
361
  device.clearStandardInternalState?.();
351
- await selectMainWallet(true);
362
+ await selectStandardWallet();
352
363
  response = await getDeviceSession(
353
364
  device,
354
365
  buildDeviceSessionGetRequest({ deriveCardano: options?.deriveCardano })
@@ -391,7 +402,7 @@ export async function getProtocolV2WalletSession(
391
402
  return {
392
403
  passphraseState: message.btc_test_address,
393
404
  newSession: message.session_id,
394
- unlockedAttachPin: mainWalletSelected ? false : undefined,
405
+ unlockedAttachPin: mainPinSelected ? false : undefined,
395
406
  resumed,
396
407
  };
397
408
  }