@onekeyfe/hd-core 1.2.0-alpha.1 → 1.2.0-alpha.3

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.
@@ -370,6 +370,57 @@ describe('Protocol V2 feature adapter', () => {
370
370
  expect(getFeatures).not.toHaveBeenCalled();
371
371
  });
372
372
 
373
+ test('honors initSession when getting Pro2 passphrase state', async () => {
374
+ const features = {
375
+ deviceId: 'pro2-device-id',
376
+ deviceType: 'pro2',
377
+ firmwareVersion: '9.9.9',
378
+ passphraseProtection: true,
379
+ sessionId: 'old-feature-session',
380
+ unlockedAttachPin: false,
381
+ };
382
+ const typedCall = jest.fn().mockResolvedValue({
383
+ type: 'PassphraseState',
384
+ message: {
385
+ passphrase_state: 'state-pro2-new',
386
+ unlocked_attach_pin: false,
387
+ },
388
+ });
389
+ const clearInternalState = jest.fn();
390
+ const updateInternalState = jest.fn();
391
+ const method = new GetPassphraseState({
392
+ payload: {
393
+ method: 'getPassphraseState',
394
+ connectId: 'connect-id',
395
+ initSession: true,
396
+ },
397
+ });
398
+ method.device = stubDevice({
399
+ originalDescriptor: { ...descriptor, protocolType: 'V2' },
400
+ features,
401
+ commands: { typedCall },
402
+ clearInternalState,
403
+ updateInternalState,
404
+ getCurrentDeviceId: () => 'pro2-device-id',
405
+ getCurrentPassphraseProtection: () => true,
406
+ }) as any;
407
+
408
+ await expect(method.run()).resolves.toEqual({
409
+ passphraseState: 'state-pro2-new',
410
+ sessionId: undefined,
411
+ unlockedAttachPin: false,
412
+ passphraseProtection: true,
413
+ });
414
+ expect(clearInternalState).toHaveBeenCalledTimes(1);
415
+ expect(updateInternalState).toHaveBeenCalledWith(
416
+ true,
417
+ 'state-pro2-new',
418
+ 'pro2-device-id',
419
+ undefined,
420
+ null
421
+ );
422
+ });
423
+
373
424
  test('stores Pro2 passphrase session cache without synthetic device id', async () => {
374
425
  const device = Device.fromDescriptor({ ...descriptor, protocolType: 'V2' } as any);
375
426
  const typedCall = jest.fn().mockResolvedValue({
@@ -1 +1 @@
1
- {"version":3,"file":"GetPassphraseState.d.ts","sourceRoot":"","sources":["../../src/api/GetPassphraseState.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,UAAU;IACxD,IAAI;IAKE,GAAG;;;;;;CAqBV"}
1
+ {"version":3,"file":"GetPassphraseState.d.ts","sourceRoot":"","sources":["../../src/api/GetPassphraseState.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,UAAU;IACxD,IAAI;IAKE,GAAG;;;;;;CAwBV"}
@@ -5,7 +5,6 @@ export default class TronSignMessage extends BaseMethod<HardwareTronSignMessage>
5
5
  getVersionRange(): {
6
6
  pro2: {
7
7
  min: string;
8
- unsupported: boolean;
9
8
  };
10
9
  model_mini: {
11
10
  min: string;
@@ -1 +1 @@
1
- {"version":3,"file":"TronSignMessage.d.ts","sourceRoot":"","sources":["../../../src/api/tron/TronSignMessage.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,OAAO,KAAK,EAAE,eAAe,IAAI,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEzF,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU,CAAC,uBAAuB,CAAC;IAC9E,IAAI;IAgCJ,eAAe;;;;;;;;;IAYf,wBAAwB;;;;;;;;;;;;;;IAiBlB,GAAG;CAmBV"}
1
+ {"version":3,"file":"TronSignMessage.d.ts","sourceRoot":"","sources":["../../../src/api/tron/TronSignMessage.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,OAAO,KAAK,EAAE,eAAe,IAAI,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEzF,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU,CAAC,uBAAuB,CAAC;IAC9E,IAAI;IAgCJ,eAAe;;;;;;;;IAWf,wBAAwB;;;;;;;;;;;;;;IAiBlB,GAAG;CAmBV"}
@@ -8,7 +8,6 @@ export default class TronSignTransaction extends BaseMethod<TronSignTx> {
8
8
  getVersionRange(): {
9
9
  pro2: {
10
10
  min: string;
11
- unsupported: boolean;
12
11
  };
13
12
  model_mini: {
14
13
  min: string;
@@ -1 +1 @@
1
- {"version":3,"file":"TronSignTransaction.d.ts","sourceRoot":"","sources":["../../../src/api/tron/TronSignTransaction.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,UAAU,CAAC,UAAU,CAAC;IACrE,OAAO,CAAC,EAAE,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,UAAU;IA6G7D,IAAI;IA0BJ,eAAe;;;;;;;;;IAYf,0BAA0B,IAAI,mBAAmB;IAcjD,uCAAuC;IASvC,6CAA6C,IAAI,mBAAmB;IAcpE,sCAAsC;IAWhC,GAAG;CAUV"}
1
+ {"version":3,"file":"TronSignTransaction.d.ts","sourceRoot":"","sources":["../../../src/api/tron/TronSignTransaction.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,UAAU,CAAC,UAAU,CAAC;IACrE,OAAO,CAAC,EAAE,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,UAAU;IA6G7D,IAAI;IA0BJ,eAAe;;;;;;;;IAWf,0BAA0B,IAAI,mBAAmB;IAcjD,uCAAuC;IASvC,6CAA6C,IAAI,mBAAmB;IAcpE,sCAAsC;IAWhC,GAAG;CAUV"}
package/dist/index.js CHANGED
@@ -39211,6 +39211,9 @@ const getPassphraseStateWithRefreshDeviceInfo = (device, options) => __awaiter(v
39211
39211
  const { features } = device;
39212
39212
  const locked = (features === null || features === void 0 ? void 0 : features.unlocked) === false;
39213
39213
  const deviceType = device.getCurrentDeviceType();
39214
+ if (options === null || options === void 0 ? void 0 : options.initSession) {
39215
+ device.clearInternalState();
39216
+ }
39214
39217
  const { passphraseState, newSession, unlockedAttachPin } = yield getPassphraseState(device, Object.assign({}, options));
39215
39218
  const isModeT = deviceType === hdShared.EDeviceType.Touch ||
39216
39219
  deviceType === hdShared.EDeviceType.Pro ||
@@ -39221,7 +39224,7 @@ const getPassphraseStateWithRefreshDeviceInfo = (device, options) => __awaiter(v
39221
39224
  yield device.getFeatures();
39222
39225
  }
39223
39226
  const deviceId = device.getCurrentDeviceId();
39224
- device.updateInternalState((_a = device.getCurrentPassphraseProtection()) !== null && _a !== void 0 ? _a : false, passphraseState, deviceId, newSession, (_b = device.features) === null || _b === void 0 ? void 0 : _b.sessionId);
39227
+ device.updateInternalState((_a = device.getCurrentPassphraseProtection()) !== null && _a !== void 0 ? _a : false, passphraseState, deviceId, newSession, (options === null || options === void 0 ? void 0 : options.initSession) ? null : (_b = device.features) === null || _b === void 0 ? void 0 : _b.sessionId);
39225
39228
  return { passphraseState, newSession, unlockedAttachPin };
39226
39229
  });
39227
39230
  const supportProSeriesAttachPinPassphrase = (deviceType, firmwareVersion) => deviceType === hdShared.EDeviceType.Pro && semver__default["default"].gte(firmwareVersion, '4.15.0');
@@ -43083,6 +43086,7 @@ class GetPassphraseState extends BaseMethod {
43083
43086
  expectPassphraseState: this.payload.passphraseState,
43084
43087
  onlyMainPin: this.payload.useEmptyPassphrase,
43085
43088
  allowCreateAttachPin: this.payload.allowCreateAttachPin,
43089
+ initSession: this.payload.initSession,
43086
43090
  });
43087
43091
  const { features } = this.device;
43088
43092
  const passphraseProtection = (_a = this.device.getCurrentPassphraseProtection()) !== null && _a !== void 0 ? _a : null;
@@ -43090,7 +43094,9 @@ class GetPassphraseState extends BaseMethod {
43090
43094
  const isProSeries = deviceType === hdShared.EDeviceType.Pro || deviceType === hdShared.EDeviceType.Pro2;
43091
43095
  return Promise.resolve({
43092
43096
  passphraseState: isProSeries || passphraseProtection === true ? passphraseState : undefined,
43093
- sessionId: (_b = newSession !== null && newSession !== void 0 ? newSession : features === null || features === void 0 ? void 0 : features.sessionId) !== null && _b !== void 0 ? _b : undefined,
43097
+ sessionId: this.payload.initSession
43098
+ ? newSession !== null && newSession !== void 0 ? newSession : undefined
43099
+ : (_b = newSession !== null && newSession !== void 0 ? newSession : features === null || features === void 0 ? void 0 : features.sessionId) !== null && _b !== void 0 ? _b : undefined,
43094
43100
  unlockedAttachPin: unlockedAttachPin !== null && unlockedAttachPin !== void 0 ? unlockedAttachPin : features === null || features === void 0 ? void 0 : features.unlockedAttachPin,
43095
43101
  passphraseProtection,
43096
43102
  });
@@ -51589,7 +51595,6 @@ class TronSignMessage extends BaseMethod {
51589
51595
  return {
51590
51596
  pro2: {
51591
51597
  min: '0.0.0',
51592
- unsupported: true,
51593
51598
  },
51594
51599
  model_mini: {
51595
51600
  min: '2.5.0',
@@ -51746,7 +51751,6 @@ class TronSignTransaction extends BaseMethod {
51746
51751
  return {
51747
51752
  pro2: {
51748
51753
  min: '0.0.0',
51749
- unsupported: true,
51750
51754
  },
51751
51755
  model_mini: {
51752
51756
  min: '2.5.0',
@@ -12,6 +12,7 @@ export declare const getPassphraseStateWithRefreshDeviceInfo: (device: Device, o
12
12
  expectPassphraseState?: string;
13
13
  onlyMainPin?: boolean;
14
14
  allowCreateAttachPin?: boolean;
15
+ initSession?: boolean;
15
16
  }) => Promise<{
16
17
  passphraseState: string | undefined;
17
18
  newSession: string | undefined;
@@ -21,6 +22,7 @@ export declare const getPassphraseState: (device: Device, options?: {
21
22
  expectPassphraseState?: string;
22
23
  onlyMainPin?: boolean;
23
24
  allowCreateAttachPin?: boolean;
25
+ initSession?: boolean;
24
26
  }) => Promise<{
25
27
  passphraseState: string | undefined;
26
28
  newSession: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"deviceFeaturesUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceFeaturesUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,KAAK,aAAa,EAA6B,MAAM,qBAAqB,CAAC;AAKjG,OAAoB,EAClB,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC7B,MAAM,6BAA6B,CAAC;AAMrC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAe,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAM1E,eAAO,MAAM,iCAAiC,aAClC,QAAQ,GAAG,SAAS,KAC7B;IAAE,QAAQ,EAAE,IAAI,CAAC;IAAC,uBAAuB,EAAE,uBAAuB,CAAA;CAiCpE,CAAC;AAEF,eAAO,MAAM,yBAAyB,aAAc,QAAQ,KAAG,kBAU9D,CAAC;AAEF,eAAO,MAAM,oBAAoB,cAAe,QAAQ,KAAG,kBAe1D,CAAC;AAEF,eAAO,MAAM,uCAAuC,WAC1C,MAAM,YACJ;IACR,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;;;;EAuCF,CAAC;AAOF,eAAO,MAAM,kBAAkB,WACrB,MAAM,YACJ;IACR,qBA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"@onekeyfe/hd-core",
3
- "version": "1.2.0-alpha.1",
3
+ "version": "1.2.0-alpha.3",
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.1",
29
- "@onekeyfe/hd-transport": "1.2.0-alpha.1",
28
+ "@onekeyfe/hd-shared": "1.2.0-alpha.3",
29
+ "@onekeyfe/hd-transport": "1.2.0-alpha.3",
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": "4f4aae3a47be7bd54b4db4a10c400056784e01bd"
47
+ "gitHead": "54a4a40baee7e376b9a810dade60007d2c9b00c9"
48
48
  }
@@ -16,6 +16,7 @@ export default class GetPassphraseState extends BaseMethod {
16
16
  expectPassphraseState: this.payload.passphraseState,
17
17
  onlyMainPin: this.payload.useEmptyPassphrase,
18
18
  allowCreateAttachPin: this.payload.allowCreateAttachPin,
19
+ initSession: this.payload.initSession,
19
20
  });
20
21
 
21
22
  const { features } = this.device;
@@ -26,7 +27,9 @@ export default class GetPassphraseState extends BaseMethod {
26
27
  // refresh device info
27
28
  return Promise.resolve({
28
29
  passphraseState: isProSeries || passphraseProtection === true ? passphraseState : undefined,
29
- sessionId: newSession ?? features?.sessionId ?? undefined,
30
+ sessionId: this.payload.initSession
31
+ ? newSession ?? undefined
32
+ : newSession ?? features?.sessionId ?? undefined,
30
33
  unlockedAttachPin: unlockedAttachPin ?? features?.unlockedAttachPin,
31
34
  passphraseProtection,
32
35
  });
@@ -47,7 +47,6 @@ export default class TronSignMessage extends BaseMethod<HardwareTronSignMessage>
47
47
  return {
48
48
  pro2: {
49
49
  min: '0.0.0',
50
- unsupported: true,
51
50
  },
52
51
  model_mini: {
53
52
  min: '2.5.0',
@@ -150,7 +150,6 @@ export default class TronSignTransaction extends BaseMethod<TronSignTx> {
150
150
  return {
151
151
  pro2: {
152
152
  min: '0.0.0',
153
- unsupported: true,
154
153
  },
155
154
  model_mini: {
156
155
  min: '2.5.0',
@@ -93,12 +93,17 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
93
93
  expectPassphraseState?: string;
94
94
  onlyMainPin?: boolean;
95
95
  allowCreateAttachPin?: boolean;
96
+ initSession?: boolean;
96
97
  }
97
98
  ) => {
98
99
  const { features } = device;
99
100
  const locked = features?.unlocked === false;
100
101
  const deviceType = device.getCurrentDeviceType();
101
102
 
103
+ if (options?.initSession) {
104
+ device.clearInternalState();
105
+ }
106
+
102
107
  const { passphraseState, newSession, unlockedAttachPin } = await getPassphraseState(device, {
103
108
  ...options,
104
109
  });
@@ -128,7 +133,7 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
128
133
  passphraseState,
129
134
  deviceId,
130
135
  newSession,
131
- device.features?.sessionId
136
+ options?.initSession ? null : device.features?.sessionId
132
137
  );
133
138
 
134
139
  return { passphraseState, newSession, unlockedAttachPin };
@@ -145,6 +150,7 @@ export const getPassphraseState = async (
145
150
  expectPassphraseState?: string;
146
151
  onlyMainPin?: boolean;
147
152
  allowCreateAttachPin?: boolean;
153
+ initSession?: boolean;
148
154
  }
149
155
  ): Promise<{
150
156
  passphraseState: string | undefined;