@onekeyfe/hd-web-sdk 0.1.17 → 0.1.20
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.5347aa98da0df5421f87.js +3 -0
- package/build/js/{iframe.bc96e38a35b7448d677b.js.LICENSE.txt → iframe.5347aa98da0df5421f87.js.LICENSE.txt} +0 -0
- package/build/js/iframe.5347aa98da0df5421f87.js.map +1 -0
- package/build/onekey-js-sdk.js +387 -98
- 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 +6 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +9 -0
- package/build/js/iframe.bc96e38a35b7448d677b.js +0 -3
- package/build/js/iframe.bc96e38a35b7448d677b.js.map +0 -1
package/build/onekey-js-sdk.js
CHANGED
|
@@ -4096,8 +4096,9 @@ const inject = ({
|
|
|
4096
4096
|
checkBridgeStatus: () => call({
|
|
4097
4097
|
method: 'checkBridgeStatus'
|
|
4098
4098
|
}),
|
|
4099
|
-
cipherKeyValue: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4099
|
+
cipherKeyValue: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4100
4100
|
connectId,
|
|
4101
|
+
deviceId,
|
|
4101
4102
|
method: 'cipherKeyValue'
|
|
4102
4103
|
})),
|
|
4103
4104
|
deviceBackup: connectId => call({
|
|
@@ -4140,96 +4141,119 @@ const inject = ({
|
|
|
4140
4141
|
connectId,
|
|
4141
4142
|
method: 'deviceWipe'
|
|
4142
4143
|
}),
|
|
4143
|
-
evmGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4144
|
+
evmGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4144
4145
|
connectId,
|
|
4146
|
+
deviceId,
|
|
4145
4147
|
method: 'evmGetAddress'
|
|
4146
4148
|
})),
|
|
4147
|
-
evmGetPublicKey: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4149
|
+
evmGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4148
4150
|
connectId,
|
|
4151
|
+
deviceId,
|
|
4149
4152
|
method: 'evmGetPublicKey'
|
|
4150
4153
|
})),
|
|
4151
|
-
evmSignMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4154
|
+
evmSignMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4152
4155
|
connectId,
|
|
4156
|
+
deviceId,
|
|
4153
4157
|
method: 'evmSignMessage'
|
|
4154
4158
|
})),
|
|
4155
|
-
evmSignMessageEIP712: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4159
|
+
evmSignMessageEIP712: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4156
4160
|
connectId,
|
|
4161
|
+
deviceId,
|
|
4157
4162
|
method: 'evmSignMessageEIP712'
|
|
4158
4163
|
})),
|
|
4159
|
-
evmSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4164
|
+
evmSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4160
4165
|
connectId,
|
|
4166
|
+
deviceId,
|
|
4161
4167
|
method: 'evmSignTransaction'
|
|
4162
4168
|
})),
|
|
4163
|
-
evmSignTypedData: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4169
|
+
evmSignTypedData: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4164
4170
|
connectId,
|
|
4171
|
+
deviceId,
|
|
4165
4172
|
method: 'evmSignTypedData'
|
|
4166
4173
|
})),
|
|
4167
|
-
evmVerifyMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4174
|
+
evmVerifyMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4168
4175
|
connectId,
|
|
4176
|
+
deviceId,
|
|
4169
4177
|
method: 'evmVerifyMessage'
|
|
4170
4178
|
})),
|
|
4171
|
-
btcGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4179
|
+
btcGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4172
4180
|
connectId,
|
|
4181
|
+
deviceId,
|
|
4173
4182
|
method: 'btcGetAddress'
|
|
4174
4183
|
})),
|
|
4175
|
-
btcGetPublicKey: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4184
|
+
btcGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4176
4185
|
connectId,
|
|
4186
|
+
deviceId,
|
|
4177
4187
|
method: 'btcGetPublicKey'
|
|
4178
4188
|
})),
|
|
4179
|
-
btcSignMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4189
|
+
btcSignMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4180
4190
|
connectId,
|
|
4191
|
+
deviceId,
|
|
4181
4192
|
method: 'btcSignMessage'
|
|
4182
4193
|
})),
|
|
4183
|
-
btcSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4194
|
+
btcSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4184
4195
|
connectId,
|
|
4196
|
+
deviceId,
|
|
4185
4197
|
method: 'btcSignTransaction'
|
|
4186
4198
|
})),
|
|
4187
|
-
btcVerifyMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4199
|
+
btcVerifyMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4188
4200
|
connectId,
|
|
4201
|
+
deviceId,
|
|
4189
4202
|
method: 'btcVerifyMessage'
|
|
4190
4203
|
})),
|
|
4191
|
-
starcoinGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4204
|
+
starcoinGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4192
4205
|
connectId,
|
|
4206
|
+
deviceId,
|
|
4193
4207
|
method: 'starcoinGetAddress'
|
|
4194
4208
|
})),
|
|
4195
|
-
starcoinGetPublicKey: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4209
|
+
starcoinGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4196
4210
|
connectId,
|
|
4211
|
+
deviceId,
|
|
4197
4212
|
method: 'starcoinGetPublicKey'
|
|
4198
4213
|
})),
|
|
4199
|
-
starcoinSignMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4214
|
+
starcoinSignMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4200
4215
|
connectId,
|
|
4216
|
+
deviceId,
|
|
4201
4217
|
method: 'starcoinSignMessage'
|
|
4202
4218
|
})),
|
|
4203
|
-
starcoinSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4219
|
+
starcoinSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4204
4220
|
connectId,
|
|
4221
|
+
deviceId,
|
|
4205
4222
|
method: 'starcoinSignTransaction'
|
|
4206
4223
|
})),
|
|
4207
|
-
starcoinVerifyMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4224
|
+
starcoinVerifyMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4208
4225
|
connectId,
|
|
4226
|
+
deviceId,
|
|
4209
4227
|
method: 'starcoinVerifyMessage'
|
|
4210
4228
|
})),
|
|
4211
|
-
nemGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4229
|
+
nemGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4212
4230
|
connectId,
|
|
4231
|
+
deviceId,
|
|
4213
4232
|
method: 'nemGetAddress'
|
|
4214
4233
|
})),
|
|
4215
|
-
nemSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4234
|
+
nemSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4216
4235
|
connectId,
|
|
4236
|
+
deviceId,
|
|
4217
4237
|
method: 'nemSignTransaction'
|
|
4218
4238
|
})),
|
|
4219
|
-
solGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4239
|
+
solGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4220
4240
|
connectId,
|
|
4241
|
+
deviceId,
|
|
4221
4242
|
method: 'solGetAddress'
|
|
4222
4243
|
})),
|
|
4223
|
-
solSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4244
|
+
solSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4224
4245
|
connectId,
|
|
4246
|
+
deviceId,
|
|
4225
4247
|
method: 'solSignTransaction'
|
|
4226
4248
|
})),
|
|
4227
|
-
stellarGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4249
|
+
stellarGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4228
4250
|
connectId,
|
|
4251
|
+
deviceId,
|
|
4229
4252
|
method: 'stellarGetAddress'
|
|
4230
4253
|
})),
|
|
4231
|
-
stellarSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4254
|
+
stellarSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4232
4255
|
connectId,
|
|
4256
|
+
deviceId,
|
|
4233
4257
|
method: 'stellarSignTransaction'
|
|
4234
4258
|
})),
|
|
4235
4259
|
firmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
@@ -14326,7 +14350,8 @@ const DEVICE = {
|
|
|
14326
14350
|
PIN: 'pin',
|
|
14327
14351
|
PASSPHRASE: 'passphrase',
|
|
14328
14352
|
PASSPHRASE_ON_DEVICE: 'passphrase_on_device',
|
|
14329
|
-
WORD: 'word'
|
|
14353
|
+
WORD: 'word',
|
|
14354
|
+
FEATURES: 'features'
|
|
14330
14355
|
};
|
|
14331
14356
|
|
|
14332
14357
|
const createDeviceMessage = (type, payload) => ({
|
|
@@ -14335,6 +14360,18 @@ const createDeviceMessage = (type, payload) => ({
|
|
|
14335
14360
|
payload
|
|
14336
14361
|
});
|
|
14337
14362
|
|
|
14363
|
+
const FIRMWARE_EVENT = 'FIRMWARE_EVENT';
|
|
14364
|
+
const FIRMWARE = {
|
|
14365
|
+
RELEASE_INFO: 'firmware-release-info',
|
|
14366
|
+
BLE_RELEASE_INFO: 'ble-firmware-release-info'
|
|
14367
|
+
};
|
|
14368
|
+
|
|
14369
|
+
const createFirmwareMessage = (type, payload) => ({
|
|
14370
|
+
event: FIRMWARE_EVENT,
|
|
14371
|
+
type,
|
|
14372
|
+
payload
|
|
14373
|
+
});
|
|
14374
|
+
|
|
14338
14375
|
const assertType = (res, resType) => {
|
|
14339
14376
|
const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
|
|
14340
14377
|
|
|
@@ -14353,17 +14390,19 @@ class DeviceCommands {
|
|
|
14353
14390
|
this.disposed = false;
|
|
14354
14391
|
}
|
|
14355
14392
|
|
|
14356
|
-
dispose() {
|
|
14393
|
+
dispose(cancelRequest) {
|
|
14357
14394
|
var _a, _b;
|
|
14358
14395
|
|
|
14359
|
-
this
|
|
14396
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14397
|
+
this.disposed = true;
|
|
14360
14398
|
|
|
14361
|
-
|
|
14362
|
-
|
|
14363
|
-
|
|
14399
|
+
if (cancelRequest && this._cancelableRequest) {
|
|
14400
|
+
this._cancelableRequest();
|
|
14401
|
+
}
|
|
14364
14402
|
|
|
14365
|
-
|
|
14366
|
-
|
|
14403
|
+
this._cancelableRequest = undefined;
|
|
14404
|
+
yield (_b = (_a = this.transport).cancel) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
14405
|
+
});
|
|
14367
14406
|
}
|
|
14368
14407
|
|
|
14369
14408
|
call(type, msg = {}) {
|
|
@@ -14491,7 +14530,12 @@ class DeviceCommands {
|
|
|
14491
14530
|
}, () => this._commonCall('Cancel', {}));
|
|
14492
14531
|
}
|
|
14493
14532
|
|
|
14494
|
-
if (res.type === 'PassphraseRequest')
|
|
14533
|
+
if (res.type === 'PassphraseRequest') {
|
|
14534
|
+
return this._commonCall('PassphraseAck', {
|
|
14535
|
+
passphrase: ''
|
|
14536
|
+
});
|
|
14537
|
+
}
|
|
14538
|
+
|
|
14495
14539
|
if (res.type === 'Deprecated_PassphraseStateRequest') ;
|
|
14496
14540
|
if (res.type === 'WordRequest') ;
|
|
14497
14541
|
return Promise.resolve(res);
|
|
@@ -14729,7 +14773,7 @@ class Device extends events.exports {
|
|
|
14729
14773
|
});
|
|
14730
14774
|
|
|
14731
14775
|
if (this.commands) {
|
|
14732
|
-
this.commands.dispose();
|
|
14776
|
+
yield this.commands.dispose(false);
|
|
14733
14777
|
}
|
|
14734
14778
|
|
|
14735
14779
|
this.commands = new DeviceCommands(this, (_d = this.mainId) !== null && _d !== void 0 ? _d : '');
|
|
@@ -14753,7 +14797,7 @@ class Device extends events.exports {
|
|
|
14753
14797
|
|
|
14754
14798
|
if (this.isUsedHere() && !this.keepSession && this.mainId || this.mainId && env === 'react-native') {
|
|
14755
14799
|
if (this.commands) {
|
|
14756
|
-
this.commands.dispose();
|
|
14800
|
+
this.commands.dispose(false);
|
|
14757
14801
|
|
|
14758
14802
|
if (this.commands.callPromise) {
|
|
14759
14803
|
try {
|
|
@@ -14825,6 +14869,7 @@ class Device extends events.exports {
|
|
|
14825
14869
|
feat.unlocked = feat.unlocked || true;
|
|
14826
14870
|
this.features = feat;
|
|
14827
14871
|
this.featuresNeedsReload = false;
|
|
14872
|
+
this.emit(DEVICE.FEATURES, this, feat);
|
|
14828
14873
|
}
|
|
14829
14874
|
|
|
14830
14875
|
updateDescriptor(descriptor, forceUpdate = false) {
|
|
@@ -14859,7 +14904,7 @@ class Device extends events.exports {
|
|
|
14859
14904
|
run(fn, options) {
|
|
14860
14905
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14861
14906
|
if (this.runPromise) {
|
|
14862
|
-
this.
|
|
14907
|
+
yield this.interruptionFromOutside();
|
|
14863
14908
|
Log$3.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
|
|
14864
14909
|
}
|
|
14865
14910
|
|
|
@@ -14880,6 +14925,11 @@ class Device extends events.exports {
|
|
|
14880
14925
|
}
|
|
14881
14926
|
} catch (error) {
|
|
14882
14927
|
this.runPromise = null;
|
|
14928
|
+
|
|
14929
|
+
if (error instanceof hdShared.HardwareError) {
|
|
14930
|
+
return Promise.reject(error);
|
|
14931
|
+
}
|
|
14932
|
+
|
|
14883
14933
|
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, `Initialize failed: ${error.message}, code: ${error.code}`));
|
|
14884
14934
|
}
|
|
14885
14935
|
}
|
|
@@ -14906,14 +14956,28 @@ class Device extends events.exports {
|
|
|
14906
14956
|
});
|
|
14907
14957
|
}
|
|
14908
14958
|
|
|
14909
|
-
|
|
14910
|
-
|
|
14911
|
-
this.commands
|
|
14912
|
-
|
|
14959
|
+
interruptionFromOutside() {
|
|
14960
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14961
|
+
if (this.commands) {
|
|
14962
|
+
yield this.commands.dispose(false);
|
|
14963
|
+
}
|
|
14913
14964
|
|
|
14914
|
-
|
|
14915
|
-
|
|
14916
|
-
|
|
14965
|
+
if (this.runPromise) {
|
|
14966
|
+
this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromOutside));
|
|
14967
|
+
}
|
|
14968
|
+
});
|
|
14969
|
+
}
|
|
14970
|
+
|
|
14971
|
+
interruptionFromUser() {
|
|
14972
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14973
|
+
if (this.commands) {
|
|
14974
|
+
yield this.commands.dispose(true);
|
|
14975
|
+
}
|
|
14976
|
+
|
|
14977
|
+
if (this.runPromise) {
|
|
14978
|
+
this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser));
|
|
14979
|
+
}
|
|
14980
|
+
});
|
|
14917
14981
|
}
|
|
14918
14982
|
|
|
14919
14983
|
getMode() {
|
|
@@ -14991,9 +15055,17 @@ class Device extends events.exports {
|
|
|
14991
15055
|
return null;
|
|
14992
15056
|
}
|
|
14993
15057
|
|
|
15058
|
+
checkDeviceId(deviceId) {
|
|
15059
|
+
if (this.features) {
|
|
15060
|
+
return this.features.device_id === deviceId;
|
|
15061
|
+
}
|
|
15062
|
+
|
|
15063
|
+
return false;
|
|
15064
|
+
}
|
|
15065
|
+
|
|
14994
15066
|
}
|
|
14995
15067
|
|
|
14996
|
-
const cacheDeviceMap =
|
|
15068
|
+
const cacheDeviceMap = {};
|
|
14997
15069
|
const Log$2 = getLogger(exports.d0.DeviceList);
|
|
14998
15070
|
|
|
14999
15071
|
class DeviceList extends events.exports {
|
|
@@ -15002,7 +15074,7 @@ class DeviceList extends events.exports {
|
|
|
15002
15074
|
this.devices = {};
|
|
15003
15075
|
}
|
|
15004
15076
|
|
|
15005
|
-
getDeviceLists() {
|
|
15077
|
+
getDeviceLists(connectId) {
|
|
15006
15078
|
var e_1, _a;
|
|
15007
15079
|
|
|
15008
15080
|
var _b, _c;
|
|
@@ -15014,6 +15086,21 @@ class DeviceList extends events.exports {
|
|
|
15014
15086
|
const deviceList = [];
|
|
15015
15087
|
Log$2.debug('get device list');
|
|
15016
15088
|
|
|
15089
|
+
if (connectId) {
|
|
15090
|
+
const device = cacheDeviceMap[connectId];
|
|
15091
|
+
|
|
15092
|
+
if (device) {
|
|
15093
|
+
const exist = descriptorList.find(d => d.path === device.originalDescriptor.path);
|
|
15094
|
+
|
|
15095
|
+
if (exist) {
|
|
15096
|
+
device.updateDescriptor(exist, true);
|
|
15097
|
+
Log$2.debug('find existed Device: ', connectId);
|
|
15098
|
+
this.devices[connectId] = device;
|
|
15099
|
+
return [device];
|
|
15100
|
+
}
|
|
15101
|
+
}
|
|
15102
|
+
}
|
|
15103
|
+
|
|
15017
15104
|
try {
|
|
15018
15105
|
for (var descriptorList_1 = __asyncValues(descriptorList), descriptorList_1_1; descriptorList_1_1 = yield descriptorList_1.next(), !descriptorList_1_1.done;) {
|
|
15019
15106
|
const descriptor = descriptorList_1_1.value;
|
|
@@ -15027,15 +15114,14 @@ class DeviceList extends events.exports {
|
|
|
15027
15114
|
if (device.features) {
|
|
15028
15115
|
const uuid = getDeviceUUID(device.features);
|
|
15029
15116
|
|
|
15030
|
-
if (cacheDeviceMap
|
|
15031
|
-
const cache = cacheDeviceMap
|
|
15117
|
+
if (cacheDeviceMap[uuid]) {
|
|
15118
|
+
const cache = cacheDeviceMap[uuid];
|
|
15032
15119
|
cache === null || cache === void 0 ? void 0 : cache.updateFromCache(device);
|
|
15033
15120
|
device = cache;
|
|
15034
|
-
Log$2.debug('use cache device: ', uuid);
|
|
15035
15121
|
}
|
|
15036
15122
|
|
|
15037
15123
|
this.devices[uuid] = device;
|
|
15038
|
-
cacheDeviceMap
|
|
15124
|
+
cacheDeviceMap[uuid] = device;
|
|
15039
15125
|
}
|
|
15040
15126
|
}
|
|
15041
15127
|
} catch (e_1_1) {
|
|
@@ -15064,8 +15150,32 @@ class DeviceList extends events.exports {
|
|
|
15064
15150
|
|
|
15065
15151
|
}
|
|
15066
15152
|
|
|
15153
|
+
const getFirmwareReleaseInfo = features => {
|
|
15154
|
+
const firmwareStatus = DataManager.getFirmwareStatus(features);
|
|
15155
|
+
const changelog = DataManager.getFirmwareChangelog(features);
|
|
15156
|
+
const release = DataManager.getFirmwareLeatestRelease(features);
|
|
15157
|
+
return {
|
|
15158
|
+
status: firmwareStatus,
|
|
15159
|
+
changelog,
|
|
15160
|
+
release
|
|
15161
|
+
};
|
|
15162
|
+
};
|
|
15163
|
+
|
|
15164
|
+
const getBleFirmwareReleaseInfo = features => {
|
|
15165
|
+
const firmwareStatus = DataManager.getBLEFirmwareStatus(features);
|
|
15166
|
+
const changelog = DataManager.getBleFirmwareChangelog(features);
|
|
15167
|
+
const release = DataManager.getBleFirmwareLeatestRelease(features);
|
|
15168
|
+
return {
|
|
15169
|
+
status: firmwareStatus,
|
|
15170
|
+
changelog,
|
|
15171
|
+
release
|
|
15172
|
+
};
|
|
15173
|
+
};
|
|
15174
|
+
|
|
15067
15175
|
class BaseMethod {
|
|
15068
15176
|
constructor(message) {
|
|
15177
|
+
this.shouldEnsureConnected = true;
|
|
15178
|
+
this.checkDeviceId = false;
|
|
15069
15179
|
const {
|
|
15070
15180
|
payload
|
|
15071
15181
|
} = message;
|
|
@@ -15073,6 +15183,7 @@ class BaseMethod {
|
|
|
15073
15183
|
this.payload = payload;
|
|
15074
15184
|
this.responseID = message.id || 0;
|
|
15075
15185
|
this.connectId = payload.connectId || '';
|
|
15186
|
+
this.deviceId = payload.deviceId || '';
|
|
15076
15187
|
this.useDevice = true;
|
|
15077
15188
|
this.allowDeviceMode = [UI_REQUEST.INITIALIZE];
|
|
15078
15189
|
this.requireDeviceMode = [];
|
|
@@ -15087,6 +15198,18 @@ class BaseMethod {
|
|
|
15087
15198
|
this.connectId = device.originalDescriptor.path;
|
|
15088
15199
|
}
|
|
15089
15200
|
|
|
15201
|
+
checkFirmwareRelease() {
|
|
15202
|
+
if (!this.device || !this.device.features) return;
|
|
15203
|
+
const releaseInfo = getFirmwareReleaseInfo(this.device.features);
|
|
15204
|
+
this.postMessage(createFirmwareMessage(FIRMWARE.RELEASE_INFO, Object.assign(Object.assign({}, releaseInfo), {
|
|
15205
|
+
features: this.device.features
|
|
15206
|
+
})));
|
|
15207
|
+
const bleReleaseInfo = getBleFirmwareReleaseInfo(this.device.features);
|
|
15208
|
+
this.postMessage(createFirmwareMessage(FIRMWARE.BLE_RELEASE_INFO, Object.assign(Object.assign({}, bleReleaseInfo), {
|
|
15209
|
+
features: this.device.features
|
|
15210
|
+
})));
|
|
15211
|
+
}
|
|
15212
|
+
|
|
15090
15213
|
dispose() {}
|
|
15091
15214
|
|
|
15092
15215
|
}
|
|
@@ -15283,6 +15406,7 @@ class CipherKeyValue extends BaseMethod {
|
|
|
15283
15406
|
init() {
|
|
15284
15407
|
var _a;
|
|
15285
15408
|
|
|
15409
|
+
this.checkDeviceId = true;
|
|
15286
15410
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
15287
15411
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
15288
15412
|
const payload = this.hasBundle ? this.payload : {
|
|
@@ -15560,6 +15684,7 @@ class BTCGetAddress extends BaseMethod {
|
|
|
15560
15684
|
}
|
|
15561
15685
|
|
|
15562
15686
|
init() {
|
|
15687
|
+
this.checkDeviceId = true;
|
|
15563
15688
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
15564
15689
|
this.hasBundle = Object.prototype.hasOwnProperty.call(this.payload, 'bundle');
|
|
15565
15690
|
const payload = this.hasBundle ? this.payload : {
|
|
@@ -15643,6 +15768,7 @@ class BTCGetPublicKey extends BaseMethod {
|
|
|
15643
15768
|
}
|
|
15644
15769
|
|
|
15645
15770
|
init() {
|
|
15771
|
+
this.checkDeviceId = true;
|
|
15646
15772
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
15647
15773
|
this.hasBundle = Object.prototype.hasOwnProperty.call(this.payload, 'bundle');
|
|
15648
15774
|
const payload = this.hasBundle ? this.payload : {
|
|
@@ -15717,6 +15843,7 @@ class BTCGetPublicKey extends BaseMethod {
|
|
|
15717
15843
|
|
|
15718
15844
|
class BTCSignMessage extends BaseMethod {
|
|
15719
15845
|
init() {
|
|
15846
|
+
this.checkDeviceId = true;
|
|
15720
15847
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
15721
15848
|
validateParams(this.payload, [{
|
|
15722
15849
|
name: 'path',
|
|
@@ -16193,6 +16320,7 @@ var signtxLegacy = (typedCall, inputs, outputs, refTxsArray, options, coinName)
|
|
|
16193
16320
|
|
|
16194
16321
|
class BTCSignTransaction extends BaseMethod {
|
|
16195
16322
|
init() {
|
|
16323
|
+
this.checkDeviceId = true;
|
|
16196
16324
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
16197
16325
|
validateParams(this.payload, [{
|
|
16198
16326
|
name: 'coin',
|
|
@@ -16367,6 +16495,7 @@ class BTCSignTransaction extends BaseMethod {
|
|
|
16367
16495
|
|
|
16368
16496
|
class BTCVerifyMessage extends BaseMethod {
|
|
16369
16497
|
init() {
|
|
16498
|
+
this.checkDeviceId = true;
|
|
16370
16499
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
16371
16500
|
validateParams(this.payload, [{
|
|
16372
16501
|
name: 'address',
|
|
@@ -16416,14 +16545,8 @@ class CheckFirmwareRelease extends BaseMethod {
|
|
|
16416
16545
|
|
|
16417
16546
|
run() {
|
|
16418
16547
|
if (this.device.features) {
|
|
16419
|
-
const
|
|
16420
|
-
|
|
16421
|
-
const release = DataManager.getFirmwareLeatestRelease(this.device.features);
|
|
16422
|
-
return Promise.resolve({
|
|
16423
|
-
status: firmwareStatus,
|
|
16424
|
-
changelog,
|
|
16425
|
-
release
|
|
16426
|
-
});
|
|
16548
|
+
const releaseInfo = getFirmwareReleaseInfo(this.device.features);
|
|
16549
|
+
return Promise.resolve(releaseInfo);
|
|
16427
16550
|
}
|
|
16428
16551
|
|
|
16429
16552
|
return Promise.resolve(null);
|
|
@@ -16434,18 +16557,13 @@ class CheckFirmwareRelease extends BaseMethod {
|
|
|
16434
16557
|
class CheckBLEFirmwareRelease extends BaseMethod {
|
|
16435
16558
|
init() {
|
|
16436
16559
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
|
|
16560
|
+
this.checkDeviceId = true;
|
|
16437
16561
|
}
|
|
16438
16562
|
|
|
16439
16563
|
run() {
|
|
16440
16564
|
if (this.device.features) {
|
|
16441
|
-
const
|
|
16442
|
-
|
|
16443
|
-
const release = DataManager.getBleFirmwareLeatestRelease(this.device.features);
|
|
16444
|
-
return Promise.resolve({
|
|
16445
|
-
status: firmwareStatus,
|
|
16446
|
-
changelog,
|
|
16447
|
-
release
|
|
16448
|
-
});
|
|
16565
|
+
const releaseInfo = getBleFirmwareReleaseInfo(this.device.features);
|
|
16566
|
+
return Promise.resolve(releaseInfo);
|
|
16449
16567
|
}
|
|
16450
16568
|
|
|
16451
16569
|
return Promise.resolve(null);
|
|
@@ -16806,6 +16924,7 @@ class EvmGetAddress extends BaseMethod {
|
|
|
16806
16924
|
init() {
|
|
16807
16925
|
var _a;
|
|
16808
16926
|
|
|
16927
|
+
this.checkDeviceId = true;
|
|
16809
16928
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
16810
16929
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
16811
16930
|
const payload = this.hasBundle ? this.payload : {
|
|
@@ -16866,6 +16985,7 @@ class EVMGetPublicKey extends BaseMethod {
|
|
|
16866
16985
|
init() {
|
|
16867
16986
|
var _a;
|
|
16868
16987
|
|
|
16988
|
+
this.checkDeviceId = true;
|
|
16869
16989
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
16870
16990
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
16871
16991
|
const payload = this.hasBundle ? this.payload : {
|
|
@@ -16915,6 +17035,7 @@ class EVMGetPublicKey extends BaseMethod {
|
|
|
16915
17035
|
|
|
16916
17036
|
class EVMSignMessage$2 extends BaseMethod {
|
|
16917
17037
|
init() {
|
|
17038
|
+
this.checkDeviceId = true;
|
|
16918
17039
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
16919
17040
|
validateParams(this.payload, [{
|
|
16920
17041
|
name: 'path',
|
|
@@ -16946,6 +17067,7 @@ class EVMSignMessage$2 extends BaseMethod {
|
|
|
16946
17067
|
|
|
16947
17068
|
class EVMSignMessageEIP712 extends BaseMethod {
|
|
16948
17069
|
init() {
|
|
17070
|
+
this.checkDeviceId = true;
|
|
16949
17071
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
16950
17072
|
validateParams(this.payload, [{
|
|
16951
17073
|
name: 'path',
|
|
@@ -17109,6 +17231,7 @@ class EVMSignTransaction extends BaseMethod {
|
|
|
17109
17231
|
}
|
|
17110
17232
|
|
|
17111
17233
|
init() {
|
|
17234
|
+
this.checkDeviceId = true;
|
|
17112
17235
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
17113
17236
|
validateParams(this.payload, [{
|
|
17114
17237
|
name: 'path',
|
|
@@ -17350,6 +17473,7 @@ const getFieldType = (typeName, types) => {
|
|
|
17350
17473
|
|
|
17351
17474
|
class EVMSignTypedData extends BaseMethod {
|
|
17352
17475
|
init() {
|
|
17476
|
+
this.checkDeviceId = true;
|
|
17353
17477
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
17354
17478
|
validateParams(this.payload, [{
|
|
17355
17479
|
name: 'path',
|
|
@@ -17573,6 +17697,7 @@ class EVMSignTypedData extends BaseMethod {
|
|
|
17573
17697
|
|
|
17574
17698
|
class EVMSignMessage$1 extends BaseMethod {
|
|
17575
17699
|
init() {
|
|
17700
|
+
this.checkDeviceId = true;
|
|
17576
17701
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
17577
17702
|
validateParams(this.payload, [{
|
|
17578
17703
|
name: 'address',
|
|
@@ -17617,6 +17742,7 @@ class StarcoinGetAddress extends BaseMethod {
|
|
|
17617
17742
|
init() {
|
|
17618
17743
|
var _a;
|
|
17619
17744
|
|
|
17745
|
+
this.checkDeviceId = true;
|
|
17620
17746
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
17621
17747
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
17622
17748
|
const payload = this.hasBundle ? this.payload : {
|
|
@@ -17673,6 +17799,7 @@ class StarcoinGetPublicKey extends BaseMethod {
|
|
|
17673
17799
|
init() {
|
|
17674
17800
|
var _a;
|
|
17675
17801
|
|
|
17802
|
+
this.checkDeviceId = true;
|
|
17676
17803
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
17677
17804
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
17678
17805
|
const payload = this.hasBundle ? this.payload : {
|
|
@@ -17722,6 +17849,7 @@ class StarcoinGetPublicKey extends BaseMethod {
|
|
|
17722
17849
|
|
|
17723
17850
|
class StarcoinSignMessage extends BaseMethod {
|
|
17724
17851
|
init() {
|
|
17852
|
+
this.checkDeviceId = true;
|
|
17725
17853
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
17726
17854
|
validateParams(this.payload, [{
|
|
17727
17855
|
name: 'path',
|
|
@@ -17753,6 +17881,7 @@ class StarcoinSignMessage extends BaseMethod {
|
|
|
17753
17881
|
|
|
17754
17882
|
class StarcoinSignTransaction extends BaseMethod {
|
|
17755
17883
|
init() {
|
|
17884
|
+
this.checkDeviceId = true;
|
|
17756
17885
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
17757
17886
|
validateParams(this.payload, [{
|
|
17758
17887
|
name: 'path',
|
|
@@ -17784,6 +17913,7 @@ class StarcoinSignTransaction extends BaseMethod {
|
|
|
17784
17913
|
|
|
17785
17914
|
class EVMSignMessage extends BaseMethod {
|
|
17786
17915
|
init() {
|
|
17916
|
+
this.checkDeviceId = true;
|
|
17787
17917
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
17788
17918
|
validateParams(this.payload, [{
|
|
17789
17919
|
name: 'publicKey',
|
|
@@ -17830,6 +17960,7 @@ class NEMGetAddress extends BaseMethod {
|
|
|
17830
17960
|
init() {
|
|
17831
17961
|
var _a;
|
|
17832
17962
|
|
|
17963
|
+
this.checkDeviceId = true;
|
|
17833
17964
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
17834
17965
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
17835
17966
|
const payload = this.hasBundle ? this.payload : {
|
|
@@ -18083,6 +18214,7 @@ class NEMSignTransaction extends BaseMethod {
|
|
|
18083
18214
|
}
|
|
18084
18215
|
|
|
18085
18216
|
init() {
|
|
18217
|
+
this.checkDeviceId = true;
|
|
18086
18218
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
18087
18219
|
validateParams(this.payload, [{
|
|
18088
18220
|
name: 'path',
|
|
@@ -18118,6 +18250,7 @@ class SolGetAddress extends BaseMethod {
|
|
|
18118
18250
|
init() {
|
|
18119
18251
|
var _a;
|
|
18120
18252
|
|
|
18253
|
+
this.checkDeviceId = true;
|
|
18121
18254
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
18122
18255
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
18123
18256
|
const payload = this.hasBundle ? this.payload : {
|
|
@@ -18178,6 +18311,7 @@ class SolSignTransaction extends BaseMethod {
|
|
|
18178
18311
|
init() {
|
|
18179
18312
|
var _a;
|
|
18180
18313
|
|
|
18314
|
+
this.checkDeviceId = true;
|
|
18181
18315
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
18182
18316
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
18183
18317
|
const payload = this.hasBundle ? this.payload : {
|
|
@@ -18247,6 +18381,7 @@ class StellarGetAddress extends BaseMethod {
|
|
|
18247
18381
|
init() {
|
|
18248
18382
|
var _a;
|
|
18249
18383
|
|
|
18384
|
+
this.checkDeviceId = true;
|
|
18250
18385
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
18251
18386
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
18252
18387
|
const payload = this.hasBundle ? this.payload : {
|
|
@@ -18483,6 +18618,7 @@ class StellarSignTransaction extends BaseMethod {
|
|
|
18483
18618
|
}
|
|
18484
18619
|
|
|
18485
18620
|
init() {
|
|
18621
|
+
this.checkDeviceId = true;
|
|
18486
18622
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
18487
18623
|
validateParams(this.payload, [{
|
|
18488
18624
|
name: 'path',
|
|
@@ -18806,6 +18942,10 @@ function findMethod(message) {
|
|
|
18806
18942
|
const safeThrowError = error => {
|
|
18807
18943
|
if (error instanceof hdShared.HardwareError) {
|
|
18808
18944
|
throw error;
|
|
18945
|
+
} else if (error.code === 'ERR_NETWORK') {
|
|
18946
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNotInstalled);
|
|
18947
|
+
} else if (error.code === 'ECONNABORTED') {
|
|
18948
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
|
|
18809
18949
|
} else {
|
|
18810
18950
|
throw hdShared.ERRORS.TypedError(error);
|
|
18811
18951
|
}
|
|
@@ -18983,7 +19123,10 @@ let _uiPromises = [];
|
|
|
18983
19123
|
|
|
18984
19124
|
let _callPromise;
|
|
18985
19125
|
|
|
19126
|
+
const callApiQueue = [];
|
|
18986
19127
|
const deviceCacheMap = new Map();
|
|
19128
|
+
let pollingId = 1;
|
|
19129
|
+
const pollingState = {};
|
|
18987
19130
|
|
|
18988
19131
|
const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
|
|
18989
19132
|
var _a;
|
|
@@ -19015,31 +19158,32 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
19015
19158
|
}
|
|
19016
19159
|
}
|
|
19017
19160
|
|
|
19018
|
-
|
|
19019
|
-
|
|
19020
|
-
|
|
19021
|
-
|
|
19161
|
+
callApiQueue.push(method);
|
|
19162
|
+
|
|
19163
|
+
if (callApiQueue.length > 1) {
|
|
19164
|
+
Log.debug('should cancel the previous method execution: ', callApiQueue);
|
|
19022
19165
|
}
|
|
19023
19166
|
|
|
19024
|
-
|
|
19167
|
+
if (pollingState[pollingId]) {
|
|
19168
|
+
pollingState[pollingId] = false;
|
|
19169
|
+
}
|
|
19170
|
+
|
|
19171
|
+
pollingId += 1;
|
|
19025
19172
|
let device;
|
|
19026
19173
|
|
|
19027
19174
|
try {
|
|
19028
|
-
|
|
19029
|
-
|
|
19030
|
-
|
|
19031
|
-
|
|
19032
|
-
}
|
|
19033
|
-
} catch (error) {
|
|
19034
|
-
return Promise.reject(error);
|
|
19175
|
+
device = yield ensureConnected(method, pollingId);
|
|
19176
|
+
} catch (e) {
|
|
19177
|
+
return createResponseMessage(method.responseID, false, {
|
|
19178
|
+
error: e
|
|
19179
|
+
});
|
|
19035
19180
|
}
|
|
19036
19181
|
|
|
19037
19182
|
Log.debug('Call API - setDevice: ', device.mainId);
|
|
19038
19183
|
(_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
|
|
19039
19184
|
device.on(DEVICE.PIN, onDevicePinHandler);
|
|
19040
|
-
device.on(DEVICE.BUTTON,
|
|
19041
|
-
|
|
19042
|
-
});
|
|
19185
|
+
device.on(DEVICE.BUTTON, onDeviceButtonHandler);
|
|
19186
|
+
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
19043
19187
|
|
|
19044
19188
|
try {
|
|
19045
19189
|
const inner = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -19071,6 +19215,16 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
19071
19215
|
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceUnexpectedMode, unexpectedMode));
|
|
19072
19216
|
}
|
|
19073
19217
|
|
|
19218
|
+
if (method.deviceId && method.checkDeviceId) {
|
|
19219
|
+
const isSameDeviceID = device.checkDeviceId(method.deviceId);
|
|
19220
|
+
|
|
19221
|
+
if (!isSameDeviceID) {
|
|
19222
|
+
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckDeviceIdError));
|
|
19223
|
+
}
|
|
19224
|
+
}
|
|
19225
|
+
|
|
19226
|
+
method.checkFirmwareRelease();
|
|
19227
|
+
|
|
19074
19228
|
if (_deviceList) {
|
|
19075
19229
|
yield TransportManager.reconfigure(device.getFirmwareVersion());
|
|
19076
19230
|
}
|
|
@@ -19118,8 +19272,16 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
19118
19272
|
}
|
|
19119
19273
|
}
|
|
19120
19274
|
|
|
19275
|
+
const index = messageResponse && messageResponse.id ? callApiQueue.findIndex(m => m.responseID === messageResponse.id) : -1;
|
|
19276
|
+
|
|
19277
|
+
if (index > -1) {
|
|
19278
|
+
callApiQueue.splice(index, 1);
|
|
19279
|
+
Log.debug('Remove the finished method from the queue: ', callApiQueue);
|
|
19280
|
+
}
|
|
19281
|
+
|
|
19121
19282
|
closePopup();
|
|
19122
19283
|
cleanup();
|
|
19284
|
+
removeDeviceListener(device);
|
|
19123
19285
|
}
|
|
19124
19286
|
});
|
|
19125
19287
|
|
|
@@ -19138,7 +19300,7 @@ function initDeviceList(method) {
|
|
|
19138
19300
|
_deviceList.connector = _connector;
|
|
19139
19301
|
}
|
|
19140
19302
|
|
|
19141
|
-
yield _deviceList.getDeviceLists();
|
|
19303
|
+
yield _deviceList.getDeviceLists(method.connectId);
|
|
19142
19304
|
});
|
|
19143
19305
|
}
|
|
19144
19306
|
|
|
@@ -19191,23 +19353,119 @@ function initDeviceForBle(method) {
|
|
|
19191
19353
|
return device;
|
|
19192
19354
|
}
|
|
19193
19355
|
|
|
19356
|
+
const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19357
|
+
let tryCount = 0;
|
|
19358
|
+
const MAX_RETRY_COUNT = method.payload && method.payload.retryCount || 5;
|
|
19359
|
+
const POLL_INTERVAL_TIME = method.payload && method.payload.pollIntervalTime || 1000;
|
|
19360
|
+
const TIME_OUT = method.payload && method.payload.timeout || 10000;
|
|
19361
|
+
let timer = null;
|
|
19362
|
+
Log.debug(`EnsureConnected function start, MAX_RETRY_COUNT=${MAX_RETRY_COUNT}, POLL_INTERVAL_TIME=${POLL_INTERVAL_TIME} `);
|
|
19363
|
+
|
|
19364
|
+
const poll = (time = POLL_INTERVAL_TIME) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19365
|
+
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19366
|
+
if (!pollingState[pollingId]) {
|
|
19367
|
+
Log.debug('EnsureConnected function stop, polling id: ', pollingId);
|
|
19368
|
+
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PollingStop));
|
|
19369
|
+
return;
|
|
19370
|
+
}
|
|
19371
|
+
|
|
19372
|
+
if (timer) {
|
|
19373
|
+
clearTimeout(timer);
|
|
19374
|
+
}
|
|
19375
|
+
|
|
19376
|
+
timer = setTimeout(() => {
|
|
19377
|
+
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PollingTimeout));
|
|
19378
|
+
}, TIME_OUT);
|
|
19379
|
+
tryCount += 1;
|
|
19380
|
+
Log.debug('EnsureConnected function try count: ', tryCount, ' poll interval time: ', time);
|
|
19381
|
+
|
|
19382
|
+
try {
|
|
19383
|
+
yield initDeviceList(method);
|
|
19384
|
+
} catch (error) {
|
|
19385
|
+
Log.debug('device list error: ', error);
|
|
19386
|
+
|
|
19387
|
+
if ([hdShared.HardwareErrorCode.BridgeNotInstalled, hdShared.HardwareErrorCode.BridgeTimeoutError].includes(error.errorCode)) {
|
|
19388
|
+
_deviceList = undefined;
|
|
19389
|
+
reject(error);
|
|
19390
|
+
return;
|
|
19391
|
+
}
|
|
19392
|
+
|
|
19393
|
+
if (error.errorCode === hdShared.HardwareErrorCode.TransportNotConfigured) {
|
|
19394
|
+
yield TransportManager.configure();
|
|
19395
|
+
}
|
|
19396
|
+
}
|
|
19397
|
+
|
|
19398
|
+
const env = DataManager.getSettings('env');
|
|
19399
|
+
let device;
|
|
19400
|
+
|
|
19401
|
+
try {
|
|
19402
|
+
if (env === 'react-native') {
|
|
19403
|
+
device = initDeviceForBle(method);
|
|
19404
|
+
} else {
|
|
19405
|
+
device = initDevice(method);
|
|
19406
|
+
}
|
|
19407
|
+
|
|
19408
|
+
if (device) {
|
|
19409
|
+
if (timer) {
|
|
19410
|
+
clearTimeout(timer);
|
|
19411
|
+
}
|
|
19412
|
+
|
|
19413
|
+
if (env === 'react-native') {
|
|
19414
|
+
yield device.acquire();
|
|
19415
|
+
yield device.initialize();
|
|
19416
|
+
}
|
|
19417
|
+
|
|
19418
|
+
resolve(device);
|
|
19419
|
+
return;
|
|
19420
|
+
}
|
|
19421
|
+
} catch (error) {
|
|
19422
|
+
Log.debug('device error: ', error);
|
|
19423
|
+
|
|
19424
|
+
if (error.errorCode === hdShared.HardwareErrorCode.BlePermissionError) {
|
|
19425
|
+
reject(error);
|
|
19426
|
+
return;
|
|
19427
|
+
}
|
|
19428
|
+
}
|
|
19429
|
+
|
|
19430
|
+
if (tryCount > 5) {
|
|
19431
|
+
if (timer) {
|
|
19432
|
+
clearTimeout(timer);
|
|
19433
|
+
}
|
|
19434
|
+
|
|
19435
|
+
Log.debug('EnsureConnected get to max try count, will return: ', tryCount);
|
|
19436
|
+
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound));
|
|
19437
|
+
return;
|
|
19438
|
+
}
|
|
19439
|
+
|
|
19440
|
+
return setTimeout(() => resolve(poll(time * 1.5)), time);
|
|
19441
|
+
}));
|
|
19442
|
+
});
|
|
19443
|
+
|
|
19444
|
+
pollingState[pollingId] = true;
|
|
19445
|
+
return poll();
|
|
19446
|
+
});
|
|
19447
|
+
|
|
19194
19448
|
const cancel = connectId => {
|
|
19195
19449
|
const env = DataManager.getSettings('env');
|
|
19196
19450
|
|
|
19197
|
-
|
|
19198
|
-
|
|
19451
|
+
try {
|
|
19452
|
+
if (connectId) {
|
|
19453
|
+
let device;
|
|
19199
19454
|
|
|
19200
|
-
|
|
19201
|
-
|
|
19202
|
-
|
|
19203
|
-
|
|
19204
|
-
|
|
19205
|
-
|
|
19206
|
-
|
|
19207
|
-
|
|
19208
|
-
|
|
19455
|
+
if (env === 'react-native') {
|
|
19456
|
+
device = initDeviceForBle({
|
|
19457
|
+
connectId
|
|
19458
|
+
});
|
|
19459
|
+
} else {
|
|
19460
|
+
device = initDevice({
|
|
19461
|
+
connectId
|
|
19462
|
+
});
|
|
19463
|
+
}
|
|
19209
19464
|
|
|
19210
|
-
|
|
19465
|
+
device === null || device === void 0 ? void 0 : device.interruptionFromUser();
|
|
19466
|
+
}
|
|
19467
|
+
} catch (e) {
|
|
19468
|
+
Log.error('Cancel API Error: ', e);
|
|
19211
19469
|
}
|
|
19212
19470
|
|
|
19213
19471
|
cleanup();
|
|
@@ -19219,6 +19477,12 @@ const cleanup = () => {
|
|
|
19219
19477
|
Log.debug('Cleanup...');
|
|
19220
19478
|
};
|
|
19221
19479
|
|
|
19480
|
+
const removeDeviceListener = device => {
|
|
19481
|
+
device.removeListener(DEVICE.PIN, onDevicePinHandler);
|
|
19482
|
+
device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler);
|
|
19483
|
+
device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
19484
|
+
};
|
|
19485
|
+
|
|
19222
19486
|
const closePopup = () => {
|
|
19223
19487
|
postMessage(createUiMessage(UI_REQUEST$1.CLOSE_UI_WINDOW));
|
|
19224
19488
|
};
|
|
@@ -19251,6 +19515,10 @@ const onDeviceButtonHandler = (...[device, request]) => {
|
|
|
19251
19515
|
}
|
|
19252
19516
|
};
|
|
19253
19517
|
|
|
19518
|
+
const onDeviceFeaturesHandler = (...[_, features]) => {
|
|
19519
|
+
postMessage(createDeviceMessage(DEVICE.FEATURES, Object.assign({}, features)));
|
|
19520
|
+
};
|
|
19521
|
+
|
|
19254
19522
|
const postMessage = message => {
|
|
19255
19523
|
_core.emit(CORE_EVENT, message);
|
|
19256
19524
|
};
|
|
@@ -19375,9 +19643,11 @@ __webpack_unused_export__ = ({
|
|
|
19375
19643
|
__webpack_unused_export__ = CORE_EVENT;
|
|
19376
19644
|
__webpack_unused_export__ = Core;
|
|
19377
19645
|
__webpack_unused_export__ = DEFAULT_PRIORITY;
|
|
19378
|
-
|
|
19379
|
-
|
|
19646
|
+
exports.Td = DEVICE;
|
|
19647
|
+
exports.Fd = DEVICE_EVENT;
|
|
19380
19648
|
__webpack_unused_export__ = DataManager;
|
|
19649
|
+
__webpack_unused_export__ = FIRMWARE;
|
|
19650
|
+
exports.SI = FIRMWARE_EVENT;
|
|
19381
19651
|
exports.Bg = IFRAME;
|
|
19382
19652
|
__webpack_unused_export__ = LOG;
|
|
19383
19653
|
exports.og = LOG_EVENT;
|
|
@@ -19388,6 +19658,7 @@ __webpack_unused_export__ = UI_RESPONSE;
|
|
|
19388
19658
|
__webpack_unused_export__ = corsValidator;
|
|
19389
19659
|
__webpack_unused_export__ = createDeviceMessage;
|
|
19390
19660
|
exports.xG = createErrorMessage;
|
|
19661
|
+
__webpack_unused_export__ = createFirmwareMessage;
|
|
19391
19662
|
__webpack_unused_export__ = createIFrameMessage;
|
|
19392
19663
|
__webpack_unused_export__ = createLogMessage;
|
|
19393
19664
|
__webpack_unused_export__ = createResponseMessage;
|
|
@@ -20568,6 +20839,8 @@ const HardwareErrorCode = {
|
|
|
20568
20839
|
DeviceInitializeFailed: 106,
|
|
20569
20840
|
DeviceInterruptedFromOutside: 107,
|
|
20570
20841
|
DeviceUnexpectedBootloaderMode: 108,
|
|
20842
|
+
DeviceInterruptedFromUser: 109,
|
|
20843
|
+
DeviceCheckDeviceIdError: 110,
|
|
20571
20844
|
NotInitialized: 200,
|
|
20572
20845
|
IFrameNotInitialized: 300,
|
|
20573
20846
|
IFrameAleradyInitialized: 301,
|
|
@@ -20600,7 +20873,10 @@ const HardwareErrorCode = {
|
|
|
20600
20873
|
FirmwareError: 804,
|
|
20601
20874
|
ResponseUnexpectTypeError: 805,
|
|
20602
20875
|
BridgeNetworkError: 806,
|
|
20603
|
-
BridgeTimeoutError: 807
|
|
20876
|
+
BridgeTimeoutError: 807,
|
|
20877
|
+
BridgeNotInstalled: 808,
|
|
20878
|
+
PollingTimeout: 809,
|
|
20879
|
+
PollingStop: 810
|
|
20604
20880
|
};
|
|
20605
20881
|
const HardwareErrorCodeMessage = {
|
|
20606
20882
|
[HardwareErrorCode.UnknownError]: 'Unknown error occurred. Check message property.',
|
|
@@ -20611,7 +20887,9 @@ const HardwareErrorCodeMessage = {
|
|
|
20611
20887
|
[HardwareErrorCode.DeviceNotFound]: 'Device not found',
|
|
20612
20888
|
[HardwareErrorCode.DeviceInitializeFailed]: 'Device initialization failed',
|
|
20613
20889
|
[HardwareErrorCode.DeviceInterruptedFromOutside]: 'Device interrupted',
|
|
20890
|
+
[HardwareErrorCode.DeviceInterruptedFromUser]: 'Device interrupted',
|
|
20614
20891
|
[HardwareErrorCode.DeviceUnexpectedBootloaderMode]: 'Device should be in bootloader mode',
|
|
20892
|
+
[HardwareErrorCode.DeviceCheckDeviceIdError]: 'Device Id in the features is not same.',
|
|
20615
20893
|
[HardwareErrorCode.NotInitialized]: 'Not initialized',
|
|
20616
20894
|
[HardwareErrorCode.IFrameNotInitialized]: 'IFrame not initialized',
|
|
20617
20895
|
[HardwareErrorCode.IFrameAleradyInitialized]: 'IFrame alerady initialized',
|
|
@@ -20644,7 +20922,10 @@ const HardwareErrorCodeMessage = {
|
|
|
20644
20922
|
[HardwareErrorCode.FirmwareError]: 'Firmware installation failed',
|
|
20645
20923
|
[HardwareErrorCode.ResponseUnexpectTypeError]: 'Response type is not expected',
|
|
20646
20924
|
[HardwareErrorCode.BridgeNetworkError]: 'Bridge network error',
|
|
20647
|
-
[HardwareErrorCode.BridgeTimeoutError]: 'Bridge network timeout'
|
|
20925
|
+
[HardwareErrorCode.BridgeTimeoutError]: 'Bridge network timeout',
|
|
20926
|
+
[HardwareErrorCode.BridgeNotInstalled]: 'Bridge not installed',
|
|
20927
|
+
[HardwareErrorCode.PollingTimeout]: 'Polling timeout',
|
|
20928
|
+
[HardwareErrorCode.PollingStop]: 'Polling stop'
|
|
20648
20929
|
};
|
|
20649
20930
|
|
|
20650
20931
|
const TypedError = (hardwareError, message) => {
|
|
@@ -45776,9 +46057,17 @@ const handleMessage = async message => {
|
|
|
45776
46057
|
break;
|
|
45777
46058
|
|
|
45778
46059
|
case dist/* LOG_EVENT */.og:
|
|
46060
|
+
case dist/* FIRMWARE_EVENT */.SI:
|
|
45779
46061
|
eventEmitter.emit(message.event, message);
|
|
45780
46062
|
break;
|
|
45781
46063
|
|
|
46064
|
+
case dist/* DEVICE_EVENT */.Fd:
|
|
46065
|
+
if (message.type === dist/* DEVICE.FEATURES */.Td.FEATURES) {
|
|
46066
|
+
eventEmitter.emit(message.type, message.payload);
|
|
46067
|
+
}
|
|
46068
|
+
|
|
46069
|
+
break;
|
|
46070
|
+
|
|
45782
46071
|
default:
|
|
45783
46072
|
src_Log.log('No need to be captured message', message.event);
|
|
45784
46073
|
}
|
|
@@ -45867,7 +46156,7 @@ const src_init = async settings => {
|
|
|
45867
46156
|
|
|
45868
46157
|
try {
|
|
45869
46158
|
await init({ ..._settings,
|
|
45870
|
-
version: "0.1.
|
|
46159
|
+
version: "0.1.20"
|
|
45871
46160
|
});
|
|
45872
46161
|
return true;
|
|
45873
46162
|
} catch (e) {
|