@onekeyfe/hd-core 1.1.26 → 1.1.27-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/preInitialize.test.ts +22 -0
- package/dist/api/BaseMethod.d.ts +4 -0
- package/dist/api/BaseMethod.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/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/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/scdo/ScdoSignMessage.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
- package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
- package/dist/api/starcoin/StarcoinSignMessage.d.ts.map +1 -1
- package/dist/api/starcoin/StarcoinSignTransaction.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
- package/dist/api/sui/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 +15 -0
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.js +340 -113
- 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/package.json +4 -4
- package/src/api/BaseMethod.ts +22 -0
- 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/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/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 -0
- package/src/api/solana/SolSignOffchainMessage.ts +1 -0
- package/src/api/solana/SolSignTransaction.ts +1 -0
- package/src/api/starcoin/StarcoinSignMessage.ts +1 -0
- package/src/api/starcoin/StarcoinSignTransaction.ts +1 -0
- package/src/api/stellar/StellarSignTransaction.ts +1 -0
- package/src/api/sui/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 +144 -27
- package/src/device/Device.ts +66 -9
- package/src/inject.ts +1 -1
- package/src/types/api/index.ts +2 -0
- package/src/types/api/preInitialize.ts +3 -0
- package/src/types/params.ts +5 -0
package/dist/index.js
CHANGED
|
@@ -131,6 +131,7 @@ const createCoreApi = (call) => ({
|
|
|
131
131
|
checkFirmwareTypeAvailable: params => call(Object.assign(Object.assign({}, params), { method: 'checkFirmwareTypeAvailable' })),
|
|
132
132
|
cipherKeyValue: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'cipherKeyValue' })),
|
|
133
133
|
testInitializeDeviceDuration: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'testInitializeDeviceDuration' })),
|
|
134
|
+
preInitialize: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'preInitialize' })),
|
|
134
135
|
deviceBackup: connectId => call({ connectId, method: 'deviceBackup' }),
|
|
135
136
|
deviceChangePin: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceChangePin' })),
|
|
136
137
|
deviceFlags: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFlags' })),
|
|
@@ -788,7 +789,7 @@ const createLogMessage = (type, payload) => ({
|
|
|
788
789
|
|
|
789
790
|
const MAX_ENTRIES = 500;
|
|
790
791
|
let postMessage$1;
|
|
791
|
-
class Log$
|
|
792
|
+
class Log$h {
|
|
792
793
|
constructor(prefix, enabled) {
|
|
793
794
|
this.prefix = prefix;
|
|
794
795
|
this.enabled = enabled;
|
|
@@ -840,7 +841,7 @@ class Log$g {
|
|
|
840
841
|
}
|
|
841
842
|
const _logs = {};
|
|
842
843
|
const initLog = (prefix, enabled) => {
|
|
843
|
-
const instance = new Log$
|
|
844
|
+
const instance = new Log$h(prefix, !!enabled);
|
|
844
845
|
_logs[prefix] = instance;
|
|
845
846
|
return instance;
|
|
846
847
|
};
|
|
@@ -1038,7 +1039,7 @@ function patchFeatures(response) {
|
|
|
1038
1039
|
return response;
|
|
1039
1040
|
}
|
|
1040
1041
|
|
|
1041
|
-
const Log$
|
|
1042
|
+
const Log$g = getLogger(exports.LoggerNames.Core);
|
|
1042
1043
|
let globalInstanceCounter = 0;
|
|
1043
1044
|
let sdkInstanceCounter = 0;
|
|
1044
1045
|
function generateSdkInstanceId() {
|
|
@@ -1098,7 +1099,7 @@ function completeRequestContext(responseID, error) {
|
|
|
1098
1099
|
context.status = error ? 'error' : 'success';
|
|
1099
1100
|
if (error) {
|
|
1100
1101
|
context.error = error.message;
|
|
1101
|
-
Log$
|
|
1102
|
+
Log$g.error(`[RequestContext] [completeRequestContext] Error: ${formatRequestContext(context)}`);
|
|
1102
1103
|
}
|
|
1103
1104
|
globalActiveRequests.delete(responseID);
|
|
1104
1105
|
if (context.sdkInstanceId) {
|
|
@@ -25308,7 +25309,7 @@ const findLatestRelease = (releases) => {
|
|
|
25308
25309
|
};
|
|
25309
25310
|
|
|
25310
25311
|
var _a$1;
|
|
25311
|
-
const Log$
|
|
25312
|
+
const Log$f = getLogger(exports.LoggerNames.Core);
|
|
25312
25313
|
const FIRMWARE_FIELDS = [
|
|
25313
25314
|
'firmware',
|
|
25314
25315
|
'firmware-v2',
|
|
@@ -25370,37 +25371,37 @@ class DataManager {
|
|
|
25370
25371
|
let data = null;
|
|
25371
25372
|
let fetchMethod = 'none';
|
|
25372
25373
|
if (settings.configFetcher) {
|
|
25373
|
-
Log$
|
|
25374
|
+
Log$f.debug('[DataConfig] Trying configFetcher (client-side fetcher)...');
|
|
25374
25375
|
try {
|
|
25375
25376
|
data = yield settings.configFetcher(urlWithCache);
|
|
25376
25377
|
if (data) {
|
|
25377
25378
|
fetchMethod = 'configFetcher';
|
|
25378
|
-
Log$
|
|
25379
|
+
Log$f.log('[DataConfig] ConfigFetcher success');
|
|
25379
25380
|
}
|
|
25380
25381
|
else {
|
|
25381
|
-
Log$
|
|
25382
|
+
Log$f.debug('[DataConfig] ConfigFetcher returned null, will fallback to axios');
|
|
25382
25383
|
}
|
|
25383
25384
|
}
|
|
25384
25385
|
catch (e) {
|
|
25385
|
-
Log$
|
|
25386
|
+
Log$f.warn('[DataConfig] ConfigFetcher error, will fallback to axios:', e);
|
|
25386
25387
|
}
|
|
25387
25388
|
}
|
|
25388
25389
|
if (!data) {
|
|
25389
|
-
Log$
|
|
25390
|
+
Log$f.debug('[DataConfig] Trying axios (SDK default fetcher)...');
|
|
25390
25391
|
try {
|
|
25391
25392
|
const response = yield axios__default["default"].get(urlWithCache, {
|
|
25392
25393
|
timeout: 7000,
|
|
25393
25394
|
});
|
|
25394
25395
|
data = response.data;
|
|
25395
25396
|
fetchMethod = 'axios';
|
|
25396
|
-
Log$
|
|
25397
|
+
Log$f.log('[DataConfig] Axios fetch success');
|
|
25397
25398
|
}
|
|
25398
25399
|
catch (e) {
|
|
25399
|
-
Log$
|
|
25400
|
+
Log$f.warn('[DataConfig] Axios fetch error:', e);
|
|
25400
25401
|
}
|
|
25401
25402
|
}
|
|
25402
25403
|
if (data) {
|
|
25403
|
-
Log$
|
|
25404
|
+
Log$f.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
|
|
25404
25405
|
this.deviceMap = {
|
|
25405
25406
|
[hdShared.EDeviceType.Classic]: this.enrichFirmwareReleaseInfo(data.classic),
|
|
25406
25407
|
[hdShared.EDeviceType.Classic1s]: this.enrichFirmwareReleaseInfo(data.classic1s),
|
|
@@ -25414,7 +25415,7 @@ class DataManager {
|
|
|
25414
25415
|
};
|
|
25415
25416
|
}
|
|
25416
25417
|
else {
|
|
25417
|
-
Log$
|
|
25418
|
+
Log$f.warn('[DataConfig] All fetch methods failed, using built-in default config');
|
|
25418
25419
|
}
|
|
25419
25420
|
});
|
|
25420
25421
|
}
|
|
@@ -26682,7 +26683,7 @@ const LogBlockEvent = new Set([
|
|
|
26682
26683
|
UI_RESPONSE.RECEIVE_PASSPHRASE,
|
|
26683
26684
|
]);
|
|
26684
26685
|
|
|
26685
|
-
const Log$
|
|
26686
|
+
const Log$e = getLogger(exports.LoggerNames.DevicePool);
|
|
26686
26687
|
const getDiff = (current, descriptors) => {
|
|
26687
26688
|
const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
|
|
26688
26689
|
const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
|
|
@@ -26740,7 +26741,7 @@ class DevicePool extends events.exports {
|
|
|
26740
26741
|
yield this._checkDevicePool(initOptions);
|
|
26741
26742
|
return { devices, deviceList };
|
|
26742
26743
|
}
|
|
26743
|
-
Log$
|
|
26744
|
+
Log$e.debug('found device in cache, but path is different: ', connectId);
|
|
26744
26745
|
}
|
|
26745
26746
|
}
|
|
26746
26747
|
try {
|
|
@@ -26801,7 +26802,7 @@ class DevicePool extends events.exports {
|
|
|
26801
26802
|
for (let i = this.connectedPool.length - 1; i >= 0; i--) {
|
|
26802
26803
|
const descriptor = this.connectedPool[i];
|
|
26803
26804
|
const device = yield this._createDevice(descriptor, initOptions);
|
|
26804
|
-
Log$
|
|
26805
|
+
Log$e.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
|
|
26805
26806
|
this.emitter.emit(DEVICE.CONNECT, device);
|
|
26806
26807
|
this.connectedPool.splice(i, 1);
|
|
26807
26808
|
}
|
|
@@ -26821,9 +26822,9 @@ class DevicePool extends events.exports {
|
|
|
26821
26822
|
const diff = getDiff(this.current || [], upcoming);
|
|
26822
26823
|
this.upcoming = upcoming;
|
|
26823
26824
|
this.current = this.upcoming;
|
|
26824
|
-
Log$
|
|
26825
|
-
Log$
|
|
26826
|
-
Log$
|
|
26825
|
+
Log$e.debug('device pool -> current: ', this.current);
|
|
26826
|
+
Log$e.debug('device pool -> upcomming: ', this.upcoming);
|
|
26827
|
+
Log$e.debug('DeviceCache.reportDeviceChange diff: ', diff);
|
|
26827
26828
|
if (!diff.didUpdate) {
|
|
26828
26829
|
return;
|
|
26829
26830
|
}
|
|
@@ -26833,7 +26834,7 @@ class DevicePool extends events.exports {
|
|
|
26833
26834
|
this._addConnectedDeviceToPool(d);
|
|
26834
26835
|
return;
|
|
26835
26836
|
}
|
|
26836
|
-
Log$
|
|
26837
|
+
Log$e.debug('emit DEVICE.CONNECT: ', device.features);
|
|
26837
26838
|
this.emitter.emit(DEVICE.CONNECT, device);
|
|
26838
26839
|
});
|
|
26839
26840
|
diff.disconnected.forEach(d => {
|
|
@@ -26843,7 +26844,7 @@ class DevicePool extends events.exports {
|
|
|
26843
26844
|
this._addDisconnectedDeviceToPool(d);
|
|
26844
26845
|
return;
|
|
26845
26846
|
}
|
|
26846
|
-
Log$
|
|
26847
|
+
Log$e.debug('emit DEVICE.DISCONNECT: ', device.features);
|
|
26847
26848
|
this.emitter.emit(DEVICE.DISCONNECT, device);
|
|
26848
26849
|
});
|
|
26849
26850
|
}
|
|
@@ -26879,7 +26880,7 @@ class DevicePool extends events.exports {
|
|
|
26879
26880
|
this.disconnectPool = [];
|
|
26880
26881
|
this.devicesCache = {};
|
|
26881
26882
|
this.emitter.removeAllListeners();
|
|
26882
|
-
Log$
|
|
26883
|
+
Log$e.debug('DevicePool state has been reset');
|
|
26883
26884
|
}
|
|
26884
26885
|
}
|
|
26885
26886
|
DevicePool.current = null;
|
|
@@ -26889,7 +26890,7 @@ DevicePool.disconnectPool = [];
|
|
|
26889
26890
|
DevicePool.devicesCache = {};
|
|
26890
26891
|
DevicePool.emitter = new events.exports();
|
|
26891
26892
|
|
|
26892
|
-
const Log$
|
|
26893
|
+
const Log$d = getLogger(exports.LoggerNames.Transport);
|
|
26893
26894
|
const BleLogger = getLogger(exports.LoggerNames.HdBleTransport);
|
|
26894
26895
|
const HttpLogger = getLogger(exports.LoggerNames.HdTransportHttp);
|
|
26895
26896
|
const LowLevelLogger = getLogger(exports.LoggerNames.HdTransportLowLevel);
|
|
@@ -26898,7 +26899,7 @@ const WebBleLogger = getLogger(exports.LoggerNames.HdWebBleTransport);
|
|
|
26898
26899
|
const WebUsbLogger = getLogger(exports.LoggerNames.HdTransportWebUsb);
|
|
26899
26900
|
class TransportManager {
|
|
26900
26901
|
static load() {
|
|
26901
|
-
Log$
|
|
26902
|
+
Log$d.debug('transport manager load');
|
|
26902
26903
|
this.defaultMessages = DataManager.getProtobufMessages();
|
|
26903
26904
|
this.currentMessages = this.defaultMessages;
|
|
26904
26905
|
this.messageVersion = 'latest';
|
|
@@ -26907,14 +26908,14 @@ class TransportManager {
|
|
|
26907
26908
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26908
26909
|
try {
|
|
26909
26910
|
const env = DataManager.getSettings('env');
|
|
26910
|
-
Log$
|
|
26911
|
+
Log$d.debug('Initializing transports', env);
|
|
26911
26912
|
if (env === 'react-native') {
|
|
26912
26913
|
if (!this.reactNativeInit) {
|
|
26913
26914
|
yield this.transport.init(BleLogger, DevicePool.emitter);
|
|
26914
26915
|
this.reactNativeInit = true;
|
|
26915
26916
|
}
|
|
26916
26917
|
else {
|
|
26917
|
-
Log$
|
|
26918
|
+
Log$d.debug('React Native Do Not Initializing transports');
|
|
26918
26919
|
}
|
|
26919
26920
|
}
|
|
26920
26921
|
else if (env === 'node-usb') {
|
|
@@ -26935,12 +26936,12 @@ class TransportManager {
|
|
|
26935
26936
|
else {
|
|
26936
26937
|
yield this.transport.init(HttpLogger);
|
|
26937
26938
|
}
|
|
26938
|
-
Log$
|
|
26939
|
+
Log$d.debug('Configuring transports');
|
|
26939
26940
|
yield this.transport.configure(JSON.stringify(this.defaultMessages));
|
|
26940
|
-
Log$
|
|
26941
|
+
Log$d.debug('Configuring transports done');
|
|
26941
26942
|
}
|
|
26942
26943
|
catch (error) {
|
|
26943
|
-
Log$
|
|
26944
|
+
Log$d.debug('Initializing transports error: ', error);
|
|
26944
26945
|
if (error.code === 'ECONNABORTED') {
|
|
26945
26946
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
|
|
26946
26947
|
}
|
|
@@ -26949,12 +26950,12 @@ class TransportManager {
|
|
|
26949
26950
|
}
|
|
26950
26951
|
static reconfigure(features) {
|
|
26951
26952
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26952
|
-
Log$
|
|
26953
|
+
Log$d.debug(`Begin reconfiguring transports`);
|
|
26953
26954
|
const { messageVersion, messages } = getSupportMessageVersion(features);
|
|
26954
26955
|
if (this.currentMessages === messages || !messages) {
|
|
26955
26956
|
return;
|
|
26956
26957
|
}
|
|
26957
|
-
Log$
|
|
26958
|
+
Log$d.debug(`Reconfiguring transports version:${messageVersion}`);
|
|
26958
26959
|
try {
|
|
26959
26960
|
yield this.transport.configure(JSON.stringify(messages));
|
|
26960
26961
|
this.currentMessages = messages;
|
|
@@ -26975,9 +26976,9 @@ class TransportManager {
|
|
|
26975
26976
|
}
|
|
26976
26977
|
if (plugin) {
|
|
26977
26978
|
this.plugin = plugin;
|
|
26978
|
-
Log$
|
|
26979
|
+
Log$d.debug('set transport plugin: ', this.plugin);
|
|
26979
26980
|
}
|
|
26980
|
-
Log$
|
|
26981
|
+
Log$d.debug('set transport: ', this.transport.name, this.transport.version, this.transport.configured);
|
|
26981
26982
|
}
|
|
26982
26983
|
static getTransport() {
|
|
26983
26984
|
return this.transport;
|
|
@@ -27065,7 +27066,7 @@ const cancelDeviceWithInitialize = (device) => {
|
|
|
27065
27066
|
},
|
|
27066
27067
|
}));
|
|
27067
27068
|
};
|
|
27068
|
-
const Log$
|
|
27069
|
+
const Log$c = getLogger(exports.LoggerNames.DeviceCommands);
|
|
27069
27070
|
const LogCore = getLogger(exports.LoggerNames.Core);
|
|
27070
27071
|
class DeviceCommands {
|
|
27071
27072
|
constructor(device, mainId) {
|
|
@@ -27074,7 +27075,7 @@ class DeviceCommands {
|
|
|
27074
27075
|
this.transport = TransportManager.getTransport();
|
|
27075
27076
|
this.disposed = false;
|
|
27076
27077
|
this.instanceId = generateInstanceId('DeviceCommands', device.sdkInstanceId);
|
|
27077
|
-
Log$
|
|
27078
|
+
Log$c.debug(`[DeviceCommands] Created: ${this.instanceId}, device: ${this.device.instanceId}`);
|
|
27078
27079
|
}
|
|
27079
27080
|
dispose(_cancelRequest) {
|
|
27080
27081
|
var _a, _b;
|
|
@@ -27142,7 +27143,7 @@ class DeviceCommands {
|
|
|
27142
27143
|
call(type, msg = {}) {
|
|
27143
27144
|
var _a;
|
|
27144
27145
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27145
|
-
Log$
|
|
27146
|
+
Log$c.debug('[DeviceCommands] [call] Sending', type);
|
|
27146
27147
|
try {
|
|
27147
27148
|
const promise = this.transport.call(this.mainId, type, msg);
|
|
27148
27149
|
this.callPromise = promise;
|
|
@@ -27176,7 +27177,7 @@ class DeviceCommands {
|
|
|
27176
27177
|
}
|
|
27177
27178
|
}
|
|
27178
27179
|
if (responseData) {
|
|
27179
|
-
Log$
|
|
27180
|
+
Log$c.debug('error response', responseData);
|
|
27180
27181
|
}
|
|
27181
27182
|
if (responseError === 'device disconnected during action') {
|
|
27182
27183
|
return { type: 'BridgeDeviceDisconnected', message: { error: responseError } };
|
|
@@ -27207,7 +27208,7 @@ class DeviceCommands {
|
|
|
27207
27208
|
'BixinPinInputOnDevice',
|
|
27208
27209
|
];
|
|
27209
27210
|
if (!skipTypes.includes(type) && msg) {
|
|
27210
|
-
Log$
|
|
27211
|
+
Log$c.debug('[DeviceCommands] [typedCall] Sending payload', type, msg);
|
|
27211
27212
|
}
|
|
27212
27213
|
}
|
|
27213
27214
|
catch (e) {
|
|
@@ -27217,7 +27218,7 @@ class DeviceCommands {
|
|
|
27217
27218
|
assertType(response, resType);
|
|
27218
27219
|
}
|
|
27219
27220
|
catch (error) {
|
|
27220
|
-
Log$
|
|
27221
|
+
Log$c.debug('DeviceCommands typedcall error: ', error);
|
|
27221
27222
|
if (error instanceof hdShared.HardwareError) {
|
|
27222
27223
|
if (error.errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError) {
|
|
27223
27224
|
if (error.message.indexOf('BridgeNetworkError') > -1) {
|
|
@@ -27248,10 +27249,10 @@ class DeviceCommands {
|
|
|
27248
27249
|
_filterCommonTypes(res, callType) {
|
|
27249
27250
|
try {
|
|
27250
27251
|
if (DataManager.getSettings('env') === 'react-native') {
|
|
27251
|
-
Log$
|
|
27252
|
+
Log$c.debug('_filterCommonTypes: ', JSON.stringify(res));
|
|
27252
27253
|
}
|
|
27253
27254
|
else {
|
|
27254
|
-
Log$
|
|
27255
|
+
Log$c.debug('_filterCommonTypes: ', res);
|
|
27255
27256
|
}
|
|
27256
27257
|
}
|
|
27257
27258
|
catch (error) {
|
|
@@ -27380,7 +27381,7 @@ class DeviceCommands {
|
|
|
27380
27381
|
reject(error);
|
|
27381
27382
|
});
|
|
27382
27383
|
const listenerCount = this.device.listenerCount(DEVICE.PIN);
|
|
27383
|
-
Log$
|
|
27384
|
+
Log$c.debug(`[${this.instanceId}] _promptPin called`, {
|
|
27384
27385
|
responseID: this.currentResponseID,
|
|
27385
27386
|
deviceInstanceId: this.device.instanceId,
|
|
27386
27387
|
listenerCount,
|
|
@@ -27452,7 +27453,7 @@ const parseRunOptions = (options) => {
|
|
|
27452
27453
|
options = {};
|
|
27453
27454
|
return options;
|
|
27454
27455
|
};
|
|
27455
|
-
const Log$
|
|
27456
|
+
const Log$b = getLogger(exports.LoggerNames.Device);
|
|
27456
27457
|
const deviceSessionCache = {};
|
|
27457
27458
|
function preloadSessionCache(deviceId, passphraseState, sessionId) {
|
|
27458
27459
|
const key = `${deviceId}@${passphraseState}`;
|
|
@@ -27476,7 +27477,7 @@ class Device extends events.exports {
|
|
|
27476
27477
|
this.sdkInstanceId = sdkInstanceId;
|
|
27477
27478
|
this.instanceId = generateInstanceId('Device', this.sdkInstanceId);
|
|
27478
27479
|
this.createdAt = Date.now();
|
|
27479
|
-
Log$
|
|
27480
|
+
Log$b.debug(`[Device] Created: ${this.instanceId}${this.sdkInstanceId ? ` for SDK: ${this.sdkInstanceId}` : ''}`);
|
|
27480
27481
|
}
|
|
27481
27482
|
static fromDescriptor(originalDescriptor, sdkInstanceId) {
|
|
27482
27483
|
const descriptor = Object.assign({}, originalDescriptor);
|
|
@@ -27549,11 +27550,11 @@ class Device extends events.exports {
|
|
|
27549
27550
|
if (DataManager.isBleConnect(env)) {
|
|
27550
27551
|
const res = yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.originalDescriptor.id));
|
|
27551
27552
|
this.mainId = (_b = res.uuid) !== null && _b !== void 0 ? _b : '';
|
|
27552
|
-
Log$
|
|
27553
|
+
Log$b.debug('Expected uuid:', this.mainId);
|
|
27553
27554
|
}
|
|
27554
27555
|
else {
|
|
27555
27556
|
this.mainId = yield ((_c = this.deviceConnector) === null || _c === void 0 ? void 0 : _c.acquire(this.originalDescriptor.path, this.originalDescriptor.session));
|
|
27556
|
-
Log$
|
|
27557
|
+
Log$b.debug('Expected session id:', this.mainId);
|
|
27557
27558
|
}
|
|
27558
27559
|
this.deviceAcquired = true;
|
|
27559
27560
|
this.updateDescriptor({ [mainIdKey]: this.mainId });
|
|
@@ -27581,11 +27582,11 @@ class Device extends events.exports {
|
|
|
27581
27582
|
(this.mainId && DataManager.isBleConnect(env))) {
|
|
27582
27583
|
if (this.pendingCallbackPromise) {
|
|
27583
27584
|
try {
|
|
27584
|
-
Log$
|
|
27585
|
+
Log$b.debug('Waiting for callback tasks to complete before releasing device (in release method)');
|
|
27585
27586
|
yield this.pendingCallbackPromise.promise;
|
|
27586
27587
|
}
|
|
27587
27588
|
catch (error) {
|
|
27588
|
-
Log$
|
|
27589
|
+
Log$b.error('Error waiting for callback tasks in release method:', error);
|
|
27589
27590
|
}
|
|
27590
27591
|
}
|
|
27591
27592
|
if (this.commands) {
|
|
@@ -27604,7 +27605,7 @@ class Device extends events.exports {
|
|
|
27604
27605
|
this.updateDescriptor({ session: null });
|
|
27605
27606
|
}
|
|
27606
27607
|
catch (err) {
|
|
27607
|
-
Log$
|
|
27608
|
+
Log$b.error('[Device] release error: ', err);
|
|
27608
27609
|
}
|
|
27609
27610
|
finally {
|
|
27610
27611
|
this.needReloadDevice = true;
|
|
@@ -27613,6 +27614,46 @@ class Device extends events.exports {
|
|
|
27613
27614
|
this.deviceAcquired = false;
|
|
27614
27615
|
});
|
|
27615
27616
|
}
|
|
27617
|
+
preInitialize(initOptions) {
|
|
27618
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27619
|
+
if (!this.features) {
|
|
27620
|
+
yield this.acquire();
|
|
27621
|
+
yield this.initialize(initOptions);
|
|
27622
|
+
}
|
|
27623
|
+
this.markPreInitialized({
|
|
27624
|
+
passphraseState: initOptions === null || initOptions === void 0 ? void 0 : initOptions.passphraseState,
|
|
27625
|
+
});
|
|
27626
|
+
});
|
|
27627
|
+
}
|
|
27628
|
+
markPreInitialized(meta) {
|
|
27629
|
+
this.preInitializedAt = Date.now();
|
|
27630
|
+
this.preInitializeMeta = meta
|
|
27631
|
+
? {
|
|
27632
|
+
passphraseState: meta.passphraseState === '' ? undefined : meta.passphraseState,
|
|
27633
|
+
}
|
|
27634
|
+
: undefined;
|
|
27635
|
+
}
|
|
27636
|
+
clearPreInitialized() {
|
|
27637
|
+
this.preInitializedAt = undefined;
|
|
27638
|
+
this.preInitializeMeta = undefined;
|
|
27639
|
+
}
|
|
27640
|
+
isPreInitializeMetaMatch(payload) {
|
|
27641
|
+
if (!this.preInitializeMeta)
|
|
27642
|
+
return true;
|
|
27643
|
+
const passphraseState = (payload === null || payload === void 0 ? void 0 : payload.passphraseState) === '' ? undefined : payload === null || payload === void 0 ? void 0 : payload.passphraseState;
|
|
27644
|
+
return this.preInitializeMeta.passphraseState === passphraseState;
|
|
27645
|
+
}
|
|
27646
|
+
isPreInitializedValid(ttlMs) {
|
|
27647
|
+
if (!this.preInitializedAt)
|
|
27648
|
+
return false;
|
|
27649
|
+
return Date.now() - this.preInitializedAt <= ttlMs;
|
|
27650
|
+
}
|
|
27651
|
+
setLastInitializeDuration(durationMs) {
|
|
27652
|
+
this.lastInitializeDurationMs = durationMs;
|
|
27653
|
+
}
|
|
27654
|
+
getLastInitializeDuration() {
|
|
27655
|
+
return this.lastInitializeDurationMs;
|
|
27656
|
+
}
|
|
27616
27657
|
getCommands() {
|
|
27617
27658
|
return this.commands;
|
|
27618
27659
|
}
|
|
@@ -27624,8 +27665,8 @@ class Device extends events.exports {
|
|
|
27624
27665
|
}
|
|
27625
27666
|
getInternalState(_deviceId) {
|
|
27626
27667
|
var _a, _b;
|
|
27627
|
-
Log$
|
|
27628
|
-
Log$
|
|
27668
|
+
Log$b.debug('getInternalState session cache: ', deviceSessionCache);
|
|
27669
|
+
Log$b.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}`);
|
|
27629
27670
|
const deviceId = _deviceId || ((_b = this.features) === null || _b === void 0 ? void 0 : _b.device_id);
|
|
27630
27671
|
if (!deviceId)
|
|
27631
27672
|
return undefined;
|
|
@@ -27635,7 +27676,7 @@ class Device extends events.exports {
|
|
|
27635
27676
|
return deviceSessionCache[usePassKey];
|
|
27636
27677
|
}
|
|
27637
27678
|
updateInternalState(enablePassphrase, passphraseState, deviceId, sessionId = null, featuresSessionId = null) {
|
|
27638
|
-
Log$
|
|
27679
|
+
Log$b.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `passphraseState: ${passphraseState}`, `sessionId: ${sessionId}`, `featuresSessionId: ${featuresSessionId}`);
|
|
27639
27680
|
if (enablePassphrase) {
|
|
27640
27681
|
if (sessionId) {
|
|
27641
27682
|
deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = sessionId;
|
|
@@ -27648,11 +27689,11 @@ class Device extends events.exports {
|
|
|
27648
27689
|
if (deviceSessionCache[oldKey]) {
|
|
27649
27690
|
delete deviceSessionCache[oldKey];
|
|
27650
27691
|
}
|
|
27651
|
-
Log$
|
|
27692
|
+
Log$b.debug('updateInternalState session cache: ', deviceSessionCache);
|
|
27652
27693
|
}
|
|
27653
27694
|
setInternalState(state, initSession) {
|
|
27654
27695
|
var _a, _b;
|
|
27655
|
-
Log$
|
|
27696
|
+
Log$b.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}`);
|
|
27656
27697
|
if (!this.features)
|
|
27657
27698
|
return;
|
|
27658
27699
|
if (!this.passphraseState && !initSession)
|
|
@@ -27664,11 +27705,11 @@ class Device extends events.exports {
|
|
|
27664
27705
|
if (state) {
|
|
27665
27706
|
deviceSessionCache[key] = state;
|
|
27666
27707
|
}
|
|
27667
|
-
Log$
|
|
27708
|
+
Log$b.debug('setInternalState done session cache: ', deviceSessionCache);
|
|
27668
27709
|
}
|
|
27669
27710
|
clearInternalState(_deviceId) {
|
|
27670
27711
|
var _a;
|
|
27671
|
-
Log$
|
|
27712
|
+
Log$b.debug('clearInternalState param: ', _deviceId);
|
|
27672
27713
|
const deviceId = _deviceId || ((_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id);
|
|
27673
27714
|
if (!deviceId)
|
|
27674
27715
|
return;
|
|
@@ -27695,12 +27736,7 @@ class Device extends events.exports {
|
|
|
27695
27736
|
}
|
|
27696
27737
|
payload.passphrase_state = options === null || options === void 0 ? void 0 : options.passphraseState;
|
|
27697
27738
|
payload.is_contains_attach = true;
|
|
27698
|
-
|
|
27699
|
-
deviceId: options === null || options === void 0 ? void 0 : options.deviceId,
|
|
27700
|
-
passphraseState: options === null || options === void 0 ? void 0 : options.passphraseState,
|
|
27701
|
-
initSession: options === null || options === void 0 ? void 0 : options.initSession,
|
|
27702
|
-
InitializePayload: payload,
|
|
27703
|
-
});
|
|
27739
|
+
const initStartAt = Date.now();
|
|
27704
27740
|
try {
|
|
27705
27741
|
const { message } = yield Promise.race([
|
|
27706
27742
|
this.commands.typedCall('Initialize', 'Features', payload),
|
|
@@ -27710,12 +27746,13 @@ class Device extends events.exports {
|
|
|
27710
27746
|
}, 25 * 1000);
|
|
27711
27747
|
}),
|
|
27712
27748
|
]);
|
|
27713
|
-
|
|
27749
|
+
const initCostMs = Date.now() - initStartAt;
|
|
27750
|
+
this.setLastInitializeDuration(initCostMs);
|
|
27714
27751
|
this._updateFeatures(message, options === null || options === void 0 ? void 0 : options.initSession);
|
|
27715
27752
|
yield TransportManager.reconfigure(this.features);
|
|
27716
27753
|
}
|
|
27717
27754
|
catch (error) {
|
|
27718
|
-
Log$
|
|
27755
|
+
Log$b.error('Initialization failed:', error);
|
|
27719
27756
|
throw error;
|
|
27720
27757
|
}
|
|
27721
27758
|
});
|
|
@@ -27766,7 +27803,7 @@ class Device extends events.exports {
|
|
|
27766
27803
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27767
27804
|
if (this.runPromise) {
|
|
27768
27805
|
yield this.interruptionFromOutside();
|
|
27769
|
-
Log$
|
|
27806
|
+
Log$b.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
|
|
27770
27807
|
}
|
|
27771
27808
|
options = parseRunOptions(options);
|
|
27772
27809
|
this.runPromise = hdShared.createDeferred(this._runInner.bind(this, fn, options));
|
|
@@ -27788,7 +27825,9 @@ class Device extends events.exports {
|
|
|
27788
27825
|
}
|
|
27789
27826
|
try {
|
|
27790
27827
|
if (fn) {
|
|
27791
|
-
|
|
27828
|
+
if (!(options === null || options === void 0 ? void 0 : options.skipInitialize)) {
|
|
27829
|
+
yield this.initialize(options);
|
|
27830
|
+
}
|
|
27792
27831
|
}
|
|
27793
27832
|
}
|
|
27794
27833
|
catch (error) {
|
|
@@ -27822,7 +27861,7 @@ class Device extends events.exports {
|
|
|
27822
27861
|
yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.disconnect(this.mainId));
|
|
27823
27862
|
}
|
|
27824
27863
|
yield this.release();
|
|
27825
|
-
Log$
|
|
27864
|
+
Log$b.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
|
|
27826
27865
|
}
|
|
27827
27866
|
this.runPromise = null;
|
|
27828
27867
|
return;
|
|
@@ -27832,7 +27871,7 @@ class Device extends events.exports {
|
|
|
27832
27871
|
options.keepSession === false) {
|
|
27833
27872
|
this.keepSession = false;
|
|
27834
27873
|
yield this.release();
|
|
27835
|
-
Log$
|
|
27874
|
+
Log$b.debug('release device, mainId: ', this.mainId);
|
|
27836
27875
|
}
|
|
27837
27876
|
if (this.runPromise) {
|
|
27838
27877
|
this.runPromise.resolve();
|
|
@@ -27865,7 +27904,7 @@ class Device extends events.exports {
|
|
|
27865
27904
|
setCancelableAction(callback) {
|
|
27866
27905
|
this.cancelableAction = (e) => callback(e)
|
|
27867
27906
|
.catch(e2 => {
|
|
27868
|
-
Log$
|
|
27907
|
+
Log$b.debug('cancelableAction error', e2);
|
|
27869
27908
|
})
|
|
27870
27909
|
.finally(() => {
|
|
27871
27910
|
this.clearCancelableAction();
|
|
@@ -28020,7 +28059,7 @@ class Device extends events.exports {
|
|
|
28020
28059
|
}
|
|
28021
28060
|
const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
|
|
28022
28061
|
const useErrorAttachPin = unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
|
|
28023
|
-
Log$
|
|
28062
|
+
Log$b.debug('Check passphrase state safety: ', {
|
|
28024
28063
|
passphraseState,
|
|
28025
28064
|
newPassphraseState,
|
|
28026
28065
|
unlockedAttachPin,
|
|
@@ -28068,6 +28107,27 @@ class DeviceList extends events.exports {
|
|
|
28068
28107
|
}
|
|
28069
28108
|
}
|
|
28070
28109
|
|
|
28110
|
+
class PollingStateManager {
|
|
28111
|
+
constructor() {
|
|
28112
|
+
this.activePolls = new Map();
|
|
28113
|
+
}
|
|
28114
|
+
start(connectId) {
|
|
28115
|
+
var _a;
|
|
28116
|
+
const currentId = ((_a = this.activePolls.get(connectId)) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
28117
|
+
this.activePolls.set(connectId, currentId);
|
|
28118
|
+
return currentId;
|
|
28119
|
+
}
|
|
28120
|
+
isActive(connectId, pollingId) {
|
|
28121
|
+
return this.activePolls.get(connectId) === pollingId;
|
|
28122
|
+
}
|
|
28123
|
+
stop(connectId) {
|
|
28124
|
+
this.activePolls.delete(connectId);
|
|
28125
|
+
}
|
|
28126
|
+
stopAll() {
|
|
28127
|
+
this.activePolls.clear();
|
|
28128
|
+
}
|
|
28129
|
+
}
|
|
28130
|
+
|
|
28071
28131
|
const getFirmwareReleaseInfo = (features, firmwareType) => {
|
|
28072
28132
|
const firmwareStatus = DataManager.getFirmwareStatus(features, firmwareType);
|
|
28073
28133
|
const changelog = DataManager.getFirmwareChangelog(features, firmwareType);
|
|
@@ -28120,7 +28180,7 @@ const getBootloaderReleaseInfo = ({ features, willUpdateFirmwareVersion, firmwar
|
|
|
28120
28180
|
};
|
|
28121
28181
|
};
|
|
28122
28182
|
|
|
28123
|
-
const Log$
|
|
28183
|
+
const Log$a = getLogger(exports.LoggerNames.Method);
|
|
28124
28184
|
const isEvmLedgerLegacyPathWithHighIndex = (path) => {
|
|
28125
28185
|
let addressN;
|
|
28126
28186
|
if (typeof path === 'string') {
|
|
@@ -28144,11 +28204,23 @@ const isEvmLedgerLegacyPathWithHighIndex = (path) => {
|
|
|
28144
28204
|
};
|
|
28145
28205
|
const EVM_LEDGER_LEGACY_METHODS = ['evmGetAddress', 'evmGetPublicKey'];
|
|
28146
28206
|
class BaseMethod {
|
|
28207
|
+
getPreWarmKey() {
|
|
28208
|
+
var _a, _b, _c, _d;
|
|
28209
|
+
const payload = ((_a = this.payload) !== null && _a !== void 0 ? _a : {});
|
|
28210
|
+
return [
|
|
28211
|
+
(_c = (_b = this.connectId) !== null && _b !== void 0 ? _b : payload.connectId) !== null && _c !== void 0 ? _c : '',
|
|
28212
|
+
(_d = payload.passphraseState) !== null && _d !== void 0 ? _d : '',
|
|
28213
|
+
this.name,
|
|
28214
|
+
].join('|');
|
|
28215
|
+
}
|
|
28147
28216
|
constructor(message) {
|
|
28148
28217
|
this.shouldEnsureConnected = true;
|
|
28149
28218
|
this.checkDeviceId = false;
|
|
28150
28219
|
this.useDevicePassphraseState = true;
|
|
28151
28220
|
this.skipForceUpdateCheck = false;
|
|
28221
|
+
this.allowUsePreInitialize = false;
|
|
28222
|
+
this.isPreWarmSignal = false;
|
|
28223
|
+
this.preWarmTtl = 60 * 1000;
|
|
28152
28224
|
this.strictCheckDeviceSupport = false;
|
|
28153
28225
|
this.temporarySafetyCheckPrompted = false;
|
|
28154
28226
|
this.postPreviousAddressMessage = (data) => {
|
|
@@ -28173,7 +28245,7 @@ class BaseMethod {
|
|
|
28173
28245
|
setContext(context) {
|
|
28174
28246
|
this.sdkInstanceId = context.sdkInstanceId;
|
|
28175
28247
|
this.instanceId = generateInstanceId('Method', this.sdkInstanceId);
|
|
28176
|
-
Log$
|
|
28248
|
+
Log$a.debug(`[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}`);
|
|
28177
28249
|
}
|
|
28178
28250
|
setDevice(device) {
|
|
28179
28251
|
var _a, _b;
|
|
@@ -28193,7 +28265,7 @@ class BaseMethod {
|
|
|
28193
28265
|
if (device.commands) {
|
|
28194
28266
|
device.commands.currentResponseID = this.responseID;
|
|
28195
28267
|
}
|
|
28196
|
-
Log$
|
|
28268
|
+
Log$a.debug(`[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${(_b = device.commands) === null || _b === void 0 ? void 0 : _b.instanceId}`);
|
|
28197
28269
|
}
|
|
28198
28270
|
checkFirmwareRelease() {
|
|
28199
28271
|
if (!this.device || !this.device.features)
|
|
@@ -28266,7 +28338,7 @@ class BaseMethod {
|
|
|
28266
28338
|
checkFlag = true;
|
|
28267
28339
|
}
|
|
28268
28340
|
if (checkFlag && ((_c = this.device.features) === null || _c === void 0 ? void 0 : _c.safety_checks) === 'Strict') {
|
|
28269
|
-
Log$
|
|
28341
|
+
Log$a.debug('will change safety_checks level');
|
|
28270
28342
|
yield this.device.commands.typedCall('ApplySettings', 'Success', {
|
|
28271
28343
|
safety_checks: 'PromptTemporarily',
|
|
28272
28344
|
});
|
|
@@ -28300,6 +28372,36 @@ class TestInitializeDeviceDuration extends BaseMethod {
|
|
|
28300
28372
|
}
|
|
28301
28373
|
}
|
|
28302
28374
|
|
|
28375
|
+
const Log$9 = getLogger(exports.LoggerNames.Core);
|
|
28376
|
+
const parseInitOptions$1 = (payload) => ({
|
|
28377
|
+
initSession: payload === null || payload === void 0 ? void 0 : payload.initSession,
|
|
28378
|
+
passphraseState: payload === null || payload === void 0 ? void 0 : payload.passphraseState,
|
|
28379
|
+
deriveCardano: payload === null || payload === void 0 ? void 0 : payload.deriveCardano,
|
|
28380
|
+
});
|
|
28381
|
+
class PreInitialize extends BaseMethod {
|
|
28382
|
+
init() {
|
|
28383
|
+
this.skipForceUpdateCheck = true;
|
|
28384
|
+
this.useDevicePassphraseState = false;
|
|
28385
|
+
this.isPreWarmSignal = true;
|
|
28386
|
+
}
|
|
28387
|
+
run() {
|
|
28388
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28389
|
+
try {
|
|
28390
|
+
yield this.device.preInitialize(parseInitOptions$1(this.payload));
|
|
28391
|
+
if (this.device.hasDeviceAcquire()) {
|
|
28392
|
+
yield this.device.release();
|
|
28393
|
+
}
|
|
28394
|
+
return true;
|
|
28395
|
+
}
|
|
28396
|
+
catch (_a) {
|
|
28397
|
+
this.device.clearPreInitialized();
|
|
28398
|
+
Log$9.debug('[PRE-INIT][FAILED]');
|
|
28399
|
+
return false;
|
|
28400
|
+
}
|
|
28401
|
+
});
|
|
28402
|
+
}
|
|
28403
|
+
}
|
|
28404
|
+
|
|
28303
28405
|
class SearchDevices extends BaseMethod {
|
|
28304
28406
|
init() {
|
|
28305
28407
|
this.useDevice = false;
|
|
@@ -32378,6 +32480,7 @@ class BTCSignMessage extends BaseMethod {
|
|
|
32378
32480
|
init() {
|
|
32379
32481
|
this.checkDeviceId = true;
|
|
32380
32482
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
32483
|
+
this.allowUsePreInitialize = true;
|
|
32381
32484
|
validateParams(this.payload, [
|
|
32382
32485
|
{ name: 'path', required: true },
|
|
32383
32486
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -32434,6 +32537,7 @@ class BTCSignPsbt extends BaseMethod {
|
|
|
32434
32537
|
init() {
|
|
32435
32538
|
this.checkDeviceId = true;
|
|
32436
32539
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
32540
|
+
this.allowUsePreInitialize = true;
|
|
32437
32541
|
validateParams(this.payload, [
|
|
32438
32542
|
{ name: 'psbt', type: 'hexString', required: true },
|
|
32439
32543
|
{ name: 'coin', type: 'string' },
|
|
@@ -32752,6 +32856,7 @@ class BTCSignTransaction extends BaseMethod {
|
|
|
32752
32856
|
init() {
|
|
32753
32857
|
this.checkDeviceId = true;
|
|
32754
32858
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
32859
|
+
this.allowUsePreInitialize = true;
|
|
32755
32860
|
validateParams(this.payload, [
|
|
32756
32861
|
{ name: 'coin', type: 'string', required: true },
|
|
32757
32862
|
{ name: 'inputs', type: 'array', required: true },
|
|
@@ -32932,6 +33037,7 @@ class ConfluxGetAddress extends BaseMethod {
|
|
|
32932
33037
|
class ConfluxSignMessage extends BaseMethod {
|
|
32933
33038
|
init() {
|
|
32934
33039
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
33040
|
+
this.allowUsePreInitialize = true;
|
|
32935
33041
|
validateParams(this.payload, [
|
|
32936
33042
|
{ name: 'path', required: true },
|
|
32937
33043
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -32961,6 +33067,7 @@ class ConfluxSignMessage extends BaseMethod {
|
|
|
32961
33067
|
class ConfluxSignMessageCIP23 extends BaseMethod {
|
|
32962
33068
|
init() {
|
|
32963
33069
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
33070
|
+
this.allowUsePreInitialize = true;
|
|
32964
33071
|
validateParams(this.payload, [
|
|
32965
33072
|
{ name: 'path', required: true },
|
|
32966
33073
|
{ name: 'domainHash', type: 'hexString', required: true },
|
|
@@ -33046,6 +33153,7 @@ class ConfluxSignTransaction extends BaseMethod {
|
|
|
33046
33153
|
}
|
|
33047
33154
|
init() {
|
|
33048
33155
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
33156
|
+
this.allowUsePreInitialize = true;
|
|
33049
33157
|
validateParams(this.payload, [
|
|
33050
33158
|
{ name: 'path', required: true },
|
|
33051
33159
|
{ name: 'transaction', type: 'object', required: true },
|
|
@@ -33289,10 +33397,12 @@ class EVMSignMessage$2 extends BaseMethod {
|
|
|
33289
33397
|
init() {
|
|
33290
33398
|
this.checkDeviceId = true;
|
|
33291
33399
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
33400
|
+
this.allowUsePreInitialize = true;
|
|
33292
33401
|
validateParams(this.payload, [
|
|
33293
33402
|
{ name: 'path', required: true },
|
|
33294
33403
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
33295
33404
|
{ name: 'chainId', type: 'number' },
|
|
33405
|
+
{ name: 'usePreInitialize', type: 'boolean' },
|
|
33296
33406
|
]);
|
|
33297
33407
|
const { path, messageHex, chainId } = this.payload;
|
|
33298
33408
|
const addressN = validatePath(path, 3);
|
|
@@ -33322,6 +33432,7 @@ class EVMSignMessageEIP712 extends BaseMethod {
|
|
|
33322
33432
|
init() {
|
|
33323
33433
|
this.checkDeviceId = true;
|
|
33324
33434
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
33435
|
+
this.allowUsePreInitialize = true;
|
|
33325
33436
|
validateParams(this.payload, [
|
|
33326
33437
|
{ name: 'path', required: true },
|
|
33327
33438
|
{ name: 'domainHash', type: 'hexString', required: true },
|
|
@@ -33555,9 +33666,11 @@ class EVMSignTransaction extends BaseMethod {
|
|
|
33555
33666
|
init() {
|
|
33556
33667
|
this.checkDeviceId = true;
|
|
33557
33668
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
33669
|
+
this.allowUsePreInitialize = true;
|
|
33558
33670
|
validateParams(this.payload, [
|
|
33559
33671
|
{ name: 'path', required: true },
|
|
33560
33672
|
{ name: 'transaction', type: 'object', required: true },
|
|
33673
|
+
{ name: 'usePreInitialize', type: 'boolean' },
|
|
33561
33674
|
]);
|
|
33562
33675
|
const { path, transaction } = this.payload;
|
|
33563
33676
|
this.addressN = validatePath(path, 3);
|
|
@@ -33824,6 +33937,7 @@ class EVMSignTypedData extends BaseMethod {
|
|
|
33824
33937
|
init() {
|
|
33825
33938
|
this.checkDeviceId = true;
|
|
33826
33939
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
33940
|
+
this.allowUsePreInitialize = true;
|
|
33827
33941
|
validateParams(this.payload, [
|
|
33828
33942
|
{ name: 'path', required: true },
|
|
33829
33943
|
{ name: 'metamaskV4Compat', type: 'boolean' },
|
|
@@ -33831,6 +33945,7 @@ class EVMSignTypedData extends BaseMethod {
|
|
|
33831
33945
|
{ name: 'domainHash', type: 'hexString' },
|
|
33832
33946
|
{ name: 'messageHash', type: 'hexString' },
|
|
33833
33947
|
{ name: 'chainId', type: 'number' },
|
|
33948
|
+
{ name: 'usePreInitialize', type: 'boolean' },
|
|
33834
33949
|
]);
|
|
33835
33950
|
const { path, data, metamaskV4Compat, domainHash, messageHash, chainId } = this.payload;
|
|
33836
33951
|
const addressN = validatePath(path, 3);
|
|
@@ -34377,6 +34492,7 @@ class StarcoinSignMessage extends BaseMethod {
|
|
|
34377
34492
|
init() {
|
|
34378
34493
|
this.checkDeviceId = true;
|
|
34379
34494
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
34495
|
+
this.allowUsePreInitialize = true;
|
|
34380
34496
|
validateParams(this.payload, [
|
|
34381
34497
|
{ name: 'path', required: true },
|
|
34382
34498
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -34400,6 +34516,7 @@ class StarcoinSignTransaction extends BaseMethod {
|
|
|
34400
34516
|
init() {
|
|
34401
34517
|
this.checkDeviceId = true;
|
|
34402
34518
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
34519
|
+
this.allowUsePreInitialize = true;
|
|
34403
34520
|
validateParams(this.payload, [
|
|
34404
34521
|
{ name: 'path', required: true },
|
|
34405
34522
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -34668,6 +34785,7 @@ class NEMSignTransaction extends BaseMethod {
|
|
|
34668
34785
|
init() {
|
|
34669
34786
|
this.checkDeviceId = true;
|
|
34670
34787
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
34788
|
+
this.allowUsePreInitialize = true;
|
|
34671
34789
|
validateParams(this.payload, [
|
|
34672
34790
|
{ name: 'path', required: true },
|
|
34673
34791
|
{ name: 'transaction', type: 'object', required: true },
|
|
@@ -34742,6 +34860,7 @@ class SolSignTransaction extends BaseMethod {
|
|
|
34742
34860
|
var _a;
|
|
34743
34861
|
this.checkDeviceId = true;
|
|
34744
34862
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
34863
|
+
this.allowUsePreInitialize = true;
|
|
34745
34864
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
34746
34865
|
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
34747
34866
|
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
@@ -34819,6 +34938,7 @@ class SolSignOffchainMessage extends BaseMethod {
|
|
|
34819
34938
|
init() {
|
|
34820
34939
|
this.checkDeviceId = true;
|
|
34821
34940
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
34941
|
+
this.allowUsePreInitialize = true;
|
|
34822
34942
|
validateParams(this.payload, [
|
|
34823
34943
|
{ name: 'path', required: true },
|
|
34824
34944
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -34861,6 +34981,7 @@ class SolSignMessage extends BaseMethod {
|
|
|
34861
34981
|
init() {
|
|
34862
34982
|
this.checkDeviceId = true;
|
|
34863
34983
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
34984
|
+
this.allowUsePreInitialize = true;
|
|
34864
34985
|
validateParams(this.payload, [
|
|
34865
34986
|
{ name: 'path', required: true },
|
|
34866
34987
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -35162,6 +35283,7 @@ class StellarSignTransaction extends BaseMethod {
|
|
|
35162
35283
|
init() {
|
|
35163
35284
|
this.checkDeviceId = true;
|
|
35164
35285
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
35286
|
+
this.allowUsePreInitialize = true;
|
|
35165
35287
|
validateParams(this.payload, [
|
|
35166
35288
|
{ name: 'path', required: true },
|
|
35167
35289
|
{ name: 'networkPassphrase', type: 'string', required: true },
|
|
@@ -35271,6 +35393,7 @@ class TronSignMessage extends BaseMethod {
|
|
|
35271
35393
|
init() {
|
|
35272
35394
|
this.checkDeviceId = true;
|
|
35273
35395
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
35396
|
+
this.allowUsePreInitialize = true;
|
|
35274
35397
|
validateParams(this.payload, [
|
|
35275
35398
|
{ name: 'path', required: true },
|
|
35276
35399
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -35425,6 +35548,7 @@ class TronSignTransaction extends BaseMethod {
|
|
|
35425
35548
|
init() {
|
|
35426
35549
|
this.checkDeviceId = true;
|
|
35427
35550
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
35551
|
+
this.allowUsePreInitialize = true;
|
|
35428
35552
|
validateParams(this.payload, [
|
|
35429
35553
|
{ name: 'path', required: true },
|
|
35430
35554
|
{ name: 'transaction', type: 'object', required: true },
|
|
@@ -35554,6 +35678,7 @@ class NearSignTransaction extends BaseMethod {
|
|
|
35554
35678
|
init() {
|
|
35555
35679
|
this.checkDeviceId = true;
|
|
35556
35680
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
35681
|
+
this.allowUsePreInitialize = true;
|
|
35557
35682
|
validateParams(this.payload, [
|
|
35558
35683
|
{ name: 'path', required: true },
|
|
35559
35684
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -35730,6 +35855,7 @@ class AptosSignTransaction extends BaseMethod {
|
|
|
35730
35855
|
init() {
|
|
35731
35856
|
this.checkDeviceId = true;
|
|
35732
35857
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
35858
|
+
this.allowUsePreInitialize = true;
|
|
35733
35859
|
validateParams(this.payload, [
|
|
35734
35860
|
{ name: 'path', required: true },
|
|
35735
35861
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -35780,6 +35906,7 @@ class AptosSignMessage extends BaseMethod {
|
|
|
35780
35906
|
init() {
|
|
35781
35907
|
this.checkDeviceId = true;
|
|
35782
35908
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
35909
|
+
this.allowUsePreInitialize = true;
|
|
35783
35910
|
validateParams(this.payload, [
|
|
35784
35911
|
{ name: 'path', required: true },
|
|
35785
35912
|
{ name: 'payload', type: 'object', required: true },
|
|
@@ -35841,6 +35968,7 @@ class AptosSignInMessage extends BaseMethod {
|
|
|
35841
35968
|
init() {
|
|
35842
35969
|
this.checkDeviceId = true;
|
|
35843
35970
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
35971
|
+
this.allowUsePreInitialize = true;
|
|
35844
35972
|
validateParams(this.payload, [
|
|
35845
35973
|
{ name: 'path', required: true },
|
|
35846
35974
|
{ name: 'payload', type: 'string', required: true },
|
|
@@ -35936,6 +36064,7 @@ class AlgoSignTransaction extends BaseMethod {
|
|
|
35936
36064
|
init() {
|
|
35937
36065
|
this.checkDeviceId = true;
|
|
35938
36066
|
this.allowDeviceMode = [...this.allowDeviceMode];
|
|
36067
|
+
this.allowUsePreInitialize = true;
|
|
35939
36068
|
validateParams(this.payload, [
|
|
35940
36069
|
{ name: 'path', required: true },
|
|
35941
36070
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -36098,6 +36227,7 @@ class CosmosSignTransaction extends BaseMethod {
|
|
|
36098
36227
|
init() {
|
|
36099
36228
|
this.checkDeviceId = true;
|
|
36100
36229
|
this.allowDeviceMode = [...this.allowDeviceMode];
|
|
36230
|
+
this.allowUsePreInitialize = true;
|
|
36101
36231
|
validateParams(this.payload, [
|
|
36102
36232
|
{ name: 'path', required: true },
|
|
36103
36233
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -36219,6 +36349,7 @@ class XrpGetAddress extends BaseMethod {
|
|
|
36219
36349
|
init() {
|
|
36220
36350
|
this.checkDeviceId = true;
|
|
36221
36351
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
36352
|
+
this.allowUsePreInitialize = true;
|
|
36222
36353
|
const { payload } = this;
|
|
36223
36354
|
validateParams(payload, [
|
|
36224
36355
|
{ name: 'path', required: true },
|
|
@@ -36439,6 +36570,7 @@ class SuiSignMessage extends BaseMethod {
|
|
|
36439
36570
|
init() {
|
|
36440
36571
|
this.checkDeviceId = true;
|
|
36441
36572
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
36573
|
+
this.allowUsePreInitialize = true;
|
|
36442
36574
|
validateParams(this.payload, [
|
|
36443
36575
|
{ name: 'path', required: true },
|
|
36444
36576
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -36492,6 +36624,7 @@ class SuiSignTransaction extends BaseMethod {
|
|
|
36492
36624
|
init() {
|
|
36493
36625
|
this.checkDeviceId = true;
|
|
36494
36626
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
36627
|
+
this.allowUsePreInitialize = true;
|
|
36495
36628
|
validateParams(this.payload, [
|
|
36496
36629
|
{ name: 'path', required: true },
|
|
36497
36630
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -37290,6 +37423,7 @@ class CardanoSignTransaction extends BaseMethod {
|
|
|
37290
37423
|
var _a;
|
|
37291
37424
|
this.checkDeviceId = true;
|
|
37292
37425
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
37426
|
+
this.allowUsePreInitialize = true;
|
|
37293
37427
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
37294
37428
|
const { payload } = this;
|
|
37295
37429
|
if (payload.auxiliaryData && payload.auxiliaryData.governanceRegistrationParameters) {
|
|
@@ -37525,6 +37659,7 @@ class CardanoSignMessage extends BaseMethod {
|
|
|
37525
37659
|
init() {
|
|
37526
37660
|
this.checkDeviceId = true;
|
|
37527
37661
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
37662
|
+
this.allowUsePreInitialize = true;
|
|
37528
37663
|
const { payload } = this;
|
|
37529
37664
|
validateParams(payload, [
|
|
37530
37665
|
{ name: 'path', type: 'string', required: true },
|
|
@@ -37638,6 +37773,7 @@ class FilecoinSignTransaction extends BaseMethod {
|
|
|
37638
37773
|
init() {
|
|
37639
37774
|
this.checkDeviceId = true;
|
|
37640
37775
|
this.allowDeviceMode = [...this.allowDeviceMode];
|
|
37776
|
+
this.allowUsePreInitialize = true;
|
|
37641
37777
|
validateParams(this.payload, [
|
|
37642
37778
|
{ name: 'path', required: true },
|
|
37643
37779
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -37808,6 +37944,7 @@ class PolkadotSignTransaction extends BaseMethod {
|
|
|
37808
37944
|
init() {
|
|
37809
37945
|
this.checkDeviceId = true;
|
|
37810
37946
|
this.allowDeviceMode = [...this.allowDeviceMode];
|
|
37947
|
+
this.allowUsePreInitialize = true;
|
|
37811
37948
|
validateParams(this.payload, [
|
|
37812
37949
|
{ name: 'path', required: true },
|
|
37813
37950
|
{ name: 'network', required: true },
|
|
@@ -38230,6 +38367,7 @@ class KaspaSignTransaction extends BaseMethod {
|
|
|
38230
38367
|
var _a, _b, _c, _d, _e;
|
|
38231
38368
|
this.checkDeviceId = true;
|
|
38232
38369
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
38370
|
+
this.allowUsePreInitialize = true;
|
|
38233
38371
|
const payload = this.payload;
|
|
38234
38372
|
validateParams(payload, [
|
|
38235
38373
|
{ name: 'version', type: 'number' },
|
|
@@ -38402,6 +38540,7 @@ class NexaSignTransaction extends BaseMethod {
|
|
|
38402
38540
|
this.hasBundle = false;
|
|
38403
38541
|
}
|
|
38404
38542
|
init() {
|
|
38543
|
+
this.allowUsePreInitialize = true;
|
|
38405
38544
|
const payload = this.payload;
|
|
38406
38545
|
payload.inputs.forEach(input => {
|
|
38407
38546
|
validateParams(input, [
|
|
@@ -38553,6 +38692,7 @@ class NostrSignEvent extends BaseMethod {
|
|
|
38553
38692
|
init() {
|
|
38554
38693
|
this.checkDeviceId = true;
|
|
38555
38694
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
38695
|
+
this.allowUsePreInitialize = true;
|
|
38556
38696
|
const { payload } = this;
|
|
38557
38697
|
if (!validateEvent(payload.event)) {
|
|
38558
38698
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Can't serialize event with wrong or missing properties`);
|
|
@@ -38695,6 +38835,7 @@ class NostrSignSchnorr extends BaseMethod {
|
|
|
38695
38835
|
init() {
|
|
38696
38836
|
this.checkDeviceId = true;
|
|
38697
38837
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
38838
|
+
this.allowUsePreInitialize = true;
|
|
38698
38839
|
const { payload } = this;
|
|
38699
38840
|
validateParams(payload, [
|
|
38700
38841
|
{ name: 'path', required: true },
|
|
@@ -38858,6 +38999,7 @@ class NervosSignTransaction extends BaseMethod {
|
|
|
38858
38999
|
init() {
|
|
38859
39000
|
this.checkDeviceId = true;
|
|
38860
39001
|
this.allowDeviceMode = [...this.allowDeviceMode];
|
|
39002
|
+
this.allowUsePreInitialize = true;
|
|
38861
39003
|
validateParams(this.payload, [
|
|
38862
39004
|
{ name: 'path', required: true },
|
|
38863
39005
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -38965,6 +39107,7 @@ class DnxSignTransaction extends BaseMethod {
|
|
|
38965
39107
|
init() {
|
|
38966
39108
|
this.checkDeviceId = true;
|
|
38967
39109
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
39110
|
+
this.allowUsePreInitialize = true;
|
|
38968
39111
|
const { payload } = this;
|
|
38969
39112
|
const addressN = validatePath(payload.path, 3);
|
|
38970
39113
|
validateParams(payload, [
|
|
@@ -39146,6 +39289,7 @@ class TonSignMessage extends BaseMethod {
|
|
|
39146
39289
|
this.strictCheckDeviceSupport = true;
|
|
39147
39290
|
this.checkDeviceId = true;
|
|
39148
39291
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
39292
|
+
this.allowUsePreInitialize = true;
|
|
39149
39293
|
validateParams(this.payload, [
|
|
39150
39294
|
{ name: 'path', required: true },
|
|
39151
39295
|
{ name: 'destination', type: 'string' },
|
|
@@ -39290,6 +39434,7 @@ class TonSignProof extends BaseMethod {
|
|
|
39290
39434
|
this.strictCheckDeviceSupport = true;
|
|
39291
39435
|
this.checkDeviceId = true;
|
|
39292
39436
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
39437
|
+
this.allowUsePreInitialize = true;
|
|
39293
39438
|
validateParams(this.payload, [
|
|
39294
39439
|
{ name: 'path', required: true },
|
|
39295
39440
|
{ name: 'appdomain', type: 'string' },
|
|
@@ -39338,6 +39483,7 @@ class TonSignData extends BaseMethod {
|
|
|
39338
39483
|
this.strictCheckDeviceSupport = false;
|
|
39339
39484
|
this.checkDeviceId = true;
|
|
39340
39485
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
39486
|
+
this.allowUsePreInitialize = true;
|
|
39341
39487
|
validateParams(this.payload, [
|
|
39342
39488
|
{ name: 'path', required: true },
|
|
39343
39489
|
{ name: 'type', type: 'number', required: true },
|
|
@@ -39454,6 +39600,7 @@ class ScdoSignTransaction extends BaseMethod {
|
|
|
39454
39600
|
init() {
|
|
39455
39601
|
this.checkDeviceId = true;
|
|
39456
39602
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
39603
|
+
this.allowUsePreInitialize = true;
|
|
39457
39604
|
validateParams(this.payload, [
|
|
39458
39605
|
{ name: 'path', required: true },
|
|
39459
39606
|
{ name: 'nonce', required: true },
|
|
@@ -39507,6 +39654,7 @@ class ScdoSignMessage extends BaseMethod {
|
|
|
39507
39654
|
init() {
|
|
39508
39655
|
this.checkDeviceId = true;
|
|
39509
39656
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
39657
|
+
this.allowUsePreInitialize = true;
|
|
39510
39658
|
validateParams(this.payload, [
|
|
39511
39659
|
{ name: 'path', required: true },
|
|
39512
39660
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -39629,6 +39777,7 @@ class AlephiumSignTransaction extends BaseMethod {
|
|
|
39629
39777
|
init() {
|
|
39630
39778
|
this.checkDeviceId = true;
|
|
39631
39779
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
39780
|
+
this.allowUsePreInitialize = true;
|
|
39632
39781
|
validateParams(this.payload, [
|
|
39633
39782
|
{ name: 'path', required: true },
|
|
39634
39783
|
{ name: 'rawTx', required: true, type: 'hexString' },
|
|
@@ -39670,6 +39819,7 @@ class AlephiumSignMessage extends BaseMethod {
|
|
|
39670
39819
|
init() {
|
|
39671
39820
|
this.checkDeviceId = true;
|
|
39672
39821
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
39822
|
+
this.allowUsePreInitialize = true;
|
|
39673
39823
|
validateParams(this.payload, [
|
|
39674
39824
|
{ name: 'path', required: true },
|
|
39675
39825
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -39875,6 +40025,7 @@ class BenfenSignMessage extends BaseMethod {
|
|
|
39875
40025
|
init() {
|
|
39876
40026
|
this.checkDeviceId = true;
|
|
39877
40027
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
40028
|
+
this.allowUsePreInitialize = true;
|
|
39878
40029
|
validateParams(this.payload, [
|
|
39879
40030
|
{ name: 'path', required: true },
|
|
39880
40031
|
{ name: 'messageHex', type: 'hexString', required: true },
|
|
@@ -39928,6 +40079,7 @@ class BenfenSignTransaction extends BaseMethod {
|
|
|
39928
40079
|
init() {
|
|
39929
40080
|
this.checkDeviceId = true;
|
|
39930
40081
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
40082
|
+
this.allowUsePreInitialize = true;
|
|
39931
40083
|
validateParams(this.payload, [
|
|
39932
40084
|
{ name: 'path', required: true },
|
|
39933
40085
|
{ name: 'rawTx', type: 'hexString', required: true },
|
|
@@ -40035,6 +40187,7 @@ class NeoSignTransaction extends BaseMethod {
|
|
|
40035
40187
|
init() {
|
|
40036
40188
|
this.checkDeviceId = true;
|
|
40037
40189
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
40190
|
+
this.allowUsePreInitialize = true;
|
|
40038
40191
|
this.strictCheckDeviceSupport = true;
|
|
40039
40192
|
validateParams(this.payload, [
|
|
40040
40193
|
{ name: 'path', required: true },
|
|
@@ -40079,6 +40232,7 @@ class NeoSignTransaction extends BaseMethod {
|
|
|
40079
40232
|
var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
40080
40233
|
__proto__: null,
|
|
40081
40234
|
testInitializeDeviceDuration: TestInitializeDeviceDuration,
|
|
40235
|
+
preInitialize: PreInitialize,
|
|
40082
40236
|
searchDevices: SearchDevices,
|
|
40083
40237
|
getFeatures: GetFeatures,
|
|
40084
40238
|
getOnekeyFeatures: GetOnekeyFeatures,
|
|
@@ -40425,13 +40579,15 @@ class RequestQueue {
|
|
|
40425
40579
|
this.pendingCallbackTasks.set(connectId, callbackPromise);
|
|
40426
40580
|
callbackPromise.promise.finally(() => {
|
|
40427
40581
|
Log$1.debug(`Callback task completed for connectId: ${connectId}`);
|
|
40428
|
-
this.pendingCallbackTasks.
|
|
40582
|
+
if (this.pendingCallbackTasks.get(connectId) === callbackPromise) {
|
|
40583
|
+
this.pendingCallbackTasks.delete(connectId);
|
|
40584
|
+
}
|
|
40429
40585
|
});
|
|
40430
40586
|
}
|
|
40431
|
-
waitForPendingCallbackTasks(connectId) {
|
|
40587
|
+
waitForPendingCallbackTasks(connectId, exceptTask) {
|
|
40432
40588
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40433
40589
|
const pendingTask = this.pendingCallbackTasks.get(connectId);
|
|
40434
|
-
if (pendingTask) {
|
|
40590
|
+
if (pendingTask && pendingTask !== exceptTask) {
|
|
40435
40591
|
Log$1.debug(`Waiting for pending callback task to complete for connectId: ${connectId}`);
|
|
40436
40592
|
yield pendingTask.promise;
|
|
40437
40593
|
}
|
|
@@ -40468,6 +40624,9 @@ const getSynchronize = (mutex) => {
|
|
|
40468
40624
|
};
|
|
40469
40625
|
|
|
40470
40626
|
const Log = getLogger(exports.LoggerNames.Core);
|
|
40627
|
+
const PRE_INITIALIZE_TTL_MS = 60 * 1000;
|
|
40628
|
+
const preWarmInflight = new Map();
|
|
40629
|
+
const preWarmDoneAt = new Map();
|
|
40471
40630
|
function hasDeriveCardano(method) {
|
|
40472
40631
|
var _a;
|
|
40473
40632
|
if (method.name.startsWith('allNetworkGetAddress') &&
|
|
@@ -40489,8 +40648,7 @@ let _deviceList;
|
|
|
40489
40648
|
let _connector;
|
|
40490
40649
|
let _uiPromises = [];
|
|
40491
40650
|
const deviceCacheMap = new Map();
|
|
40492
|
-
|
|
40493
|
-
const pollingState = {};
|
|
40651
|
+
const pollingManager = new PollingStateManager();
|
|
40494
40652
|
let preConnectCache = {
|
|
40495
40653
|
passphraseState: undefined,
|
|
40496
40654
|
};
|
|
@@ -40567,8 +40725,41 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
|
|
|
40567
40725
|
if (error) {
|
|
40568
40726
|
return createResponseMessage(method.responseID, false, { error });
|
|
40569
40727
|
}
|
|
40728
|
+
if (method.isPreWarmSignal) {
|
|
40729
|
+
return handlePreWarmSignal(context, message, method);
|
|
40730
|
+
}
|
|
40570
40731
|
return onCallDevice(context, message, method);
|
|
40571
40732
|
});
|
|
40733
|
+
const handlePreWarmSignal = (context, message, method) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40734
|
+
const key = method.getPreWarmKey();
|
|
40735
|
+
const inflight = preWarmInflight.get(key);
|
|
40736
|
+
if (inflight) {
|
|
40737
|
+
try {
|
|
40738
|
+
yield inflight;
|
|
40739
|
+
}
|
|
40740
|
+
catch (_b) {
|
|
40741
|
+
}
|
|
40742
|
+
return createResponseMessage(method.responseID, true, true);
|
|
40743
|
+
}
|
|
40744
|
+
const doneAt = preWarmDoneAt.get(key);
|
|
40745
|
+
if (typeof doneAt === 'number' && Date.now() - doneAt <= method.preWarmTtl) {
|
|
40746
|
+
return createResponseMessage(method.responseID, true, true);
|
|
40747
|
+
}
|
|
40748
|
+
const run = onCallDevice(context, message, method);
|
|
40749
|
+
preWarmInflight.set(key, run);
|
|
40750
|
+
try {
|
|
40751
|
+
const result = yield run;
|
|
40752
|
+
if ((result === null || result === void 0 ? void 0 : result.success) === true && (result === null || result === void 0 ? void 0 : result.payload) === true) {
|
|
40753
|
+
preWarmDoneAt.set(key, Date.now());
|
|
40754
|
+
}
|
|
40755
|
+
return result;
|
|
40756
|
+
}
|
|
40757
|
+
finally {
|
|
40758
|
+
if (preWarmInflight.get(key) === run) {
|
|
40759
|
+
preWarmInflight.delete(key);
|
|
40760
|
+
}
|
|
40761
|
+
}
|
|
40762
|
+
});
|
|
40572
40763
|
const waitWithTimeout = (promise, timeout) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40573
40764
|
const timeoutPromise = new Promise((_, reject) => {
|
|
40574
40765
|
setTimeout(() => reject(new Error('Request timeout')), timeout);
|
|
@@ -40589,11 +40780,13 @@ const waitForPendingPromise = (getPrePendingCallPromise, removePrePendingCallPro
|
|
|
40589
40780
|
}
|
|
40590
40781
|
});
|
|
40591
40782
|
const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40592
|
-
var
|
|
40783
|
+
var _c, _d, _e, _f, _g;
|
|
40593
40784
|
let messageResponse;
|
|
40594
40785
|
const { requestQueue, getPrePendingCallPromise, setPrePendingCallPromise } = context;
|
|
40595
40786
|
updateMethodRequestContext(method, { status: 'running' });
|
|
40596
|
-
const
|
|
40787
|
+
const normalizePassphraseState = (s) => s || '';
|
|
40788
|
+
const connectStateChange = normalizePassphraseState(preConnectCache.passphraseState) !==
|
|
40789
|
+
normalizePassphraseState(method.payload.passphraseState);
|
|
40597
40790
|
preConnectCache = {
|
|
40598
40791
|
passphraseState: method.payload.passphraseState,
|
|
40599
40792
|
};
|
|
@@ -40606,15 +40799,19 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
40606
40799
|
}
|
|
40607
40800
|
yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
40608
40801
|
const task = requestQueue.createTask(method);
|
|
40802
|
+
let preWarmCallbackTask;
|
|
40803
|
+
if (method.isPreWarmSignal && method.connectId) {
|
|
40804
|
+
preWarmCallbackTask = hdShared.createDeferred();
|
|
40805
|
+
context.registerCallbackTask(method.connectId, preWarmCallbackTask);
|
|
40806
|
+
}
|
|
40609
40807
|
let device;
|
|
40610
40808
|
try {
|
|
40611
|
-
|
|
40612
|
-
|
|
40613
|
-
|
|
40614
|
-
pollingId += 1;
|
|
40615
|
-
device = yield ensureConnected(context, method, pollingId, (_b = task.abortController) === null || _b === void 0 ? void 0 : _b.signal);
|
|
40809
|
+
const connectId = (_c = method.connectId) !== null && _c !== void 0 ? _c : '';
|
|
40810
|
+
const pollingId = pollingManager.start(connectId);
|
|
40811
|
+
device = yield ensureConnected(context, method, connectId, pollingId, (_d = task.abortController) === null || _d === void 0 ? void 0 : _d.signal);
|
|
40616
40812
|
}
|
|
40617
40813
|
catch (e) {
|
|
40814
|
+
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
40618
40815
|
console.log('ensureConnected error: ', e);
|
|
40619
40816
|
completeMethodRequestContext(method, e);
|
|
40620
40817
|
if (e.name === 'AbortError' || e.message === 'Request aborted') {
|
|
@@ -40626,16 +40823,17 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
40626
40823
|
requestQueue.releaseTask(method.responseID);
|
|
40627
40824
|
return createResponseMessage(method.responseID, false, { error: e });
|
|
40628
40825
|
}
|
|
40629
|
-
if ((
|
|
40826
|
+
if ((_e = method.payload) === null || _e === void 0 ? void 0 : _e.onlyConnectBleDevice) {
|
|
40827
|
+
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
40630
40828
|
Log.debug('Call API - only connect ble device: ', device === null || device === void 0 ? void 0 : device.mainId);
|
|
40631
40829
|
return createResponseMessage(method.responseID, true, null);
|
|
40632
40830
|
}
|
|
40633
40831
|
Log.debug('Call API - setDevice: ', device.mainId);
|
|
40634
|
-
(
|
|
40832
|
+
(_f = method.setDevice) === null || _f === void 0 ? void 0 : _f.call(method, device);
|
|
40635
40833
|
method.context = context;
|
|
40636
40834
|
updateMethodRequestContext(method, {
|
|
40637
40835
|
deviceInstanceId: device.instanceId,
|
|
40638
|
-
commandsInstanceId: (
|
|
40836
|
+
commandsInstanceId: (_g = device.commands) === null || _g === void 0 ? void 0 : _g.instanceId,
|
|
40639
40837
|
});
|
|
40640
40838
|
const activeRequests = getActiveRequestsByDeviceInstance(device.instanceId);
|
|
40641
40839
|
if (activeRequests.length > 0) {
|
|
@@ -40650,11 +40848,11 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
40650
40848
|
device.on(DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE, onSelectDeviceForSwitchFirmwareWebDeviceHandler);
|
|
40651
40849
|
try {
|
|
40652
40850
|
if (method.connectId) {
|
|
40653
|
-
yield context.waitForCallbackTasks(method.connectId);
|
|
40851
|
+
yield context.waitForCallbackTasks(method.connectId, preWarmCallbackTask);
|
|
40654
40852
|
}
|
|
40655
40853
|
yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
40656
40854
|
const inner = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40657
|
-
var
|
|
40855
|
+
var _h, _j, _k, _l, _m;
|
|
40658
40856
|
const versionRange = getMethodVersionRange(device.features, type => method.getVersionRange()[type]);
|
|
40659
40857
|
if (device.features) {
|
|
40660
40858
|
yield DataManager.checkAndReloadData();
|
|
@@ -40741,7 +40939,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
40741
40939
|
require: support.require,
|
|
40742
40940
|
}));
|
|
40743
40941
|
}
|
|
40744
|
-
const passphraseStateSafety = yield device.checkPassphraseStateSafety((
|
|
40942
|
+
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);
|
|
40745
40943
|
checkPassphraseEnableState(method, device.features);
|
|
40746
40944
|
if (!passphraseStateSafety) {
|
|
40747
40945
|
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
@@ -40758,10 +40956,9 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
40758
40956
|
: hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
|
|
40759
40957
|
throw error;
|
|
40760
40958
|
}
|
|
40761
|
-
(
|
|
40959
|
+
(_m = (_l = method.device) === null || _l === void 0 ? void 0 : _l.commands) === null || _m === void 0 ? void 0 : _m.checkDisposed();
|
|
40762
40960
|
try {
|
|
40763
40961
|
const response = yield method.run();
|
|
40764
|
-
Log.debug('Call API - Inner Method Run: ');
|
|
40765
40962
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
40766
40963
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
40767
40964
|
completeMethodRequestContext(method);
|
|
@@ -40778,7 +40975,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
40778
40975
|
}
|
|
40779
40976
|
});
|
|
40780
40977
|
Log.debug('Call API - Device Run: ', device.mainId);
|
|
40781
|
-
const runOptions = Object.assign({ keepSession: method.payload.keepSession }, parseInitOptions(method));
|
|
40978
|
+
const runOptions = Object.assign({ keepSession: method.payload.keepSession, skipInitialize: canSkipInitialize(method, device) }, parseInitOptions(method));
|
|
40782
40979
|
const deviceRun = () => device.run(inner, runOptions);
|
|
40783
40980
|
task.callPromise = hdShared.createDeferred(deviceRun);
|
|
40784
40981
|
try {
|
|
@@ -40797,6 +40994,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
40797
40994
|
completeMethodRequestContext(method, error);
|
|
40798
40995
|
}
|
|
40799
40996
|
finally {
|
|
40997
|
+
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
40800
40998
|
const response = messageResponse;
|
|
40801
40999
|
if (response) {
|
|
40802
41000
|
if (method) {
|
|
@@ -40891,8 +41089,29 @@ function initDeviceForBle(method) {
|
|
|
40891
41089
|
device.deviceConnector = _connector;
|
|
40892
41090
|
return device;
|
|
40893
41091
|
}
|
|
40894
|
-
|
|
40895
|
-
|
|
41092
|
+
function canSkipInitialize(method, device) {
|
|
41093
|
+
var _a;
|
|
41094
|
+
const reasons = [];
|
|
41095
|
+
if (!method.allowUsePreInitialize)
|
|
41096
|
+
reasons.push('method.disallow');
|
|
41097
|
+
if (!((_a = method.payload) === null || _a === void 0 ? void 0 : _a.usePreInitialize))
|
|
41098
|
+
reasons.push('payload.usePreInitialize=false');
|
|
41099
|
+
if (!device.isPreInitializeMetaMatch(method.payload))
|
|
41100
|
+
reasons.push('meta.mismatch');
|
|
41101
|
+
if (!device.features)
|
|
41102
|
+
reasons.push('features.missing');
|
|
41103
|
+
if (!device.isPreInitializedValid(PRE_INITIALIZE_TTL_MS))
|
|
41104
|
+
reasons.push('ttl.expired');
|
|
41105
|
+
if (reasons.length) {
|
|
41106
|
+
Log.debug(`[PRE-INIT][MISS] method=${method.name} ${reasons.join(',')}`);
|
|
41107
|
+
return false;
|
|
41108
|
+
}
|
|
41109
|
+
const savedMs = device.getLastInitializeDuration();
|
|
41110
|
+
const saved = typeof savedMs === 'number' ? `saved ${savedMs}ms` : 'within TTL + meta match';
|
|
41111
|
+
Log.debug(`[PRE-INIT][HIT] method=${method.name} skip Initialize (${saved})`);
|
|
41112
|
+
return true;
|
|
41113
|
+
}
|
|
41114
|
+
function connectDeviceForBle(method, device, retryCount = 0) {
|
|
40896
41115
|
var _a;
|
|
40897
41116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40898
41117
|
try {
|
|
@@ -40900,14 +41119,20 @@ function connectDeviceForBle(method, device) {
|
|
|
40900
41119
|
if ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.onlyConnectBleDevice) {
|
|
40901
41120
|
return;
|
|
40902
41121
|
}
|
|
40903
|
-
|
|
41122
|
+
if (!canSkipInitialize(method, device)) {
|
|
41123
|
+
const initOptions = parseInitOptions(method);
|
|
41124
|
+
yield device.initialize(initOptions);
|
|
41125
|
+
device.markPreInitialized({
|
|
41126
|
+
passphraseState: initOptions.passphraseState,
|
|
41127
|
+
});
|
|
41128
|
+
}
|
|
40904
41129
|
}
|
|
40905
41130
|
catch (err) {
|
|
40906
|
-
if (err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError &&
|
|
40907
|
-
|
|
40908
|
-
Log.debug(`
|
|
41131
|
+
if (err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError && retryCount < 6) {
|
|
41132
|
+
const nextRetry = retryCount + 1;
|
|
41133
|
+
Log.debug(`Bluetooth connect timeout and will retry, retry count: ${nextRetry}`);
|
|
40909
41134
|
yield wait(3000);
|
|
40910
|
-
yield connectDeviceForBle(method, device);
|
|
41135
|
+
yield connectDeviceForBle(method, device, nextRetry);
|
|
40911
41136
|
}
|
|
40912
41137
|
else {
|
|
40913
41138
|
throw err;
|
|
@@ -40915,7 +41140,7 @@ function connectDeviceForBle(method, device) {
|
|
|
40915
41140
|
}
|
|
40916
41141
|
});
|
|
40917
41142
|
}
|
|
40918
|
-
const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41143
|
+
const ensureConnected = (_context, method, connectId, pollingId, abortSignal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40919
41144
|
let tryCount = 0;
|
|
40920
41145
|
const MAX_RETRY_COUNT = method.payload && typeof method.payload.retryCount === 'number' ? method.payload.retryCount : 5;
|
|
40921
41146
|
const POLL_INTERVAL_TIME = (method.payload && method.payload.pollIntervalTime) || 1000;
|
|
@@ -40924,7 +41149,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
|
|
|
40924
41149
|
Log.debug(`EnsureConnected function start, MAX_RETRY_COUNT=${MAX_RETRY_COUNT}, POLL_INTERVAL_TIME=${POLL_INTERVAL_TIME} `);
|
|
40925
41150
|
const poll = (time = POLL_INTERVAL_TIME) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40926
41151
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40927
|
-
var
|
|
41152
|
+
var _o;
|
|
40928
41153
|
const abort = () => {
|
|
40929
41154
|
if (abortSignal && abortSignal.aborted) {
|
|
40930
41155
|
if (timer) {
|
|
@@ -40938,7 +41163,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
|
|
|
40938
41163
|
if (abort()) {
|
|
40939
41164
|
return;
|
|
40940
41165
|
}
|
|
40941
|
-
if (!
|
|
41166
|
+
if (!pollingManager.isActive(connectId, pollingId)) {
|
|
40942
41167
|
Log.debug('EnsureConnected function stop, polling id: ', pollingId);
|
|
40943
41168
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PollingStop));
|
|
40944
41169
|
return;
|
|
@@ -40986,7 +41211,6 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
|
|
|
40986
41211
|
clearTimeout(timer);
|
|
40987
41212
|
}
|
|
40988
41213
|
if (DataManager.isBleConnect(env)) {
|
|
40989
|
-
bleTimeoutRetry = 0;
|
|
40990
41214
|
if (abort()) {
|
|
40991
41215
|
return;
|
|
40992
41216
|
}
|
|
@@ -41029,7 +41253,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
|
|
|
41029
41253
|
clearTimeout(timer);
|
|
41030
41254
|
}
|
|
41031
41255
|
Log.debug('EnsureConnected get to max try count, will return: ', tryCount);
|
|
41032
|
-
if (DataManager.isBrowserWebUsb(env) && !((
|
|
41256
|
+
if (DataManager.isBrowserWebUsb(env) && !((_o = method.payload) === null || _o === void 0 ? void 0 : _o.skipWebDevicePrompt)) {
|
|
41033
41257
|
postMessage(createUiMessage(UI_REQUEST.WEB_DEVICE_PROMPT_ACCESS_PERMISSION));
|
|
41034
41258
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission));
|
|
41035
41259
|
}
|
|
@@ -41044,7 +41268,6 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
|
|
|
41044
41268
|
return setTimeout(() => resolve(poll(time * 1.5)), time);
|
|
41045
41269
|
}));
|
|
41046
41270
|
});
|
|
41047
|
-
pollingState[pollingId] = true;
|
|
41048
41271
|
return poll();
|
|
41049
41272
|
});
|
|
41050
41273
|
const cancel = (context, connectId) => {
|
|
@@ -41140,6 +41363,7 @@ const onDeviceConnectHandler = (device) => {
|
|
|
41140
41363
|
postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject }));
|
|
41141
41364
|
};
|
|
41142
41365
|
const onDeviceDisconnectHandler = (device) => {
|
|
41366
|
+
device.clearPreInitialized();
|
|
41143
41367
|
const env = DataManager.getSettings('env');
|
|
41144
41368
|
const deviceObject = DataManager.isBleConnect(env) ? device : device.toMessageObject();
|
|
41145
41369
|
postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject }));
|
|
@@ -41253,7 +41477,7 @@ class Core extends events.exports {
|
|
|
41253
41477
|
registerCallbackTask: (connectId, callbackPromise) => {
|
|
41254
41478
|
this.requestQueue.registerPendingCallbackTask(connectId, callbackPromise);
|
|
41255
41479
|
},
|
|
41256
|
-
waitForCallbackTasks: (connectId) => this.requestQueue.waitForPendingCallbackTasks(connectId),
|
|
41480
|
+
waitForCallbackTasks: (connectId, exceptTask) => this.requestQueue.waitForPendingCallbackTasks(connectId, exceptTask),
|
|
41257
41481
|
cancelCallbackTasks: (connectId) => this.requestQueue.cancelCallbackTasks(connectId),
|
|
41258
41482
|
};
|
|
41259
41483
|
}
|
|
@@ -41283,10 +41507,10 @@ class Core extends events.exports {
|
|
|
41283
41507
|
break;
|
|
41284
41508
|
}
|
|
41285
41509
|
case IFRAME.CALL: {
|
|
41286
|
-
Log.log(
|
|
41510
|
+
Log.log(`[${Date.now()}][CALL_API]`, message);
|
|
41287
41511
|
const response = yield callAPI(this.getCoreContext(), message);
|
|
41288
41512
|
const { success, payload } = response;
|
|
41289
|
-
Log.log(
|
|
41513
|
+
Log.log(`[${Date.now()}][CALL_API_RESPONSE]`, response);
|
|
41290
41514
|
if (success) {
|
|
41291
41515
|
return response;
|
|
41292
41516
|
}
|
|
@@ -41309,6 +41533,9 @@ class Core extends events.exports {
|
|
|
41309
41533
|
dispose() {
|
|
41310
41534
|
_deviceList = undefined;
|
|
41311
41535
|
_connector = undefined;
|
|
41536
|
+
deviceCacheMap.clear();
|
|
41537
|
+
preWarmInflight.clear();
|
|
41538
|
+
preWarmDoneAt.clear();
|
|
41312
41539
|
Log.debug(`[Core] Disposing SDK instance: ${this.sdkInstanceId}`);
|
|
41313
41540
|
cleanupSdkInstance(this.sdkInstanceId);
|
|
41314
41541
|
}
|
|
@@ -41331,7 +41558,7 @@ const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0,
|
|
|
41331
41558
|
yield DataManager.load(settings);
|
|
41332
41559
|
initTransport(Transport, plugin);
|
|
41333
41560
|
}
|
|
41334
|
-
catch (
|
|
41561
|
+
catch (_p) {
|
|
41335
41562
|
Log.error('DataManager.load error');
|
|
41336
41563
|
}
|
|
41337
41564
|
enableLog(DataManager.getSettings('debug'));
|