@onekeyfe/hd-core 1.2.2-alpha.119 → 1.2.2-alpha.120
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__/AllNetworkGetAddressBase.tracing.test.ts +298 -8
- package/__tests__/core-error-output.test.ts +0 -77
- package/__tests__/device-lifecycle-events.test.ts +8 -8
- package/__tests__/search-devices.test.ts +8 -196
- package/dist/api/SearchDevices.d.ts +15 -2
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddress.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts +3 -0
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts +0 -2
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/index.js +88 -173
- package/package.json +4 -4
- package/src/api/SearchDevices.ts +27 -121
- package/src/api/allnetwork/AllNetworkGetAddress.ts +47 -20
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +32 -7
- package/src/core/index.ts +19 -58
- package/src/data-manager/TransportManager.ts +3 -14
- package/src/device/Device.ts +0 -7
package/dist/index.js
CHANGED
|
@@ -43705,18 +43705,6 @@ class TransportManager {
|
|
|
43705
43705
|
this.defaultMessages = DataManager.getProtobufMessages();
|
|
43706
43706
|
this.currentMessages = this.defaultMessages;
|
|
43707
43707
|
this.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
43708
|
-
this.webUsbInit = false;
|
|
43709
|
-
}
|
|
43710
|
-
static ensureInitialized() {
|
|
43711
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
43712
|
-
const env = DataManager.getSettings('env');
|
|
43713
|
-
if (env !== 'webusb' && env !== 'desktop-webusb')
|
|
43714
|
-
return;
|
|
43715
|
-
if (this.webUsbInit)
|
|
43716
|
-
return;
|
|
43717
|
-
yield this.transport.init(WebUsbLogger, DevicePool.emitter);
|
|
43718
|
-
this.webUsbInit = true;
|
|
43719
|
-
});
|
|
43720
43708
|
}
|
|
43721
43709
|
static configure() {
|
|
43722
43710
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -43745,7 +43733,7 @@ class TransportManager {
|
|
|
43745
43733
|
yield this.transport.init(WebBleLogger, DevicePool.emitter);
|
|
43746
43734
|
}
|
|
43747
43735
|
else if (env === 'webusb' || env === 'desktop-webusb') {
|
|
43748
|
-
yield this.
|
|
43736
|
+
yield this.transport.init(WebUsbLogger, DevicePool.emitter);
|
|
43749
43737
|
}
|
|
43750
43738
|
else {
|
|
43751
43739
|
yield this.transport.init(HttpLogger);
|
|
@@ -43828,7 +43816,6 @@ class TransportManager {
|
|
|
43828
43816
|
}
|
|
43829
43817
|
}
|
|
43830
43818
|
TransportManager.reactNativeInit = false;
|
|
43831
|
-
TransportManager.webUsbInit = false;
|
|
43832
43819
|
TransportManager.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
43833
43820
|
TransportManager.plugin = null;
|
|
43834
43821
|
|
|
@@ -46508,7 +46495,6 @@ class Device extends events.exports {
|
|
|
46508
46495
|
}
|
|
46509
46496
|
else if (!acquired) {
|
|
46510
46497
|
if (mainId && (deviceConnector === null || deviceConnector === void 0 ? void 0 : deviceConnector.disconnect)) {
|
|
46511
|
-
Log$h.debug('interruptionFromUser: disconnecting device without acquire, mainId:', mainId);
|
|
46512
46498
|
yield deviceConnector.disconnect(mainId);
|
|
46513
46499
|
}
|
|
46514
46500
|
if (this.connectionAttempt === attempt)
|
|
@@ -47277,48 +47263,6 @@ class PreInitialize extends BaseMethod {
|
|
|
47277
47263
|
}
|
|
47278
47264
|
|
|
47279
47265
|
const Log$e = getLogger(exports.LoggerNames.DevicePool);
|
|
47280
|
-
const getDescriptorKeys = (descriptor) => [descriptor.path, descriptor.id].filter((key) => typeof key === 'string' && key.length > 0);
|
|
47281
|
-
const isOwnedByActiveWebUsbRequest = (descriptor, requestQueue) => {
|
|
47282
|
-
if (!requestQueue)
|
|
47283
|
-
return false;
|
|
47284
|
-
return getDescriptorKeys(descriptor).some(key => requestQueue.getRequestTasksIdByConnectId(key).length > 0);
|
|
47285
|
-
};
|
|
47286
|
-
const getUsbHandle = (descriptor) => descriptor === null || descriptor === void 0 ? void 0 : descriptor.device;
|
|
47287
|
-
const getOwningRequestDevice = (descriptor, requestQueue) => {
|
|
47288
|
-
var _a, _b;
|
|
47289
|
-
if (!requestQueue)
|
|
47290
|
-
return undefined;
|
|
47291
|
-
const usbHandle = getUsbHandle(descriptor);
|
|
47292
|
-
if (usbHandle === undefined)
|
|
47293
|
-
return undefined;
|
|
47294
|
-
for (const key of getDescriptorKeys(descriptor)) {
|
|
47295
|
-
for (const requestId of requestQueue.getRequestTasksIdByConnectId(key)) {
|
|
47296
|
-
const device = (_a = requestQueue.getTask(requestId)) === null || _a === void 0 ? void 0 : _a.method.device;
|
|
47297
|
-
if ((device === null || device === void 0 ? void 0 : device.features) &&
|
|
47298
|
-
(device.mainId === key || ((_b = device.originalDescriptor) === null || _b === void 0 ? void 0 : _b.path) === key) &&
|
|
47299
|
-
getUsbHandle(device.originalDescriptor) === usbHandle) {
|
|
47300
|
-
return device;
|
|
47301
|
-
}
|
|
47302
|
-
}
|
|
47303
|
-
}
|
|
47304
|
-
return undefined;
|
|
47305
|
-
};
|
|
47306
|
-
const toSearchDeviceFromDescriptor = (descriptor) => {
|
|
47307
|
-
const connectId = descriptor.path || descriptor.id || null;
|
|
47308
|
-
return {
|
|
47309
|
-
connectId,
|
|
47310
|
-
uuid: '',
|
|
47311
|
-
serialNo: null,
|
|
47312
|
-
deviceId: null,
|
|
47313
|
-
deviceType: hdShared.EDeviceType.Unknown,
|
|
47314
|
-
name: descriptor.name || connectId || '',
|
|
47315
|
-
commType: descriptor.commType,
|
|
47316
|
-
};
|
|
47317
|
-
};
|
|
47318
|
-
const toSearchDevice = (device) => {
|
|
47319
|
-
const message = device.toMessageObject();
|
|
47320
|
-
return message ? message : null;
|
|
47321
|
-
};
|
|
47322
47266
|
class SearchDevices extends BaseMethod {
|
|
47323
47267
|
init() {
|
|
47324
47268
|
this.useDevice = false;
|
|
@@ -47326,32 +47270,20 @@ class SearchDevices extends BaseMethod {
|
|
|
47326
47270
|
this.skipForceUpdateCheck = true;
|
|
47327
47271
|
}
|
|
47328
47272
|
run() {
|
|
47329
|
-
var _a, _b, _c, _d, _e
|
|
47273
|
+
var _a, _b, _c, _d, _e;
|
|
47330
47274
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47275
|
+
yield TransportManager.configure();
|
|
47276
|
+
const deviceDiff = yield ((_a = this.connector) === null || _a === void 0 ? void 0 : _a.enumerate());
|
|
47277
|
+
const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
|
|
47331
47278
|
const env = DataManager.getSettings('env');
|
|
47332
|
-
const isWebUsb = env === 'webusb' || env === 'desktop-webusb';
|
|
47333
|
-
const requestQueue = (_a = this.context) === null || _a === void 0 ? void 0 : _a.requestQueue;
|
|
47334
|
-
const hasActiveWebUsbRequest = isWebUsb && ((_b = requestQueue === null || requestQueue === void 0 ? void 0 : requestQueue.getRequestTasksId().length) !== null && _b !== void 0 ? _b : 0) > 0;
|
|
47335
|
-
if (isWebUsb) {
|
|
47336
|
-
try {
|
|
47337
|
-
yield TransportManager.ensureInitialized();
|
|
47338
|
-
}
|
|
47339
|
-
catch (error) {
|
|
47340
|
-
Log$e.debug('WebUSB bring-up unavailable', error);
|
|
47341
|
-
}
|
|
47342
|
-
}
|
|
47343
|
-
if (!hasActiveWebUsbRequest)
|
|
47344
|
-
yield TransportManager.configure();
|
|
47345
|
-
const deviceDiff = yield ((_c = this.connector) === null || _c === void 0 ? void 0 : _c.enumerate());
|
|
47346
|
-
const devicesDescriptor = (_d = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _d !== void 0 ? _d : [];
|
|
47347
47279
|
if (DataManager.isBleConnect(env)) {
|
|
47348
47280
|
const devices = [];
|
|
47349
47281
|
const seenIds = new Set();
|
|
47350
47282
|
for (const device of devicesDescriptor) {
|
|
47351
|
-
const lowerId = (
|
|
47283
|
+
const lowerId = (_c = device.id) === null || _c === void 0 ? void 0 : _c.toLowerCase();
|
|
47352
47284
|
if (!seenIds.has(lowerId)) {
|
|
47353
47285
|
seenIds.add(lowerId);
|
|
47354
|
-
const rawBleName = (
|
|
47286
|
+
const rawBleName = (_e = (_d = device.name) !== null && _d !== void 0 ? _d : device.localName) !== null && _e !== void 0 ? _e : '';
|
|
47355
47287
|
const bleName = hdShared.canonicalizePro2BleAdvertisementName(rawBleName);
|
|
47356
47288
|
devices.push(Object.assign(Object.assign({}, device), { connectId: device.id, serialNo: null, uuid: '', deviceId: null, name: bleName || device.name, deviceType: getDeviceTypeByBleName(bleName) }));
|
|
47357
47289
|
}
|
|
@@ -47360,34 +47292,22 @@ class SearchDevices extends BaseMethod {
|
|
|
47360
47292
|
}
|
|
47361
47293
|
const deviceList = [];
|
|
47362
47294
|
for (const descriptor of devicesDescriptor) {
|
|
47363
|
-
|
|
47364
|
-
const
|
|
47365
|
-
|
|
47366
|
-
|
|
47367
|
-
|
|
47295
|
+
try {
|
|
47296
|
+
const result = yield DevicePool.getDevices([descriptor], descriptor.path, {
|
|
47297
|
+
connectProtocol: undefined,
|
|
47298
|
+
forceProtocolDetection: true,
|
|
47299
|
+
refreshRuntimeState: true,
|
|
47300
|
+
});
|
|
47301
|
+
deviceList.push(...result.deviceList);
|
|
47368
47302
|
}
|
|
47369
|
-
|
|
47370
|
-
|
|
47371
|
-
|
|
47372
|
-
|
|
47373
|
-
|
|
47374
|
-
refreshRuntimeState: true,
|
|
47375
|
-
});
|
|
47376
|
-
for (const device of result.deviceList) {
|
|
47377
|
-
const message = toSearchDevice(device);
|
|
47378
|
-
if (message)
|
|
47379
|
-
deviceList.push(message);
|
|
47380
|
-
}
|
|
47381
|
-
}
|
|
47382
|
-
catch (error) {
|
|
47383
|
-
const errorCode = error && typeof error === 'object' && 'errorCode' in error
|
|
47384
|
-
? error.errorCode
|
|
47385
|
-
: undefined;
|
|
47386
|
-
Log$e.debug('Skip unavailable device during search', Object.assign({ path: descriptor.path }, (errorCode !== undefined ? { errorCode } : {})));
|
|
47387
|
-
}
|
|
47303
|
+
catch (error) {
|
|
47304
|
+
const errorCode = error && typeof error === 'object' && 'errorCode' in error
|
|
47305
|
+
? error.errorCode
|
|
47306
|
+
: undefined;
|
|
47307
|
+
Log$e.debug('Skip unavailable device during search', Object.assign({ path: descriptor.path }, (errorCode !== undefined ? { errorCode } : {})));
|
|
47388
47308
|
}
|
|
47389
47309
|
}
|
|
47390
|
-
return deviceList;
|
|
47310
|
+
return deviceList.map(device => device.toMessageObject());
|
|
47391
47311
|
});
|
|
47392
47312
|
}
|
|
47393
47313
|
}
|
|
@@ -55995,6 +55915,7 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
55995
55915
|
super(...arguments);
|
|
55996
55916
|
this.abortController = null;
|
|
55997
55917
|
this.loadingCleanupInBackground = false;
|
|
55918
|
+
this.protocolV2ResumedSeedDomains = new Set();
|
|
55998
55919
|
}
|
|
55999
55920
|
getSupportedProtocols() {
|
|
56000
55921
|
return ['V1', 'V2'];
|
|
@@ -56030,6 +55951,19 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
56030
55951
|
_originalIndex: originalIndex,
|
|
56031
55952
|
};
|
|
56032
55953
|
}
|
|
55954
|
+
hasProtocolV2WalletResume(deriveCardano) {
|
|
55955
|
+
if (deriveCardano) {
|
|
55956
|
+
return this.protocolV2ResumedSeedDomains.has('cardano');
|
|
55957
|
+
}
|
|
55958
|
+
return (this.protocolV2ResumedSeedDomains.has('standard') ||
|
|
55959
|
+
this.protocolV2ResumedSeedDomains.has('cardano'));
|
|
55960
|
+
}
|
|
55961
|
+
markProtocolV2WalletResumed(deriveCardano) {
|
|
55962
|
+
this.protocolV2ResumedSeedDomains.add('standard');
|
|
55963
|
+
if (deriveCardano) {
|
|
55964
|
+
this.protocolV2ResumedSeedDomains.add('cardano');
|
|
55965
|
+
}
|
|
55966
|
+
}
|
|
56033
55967
|
callMethod(methodName, params, rootFingerprint) {
|
|
56034
55968
|
var _a, _b, _c;
|
|
56035
55969
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -56092,11 +56026,14 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
56092
56026
|
const useEmptyPassphrase = this.payload.useEmptyPassphrase === true;
|
|
56093
56027
|
const deriveCardano = method.name.startsWith('cardano') ? true : undefined;
|
|
56094
56028
|
const shouldResumeWalletSession = useEmptyPassphrase || !!this.payload.passphraseState;
|
|
56095
|
-
if (this.device.isProtocolV2() &&
|
|
56029
|
+
if (this.device.isProtocolV2() &&
|
|
56030
|
+
shouldResumeWalletSession &&
|
|
56031
|
+
!this.hasProtocolV2WalletResume(deriveCardano)) {
|
|
56096
56032
|
const passphraseStateSafety = yield this.device.checkPassphraseStateSafety(this.payload.passphraseState, useEmptyPassphrase, this.payload.skipPassphraseCheck, deriveCardano, (_d = this.protocolV2UnlockContext) === null || _d === void 0 ? void 0 : _d.preflightMainPinSelected);
|
|
56097
56033
|
if (!passphraseStateSafety) {
|
|
56098
56034
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
56099
56035
|
}
|
|
56036
|
+
this.markProtocolV2WalletResumed(deriveCardano);
|
|
56100
56037
|
}
|
|
56101
56038
|
}),
|
|
56102
56039
|
});
|
|
@@ -56248,7 +56185,7 @@ function handleSkippableHardwareError(e, device, method) {
|
|
|
56248
56185
|
|
|
56249
56186
|
class AllNetworkGetAddress extends AllNetworkGetAddressBase {
|
|
56250
56187
|
getAllNetworkAddress(rootFingerprint) {
|
|
56251
|
-
var _a, _b, _c
|
|
56188
|
+
var _a, _b, _c;
|
|
56252
56189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56253
56190
|
const responses = [];
|
|
56254
56191
|
const resultMap = {};
|
|
@@ -56258,40 +56195,53 @@ class AllNetworkGetAddress extends AllNetworkGetAddressBase {
|
|
|
56258
56195
|
payload: param,
|
|
56259
56196
|
originalIndex: index,
|
|
56260
56197
|
}));
|
|
56261
|
-
const
|
|
56198
|
+
const methodGroups = methodParams.reduce((groups, param) => {
|
|
56262
56199
|
var _a;
|
|
56263
56200
|
const group = (_a = groups.get(param.methodName)) !== null && _a !== void 0 ? _a : [];
|
|
56264
56201
|
group.push(param);
|
|
56265
56202
|
groups.set(param.methodName, group);
|
|
56266
56203
|
return groups;
|
|
56267
56204
|
}, new Map());
|
|
56268
|
-
|
|
56269
|
-
|
|
56270
|
-
|
|
56271
|
-
? methodParams.map(param => [param.methodName, [param]])
|
|
56272
|
-
: Array.from(groupedMethodParams.entries());
|
|
56273
|
-
let i = 0;
|
|
56274
|
-
for (const [methodName, params] of methodGroups) {
|
|
56275
|
-
const methodParams = {
|
|
56205
|
+
let processed = 0;
|
|
56206
|
+
for (const [methodName, params] of methodGroups.entries()) {
|
|
56207
|
+
const methodCallParams = {
|
|
56276
56208
|
bundle: params.map(param => (Object.assign({}, param.params))),
|
|
56277
56209
|
};
|
|
56278
56210
|
if ((_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
|
|
56279
56211
|
throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
|
|
56280
56212
|
}
|
|
56281
|
-
const
|
|
56282
|
-
|
|
56213
|
+
const isProtocolV2 = this.device.isProtocolV2();
|
|
56214
|
+
const runIndividually = isProtocolV2 &&
|
|
56215
|
+
params.length > 1 &&
|
|
56216
|
+
params.some(param => param._originRequestParams.showOnOneKey !== false);
|
|
56217
|
+
let response = [];
|
|
56218
|
+
if (!runIndividually) {
|
|
56219
|
+
response = yield this.callMethod(methodName, methodCallParams, rootFingerprint);
|
|
56220
|
+
}
|
|
56221
|
+
if (isProtocolV2 &&
|
|
56222
|
+
params.length > 1 &&
|
|
56223
|
+
(runIndividually || response.every(item => !item.success))) {
|
|
56224
|
+
response = [];
|
|
56225
|
+
for (const param of params) {
|
|
56226
|
+
if ((_b = this.abortController) === null || _b === void 0 ? void 0 : _b.signal.aborted) {
|
|
56227
|
+
throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
|
|
56228
|
+
}
|
|
56229
|
+
const itemResponse = yield this.callMethod(methodName, { bundle: [Object.assign({}, param.params)] }, rootFingerprint);
|
|
56230
|
+
response.push(...itemResponse);
|
|
56231
|
+
}
|
|
56232
|
+
}
|
|
56233
|
+
if ((_c = this.abortController) === null || _c === void 0 ? void 0 : _c.signal.aborted) {
|
|
56283
56234
|
throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
|
|
56284
56235
|
}
|
|
56285
|
-
for (let
|
|
56286
|
-
const { _originRequestParams, _originalIndex } = params[
|
|
56287
|
-
|
|
56288
|
-
resultMap[responseKey] = Object.assign(Object.assign({}, _originRequestParams), response[i]);
|
|
56236
|
+
for (let index = 0; index < params.length; index++) {
|
|
56237
|
+
const { _originRequestParams, _originalIndex } = params[index];
|
|
56238
|
+
resultMap[`${_originalIndex}`] = Object.assign(Object.assign({}, _originRequestParams), response[index]);
|
|
56289
56239
|
}
|
|
56290
|
-
|
|
56291
|
-
|
|
56240
|
+
processed += params.length;
|
|
56241
|
+
if (bundle.length > 1) {
|
|
56242
|
+
const progress = Math.round((processed / bundle.length) * 100);
|
|
56292
56243
|
this.postMessage(createUiMessage(UI_REQUEST.DEVICE_PROGRESS, { progress }));
|
|
56293
56244
|
}
|
|
56294
|
-
i++;
|
|
56295
56245
|
}
|
|
56296
56246
|
for (let i = 0; i < bundle.length; i++) {
|
|
56297
56247
|
responses.push(resultMap[i]);
|
|
@@ -65930,7 +65880,7 @@ const createUiProgressMessageFilter = (intervalMs = DEFAULT_UI_PROGRESS_INTERVAL
|
|
|
65930
65880
|
|
|
65931
65881
|
const Log = getLogger(exports.LoggerNames.Core);
|
|
65932
65882
|
const PRE_INITIALIZE_TTL_MS = 60 * 1000;
|
|
65933
|
-
const PRE_PENDING_CALL_TIMEOUT_MS =
|
|
65883
|
+
const PRE_PENDING_CALL_TIMEOUT_MS = 15 * 1000;
|
|
65934
65884
|
const PRO2_USB_SIGNING_COOLDOWN_MS = 1000;
|
|
65935
65885
|
const preWarmInflight = new Map();
|
|
65936
65886
|
const preWarmDoneAt = new Map();
|
|
@@ -66010,7 +65960,6 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
|
|
|
66010
65960
|
}
|
|
66011
65961
|
};
|
|
66012
65962
|
(_a = method.setContext) === null || _a === void 0 ? void 0 : _a.call(method, context);
|
|
66013
|
-
method.context = context;
|
|
66014
65963
|
method.requestContext = createRequestContext(method.responseID, method.name, {
|
|
66015
65964
|
sdkInstanceId: context.sdkInstanceId,
|
|
66016
65965
|
connectId: method.connectId,
|
|
@@ -66028,11 +65977,7 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
|
|
|
66028
65977
|
if (!method.useDevice) {
|
|
66029
65978
|
updateMethodRequestContext(method, { status: 'running' });
|
|
66030
65979
|
try {
|
|
66031
|
-
const
|
|
66032
|
-
const response = method.name === 'searchDevices' &&
|
|
66033
|
-
(DataManager.isBrowserWebUsb(env) || DataManager.isDesktopWebUsb(env))
|
|
66034
|
-
? yield context.methodSynchronize(() => method.run(), 'webusb-discovery')
|
|
66035
|
-
: yield method.run();
|
|
65980
|
+
const response = yield method.run();
|
|
66036
65981
|
completeMethodRequestContext(method);
|
|
66037
65982
|
return createResponseMessage(method.responseID, true, response);
|
|
66038
65983
|
}
|
|
@@ -66103,28 +66048,20 @@ const waitForPendingPromise = (connectId, getPrePendingCallPromise, removePrePen
|
|
|
66103
66048
|
if (pendingPromise) {
|
|
66104
66049
|
Log.debug('pre pending call promise before call method, wait for it');
|
|
66105
66050
|
let timer;
|
|
66106
|
-
let timedOut = false;
|
|
66107
|
-
let completed = false;
|
|
66108
66051
|
try {
|
|
66109
66052
|
yield Promise.race([
|
|
66110
66053
|
pendingPromise,
|
|
66111
|
-
new Promise(
|
|
66054
|
+
new Promise((_, reject) => {
|
|
66112
66055
|
timer = setTimeout(() => {
|
|
66113
|
-
|
|
66114
|
-
resolve();
|
|
66056
|
+
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceBusy, 'Previous device cancellation is still draining'));
|
|
66115
66057
|
}, PRE_PENDING_CALL_TIMEOUT_MS);
|
|
66116
66058
|
}),
|
|
66117
66059
|
]);
|
|
66118
|
-
|
|
66060
|
+
removePrePendingCallPromise === null || removePrePendingCallPromise === void 0 ? void 0 : removePrePendingCallPromise(connectId, pendingPromise);
|
|
66119
66061
|
}
|
|
66120
66062
|
finally {
|
|
66121
66063
|
if (timer)
|
|
66122
66064
|
clearTimeout(timer);
|
|
66123
|
-
if (timedOut || completed)
|
|
66124
|
-
removePrePendingCallPromise === null || removePrePendingCallPromise === void 0 ? void 0 : removePrePendingCallPromise(connectId, pendingPromise);
|
|
66125
|
-
}
|
|
66126
|
-
if (timedOut) {
|
|
66127
|
-
Log.warn('pre pending call promise timed out before call method', { connectId });
|
|
66128
66065
|
}
|
|
66129
66066
|
Log.debug('pre pending call promise before call method done');
|
|
66130
66067
|
}
|
|
@@ -66172,22 +66109,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
66172
66109
|
context.registerCallbackTask(method.connectId, preWarmCallbackTask);
|
|
66173
66110
|
}
|
|
66174
66111
|
const pollingId = pollingManager.start(connectId);
|
|
66175
|
-
|
|
66176
|
-
const connect = () => ensureConnected(context, method, connectId, pollingId, method.abortSignal);
|
|
66177
|
-
if (DataManager.isBrowserWebUsb(env) || DataManager.isDesktopWebUsb(env)) {
|
|
66178
|
-
const connectPromise = context.methodSynchronize(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
66179
|
-
var _k;
|
|
66180
|
-
if ((_k = method.abortSignal) === null || _k === void 0 ? void 0 : _k.aborted) {
|
|
66181
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
|
|
66182
|
-
}
|
|
66183
|
-
return connect();
|
|
66184
|
-
}), 'webusb-discovery');
|
|
66185
|
-
connectPromise.catch(() => undefined);
|
|
66186
|
-
device = yield requestQueue.waitForTask(task, () => connectPromise);
|
|
66187
|
-
}
|
|
66188
|
-
else {
|
|
66189
|
-
device = yield connect();
|
|
66190
|
-
}
|
|
66112
|
+
device = yield ensureConnected(context, method, connectId, pollingId, method.abortSignal);
|
|
66191
66113
|
if ((_e = method.abortSignal) === null || _e === void 0 ? void 0 : _e.aborted) {
|
|
66192
66114
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
|
|
66193
66115
|
}
|
|
@@ -66252,12 +66174,12 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
66252
66174
|
return waitForPendingPromise((_a = method.connectId) !== null && _a !== void 0 ? _a : '', getPrePendingCallPromise, removePrePendingCallPromise);
|
|
66253
66175
|
});
|
|
66254
66176
|
const inner = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
66255
|
-
var
|
|
66177
|
+
var _k, _l;
|
|
66256
66178
|
method.assertProtocolSupported(device.getProtocol(), device.getCurrentFirmwareType());
|
|
66257
66179
|
protocolV2Operation = device.isProtocolV2();
|
|
66258
66180
|
const versionRange = device.getCurrentMethodVersionRange(type => method.getVersionRange()[type]);
|
|
66259
|
-
const currentFirmwareVersion = (
|
|
66260
|
-
const currentBleVersion = (
|
|
66181
|
+
const currentFirmwareVersion = (_k = device.getCurrentFirmwareVersionString()) !== null && _k !== void 0 ? _k : '0.0.0';
|
|
66182
|
+
const currentBleVersion = (_l = device.getCurrentBLEFirmwareVersionString()) !== null && _l !== void 0 ? _l : '0.0.0';
|
|
66261
66183
|
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
66262
66184
|
let newVersionStatus;
|
|
66263
66185
|
if (device.features && !device.isProtocolV2()) {
|
|
@@ -66335,7 +66257,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
66335
66257
|
}
|
|
66336
66258
|
},
|
|
66337
66259
|
prepare: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
66338
|
-
var _o, _p, _q, _r, _s
|
|
66260
|
+
var _m, _o, _p, _q, _r, _s;
|
|
66339
66261
|
if (method.deviceId && method.checkDeviceId && !deviceIdCheckedDuringUnlockPreflight) {
|
|
66340
66262
|
const isSameDeviceID = yield checkLiveDeviceId(device, method.deviceId);
|
|
66341
66263
|
if (!isSameDeviceID) {
|
|
@@ -66355,7 +66277,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
66355
66277
|
require: support.require,
|
|
66356
66278
|
});
|
|
66357
66279
|
}
|
|
66358
|
-
const passphraseStateSafety = yield device.checkPassphraseStateSafety((
|
|
66280
|
+
const passphraseStateSafety = yield device.checkPassphraseStateSafety((_m = method.payload) === null || _m === void 0 ? void 0 : _m.passphraseState, (_o = method.payload) === null || _o === void 0 ? void 0 : _o.useEmptyPassphrase, (_p = method.payload) === null || _p === void 0 ? void 0 : _p.skipPassphraseCheck, resolveDeriveCardano(method), (_q = method.protocolV2UnlockContext) === null || _q === void 0 ? void 0 : _q.preflightMainPinSelected);
|
|
66359
66281
|
checkPassphraseEnableState(method, device.features);
|
|
66360
66282
|
if (!passphraseStateSafety) {
|
|
66361
66283
|
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
@@ -66373,7 +66295,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
66373
66295
|
? e
|
|
66374
66296
|
: hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
|
|
66375
66297
|
}
|
|
66376
|
-
(
|
|
66298
|
+
(_s = (_r = method.device) === null || _r === void 0 ? void 0 : _r.commands) === null || _s === void 0 ? void 0 : _s.checkDisposed();
|
|
66377
66299
|
}),
|
|
66378
66300
|
});
|
|
66379
66301
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
@@ -66728,11 +66650,10 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66728
66650
|
const POLL_INTERVAL_TIME = (method.payload && method.payload.pollIntervalTime) || 1000;
|
|
66729
66651
|
const TIME_OUT = (method.payload && method.payload.timeout) || 10000;
|
|
66730
66652
|
let timer = null;
|
|
66731
|
-
let lastInitializeError;
|
|
66732
66653
|
Log.debug(`EnsureConnected function start, MAX_RETRY_COUNT=${MAX_RETRY_COUNT}, POLL_INTERVAL_TIME=${POLL_INTERVAL_TIME} `);
|
|
66733
66654
|
const poll = (time = POLL_INTERVAL_TIME) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66734
66655
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66735
|
-
var
|
|
66656
|
+
var _t;
|
|
66736
66657
|
const abort = () => {
|
|
66737
66658
|
if (abortSignal && abortSignal.aborted) {
|
|
66738
66659
|
if (timer) {
|
|
@@ -66761,10 +66682,8 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66761
66682
|
Log.debug('EnsureConnected function try count: ', tryCount, ' poll interval time: ', time);
|
|
66762
66683
|
try {
|
|
66763
66684
|
yield initDeviceList(method);
|
|
66764
|
-
lastInitializeError = undefined;
|
|
66765
66685
|
}
|
|
66766
66686
|
catch (error) {
|
|
66767
|
-
lastInitializeError = error;
|
|
66768
66687
|
Log.debug('device list error: ', error);
|
|
66769
66688
|
if ([
|
|
66770
66689
|
hdShared.HardwareErrorCode.BridgeNotInstalled,
|
|
@@ -66777,7 +66696,6 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66777
66696
|
}
|
|
66778
66697
|
if (error.errorCode === hdShared.HardwareErrorCode.TransportNotConfigured) {
|
|
66779
66698
|
yield TransportManager.configure();
|
|
66780
|
-
lastInitializeError = undefined;
|
|
66781
66699
|
}
|
|
66782
66700
|
}
|
|
66783
66701
|
if (abort()) {
|
|
@@ -66860,16 +66778,13 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66860
66778
|
clearTimeout(timer);
|
|
66861
66779
|
}
|
|
66862
66780
|
Log.debug('EnsureConnected get to max try count, will return: ', tryCount);
|
|
66863
|
-
|
|
66864
|
-
const needsPermissionPrompt = DataManager.isBrowserWebUsb(env) && !((_u = method.payload) === null || _u === void 0 ? void 0 : _u.skipWebDevicePrompt);
|
|
66865
|
-
const fallbackError = needsPermissionPrompt
|
|
66866
|
-
? hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission)
|
|
66867
|
-
: hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
|
|
66868
|
-
const errorToReject = preserveWebUsbInitError && lastInitializeError ? lastInitializeError : fallbackError;
|
|
66869
|
-
if (needsPermissionPrompt && errorToReject === fallbackError) {
|
|
66781
|
+
if (DataManager.isBrowserWebUsb(env) && !((_t = method.payload) === null || _t === void 0 ? void 0 : _t.skipWebDevicePrompt)) {
|
|
66870
66782
|
postMessage(createUiMessage(UI_REQUEST.WEB_DEVICE_PROMPT_ACCESS_PERMISSION));
|
|
66783
|
+
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission));
|
|
66784
|
+
}
|
|
66785
|
+
else {
|
|
66786
|
+
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound));
|
|
66871
66787
|
}
|
|
66872
|
-
reject(errorToReject);
|
|
66873
66788
|
return;
|
|
66874
66789
|
}
|
|
66875
66790
|
if (abort()) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.2-alpha.
|
|
3
|
+
"version": "1.2.2-alpha.120",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.2-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.2-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.2-alpha.120",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.2-alpha.120",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"buffer": "^6.0.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/w3c-web-usb": "^1.0.10",
|
|
47
47
|
"@types/web-bluetooth": "^0.0.21"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "26958fa2be6aa34a07f42403fb7022d2785e70b9"
|
|
50
50
|
}
|