@onekeyfe/hd-core 1.2.2-alpha.9 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +503 -10
- package/__tests__/DeviceCommands.test.ts +254 -1
- package/__tests__/core-error-output.test.ts +169 -1
- package/__tests__/device-lifecycle-events.test.ts +395 -15
- package/__tests__/logBlockEvent.test.ts +45 -122
- package/__tests__/open-wallet-session-error-response.test.ts +2 -2
- package/__tests__/open-wallet-session.test.ts +8 -358
- package/__tests__/protocol-v2.test.ts +130 -0
- package/__tests__/public-device-state-api.test.ts +2 -7
- package/__tests__/search-devices.test.ts +196 -8
- package/__tests__/sol-sign-offchain-message.test.ts +64 -0
- package/dist/api/FirmwareUpdateV4.d.ts +1 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetFeatures.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts +2 -15
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts +1 -0
- package/dist/api/UploadPortfolio.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddress.d.ts +2 -0
- package/dist/api/allnetwork/AllNetworkGetAddress.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts +7 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressByLoop.d.ts.map +1 -1
- package/dist/api/device/DeviceVerify.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/core/RequestQueue.d.ts +1 -0
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/uiPromiseRegistry.d.ts +1 -1
- package/dist/data-manager/TransportManager.d.ts +2 -0
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +2 -0
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +5 -4
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/index.d.ts +35 -30
- package/dist/index.js +587 -314
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/api/getFeatures.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +1 -10
- package/dist/types/api/openWalletSession.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -4
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/api/solSignOffchainMessage.d.ts +1 -0
- package/dist/types/api/solSignOffchainMessage.d.ts.map +1 -1
- package/dist/types/params.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 +9 -4
- package/src/api/GetFeatures.ts +1 -0
- package/src/api/GetPassphraseState.ts +1 -0
- package/src/api/OpenWalletSession.ts +7 -77
- package/src/api/SearchDevices.ts +121 -27
- package/src/api/UploadPortfolio.ts +5 -4
- package/src/api/allnetwork/AllNetworkGetAddress.ts +79 -45
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +95 -24
- package/src/api/allnetwork/AllNetworkGetAddressByLoop.ts +3 -0
- package/src/api/device/DeviceVerify.ts +8 -0
- package/src/api/solana/SolSignOffchainMessage.ts +44 -4
- package/src/core/RequestQueue.ts +20 -0
- package/src/core/index.ts +159 -52
- package/src/data/messages/messages-protocol-v2.json +49 -33
- package/src/data/messages/messages.json +8 -5
- package/src/data-manager/TransportManager.ts +14 -3
- package/src/device/Device.ts +58 -27
- package/src/device/DeviceCommands.ts +29 -2
- package/src/events/logBlockEvent.ts +6 -75
- package/src/protocols/protocol-v2/walletSession.ts +14 -2
- package/src/types/api/getFeatures.ts +2 -1
- package/src/types/api/getPassphraseState.ts +2 -5
- package/src/types/api/openWalletSession.ts +7 -19
- package/src/types/api/protocolV2.ts +3 -4
- package/src/types/api/solSignOffchainMessage.ts +2 -0
- package/src/types/params.ts +7 -0
package/dist/index.js
CHANGED
|
@@ -291,7 +291,6 @@ const writeFirmwareByteSource = ({ source, chunkSize, write, }) => __awaiter(voi
|
|
|
291
291
|
const OpenWalletSessionMode = {
|
|
292
292
|
Standard: 'standard',
|
|
293
293
|
SelectHidden: 'select-hidden',
|
|
294
|
-
ResumeHidden: 'resume-hidden',
|
|
295
294
|
};
|
|
296
295
|
|
|
297
296
|
exports.EOneKeyDeviceMode = void 0;
|
|
@@ -13203,7 +13202,8 @@ var nested$2 = {
|
|
|
13203
13202
|
},
|
|
13204
13203
|
SolanaOffChainMessageVersion: {
|
|
13205
13204
|
values: {
|
|
13206
|
-
MESSAGE_VERSION_0: 0
|
|
13205
|
+
MESSAGE_VERSION_0: 0,
|
|
13206
|
+
MESSAGE_VERSION_1: 1
|
|
13207
13207
|
}
|
|
13208
13208
|
},
|
|
13209
13209
|
SolanaOffChainMessageFormat: {
|
|
@@ -13236,14 +13236,16 @@ var nested$2 = {
|
|
|
13236
13236
|
},
|
|
13237
13237
|
message_format: {
|
|
13238
13238
|
type: "SolanaOffChainMessageFormat",
|
|
13239
|
-
id: 4
|
|
13240
|
-
options: {
|
|
13241
|
-
"default": "V0_RESTRICTED_ASCII"
|
|
13242
|
-
}
|
|
13239
|
+
id: 4
|
|
13243
13240
|
},
|
|
13244
13241
|
application_domain: {
|
|
13245
13242
|
type: "bytes",
|
|
13246
13243
|
id: 5
|
|
13244
|
+
},
|
|
13245
|
+
required_signers: {
|
|
13246
|
+
rule: "repeated",
|
|
13247
|
+
type: "bytes",
|
|
13248
|
+
id: 7
|
|
13247
13249
|
}
|
|
13248
13250
|
}
|
|
13249
13251
|
},
|
|
@@ -31499,10 +31501,6 @@ var nested = {
|
|
|
31499
31501
|
request_id: {
|
|
31500
31502
|
type: "bytes",
|
|
31501
31503
|
id: 5
|
|
31502
|
-
},
|
|
31503
|
-
source_fingerprint: {
|
|
31504
|
-
type: "uint32",
|
|
31505
|
-
id: 6
|
|
31506
31504
|
}
|
|
31507
31505
|
}
|
|
31508
31506
|
},
|
|
@@ -31758,10 +31756,6 @@ var nested = {
|
|
|
31758
31756
|
expected_address: {
|
|
31759
31757
|
type: "bytes",
|
|
31760
31758
|
id: 12
|
|
31761
|
-
},
|
|
31762
|
-
source_fingerprint: {
|
|
31763
|
-
type: "uint32",
|
|
31764
|
-
id: 13
|
|
31765
31759
|
}
|
|
31766
31760
|
}
|
|
31767
31761
|
},
|
|
@@ -31846,10 +31840,6 @@ var nested = {
|
|
|
31846
31840
|
expected_address: {
|
|
31847
31841
|
type: "bytes",
|
|
31848
31842
|
id: 12
|
|
31849
|
-
},
|
|
31850
|
-
source_fingerprint: {
|
|
31851
|
-
type: "uint32",
|
|
31852
|
-
id: 13
|
|
31853
31843
|
}
|
|
31854
31844
|
}
|
|
31855
31845
|
},
|
|
@@ -31997,7 +31987,29 @@ var nested = {
|
|
|
31997
31987
|
type: "EthereumAuthorizationSignature",
|
|
31998
31988
|
id: 10
|
|
31999
31989
|
}
|
|
32000
|
-
}
|
|
31990
|
+
},
|
|
31991
|
+
reserved: [
|
|
31992
|
+
[
|
|
31993
|
+
5,
|
|
31994
|
+
5
|
|
31995
|
+
],
|
|
31996
|
+
[
|
|
31997
|
+
6,
|
|
31998
|
+
6
|
|
31999
|
+
],
|
|
32000
|
+
[
|
|
32001
|
+
7,
|
|
32002
|
+
7
|
|
32003
|
+
],
|
|
32004
|
+
[
|
|
32005
|
+
8,
|
|
32006
|
+
8
|
|
32007
|
+
],
|
|
32008
|
+
[
|
|
32009
|
+
9,
|
|
32010
|
+
9
|
|
32011
|
+
]
|
|
32012
|
+
]
|
|
32001
32013
|
},
|
|
32002
32014
|
EthereumTxAckOneKey: {
|
|
32003
32015
|
fields: {
|
|
@@ -32026,10 +32038,6 @@ var nested = {
|
|
|
32026
32038
|
chain_id: {
|
|
32027
32039
|
type: "uint64",
|
|
32028
32040
|
id: 3
|
|
32029
|
-
},
|
|
32030
|
-
source_fingerprint: {
|
|
32031
|
-
type: "uint32",
|
|
32032
|
-
id: 4
|
|
32033
32041
|
}
|
|
32034
32042
|
}
|
|
32035
32043
|
},
|
|
@@ -36027,7 +36035,8 @@ var nested = {
|
|
|
36027
36035
|
},
|
|
36028
36036
|
SolanaOffChainMessageVersion: {
|
|
36029
36037
|
values: {
|
|
36030
|
-
MESSAGE_VERSION_0: 0
|
|
36038
|
+
MESSAGE_VERSION_0: 0,
|
|
36039
|
+
MESSAGE_VERSION_1: 1
|
|
36031
36040
|
}
|
|
36032
36041
|
},
|
|
36033
36042
|
SolanaOffChainMessageFormat: {
|
|
@@ -36075,10 +36084,6 @@ var nested = {
|
|
|
36075
36084
|
rule: "required",
|
|
36076
36085
|
type: "bytes",
|
|
36077
36086
|
id: 2
|
|
36078
|
-
},
|
|
36079
|
-
source_fingerprint: {
|
|
36080
|
-
type: "uint32",
|
|
36081
|
-
id: 3
|
|
36082
36087
|
}
|
|
36083
36088
|
}
|
|
36084
36089
|
},
|
|
@@ -36115,17 +36120,15 @@ var nested = {
|
|
|
36115
36120
|
},
|
|
36116
36121
|
message_format: {
|
|
36117
36122
|
type: "SolanaOffChainMessageFormat",
|
|
36118
|
-
id: 4
|
|
36119
|
-
options: {
|
|
36120
|
-
"default": "V0_RESTRICTED_ASCII"
|
|
36121
|
-
}
|
|
36123
|
+
id: 4
|
|
36122
36124
|
},
|
|
36123
36125
|
application_domain: {
|
|
36124
36126
|
type: "bytes",
|
|
36125
36127
|
id: 5
|
|
36126
36128
|
},
|
|
36127
|
-
|
|
36128
|
-
|
|
36129
|
+
required_signers: {
|
|
36130
|
+
rule: "repeated",
|
|
36131
|
+
type: "bytes",
|
|
36129
36132
|
id: 6
|
|
36130
36133
|
}
|
|
36131
36134
|
}
|
|
@@ -36144,10 +36147,6 @@ var nested = {
|
|
|
36144
36147
|
rule: "required",
|
|
36145
36148
|
type: "bytes",
|
|
36146
36149
|
id: 2
|
|
36147
|
-
},
|
|
36148
|
-
source_fingerprint: {
|
|
36149
|
-
type: "uint32",
|
|
36150
|
-
id: 3
|
|
36151
36150
|
}
|
|
36152
36151
|
}
|
|
36153
36152
|
},
|
|
@@ -38564,6 +38563,7 @@ var nested = {
|
|
|
38564
38563
|
MessageType_DeviceFindMyTokenState: 60450,
|
|
38565
38564
|
MessageType_DeviceFindMyTokenUpdate: 60451,
|
|
38566
38565
|
MessageType_DeviceFindMyTokenStateGet: 60452,
|
|
38566
|
+
MessageType_DeviceAnimationControl: 60461,
|
|
38567
38567
|
MessageType_DeviceInfoGet: 60600,
|
|
38568
38568
|
MessageType_DeviceInfo: 60601,
|
|
38569
38569
|
MessageType_DeviceStatusGet: 60602,
|
|
@@ -38902,6 +38902,26 @@ var nested = {
|
|
|
38902
38902
|
}
|
|
38903
38903
|
}
|
|
38904
38904
|
},
|
|
38905
|
+
DeviceAnimationAction: {
|
|
38906
|
+
values: {
|
|
38907
|
+
AnimationAction_Unknown: 0,
|
|
38908
|
+
AnimationAction_Start: 1,
|
|
38909
|
+
AnimationAction_Stop: 2
|
|
38910
|
+
}
|
|
38911
|
+
},
|
|
38912
|
+
DeviceAnimationControl: {
|
|
38913
|
+
fields: {
|
|
38914
|
+
action: {
|
|
38915
|
+
rule: "required",
|
|
38916
|
+
type: "DeviceAnimationAction",
|
|
38917
|
+
id: 1
|
|
38918
|
+
},
|
|
38919
|
+
timeout_ms: {
|
|
38920
|
+
type: "uint32",
|
|
38921
|
+
id: 2
|
|
38922
|
+
}
|
|
38923
|
+
}
|
|
38924
|
+
},
|
|
38905
38925
|
DeviceFactoryAck: {
|
|
38906
38926
|
values: {
|
|
38907
38927
|
FACTORY_ACK_SUCCESS: 0,
|
|
@@ -38963,6 +38983,10 @@ var nested = {
|
|
|
38963
38983
|
manufacture_time: {
|
|
38964
38984
|
type: "DeviceFactoryInfoManufactureTime",
|
|
38965
38985
|
id: 5
|
|
38986
|
+
},
|
|
38987
|
+
data: {
|
|
38988
|
+
type: "bytes",
|
|
38989
|
+
id: 100
|
|
38966
38990
|
}
|
|
38967
38991
|
}
|
|
38968
38992
|
},
|
|
@@ -38972,11 +38996,19 @@ var nested = {
|
|
|
38972
38996
|
rule: "required",
|
|
38973
38997
|
type: "DeviceFactoryInfo",
|
|
38974
38998
|
id: 1
|
|
38999
|
+
},
|
|
39000
|
+
full_data: {
|
|
39001
|
+
type: "bool",
|
|
39002
|
+
id: 2
|
|
38975
39003
|
}
|
|
38976
39004
|
}
|
|
38977
39005
|
},
|
|
38978
39006
|
DeviceFactoryInfoGet: {
|
|
38979
39007
|
fields: {
|
|
39008
|
+
full_data: {
|
|
39009
|
+
type: "bool",
|
|
39010
|
+
id: 1
|
|
39011
|
+
}
|
|
38980
39012
|
}
|
|
38981
39013
|
},
|
|
38982
39014
|
DeviceFactoryPermanentLock: {
|
|
@@ -41663,61 +41695,13 @@ const LogBlockEvent = new Set([
|
|
|
41663
41695
|
UI_RESPONSE.RECEIVE_PIN,
|
|
41664
41696
|
UI_RESPONSE.RECEIVE_PASSPHRASE,
|
|
41665
41697
|
]);
|
|
41666
|
-
const
|
|
41667
|
-
'openWalletSession',
|
|
41698
|
+
const LogPayloadBlockMethod = new Set([
|
|
41668
41699
|
'deviceUploadNft',
|
|
41669
41700
|
'deviceUploadWallpaper',
|
|
41670
41701
|
'uploadPortfolio',
|
|
41671
41702
|
'fileWrite',
|
|
41672
41703
|
'fileRead',
|
|
41673
41704
|
]);
|
|
41674
|
-
const LogPayloadBlockMethod = new Set([
|
|
41675
|
-
'deviceUploadNft',
|
|
41676
|
-
'deviceUploadWallpaper',
|
|
41677
|
-
'uploadPortfolio',
|
|
41678
|
-
]);
|
|
41679
|
-
const SensitiveLogKeys = new Set([
|
|
41680
|
-
'devicestate',
|
|
41681
|
-
'entropy',
|
|
41682
|
-
'expectedpassphrasestate',
|
|
41683
|
-
'mnemonic',
|
|
41684
|
-
'passphrase',
|
|
41685
|
-
'passphrasestate',
|
|
41686
|
-
'password',
|
|
41687
|
-
'pin',
|
|
41688
|
-
'privatekey',
|
|
41689
|
-
'seed',
|
|
41690
|
-
'session',
|
|
41691
|
-
'sessionid',
|
|
41692
|
-
'walletsessionid',
|
|
41693
|
-
'xprv',
|
|
41694
|
-
]);
|
|
41695
|
-
const normalizeLogKey = (key) => key.replace(/[_-]/g, '').toLowerCase();
|
|
41696
|
-
const isSigningMethod = (methodName) => /sign/i.test(methodName);
|
|
41697
|
-
const redactLogValue = (value, seen) => {
|
|
41698
|
-
if (ArrayBuffer.isView(value)) {
|
|
41699
|
-
return `[BINARY:${value.byteLength}]`;
|
|
41700
|
-
}
|
|
41701
|
-
if (value instanceof ArrayBuffer) {
|
|
41702
|
-
return `[BINARY:${value.byteLength}]`;
|
|
41703
|
-
}
|
|
41704
|
-
if (Array.isArray(value)) {
|
|
41705
|
-
return value.map(item => redactLogValue(item, seen));
|
|
41706
|
-
}
|
|
41707
|
-
if (!value || typeof value !== 'object')
|
|
41708
|
-
return value;
|
|
41709
|
-
if (seen.has(value))
|
|
41710
|
-
return '[CIRCULAR]';
|
|
41711
|
-
seen.add(value);
|
|
41712
|
-
const redacted = Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
41713
|
-
key,
|
|
41714
|
-
SensitiveLogKeys.has(normalizeLogKey(key)) && item !== null && item !== undefined
|
|
41715
|
-
? '[REDACTED]'
|
|
41716
|
-
: redactLogValue(item, seen),
|
|
41717
|
-
]));
|
|
41718
|
-
seen.delete(value);
|
|
41719
|
-
return redacted;
|
|
41720
|
-
};
|
|
41721
41705
|
function getLogBlockLabel(message) {
|
|
41722
41706
|
if (!message || typeof message !== 'object')
|
|
41723
41707
|
return undefined;
|
|
@@ -41726,26 +41710,16 @@ function getLogBlockLabel(message) {
|
|
|
41726
41710
|
return type;
|
|
41727
41711
|
}
|
|
41728
41712
|
const methodName = method !== null && method !== void 0 ? method : payload === null || payload === void 0 ? void 0 : payload.method;
|
|
41729
|
-
if (methodName &&
|
|
41713
|
+
if (methodName && LogPayloadBlockMethod.has(methodName)) {
|
|
41730
41714
|
return methodName;
|
|
41731
41715
|
}
|
|
41732
41716
|
return undefined;
|
|
41733
41717
|
}
|
|
41734
41718
|
function getSafeLogPayload(value, blockLabel) {
|
|
41735
|
-
if (blockLabel
|
|
41736
|
-
(LogBlockEvent.has(blockLabel) ||
|
|
41737
|
-
LogPayloadBlockMethod.has(blockLabel) ||
|
|
41738
|
-
isSigningMethod(blockLabel))) {
|
|
41719
|
+
if (blockLabel) {
|
|
41739
41720
|
return { method: blockLabel, payload: '[REDACTED]' };
|
|
41740
41721
|
}
|
|
41741
|
-
|
|
41742
|
-
if (blockLabel &&
|
|
41743
|
-
redactedValue &&
|
|
41744
|
-
typeof redactedValue === 'object' &&
|
|
41745
|
-
!Array.isArray(redactedValue)) {
|
|
41746
|
-
return Object.assign(Object.assign({}, redactedValue), { method: blockLabel });
|
|
41747
|
-
}
|
|
41748
|
-
return redactedValue;
|
|
41722
|
+
return value;
|
|
41749
41723
|
}
|
|
41750
41724
|
function formatLogMethodLabel(label, methodName) {
|
|
41751
41725
|
return methodName ? `${label} [${methodName}]` : label;
|
|
@@ -41869,7 +41843,7 @@ const selectDeviceSession = (device, expectedPassphraseState, deriveCardano, onS
|
|
|
41869
41843
|
return getDeviceSession(device, buildDeviceSessionGetRequest());
|
|
41870
41844
|
});
|
|
41871
41845
|
function getProtocolV2WalletSession(device, options) {
|
|
41872
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
41846
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
41873
41847
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41874
41848
|
const forceWalletSelection = (options === null || options === void 0 ? void 0 : options.forceWalletSelection) === true || (options === null || options === void 0 ? void 0 : options.initSession) === true;
|
|
41875
41849
|
const readCurrentAttachPinSession = (options === null || options === void 0 ? void 0 : options.readCurrentAttachPinSession) === true;
|
|
@@ -41904,6 +41878,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41904
41878
|
? device.getInternalState()
|
|
41905
41879
|
: undefined;
|
|
41906
41880
|
let response;
|
|
41881
|
+
let walletSelectionRequested = false;
|
|
41907
41882
|
let resumed = false;
|
|
41908
41883
|
let walletStatusRefreshed = false;
|
|
41909
41884
|
const markWalletStatusRefreshed = () => {
|
|
@@ -41940,7 +41915,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41940
41915
|
return keepAttachPin ? Object.assign(session, { viaAttachPin: true }) : session;
|
|
41941
41916
|
});
|
|
41942
41917
|
const rejectMismatchedAttachPinWallet = () => __awaiter(this, void 0, void 0, function* () {
|
|
41943
|
-
var
|
|
41918
|
+
var _o;
|
|
41944
41919
|
const features = yield refreshProtocolV2DeviceStatus(device);
|
|
41945
41920
|
markWalletStatusRefreshed();
|
|
41946
41921
|
if (features.unlockedAttachPin !== true) {
|
|
@@ -41949,10 +41924,10 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41949
41924
|
try {
|
|
41950
41925
|
yield device.lockDevice();
|
|
41951
41926
|
}
|
|
41952
|
-
catch (
|
|
41927
|
+
catch (_p) {
|
|
41953
41928
|
}
|
|
41954
41929
|
if (options === null || options === void 0 ? void 0 : options.rejectAttachPinForMainWallet) {
|
|
41955
|
-
(
|
|
41930
|
+
(_o = device.clearStandardInternalState) === null || _o === void 0 ? void 0 : _o.call(device);
|
|
41956
41931
|
device.clearInternalState();
|
|
41957
41932
|
}
|
|
41958
41933
|
else {
|
|
@@ -41961,11 +41936,11 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41961
41936
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckUnlockTypeError);
|
|
41962
41937
|
});
|
|
41963
41938
|
const lockAttachPinBeforePassphraseSelection = () => __awaiter(this, void 0, void 0, function* () {
|
|
41964
|
-
var
|
|
41939
|
+
var _q;
|
|
41965
41940
|
if (readCurrentAttachPinSession || (options === null || options === void 0 ? void 0 : options.onlyMainPin)) {
|
|
41966
41941
|
return;
|
|
41967
41942
|
}
|
|
41968
|
-
if (((
|
|
41943
|
+
if (((_q = device.features) === null || _q === void 0 ? void 0 : _q.unlockedAttachPin) !== true) {
|
|
41969
41944
|
return;
|
|
41970
41945
|
}
|
|
41971
41946
|
yield rejectMismatchedAttachPinWallet();
|
|
@@ -41986,8 +41961,8 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41986
41961
|
}
|
|
41987
41962
|
});
|
|
41988
41963
|
const selectStandardWallet = (forceMainPin = false) => __awaiter(this, void 0, void 0, function* () {
|
|
41989
|
-
var
|
|
41990
|
-
if (((
|
|
41964
|
+
var _r;
|
|
41965
|
+
if (((_r = device.features) === null || _r === void 0 ? void 0 : _r.passphraseProtection) === true) {
|
|
41991
41966
|
yield selectMainPin();
|
|
41992
41967
|
yield askDevicePassphrase(device, {
|
|
41993
41968
|
passphrase: '',
|
|
@@ -42052,6 +42027,9 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42052
42027
|
throw error;
|
|
42053
42028
|
}
|
|
42054
42029
|
resumed = false;
|
|
42030
|
+
if (((_g = device.features) === null || _g === void 0 ? void 0 : _g.unlockedAttachPin) === true) {
|
|
42031
|
+
response = yield getDeviceSession(device, sessionGetRequest());
|
|
42032
|
+
}
|
|
42055
42033
|
}
|
|
42056
42034
|
}
|
|
42057
42035
|
else if (expectedPassphraseState) {
|
|
@@ -42072,6 +42050,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42072
42050
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WalletSessionInvalid);
|
|
42073
42051
|
}
|
|
42074
42052
|
yield lockAttachPinBeforePassphraseSelection();
|
|
42053
|
+
walletSelectionRequested = true;
|
|
42075
42054
|
response = yield selectDeviceSession(device, expectedPassphraseState, options === null || options === void 0 ? void 0 : options.deriveCardano, markWalletStatusRefreshed);
|
|
42076
42055
|
}
|
|
42077
42056
|
let { message } = response;
|
|
@@ -42080,7 +42059,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42080
42059
|
}
|
|
42081
42060
|
catch (error) {
|
|
42082
42061
|
if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
42083
|
-
(
|
|
42062
|
+
(_h = device.clearStandardInternalState) === null || _h === void 0 ? void 0 : _h.call(device);
|
|
42084
42063
|
}
|
|
42085
42064
|
else {
|
|
42086
42065
|
device.clearInternalState();
|
|
@@ -42094,8 +42073,12 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42094
42073
|
device.clearInternalState();
|
|
42095
42074
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WalletSessionInvalid);
|
|
42096
42075
|
}
|
|
42076
|
+
if (walletSelectionRequested) {
|
|
42077
|
+
clearCurrentWalletSession();
|
|
42078
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
42079
|
+
}
|
|
42097
42080
|
if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
42098
|
-
(
|
|
42081
|
+
(_j = device.clearStandardInternalState) === null || _j === void 0 ? void 0 : _j.call(device);
|
|
42099
42082
|
yield selectStandardWallet(true);
|
|
42100
42083
|
response = yield getDeviceSession(device, sessionGetRequest());
|
|
42101
42084
|
}
|
|
@@ -42110,7 +42093,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42110
42093
|
}
|
|
42111
42094
|
catch (error) {
|
|
42112
42095
|
if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
42113
|
-
(
|
|
42096
|
+
(_k = device.clearStandardInternalState) === null || _k === void 0 ? void 0 : _k.call(device);
|
|
42114
42097
|
}
|
|
42115
42098
|
else {
|
|
42116
42099
|
device.clearInternalState();
|
|
@@ -42133,7 +42116,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42133
42116
|
if (sessionIsAttachPinWallet(response)) {
|
|
42134
42117
|
response = yield askEmptyPassphraseAndGet({ deriveCardano: true, keepAttachPin: true });
|
|
42135
42118
|
}
|
|
42136
|
-
else if (((
|
|
42119
|
+
else if (((_l = device.features) === null || _l === void 0 ? void 0 : _l.passphraseProtection) === false) {
|
|
42137
42120
|
response = yield getDeviceSession(device, buildDeviceSessionGetRequest());
|
|
42138
42121
|
}
|
|
42139
42122
|
else if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
@@ -42150,7 +42133,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42150
42133
|
}
|
|
42151
42134
|
catch (error) {
|
|
42152
42135
|
if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
42153
|
-
(
|
|
42136
|
+
(_m = device.clearStandardInternalState) === null || _m === void 0 ? void 0 : _m.call(device);
|
|
42154
42137
|
}
|
|
42155
42138
|
else {
|
|
42156
42139
|
device.clearInternalState();
|
|
@@ -43722,6 +43705,18 @@ class TransportManager {
|
|
|
43722
43705
|
this.defaultMessages = DataManager.getProtobufMessages();
|
|
43723
43706
|
this.currentMessages = this.defaultMessages;
|
|
43724
43707
|
this.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
43708
|
+
this.webUsbInit = false;
|
|
43709
|
+
}
|
|
43710
|
+
static ensureInitialized() {
|
|
43711
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43712
|
+
const env = DataManager.getSettings('env');
|
|
43713
|
+
if (env !== 'webusb' && env !== 'desktop-webusb')
|
|
43714
|
+
return;
|
|
43715
|
+
if (this.webUsbInit)
|
|
43716
|
+
return;
|
|
43717
|
+
yield this.transport.init(WebUsbLogger, DevicePool.emitter);
|
|
43718
|
+
this.webUsbInit = true;
|
|
43719
|
+
});
|
|
43725
43720
|
}
|
|
43726
43721
|
static configure() {
|
|
43727
43722
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -43750,7 +43745,7 @@ class TransportManager {
|
|
|
43750
43745
|
yield this.transport.init(WebBleLogger, DevicePool.emitter);
|
|
43751
43746
|
}
|
|
43752
43747
|
else if (env === 'webusb' || env === 'desktop-webusb') {
|
|
43753
|
-
yield this.
|
|
43748
|
+
yield this.ensureInitialized();
|
|
43754
43749
|
}
|
|
43755
43750
|
else {
|
|
43756
43751
|
yield this.transport.init(HttpLogger);
|
|
@@ -43833,6 +43828,7 @@ class TransportManager {
|
|
|
43833
43828
|
}
|
|
43834
43829
|
}
|
|
43835
43830
|
TransportManager.reactNativeInit = false;
|
|
43831
|
+
TransportManager.webUsbInit = false;
|
|
43836
43832
|
TransportManager.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
43837
43833
|
TransportManager.plugin = null;
|
|
43838
43834
|
|
|
@@ -43955,6 +43951,7 @@ class DeviceCommands {
|
|
|
43955
43951
|
var _a, _b;
|
|
43956
43952
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43957
43953
|
this.disposed = true;
|
|
43954
|
+
this.disposalToken = {};
|
|
43958
43955
|
yield ((_b = (_a = this.transport).cancel) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
43959
43956
|
});
|
|
43960
43957
|
}
|
|
@@ -44128,7 +44125,24 @@ class DeviceCommands {
|
|
|
44128
44125
|
}
|
|
44129
44126
|
_commonCall(type, msg, options) {
|
|
44130
44127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44131
|
-
const
|
|
44128
|
+
const { disposalToken } = this;
|
|
44129
|
+
let resp = yield this.call(type, msg, options);
|
|
44130
|
+
for (let retry = 0; retry < 3 &&
|
|
44131
|
+
this.device.isProtocolV2() &&
|
|
44132
|
+
DEVICE_SESSION_CALLS.has(type) &&
|
|
44133
|
+
resp.type === 'Failure' &&
|
|
44134
|
+
resp.message.code === 'Failure_ProcessError' &&
|
|
44135
|
+
resp.message.subcode === hdTransport.DeviceSessionErrorCode.DeviceSessionError_Busy; retry += 1) {
|
|
44136
|
+
yield wait(100);
|
|
44137
|
+
if (this.device.wasInterruptedByUser()) {
|
|
44138
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser);
|
|
44139
|
+
}
|
|
44140
|
+
this.checkDisposed();
|
|
44141
|
+
if (this.disposalToken !== disposalToken) {
|
|
44142
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'DeviceCommands lifecycle changed');
|
|
44143
|
+
}
|
|
44144
|
+
resp = yield this.call(type, msg, options);
|
|
44145
|
+
}
|
|
44132
44146
|
return this._filterCommonTypes(resp, type, options);
|
|
44133
44147
|
});
|
|
44134
44148
|
}
|
|
@@ -46349,6 +46363,10 @@ class Device extends events.exports {
|
|
|
46349
46363
|
}
|
|
46350
46364
|
this.invalidateProtocolV2RuntimeState();
|
|
46351
46365
|
}
|
|
46366
|
+
waitForRunCleanup() {
|
|
46367
|
+
var _a;
|
|
46368
|
+
return (_a = this.runCleanupPromise) !== null && _a !== void 0 ? _a : Promise.resolve();
|
|
46369
|
+
}
|
|
46352
46370
|
run(fn, options) {
|
|
46353
46371
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46354
46372
|
if (this.runPromise) {
|
|
@@ -46466,44 +46484,68 @@ class Device extends events.exports {
|
|
|
46466
46484
|
});
|
|
46467
46485
|
}
|
|
46468
46486
|
interruptionFromUser() {
|
|
46469
|
-
var _a
|
|
46470
|
-
|
|
46471
|
-
|
|
46472
|
-
|
|
46473
|
-
|
|
46474
|
-
|
|
46475
|
-
|
|
46476
|
-
|
|
46477
|
-
|
|
46478
|
-
|
|
46479
|
-
|
|
46480
|
-
|
|
46481
|
-
|
|
46487
|
+
var _a;
|
|
46488
|
+
const attempt = this.connectionAttempt;
|
|
46489
|
+
if (((_a = this.userInterruption) === null || _a === void 0 ? void 0 : _a.attempt) === attempt) {
|
|
46490
|
+
return this.userInterruption.promise;
|
|
46491
|
+
}
|
|
46492
|
+
const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser);
|
|
46493
|
+
this.interruptedAttempt = attempt;
|
|
46494
|
+
const cleanupPromise = this.runCleanupPromise;
|
|
46495
|
+
const { cancelableAction, commands, runPromise, deviceConnector, mainId } = this;
|
|
46496
|
+
const sendFallbackCancel = this.shouldSendFallbackProtocolCancel();
|
|
46497
|
+
const acquired = this.hasDeviceAcquire();
|
|
46498
|
+
const promise = (() => __awaiter(this, void 0, void 0, function* () {
|
|
46499
|
+
var _b;
|
|
46500
|
+
try {
|
|
46501
|
+
if (cancelableAction) {
|
|
46502
|
+
yield cancelableAction(error);
|
|
46503
|
+
}
|
|
46504
|
+
else if (sendFallbackCancel) {
|
|
46505
|
+
yield ((_b = commands === null || commands === void 0 ? void 0 : commands.cancelDevice) === null || _b === void 0 ? void 0 : _b.call(commands).catch(cancelError => {
|
|
46506
|
+
Log$h.debug('Protocol V2 fallback cancel error', cancelError);
|
|
46507
|
+
}));
|
|
46508
|
+
}
|
|
46509
|
+
else if (!acquired) {
|
|
46510
|
+
if (mainId && (deviceConnector === null || deviceConnector === void 0 ? void 0 : deviceConnector.disconnect)) {
|
|
46511
|
+
Log$h.debug('interruptionFromUser: disconnecting device without acquire, mainId:', mainId);
|
|
46512
|
+
yield deviceConnector.disconnect(mainId);
|
|
46513
|
+
}
|
|
46514
|
+
if (this.connectionAttempt === attempt)
|
|
46515
|
+
this.markTransportDisconnected();
|
|
46516
|
+
}
|
|
46517
|
+
yield (commands === null || commands === void 0 ? void 0 : commands.cancel());
|
|
46482
46518
|
}
|
|
46483
|
-
|
|
46484
|
-
|
|
46485
|
-
|
|
46486
|
-
|
|
46519
|
+
catch (cleanupError) {
|
|
46520
|
+
Log$h.warn('User cancellation cleanup failed; disconnecting device', cleanupError);
|
|
46521
|
+
if (mainId && (deviceConnector === null || deviceConnector === void 0 ? void 0 : deviceConnector.disconnect)) {
|
|
46522
|
+
yield deviceConnector.disconnect(mainId).catch(disconnectError => {
|
|
46523
|
+
Log$h.debug('User cancellation fallback disconnect failed', disconnectError);
|
|
46487
46524
|
});
|
|
46488
46525
|
}
|
|
46489
|
-
this.
|
|
46526
|
+
if (this.connectionAttempt === attempt)
|
|
46527
|
+
this.markTransportDisconnected();
|
|
46490
46528
|
}
|
|
46491
|
-
|
|
46492
|
-
|
|
46493
|
-
this.runPromise
|
|
46494
|
-
|
|
46529
|
+
finally {
|
|
46530
|
+
runPromise === null || runPromise === void 0 ? void 0 : runPromise.reject(error);
|
|
46531
|
+
if (this.runPromise === runPromise)
|
|
46532
|
+
this.runPromise = null;
|
|
46533
|
+
yield (cleanupPromise === null || cleanupPromise === void 0 ? void 0 : cleanupPromise.catch(() => undefined));
|
|
46495
46534
|
}
|
|
46496
|
-
|
|
46497
|
-
}
|
|
46535
|
+
}))();
|
|
46536
|
+
this.userInterruption = { attempt, promise };
|
|
46537
|
+
return promise;
|
|
46498
46538
|
}
|
|
46499
46539
|
setCancelableAction(callback) {
|
|
46500
|
-
|
|
46540
|
+
const action = (e) => callback(e)
|
|
46501
46541
|
.catch(e2 => {
|
|
46502
46542
|
Log$h.debug('cancelableAction error', e2);
|
|
46503
46543
|
})
|
|
46504
46544
|
.finally(() => {
|
|
46505
|
-
this.
|
|
46545
|
+
if (this.cancelableAction === action)
|
|
46546
|
+
this.clearCancelableAction();
|
|
46506
46547
|
});
|
|
46548
|
+
this.cancelableAction = action;
|
|
46507
46549
|
}
|
|
46508
46550
|
clearCancelableAction() {
|
|
46509
46551
|
this.cancelableAction = undefined;
|
|
@@ -47235,6 +47277,48 @@ class PreInitialize extends BaseMethod {
|
|
|
47235
47277
|
}
|
|
47236
47278
|
|
|
47237
47279
|
const Log$e = getLogger(exports.LoggerNames.DevicePool);
|
|
47280
|
+
const getDescriptorKeys = (descriptor) => [descriptor.path, descriptor.id].filter((key) => typeof key === 'string' && key.length > 0);
|
|
47281
|
+
const isOwnedByActiveWebUsbRequest = (descriptor, requestQueue) => {
|
|
47282
|
+
if (!requestQueue)
|
|
47283
|
+
return false;
|
|
47284
|
+
return getDescriptorKeys(descriptor).some(key => requestQueue.getRequestTasksIdByConnectId(key).length > 0);
|
|
47285
|
+
};
|
|
47286
|
+
const getUsbHandle = (descriptor) => descriptor === null || descriptor === void 0 ? void 0 : descriptor.device;
|
|
47287
|
+
const getOwningRequestDevice = (descriptor, requestQueue) => {
|
|
47288
|
+
var _a, _b;
|
|
47289
|
+
if (!requestQueue)
|
|
47290
|
+
return undefined;
|
|
47291
|
+
const usbHandle = getUsbHandle(descriptor);
|
|
47292
|
+
if (usbHandle === undefined)
|
|
47293
|
+
return undefined;
|
|
47294
|
+
for (const key of getDescriptorKeys(descriptor)) {
|
|
47295
|
+
for (const requestId of requestQueue.getRequestTasksIdByConnectId(key)) {
|
|
47296
|
+
const device = (_a = requestQueue.getTask(requestId)) === null || _a === void 0 ? void 0 : _a.method.device;
|
|
47297
|
+
if ((device === null || device === void 0 ? void 0 : device.features) &&
|
|
47298
|
+
(device.mainId === key || ((_b = device.originalDescriptor) === null || _b === void 0 ? void 0 : _b.path) === key) &&
|
|
47299
|
+
getUsbHandle(device.originalDescriptor) === usbHandle) {
|
|
47300
|
+
return device;
|
|
47301
|
+
}
|
|
47302
|
+
}
|
|
47303
|
+
}
|
|
47304
|
+
return undefined;
|
|
47305
|
+
};
|
|
47306
|
+
const toSearchDeviceFromDescriptor = (descriptor) => {
|
|
47307
|
+
const connectId = descriptor.path || descriptor.id || null;
|
|
47308
|
+
return {
|
|
47309
|
+
connectId,
|
|
47310
|
+
uuid: '',
|
|
47311
|
+
serialNo: null,
|
|
47312
|
+
deviceId: null,
|
|
47313
|
+
deviceType: hdShared.EDeviceType.Unknown,
|
|
47314
|
+
name: descriptor.name || connectId || '',
|
|
47315
|
+
commType: descriptor.commType,
|
|
47316
|
+
};
|
|
47317
|
+
};
|
|
47318
|
+
const toSearchDevice = (device) => {
|
|
47319
|
+
const message = device.toMessageObject();
|
|
47320
|
+
return message ? message : null;
|
|
47321
|
+
};
|
|
47238
47322
|
class SearchDevices extends BaseMethod {
|
|
47239
47323
|
init() {
|
|
47240
47324
|
this.useDevice = false;
|
|
@@ -47242,20 +47326,32 @@ class SearchDevices extends BaseMethod {
|
|
|
47242
47326
|
this.skipForceUpdateCheck = true;
|
|
47243
47327
|
}
|
|
47244
47328
|
run() {
|
|
47245
|
-
var _a, _b, _c, _d, _e;
|
|
47329
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
47246
47330
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47247
|
-
yield TransportManager.configure();
|
|
47248
|
-
const deviceDiff = yield ((_a = this.connector) === null || _a === void 0 ? void 0 : _a.enumerate());
|
|
47249
|
-
const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
|
|
47250
47331
|
const env = DataManager.getSettings('env');
|
|
47332
|
+
const isWebUsb = env === 'webusb' || env === 'desktop-webusb';
|
|
47333
|
+
const requestQueue = (_a = this.context) === null || _a === void 0 ? void 0 : _a.requestQueue;
|
|
47334
|
+
const hasActiveWebUsbRequest = isWebUsb && ((_b = requestQueue === null || requestQueue === void 0 ? void 0 : requestQueue.getRequestTasksId().length) !== null && _b !== void 0 ? _b : 0) > 0;
|
|
47335
|
+
if (isWebUsb) {
|
|
47336
|
+
try {
|
|
47337
|
+
yield TransportManager.ensureInitialized();
|
|
47338
|
+
}
|
|
47339
|
+
catch (error) {
|
|
47340
|
+
Log$e.debug('WebUSB bring-up unavailable', error);
|
|
47341
|
+
}
|
|
47342
|
+
}
|
|
47343
|
+
if (!hasActiveWebUsbRequest)
|
|
47344
|
+
yield TransportManager.configure();
|
|
47345
|
+
const deviceDiff = yield ((_c = this.connector) === null || _c === void 0 ? void 0 : _c.enumerate());
|
|
47346
|
+
const devicesDescriptor = (_d = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _d !== void 0 ? _d : [];
|
|
47251
47347
|
if (DataManager.isBleConnect(env)) {
|
|
47252
47348
|
const devices = [];
|
|
47253
47349
|
const seenIds = new Set();
|
|
47254
47350
|
for (const device of devicesDescriptor) {
|
|
47255
|
-
const lowerId = (
|
|
47351
|
+
const lowerId = (_e = device.id) === null || _e === void 0 ? void 0 : _e.toLowerCase();
|
|
47256
47352
|
if (!seenIds.has(lowerId)) {
|
|
47257
47353
|
seenIds.add(lowerId);
|
|
47258
|
-
const rawBleName = (
|
|
47354
|
+
const rawBleName = (_g = (_f = device.name) !== null && _f !== void 0 ? _f : device.localName) !== null && _g !== void 0 ? _g : '';
|
|
47259
47355
|
const bleName = hdShared.canonicalizePro2BleAdvertisementName(rawBleName);
|
|
47260
47356
|
devices.push(Object.assign(Object.assign({}, device), { connectId: device.id, serialNo: null, uuid: '', deviceId: null, name: bleName || device.name, deviceType: getDeviceTypeByBleName(bleName) }));
|
|
47261
47357
|
}
|
|
@@ -47264,22 +47360,34 @@ class SearchDevices extends BaseMethod {
|
|
|
47264
47360
|
}
|
|
47265
47361
|
const deviceList = [];
|
|
47266
47362
|
for (const descriptor of devicesDescriptor) {
|
|
47267
|
-
|
|
47268
|
-
const
|
|
47269
|
-
|
|
47270
|
-
|
|
47271
|
-
|
|
47272
|
-
});
|
|
47273
|
-
deviceList.push(...result.deviceList);
|
|
47363
|
+
if (hasActiveWebUsbRequest && isOwnedByActiveWebUsbRequest(descriptor, requestQueue)) {
|
|
47364
|
+
const cached = DevicePool.getDeviceByPath(descriptor.path);
|
|
47365
|
+
const known = (cached === null || cached === void 0 ? void 0 : cached.features) ? cached : getOwningRequestDevice(descriptor, requestQueue);
|
|
47366
|
+
const message = known ? toSearchDevice(known) : null;
|
|
47367
|
+
deviceList.push(message !== null && message !== void 0 ? message : toSearchDeviceFromDescriptor(descriptor));
|
|
47274
47368
|
}
|
|
47275
|
-
|
|
47276
|
-
|
|
47277
|
-
|
|
47278
|
-
|
|
47279
|
-
|
|
47369
|
+
else {
|
|
47370
|
+
try {
|
|
47371
|
+
const result = yield DevicePool.getDevices([descriptor], descriptor.path, {
|
|
47372
|
+
connectProtocol: undefined,
|
|
47373
|
+
forceProtocolDetection: true,
|
|
47374
|
+
refreshRuntimeState: true,
|
|
47375
|
+
});
|
|
47376
|
+
for (const device of result.deviceList) {
|
|
47377
|
+
const message = toSearchDevice(device);
|
|
47378
|
+
if (message)
|
|
47379
|
+
deviceList.push(message);
|
|
47380
|
+
}
|
|
47381
|
+
}
|
|
47382
|
+
catch (error) {
|
|
47383
|
+
const errorCode = error && typeof error === 'object' && 'errorCode' in error
|
|
47384
|
+
? error.errorCode
|
|
47385
|
+
: undefined;
|
|
47386
|
+
Log$e.debug('Skip unavailable device during search', Object.assign({ path: descriptor.path }, (errorCode !== undefined ? { errorCode } : {})));
|
|
47387
|
+
}
|
|
47280
47388
|
}
|
|
47281
47389
|
}
|
|
47282
|
-
return deviceList
|
|
47390
|
+
return deviceList;
|
|
47283
47391
|
});
|
|
47284
47392
|
}
|
|
47285
47393
|
}
|
|
@@ -47613,15 +47721,6 @@ function validateResult(result, nonNullableFields, options) {
|
|
|
47613
47721
|
}
|
|
47614
47722
|
}
|
|
47615
47723
|
|
|
47616
|
-
const requiredString = (value, name) => {
|
|
47617
|
-
if (value === undefined || value === null) {
|
|
47618
|
-
throw invalidParameter(`Missing required parameter: ${name}`);
|
|
47619
|
-
}
|
|
47620
|
-
if (typeof value !== 'string' || !value.trim()) {
|
|
47621
|
-
throw invalidParameter(`Parameter [${name}] must be a non-empty string.`);
|
|
47622
|
-
}
|
|
47623
|
-
return value.trim();
|
|
47624
|
-
};
|
|
47625
47724
|
const wasResumed = (session) => !!session &&
|
|
47626
47725
|
typeof session === 'object' &&
|
|
47627
47726
|
'resumed' in session &&
|
|
@@ -47643,25 +47742,16 @@ const normalizeParams = (payload) => {
|
|
|
47643
47742
|
throw invalidParameter('Parameter [mode] is required.');
|
|
47644
47743
|
}
|
|
47645
47744
|
if (payload.mode !== OpenWalletSessionMode.Standard &&
|
|
47646
|
-
payload.mode !== OpenWalletSessionMode.SelectHidden
|
|
47647
|
-
|
|
47648
|
-
throw invalidParameter('Parameter [mode] must be one of standard, select-hidden, or resume-hidden.');
|
|
47745
|
+
payload.mode !== OpenWalletSessionMode.SelectHidden) {
|
|
47746
|
+
throw invalidParameter('Parameter [mode] must be one of standard or select-hidden.');
|
|
47649
47747
|
}
|
|
47650
47748
|
if (payload.useEmptyPassphrase !== undefined || payload.initSession !== undefined) {
|
|
47651
47749
|
throw invalidParameter('Legacy parameters [useEmptyPassphrase] and [initSession] are not supported by openWalletSession.');
|
|
47652
47750
|
}
|
|
47653
|
-
if (payload.
|
|
47654
|
-
|
|
47655
|
-
if (payload.deviceId !== undefined || payload.passphraseState !== undefined) {
|
|
47656
|
-
throw invalidParameter('Parameters [deviceId] and [passphraseState] are only allowed with mode [resume-hidden].');
|
|
47657
|
-
}
|
|
47658
|
-
return { mode: payload.mode };
|
|
47751
|
+
if (payload.deviceId !== undefined || payload.passphraseState !== undefined) {
|
|
47752
|
+
throw invalidParameter('Parameters [deviceId] and [passphraseState] are not supported by openWalletSession. Pass passphraseState on later address and signing calls.');
|
|
47659
47753
|
}
|
|
47660
|
-
return {
|
|
47661
|
-
mode: OpenWalletSessionMode.ResumeHidden,
|
|
47662
|
-
deviceId: requiredString(payload.deviceId, 'deviceId'),
|
|
47663
|
-
passphraseState: requiredString(payload.passphraseState, 'passphraseState'),
|
|
47664
|
-
};
|
|
47754
|
+
return { mode: payload.mode };
|
|
47665
47755
|
};
|
|
47666
47756
|
class OpenWalletSession extends BaseMethod {
|
|
47667
47757
|
getSupportedProtocols() {
|
|
@@ -47764,43 +47854,6 @@ class OpenWalletSession extends BaseMethod {
|
|
|
47764
47854
|
resumed: wasResumed(session),
|
|
47765
47855
|
};
|
|
47766
47856
|
}
|
|
47767
|
-
if (this.params.mode === OpenWalletSessionMode.ResumeHidden) {
|
|
47768
|
-
if (isProtocolV2) {
|
|
47769
|
-
yield ensureProtocolV2WalletStatus();
|
|
47770
|
-
const refreshedDeviceId = requireDeviceId();
|
|
47771
|
-
if (refreshedDeviceId !== this.params.deviceId) {
|
|
47772
|
-
deviceWalletSessionStore.delete(this.params.deviceId, this.params.passphraseState);
|
|
47773
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
47774
|
-
}
|
|
47775
|
-
}
|
|
47776
|
-
else if (requireDeviceId() !== this.params.deviceId) {
|
|
47777
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
47778
|
-
}
|
|
47779
|
-
this.device.passphraseState = this.params.passphraseState;
|
|
47780
|
-
const cachedSessionId = deviceWalletSessionStore.get(this.params.deviceId, this.params.passphraseState);
|
|
47781
|
-
if (!cachedSessionId && !isProtocolV2) {
|
|
47782
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WalletSessionInvalid);
|
|
47783
|
-
}
|
|
47784
|
-
if (!isProtocolV2) {
|
|
47785
|
-
yield this.device.initialize({
|
|
47786
|
-
deviceId: this.params.deviceId,
|
|
47787
|
-
passphraseState: this.params.passphraseState,
|
|
47788
|
-
});
|
|
47789
|
-
}
|
|
47790
|
-
const session = isProtocolV2
|
|
47791
|
-
? yield getProtocolV2WalletSession(this.device, {
|
|
47792
|
-
expectedPassphraseState: this.params.passphraseState,
|
|
47793
|
-
})
|
|
47794
|
-
: yield getPassphraseStateWithRefreshDeviceInfo(this.device, {
|
|
47795
|
-
expectPassphraseState: this.params.passphraseState,
|
|
47796
|
-
});
|
|
47797
|
-
const deviceId = requireDeviceId();
|
|
47798
|
-
if (session.passphraseState !== this.params.passphraseState) {
|
|
47799
|
-
this.device.clearInternalState();
|
|
47800
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
47801
|
-
}
|
|
47802
|
-
return Object.assign(Object.assign({ protocol, walletType: 'hidden', deviceId }, requireHiddenWalletResponse(session)), { resumed: wasResumed(session) || (!isProtocolV2 && session.newSession === cachedSessionId) });
|
|
47803
|
-
}
|
|
47804
47857
|
this.device.passphraseState = undefined;
|
|
47805
47858
|
const walletStatus = yield ensureProtocolV2WalletStatus();
|
|
47806
47859
|
if (isProtocolV2 && walletStatus.status.passphraseProtection !== true) {
|
|
@@ -49211,6 +49264,14 @@ class DeviceVerify extends BaseMethod {
|
|
|
49211
49264
|
this.unlockPolicy = 'unlock-before-run';
|
|
49212
49265
|
this.protocolV2PreUnlockPinType = hdTransport.DeviceSessionPinType.Any;
|
|
49213
49266
|
this.useDevicePassphraseState = false;
|
|
49267
|
+
this.protocolV2UiInteraction = {
|
|
49268
|
+
request: 'button',
|
|
49269
|
+
source: 'method-lifecycle',
|
|
49270
|
+
reason: 'device-management',
|
|
49271
|
+
completion: 'operation-completed',
|
|
49272
|
+
deviceOnly: true,
|
|
49273
|
+
operation: 'deviceVerify',
|
|
49274
|
+
};
|
|
49214
49275
|
validateParams(this.payload, [{ name: 'dataHex', type: 'hexString' }]);
|
|
49215
49276
|
this.params = {
|
|
49216
49277
|
data: formatAnyHex(this.payload.dataHex),
|
|
@@ -52650,6 +52711,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52650
52711
|
this.protocolV2InstallDisconnectObserved = false;
|
|
52651
52712
|
this.protocolV2InstallTerminalSuccessObserved = false;
|
|
52652
52713
|
this.protocolV2LastTransferProgressAt = 0;
|
|
52714
|
+
this.protocolV2LastTransferredBytes = 0;
|
|
52653
52715
|
}
|
|
52654
52716
|
getSupportedProtocols() {
|
|
52655
52717
|
return ['V2'];
|
|
@@ -53812,6 +53874,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53812
53874
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartTransferData);
|
|
53813
53875
|
this.protocolV2LastTransferProgress = undefined;
|
|
53814
53876
|
this.protocolV2LastTransferProgressAt = 0;
|
|
53877
|
+
this.protocolV2LastTransferredBytes = 0;
|
|
53815
53878
|
const transferStartedAt = Date.now();
|
|
53816
53879
|
let processedSize = 0;
|
|
53817
53880
|
for (const resource of resourcesToSync) {
|
|
@@ -53894,13 +53957,15 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53894
53957
|
const now = Date.now();
|
|
53895
53958
|
const elapsedMs = Math.max(now - transferStartedAt, 0);
|
|
53896
53959
|
const progress = Math.min(Math.ceil((transferredBytes / totalSize) * 100), 99);
|
|
53897
|
-
const shouldPostProgress =
|
|
53898
|
-
|
|
53899
|
-
|
|
53900
|
-
|
|
53960
|
+
const shouldPostProgress = transferredBytes >= this.protocolV2LastTransferredBytes &&
|
|
53961
|
+
(progress !== this.protocolV2LastTransferProgress ||
|
|
53962
|
+
now - this.protocolV2LastTransferProgressAt >=
|
|
53963
|
+
PROTOCOL_V2_TRANSFER_PROGRESS_HEARTBEAT_MS ||
|
|
53964
|
+
chunkEnd === source.size);
|
|
53901
53965
|
if (shouldPostProgress) {
|
|
53902
53966
|
this.protocolV2LastTransferProgress = progress;
|
|
53903
53967
|
this.protocolV2LastTransferProgressAt = now;
|
|
53968
|
+
this.protocolV2LastTransferredBytes = transferredBytes;
|
|
53904
53969
|
this.postProgressMessage(progress, 'transferData', {
|
|
53905
53970
|
transferredBytes,
|
|
53906
53971
|
totalBytes: totalSize,
|
|
@@ -55459,16 +55524,16 @@ const FILESYSTEM_FILE_WRITE_MESSAGE_TYPE = 60805;
|
|
|
55459
55524
|
const PORTFOLIO_UPDATE_MESSAGE_TYPE = 61400;
|
|
55460
55525
|
class UploadPortfolio extends FileWrite {
|
|
55461
55526
|
init() {
|
|
55462
|
-
const { packageBase64, timeoutMs } = this.payload;
|
|
55527
|
+
const { packageBase64, timeoutMs, uiMode = 'silent' } = this.payload;
|
|
55463
55528
|
const packageBytes = decodeCanonicalBase64({
|
|
55464
55529
|
value: packageBase64,
|
|
55465
55530
|
parameterName: 'packageBase64',
|
|
55466
55531
|
maxBytes: PORTFOLIO_PACKAGE_MAX_BYTES,
|
|
55467
55532
|
});
|
|
55468
|
-
this.payload = Object.assign(Object.assign({}, this.payload), { path: PORTFOLIO_PENDING_PATH, offset: 0, data: packageBytes, chunkSize: PORTFOLIO_CHUNK_SIZE, overwrite: true, append: false, emitProgress:
|
|
55533
|
+
this.payload = Object.assign(Object.assign({}, this.payload), { path: PORTFOLIO_PENDING_PATH, offset: 0, data: packageBytes, chunkSize: PORTFOLIO_CHUNK_SIZE, overwrite: true, append: false, emitProgress: uiMode === 'progress', timeoutMs });
|
|
55469
55534
|
super.init();
|
|
55470
55535
|
this.unlockPolicy = 'none';
|
|
55471
|
-
this.protocolV2UiMode = 'none';
|
|
55536
|
+
this.protocolV2UiMode = uiMode === 'progress' ? 'auto' : 'none';
|
|
55472
55537
|
}
|
|
55473
55538
|
run() {
|
|
55474
55539
|
const _super = Object.create(null, {
|
|
@@ -55929,6 +55994,8 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
55929
55994
|
constructor() {
|
|
55930
55995
|
super(...arguments);
|
|
55931
55996
|
this.abortController = null;
|
|
55997
|
+
this.loadingCleanupInBackground = false;
|
|
55998
|
+
this.protocolV2ResumedSeedDomains = new Set();
|
|
55932
55999
|
}
|
|
55933
56000
|
getSupportedProtocols() {
|
|
55934
56001
|
return ['V1', 'V2'];
|
|
@@ -55964,7 +56031,20 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
55964
56031
|
_originalIndex: originalIndex,
|
|
55965
56032
|
};
|
|
55966
56033
|
}
|
|
55967
|
-
|
|
56034
|
+
hasProtocolV2WalletResume(deriveCardano) {
|
|
56035
|
+
if (deriveCardano) {
|
|
56036
|
+
return this.protocolV2ResumedSeedDomains.has('cardano');
|
|
56037
|
+
}
|
|
56038
|
+
return (this.protocolV2ResumedSeedDomains.has('standard') ||
|
|
56039
|
+
this.protocolV2ResumedSeedDomains.has('cardano'));
|
|
56040
|
+
}
|
|
56041
|
+
markProtocolV2WalletResumed(deriveCardano) {
|
|
56042
|
+
this.protocolV2ResumedSeedDomains.add('standard');
|
|
56043
|
+
if (deriveCardano) {
|
|
56044
|
+
this.protocolV2ResumedSeedDomains.add('cardano');
|
|
56045
|
+
}
|
|
56046
|
+
}
|
|
56047
|
+
callMethod(methodName, params, rootFingerprint, postMessage = this.postMessage) {
|
|
55968
56048
|
var _a, _b, _c;
|
|
55969
56049
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55970
56050
|
const method = findMethod({
|
|
@@ -55973,7 +56053,7 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
55973
56053
|
payload: Object.assign({ connectId: this.payload.connectId, deviceId: this.payload.deviceId, method: methodName }, params),
|
|
55974
56054
|
});
|
|
55975
56055
|
method.connector = this.connector;
|
|
55976
|
-
method.postMessage =
|
|
56056
|
+
method.postMessage = postMessage;
|
|
55977
56057
|
if (this.context) {
|
|
55978
56058
|
(_a = method.setContext) === null || _a === void 0 ? void 0 : _a.call(method, this.context);
|
|
55979
56059
|
}
|
|
@@ -56026,11 +56106,14 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
56026
56106
|
const useEmptyPassphrase = this.payload.useEmptyPassphrase === true;
|
|
56027
56107
|
const deriveCardano = method.name.startsWith('cardano') ? true : undefined;
|
|
56028
56108
|
const shouldResumeWalletSession = useEmptyPassphrase || !!this.payload.passphraseState;
|
|
56029
|
-
if (this.device.isProtocolV2() &&
|
|
56109
|
+
if (this.device.isProtocolV2() &&
|
|
56110
|
+
shouldResumeWalletSession &&
|
|
56111
|
+
!this.hasProtocolV2WalletResume(deriveCardano)) {
|
|
56030
56112
|
const passphraseStateSafety = yield this.device.checkPassphraseStateSafety(this.payload.passphraseState, useEmptyPassphrase, this.payload.skipPassphraseCheck, deriveCardano, (_d = this.protocolV2UnlockContext) === null || _d === void 0 ? void 0 : _d.preflightMainPinSelected);
|
|
56031
56113
|
if (!passphraseStateSafety) {
|
|
56032
56114
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
56033
56115
|
}
|
|
56116
|
+
this.markProtocolV2WalletResumed(deriveCardano);
|
|
56034
56117
|
}
|
|
56035
56118
|
}),
|
|
56036
56119
|
});
|
|
@@ -56066,27 +56149,63 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
56066
56149
|
return result;
|
|
56067
56150
|
});
|
|
56068
56151
|
}
|
|
56069
|
-
|
|
56152
|
+
stopAllNetworkLoading(canSend = true) {
|
|
56070
56153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56071
|
-
const
|
|
56072
|
-
|
|
56073
|
-
|
|
56074
|
-
|
|
56075
|
-
|
|
56076
|
-
|
|
56077
|
-
|
|
56078
|
-
|
|
56154
|
+
const commands = this.loadingCommands;
|
|
56155
|
+
this.loadingCommands = undefined;
|
|
56156
|
+
if (!canSend || !commands || commands.disposed || commands !== this.device.commands)
|
|
56157
|
+
return;
|
|
56158
|
+
try {
|
|
56159
|
+
yield commands.typedCall('DeviceAnimationControl', 'Success', {
|
|
56160
|
+
action: hdTransport.Messages.DeviceAnimationAction.AnimationAction_Stop,
|
|
56161
|
+
});
|
|
56079
56162
|
}
|
|
56080
|
-
|
|
56081
|
-
|
|
56163
|
+
catch (_a) {
|
|
56164
|
+
}
|
|
56165
|
+
});
|
|
56166
|
+
}
|
|
56167
|
+
run() {
|
|
56168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56169
|
+
this.loadingCleanupInBackground = false;
|
|
56170
|
+
try {
|
|
56171
|
+
if (this.device.isProtocolV2() &&
|
|
56172
|
+
(this.device.getCurrentDeviceType() === hdShared.EDeviceType.Pro2 ||
|
|
56173
|
+
this.device.getCurrentDeviceType() === hdShared.EDeviceType.Neo)) {
|
|
56174
|
+
const protocolInfo = yield this.device.ensureProtocolV2RuntimeContext();
|
|
56175
|
+
if (supportsProtocolV2Message(protocolInfo, 60461)) {
|
|
56176
|
+
const { commands } = this.device;
|
|
56177
|
+
yield commands.typedCall('DeviceAnimationControl', 'Success', {
|
|
56178
|
+
action: hdTransport.Messages.DeviceAnimationAction.AnimationAction_Start,
|
|
56179
|
+
});
|
|
56180
|
+
this.loadingCommands = commands;
|
|
56181
|
+
}
|
|
56182
|
+
}
|
|
56183
|
+
const res = yield this.device.commands.typedCall('GetPublicKey', 'PublicKey', {
|
|
56184
|
+
address_n: [toHardened(44), toHardened(1), toHardened(0)],
|
|
56185
|
+
coin_name: 'Testnet',
|
|
56186
|
+
script_type: 'SPENDADDRESS',
|
|
56187
|
+
show_display: false,
|
|
56188
|
+
});
|
|
56189
|
+
if (!this.device.isProtocolV2()) {
|
|
56190
|
+
this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
|
|
56191
|
+
}
|
|
56192
|
+
if (res.message.root_fingerprint == null) {
|
|
56193
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter);
|
|
56194
|
+
}
|
|
56195
|
+
this.abortController = new AbortController();
|
|
56196
|
+
return yield this.getAllNetworkAddress(res.message.root_fingerprint);
|
|
56082
56197
|
}
|
|
56083
|
-
|
|
56084
|
-
|
|
56198
|
+
catch (e) {
|
|
56199
|
+
yield this.stopAllNetworkLoading(false);
|
|
56085
56200
|
if (e instanceof hdShared.HardwareError && e.errorCode === hdShared.HardwareErrorCode.RepeatUnlocking) {
|
|
56086
56201
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RepeatUnlocking, e.message);
|
|
56087
56202
|
}
|
|
56088
56203
|
throw e;
|
|
56089
|
-
}
|
|
56204
|
+
}
|
|
56205
|
+
finally {
|
|
56206
|
+
if (!this.loadingCleanupInBackground)
|
|
56207
|
+
yield this.stopAllNetworkLoading();
|
|
56208
|
+
}
|
|
56090
56209
|
});
|
|
56091
56210
|
}
|
|
56092
56211
|
}
|
|
@@ -56147,57 +56266,83 @@ function handleSkippableHardwareError(e, device, method) {
|
|
|
56147
56266
|
}
|
|
56148
56267
|
|
|
56149
56268
|
class AllNetworkGetAddress extends AllNetworkGetAddressBase {
|
|
56269
|
+
checkAborted() {
|
|
56270
|
+
var _a;
|
|
56271
|
+
if ((_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
|
|
56272
|
+
throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
|
|
56273
|
+
}
|
|
56274
|
+
}
|
|
56275
|
+
callAddressGroup(methodName, params, rootFingerprint) {
|
|
56276
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56277
|
+
const methodCallParams = { bundle: params.map(param => (Object.assign({}, param.params))) };
|
|
56278
|
+
if (!this.device.isProtocolV2() || params.length === 1) {
|
|
56279
|
+
return this.callMethod(methodName, methodCallParams, rootFingerprint);
|
|
56280
|
+
}
|
|
56281
|
+
const postedAddressCounts = new Map();
|
|
56282
|
+
let runningIndividually = false;
|
|
56283
|
+
const postMessage = message => {
|
|
56284
|
+
var _a;
|
|
56285
|
+
if (message.type === UI_REQUEST.PREVIOUS_ADDRESS_RESULT) {
|
|
56286
|
+
const { path, address } = message.payload.data;
|
|
56287
|
+
const key = JSON.stringify([path, address]);
|
|
56288
|
+
const count = (_a = postedAddressCounts.get(key)) !== null && _a !== void 0 ? _a : 0;
|
|
56289
|
+
if (runningIndividually && count > 0) {
|
|
56290
|
+
postedAddressCounts.set(key, count - 1);
|
|
56291
|
+
return;
|
|
56292
|
+
}
|
|
56293
|
+
if (!runningIndividually)
|
|
56294
|
+
postedAddressCounts.set(key, count + 1);
|
|
56295
|
+
}
|
|
56296
|
+
this.postMessage(message);
|
|
56297
|
+
};
|
|
56298
|
+
if (params.every(param => param._originRequestParams.showOnOneKey === false)) {
|
|
56299
|
+
const response = yield this.callMethod(methodName, methodCallParams, rootFingerprint, postMessage);
|
|
56300
|
+
if (response.some(item => item.success))
|
|
56301
|
+
return response;
|
|
56302
|
+
}
|
|
56303
|
+
runningIndividually = true;
|
|
56304
|
+
const responses = [];
|
|
56305
|
+
for (const param of params) {
|
|
56306
|
+
this.checkAborted();
|
|
56307
|
+
const response = yield this.callMethod(methodName, { bundle: [Object.assign({}, param.params)] }, rootFingerprint, postMessage);
|
|
56308
|
+
responses.push(...response);
|
|
56309
|
+
}
|
|
56310
|
+
return responses;
|
|
56311
|
+
});
|
|
56312
|
+
}
|
|
56150
56313
|
getAllNetworkAddress(rootFingerprint) {
|
|
56151
|
-
var _a, _b, _c, _d;
|
|
56152
56314
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56153
56315
|
const responses = [];
|
|
56154
|
-
const resultMap = {};
|
|
56155
56316
|
const { bundle } = this.payload;
|
|
56156
56317
|
const methodParams = bundle.map((param, index) => this.generateMethodName({
|
|
56157
56318
|
network: param.network,
|
|
56158
56319
|
payload: param,
|
|
56159
56320
|
originalIndex: index,
|
|
56160
56321
|
}));
|
|
56161
|
-
const
|
|
56322
|
+
const methodGroups = methodParams.reduce((groups, param) => {
|
|
56162
56323
|
var _a;
|
|
56163
56324
|
const group = (_a = groups.get(param.methodName)) !== null && _a !== void 0 ? _a : [];
|
|
56164
56325
|
group.push(param);
|
|
56165
56326
|
groups.set(param.methodName, group);
|
|
56166
56327
|
return groups;
|
|
56167
56328
|
}, new Map());
|
|
56168
|
-
|
|
56169
|
-
|
|
56170
|
-
|
|
56171
|
-
|
|
56172
|
-
|
|
56173
|
-
|
|
56174
|
-
|
|
56175
|
-
|
|
56176
|
-
bundle: params.map(param => (Object.assign({}, param.params))),
|
|
56177
|
-
};
|
|
56178
|
-
if ((_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
|
|
56179
|
-
throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
|
|
56180
|
-
}
|
|
56181
|
-
const response = yield this.callMethod(methodName, methodParams, rootFingerprint);
|
|
56182
|
-
if ((_b = this.abortController) === null || _b === void 0 ? void 0 : _b.signal.aborted) {
|
|
56183
|
-
throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
|
|
56184
|
-
}
|
|
56185
|
-
for (let i = 0; i < params.length; i++) {
|
|
56186
|
-
const { _originRequestParams, _originalIndex } = params[i];
|
|
56187
|
-
const responseKey = `${_originalIndex}`;
|
|
56188
|
-
resultMap[responseKey] = Object.assign(Object.assign({}, _originRequestParams), response[i]);
|
|
56329
|
+
let processed = 0;
|
|
56330
|
+
for (const [methodName, params] of methodGroups.entries()) {
|
|
56331
|
+
this.checkAborted();
|
|
56332
|
+
const response = yield this.callAddressGroup(methodName, params, rootFingerprint);
|
|
56333
|
+
this.checkAborted();
|
|
56334
|
+
for (let index = 0; index < params.length; index++) {
|
|
56335
|
+
const { _originRequestParams, _originalIndex } = params[index];
|
|
56336
|
+
responses[_originalIndex] = Object.assign(Object.assign({}, _originRequestParams), response[index]);
|
|
56189
56337
|
}
|
|
56190
|
-
|
|
56191
|
-
|
|
56338
|
+
processed += params.length;
|
|
56339
|
+
if (bundle.length > 1) {
|
|
56340
|
+
const progress = Math.round((processed / bundle.length) * 100);
|
|
56192
56341
|
this.postMessage(createUiMessage(UI_REQUEST.DEVICE_PROGRESS, { progress }));
|
|
56193
56342
|
}
|
|
56194
|
-
i++;
|
|
56195
|
-
}
|
|
56196
|
-
for (let i = 0; i < bundle.length; i++) {
|
|
56197
|
-
responses.push(resultMap[i]);
|
|
56198
56343
|
}
|
|
56199
56344
|
this.abortController = null;
|
|
56200
|
-
return
|
|
56345
|
+
return responses;
|
|
56201
56346
|
});
|
|
56202
56347
|
}
|
|
56203
56348
|
}
|
|
@@ -56213,6 +56358,7 @@ class AllNetworkGetAddressByLoop extends AllNetworkGetAddressBase {
|
|
|
56213
56358
|
throw new Error('callbackIdFinish is required');
|
|
56214
56359
|
}
|
|
56215
56360
|
const bundle = this.payload.bundle || [this.payload];
|
|
56361
|
+
this.loadingCleanupInBackground = true;
|
|
56216
56362
|
const callbackPromise = this.processCallbacksInBackground(bundle, rootFingerprint, callbackId, callbackIdFinish);
|
|
56217
56363
|
this.device.pendingCallbackPromise = hdShared.createDeferred(callbackPromise);
|
|
56218
56364
|
if (this.context && this.payload.connectId) {
|
|
@@ -56253,6 +56399,7 @@ class AllNetworkGetAddressByLoop extends AllNetworkGetAddressBase {
|
|
|
56253
56399
|
});
|
|
56254
56400
|
}
|
|
56255
56401
|
catch (error) {
|
|
56402
|
+
yield this.stopAllNetworkLoading(false);
|
|
56256
56403
|
let errorCode = error.errorCode || error.code;
|
|
56257
56404
|
let errorMessage = error.message;
|
|
56258
56405
|
if (error instanceof hdShared.HardwareError) {
|
|
@@ -56280,6 +56427,7 @@ class AllNetworkGetAddressByLoop extends AllNetworkGetAddressBase {
|
|
|
56280
56427
|
});
|
|
56281
56428
|
}
|
|
56282
56429
|
finally {
|
|
56430
|
+
yield this.stopAllNetworkLoading();
|
|
56283
56431
|
(_c = this.context) === null || _c === void 0 ? void 0 : _c.cancelCallbackTasks(this.payload.connectId);
|
|
56284
56432
|
this.abortController = null;
|
|
56285
56433
|
}
|
|
@@ -59514,6 +59662,23 @@ class SolSignTransaction extends BaseMethod {
|
|
|
59514
59662
|
}
|
|
59515
59663
|
}
|
|
59516
59664
|
|
|
59665
|
+
const SOLANA_PUBLIC_KEY_LENGTH = 32;
|
|
59666
|
+
const SOLANA_APPLICATION_DOMAIN_LENGTH = 32;
|
|
59667
|
+
const normalizeRequiredSigners = (requiredSigners = []) => {
|
|
59668
|
+
const normalized = requiredSigners.map((signer, index) => {
|
|
59669
|
+
if (typeof signer !== 'string' ||
|
|
59670
|
+
!isHexString(addHexPrefix(signer), SOLANA_PUBLIC_KEY_LENGTH)) {
|
|
59671
|
+
throw invalidParameter(`Parameter [requiredSigners][${index}] must be a ${SOLANA_PUBLIC_KEY_LENGTH}-byte hex public key.`);
|
|
59672
|
+
}
|
|
59673
|
+
return stripHexPrefix(signer).toLowerCase();
|
|
59674
|
+
});
|
|
59675
|
+
for (let index = 1; index < normalized.length; index += 1) {
|
|
59676
|
+
if (normalized[index - 1] >= normalized[index]) {
|
|
59677
|
+
throw invalidParameter('Parameter [requiredSigners] must be strictly sorted and unique.');
|
|
59678
|
+
}
|
|
59679
|
+
}
|
|
59680
|
+
return normalized;
|
|
59681
|
+
};
|
|
59517
59682
|
class SolSignOffchainMessage extends BaseMethod {
|
|
59518
59683
|
getSupportedProtocols() {
|
|
59519
59684
|
return ['V1', 'V2'];
|
|
@@ -59528,15 +59693,21 @@ class SolSignOffchainMessage extends BaseMethod {
|
|
|
59528
59693
|
{ name: 'messageVersion', type: 'number', required: false },
|
|
59529
59694
|
{ name: 'messageFormat', type: 'number', required: false },
|
|
59530
59695
|
{ name: 'applicationDomainHex', type: 'hexString', required: false },
|
|
59696
|
+
{ name: 'requiredSigners', type: 'array', required: false, allowEmpty: true },
|
|
59531
59697
|
]);
|
|
59532
|
-
const { path, messageHex, messageVersion, messageFormat, applicationDomainHex } = this.payload;
|
|
59698
|
+
const { path, messageHex, messageVersion, messageFormat, applicationDomainHex, requiredSigners, } = this.payload;
|
|
59533
59699
|
const addressN = validatePath(path, 3);
|
|
59700
|
+
if (applicationDomainHex !== undefined &&
|
|
59701
|
+
!isHexString(addHexPrefix(applicationDomainHex), SOLANA_APPLICATION_DOMAIN_LENGTH)) {
|
|
59702
|
+
throw invalidParameter('Parameter [applicationDomainHex] must be 32 bytes.');
|
|
59703
|
+
}
|
|
59534
59704
|
this.params = {
|
|
59535
59705
|
address_n: addressN,
|
|
59536
59706
|
message: stripHexPrefix(messageHex),
|
|
59537
59707
|
message_version: messageVersion !== null && messageVersion !== void 0 ? messageVersion : undefined,
|
|
59538
59708
|
message_format: messageFormat !== null && messageFormat !== void 0 ? messageFormat : undefined,
|
|
59539
|
-
application_domain: applicationDomainHex
|
|
59709
|
+
application_domain: applicationDomainHex ? stripHexPrefix(applicationDomainHex) : undefined,
|
|
59710
|
+
required_signers: normalizeRequiredSigners(requiredSigners),
|
|
59540
59711
|
};
|
|
59541
59712
|
}
|
|
59542
59713
|
getVersionRange() {
|
|
@@ -65582,6 +65753,29 @@ class RequestQueue {
|
|
|
65582
65753
|
getTask(requestId) {
|
|
65583
65754
|
return this.requestQueue.get(requestId);
|
|
65584
65755
|
}
|
|
65756
|
+
waitForTask(task, pending) {
|
|
65757
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65758
|
+
const signal = task.method.abortSignal;
|
|
65759
|
+
const cancellationError = () => hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
|
|
65760
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted)
|
|
65761
|
+
throw cancellationError();
|
|
65762
|
+
let onAbort;
|
|
65763
|
+
try {
|
|
65764
|
+
const cancelled = new Promise((_, reject) => {
|
|
65765
|
+
onAbort = () => reject(cancellationError());
|
|
65766
|
+
signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', onAbort, { once: true });
|
|
65767
|
+
});
|
|
65768
|
+
const result = yield Promise.race([pending(), cancelled]);
|
|
65769
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted)
|
|
65770
|
+
throw cancellationError();
|
|
65771
|
+
return result;
|
|
65772
|
+
}
|
|
65773
|
+
finally {
|
|
65774
|
+
if (onAbort)
|
|
65775
|
+
signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', onAbort);
|
|
65776
|
+
}
|
|
65777
|
+
});
|
|
65778
|
+
}
|
|
65585
65779
|
getAbortController(requestId) {
|
|
65586
65780
|
var _a;
|
|
65587
65781
|
return (_a = this.requestQueue.get(requestId)) === null || _a === void 0 ? void 0 : _a.abortController;
|
|
@@ -65781,7 +65975,8 @@ const createUiProgressMessageFilter = (intervalMs = DEFAULT_UI_PROGRESS_INTERVAL
|
|
|
65781
65975
|
|
|
65782
65976
|
const Log = getLogger(exports.LoggerNames.Core);
|
|
65783
65977
|
const PRE_INITIALIZE_TTL_MS = 60 * 1000;
|
|
65784
|
-
const PRE_PENDING_CALL_TIMEOUT_MS =
|
|
65978
|
+
const PRE_PENDING_CALL_TIMEOUT_MS = 5 * 1000;
|
|
65979
|
+
const PRO2_USB_SIGNING_COOLDOWN_MS = 1000;
|
|
65785
65980
|
const preWarmInflight = new Map();
|
|
65786
65981
|
const preWarmDoneAt = new Map();
|
|
65787
65982
|
function resolveDeriveCardano(method) {
|
|
@@ -65860,6 +66055,7 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
|
|
|
65860
66055
|
}
|
|
65861
66056
|
};
|
|
65862
66057
|
(_a = method.setContext) === null || _a === void 0 ? void 0 : _a.call(method, context);
|
|
66058
|
+
method.context = context;
|
|
65863
66059
|
method.requestContext = createRequestContext(method.responseID, method.name, {
|
|
65864
66060
|
sdkInstanceId: context.sdkInstanceId,
|
|
65865
66061
|
connectId: method.connectId,
|
|
@@ -65877,7 +66073,11 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
|
|
|
65877
66073
|
if (!method.useDevice) {
|
|
65878
66074
|
updateMethodRequestContext(method, { status: 'running' });
|
|
65879
66075
|
try {
|
|
65880
|
-
const
|
|
66076
|
+
const env = DataManager.getSettings('env');
|
|
66077
|
+
const response = method.name === 'searchDevices' &&
|
|
66078
|
+
(DataManager.isBrowserWebUsb(env) || DataManager.isDesktopWebUsb(env))
|
|
66079
|
+
? yield context.methodSynchronize(() => method.run(), 'webusb-discovery')
|
|
66080
|
+
: yield method.run();
|
|
65881
66081
|
completeMethodRequestContext(method);
|
|
65882
66082
|
return createResponseMessage(method.responseID, true, response);
|
|
65883
66083
|
}
|
|
@@ -65949,6 +66149,7 @@ const waitForPendingPromise = (connectId, getPrePendingCallPromise, removePrePen
|
|
|
65949
66149
|
Log.debug('pre pending call promise before call method, wait for it');
|
|
65950
66150
|
let timer;
|
|
65951
66151
|
let timedOut = false;
|
|
66152
|
+
let completed = false;
|
|
65952
66153
|
try {
|
|
65953
66154
|
yield Promise.race([
|
|
65954
66155
|
pendingPromise,
|
|
@@ -65959,13 +66160,13 @@ const waitForPendingPromise = (connectId, getPrePendingCallPromise, removePrePen
|
|
|
65959
66160
|
}, PRE_PENDING_CALL_TIMEOUT_MS);
|
|
65960
66161
|
}),
|
|
65961
66162
|
]);
|
|
65962
|
-
|
|
65963
|
-
catch (error) {
|
|
66163
|
+
completed = !timedOut;
|
|
65964
66164
|
}
|
|
65965
66165
|
finally {
|
|
65966
66166
|
if (timer)
|
|
65967
66167
|
clearTimeout(timer);
|
|
65968
|
-
|
|
66168
|
+
if (timedOut || completed)
|
|
66169
|
+
removePrePendingCallPromise === null || removePrePendingCallPromise === void 0 ? void 0 : removePrePendingCallPromise(connectId, pendingPromise);
|
|
65969
66170
|
}
|
|
65970
66171
|
if (timedOut) {
|
|
65971
66172
|
Log.warn('pre pending call promise timed out before call method', { connectId });
|
|
@@ -65973,8 +66174,19 @@ const waitForPendingPromise = (connectId, getPrePendingCallPromise, removePrePen
|
|
|
65973
66174
|
Log.debug('pre pending call promise before call method done');
|
|
65974
66175
|
}
|
|
65975
66176
|
});
|
|
66177
|
+
function getPostCallPendingPromise(method, device) {
|
|
66178
|
+
const cleanupPromise = device.waitForRunCleanup();
|
|
66179
|
+
const env = DataManager.getSettings('env');
|
|
66180
|
+
const deviceType = device.getCurrentDeviceType();
|
|
66181
|
+
const requiresSigningCooldown = method.name.includes('Sign') &&
|
|
66182
|
+
(deviceType === hdShared.EDeviceType.Pro2 || deviceType === hdShared.EDeviceType.Neo) &&
|
|
66183
|
+
(DataManager.isBrowserWebUsb(env) || DataManager.isDesktopWebUsb(env) || env === 'node-usb');
|
|
66184
|
+
return requiresSigningCooldown
|
|
66185
|
+
? cleanupPromise.then(() => wait(PRO2_USB_SIGNING_COOLDOWN_MS)).then(() => undefined)
|
|
66186
|
+
: cleanupPromise;
|
|
66187
|
+
}
|
|
65976
66188
|
const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65977
|
-
var _d, _e, _f, _g, _h, _j
|
|
66189
|
+
var _d, _e, _f, _g, _h, _j;
|
|
65978
66190
|
let messageResponse;
|
|
65979
66191
|
const { requestQueue, getPrePendingCallPromise, removePrePendingCallPromise } = context;
|
|
65980
66192
|
updateMethodRequestContext(method, { status: 'running' });
|
|
@@ -65988,21 +66200,42 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65988
66200
|
Log.debug('passphrase state change, clear device cache');
|
|
65989
66201
|
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
65990
66202
|
}
|
|
65991
|
-
if (method.connectId) {
|
|
65992
|
-
yield context.waitForCallbackTasks(method.connectId);
|
|
65993
|
-
}
|
|
65994
|
-
yield waitForPendingPromise((_d = method.connectId) !== null && _d !== void 0 ? _d : '', getPrePendingCallPromise, removePrePendingCallPromise);
|
|
65995
66203
|
const task = requestQueue.createTask(method);
|
|
65996
66204
|
let preWarmCallbackTask;
|
|
65997
|
-
if (method.isPreWarmSignal && method.connectId) {
|
|
65998
|
-
preWarmCallbackTask = hdShared.createDeferred();
|
|
65999
|
-
context.registerCallbackTask(method.connectId, preWarmCallbackTask);
|
|
66000
|
-
}
|
|
66001
66205
|
let device;
|
|
66002
66206
|
try {
|
|
66003
|
-
const connectId = (
|
|
66207
|
+
const connectId = (_d = method.connectId) !== null && _d !== void 0 ? _d : '';
|
|
66208
|
+
if (connectId) {
|
|
66209
|
+
yield requestQueue.waitForTask(task, () => context.waitForCallbackTasks(connectId));
|
|
66210
|
+
}
|
|
66211
|
+
yield requestQueue.waitForTask(task, () => {
|
|
66212
|
+
var _a;
|
|
66213
|
+
return waitForPendingPromise((_a = method.connectId) !== null && _a !== void 0 ? _a : '', getPrePendingCallPromise, removePrePendingCallPromise);
|
|
66214
|
+
});
|
|
66215
|
+
if (method.isPreWarmSignal && method.connectId) {
|
|
66216
|
+
preWarmCallbackTask = hdShared.createDeferred();
|
|
66217
|
+
context.registerCallbackTask(method.connectId, preWarmCallbackTask);
|
|
66218
|
+
}
|
|
66004
66219
|
const pollingId = pollingManager.start(connectId);
|
|
66005
|
-
|
|
66220
|
+
const env = DataManager.getSettings('env');
|
|
66221
|
+
const connect = () => ensureConnected(context, method, connectId, pollingId, method.abortSignal);
|
|
66222
|
+
if (DataManager.isBrowserWebUsb(env) || DataManager.isDesktopWebUsb(env)) {
|
|
66223
|
+
const connectPromise = context.methodSynchronize(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
66224
|
+
var _k;
|
|
66225
|
+
if ((_k = method.abortSignal) === null || _k === void 0 ? void 0 : _k.aborted) {
|
|
66226
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
|
|
66227
|
+
}
|
|
66228
|
+
return connect();
|
|
66229
|
+
}), 'webusb-discovery');
|
|
66230
|
+
connectPromise.catch(() => undefined);
|
|
66231
|
+
device = yield requestQueue.waitForTask(task, () => connectPromise);
|
|
66232
|
+
}
|
|
66233
|
+
else {
|
|
66234
|
+
device = yield connect();
|
|
66235
|
+
}
|
|
66236
|
+
if ((_e = method.abortSignal) === null || _e === void 0 ? void 0 : _e.aborted) {
|
|
66237
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
|
|
66238
|
+
}
|
|
66006
66239
|
}
|
|
66007
66240
|
catch (e) {
|
|
66008
66241
|
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
@@ -66017,7 +66250,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
66017
66250
|
requestQueue.releaseTask(method.responseID);
|
|
66018
66251
|
return createResponseMessage(method.responseID, false, { error: e });
|
|
66019
66252
|
}
|
|
66020
|
-
if ((
|
|
66253
|
+
if ((_f = method.payload) === null || _f === void 0 ? void 0 : _f.onlyConnectBleDevice) {
|
|
66021
66254
|
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
66022
66255
|
Log.debug('Call API - only connect ble device: ', device === null || device === void 0 ? void 0 : device.mainId);
|
|
66023
66256
|
completeMethodRequestContext(method);
|
|
@@ -66025,11 +66258,11 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
66025
66258
|
return createResponseMessage(method.responseID, true, null);
|
|
66026
66259
|
}
|
|
66027
66260
|
Log.debug('Call API - setDevice: ', device.mainId);
|
|
66028
|
-
(
|
|
66261
|
+
(_g = method.setDevice) === null || _g === void 0 ? void 0 : _g.call(method, device);
|
|
66029
66262
|
method.context = context;
|
|
66030
66263
|
updateMethodRequestContext(method, {
|
|
66031
66264
|
deviceInstanceId: device.instanceId,
|
|
66032
|
-
commandsInstanceId: (
|
|
66265
|
+
commandsInstanceId: (_h = device.commands) === null || _h === void 0 ? void 0 : _h.instanceId,
|
|
66033
66266
|
});
|
|
66034
66267
|
const activeRequests = getActiveRequestsByDeviceInstance(device.instanceId);
|
|
66035
66268
|
if (activeRequests.length > 0) {
|
|
@@ -66055,10 +66288,14 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
66055
66288
|
device.beginProtocolV2UiInteraction();
|
|
66056
66289
|
device.on(DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE, onSelectDeviceForSwitchFirmwareWebDeviceHandler);
|
|
66057
66290
|
try {
|
|
66058
|
-
|
|
66059
|
-
|
|
66291
|
+
const { connectId } = method;
|
|
66292
|
+
if (connectId) {
|
|
66293
|
+
yield requestQueue.waitForTask(task, () => context.waitForCallbackTasks(connectId, preWarmCallbackTask));
|
|
66060
66294
|
}
|
|
66061
|
-
yield
|
|
66295
|
+
yield requestQueue.waitForTask(task, () => {
|
|
66296
|
+
var _a;
|
|
66297
|
+
return waitForPendingPromise((_a = method.connectId) !== null && _a !== void 0 ? _a : '', getPrePendingCallPromise, removePrePendingCallPromise);
|
|
66298
|
+
});
|
|
66062
66299
|
const inner = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
66063
66300
|
var _l, _m;
|
|
66064
66301
|
method.assertProtocolSupported(device.getProtocol(), device.getCurrentFirmwareType());
|
|
@@ -66185,6 +66422,9 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
66185
66422
|
}),
|
|
66186
66423
|
});
|
|
66187
66424
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
66425
|
+
if (method.connectId) {
|
|
66426
|
+
context.setPrePendingCallPromise(method.connectId, getPostCallPendingPromise(method, device));
|
|
66427
|
+
}
|
|
66188
66428
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
66189
66429
|
completeMethodRequestContext(method);
|
|
66190
66430
|
}
|
|
@@ -66195,6 +66435,9 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
66195
66435
|
}
|
|
66196
66436
|
Log.debug(`Call API - Inner Method Run Error`, error);
|
|
66197
66437
|
messageResponse = createResponseMessage(method.responseID, false, { error });
|
|
66438
|
+
if (method.connectId) {
|
|
66439
|
+
context.setPrePendingCallPromise(method.connectId, getPostCallPendingPromise(method, device));
|
|
66440
|
+
}
|
|
66198
66441
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
66199
66442
|
completeMethodRequestContext(method, error);
|
|
66200
66443
|
if (error instanceof hdShared.HardwareError &&
|
|
@@ -66213,6 +66456,9 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
66213
66456
|
});
|
|
66214
66457
|
Log.debug('Call API - Device Run: ', device.mainId);
|
|
66215
66458
|
const runOptions = Object.assign({ keepSession: method.payload.keepSession, skipInitialize: canSkipInitialize(method, device) }, parseInitOptions(method));
|
|
66459
|
+
if ((_j = method.abortSignal) === null || _j === void 0 ? void 0 : _j.aborted) {
|
|
66460
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
|
|
66461
|
+
}
|
|
66216
66462
|
const deviceRun = () => device.run(inner, runOptions);
|
|
66217
66463
|
task.callPromise = hdShared.createDeferred(deviceRun);
|
|
66218
66464
|
try {
|
|
@@ -66231,6 +66477,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
66231
66477
|
requestQueue.rejectRequest(method.responseID, hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodError, error.message));
|
|
66232
66478
|
Log.debug('Call API - Run Error: ', error);
|
|
66233
66479
|
completeMethodRequestContext(method, error);
|
|
66480
|
+
return messageResponse;
|
|
66234
66481
|
}
|
|
66235
66482
|
finally {
|
|
66236
66483
|
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
@@ -66380,11 +66627,15 @@ function isRetryableBleProtocolV2ProbeError(method, error) {
|
|
|
66380
66627
|
message.includes('did not respond to expected protocol'));
|
|
66381
66628
|
}
|
|
66382
66629
|
function isRetryableBleConnectionError(method, error) {
|
|
66383
|
-
var _a;
|
|
66630
|
+
var _a, _b;
|
|
66384
66631
|
if ((_a = method.device) === null || _a === void 0 ? void 0 : _a.wasInterruptedByUser()) {
|
|
66385
66632
|
return false;
|
|
66386
66633
|
}
|
|
66387
66634
|
const typedError = error;
|
|
66635
|
+
if ((typedError === null || typedError === void 0 ? void 0 : typedError.errorCode) === hdShared.HardwareErrorCode.BleTimeoutError &&
|
|
66636
|
+
((_b = typedError.params) === null || _b === void 0 ? void 0 : _b.acquireDeadlineExceeded) === true) {
|
|
66637
|
+
return false;
|
|
66638
|
+
}
|
|
66388
66639
|
return ((typedError === null || typedError === void 0 ? void 0 : typedError.errorCode) === hdShared.HardwareErrorCode.BleTimeoutError ||
|
|
66389
66640
|
(typedError === null || typedError === void 0 ? void 0 : typedError.errorCode) === hdShared.HardwareErrorCode.BleConnectedError ||
|
|
66390
66641
|
isRetryableBleProtocolV2ProbeError(method, error) ||
|
|
@@ -66397,10 +66648,11 @@ function isMissingDetectedProtocolV2Error(method, error) {
|
|
|
66397
66648
|
typeof typedError.message === 'string' &&
|
|
66398
66649
|
typedError.message.includes('Device protocol has not been detected'));
|
|
66399
66650
|
}
|
|
66400
|
-
function
|
|
66401
|
-
return (
|
|
66402
|
-
|
|
66403
|
-
|
|
66651
|
+
function isTerminalBleStaleBondError(error) {
|
|
66652
|
+
return hdShared.isBleStaleBondHardwareError(error);
|
|
66653
|
+
}
|
|
66654
|
+
function isDeviceIdentityMismatchError(error) {
|
|
66655
|
+
return ((error === null || error === void 0 ? void 0 : error.errorCode) === hdShared.HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
66404
66656
|
}
|
|
66405
66657
|
const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
|
|
66406
66658
|
function raceBleAcquire(acquirePromise, abortSignal) {
|
|
@@ -66415,7 +66667,7 @@ function raceBleAcquire(acquirePromise, abortSignal) {
|
|
|
66415
66667
|
fn();
|
|
66416
66668
|
};
|
|
66417
66669
|
const onAbort = () => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled)));
|
|
66418
|
-
const deadline = setTimeout(() => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, `BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline
|
|
66670
|
+
const deadline = setTimeout(() => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, `BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`, { acquireDeadlineExceeded: true }))), BLE_ACQUIRE_DEADLINE_MS);
|
|
66419
66671
|
acquirePromise.then(value => settle(() => resolve(value)), error => settle(() => reject(error)));
|
|
66420
66672
|
if (abortSignal) {
|
|
66421
66673
|
if (abortSignal.aborted) {
|
|
@@ -66430,7 +66682,7 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
|
66430
66682
|
var _a;
|
|
66431
66683
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66432
66684
|
try {
|
|
66433
|
-
if (device.wasInterruptedByUser()) {
|
|
66685
|
+
if ((abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) || device.wasInterruptedByUser()) {
|
|
66434
66686
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser);
|
|
66435
66687
|
}
|
|
66436
66688
|
if (method.payload.forceProtocolDetection && device.hasDeviceAcquire()) {
|
|
@@ -66486,6 +66738,9 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
|
66486
66738
|
}
|
|
66487
66739
|
}
|
|
66488
66740
|
catch (err) {
|
|
66741
|
+
if ((abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) || device.wasInterruptedByUser()) {
|
|
66742
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser);
|
|
66743
|
+
}
|
|
66489
66744
|
const requiresColdReconnect = isMissingDetectedProtocolV2Error(method, err);
|
|
66490
66745
|
if ((hdShared.ERROR_CODES_REQUIRE_DISCONNECT.includes(err.errorCode) || requiresColdReconnect) &&
|
|
66491
66746
|
device.mainId &&
|
|
@@ -66518,6 +66773,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66518
66773
|
const POLL_INTERVAL_TIME = (method.payload && method.payload.pollIntervalTime) || 1000;
|
|
66519
66774
|
const TIME_OUT = (method.payload && method.payload.timeout) || 10000;
|
|
66520
66775
|
let timer = null;
|
|
66776
|
+
let lastInitializeError;
|
|
66521
66777
|
Log.debug(`EnsureConnected function start, MAX_RETRY_COUNT=${MAX_RETRY_COUNT}, POLL_INTERVAL_TIME=${POLL_INTERVAL_TIME} `);
|
|
66522
66778
|
const poll = (time = POLL_INTERVAL_TIME) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66523
66779
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -66550,8 +66806,10 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66550
66806
|
Log.debug('EnsureConnected function try count: ', tryCount, ' poll interval time: ', time);
|
|
66551
66807
|
try {
|
|
66552
66808
|
yield initDeviceList(method);
|
|
66809
|
+
lastInitializeError = undefined;
|
|
66553
66810
|
}
|
|
66554
66811
|
catch (error) {
|
|
66812
|
+
lastInitializeError = error;
|
|
66555
66813
|
Log.debug('device list error: ', error);
|
|
66556
66814
|
if ([
|
|
66557
66815
|
hdShared.HardwareErrorCode.BridgeNotInstalled,
|
|
@@ -66564,6 +66822,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66564
66822
|
}
|
|
66565
66823
|
if (error.errorCode === hdShared.HardwareErrorCode.TransportNotConfigured) {
|
|
66566
66824
|
yield TransportManager.configure();
|
|
66825
|
+
lastInitializeError = undefined;
|
|
66567
66826
|
}
|
|
66568
66827
|
}
|
|
66569
66828
|
if (abort()) {
|
|
@@ -66622,6 +66881,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66622
66881
|
hdShared.HardwareErrorCode.BleDeviceBondedCanceled,
|
|
66623
66882
|
hdShared.HardwareErrorCode.BleCharacteristicNotifyError,
|
|
66624
66883
|
hdShared.HardwareErrorCode.BleTimeoutError,
|
|
66884
|
+
hdShared.HardwareErrorCode.PollingTimeout,
|
|
66625
66885
|
hdShared.HardwareErrorCode.BleWriteCharacteristicError,
|
|
66626
66886
|
hdShared.HardwareErrorCode.BleAlreadyConnected,
|
|
66627
66887
|
hdShared.HardwareErrorCode.FirmwareUpdateLimitOneDevice,
|
|
@@ -66632,7 +66892,10 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66632
66892
|
hdShared.HardwareErrorCode.DeviceInterruptedFromUser,
|
|
66633
66893
|
hdShared.HardwareErrorCode.CallQueueActionCancelled,
|
|
66634
66894
|
].includes(error.errorCode) ||
|
|
66635
|
-
|
|
66895
|
+
(env === 'react-native' &&
|
|
66896
|
+
[hdShared.HardwareErrorCode.BleDeviceDisconnected, hdShared.HardwareErrorCode.PollingTimeout].includes(error.errorCode)) ||
|
|
66897
|
+
isTerminalBleStaleBondError(error) ||
|
|
66898
|
+
isDeviceIdentityMismatchError(error)) {
|
|
66636
66899
|
reject(error);
|
|
66637
66900
|
return;
|
|
66638
66901
|
}
|
|
@@ -66642,13 +66905,16 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66642
66905
|
clearTimeout(timer);
|
|
66643
66906
|
}
|
|
66644
66907
|
Log.debug('EnsureConnected get to max try count, will return: ', tryCount);
|
|
66645
|
-
|
|
66908
|
+
const preserveWebUsbInitError = DataManager.isBrowserWebUsb(env) || DataManager.isDesktopWebUsb(env);
|
|
66909
|
+
const needsPermissionPrompt = DataManager.isBrowserWebUsb(env) && !((_u = method.payload) === null || _u === void 0 ? void 0 : _u.skipWebDevicePrompt);
|
|
66910
|
+
const fallbackError = needsPermissionPrompt
|
|
66911
|
+
? hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission)
|
|
66912
|
+
: hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
|
|
66913
|
+
const errorToReject = preserveWebUsbInitError && lastInitializeError ? lastInitializeError : fallbackError;
|
|
66914
|
+
if (needsPermissionPrompt && errorToReject === fallbackError) {
|
|
66646
66915
|
postMessage(createUiMessage(UI_REQUEST.WEB_DEVICE_PROMPT_ACCESS_PERMISSION));
|
|
66647
|
-
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission));
|
|
66648
|
-
}
|
|
66649
|
-
else {
|
|
66650
|
-
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound));
|
|
66651
66916
|
}
|
|
66917
|
+
reject(errorToReject);
|
|
66652
66918
|
return;
|
|
66653
66919
|
}
|
|
66654
66920
|
if (abort()) {
|
|
@@ -66694,9 +66960,9 @@ const cancel = (context, connectId) => {
|
|
|
66694
66960
|
}
|
|
66695
66961
|
else {
|
|
66696
66962
|
const env = DataManager.getSettings('env');
|
|
66963
|
+
requestQueue.abortAllRequests();
|
|
66697
66964
|
if (DataManager.isBleConnect(env)) {
|
|
66698
66965
|
Log.debug('Cancel Api all _deviceList: ');
|
|
66699
|
-
requestQueue.abortAllRequests();
|
|
66700
66966
|
const canceledDevices = [];
|
|
66701
66967
|
const interruptDevice = (device) => {
|
|
66702
66968
|
if (!device || canceledDevices.includes(device)) {
|
|
@@ -66927,7 +67193,14 @@ class Core extends events.exports {
|
|
|
66927
67193
|
this.prePendingCallPromises.delete(connectId);
|
|
66928
67194
|
return;
|
|
66929
67195
|
}
|
|
66930
|
-
this.prePendingCallPromises.
|
|
67196
|
+
const previous = this.prePendingCallPromises.get(connectId);
|
|
67197
|
+
const cleanupPromise = previous && previous !== promise
|
|
67198
|
+
? Promise.all([previous, promise]).then(() => undefined)
|
|
67199
|
+
: promise;
|
|
67200
|
+
this.prePendingCallPromises.set(connectId, cleanupPromise);
|
|
67201
|
+
cleanupPromise.catch(error => {
|
|
67202
|
+
Log.warn('Device cancellation cleanup failed', { errorCode: error === null || error === void 0 ? void 0 : error.errorCode });
|
|
67203
|
+
});
|
|
66931
67204
|
},
|
|
66932
67205
|
removePrePendingCallPromise: (connectId, promise) => {
|
|
66933
67206
|
if (this.prePendingCallPromises.get(connectId) === promise) {
|