@onekeyfe/hd-web-sdk 0.0.9 → 0.1.1
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.6bb43909abd5d815e337.js +3 -0
- package/build/js/{iframe.1a13e0dba05bc9240b0d.js.LICENSE.txt → iframe.6bb43909abd5d815e337.js.LICENSE.txt} +0 -0
- package/build/js/iframe.6bb43909abd5d815e337.js.map +1 -0
- package/build/onekey-js-sdk.js +266 -21
- 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/package.json +6 -4
- package/webpack/webpack.config.ts +5 -0
- package/build/js/iframe.1a13e0dba05bc9240b0d.js +0 -3
- package/build/js/iframe.1a13e0dba05bc9240b0d.js.map +0 -1
package/build/onekey-js-sdk.js
CHANGED
|
@@ -4215,6 +4215,10 @@ const inject = ({
|
|
|
4215
4215
|
stellarSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4216
4216
|
connectId,
|
|
4217
4217
|
method: 'stellarSignTransaction'
|
|
4218
|
+
})),
|
|
4219
|
+
firmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4220
|
+
connectId,
|
|
4221
|
+
method: 'firmwareUpdate'
|
|
4218
4222
|
}))
|
|
4219
4223
|
};
|
|
4220
4224
|
return api;
|
|
@@ -4772,6 +4776,7 @@ const ERROR_CODES = {
|
|
|
4772
4776
|
Method_InvalidParameter: '',
|
|
4773
4777
|
Call_API: '',
|
|
4774
4778
|
Call_NotResponse: 'No response data',
|
|
4779
|
+
Method_FirmwareUpdate_DownloadFailed: '',
|
|
4775
4780
|
Transport_InvalidProtobuf: '',
|
|
4776
4781
|
Device_FwException: '',
|
|
4777
4782
|
Device_UnexpectedMode: '',
|
|
@@ -4904,7 +4909,8 @@ const enableLog = enabled => {
|
|
|
4904
4909
|
const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0, function* () {
|
|
4905
4910
|
const response = yield axios__default["default"].request({
|
|
4906
4911
|
url,
|
|
4907
|
-
withCredentials: false
|
|
4912
|
+
withCredentials: false,
|
|
4913
|
+
responseType: type === 'binary' ? 'arraybuffer' : 'json'
|
|
4908
4914
|
});
|
|
4909
4915
|
|
|
4910
4916
|
if (+response.status === 200) {
|
|
@@ -4913,7 +4919,7 @@ const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0,
|
|
|
4913
4919
|
}
|
|
4914
4920
|
|
|
4915
4921
|
if (type === 'binary') {
|
|
4916
|
-
return response.data
|
|
4922
|
+
return response.data;
|
|
4917
4923
|
}
|
|
4918
4924
|
|
|
4919
4925
|
return response.data;
|
|
@@ -4922,7 +4928,7 @@ const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0,
|
|
|
4922
4928
|
throw new Error(`httpRequest error: ${url} ${response.statusText}`);
|
|
4923
4929
|
});
|
|
4924
4930
|
|
|
4925
|
-
const httpRequest = (url,
|
|
4931
|
+
const httpRequest = (url, type) => httpRequest$1(url, type);
|
|
4926
4932
|
|
|
4927
4933
|
const getTimeStamp = () => new Date().getTime();
|
|
4928
4934
|
|
|
@@ -13896,6 +13902,25 @@ var MessagesJSON = {
|
|
|
13896
13902
|
nested: nested
|
|
13897
13903
|
};
|
|
13898
13904
|
|
|
13905
|
+
const getReleaseStatus = (releases, currentVersion) => {
|
|
13906
|
+
const newVersions = releases.filter(r => semver__default["default"].gt(r.version.join('.'), currentVersion));
|
|
13907
|
+
|
|
13908
|
+
if (newVersions.length === 0) {
|
|
13909
|
+
return 'valid';
|
|
13910
|
+
}
|
|
13911
|
+
|
|
13912
|
+
if (newVersions.some(r => r.required)) {
|
|
13913
|
+
return 'required';
|
|
13914
|
+
}
|
|
13915
|
+
|
|
13916
|
+
return 'outdated';
|
|
13917
|
+
};
|
|
13918
|
+
|
|
13919
|
+
const getReleaseChangelog = (releases, currentVersion) => {
|
|
13920
|
+
const newVersions = releases.filter(r => semver__default["default"].gt(r.version.join('.'), currentVersion));
|
|
13921
|
+
return newVersions.map(r => r.changelog);
|
|
13922
|
+
};
|
|
13923
|
+
|
|
13899
13924
|
var _a;
|
|
13900
13925
|
|
|
13901
13926
|
class DataManager {
|
|
@@ -13975,17 +14000,31 @@ DataManager.getFirmwareStatus = features => {
|
|
|
13975
14000
|
}
|
|
13976
14001
|
|
|
13977
14002
|
const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.firmware) !== null && _c !== void 0 ? _c : [];
|
|
13978
|
-
const latestFirmware = targetDeviceConfigList[targetDeviceConfigList.length - 1];
|
|
13979
|
-
if (!latestFirmware) return 'valid';
|
|
13980
|
-
const latestVersion = latestFirmware.version.join('.');
|
|
13981
14003
|
const currentVersion = deviceFirmwareVersion.join('.');
|
|
14004
|
+
return getReleaseStatus(targetDeviceConfigList, currentVersion);
|
|
14005
|
+
};
|
|
14006
|
+
|
|
14007
|
+
DataManager.getFirmwareChangelog = features => {
|
|
14008
|
+
var _b, _c;
|
|
14009
|
+
|
|
14010
|
+
const deviceType = getDeviceType(features);
|
|
14011
|
+
const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
|
|
13982
14012
|
|
|
13983
|
-
if (
|
|
13984
|
-
|
|
13985
|
-
return 'outdated';
|
|
14013
|
+
if (features.firmware_present === false || deviceType === 'classic' && features.bootloader_mode) {
|
|
14014
|
+
return [];
|
|
13986
14015
|
}
|
|
13987
14016
|
|
|
13988
|
-
|
|
14017
|
+
const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.firmware) !== null && _c !== void 0 ? _c : [];
|
|
14018
|
+
const currentVersion = deviceFirmwareVersion.join('.');
|
|
14019
|
+
return getReleaseChangelog(targetDeviceConfigList, currentVersion);
|
|
14020
|
+
};
|
|
14021
|
+
|
|
14022
|
+
DataManager.getFirmwareLeatestRelease = features => {
|
|
14023
|
+
var _b, _c;
|
|
14024
|
+
|
|
14025
|
+
const deviceType = getDeviceType(features);
|
|
14026
|
+
const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.firmware) !== null && _c !== void 0 ? _c : [];
|
|
14027
|
+
return targetDeviceConfigList[targetDeviceConfigList.length - 1];
|
|
13989
14028
|
};
|
|
13990
14029
|
|
|
13991
14030
|
DataManager.getBLEFirmwareStatus = features => {
|
|
@@ -13999,17 +14038,31 @@ DataManager.getBLEFirmwareStatus = features => {
|
|
|
13999
14038
|
}
|
|
14000
14039
|
|
|
14001
14040
|
const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.ble) !== null && _c !== void 0 ? _c : [];
|
|
14002
|
-
const latestBLEFirmware = targetDeviceConfigList[targetDeviceConfigList.length - 1];
|
|
14003
|
-
if (!latestBLEFirmware) return 'valid';
|
|
14004
|
-
const latestVersion = latestBLEFirmware.version.join('.');
|
|
14005
14041
|
const currentVersion = deviceBLEFirmwareVersion.join('.');
|
|
14042
|
+
return getReleaseStatus(targetDeviceConfigList, currentVersion);
|
|
14043
|
+
};
|
|
14044
|
+
|
|
14045
|
+
DataManager.getBleFirmwareChangelog = features => {
|
|
14046
|
+
var _b, _c;
|
|
14006
14047
|
|
|
14007
|
-
|
|
14008
|
-
|
|
14009
|
-
|
|
14048
|
+
const deviceType = getDeviceType(features);
|
|
14049
|
+
const deviceBLEFirmwareVersion = getDeviceBLEFirmwareVersion(features);
|
|
14050
|
+
|
|
14051
|
+
if (!deviceBLEFirmwareVersion) {
|
|
14052
|
+
return [];
|
|
14010
14053
|
}
|
|
14011
14054
|
|
|
14012
|
-
|
|
14055
|
+
const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.ble) !== null && _c !== void 0 ? _c : [];
|
|
14056
|
+
const currentVersion = deviceBLEFirmwareVersion.join('.');
|
|
14057
|
+
return getReleaseChangelog(targetDeviceConfigList, currentVersion);
|
|
14058
|
+
};
|
|
14059
|
+
|
|
14060
|
+
DataManager.getBleFirmwareLeatestRelease = features => {
|
|
14061
|
+
var _b, _c;
|
|
14062
|
+
|
|
14063
|
+
const deviceType = getDeviceType(features);
|
|
14064
|
+
const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.ble) !== null && _c !== void 0 ? _c : [];
|
|
14065
|
+
return targetDeviceConfigList[targetDeviceConfigList.length - 1];
|
|
14013
14066
|
};
|
|
14014
14067
|
|
|
14015
14068
|
DataManager.getTransportStatus = localVersion => {
|
|
@@ -14142,7 +14195,8 @@ const UI_REQUEST$1 = {
|
|
|
14142
14195
|
REQUEST_BUTTON: 'ui-button',
|
|
14143
14196
|
CLOSE_UI_WINDOW: 'ui-close_window',
|
|
14144
14197
|
BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
|
|
14145
|
-
LOCATION_PERMISSION: 'ui-location_permission'
|
|
14198
|
+
LOCATION_PERMISSION: 'ui-location_permission',
|
|
14199
|
+
FIRMWARE_PROGRESS: 'ui-firmware-progress'
|
|
14146
14200
|
};
|
|
14147
14201
|
|
|
14148
14202
|
const createUiMessage = (type, payload) => ({
|
|
@@ -14614,6 +14668,10 @@ class Device extends events.exports {
|
|
|
14614
14668
|
});
|
|
14615
14669
|
}
|
|
14616
14670
|
|
|
14671
|
+
getCommands() {
|
|
14672
|
+
return this.commands;
|
|
14673
|
+
}
|
|
14674
|
+
|
|
14617
14675
|
getInternalState() {
|
|
14618
14676
|
return this.internalState[this.instance];
|
|
14619
14677
|
}
|
|
@@ -16221,7 +16279,13 @@ class CheckFirmwareRelease extends BaseMethod {
|
|
|
16221
16279
|
run() {
|
|
16222
16280
|
if (this.device.features) {
|
|
16223
16281
|
const firmwareStatus = DataManager.getFirmwareStatus(this.device.features);
|
|
16224
|
-
|
|
16282
|
+
const changelog = DataManager.getFirmwareChangelog(this.device.features);
|
|
16283
|
+
const release = DataManager.getFirmwareLeatestRelease(this.device.features);
|
|
16284
|
+
return Promise.resolve({
|
|
16285
|
+
status: firmwareStatus,
|
|
16286
|
+
changelog,
|
|
16287
|
+
release
|
|
16288
|
+
});
|
|
16225
16289
|
}
|
|
16226
16290
|
|
|
16227
16291
|
return Promise.resolve(null);
|
|
@@ -16237,7 +16301,13 @@ class CheckBLEFirmwareRelease extends BaseMethod {
|
|
|
16237
16301
|
run() {
|
|
16238
16302
|
if (this.device.features) {
|
|
16239
16303
|
const firmwareStatus = DataManager.getBLEFirmwareStatus(this.device.features);
|
|
16240
|
-
|
|
16304
|
+
const changelog = DataManager.getBleFirmwareChangelog(this.device.features);
|
|
16305
|
+
const release = DataManager.getBleFirmwareLeatestRelease(this.device.features);
|
|
16306
|
+
return Promise.resolve({
|
|
16307
|
+
status: firmwareStatus,
|
|
16308
|
+
changelog,
|
|
16309
|
+
release
|
|
16310
|
+
});
|
|
16241
16311
|
}
|
|
16242
16312
|
|
|
16243
16313
|
return Promise.resolve(null);
|
|
@@ -18022,6 +18092,179 @@ class StellarSignTransaction extends BaseMethod {
|
|
|
18022
18092
|
|
|
18023
18093
|
}
|
|
18024
18094
|
|
|
18095
|
+
const getBinary = ({
|
|
18096
|
+
features,
|
|
18097
|
+
updateType,
|
|
18098
|
+
version
|
|
18099
|
+
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18100
|
+
const releaseInfo = getInfo({
|
|
18101
|
+
features,
|
|
18102
|
+
updateType
|
|
18103
|
+
});
|
|
18104
|
+
|
|
18105
|
+
if (!releaseInfo) {
|
|
18106
|
+
throw TypedError('Runtime', 'no firmware found for this device');
|
|
18107
|
+
}
|
|
18108
|
+
|
|
18109
|
+
if (version && !semver__default["default"].eq(releaseInfo.version, version)) {
|
|
18110
|
+
throw TypedError('Runtime', 'firmware version mismatch');
|
|
18111
|
+
}
|
|
18112
|
+
|
|
18113
|
+
const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
|
|
18114
|
+
const fw = yield httpRequest(url, 'binary');
|
|
18115
|
+
return Object.assign(Object.assign({}, releaseInfo), {
|
|
18116
|
+
binary: fw
|
|
18117
|
+
});
|
|
18118
|
+
});
|
|
18119
|
+
|
|
18120
|
+
const getInfo = ({
|
|
18121
|
+
features,
|
|
18122
|
+
updateType
|
|
18123
|
+
}) => {
|
|
18124
|
+
var _a, _b, _c;
|
|
18125
|
+
|
|
18126
|
+
const deviceType = getDeviceType(features);
|
|
18127
|
+
const {
|
|
18128
|
+
deviceMap
|
|
18129
|
+
} = DataManager;
|
|
18130
|
+
const releaseInfo = (_c = (_b = (_a = deviceMap === null || deviceMap === void 0 ? void 0 : deviceMap[deviceType]) === null || _a === void 0 ? void 0 : _a[updateType]) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : null;
|
|
18131
|
+
return releaseInfo;
|
|
18132
|
+
};
|
|
18133
|
+
|
|
18134
|
+
const postConfirmationMessage = device => {
|
|
18135
|
+
var _a;
|
|
18136
|
+
|
|
18137
|
+
if ((_a = device.features) === null || _a === void 0 ? void 0 : _a.firmware_present) {
|
|
18138
|
+
device.emit(DEVICE.BUTTON, device, {
|
|
18139
|
+
code: 'ButtonRequest_FirmwareUpdate'
|
|
18140
|
+
});
|
|
18141
|
+
}
|
|
18142
|
+
};
|
|
18143
|
+
|
|
18144
|
+
const postProgressMessage = (device, progress, postMessage) => {
|
|
18145
|
+
postMessage(createUiMessage(UI_REQUEST$1.FIRMWARE_PROGRESS, {
|
|
18146
|
+
device: device.toMessageObject(),
|
|
18147
|
+
progress
|
|
18148
|
+
}));
|
|
18149
|
+
};
|
|
18150
|
+
|
|
18151
|
+
const uploadFirmware = (updateType, typedCall, postMessage, device, {
|
|
18152
|
+
payload
|
|
18153
|
+
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18154
|
+
var _a, _b;
|
|
18155
|
+
|
|
18156
|
+
if (((_a = device.features) === null || _a === void 0 ? void 0 : _a.major_version) === 1) {
|
|
18157
|
+
postConfirmationMessage(device);
|
|
18158
|
+
const eraseCommand = updateType === 'firmware' ? 'FirmwareErase' : 'FirmwareErase_ex';
|
|
18159
|
+
yield typedCall(eraseCommand, 'Success', {});
|
|
18160
|
+
postProgressMessage(device, 0, postMessage);
|
|
18161
|
+
const {
|
|
18162
|
+
message
|
|
18163
|
+
} = yield typedCall('FirmwareUpload', 'Success', {
|
|
18164
|
+
payload
|
|
18165
|
+
});
|
|
18166
|
+
return message;
|
|
18167
|
+
}
|
|
18168
|
+
|
|
18169
|
+
if (((_b = device.features) === null || _b === void 0 ? void 0 : _b.major_version) === 2) {
|
|
18170
|
+
postConfirmationMessage(device);
|
|
18171
|
+
const length = payload.byteLength;
|
|
18172
|
+
let response = yield typedCall('FirmwareErase', ['FirmwareRequest', 'Success'], {
|
|
18173
|
+
length
|
|
18174
|
+
});
|
|
18175
|
+
|
|
18176
|
+
while (response.type !== 'Success') {
|
|
18177
|
+
const start = response.message.offset;
|
|
18178
|
+
const end = response.message.offset + response.message.length;
|
|
18179
|
+
const chunk = payload.slice(start, end);
|
|
18180
|
+
|
|
18181
|
+
if (start > 0) {
|
|
18182
|
+
postProgressMessage(device, Math.round(start / length * 100), postMessage);
|
|
18183
|
+
}
|
|
18184
|
+
|
|
18185
|
+
response = yield typedCall('FirmwareUpload', ['FirmwareRequest', 'Success'], {
|
|
18186
|
+
payload: chunk
|
|
18187
|
+
});
|
|
18188
|
+
}
|
|
18189
|
+
|
|
18190
|
+
postProgressMessage(device, 100, postMessage);
|
|
18191
|
+
return response.message;
|
|
18192
|
+
}
|
|
18193
|
+
|
|
18194
|
+
throw TypedError('Runtime', 'uploadFirmware: unknown major_version');
|
|
18195
|
+
});
|
|
18196
|
+
|
|
18197
|
+
class FirmwareUpdate extends BaseMethod {
|
|
18198
|
+
init() {
|
|
18199
|
+
this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
|
|
18200
|
+
this.requireDeviceMode = [UI_REQUEST.BOOTLOADER];
|
|
18201
|
+
const {
|
|
18202
|
+
payload
|
|
18203
|
+
} = this;
|
|
18204
|
+
validateParams(payload, [{
|
|
18205
|
+
name: 'version',
|
|
18206
|
+
type: 'array'
|
|
18207
|
+
}, {
|
|
18208
|
+
name: 'binary',
|
|
18209
|
+
type: 'buffer'
|
|
18210
|
+
}]);
|
|
18211
|
+
|
|
18212
|
+
if (!payload.updateType) {
|
|
18213
|
+
throw TypedError('Method_InvalidParameter', 'updateType is required');
|
|
18214
|
+
}
|
|
18215
|
+
|
|
18216
|
+
this.params = {
|
|
18217
|
+
updateType: payload.updateType
|
|
18218
|
+
};
|
|
18219
|
+
|
|
18220
|
+
if ('version' in payload) {
|
|
18221
|
+
this.params = Object.assign(Object.assign({}, this.params), {
|
|
18222
|
+
version: payload.version
|
|
18223
|
+
});
|
|
18224
|
+
}
|
|
18225
|
+
|
|
18226
|
+
if ('binary' in payload) {
|
|
18227
|
+
this.params = Object.assign(Object.assign({}, this.params), {
|
|
18228
|
+
binary: payload.binary
|
|
18229
|
+
});
|
|
18230
|
+
}
|
|
18231
|
+
}
|
|
18232
|
+
|
|
18233
|
+
run() {
|
|
18234
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18235
|
+
const {
|
|
18236
|
+
device,
|
|
18237
|
+
params
|
|
18238
|
+
} = this;
|
|
18239
|
+
let binary;
|
|
18240
|
+
|
|
18241
|
+
try {
|
|
18242
|
+
if (params.binary) {
|
|
18243
|
+
binary = this.params.binary;
|
|
18244
|
+
} else {
|
|
18245
|
+
if (!device.features) {
|
|
18246
|
+
throw TypedError('Runtime', 'no features found for this device');
|
|
18247
|
+
}
|
|
18248
|
+
|
|
18249
|
+
const firmware = yield getBinary({
|
|
18250
|
+
features: device.features,
|
|
18251
|
+
version: params.version,
|
|
18252
|
+
updateType: params.updateType
|
|
18253
|
+
});
|
|
18254
|
+
binary = firmware.binary;
|
|
18255
|
+
}
|
|
18256
|
+
} catch (err) {
|
|
18257
|
+
throw TypedError('Method_FirmwareUpdate_DownloadFailed', err);
|
|
18258
|
+
}
|
|
18259
|
+
|
|
18260
|
+
return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, {
|
|
18261
|
+
payload: binary
|
|
18262
|
+
});
|
|
18263
|
+
});
|
|
18264
|
+
}
|
|
18265
|
+
|
|
18266
|
+
}
|
|
18267
|
+
|
|
18025
18268
|
var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
18026
18269
|
__proto__: null,
|
|
18027
18270
|
searchDevices: SearchDevices,
|
|
@@ -18061,7 +18304,8 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
18061
18304
|
solGetAddress: SolGetAddress,
|
|
18062
18305
|
solSignTransaction: SolSignTransaction,
|
|
18063
18306
|
stellarGetAddress: StellarGetAddress,
|
|
18064
|
-
stellarSignTransaction: StellarSignTransaction
|
|
18307
|
+
stellarSignTransaction: StellarSignTransaction,
|
|
18308
|
+
firmwareUpdate: FirmwareUpdate
|
|
18065
18309
|
});
|
|
18066
18310
|
|
|
18067
18311
|
function findMethod(message) {
|
|
@@ -18267,6 +18511,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
18267
18511
|
try {
|
|
18268
18512
|
method = findMethod(message);
|
|
18269
18513
|
method.connector = _connector;
|
|
18514
|
+
method.postMessage = postMessage;
|
|
18270
18515
|
method.init();
|
|
18271
18516
|
} catch (error) {
|
|
18272
18517
|
return Promise.reject(error);
|