@onekeyfe/hd-web-sdk 0.0.10 → 0.1.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/build/iframe.html +1 -1
- package/build/js/iframe.435f82a3bee253ffd1d3.js +3 -0
- package/build/js/{iframe.1a13e0dba05bc9240b0d.js.LICENSE.txt → iframe.435f82a3bee253ffd1d3.js.LICENSE.txt} +0 -0
- package/build/js/iframe.435f82a3bee253ffd1d3.js.map +1 -0
- package/build/onekey-js-sdk.js +379 -54
- package/build/onekey-js-sdk.js.map +1 -1
- package/build/onekey-js-sdk.min.js +1 -1
- package/build/onekey-js-sdk.min.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/index.ts +3 -1
- package/webpack/webpack.config.ts +5 -0
- package/build/js/iframe.1a13e0dba05bc9240b0d.js +0 -3
- package/build/js/iframe.1a13e0dba05bc9240b0d.js.map +0 -1
package/build/onekey-js-sdk.js
CHANGED
|
@@ -4215,6 +4215,10 @@ const inject = ({
|
|
|
4215
4215
|
stellarSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4216
4216
|
connectId,
|
|
4217
4217
|
method: 'stellarSignTransaction'
|
|
4218
|
+
})),
|
|
4219
|
+
firmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4220
|
+
connectId,
|
|
4221
|
+
method: 'firmwareUpdate'
|
|
4218
4222
|
}))
|
|
4219
4223
|
};
|
|
4220
4224
|
return api;
|
|
@@ -4772,11 +4776,13 @@ const ERROR_CODES = {
|
|
|
4772
4776
|
Method_InvalidParameter: '',
|
|
4773
4777
|
Call_API: '',
|
|
4774
4778
|
Call_NotResponse: 'No response data',
|
|
4779
|
+
Method_FirmwareUpdate_DownloadFailed: '',
|
|
4775
4780
|
Transport_InvalidProtobuf: '',
|
|
4776
4781
|
Device_FwException: '',
|
|
4777
4782
|
Device_UnexpectedMode: '',
|
|
4778
4783
|
Device_CallInProgress: '',
|
|
4779
4784
|
Device_InitializeFailed: '',
|
|
4785
|
+
Device_Interrupted: 'The device is performing other operations',
|
|
4780
4786
|
Not_Use_Onekey_Device: 'Please use onekey device',
|
|
4781
4787
|
Runtime: '',
|
|
4782
4788
|
Init_NotInitialized: 'Init_NotInitialized',
|
|
@@ -4828,7 +4834,7 @@ const colors = {
|
|
|
4828
4834
|
};
|
|
4829
4835
|
const MAX_ENTRIES = 100;
|
|
4830
4836
|
|
|
4831
|
-
class Log$
|
|
4837
|
+
class Log$6 {
|
|
4832
4838
|
constructor(prefix, enabled) {
|
|
4833
4839
|
this.prefix = prefix;
|
|
4834
4840
|
this.enabled = enabled;
|
|
@@ -4890,7 +4896,7 @@ class Log$5 {
|
|
|
4890
4896
|
const _logs = {};
|
|
4891
4897
|
|
|
4892
4898
|
const initLog = (prefix, enabled) => {
|
|
4893
|
-
const instance = new Log$
|
|
4899
|
+
const instance = new Log$6(prefix, !!enabled);
|
|
4894
4900
|
_logs[prefix] = instance;
|
|
4895
4901
|
return instance;
|
|
4896
4902
|
};
|
|
@@ -4904,7 +4910,8 @@ const enableLog = enabled => {
|
|
|
4904
4910
|
const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0, function* () {
|
|
4905
4911
|
const response = yield axios__default["default"].request({
|
|
4906
4912
|
url,
|
|
4907
|
-
withCredentials: false
|
|
4913
|
+
withCredentials: false,
|
|
4914
|
+
responseType: type === 'binary' ? 'arraybuffer' : 'json'
|
|
4908
4915
|
});
|
|
4909
4916
|
|
|
4910
4917
|
if (+response.status === 200) {
|
|
@@ -4913,7 +4920,7 @@ const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0,
|
|
|
4913
4920
|
}
|
|
4914
4921
|
|
|
4915
4922
|
if (type === 'binary') {
|
|
4916
|
-
return response.data
|
|
4923
|
+
return response.data;
|
|
4917
4924
|
}
|
|
4918
4925
|
|
|
4919
4926
|
return response.data;
|
|
@@ -4922,7 +4929,7 @@ const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0,
|
|
|
4922
4929
|
throw new Error(`httpRequest error: ${url} ${response.statusText}`);
|
|
4923
4930
|
});
|
|
4924
4931
|
|
|
4925
|
-
const httpRequest = (url,
|
|
4932
|
+
const httpRequest = (url, type) => httpRequest$1(url, type);
|
|
4926
4933
|
|
|
4927
4934
|
const getTimeStamp = () => new Date().getTime();
|
|
4928
4935
|
|
|
@@ -13896,6 +13903,25 @@ var MessagesJSON = {
|
|
|
13896
13903
|
nested: nested
|
|
13897
13904
|
};
|
|
13898
13905
|
|
|
13906
|
+
const getReleaseStatus = (releases, currentVersion) => {
|
|
13907
|
+
const newVersions = releases.filter(r => semver__default["default"].gt(r.version.join('.'), currentVersion));
|
|
13908
|
+
|
|
13909
|
+
if (newVersions.length === 0) {
|
|
13910
|
+
return 'valid';
|
|
13911
|
+
}
|
|
13912
|
+
|
|
13913
|
+
if (newVersions.some(r => r.required)) {
|
|
13914
|
+
return 'required';
|
|
13915
|
+
}
|
|
13916
|
+
|
|
13917
|
+
return 'outdated';
|
|
13918
|
+
};
|
|
13919
|
+
|
|
13920
|
+
const getReleaseChangelog = (releases, currentVersion) => {
|
|
13921
|
+
const newVersions = releases.filter(r => semver__default["default"].gt(r.version.join('.'), currentVersion));
|
|
13922
|
+
return newVersions.map(r => r.changelog);
|
|
13923
|
+
};
|
|
13924
|
+
|
|
13899
13925
|
var _a;
|
|
13900
13926
|
|
|
13901
13927
|
class DataManager {
|
|
@@ -13975,17 +14001,31 @@ DataManager.getFirmwareStatus = features => {
|
|
|
13975
14001
|
}
|
|
13976
14002
|
|
|
13977
14003
|
const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.firmware) !== null && _c !== void 0 ? _c : [];
|
|
13978
|
-
const latestFirmware = targetDeviceConfigList[targetDeviceConfigList.length - 1];
|
|
13979
|
-
if (!latestFirmware) return 'valid';
|
|
13980
|
-
const latestVersion = latestFirmware.version.join('.');
|
|
13981
14004
|
const currentVersion = deviceFirmwareVersion.join('.');
|
|
14005
|
+
return getReleaseStatus(targetDeviceConfigList, currentVersion);
|
|
14006
|
+
};
|
|
14007
|
+
|
|
14008
|
+
DataManager.getFirmwareChangelog = features => {
|
|
14009
|
+
var _b, _c;
|
|
14010
|
+
|
|
14011
|
+
const deviceType = getDeviceType(features);
|
|
14012
|
+
const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
|
|
13982
14013
|
|
|
13983
|
-
if (
|
|
13984
|
-
|
|
13985
|
-
return 'outdated';
|
|
14014
|
+
if (features.firmware_present === false || deviceType === 'classic' && features.bootloader_mode) {
|
|
14015
|
+
return [];
|
|
13986
14016
|
}
|
|
13987
14017
|
|
|
13988
|
-
|
|
14018
|
+
const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.firmware) !== null && _c !== void 0 ? _c : [];
|
|
14019
|
+
const currentVersion = deviceFirmwareVersion.join('.');
|
|
14020
|
+
return getReleaseChangelog(targetDeviceConfigList, currentVersion);
|
|
14021
|
+
};
|
|
14022
|
+
|
|
14023
|
+
DataManager.getFirmwareLeatestRelease = features => {
|
|
14024
|
+
var _b, _c;
|
|
14025
|
+
|
|
14026
|
+
const deviceType = getDeviceType(features);
|
|
14027
|
+
const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.firmware) !== null && _c !== void 0 ? _c : [];
|
|
14028
|
+
return targetDeviceConfigList[targetDeviceConfigList.length - 1];
|
|
13989
14029
|
};
|
|
13990
14030
|
|
|
13991
14031
|
DataManager.getBLEFirmwareStatus = features => {
|
|
@@ -13999,17 +14039,31 @@ DataManager.getBLEFirmwareStatus = features => {
|
|
|
13999
14039
|
}
|
|
14000
14040
|
|
|
14001
14041
|
const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.ble) !== null && _c !== void 0 ? _c : [];
|
|
14002
|
-
const latestBLEFirmware = targetDeviceConfigList[targetDeviceConfigList.length - 1];
|
|
14003
|
-
if (!latestBLEFirmware) return 'valid';
|
|
14004
|
-
const latestVersion = latestBLEFirmware.version.join('.');
|
|
14005
14042
|
const currentVersion = deviceBLEFirmwareVersion.join('.');
|
|
14043
|
+
return getReleaseStatus(targetDeviceConfigList, currentVersion);
|
|
14044
|
+
};
|
|
14045
|
+
|
|
14046
|
+
DataManager.getBleFirmwareChangelog = features => {
|
|
14047
|
+
var _b, _c;
|
|
14006
14048
|
|
|
14007
|
-
|
|
14008
|
-
|
|
14009
|
-
|
|
14049
|
+
const deviceType = getDeviceType(features);
|
|
14050
|
+
const deviceBLEFirmwareVersion = getDeviceBLEFirmwareVersion(features);
|
|
14051
|
+
|
|
14052
|
+
if (!deviceBLEFirmwareVersion) {
|
|
14053
|
+
return [];
|
|
14010
14054
|
}
|
|
14011
14055
|
|
|
14012
|
-
|
|
14056
|
+
const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.ble) !== null && _c !== void 0 ? _c : [];
|
|
14057
|
+
const currentVersion = deviceBLEFirmwareVersion.join('.');
|
|
14058
|
+
return getReleaseChangelog(targetDeviceConfigList, currentVersion);
|
|
14059
|
+
};
|
|
14060
|
+
|
|
14061
|
+
DataManager.getBleFirmwareLeatestRelease = features => {
|
|
14062
|
+
var _b, _c;
|
|
14063
|
+
|
|
14064
|
+
const deviceType = getDeviceType(features);
|
|
14065
|
+
const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.ble) !== null && _c !== void 0 ? _c : [];
|
|
14066
|
+
return targetDeviceConfigList[targetDeviceConfigList.length - 1];
|
|
14013
14067
|
};
|
|
14014
14068
|
|
|
14015
14069
|
DataManager.getTransportStatus = localVersion => {
|
|
@@ -14021,7 +14075,7 @@ DataManager.getTransportStatus = localVersion => {
|
|
|
14021
14075
|
return isLatest ? 'valid' : 'outdated';
|
|
14022
14076
|
};
|
|
14023
14077
|
|
|
14024
|
-
const Log$
|
|
14078
|
+
const Log$5 = initLog('Transport');
|
|
14025
14079
|
|
|
14026
14080
|
class TransportManager {
|
|
14027
14081
|
static load() {
|
|
@@ -14034,24 +14088,24 @@ class TransportManager {
|
|
|
14034
14088
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14035
14089
|
try {
|
|
14036
14090
|
const env = DataManager.getSettings('env');
|
|
14037
|
-
Log$
|
|
14091
|
+
Log$5.debug('Initializing transports');
|
|
14038
14092
|
|
|
14039
14093
|
if (env === 'react-native') {
|
|
14040
14094
|
if (!this.reactNativeInit) {
|
|
14041
14095
|
yield this.transport.init();
|
|
14042
14096
|
this.reactNativeInit = true;
|
|
14043
14097
|
} else {
|
|
14044
|
-
Log$
|
|
14098
|
+
Log$5.debug('React Native Do Not Initializing transports');
|
|
14045
14099
|
}
|
|
14046
14100
|
} else {
|
|
14047
14101
|
yield this.transport.init();
|
|
14048
14102
|
}
|
|
14049
14103
|
|
|
14050
|
-
Log$
|
|
14104
|
+
Log$5.debug('Configuring transports');
|
|
14051
14105
|
yield this.transport.configure(JSON.stringify(this.defaultMessages));
|
|
14052
|
-
Log$
|
|
14106
|
+
Log$5.debug('Configuring transports done');
|
|
14053
14107
|
} catch (error) {
|
|
14054
|
-
Log$
|
|
14108
|
+
Log$5.debug('Initializing transports error: ', error);
|
|
14055
14109
|
}
|
|
14056
14110
|
});
|
|
14057
14111
|
}
|
|
@@ -14142,7 +14196,8 @@ const UI_REQUEST$1 = {
|
|
|
14142
14196
|
REQUEST_BUTTON: 'ui-button',
|
|
14143
14197
|
CLOSE_UI_WINDOW: 'ui-close_window',
|
|
14144
14198
|
BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
|
|
14145
|
-
LOCATION_PERMISSION: 'ui-location_permission'
|
|
14199
|
+
LOCATION_PERMISSION: 'ui-location_permission',
|
|
14200
|
+
FIRMWARE_PROGRESS: 'ui-firmware-progress'
|
|
14146
14201
|
};
|
|
14147
14202
|
|
|
14148
14203
|
const createUiMessage = (type, payload) => ({
|
|
@@ -14154,7 +14209,8 @@ const createUiMessage = (type, payload) => ({
|
|
|
14154
14209
|
const IFRAME = {
|
|
14155
14210
|
INIT: 'iframe-init',
|
|
14156
14211
|
INIT_BRIDGE: 'iframe-init-bridge',
|
|
14157
|
-
CALL: 'iframe-call'
|
|
14212
|
+
CALL: 'iframe-call',
|
|
14213
|
+
CANCEL: 'iframe-cancel'
|
|
14158
14214
|
};
|
|
14159
14215
|
|
|
14160
14216
|
const createIFrameMessage = (type, payload) => ({
|
|
@@ -14217,7 +14273,7 @@ const assertType = (res, resType) => {
|
|
|
14217
14273
|
}
|
|
14218
14274
|
};
|
|
14219
14275
|
|
|
14220
|
-
const Log$
|
|
14276
|
+
const Log$4 = initLog('DeviceCommands');
|
|
14221
14277
|
|
|
14222
14278
|
class DeviceCommands {
|
|
14223
14279
|
constructor(device, mainId) {
|
|
@@ -14228,8 +14284,16 @@ class DeviceCommands {
|
|
|
14228
14284
|
}
|
|
14229
14285
|
|
|
14230
14286
|
dispose() {
|
|
14287
|
+
var _a, _b;
|
|
14288
|
+
|
|
14231
14289
|
this.disposed = true;
|
|
14290
|
+
|
|
14291
|
+
if (this._cancelableRequest) {
|
|
14292
|
+
this._cancelableRequest();
|
|
14293
|
+
}
|
|
14294
|
+
|
|
14232
14295
|
this._cancelableRequest = undefined;
|
|
14296
|
+
(_b = (_a = this.transport).cancel) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
14233
14297
|
}
|
|
14234
14298
|
|
|
14235
14299
|
call(type, msg = {}) {
|
|
@@ -14240,10 +14304,10 @@ class DeviceCommands {
|
|
|
14240
14304
|
const promise = this.transport.call(this.mainId, type, msg);
|
|
14241
14305
|
this.callPromise = promise;
|
|
14242
14306
|
const res = yield promise;
|
|
14243
|
-
Log$
|
|
14307
|
+
Log$4.debug('[DeviceCommands] [call] Received', res.type);
|
|
14244
14308
|
return res;
|
|
14245
14309
|
} catch (error) {
|
|
14246
|
-
Log$
|
|
14310
|
+
Log$4.debug('[DeviceCommands] [call] Received error', error);
|
|
14247
14311
|
throw error;
|
|
14248
14312
|
}
|
|
14249
14313
|
});
|
|
@@ -14467,7 +14531,7 @@ const parseRunOptions = options => {
|
|
|
14467
14531
|
return options;
|
|
14468
14532
|
};
|
|
14469
14533
|
|
|
14470
|
-
const Log$
|
|
14534
|
+
const Log$3 = initLog('Device');
|
|
14471
14535
|
|
|
14472
14536
|
class Device extends events.exports {
|
|
14473
14537
|
constructor(descriptor) {
|
|
@@ -14479,7 +14543,6 @@ class Device extends events.exports {
|
|
|
14479
14543
|
this.unavailableCapabilities = {};
|
|
14480
14544
|
this.instance = 0;
|
|
14481
14545
|
this.internalState = [];
|
|
14482
|
-
this.loaded = false;
|
|
14483
14546
|
this.needReloadDevice = false;
|
|
14484
14547
|
this.keepSession = false;
|
|
14485
14548
|
this.originalDescriptor = descriptor;
|
|
@@ -14554,10 +14617,10 @@ class Device extends events.exports {
|
|
|
14554
14617
|
if (env === 'react-native') {
|
|
14555
14618
|
const res = yield (_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.originalDescriptor.id);
|
|
14556
14619
|
this.mainId = (_b = res.uuid) !== null && _b !== void 0 ? _b : '';
|
|
14557
|
-
Log$
|
|
14620
|
+
Log$3.debug('Expected uuid:', this.mainId);
|
|
14558
14621
|
} else {
|
|
14559
14622
|
this.mainId = yield (_c = this.deviceConnector) === null || _c === void 0 ? void 0 : _c.acquire(this.originalDescriptor.path, this.originalDescriptor.session);
|
|
14560
|
-
Log$
|
|
14623
|
+
Log$3.debug('Expected session id:', this.mainId);
|
|
14561
14624
|
}
|
|
14562
14625
|
|
|
14563
14626
|
this.updateDescriptor({
|
|
@@ -14606,7 +14669,7 @@ class Device extends events.exports {
|
|
|
14606
14669
|
session: null
|
|
14607
14670
|
});
|
|
14608
14671
|
} catch (err) {
|
|
14609
|
-
Log$
|
|
14672
|
+
Log$3.error('[Device] release error: ', err);
|
|
14610
14673
|
} finally {
|
|
14611
14674
|
this.needReloadDevice = true;
|
|
14612
14675
|
}
|
|
@@ -14614,6 +14677,10 @@ class Device extends events.exports {
|
|
|
14614
14677
|
});
|
|
14615
14678
|
}
|
|
14616
14679
|
|
|
14680
|
+
getCommands() {
|
|
14681
|
+
return this.commands;
|
|
14682
|
+
}
|
|
14683
|
+
|
|
14617
14684
|
getInternalState() {
|
|
14618
14685
|
return this.internalState[this.instance];
|
|
14619
14686
|
}
|
|
@@ -14674,11 +14741,21 @@ class Device extends events.exports {
|
|
|
14674
14741
|
}
|
|
14675
14742
|
}
|
|
14676
14743
|
|
|
14744
|
+
updateFromCache(device) {
|
|
14745
|
+
this.mainId = device.mainId;
|
|
14746
|
+
this.commands = device.commands;
|
|
14747
|
+
this.updateDescriptor(device.originalDescriptor);
|
|
14748
|
+
|
|
14749
|
+
if (device.features) {
|
|
14750
|
+
this._updateFeatures(device.features);
|
|
14751
|
+
}
|
|
14752
|
+
}
|
|
14753
|
+
|
|
14677
14754
|
run(fn, options) {
|
|
14678
14755
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14679
14756
|
if (this.runPromise) {
|
|
14680
|
-
|
|
14681
|
-
|
|
14757
|
+
this.interruption();
|
|
14758
|
+
Log$3.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
|
|
14682
14759
|
}
|
|
14683
14760
|
|
|
14684
14761
|
options = parseRunOptions(options);
|
|
@@ -14710,14 +14787,10 @@ class Device extends events.exports {
|
|
|
14710
14787
|
yield fn();
|
|
14711
14788
|
}
|
|
14712
14789
|
|
|
14713
|
-
if (this.loaded && this.features) {
|
|
14714
|
-
yield this.getFeatures();
|
|
14715
|
-
}
|
|
14716
|
-
|
|
14717
14790
|
if (!this.keepSession && typeof options.keepSession !== 'boolean' || options.keepSession === false) {
|
|
14718
14791
|
this.keepSession = false;
|
|
14719
14792
|
yield this.release();
|
|
14720
|
-
Log$
|
|
14793
|
+
Log$3.debug('release device, mainId: ', this.mainId);
|
|
14721
14794
|
}
|
|
14722
14795
|
|
|
14723
14796
|
if (this.runPromise) {
|
|
@@ -14725,13 +14798,19 @@ class Device extends events.exports {
|
|
|
14725
14798
|
}
|
|
14726
14799
|
|
|
14727
14800
|
this.runPromise = null;
|
|
14728
|
-
|
|
14729
|
-
if (!this.loaded) {
|
|
14730
|
-
this.loaded = true;
|
|
14731
|
-
}
|
|
14732
14801
|
});
|
|
14733
14802
|
}
|
|
14734
14803
|
|
|
14804
|
+
interruption() {
|
|
14805
|
+
if (this.commands) {
|
|
14806
|
+
this.commands.dispose();
|
|
14807
|
+
}
|
|
14808
|
+
|
|
14809
|
+
if (this.runPromise) {
|
|
14810
|
+
this.runPromise.reject(TypedError('Device_Interrupted'));
|
|
14811
|
+
}
|
|
14812
|
+
}
|
|
14813
|
+
|
|
14735
14814
|
getMode() {
|
|
14736
14815
|
var _a, _b, _c;
|
|
14737
14816
|
|
|
@@ -14809,6 +14888,9 @@ class Device extends events.exports {
|
|
|
14809
14888
|
|
|
14810
14889
|
}
|
|
14811
14890
|
|
|
14891
|
+
const cacheDeviceMap = new Map();
|
|
14892
|
+
const Log$2 = initLog('DeviceList');
|
|
14893
|
+
|
|
14812
14894
|
class DeviceList extends events.exports {
|
|
14813
14895
|
constructor() {
|
|
14814
14896
|
super(...arguments);
|
|
@@ -14830,7 +14912,7 @@ class DeviceList extends events.exports {
|
|
|
14830
14912
|
try {
|
|
14831
14913
|
for (var descriptorList_1 = __asyncValues(descriptorList), descriptorList_1_1; descriptorList_1_1 = yield descriptorList_1.next(), !descriptorList_1_1.done;) {
|
|
14832
14914
|
const descriptor = descriptorList_1_1.value;
|
|
14833
|
-
|
|
14915
|
+
let device = Device.fromDescriptor(descriptor);
|
|
14834
14916
|
device.deviceConnector = this.connector;
|
|
14835
14917
|
yield device.connect();
|
|
14836
14918
|
yield device.initialize();
|
|
@@ -14839,7 +14921,16 @@ class DeviceList extends events.exports {
|
|
|
14839
14921
|
|
|
14840
14922
|
if (device.features) {
|
|
14841
14923
|
const uuid = getDeviceUUID(device.features);
|
|
14924
|
+
|
|
14925
|
+
if (cacheDeviceMap.has(uuid)) {
|
|
14926
|
+
const cache = cacheDeviceMap.get(uuid);
|
|
14927
|
+
cache === null || cache === void 0 ? void 0 : cache.updateFromCache(device);
|
|
14928
|
+
device = cache;
|
|
14929
|
+
Log$2.debug('use cache device: ', uuid);
|
|
14930
|
+
}
|
|
14931
|
+
|
|
14842
14932
|
this.devices[uuid] = device;
|
|
14933
|
+
cacheDeviceMap.set(uuid, device);
|
|
14843
14934
|
}
|
|
14844
14935
|
}
|
|
14845
14936
|
} catch (e_1_1) {
|
|
@@ -16221,7 +16312,13 @@ class CheckFirmwareRelease extends BaseMethod {
|
|
|
16221
16312
|
run() {
|
|
16222
16313
|
if (this.device.features) {
|
|
16223
16314
|
const firmwareStatus = DataManager.getFirmwareStatus(this.device.features);
|
|
16224
|
-
|
|
16315
|
+
const changelog = DataManager.getFirmwareChangelog(this.device.features);
|
|
16316
|
+
const release = DataManager.getFirmwareLeatestRelease(this.device.features);
|
|
16317
|
+
return Promise.resolve({
|
|
16318
|
+
status: firmwareStatus,
|
|
16319
|
+
changelog,
|
|
16320
|
+
release
|
|
16321
|
+
});
|
|
16225
16322
|
}
|
|
16226
16323
|
|
|
16227
16324
|
return Promise.resolve(null);
|
|
@@ -16237,7 +16334,13 @@ class CheckBLEFirmwareRelease extends BaseMethod {
|
|
|
16237
16334
|
run() {
|
|
16238
16335
|
if (this.device.features) {
|
|
16239
16336
|
const firmwareStatus = DataManager.getBLEFirmwareStatus(this.device.features);
|
|
16240
|
-
|
|
16337
|
+
const changelog = DataManager.getBleFirmwareChangelog(this.device.features);
|
|
16338
|
+
const release = DataManager.getBleFirmwareLeatestRelease(this.device.features);
|
|
16339
|
+
return Promise.resolve({
|
|
16340
|
+
status: firmwareStatus,
|
|
16341
|
+
changelog,
|
|
16342
|
+
release
|
|
16343
|
+
});
|
|
16241
16344
|
}
|
|
16242
16345
|
|
|
16243
16346
|
return Promise.resolve(null);
|
|
@@ -18022,6 +18125,179 @@ class StellarSignTransaction extends BaseMethod {
|
|
|
18022
18125
|
|
|
18023
18126
|
}
|
|
18024
18127
|
|
|
18128
|
+
const getBinary = ({
|
|
18129
|
+
features,
|
|
18130
|
+
updateType,
|
|
18131
|
+
version
|
|
18132
|
+
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18133
|
+
const releaseInfo = getInfo({
|
|
18134
|
+
features,
|
|
18135
|
+
updateType
|
|
18136
|
+
});
|
|
18137
|
+
|
|
18138
|
+
if (!releaseInfo) {
|
|
18139
|
+
throw TypedError('Runtime', 'no firmware found for this device');
|
|
18140
|
+
}
|
|
18141
|
+
|
|
18142
|
+
if (version && !semver__default["default"].eq(releaseInfo.version, version)) {
|
|
18143
|
+
throw TypedError('Runtime', 'firmware version mismatch');
|
|
18144
|
+
}
|
|
18145
|
+
|
|
18146
|
+
const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
|
|
18147
|
+
const fw = yield httpRequest(url, 'binary');
|
|
18148
|
+
return Object.assign(Object.assign({}, releaseInfo), {
|
|
18149
|
+
binary: fw
|
|
18150
|
+
});
|
|
18151
|
+
});
|
|
18152
|
+
|
|
18153
|
+
const getInfo = ({
|
|
18154
|
+
features,
|
|
18155
|
+
updateType
|
|
18156
|
+
}) => {
|
|
18157
|
+
var _a, _b, _c;
|
|
18158
|
+
|
|
18159
|
+
const deviceType = getDeviceType(features);
|
|
18160
|
+
const {
|
|
18161
|
+
deviceMap
|
|
18162
|
+
} = DataManager;
|
|
18163
|
+
const releaseInfo = (_c = (_b = (_a = deviceMap === null || deviceMap === void 0 ? void 0 : deviceMap[deviceType]) === null || _a === void 0 ? void 0 : _a[updateType]) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : null;
|
|
18164
|
+
return releaseInfo;
|
|
18165
|
+
};
|
|
18166
|
+
|
|
18167
|
+
const postConfirmationMessage = device => {
|
|
18168
|
+
var _a;
|
|
18169
|
+
|
|
18170
|
+
if ((_a = device.features) === null || _a === void 0 ? void 0 : _a.firmware_present) {
|
|
18171
|
+
device.emit(DEVICE.BUTTON, device, {
|
|
18172
|
+
code: 'ButtonRequest_FirmwareUpdate'
|
|
18173
|
+
});
|
|
18174
|
+
}
|
|
18175
|
+
};
|
|
18176
|
+
|
|
18177
|
+
const postProgressMessage = (device, progress, postMessage) => {
|
|
18178
|
+
postMessage(createUiMessage(UI_REQUEST$1.FIRMWARE_PROGRESS, {
|
|
18179
|
+
device: device.toMessageObject(),
|
|
18180
|
+
progress
|
|
18181
|
+
}));
|
|
18182
|
+
};
|
|
18183
|
+
|
|
18184
|
+
const uploadFirmware = (updateType, typedCall, postMessage, device, {
|
|
18185
|
+
payload
|
|
18186
|
+
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18187
|
+
var _a, _b;
|
|
18188
|
+
|
|
18189
|
+
if (((_a = device.features) === null || _a === void 0 ? void 0 : _a.major_version) === 1) {
|
|
18190
|
+
postConfirmationMessage(device);
|
|
18191
|
+
const eraseCommand = updateType === 'firmware' ? 'FirmwareErase' : 'FirmwareErase_ex';
|
|
18192
|
+
yield typedCall(eraseCommand, 'Success', {});
|
|
18193
|
+
postProgressMessage(device, 0, postMessage);
|
|
18194
|
+
const {
|
|
18195
|
+
message
|
|
18196
|
+
} = yield typedCall('FirmwareUpload', 'Success', {
|
|
18197
|
+
payload
|
|
18198
|
+
});
|
|
18199
|
+
return message;
|
|
18200
|
+
}
|
|
18201
|
+
|
|
18202
|
+
if (((_b = device.features) === null || _b === void 0 ? void 0 : _b.major_version) === 2) {
|
|
18203
|
+
postConfirmationMessage(device);
|
|
18204
|
+
const length = payload.byteLength;
|
|
18205
|
+
let response = yield typedCall('FirmwareErase', ['FirmwareRequest', 'Success'], {
|
|
18206
|
+
length
|
|
18207
|
+
});
|
|
18208
|
+
|
|
18209
|
+
while (response.type !== 'Success') {
|
|
18210
|
+
const start = response.message.offset;
|
|
18211
|
+
const end = response.message.offset + response.message.length;
|
|
18212
|
+
const chunk = payload.slice(start, end);
|
|
18213
|
+
|
|
18214
|
+
if (start > 0) {
|
|
18215
|
+
postProgressMessage(device, Math.round(start / length * 100), postMessage);
|
|
18216
|
+
}
|
|
18217
|
+
|
|
18218
|
+
response = yield typedCall('FirmwareUpload', ['FirmwareRequest', 'Success'], {
|
|
18219
|
+
payload: chunk
|
|
18220
|
+
});
|
|
18221
|
+
}
|
|
18222
|
+
|
|
18223
|
+
postProgressMessage(device, 100, postMessage);
|
|
18224
|
+
return response.message;
|
|
18225
|
+
}
|
|
18226
|
+
|
|
18227
|
+
throw TypedError('Runtime', 'uploadFirmware: unknown major_version');
|
|
18228
|
+
});
|
|
18229
|
+
|
|
18230
|
+
class FirmwareUpdate extends BaseMethod {
|
|
18231
|
+
init() {
|
|
18232
|
+
this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
|
|
18233
|
+
this.requireDeviceMode = [UI_REQUEST.BOOTLOADER];
|
|
18234
|
+
const {
|
|
18235
|
+
payload
|
|
18236
|
+
} = this;
|
|
18237
|
+
validateParams(payload, [{
|
|
18238
|
+
name: 'version',
|
|
18239
|
+
type: 'array'
|
|
18240
|
+
}, {
|
|
18241
|
+
name: 'binary',
|
|
18242
|
+
type: 'buffer'
|
|
18243
|
+
}]);
|
|
18244
|
+
|
|
18245
|
+
if (!payload.updateType) {
|
|
18246
|
+
throw TypedError('Method_InvalidParameter', 'updateType is required');
|
|
18247
|
+
}
|
|
18248
|
+
|
|
18249
|
+
this.params = {
|
|
18250
|
+
updateType: payload.updateType
|
|
18251
|
+
};
|
|
18252
|
+
|
|
18253
|
+
if ('version' in payload) {
|
|
18254
|
+
this.params = Object.assign(Object.assign({}, this.params), {
|
|
18255
|
+
version: payload.version
|
|
18256
|
+
});
|
|
18257
|
+
}
|
|
18258
|
+
|
|
18259
|
+
if ('binary' in payload) {
|
|
18260
|
+
this.params = Object.assign(Object.assign({}, this.params), {
|
|
18261
|
+
binary: payload.binary
|
|
18262
|
+
});
|
|
18263
|
+
}
|
|
18264
|
+
}
|
|
18265
|
+
|
|
18266
|
+
run() {
|
|
18267
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18268
|
+
const {
|
|
18269
|
+
device,
|
|
18270
|
+
params
|
|
18271
|
+
} = this;
|
|
18272
|
+
let binary;
|
|
18273
|
+
|
|
18274
|
+
try {
|
|
18275
|
+
if (params.binary) {
|
|
18276
|
+
binary = this.params.binary;
|
|
18277
|
+
} else {
|
|
18278
|
+
if (!device.features) {
|
|
18279
|
+
throw TypedError('Runtime', 'no features found for this device');
|
|
18280
|
+
}
|
|
18281
|
+
|
|
18282
|
+
const firmware = yield getBinary({
|
|
18283
|
+
features: device.features,
|
|
18284
|
+
version: params.version,
|
|
18285
|
+
updateType: params.updateType
|
|
18286
|
+
});
|
|
18287
|
+
binary = firmware.binary;
|
|
18288
|
+
}
|
|
18289
|
+
} catch (err) {
|
|
18290
|
+
throw TypedError('Method_FirmwareUpdate_DownloadFailed', err);
|
|
18291
|
+
}
|
|
18292
|
+
|
|
18293
|
+
return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, {
|
|
18294
|
+
payload: binary
|
|
18295
|
+
});
|
|
18296
|
+
});
|
|
18297
|
+
}
|
|
18298
|
+
|
|
18299
|
+
}
|
|
18300
|
+
|
|
18025
18301
|
var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
18026
18302
|
__proto__: null,
|
|
18027
18303
|
searchDevices: SearchDevices,
|
|
@@ -18061,7 +18337,8 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
18061
18337
|
solGetAddress: SolGetAddress,
|
|
18062
18338
|
solSignTransaction: SolSignTransaction,
|
|
18063
18339
|
stellarGetAddress: StellarGetAddress,
|
|
18064
|
-
stellarSignTransaction: StellarSignTransaction
|
|
18340
|
+
stellarSignTransaction: StellarSignTransaction,
|
|
18341
|
+
firmwareUpdate: FirmwareUpdate
|
|
18065
18342
|
});
|
|
18066
18343
|
|
|
18067
18344
|
function findMethod(message) {
|
|
@@ -18254,6 +18531,8 @@ let _uiPromises = [];
|
|
|
18254
18531
|
|
|
18255
18532
|
let _callPromise;
|
|
18256
18533
|
|
|
18534
|
+
const deviceCacheMap = new Map();
|
|
18535
|
+
|
|
18257
18536
|
const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
|
|
18258
18537
|
var _a, _b;
|
|
18259
18538
|
|
|
@@ -18267,6 +18546,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
18267
18546
|
try {
|
|
18268
18547
|
method = findMethod(message);
|
|
18269
18548
|
method.connector = _connector;
|
|
18549
|
+
method.postMessage = postMessage;
|
|
18270
18550
|
method.init();
|
|
18271
18551
|
} catch (error) {
|
|
18272
18552
|
return Promise.reject(error);
|
|
@@ -18435,13 +18715,44 @@ function initDeviceForBle(method) {
|
|
|
18435
18715
|
return initDevice(method);
|
|
18436
18716
|
}
|
|
18437
18717
|
|
|
18438
|
-
|
|
18439
|
-
|
|
18440
|
-
|
|
18718
|
+
let device;
|
|
18719
|
+
|
|
18720
|
+
if (deviceCacheMap.has(method.connectId)) {
|
|
18721
|
+
device = deviceCacheMap.get(method.connectId);
|
|
18722
|
+
} else {
|
|
18723
|
+
device = Device.fromDescriptor({
|
|
18724
|
+
id: method.connectId
|
|
18725
|
+
});
|
|
18726
|
+
deviceCacheMap.set(method.connectId, device);
|
|
18727
|
+
}
|
|
18728
|
+
|
|
18441
18729
|
device.deviceConnector = _connector;
|
|
18442
18730
|
return device;
|
|
18443
18731
|
}
|
|
18444
18732
|
|
|
18733
|
+
const cancel = connectId => {
|
|
18734
|
+
const env = DataManager.getSettings('env');
|
|
18735
|
+
|
|
18736
|
+
if (connectId) {
|
|
18737
|
+
let device;
|
|
18738
|
+
|
|
18739
|
+
if (env === 'react-native') {
|
|
18740
|
+
device = initDeviceForBle({
|
|
18741
|
+
connectId
|
|
18742
|
+
});
|
|
18743
|
+
} else {
|
|
18744
|
+
device = initDevice({
|
|
18745
|
+
connectId
|
|
18746
|
+
});
|
|
18747
|
+
}
|
|
18748
|
+
|
|
18749
|
+
device === null || device === void 0 ? void 0 : device.interruption();
|
|
18750
|
+
}
|
|
18751
|
+
|
|
18752
|
+
cleanup();
|
|
18753
|
+
closePopup();
|
|
18754
|
+
};
|
|
18755
|
+
|
|
18445
18756
|
const cleanup = () => {
|
|
18446
18757
|
_uiPromises = [];
|
|
18447
18758
|
Log.debug('Cleanup...');
|
|
@@ -18525,6 +18836,12 @@ class Core extends events.exports {
|
|
|
18525
18836
|
const response = yield callAPI(message);
|
|
18526
18837
|
return response;
|
|
18527
18838
|
}
|
|
18839
|
+
|
|
18840
|
+
case IFRAME.CANCEL:
|
|
18841
|
+
{
|
|
18842
|
+
cancel(message.payload.connectId);
|
|
18843
|
+
break;
|
|
18844
|
+
}
|
|
18528
18845
|
}
|
|
18529
18846
|
|
|
18530
18847
|
return Promise.resolve(message);
|
|
@@ -44207,7 +44524,15 @@ const uiResponse = response => {
|
|
|
44207
44524
|
});
|
|
44208
44525
|
};
|
|
44209
44526
|
|
|
44210
|
-
const cancel =
|
|
44527
|
+
const cancel = connectId => {
|
|
44528
|
+
sendMessage({
|
|
44529
|
+
event: dist/* IFRAME.CANCEL */.Bg.CANCEL,
|
|
44530
|
+
type: dist/* IFRAME.CANCEL */.Bg.CANCEL,
|
|
44531
|
+
payload: {
|
|
44532
|
+
connectId
|
|
44533
|
+
}
|
|
44534
|
+
});
|
|
44535
|
+
};
|
|
44211
44536
|
|
|
44212
44537
|
const createJSBridge = messageEvent => {
|
|
44213
44538
|
if (messageEvent.origin !== origin) {
|