@onekeyfe/hd-core 1.1.27-alpha.42 → 1.1.27-alpha.45
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__/preInitialize.test.ts +22 -0
- package/__tests__/protocol-v2.test.ts +233 -20
- 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/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/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 +0 -1
- package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +0 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +0 -2
- 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/SuiSignMessage.d.ts.map +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
- package/dist/api/ton/TonSignData.d.ts.map +1 -1
- package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
- 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 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/index.d.ts +22 -2
- package/dist/index.js +454 -195
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- 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/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/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/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 +2 -0
- 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/scdo/ScdoSignMessage.ts +1 -0
- package/src/api/scdo/ScdoSignTransaction.ts +1 -0
- package/src/api/solana/SolSignMessage.ts +1 -1
- package/src/api/solana/SolSignOffchainMessage.ts +1 -1
- package/src/api/solana/SolSignTransaction.ts +1 -2
- 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/SuiSignMessage.ts +1 -0
- package/src/api/sui/SuiSignTransaction.ts +1 -0
- package/src/api/ton/TonSignData.ts +1 -0
- package/src/api/ton/TonSignMessage.ts +1 -0
- package/src/api/ton/TonSignProof.ts +1 -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/device/Device.ts +91 -29
- package/src/inject.ts +1 -1
- package/src/protocols/protocol-v2/features.ts +5 -6
- package/src/types/api/index.ts +2 -0
- package/src/types/api/preInitialize.ts +3 -0
- package/src/types/params.ts +5 -0
- package/src/utils/deviceFeaturesUtils.ts +8 -17
package/dist/index.js
CHANGED
|
@@ -132,6 +132,7 @@ const createCoreApi = (call) => ({
|
|
|
132
132
|
checkFirmwareTypeAvailable: params => call(Object.assign(Object.assign({}, params), { method: 'checkFirmwareTypeAvailable' })),
|
|
133
133
|
cipherKeyValue: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'cipherKeyValue' })),
|
|
134
134
|
testInitializeDeviceDuration: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'testInitializeDeviceDuration' })),
|
|
135
|
+
preInitialize: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'preInitialize' })),
|
|
135
136
|
deviceBackup: connectId => call({ connectId, method: 'deviceBackup' }),
|
|
136
137
|
deviceChangePin: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceChangePin' })),
|
|
137
138
|
deviceFlags: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFlags' })),
|
|
@@ -816,7 +817,7 @@ const createLogMessage = (type, payload) => ({
|
|
|
816
817
|
|
|
817
818
|
const MAX_ENTRIES = 500;
|
|
818
819
|
let postMessage$1;
|
|
819
|
-
class Log$
|
|
820
|
+
class Log$i {
|
|
820
821
|
constructor(prefix, enabled) {
|
|
821
822
|
this.prefix = prefix;
|
|
822
823
|
this.enabled = enabled;
|
|
@@ -868,7 +869,7 @@ class Log$h {
|
|
|
868
869
|
}
|
|
869
870
|
const _logs = {};
|
|
870
871
|
const initLog = (prefix, enabled) => {
|
|
871
|
-
const instance = new Log$
|
|
872
|
+
const instance = new Log$i(prefix, !!enabled);
|
|
872
873
|
_logs[prefix] = instance;
|
|
873
874
|
return instance;
|
|
874
875
|
};
|
|
@@ -1066,7 +1067,7 @@ function patchFeatures(response) {
|
|
|
1066
1067
|
return response;
|
|
1067
1068
|
}
|
|
1068
1069
|
|
|
1069
|
-
const Log$
|
|
1070
|
+
const Log$h = getLogger(exports.LoggerNames.Core);
|
|
1070
1071
|
let globalInstanceCounter = 0;
|
|
1071
1072
|
let sdkInstanceCounter = 0;
|
|
1072
1073
|
function generateSdkInstanceId() {
|
|
@@ -1126,7 +1127,7 @@ function completeRequestContext(responseID, error) {
|
|
|
1126
1127
|
context.status = error ? 'error' : 'success';
|
|
1127
1128
|
if (error) {
|
|
1128
1129
|
context.error = error.message;
|
|
1129
|
-
Log$
|
|
1130
|
+
Log$h.error(`[RequestContext] [completeRequestContext] Error: ${formatRequestContext(context)}`);
|
|
1130
1131
|
}
|
|
1131
1132
|
globalActiveRequests.delete(responseID);
|
|
1132
1133
|
if (context.sdkInstanceId) {
|
|
@@ -38790,7 +38791,7 @@ const findLatestRelease = (releases) => {
|
|
|
38790
38791
|
};
|
|
38791
38792
|
|
|
38792
38793
|
var _a$1;
|
|
38793
|
-
const Log$
|
|
38794
|
+
const Log$g = getLogger(exports.LoggerNames.Core);
|
|
38794
38795
|
const FIRMWARE_FIELDS = [
|
|
38795
38796
|
'firmware',
|
|
38796
38797
|
'firmware-v2',
|
|
@@ -38852,37 +38853,37 @@ class DataManager {
|
|
|
38852
38853
|
let data = null;
|
|
38853
38854
|
let fetchMethod = 'none';
|
|
38854
38855
|
if (settings.configFetcher) {
|
|
38855
|
-
Log$
|
|
38856
|
+
Log$g.debug('[DataConfig] Trying configFetcher (client-side fetcher)...');
|
|
38856
38857
|
try {
|
|
38857
38858
|
data = yield settings.configFetcher(urlWithCache);
|
|
38858
38859
|
if (data) {
|
|
38859
38860
|
fetchMethod = 'configFetcher';
|
|
38860
|
-
Log$
|
|
38861
|
+
Log$g.log('[DataConfig] ConfigFetcher success');
|
|
38861
38862
|
}
|
|
38862
38863
|
else {
|
|
38863
|
-
Log$
|
|
38864
|
+
Log$g.debug('[DataConfig] ConfigFetcher returned null, will fallback to axios');
|
|
38864
38865
|
}
|
|
38865
38866
|
}
|
|
38866
38867
|
catch (e) {
|
|
38867
|
-
Log$
|
|
38868
|
+
Log$g.warn('[DataConfig] ConfigFetcher error, will fallback to axios:', e);
|
|
38868
38869
|
}
|
|
38869
38870
|
}
|
|
38870
38871
|
if (!data) {
|
|
38871
|
-
Log$
|
|
38872
|
+
Log$g.debug('[DataConfig] Trying axios (SDK default fetcher)...');
|
|
38872
38873
|
try {
|
|
38873
38874
|
const response = yield axios__default["default"].get(urlWithCache, {
|
|
38874
38875
|
timeout: 7000,
|
|
38875
38876
|
});
|
|
38876
38877
|
data = response.data;
|
|
38877
38878
|
fetchMethod = 'axios';
|
|
38878
|
-
Log$
|
|
38879
|
+
Log$g.log('[DataConfig] Axios fetch success');
|
|
38879
38880
|
}
|
|
38880
38881
|
catch (e) {
|
|
38881
|
-
Log$
|
|
38882
|
+
Log$g.warn('[DataConfig] Axios fetch error:', e);
|
|
38882
38883
|
}
|
|
38883
38884
|
}
|
|
38884
38885
|
if (data) {
|
|
38885
|
-
Log$
|
|
38886
|
+
Log$g.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
|
|
38886
38887
|
this.deviceMap = {
|
|
38887
38888
|
[hdShared.EDeviceType.Classic]: this.enrichFirmwareReleaseInfo(data.classic),
|
|
38888
38889
|
[hdShared.EDeviceType.Classic1s]: this.enrichFirmwareReleaseInfo(data.classic1s),
|
|
@@ -38896,7 +38897,7 @@ class DataManager {
|
|
|
38896
38897
|
};
|
|
38897
38898
|
}
|
|
38898
38899
|
else {
|
|
38899
|
-
Log$
|
|
38900
|
+
Log$g.warn('[DataConfig] All fetch methods failed, using built-in default config');
|
|
38900
38901
|
}
|
|
38901
38902
|
});
|
|
38902
38903
|
}
|
|
@@ -39224,27 +39225,20 @@ const getPassphraseStateWithRefreshDeviceInfo = (device, options) => __awaiter(v
|
|
|
39224
39225
|
const { features, commands } = device;
|
|
39225
39226
|
const locked = (features === null || features === void 0 ? void 0 : features.unlocked) === false;
|
|
39226
39227
|
const deviceType = getDeviceType(features);
|
|
39227
|
-
const isPro2 = deviceType === hdShared.EDeviceType.Pro2;
|
|
39228
39228
|
const { passphraseState, newSession, unlockedAttachPin } = yield getPassphraseState(features, commands, Object.assign({}, options));
|
|
39229
39229
|
const isModeT = deviceType === hdShared.EDeviceType.Touch || deviceType === hdShared.EDeviceType.Pro;
|
|
39230
|
-
const needRefreshWithPassphrase =
|
|
39230
|
+
const needRefreshWithPassphrase = passphraseState && (features === null || features === void 0 ? void 0 : features.passphrase_protection) !== true;
|
|
39231
39231
|
const needRefreshWithLocked = isModeT && locked;
|
|
39232
39232
|
if (needRefreshWithLocked || needRefreshWithPassphrase) {
|
|
39233
39233
|
yield device.getFeatures();
|
|
39234
39234
|
}
|
|
39235
|
-
if (isPro2 && device.features) {
|
|
39236
|
-
if (passphraseState) {
|
|
39237
|
-
device.features.passphrase_protection = true;
|
|
39238
|
-
}
|
|
39239
|
-
if (newSession) {
|
|
39240
|
-
device.features.session_id = newSession;
|
|
39241
|
-
}
|
|
39242
|
-
}
|
|
39243
39235
|
if (features === null || features === void 0 ? void 0 : features.device_id) {
|
|
39244
|
-
device.updateInternalState((
|
|
39236
|
+
device.updateInternalState((_b = (_a = device.features) === null || _a === void 0 ? void 0 : _a.passphrase_protection) !== null && _b !== void 0 ? _b : false, passphraseState, (_d = (_c = device.features) === null || _c === void 0 ? void 0 : _c.device_id) !== null && _d !== void 0 ? _d : '', newSession, (_e = device.features) === null || _e === void 0 ? void 0 : _e.session_id);
|
|
39245
39237
|
}
|
|
39246
39238
|
return { passphraseState, newSession, unlockedAttachPin };
|
|
39247
39239
|
});
|
|
39240
|
+
const supportProSeriesAttachPinPassphrase = (deviceType, firmwareVersion) => (deviceType === hdShared.EDeviceType.Pro || deviceType === hdShared.EDeviceType.Pro2) &&
|
|
39241
|
+
semver__default["default"].gte(firmwareVersion, '4.15.0');
|
|
39248
39242
|
const getPassphraseState = (features, commands, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39249
39243
|
if (!features)
|
|
39250
39244
|
return { passphraseState: undefined, newSession: undefined, unlockedAttachPin: undefined };
|
|
@@ -39252,8 +39246,7 @@ const getPassphraseState = (features, commands, options) => __awaiter(void 0, vo
|
|
|
39252
39246
|
const deviceType = getDeviceType(features);
|
|
39253
39247
|
const supportAttachPinCapability = existCapability(features, hdTransport.Enum_Capability.Capability_AttachToPin);
|
|
39254
39248
|
const supportGetPassphraseState = supportAttachPinCapability ||
|
|
39255
|
-
deviceType
|
|
39256
|
-
(deviceType === hdShared.EDeviceType.Pro && semver__default["default"].gte(firmwareVersion.join('.'), '4.15.0'));
|
|
39249
|
+
supportProSeriesAttachPinPassphrase(deviceType, firmwareVersion.join('.'));
|
|
39257
39250
|
if (supportGetPassphraseState) {
|
|
39258
39251
|
const payload = (options === null || options === void 0 ? void 0 : options.onlyMainPin)
|
|
39259
39252
|
? { _only_main_pin: true }
|
|
@@ -40199,7 +40192,7 @@ function getLogBlockLabel(message) {
|
|
|
40199
40192
|
return undefined;
|
|
40200
40193
|
}
|
|
40201
40194
|
|
|
40202
|
-
const Log$
|
|
40195
|
+
const Log$f = getLogger(exports.LoggerNames.DevicePool);
|
|
40203
40196
|
const getDiff = (current, descriptors) => {
|
|
40204
40197
|
const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
|
|
40205
40198
|
const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
|
|
@@ -40257,7 +40250,7 @@ class DevicePool extends events.exports {
|
|
|
40257
40250
|
yield this._checkDevicePool(initOptions);
|
|
40258
40251
|
return { devices, deviceList };
|
|
40259
40252
|
}
|
|
40260
|
-
Log$
|
|
40253
|
+
Log$f.debug('found device in cache, but path is different: ', connectId);
|
|
40261
40254
|
}
|
|
40262
40255
|
}
|
|
40263
40256
|
try {
|
|
@@ -40318,7 +40311,7 @@ class DevicePool extends events.exports {
|
|
|
40318
40311
|
for (let i = this.connectedPool.length - 1; i >= 0; i--) {
|
|
40319
40312
|
const descriptor = this.connectedPool[i];
|
|
40320
40313
|
const device = yield this._createDevice(descriptor, initOptions);
|
|
40321
|
-
Log$
|
|
40314
|
+
Log$f.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
|
|
40322
40315
|
this.emitter.emit(DEVICE.CONNECT, device);
|
|
40323
40316
|
this.connectedPool.splice(i, 1);
|
|
40324
40317
|
}
|
|
@@ -40338,9 +40331,9 @@ class DevicePool extends events.exports {
|
|
|
40338
40331
|
const diff = getDiff(this.current || [], upcoming);
|
|
40339
40332
|
this.upcoming = upcoming;
|
|
40340
40333
|
this.current = this.upcoming;
|
|
40341
|
-
Log$
|
|
40342
|
-
Log$
|
|
40343
|
-
Log$
|
|
40334
|
+
Log$f.debug('device pool -> current: ', this.current);
|
|
40335
|
+
Log$f.debug('device pool -> upcomming: ', this.upcoming);
|
|
40336
|
+
Log$f.debug('DeviceCache.reportDeviceChange diff: ', diff);
|
|
40344
40337
|
if (!diff.didUpdate) {
|
|
40345
40338
|
return;
|
|
40346
40339
|
}
|
|
@@ -40350,7 +40343,7 @@ class DevicePool extends events.exports {
|
|
|
40350
40343
|
this._addConnectedDeviceToPool(d);
|
|
40351
40344
|
return;
|
|
40352
40345
|
}
|
|
40353
|
-
Log$
|
|
40346
|
+
Log$f.debug('emit DEVICE.CONNECT: ', device.features);
|
|
40354
40347
|
this.emitter.emit(DEVICE.CONNECT, device);
|
|
40355
40348
|
});
|
|
40356
40349
|
diff.disconnected.forEach(d => {
|
|
@@ -40360,7 +40353,7 @@ class DevicePool extends events.exports {
|
|
|
40360
40353
|
this._addDisconnectedDeviceToPool(d);
|
|
40361
40354
|
return;
|
|
40362
40355
|
}
|
|
40363
|
-
Log$
|
|
40356
|
+
Log$f.debug('emit DEVICE.DISCONNECT: ', device.features);
|
|
40364
40357
|
this.emitter.emit(DEVICE.DISCONNECT, device);
|
|
40365
40358
|
});
|
|
40366
40359
|
}
|
|
@@ -40396,7 +40389,7 @@ class DevicePool extends events.exports {
|
|
|
40396
40389
|
this.disconnectPool = [];
|
|
40397
40390
|
this.devicesCache = {};
|
|
40398
40391
|
this.emitter.removeAllListeners();
|
|
40399
|
-
Log$
|
|
40392
|
+
Log$f.debug('DevicePool state has been reset');
|
|
40400
40393
|
}
|
|
40401
40394
|
}
|
|
40402
40395
|
DevicePool.current = null;
|
|
@@ -40406,7 +40399,7 @@ DevicePool.disconnectPool = [];
|
|
|
40406
40399
|
DevicePool.devicesCache = {};
|
|
40407
40400
|
DevicePool.emitter = new events.exports();
|
|
40408
40401
|
|
|
40409
|
-
const Log$
|
|
40402
|
+
const Log$e = getLogger(exports.LoggerNames.Transport);
|
|
40410
40403
|
const BleLogger = getLogger(exports.LoggerNames.HdBleTransport);
|
|
40411
40404
|
const HttpLogger = getLogger(exports.LoggerNames.HdTransportHttp);
|
|
40412
40405
|
const LowLevelLogger = getLogger(exports.LoggerNames.HdTransportLowLevel);
|
|
@@ -40416,7 +40409,7 @@ const WebUsbLogger = getLogger(exports.LoggerNames.HdTransportWebUsb);
|
|
|
40416
40409
|
const REACT_NATIVE_BLE_SCAN_TIMEOUT_MS = 8000;
|
|
40417
40410
|
class TransportManager {
|
|
40418
40411
|
static load() {
|
|
40419
|
-
Log$
|
|
40412
|
+
Log$e.debug('transport manager load');
|
|
40420
40413
|
this.defaultMessages = DataManager.getProtobufMessages();
|
|
40421
40414
|
this.currentMessages = this.defaultMessages;
|
|
40422
40415
|
this.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
@@ -40425,14 +40418,14 @@ class TransportManager {
|
|
|
40425
40418
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40426
40419
|
try {
|
|
40427
40420
|
const env = DataManager.getSettings('env');
|
|
40428
|
-
Log$
|
|
40421
|
+
Log$e.debug('Initializing transports', env);
|
|
40429
40422
|
if (env === 'react-native') {
|
|
40430
40423
|
if (!this.reactNativeInit) {
|
|
40431
40424
|
yield this.transport.init(BleLogger, DevicePool.emitter);
|
|
40432
40425
|
this.reactNativeInit = true;
|
|
40433
40426
|
}
|
|
40434
40427
|
else {
|
|
40435
|
-
Log$
|
|
40428
|
+
Log$e.debug('React Native Do Not Initializing transports');
|
|
40436
40429
|
}
|
|
40437
40430
|
}
|
|
40438
40431
|
else if (env === 'node-usb') {
|
|
@@ -40453,15 +40446,15 @@ class TransportManager {
|
|
|
40453
40446
|
else {
|
|
40454
40447
|
yield this.transport.init(HttpLogger);
|
|
40455
40448
|
}
|
|
40456
|
-
Log$
|
|
40449
|
+
Log$e.debug('Configuring transports');
|
|
40457
40450
|
yield this.transport.configure(JSON.stringify(this.defaultMessages));
|
|
40458
40451
|
this.currentMessages = this.defaultMessages;
|
|
40459
40452
|
this.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
40460
40453
|
yield this.configureProtocolV2Messages();
|
|
40461
|
-
Log$
|
|
40454
|
+
Log$e.debug('Configuring transports done');
|
|
40462
40455
|
}
|
|
40463
40456
|
catch (error) {
|
|
40464
|
-
Log$
|
|
40457
|
+
Log$e.debug('Initializing transports error: ', error);
|
|
40465
40458
|
if (error.code === 'ECONNABORTED') {
|
|
40466
40459
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
|
|
40467
40460
|
}
|
|
@@ -40477,7 +40470,7 @@ class TransportManager {
|
|
|
40477
40470
|
if (this.currentMessages === messages || !messages) {
|
|
40478
40471
|
return;
|
|
40479
40472
|
}
|
|
40480
|
-
Log$
|
|
40473
|
+
Log$e.debug(`Reconfiguring transports Protocol V1 schema:${protocolV1MessageSchema}`);
|
|
40481
40474
|
try {
|
|
40482
40475
|
yield this.transport.configure(JSON.stringify(messages));
|
|
40483
40476
|
this.currentMessages = messages;
|
|
@@ -40500,9 +40493,9 @@ class TransportManager {
|
|
|
40500
40493
|
}
|
|
40501
40494
|
if (plugin) {
|
|
40502
40495
|
this.plugin = plugin;
|
|
40503
|
-
Log$
|
|
40496
|
+
Log$e.debug('set transport plugin: ', this.plugin);
|
|
40504
40497
|
}
|
|
40505
|
-
Log$
|
|
40498
|
+
Log$e.debug('set transport: ', this.transport.name, this.transport.version, this.transport.configured);
|
|
40506
40499
|
}
|
|
40507
40500
|
static getTransport() {
|
|
40508
40501
|
return this.transport;
|
|
@@ -40513,7 +40506,7 @@ class TransportManager {
|
|
|
40513
40506
|
const { configureProtocolV2 } = this.transport;
|
|
40514
40507
|
if (protocolV2Messages && typeof configureProtocolV2 === 'function') {
|
|
40515
40508
|
yield configureProtocolV2.call(this.transport, JSON.stringify(protocolV2Messages));
|
|
40516
|
-
Log$
|
|
40509
|
+
Log$e.debug('Protocol V2 messages configured');
|
|
40517
40510
|
}
|
|
40518
40511
|
});
|
|
40519
40512
|
}
|
|
@@ -40685,7 +40678,7 @@ const cancelDeviceWithInitialize = (device) => {
|
|
|
40685
40678
|
},
|
|
40686
40679
|
}));
|
|
40687
40680
|
};
|
|
40688
|
-
const Log$
|
|
40681
|
+
const Log$d = getLogger(exports.LoggerNames.DeviceCommands);
|
|
40689
40682
|
const LogCore = getLogger(exports.LoggerNames.Core);
|
|
40690
40683
|
class DeviceCommands {
|
|
40691
40684
|
constructor(device, mainId) {
|
|
@@ -40694,7 +40687,7 @@ class DeviceCommands {
|
|
|
40694
40687
|
this.transport = TransportManager.getTransport();
|
|
40695
40688
|
this.disposed = false;
|
|
40696
40689
|
this.instanceId = generateInstanceId('DeviceCommands', device.sdkInstanceId);
|
|
40697
|
-
Log$
|
|
40690
|
+
Log$d.debug(`[DeviceCommands] Created: ${this.instanceId}, device: ${this.device.instanceId}`);
|
|
40698
40691
|
}
|
|
40699
40692
|
dispose(_cancelRequest) {
|
|
40700
40693
|
var _a, _b;
|
|
@@ -40764,7 +40757,7 @@ class DeviceCommands {
|
|
|
40764
40757
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40765
40758
|
const shouldReduceDebug = shouldReduceDebugForCall(type);
|
|
40766
40759
|
if (!shouldReduceDebug) {
|
|
40767
|
-
Log$
|
|
40760
|
+
Log$d.debug('[DeviceCommands] [call] Sending', type);
|
|
40768
40761
|
}
|
|
40769
40762
|
try {
|
|
40770
40763
|
const promise = this.transport.call(this.mainId, type, msg !== null && msg !== void 0 ? msg : {}, options);
|
|
@@ -40799,7 +40792,7 @@ class DeviceCommands {
|
|
|
40799
40792
|
}
|
|
40800
40793
|
}
|
|
40801
40794
|
if (responseData) {
|
|
40802
|
-
Log$
|
|
40795
|
+
Log$d.debug('error response', responseData);
|
|
40803
40796
|
}
|
|
40804
40797
|
if (responseError === 'device disconnected during action') {
|
|
40805
40798
|
return { type: 'BridgeDeviceDisconnected', message: { error: responseError } };
|
|
@@ -40839,7 +40832,7 @@ class DeviceCommands {
|
|
|
40839
40832
|
'ResourceAck',
|
|
40840
40833
|
];
|
|
40841
40834
|
if (!skipTypes.includes(type) && msg) {
|
|
40842
|
-
Log$
|
|
40835
|
+
Log$d.debug('[DeviceCommands] [typedCall] Sending payload', type, sanitizeDebugPayload(msg));
|
|
40843
40836
|
}
|
|
40844
40837
|
}
|
|
40845
40838
|
catch (e) {
|
|
@@ -40850,10 +40843,10 @@ class DeviceCommands {
|
|
|
40850
40843
|
assertType(response, resType);
|
|
40851
40844
|
}
|
|
40852
40845
|
catch (error) {
|
|
40853
|
-
Log$
|
|
40846
|
+
Log$d.debug('DeviceCommands typedcall error: ', error);
|
|
40854
40847
|
if (error instanceof hdShared.HardwareError) {
|
|
40855
40848
|
if (error.errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError) {
|
|
40856
|
-
Log$
|
|
40849
|
+
Log$d.debug('[DeviceCommands] [typedCall] Unexpected response type', {
|
|
40857
40850
|
request: type,
|
|
40858
40851
|
expected: resType,
|
|
40859
40852
|
received: response.type,
|
|
@@ -40889,10 +40882,10 @@ class DeviceCommands {
|
|
|
40889
40882
|
if (shouldReduceDebugForCall(callType)) {
|
|
40890
40883
|
}
|
|
40891
40884
|
else if (DataManager.getSettings('env') === 'react-native') {
|
|
40892
|
-
Log$
|
|
40885
|
+
Log$d.debug('_filterCommonTypes: ', JSON.stringify(sanitizeDebugPayload(res)));
|
|
40893
40886
|
}
|
|
40894
40887
|
else {
|
|
40895
|
-
Log$
|
|
40888
|
+
Log$d.debug('_filterCommonTypes: ', sanitizeDebugPayload(res));
|
|
40896
40889
|
}
|
|
40897
40890
|
}
|
|
40898
40891
|
catch (error) {
|
|
@@ -41021,7 +41014,7 @@ class DeviceCommands {
|
|
|
41021
41014
|
reject(error);
|
|
41022
41015
|
});
|
|
41023
41016
|
const listenerCount = this.device.listenerCount(DEVICE.PIN);
|
|
41024
|
-
Log$
|
|
41017
|
+
Log$d.debug(`[${this.instanceId}] _promptPin called`, {
|
|
41025
41018
|
responseID: this.currentResponseID,
|
|
41026
41019
|
deviceInstanceId: this.device.instanceId,
|
|
41027
41020
|
listenerCount,
|
|
@@ -41172,7 +41165,7 @@ function createBaseFeatures(descriptor) {
|
|
|
41172
41165
|
minor_version: 0,
|
|
41173
41166
|
patch_version: 0,
|
|
41174
41167
|
bootloader_mode: false,
|
|
41175
|
-
device_id:
|
|
41168
|
+
device_id: '',
|
|
41176
41169
|
pin_protection: null,
|
|
41177
41170
|
passphrase_protection: null,
|
|
41178
41171
|
language: null,
|
|
@@ -41215,10 +41208,10 @@ function normalizeProtocolV2Features(descriptor, deviceInfo) {
|
|
|
41215
41208
|
const features = createBaseFeatures(descriptor);
|
|
41216
41209
|
if (!deviceInfo)
|
|
41217
41210
|
return features;
|
|
41218
|
-
const serialNo = (
|
|
41211
|
+
const serialNo = (_a = deviceInfo.hw) === null || _a === void 0 ? void 0 : _a.serial_no;
|
|
41219
41212
|
const firmwareVersion = getImageVersion((_b = deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.app);
|
|
41220
41213
|
const [fwMajor, fwMinor, fwPatch] = parseVersion(firmwareVersion);
|
|
41221
|
-
return Object.assign(Object.assign({}, features), { major_version: fwMajor, minor_version: fwMinor, patch_version: fwPatch, fw_major: fwMajor, fw_minor: fwMinor, fw_patch: fwPatch, device_id: serialNo, serial_no: serialNo, onekey_serial_no: serialNo, protocol_version: (_c = deviceInfo.protocol_version) !== null && _c !== void 0 ? _c : features.protocol_version, label: (_e = (_d = deviceInfo.status) === null || _d === void 0 ? void 0 : _d.label) !== null && _e !== void 0 ? _e : features.label, language: (_g = (_f = deviceInfo.status) === null || _f === void 0 ? void 0 : _f.language) !== null && _g !== void 0 ? _g : features.language, initialized: (_j = (_h = deviceInfo.status) === null || _h === void 0 ? void 0 : _h.init_states) !== null && _j !== void 0 ? _j : features.initialized, passphrase_protection: (_l = (_k = deviceInfo.status) === null || _k === void 0 ? void 0 : _k.passphrase_protection) !== null && _l !== void 0 ? _l : features.passphrase_protection, needs_backup: (_o = (_m = deviceInfo.status) === null || _m === void 0 ? void 0 : _m.backup_required) !== null && _o !== void 0 ? _o : features.needs_backup, ble_enable: (_p = deviceInfo.status) === null || _p === void 0 ? void 0 : _p.bt_enable, onekey_ble_name: (_q = deviceInfo.bt) === null || _q === void 0 ? void 0 : _q.adv_name, ble_name: (_r = deviceInfo.bt) === null || _r === void 0 ? void 0 : _r.adv_name, onekey_firmware_version: firmwareVersion, onekey_firmware_build_id: getImageBuildId((_s = deviceInfo.fw) === null || _s === void 0 ? void 0 : _s.app), onekey_firmware_hash: getImageHash((_t = deviceInfo.fw) === null || _t === void 0 ? void 0 : _t.app), onekey_boot_version: getImageVersion((_u = deviceInfo.fw) === null || _u === void 0 ? void 0 : _u.boot), bootloader_version: getImageVersion((_v = deviceInfo.fw) === null || _v === void 0 ? void 0 : _v.boot), onekey_boot_build_id: getImageBuildId((_w = deviceInfo.fw) === null || _w === void 0 ? void 0 : _w.boot), onekey_boot_hash: getImageHash((_x = deviceInfo.fw) === null || _x === void 0 ? void 0 : _x.boot), onekey_board_version: getImageVersion((_y = deviceInfo.fw) === null || _y === void 0 ? void 0 : _y.board), onekey_board_build_id: getImageBuildId((_z = deviceInfo.fw) === null || _z === void 0 ? void 0 : _z.board), onekey_board_hash: getImageHash((_0 = deviceInfo.fw) === null || _0 === void 0 ? void 0 : _0.board), onekey_ble_version: getImageVersion((_1 = deviceInfo.bt) === null || _1 === void 0 ? void 0 : _1.app), ble_ver: getImageVersion((_2 = deviceInfo.bt) === null || _2 === void 0 ? void 0 : _2.app), onekey_ble_build_id: getImageBuildId((_3 = deviceInfo.bt) === null || _3 === void 0 ? void 0 : _3.app), onekey_ble_hash: getImageHash((_4 = deviceInfo.bt) === null || _4 === void 0 ? void 0 : _4.app), onekey_se01_version: getImageVersion((_5 = deviceInfo.se1) === null || _5 === void 0 ? void 0 : _5.app), onekey_se01_hash: getImageHash((_6 = deviceInfo.se1) === null || _6 === void 0 ? void 0 : _6.app), onekey_se01_build_id: getImageBuildId((_7 = deviceInfo.se1) === null || _7 === void 0 ? void 0 : _7.app), onekey_se01_boot_version: getImageVersion((_8 = deviceInfo.se1) === null || _8 === void 0 ? void 0 : _8.boot), onekey_se01_boot_hash: getImageHash((_9 = deviceInfo.se1) === null || _9 === void 0 ? void 0 : _9.boot), onekey_se01_boot_build_id: getImageBuildId((_10 = deviceInfo.se1) === null || _10 === void 0 ? void 0 : _10.boot), onekey_se01_state: getSeState(deviceInfo.se1), onekey_se02_version: getImageVersion((_11 = deviceInfo.se2) === null || _11 === void 0 ? void 0 : _11.app), onekey_se02_hash: getImageHash((_12 = deviceInfo.se2) === null || _12 === void 0 ? void 0 : _12.app), onekey_se02_build_id: getImageBuildId((_13 = deviceInfo.se2) === null || _13 === void 0 ? void 0 : _13.app), onekey_se02_boot_version: getImageVersion((_14 = deviceInfo.se2) === null || _14 === void 0 ? void 0 : _14.boot), onekey_se02_boot_hash: getImageHash((_15 = deviceInfo.se2) === null || _15 === void 0 ? void 0 : _15.boot), onekey_se02_boot_build_id: getImageBuildId((_16 = deviceInfo.se2) === null || _16 === void 0 ? void 0 : _16.boot), onekey_se02_state: getSeState(deviceInfo.se2), onekey_se03_version: getImageVersion((_17 = deviceInfo.se3) === null || _17 === void 0 ? void 0 : _17.app), onekey_se03_hash: getImageHash((_18 = deviceInfo.se3) === null || _18 === void 0 ? void 0 : _18.app), onekey_se03_build_id: getImageBuildId((_19 = deviceInfo.se3) === null || _19 === void 0 ? void 0 : _19.app), onekey_se03_boot_version: getImageVersion((_20 = deviceInfo.se3) === null || _20 === void 0 ? void 0 : _20.boot), onekey_se03_boot_hash: getImageHash((_21 = deviceInfo.se3) === null || _21 === void 0 ? void 0 : _21.boot), onekey_se03_boot_build_id: getImageBuildId((_22 = deviceInfo.se3) === null || _22 === void 0 ? void 0 : _22.boot), onekey_se03_state: getSeState(deviceInfo.se3), onekey_se04_version: getImageVersion((_23 = deviceInfo.se4) === null || _23 === void 0 ? void 0 : _23.app), onekey_se04_hash: getImageHash((_24 = deviceInfo.se4) === null || _24 === void 0 ? void 0 : _24.app), onekey_se04_build_id: getImageBuildId((_25 = deviceInfo.se4) === null || _25 === void 0 ? void 0 : _25.app), onekey_se04_boot_version: getImageVersion((_26 = deviceInfo.se4) === null || _26 === void 0 ? void 0 : _26.boot), onekey_se04_boot_hash: getImageHash((_27 = deviceInfo.se4) === null || _27 === void 0 ? void 0 : _27.boot), onekey_se04_boot_build_id: getImageBuildId((_28 = deviceInfo.se4) === null || _28 === void 0 ? void 0 : _28.boot), onekey_se04_state: getSeState(deviceInfo.se4) });
|
|
41214
|
+
return Object.assign(Object.assign({}, features), { major_version: fwMajor, minor_version: fwMinor, patch_version: fwPatch, fw_major: fwMajor, fw_minor: fwMinor, fw_patch: fwPatch, device_id: serialNo !== null && serialNo !== void 0 ? serialNo : features.device_id, serial_no: serialNo !== null && serialNo !== void 0 ? serialNo : features.serial_no, onekey_serial_no: serialNo !== null && serialNo !== void 0 ? serialNo : features.onekey_serial_no, protocol_version: (_c = deviceInfo.protocol_version) !== null && _c !== void 0 ? _c : features.protocol_version, label: (_e = (_d = deviceInfo.status) === null || _d === void 0 ? void 0 : _d.label) !== null && _e !== void 0 ? _e : features.label, language: (_g = (_f = deviceInfo.status) === null || _f === void 0 ? void 0 : _f.language) !== null && _g !== void 0 ? _g : features.language, initialized: (_j = (_h = deviceInfo.status) === null || _h === void 0 ? void 0 : _h.init_states) !== null && _j !== void 0 ? _j : features.initialized, passphrase_protection: (_l = (_k = deviceInfo.status) === null || _k === void 0 ? void 0 : _k.passphrase_protection) !== null && _l !== void 0 ? _l : features.passphrase_protection, needs_backup: (_o = (_m = deviceInfo.status) === null || _m === void 0 ? void 0 : _m.backup_required) !== null && _o !== void 0 ? _o : features.needs_backup, ble_enable: (_p = deviceInfo.status) === null || _p === void 0 ? void 0 : _p.bt_enable, onekey_ble_name: (_q = deviceInfo.bt) === null || _q === void 0 ? void 0 : _q.adv_name, ble_name: (_r = deviceInfo.bt) === null || _r === void 0 ? void 0 : _r.adv_name, onekey_firmware_version: firmwareVersion, onekey_firmware_build_id: getImageBuildId((_s = deviceInfo.fw) === null || _s === void 0 ? void 0 : _s.app), onekey_firmware_hash: getImageHash((_t = deviceInfo.fw) === null || _t === void 0 ? void 0 : _t.app), onekey_boot_version: getImageVersion((_u = deviceInfo.fw) === null || _u === void 0 ? void 0 : _u.boot), bootloader_version: getImageVersion((_v = deviceInfo.fw) === null || _v === void 0 ? void 0 : _v.boot), onekey_boot_build_id: getImageBuildId((_w = deviceInfo.fw) === null || _w === void 0 ? void 0 : _w.boot), onekey_boot_hash: getImageHash((_x = deviceInfo.fw) === null || _x === void 0 ? void 0 : _x.boot), onekey_board_version: getImageVersion((_y = deviceInfo.fw) === null || _y === void 0 ? void 0 : _y.board), onekey_board_build_id: getImageBuildId((_z = deviceInfo.fw) === null || _z === void 0 ? void 0 : _z.board), onekey_board_hash: getImageHash((_0 = deviceInfo.fw) === null || _0 === void 0 ? void 0 : _0.board), onekey_ble_version: getImageVersion((_1 = deviceInfo.bt) === null || _1 === void 0 ? void 0 : _1.app), ble_ver: getImageVersion((_2 = deviceInfo.bt) === null || _2 === void 0 ? void 0 : _2.app), onekey_ble_build_id: getImageBuildId((_3 = deviceInfo.bt) === null || _3 === void 0 ? void 0 : _3.app), onekey_ble_hash: getImageHash((_4 = deviceInfo.bt) === null || _4 === void 0 ? void 0 : _4.app), onekey_se01_version: getImageVersion((_5 = deviceInfo.se1) === null || _5 === void 0 ? void 0 : _5.app), onekey_se01_hash: getImageHash((_6 = deviceInfo.se1) === null || _6 === void 0 ? void 0 : _6.app), onekey_se01_build_id: getImageBuildId((_7 = deviceInfo.se1) === null || _7 === void 0 ? void 0 : _7.app), onekey_se01_boot_version: getImageVersion((_8 = deviceInfo.se1) === null || _8 === void 0 ? void 0 : _8.boot), onekey_se01_boot_hash: getImageHash((_9 = deviceInfo.se1) === null || _9 === void 0 ? void 0 : _9.boot), onekey_se01_boot_build_id: getImageBuildId((_10 = deviceInfo.se1) === null || _10 === void 0 ? void 0 : _10.boot), onekey_se01_state: getSeState(deviceInfo.se1), onekey_se02_version: getImageVersion((_11 = deviceInfo.se2) === null || _11 === void 0 ? void 0 : _11.app), onekey_se02_hash: getImageHash((_12 = deviceInfo.se2) === null || _12 === void 0 ? void 0 : _12.app), onekey_se02_build_id: getImageBuildId((_13 = deviceInfo.se2) === null || _13 === void 0 ? void 0 : _13.app), onekey_se02_boot_version: getImageVersion((_14 = deviceInfo.se2) === null || _14 === void 0 ? void 0 : _14.boot), onekey_se02_boot_hash: getImageHash((_15 = deviceInfo.se2) === null || _15 === void 0 ? void 0 : _15.boot), onekey_se02_boot_build_id: getImageBuildId((_16 = deviceInfo.se2) === null || _16 === void 0 ? void 0 : _16.boot), onekey_se02_state: getSeState(deviceInfo.se2), onekey_se03_version: getImageVersion((_17 = deviceInfo.se3) === null || _17 === void 0 ? void 0 : _17.app), onekey_se03_hash: getImageHash((_18 = deviceInfo.se3) === null || _18 === void 0 ? void 0 : _18.app), onekey_se03_build_id: getImageBuildId((_19 = deviceInfo.se3) === null || _19 === void 0 ? void 0 : _19.app), onekey_se03_boot_version: getImageVersion((_20 = deviceInfo.se3) === null || _20 === void 0 ? void 0 : _20.boot), onekey_se03_boot_hash: getImageHash((_21 = deviceInfo.se3) === null || _21 === void 0 ? void 0 : _21.boot), onekey_se03_boot_build_id: getImageBuildId((_22 = deviceInfo.se3) === null || _22 === void 0 ? void 0 : _22.boot), onekey_se03_state: getSeState(deviceInfo.se3), onekey_se04_version: getImageVersion((_23 = deviceInfo.se4) === null || _23 === void 0 ? void 0 : _23.app), onekey_se04_hash: getImageHash((_24 = deviceInfo.se4) === null || _24 === void 0 ? void 0 : _24.app), onekey_se04_build_id: getImageBuildId((_25 = deviceInfo.se4) === null || _25 === void 0 ? void 0 : _25.app), onekey_se04_boot_version: getImageVersion((_26 = deviceInfo.se4) === null || _26 === void 0 ? void 0 : _26.boot), onekey_se04_boot_hash: getImageHash((_27 = deviceInfo.se4) === null || _27 === void 0 ? void 0 : _27.boot), onekey_se04_boot_build_id: getImageBuildId((_28 = deviceInfo.se4) === null || _28 === void 0 ? void 0 : _28.boot), onekey_se04_state: getSeState(deviceInfo.se4) });
|
|
41222
41215
|
}
|
|
41223
41216
|
function getProtocolV2Features({ commands, descriptor, timeoutMs, }) {
|
|
41224
41217
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -41260,7 +41253,7 @@ const parseRunOptions = (options) => {
|
|
|
41260
41253
|
options = {};
|
|
41261
41254
|
return options;
|
|
41262
41255
|
};
|
|
41263
|
-
const Log$
|
|
41256
|
+
const Log$c = getLogger(exports.LoggerNames.Device);
|
|
41264
41257
|
const deviceSessionCache = {};
|
|
41265
41258
|
function preloadSessionCache(deviceId, passphraseState, sessionId) {
|
|
41266
41259
|
const key = `${deviceId}@${passphraseState}`;
|
|
@@ -41284,7 +41277,7 @@ class Device extends events.exports {
|
|
|
41284
41277
|
this.sdkInstanceId = sdkInstanceId;
|
|
41285
41278
|
this.instanceId = generateInstanceId('Device', this.sdkInstanceId);
|
|
41286
41279
|
this.createdAt = Date.now();
|
|
41287
|
-
Log$
|
|
41280
|
+
Log$c.debug(`[Device] Created: ${this.instanceId}${this.sdkInstanceId ? ` for SDK: ${this.sdkInstanceId}` : ''}`);
|
|
41288
41281
|
}
|
|
41289
41282
|
static fromDescriptor(originalDescriptor, sdkInstanceId) {
|
|
41290
41283
|
const descriptor = Object.assign({}, originalDescriptor);
|
|
@@ -41359,12 +41352,12 @@ class Device extends events.exports {
|
|
|
41359
41352
|
if (DataManager.isBleConnect(env)) {
|
|
41360
41353
|
acquireResult = yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.originalDescriptor.id, undefined, true, expectedProtocol));
|
|
41361
41354
|
this.mainId = (_b = acquireResult === null || acquireResult === void 0 ? void 0 : acquireResult.uuid) !== null && _b !== void 0 ? _b : '';
|
|
41362
|
-
Log$
|
|
41355
|
+
Log$c.debug('Expected uuid:', this.mainId);
|
|
41363
41356
|
}
|
|
41364
41357
|
else {
|
|
41365
41358
|
acquireResult = yield ((_c = this.deviceConnector) === null || _c === void 0 ? void 0 : _c.acquire(this.originalDescriptor.path, this.originalDescriptor.session, undefined, expectedProtocol));
|
|
41366
41359
|
this.mainId = acquireResult;
|
|
41367
|
-
Log$
|
|
41360
|
+
Log$c.debug('Expected session id:', this.mainId);
|
|
41368
41361
|
}
|
|
41369
41362
|
this.deviceAcquired = true;
|
|
41370
41363
|
this.updateDescriptor({ [mainIdKey]: this.mainId });
|
|
@@ -41396,11 +41389,11 @@ class Device extends events.exports {
|
|
|
41396
41389
|
(this.mainId && DataManager.isBleConnect(env))) {
|
|
41397
41390
|
if (this.pendingCallbackPromise) {
|
|
41398
41391
|
try {
|
|
41399
|
-
Log$
|
|
41392
|
+
Log$c.debug('Waiting for callback tasks to complete before releasing device (in release method)');
|
|
41400
41393
|
yield this.pendingCallbackPromise.promise;
|
|
41401
41394
|
}
|
|
41402
41395
|
catch (error) {
|
|
41403
|
-
Log$
|
|
41396
|
+
Log$c.error('Error waiting for callback tasks in release method:', error);
|
|
41404
41397
|
}
|
|
41405
41398
|
}
|
|
41406
41399
|
if (this.commands) {
|
|
@@ -41419,7 +41412,7 @@ class Device extends events.exports {
|
|
|
41419
41412
|
this.updateDescriptor({ session: null });
|
|
41420
41413
|
}
|
|
41421
41414
|
catch (err) {
|
|
41422
|
-
Log$
|
|
41415
|
+
Log$c.error('[Device] release error: ', err);
|
|
41423
41416
|
}
|
|
41424
41417
|
finally {
|
|
41425
41418
|
this.needReloadDevice = true;
|
|
@@ -41428,6 +41421,46 @@ class Device extends events.exports {
|
|
|
41428
41421
|
this.deviceAcquired = false;
|
|
41429
41422
|
});
|
|
41430
41423
|
}
|
|
41424
|
+
preInitialize(initOptions) {
|
|
41425
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41426
|
+
if (!this.features) {
|
|
41427
|
+
yield this.acquire();
|
|
41428
|
+
yield this.initialize(initOptions);
|
|
41429
|
+
}
|
|
41430
|
+
this.markPreInitialized({
|
|
41431
|
+
passphraseState: initOptions === null || initOptions === void 0 ? void 0 : initOptions.passphraseState,
|
|
41432
|
+
});
|
|
41433
|
+
});
|
|
41434
|
+
}
|
|
41435
|
+
markPreInitialized(meta) {
|
|
41436
|
+
this.preInitializedAt = Date.now();
|
|
41437
|
+
this.preInitializeMeta = meta
|
|
41438
|
+
? {
|
|
41439
|
+
passphraseState: meta.passphraseState === '' ? undefined : meta.passphraseState,
|
|
41440
|
+
}
|
|
41441
|
+
: undefined;
|
|
41442
|
+
}
|
|
41443
|
+
clearPreInitialized() {
|
|
41444
|
+
this.preInitializedAt = undefined;
|
|
41445
|
+
this.preInitializeMeta = undefined;
|
|
41446
|
+
}
|
|
41447
|
+
isPreInitializeMetaMatch(payload) {
|
|
41448
|
+
if (!this.preInitializeMeta)
|
|
41449
|
+
return true;
|
|
41450
|
+
const passphraseState = (payload === null || payload === void 0 ? void 0 : payload.passphraseState) === '' ? undefined : payload === null || payload === void 0 ? void 0 : payload.passphraseState;
|
|
41451
|
+
return this.preInitializeMeta.passphraseState === passphraseState;
|
|
41452
|
+
}
|
|
41453
|
+
isPreInitializedValid(ttlMs) {
|
|
41454
|
+
if (!this.preInitializedAt)
|
|
41455
|
+
return false;
|
|
41456
|
+
return Date.now() - this.preInitializedAt <= ttlMs;
|
|
41457
|
+
}
|
|
41458
|
+
setLastInitializeDuration(durationMs) {
|
|
41459
|
+
this.lastInitializeDurationMs = durationMs;
|
|
41460
|
+
}
|
|
41461
|
+
getLastInitializeDuration() {
|
|
41462
|
+
return this.lastInitializeDurationMs;
|
|
41463
|
+
}
|
|
41431
41464
|
getCommands() {
|
|
41432
41465
|
return this.commands;
|
|
41433
41466
|
}
|
|
@@ -41439,8 +41472,8 @@ class Device extends events.exports {
|
|
|
41439
41472
|
}
|
|
41440
41473
|
getInternalState(_deviceId) {
|
|
41441
41474
|
var _a, _b;
|
|
41442
|
-
Log$
|
|
41443
|
-
Log$
|
|
41475
|
+
Log$c.debug('getInternalState session cache: ', deviceSessionCache);
|
|
41476
|
+
Log$c.debug('getInternalState session param: ', `device_id: ${_deviceId}`, `features.device_id: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id}`, `passphraseState: ${this.passphraseState}`);
|
|
41444
41477
|
const deviceId = _deviceId || ((_b = this.features) === null || _b === void 0 ? void 0 : _b.device_id);
|
|
41445
41478
|
if (!deviceId)
|
|
41446
41479
|
return undefined;
|
|
@@ -41450,7 +41483,7 @@ class Device extends events.exports {
|
|
|
41450
41483
|
return deviceSessionCache[usePassKey];
|
|
41451
41484
|
}
|
|
41452
41485
|
updateInternalState(enablePassphrase, passphraseState, deviceId, sessionId = null, featuresSessionId = null) {
|
|
41453
|
-
Log$
|
|
41486
|
+
Log$c.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `passphraseState: ${passphraseState}`, `sessionId: ${sessionId}`, `featuresSessionId: ${featuresSessionId}`);
|
|
41454
41487
|
if (enablePassphrase) {
|
|
41455
41488
|
if (sessionId) {
|
|
41456
41489
|
deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = sessionId;
|
|
@@ -41463,11 +41496,11 @@ class Device extends events.exports {
|
|
|
41463
41496
|
if (deviceSessionCache[oldKey]) {
|
|
41464
41497
|
delete deviceSessionCache[oldKey];
|
|
41465
41498
|
}
|
|
41466
|
-
Log$
|
|
41499
|
+
Log$c.debug('updateInternalState session cache: ', deviceSessionCache);
|
|
41467
41500
|
}
|
|
41468
41501
|
setInternalState(state, initSession) {
|
|
41469
41502
|
var _a, _b;
|
|
41470
|
-
Log$
|
|
41503
|
+
Log$c.debug('setInternalState session param: ', `state: ${state}`, `initSession: ${initSession}`, `device_id: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id}`, `passphraseState: ${this.passphraseState}`);
|
|
41471
41504
|
if (!this.features)
|
|
41472
41505
|
return;
|
|
41473
41506
|
if (!this.passphraseState && !initSession)
|
|
@@ -41479,11 +41512,11 @@ class Device extends events.exports {
|
|
|
41479
41512
|
if (state) {
|
|
41480
41513
|
deviceSessionCache[key] = state;
|
|
41481
41514
|
}
|
|
41482
|
-
Log$
|
|
41515
|
+
Log$c.debug('setInternalState done session cache: ', deviceSessionCache);
|
|
41483
41516
|
}
|
|
41484
41517
|
clearInternalState(_deviceId) {
|
|
41485
41518
|
var _a;
|
|
41486
|
-
Log$
|
|
41519
|
+
Log$c.debug('clearInternalState param: ', _deviceId);
|
|
41487
41520
|
const deviceId = _deviceId || ((_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id);
|
|
41488
41521
|
if (!deviceId)
|
|
41489
41522
|
return;
|
|
@@ -41499,7 +41532,7 @@ class Device extends events.exports {
|
|
|
41499
41532
|
if (this.originalDescriptor.protocolType === 'V2') {
|
|
41500
41533
|
this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
|
|
41501
41534
|
if (this.features && !this.featuresNeedsReload && !(options === null || options === void 0 ? void 0 : options.initSession)) {
|
|
41502
|
-
Log$
|
|
41535
|
+
Log$c.debug('Skip Protocol V2 feature adapter; cached features are available');
|
|
41503
41536
|
return;
|
|
41504
41537
|
}
|
|
41505
41538
|
yield this._initializeProtocolV2();
|
|
@@ -41519,12 +41552,7 @@ class Device extends events.exports {
|
|
|
41519
41552
|
}
|
|
41520
41553
|
payload.passphrase_state = options === null || options === void 0 ? void 0 : options.passphraseState;
|
|
41521
41554
|
payload.is_contains_attach = true;
|
|
41522
|
-
|
|
41523
|
-
deviceId: options === null || options === void 0 ? void 0 : options.deviceId,
|
|
41524
|
-
passphraseState: options === null || options === void 0 ? void 0 : options.passphraseState,
|
|
41525
|
-
initSession: options === null || options === void 0 ? void 0 : options.initSession,
|
|
41526
|
-
InitializePayload: payload,
|
|
41527
|
-
});
|
|
41555
|
+
const initStartAt = Date.now();
|
|
41528
41556
|
try {
|
|
41529
41557
|
const { message } = yield Promise.race([
|
|
41530
41558
|
this.commands.typedCall('Initialize', 'Features', payload),
|
|
@@ -41534,45 +41562,57 @@ class Device extends events.exports {
|
|
|
41534
41562
|
}, 25 * 1000);
|
|
41535
41563
|
}),
|
|
41536
41564
|
]);
|
|
41537
|
-
|
|
41565
|
+
const initCostMs = Date.now() - initStartAt;
|
|
41566
|
+
this.setLastInitializeDuration(initCostMs);
|
|
41538
41567
|
this._updateFeatures(message, options === null || options === void 0 ? void 0 : options.initSession);
|
|
41539
41568
|
yield TransportManager.reconfigure(this.features);
|
|
41540
41569
|
}
|
|
41541
41570
|
catch (error) {
|
|
41542
|
-
Log$
|
|
41571
|
+
Log$c.error('Initialization failed:', error);
|
|
41543
41572
|
throw error;
|
|
41544
41573
|
}
|
|
41545
41574
|
});
|
|
41546
41575
|
}
|
|
41547
41576
|
_initializeProtocolV2() {
|
|
41548
41577
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41549
|
-
Log$
|
|
41578
|
+
Log$c.debug('Initialize device via Protocol V2 feature adapter');
|
|
41550
41579
|
try {
|
|
41551
41580
|
const features = yield Promise.race([
|
|
41552
|
-
|
|
41553
|
-
commands: this.commands,
|
|
41554
|
-
descriptor: this.originalDescriptor,
|
|
41555
|
-
timeoutMs: 10 * 1000,
|
|
41556
|
-
}),
|
|
41581
|
+
this._readProtocolV2Features(10 * 1000),
|
|
41557
41582
|
new Promise((_, reject) => {
|
|
41558
41583
|
setTimeout(() => {
|
|
41559
41584
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed));
|
|
41560
41585
|
}, 10 * 1000);
|
|
41561
41586
|
}),
|
|
41562
41587
|
]);
|
|
41563
|
-
Log$
|
|
41588
|
+
Log$c.debug('Protocol V2 normalized features:', features);
|
|
41564
41589
|
this._updateFeatures(features);
|
|
41565
41590
|
}
|
|
41566
41591
|
catch (error) {
|
|
41567
|
-
Log$
|
|
41592
|
+
Log$c.error('Protocol V2 initialization failed:', error);
|
|
41568
41593
|
throw error;
|
|
41569
41594
|
}
|
|
41570
41595
|
});
|
|
41571
41596
|
}
|
|
41597
|
+
_readProtocolV2Features(timeoutMs) {
|
|
41598
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41599
|
+
return getProtocolV2Features({
|
|
41600
|
+
commands: this.commands,
|
|
41601
|
+
descriptor: this.originalDescriptor,
|
|
41602
|
+
timeoutMs,
|
|
41603
|
+
});
|
|
41604
|
+
});
|
|
41605
|
+
}
|
|
41572
41606
|
getFeatures() {
|
|
41573
41607
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41608
|
+
if (this.originalDescriptor.protocolType === 'V2') {
|
|
41609
|
+
const features = yield this._readProtocolV2Features();
|
|
41610
|
+
this._updateFeatures(features);
|
|
41611
|
+
return features;
|
|
41612
|
+
}
|
|
41574
41613
|
const { message } = yield this.commands.typedCall('GetFeatures', 'Features', {});
|
|
41575
41614
|
this._updateFeatures(message);
|
|
41615
|
+
return message;
|
|
41576
41616
|
});
|
|
41577
41617
|
}
|
|
41578
41618
|
_updateFeatures(feat, initSession) {
|
|
@@ -41615,7 +41655,7 @@ class Device extends events.exports {
|
|
|
41615
41655
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41616
41656
|
if (this.runPromise) {
|
|
41617
41657
|
yield this.interruptionFromOutside();
|
|
41618
|
-
Log$
|
|
41658
|
+
Log$c.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
|
|
41619
41659
|
}
|
|
41620
41660
|
options = parseRunOptions(options);
|
|
41621
41661
|
this.runPromise = hdShared.createDeferred(this._runInner.bind(this, fn, options));
|
|
@@ -41637,7 +41677,9 @@ class Device extends events.exports {
|
|
|
41637
41677
|
}
|
|
41638
41678
|
try {
|
|
41639
41679
|
if (fn) {
|
|
41640
|
-
|
|
41680
|
+
if (!(options === null || options === void 0 ? void 0 : options.skipInitialize)) {
|
|
41681
|
+
yield this.initialize(options);
|
|
41682
|
+
}
|
|
41641
41683
|
}
|
|
41642
41684
|
}
|
|
41643
41685
|
catch (error) {
|
|
@@ -41671,7 +41713,7 @@ class Device extends events.exports {
|
|
|
41671
41713
|
yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.disconnect(this.mainId));
|
|
41672
41714
|
}
|
|
41673
41715
|
yield this.release();
|
|
41674
|
-
Log$
|
|
41716
|
+
Log$c.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
|
|
41675
41717
|
}
|
|
41676
41718
|
this.runPromise = null;
|
|
41677
41719
|
return;
|
|
@@ -41681,7 +41723,7 @@ class Device extends events.exports {
|
|
|
41681
41723
|
options.keepSession === false) {
|
|
41682
41724
|
this.keepSession = false;
|
|
41683
41725
|
yield this.release();
|
|
41684
|
-
Log$
|
|
41726
|
+
Log$c.debug('release device, mainId: ', this.mainId);
|
|
41685
41727
|
}
|
|
41686
41728
|
if (this.runPromise) {
|
|
41687
41729
|
this.runPromise.resolve();
|
|
@@ -41714,7 +41756,7 @@ class Device extends events.exports {
|
|
|
41714
41756
|
setCancelableAction(callback) {
|
|
41715
41757
|
this.cancelableAction = (e) => callback(e)
|
|
41716
41758
|
.catch(e2 => {
|
|
41717
|
-
Log$
|
|
41759
|
+
Log$c.debug('cancelableAction error', e2);
|
|
41718
41760
|
})
|
|
41719
41761
|
.finally(() => {
|
|
41720
41762
|
this.clearCancelableAction();
|
|
@@ -41798,7 +41840,8 @@ class Device extends events.exports {
|
|
|
41798
41840
|
hasUsePassphrase() {
|
|
41799
41841
|
var _a;
|
|
41800
41842
|
const isModeT = getDeviceType(this.features) === hdShared.EDeviceType.Touch ||
|
|
41801
|
-
getDeviceType(this.features) === hdShared.EDeviceType.Pro
|
|
41843
|
+
getDeviceType(this.features) === hdShared.EDeviceType.Pro ||
|
|
41844
|
+
getDeviceType(this.features) === hdShared.EDeviceType.Pro2;
|
|
41802
41845
|
const preCheckTouch = isModeT && ((_a = this.features) === null || _a === void 0 ? void 0 : _a.unlocked) === false;
|
|
41803
41846
|
return this.features && (!!this.features.passphrase_protection || preCheckTouch);
|
|
41804
41847
|
}
|
|
@@ -41810,9 +41853,6 @@ class Device extends events.exports {
|
|
|
41810
41853
|
}
|
|
41811
41854
|
lockDevice() {
|
|
41812
41855
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41813
|
-
if (getDeviceType(this.features) === hdShared.EDeviceType.Pro2) {
|
|
41814
|
-
return { message: 'LockDevice skipped for Pro2' };
|
|
41815
|
-
}
|
|
41816
41856
|
const res = yield this.commands.typedCall('LockDevice', 'Success', {});
|
|
41817
41857
|
return res.message;
|
|
41818
41858
|
});
|
|
@@ -41822,6 +41862,9 @@ class Device extends events.exports {
|
|
|
41822
41862
|
pro: {
|
|
41823
41863
|
min: '4.15.0',
|
|
41824
41864
|
},
|
|
41865
|
+
pro2: {
|
|
41866
|
+
min: '4.15.0',
|
|
41867
|
+
},
|
|
41825
41868
|
};
|
|
41826
41869
|
}
|
|
41827
41870
|
unlockDevice() {
|
|
@@ -41830,9 +41873,7 @@ class Device extends events.exports {
|
|
|
41830
41873
|
const firmwareVersion = (_a = getDeviceFirmwareVersion(this.features)) === null || _a === void 0 ? void 0 : _a.join('.');
|
|
41831
41874
|
const versionRange = getMethodVersionRange(this.features, type => this.supportUnlockVersionRange()[type]);
|
|
41832
41875
|
const supportAttachPinCapability = existCapability(this.features, hdTransport.Enum_Capability.Capability_AttachToPin);
|
|
41833
|
-
const isPro2 = getDeviceType(this.features) === hdShared.EDeviceType.Pro2;
|
|
41834
41876
|
const supportUnlock = supportAttachPinCapability ||
|
|
41835
|
-
isPro2 ||
|
|
41836
41877
|
(versionRange && semver__default["default"].gte(firmwareVersion, versionRange.min));
|
|
41837
41878
|
if (supportUnlock) {
|
|
41838
41879
|
const res = yield this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|
|
@@ -41844,9 +41885,8 @@ class Device extends events.exports {
|
|
|
41844
41885
|
res.message.passphrase_protection == null ? null : res.message.passphrase_protection;
|
|
41845
41886
|
return Promise.resolve(this.features);
|
|
41846
41887
|
}
|
|
41847
|
-
const
|
|
41848
|
-
|
|
41849
|
-
return Promise.resolve(featuresRes.message);
|
|
41888
|
+
const features = yield this.getFeatures();
|
|
41889
|
+
return Promise.resolve(features);
|
|
41850
41890
|
}
|
|
41851
41891
|
const { type } = yield this.commands.typedCall('GetAddress', 'Address', {
|
|
41852
41892
|
address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
|
|
@@ -41857,9 +41897,8 @@ class Device extends events.exports {
|
|
|
41857
41897
|
if (type === 'CallMethodError') {
|
|
41858
41898
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'unlock device error');
|
|
41859
41899
|
}
|
|
41860
|
-
const
|
|
41861
|
-
|
|
41862
|
-
return Promise.resolve(res.message);
|
|
41900
|
+
const features = yield this.getFeatures();
|
|
41901
|
+
return Promise.resolve(features);
|
|
41863
41902
|
});
|
|
41864
41903
|
}
|
|
41865
41904
|
checkPassphraseStateSafety(passphraseState, useEmptyPassphrase, skipPassphraseCheck) {
|
|
@@ -41873,7 +41912,7 @@ class Device extends events.exports {
|
|
|
41873
41912
|
const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
|
|
41874
41913
|
const useErrorAttachPin = unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
|
|
41875
41914
|
const passphraseStateMismatch = !!passphraseState && passphraseState !== newPassphraseState;
|
|
41876
|
-
Log$
|
|
41915
|
+
Log$c.debug('Check passphrase state safety: ', {
|
|
41877
41916
|
passphraseState,
|
|
41878
41917
|
newPassphraseState,
|
|
41879
41918
|
unlockedAttachPin,
|
|
@@ -41928,6 +41967,27 @@ class DeviceList extends events.exports {
|
|
|
41928
41967
|
}
|
|
41929
41968
|
}
|
|
41930
41969
|
|
|
41970
|
+
class PollingStateManager {
|
|
41971
|
+
constructor() {
|
|
41972
|
+
this.activePolls = new Map();
|
|
41973
|
+
}
|
|
41974
|
+
start(connectId) {
|
|
41975
|
+
var _a;
|
|
41976
|
+
const currentId = ((_a = this.activePolls.get(connectId)) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
41977
|
+
this.activePolls.set(connectId, currentId);
|
|
41978
|
+
return currentId;
|
|
41979
|
+
}
|
|
41980
|
+
isActive(connectId, pollingId) {
|
|
41981
|
+
return this.activePolls.get(connectId) === pollingId;
|
|
41982
|
+
}
|
|
41983
|
+
stop(connectId) {
|
|
41984
|
+
this.activePolls.delete(connectId);
|
|
41985
|
+
}
|
|
41986
|
+
stopAll() {
|
|
41987
|
+
this.activePolls.clear();
|
|
41988
|
+
}
|
|
41989
|
+
}
|
|
41990
|
+
|
|
41931
41991
|
const getFirmwareReleaseInfo = (features, firmwareType) => {
|
|
41932
41992
|
const firmwareStatus = DataManager.getFirmwareStatus(features, firmwareType);
|
|
41933
41993
|
const changelog = DataManager.getFirmwareChangelog(features, firmwareType);
|
|
@@ -41980,14 +42040,49 @@ const getBootloaderReleaseInfo = ({ features, willUpdateFirmwareVersion, firmwar
|
|
|
41980
42040
|
};
|
|
41981
42041
|
};
|
|
41982
42042
|
|
|
41983
|
-
const Log$
|
|
42043
|
+
const Log$b = getLogger(exports.LoggerNames.Method);
|
|
42044
|
+
const isEvmLedgerLegacyPathWithHighIndex = (path) => {
|
|
42045
|
+
let addressN;
|
|
42046
|
+
if (typeof path === 'string') {
|
|
42047
|
+
try {
|
|
42048
|
+
addressN = getHDPath(path);
|
|
42049
|
+
}
|
|
42050
|
+
catch (_a) {
|
|
42051
|
+
return false;
|
|
42052
|
+
}
|
|
42053
|
+
}
|
|
42054
|
+
else if (Array.isArray(path)) {
|
|
42055
|
+
addressN = path.map((item) => Number(item));
|
|
42056
|
+
}
|
|
42057
|
+
return (Array.isArray(addressN) &&
|
|
42058
|
+
addressN.length === 4 &&
|
|
42059
|
+
addressN[0] === toHardened(44) &&
|
|
42060
|
+
addressN[1] === toHardened(60) &&
|
|
42061
|
+
addressN[2] === toHardened(0) &&
|
|
42062
|
+
addressN[3] > 1 &&
|
|
42063
|
+
addressN[3] < toHardened(0));
|
|
42064
|
+
};
|
|
42065
|
+
const EVM_LEDGER_LEGACY_METHODS = ['evmGetAddress', 'evmGetPublicKey'];
|
|
41984
42066
|
class BaseMethod {
|
|
42067
|
+
getPreWarmKey() {
|
|
42068
|
+
var _a, _b, _c, _d;
|
|
42069
|
+
const payload = ((_a = this.payload) !== null && _a !== void 0 ? _a : {});
|
|
42070
|
+
return [
|
|
42071
|
+
(_c = (_b = this.connectId) !== null && _b !== void 0 ? _b : payload.connectId) !== null && _c !== void 0 ? _c : '',
|
|
42072
|
+
(_d = payload.passphraseState) !== null && _d !== void 0 ? _d : '',
|
|
42073
|
+
this.name,
|
|
42074
|
+
].join('|');
|
|
42075
|
+
}
|
|
41985
42076
|
constructor(message) {
|
|
41986
42077
|
this.shouldEnsureConnected = true;
|
|
41987
42078
|
this.checkDeviceId = false;
|
|
41988
42079
|
this.useDevicePassphraseState = true;
|
|
41989
42080
|
this.skipForceUpdateCheck = false;
|
|
42081
|
+
this.allowUsePreInitialize = false;
|
|
42082
|
+
this.isPreWarmSignal = false;
|
|
42083
|
+
this.preWarmTtl = 60 * 1000;
|
|
41990
42084
|
this.strictCheckDeviceSupport = false;
|
|
42085
|
+
this.temporarySafetyCheckPrompted = false;
|
|
41991
42086
|
this.postPreviousAddressMessage = (data) => {
|
|
41992
42087
|
this.postMessage(createUiMessage(UI_REQUEST.PREVIOUS_ADDRESS_RESULT, {
|
|
41993
42088
|
device: this.device.toMessageObject(),
|
|
@@ -42010,7 +42105,7 @@ class BaseMethod {
|
|
|
42010
42105
|
setContext(context) {
|
|
42011
42106
|
this.sdkInstanceId = context.sdkInstanceId;
|
|
42012
42107
|
this.instanceId = generateInstanceId('Method', this.sdkInstanceId);
|
|
42013
|
-
Log$
|
|
42108
|
+
Log$b.debug(`[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}`);
|
|
42014
42109
|
}
|
|
42015
42110
|
setDevice(device) {
|
|
42016
42111
|
var _a, _b;
|
|
@@ -42030,7 +42125,7 @@ class BaseMethod {
|
|
|
42030
42125
|
if (device.commands) {
|
|
42031
42126
|
device.commands.currentResponseID = this.responseID;
|
|
42032
42127
|
}
|
|
42033
|
-
Log$
|
|
42128
|
+
Log$b.debug(`[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${(_b = device.commands) === null || _b === void 0 ? void 0 : _b.instanceId}`);
|
|
42034
42129
|
}
|
|
42035
42130
|
checkFirmwareRelease() {
|
|
42036
42131
|
if (!this.device || !this.device.features)
|
|
@@ -42077,20 +42172,43 @@ class BaseMethod {
|
|
|
42077
42172
|
});
|
|
42078
42173
|
}
|
|
42079
42174
|
}
|
|
42175
|
+
shouldPromptSafetyCheckForEvmLedgerLegacyPath() {
|
|
42176
|
+
var _a, _b;
|
|
42177
|
+
if (!EVM_LEDGER_LEGACY_METHODS.includes(this.name)) {
|
|
42178
|
+
return false;
|
|
42179
|
+
}
|
|
42180
|
+
const deviceType = getDeviceType(this.device.features);
|
|
42181
|
+
if (!DeviceModelToTypes.model_touch.includes(deviceType)) {
|
|
42182
|
+
return false;
|
|
42183
|
+
}
|
|
42184
|
+
const paths = Array.isArray((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle)
|
|
42185
|
+
? this.payload.bundle.map((item) => item === null || item === void 0 ? void 0 : item.path)
|
|
42186
|
+
: [(_b = this.payload) === null || _b === void 0 ? void 0 : _b.path];
|
|
42187
|
+
return paths.some(isEvmLedgerLegacyPathWithHighIndex);
|
|
42188
|
+
}
|
|
42080
42189
|
checkSafetyLevelOnTestNet() {
|
|
42081
42190
|
var _a, _b, _c;
|
|
42082
42191
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42192
|
+
if (this.temporarySafetyCheckPrompted) {
|
|
42193
|
+
return false;
|
|
42194
|
+
}
|
|
42083
42195
|
let checkFlag = false;
|
|
42084
42196
|
if (this.name === 'evmSignTransaction' &&
|
|
42085
42197
|
[3, 4, 5, 420, 11155111].includes(Number((_b = (_a = this.payload) === null || _a === void 0 ? void 0 : _a.transaction) === null || _b === void 0 ? void 0 : _b.chainId))) {
|
|
42086
42198
|
checkFlag = true;
|
|
42087
42199
|
}
|
|
42200
|
+
if (this.shouldPromptSafetyCheckForEvmLedgerLegacyPath()) {
|
|
42201
|
+
checkFlag = true;
|
|
42202
|
+
}
|
|
42088
42203
|
if (checkFlag && ((_c = this.device.features) === null || _c === void 0 ? void 0 : _c.safety_checks) === 'Strict') {
|
|
42089
|
-
Log$
|
|
42204
|
+
Log$b.debug('will change safety_checks level');
|
|
42090
42205
|
yield this.device.commands.typedCall('ApplySettings', 'Success', {
|
|
42091
42206
|
safety_checks: 'PromptTemporarily',
|
|
42092
42207
|
});
|
|
42208
|
+
this.temporarySafetyCheckPrompted = true;
|
|
42209
|
+
return true;
|
|
42093
42210
|
}
|
|
42211
|
+
return false;
|
|
42094
42212
|
});
|
|
42095
42213
|
}
|
|
42096
42214
|
dispose() { }
|
|
@@ -42117,6 +42235,36 @@ class TestInitializeDeviceDuration extends BaseMethod {
|
|
|
42117
42235
|
}
|
|
42118
42236
|
}
|
|
42119
42237
|
|
|
42238
|
+
const Log$a = getLogger(exports.LoggerNames.Core);
|
|
42239
|
+
const parseInitOptions$1 = (payload) => ({
|
|
42240
|
+
initSession: payload === null || payload === void 0 ? void 0 : payload.initSession,
|
|
42241
|
+
passphraseState: payload === null || payload === void 0 ? void 0 : payload.passphraseState,
|
|
42242
|
+
deriveCardano: payload === null || payload === void 0 ? void 0 : payload.deriveCardano,
|
|
42243
|
+
});
|
|
42244
|
+
class PreInitialize extends BaseMethod {
|
|
42245
|
+
init() {
|
|
42246
|
+
this.skipForceUpdateCheck = true;
|
|
42247
|
+
this.useDevicePassphraseState = false;
|
|
42248
|
+
this.isPreWarmSignal = true;
|
|
42249
|
+
}
|
|
42250
|
+
run() {
|
|
42251
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42252
|
+
try {
|
|
42253
|
+
yield this.device.preInitialize(parseInitOptions$1(this.payload));
|
|
42254
|
+
if (this.device.hasDeviceAcquire()) {
|
|
42255
|
+
yield this.device.release();
|
|
42256
|
+
}
|
|
42257
|
+
return true;
|
|
42258
|
+
}
|
|
42259
|
+
catch (_a) {
|
|
42260
|
+
this.device.clearPreInitialized();
|
|
42261
|
+
Log$a.debug('[PRE-INIT][FAILED]');
|
|
42262
|
+
return false;
|
|
42263
|
+
}
|
|
42264
|
+
});
|
|
42265
|
+
}
|
|
42266
|
+
}
|
|
42267
|
+
|
|
42120
42268
|
class SearchDevices extends BaseMethod {
|
|
42121
42269
|
init() {
|
|
42122
42270
|
this.useDevice = false;
|
|
@@ -42489,10 +42637,11 @@ class GetPassphraseState extends BaseMethod {
|
|
|
42489
42637
|
allowCreateAttachPin: this.payload.allowCreateAttachPin,
|
|
42490
42638
|
});
|
|
42491
42639
|
const { features } = this.device;
|
|
42492
|
-
const isPro2 = getDeviceType(features) === hdShared.EDeviceType.Pro2;
|
|
42493
42640
|
const passphraseProtection = (_a = features === null || features === void 0 ? void 0 : features.passphrase_protection) !== null && _a !== void 0 ? _a : null;
|
|
42641
|
+
const deviceType = getDeviceType(features);
|
|
42642
|
+
const isProSeries = deviceType === hdShared.EDeviceType.Pro || deviceType === hdShared.EDeviceType.Pro2;
|
|
42494
42643
|
return Promise.resolve({
|
|
42495
|
-
passphrase_state:
|
|
42644
|
+
passphrase_state: isProSeries || passphraseProtection === true ? passphraseState : undefined,
|
|
42496
42645
|
session_id: (_b = newSession !== null && newSession !== void 0 ? newSession : features === null || features === void 0 ? void 0 : features.session_id) !== null && _b !== void 0 ? _b : undefined,
|
|
42497
42646
|
unlocked_attach_pin: unlockedAttachPin !== null && unlockedAttachPin !== void 0 ? unlockedAttachPin : features === null || features === void 0 ? void 0 : features.unlocked_attach_pin,
|
|
42498
42647
|
passphrase_protection: passphraseProtection,
|
|
@@ -43942,9 +44091,12 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
43942
44091
|
type,
|
|
43943
44092
|
}));
|
|
43944
44093
|
};
|
|
43945
|
-
this.postProgressMessage = (progress, progressType
|
|
43946
|
-
this.postMessage(createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS,
|
|
43947
|
-
|
|
44094
|
+
this.postProgressMessage = (progress, progressType) => {
|
|
44095
|
+
this.postMessage(createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
44096
|
+
device: this.device.toMessageObject(),
|
|
44097
|
+
progress,
|
|
44098
|
+
progressType,
|
|
44099
|
+
}));
|
|
43948
44100
|
};
|
|
43949
44101
|
}
|
|
43950
44102
|
init() { }
|
|
@@ -44140,7 +44292,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
44140
44292
|
});
|
|
44141
44293
|
});
|
|
44142
44294
|
}
|
|
44143
|
-
emmcCommonUpdateProcess({ payload, filePath, processedSize, totalSize,
|
|
44295
|
+
emmcCommonUpdateProcess({ payload, filePath, processedSize, totalSize, }) {
|
|
44144
44296
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44145
44297
|
if (!filePath.startsWith('0:')) {
|
|
44146
44298
|
throw new Error('filePath must start with 0:');
|
|
@@ -44150,6 +44302,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
44150
44302
|
const chunkSize = 1024 * perPackageSize;
|
|
44151
44303
|
const totalChunks = Math.ceil(payload.byteLength / chunkSize);
|
|
44152
44304
|
let offset = 0;
|
|
44305
|
+
let currentFileProcessed = 0;
|
|
44153
44306
|
for (let i = 0; i < totalChunks; i++) {
|
|
44154
44307
|
const chunkStart = i * chunkSize;
|
|
44155
44308
|
const chunkEnd = Math.min(chunkStart + chunkSize, payload.byteLength);
|
|
@@ -44158,7 +44311,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
44158
44311
|
const overwrite = i === 0;
|
|
44159
44312
|
let progress;
|
|
44160
44313
|
if (totalSize !== undefined && processedSize !== undefined) {
|
|
44161
|
-
|
|
44314
|
+
currentFileProcessed = processedSize + chunkEnd;
|
|
44162
44315
|
progress = Math.min(Math.ceil((currentFileProcessed / totalSize) * 100), 99);
|
|
44163
44316
|
}
|
|
44164
44317
|
else {
|
|
@@ -44166,15 +44319,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
44166
44319
|
}
|
|
44167
44320
|
const writeRes = yield this.emmcFileWriteWithRetry(filePath, chunkLength, offset, chunk, overwrite, progress);
|
|
44168
44321
|
offset += writeRes.message.processed_byte;
|
|
44169
|
-
|
|
44170
|
-
const transferredBytes = totalSize !== undefined && processedSize !== undefined ? processedSize + offset : offset;
|
|
44171
|
-
const totalBytes = totalSize !== null && totalSize !== void 0 ? totalSize : payload.byteLength;
|
|
44172
|
-
this.postProgressMessage(progress, 'transferData', {
|
|
44173
|
-
transferredBytes,
|
|
44174
|
-
totalBytes,
|
|
44175
|
-
rateBytesPerSecond: elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
|
|
44176
|
-
elapsedMs,
|
|
44177
|
-
});
|
|
44322
|
+
this.postProgressMessage(progress, 'transferData');
|
|
44178
44323
|
}
|
|
44179
44324
|
return totalSize !== undefined ? (processedSize !== null && processedSize !== void 0 ? processedSize : 0) + payload.byteLength : 0;
|
|
44180
44325
|
});
|
|
@@ -45006,7 +45151,6 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
45006
45151
|
totalSize += bootloaderBinary.byteLength;
|
|
45007
45152
|
}
|
|
45008
45153
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartTransferData);
|
|
45009
|
-
const transferStartTime = Date.now();
|
|
45010
45154
|
if (resourceBinary) {
|
|
45011
45155
|
const file = yield JSZip__default["default"].loadAsync(resourceBinary);
|
|
45012
45156
|
const files = Object.entries(file.files);
|
|
@@ -45019,7 +45163,6 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
45019
45163
|
filePath: `0:res/${name}`,
|
|
45020
45164
|
processedSize,
|
|
45021
45165
|
totalSize,
|
|
45022
|
-
transferStartTime,
|
|
45023
45166
|
});
|
|
45024
45167
|
}
|
|
45025
45168
|
}
|
|
@@ -45030,7 +45173,6 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
45030
45173
|
filePath: `0:boot/bootloader.bin`,
|
|
45031
45174
|
processedSize,
|
|
45032
45175
|
totalSize,
|
|
45033
|
-
transferStartTime,
|
|
45034
45176
|
});
|
|
45035
45177
|
}
|
|
45036
45178
|
yield this.createUpdatesFolderIfNotExists(`0:updates/`);
|
|
@@ -45041,7 +45183,6 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
45041
45183
|
filePath: `0:updates/${fwbinary.fileName}`,
|
|
45042
45184
|
processedSize,
|
|
45043
45185
|
totalSize,
|
|
45044
|
-
transferStartTime,
|
|
45045
45186
|
});
|
|
45046
45187
|
}
|
|
45047
45188
|
}
|
|
@@ -45647,7 +45788,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
45647
45788
|
if (bootloaderBinary)
|
|
45648
45789
|
totalSize += bootloaderBinary.byteLength;
|
|
45649
45790
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartTransferData);
|
|
45650
|
-
const transferStartTime = Date.now();
|
|
45651
45791
|
const targets = [];
|
|
45652
45792
|
if (resourceBinary) {
|
|
45653
45793
|
const resourcePath = `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}res/`;
|
|
@@ -45663,7 +45803,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
45663
45803
|
filePath: `${resourcePath}${name}`,
|
|
45664
45804
|
processedSize,
|
|
45665
45805
|
totalSize,
|
|
45666
|
-
transferStartTime,
|
|
45667
45806
|
});
|
|
45668
45807
|
}
|
|
45669
45808
|
}
|
|
@@ -45679,7 +45818,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
45679
45818
|
filePath: bootloaderPath,
|
|
45680
45819
|
processedSize,
|
|
45681
45820
|
totalSize,
|
|
45682
|
-
transferStartTime,
|
|
45683
45821
|
});
|
|
45684
45822
|
targets.push({
|
|
45685
45823
|
target_id: ProtocolV2FirmwareTargetType.TARGET_BOOTLOADER,
|
|
@@ -45693,7 +45831,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
45693
45831
|
filePath: firmwarePath,
|
|
45694
45832
|
processedSize,
|
|
45695
45833
|
totalSize,
|
|
45696
|
-
transferStartTime,
|
|
45697
45834
|
});
|
|
45698
45835
|
targets.push({
|
|
45699
45836
|
target_id: protocolV2FileNameToTargetId(fwbinary.fileName),
|
|
@@ -45863,7 +46000,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
45863
46000
|
yield typedCall('FilesystemDirMake', 'Success', { path });
|
|
45864
46001
|
});
|
|
45865
46002
|
}
|
|
45866
|
-
protocolV2CommonUpdateProcess({ payload, filePath, processedSize, totalSize,
|
|
46003
|
+
protocolV2CommonUpdateProcess({ payload, filePath, processedSize, totalSize, }) {
|
|
45867
46004
|
var _a;
|
|
45868
46005
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45869
46006
|
const chunkSize = this.getProtocolV2FirmwareChunkSize();
|
|
@@ -45886,17 +46023,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
45886
46023
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.EmmcFileWriteFirmwareError, `invalid processed_byte ${nextOffset} for offset ${offset}`);
|
|
45887
46024
|
}
|
|
45888
46025
|
offset = nextOffset;
|
|
45889
|
-
|
|
45890
|
-
const transferredBytes = totalSize !== undefined && processedSize !== undefined
|
|
45891
|
-
? Math.min(processedSize + offset, totalSize)
|
|
45892
|
-
: offset;
|
|
45893
|
-
const totalBytes = totalSize !== null && totalSize !== void 0 ? totalSize : payload.byteLength;
|
|
45894
|
-
this.postProgressMessage(getUploadProgress(offset), 'transferData', {
|
|
45895
|
-
transferredBytes,
|
|
45896
|
-
totalBytes,
|
|
45897
|
-
rateBytesPerSecond: elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
|
|
45898
|
-
elapsedMs,
|
|
45899
|
-
});
|
|
46026
|
+
this.postProgressMessage(getUploadProgress(offset), 'transferData');
|
|
45900
46027
|
}
|
|
45901
46028
|
return totalSize !== undefined ? (processedSize !== null && processedSize !== void 0 ? processedSize : 0) + payload.byteLength : 0;
|
|
45902
46029
|
});
|
|
@@ -46956,6 +47083,15 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
46956
47083
|
this.device.on(DEVICE.PIN, onSignalAbort);
|
|
46957
47084
|
this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
|
|
46958
47085
|
preCheckDeviceSupport(this.device, method);
|
|
47086
|
+
if (this.temporarySafetyCheckPrompted) {
|
|
47087
|
+
method.temporarySafetyCheckPrompted = true;
|
|
47088
|
+
}
|
|
47089
|
+
else {
|
|
47090
|
+
const appliedTemporarySafetyCheck = yield method.checkSafetyLevelOnTestNet();
|
|
47091
|
+
if (appliedTemporarySafetyCheck) {
|
|
47092
|
+
this.temporarySafetyCheckPrompted = true;
|
|
47093
|
+
}
|
|
47094
|
+
}
|
|
46959
47095
|
const response = yield method.run();
|
|
46960
47096
|
if (!Array.isArray(response) || response.length === 0) {
|
|
46961
47097
|
throw new Error('No response');
|
|
@@ -47846,6 +47982,7 @@ class BTCSignMessage extends BaseMethod {
|
|
|
47846
47982
|
init() {
|
|
47847
47983
|
this.checkDeviceId = true;
|
|
47848
47984
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
47985
|
+
this.allowUsePreInitialize = true;
|
|
47849
47986
|
validateParams(this.payload, [
|
|
47850
47987
|
{ name: 'path', required: true },
|
|
47851
47988
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -47902,6 +48039,7 @@ class BTCSignPsbt extends BaseMethod {
|
|
|
47902
48039
|
init() {
|
|
47903
48040
|
this.checkDeviceId = true;
|
|
47904
48041
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
48042
|
+
this.allowUsePreInitialize = true;
|
|
47905
48043
|
validateParams(this.payload, [
|
|
47906
48044
|
{ name: 'psbt', type: 'hexString', required: true },
|
|
47907
48045
|
{ name: 'coin', type: 'string' },
|
|
@@ -48220,6 +48358,7 @@ class BTCSignTransaction extends BaseMethod {
|
|
|
48220
48358
|
init() {
|
|
48221
48359
|
this.checkDeviceId = true;
|
|
48222
48360
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
48361
|
+
this.allowUsePreInitialize = true;
|
|
48223
48362
|
validateParams(this.payload, [
|
|
48224
48363
|
{ name: 'coin', type: 'string', required: true },
|
|
48225
48364
|
{ name: 'inputs', type: 'array', required: true },
|
|
@@ -48400,6 +48539,7 @@ class ConfluxGetAddress extends BaseMethod {
|
|
|
48400
48539
|
class ConfluxSignMessage extends BaseMethod {
|
|
48401
48540
|
init() {
|
|
48402
48541
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
48542
|
+
this.allowUsePreInitialize = true;
|
|
48403
48543
|
validateParams(this.payload, [
|
|
48404
48544
|
{ name: 'path', required: true },
|
|
48405
48545
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -48429,6 +48569,7 @@ class ConfluxSignMessage extends BaseMethod {
|
|
|
48429
48569
|
class ConfluxSignMessageCIP23 extends BaseMethod {
|
|
48430
48570
|
init() {
|
|
48431
48571
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
48572
|
+
this.allowUsePreInitialize = true;
|
|
48432
48573
|
validateParams(this.payload, [
|
|
48433
48574
|
{ name: 'path', required: true },
|
|
48434
48575
|
{ name: 'domainHash', type: 'hexString', required: true },
|
|
@@ -48514,6 +48655,7 @@ class ConfluxSignTransaction extends BaseMethod {
|
|
|
48514
48655
|
}
|
|
48515
48656
|
init() {
|
|
48516
48657
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
48658
|
+
this.allowUsePreInitialize = true;
|
|
48517
48659
|
validateParams(this.payload, [
|
|
48518
48660
|
{ name: 'path', required: true },
|
|
48519
48661
|
{ name: 'transaction', type: 'object', required: true },
|
|
@@ -48757,10 +48899,12 @@ class EVMSignMessage$2 extends BaseMethod {
|
|
|
48757
48899
|
init() {
|
|
48758
48900
|
this.checkDeviceId = true;
|
|
48759
48901
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
48902
|
+
this.allowUsePreInitialize = true;
|
|
48760
48903
|
validateParams(this.payload, [
|
|
48761
48904
|
{ name: 'path', required: true },
|
|
48762
48905
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
48763
48906
|
{ name: 'chainId', type: 'number' },
|
|
48907
|
+
{ name: 'usePreInitialize', type: 'boolean' },
|
|
48764
48908
|
]);
|
|
48765
48909
|
const { path, messageHex, chainId } = this.payload;
|
|
48766
48910
|
const addressN = validatePath(path, 3);
|
|
@@ -48790,6 +48934,7 @@ class EVMSignMessageEIP712 extends BaseMethod {
|
|
|
48790
48934
|
init() {
|
|
48791
48935
|
this.checkDeviceId = true;
|
|
48792
48936
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
48937
|
+
this.allowUsePreInitialize = true;
|
|
48793
48938
|
validateParams(this.payload, [
|
|
48794
48939
|
{ name: 'path', required: true },
|
|
48795
48940
|
{ name: 'domainHash', type: 'hexString', required: true },
|
|
@@ -49030,9 +49175,11 @@ class EVMSignTransaction extends BaseMethod {
|
|
|
49030
49175
|
init() {
|
|
49031
49176
|
this.checkDeviceId = true;
|
|
49032
49177
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
49178
|
+
this.allowUsePreInitialize = true;
|
|
49033
49179
|
validateParams(this.payload, [
|
|
49034
49180
|
{ name: 'path', required: true },
|
|
49035
49181
|
{ name: 'transaction', type: 'object', required: true },
|
|
49182
|
+
{ name: 'usePreInitialize', type: 'boolean' },
|
|
49036
49183
|
]);
|
|
49037
49184
|
const { path, transaction } = this.payload;
|
|
49038
49185
|
this.addressN = validatePath(path, 3);
|
|
@@ -49299,6 +49446,7 @@ class EVMSignTypedData extends BaseMethod {
|
|
|
49299
49446
|
init() {
|
|
49300
49447
|
this.checkDeviceId = true;
|
|
49301
49448
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
49449
|
+
this.allowUsePreInitialize = true;
|
|
49302
49450
|
validateParams(this.payload, [
|
|
49303
49451
|
{ name: 'path', required: true },
|
|
49304
49452
|
{ name: 'metamaskV4Compat', type: 'boolean' },
|
|
@@ -49306,6 +49454,7 @@ class EVMSignTypedData extends BaseMethod {
|
|
|
49306
49454
|
{ name: 'domainHash', type: 'hexString' },
|
|
49307
49455
|
{ name: 'messageHash', type: 'hexString' },
|
|
49308
49456
|
{ name: 'chainId', type: 'number' },
|
|
49457
|
+
{ name: 'usePreInitialize', type: 'boolean' },
|
|
49309
49458
|
]);
|
|
49310
49459
|
const { path, data, metamaskV4Compat, domainHash, messageHash, chainId } = this.payload;
|
|
49311
49460
|
const addressN = validatePath(path, 3);
|
|
@@ -49852,6 +50001,7 @@ class StarcoinSignMessage extends BaseMethod {
|
|
|
49852
50001
|
init() {
|
|
49853
50002
|
this.checkDeviceId = true;
|
|
49854
50003
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
50004
|
+
this.allowUsePreInitialize = true;
|
|
49855
50005
|
validateParams(this.payload, [
|
|
49856
50006
|
{ name: 'path', required: true },
|
|
49857
50007
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -49875,6 +50025,7 @@ class StarcoinSignTransaction extends BaseMethod {
|
|
|
49875
50025
|
init() {
|
|
49876
50026
|
this.checkDeviceId = true;
|
|
49877
50027
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
50028
|
+
this.allowUsePreInitialize = true;
|
|
49878
50029
|
validateParams(this.payload, [
|
|
49879
50030
|
{ name: 'path', required: true },
|
|
49880
50031
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -50143,6 +50294,7 @@ class NEMSignTransaction extends BaseMethod {
|
|
|
50143
50294
|
init() {
|
|
50144
50295
|
this.checkDeviceId = true;
|
|
50145
50296
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
50297
|
+
this.allowUsePreInitialize = true;
|
|
50146
50298
|
validateParams(this.payload, [
|
|
50147
50299
|
{ name: 'path', required: true },
|
|
50148
50300
|
{ name: 'transaction', type: 'object', required: true },
|
|
@@ -50220,6 +50372,7 @@ class SolSignTransaction extends BaseMethod {
|
|
|
50220
50372
|
var _a;
|
|
50221
50373
|
this.checkDeviceId = true;
|
|
50222
50374
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
50375
|
+
this.allowUsePreInitialize = true;
|
|
50223
50376
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
50224
50377
|
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
50225
50378
|
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
@@ -50239,7 +50392,6 @@ class SolSignTransaction extends BaseMethod {
|
|
|
50239
50392
|
return {
|
|
50240
50393
|
pro2: {
|
|
50241
50394
|
min: '0.0.0',
|
|
50242
|
-
unsupported: true,
|
|
50243
50395
|
},
|
|
50244
50396
|
model_mini: {
|
|
50245
50397
|
min: '3.1.0',
|
|
@@ -50252,7 +50404,6 @@ class SolSignTransaction extends BaseMethod {
|
|
|
50252
50404
|
return {
|
|
50253
50405
|
pro2: {
|
|
50254
50406
|
min: '0.0.0',
|
|
50255
|
-
unsupported: true,
|
|
50256
50407
|
},
|
|
50257
50408
|
classic: {
|
|
50258
50409
|
min: '2.1.9',
|
|
@@ -50305,6 +50456,7 @@ class SolSignOffchainMessage extends BaseMethod {
|
|
|
50305
50456
|
init() {
|
|
50306
50457
|
this.checkDeviceId = true;
|
|
50307
50458
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
50459
|
+
this.allowUsePreInitialize = true;
|
|
50308
50460
|
validateParams(this.payload, [
|
|
50309
50461
|
{ name: 'path', required: true },
|
|
50310
50462
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -50326,7 +50478,6 @@ class SolSignOffchainMessage extends BaseMethod {
|
|
|
50326
50478
|
return {
|
|
50327
50479
|
pro2: {
|
|
50328
50480
|
min: '0.0.0',
|
|
50329
|
-
unsupported: true,
|
|
50330
50481
|
},
|
|
50331
50482
|
pro: {
|
|
50332
50483
|
min: '4.12.0',
|
|
@@ -50351,6 +50502,7 @@ class SolSignMessage extends BaseMethod {
|
|
|
50351
50502
|
init() {
|
|
50352
50503
|
this.checkDeviceId = true;
|
|
50353
50504
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
50505
|
+
this.allowUsePreInitialize = true;
|
|
50354
50506
|
validateParams(this.payload, [
|
|
50355
50507
|
{ name: 'path', required: true },
|
|
50356
50508
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -50366,7 +50518,6 @@ class SolSignMessage extends BaseMethod {
|
|
|
50366
50518
|
return {
|
|
50367
50519
|
pro2: {
|
|
50368
50520
|
min: '0.0.0',
|
|
50369
|
-
unsupported: true,
|
|
50370
50521
|
},
|
|
50371
50522
|
pro: {
|
|
50372
50523
|
min: '4.12.0',
|
|
@@ -50672,6 +50823,7 @@ class StellarSignTransaction extends BaseMethod {
|
|
|
50672
50823
|
init() {
|
|
50673
50824
|
this.checkDeviceId = true;
|
|
50674
50825
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
50826
|
+
this.allowUsePreInitialize = true;
|
|
50675
50827
|
validateParams(this.payload, [
|
|
50676
50828
|
{ name: 'path', required: true },
|
|
50677
50829
|
{ name: 'networkPassphrase', type: 'string', required: true },
|
|
@@ -50782,6 +50934,7 @@ class TronSignMessage extends BaseMethod {
|
|
|
50782
50934
|
var _a;
|
|
50783
50935
|
this.checkDeviceId = true;
|
|
50784
50936
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
50937
|
+
this.allowUsePreInitialize = true;
|
|
50785
50938
|
validateParams(this.payload, [
|
|
50786
50939
|
{ name: 'path', required: true },
|
|
50787
50940
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -50940,6 +51093,7 @@ class TronSignTransaction extends BaseMethod {
|
|
|
50940
51093
|
init() {
|
|
50941
51094
|
this.checkDeviceId = true;
|
|
50942
51095
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
51096
|
+
this.allowUsePreInitialize = true;
|
|
50943
51097
|
validateParams(this.payload, [
|
|
50944
51098
|
{ name: 'path', required: true },
|
|
50945
51099
|
{ name: 'transaction', type: 'object', required: true },
|
|
@@ -51073,6 +51227,7 @@ class NearSignTransaction extends BaseMethod {
|
|
|
51073
51227
|
init() {
|
|
51074
51228
|
this.checkDeviceId = true;
|
|
51075
51229
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
51230
|
+
this.allowUsePreInitialize = true;
|
|
51076
51231
|
validateParams(this.payload, [
|
|
51077
51232
|
{ name: 'path', required: true },
|
|
51078
51233
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -51249,6 +51404,7 @@ class AptosSignTransaction extends BaseMethod {
|
|
|
51249
51404
|
init() {
|
|
51250
51405
|
this.checkDeviceId = true;
|
|
51251
51406
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
51407
|
+
this.allowUsePreInitialize = true;
|
|
51252
51408
|
validateParams(this.payload, [
|
|
51253
51409
|
{ name: 'path', required: true },
|
|
51254
51410
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -51299,6 +51455,7 @@ class AptosSignMessage extends BaseMethod {
|
|
|
51299
51455
|
init() {
|
|
51300
51456
|
this.checkDeviceId = true;
|
|
51301
51457
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
51458
|
+
this.allowUsePreInitialize = true;
|
|
51302
51459
|
validateParams(this.payload, [
|
|
51303
51460
|
{ name: 'path', required: true },
|
|
51304
51461
|
{ name: 'payload', type: 'object', required: true },
|
|
@@ -51360,6 +51517,7 @@ class AptosSignInMessage extends BaseMethod {
|
|
|
51360
51517
|
init() {
|
|
51361
51518
|
this.checkDeviceId = true;
|
|
51362
51519
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
51520
|
+
this.allowUsePreInitialize = true;
|
|
51363
51521
|
validateParams(this.payload, [
|
|
51364
51522
|
{ name: 'path', required: true },
|
|
51365
51523
|
{ name: 'payload', type: 'string', required: true },
|
|
@@ -51455,6 +51613,7 @@ class AlgoSignTransaction extends BaseMethod {
|
|
|
51455
51613
|
init() {
|
|
51456
51614
|
this.checkDeviceId = true;
|
|
51457
51615
|
this.allowDeviceMode = [...this.allowDeviceMode];
|
|
51616
|
+
this.allowUsePreInitialize = true;
|
|
51458
51617
|
validateParams(this.payload, [
|
|
51459
51618
|
{ name: 'path', required: true },
|
|
51460
51619
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -51617,6 +51776,7 @@ class CosmosSignTransaction extends BaseMethod {
|
|
|
51617
51776
|
init() {
|
|
51618
51777
|
this.checkDeviceId = true;
|
|
51619
51778
|
this.allowDeviceMode = [...this.allowDeviceMode];
|
|
51779
|
+
this.allowUsePreInitialize = true;
|
|
51620
51780
|
validateParams(this.payload, [
|
|
51621
51781
|
{ name: 'path', required: true },
|
|
51622
51782
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -51738,6 +51898,7 @@ class XrpGetAddress extends BaseMethod {
|
|
|
51738
51898
|
init() {
|
|
51739
51899
|
this.checkDeviceId = true;
|
|
51740
51900
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
51901
|
+
this.allowUsePreInitialize = true;
|
|
51741
51902
|
const { payload } = this;
|
|
51742
51903
|
validateParams(payload, [
|
|
51743
51904
|
{ name: 'path', required: true },
|
|
@@ -51964,6 +52125,7 @@ class SuiSignMessage extends BaseMethod {
|
|
|
51964
52125
|
init() {
|
|
51965
52126
|
this.checkDeviceId = true;
|
|
51966
52127
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
52128
|
+
this.allowUsePreInitialize = true;
|
|
51967
52129
|
validateParams(this.payload, [
|
|
51968
52130
|
{ name: 'path', required: true },
|
|
51969
52131
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -52020,6 +52182,7 @@ class SuiSignTransaction extends BaseMethod {
|
|
|
52020
52182
|
init() {
|
|
52021
52183
|
this.checkDeviceId = true;
|
|
52022
52184
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
52185
|
+
this.allowUsePreInitialize = true;
|
|
52023
52186
|
validateParams(this.payload, [
|
|
52024
52187
|
{ name: 'path', required: true },
|
|
52025
52188
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -52826,6 +52989,7 @@ class CardanoSignTransaction extends BaseMethod {
|
|
|
52826
52989
|
var _a;
|
|
52827
52990
|
this.checkDeviceId = true;
|
|
52828
52991
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
52992
|
+
this.allowUsePreInitialize = true;
|
|
52829
52993
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
52830
52994
|
const { payload } = this;
|
|
52831
52995
|
if (payload.auxiliaryData && payload.auxiliaryData.governanceRegistrationParameters) {
|
|
@@ -53061,6 +53225,7 @@ class CardanoSignMessage extends BaseMethod {
|
|
|
53061
53225
|
init() {
|
|
53062
53226
|
this.checkDeviceId = true;
|
|
53063
53227
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
53228
|
+
this.allowUsePreInitialize = true;
|
|
53064
53229
|
const { payload } = this;
|
|
53065
53230
|
validateParams(payload, [
|
|
53066
53231
|
{ name: 'path', type: 'string', required: true },
|
|
@@ -53174,6 +53339,7 @@ class FilecoinSignTransaction extends BaseMethod {
|
|
|
53174
53339
|
init() {
|
|
53175
53340
|
this.checkDeviceId = true;
|
|
53176
53341
|
this.allowDeviceMode = [...this.allowDeviceMode];
|
|
53342
|
+
this.allowUsePreInitialize = true;
|
|
53177
53343
|
validateParams(this.payload, [
|
|
53178
53344
|
{ name: 'path', required: true },
|
|
53179
53345
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -53344,6 +53510,7 @@ class PolkadotSignTransaction extends BaseMethod {
|
|
|
53344
53510
|
init() {
|
|
53345
53511
|
this.checkDeviceId = true;
|
|
53346
53512
|
this.allowDeviceMode = [...this.allowDeviceMode];
|
|
53513
|
+
this.allowUsePreInitialize = true;
|
|
53347
53514
|
validateParams(this.payload, [
|
|
53348
53515
|
{ name: 'path', required: true },
|
|
53349
53516
|
{ name: 'network', required: true },
|
|
@@ -53766,6 +53933,7 @@ class KaspaSignTransaction extends BaseMethod {
|
|
|
53766
53933
|
var _a, _b, _c, _d, _e;
|
|
53767
53934
|
this.checkDeviceId = true;
|
|
53768
53935
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
53936
|
+
this.allowUsePreInitialize = true;
|
|
53769
53937
|
const payload = this.payload;
|
|
53770
53938
|
validateParams(payload, [
|
|
53771
53939
|
{ name: 'version', type: 'number' },
|
|
@@ -53942,6 +54110,7 @@ class NexaSignTransaction extends BaseMethod {
|
|
|
53942
54110
|
this.hasBundle = false;
|
|
53943
54111
|
}
|
|
53944
54112
|
init() {
|
|
54113
|
+
this.allowUsePreInitialize = true;
|
|
53945
54114
|
const payload = this.payload;
|
|
53946
54115
|
payload.inputs.forEach(input => {
|
|
53947
54116
|
validateParams(input, [
|
|
@@ -54097,6 +54266,7 @@ class NostrSignEvent extends BaseMethod {
|
|
|
54097
54266
|
init() {
|
|
54098
54267
|
this.checkDeviceId = true;
|
|
54099
54268
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
54269
|
+
this.allowUsePreInitialize = true;
|
|
54100
54270
|
const { payload } = this;
|
|
54101
54271
|
if (!validateEvent(payload.event)) {
|
|
54102
54272
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Can't serialize event with wrong or missing properties`);
|
|
@@ -54239,6 +54409,7 @@ class NostrSignSchnorr extends BaseMethod {
|
|
|
54239
54409
|
init() {
|
|
54240
54410
|
this.checkDeviceId = true;
|
|
54241
54411
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
54412
|
+
this.allowUsePreInitialize = true;
|
|
54242
54413
|
const { payload } = this;
|
|
54243
54414
|
validateParams(payload, [
|
|
54244
54415
|
{ name: 'path', required: true },
|
|
@@ -54406,6 +54577,7 @@ class NervosSignTransaction extends BaseMethod {
|
|
|
54406
54577
|
init() {
|
|
54407
54578
|
this.checkDeviceId = true;
|
|
54408
54579
|
this.allowDeviceMode = [...this.allowDeviceMode];
|
|
54580
|
+
this.allowUsePreInitialize = true;
|
|
54409
54581
|
validateParams(this.payload, [
|
|
54410
54582
|
{ name: 'path', required: true },
|
|
54411
54583
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -54521,6 +54693,7 @@ class DnxSignTransaction extends BaseMethod {
|
|
|
54521
54693
|
init() {
|
|
54522
54694
|
this.checkDeviceId = true;
|
|
54523
54695
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
54696
|
+
this.allowUsePreInitialize = true;
|
|
54524
54697
|
const { payload } = this;
|
|
54525
54698
|
const addressN = validatePath(payload.path, 3);
|
|
54526
54699
|
validateParams(payload, [
|
|
@@ -54709,6 +54882,7 @@ class TonSignMessage extends BaseMethod {
|
|
|
54709
54882
|
this.strictCheckDeviceSupport = true;
|
|
54710
54883
|
this.checkDeviceId = true;
|
|
54711
54884
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
54885
|
+
this.allowUsePreInitialize = true;
|
|
54712
54886
|
validateParams(this.payload, [
|
|
54713
54887
|
{ name: 'path', required: true },
|
|
54714
54888
|
{ name: 'destination', type: 'string' },
|
|
@@ -54856,6 +55030,7 @@ class TonSignProof extends BaseMethod {
|
|
|
54856
55030
|
this.strictCheckDeviceSupport = true;
|
|
54857
55031
|
this.checkDeviceId = true;
|
|
54858
55032
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
55033
|
+
this.allowUsePreInitialize = true;
|
|
54859
55034
|
validateParams(this.payload, [
|
|
54860
55035
|
{ name: 'path', required: true },
|
|
54861
55036
|
{ name: 'appdomain', type: 'string' },
|
|
@@ -54907,6 +55082,7 @@ class TonSignData extends BaseMethod {
|
|
|
54907
55082
|
this.strictCheckDeviceSupport = false;
|
|
54908
55083
|
this.checkDeviceId = true;
|
|
54909
55084
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
55085
|
+
this.allowUsePreInitialize = true;
|
|
54910
55086
|
validateParams(this.payload, [
|
|
54911
55087
|
{ name: 'path', required: true },
|
|
54912
55088
|
{ name: 'type', type: 'number', required: true },
|
|
@@ -55034,6 +55210,7 @@ class ScdoSignTransaction extends BaseMethod {
|
|
|
55034
55210
|
init() {
|
|
55035
55211
|
this.checkDeviceId = true;
|
|
55036
55212
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
55213
|
+
this.allowUsePreInitialize = true;
|
|
55037
55214
|
validateParams(this.payload, [
|
|
55038
55215
|
{ name: 'path', required: true },
|
|
55039
55216
|
{ name: 'nonce', required: true },
|
|
@@ -55091,6 +55268,7 @@ class ScdoSignMessage extends BaseMethod {
|
|
|
55091
55268
|
init() {
|
|
55092
55269
|
this.checkDeviceId = true;
|
|
55093
55270
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
55271
|
+
this.allowUsePreInitialize = true;
|
|
55094
55272
|
validateParams(this.payload, [
|
|
55095
55273
|
{ name: 'path', required: true },
|
|
55096
55274
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -55221,6 +55399,7 @@ class AlephiumSignTransaction extends BaseMethod {
|
|
|
55221
55399
|
init() {
|
|
55222
55400
|
this.checkDeviceId = true;
|
|
55223
55401
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
55402
|
+
this.allowUsePreInitialize = true;
|
|
55224
55403
|
validateParams(this.payload, [
|
|
55225
55404
|
{ name: 'path', required: true },
|
|
55226
55405
|
{ name: 'rawTx', required: true, type: 'hexString' },
|
|
@@ -55266,6 +55445,7 @@ class AlephiumSignMessage extends BaseMethod {
|
|
|
55266
55445
|
init() {
|
|
55267
55446
|
this.checkDeviceId = true;
|
|
55268
55447
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
55448
|
+
this.allowUsePreInitialize = true;
|
|
55269
55449
|
validateParams(this.payload, [
|
|
55270
55450
|
{ name: 'path', required: true },
|
|
55271
55451
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -55483,6 +55663,7 @@ class BenfenSignMessage extends BaseMethod {
|
|
|
55483
55663
|
init() {
|
|
55484
55664
|
this.checkDeviceId = true;
|
|
55485
55665
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
55666
|
+
this.allowUsePreInitialize = true;
|
|
55486
55667
|
validateParams(this.payload, [
|
|
55487
55668
|
{ name: 'path', required: true },
|
|
55488
55669
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -55540,6 +55721,7 @@ class BenfenSignTransaction extends BaseMethod {
|
|
|
55540
55721
|
init() {
|
|
55541
55722
|
this.checkDeviceId = true;
|
|
55542
55723
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
55724
|
+
this.allowUsePreInitialize = true;
|
|
55543
55725
|
validateParams(this.payload, [
|
|
55544
55726
|
{ name: 'path', required: true },
|
|
55545
55727
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -55655,6 +55837,7 @@ class NeoSignTransaction extends BaseMethod {
|
|
|
55655
55837
|
init() {
|
|
55656
55838
|
this.checkDeviceId = true;
|
|
55657
55839
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
55840
|
+
this.allowUsePreInitialize = true;
|
|
55658
55841
|
this.strictCheckDeviceSupport = true;
|
|
55659
55842
|
validateParams(this.payload, [
|
|
55660
55843
|
{ name: 'path', required: true },
|
|
@@ -55703,6 +55886,7 @@ class NeoSignTransaction extends BaseMethod {
|
|
|
55703
55886
|
var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
55704
55887
|
__proto__: null,
|
|
55705
55888
|
testInitializeDeviceDuration: TestInitializeDeviceDuration,
|
|
55889
|
+
preInitialize: PreInitialize,
|
|
55706
55890
|
searchDevices: SearchDevices,
|
|
55707
55891
|
getFeatures: GetFeatures,
|
|
55708
55892
|
getDeviceInfo: GetDeviceInfo,
|
|
@@ -56091,13 +56275,15 @@ class RequestQueue {
|
|
|
56091
56275
|
this.pendingCallbackTasks.set(connectId, callbackPromise);
|
|
56092
56276
|
callbackPromise.promise.finally(() => {
|
|
56093
56277
|
Log$1.debug(`Callback task completed for connectId: ${connectId}`);
|
|
56094
|
-
this.pendingCallbackTasks.
|
|
56278
|
+
if (this.pendingCallbackTasks.get(connectId) === callbackPromise) {
|
|
56279
|
+
this.pendingCallbackTasks.delete(connectId);
|
|
56280
|
+
}
|
|
56095
56281
|
});
|
|
56096
56282
|
}
|
|
56097
|
-
waitForPendingCallbackTasks(connectId) {
|
|
56283
|
+
waitForPendingCallbackTasks(connectId, exceptTask) {
|
|
56098
56284
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56099
56285
|
const pendingTask = this.pendingCallbackTasks.get(connectId);
|
|
56100
|
-
if (pendingTask) {
|
|
56286
|
+
if (pendingTask && pendingTask !== exceptTask) {
|
|
56101
56287
|
Log$1.debug(`Waiting for pending callback task to complete for connectId: ${connectId}`);
|
|
56102
56288
|
yield pendingTask.promise;
|
|
56103
56289
|
}
|
|
@@ -56134,6 +56320,9 @@ const getSynchronize = (mutex) => {
|
|
|
56134
56320
|
};
|
|
56135
56321
|
|
|
56136
56322
|
const Log = getLogger(exports.LoggerNames.Core);
|
|
56323
|
+
const PRE_INITIALIZE_TTL_MS = 60 * 1000;
|
|
56324
|
+
const preWarmInflight = new Map();
|
|
56325
|
+
const preWarmDoneAt = new Map();
|
|
56137
56326
|
function hasDeriveCardano(method) {
|
|
56138
56327
|
var _a;
|
|
56139
56328
|
if (method.name.startsWith('allNetworkGetAddress') &&
|
|
@@ -56156,8 +56345,7 @@ let _deviceList;
|
|
|
56156
56345
|
let _connector;
|
|
56157
56346
|
let _uiPromises = [];
|
|
56158
56347
|
const deviceCacheMap = new Map();
|
|
56159
|
-
|
|
56160
|
-
const pollingState = {};
|
|
56348
|
+
const pollingManager = new PollingStateManager();
|
|
56161
56349
|
let preConnectCache = {
|
|
56162
56350
|
passphraseState: undefined,
|
|
56163
56351
|
};
|
|
@@ -56234,8 +56422,44 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
|
|
|
56234
56422
|
if (error) {
|
|
56235
56423
|
return createResponseMessage(method.responseID, false, { error });
|
|
56236
56424
|
}
|
|
56425
|
+
if (method.isPreWarmSignal) {
|
|
56426
|
+
return handlePreWarmSignal(context, message, method);
|
|
56427
|
+
}
|
|
56237
56428
|
return onCallDevice(context, message, method);
|
|
56238
56429
|
});
|
|
56430
|
+
const handlePreWarmSignal = (context, message, method) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56431
|
+
if (!method.connectId) {
|
|
56432
|
+
return createResponseMessage(method.responseID, true, true);
|
|
56433
|
+
}
|
|
56434
|
+
const key = method.getPreWarmKey();
|
|
56435
|
+
const inflight = preWarmInflight.get(key);
|
|
56436
|
+
if (inflight) {
|
|
56437
|
+
try {
|
|
56438
|
+
yield inflight;
|
|
56439
|
+
}
|
|
56440
|
+
catch (_b) {
|
|
56441
|
+
}
|
|
56442
|
+
return createResponseMessage(method.responseID, true, true);
|
|
56443
|
+
}
|
|
56444
|
+
const doneAt = preWarmDoneAt.get(key);
|
|
56445
|
+
if (typeof doneAt === 'number' && Date.now() - doneAt <= method.preWarmTtl) {
|
|
56446
|
+
return createResponseMessage(method.responseID, true, true);
|
|
56447
|
+
}
|
|
56448
|
+
const run = onCallDevice(context, message, method);
|
|
56449
|
+
preWarmInflight.set(key, run);
|
|
56450
|
+
try {
|
|
56451
|
+
const result = yield run;
|
|
56452
|
+
if ((result === null || result === void 0 ? void 0 : result.success) === true && (result === null || result === void 0 ? void 0 : result.payload) === true) {
|
|
56453
|
+
preWarmDoneAt.set(key, Date.now());
|
|
56454
|
+
}
|
|
56455
|
+
return result;
|
|
56456
|
+
}
|
|
56457
|
+
finally {
|
|
56458
|
+
if (preWarmInflight.get(key) === run) {
|
|
56459
|
+
preWarmInflight.delete(key);
|
|
56460
|
+
}
|
|
56461
|
+
}
|
|
56462
|
+
});
|
|
56239
56463
|
const waitWithTimeout = (promise, timeout) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56240
56464
|
const timeoutPromise = new Promise((_, reject) => {
|
|
56241
56465
|
setTimeout(() => reject(new Error('Request timeout')), timeout);
|
|
@@ -56256,11 +56480,13 @@ const waitForPendingPromise = (getPrePendingCallPromise, removePrePendingCallPro
|
|
|
56256
56480
|
}
|
|
56257
56481
|
});
|
|
56258
56482
|
const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56259
|
-
var
|
|
56483
|
+
var _c, _d, _e, _f, _g;
|
|
56260
56484
|
let messageResponse;
|
|
56261
56485
|
const { requestQueue, getPrePendingCallPromise, setPrePendingCallPromise } = context;
|
|
56262
56486
|
updateMethodRequestContext(method, { status: 'running' });
|
|
56263
|
-
const
|
|
56487
|
+
const normalizePassphraseState = (s) => s || '';
|
|
56488
|
+
const connectStateChange = normalizePassphraseState(preConnectCache.passphraseState) !==
|
|
56489
|
+
normalizePassphraseState(method.payload.passphraseState);
|
|
56264
56490
|
preConnectCache = {
|
|
56265
56491
|
passphraseState: method.payload.passphraseState,
|
|
56266
56492
|
};
|
|
@@ -56273,15 +56499,19 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
56273
56499
|
}
|
|
56274
56500
|
yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
56275
56501
|
const task = requestQueue.createTask(method);
|
|
56502
|
+
let preWarmCallbackTask;
|
|
56503
|
+
if (method.isPreWarmSignal && method.connectId) {
|
|
56504
|
+
preWarmCallbackTask = hdShared.createDeferred();
|
|
56505
|
+
context.registerCallbackTask(method.connectId, preWarmCallbackTask);
|
|
56506
|
+
}
|
|
56276
56507
|
let device;
|
|
56277
56508
|
try {
|
|
56278
|
-
|
|
56279
|
-
|
|
56280
|
-
|
|
56281
|
-
pollingId += 1;
|
|
56282
|
-
device = yield ensureConnected(context, method, pollingId, (_b = task.abortController) === null || _b === void 0 ? void 0 : _b.signal);
|
|
56509
|
+
const connectId = (_c = method.connectId) !== null && _c !== void 0 ? _c : '';
|
|
56510
|
+
const pollingId = pollingManager.start(connectId);
|
|
56511
|
+
device = yield ensureConnected(context, method, connectId, pollingId, (_d = task.abortController) === null || _d === void 0 ? void 0 : _d.signal);
|
|
56283
56512
|
}
|
|
56284
56513
|
catch (e) {
|
|
56514
|
+
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
56285
56515
|
console.log('ensureConnected error: ', e);
|
|
56286
56516
|
completeMethodRequestContext(method, e);
|
|
56287
56517
|
if (e.name === 'AbortError' || e.message === 'Request aborted') {
|
|
@@ -56293,16 +56523,17 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
56293
56523
|
requestQueue.releaseTask(method.responseID);
|
|
56294
56524
|
return createResponseMessage(method.responseID, false, { error: e });
|
|
56295
56525
|
}
|
|
56296
|
-
if ((
|
|
56526
|
+
if ((_e = method.payload) === null || _e === void 0 ? void 0 : _e.onlyConnectBleDevice) {
|
|
56527
|
+
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
56297
56528
|
Log.debug('Call API - only connect ble device: ', device === null || device === void 0 ? void 0 : device.mainId);
|
|
56298
56529
|
return createResponseMessage(method.responseID, true, null);
|
|
56299
56530
|
}
|
|
56300
56531
|
Log.debug('Call API - setDevice: ', device.mainId);
|
|
56301
|
-
(
|
|
56532
|
+
(_f = method.setDevice) === null || _f === void 0 ? void 0 : _f.call(method, device);
|
|
56302
56533
|
method.context = context;
|
|
56303
56534
|
updateMethodRequestContext(method, {
|
|
56304
56535
|
deviceInstanceId: device.instanceId,
|
|
56305
|
-
commandsInstanceId: (
|
|
56536
|
+
commandsInstanceId: (_g = device.commands) === null || _g === void 0 ? void 0 : _g.instanceId,
|
|
56306
56537
|
});
|
|
56307
56538
|
const activeRequests = getActiveRequestsByDeviceInstance(device.instanceId);
|
|
56308
56539
|
if (activeRequests.length > 0) {
|
|
@@ -56317,11 +56548,11 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
56317
56548
|
device.on(DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE, onSelectDeviceForSwitchFirmwareWebDeviceHandler);
|
|
56318
56549
|
try {
|
|
56319
56550
|
if (method.connectId) {
|
|
56320
|
-
yield context.waitForCallbackTasks(method.connectId);
|
|
56551
|
+
yield context.waitForCallbackTasks(method.connectId, preWarmCallbackTask);
|
|
56321
56552
|
}
|
|
56322
56553
|
yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
56323
56554
|
const inner = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56324
|
-
var
|
|
56555
|
+
var _h, _j, _k, _l, _m;
|
|
56325
56556
|
const versionRange = getMethodVersionRange(device.features, type => method.getVersionRange()[type]);
|
|
56326
56557
|
if (device.features) {
|
|
56327
56558
|
yield DataManager.checkAndReloadData();
|
|
@@ -56411,7 +56642,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
56411
56642
|
require: support.require,
|
|
56412
56643
|
}));
|
|
56413
56644
|
}
|
|
56414
|
-
const passphraseStateSafety = yield device.checkPassphraseStateSafety((
|
|
56645
|
+
const passphraseStateSafety = yield device.checkPassphraseStateSafety((_h = method.payload) === null || _h === void 0 ? void 0 : _h.passphraseState, (_j = method.payload) === null || _j === void 0 ? void 0 : _j.useEmptyPassphrase, (_k = method.payload) === null || _k === void 0 ? void 0 : _k.skipPassphraseCheck);
|
|
56415
56646
|
checkPassphraseEnableState(method, device.features);
|
|
56416
56647
|
if (!passphraseStateSafety) {
|
|
56417
56648
|
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
@@ -56428,10 +56659,9 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
56428
56659
|
: hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
|
|
56429
56660
|
throw error;
|
|
56430
56661
|
}
|
|
56431
|
-
(
|
|
56662
|
+
(_m = (_l = method.device) === null || _l === void 0 ? void 0 : _l.commands) === null || _m === void 0 ? void 0 : _m.checkDisposed();
|
|
56432
56663
|
try {
|
|
56433
56664
|
const response = yield method.run();
|
|
56434
|
-
Log.debug('Call API - Inner Method Run: ');
|
|
56435
56665
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
56436
56666
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
56437
56667
|
completeMethodRequestContext(method);
|
|
@@ -56448,7 +56678,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
56448
56678
|
}
|
|
56449
56679
|
});
|
|
56450
56680
|
Log.debug('Call API - Device Run: ', device.mainId);
|
|
56451
|
-
const runOptions = Object.assign({ keepSession: method.payload.keepSession }, parseInitOptions(method));
|
|
56681
|
+
const runOptions = Object.assign({ keepSession: method.payload.keepSession, skipInitialize: canSkipInitialize(method, device) }, parseInitOptions(method));
|
|
56452
56682
|
const deviceRun = () => device.run(inner, runOptions);
|
|
56453
56683
|
task.callPromise = hdShared.createDeferred(deviceRun);
|
|
56454
56684
|
try {
|
|
@@ -56467,6 +56697,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
56467
56697
|
completeMethodRequestContext(method, error);
|
|
56468
56698
|
}
|
|
56469
56699
|
finally {
|
|
56700
|
+
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
56470
56701
|
const response = messageResponse;
|
|
56471
56702
|
if (response) {
|
|
56472
56703
|
if (method) {
|
|
@@ -56562,7 +56793,30 @@ function initDeviceForBle(method) {
|
|
|
56562
56793
|
device.deviceConnector = _connector;
|
|
56563
56794
|
return device;
|
|
56564
56795
|
}
|
|
56565
|
-
|
|
56796
|
+
function canSkipInitialize(method, device) {
|
|
56797
|
+
var _a;
|
|
56798
|
+
const reasons = [];
|
|
56799
|
+
if (!method.allowUsePreInitialize)
|
|
56800
|
+
reasons.push('method.disallow');
|
|
56801
|
+
if (!((_a = method.payload) === null || _a === void 0 ? void 0 : _a.usePreInitialize))
|
|
56802
|
+
reasons.push('payload.usePreInitialize=false');
|
|
56803
|
+
if (!method.connectId)
|
|
56804
|
+
reasons.push('connectId.missing');
|
|
56805
|
+
if (!device.isPreInitializeMetaMatch(method.payload))
|
|
56806
|
+
reasons.push('meta.mismatch');
|
|
56807
|
+
if (!device.features)
|
|
56808
|
+
reasons.push('features.missing');
|
|
56809
|
+
if (!device.isPreInitializedValid(PRE_INITIALIZE_TTL_MS))
|
|
56810
|
+
reasons.push('ttl.expired');
|
|
56811
|
+
if (reasons.length) {
|
|
56812
|
+
Log.debug(`[PRE-INIT][MISS] method=${method.name} ${reasons.join(',')}`);
|
|
56813
|
+
return false;
|
|
56814
|
+
}
|
|
56815
|
+
const savedMs = device.getLastInitializeDuration();
|
|
56816
|
+
const saved = typeof savedMs === 'number' ? `saved ${savedMs}ms` : 'within TTL + meta match';
|
|
56817
|
+
Log.debug(`[PRE-INIT][HIT] method=${method.name} skip Initialize (${saved})`);
|
|
56818
|
+
return true;
|
|
56819
|
+
}
|
|
56566
56820
|
function isRetryableBleProtocolV2ProbeError(method, error) {
|
|
56567
56821
|
const message = error instanceof Error ? error.message : String(error !== null && error !== void 0 ? error : '');
|
|
56568
56822
|
return (method.payload.connectProtocol === 'V2' &&
|
|
@@ -56570,7 +56824,7 @@ function isRetryableBleProtocolV2ProbeError(method, error) {
|
|
|
56570
56824
|
message.includes('expected V2') &&
|
|
56571
56825
|
message.includes('did not respond to expected protocol'));
|
|
56572
56826
|
}
|
|
56573
|
-
function connectDeviceForBle(method, device) {
|
|
56827
|
+
function connectDeviceForBle(method, device, retryCount = 0) {
|
|
56574
56828
|
var _a;
|
|
56575
56829
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56576
56830
|
try {
|
|
@@ -56578,17 +56832,23 @@ function connectDeviceForBle(method, device) {
|
|
|
56578
56832
|
if ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.onlyConnectBleDevice) {
|
|
56579
56833
|
return;
|
|
56580
56834
|
}
|
|
56581
|
-
|
|
56835
|
+
if (!canSkipInitialize(method, device)) {
|
|
56836
|
+
const initOptions = parseInitOptions(method);
|
|
56837
|
+
yield device.initialize(initOptions);
|
|
56838
|
+
device.markPreInitialized({
|
|
56839
|
+
passphraseState: initOptions.passphraseState,
|
|
56840
|
+
});
|
|
56841
|
+
}
|
|
56582
56842
|
}
|
|
56583
56843
|
catch (err) {
|
|
56584
56844
|
if ((err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError ||
|
|
56585
56845
|
err.errorCode === hdShared.HardwareErrorCode.BleConnectedError ||
|
|
56586
56846
|
isRetryableBleProtocolV2ProbeError(method, err)) &&
|
|
56587
|
-
|
|
56588
|
-
|
|
56589
|
-
Log.debug(`
|
|
56847
|
+
retryCount < 6) {
|
|
56848
|
+
const nextRetry = retryCount + 1;
|
|
56849
|
+
Log.debug(`Bluetooth connect timeout and will retry, retry count: ${nextRetry}`);
|
|
56590
56850
|
yield wait(3000);
|
|
56591
|
-
yield connectDeviceForBle(method, device);
|
|
56851
|
+
yield connectDeviceForBle(method, device, nextRetry);
|
|
56592
56852
|
}
|
|
56593
56853
|
else {
|
|
56594
56854
|
throw err;
|
|
@@ -56596,7 +56856,7 @@ function connectDeviceForBle(method, device) {
|
|
|
56596
56856
|
}
|
|
56597
56857
|
});
|
|
56598
56858
|
}
|
|
56599
|
-
const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56859
|
+
const ensureConnected = (_context, method, connectId, pollingId, abortSignal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56600
56860
|
let tryCount = 0;
|
|
56601
56861
|
const MAX_RETRY_COUNT = method.payload && typeof method.payload.retryCount === 'number' ? method.payload.retryCount : 5;
|
|
56602
56862
|
const POLL_INTERVAL_TIME = (method.payload && method.payload.pollIntervalTime) || 1000;
|
|
@@ -56605,7 +56865,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
|
|
|
56605
56865
|
Log.debug(`EnsureConnected function start, MAX_RETRY_COUNT=${MAX_RETRY_COUNT}, POLL_INTERVAL_TIME=${POLL_INTERVAL_TIME} `);
|
|
56606
56866
|
const poll = (time = POLL_INTERVAL_TIME) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56607
56867
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56608
|
-
var
|
|
56868
|
+
var _o;
|
|
56609
56869
|
const abort = () => {
|
|
56610
56870
|
if (abortSignal && abortSignal.aborted) {
|
|
56611
56871
|
if (timer) {
|
|
@@ -56619,7 +56879,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
|
|
|
56619
56879
|
if (abort()) {
|
|
56620
56880
|
return;
|
|
56621
56881
|
}
|
|
56622
|
-
if (!
|
|
56882
|
+
if (!pollingManager.isActive(connectId, pollingId)) {
|
|
56623
56883
|
Log.debug('EnsureConnected function stop, polling id: ', pollingId);
|
|
56624
56884
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PollingStop));
|
|
56625
56885
|
return;
|
|
@@ -56667,7 +56927,6 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
|
|
|
56667
56927
|
clearTimeout(timer);
|
|
56668
56928
|
}
|
|
56669
56929
|
if (DataManager.isBleConnect(env)) {
|
|
56670
|
-
bleTimeoutRetry = 0;
|
|
56671
56930
|
if (abort()) {
|
|
56672
56931
|
return;
|
|
56673
56932
|
}
|
|
@@ -56710,7 +56969,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
|
|
|
56710
56969
|
clearTimeout(timer);
|
|
56711
56970
|
}
|
|
56712
56971
|
Log.debug('EnsureConnected get to max try count, will return: ', tryCount);
|
|
56713
|
-
if (DataManager.isBrowserWebUsb(env) && !((
|
|
56972
|
+
if (DataManager.isBrowserWebUsb(env) && !((_o = method.payload) === null || _o === void 0 ? void 0 : _o.skipWebDevicePrompt)) {
|
|
56714
56973
|
postMessage(createUiMessage(UI_REQUEST.WEB_DEVICE_PROMPT_ACCESS_PERMISSION));
|
|
56715
56974
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission));
|
|
56716
56975
|
}
|
|
@@ -56725,7 +56984,6 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
|
|
|
56725
56984
|
return setTimeout(() => resolve(poll(time * 1.5)), time);
|
|
56726
56985
|
}));
|
|
56727
56986
|
});
|
|
56728
|
-
pollingState[pollingId] = true;
|
|
56729
56987
|
return poll();
|
|
56730
56988
|
});
|
|
56731
56989
|
const cancel = (context, connectId) => {
|
|
@@ -56805,12 +57063,9 @@ const checkPassphraseEnableState = (method, features) => {
|
|
|
56805
57063
|
}
|
|
56806
57064
|
};
|
|
56807
57065
|
const shouldCheckPassphraseState = (method, device) => {
|
|
56808
|
-
var _a, _b;
|
|
56809
57066
|
if (!method.useDevicePassphraseState)
|
|
56810
57067
|
return false;
|
|
56811
|
-
|
|
56812
|
-
const pro2ExplicitWalletSelection = isPro2 && (!!((_a = method.payload) === null || _a === void 0 ? void 0 : _a.passphraseState) || !!((_b = method.payload) === null || _b === void 0 ? void 0 : _b.useEmptyPassphrase));
|
|
56813
|
-
return device.hasUsePassphrase() || pro2ExplicitWalletSelection;
|
|
57068
|
+
return device.hasUsePassphrase();
|
|
56814
57069
|
};
|
|
56815
57070
|
const cleanup = () => {
|
|
56816
57071
|
_uiPromises = [];
|
|
@@ -56829,6 +57084,7 @@ const onDeviceConnectHandler = (device) => {
|
|
|
56829
57084
|
postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject }));
|
|
56830
57085
|
};
|
|
56831
57086
|
const onDeviceDisconnectHandler = (device) => {
|
|
57087
|
+
device.clearPreInitialized();
|
|
56832
57088
|
const env = DataManager.getSettings('env');
|
|
56833
57089
|
const deviceObject = DataManager.isBleConnect(env) ? device : device.toMessageObject();
|
|
56834
57090
|
postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject }));
|
|
@@ -56942,7 +57198,7 @@ class Core extends events.exports {
|
|
|
56942
57198
|
registerCallbackTask: (connectId, callbackPromise) => {
|
|
56943
57199
|
this.requestQueue.registerPendingCallbackTask(connectId, callbackPromise);
|
|
56944
57200
|
},
|
|
56945
|
-
waitForCallbackTasks: (connectId) => this.requestQueue.waitForPendingCallbackTasks(connectId),
|
|
57201
|
+
waitForCallbackTasks: (connectId, exceptTask) => this.requestQueue.waitForPendingCallbackTasks(connectId, exceptTask),
|
|
56946
57202
|
cancelCallbackTasks: (connectId) => this.requestQueue.cancelCallbackTasks(connectId),
|
|
56947
57203
|
};
|
|
56948
57204
|
}
|
|
@@ -56972,10 +57228,10 @@ class Core extends events.exports {
|
|
|
56972
57228
|
break;
|
|
56973
57229
|
}
|
|
56974
57230
|
case IFRAME.CALL: {
|
|
56975
|
-
Log.log(
|
|
57231
|
+
Log.log(`[${Date.now()}][CALL_API]`, message);
|
|
56976
57232
|
const response = yield callAPI(this.getCoreContext(), message);
|
|
56977
57233
|
const { success, payload } = response;
|
|
56978
|
-
Log.log(
|
|
57234
|
+
Log.log(`[${Date.now()}][CALL_API_RESPONSE]`, response);
|
|
56979
57235
|
if (success) {
|
|
56980
57236
|
return response;
|
|
56981
57237
|
}
|
|
@@ -56998,6 +57254,9 @@ class Core extends events.exports {
|
|
|
56998
57254
|
dispose() {
|
|
56999
57255
|
_deviceList = undefined;
|
|
57000
57256
|
_connector = undefined;
|
|
57257
|
+
deviceCacheMap.clear();
|
|
57258
|
+
preWarmInflight.clear();
|
|
57259
|
+
preWarmDoneAt.clear();
|
|
57001
57260
|
Log.debug(`[Core] Disposing SDK instance: ${this.sdkInstanceId}`);
|
|
57002
57261
|
cleanupSdkInstance(this.sdkInstanceId);
|
|
57003
57262
|
}
|
|
@@ -57020,7 +57279,7 @@ const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0,
|
|
|
57020
57279
|
yield DataManager.load(settings);
|
|
57021
57280
|
initTransport(Transport, plugin);
|
|
57022
57281
|
}
|
|
57023
|
-
catch (
|
|
57282
|
+
catch (_p) {
|
|
57024
57283
|
Log.error('DataManager.load error');
|
|
57025
57284
|
}
|
|
57026
57285
|
enableLog(DataManager.getSettings('debug'));
|