@onekeyfe/hd-web-sdk 0.0.10 → 0.1.0
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.ea300fd8da90869700fc.js +3 -0
- package/build/js/{iframe.1a13e0dba05bc9240b0d.js.LICENSE.txt → iframe.ea300fd8da90869700fc.js.LICENSE.txt} +0 -0
- package/build/js/iframe.ea300fd8da90869700fc.js.map +1 -0
- package/build/onekey-js-sdk.js +191 -5
- 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
|
|
|
@@ -14142,7 +14148,8 @@ const UI_REQUEST$1 = {
|
|
|
14142
14148
|
REQUEST_BUTTON: 'ui-button',
|
|
14143
14149
|
CLOSE_UI_WINDOW: 'ui-close_window',
|
|
14144
14150
|
BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
|
|
14145
|
-
LOCATION_PERMISSION: 'ui-location_permission'
|
|
14151
|
+
LOCATION_PERMISSION: 'ui-location_permission',
|
|
14152
|
+
FIRMWARE_PROGRESS: 'ui-firmware-progress'
|
|
14146
14153
|
};
|
|
14147
14154
|
|
|
14148
14155
|
const createUiMessage = (type, payload) => ({
|
|
@@ -14614,6 +14621,10 @@ class Device extends events.exports {
|
|
|
14614
14621
|
});
|
|
14615
14622
|
}
|
|
14616
14623
|
|
|
14624
|
+
getCommands() {
|
|
14625
|
+
return this.commands;
|
|
14626
|
+
}
|
|
14627
|
+
|
|
14617
14628
|
getInternalState() {
|
|
14618
14629
|
return this.internalState[this.instance];
|
|
14619
14630
|
}
|
|
@@ -18022,6 +18033,179 @@ class StellarSignTransaction extends BaseMethod {
|
|
|
18022
18033
|
|
|
18023
18034
|
}
|
|
18024
18035
|
|
|
18036
|
+
const getBinary = ({
|
|
18037
|
+
features,
|
|
18038
|
+
updateType,
|
|
18039
|
+
version
|
|
18040
|
+
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18041
|
+
const releaseInfo = getInfo({
|
|
18042
|
+
features,
|
|
18043
|
+
updateType
|
|
18044
|
+
});
|
|
18045
|
+
|
|
18046
|
+
if (!releaseInfo) {
|
|
18047
|
+
throw TypedError('Runtime', 'no firmware found for this device');
|
|
18048
|
+
}
|
|
18049
|
+
|
|
18050
|
+
if (version && !semver__default["default"].eq(releaseInfo.version, version)) {
|
|
18051
|
+
throw TypedError('Runtime', 'firmware version mismatch');
|
|
18052
|
+
}
|
|
18053
|
+
|
|
18054
|
+
const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
|
|
18055
|
+
const fw = yield httpRequest(url, 'binary');
|
|
18056
|
+
return Object.assign(Object.assign({}, releaseInfo), {
|
|
18057
|
+
binary: fw
|
|
18058
|
+
});
|
|
18059
|
+
});
|
|
18060
|
+
|
|
18061
|
+
const getInfo = ({
|
|
18062
|
+
features,
|
|
18063
|
+
updateType
|
|
18064
|
+
}) => {
|
|
18065
|
+
var _a, _b, _c;
|
|
18066
|
+
|
|
18067
|
+
const deviceType = getDeviceType(features);
|
|
18068
|
+
const {
|
|
18069
|
+
deviceMap
|
|
18070
|
+
} = DataManager;
|
|
18071
|
+
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;
|
|
18072
|
+
return releaseInfo;
|
|
18073
|
+
};
|
|
18074
|
+
|
|
18075
|
+
const postConfirmationMessage = device => {
|
|
18076
|
+
var _a;
|
|
18077
|
+
|
|
18078
|
+
if ((_a = device.features) === null || _a === void 0 ? void 0 : _a.firmware_present) {
|
|
18079
|
+
device.emit(DEVICE.BUTTON, device, {
|
|
18080
|
+
code: 'ButtonRequest_FirmwareUpdate'
|
|
18081
|
+
});
|
|
18082
|
+
}
|
|
18083
|
+
};
|
|
18084
|
+
|
|
18085
|
+
const postProgressMessage = (device, progress, postMessage) => {
|
|
18086
|
+
postMessage(createUiMessage(UI_REQUEST$1.FIRMWARE_PROGRESS, {
|
|
18087
|
+
device: device.toMessageObject(),
|
|
18088
|
+
progress
|
|
18089
|
+
}));
|
|
18090
|
+
};
|
|
18091
|
+
|
|
18092
|
+
const uploadFirmware = (updateType, typedCall, postMessage, device, {
|
|
18093
|
+
payload
|
|
18094
|
+
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18095
|
+
var _a, _b;
|
|
18096
|
+
|
|
18097
|
+
if (((_a = device.features) === null || _a === void 0 ? void 0 : _a.major_version) === 1) {
|
|
18098
|
+
postConfirmationMessage(device);
|
|
18099
|
+
const eraseCommand = updateType === 'firmware' ? 'FirmwareErase' : 'FirmwareErase_ex';
|
|
18100
|
+
yield typedCall(eraseCommand, 'Success', {});
|
|
18101
|
+
postProgressMessage(device, 0, postMessage);
|
|
18102
|
+
const {
|
|
18103
|
+
message
|
|
18104
|
+
} = yield typedCall('FirmwareUpload', 'Success', {
|
|
18105
|
+
payload
|
|
18106
|
+
});
|
|
18107
|
+
return message;
|
|
18108
|
+
}
|
|
18109
|
+
|
|
18110
|
+
if (((_b = device.features) === null || _b === void 0 ? void 0 : _b.major_version) === 2) {
|
|
18111
|
+
postConfirmationMessage(device);
|
|
18112
|
+
const length = payload.byteLength;
|
|
18113
|
+
let response = yield typedCall('FirmwareErase', ['FirmwareRequest', 'Success'], {
|
|
18114
|
+
length
|
|
18115
|
+
});
|
|
18116
|
+
|
|
18117
|
+
while (response.type !== 'Success') {
|
|
18118
|
+
const start = response.message.offset;
|
|
18119
|
+
const end = response.message.offset + response.message.length;
|
|
18120
|
+
const chunk = payload.slice(start, end);
|
|
18121
|
+
|
|
18122
|
+
if (start > 0) {
|
|
18123
|
+
postProgressMessage(device, Math.round(start / length * 100), postMessage);
|
|
18124
|
+
}
|
|
18125
|
+
|
|
18126
|
+
response = yield typedCall('FirmwareUpload', ['FirmwareRequest', 'Success'], {
|
|
18127
|
+
payload: chunk
|
|
18128
|
+
});
|
|
18129
|
+
}
|
|
18130
|
+
|
|
18131
|
+
postProgressMessage(device, 100, postMessage);
|
|
18132
|
+
return response.message;
|
|
18133
|
+
}
|
|
18134
|
+
|
|
18135
|
+
throw TypedError('Runtime', 'uploadFirmware: unknown major_version');
|
|
18136
|
+
});
|
|
18137
|
+
|
|
18138
|
+
class FirmwareUpdate extends BaseMethod {
|
|
18139
|
+
init() {
|
|
18140
|
+
this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
|
|
18141
|
+
this.requireDeviceMode = [UI_REQUEST.BOOTLOADER];
|
|
18142
|
+
const {
|
|
18143
|
+
payload
|
|
18144
|
+
} = this;
|
|
18145
|
+
validateParams(payload, [{
|
|
18146
|
+
name: 'version',
|
|
18147
|
+
type: 'array'
|
|
18148
|
+
}, {
|
|
18149
|
+
name: 'binary',
|
|
18150
|
+
type: 'buffer'
|
|
18151
|
+
}]);
|
|
18152
|
+
|
|
18153
|
+
if (!payload.updateType) {
|
|
18154
|
+
throw TypedError('Method_InvalidParameter', 'updateType is required');
|
|
18155
|
+
}
|
|
18156
|
+
|
|
18157
|
+
this.params = {
|
|
18158
|
+
updateType: payload.updateType
|
|
18159
|
+
};
|
|
18160
|
+
|
|
18161
|
+
if ('version' in payload) {
|
|
18162
|
+
this.params = Object.assign(Object.assign({}, this.params), {
|
|
18163
|
+
version: payload.version
|
|
18164
|
+
});
|
|
18165
|
+
}
|
|
18166
|
+
|
|
18167
|
+
if ('binary' in payload) {
|
|
18168
|
+
this.params = Object.assign(Object.assign({}, this.params), {
|
|
18169
|
+
binary: payload.binary
|
|
18170
|
+
});
|
|
18171
|
+
}
|
|
18172
|
+
}
|
|
18173
|
+
|
|
18174
|
+
run() {
|
|
18175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18176
|
+
const {
|
|
18177
|
+
device,
|
|
18178
|
+
params
|
|
18179
|
+
} = this;
|
|
18180
|
+
let binary;
|
|
18181
|
+
|
|
18182
|
+
try {
|
|
18183
|
+
if (params.binary) {
|
|
18184
|
+
binary = this.params.binary;
|
|
18185
|
+
} else {
|
|
18186
|
+
if (!device.features) {
|
|
18187
|
+
throw TypedError('Runtime', 'no features found for this device');
|
|
18188
|
+
}
|
|
18189
|
+
|
|
18190
|
+
const firmware = yield getBinary({
|
|
18191
|
+
features: device.features,
|
|
18192
|
+
version: params.version,
|
|
18193
|
+
updateType: params.updateType
|
|
18194
|
+
});
|
|
18195
|
+
binary = firmware.binary;
|
|
18196
|
+
}
|
|
18197
|
+
} catch (err) {
|
|
18198
|
+
throw TypedError('Method_FirmwareUpdate_DownloadFailed', err);
|
|
18199
|
+
}
|
|
18200
|
+
|
|
18201
|
+
return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, {
|
|
18202
|
+
payload: binary
|
|
18203
|
+
});
|
|
18204
|
+
});
|
|
18205
|
+
}
|
|
18206
|
+
|
|
18207
|
+
}
|
|
18208
|
+
|
|
18025
18209
|
var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
18026
18210
|
__proto__: null,
|
|
18027
18211
|
searchDevices: SearchDevices,
|
|
@@ -18061,7 +18245,8 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
18061
18245
|
solGetAddress: SolGetAddress,
|
|
18062
18246
|
solSignTransaction: SolSignTransaction,
|
|
18063
18247
|
stellarGetAddress: StellarGetAddress,
|
|
18064
|
-
stellarSignTransaction: StellarSignTransaction
|
|
18248
|
+
stellarSignTransaction: StellarSignTransaction,
|
|
18249
|
+
firmwareUpdate: FirmwareUpdate
|
|
18065
18250
|
});
|
|
18066
18251
|
|
|
18067
18252
|
function findMethod(message) {
|
|
@@ -18267,6 +18452,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
18267
18452
|
try {
|
|
18268
18453
|
method = findMethod(message);
|
|
18269
18454
|
method.connector = _connector;
|
|
18455
|
+
method.postMessage = postMessage;
|
|
18270
18456
|
method.init();
|
|
18271
18457
|
} catch (error) {
|
|
18272
18458
|
return Promise.reject(error);
|