@onekeyfe/hd-web-sdk 0.1.27 → 0.1.30
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.79fb007e34c359a6326e.js +3 -0
- package/build/js/{iframe.018b08d876d5a3fcfde7.js.LICENSE.txt → iframe.79fb007e34c359a6326e.js.LICENSE.txt} +0 -0
- package/build/js/iframe.79fb007e34c359a6326e.js.map +1 -0
- package/build/onekey-js-sdk.js +519 -256
- 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/iframe/builder.d.ts.map +1 -1
- package/dist/iframe/builder.js +3 -0
- package/dist/iframe/builder.js.map +1 -1
- package/dist/iframe/index.d.ts.map +1 -1
- package/dist/iframe/index.js +3 -1
- package/dist/iframe/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
- package/src/iframe/builder.ts +3 -0
- package/src/iframe/index.ts +3 -1
- package/src/index.ts +7 -4
- package/build/js/iframe.018b08d876d5a3fcfde7.js +0 -3
- package/build/js/iframe.018b08d876d5a3fcfde7.js.map +0 -1
package/build/onekey-js-sdk.js
CHANGED
|
@@ -4263,7 +4263,10 @@ const inject = ({
|
|
|
4263
4263
|
firmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4264
4264
|
connectId,
|
|
4265
4265
|
method: 'firmwareUpdate'
|
|
4266
|
-
}))
|
|
4266
|
+
})),
|
|
4267
|
+
requestWebUsbDevice: () => call({
|
|
4268
|
+
method: 'requestWebUsbDevice'
|
|
4269
|
+
})
|
|
4267
4270
|
};
|
|
4268
4271
|
return api;
|
|
4269
4272
|
};
|
|
@@ -13827,7 +13830,7 @@ const createLogMessage = (type, payload) => ({
|
|
|
13827
13830
|
const MAX_ENTRIES = 500;
|
|
13828
13831
|
let postMessage$1;
|
|
13829
13832
|
|
|
13830
|
-
class Log$
|
|
13833
|
+
class Log$7 {
|
|
13831
13834
|
constructor(prefix, enabled) {
|
|
13832
13835
|
this.prefix = prefix;
|
|
13833
13836
|
this.enabled = enabled;
|
|
@@ -13896,7 +13899,7 @@ class Log$6 {
|
|
|
13896
13899
|
const _logs = {};
|
|
13897
13900
|
|
|
13898
13901
|
const initLog = (prefix, enabled) => {
|
|
13899
|
-
const instance = new Log$
|
|
13902
|
+
const instance = new Log$7(prefix, !!enabled);
|
|
13900
13903
|
_logs[prefix] = instance;
|
|
13901
13904
|
return instance;
|
|
13902
13905
|
};
|
|
@@ -13972,6 +13975,8 @@ exports.d0 = void 0;
|
|
|
13972
13975
|
LoggerNames["DeviceCommands"] = "DeviceCommands";
|
|
13973
13976
|
LoggerNames["DeviceConnector"] = "DeviceConnector";
|
|
13974
13977
|
LoggerNames["DeviceList"] = "DeviceList";
|
|
13978
|
+
LoggerNames["DevicePool"] = "DevicePool";
|
|
13979
|
+
LoggerNames["HdCommonConnectSdk"] = "@onekey/common-connect-sdk";
|
|
13975
13980
|
LoggerNames["HdBleSdk"] = "@onekey/hd-ble-sdk";
|
|
13976
13981
|
LoggerNames["HdTransportHttp"] = "@onekey/hd-transport-http";
|
|
13977
13982
|
LoggerNames["HdBleTransport"] = "@onekey/hd-ble-transport";
|
|
@@ -13988,13 +13993,15 @@ const LoggerMap = {
|
|
|
13988
13993
|
[exports.d0.DeviceCommands]: initLog(exports.d0.DeviceCommands),
|
|
13989
13994
|
[exports.d0.DeviceConnector]: initLog(exports.d0.DeviceConnector),
|
|
13990
13995
|
[exports.d0.DeviceList]: initLog(exports.d0.DeviceList),
|
|
13996
|
+
[exports.d0.DevicePool]: initLog(exports.d0.DevicePool),
|
|
13991
13997
|
[exports.d0.HdBleSdk]: initLog(exports.d0.HdBleSdk),
|
|
13992
13998
|
[exports.d0.HdTransportHttp]: initLog(exports.d0.HdTransportHttp),
|
|
13993
13999
|
[exports.d0.HdBleTransport]: initLog(exports.d0.HdBleTransport),
|
|
13994
14000
|
[exports.d0.Connect]: initLog(exports.d0.Connect),
|
|
13995
14001
|
[exports.d0.Iframe]: initLog(exports.d0.Iframe),
|
|
13996
14002
|
[exports.d0.SendMessage]: initLog(exports.d0.SendMessage),
|
|
13997
|
-
[exports.d0.Method]: initLog(exports.d0.Method)
|
|
14003
|
+
[exports.d0.Method]: initLog(exports.d0.Method),
|
|
14004
|
+
[exports.d0.HdCommonConnectSdk]: initLog(exports.d0.Method)
|
|
13998
14005
|
};
|
|
13999
14006
|
|
|
14000
14007
|
const getLogger = key => LoggerMap[key];
|
|
@@ -14171,95 +14178,6 @@ DataManager.getTransportStatus = localVersion => {
|
|
|
14171
14178
|
return isLatest ? 'valid' : 'outdated';
|
|
14172
14179
|
};
|
|
14173
14180
|
|
|
14174
|
-
const Log$5 = getLogger(exports.d0.Transport);
|
|
14175
|
-
const BleLogger = getLogger(exports.d0.HdBleTransport);
|
|
14176
|
-
const HttpLogger = getLogger(exports.d0.HdTransportHttp);
|
|
14177
|
-
|
|
14178
|
-
class TransportManager {
|
|
14179
|
-
static load() {
|
|
14180
|
-
Log$5.debug('transport manager load');
|
|
14181
|
-
this.defaultMessages = DataManager.getProtobufMessages();
|
|
14182
|
-
this.currentMessages = this.defaultMessages;
|
|
14183
|
-
}
|
|
14184
|
-
|
|
14185
|
-
static configure() {
|
|
14186
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
14187
|
-
try {
|
|
14188
|
-
const env = DataManager.getSettings('env');
|
|
14189
|
-
Log$5.debug('Initializing transports');
|
|
14190
|
-
|
|
14191
|
-
if (env === 'react-native') {
|
|
14192
|
-
if (!this.reactNativeInit) {
|
|
14193
|
-
yield this.transport.init(BleLogger);
|
|
14194
|
-
this.reactNativeInit = true;
|
|
14195
|
-
} else {
|
|
14196
|
-
Log$5.debug('React Native Do Not Initializing transports');
|
|
14197
|
-
}
|
|
14198
|
-
} else {
|
|
14199
|
-
yield this.transport.init(HttpLogger);
|
|
14200
|
-
}
|
|
14201
|
-
|
|
14202
|
-
Log$5.debug('Configuring transports');
|
|
14203
|
-
yield this.transport.configure(JSON.stringify(this.defaultMessages));
|
|
14204
|
-
Log$5.debug('Configuring transports done');
|
|
14205
|
-
} catch (error) {
|
|
14206
|
-
Log$5.debug('Initializing transports error: ', error);
|
|
14207
|
-
|
|
14208
|
-
if (error.code === 'ECONNABORTED') {
|
|
14209
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
|
|
14210
|
-
}
|
|
14211
|
-
}
|
|
14212
|
-
});
|
|
14213
|
-
}
|
|
14214
|
-
|
|
14215
|
-
static reconfigure(messages) {
|
|
14216
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
14217
|
-
if (Array.isArray(messages)) {
|
|
14218
|
-
messages = DataManager.getProtobufMessages();
|
|
14219
|
-
}
|
|
14220
|
-
|
|
14221
|
-
if (this.currentMessages === messages || !messages) {
|
|
14222
|
-
return;
|
|
14223
|
-
}
|
|
14224
|
-
|
|
14225
|
-
try {
|
|
14226
|
-
yield this.transport.configure(JSON.stringify(messages));
|
|
14227
|
-
this.currentMessages = messages;
|
|
14228
|
-
} catch (error) {
|
|
14229
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportInvalidProtobuf, `Transport_InvalidProtobuf: ${error.message}`);
|
|
14230
|
-
}
|
|
14231
|
-
});
|
|
14232
|
-
}
|
|
14233
|
-
|
|
14234
|
-
static setTransport(TransportConstructor) {
|
|
14235
|
-
const env = DataManager.getSettings('env');
|
|
14236
|
-
|
|
14237
|
-
if (env === 'react-native') {
|
|
14238
|
-
this.transport = new TransportConstructor({
|
|
14239
|
-
scanTimeout: 3000
|
|
14240
|
-
});
|
|
14241
|
-
} else {
|
|
14242
|
-
this.transport = new TransportConstructor();
|
|
14243
|
-
}
|
|
14244
|
-
|
|
14245
|
-
Log$5.debug('set transport: ', this.transport);
|
|
14246
|
-
}
|
|
14247
|
-
|
|
14248
|
-
static getTransport() {
|
|
14249
|
-
return this.transport;
|
|
14250
|
-
}
|
|
14251
|
-
|
|
14252
|
-
static getDefaultMessages() {
|
|
14253
|
-
return this.defaultMessages;
|
|
14254
|
-
}
|
|
14255
|
-
|
|
14256
|
-
static getCurrentMessages() {
|
|
14257
|
-
return this.currentMessages;
|
|
14258
|
-
}
|
|
14259
|
-
|
|
14260
|
-
}
|
|
14261
|
-
|
|
14262
|
-
TransportManager.reactNativeInit = false;
|
|
14263
14181
|
const CORE_EVENT = 'CORE_EVENT';
|
|
14264
14182
|
|
|
14265
14183
|
const parseMessage = messageData => {
|
|
@@ -14393,6 +14311,348 @@ const createFirmwareMessage = (type, payload) => ({
|
|
|
14393
14311
|
payload
|
|
14394
14312
|
});
|
|
14395
14313
|
|
|
14314
|
+
const Log$6 = getLogger(exports.d0.DevicePool);
|
|
14315
|
+
|
|
14316
|
+
const getDiff = (current, descriptors) => {
|
|
14317
|
+
const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
|
|
14318
|
+
const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
|
|
14319
|
+
const changedSessions = descriptors.filter(d => {
|
|
14320
|
+
const currentDescriptor = current.find(x => x.path === d.path);
|
|
14321
|
+
|
|
14322
|
+
if (currentDescriptor) {
|
|
14323
|
+
return currentDescriptor.session !== d.session;
|
|
14324
|
+
}
|
|
14325
|
+
|
|
14326
|
+
return false;
|
|
14327
|
+
});
|
|
14328
|
+
const acquired = changedSessions.filter(d => typeof d.session === 'string');
|
|
14329
|
+
const released = changedSessions.filter(d => typeof d.session !== 'string');
|
|
14330
|
+
const changedDebugSessions = descriptors.filter(d => {
|
|
14331
|
+
const currentDescriptor = current.find(x => x.path === d.path);
|
|
14332
|
+
|
|
14333
|
+
if (currentDescriptor) {
|
|
14334
|
+
return currentDescriptor.debugSession !== d.debugSession;
|
|
14335
|
+
}
|
|
14336
|
+
|
|
14337
|
+
return false;
|
|
14338
|
+
});
|
|
14339
|
+
const debugAcquired = changedSessions.filter(d => typeof d.debugSession === 'string');
|
|
14340
|
+
const debugReleased = changedSessions.filter(d => typeof d.debugSession !== 'string');
|
|
14341
|
+
const didUpdate = connected.length + disconnected.length + changedSessions.length + changedDebugSessions.length > 0;
|
|
14342
|
+
return {
|
|
14343
|
+
connected,
|
|
14344
|
+
disconnected,
|
|
14345
|
+
changedSessions,
|
|
14346
|
+
acquired,
|
|
14347
|
+
released,
|
|
14348
|
+
changedDebugSessions,
|
|
14349
|
+
debugAcquired,
|
|
14350
|
+
debugReleased,
|
|
14351
|
+
didUpdate,
|
|
14352
|
+
descriptors
|
|
14353
|
+
};
|
|
14354
|
+
};
|
|
14355
|
+
|
|
14356
|
+
class DevicePool extends events.exports {
|
|
14357
|
+
static setConnector(connector) {
|
|
14358
|
+
this.connector = connector;
|
|
14359
|
+
}
|
|
14360
|
+
|
|
14361
|
+
static getDevices(descriptorList, connectId) {
|
|
14362
|
+
var descriptorList_1, descriptorList_1_1;
|
|
14363
|
+
|
|
14364
|
+
var e_1, _a;
|
|
14365
|
+
|
|
14366
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14367
|
+
Log$6.debug('get device list');
|
|
14368
|
+
const devices = {};
|
|
14369
|
+
const deviceList = [];
|
|
14370
|
+
|
|
14371
|
+
if (connectId) {
|
|
14372
|
+
const device = this.devicesCache[connectId];
|
|
14373
|
+
|
|
14374
|
+
if (device) {
|
|
14375
|
+
const exist = descriptorList.find(d => d.path === device.originalDescriptor.path);
|
|
14376
|
+
|
|
14377
|
+
if (exist) {
|
|
14378
|
+
Log$6.debug('find existed Device: ', connectId);
|
|
14379
|
+
device.updateDescriptor(exist, true);
|
|
14380
|
+
devices[connectId] = device;
|
|
14381
|
+
deviceList.push(device);
|
|
14382
|
+
yield this._checkDevicePool();
|
|
14383
|
+
return {
|
|
14384
|
+
devices,
|
|
14385
|
+
deviceList
|
|
14386
|
+
};
|
|
14387
|
+
}
|
|
14388
|
+
|
|
14389
|
+
Log$6.debug('found device in cache, but path is different: ', connectId);
|
|
14390
|
+
}
|
|
14391
|
+
}
|
|
14392
|
+
|
|
14393
|
+
try {
|
|
14394
|
+
for (descriptorList_1 = __asyncValues(descriptorList); descriptorList_1_1 = yield descriptorList_1.next(), !descriptorList_1_1.done;) {
|
|
14395
|
+
const descriptor = descriptorList_1_1.value;
|
|
14396
|
+
const device = yield this._createDevice(descriptor);
|
|
14397
|
+
|
|
14398
|
+
if (device.features) {
|
|
14399
|
+
const uuid = getDeviceUUID(device.features);
|
|
14400
|
+
|
|
14401
|
+
if (this.devicesCache[uuid]) {
|
|
14402
|
+
const cache = this.devicesCache[uuid];
|
|
14403
|
+
cache.updateDescriptor(descriptor, true);
|
|
14404
|
+
}
|
|
14405
|
+
|
|
14406
|
+
this.devicesCache[uuid] = device;
|
|
14407
|
+
devices[uuid] = device;
|
|
14408
|
+
}
|
|
14409
|
+
|
|
14410
|
+
deviceList.push(device);
|
|
14411
|
+
}
|
|
14412
|
+
} catch (e_1_1) {
|
|
14413
|
+
e_1 = {
|
|
14414
|
+
error: e_1_1
|
|
14415
|
+
};
|
|
14416
|
+
} finally {
|
|
14417
|
+
try {
|
|
14418
|
+
if (descriptorList_1_1 && !descriptorList_1_1.done && (_a = descriptorList_1.return)) yield _a.call(descriptorList_1);
|
|
14419
|
+
} finally {
|
|
14420
|
+
if (e_1) throw e_1.error;
|
|
14421
|
+
}
|
|
14422
|
+
}
|
|
14423
|
+
|
|
14424
|
+
Log$6.debug('get devices result : ', devices, deviceList);
|
|
14425
|
+
console.log('device poll -> connected: ', this.connectedPool);
|
|
14426
|
+
console.log('device poll -> disconnected: ', this.disconnectPool);
|
|
14427
|
+
yield this._checkDevicePool();
|
|
14428
|
+
return {
|
|
14429
|
+
devices,
|
|
14430
|
+
deviceList
|
|
14431
|
+
};
|
|
14432
|
+
});
|
|
14433
|
+
}
|
|
14434
|
+
|
|
14435
|
+
static _createDevice(descriptor) {
|
|
14436
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14437
|
+
let device = this.getDeviceByPath(descriptor.path);
|
|
14438
|
+
|
|
14439
|
+
if (!device) {
|
|
14440
|
+
device = Device.fromDescriptor(descriptor);
|
|
14441
|
+
device.deviceConnector = this.connector;
|
|
14442
|
+
yield device.connect();
|
|
14443
|
+
yield device.initialize();
|
|
14444
|
+
yield device.release();
|
|
14445
|
+
}
|
|
14446
|
+
|
|
14447
|
+
return device;
|
|
14448
|
+
});
|
|
14449
|
+
}
|
|
14450
|
+
|
|
14451
|
+
static _checkDevicePool() {
|
|
14452
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14453
|
+
yield this._sendConnectMessage();
|
|
14454
|
+
|
|
14455
|
+
this._sendDisconnectMessage();
|
|
14456
|
+
});
|
|
14457
|
+
}
|
|
14458
|
+
|
|
14459
|
+
static _sendConnectMessage() {
|
|
14460
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14461
|
+
for (let i = this.connectedPool.length - 1; i >= 0; i--) {
|
|
14462
|
+
const descriptor = this.connectedPool[i];
|
|
14463
|
+
const device = yield this._createDevice(descriptor);
|
|
14464
|
+
Log$6.debug('emit DEVICE.CONNECT: ', device);
|
|
14465
|
+
this.emitter.emit(DEVICE.CONNECT, device);
|
|
14466
|
+
this.connectedPool.splice(i, 1);
|
|
14467
|
+
}
|
|
14468
|
+
});
|
|
14469
|
+
}
|
|
14470
|
+
|
|
14471
|
+
static _sendDisconnectMessage() {
|
|
14472
|
+
for (let i = this.disconnectPool.length - 1; i >= 0; i--) {
|
|
14473
|
+
const descriptor = this.connectedPool[i];
|
|
14474
|
+
const device = this.getDeviceByPath(descriptor.path);
|
|
14475
|
+
|
|
14476
|
+
if (device) {
|
|
14477
|
+
this.emitter.emit(DEVICE.DISCONNECT, device);
|
|
14478
|
+
}
|
|
14479
|
+
|
|
14480
|
+
this.disconnectPool.splice(i, 1);
|
|
14481
|
+
}
|
|
14482
|
+
}
|
|
14483
|
+
|
|
14484
|
+
static reportDeviceChange(upcoming) {
|
|
14485
|
+
const diff = getDiff(this.current || [], upcoming);
|
|
14486
|
+
this.upcoming = upcoming;
|
|
14487
|
+
this.current = this.upcoming;
|
|
14488
|
+
console.log('device pool -> current: ', this.current);
|
|
14489
|
+
console.log('device pool -> upcomming: ', this.upcoming);
|
|
14490
|
+
console.log('DeviceCache.reportDeviceChange diff: ', diff);
|
|
14491
|
+
|
|
14492
|
+
if (!diff.didUpdate) {
|
|
14493
|
+
return;
|
|
14494
|
+
}
|
|
14495
|
+
|
|
14496
|
+
diff.connected.forEach(d => {
|
|
14497
|
+
const device = this.getDeviceByPath(d.path);
|
|
14498
|
+
|
|
14499
|
+
if (!device) {
|
|
14500
|
+
this._addConnectedDeviceToPool(d);
|
|
14501
|
+
|
|
14502
|
+
return;
|
|
14503
|
+
}
|
|
14504
|
+
|
|
14505
|
+
Log$6.debug('emit DEVICE.CONNECT: ', device);
|
|
14506
|
+
this.emitter.emit(DEVICE.CONNECT, device);
|
|
14507
|
+
});
|
|
14508
|
+
diff.disconnected.forEach(d => {
|
|
14509
|
+
this._removeDeviceFromConnectedPool(d.path);
|
|
14510
|
+
|
|
14511
|
+
const device = this.getDeviceByPath(d.path);
|
|
14512
|
+
|
|
14513
|
+
if (!device) {
|
|
14514
|
+
this._addDisconnectedDeviceToPool(d);
|
|
14515
|
+
|
|
14516
|
+
return;
|
|
14517
|
+
}
|
|
14518
|
+
|
|
14519
|
+
Log$6.debug('emit DEVICE.DISCONNECT: ', device);
|
|
14520
|
+
this.emitter.emit(DEVICE.DISCONNECT, device);
|
|
14521
|
+
});
|
|
14522
|
+
}
|
|
14523
|
+
|
|
14524
|
+
static getDeviceByPath(path) {
|
|
14525
|
+
return Object.values(this.devicesCache).find(d => d.originalDescriptor.path === path);
|
|
14526
|
+
}
|
|
14527
|
+
|
|
14528
|
+
static _addConnectedDeviceToPool(descriptor) {
|
|
14529
|
+
const existDescriptorIndex = this.connectedPool.findIndex(d => d.path === descriptor.path);
|
|
14530
|
+
|
|
14531
|
+
if (existDescriptorIndex > -1) {
|
|
14532
|
+
this.connectedPool.splice(existDescriptorIndex, 1, descriptor);
|
|
14533
|
+
return;
|
|
14534
|
+
}
|
|
14535
|
+
|
|
14536
|
+
this.connectedPool.push(descriptor);
|
|
14537
|
+
}
|
|
14538
|
+
|
|
14539
|
+
static _removeDeviceFromConnectedPool(path) {
|
|
14540
|
+
const index = this.connectedPool.findIndex(d => d.path === path);
|
|
14541
|
+
|
|
14542
|
+
if (index > -1) {
|
|
14543
|
+
this.connectedPool.splice(index, 1);
|
|
14544
|
+
}
|
|
14545
|
+
}
|
|
14546
|
+
|
|
14547
|
+
static _addDisconnectedDeviceToPool(descriptor) {
|
|
14548
|
+
const existDescriptorIndex = this.disconnectPool.findIndex(d => d.path === descriptor.path);
|
|
14549
|
+
|
|
14550
|
+
if (existDescriptorIndex > -1) {
|
|
14551
|
+
this.disconnectPool.splice(existDescriptorIndex, 1, descriptor);
|
|
14552
|
+
return;
|
|
14553
|
+
}
|
|
14554
|
+
|
|
14555
|
+
this.disconnectPool.push(descriptor);
|
|
14556
|
+
}
|
|
14557
|
+
|
|
14558
|
+
}
|
|
14559
|
+
|
|
14560
|
+
DevicePool.current = null;
|
|
14561
|
+
DevicePool.upcoming = [];
|
|
14562
|
+
DevicePool.connectedPool = [];
|
|
14563
|
+
DevicePool.disconnectPool = [];
|
|
14564
|
+
DevicePool.devicesCache = {};
|
|
14565
|
+
DevicePool.emitter = new events.exports();
|
|
14566
|
+
const Log$5 = getLogger(exports.d0.Transport);
|
|
14567
|
+
const BleLogger = getLogger(exports.d0.HdBleTransport);
|
|
14568
|
+
const HttpLogger = getLogger(exports.d0.HdTransportHttp);
|
|
14569
|
+
|
|
14570
|
+
class TransportManager {
|
|
14571
|
+
static load() {
|
|
14572
|
+
Log$5.debug('transport manager load');
|
|
14573
|
+
this.defaultMessages = DataManager.getProtobufMessages();
|
|
14574
|
+
this.currentMessages = this.defaultMessages;
|
|
14575
|
+
}
|
|
14576
|
+
|
|
14577
|
+
static configure() {
|
|
14578
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14579
|
+
try {
|
|
14580
|
+
const env = DataManager.getSettings('env');
|
|
14581
|
+
Log$5.debug('Initializing transports');
|
|
14582
|
+
|
|
14583
|
+
if (env === 'react-native') {
|
|
14584
|
+
if (!this.reactNativeInit) {
|
|
14585
|
+
yield this.transport.init(BleLogger, DevicePool.emitter);
|
|
14586
|
+
this.reactNativeInit = true;
|
|
14587
|
+
} else {
|
|
14588
|
+
Log$5.debug('React Native Do Not Initializing transports');
|
|
14589
|
+
}
|
|
14590
|
+
} else {
|
|
14591
|
+
yield this.transport.init(HttpLogger);
|
|
14592
|
+
}
|
|
14593
|
+
|
|
14594
|
+
Log$5.debug('Configuring transports');
|
|
14595
|
+
yield this.transport.configure(JSON.stringify(this.defaultMessages));
|
|
14596
|
+
Log$5.debug('Configuring transports done');
|
|
14597
|
+
} catch (error) {
|
|
14598
|
+
Log$5.debug('Initializing transports error: ', error);
|
|
14599
|
+
|
|
14600
|
+
if (error.code === 'ECONNABORTED') {
|
|
14601
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
|
|
14602
|
+
}
|
|
14603
|
+
}
|
|
14604
|
+
});
|
|
14605
|
+
}
|
|
14606
|
+
|
|
14607
|
+
static reconfigure(messages) {
|
|
14608
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14609
|
+
if (Array.isArray(messages)) {
|
|
14610
|
+
messages = DataManager.getProtobufMessages();
|
|
14611
|
+
}
|
|
14612
|
+
|
|
14613
|
+
if (this.currentMessages === messages || !messages) {
|
|
14614
|
+
return;
|
|
14615
|
+
}
|
|
14616
|
+
|
|
14617
|
+
try {
|
|
14618
|
+
yield this.transport.configure(JSON.stringify(messages));
|
|
14619
|
+
this.currentMessages = messages;
|
|
14620
|
+
} catch (error) {
|
|
14621
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportInvalidProtobuf, `Transport_InvalidProtobuf: ${error.message}`);
|
|
14622
|
+
}
|
|
14623
|
+
});
|
|
14624
|
+
}
|
|
14625
|
+
|
|
14626
|
+
static setTransport(TransportConstructor) {
|
|
14627
|
+
const env = DataManager.getSettings('env');
|
|
14628
|
+
|
|
14629
|
+
if (env === 'react-native') {
|
|
14630
|
+
this.transport = new TransportConstructor({
|
|
14631
|
+
scanTimeout: 3000
|
|
14632
|
+
});
|
|
14633
|
+
} else {
|
|
14634
|
+
this.transport = new TransportConstructor();
|
|
14635
|
+
}
|
|
14636
|
+
|
|
14637
|
+
Log$5.debug('set transport: ', this.transport);
|
|
14638
|
+
}
|
|
14639
|
+
|
|
14640
|
+
static getTransport() {
|
|
14641
|
+
return this.transport;
|
|
14642
|
+
}
|
|
14643
|
+
|
|
14644
|
+
static getDefaultMessages() {
|
|
14645
|
+
return this.defaultMessages;
|
|
14646
|
+
}
|
|
14647
|
+
|
|
14648
|
+
static getCurrentMessages() {
|
|
14649
|
+
return this.currentMessages;
|
|
14650
|
+
}
|
|
14651
|
+
|
|
14652
|
+
}
|
|
14653
|
+
|
|
14654
|
+
TransportManager.reactNativeInit = false;
|
|
14655
|
+
|
|
14396
14656
|
const assertType = (res, resType) => {
|
|
14397
14657
|
const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
|
|
14398
14658
|
|
|
@@ -14544,8 +14804,13 @@ class DeviceCommands {
|
|
|
14544
14804
|
}
|
|
14545
14805
|
|
|
14546
14806
|
if (res.type === 'EntropyRequest') ;
|
|
14807
|
+
const isWebusbEnv = DataManager.getSettings('env') === 'webusb';
|
|
14547
14808
|
|
|
14548
14809
|
if (res.type === 'PinMatrixRequest') {
|
|
14810
|
+
if (isWebusbEnv) {
|
|
14811
|
+
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Please unlock your device'));
|
|
14812
|
+
}
|
|
14813
|
+
|
|
14549
14814
|
return this._promptPin(res.message.type).then(pin => {
|
|
14550
14815
|
if (pin === '@@ONEKEY_INPUT_PIN_IN_DEVICE') {
|
|
14551
14816
|
return this._commonCall('BixinPinInputOnDevice');
|
|
@@ -14600,7 +14865,7 @@ const UI_REQUEST = {
|
|
|
14600
14865
|
FIRMWARE_NOT_INSTALLED: 'ui-device_firmware_not_installed',
|
|
14601
14866
|
NOT_USE_ONEKEY_DEVICE: 'ui-device_please_use_onekey_device'
|
|
14602
14867
|
};
|
|
14603
|
-
const DEFAULT_DOMAIN = `https://jssdk.onekey.so/${"0.1.
|
|
14868
|
+
const DEFAULT_DOMAIN = `https://jssdk.onekey.so/${"0.1.30"}/`;
|
|
14604
14869
|
const DEFAULT_PRIORITY = 2;
|
|
14605
14870
|
const initialSettings = {
|
|
14606
14871
|
configSrc: './data/config.json',
|
|
@@ -15094,9 +15359,6 @@ class Device extends events.exports {
|
|
|
15094
15359
|
|
|
15095
15360
|
}
|
|
15096
15361
|
|
|
15097
|
-
const cacheDeviceMap = {};
|
|
15098
|
-
const Log$2 = getLogger(exports.d0.DeviceList);
|
|
15099
|
-
|
|
15100
15362
|
class DeviceList extends events.exports {
|
|
15101
15363
|
constructor() {
|
|
15102
15364
|
super(...arguments);
|
|
@@ -15104,67 +15366,17 @@ class DeviceList extends events.exports {
|
|
|
15104
15366
|
}
|
|
15105
15367
|
|
|
15106
15368
|
getDeviceLists(connectId) {
|
|
15107
|
-
var
|
|
15108
|
-
|
|
15109
|
-
var _b, _c;
|
|
15369
|
+
var _a, _b;
|
|
15110
15370
|
|
|
15111
15371
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15112
|
-
const deviceDiff = yield (
|
|
15113
|
-
const descriptorList = (
|
|
15372
|
+
const deviceDiff = yield (_a = this.connector) === null || _a === void 0 ? void 0 : _a.enumerate();
|
|
15373
|
+
const descriptorList = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
|
|
15114
15374
|
this.devices = {};
|
|
15115
|
-
const
|
|
15116
|
-
|
|
15117
|
-
|
|
15118
|
-
|
|
15119
|
-
|
|
15120
|
-
|
|
15121
|
-
if (device) {
|
|
15122
|
-
const exist = descriptorList.find(d => d.path === device.originalDescriptor.path);
|
|
15123
|
-
|
|
15124
|
-
if (exist) {
|
|
15125
|
-
device.updateDescriptor(exist, true);
|
|
15126
|
-
Log$2.debug('find existed Device: ', connectId);
|
|
15127
|
-
this.devices[connectId] = device;
|
|
15128
|
-
return [device];
|
|
15129
|
-
}
|
|
15130
|
-
}
|
|
15131
|
-
}
|
|
15132
|
-
|
|
15133
|
-
try {
|
|
15134
|
-
for (var descriptorList_1 = __asyncValues(descriptorList), descriptorList_1_1; descriptorList_1_1 = yield descriptorList_1.next(), !descriptorList_1_1.done;) {
|
|
15135
|
-
const descriptor = descriptorList_1_1.value;
|
|
15136
|
-
let device = Device.fromDescriptor(descriptor);
|
|
15137
|
-
device.deviceConnector = this.connector;
|
|
15138
|
-
yield device.connect();
|
|
15139
|
-
yield device.initialize();
|
|
15140
|
-
yield device.release();
|
|
15141
|
-
deviceList.push(device);
|
|
15142
|
-
|
|
15143
|
-
if (device.features) {
|
|
15144
|
-
const uuid = getDeviceUUID(device.features);
|
|
15145
|
-
|
|
15146
|
-
if (cacheDeviceMap[uuid]) {
|
|
15147
|
-
const cache = cacheDeviceMap[uuid];
|
|
15148
|
-
cache === null || cache === void 0 ? void 0 : cache.updateFromCache(device);
|
|
15149
|
-
device = cache;
|
|
15150
|
-
}
|
|
15151
|
-
|
|
15152
|
-
this.devices[uuid] = device;
|
|
15153
|
-
cacheDeviceMap[uuid] = device;
|
|
15154
|
-
}
|
|
15155
|
-
}
|
|
15156
|
-
} catch (e_1_1) {
|
|
15157
|
-
e_1 = {
|
|
15158
|
-
error: e_1_1
|
|
15159
|
-
};
|
|
15160
|
-
} finally {
|
|
15161
|
-
try {
|
|
15162
|
-
if (descriptorList_1_1 && !descriptorList_1_1.done && (_a = descriptorList_1.return)) yield _a.call(descriptorList_1);
|
|
15163
|
-
} finally {
|
|
15164
|
-
if (e_1) throw e_1.error;
|
|
15165
|
-
}
|
|
15166
|
-
}
|
|
15167
|
-
|
|
15375
|
+
const {
|
|
15376
|
+
deviceList,
|
|
15377
|
+
devices
|
|
15378
|
+
} = yield DevicePool.getDevices(descriptorList, connectId);
|
|
15379
|
+
this.devices = devices;
|
|
15168
15380
|
return deviceList;
|
|
15169
15381
|
});
|
|
15170
15382
|
}
|
|
@@ -15258,14 +15470,12 @@ class SearchDevices extends BaseMethod {
|
|
|
15258
15470
|
}
|
|
15259
15471
|
|
|
15260
15472
|
run() {
|
|
15261
|
-
var
|
|
15262
|
-
|
|
15263
|
-
var _b, _c;
|
|
15473
|
+
var _a, _b;
|
|
15264
15474
|
|
|
15265
15475
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15266
15476
|
yield TransportManager.configure();
|
|
15267
|
-
const deviceDiff = yield (
|
|
15268
|
-
const devicesDescriptor = (
|
|
15477
|
+
const deviceDiff = yield (_a = this.connector) === null || _a === void 0 ? void 0 : _a.enumerate();
|
|
15478
|
+
const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
|
|
15269
15479
|
const env = DataManager.getSettings('env');
|
|
15270
15480
|
|
|
15271
15481
|
if (env === 'react-native') {
|
|
@@ -15279,31 +15489,10 @@ class SearchDevices extends BaseMethod {
|
|
|
15279
15489
|
});
|
|
15280
15490
|
}
|
|
15281
15491
|
|
|
15282
|
-
const
|
|
15283
|
-
|
|
15284
|
-
|
|
15285
|
-
|
|
15286
|
-
const descriptor = devicesDescriptor_1_1.value;
|
|
15287
|
-
const device = Device.fromDescriptor(descriptor);
|
|
15288
|
-
device.deviceConnector = this.connector;
|
|
15289
|
-
yield device.connect();
|
|
15290
|
-
yield device.initialize();
|
|
15291
|
-
yield device.release();
|
|
15292
|
-
devices.push(device);
|
|
15293
|
-
}
|
|
15294
|
-
} catch (e_1_1) {
|
|
15295
|
-
e_1 = {
|
|
15296
|
-
error: e_1_1
|
|
15297
|
-
};
|
|
15298
|
-
} finally {
|
|
15299
|
-
try {
|
|
15300
|
-
if (devicesDescriptor_1_1 && !devicesDescriptor_1_1.done && (_a = devicesDescriptor_1.return)) yield _a.call(devicesDescriptor_1);
|
|
15301
|
-
} finally {
|
|
15302
|
-
if (e_1) throw e_1.error;
|
|
15303
|
-
}
|
|
15304
|
-
}
|
|
15305
|
-
|
|
15306
|
-
return devices.map(device => device.toMessageObject());
|
|
15492
|
+
const {
|
|
15493
|
+
deviceList
|
|
15494
|
+
} = yield DevicePool.getDevices(devicesDescriptor);
|
|
15495
|
+
return deviceList.map(device => device.toMessageObject());
|
|
15307
15496
|
});
|
|
15308
15497
|
}
|
|
15309
15498
|
|
|
@@ -17278,7 +17467,7 @@ class EVMSignTransaction extends BaseMethod {
|
|
|
17278
17467
|
}))
|
|
17279
17468
|
};
|
|
17280
17469
|
const response = yield this.device.commands.typedCall('EthereumSignTxEIP1559', 'EthereumTxRequest', message);
|
|
17281
|
-
return this.processTxRequest(response.message, rest
|
|
17470
|
+
return this.processTxRequest(response.message, rest);
|
|
17282
17471
|
});
|
|
17283
17472
|
}
|
|
17284
17473
|
|
|
@@ -18913,6 +19102,47 @@ class FirmwareUpdate extends BaseMethod {
|
|
|
18913
19102
|
|
|
18914
19103
|
}
|
|
18915
19104
|
|
|
19105
|
+
const Log$2 = getLogger(exports.d0.Method);
|
|
19106
|
+
|
|
19107
|
+
class RequestWebUsbDevice extends BaseMethod {
|
|
19108
|
+
init() {
|
|
19109
|
+
this.useDevice = false;
|
|
19110
|
+
}
|
|
19111
|
+
|
|
19112
|
+
run() {
|
|
19113
|
+
var _a, _b;
|
|
19114
|
+
|
|
19115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19116
|
+
yield TransportManager.configure();
|
|
19117
|
+
const env = DataManager.getSettings('env');
|
|
19118
|
+
|
|
19119
|
+
if (env !== 'webusb') {
|
|
19120
|
+
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Not webusb environment'));
|
|
19121
|
+
}
|
|
19122
|
+
|
|
19123
|
+
try {
|
|
19124
|
+
const deviceDiff = yield (_a = this.connector) === null || _a === void 0 ? void 0 : _a.enumerate();
|
|
19125
|
+
const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
|
|
19126
|
+
const {
|
|
19127
|
+
deviceList
|
|
19128
|
+
} = yield DevicePool.getDevices(devicesDescriptor);
|
|
19129
|
+
|
|
19130
|
+
if (deviceList.length > 0) {
|
|
19131
|
+
return {
|
|
19132
|
+
device: deviceList[0].toMessageObject()
|
|
19133
|
+
};
|
|
19134
|
+
}
|
|
19135
|
+
|
|
19136
|
+
return yield Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
|
|
19137
|
+
} catch (error) {
|
|
19138
|
+
Log$2.debug(error);
|
|
19139
|
+
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
|
|
19140
|
+
}
|
|
19141
|
+
});
|
|
19142
|
+
}
|
|
19143
|
+
|
|
19144
|
+
}
|
|
19145
|
+
|
|
18916
19146
|
class CheckBridgeStatus extends BaseMethod {
|
|
18917
19147
|
init() {
|
|
18918
19148
|
this.useDevice = false;
|
|
@@ -18971,6 +19201,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
18971
19201
|
stellarGetAddress: StellarGetAddress,
|
|
18972
19202
|
stellarSignTransaction: StellarSignTransaction,
|
|
18973
19203
|
firmwareUpdate: FirmwareUpdate,
|
|
19204
|
+
requestWebUsbDevice: RequestWebUsbDevice,
|
|
18974
19205
|
getLogs: CheckBridgeStatus
|
|
18975
19206
|
});
|
|
18976
19207
|
|
|
@@ -19010,54 +19241,6 @@ const resolveAfter = (msec, value) => new Promise(resolve => {
|
|
|
19010
19241
|
|
|
19011
19242
|
const Log$1 = getLogger(exports.d0.DeviceConnector);
|
|
19012
19243
|
|
|
19013
|
-
const getDiff = (current, descriptors) => {
|
|
19014
|
-
const env = DataManager.getSettings('env');
|
|
19015
|
-
|
|
19016
|
-
if (env === 'react-native') {
|
|
19017
|
-
return {
|
|
19018
|
-
descriptors
|
|
19019
|
-
};
|
|
19020
|
-
}
|
|
19021
|
-
|
|
19022
|
-
const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
|
|
19023
|
-
const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
|
|
19024
|
-
const changedSessions = descriptors.filter(d => {
|
|
19025
|
-
const currentDescriptor = current.find(x => x.path === d.path);
|
|
19026
|
-
|
|
19027
|
-
if (currentDescriptor) {
|
|
19028
|
-
return currentDescriptor.session !== d.session;
|
|
19029
|
-
}
|
|
19030
|
-
|
|
19031
|
-
return false;
|
|
19032
|
-
});
|
|
19033
|
-
const acquired = changedSessions.filter(d => typeof d.session === 'string');
|
|
19034
|
-
const released = changedSessions.filter(d => typeof d.session !== 'string');
|
|
19035
|
-
const changedDebugSessions = descriptors.filter(d => {
|
|
19036
|
-
const currentDescriptor = current.find(x => x.path === d.path);
|
|
19037
|
-
|
|
19038
|
-
if (currentDescriptor) {
|
|
19039
|
-
return currentDescriptor.debugSession !== d.debugSession;
|
|
19040
|
-
}
|
|
19041
|
-
|
|
19042
|
-
return false;
|
|
19043
|
-
});
|
|
19044
|
-
const debugAcquired = changedSessions.filter(d => typeof d.debugSession === 'string');
|
|
19045
|
-
const debugReleased = changedSessions.filter(d => typeof d.debugSession !== 'string');
|
|
19046
|
-
const didUpdate = connected.length + disconnected.length + changedSessions.length + changedDebugSessions.length > 0;
|
|
19047
|
-
return {
|
|
19048
|
-
connected,
|
|
19049
|
-
disconnected,
|
|
19050
|
-
changedSessions,
|
|
19051
|
-
acquired,
|
|
19052
|
-
released,
|
|
19053
|
-
changedDebugSessions,
|
|
19054
|
-
debugAcquired,
|
|
19055
|
-
debugReleased,
|
|
19056
|
-
didUpdate,
|
|
19057
|
-
descriptors
|
|
19058
|
-
};
|
|
19059
|
-
};
|
|
19060
|
-
|
|
19061
19244
|
class DeviceConnector {
|
|
19062
19245
|
constructor() {
|
|
19063
19246
|
this.listenTimestamp = 0;
|
|
@@ -19066,17 +19249,20 @@ class DeviceConnector {
|
|
|
19066
19249
|
this.listening = false;
|
|
19067
19250
|
TransportManager.load();
|
|
19068
19251
|
this.transport = TransportManager.getTransport();
|
|
19252
|
+
DevicePool.setConnector(this);
|
|
19069
19253
|
}
|
|
19070
19254
|
|
|
19071
19255
|
enumerate() {
|
|
19072
19256
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19073
19257
|
try {
|
|
19074
|
-
|
|
19258
|
+
const descriptors = yield this.transport.enumerate();
|
|
19259
|
+
this.upcoming = descriptors;
|
|
19075
19260
|
|
|
19076
|
-
|
|
19261
|
+
this._reportDevicesChange();
|
|
19077
19262
|
|
|
19078
|
-
|
|
19079
|
-
|
|
19263
|
+
return {
|
|
19264
|
+
descriptors
|
|
19265
|
+
};
|
|
19080
19266
|
} catch (error) {
|
|
19081
19267
|
safeThrowError(error);
|
|
19082
19268
|
}
|
|
@@ -19157,9 +19343,7 @@ class DeviceConnector {
|
|
|
19157
19343
|
}
|
|
19158
19344
|
|
|
19159
19345
|
_reportDevicesChange() {
|
|
19160
|
-
|
|
19161
|
-
this.current = this.upcoming;
|
|
19162
|
-
return diff;
|
|
19346
|
+
DevicePool.reportDeviceChange(this.upcoming);
|
|
19163
19347
|
}
|
|
19164
19348
|
|
|
19165
19349
|
}
|
|
@@ -19200,6 +19384,8 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
19200
19384
|
return Promise.reject(error);
|
|
19201
19385
|
}
|
|
19202
19386
|
|
|
19387
|
+
DevicePool.emitter.on(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
19388
|
+
|
|
19203
19389
|
if (!method.useDevice) {
|
|
19204
19390
|
try {
|
|
19205
19391
|
const response = yield method.run();
|
|
@@ -19250,11 +19436,17 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
19250
19436
|
const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
|
|
19251
19437
|
|
|
19252
19438
|
if (semver__default["default"].valid(versionRange.min) && semver__default["default"].lt(currentVersion, versionRange.min)) {
|
|
19253
|
-
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.
|
|
19439
|
+
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNeedUpgradeFirmware, `Device firmware version is too low, please update to ${versionRange.min}`, {
|
|
19440
|
+
current: currentVersion,
|
|
19441
|
+
require: versionRange.min
|
|
19442
|
+
}));
|
|
19254
19443
|
}
|
|
19255
19444
|
|
|
19256
|
-
if (versionRange.max && semver__default["default"].valid(versionRange.max) && semver__default["default"].
|
|
19257
|
-
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.
|
|
19445
|
+
if (versionRange.max && semver__default["default"].valid(versionRange.max) && semver__default["default"].gte(currentVersion, versionRange.max)) {
|
|
19446
|
+
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodDeprecated, `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`, {
|
|
19447
|
+
current: currentVersion,
|
|
19448
|
+
deprecated: versionRange.max
|
|
19449
|
+
}));
|
|
19258
19450
|
}
|
|
19259
19451
|
}
|
|
19260
19452
|
|
|
@@ -19535,12 +19727,29 @@ const removeDeviceListener = device => {
|
|
|
19535
19727
|
device.removeListener(DEVICE.PIN, onDevicePinHandler);
|
|
19536
19728
|
device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler);
|
|
19537
19729
|
device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
19730
|
+
DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
19538
19731
|
};
|
|
19539
19732
|
|
|
19540
19733
|
const closePopup = () => {
|
|
19541
19734
|
postMessage(createUiMessage(UI_REQUEST$1.CLOSE_UI_WINDOW));
|
|
19542
19735
|
};
|
|
19543
19736
|
|
|
19737
|
+
const onDeviceConnectHandler = device => {
|
|
19738
|
+
const env = DataManager.getSettings('env');
|
|
19739
|
+
const deviceObject = env === 'react-native' ? device : device.toMessageObject();
|
|
19740
|
+
postMessage(createDeviceMessage(DEVICE.CONNECT, {
|
|
19741
|
+
device: deviceObject
|
|
19742
|
+
}));
|
|
19743
|
+
};
|
|
19744
|
+
|
|
19745
|
+
const onDeviceDisconnectHandler = device => {
|
|
19746
|
+
const env = DataManager.getSettings('env');
|
|
19747
|
+
const deviceObject = env === 'react-native' ? device : device.toMessageObject();
|
|
19748
|
+
postMessage(createDeviceMessage(DEVICE.DISCONNECT, {
|
|
19749
|
+
device: deviceObject
|
|
19750
|
+
}));
|
|
19751
|
+
};
|
|
19752
|
+
|
|
19544
19753
|
const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19545
19754
|
Log.debug('onDevicePinHandler');
|
|
19546
19755
|
const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PIN, device);
|
|
@@ -19642,6 +19851,7 @@ const initCore = () => {
|
|
|
19642
19851
|
|
|
19643
19852
|
const initConnector = () => {
|
|
19644
19853
|
_connector = new DeviceConnector();
|
|
19854
|
+
DevicePool.emitter.on(DEVICE.DISCONNECT, onDeviceDisconnectHandler);
|
|
19645
19855
|
return _connector;
|
|
19646
19856
|
};
|
|
19647
19857
|
|
|
@@ -19998,6 +20208,19 @@ const readHeader = buffer => {
|
|
|
19998
20208
|
};
|
|
19999
20209
|
};
|
|
20000
20210
|
|
|
20211
|
+
const readHeaderChunked = buffer => {
|
|
20212
|
+
const sharp1 = buffer.readByte();
|
|
20213
|
+
const sharp2 = buffer.readByte();
|
|
20214
|
+
const typeId = buffer.readUint16();
|
|
20215
|
+
const length = buffer.readUint32();
|
|
20216
|
+
return {
|
|
20217
|
+
sharp1,
|
|
20218
|
+
sharp2,
|
|
20219
|
+
typeId,
|
|
20220
|
+
length
|
|
20221
|
+
};
|
|
20222
|
+
};
|
|
20223
|
+
|
|
20001
20224
|
const decode = byteBuffer => {
|
|
20002
20225
|
const {
|
|
20003
20226
|
typeId
|
|
@@ -20008,6 +20231,32 @@ const decode = byteBuffer => {
|
|
|
20008
20231
|
};
|
|
20009
20232
|
};
|
|
20010
20233
|
|
|
20234
|
+
const decodeChunked = bytes => {
|
|
20235
|
+
const byteBuffer = ByteBuffer__default["default"].wrap(bytes, undefined, undefined, true);
|
|
20236
|
+
const {
|
|
20237
|
+
sharp1,
|
|
20238
|
+
sharp2,
|
|
20239
|
+
typeId,
|
|
20240
|
+
length
|
|
20241
|
+
} = readHeaderChunked(byteBuffer);
|
|
20242
|
+
|
|
20243
|
+
if (sharp1 !== MESSAGE_HEADER_BYTE || sharp2 !== MESSAGE_HEADER_BYTE) {
|
|
20244
|
+
throw new Error("Didn't receive expected header signature.");
|
|
20245
|
+
}
|
|
20246
|
+
|
|
20247
|
+
return {
|
|
20248
|
+
length,
|
|
20249
|
+
typeId,
|
|
20250
|
+
restBuffer: byteBuffer
|
|
20251
|
+
};
|
|
20252
|
+
};
|
|
20253
|
+
|
|
20254
|
+
var decodeProtocol = /*#__PURE__*/Object.freeze({
|
|
20255
|
+
__proto__: null,
|
|
20256
|
+
decode: decode,
|
|
20257
|
+
decodeChunked: decodeChunked
|
|
20258
|
+
});
|
|
20259
|
+
|
|
20011
20260
|
function encode(data, options) {
|
|
20012
20261
|
const {
|
|
20013
20262
|
addTrezorHeaders,
|
|
@@ -20059,17 +20308,21 @@ function buildOne(messages, name, data) {
|
|
|
20059
20308
|
});
|
|
20060
20309
|
}
|
|
20061
20310
|
|
|
20062
|
-
const
|
|
20311
|
+
const buildEncodeBuffers = (messages, name, data) => {
|
|
20063
20312
|
const {
|
|
20064
20313
|
Message,
|
|
20065
20314
|
messageType
|
|
20066
20315
|
} = createMessageFromName(messages, name);
|
|
20067
20316
|
const buffer = encode$1(Message, data);
|
|
20068
|
-
|
|
20317
|
+
return encode(buffer, {
|
|
20069
20318
|
addTrezorHeaders: true,
|
|
20070
20319
|
chunked: true,
|
|
20071
20320
|
messageType
|
|
20072
20321
|
});
|
|
20322
|
+
};
|
|
20323
|
+
|
|
20324
|
+
const buildBuffers = (messages, name, data) => {
|
|
20325
|
+
const encodeBuffers = buildEncodeBuffers(messages, name, data);
|
|
20073
20326
|
const outBuffers = [];
|
|
20074
20327
|
|
|
20075
20328
|
for (const buf of encodeBuffers) {
|
|
@@ -20752,8 +21005,10 @@ var index = {
|
|
|
20752
21005
|
check,
|
|
20753
21006
|
buildOne,
|
|
20754
21007
|
buildBuffers,
|
|
21008
|
+
buildEncodeBuffers,
|
|
20755
21009
|
receiveOne,
|
|
20756
|
-
parseConfigure
|
|
21010
|
+
parseConfigure,
|
|
21011
|
+
decodeProtocol
|
|
20757
21012
|
};
|
|
20758
21013
|
exports.BUFFER_SIZE = BUFFER_SIZE;
|
|
20759
21014
|
exports.COMMON_HEADER_SIZE = COMMON_HEADER_SIZE;
|
|
@@ -20862,6 +21117,7 @@ class HardwareError extends Error {
|
|
|
20862
21117
|
super();
|
|
20863
21118
|
this.errorCode = HardwareErrorCode.UnknownError;
|
|
20864
21119
|
this.message = '';
|
|
21120
|
+
this.params = {};
|
|
20865
21121
|
const errorMessageMapping = HardwareErrorCodeMessage;
|
|
20866
21122
|
this.message = errorMessageMapping[HardwareErrorCode.UnknownError];
|
|
20867
21123
|
|
|
@@ -20875,6 +21131,7 @@ class HardwareError extends Error {
|
|
|
20875
21131
|
this.message = fillStringWithArguments(message, hardwareError);
|
|
20876
21132
|
}
|
|
20877
21133
|
|
|
21134
|
+
this.params = hardwareError.params;
|
|
20878
21135
|
this.errorCode = hardwareError.errorCode;
|
|
20879
21136
|
}
|
|
20880
21137
|
|
|
@@ -20906,6 +21163,8 @@ const HardwareErrorCode = {
|
|
|
20906
21163
|
CallMethodNotResponse: 404,
|
|
20907
21164
|
CallMethodInvalidParameter: 405,
|
|
20908
21165
|
FirmwareUpdateDownloadFailed: 406,
|
|
21166
|
+
CallMethodNeedUpgradeFirmware: 407,
|
|
21167
|
+
CallMethodDeprecated: 408,
|
|
20909
21168
|
NetworkError: 500,
|
|
20910
21169
|
TransportNotConfigured: 600,
|
|
20911
21170
|
TransportCallInProgress: 601,
|
|
@@ -20957,6 +21216,8 @@ const HardwareErrorCodeMessage = {
|
|
|
20957
21216
|
[HardwareErrorCode.CallMethodNotResponse]: 'Method does not responding',
|
|
20958
21217
|
[HardwareErrorCode.CallMethodInvalidParameter]: 'Call method invalid parameter',
|
|
20959
21218
|
[HardwareErrorCode.FirmwareUpdateDownloadFailed]: 'Firmware update download failed',
|
|
21219
|
+
[HardwareErrorCode.CallMethodNeedUpgradeFirmware]: 'Call method need upgrade firmware',
|
|
21220
|
+
[HardwareErrorCode.CallMethodDeprecated]: 'Call method is deprecated',
|
|
20960
21221
|
[HardwareErrorCode.NetworkError]: 'Network request error',
|
|
20961
21222
|
[HardwareErrorCode.TransportNotConfigured]: 'Transport not configured',
|
|
20962
21223
|
[HardwareErrorCode.TransportCallInProgress]: 'Transport call in progress',
|
|
@@ -20986,14 +21247,15 @@ const HardwareErrorCodeMessage = {
|
|
|
20986
21247
|
[HardwareErrorCode.PollingStop]: 'Polling stop'
|
|
20987
21248
|
};
|
|
20988
21249
|
|
|
20989
|
-
const TypedError = (hardwareError, message) => {
|
|
21250
|
+
const TypedError = (hardwareError, message, params) => {
|
|
20990
21251
|
if (typeof hardwareError === 'string') {
|
|
20991
21252
|
return new HardwareError(hardwareError);
|
|
20992
21253
|
}
|
|
20993
21254
|
|
|
20994
21255
|
return new HardwareError({
|
|
20995
21256
|
errorCode: hardwareError,
|
|
20996
|
-
message: message !== null && message !== void 0 ? message : ''
|
|
21257
|
+
message: message !== null && message !== void 0 ? message : '',
|
|
21258
|
+
params
|
|
20997
21259
|
});
|
|
20998
21260
|
};
|
|
20999
21261
|
|
|
@@ -21001,7 +21263,8 @@ const serializeError = payload => {
|
|
|
21001
21263
|
if (payload && payload.error instanceof HardwareError) {
|
|
21002
21264
|
return {
|
|
21003
21265
|
error: payload.error.message,
|
|
21004
|
-
code: payload.error.errorCode
|
|
21266
|
+
code: payload.error.errorCode,
|
|
21267
|
+
params: payload.error.params
|
|
21005
21268
|
};
|
|
21006
21269
|
}
|
|
21007
21270
|
|
|
@@ -43831,6 +44094,10 @@ const init = async settings => {
|
|
|
43831
44094
|
instance.style.width = '0px';
|
|
43832
44095
|
instance.style.height = '0px';
|
|
43833
44096
|
instance.id = 'onekey-connect';
|
|
44097
|
+
|
|
44098
|
+
if (settings.env === 'webusb') {
|
|
44099
|
+
instance.allow = 'usb';
|
|
44100
|
+
}
|
|
43834
44101
|
}
|
|
43835
44102
|
|
|
43836
44103
|
const manifest = `version=${settings.version}`;
|
|
@@ -46128,11 +46395,7 @@ const handleMessage = async message => {
|
|
|
46128
46395
|
break;
|
|
46129
46396
|
|
|
46130
46397
|
case dist/* DEVICE_EVENT */.Fd:
|
|
46131
|
-
if (
|
|
46132
|
-
eventEmitter.emit(message.type, message.payload);
|
|
46133
|
-
}
|
|
46134
|
-
|
|
46135
|
-
if (message.type === dist/* DEVICE.SUPPORT_FEATURES */.Td.SUPPORT_FEATURES) {
|
|
46398
|
+
if ([dist/* DEVICE.CONNECT */.Td.CONNECT, dist/* DEVICE.DISCONNECT */.Td.DISCONNECT, dist/* DEVICE.FEATURES */.Td.FEATURES, dist/* DEVICE.SUPPORT_FEATURES */.Td.SUPPORT_FEATURES].includes(message.type)) {
|
|
46136
46399
|
eventEmitter.emit(message.type, message.payload);
|
|
46137
46400
|
}
|
|
46138
46401
|
|
|
@@ -46232,7 +46495,7 @@ const src_init = async settings => {
|
|
|
46232
46495
|
|
|
46233
46496
|
try {
|
|
46234
46497
|
await init({ ..._settings,
|
|
46235
|
-
version: "0.1.
|
|
46498
|
+
version: "0.1.30"
|
|
46236
46499
|
});
|
|
46237
46500
|
return true;
|
|
46238
46501
|
} catch (e) {
|