@onekeyfe/hd-core 1.2.8-alpha.111 → 1.2.8-alpha.113
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/__tests__/logBlockEvent.test.ts +0 -43
- package/__tests__/protocol-v2.test.ts +239 -0
- package/dist/api/FirmwareUpdateV4.d.ts +3 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/index.d.ts +3 -36
- package/dist/index.js +156 -365
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +0 -2
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +0 -4
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +216 -51
- package/src/api/index.ts +0 -2
- package/src/data/messages/messages-protocol-v2.json +1 -138
- package/src/events/logBlockEvent.ts +2 -4
- package/src/inject.ts +0 -4
- package/src/types/api/export.ts +0 -2
- package/src/types/api/index.ts +0 -8
- package/__tests__/zcash-protobuf.test.ts +0 -141
- package/__tests__/zcash-sign-pczt.test.ts +0 -387
- package/dist/api/zcash/ZcashGetAddress.d.ts +0 -12
- package/dist/api/zcash/ZcashGetAddress.d.ts.map +0 -1
- package/dist/api/zcash/ZcashSignPczt.d.ts +0 -16
- package/dist/api/zcash/ZcashSignPczt.d.ts.map +0 -1
- package/dist/types/api/zcashGetAddress.d.ts +0 -22
- package/dist/types/api/zcashGetAddress.d.ts.map +0 -1
- package/dist/types/api/zcashSignPczt.d.ts +0 -9
- package/dist/types/api/zcashSignPczt.d.ts.map +0 -1
- package/src/api/zcash/ZcashGetAddress.ts +0 -121
- package/src/api/zcash/ZcashSignPczt.ts +0 -155
- package/src/types/api/zcashGetAddress.ts +0 -36
- package/src/types/api/zcashSignPczt.ts +0 -18
package/dist/index.js
CHANGED
|
@@ -1721,8 +1721,6 @@ const createCoreApi = (call) => ({
|
|
|
1721
1721
|
benfenSignMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'benfenSignMessage' })),
|
|
1722
1722
|
neoGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'neoGetAddress' })),
|
|
1723
1723
|
neoSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'neoSignTransaction' })),
|
|
1724
|
-
zcashGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'zcashGetAddress' })),
|
|
1725
|
-
zcashSignPczt: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'zcashSignPczt' })),
|
|
1726
1724
|
});
|
|
1727
1725
|
|
|
1728
1726
|
const lowLevelInject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, updateSettings, switchTransport, addHardwareGlobalEventListener, }) => {
|
|
@@ -2441,8 +2439,6 @@ const LogPayloadBlockMethod = new Set([
|
|
|
2441
2439
|
'uploadPortfolio',
|
|
2442
2440
|
'fileWrite',
|
|
2443
2441
|
'fileRead',
|
|
2444
|
-
'zcashGetAddress',
|
|
2445
|
-
'zcashSignPczt',
|
|
2446
2442
|
]);
|
|
2447
2443
|
function getLogBlockLabel(message) {
|
|
2448
2444
|
if (!message || typeof message !== 'object')
|
|
@@ -37946,61 +37942,6 @@ var nested = {
|
|
|
37946
37942
|
}
|
|
37947
37943
|
}
|
|
37948
37944
|
},
|
|
37949
|
-
ZcashSignPczt: {
|
|
37950
|
-
fields: {
|
|
37951
|
-
pczt_length: {
|
|
37952
|
-
rule: "required",
|
|
37953
|
-
type: "uint32",
|
|
37954
|
-
id: 1
|
|
37955
|
-
},
|
|
37956
|
-
pczt_initial_chunk: {
|
|
37957
|
-
rule: "required",
|
|
37958
|
-
type: "bytes",
|
|
37959
|
-
id: 2
|
|
37960
|
-
}
|
|
37961
|
-
}
|
|
37962
|
-
},
|
|
37963
|
-
ZcashPcztChunkRequest: {
|
|
37964
|
-
fields: {
|
|
37965
|
-
chunk_length: {
|
|
37966
|
-
rule: "required",
|
|
37967
|
-
type: "uint32",
|
|
37968
|
-
id: 1
|
|
37969
|
-
}
|
|
37970
|
-
}
|
|
37971
|
-
},
|
|
37972
|
-
ZcashPcztChunkAck: {
|
|
37973
|
-
fields: {
|
|
37974
|
-
data_chunk: {
|
|
37975
|
-
rule: "required",
|
|
37976
|
-
type: "bytes",
|
|
37977
|
-
id: 1
|
|
37978
|
-
}
|
|
37979
|
-
}
|
|
37980
|
-
},
|
|
37981
|
-
ZcashSignedPczt: {
|
|
37982
|
-
fields: {
|
|
37983
|
-
pczt_length: {
|
|
37984
|
-
rule: "required",
|
|
37985
|
-
type: "uint32",
|
|
37986
|
-
id: 1
|
|
37987
|
-
},
|
|
37988
|
-
pczt_initial_chunk: {
|
|
37989
|
-
rule: "required",
|
|
37990
|
-
type: "bytes",
|
|
37991
|
-
id: 2
|
|
37992
|
-
}
|
|
37993
|
-
}
|
|
37994
|
-
},
|
|
37995
|
-
ZcashSignedPcztChunkRequest: {
|
|
37996
|
-
fields: {
|
|
37997
|
-
chunk_length: {
|
|
37998
|
-
rule: "required",
|
|
37999
|
-
type: "uint32",
|
|
38000
|
-
id: 1
|
|
38001
|
-
}
|
|
38002
|
-
}
|
|
38003
|
-
},
|
|
38004
37945
|
wire_in: {
|
|
38005
37946
|
type: "bool",
|
|
38006
37947
|
id: 50002,
|
|
@@ -38426,11 +38367,6 @@ var nested = {
|
|
|
38426
38367
|
MessageType_NeoAddress: 12302,
|
|
38427
38368
|
MessageType_NeoSignTx: 12303,
|
|
38428
38369
|
MessageType_NeoSignedTx: 12304,
|
|
38429
|
-
MessageType_ZcashSignPczt: 12402,
|
|
38430
|
-
MessageType_ZcashSignedPczt: 12403,
|
|
38431
|
-
MessageType_ZcashPcztChunkRequest: 12404,
|
|
38432
|
-
MessageType_ZcashPcztChunkAck: 12405,
|
|
38433
|
-
MessageType_ZcashSignedPcztChunkRequest: 12406,
|
|
38434
38370
|
MessageType_DeviceFactoryInfoSet: 60000,
|
|
38435
38371
|
MessageType_DeviceFactoryInfoGet: 60001,
|
|
38436
38372
|
MessageType_DeviceFactoryInfo: 60002,
|
|
@@ -38483,9 +38419,7 @@ var nested = {
|
|
|
38483
38419
|
MessageType_PortfolioUpdate: 61400,
|
|
38484
38420
|
MessageType_NftUpdate: 61500,
|
|
38485
38421
|
MessageType_OnboardingStatusGet: 61600,
|
|
38486
|
-
MessageType_OnboardingStatus: 61601
|
|
38487
|
-
MessageType_ZcashGetAddress: 12400,
|
|
38488
|
-
MessageType_ZcashAddress: 12401
|
|
38422
|
+
MessageType_OnboardingStatus: 61601
|
|
38489
38423
|
},
|
|
38490
38424
|
reserved: [
|
|
38491
38425
|
[
|
|
@@ -40790,81 +40724,6 @@ var nested = {
|
|
|
40790
40724
|
}
|
|
40791
40725
|
}
|
|
40792
40726
|
}
|
|
40793
|
-
},
|
|
40794
|
-
ZcashAddressType: {
|
|
40795
|
-
values: {
|
|
40796
|
-
UNIFIED_ORCHARD_P2PKH: 0,
|
|
40797
|
-
TRANSPARENT_P2PKH: 1,
|
|
40798
|
-
UNIFIED_ORCHARD: 2
|
|
40799
|
-
}
|
|
40800
|
-
},
|
|
40801
|
-
ZcashAddressScope: {
|
|
40802
|
-
values: {
|
|
40803
|
-
EXTERNAL: 0,
|
|
40804
|
-
INTERNAL: 1
|
|
40805
|
-
}
|
|
40806
|
-
},
|
|
40807
|
-
ZcashGetAddress: {
|
|
40808
|
-
fields: {
|
|
40809
|
-
address_n: {
|
|
40810
|
-
rule: "repeated",
|
|
40811
|
-
type: "uint32",
|
|
40812
|
-
id: 1,
|
|
40813
|
-
options: {
|
|
40814
|
-
packed: false
|
|
40815
|
-
}
|
|
40816
|
-
},
|
|
40817
|
-
show_display: {
|
|
40818
|
-
type: "bool",
|
|
40819
|
-
id: 2
|
|
40820
|
-
},
|
|
40821
|
-
include_seed_fingerprint: {
|
|
40822
|
-
type: "bool",
|
|
40823
|
-
id: 3
|
|
40824
|
-
},
|
|
40825
|
-
include_ufvk: {
|
|
40826
|
-
type: "bool",
|
|
40827
|
-
id: 4
|
|
40828
|
-
},
|
|
40829
|
-
diversifier_index: {
|
|
40830
|
-
type: "uint32",
|
|
40831
|
-
id: 5,
|
|
40832
|
-
options: {
|
|
40833
|
-
"default": 0
|
|
40834
|
-
}
|
|
40835
|
-
},
|
|
40836
|
-
address_type: {
|
|
40837
|
-
type: "ZcashAddressType",
|
|
40838
|
-
id: 6,
|
|
40839
|
-
options: {
|
|
40840
|
-
"default": "UNIFIED_ORCHARD_P2PKH"
|
|
40841
|
-
}
|
|
40842
|
-
},
|
|
40843
|
-
scope: {
|
|
40844
|
-
type: "ZcashAddressScope",
|
|
40845
|
-
id: 7,
|
|
40846
|
-
options: {
|
|
40847
|
-
"default": "EXTERNAL"
|
|
40848
|
-
}
|
|
40849
|
-
}
|
|
40850
|
-
}
|
|
40851
|
-
},
|
|
40852
|
-
ZcashAddress: {
|
|
40853
|
-
fields: {
|
|
40854
|
-
address: {
|
|
40855
|
-
rule: "required",
|
|
40856
|
-
type: "string",
|
|
40857
|
-
id: 1
|
|
40858
|
-
},
|
|
40859
|
-
ufvk: {
|
|
40860
|
-
type: "string",
|
|
40861
|
-
id: 2
|
|
40862
|
-
},
|
|
40863
|
-
seed_fingerprint: {
|
|
40864
|
-
type: "bytes",
|
|
40865
|
-
id: 3
|
|
40866
|
-
}
|
|
40867
|
-
}
|
|
40868
40727
|
}
|
|
40869
40728
|
};
|
|
40870
40729
|
var MessagesProtocolV2JSON = {
|
|
@@ -52772,6 +52631,7 @@ const PROTOCOL_V2_CONNECT_POLL_INTERVAL = 500;
|
|
|
52772
52631
|
const PROTOCOL_V2_CONNECT_SINGLE_TIMEOUT = 75 * 1000;
|
|
52773
52632
|
const PROTOCOL_V2_DEVICE_INFO_READY_TIMEOUT = 30 * 1000;
|
|
52774
52633
|
const PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT = 3;
|
|
52634
|
+
const PROTOCOL_V2_BLE_FILE_WRITE_WINDOW_MIN_BOOTLOADER_VERSION = '1.0.2';
|
|
52775
52635
|
const PROTOCOL_V2_TRANSFER_PROGRESS_HEARTBEAT_MS = 1000;
|
|
52776
52636
|
const PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE = 'FirmwareInstallStatusConflict';
|
|
52777
52637
|
const PROTOCOL_V2_INSTALL_FAILED_CODE = 'FirmwareInstallFailed';
|
|
@@ -52819,6 +52679,11 @@ function assertProtocolV2FirmwareTargetsSupported(deviceType, params, hasExplici
|
|
|
52819
52679
|
: `Cannot safely update ${targetList} without a confirmed Pro2 device type`;
|
|
52820
52680
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportMethod, message);
|
|
52821
52681
|
}
|
|
52682
|
+
function supportsProtocolV2BleFileWriteWindow(bootloaderVersion, minBootloaderVersion = PROTOCOL_V2_BLE_FILE_WRITE_WINDOW_MIN_BOOTLOADER_VERSION) {
|
|
52683
|
+
return (!!minBootloaderVersion &&
|
|
52684
|
+
!!semver__default["default"].valid(bootloaderVersion) &&
|
|
52685
|
+
semver__default["default"].gte(bootloaderVersion, minBootloaderVersion));
|
|
52686
|
+
}
|
|
52822
52687
|
const getProtocolV2DeviceTransferProgress = (bytesBeforeChunk, bytesAfterChunk, totalBytes) => {
|
|
52823
52688
|
if (!Number.isFinite(totalBytes) || totalBytes <= 0) {
|
|
52824
52689
|
return 0;
|
|
@@ -54258,11 +54123,18 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54258
54123
|
}
|
|
54259
54124
|
if (totalSize > 0) {
|
|
54260
54125
|
const elapsedMs = Math.max(Date.now() - transferStartedAt, 0);
|
|
54126
|
+
const rateBytesPerSecond = elapsedMs > 0 ? Math.round((totalSize / elapsedMs) * 1000) : undefined;
|
|
54261
54127
|
this.postProgressMessage(100, 'transferData', {
|
|
54262
54128
|
transferredBytes: totalSize,
|
|
54263
54129
|
totalBytes: totalSize,
|
|
54264
|
-
rateBytesPerSecond
|
|
54130
|
+
rateBytesPerSecond,
|
|
54131
|
+
elapsedMs,
|
|
54132
|
+
});
|
|
54133
|
+
Log$6.debug('[FirmwareUpdateV4] Protocol V2 transfer completed', {
|
|
54134
|
+
files: resourcesToSync.length + installSources.length,
|
|
54135
|
+
totalBytes: totalSize,
|
|
54265
54136
|
elapsedMs,
|
|
54137
|
+
rateBytesPerSecond,
|
|
54266
54138
|
});
|
|
54267
54139
|
}
|
|
54268
54140
|
if (stagedInstallTargets.length === 0) {
|
|
@@ -54273,10 +54145,15 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54273
54145
|
target_id: item.targetId,
|
|
54274
54146
|
path: item.path,
|
|
54275
54147
|
}));
|
|
54148
|
+
const installStartedAt = Date.now();
|
|
54276
54149
|
try {
|
|
54277
54150
|
yield this.protocolV2StartFirmwareUpdate({ targets });
|
|
54278
54151
|
yield hdShared.wait(PROTOCOL_V2_INSTALL_STATUS_INITIAL_DELAY);
|
|
54279
54152
|
yield this.waitForProtocolV2FirmwareUpdateComplete(targets, true);
|
|
54153
|
+
Log$6.debug('[FirmwareUpdateV4] Protocol V2 install completed', {
|
|
54154
|
+
targets: targets.length,
|
|
54155
|
+
elapsedMs: Math.max(Date.now() - installStartedAt, 0),
|
|
54156
|
+
});
|
|
54280
54157
|
}
|
|
54281
54158
|
finally {
|
|
54282
54159
|
(_a = this.device) === null || _a === void 0 ? void 0 : _a.clearCancelableAction();
|
|
@@ -54285,51 +54162,81 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54285
54162
|
}
|
|
54286
54163
|
protocolV2SourceUpdateProcess({ source, filePath, processedSize, totalSize, transferStartedAt = Date.now(), }) {
|
|
54287
54164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54165
|
+
const reportConfirmedChunk = (chunkEnd) => {
|
|
54166
|
+
const transferredBytes = processedSize + chunkEnd;
|
|
54167
|
+
const now = Date.now();
|
|
54168
|
+
const elapsedMs = Math.max(now - transferStartedAt, 0);
|
|
54169
|
+
const progress = Math.min(Math.ceil((transferredBytes / totalSize) * 100), 99);
|
|
54170
|
+
const shouldPostProgress = transferredBytes >= this.protocolV2LastTransferredBytes &&
|
|
54171
|
+
(progress !== this.protocolV2LastTransferProgress ||
|
|
54172
|
+
now - this.protocolV2LastTransferProgressAt >=
|
|
54173
|
+
PROTOCOL_V2_TRANSFER_PROGRESS_HEARTBEAT_MS ||
|
|
54174
|
+
chunkEnd === source.size);
|
|
54175
|
+
if (shouldPostProgress) {
|
|
54176
|
+
this.protocolV2LastTransferProgress = progress;
|
|
54177
|
+
this.protocolV2LastTransferProgressAt = now;
|
|
54178
|
+
this.protocolV2LastTransferredBytes = transferredBytes;
|
|
54179
|
+
this.postProgressMessage(progress, 'transferData', {
|
|
54180
|
+
transferredBytes,
|
|
54181
|
+
totalBytes: totalSize,
|
|
54182
|
+
rateBytesPerSecond: elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
|
|
54183
|
+
elapsedMs,
|
|
54184
|
+
});
|
|
54185
|
+
}
|
|
54186
|
+
};
|
|
54288
54187
|
let lastError;
|
|
54289
54188
|
for (let attempt = 1; attempt <= PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT; attempt += 1) {
|
|
54290
54189
|
this.throwIfAborted();
|
|
54190
|
+
const attemptStartedAt = Date.now();
|
|
54291
54191
|
try {
|
|
54292
|
-
|
|
54293
|
-
|
|
54294
|
-
|
|
54295
|
-
|
|
54296
|
-
|
|
54297
|
-
|
|
54298
|
-
|
|
54299
|
-
|
|
54300
|
-
|
|
54301
|
-
|
|
54302
|
-
|
|
54303
|
-
|
|
54304
|
-
|
|
54305
|
-
|
|
54306
|
-
|
|
54307
|
-
|
|
54308
|
-
|
|
54309
|
-
|
|
54310
|
-
|
|
54311
|
-
|
|
54312
|
-
|
|
54313
|
-
|
|
54314
|
-
|
|
54315
|
-
|
|
54316
|
-
|
|
54317
|
-
|
|
54318
|
-
|
|
54319
|
-
|
|
54320
|
-
|
|
54321
|
-
|
|
54322
|
-
|
|
54323
|
-
|
|
54324
|
-
|
|
54325
|
-
|
|
54326
|
-
|
|
54192
|
+
const chunkSize = this.getProtocolV2FirmwareChunkSize('write', filePath);
|
|
54193
|
+
const windowed = this.shouldUseProtocolV2BleFileWriteWindow();
|
|
54194
|
+
if (windowed) {
|
|
54195
|
+
yield this.writeProtocolV2SourceWindowed({
|
|
54196
|
+
source,
|
|
54197
|
+
filePath,
|
|
54198
|
+
chunkSize,
|
|
54199
|
+
processedSize,
|
|
54200
|
+
totalSize,
|
|
54201
|
+
onChunkConfirmed: reportConfirmedChunk,
|
|
54202
|
+
});
|
|
54203
|
+
}
|
|
54204
|
+
else {
|
|
54205
|
+
yield writeFirmwareByteSource({
|
|
54206
|
+
source,
|
|
54207
|
+
chunkSize,
|
|
54208
|
+
write: ({ data, sourceOffset, length, first }) => __awaiter(this, void 0, void 0, function* () {
|
|
54209
|
+
this.throwIfAborted();
|
|
54210
|
+
const chunkEnd = sourceOffset + length;
|
|
54211
|
+
const deviceProgress = getProtocolV2DeviceTransferProgress(processedSize + sourceOffset, processedSize + chunkEnd, totalSize);
|
|
54212
|
+
const response = yield this.fileWriteChunk(filePath, source.size, sourceOffset, data, first, deviceProgress);
|
|
54213
|
+
const rawProcessedByte = response.message.processed_byte;
|
|
54214
|
+
const nextOffset = rawProcessedByte === undefined ? chunkEnd : Number(rawProcessedByte);
|
|
54215
|
+
if (!Number.isFinite(nextOffset) || nextOffset !== chunkEnd) {
|
|
54216
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.EmmcFileWriteFirmwareError, `invalid processed_byte ${rawProcessedByte} for offset ${sourceOffset}`);
|
|
54217
|
+
}
|
|
54218
|
+
reportConfirmedChunk(chunkEnd);
|
|
54219
|
+
return length;
|
|
54220
|
+
}),
|
|
54221
|
+
});
|
|
54222
|
+
}
|
|
54223
|
+
Log$6.debug('[FirmwareUpdateV4] Protocol V2 file transferred', {
|
|
54224
|
+
path: filePath,
|
|
54225
|
+
bytes: source.size,
|
|
54226
|
+
elapsedMs: Math.max(Date.now() - attemptStartedAt, 0),
|
|
54227
|
+
attempt,
|
|
54228
|
+
fileWriteWindow: windowed ? hdTransport.PROTOCOL_V2_FILE_WRITE_PIPELINE_WINDOW : 1,
|
|
54327
54229
|
});
|
|
54328
54230
|
return processedSize + source.size;
|
|
54329
54231
|
}
|
|
54330
54232
|
catch (error) {
|
|
54331
54233
|
this.throwIfAborted();
|
|
54332
54234
|
lastError = error;
|
|
54235
|
+
Log$6.debug('[FirmwareUpdateV4] Protocol V2 file transfer attempt failed', {
|
|
54236
|
+
path: filePath,
|
|
54237
|
+
attempt,
|
|
54238
|
+
error: getProtocolV2UnknownErrorText(error),
|
|
54239
|
+
});
|
|
54333
54240
|
if (attempt < PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT) {
|
|
54334
54241
|
yield this.recoverProtocolV2FileTransfer();
|
|
54335
54242
|
this.throwIfAborted();
|
|
@@ -55012,6 +54919,76 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
55012
54919
|
return writeRes;
|
|
55013
54920
|
});
|
|
55014
54921
|
}
|
|
54922
|
+
shouldUseProtocolV2BleFileWriteWindow(minBootloaderVersion = PROTOCOL_V2_BLE_FILE_WRITE_WINDOW_MIN_BOOTLOADER_VERSION) {
|
|
54923
|
+
var _a, _b;
|
|
54924
|
+
const env = DataManager.getSettings('env');
|
|
54925
|
+
if ((env !== 'react-native' && env !== 'desktop-web-ble') ||
|
|
54926
|
+
!this.isProtocolV2BootloaderMode()) {
|
|
54927
|
+
return false;
|
|
54928
|
+
}
|
|
54929
|
+
const bootloaderVersion = getDeviceBootloaderVersion(this.device.features).join('.');
|
|
54930
|
+
const enabled = supportsProtocolV2BleFileWriteWindow(bootloaderVersion, minBootloaderVersion);
|
|
54931
|
+
Log$6.debug('[FirmwareUpdateV4] BLE FileWrite window', {
|
|
54932
|
+
enabled,
|
|
54933
|
+
bootloaderVersion,
|
|
54934
|
+
bootloaderBuildId: (_b = (_a = this.device.features) === null || _a === void 0 ? void 0 : _a.verify) === null || _b === void 0 ? void 0 : _b.bootloaderBuildId,
|
|
54935
|
+
});
|
|
54936
|
+
return enabled;
|
|
54937
|
+
}
|
|
54938
|
+
writeProtocolV2SourceWindowed({ source, filePath, chunkSize, processedSize, totalSize, onChunkConfirmed, }) {
|
|
54939
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54940
|
+
let sendOffset = 0;
|
|
54941
|
+
let sourceError;
|
|
54942
|
+
const readRequest = () => __awaiter(this, void 0, void 0, function* () {
|
|
54943
|
+
const offset = sendOffset;
|
|
54944
|
+
const length = Math.min(chunkSize, source.size - offset);
|
|
54945
|
+
const data = yield source.readAt(offset, length);
|
|
54946
|
+
sendOffset += length;
|
|
54947
|
+
return {
|
|
54948
|
+
file: { path: filePath, offset, total_size: source.size, data },
|
|
54949
|
+
overwrite: offset === 0,
|
|
54950
|
+
append: false,
|
|
54951
|
+
ui_percentage: getProtocolV2DeviceTransferProgress(processedSize + offset, processedSize + sendOffset, totalSize),
|
|
54952
|
+
};
|
|
54953
|
+
});
|
|
54954
|
+
const nextRequest = () => __awaiter(this, void 0, void 0, function* () {
|
|
54955
|
+
var _a;
|
|
54956
|
+
if (((_a = this.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) || sendOffset >= source.size)
|
|
54957
|
+
return undefined;
|
|
54958
|
+
try {
|
|
54959
|
+
return yield readRequest();
|
|
54960
|
+
}
|
|
54961
|
+
catch (error) {
|
|
54962
|
+
sourceError = error;
|
|
54963
|
+
return undefined;
|
|
54964
|
+
}
|
|
54965
|
+
});
|
|
54966
|
+
this.throwIfAborted();
|
|
54967
|
+
if (source.size === 0)
|
|
54968
|
+
return;
|
|
54969
|
+
const firstRequest = yield readRequest();
|
|
54970
|
+
const env = DataManager.getSettings('env');
|
|
54971
|
+
const response = yield this.device
|
|
54972
|
+
.getCommands()
|
|
54973
|
+
.typedCall('FilesystemFileWrite', 'FilesystemFile', firstRequest, {
|
|
54974
|
+
timeoutMs: env === 'react-native' ? PROTOCOL_V2_FILE_WRITE_RESPONSE_TIMEOUT : undefined,
|
|
54975
|
+
writeWithResponse: false,
|
|
54976
|
+
fileWritePipeline: {
|
|
54977
|
+
next: nextRequest,
|
|
54978
|
+
onResponse: confirmed => {
|
|
54979
|
+
onChunkConfirmed(Number(confirmed.message.processed_byte));
|
|
54980
|
+
},
|
|
54981
|
+
},
|
|
54982
|
+
});
|
|
54983
|
+
this.throwIfAborted();
|
|
54984
|
+
if (sourceError)
|
|
54985
|
+
throw sourceError;
|
|
54986
|
+
const rawProcessedByte = response.message.processed_byte;
|
|
54987
|
+
if (Number(rawProcessedByte) !== source.size) {
|
|
54988
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.EmmcFileWriteFirmwareError, `invalid processed_byte ${rawProcessedByte} for file size ${source.size}`);
|
|
54989
|
+
}
|
|
54990
|
+
});
|
|
54991
|
+
}
|
|
55015
54992
|
recoverProtocolV2FileTransfer() {
|
|
55016
54993
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55017
54994
|
const env = DataManager.getSettings('env');
|
|
@@ -65830,190 +65807,6 @@ class NeoSignTransaction extends BaseMethod {
|
|
|
65830
65807
|
}
|
|
65831
65808
|
}
|
|
65832
65809
|
|
|
65833
|
-
class ZcashGetAddress extends BaseMethod {
|
|
65834
|
-
constructor() {
|
|
65835
|
-
super(...arguments);
|
|
65836
|
-
this.hasBundle = false;
|
|
65837
|
-
}
|
|
65838
|
-
getSupportedProtocols() {
|
|
65839
|
-
return ['V2'];
|
|
65840
|
-
}
|
|
65841
|
-
init() {
|
|
65842
|
-
var _a;
|
|
65843
|
-
this.checkDeviceId = true;
|
|
65844
|
-
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
65845
|
-
this.strictCheckDeviceSupport = true;
|
|
65846
|
-
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
65847
|
-
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
65848
|
-
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
65849
|
-
this.params = [];
|
|
65850
|
-
payload.bundle.forEach((batch) => {
|
|
65851
|
-
var _a, _b, _c, _d, _e, _f;
|
|
65852
|
-
const addressN = validatePath(batch.path, 3);
|
|
65853
|
-
if (addressN.length !== 3 ||
|
|
65854
|
-
addressN[0] !== toHardened(32) ||
|
|
65855
|
-
addressN[1] !== toHardened(133) ||
|
|
65856
|
-
addressN[2] < toHardened(0) ||
|
|
65857
|
-
addressN[2] > 0xffffffff) {
|
|
65858
|
-
throw invalidParameter("Zcash requires a ZIP-32 account path m/32'/133'/account'");
|
|
65859
|
-
}
|
|
65860
|
-
const addressType = (_a = batch.addressType) !== null && _a !== void 0 ? _a : hdTransport.ZcashAddressType.UNIFIED_ORCHARD_P2PKH;
|
|
65861
|
-
const scope = (_b = batch.scope) !== null && _b !== void 0 ? _b : hdTransport.ZcashAddressScope.EXTERNAL;
|
|
65862
|
-
const diversifierIndex = (_c = batch.diversifierIndex) !== null && _c !== void 0 ? _c : 0;
|
|
65863
|
-
if (![
|
|
65864
|
-
hdTransport.ZcashAddressType.UNIFIED_ORCHARD_P2PKH,
|
|
65865
|
-
hdTransport.ZcashAddressType.TRANSPARENT_P2PKH,
|
|
65866
|
-
hdTransport.ZcashAddressType.UNIFIED_ORCHARD,
|
|
65867
|
-
].includes(addressType) ||
|
|
65868
|
-
![hdTransport.ZcashAddressScope.EXTERNAL, hdTransport.ZcashAddressScope.INTERNAL].includes(scope)) {
|
|
65869
|
-
throw invalidParameter('Invalid Zcash address type or scope');
|
|
65870
|
-
}
|
|
65871
|
-
const maxIndex = addressType === hdTransport.ZcashAddressType.UNIFIED_ORCHARD ? 0xffffffff : 0x7fffffff;
|
|
65872
|
-
if (!Number.isSafeInteger(diversifierIndex) ||
|
|
65873
|
-
diversifierIndex < 0 ||
|
|
65874
|
-
diversifierIndex > maxIndex) {
|
|
65875
|
-
throw invalidParameter('Invalid Zcash diversifier index');
|
|
65876
|
-
}
|
|
65877
|
-
validateParams(batch, [
|
|
65878
|
-
{ name: 'path', required: true },
|
|
65879
|
-
{ name: 'showOnOneKey', type: 'boolean' },
|
|
65880
|
-
{ name: 'includeUfvk', type: 'boolean' },
|
|
65881
|
-
{ name: 'includeSeedFingerprint', type: 'boolean' },
|
|
65882
|
-
]);
|
|
65883
|
-
this.params.push({
|
|
65884
|
-
address_n: addressN,
|
|
65885
|
-
address_type: addressType,
|
|
65886
|
-
scope,
|
|
65887
|
-
diversifier_index: diversifierIndex,
|
|
65888
|
-
show_display: (_d = batch.showOnOneKey) !== null && _d !== void 0 ? _d : true,
|
|
65889
|
-
include_ufvk: (_e = batch.includeUfvk) !== null && _e !== void 0 ? _e : false,
|
|
65890
|
-
include_seed_fingerprint: (_f = batch.includeSeedFingerprint) !== null && _f !== void 0 ? _f : false,
|
|
65891
|
-
});
|
|
65892
|
-
});
|
|
65893
|
-
}
|
|
65894
|
-
getVersionRange() {
|
|
65895
|
-
return {
|
|
65896
|
-
model_pro2: {
|
|
65897
|
-
min: '0.0.0',
|
|
65898
|
-
},
|
|
65899
|
-
};
|
|
65900
|
-
}
|
|
65901
|
-
run() {
|
|
65902
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
65903
|
-
const responses = [];
|
|
65904
|
-
for (let i = 0; i < this.params.length; i++) {
|
|
65905
|
-
const param = this.params[i];
|
|
65906
|
-
const res = yield this.device.commands.typedCall('ZcashGetAddress', 'ZcashAddress', Object.assign({}, param));
|
|
65907
|
-
const path = serializedPath(param.address_n);
|
|
65908
|
-
responses.push({
|
|
65909
|
-
path,
|
|
65910
|
-
address: res.message.address,
|
|
65911
|
-
ufvk: res.message.ufvk,
|
|
65912
|
-
seedFingerprint: res.message.seed_fingerprint,
|
|
65913
|
-
});
|
|
65914
|
-
this.postPreviousAddressMessage({
|
|
65915
|
-
address: res.message.address,
|
|
65916
|
-
path,
|
|
65917
|
-
});
|
|
65918
|
-
}
|
|
65919
|
-
validateResult(responses, ['address'], {
|
|
65920
|
-
expectedLength: this.params.length,
|
|
65921
|
-
});
|
|
65922
|
-
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
65923
|
-
});
|
|
65924
|
-
}
|
|
65925
|
-
}
|
|
65926
|
-
|
|
65927
|
-
const CHUNK_BYTE_SIZE = 1024;
|
|
65928
|
-
const SIGNED_PCZT_SANITY_MAX_BYTES = 16 * 1024 * 1024;
|
|
65929
|
-
class ZcashSignPczt extends BaseMethod {
|
|
65930
|
-
constructor() {
|
|
65931
|
-
super(...arguments);
|
|
65932
|
-
this.pczt = Buffer.alloc(0);
|
|
65933
|
-
this.uploadPczt = (typedCall, res, offset) => __awaiter(this, void 0, void 0, function* () {
|
|
65934
|
-
if (res.type === 'ZcashSignedPczt') {
|
|
65935
|
-
if (offset !== this.pczt.length) {
|
|
65936
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, 'device completed signing before receiving the whole pczt');
|
|
65937
|
-
}
|
|
65938
|
-
return res;
|
|
65939
|
-
}
|
|
65940
|
-
const { chunk_length: chunkLength } = res.message;
|
|
65941
|
-
if (!Number.isSafeInteger(chunkLength) ||
|
|
65942
|
-
chunkLength <= 0 ||
|
|
65943
|
-
offset + chunkLength > this.pczt.length) {
|
|
65944
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, `device requested ${chunkLength} bytes at offset ${offset} of ${this.pczt.length}`);
|
|
65945
|
-
}
|
|
65946
|
-
const chunk = this.pczt.subarray(offset, offset + chunkLength);
|
|
65947
|
-
const next = yield typedCall('ZcashPcztChunkAck', ['ZcashSignedPczt', 'ZcashPcztChunkRequest'], {
|
|
65948
|
-
data_chunk: utils.bytesToHex(chunk),
|
|
65949
|
-
});
|
|
65950
|
-
return this.uploadPczt(typedCall, next, offset + chunkLength);
|
|
65951
|
-
});
|
|
65952
|
-
this.downloadSignedPczt = (typedCall, res) => __awaiter(this, void 0, void 0, function* () {
|
|
65953
|
-
var _a;
|
|
65954
|
-
const { pczt_length: total, pczt_initial_chunk: initial } = res.message;
|
|
65955
|
-
if (!Number.isSafeInteger(total) || total <= 0 || total > SIGNED_PCZT_SANITY_MAX_BYTES) {
|
|
65956
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, `device announced invalid signed pczt length ${total}`);
|
|
65957
|
-
}
|
|
65958
|
-
const parts = [Buffer.from(initial !== null && initial !== void 0 ? initial : '', 'hex')];
|
|
65959
|
-
let received = parts[0].length;
|
|
65960
|
-
if (received > total) {
|
|
65961
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, 'device returned more initial pczt bytes than announced');
|
|
65962
|
-
}
|
|
65963
|
-
while (received < total) {
|
|
65964
|
-
const chunkLength = Math.min(CHUNK_BYTE_SIZE, total - received);
|
|
65965
|
-
const ack = yield typedCall('ZcashSignedPcztChunkRequest', 'ZcashPcztChunkAck', {
|
|
65966
|
-
chunk_length: chunkLength,
|
|
65967
|
-
});
|
|
65968
|
-
const chunk = Buffer.from((_a = ack.message.data_chunk) !== null && _a !== void 0 ? _a : '', 'hex');
|
|
65969
|
-
if (chunk.length !== chunkLength) {
|
|
65970
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, `device returned ${chunk.length} of ${chunkLength} requested bytes at offset ${received} of ${total}`);
|
|
65971
|
-
}
|
|
65972
|
-
parts.push(chunk);
|
|
65973
|
-
received += chunk.length;
|
|
65974
|
-
}
|
|
65975
|
-
return Buffer.concat(parts);
|
|
65976
|
-
});
|
|
65977
|
-
}
|
|
65978
|
-
getSupportedProtocols() {
|
|
65979
|
-
return ['V2'];
|
|
65980
|
-
}
|
|
65981
|
-
init() {
|
|
65982
|
-
this.checkDeviceId = true;
|
|
65983
|
-
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
65984
|
-
this.strictCheckDeviceSupport = true;
|
|
65985
|
-
validateParams(this.payload, [{ name: 'pczt', type: 'hexString', required: true }]);
|
|
65986
|
-
const pcztHex = stripHexPrefix(this.payload.pczt);
|
|
65987
|
-
if (pcztHex.length % 2 !== 0) {
|
|
65988
|
-
throw invalidParameter('pczt hex must have an even length');
|
|
65989
|
-
}
|
|
65990
|
-
this.pczt = Buffer.from(pcztHex, 'hex');
|
|
65991
|
-
if (this.pczt.length === 0) {
|
|
65992
|
-
throw invalidParameter('pczt is empty');
|
|
65993
|
-
}
|
|
65994
|
-
this.params = {
|
|
65995
|
-
pczt_length: this.pczt.length,
|
|
65996
|
-
pczt_initial_chunk: utils.bytesToHex(this.pczt.subarray(0, CHUNK_BYTE_SIZE)),
|
|
65997
|
-
};
|
|
65998
|
-
}
|
|
65999
|
-
getVersionRange() {
|
|
66000
|
-
return {
|
|
66001
|
-
model_pro2: {
|
|
66002
|
-
min: '0.0.0',
|
|
66003
|
-
},
|
|
66004
|
-
};
|
|
66005
|
-
}
|
|
66006
|
-
run() {
|
|
66007
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
66008
|
-
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
66009
|
-
const first = yield typedCall('ZcashSignPczt', ['ZcashSignedPczt', 'ZcashPcztChunkRequest'], Object.assign({}, this.params));
|
|
66010
|
-
const signed = yield this.uploadPczt(typedCall, first, Math.min(CHUNK_BYTE_SIZE, this.pczt.length));
|
|
66011
|
-
const pczt = yield this.downloadSignedPczt(typedCall, signed);
|
|
66012
|
-
return { pczt: utils.bytesToHex(pczt) };
|
|
66013
|
-
});
|
|
66014
|
-
}
|
|
66015
|
-
}
|
|
66016
|
-
|
|
66017
65810
|
var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
66018
65811
|
__proto__: null,
|
|
66019
65812
|
testInitializeDeviceDuration: TestInitializeDeviceDuration,
|
|
@@ -66157,9 +65950,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
66157
65950
|
benfenSignMessage: BenfenSignMessage,
|
|
66158
65951
|
benfenSignTransaction: BenfenSignTransaction,
|
|
66159
65952
|
neoGetAddress: NeoGetAddress,
|
|
66160
|
-
neoSignTransaction: NeoSignTransaction
|
|
66161
|
-
zcashGetAddress: ZcashGetAddress,
|
|
66162
|
-
zcashSignPczt: ZcashSignPczt
|
|
65953
|
+
neoSignTransaction: NeoSignTransaction
|
|
66163
65954
|
});
|
|
66164
65955
|
|
|
66165
65956
|
const publicMethodRegistry = ApiMethods;
|
package/dist/inject.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":";AAWA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAc3C,QAAA,MAAM,eAAe,OAAQ,MAAM,WAAW,GAAG,EAAE,SAKlD,CAAC;AAEF,QAAA,MAAM,eAAe,OAAQ,MAAM,SAElC,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC;AAE5C,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,UAAU,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC1C,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5B,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAClC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC7C;AAQD,eAAO,MAAM,uBAAuB,YAAa,OAAO,CAAC,MAAM,CAAC;;;CAoC/D,CAAC;AAEF,eAAO,MAAM,MAAM,gGAShB,SAAS,KAAG,OAuCd,CAAC;AAEF,eAAO,MAAM,aAAa,SAClB,OAAO,CAAC,MAAM,CAAC,KACpB,KACD,OAAO,EACL,IAAI,GACJ,KAAK,GACL,MAAM,GACN,oBAAoB,GACpB,MAAM,GACN,MAAM,GACN,0BAA0B,GAC1B,SAAS,GACT,YAAY,GACZ,QAAQ,GACR,gBAAgB,GAChB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":";AAWA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAc3C,QAAA,MAAM,eAAe,OAAQ,MAAM,WAAW,GAAG,EAAE,SAKlD,CAAC;AAEF,QAAA,MAAM,eAAe,OAAQ,MAAM,SAElC,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC;AAE5C,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,UAAU,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC1C,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5B,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAClC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC7C;AAQD,eAAO,MAAM,uBAAuB,YAAa,OAAO,CAAC,MAAM,CAAC;;;CAoC/D,CAAC;AAEF,eAAO,MAAM,MAAM,gGAShB,SAAS,KAAG,OAuCd,CAAC;AAEF,eAAO,MAAM,aAAa,SAClB,OAAO,CAAC,MAAM,CAAC,KACpB,KACD,OAAO,EACL,IAAI,GACJ,KAAK,GACL,MAAM,GACN,oBAAoB,GACpB,MAAM,GACN,MAAM,GACN,0BAA0B,GAC1B,SAAS,GACT,YAAY,GACZ,QAAQ,GACR,gBAAgB,GAChB,iBAAiB,CAwVnB,CAAC"}
|
|
@@ -93,6 +93,4 @@ export type { BenfenAddress, BenfenGetAddressParams } from './benfenGetAddress';
|
|
|
93
93
|
export type { BenfenPublicKey, BenfenGetPublicKeyParams } from './benfenGetPublicKey';
|
|
94
94
|
export type { BenfenSignMessageParams } from './benfenSignMessage';
|
|
95
95
|
export type { BenfenSignedTx, BenfenSignTransactionParams } from './benfenSignTransaction';
|
|
96
|
-
export type { ZcashAddress, ZcashGetAddressParams } from './zcashGetAddress';
|
|
97
|
-
export type { ZcashSignedPczt, ZcashSignPcztParams } from './zcashSignPczt';
|
|
98
96
|
//# sourceMappingURL=export.d.ts.map
|