@onekeyfe/hd-core 1.1.4-alpha.1 → 1.1.4-alpha.3
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/dist/api/BaseMethod.d.ts +2 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddress.d.ts +4 -28
- package/dist/api/allnetwork/AllNetworkGetAddress.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts +47 -0
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -0
- package/dist/api/allnetwork/AllNetworkGetAddressByLoop.d.ts +8 -0
- package/dist/api/allnetwork/AllNetworkGetAddressByLoop.d.ts.map +1 -0
- package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
- package/dist/api/cosmos/CosmosGetPublicKey.d.ts +1 -1
- package/dist/api/cosmos/CosmosGetPublicKey.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +0 -2
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/evm/EVMGetPublicKey.d.ts +1 -0
- package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/core/RequestQueue.d.ts +4 -0
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +4 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/events/call.d.ts +9 -0
- package/dist/events/call.d.ts.map +1 -1
- package/dist/events/core.d.ts +2 -2
- package/dist/events/core.d.ts.map +1 -1
- package/dist/events/iframe.d.ts +11 -1
- package/dist/events/iframe.d.ts.map +1 -1
- package/dist/index.d.ts +43 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +400 -143
- package/dist/inject.d.ts +3 -0
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/allNetworkGetAddress.d.ts +12 -3
- package/dist/types/api/allNetworkGetAddress.d.ts.map +1 -1
- package/dist/types/api/evmGetPublicKey.d.ts +1 -0
- package/dist/types/api/evmGetPublicKey.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +2 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +3 -0
- package/src/api/allnetwork/AllNetworkGetAddress.ts +19 -408
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +480 -0
- package/src/api/allnetwork/AllNetworkGetAddressByLoop.ts +161 -0
- package/src/api/btc/BTCGetPublicKey.ts +13 -0
- package/src/api/cosmos/CosmosGetPublicKey.ts +1 -1
- package/src/api/device/DeviceUnlock.ts +1 -48
- package/src/api/evm/EVMGetPublicKey.ts +9 -3
- package/src/api/index.ts +1 -0
- package/src/core/RequestQueue.ts +26 -0
- package/src/core/index.ts +30 -3
- package/src/device/Device.ts +66 -0
- package/src/events/call.ts +10 -0
- package/src/events/core.ts +7 -1
- package/src/events/iframe.ts +12 -1
- package/src/index.ts +2 -1
- package/src/inject.ts +47 -0
- package/src/types/api/allNetworkGetAddress.ts +17 -3
- package/src/types/api/evmGetPublicKey.ts +1 -0
- package/src/types/api/index.ts +2 -1
package/dist/index.js
CHANGED
|
@@ -26,6 +26,82 @@ var ByteBuffer__default = /*#__PURE__*/_interopDefaultLegacy(ByteBuffer);
|
|
|
26
26
|
var BigNumber__default = /*#__PURE__*/_interopDefaultLegacy(BigNumber);
|
|
27
27
|
var JSZip__default = /*#__PURE__*/_interopDefaultLegacy(JSZip);
|
|
28
28
|
|
|
29
|
+
/******************************************************************************
|
|
30
|
+
Copyright (c) Microsoft Corporation.
|
|
31
|
+
|
|
32
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
33
|
+
purpose with or without fee is hereby granted.
|
|
34
|
+
|
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
36
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
37
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
38
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
39
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
40
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
41
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
42
|
+
***************************************************************************** */
|
|
43
|
+
|
|
44
|
+
function __rest(s, e) {
|
|
45
|
+
var t = {};
|
|
46
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
47
|
+
t[p] = s[p];
|
|
48
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
49
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
50
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
51
|
+
t[p[i]] = s[p[i]];
|
|
52
|
+
}
|
|
53
|
+
return t;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
57
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
58
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
59
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
60
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
61
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
62
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function __values(o) {
|
|
67
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
68
|
+
if (m) return m.call(o);
|
|
69
|
+
if (o && typeof o.length === "number") return {
|
|
70
|
+
next: function () {
|
|
71
|
+
if (o && i >= o.length) o = void 0;
|
|
72
|
+
return { value: o && o[i++], done: !o };
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function __asyncValues(o) {
|
|
79
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
80
|
+
var m = o[Symbol.asyncIterator], i;
|
|
81
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
82
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
83
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
87
|
+
var e = new Error(message);
|
|
88
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const callbackManager = new Map();
|
|
92
|
+
const generateCallbackId = () => `callback_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
93
|
+
const registerCallback = (id, callback) => {
|
|
94
|
+
callbackManager.set(id, callback);
|
|
95
|
+
};
|
|
96
|
+
const executeCallback = (id, ...args) => {
|
|
97
|
+
const callback = callbackManager.get(id);
|
|
98
|
+
if (callback) {
|
|
99
|
+
callback(...args);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const cleanupCallback = (id) => {
|
|
103
|
+
callbackManager.delete(id);
|
|
104
|
+
};
|
|
29
105
|
const inject = ({ call, cancel, dispose, eventEmitter, init, updateSettings, switchTransport, uiResponse, }) => {
|
|
30
106
|
const api = Object.assign({ on: (type, fn) => {
|
|
31
107
|
eventEmitter.on(type, fn);
|
|
@@ -77,6 +153,20 @@ const createCoreApi = (call) => ({
|
|
|
77
153
|
getNextU2FCounter: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'getNextU2FCounter' })),
|
|
78
154
|
setU2FCounter: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'setU2FCounter' })),
|
|
79
155
|
allNetworkGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'allNetworkGetAddress' })),
|
|
156
|
+
allNetworkGetAddressByLoop: (connectId, deviceId, params) => {
|
|
157
|
+
const { onLoopItemResponse, onAllItemsResponse } = params, restParams = __rest(params, ["onLoopItemResponse", "onAllItemsResponse"]);
|
|
158
|
+
const callbackId = generateCallbackId();
|
|
159
|
+
registerCallback(callbackId, onLoopItemResponse);
|
|
160
|
+
const callbackIdFinish = generateCallbackId();
|
|
161
|
+
registerCallback(callbackIdFinish, (data) => {
|
|
162
|
+
onAllItemsResponse === null || onAllItemsResponse === void 0 ? void 0 : onAllItemsResponse(data);
|
|
163
|
+
cleanupCallback(callbackIdFinish);
|
|
164
|
+
cleanupCallback(callbackId);
|
|
165
|
+
});
|
|
166
|
+
return call(Object.assign(Object.assign({}, restParams), { connectId,
|
|
167
|
+
deviceId, method: 'allNetworkGetAddressByLoop', callbackId,
|
|
168
|
+
callbackIdFinish }));
|
|
169
|
+
},
|
|
80
170
|
evmGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'evmGetAddress' })),
|
|
81
171
|
evmGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'evmGetPublicKey' })),
|
|
82
172
|
evmSignMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'evmSignMessage' })),
|
|
@@ -684,68 +774,6 @@ const topLevelInject = () => {
|
|
|
684
774
|
return api;
|
|
685
775
|
};
|
|
686
776
|
|
|
687
|
-
/******************************************************************************
|
|
688
|
-
Copyright (c) Microsoft Corporation.
|
|
689
|
-
|
|
690
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
691
|
-
purpose with or without fee is hereby granted.
|
|
692
|
-
|
|
693
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
694
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
695
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
696
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
697
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
698
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
699
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
700
|
-
***************************************************************************** */
|
|
701
|
-
|
|
702
|
-
function __rest(s, e) {
|
|
703
|
-
var t = {};
|
|
704
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
705
|
-
t[p] = s[p];
|
|
706
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
707
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
708
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
709
|
-
t[p[i]] = s[p[i]];
|
|
710
|
-
}
|
|
711
|
-
return t;
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
715
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
716
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
717
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
718
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
719
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
720
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
function __values(o) {
|
|
725
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
726
|
-
if (m) return m.call(o);
|
|
727
|
-
if (o && typeof o.length === "number") return {
|
|
728
|
-
next: function () {
|
|
729
|
-
if (o && i >= o.length) o = void 0;
|
|
730
|
-
return { value: o && o[i++], done: !o };
|
|
731
|
-
}
|
|
732
|
-
};
|
|
733
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
function __asyncValues(o) {
|
|
737
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
738
|
-
var m = o[Symbol.asyncIterator], i;
|
|
739
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
740
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
741
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
745
|
-
var e = new Error(message);
|
|
746
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
747
|
-
};
|
|
748
|
-
|
|
749
777
|
const LOG_EVENT = 'LOG_EVENT';
|
|
750
778
|
const LOG = {
|
|
751
779
|
OUTPUT: 'log-output',
|
|
@@ -25798,6 +25826,7 @@ const IFRAME = {
|
|
|
25798
25826
|
CALL: 'iframe-call',
|
|
25799
25827
|
CANCEL: 'iframe-cancel',
|
|
25800
25828
|
SWITCH_TRANSPORT: 'iframe-switch-transport',
|
|
25829
|
+
CALLBACK: 'iframe-callback',
|
|
25801
25830
|
};
|
|
25802
25831
|
const createIFrameMessage = (type, payload) => ({
|
|
25803
25832
|
event: UI_EVENT,
|
|
@@ -26691,6 +26720,15 @@ class Device extends events.exports {
|
|
|
26691
26720
|
const env = DataManager.getSettings('env');
|
|
26692
26721
|
if ((this.isUsedHere() && !this.keepSession && this.mainId) ||
|
|
26693
26722
|
(this.mainId && DataManager.isBleConnect(env))) {
|
|
26723
|
+
if (this.pendingCallbackPromise) {
|
|
26724
|
+
try {
|
|
26725
|
+
Log$a.debug('Waiting for callback tasks to complete before releasing device (in release method)');
|
|
26726
|
+
yield this.pendingCallbackPromise.promise;
|
|
26727
|
+
}
|
|
26728
|
+
catch (error) {
|
|
26729
|
+
Log$a.error('Error waiting for callback tasks in release method:', error);
|
|
26730
|
+
}
|
|
26731
|
+
}
|
|
26694
26732
|
if (this.commands) {
|
|
26695
26733
|
this.commands.dispose(false);
|
|
26696
26734
|
if (this.commands.callPromise) {
|
|
@@ -27071,6 +27109,46 @@ class Device extends events.exports {
|
|
|
27071
27109
|
return res.message;
|
|
27072
27110
|
});
|
|
27073
27111
|
}
|
|
27112
|
+
supportUnlockVersionRange() {
|
|
27113
|
+
return {
|
|
27114
|
+
pro: {
|
|
27115
|
+
min: '4.15.0',
|
|
27116
|
+
},
|
|
27117
|
+
};
|
|
27118
|
+
}
|
|
27119
|
+
unlockDevice() {
|
|
27120
|
+
var _a;
|
|
27121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27122
|
+
const firmwareVersion = (_a = getDeviceFirmwareVersion(this.features)) === null || _a === void 0 ? void 0 : _a.join('.');
|
|
27123
|
+
const versionRange = getMethodVersionRange(this.features, type => this.supportUnlockVersionRange()[type]);
|
|
27124
|
+
if (versionRange && semver__default["default"].gte(firmwareVersion, versionRange.min)) {
|
|
27125
|
+
const res = yield this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|
|
27126
|
+
if (this.features) {
|
|
27127
|
+
this.features.unlocked = res.message.unlocked == null ? null : res.message.unlocked;
|
|
27128
|
+
this.features.unlocked_attach_pin =
|
|
27129
|
+
res.message.unlocked_attach_pin == null ? undefined : res.message.unlocked_attach_pin;
|
|
27130
|
+
this.features.passphrase_protection =
|
|
27131
|
+
res.message.passphrase_protection == null ? null : res.message.passphrase_protection;
|
|
27132
|
+
return Promise.resolve(this.features);
|
|
27133
|
+
}
|
|
27134
|
+
const featuresRes = yield this.commands.typedCall('GetFeatures', 'Features');
|
|
27135
|
+
this._updateFeatures(featuresRes.message);
|
|
27136
|
+
return Promise.resolve(featuresRes.message);
|
|
27137
|
+
}
|
|
27138
|
+
const { type } = yield this.commands.typedCall('GetAddress', 'Address', {
|
|
27139
|
+
address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
|
|
27140
|
+
coin_name: 'Testnet',
|
|
27141
|
+
script_type: 'SPENDADDRESS',
|
|
27142
|
+
show_display: false,
|
|
27143
|
+
});
|
|
27144
|
+
if (type === 'CallMethodError') {
|
|
27145
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'unlock device error');
|
|
27146
|
+
}
|
|
27147
|
+
const res = yield this.commands.typedCall('GetFeatures', 'Features');
|
|
27148
|
+
this._updateFeatures(res.message);
|
|
27149
|
+
return Promise.resolve(res.message);
|
|
27150
|
+
});
|
|
27151
|
+
}
|
|
27074
27152
|
checkPassphraseStateSafety(passphraseState, useEmptyPassphrase, skipPassphraseCheck) {
|
|
27075
27153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27076
27154
|
if (!this.features)
|
|
@@ -28643,42 +28721,9 @@ class DeviceUnlock extends BaseMethod {
|
|
|
28643
28721
|
init() {
|
|
28644
28722
|
this.useDevicePassphraseState = false;
|
|
28645
28723
|
}
|
|
28646
|
-
supportUnlockVersionRange() {
|
|
28647
|
-
return {
|
|
28648
|
-
pro: {
|
|
28649
|
-
min: '4.15.0',
|
|
28650
|
-
},
|
|
28651
|
-
};
|
|
28652
|
-
}
|
|
28653
28724
|
run() {
|
|
28654
|
-
var _a;
|
|
28655
28725
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28656
|
-
|
|
28657
|
-
const versionRange = getMethodVersionRange(this.device.features, type => this.supportUnlockVersionRange()[type]);
|
|
28658
|
-
if (versionRange && semver__default["default"].gte(firmwareVersion, versionRange.min)) {
|
|
28659
|
-
const res = yield this.device.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|
|
28660
|
-
if (this.device.features) {
|
|
28661
|
-
this.device.features.unlocked = res.message.unlocked == null ? null : res.message.unlocked;
|
|
28662
|
-
this.device.features.unlocked_attach_pin =
|
|
28663
|
-
res.message.unlocked_attach_pin == null ? undefined : res.message.unlocked_attach_pin;
|
|
28664
|
-
this.device.features.passphrase_protection =
|
|
28665
|
-
res.message.passphrase_protection == null ? null : res.message.passphrase_protection;
|
|
28666
|
-
return Promise.resolve(this.device.features);
|
|
28667
|
-
}
|
|
28668
|
-
const featuresRes = yield this.device.commands.typedCall('GetFeatures', 'Features');
|
|
28669
|
-
return Promise.resolve(featuresRes.message);
|
|
28670
|
-
}
|
|
28671
|
-
const { type } = yield this.device.commands.typedCall('GetAddress', 'Address', {
|
|
28672
|
-
address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
|
|
28673
|
-
coin_name: 'Testnet',
|
|
28674
|
-
script_type: 'SPENDADDRESS',
|
|
28675
|
-
show_display: false,
|
|
28676
|
-
});
|
|
28677
|
-
if (type === 'CallMethodError') {
|
|
28678
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
|
|
28679
|
-
}
|
|
28680
|
-
const res = yield this.device.commands.typedCall('GetFeatures', 'Features');
|
|
28681
|
-
return Promise.resolve(res.message);
|
|
28726
|
+
return this.device.unlockDevice();
|
|
28682
28727
|
});
|
|
28683
28728
|
}
|
|
28684
28729
|
}
|
|
@@ -30041,12 +30086,17 @@ const networkConfigMap = {
|
|
|
30041
30086
|
methodName: 'neoGetAddress',
|
|
30042
30087
|
},
|
|
30043
30088
|
};
|
|
30044
|
-
class
|
|
30089
|
+
class AllNetworkGetAddressBase extends BaseMethod {
|
|
30090
|
+
constructor() {
|
|
30091
|
+
super(...arguments);
|
|
30092
|
+
this.abortController = null;
|
|
30093
|
+
}
|
|
30045
30094
|
init() {
|
|
30095
|
+
var _a, _b;
|
|
30046
30096
|
this.checkDeviceId = true;
|
|
30047
30097
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
30048
30098
|
validateParams(this.payload, [{ name: 'bundle', type: 'array' }]);
|
|
30049
|
-
this.payload.bundle.forEach((batch) => {
|
|
30099
|
+
(_b = (_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle) === null || _b === void 0 ? void 0 : _b.forEach((batch) => {
|
|
30050
30100
|
validateParams(batch, [
|
|
30051
30101
|
{ name: 'path', required: true },
|
|
30052
30102
|
{ name: 'network', type: 'string', required: true },
|
|
@@ -30072,7 +30122,7 @@ class AllNetworkGetAddress extends BaseMethod {
|
|
|
30072
30122
|
_originalIndex: originalIndex,
|
|
30073
30123
|
};
|
|
30074
30124
|
}
|
|
30075
|
-
callMethod(methodName, params) {
|
|
30125
|
+
callMethod(methodName, params, rootFingerprint) {
|
|
30076
30126
|
var _a;
|
|
30077
30127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30078
30128
|
const method = findMethod({
|
|
@@ -30086,12 +30136,29 @@ class AllNetworkGetAddress extends BaseMethod {
|
|
|
30086
30136
|
try {
|
|
30087
30137
|
method.init();
|
|
30088
30138
|
(_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, this.device);
|
|
30139
|
+
method.context = this.context;
|
|
30140
|
+
const onSignalAbort = () => {
|
|
30141
|
+
var _a;
|
|
30142
|
+
(_a = this.abortController) === null || _a === void 0 ? void 0 : _a.abort(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
|
|
30143
|
+
};
|
|
30144
|
+
const _onDeviceButtonHandler = (...[device, request]) => {
|
|
30145
|
+
if (request.code === 'ButtonRequest_PinEntry' ||
|
|
30146
|
+
request.code === 'ButtonRequest_AttachPin') {
|
|
30147
|
+
onSignalAbort();
|
|
30148
|
+
}
|
|
30149
|
+
else {
|
|
30150
|
+
onDeviceButtonHandler(device, request);
|
|
30151
|
+
}
|
|
30152
|
+
};
|
|
30153
|
+
this.device.on(DEVICE.BUTTON, _onDeviceButtonHandler);
|
|
30154
|
+
this.device.on(DEVICE.PIN, onSignalAbort);
|
|
30155
|
+
this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
|
|
30089
30156
|
preCheckDeviceSupport(this.device, method);
|
|
30090
30157
|
const response = yield method.run();
|
|
30091
30158
|
if (!Array.isArray(response) || response.length === 0) {
|
|
30092
30159
|
throw new Error('No response');
|
|
30093
30160
|
}
|
|
30094
|
-
result = response.map((item, index) => (Object.assign(Object.assign({}, params.bundle[index]._originRequestParams), { success: true, payload: item })));
|
|
30161
|
+
result = response.map((item, index) => (Object.assign(Object.assign({}, params.bundle[index]._originRequestParams), { success: true, payload: Object.assign(Object.assign({}, item), { rootFingerprint }) })));
|
|
30095
30162
|
}
|
|
30096
30163
|
catch (e) {
|
|
30097
30164
|
const error = handleSkippableHardwareError(e, this.device, method);
|
|
@@ -30112,45 +30179,24 @@ class AllNetworkGetAddress extends BaseMethod {
|
|
|
30112
30179
|
});
|
|
30113
30180
|
}
|
|
30114
30181
|
run() {
|
|
30115
|
-
var _a, _b;
|
|
30116
30182
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30117
|
-
const
|
|
30118
|
-
|
|
30119
|
-
|
|
30120
|
-
|
|
30121
|
-
|
|
30122
|
-
|
|
30123
|
-
|
|
30124
|
-
|
|
30125
|
-
|
|
30126
|
-
|
|
30127
|
-
|
|
30128
|
-
|
|
30129
|
-
|
|
30130
|
-
|
|
30131
|
-
return acc;
|
|
30132
|
-
}, {});
|
|
30133
|
-
let i = 0;
|
|
30134
|
-
for (const [methodName, params] of Object.entries(methodGroups)) {
|
|
30135
|
-
const methodParams = {
|
|
30136
|
-
bundle: params.map(param => (Object.assign({}, param.params))),
|
|
30137
|
-
};
|
|
30138
|
-
const response = yield this.callMethod(methodName, methodParams);
|
|
30139
|
-
for (let i = 0; i < params.length; i++) {
|
|
30140
|
-
const { _originRequestParams, _originalIndex } = params[i];
|
|
30141
|
-
const responseKey = `${_originalIndex}`;
|
|
30142
|
-
resultMap[responseKey] = Object.assign(Object.assign({}, _originRequestParams), response[i]);
|
|
30143
|
-
}
|
|
30144
|
-
if (((_b = (_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle) === null || _b === void 0 ? void 0 : _b.length) > 1) {
|
|
30145
|
-
const progress = Math.round(((i + 1) / this.payload.bundle.length) * 100);
|
|
30146
|
-
this.postMessage(createUiMessage(UI_REQUEST.DEVICE_PROGRESS, { progress }));
|
|
30183
|
+
const res = yield this.device.commands.typedCall('GetPublicKey', 'PublicKey', {
|
|
30184
|
+
address_n: [toHardened(44), toHardened(1), toHardened(0)],
|
|
30185
|
+
coin_name: 'Testnet',
|
|
30186
|
+
script_type: 'SPENDADDRESS',
|
|
30187
|
+
show_display: false,
|
|
30188
|
+
});
|
|
30189
|
+
this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
|
|
30190
|
+
if (res.message.root_fingerprint == null) {
|
|
30191
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter);
|
|
30192
|
+
}
|
|
30193
|
+
this.abortController = new AbortController();
|
|
30194
|
+
return this.getAllNetworkAddress(res.message.root_fingerprint).catch(e => {
|
|
30195
|
+
if (e instanceof hdShared.HardwareError && e.errorCode === hdShared.HardwareErrorCode.RepeatUnlocking) {
|
|
30196
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RepeatUnlocking, e.message);
|
|
30147
30197
|
}
|
|
30148
|
-
|
|
30149
|
-
}
|
|
30150
|
-
for (let i = 0; i < bundle.length; i++) {
|
|
30151
|
-
responses.push(resultMap[i]);
|
|
30152
|
-
}
|
|
30153
|
-
return Promise.resolve(responses);
|
|
30198
|
+
throw e;
|
|
30199
|
+
});
|
|
30154
30200
|
});
|
|
30155
30201
|
}
|
|
30156
30202
|
}
|
|
@@ -30171,10 +30217,7 @@ function handleSkippableHardwareError(e, device, method) {
|
|
|
30171
30217
|
let error;
|
|
30172
30218
|
if (e instanceof hdShared.HardwareError && e.errorCode !== hdShared.HardwareErrorCode.RuntimeError) {
|
|
30173
30219
|
const { errorCode } = e;
|
|
30174
|
-
if (errorCode === hdShared.HardwareErrorCode.
|
|
30175
|
-
error = e;
|
|
30176
|
-
}
|
|
30177
|
-
else if (errorCode === hdShared.HardwareErrorCode.CallMethodNeedUpgradeFirmware) {
|
|
30220
|
+
if (errorCode === hdShared.HardwareErrorCode.CallMethodNeedUpgradeFirmware) {
|
|
30178
30221
|
error = e;
|
|
30179
30222
|
}
|
|
30180
30223
|
else if (errorCode === hdShared.HardwareErrorCode.DeviceNotSupportMethod) {
|
|
@@ -30200,6 +30243,164 @@ function handleSkippableHardwareError(e, device, method) {
|
|
|
30200
30243
|
return error;
|
|
30201
30244
|
}
|
|
30202
30245
|
|
|
30246
|
+
class AllNetworkGetAddress extends AllNetworkGetAddressBase {
|
|
30247
|
+
getAllNetworkAddress(rootFingerprint) {
|
|
30248
|
+
var _a, _b, _c, _d;
|
|
30249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30250
|
+
const responses = [];
|
|
30251
|
+
const resultMap = {};
|
|
30252
|
+
const { bundle } = this.payload;
|
|
30253
|
+
const methodGroups = bundle
|
|
30254
|
+
.map((param, index) => this.generateMethodName({
|
|
30255
|
+
network: param.network,
|
|
30256
|
+
payload: param,
|
|
30257
|
+
originalIndex: index,
|
|
30258
|
+
}))
|
|
30259
|
+
.reduce((acc, cur) => {
|
|
30260
|
+
if (!acc[cur.methodName]) {
|
|
30261
|
+
acc[cur.methodName] = [];
|
|
30262
|
+
}
|
|
30263
|
+
acc[cur.methodName].push(cur);
|
|
30264
|
+
return acc;
|
|
30265
|
+
}, {});
|
|
30266
|
+
let i = 0;
|
|
30267
|
+
for (const [methodName, params] of Object.entries(methodGroups)) {
|
|
30268
|
+
const methodParams = {
|
|
30269
|
+
bundle: params.map(param => (Object.assign({}, param.params))),
|
|
30270
|
+
};
|
|
30271
|
+
if ((_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
|
|
30272
|
+
throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
|
|
30273
|
+
}
|
|
30274
|
+
const response = yield this.callMethod(methodName, methodParams, rootFingerprint);
|
|
30275
|
+
if ((_b = this.abortController) === null || _b === void 0 ? void 0 : _b.signal.aborted) {
|
|
30276
|
+
throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
|
|
30277
|
+
}
|
|
30278
|
+
for (let i = 0; i < params.length; i++) {
|
|
30279
|
+
const { _originRequestParams, _originalIndex } = params[i];
|
|
30280
|
+
const responseKey = `${_originalIndex}`;
|
|
30281
|
+
resultMap[responseKey] = Object.assign(Object.assign({}, _originRequestParams), response[i]);
|
|
30282
|
+
}
|
|
30283
|
+
if (((_d = (_c = this.payload) === null || _c === void 0 ? void 0 : _c.bundle) === null || _d === void 0 ? void 0 : _d.length) > 1) {
|
|
30284
|
+
const progress = Math.round(((i + 1) / this.payload.bundle.length) * 100);
|
|
30285
|
+
this.postMessage(createUiMessage(UI_REQUEST.DEVICE_PROGRESS, { progress }));
|
|
30286
|
+
}
|
|
30287
|
+
i++;
|
|
30288
|
+
}
|
|
30289
|
+
for (let i = 0; i < bundle.length; i++) {
|
|
30290
|
+
responses.push(resultMap[i]);
|
|
30291
|
+
}
|
|
30292
|
+
this.abortController = null;
|
|
30293
|
+
return Promise.resolve(responses);
|
|
30294
|
+
});
|
|
30295
|
+
}
|
|
30296
|
+
}
|
|
30297
|
+
|
|
30298
|
+
class AllNetworkGetAddressByLoop extends AllNetworkGetAddressBase {
|
|
30299
|
+
getAllNetworkAddress(rootFingerprint) {
|
|
30300
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30301
|
+
const { callbackId, callbackIdFinish } = this.payload;
|
|
30302
|
+
if (!callbackId) {
|
|
30303
|
+
throw new Error('callbackId is required');
|
|
30304
|
+
}
|
|
30305
|
+
if (!callbackIdFinish) {
|
|
30306
|
+
throw new Error('callbackIdFinish is required');
|
|
30307
|
+
}
|
|
30308
|
+
const bundle = this.payload.bundle || [this.payload];
|
|
30309
|
+
const callbackPromise = this.processCallbacksInBackground(bundle, rootFingerprint, callbackId, callbackIdFinish);
|
|
30310
|
+
this.device.pendingCallbackPromise = hdShared.createDeferred(callbackPromise);
|
|
30311
|
+
if (this.context && this.payload.connectId) {
|
|
30312
|
+
this.context.registerCallbackTask(this.payload.connectId, this.device.pendingCallbackPromise);
|
|
30313
|
+
}
|
|
30314
|
+
return Promise.resolve([]);
|
|
30315
|
+
});
|
|
30316
|
+
}
|
|
30317
|
+
processCallbacksInBackground(bundle, rootFingerprint, callbackId, callbackIdFinish) {
|
|
30318
|
+
var _a, _b, _c;
|
|
30319
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30320
|
+
try {
|
|
30321
|
+
const allResults = [];
|
|
30322
|
+
for (let i = 0; i < bundle.length; i++) {
|
|
30323
|
+
const item = bundle[i];
|
|
30324
|
+
if ((_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
|
|
30325
|
+
throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
|
|
30326
|
+
}
|
|
30327
|
+
const methodParams = this.generateMethodName({
|
|
30328
|
+
network: item.network,
|
|
30329
|
+
payload: item,
|
|
30330
|
+
originalIndex: i,
|
|
30331
|
+
});
|
|
30332
|
+
const singleMethodParams = {
|
|
30333
|
+
bundle: [methodParams.params],
|
|
30334
|
+
};
|
|
30335
|
+
const response = yield this.callMethod(methodParams.methodName, singleMethodParams, rootFingerprint);
|
|
30336
|
+
if ((_b = this.abortController) === null || _b === void 0 ? void 0 : _b.signal.aborted) {
|
|
30337
|
+
throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
|
|
30338
|
+
}
|
|
30339
|
+
const singleResult = Object.assign(Object.assign({}, item), response[0]);
|
|
30340
|
+
allResults.push(singleResult);
|
|
30341
|
+
this.sendItemCallback(callbackId, singleResult, i);
|
|
30342
|
+
}
|
|
30343
|
+
this.sendFinishCallback({
|
|
30344
|
+
callbackId: callbackIdFinish,
|
|
30345
|
+
data: allResults,
|
|
30346
|
+
});
|
|
30347
|
+
}
|
|
30348
|
+
catch (error) {
|
|
30349
|
+
let errorCode = error.errorCode || error.code;
|
|
30350
|
+
let errorMessage = error.message;
|
|
30351
|
+
if (error instanceof hdShared.HardwareError) {
|
|
30352
|
+
errorCode = error.errorCode;
|
|
30353
|
+
errorMessage = error.message;
|
|
30354
|
+
}
|
|
30355
|
+
else if (error.message === hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]) {
|
|
30356
|
+
errorCode = hdShared.HardwareErrorCode.RepeatUnlocking;
|
|
30357
|
+
errorMessage = error.message;
|
|
30358
|
+
}
|
|
30359
|
+
else {
|
|
30360
|
+
const hardwareError = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, error.message);
|
|
30361
|
+
errorCode = hardwareError.errorCode;
|
|
30362
|
+
errorMessage = hardwareError.message;
|
|
30363
|
+
}
|
|
30364
|
+
this.sendFinishCallback({
|
|
30365
|
+
callbackId: callbackIdFinish,
|
|
30366
|
+
error: {
|
|
30367
|
+
success: false,
|
|
30368
|
+
payload: {
|
|
30369
|
+
error: errorMessage,
|
|
30370
|
+
code: errorCode,
|
|
30371
|
+
},
|
|
30372
|
+
},
|
|
30373
|
+
});
|
|
30374
|
+
}
|
|
30375
|
+
finally {
|
|
30376
|
+
(_c = this.context) === null || _c === void 0 ? void 0 : _c.cancelCallbackTasks(this.payload.connectId);
|
|
30377
|
+
this.abortController = null;
|
|
30378
|
+
}
|
|
30379
|
+
});
|
|
30380
|
+
}
|
|
30381
|
+
sendFinishCallback({ callbackId, data, error, }) {
|
|
30382
|
+
this.postMessage({
|
|
30383
|
+
event: IFRAME.CALLBACK,
|
|
30384
|
+
type: IFRAME.CALLBACK,
|
|
30385
|
+
payload: {
|
|
30386
|
+
callbackId,
|
|
30387
|
+
data,
|
|
30388
|
+
error,
|
|
30389
|
+
},
|
|
30390
|
+
});
|
|
30391
|
+
}
|
|
30392
|
+
sendItemCallback(callbackId, data, itemIndex) {
|
|
30393
|
+
this.postMessage({
|
|
30394
|
+
event: IFRAME.CALLBACK,
|
|
30395
|
+
type: IFRAME.CALLBACK,
|
|
30396
|
+
payload: {
|
|
30397
|
+
callbackId,
|
|
30398
|
+
data: Object.assign(Object.assign({}, data), { index: itemIndex }),
|
|
30399
|
+
},
|
|
30400
|
+
});
|
|
30401
|
+
}
|
|
30402
|
+
}
|
|
30403
|
+
|
|
30203
30404
|
var bitcoin = [
|
|
30204
30405
|
{
|
|
30205
30406
|
name: "Bitcoin",
|
|
@@ -30774,6 +30975,15 @@ class BTCGetPublicKey extends BaseMethod {
|
|
|
30774
30975
|
}
|
|
30775
30976
|
}
|
|
30776
30977
|
catch (error) {
|
|
30978
|
+
if (error instanceof hdShared.HardwareError) {
|
|
30979
|
+
const { errorCode } = error;
|
|
30980
|
+
if (errorCode === hdShared.HardwareErrorCode.PinCancelled ||
|
|
30981
|
+
errorCode === hdShared.HardwareErrorCode.ActionCancelled ||
|
|
30982
|
+
errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError ||
|
|
30983
|
+
errorCode === hdShared.HardwareErrorCode.PinInvalid) {
|
|
30984
|
+
throw error;
|
|
30985
|
+
}
|
|
30986
|
+
}
|
|
30777
30987
|
responses = [];
|
|
30778
30988
|
for (let i = 0; i < this.params.length; i++) {
|
|
30779
30989
|
const param = this.params[i];
|
|
@@ -31613,6 +31823,7 @@ class EVMGetPublicKey extends BaseMethod {
|
|
|
31613
31823
|
constructor() {
|
|
31614
31824
|
super(...arguments);
|
|
31615
31825
|
this.hasBundle = false;
|
|
31826
|
+
this.confirmShowOnOneKey = false;
|
|
31616
31827
|
this.useBatch = false;
|
|
31617
31828
|
}
|
|
31618
31829
|
init() {
|
|
@@ -31620,7 +31831,8 @@ class EVMGetPublicKey extends BaseMethod {
|
|
|
31620
31831
|
this.checkDeviceId = true;
|
|
31621
31832
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
31622
31833
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
31623
|
-
this.
|
|
31834
|
+
this.confirmShowOnOneKey = (_c = (_b = this.payload) === null || _b === void 0 ? void 0 : _b.bundle) === null || _c === void 0 ? void 0 : _c.some((item) => !!item.showOnOneKey);
|
|
31835
|
+
this.useBatch = !this.confirmShowOnOneKey && this.hasBundle && this.payload.useBatch;
|
|
31624
31836
|
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
31625
31837
|
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
31626
31838
|
this.params = [];
|
|
@@ -31656,7 +31868,7 @@ class EVMGetPublicKey extends BaseMethod {
|
|
|
31656
31868
|
var _a;
|
|
31657
31869
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31658
31870
|
const responses = [];
|
|
31659
|
-
if (this.useBatch &&
|
|
31871
|
+
if (this.useBatch && supportBatchPublicKey((_a = this.device) === null || _a === void 0 ? void 0 : _a.features)) {
|
|
31660
31872
|
try {
|
|
31661
31873
|
const res = yield batchGetPublickeys(this.device, this.params, 'secp256k1', 60, {
|
|
31662
31874
|
includeNode: false,
|
|
@@ -38113,6 +38325,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
38113
38325
|
promptWebDeviceAccess: PromptWebDeviceAccess,
|
|
38114
38326
|
cipherKeyValue: CipherKeyValue,
|
|
38115
38327
|
allNetworkGetAddress: AllNetworkGetAddress,
|
|
38328
|
+
allNetworkGetAddressByLoop: AllNetworkGetAddressByLoop,
|
|
38116
38329
|
btcGetAddress: BTCGetAddress,
|
|
38117
38330
|
btcGetPublicKey: BTCGetPublicKey,
|
|
38118
38331
|
btcSignMessage: BTCSignMessage,
|
|
@@ -38325,6 +38538,7 @@ const Log$1 = getLogger(exports.LoggerNames.Core);
|
|
|
38325
38538
|
class RequestQueue {
|
|
38326
38539
|
constructor() {
|
|
38327
38540
|
this.requestQueue = new Map();
|
|
38541
|
+
this.pendingCallbackTasks = new Map();
|
|
38328
38542
|
this.generateRequestId = (method) => {
|
|
38329
38543
|
if (method && method.responseID != null) {
|
|
38330
38544
|
return method.responseID;
|
|
@@ -38401,6 +38615,28 @@ class RequestQueue {
|
|
|
38401
38615
|
releaseTask(requestId) {
|
|
38402
38616
|
this.requestQueue.delete(requestId);
|
|
38403
38617
|
}
|
|
38618
|
+
registerPendingCallbackTask(connectId, callbackPromise) {
|
|
38619
|
+
this.pendingCallbackTasks.set(connectId, callbackPromise);
|
|
38620
|
+
callbackPromise.promise.finally(() => {
|
|
38621
|
+
Log$1.debug(`Callback task completed for connectId: ${connectId}`);
|
|
38622
|
+
this.pendingCallbackTasks.delete(connectId);
|
|
38623
|
+
});
|
|
38624
|
+
}
|
|
38625
|
+
waitForPendingCallbackTasks(connectId) {
|
|
38626
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38627
|
+
const pendingTask = this.pendingCallbackTasks.get(connectId);
|
|
38628
|
+
if (pendingTask) {
|
|
38629
|
+
Log$1.debug(`Waiting for pending callback task to complete for connectId: ${connectId}`);
|
|
38630
|
+
yield pendingTask.promise;
|
|
38631
|
+
}
|
|
38632
|
+
});
|
|
38633
|
+
}
|
|
38634
|
+
cancelCallbackTasks(connectId) {
|
|
38635
|
+
const pendingTask = this.pendingCallbackTasks.get(connectId);
|
|
38636
|
+
if (pendingTask) {
|
|
38637
|
+
pendingTask.resolve();
|
|
38638
|
+
}
|
|
38639
|
+
}
|
|
38404
38640
|
}
|
|
38405
38641
|
|
|
38406
38642
|
const getMutex = () => {
|
|
@@ -38523,6 +38759,9 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
38523
38759
|
Log.debug('passphrase state change, clear device cache');
|
|
38524
38760
|
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
38525
38761
|
}
|
|
38762
|
+
if (method.connectId) {
|
|
38763
|
+
yield context.waitForCallbackTasks(method.connectId);
|
|
38764
|
+
}
|
|
38526
38765
|
yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
38527
38766
|
const task = requestQueue.createTask(method);
|
|
38528
38767
|
let device;
|
|
@@ -38546,6 +38785,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
38546
38785
|
}
|
|
38547
38786
|
Log.debug('Call API - setDevice: ', device.mainId);
|
|
38548
38787
|
(_b = method.setDevice) === null || _b === void 0 ? void 0 : _b.call(method, device);
|
|
38788
|
+
method.context = context;
|
|
38549
38789
|
device.on(DEVICE.PIN, onDevicePinHandler);
|
|
38550
38790
|
device.on(DEVICE.BUTTON, onDeviceButtonHandler);
|
|
38551
38791
|
device.on(DEVICE.PASSPHRASE, message.payload.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler);
|
|
@@ -38553,6 +38793,9 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
38553
38793
|
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
38554
38794
|
device.on(DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE, onSelectDeviceInBootloaderForWebDeviceHandler);
|
|
38555
38795
|
try {
|
|
38796
|
+
if (method.connectId) {
|
|
38797
|
+
yield context.waitForCallbackTasks(method.connectId);
|
|
38798
|
+
}
|
|
38556
38799
|
yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
38557
38800
|
const inner = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38558
38801
|
var _c, _d, _e, _f, _g;
|
|
@@ -38860,6 +39103,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
|
|
|
38860
39103
|
hdShared.HardwareErrorCode.BleWriteCharacteristicError,
|
|
38861
39104
|
hdShared.HardwareErrorCode.BleAlreadyConnected,
|
|
38862
39105
|
hdShared.HardwareErrorCode.FirmwareUpdateLimitOneDevice,
|
|
39106
|
+
hdShared.HardwareErrorCode.SelectDevice,
|
|
38863
39107
|
hdShared.HardwareErrorCode.DeviceDetectInBootloaderMode,
|
|
38864
39108
|
hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure,
|
|
38865
39109
|
hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission,
|
|
@@ -38890,6 +39134,7 @@ const cancel = (context, connectId) => {
|
|
|
38890
39134
|
const { requestQueue, setPrePendingCallPromise } = context;
|
|
38891
39135
|
if (connectId) {
|
|
38892
39136
|
try {
|
|
39137
|
+
requestQueue.cancelCallbackTasks(connectId);
|
|
38893
39138
|
const requestIds = requestQueue.getRequestTasksId();
|
|
38894
39139
|
Log.debug(`Cancel Api connect requestQueues: length:${requestIds.length} requestIds:${requestIds.join(',')}`);
|
|
38895
39140
|
const canceledDevices = [];
|
|
@@ -39070,6 +39315,11 @@ class Core extends events.exports {
|
|
|
39070
39315
|
setPrePendingCallPromise: (promise) => {
|
|
39071
39316
|
this.prePendingCallPromise = promise;
|
|
39072
39317
|
},
|
|
39318
|
+
registerCallbackTask: (connectId, callbackPromise) => {
|
|
39319
|
+
this.requestQueue.registerPendingCallbackTask(connectId, callbackPromise);
|
|
39320
|
+
},
|
|
39321
|
+
waitForCallbackTasks: (connectId) => this.requestQueue.waitForPendingCallbackTasks(connectId),
|
|
39322
|
+
cancelCallbackTasks: (connectId) => this.requestQueue.cancelCallbackTasks(connectId),
|
|
39073
39323
|
};
|
|
39074
39324
|
}
|
|
39075
39325
|
handleMessage(message) {
|
|
@@ -39111,6 +39361,11 @@ class Core extends events.exports {
|
|
|
39111
39361
|
cancel(this.getCoreContext(), message.payload.connectId);
|
|
39112
39362
|
break;
|
|
39113
39363
|
}
|
|
39364
|
+
case IFRAME.CALLBACK: {
|
|
39365
|
+
Log.log('callback message: ', message);
|
|
39366
|
+
postMessage(message);
|
|
39367
|
+
break;
|
|
39368
|
+
}
|
|
39114
39369
|
}
|
|
39115
39370
|
return Promise.resolve(message);
|
|
39116
39371
|
});
|
|
@@ -39209,6 +39464,7 @@ exports.UI_REQUEST = UI_REQUEST;
|
|
|
39209
39464
|
exports.UI_RESPONSE = UI_RESPONSE;
|
|
39210
39465
|
exports.checkNeedUpdateBootForClassicAndMini = checkNeedUpdateBootForClassicAndMini;
|
|
39211
39466
|
exports.checkNeedUpdateBootForTouch = checkNeedUpdateBootForTouch;
|
|
39467
|
+
exports.cleanupCallback = cleanupCallback;
|
|
39212
39468
|
exports.corsValidator = corsValidator;
|
|
39213
39469
|
exports.createDeviceMessage = createDeviceMessage;
|
|
39214
39470
|
exports.createErrorMessage = createErrorMessage;
|
|
@@ -39220,6 +39476,7 @@ exports.createUiMessage = createUiMessage;
|
|
|
39220
39476
|
exports.createUiResponse = createUiResponse;
|
|
39221
39477
|
exports["default"] = HardwareSdk;
|
|
39222
39478
|
exports.enableLog = enableLog;
|
|
39479
|
+
exports.executeCallback = executeCallback;
|
|
39223
39480
|
exports.getDeviceBLEFirmwareVersion = getDeviceBLEFirmwareVersion;
|
|
39224
39481
|
exports.getDeviceBleName = getDeviceBleName;
|
|
39225
39482
|
exports.getDeviceBoardloaderVersion = getDeviceBoardloaderVersion;
|