@onekeyfe/hd-core 1.1.27-alpha.41 → 1.1.27-alpha.43
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/__tests__/DeviceCommands.test.ts +99 -0
- package/__tests__/evmLedgerLegacySafety.test.ts +261 -0
- package/__tests__/logBlockEvent.test.ts +37 -0
- package/__tests__/preInitialize.test.ts +22 -0
- package/__tests__/protocol-v2.test.ts +139 -27
- package/dist/api/BaseMethod.d.ts +7 -1
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
- package/dist/api/algo/AlgoSignTransaction.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/aptos/AptosSignInMessage.d.ts.map +1 -1
- package/dist/api/aptos/AptosSignMessage.d.ts.map +1 -1
- package/dist/api/aptos/AptosSignTransaction.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
- package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
- package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
- package/dist/api/cardano/CardanoSignMessage.d.ts.map +1 -1
- package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
- package/dist/api/cosmos/CosmosSignTransaction.d.ts.map +1 -1
- package/dist/api/device/DeviceLock.d.ts.map +1 -1
- package/dist/api/device/PreInitialize.d.ts +6 -0
- package/dist/api/device/PreInitialize.d.ts.map +1 -0
- package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
- package/dist/api/evm/EVMSignMessage.d.ts.map +1 -1
- package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/filecoin/FilecoinSignTransaction.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +2 -10
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/near/NearSignTransaction.d.ts.map +1 -1
- package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -1
- package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
- package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
- package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
- package/dist/api/nostr/NostrSignEvent.d.ts.map +1 -1
- package/dist/api/nostr/NostrSignSchnorr.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotSignTransaction.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +1 -1
- package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
- package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
- package/dist/api/starcoin/StarcoinSignMessage.d.ts.map +1 -1
- package/dist/api/starcoin/StarcoinSignTransaction.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
- package/dist/api/sui/SuiGetAddress.d.ts +3 -0
- package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +3 -0
- package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +3 -0
- package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +3 -0
- package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +3 -0
- package/dist/api/ton/TonGetAddress.d.ts.map +1 -1
- package/dist/api/ton/TonSignData.d.ts +5 -0
- package/dist/api/ton/TonSignData.d.ts.map +1 -1
- package/dist/api/ton/TonSignMessage.d.ts +3 -0
- package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
- package/dist/api/ton/TonSignProof.d.ts +3 -0
- package/dist/api/ton/TonSignProof.d.ts.map +1 -1
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
- package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
- package/dist/api/xrp/XrpSignTransaction.d.ts.map +1 -1
- package/dist/core/PollingStateManager.d.ts +8 -0
- package/dist/core/PollingStateManager.d.ts.map +1 -0
- package/dist/core/RequestQueue.d.ts +1 -1
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +17 -2
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts +1 -0
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/index.d.ts +25 -5
- package/dist/index.js +928 -407
- package/dist/types/api/index.d.ts +2 -0
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/preInitialize.d.ts +3 -0
- package/dist/types/api/preInitialize.d.ts.map +1 -0
- package/dist/types/api/protocolV2.d.ts +2 -2
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/params.d.ts +1 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +82 -2
- package/src/api/FirmwareUpdateV3.ts +0 -4
- package/src/api/FirmwareUpdateV4.ts +1 -19
- package/src/api/GetPassphraseState.ts +4 -3
- package/src/api/alephium/AlephiumSignMessage.ts +1 -0
- package/src/api/alephium/AlephiumSignTransaction.ts +1 -0
- package/src/api/algo/AlgoSignTransaction.ts +1 -0
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +8 -0
- package/src/api/aptos/AptosSignInMessage.ts +1 -0
- package/src/api/aptos/AptosSignMessage.ts +1 -0
- package/src/api/aptos/AptosSignTransaction.ts +1 -0
- package/src/api/benfen/BenfenSignMessage.ts +1 -0
- package/src/api/benfen/BenfenSignTransaction.ts +1 -0
- package/src/api/btc/BTCSignMessage.ts +1 -0
- package/src/api/btc/BTCSignPsbt.ts +1 -0
- package/src/api/btc/BTCSignTransaction.ts +1 -0
- package/src/api/cardano/CardanoSignMessage.ts +1 -0
- package/src/api/cardano/CardanoSignTransaction.ts +1 -0
- package/src/api/conflux/ConfluxSignMessage.ts +1 -0
- package/src/api/conflux/ConfluxSignMessageCIP23.ts +1 -0
- package/src/api/conflux/ConfluxSignTransaction.ts +1 -0
- package/src/api/cosmos/CosmosSignTransaction.ts +1 -0
- package/src/api/device/DeviceLock.ts +1 -3
- package/src/api/device/PreInitialize.ts +41 -0
- package/src/api/dynex/DnxSignTransaction.ts +1 -0
- package/src/api/evm/EVMSignMessage.ts +2 -0
- package/src/api/evm/EVMSignMessageEIP712.ts +1 -0
- package/src/api/evm/EVMSignTransaction.ts +2 -0
- package/src/api/evm/EVMSignTypedData.ts +3 -1
- package/src/api/filecoin/FilecoinSignTransaction.ts +1 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +4 -27
- package/src/api/index.ts +1 -0
- package/src/api/kaspa/KaspaSignTransaction.ts +1 -0
- package/src/api/near/NearSignTransaction.ts +1 -0
- package/src/api/nem/NEMSignTransaction.ts +1 -0
- package/src/api/neo/NeoSignTransaction.ts +1 -0
- package/src/api/nervos/NervosSignTransaction.ts +1 -0
- package/src/api/nexa/NexaSignTransaction.ts +2 -0
- package/src/api/nostr/NostrSignEvent.ts +1 -0
- package/src/api/nostr/NostrSignSchnorr.ts +1 -0
- package/src/api/polkadot/PolkadotSignTransaction.ts +1 -0
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +1 -5
- package/src/api/scdo/ScdoSignMessage.ts +1 -0
- package/src/api/scdo/ScdoSignTransaction.ts +1 -0
- package/src/api/solana/SolSignMessage.ts +1 -0
- package/src/api/solana/SolSignOffchainMessage.ts +1 -0
- package/src/api/solana/SolSignTransaction.ts +1 -0
- package/src/api/starcoin/StarcoinSignMessage.ts +1 -0
- package/src/api/starcoin/StarcoinSignTransaction.ts +1 -0
- package/src/api/stellar/StellarSignTransaction.ts +1 -0
- package/src/api/sui/SuiGetAddress.ts +3 -0
- package/src/api/sui/SuiGetPublicKey.ts +3 -0
- package/src/api/sui/SuiSignMessage.ts +4 -0
- package/src/api/sui/SuiSignTransaction.ts +4 -0
- package/src/api/ton/TonGetAddress.ts +3 -0
- package/src/api/ton/TonSignData.ts +11 -3
- package/src/api/ton/TonSignMessage.ts +4 -0
- package/src/api/ton/TonSignProof.ts +4 -0
- package/src/api/tron/TronSignMessage.ts +1 -0
- package/src/api/tron/TronSignTransaction.ts +1 -0
- package/src/api/xrp/XrpSignTransaction.ts +1 -0
- package/src/core/PollingStateManager.ts +47 -0
- package/src/core/RequestQueue.ts +10 -3
- package/src/core/index.ts +153 -34
- package/src/data/messages/messages-protocol-v2.json +489 -268
- package/src/device/Device.ts +73 -16
- package/src/events/logBlockEvent.ts +23 -0
- package/src/inject.ts +1 -1
- package/src/types/api/index.ts +2 -0
- package/src/types/api/preInitialize.ts +3 -0
- package/src/types/api/protocolV2.ts +2 -2
- package/src/types/params.ts +5 -0
- package/src/utils/deviceFeaturesUtils.ts +8 -17
package/src/device/Device.ts
CHANGED
|
@@ -51,7 +51,7 @@ import type {
|
|
|
51
51
|
} from '../events';
|
|
52
52
|
import type { PassphrasePromptResponse } from './DeviceCommands';
|
|
53
53
|
import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
54
|
-
import type { OneKeyDeviceInfo as DeviceDescriptor } from '@onekeyfe/hd-transport';
|
|
54
|
+
import type { OneKeyDeviceInfo as DeviceDescriptor, Success } from '@onekeyfe/hd-transport';
|
|
55
55
|
import type DeviceConnector from './DeviceConnector';
|
|
56
56
|
|
|
57
57
|
export type InitOptions = {
|
|
@@ -64,6 +64,7 @@ export type InitOptions = {
|
|
|
64
64
|
|
|
65
65
|
export type RunOptions = {
|
|
66
66
|
keepSession?: boolean;
|
|
67
|
+
skipInitialize?: boolean;
|
|
67
68
|
} & InitOptions;
|
|
68
69
|
|
|
69
70
|
const parseRunOptions = (options?: RunOptions): RunOptions => {
|
|
@@ -198,6 +199,17 @@ export class Device extends EventEmitter {
|
|
|
198
199
|
|
|
199
200
|
pendingCallbackPromise?: Deferred<void>;
|
|
200
201
|
|
|
202
|
+
/** Pre-initialize timestamp (ms) */
|
|
203
|
+
private preInitializedAt?: number;
|
|
204
|
+
|
|
205
|
+
/** Pre-initialize context, used to verify state consistency before skipping */
|
|
206
|
+
private preInitializeMeta?: {
|
|
207
|
+
passphraseState?: string;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/** Last Initialize duration (ms), reported as "saved" when a skip happens */
|
|
211
|
+
private lastInitializeDurationMs?: number;
|
|
212
|
+
|
|
201
213
|
constructor(descriptor: DeviceDescriptor, sdkInstanceId?: string) {
|
|
202
214
|
super();
|
|
203
215
|
this.originalDescriptor = descriptor;
|
|
@@ -378,6 +390,54 @@ export class Device extends EventEmitter {
|
|
|
378
390
|
this.deviceAcquired = false;
|
|
379
391
|
}
|
|
380
392
|
|
|
393
|
+
/**
|
|
394
|
+
* Pre-initialize: connect + Initialize ahead of the sign. Only runs the
|
|
395
|
+
* fallback init when features are missing (gate on `!this.features`, not
|
|
396
|
+
* isUsedHere which is always false on BLE); otherwise just records the mark.
|
|
397
|
+
*/
|
|
398
|
+
async preInitialize(initOptions?: InitOptions) {
|
|
399
|
+
if (!this.features) {
|
|
400
|
+
await this.acquire();
|
|
401
|
+
await this.initialize(initOptions);
|
|
402
|
+
}
|
|
403
|
+
this.markPreInitialized({
|
|
404
|
+
passphraseState: initOptions?.passphraseState,
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
markPreInitialized(meta?: { passphraseState?: string }) {
|
|
409
|
+
this.preInitializedAt = Date.now();
|
|
410
|
+
this.preInitializeMeta = meta
|
|
411
|
+
? {
|
|
412
|
+
passphraseState: meta.passphraseState === '' ? undefined : meta.passphraseState,
|
|
413
|
+
}
|
|
414
|
+
: undefined;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
clearPreInitialized() {
|
|
418
|
+
this.preInitializedAt = undefined;
|
|
419
|
+
this.preInitializeMeta = undefined;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
isPreInitializeMetaMatch(payload?: { passphraseState?: string }) {
|
|
423
|
+
if (!this.preInitializeMeta) return true;
|
|
424
|
+
const passphraseState = payload?.passphraseState === '' ? undefined : payload?.passphraseState;
|
|
425
|
+
return this.preInitializeMeta.passphraseState === passphraseState;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
isPreInitializedValid(ttlMs: number) {
|
|
429
|
+
if (!this.preInitializedAt) return false;
|
|
430
|
+
return Date.now() - this.preInitializedAt <= ttlMs;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
setLastInitializeDuration(durationMs: number) {
|
|
434
|
+
this.lastInitializeDurationMs = durationMs;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
getLastInitializeDuration() {
|
|
438
|
+
return this.lastInitializeDurationMs;
|
|
439
|
+
}
|
|
440
|
+
|
|
381
441
|
getCommands() {
|
|
382
442
|
return this.commands;
|
|
383
443
|
}
|
|
@@ -516,13 +576,7 @@ export class Device extends EventEmitter {
|
|
|
516
576
|
payload.passphrase_state = options?.passphraseState;
|
|
517
577
|
payload.is_contains_attach = true;
|
|
518
578
|
|
|
519
|
-
|
|
520
|
-
deviceId: options?.deviceId,
|
|
521
|
-
passphraseState: options?.passphraseState,
|
|
522
|
-
initSession: options?.initSession,
|
|
523
|
-
InitializePayload: payload,
|
|
524
|
-
});
|
|
525
|
-
|
|
579
|
+
const initStartAt = Date.now();
|
|
526
580
|
try {
|
|
527
581
|
// @ts-expect-error
|
|
528
582
|
const { message } = await Promise.race([
|
|
@@ -535,7 +589,8 @@ export class Device extends EventEmitter {
|
|
|
535
589
|
}),
|
|
536
590
|
]);
|
|
537
591
|
|
|
538
|
-
|
|
592
|
+
const initCostMs = Date.now() - initStartAt;
|
|
593
|
+
this.setLastInitializeDuration(initCostMs);
|
|
539
594
|
this._updateFeatures(message, options?.initSession);
|
|
540
595
|
await TransportManager.reconfigure(this.features);
|
|
541
596
|
} catch (error) {
|
|
@@ -652,7 +707,9 @@ export class Device extends EventEmitter {
|
|
|
652
707
|
|
|
653
708
|
try {
|
|
654
709
|
if (fn) {
|
|
655
|
-
|
|
710
|
+
if (!options?.skipInitialize) {
|
|
711
|
+
await this.initialize(options);
|
|
712
|
+
}
|
|
656
713
|
}
|
|
657
714
|
} catch (error) {
|
|
658
715
|
this.runPromise = null;
|
|
@@ -849,7 +906,8 @@ export class Device extends EventEmitter {
|
|
|
849
906
|
hasUsePassphrase() {
|
|
850
907
|
const isModeT =
|
|
851
908
|
getDeviceType(this.features) === EDeviceType.Touch ||
|
|
852
|
-
getDeviceType(this.features) === EDeviceType.Pro
|
|
909
|
+
getDeviceType(this.features) === EDeviceType.Pro ||
|
|
910
|
+
getDeviceType(this.features) === EDeviceType.Pro2;
|
|
853
911
|
const preCheckTouch = isModeT && this.features?.unlocked === false;
|
|
854
912
|
|
|
855
913
|
return this.features && (!!this.features.passphrase_protection || preCheckTouch);
|
|
@@ -862,7 +920,7 @@ export class Device extends EventEmitter {
|
|
|
862
920
|
return false;
|
|
863
921
|
}
|
|
864
922
|
|
|
865
|
-
async lockDevice() {
|
|
923
|
+
async lockDevice(): Promise<Success> {
|
|
866
924
|
const res = await this.commands.typedCall('LockDevice', 'Success', {});
|
|
867
925
|
return res.message;
|
|
868
926
|
}
|
|
@@ -872,6 +930,9 @@ export class Device extends EventEmitter {
|
|
|
872
930
|
pro: {
|
|
873
931
|
min: '4.15.0',
|
|
874
932
|
},
|
|
933
|
+
pro2: {
|
|
934
|
+
min: '4.15.0',
|
|
935
|
+
},
|
|
875
936
|
};
|
|
876
937
|
}
|
|
877
938
|
|
|
@@ -886,12 +947,8 @@ export class Device extends EventEmitter {
|
|
|
886
947
|
this.features,
|
|
887
948
|
Enum_Capability.Capability_AttachToPin
|
|
888
949
|
);
|
|
889
|
-
const isPro2 = getDeviceType(this.features) === EDeviceType.Pro2;
|
|
890
|
-
|
|
891
950
|
const supportUnlock =
|
|
892
951
|
supportAttachPinCapability ||
|
|
893
|
-
// Pro2 V2 暂未从 features 暴露 capabilities,先直连该方法用于固件联调。
|
|
894
|
-
isPro2 ||
|
|
895
952
|
(versionRange && semver.gte(firmwareVersion, versionRange.min));
|
|
896
953
|
|
|
897
954
|
if (supportUnlock) {
|
|
@@ -4,3 +4,26 @@ export const LogBlockEvent: Set<string> = new Set([
|
|
|
4
4
|
UI_RESPONSE.RECEIVE_PIN,
|
|
5
5
|
UI_RESPONSE.RECEIVE_PASSPHRASE,
|
|
6
6
|
]);
|
|
7
|
+
|
|
8
|
+
const LogBlockMethod: Set<string> = new Set(['evmSignTypedData']);
|
|
9
|
+
|
|
10
|
+
export function getLogBlockLabel(message: unknown): string | undefined {
|
|
11
|
+
if (!message || typeof message !== 'object') return undefined;
|
|
12
|
+
|
|
13
|
+
const { type, payload, method } = message as {
|
|
14
|
+
type?: string;
|
|
15
|
+
payload?: { method?: string };
|
|
16
|
+
method?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
if (type && LogBlockEvent.has(type)) {
|
|
20
|
+
return type;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const methodName = method ?? payload?.method;
|
|
24
|
+
if (methodName && LogBlockMethod.has(methodName)) {
|
|
25
|
+
return methodName;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
package/src/inject.ts
CHANGED
|
@@ -143,7 +143,7 @@ export const createCoreApi = (
|
|
|
143
143
|
|
|
144
144
|
testInitializeDeviceDuration: (connectId, params) =>
|
|
145
145
|
call({ ...params, connectId, method: 'testInitializeDeviceDuration' }),
|
|
146
|
-
|
|
146
|
+
preInitialize: (connectId, params) => call({ ...params, connectId, method: 'preInitialize' }),
|
|
147
147
|
deviceBackup: connectId => call({ connectId, method: 'deviceBackup' }),
|
|
148
148
|
deviceChangePin: (connectId, params) => call({ ...params, connectId, method: 'deviceChangePin' }),
|
|
149
149
|
deviceFlags: (connectId, params) => call({ ...params, connectId, method: 'deviceFlags' }),
|
package/src/types/api/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ import type { off, on, removeAllListeners } from './event';
|
|
|
30
30
|
import type { uiResponse } from './uiResponse';
|
|
31
31
|
import type { init, updateSettings } from './init';
|
|
32
32
|
import type { testInitializeDeviceDuration } from './testInitializeDeviceDuration';
|
|
33
|
+
import type { preInitialize } from './preInitialize';
|
|
33
34
|
import type { getLogs } from './getLogs';
|
|
34
35
|
import type { checkBridgeStatus } from './checkBridgeStatus';
|
|
35
36
|
import type { checkBridgeRelease } from './checkBridgeRelease';
|
|
@@ -199,6 +200,7 @@ export type CoreApi = {
|
|
|
199
200
|
* Test function
|
|
200
201
|
*/
|
|
201
202
|
testInitializeDeviceDuration: typeof testInitializeDeviceDuration;
|
|
203
|
+
preInitialize: typeof preInitialize;
|
|
202
204
|
|
|
203
205
|
/**
|
|
204
206
|
* Core function
|
|
@@ -2,11 +2,11 @@ import type { CommonParams, Response } from '../params';
|
|
|
2
2
|
import type {
|
|
3
3
|
DeviceFirmwareTarget,
|
|
4
4
|
DeviceFirmwareUpdateStatus,
|
|
5
|
-
DeviceOnboardingStatus,
|
|
6
5
|
DeviceInfoTargets,
|
|
7
6
|
DeviceInfoTypes,
|
|
8
7
|
DeviceRebootType,
|
|
9
8
|
FactoryDeviceInfo,
|
|
9
|
+
OnboardingStatus,
|
|
10
10
|
ProtoVersion,
|
|
11
11
|
ProtocolV2DeviceInfo,
|
|
12
12
|
Success,
|
|
@@ -162,7 +162,7 @@ export declare function deviceGetDeviceInfo(
|
|
|
162
162
|
export declare function deviceGetOnboardingStatus(
|
|
163
163
|
connectId: string,
|
|
164
164
|
params?: CommonParams
|
|
165
|
-
): Response<
|
|
165
|
+
): Response<OnboardingStatus>;
|
|
166
166
|
|
|
167
167
|
export declare function deviceFirmwareUpdate(
|
|
168
168
|
connectId: string,
|
package/src/types/params.ts
CHANGED
|
@@ -50,6 +50,11 @@ export interface CommonParams {
|
|
|
50
50
|
*/
|
|
51
51
|
onlyConnectBleDevice?: boolean;
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Use pre-initialized device state (BLE only)
|
|
55
|
+
*/
|
|
56
|
+
usePreInitialize?: boolean;
|
|
57
|
+
|
|
53
58
|
/**
|
|
54
59
|
* Expected transport protocol. If omitted, SDK probes Protocol V1 then Protocol V2.
|
|
55
60
|
*/
|
|
@@ -19,7 +19,7 @@ import { existCapability } from './capabilitieUtils';
|
|
|
19
19
|
|
|
20
20
|
import type { Device } from '../device/Device';
|
|
21
21
|
import type { DeviceCommands } from '../device/DeviceCommands';
|
|
22
|
-
import type { Features, SupportFeatureType } from '../types';
|
|
22
|
+
import type { Features, IDeviceType, SupportFeatureType } from '../types';
|
|
23
23
|
|
|
24
24
|
export const getSupportProtocolV1MessageSchema = (
|
|
25
25
|
features: Features | undefined
|
|
@@ -98,7 +98,6 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
98
98
|
const { features, commands } = device;
|
|
99
99
|
const locked = features?.unlocked === false;
|
|
100
100
|
const deviceType = getDeviceType(features);
|
|
101
|
-
const isPro2 = deviceType === EDeviceType.Pro2;
|
|
102
101
|
|
|
103
102
|
const { passphraseState, newSession, unlockedAttachPin } = await getPassphraseState(
|
|
104
103
|
features,
|
|
@@ -112,8 +111,7 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
112
111
|
|
|
113
112
|
// 如果可以获取到 passphraseState,但是设备 features 显示设备未开启 passphrase,需要刷新设备状态
|
|
114
113
|
// if passphraseState can be obtained, but the device features show that the device has not enabled passphrase, the device status needs to be refreshed
|
|
115
|
-
const needRefreshWithPassphrase =
|
|
116
|
-
!isPro2 && passphraseState && features?.passphrase_protection !== true;
|
|
114
|
+
const needRefreshWithPassphrase = passphraseState && features?.passphrase_protection !== true;
|
|
117
115
|
// 如果 Touch/Pro 在之前是锁定状态,刷新设备状态
|
|
118
116
|
// if Touch/Pro was locked before, refresh the device state
|
|
119
117
|
const needRefreshWithLocked = isModeT && locked;
|
|
@@ -123,19 +121,10 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
123
121
|
await device.getFeatures();
|
|
124
122
|
}
|
|
125
123
|
|
|
126
|
-
if (isPro2 && device.features) {
|
|
127
|
-
if (passphraseState) {
|
|
128
|
-
device.features.passphrase_protection = true;
|
|
129
|
-
}
|
|
130
|
-
if (newSession) {
|
|
131
|
-
device.features.session_id = newSession;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
124
|
// Attach to pin try to fix internal state
|
|
136
125
|
if (features?.device_id) {
|
|
137
126
|
device.updateInternalState(
|
|
138
|
-
|
|
127
|
+
device.features?.passphrase_protection ?? false,
|
|
139
128
|
passphraseState,
|
|
140
129
|
device.features?.device_id ?? '',
|
|
141
130
|
newSession,
|
|
@@ -146,6 +135,10 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
146
135
|
return { passphraseState, newSession, unlockedAttachPin };
|
|
147
136
|
};
|
|
148
137
|
|
|
138
|
+
const supportProSeriesAttachPinPassphrase = (deviceType: IDeviceType, firmwareVersion: string) =>
|
|
139
|
+
(deviceType === EDeviceType.Pro || deviceType === EDeviceType.Pro2) &&
|
|
140
|
+
semver.gte(firmwareVersion, '4.15.0');
|
|
141
|
+
|
|
149
142
|
export const getPassphraseState = async (
|
|
150
143
|
features: Features | undefined,
|
|
151
144
|
commands: DeviceCommands,
|
|
@@ -171,9 +164,7 @@ export const getPassphraseState = async (
|
|
|
171
164
|
);
|
|
172
165
|
const supportGetPassphraseState =
|
|
173
166
|
supportAttachPinCapability ||
|
|
174
|
-
|
|
175
|
-
deviceType === EDeviceType.Pro2 ||
|
|
176
|
-
(deviceType === EDeviceType.Pro && semver.gte(firmwareVersion.join('.'), '4.15.0'));
|
|
167
|
+
supportProSeriesAttachPinPassphrase(deviceType, firmwareVersion.join('.'));
|
|
177
168
|
|
|
178
169
|
if (supportGetPassphraseState) {
|
|
179
170
|
const payload: GetPassphraseStateMessage = options?.onlyMainPin
|