@onekeyfe/hd-web-sdk 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/iframe.html +1 -1
- package/build/js/iframe.435f82a3bee253ffd1d3.js +3 -0
- package/build/js/{iframe.6bb43909abd5d815e337.js.LICENSE.txt → iframe.435f82a3bee253ffd1d3.js.LICENSE.txt} +0 -0
- package/build/js/iframe.435f82a3bee253ffd1d3.js.map +1 -0
- package/build/onekey-js-sdk.js +113 -33
- package/build/onekey-js-sdk.js.map +1 -1
- package/build/onekey-js-sdk.min.js +1 -1
- package/build/onekey-js-sdk.min.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +3 -1
- package/build/js/iframe.6bb43909abd5d815e337.js +0 -3
- package/build/js/iframe.6bb43909abd5d815e337.js.map +0 -1
package/build/onekey-js-sdk.js
CHANGED
|
@@ -4782,6 +4782,7 @@ const ERROR_CODES = {
|
|
|
4782
4782
|
Device_UnexpectedMode: '',
|
|
4783
4783
|
Device_CallInProgress: '',
|
|
4784
4784
|
Device_InitializeFailed: '',
|
|
4785
|
+
Device_Interrupted: 'The device is performing other operations',
|
|
4785
4786
|
Not_Use_Onekey_Device: 'Please use onekey device',
|
|
4786
4787
|
Runtime: '',
|
|
4787
4788
|
Init_NotInitialized: 'Init_NotInitialized',
|
|
@@ -4833,7 +4834,7 @@ const colors = {
|
|
|
4833
4834
|
};
|
|
4834
4835
|
const MAX_ENTRIES = 100;
|
|
4835
4836
|
|
|
4836
|
-
class Log$
|
|
4837
|
+
class Log$6 {
|
|
4837
4838
|
constructor(prefix, enabled) {
|
|
4838
4839
|
this.prefix = prefix;
|
|
4839
4840
|
this.enabled = enabled;
|
|
@@ -4895,7 +4896,7 @@ class Log$5 {
|
|
|
4895
4896
|
const _logs = {};
|
|
4896
4897
|
|
|
4897
4898
|
const initLog = (prefix, enabled) => {
|
|
4898
|
-
const instance = new Log$
|
|
4899
|
+
const instance = new Log$6(prefix, !!enabled);
|
|
4899
4900
|
_logs[prefix] = instance;
|
|
4900
4901
|
return instance;
|
|
4901
4902
|
};
|
|
@@ -14074,7 +14075,7 @@ DataManager.getTransportStatus = localVersion => {
|
|
|
14074
14075
|
return isLatest ? 'valid' : 'outdated';
|
|
14075
14076
|
};
|
|
14076
14077
|
|
|
14077
|
-
const Log$
|
|
14078
|
+
const Log$5 = initLog('Transport');
|
|
14078
14079
|
|
|
14079
14080
|
class TransportManager {
|
|
14080
14081
|
static load() {
|
|
@@ -14087,24 +14088,24 @@ class TransportManager {
|
|
|
14087
14088
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14088
14089
|
try {
|
|
14089
14090
|
const env = DataManager.getSettings('env');
|
|
14090
|
-
Log$
|
|
14091
|
+
Log$5.debug('Initializing transports');
|
|
14091
14092
|
|
|
14092
14093
|
if (env === 'react-native') {
|
|
14093
14094
|
if (!this.reactNativeInit) {
|
|
14094
14095
|
yield this.transport.init();
|
|
14095
14096
|
this.reactNativeInit = true;
|
|
14096
14097
|
} else {
|
|
14097
|
-
Log$
|
|
14098
|
+
Log$5.debug('React Native Do Not Initializing transports');
|
|
14098
14099
|
}
|
|
14099
14100
|
} else {
|
|
14100
14101
|
yield this.transport.init();
|
|
14101
14102
|
}
|
|
14102
14103
|
|
|
14103
|
-
Log$
|
|
14104
|
+
Log$5.debug('Configuring transports');
|
|
14104
14105
|
yield this.transport.configure(JSON.stringify(this.defaultMessages));
|
|
14105
|
-
Log$
|
|
14106
|
+
Log$5.debug('Configuring transports done');
|
|
14106
14107
|
} catch (error) {
|
|
14107
|
-
Log$
|
|
14108
|
+
Log$5.debug('Initializing transports error: ', error);
|
|
14108
14109
|
}
|
|
14109
14110
|
});
|
|
14110
14111
|
}
|
|
@@ -14208,7 +14209,8 @@ const createUiMessage = (type, payload) => ({
|
|
|
14208
14209
|
const IFRAME = {
|
|
14209
14210
|
INIT: 'iframe-init',
|
|
14210
14211
|
INIT_BRIDGE: 'iframe-init-bridge',
|
|
14211
|
-
CALL: 'iframe-call'
|
|
14212
|
+
CALL: 'iframe-call',
|
|
14213
|
+
CANCEL: 'iframe-cancel'
|
|
14212
14214
|
};
|
|
14213
14215
|
|
|
14214
14216
|
const createIFrameMessage = (type, payload) => ({
|
|
@@ -14271,7 +14273,7 @@ const assertType = (res, resType) => {
|
|
|
14271
14273
|
}
|
|
14272
14274
|
};
|
|
14273
14275
|
|
|
14274
|
-
const Log$
|
|
14276
|
+
const Log$4 = initLog('DeviceCommands');
|
|
14275
14277
|
|
|
14276
14278
|
class DeviceCommands {
|
|
14277
14279
|
constructor(device, mainId) {
|
|
@@ -14282,8 +14284,16 @@ class DeviceCommands {
|
|
|
14282
14284
|
}
|
|
14283
14285
|
|
|
14284
14286
|
dispose() {
|
|
14287
|
+
var _a, _b;
|
|
14288
|
+
|
|
14285
14289
|
this.disposed = true;
|
|
14290
|
+
|
|
14291
|
+
if (this._cancelableRequest) {
|
|
14292
|
+
this._cancelableRequest();
|
|
14293
|
+
}
|
|
14294
|
+
|
|
14286
14295
|
this._cancelableRequest = undefined;
|
|
14296
|
+
(_b = (_a = this.transport).cancel) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
14287
14297
|
}
|
|
14288
14298
|
|
|
14289
14299
|
call(type, msg = {}) {
|
|
@@ -14294,10 +14304,10 @@ class DeviceCommands {
|
|
|
14294
14304
|
const promise = this.transport.call(this.mainId, type, msg);
|
|
14295
14305
|
this.callPromise = promise;
|
|
14296
14306
|
const res = yield promise;
|
|
14297
|
-
Log$
|
|
14307
|
+
Log$4.debug('[DeviceCommands] [call] Received', res.type);
|
|
14298
14308
|
return res;
|
|
14299
14309
|
} catch (error) {
|
|
14300
|
-
Log$
|
|
14310
|
+
Log$4.debug('[DeviceCommands] [call] Received error', error);
|
|
14301
14311
|
throw error;
|
|
14302
14312
|
}
|
|
14303
14313
|
});
|
|
@@ -14521,7 +14531,7 @@ const parseRunOptions = options => {
|
|
|
14521
14531
|
return options;
|
|
14522
14532
|
};
|
|
14523
14533
|
|
|
14524
|
-
const Log$
|
|
14534
|
+
const Log$3 = initLog('Device');
|
|
14525
14535
|
|
|
14526
14536
|
class Device extends events.exports {
|
|
14527
14537
|
constructor(descriptor) {
|
|
@@ -14533,7 +14543,6 @@ class Device extends events.exports {
|
|
|
14533
14543
|
this.unavailableCapabilities = {};
|
|
14534
14544
|
this.instance = 0;
|
|
14535
14545
|
this.internalState = [];
|
|
14536
|
-
this.loaded = false;
|
|
14537
14546
|
this.needReloadDevice = false;
|
|
14538
14547
|
this.keepSession = false;
|
|
14539
14548
|
this.originalDescriptor = descriptor;
|
|
@@ -14608,10 +14617,10 @@ class Device extends events.exports {
|
|
|
14608
14617
|
if (env === 'react-native') {
|
|
14609
14618
|
const res = yield (_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.originalDescriptor.id);
|
|
14610
14619
|
this.mainId = (_b = res.uuid) !== null && _b !== void 0 ? _b : '';
|
|
14611
|
-
Log$
|
|
14620
|
+
Log$3.debug('Expected uuid:', this.mainId);
|
|
14612
14621
|
} else {
|
|
14613
14622
|
this.mainId = yield (_c = this.deviceConnector) === null || _c === void 0 ? void 0 : _c.acquire(this.originalDescriptor.path, this.originalDescriptor.session);
|
|
14614
|
-
Log$
|
|
14623
|
+
Log$3.debug('Expected session id:', this.mainId);
|
|
14615
14624
|
}
|
|
14616
14625
|
|
|
14617
14626
|
this.updateDescriptor({
|
|
@@ -14660,7 +14669,7 @@ class Device extends events.exports {
|
|
|
14660
14669
|
session: null
|
|
14661
14670
|
});
|
|
14662
14671
|
} catch (err) {
|
|
14663
|
-
Log$
|
|
14672
|
+
Log$3.error('[Device] release error: ', err);
|
|
14664
14673
|
} finally {
|
|
14665
14674
|
this.needReloadDevice = true;
|
|
14666
14675
|
}
|
|
@@ -14732,11 +14741,21 @@ class Device extends events.exports {
|
|
|
14732
14741
|
}
|
|
14733
14742
|
}
|
|
14734
14743
|
|
|
14744
|
+
updateFromCache(device) {
|
|
14745
|
+
this.mainId = device.mainId;
|
|
14746
|
+
this.commands = device.commands;
|
|
14747
|
+
this.updateDescriptor(device.originalDescriptor);
|
|
14748
|
+
|
|
14749
|
+
if (device.features) {
|
|
14750
|
+
this._updateFeatures(device.features);
|
|
14751
|
+
}
|
|
14752
|
+
}
|
|
14753
|
+
|
|
14735
14754
|
run(fn, options) {
|
|
14736
14755
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14737
14756
|
if (this.runPromise) {
|
|
14738
|
-
|
|
14739
|
-
|
|
14757
|
+
this.interruption();
|
|
14758
|
+
Log$3.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
|
|
14740
14759
|
}
|
|
14741
14760
|
|
|
14742
14761
|
options = parseRunOptions(options);
|
|
@@ -14768,14 +14787,10 @@ class Device extends events.exports {
|
|
|
14768
14787
|
yield fn();
|
|
14769
14788
|
}
|
|
14770
14789
|
|
|
14771
|
-
if (this.loaded && this.features) {
|
|
14772
|
-
yield this.getFeatures();
|
|
14773
|
-
}
|
|
14774
|
-
|
|
14775
14790
|
if (!this.keepSession && typeof options.keepSession !== 'boolean' || options.keepSession === false) {
|
|
14776
14791
|
this.keepSession = false;
|
|
14777
14792
|
yield this.release();
|
|
14778
|
-
Log$
|
|
14793
|
+
Log$3.debug('release device, mainId: ', this.mainId);
|
|
14779
14794
|
}
|
|
14780
14795
|
|
|
14781
14796
|
if (this.runPromise) {
|
|
@@ -14783,13 +14798,19 @@ class Device extends events.exports {
|
|
|
14783
14798
|
}
|
|
14784
14799
|
|
|
14785
14800
|
this.runPromise = null;
|
|
14786
|
-
|
|
14787
|
-
if (!this.loaded) {
|
|
14788
|
-
this.loaded = true;
|
|
14789
|
-
}
|
|
14790
14801
|
});
|
|
14791
14802
|
}
|
|
14792
14803
|
|
|
14804
|
+
interruption() {
|
|
14805
|
+
if (this.commands) {
|
|
14806
|
+
this.commands.dispose();
|
|
14807
|
+
}
|
|
14808
|
+
|
|
14809
|
+
if (this.runPromise) {
|
|
14810
|
+
this.runPromise.reject(TypedError('Device_Interrupted'));
|
|
14811
|
+
}
|
|
14812
|
+
}
|
|
14813
|
+
|
|
14793
14814
|
getMode() {
|
|
14794
14815
|
var _a, _b, _c;
|
|
14795
14816
|
|
|
@@ -14867,6 +14888,9 @@ class Device extends events.exports {
|
|
|
14867
14888
|
|
|
14868
14889
|
}
|
|
14869
14890
|
|
|
14891
|
+
const cacheDeviceMap = new Map();
|
|
14892
|
+
const Log$2 = initLog('DeviceList');
|
|
14893
|
+
|
|
14870
14894
|
class DeviceList extends events.exports {
|
|
14871
14895
|
constructor() {
|
|
14872
14896
|
super(...arguments);
|
|
@@ -14888,7 +14912,7 @@ class DeviceList extends events.exports {
|
|
|
14888
14912
|
try {
|
|
14889
14913
|
for (var descriptorList_1 = __asyncValues(descriptorList), descriptorList_1_1; descriptorList_1_1 = yield descriptorList_1.next(), !descriptorList_1_1.done;) {
|
|
14890
14914
|
const descriptor = descriptorList_1_1.value;
|
|
14891
|
-
|
|
14915
|
+
let device = Device.fromDescriptor(descriptor);
|
|
14892
14916
|
device.deviceConnector = this.connector;
|
|
14893
14917
|
yield device.connect();
|
|
14894
14918
|
yield device.initialize();
|
|
@@ -14897,7 +14921,16 @@ class DeviceList extends events.exports {
|
|
|
14897
14921
|
|
|
14898
14922
|
if (device.features) {
|
|
14899
14923
|
const uuid = getDeviceUUID(device.features);
|
|
14924
|
+
|
|
14925
|
+
if (cacheDeviceMap.has(uuid)) {
|
|
14926
|
+
const cache = cacheDeviceMap.get(uuid);
|
|
14927
|
+
cache === null || cache === void 0 ? void 0 : cache.updateFromCache(device);
|
|
14928
|
+
device = cache;
|
|
14929
|
+
Log$2.debug('use cache device: ', uuid);
|
|
14930
|
+
}
|
|
14931
|
+
|
|
14900
14932
|
this.devices[uuid] = device;
|
|
14933
|
+
cacheDeviceMap.set(uuid, device);
|
|
14901
14934
|
}
|
|
14902
14935
|
}
|
|
14903
14936
|
} catch (e_1_1) {
|
|
@@ -18498,6 +18531,8 @@ let _uiPromises = [];
|
|
|
18498
18531
|
|
|
18499
18532
|
let _callPromise;
|
|
18500
18533
|
|
|
18534
|
+
const deviceCacheMap = new Map();
|
|
18535
|
+
|
|
18501
18536
|
const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
|
|
18502
18537
|
var _a, _b;
|
|
18503
18538
|
|
|
@@ -18680,13 +18715,44 @@ function initDeviceForBle(method) {
|
|
|
18680
18715
|
return initDevice(method);
|
|
18681
18716
|
}
|
|
18682
18717
|
|
|
18683
|
-
|
|
18684
|
-
|
|
18685
|
-
|
|
18718
|
+
let device;
|
|
18719
|
+
|
|
18720
|
+
if (deviceCacheMap.has(method.connectId)) {
|
|
18721
|
+
device = deviceCacheMap.get(method.connectId);
|
|
18722
|
+
} else {
|
|
18723
|
+
device = Device.fromDescriptor({
|
|
18724
|
+
id: method.connectId
|
|
18725
|
+
});
|
|
18726
|
+
deviceCacheMap.set(method.connectId, device);
|
|
18727
|
+
}
|
|
18728
|
+
|
|
18686
18729
|
device.deviceConnector = _connector;
|
|
18687
18730
|
return device;
|
|
18688
18731
|
}
|
|
18689
18732
|
|
|
18733
|
+
const cancel = connectId => {
|
|
18734
|
+
const env = DataManager.getSettings('env');
|
|
18735
|
+
|
|
18736
|
+
if (connectId) {
|
|
18737
|
+
let device;
|
|
18738
|
+
|
|
18739
|
+
if (env === 'react-native') {
|
|
18740
|
+
device = initDeviceForBle({
|
|
18741
|
+
connectId
|
|
18742
|
+
});
|
|
18743
|
+
} else {
|
|
18744
|
+
device = initDevice({
|
|
18745
|
+
connectId
|
|
18746
|
+
});
|
|
18747
|
+
}
|
|
18748
|
+
|
|
18749
|
+
device === null || device === void 0 ? void 0 : device.interruption();
|
|
18750
|
+
}
|
|
18751
|
+
|
|
18752
|
+
cleanup();
|
|
18753
|
+
closePopup();
|
|
18754
|
+
};
|
|
18755
|
+
|
|
18690
18756
|
const cleanup = () => {
|
|
18691
18757
|
_uiPromises = [];
|
|
18692
18758
|
Log.debug('Cleanup...');
|
|
@@ -18770,6 +18836,12 @@ class Core extends events.exports {
|
|
|
18770
18836
|
const response = yield callAPI(message);
|
|
18771
18837
|
return response;
|
|
18772
18838
|
}
|
|
18839
|
+
|
|
18840
|
+
case IFRAME.CANCEL:
|
|
18841
|
+
{
|
|
18842
|
+
cancel(message.payload.connectId);
|
|
18843
|
+
break;
|
|
18844
|
+
}
|
|
18773
18845
|
}
|
|
18774
18846
|
|
|
18775
18847
|
return Promise.resolve(message);
|
|
@@ -44452,7 +44524,15 @@ const uiResponse = response => {
|
|
|
44452
44524
|
});
|
|
44453
44525
|
};
|
|
44454
44526
|
|
|
44455
|
-
const cancel =
|
|
44527
|
+
const cancel = connectId => {
|
|
44528
|
+
sendMessage({
|
|
44529
|
+
event: dist/* IFRAME.CANCEL */.Bg.CANCEL,
|
|
44530
|
+
type: dist/* IFRAME.CANCEL */.Bg.CANCEL,
|
|
44531
|
+
payload: {
|
|
44532
|
+
connectId
|
|
44533
|
+
}
|
|
44534
|
+
});
|
|
44535
|
+
};
|
|
44456
44536
|
|
|
44457
44537
|
const createJSBridge = messageEvent => {
|
|
44458
44538
|
if (messageEvent.origin !== origin) {
|