@onekeyfe/hd-core 1.2.0-alpha.17 → 1.2.0-alpha.19
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__/DeviceEventRegistration.test.ts +3 -0
- package/__tests__/device-features-state.test.ts +78 -0
- package/__tests__/device-identity.test.ts +30 -0
- package/__tests__/device-pool-state.test.ts +113 -0
- package/__tests__/device-settings.test.ts +108 -0
- package/__tests__/device-state-contract.test.ts +27 -0
- package/__tests__/device-state-events.test.ts +163 -0
- package/__tests__/device-state-mapper.test.ts +222 -0
- package/__tests__/device-state-projector.test.ts +94 -0
- package/__tests__/device-state-store.test.ts +115 -0
- package/__tests__/device-wallet-session-store.test.ts +46 -0
- package/__tests__/deviceFeaturesUtils.test.ts +13 -1
- package/__tests__/deviceSettings.test.ts +54 -0
- package/__tests__/get-device-state.test.ts +367 -0
- package/__tests__/kaspaSignTransaction.test.ts +591 -0
- package/__tests__/logBlockEvent.test.ts +13 -0
- package/__tests__/protocol-v2.test.ts +358 -413
- package/__tests__/public-device-state-api.test.ts +153 -0
- package/__tests__/refresh-device-state.test.ts +101 -0
- package/__tests__/request-context-logging.test.ts +16 -0
- package/__tests__/search-devices.test.ts +93 -0
- package/dist/api/ClearSessionCache.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetDeviceState.d.ts +7 -0
- package/dist/api/GetDeviceState.d.ts.map +1 -0
- package/dist/api/GetFeatures.d.ts +1 -1
- package/dist/api/GetFeatures.d.ts.map +1 -1
- package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -4
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/internal.d.ts +4 -0
- package/dist/api/internal.d.ts.map +1 -0
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +5 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/kaspa/helpers/TransferSerialize.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts +0 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -1
- package/dist/api/utils.d.ts +2 -1
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +22 -3
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DeviceFeaturesState.d.ts +4 -0
- package/dist/device/DeviceFeaturesState.d.ts.map +1 -0
- package/dist/device/DevicePool.d.ts +1 -0
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts +13 -0
- package/dist/device/DeviceStateMapper.d.ts.map +1 -0
- package/dist/device/DeviceStateProjector.d.ts +8 -0
- package/dist/device/DeviceStateProjector.d.ts.map +1 -0
- package/dist/device/DeviceStateStore.d.ts +23 -0
- package/dist/device/DeviceStateStore.d.ts.map +1 -0
- package/dist/device/deviceIdentity.d.ts +5 -0
- package/dist/device/deviceIdentity.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/index.d.ts +0 -1
- package/dist/deviceProfile/index.d.ts.map +1 -1
- package/dist/events/device.d.ts +7 -2
- package/dist/events/device.d.ts.map +1 -1
- package/dist/index.d.ts +722 -648
- package/dist/index.js +1863 -1033
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +1 -0
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +1 -1
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/api/deviceSettings.d.ts +8 -0
- package/dist/types/api/deviceSettings.d.ts.map +1 -1
- package/dist/types/api/getDeviceState.d.ts +12 -0
- package/dist/types/api/getDeviceState.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +4 -7
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/kaspaSignTransaction.d.ts +27 -2
- package/dist/types/api/kaspaSignTransaction.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +1 -6
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +121 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/tracing.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/ClearSessionCache.ts +4 -0
- package/src/api/FirmwareUpdateV4.ts +15 -7
- package/src/api/GetDeviceState.ts +55 -0
- package/src/api/GetFeatures.ts +8 -3
- package/src/api/GetOnekeyFeatures.ts +3 -72
- package/src/api/GetPassphraseState.ts +3 -1
- package/src/api/SearchDevices.ts +25 -4
- package/src/api/device/DeviceRebootToBoardloader.ts +1 -0
- package/src/api/device/DeviceRebootToBootloader.ts +1 -0
- package/src/api/device/DeviceSettings.ts +28 -0
- package/src/api/index.ts +1 -4
- package/src/api/internal.ts +9 -0
- package/src/api/kaspa/KaspaSignTransaction.ts +341 -22
- package/src/api/kaspa/helpers/TransferSerialize.ts +14 -0
- package/src/api/protocol-v2/DeviceInfoGet.ts +3 -5
- package/src/api/protocol-v2/DeviceReboot.ts +3 -1
- package/src/api/protocol-v2/DeviceSettingsGet.ts +3 -1
- package/src/api/protocol-v2/DeviceSettingsSet.ts +2 -0
- package/src/api/protocol-v2/DeviceStatusGet.ts +1 -0
- package/src/api/utils.ts +9 -3
- package/src/constants/index.ts +1 -4
- package/src/core/index.ts +7 -1
- package/src/data/messages/messages-protocol-v2.json +22 -13
- package/src/data/messages/messages.json +286 -1
- package/src/device/Device.ts +256 -78
- package/src/device/DeviceFeaturesState.ts +34 -0
- package/src/device/DevicePool.ts +35 -9
- package/src/device/DeviceStateMapper.ts +364 -0
- package/src/device/DeviceStateProjector.ts +92 -0
- package/src/device/DeviceStateStore.ts +242 -0
- package/src/device/deviceIdentity.ts +18 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +166 -109
- package/src/deviceProfile/index.ts +0 -1
- package/src/events/device.ts +13 -1
- package/src/events/logBlockEvent.ts +1 -1
- package/src/inject.ts +4 -5
- package/src/protocols/protocol-v2/features.ts +18 -9
- package/src/protocols/protocol-v2/index.ts +1 -0
- package/src/protocols/protocol-v2/walletSession.ts +5 -7
- package/src/types/api/deviceSettings.ts +8 -0
- package/src/types/api/getDeviceState.ts +19 -0
- package/src/types/api/index.ts +3 -20
- package/src/types/api/kaspaSignTransaction.ts +40 -2
- package/src/types/api/protocolV2.ts +0 -24
- package/src/types/device.ts +148 -1
- package/src/utils/deviceFeaturesUtils.ts +5 -1
- package/src/utils/deviceSettings.ts +41 -0
- package/src/utils/tracing.ts +3 -1
- package/dist/api/GetDeviceInfo.d.ts +0 -9
- package/dist/api/GetDeviceInfo.d.ts.map +0 -1
- package/dist/deviceProfile/buildDeviceProfile.d.ts +0 -22
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +0 -1
- package/dist/types/api/getDeviceInfo.d.ts +0 -88
- package/dist/types/api/getDeviceInfo.d.ts.map +0 -1
- package/src/api/GetDeviceInfo.ts +0 -152
- package/src/deviceProfile/buildDeviceProfile.ts +0 -370
- package/src/types/api/getDeviceInfo.ts +0 -106
package/dist/index.js
CHANGED
|
@@ -123,7 +123,10 @@ const createCoreApi = (call) => ({
|
|
|
123
123
|
clearSessionCache: params => call(Object.assign(Object.assign({}, params), { method: 'clearSessionCache' })),
|
|
124
124
|
searchDevices: params => call(Object.assign(Object.assign({}, params), { method: 'searchDevices' })),
|
|
125
125
|
getFeatures: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'getFeatures' })),
|
|
126
|
-
|
|
126
|
+
getDeviceState: (connectId, params) => {
|
|
127
|
+
const _a = (params !== null && params !== void 0 ? params : {}), commonParams = __rest(_a, ["refresh", "includeRaw"]);
|
|
128
|
+
return call(Object.assign(Object.assign({}, commonParams), { connectId, method: 'getDeviceState' }));
|
|
129
|
+
},
|
|
127
130
|
getOnekeyFeatures: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'getOnekeyFeatures' })),
|
|
128
131
|
checkFirmwareRelease: connectId => call({ connectId, method: 'checkFirmwareRelease' }),
|
|
129
132
|
checkBLEFirmwareRelease: connectId => call({ connectId, method: 'checkBLEFirmwareRelease' }),
|
|
@@ -143,15 +146,12 @@ const createCoreApi = (call) => ({
|
|
|
143
146
|
protocolInfoRequest: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'protocolInfoRequest' })),
|
|
144
147
|
ping: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'ping' })),
|
|
145
148
|
deviceReboot: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceReboot' })),
|
|
146
|
-
deviceInfoGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceInfoGet' })),
|
|
147
|
-
deviceStatusGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceStatusGet' })),
|
|
148
149
|
deviceGetOnboardingStatus: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceGetOnboardingStatus' })),
|
|
149
150
|
deviceSessionOpen: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceSessionOpen' })),
|
|
150
151
|
deviceFirmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFirmwareUpdate' })),
|
|
151
152
|
deviceGetFirmwareUpdateStatus: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceGetFirmwareUpdateStatus' })),
|
|
152
153
|
deviceFactoryInfoSet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFactoryInfoSet' })),
|
|
153
154
|
deviceFactoryInfoGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFactoryInfoGet' })),
|
|
154
|
-
deviceSettingsGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceSettingsGet' })),
|
|
155
155
|
deviceSettingsSet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceSettingsSet' })),
|
|
156
156
|
deviceSettingsPageShow: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceSettingsPageShow' })),
|
|
157
157
|
deviceUploadWallpaper: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceUploadWallpaper' })),
|
|
@@ -826,7 +826,7 @@ const createLogMessage = (type, payload) => ({
|
|
|
826
826
|
|
|
827
827
|
const MAX_ENTRIES = 500;
|
|
828
828
|
let postMessage$1;
|
|
829
|
-
class Log$
|
|
829
|
+
class Log$k {
|
|
830
830
|
constructor(prefix, enabled) {
|
|
831
831
|
this.prefix = prefix;
|
|
832
832
|
this.enabled = enabled;
|
|
@@ -878,7 +878,7 @@ class Log$j {
|
|
|
878
878
|
}
|
|
879
879
|
const _logs = {};
|
|
880
880
|
const initLog = (prefix, enabled) => {
|
|
881
|
-
const instance = new Log$
|
|
881
|
+
const instance = new Log$k(prefix, !!enabled);
|
|
882
882
|
_logs[prefix] = instance;
|
|
883
883
|
return instance;
|
|
884
884
|
};
|
|
@@ -1076,7 +1076,7 @@ function patchFeatures(response) {
|
|
|
1076
1076
|
return response;
|
|
1077
1077
|
}
|
|
1078
1078
|
|
|
1079
|
-
const Log$
|
|
1079
|
+
const Log$j = getLogger(exports.LoggerNames.Core);
|
|
1080
1080
|
let globalInstanceCounter = 0;
|
|
1081
1081
|
let sdkInstanceCounter = 0;
|
|
1082
1082
|
function generateSdkInstanceId() {
|
|
@@ -1136,7 +1136,7 @@ function completeRequestContext(responseID, error) {
|
|
|
1136
1136
|
context.status = error ? 'error' : 'success';
|
|
1137
1137
|
if (error) {
|
|
1138
1138
|
context.error = error.message;
|
|
1139
|
-
Log$
|
|
1139
|
+
Log$j.debug(`[RequestContext] [completeRequestContext] Error: ${formatRequestContext(context)}`);
|
|
1140
1140
|
}
|
|
1141
1141
|
globalActiveRequests.delete(responseID);
|
|
1142
1142
|
if (context.sdkInstanceId) {
|
|
@@ -7564,7 +7564,6 @@ var nested$2 = {
|
|
|
7564
7564
|
}
|
|
7565
7565
|
},
|
|
7566
7566
|
raw_message: {
|
|
7567
|
-
rule: "required",
|
|
7568
7567
|
type: "bytes",
|
|
7569
7568
|
id: 2
|
|
7570
7569
|
},
|
|
@@ -7595,6 +7594,42 @@ var nested$2 = {
|
|
|
7595
7594
|
options: {
|
|
7596
7595
|
"default": true
|
|
7597
7596
|
}
|
|
7597
|
+
},
|
|
7598
|
+
output_count: {
|
|
7599
|
+
type: "uint32",
|
|
7600
|
+
id: 7
|
|
7601
|
+
},
|
|
7602
|
+
version: {
|
|
7603
|
+
type: "uint32",
|
|
7604
|
+
id: 8,
|
|
7605
|
+
options: {
|
|
7606
|
+
"default": 0
|
|
7607
|
+
}
|
|
7608
|
+
},
|
|
7609
|
+
lock_time: {
|
|
7610
|
+
type: "uint64",
|
|
7611
|
+
id: 9,
|
|
7612
|
+
options: {
|
|
7613
|
+
"default": 0
|
|
7614
|
+
}
|
|
7615
|
+
},
|
|
7616
|
+
subnetwork_id: {
|
|
7617
|
+
type: "bytes",
|
|
7618
|
+
id: 10
|
|
7619
|
+
},
|
|
7620
|
+
gas: {
|
|
7621
|
+
type: "uint64",
|
|
7622
|
+
id: 11,
|
|
7623
|
+
options: {
|
|
7624
|
+
"default": 0
|
|
7625
|
+
}
|
|
7626
|
+
},
|
|
7627
|
+
payload_length: {
|
|
7628
|
+
type: "uint32",
|
|
7629
|
+
id: 12,
|
|
7630
|
+
options: {
|
|
7631
|
+
"default": 0
|
|
7632
|
+
}
|
|
7598
7633
|
}
|
|
7599
7634
|
}
|
|
7600
7635
|
},
|
|
@@ -7628,6 +7663,249 @@ var nested$2 = {
|
|
|
7628
7663
|
}
|
|
7629
7664
|
}
|
|
7630
7665
|
},
|
|
7666
|
+
KaspaOutpoint: {
|
|
7667
|
+
fields: {
|
|
7668
|
+
tx_id: {
|
|
7669
|
+
rule: "required",
|
|
7670
|
+
type: "bytes",
|
|
7671
|
+
id: 1
|
|
7672
|
+
},
|
|
7673
|
+
index: {
|
|
7674
|
+
rule: "required",
|
|
7675
|
+
type: "uint32",
|
|
7676
|
+
id: 2
|
|
7677
|
+
}
|
|
7678
|
+
}
|
|
7679
|
+
},
|
|
7680
|
+
KaspaInputScriptType: {
|
|
7681
|
+
values: {
|
|
7682
|
+
KASPA_SPEND_P2PK_SCHNORR: 0,
|
|
7683
|
+
KASPA_SPEND_P2PK_ECDSA: 1
|
|
7684
|
+
}
|
|
7685
|
+
},
|
|
7686
|
+
KaspaOutputScriptType: {
|
|
7687
|
+
values: {
|
|
7688
|
+
KASPA_PAYTOADDRESS: 0,
|
|
7689
|
+
KASPA_PAYTOCHANGE: 1
|
|
7690
|
+
}
|
|
7691
|
+
},
|
|
7692
|
+
KaspaRequestType: {
|
|
7693
|
+
values: {
|
|
7694
|
+
KASPA_TX_INPUT: 0,
|
|
7695
|
+
KASPA_TX_OUTPUT: 1,
|
|
7696
|
+
KASPA_TX_PAYLOAD: 2,
|
|
7697
|
+
KASPA_TX_FINISHED: 3,
|
|
7698
|
+
KASPA_TX_PREV_META: 4
|
|
7699
|
+
}
|
|
7700
|
+
},
|
|
7701
|
+
KaspaTxRequestSignature: {
|
|
7702
|
+
fields: {
|
|
7703
|
+
signature_index: {
|
|
7704
|
+
rule: "required",
|
|
7705
|
+
type: "uint32",
|
|
7706
|
+
id: 1
|
|
7707
|
+
},
|
|
7708
|
+
signature: {
|
|
7709
|
+
rule: "required",
|
|
7710
|
+
type: "bytes",
|
|
7711
|
+
id: 2
|
|
7712
|
+
}
|
|
7713
|
+
}
|
|
7714
|
+
},
|
|
7715
|
+
KaspaTxRequest: {
|
|
7716
|
+
fields: {
|
|
7717
|
+
request_type: {
|
|
7718
|
+
rule: "required",
|
|
7719
|
+
type: "KaspaRequestType",
|
|
7720
|
+
id: 1
|
|
7721
|
+
},
|
|
7722
|
+
request_index: {
|
|
7723
|
+
type: "uint32",
|
|
7724
|
+
id: 2
|
|
7725
|
+
},
|
|
7726
|
+
signature: {
|
|
7727
|
+
type: "KaspaTxRequestSignature",
|
|
7728
|
+
id: 3
|
|
7729
|
+
},
|
|
7730
|
+
request_payload_length: {
|
|
7731
|
+
type: "uint32",
|
|
7732
|
+
id: 4
|
|
7733
|
+
},
|
|
7734
|
+
prev_tx_id: {
|
|
7735
|
+
type: "bytes",
|
|
7736
|
+
id: 5
|
|
7737
|
+
}
|
|
7738
|
+
}
|
|
7739
|
+
},
|
|
7740
|
+
KaspaTxAckInput: {
|
|
7741
|
+
fields: {
|
|
7742
|
+
address_n: {
|
|
7743
|
+
rule: "repeated",
|
|
7744
|
+
type: "uint32",
|
|
7745
|
+
id: 1,
|
|
7746
|
+
options: {
|
|
7747
|
+
packed: false
|
|
7748
|
+
}
|
|
7749
|
+
},
|
|
7750
|
+
previous_outpoint: {
|
|
7751
|
+
rule: "required",
|
|
7752
|
+
type: "KaspaOutpoint",
|
|
7753
|
+
id: 2
|
|
7754
|
+
},
|
|
7755
|
+
amount: {
|
|
7756
|
+
rule: "required",
|
|
7757
|
+
type: "uint64",
|
|
7758
|
+
id: 3
|
|
7759
|
+
},
|
|
7760
|
+
sequence: {
|
|
7761
|
+
rule: "required",
|
|
7762
|
+
type: "uint64",
|
|
7763
|
+
id: 4
|
|
7764
|
+
},
|
|
7765
|
+
sig_op_count: {
|
|
7766
|
+
rule: "required",
|
|
7767
|
+
type: "uint32",
|
|
7768
|
+
id: 5
|
|
7769
|
+
},
|
|
7770
|
+
script_type: {
|
|
7771
|
+
type: "KaspaInputScriptType",
|
|
7772
|
+
id: 6,
|
|
7773
|
+
options: {
|
|
7774
|
+
"default": "KASPA_SPEND_P2PK_SCHNORR"
|
|
7775
|
+
}
|
|
7776
|
+
},
|
|
7777
|
+
use_tweak: {
|
|
7778
|
+
type: "bool",
|
|
7779
|
+
id: 9,
|
|
7780
|
+
options: {
|
|
7781
|
+
"default": true
|
|
7782
|
+
}
|
|
7783
|
+
}
|
|
7784
|
+
}
|
|
7785
|
+
},
|
|
7786
|
+
KaspaTxAckOutput: {
|
|
7787
|
+
fields: {
|
|
7788
|
+
script_type: {
|
|
7789
|
+
type: "KaspaOutputScriptType",
|
|
7790
|
+
id: 1,
|
|
7791
|
+
options: {
|
|
7792
|
+
"default": "KASPA_PAYTOADDRESS"
|
|
7793
|
+
}
|
|
7794
|
+
},
|
|
7795
|
+
amount: {
|
|
7796
|
+
rule: "required",
|
|
7797
|
+
type: "uint64",
|
|
7798
|
+
id: 2
|
|
7799
|
+
},
|
|
7800
|
+
address_n: {
|
|
7801
|
+
rule: "repeated",
|
|
7802
|
+
type: "uint32",
|
|
7803
|
+
id: 3,
|
|
7804
|
+
options: {
|
|
7805
|
+
packed: false
|
|
7806
|
+
}
|
|
7807
|
+
},
|
|
7808
|
+
address: {
|
|
7809
|
+
type: "string",
|
|
7810
|
+
id: 4
|
|
7811
|
+
},
|
|
7812
|
+
scheme: {
|
|
7813
|
+
type: "string",
|
|
7814
|
+
id: 7,
|
|
7815
|
+
options: {
|
|
7816
|
+
"default": "schnorr"
|
|
7817
|
+
}
|
|
7818
|
+
},
|
|
7819
|
+
use_tweak: {
|
|
7820
|
+
type: "bool",
|
|
7821
|
+
id: 8,
|
|
7822
|
+
options: {
|
|
7823
|
+
"default": true
|
|
7824
|
+
}
|
|
7825
|
+
}
|
|
7826
|
+
}
|
|
7827
|
+
},
|
|
7828
|
+
KaspaTxAckPayloadChunk: {
|
|
7829
|
+
fields: {
|
|
7830
|
+
payload_chunk: {
|
|
7831
|
+
rule: "required",
|
|
7832
|
+
type: "bytes",
|
|
7833
|
+
id: 1
|
|
7834
|
+
}
|
|
7835
|
+
}
|
|
7836
|
+
},
|
|
7837
|
+
KaspaTxAckPrevMeta: {
|
|
7838
|
+
fields: {
|
|
7839
|
+
version: {
|
|
7840
|
+
rule: "required",
|
|
7841
|
+
type: "uint32",
|
|
7842
|
+
id: 1
|
|
7843
|
+
},
|
|
7844
|
+
input_count: {
|
|
7845
|
+
rule: "required",
|
|
7846
|
+
type: "uint32",
|
|
7847
|
+
id: 2
|
|
7848
|
+
},
|
|
7849
|
+
output_count: {
|
|
7850
|
+
rule: "required",
|
|
7851
|
+
type: "uint32",
|
|
7852
|
+
id: 3
|
|
7853
|
+
},
|
|
7854
|
+
lock_time: {
|
|
7855
|
+
rule: "required",
|
|
7856
|
+
type: "uint64",
|
|
7857
|
+
id: 4
|
|
7858
|
+
},
|
|
7859
|
+
subnetwork_id: {
|
|
7860
|
+
rule: "required",
|
|
7861
|
+
type: "bytes",
|
|
7862
|
+
id: 5
|
|
7863
|
+
},
|
|
7864
|
+
gas: {
|
|
7865
|
+
rule: "required",
|
|
7866
|
+
type: "uint64",
|
|
7867
|
+
id: 6
|
|
7868
|
+
},
|
|
7869
|
+
payload_length: {
|
|
7870
|
+
rule: "required",
|
|
7871
|
+
type: "uint32",
|
|
7872
|
+
id: 7
|
|
7873
|
+
}
|
|
7874
|
+
}
|
|
7875
|
+
},
|
|
7876
|
+
KaspaTxAckPrevInput: {
|
|
7877
|
+
fields: {
|
|
7878
|
+
previous_outpoint: {
|
|
7879
|
+
rule: "required",
|
|
7880
|
+
type: "KaspaOutpoint",
|
|
7881
|
+
id: 1
|
|
7882
|
+
},
|
|
7883
|
+
sequence: {
|
|
7884
|
+
rule: "required",
|
|
7885
|
+
type: "uint64",
|
|
7886
|
+
id: 2
|
|
7887
|
+
}
|
|
7888
|
+
}
|
|
7889
|
+
},
|
|
7890
|
+
KaspaTxAckPrevOutput: {
|
|
7891
|
+
fields: {
|
|
7892
|
+
amount: {
|
|
7893
|
+
rule: "required",
|
|
7894
|
+
type: "uint64",
|
|
7895
|
+
id: 1
|
|
7896
|
+
},
|
|
7897
|
+
script_version: {
|
|
7898
|
+
rule: "required",
|
|
7899
|
+
type: "uint32",
|
|
7900
|
+
id: 2
|
|
7901
|
+
},
|
|
7902
|
+
script_public_key: {
|
|
7903
|
+
rule: "required",
|
|
7904
|
+
type: "bytes",
|
|
7905
|
+
id: 3
|
|
7906
|
+
}
|
|
7907
|
+
}
|
|
7908
|
+
},
|
|
7631
7909
|
KaspaSignedTx: {
|
|
7632
7910
|
fields: {
|
|
7633
7911
|
signature: {
|
|
@@ -14075,6 +14353,13 @@ var nested$2 = {
|
|
|
14075
14353
|
MessageType_KaspaSignedTx: 11303,
|
|
14076
14354
|
MessageType_KaspaTxInputRequest: 11304,
|
|
14077
14355
|
MessageType_KaspaTxInputAck: 11305,
|
|
14356
|
+
MessageType_KaspaTxRequest: 11306,
|
|
14357
|
+
MessageType_KaspaTxAckInput: 11307,
|
|
14358
|
+
MessageType_KaspaTxAckOutput: 11308,
|
|
14359
|
+
MessageType_KaspaTxAckPayloadChunk: 11309,
|
|
14360
|
+
MessageType_KaspaTxAckPrevMeta: 11310,
|
|
14361
|
+
MessageType_KaspaTxAckPrevInput: 11311,
|
|
14362
|
+
MessageType_KaspaTxAckPrevOutput: 11312,
|
|
14078
14363
|
MessageType_NexaGetAddress: 11400,
|
|
14079
14364
|
MessageType_NexaAddress: 11401,
|
|
14080
14365
|
MessageType_NexaSignTx: 11402,
|
|
@@ -36928,7 +37213,8 @@ var nested = {
|
|
|
36928
37213
|
LayoutSafeTxCreate: 1,
|
|
36929
37214
|
LayoutFinalConfirm: 2,
|
|
36930
37215
|
Layout7702: 3,
|
|
36931
|
-
LayoutFlat: 4
|
|
37216
|
+
LayoutFlat: 4,
|
|
37217
|
+
LayoutEthApprove: 5
|
|
36932
37218
|
}
|
|
36933
37219
|
},
|
|
36934
37220
|
ViewSignPage: {
|
|
@@ -36987,6 +37273,18 @@ var nested = {
|
|
|
36987
37273
|
rule: "required",
|
|
36988
37274
|
type: "string",
|
|
36989
37275
|
id: 3
|
|
37276
|
+
},
|
|
37277
|
+
network: {
|
|
37278
|
+
type: "string",
|
|
37279
|
+
id: 4
|
|
37280
|
+
},
|
|
37281
|
+
derive_type: {
|
|
37282
|
+
type: "string",
|
|
37283
|
+
id: 5
|
|
37284
|
+
},
|
|
37285
|
+
value_key: {
|
|
37286
|
+
type: "uint32",
|
|
37287
|
+
id: 6
|
|
36990
37288
|
}
|
|
36991
37289
|
}
|
|
36992
37290
|
},
|
|
@@ -37196,10 +37494,6 @@ var nested = {
|
|
|
37196
37494
|
type: "string",
|
|
37197
37495
|
id: 4
|
|
37198
37496
|
},
|
|
37199
|
-
passphrase_enable: {
|
|
37200
|
-
type: "bool",
|
|
37201
|
-
id: 6
|
|
37202
|
-
},
|
|
37203
37497
|
brightness: {
|
|
37204
37498
|
type: "uint32",
|
|
37205
37499
|
id: 7
|
|
@@ -37232,14 +37526,6 @@ var nested = {
|
|
|
37232
37526
|
type: "bool",
|
|
37233
37527
|
id: 14
|
|
37234
37528
|
},
|
|
37235
|
-
fido_enabled: {
|
|
37236
|
-
type: "bool",
|
|
37237
|
-
id: 15
|
|
37238
|
-
},
|
|
37239
|
-
experimental_features: {
|
|
37240
|
-
type: "bool",
|
|
37241
|
-
id: 16
|
|
37242
|
-
},
|
|
37243
37529
|
usb_lock_enable: {
|
|
37244
37530
|
type: "bool",
|
|
37245
37531
|
id: 17
|
|
@@ -37247,6 +37533,14 @@ var nested = {
|
|
|
37247
37533
|
random_keypad: {
|
|
37248
37534
|
type: "bool",
|
|
37249
37535
|
id: 18
|
|
37536
|
+
},
|
|
37537
|
+
passphrase_enable: {
|
|
37538
|
+
type: "bool",
|
|
37539
|
+
id: 100
|
|
37540
|
+
},
|
|
37541
|
+
fido_enabled: {
|
|
37542
|
+
type: "bool",
|
|
37543
|
+
id: 101
|
|
37250
37544
|
}
|
|
37251
37545
|
}
|
|
37252
37546
|
},
|
|
@@ -38972,7 +39266,7 @@ const findLatestRelease = (releases) => {
|
|
|
38972
39266
|
};
|
|
38973
39267
|
|
|
38974
39268
|
var _a$1;
|
|
38975
|
-
const Log$
|
|
39269
|
+
const Log$i = getLogger(exports.LoggerNames.Core);
|
|
38976
39270
|
const FIRMWARE_FIELDS = [
|
|
38977
39271
|
'firmware',
|
|
38978
39272
|
'firmware-v1',
|
|
@@ -39036,37 +39330,37 @@ class DataManager {
|
|
|
39036
39330
|
let data = null;
|
|
39037
39331
|
let fetchMethod = 'none';
|
|
39038
39332
|
if (settings.configFetcher) {
|
|
39039
|
-
Log$
|
|
39333
|
+
Log$i.debug('[DataConfig] Trying configFetcher (client-side fetcher)...');
|
|
39040
39334
|
try {
|
|
39041
39335
|
data = yield settings.configFetcher(urlWithCache);
|
|
39042
39336
|
if (data) {
|
|
39043
39337
|
fetchMethod = 'configFetcher';
|
|
39044
|
-
Log$
|
|
39338
|
+
Log$i.log('[DataConfig] ConfigFetcher success');
|
|
39045
39339
|
}
|
|
39046
39340
|
else {
|
|
39047
|
-
Log$
|
|
39341
|
+
Log$i.debug('[DataConfig] ConfigFetcher returned null, will fallback to axios');
|
|
39048
39342
|
}
|
|
39049
39343
|
}
|
|
39050
39344
|
catch (e) {
|
|
39051
|
-
Log$
|
|
39345
|
+
Log$i.warn('[DataConfig] ConfigFetcher error, will fallback to axios:', e);
|
|
39052
39346
|
}
|
|
39053
39347
|
}
|
|
39054
39348
|
if (!data) {
|
|
39055
|
-
Log$
|
|
39349
|
+
Log$i.debug('[DataConfig] Trying axios (SDK default fetcher)...');
|
|
39056
39350
|
try {
|
|
39057
39351
|
const response = yield axios__default["default"].get(urlWithCache, {
|
|
39058
39352
|
timeout: 7000,
|
|
39059
39353
|
});
|
|
39060
39354
|
data = response.data;
|
|
39061
39355
|
fetchMethod = 'axios';
|
|
39062
|
-
Log$
|
|
39356
|
+
Log$i.log('[DataConfig] Axios fetch success');
|
|
39063
39357
|
}
|
|
39064
39358
|
catch (e) {
|
|
39065
|
-
Log$
|
|
39359
|
+
Log$i.warn('[DataConfig] Axios fetch error:', e);
|
|
39066
39360
|
}
|
|
39067
39361
|
}
|
|
39068
39362
|
if (data) {
|
|
39069
|
-
Log$
|
|
39363
|
+
Log$i.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
|
|
39070
39364
|
this.deviceMap = {
|
|
39071
39365
|
[hdShared.EDeviceType.Classic]: this.enrichFirmwareReleaseInfo(data.classic),
|
|
39072
39366
|
[hdShared.EDeviceType.Classic1s]: this.enrichFirmwareReleaseInfo(data.classic1s),
|
|
@@ -39081,7 +39375,7 @@ class DataManager {
|
|
|
39081
39375
|
};
|
|
39082
39376
|
}
|
|
39083
39377
|
else {
|
|
39084
|
-
Log$
|
|
39378
|
+
Log$i.warn('[DataConfig] All fetch methods failed, using built-in default config');
|
|
39085
39379
|
}
|
|
39086
39380
|
});
|
|
39087
39381
|
}
|
|
@@ -39512,6 +39806,7 @@ const DEVICE = {
|
|
|
39512
39806
|
SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE: 'select_device_in_bootloader_for_web_device',
|
|
39513
39807
|
SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE: 'select_device_for_switch_firmware_web_device',
|
|
39514
39808
|
FEATURES: 'features',
|
|
39809
|
+
STATE: 'state',
|
|
39515
39810
|
};
|
|
39516
39811
|
const createDeviceMessage = (type, payload) => ({
|
|
39517
39812
|
event: DEVICE_EVENT,
|
|
@@ -39534,7 +39829,7 @@ const LogBlockEvent = new Set([
|
|
|
39534
39829
|
UI_RESPONSE.RECEIVE_PIN,
|
|
39535
39830
|
UI_RESPONSE.RECEIVE_PASSPHRASE,
|
|
39536
39831
|
]);
|
|
39537
|
-
const LogBlockMethod = new Set(['evmSignTypedData']);
|
|
39832
|
+
const LogBlockMethod = new Set(['evmSignTypedData', 'deviceSessionOpen']);
|
|
39538
39833
|
function getLogBlockLabel(message) {
|
|
39539
39834
|
if (!message || typeof message !== 'object')
|
|
39540
39835
|
return undefined;
|
|
@@ -39577,18 +39872,6 @@ const normalizeHostPassphrase = (passphrase) => {
|
|
|
39577
39872
|
}
|
|
39578
39873
|
return normalized;
|
|
39579
39874
|
};
|
|
39580
|
-
function requestProtocolV2DeviceStatus$1(device) {
|
|
39581
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39582
|
-
const { message } = yield device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
|
|
39583
|
-
return message;
|
|
39584
|
-
});
|
|
39585
|
-
}
|
|
39586
|
-
function refreshProtocolV2DeviceStatus(device) {
|
|
39587
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39588
|
-
const status = yield requestProtocolV2DeviceStatus$1(device);
|
|
39589
|
-
return device.updateProtocolV2Status(status);
|
|
39590
|
-
});
|
|
39591
|
-
}
|
|
39592
39875
|
const openDeviceSession = (device, request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39593
39876
|
try {
|
|
39594
39877
|
return yield device.commands.typedCall('DeviceSessionOpen', 'DeviceSession', request);
|
|
@@ -39641,7 +39924,7 @@ const openSelectedHiddenWallet = (device, promptPayload) => __awaiter(void 0, vo
|
|
|
39641
39924
|
return openDeviceSession(device, request);
|
|
39642
39925
|
});
|
|
39643
39926
|
function getProtocolV2WalletSession(device, options) {
|
|
39644
|
-
var _a, _b, _c, _d, _e, _f;
|
|
39927
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
39645
39928
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39646
39929
|
if (options === null || options === void 0 ? void 0 : options.initSession) {
|
|
39647
39930
|
device.clearInternalState();
|
|
@@ -39689,14 +39972,11 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
39689
39972
|
device.clearInternalState();
|
|
39690
39973
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
39691
39974
|
}
|
|
39692
|
-
|
|
39693
|
-
yield refreshProtocolV2DeviceStatus(device);
|
|
39694
|
-
}
|
|
39695
|
-
device.updateInternalState(true, message.btc_test_address, device.getCurrentDeviceId(), message.session_id, (options === null || options === void 0 ? void 0 : options.initSession) ? null : (_d = device.features) === null || _d === void 0 ? void 0 : _d.sessionId);
|
|
39975
|
+
device.updateInternalState(true, message.btc_test_address, device.getCurrentDeviceId(), message.session_id, (options === null || options === void 0 ? void 0 : options.initSession) ? null : (_e = (_d = device.features) === null || _d === void 0 ? void 0 : _d.sessionId) !== null && _e !== void 0 ? _e : null);
|
|
39696
39976
|
return {
|
|
39697
39977
|
passphraseState: message.btc_test_address,
|
|
39698
39978
|
newSession: message.session_id,
|
|
39699
|
-
unlockedAttachPin: (
|
|
39979
|
+
unlockedAttachPin: (_g = (_f = device.features) === null || _f === void 0 ? void 0 : _f.unlockedAttachPin) !== null && _g !== void 0 ? _g : undefined,
|
|
39700
39980
|
};
|
|
39701
39981
|
}
|
|
39702
39982
|
catch (error) {
|
|
@@ -39748,7 +40028,9 @@ const supportInputPinOnSoftware = (features) => {
|
|
|
39748
40028
|
if (!features)
|
|
39749
40029
|
return { support: false };
|
|
39750
40030
|
const deviceType = getDeviceType(features);
|
|
39751
|
-
if (deviceType === hdShared.EDeviceType.Touch ||
|
|
40031
|
+
if (deviceType === hdShared.EDeviceType.Touch ||
|
|
40032
|
+
deviceType === hdShared.EDeviceType.Pro ||
|
|
40033
|
+
deviceType === hdShared.EDeviceType.Pro2) {
|
|
39752
40034
|
return { support: false };
|
|
39753
40035
|
}
|
|
39754
40036
|
const currentVersion = getDeviceFirmwareVersion(features).join('.');
|
|
@@ -40131,6 +40413,25 @@ const LANGUAGE_LABELS = {
|
|
|
40131
40413
|
it: 'Italiano',
|
|
40132
40414
|
pt_br: 'Portuguese (Brazil)',
|
|
40133
40415
|
};
|
|
40416
|
+
const PRO2_LANGUAGE_OPTIONS = [
|
|
40417
|
+
{ code: 'en-Latn-US', label: 'English' },
|
|
40418
|
+
{ code: 'zh-Hans-CN', label: '简体中文' },
|
|
40419
|
+
{ code: 'zh-Hant-HK', label: '繁體中文(香港)' },
|
|
40420
|
+
{ code: 'zh-Hant-TW', label: '繁體中文(台灣)' },
|
|
40421
|
+
{ code: 'ja-Jpan-JP', label: '日本語' },
|
|
40422
|
+
{ code: 'ko-Kore-KR', label: '한국어' },
|
|
40423
|
+
{ code: 'fr-Latn-FR', label: 'Français' },
|
|
40424
|
+
{ code: 'de-Latn-DE', label: 'Deutsch' },
|
|
40425
|
+
{ code: 'ru-Cyrl-RU', label: 'Русский' },
|
|
40426
|
+
{ code: 'es-Latn-ES', label: 'Español' },
|
|
40427
|
+
{ code: 'it-Latn-IT', label: 'Italiano' },
|
|
40428
|
+
{ code: 'pt-Latn-BR', label: 'Portuguese (Brazil)' },
|
|
40429
|
+
{ code: 'vi-Latn-VN', label: 'Tiếng Việt' },
|
|
40430
|
+
{ code: 'tr-Latn-TR', label: 'Türkçe' },
|
|
40431
|
+
{ code: 'id-Latn-ID', label: 'Bahasa Indonesia' },
|
|
40432
|
+
{ code: 'fil-Latn-PH', label: 'Filipino' },
|
|
40433
|
+
{ code: 'uk-Cyrl-UA', label: 'Українська' },
|
|
40434
|
+
];
|
|
40134
40435
|
const getLanguageConfig = (deviceType) => {
|
|
40135
40436
|
let keys = [];
|
|
40136
40437
|
switch (deviceType) {
|
|
@@ -40146,6 +40447,8 @@ const getLanguageConfig = (deviceType) => {
|
|
|
40146
40447
|
case hdShared.EDeviceType.Pro:
|
|
40147
40448
|
keys = Object.keys(LANGUAGE_LABELS);
|
|
40148
40449
|
break;
|
|
40450
|
+
case hdShared.EDeviceType.Pro2:
|
|
40451
|
+
return PRO2_LANGUAGE_OPTIONS.map(option => (Object.assign({}, option)));
|
|
40149
40452
|
default:
|
|
40150
40453
|
keys = [];
|
|
40151
40454
|
break;
|
|
@@ -40176,6 +40479,16 @@ const getAutoLockOptions = (_deviceType) => {
|
|
|
40176
40479
|
{ seconds: 0, minute: 30, hour: 0, day: 0 },
|
|
40177
40480
|
{ seconds: 0, minute: 0, hour: 0, day: 0 },
|
|
40178
40481
|
];
|
|
40482
|
+
case hdShared.EDeviceType.Pro2:
|
|
40483
|
+
return [
|
|
40484
|
+
{ seconds: 30, minute: 0, hour: 0, day: 0 },
|
|
40485
|
+
{ seconds: 0, minute: 1, hour: 0, day: 0 },
|
|
40486
|
+
{ seconds: 0, minute: 2, hour: 0, day: 0 },
|
|
40487
|
+
{ seconds: 0, minute: 5, hour: 0, day: 0 },
|
|
40488
|
+
{ seconds: 0, minute: 10, hour: 0, day: 0 },
|
|
40489
|
+
{ seconds: 0, minute: 30, hour: 0, day: 0 },
|
|
40490
|
+
{ seconds: 0, minute: 0, hour: 0, day: 0 },
|
|
40491
|
+
];
|
|
40179
40492
|
default:
|
|
40180
40493
|
return [];
|
|
40181
40494
|
}
|
|
@@ -40203,6 +40516,15 @@ const getAutoShutDownOptions = (_deviceType) => {
|
|
|
40203
40516
|
{ seconds: 0, minute: 10, hour: 0, day: 0 },
|
|
40204
40517
|
{ seconds: 0, minute: 0, hour: 0, day: 0 },
|
|
40205
40518
|
];
|
|
40519
|
+
case hdShared.EDeviceType.Pro2:
|
|
40520
|
+
return [
|
|
40521
|
+
{ seconds: 0, minute: 1, hour: 0, day: 0 },
|
|
40522
|
+
{ seconds: 0, minute: 2, hour: 0, day: 0 },
|
|
40523
|
+
{ seconds: 0, minute: 5, hour: 0, day: 0 },
|
|
40524
|
+
{ seconds: 0, minute: 10, hour: 0, day: 0 },
|
|
40525
|
+
{ seconds: 0, minute: 30, hour: 0, day: 0 },
|
|
40526
|
+
{ seconds: 0, minute: 0, hour: 0, day: 0 },
|
|
40527
|
+
];
|
|
40206
40528
|
default:
|
|
40207
40529
|
return [];
|
|
40208
40530
|
}
|
|
@@ -40637,7 +40959,7 @@ const getDefectiveDeviceInfo = (features) => {
|
|
|
40637
40959
|
};
|
|
40638
40960
|
};
|
|
40639
40961
|
|
|
40640
|
-
const Log$
|
|
40962
|
+
const Log$h = getLogger(exports.LoggerNames.DevicePool);
|
|
40641
40963
|
const getDiff = (current, descriptors) => {
|
|
40642
40964
|
const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
|
|
40643
40965
|
const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
|
|
@@ -40689,12 +41011,13 @@ class DevicePool extends events.exports {
|
|
|
40689
41011
|
const exist = descriptorList.find(d => d.path === device.originalDescriptor.path);
|
|
40690
41012
|
if (exist) {
|
|
40691
41013
|
device.updateDescriptor(exist, true);
|
|
41014
|
+
yield this._refreshRuntimeState(device, initOptions);
|
|
40692
41015
|
devices[connectId] = device;
|
|
40693
41016
|
deviceList.push(device);
|
|
40694
41017
|
yield this._checkDevicePool(initOptions, connectId);
|
|
40695
41018
|
return { devices, deviceList };
|
|
40696
41019
|
}
|
|
40697
|
-
Log$
|
|
41020
|
+
Log$h.debug('found device in cache, but path is different: ', connectId);
|
|
40698
41021
|
}
|
|
40699
41022
|
}
|
|
40700
41023
|
const matchedDescriptor = connectId
|
|
@@ -40742,12 +41065,38 @@ class DevicePool extends events.exports {
|
|
|
40742
41065
|
device = Device.fromDescriptor(descriptor);
|
|
40743
41066
|
device.deviceConnector = this.connector;
|
|
40744
41067
|
yield device.connect(initOptions === null || initOptions === void 0 ? void 0 : initOptions.connectProtocol);
|
|
40745
|
-
|
|
40746
|
-
|
|
41068
|
+
try {
|
|
41069
|
+
yield device.initialize(initOptions);
|
|
41070
|
+
if ((initOptions === null || initOptions === void 0 ? void 0 : initOptions.refreshRuntimeState) && device.isProtocolV2()) {
|
|
41071
|
+
yield device.getDeviceState({ refreshSections: ['status'] });
|
|
41072
|
+
}
|
|
41073
|
+
}
|
|
41074
|
+
finally {
|
|
41075
|
+
yield device.release();
|
|
41076
|
+
}
|
|
40747
41077
|
}
|
|
40748
41078
|
return device;
|
|
40749
41079
|
});
|
|
40750
41080
|
}
|
|
41081
|
+
static _refreshRuntimeState(device, initOptions) {
|
|
41082
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41083
|
+
if (!(initOptions === null || initOptions === void 0 ? void 0 : initOptions.refreshRuntimeState) || !device.isProtocolV2())
|
|
41084
|
+
return;
|
|
41085
|
+
let refreshError;
|
|
41086
|
+
yield device.run(() => __awaiter(this, void 0, void 0, function* () {
|
|
41087
|
+
try {
|
|
41088
|
+
yield device.getDeviceState({ refreshSections: ['status'] });
|
|
41089
|
+
}
|
|
41090
|
+
catch (error) {
|
|
41091
|
+
refreshError = error;
|
|
41092
|
+
}
|
|
41093
|
+
}), { connectProtocol: initOptions.connectProtocol });
|
|
41094
|
+
if (refreshError instanceof Error)
|
|
41095
|
+
throw refreshError;
|
|
41096
|
+
if (refreshError)
|
|
41097
|
+
throw new Error(String(refreshError));
|
|
41098
|
+
});
|
|
41099
|
+
}
|
|
40751
41100
|
static _checkDevicePool(initOptions, connectId) {
|
|
40752
41101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40753
41102
|
yield this._sendConnectMessage(initOptions, connectId);
|
|
@@ -40758,21 +41107,21 @@ class DevicePool extends events.exports {
|
|
|
40758
41107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40759
41108
|
for (let i = this.connectedPool.length - 1; i >= 0; i--) {
|
|
40760
41109
|
const descriptor = this.connectedPool[i];
|
|
40761
|
-
if (connectId
|
|
40762
|
-
|
|
41110
|
+
if (!connectId || descriptor.path === connectId) {
|
|
41111
|
+
const device = yield this._createDevice(descriptor, initOptions);
|
|
41112
|
+
Log$h.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
|
|
41113
|
+
this.emitter.emit(DEVICE.CONNECT, device);
|
|
41114
|
+
this.connectedPool.splice(i, 1);
|
|
40763
41115
|
}
|
|
40764
|
-
const device = yield this._createDevice(descriptor, initOptions);
|
|
40765
|
-
Log$g.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
|
|
40766
|
-
this.emitter.emit(DEVICE.CONNECT, device);
|
|
40767
|
-
this.connectedPool.splice(i, 1);
|
|
40768
41116
|
}
|
|
40769
41117
|
});
|
|
40770
41118
|
}
|
|
40771
41119
|
static _sendDisconnectMessage() {
|
|
40772
41120
|
for (let i = this.disconnectPool.length - 1; i >= 0; i--) {
|
|
40773
|
-
const descriptor = this.
|
|
41121
|
+
const descriptor = this.disconnectPool[i];
|
|
40774
41122
|
const device = (descriptor === null || descriptor === void 0 ? void 0 : descriptor.path) ? this.getDeviceByPath(descriptor.path) : null;
|
|
40775
41123
|
if (device) {
|
|
41124
|
+
device.markTransportDisconnected();
|
|
40776
41125
|
this.emitter.emit(DEVICE.DISCONNECT, device);
|
|
40777
41126
|
}
|
|
40778
41127
|
this.disconnectPool.splice(i, 1);
|
|
@@ -40782,9 +41131,9 @@ class DevicePool extends events.exports {
|
|
|
40782
41131
|
const diff = getDiff(this.current || [], upcoming);
|
|
40783
41132
|
this.upcoming = upcoming;
|
|
40784
41133
|
this.current = this.upcoming;
|
|
40785
|
-
Log$
|
|
40786
|
-
Log$
|
|
40787
|
-
Log$
|
|
41134
|
+
Log$h.debug('device pool -> current: ', this.current);
|
|
41135
|
+
Log$h.debug('device pool -> upcomming: ', this.upcoming);
|
|
41136
|
+
Log$h.debug('DeviceCache.reportDeviceChange diff: ', diff);
|
|
40788
41137
|
if (!diff.didUpdate) {
|
|
40789
41138
|
return;
|
|
40790
41139
|
}
|
|
@@ -40794,7 +41143,7 @@ class DevicePool extends events.exports {
|
|
|
40794
41143
|
this._addConnectedDeviceToPool(d);
|
|
40795
41144
|
return;
|
|
40796
41145
|
}
|
|
40797
|
-
Log$
|
|
41146
|
+
Log$h.debug('emit DEVICE.CONNECT: ', device.features);
|
|
40798
41147
|
this.emitter.emit(DEVICE.CONNECT, device);
|
|
40799
41148
|
});
|
|
40800
41149
|
diff.disconnected.forEach(d => {
|
|
@@ -40804,7 +41153,8 @@ class DevicePool extends events.exports {
|
|
|
40804
41153
|
this._addDisconnectedDeviceToPool(d);
|
|
40805
41154
|
return;
|
|
40806
41155
|
}
|
|
40807
|
-
Log$
|
|
41156
|
+
Log$h.debug('emit DEVICE.DISCONNECT: ', device.features);
|
|
41157
|
+
device.markTransportDisconnected();
|
|
40808
41158
|
this.emitter.emit(DEVICE.DISCONNECT, device);
|
|
40809
41159
|
});
|
|
40810
41160
|
}
|
|
@@ -40840,7 +41190,7 @@ class DevicePool extends events.exports {
|
|
|
40840
41190
|
this.disconnectPool = [];
|
|
40841
41191
|
this.devicesCache = {};
|
|
40842
41192
|
this.emitter.removeAllListeners();
|
|
40843
|
-
Log$
|
|
41193
|
+
Log$h.debug('DevicePool state has been reset');
|
|
40844
41194
|
}
|
|
40845
41195
|
}
|
|
40846
41196
|
DevicePool.current = null;
|
|
@@ -40850,7 +41200,7 @@ DevicePool.disconnectPool = [];
|
|
|
40850
41200
|
DevicePool.devicesCache = {};
|
|
40851
41201
|
DevicePool.emitter = new events.exports();
|
|
40852
41202
|
|
|
40853
|
-
const Log$
|
|
41203
|
+
const Log$g = getLogger(exports.LoggerNames.Transport);
|
|
40854
41204
|
const BleLogger = getLogger(exports.LoggerNames.HdBleTransport);
|
|
40855
41205
|
const HttpLogger = getLogger(exports.LoggerNames.HdTransportHttp);
|
|
40856
41206
|
const LowLevelLogger = getLogger(exports.LoggerNames.HdTransportLowLevel);
|
|
@@ -40860,7 +41210,7 @@ const WebUsbLogger = getLogger(exports.LoggerNames.HdTransportWebUsb);
|
|
|
40860
41210
|
const REACT_NATIVE_BLE_SCAN_TIMEOUT_MS = 8000;
|
|
40861
41211
|
class TransportManager {
|
|
40862
41212
|
static load() {
|
|
40863
|
-
Log$
|
|
41213
|
+
Log$g.debug('transport manager load');
|
|
40864
41214
|
this.defaultMessages = DataManager.getProtobufMessages();
|
|
40865
41215
|
this.currentMessages = this.defaultMessages;
|
|
40866
41216
|
this.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
@@ -40869,14 +41219,14 @@ class TransportManager {
|
|
|
40869
41219
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40870
41220
|
try {
|
|
40871
41221
|
const env = DataManager.getSettings('env');
|
|
40872
|
-
Log$
|
|
41222
|
+
Log$g.debug('Initializing transports', env);
|
|
40873
41223
|
if (env === 'react-native') {
|
|
40874
41224
|
if (!this.reactNativeInit) {
|
|
40875
41225
|
yield this.transport.init(BleLogger, DevicePool.emitter);
|
|
40876
41226
|
this.reactNativeInit = true;
|
|
40877
41227
|
}
|
|
40878
41228
|
else {
|
|
40879
|
-
Log$
|
|
41229
|
+
Log$g.debug('React Native Do Not Initializing transports');
|
|
40880
41230
|
}
|
|
40881
41231
|
}
|
|
40882
41232
|
else if (env === 'node-usb') {
|
|
@@ -40897,15 +41247,15 @@ class TransportManager {
|
|
|
40897
41247
|
else {
|
|
40898
41248
|
yield this.transport.init(HttpLogger);
|
|
40899
41249
|
}
|
|
40900
|
-
Log$
|
|
41250
|
+
Log$g.debug('Configuring transports');
|
|
40901
41251
|
yield this.transport.configure(JSON.stringify(this.defaultMessages));
|
|
40902
41252
|
this.currentMessages = this.defaultMessages;
|
|
40903
41253
|
this.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
40904
41254
|
yield this.configureProtocolV2Messages();
|
|
40905
|
-
Log$
|
|
41255
|
+
Log$g.debug('Configuring transports done');
|
|
40906
41256
|
}
|
|
40907
41257
|
catch (error) {
|
|
40908
|
-
Log$
|
|
41258
|
+
Log$g.debug('Initializing transports error: ', error);
|
|
40909
41259
|
if (error.code === 'ECONNABORTED') {
|
|
40910
41260
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
|
|
40911
41261
|
}
|
|
@@ -40921,7 +41271,7 @@ class TransportManager {
|
|
|
40921
41271
|
if (this.currentMessages === messages || !messages) {
|
|
40922
41272
|
return;
|
|
40923
41273
|
}
|
|
40924
|
-
Log$
|
|
41274
|
+
Log$g.debug(`Reconfiguring transports Protocol V1 schema:${protocolV1MessageSchema}`);
|
|
40925
41275
|
try {
|
|
40926
41276
|
yield this.transport.configure(JSON.stringify(messages));
|
|
40927
41277
|
this.currentMessages = messages;
|
|
@@ -40944,9 +41294,9 @@ class TransportManager {
|
|
|
40944
41294
|
}
|
|
40945
41295
|
if (plugin) {
|
|
40946
41296
|
this.plugin = plugin;
|
|
40947
|
-
Log$
|
|
41297
|
+
Log$g.debug('set transport plugin: ', this.plugin);
|
|
40948
41298
|
}
|
|
40949
|
-
Log$
|
|
41299
|
+
Log$g.debug('set transport: ', this.transport.name, this.transport.version, this.transport.configured);
|
|
40950
41300
|
}
|
|
40951
41301
|
static getTransport() {
|
|
40952
41302
|
return this.transport;
|
|
@@ -40957,7 +41307,7 @@ class TransportManager {
|
|
|
40957
41307
|
const { configureProtocolV2 } = this.transport;
|
|
40958
41308
|
if (protocolV2Messages && typeof configureProtocolV2 === 'function') {
|
|
40959
41309
|
yield configureProtocolV2.call(this.transport, JSON.stringify(protocolV2Messages));
|
|
40960
|
-
Log$
|
|
41310
|
+
Log$g.debug('Protocol V2 messages configured');
|
|
40961
41311
|
}
|
|
40962
41312
|
});
|
|
40963
41313
|
}
|
|
@@ -41135,7 +41485,7 @@ const cancelDeviceWithInitialize = (device) => {
|
|
|
41135
41485
|
},
|
|
41136
41486
|
}));
|
|
41137
41487
|
};
|
|
41138
|
-
const Log$
|
|
41488
|
+
const Log$f = getLogger(exports.LoggerNames.DeviceCommands);
|
|
41139
41489
|
const LogCore = getLogger(exports.LoggerNames.Core);
|
|
41140
41490
|
class DeviceCommands {
|
|
41141
41491
|
constructor(device, mainId) {
|
|
@@ -41144,7 +41494,7 @@ class DeviceCommands {
|
|
|
41144
41494
|
this.transport = TransportManager.getTransport();
|
|
41145
41495
|
this.disposed = false;
|
|
41146
41496
|
this.instanceId = generateInstanceId('DeviceCommands', device.sdkInstanceId);
|
|
41147
|
-
Log$
|
|
41497
|
+
Log$f.debug(`[DeviceCommands] Created: ${this.instanceId}, device: ${this.device.instanceId}`);
|
|
41148
41498
|
}
|
|
41149
41499
|
dispose(_cancelRequest) {
|
|
41150
41500
|
var _a, _b;
|
|
@@ -41214,7 +41564,7 @@ class DeviceCommands {
|
|
|
41214
41564
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41215
41565
|
const shouldReduceDebug = shouldReduceDebugForCall(type);
|
|
41216
41566
|
if (!shouldReduceDebug) {
|
|
41217
|
-
Log$
|
|
41567
|
+
Log$f.debug('[DeviceCommands] [call] Sending', type);
|
|
41218
41568
|
}
|
|
41219
41569
|
try {
|
|
41220
41570
|
const promise = this.transport.call(this.mainId, type, msg !== null && msg !== void 0 ? msg : {}, options);
|
|
@@ -41249,7 +41599,7 @@ class DeviceCommands {
|
|
|
41249
41599
|
}
|
|
41250
41600
|
}
|
|
41251
41601
|
if (responseData) {
|
|
41252
|
-
Log$
|
|
41602
|
+
Log$f.debug('error response', responseData);
|
|
41253
41603
|
}
|
|
41254
41604
|
if (responseError === 'device disconnected during action') {
|
|
41255
41605
|
return { type: 'BridgeDeviceDisconnected', message: { error: responseError } };
|
|
@@ -41289,7 +41639,7 @@ class DeviceCommands {
|
|
|
41289
41639
|
'ResourceAck',
|
|
41290
41640
|
];
|
|
41291
41641
|
if (!skipTypes.includes(type) && msg) {
|
|
41292
|
-
Log$
|
|
41642
|
+
Log$f.debug('[DeviceCommands] [typedCall] Sending payload', type, sanitizeDebugPayload(msg));
|
|
41293
41643
|
}
|
|
41294
41644
|
}
|
|
41295
41645
|
catch (e) {
|
|
@@ -41300,10 +41650,10 @@ class DeviceCommands {
|
|
|
41300
41650
|
assertType(response, resType);
|
|
41301
41651
|
}
|
|
41302
41652
|
catch (error) {
|
|
41303
|
-
Log$
|
|
41653
|
+
Log$f.debug('DeviceCommands typedcall error: ', error);
|
|
41304
41654
|
if (error instanceof hdShared.HardwareError) {
|
|
41305
41655
|
if (error.errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError) {
|
|
41306
|
-
Log$
|
|
41656
|
+
Log$f.debug('[DeviceCommands] [typedCall] Unexpected response type', {
|
|
41307
41657
|
request: type,
|
|
41308
41658
|
expected: resType,
|
|
41309
41659
|
received: response.type,
|
|
@@ -41340,10 +41690,10 @@ class DeviceCommands {
|
|
|
41340
41690
|
if (shouldReduceDebugForCall(callType)) {
|
|
41341
41691
|
}
|
|
41342
41692
|
else if (DataManager.getSettings('env') === 'react-native') {
|
|
41343
|
-
Log$
|
|
41693
|
+
Log$f.debug('_filterCommonTypes: ', JSON.stringify(sanitizeDebugPayload(res)));
|
|
41344
41694
|
}
|
|
41345
41695
|
else {
|
|
41346
|
-
Log$
|
|
41696
|
+
Log$f.debug('_filterCommonTypes: ', sanitizeDebugPayload(res));
|
|
41347
41697
|
}
|
|
41348
41698
|
}
|
|
41349
41699
|
catch (error) {
|
|
@@ -41480,7 +41830,7 @@ class DeviceCommands {
|
|
|
41480
41830
|
reject(error);
|
|
41481
41831
|
});
|
|
41482
41832
|
const listenerCount = this.device.listenerCount(DEVICE.PIN);
|
|
41483
|
-
Log$
|
|
41833
|
+
Log$f.debug(`[${this.instanceId}] _promptPin called`, {
|
|
41484
41834
|
responseID: this.currentResponseID,
|
|
41485
41835
|
deviceInstanceId: this.device.instanceId,
|
|
41486
41836
|
listenerCount,
|
|
@@ -41556,6 +41906,722 @@ class DeviceCommands {
|
|
|
41556
41906
|
}
|
|
41557
41907
|
}
|
|
41558
41908
|
|
|
41909
|
+
function mergeDeviceFeaturesPatch(previous, patch) {
|
|
41910
|
+
let next = previous;
|
|
41911
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
41912
|
+
if (value !== undefined && !Object.is(previous[key], value)) {
|
|
41913
|
+
if (next === previous) {
|
|
41914
|
+
next = Object.assign({}, previous);
|
|
41915
|
+
}
|
|
41916
|
+
next[key] = value;
|
|
41917
|
+
}
|
|
41918
|
+
}
|
|
41919
|
+
return next;
|
|
41920
|
+
}
|
|
41921
|
+
|
|
41922
|
+
const isProtocolV2RomloaderDeviceInfo = (deviceInfo, deviceStatus) => {
|
|
41923
|
+
var _a, _b, _c;
|
|
41924
|
+
return !!deviceInfo &&
|
|
41925
|
+
deviceStatus == null &&
|
|
41926
|
+
((_a = deviceInfo.fw) === null || _a === void 0 ? void 0 : _a.romloader) != null &&
|
|
41927
|
+
((_b = deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.application) == null &&
|
|
41928
|
+
((_c = deviceInfo.fw) === null || _c === void 0 ? void 0 : _c.application_data) == null &&
|
|
41929
|
+
deviceInfo.coprocessor == null &&
|
|
41930
|
+
deviceInfo.se1 == null &&
|
|
41931
|
+
deviceInfo.se2 == null &&
|
|
41932
|
+
deviceInfo.se3 == null &&
|
|
41933
|
+
deviceInfo.se4 == null;
|
|
41934
|
+
};
|
|
41935
|
+
const isProtocolV2BootloaderDeviceInfo = (deviceInfo, deviceStatus) => {
|
|
41936
|
+
var _a, _b;
|
|
41937
|
+
return !!deviceInfo &&
|
|
41938
|
+
deviceStatus == null &&
|
|
41939
|
+
!isProtocolV2RomloaderDeviceInfo(deviceInfo, deviceStatus) &&
|
|
41940
|
+
((_a = deviceInfo.fw) === null || _a === void 0 ? void 0 : _a.application) == null &&
|
|
41941
|
+
((_b = deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.application_data) == null;
|
|
41942
|
+
};
|
|
41943
|
+
const isProtocolV2LoaderDeviceInfo = (deviceInfo, deviceStatus) => isProtocolV2RomloaderDeviceInfo(deviceInfo, deviceStatus) ||
|
|
41944
|
+
isProtocolV2BootloaderDeviceInfo(deviceInfo, deviceStatus);
|
|
41945
|
+
const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
|
|
41946
|
+
targets: {
|
|
41947
|
+
hw: true,
|
|
41948
|
+
fw: true,
|
|
41949
|
+
coprocessor: true,
|
|
41950
|
+
},
|
|
41951
|
+
types: {
|
|
41952
|
+
version: true,
|
|
41953
|
+
specific: true,
|
|
41954
|
+
},
|
|
41955
|
+
};
|
|
41956
|
+
const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
|
|
41957
|
+
targets: {
|
|
41958
|
+
hw: true,
|
|
41959
|
+
fw: true,
|
|
41960
|
+
coprocessor: true,
|
|
41961
|
+
se1: true,
|
|
41962
|
+
se2: true,
|
|
41963
|
+
se3: true,
|
|
41964
|
+
se4: true,
|
|
41965
|
+
},
|
|
41966
|
+
types: {
|
|
41967
|
+
version: true,
|
|
41968
|
+
specific: true,
|
|
41969
|
+
},
|
|
41970
|
+
};
|
|
41971
|
+
const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
|
|
41972
|
+
targets: {
|
|
41973
|
+
hw: true,
|
|
41974
|
+
fw: true,
|
|
41975
|
+
coprocessor: true,
|
|
41976
|
+
se1: true,
|
|
41977
|
+
se2: true,
|
|
41978
|
+
se3: true,
|
|
41979
|
+
se4: true,
|
|
41980
|
+
},
|
|
41981
|
+
types: {
|
|
41982
|
+
version: true,
|
|
41983
|
+
build_id: true,
|
|
41984
|
+
hash: true,
|
|
41985
|
+
specific: true,
|
|
41986
|
+
},
|
|
41987
|
+
};
|
|
41988
|
+
const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS = 10 * 1000;
|
|
41989
|
+
function requestProtocolV2DeviceInfo({ commands, timeoutMs = PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS, request = PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST, }) {
|
|
41990
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41991
|
+
const { message } = yield commands.typedCall('DeviceInfoGet', 'DeviceInfo', request, {
|
|
41992
|
+
timeoutMs,
|
|
41993
|
+
});
|
|
41994
|
+
return message;
|
|
41995
|
+
});
|
|
41996
|
+
}
|
|
41997
|
+
function requestProtocolV2DeviceStatus({ commands, }) {
|
|
41998
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41999
|
+
const { message } = yield commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
|
|
42000
|
+
return message;
|
|
42001
|
+
});
|
|
42002
|
+
}
|
|
42003
|
+
|
|
42004
|
+
const firstMeaningfulVersion = (...versions) => { var _a; return (_a = versions.find(version => Boolean(version && version !== '0.0.0'))) !== null && _a !== void 0 ? _a : null; };
|
|
42005
|
+
const versionFromParts = (major, minor, patch) => [major, minor, patch].map(part => Number(part) || 0).join('.');
|
|
42006
|
+
const getProtocolV1Mode = (features) => {
|
|
42007
|
+
if (features.bootloader_mode === true)
|
|
42008
|
+
return 'bootloader';
|
|
42009
|
+
if (features.initialized === false)
|
|
42010
|
+
return 'notInitialized';
|
|
42011
|
+
if (features.no_backup === true)
|
|
42012
|
+
return 'backupMode';
|
|
42013
|
+
return 'normal';
|
|
42014
|
+
};
|
|
42015
|
+
const getProtocolV1DeviceType = (features) => {
|
|
42016
|
+
const onekeyDeviceType = features.onekey_device_type;
|
|
42017
|
+
switch (onekeyDeviceType) {
|
|
42018
|
+
case 'CLASSIC':
|
|
42019
|
+
return hdShared.EDeviceType.Classic;
|
|
42020
|
+
case 'CLASSIC1S':
|
|
42021
|
+
return hdShared.EDeviceType.Classic1s;
|
|
42022
|
+
case 'MINI':
|
|
42023
|
+
return hdShared.EDeviceType.Mini;
|
|
42024
|
+
case 'TOUCH':
|
|
42025
|
+
return hdShared.EDeviceType.Touch;
|
|
42026
|
+
case 'PRO':
|
|
42027
|
+
return hdShared.EDeviceType.Pro;
|
|
42028
|
+
case 'PRO2':
|
|
42029
|
+
case 'pro2':
|
|
42030
|
+
return hdShared.EDeviceType.Pro2;
|
|
42031
|
+
case 'PURE':
|
|
42032
|
+
return hdShared.EDeviceType.ClassicPure;
|
|
42033
|
+
}
|
|
42034
|
+
const serialNo = features.onekey_serial_no || features.onekey_serial || features.serial_no || '';
|
|
42035
|
+
const prefix = serialNo.slice(0, 2).toLowerCase();
|
|
42036
|
+
if (prefix === 'bi' || prefix === 'cl')
|
|
42037
|
+
return hdShared.EDeviceType.Classic;
|
|
42038
|
+
if (prefix === 'cp')
|
|
42039
|
+
return hdShared.EDeviceType.ClassicPure;
|
|
42040
|
+
if (prefix === 'mi')
|
|
42041
|
+
return hdShared.EDeviceType.Mini;
|
|
42042
|
+
if (prefix === 'tc')
|
|
42043
|
+
return hdShared.EDeviceType.Touch;
|
|
42044
|
+
if (prefix === 'pr')
|
|
42045
|
+
return hdShared.EDeviceType.Pro;
|
|
42046
|
+
if (prefix === 'p2')
|
|
42047
|
+
return hdShared.EDeviceType.Pro2;
|
|
42048
|
+
if (!serialNo && features.bootloader_mode === true && features.model === '1') {
|
|
42049
|
+
return hdShared.EDeviceType.Classic;
|
|
42050
|
+
}
|
|
42051
|
+
return hdShared.EDeviceType.Unknown;
|
|
42052
|
+
};
|
|
42053
|
+
const getProtocolV1FirmwareType = (features) => {
|
|
42054
|
+
if (features.fw_vendor === 'OneKey Bitcoin-only')
|
|
42055
|
+
return hdShared.EFirmwareType.BitcoinOnly;
|
|
42056
|
+
const capabilities = features.capabilities;
|
|
42057
|
+
if ((capabilities === null || capabilities === void 0 ? void 0 : capabilities.length) &&
|
|
42058
|
+
!capabilities.includes(hdTransport.Enum_Capability.Capability_Bitcoin_like) &&
|
|
42059
|
+
!capabilities.includes('Capability_Bitcoin_like')) {
|
|
42060
|
+
return hdShared.EFirmwareType.BitcoinOnly;
|
|
42061
|
+
}
|
|
42062
|
+
return hdShared.EFirmwareType.Universal;
|
|
42063
|
+
};
|
|
42064
|
+
const getProtocolV1Label = (features) => typeof features.label === 'string' && features.label.length > 0 ? features.label : null;
|
|
42065
|
+
const buildProtocolV1FeaturesPayload = (protocolV1Features, previous) => {
|
|
42066
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70;
|
|
42067
|
+
const features = protocolV1Features;
|
|
42068
|
+
const firmwareVersion = firstMeaningfulVersion(features.onekey_firmware_version, features.onekey_version, versionFromParts(features.major_version, features.minor_version, features.patch_version), previous === null || previous === void 0 ? void 0 : previous.firmwareVersion);
|
|
42069
|
+
const bootloaderVersion = firstMeaningfulVersion(features.onekey_boot_version, features.bootloader_version, features.bootloader_mode
|
|
42070
|
+
? versionFromParts(features.major_version, features.minor_version, features.patch_version)
|
|
42071
|
+
: null, previous === null || previous === void 0 ? void 0 : previous.bootloaderVersion);
|
|
42072
|
+
const boardVersion = firstMeaningfulVersion(features.onekey_board_version, features.boardloader_version, previous === null || previous === void 0 ? void 0 : previous.boardVersion);
|
|
42073
|
+
const bleVersion = firstMeaningfulVersion(features.onekey_ble_version, features.ble_ver, previous === null || previous === void 0 ? void 0 : previous.bleVersion);
|
|
42074
|
+
const serialNo = features.onekey_serial_no || features.onekey_serial || features.serial_no || '';
|
|
42075
|
+
const bleName = features.onekey_ble_name || features.ble_name || null;
|
|
42076
|
+
const deviceType = getProtocolV1DeviceType(features);
|
|
42077
|
+
const sessionId = (_b = (_a = features.session_id) !== null && _a !== void 0 ? _a : previous === null || previous === void 0 ? void 0 : previous.sessionId) !== null && _b !== void 0 ? _b : null;
|
|
42078
|
+
return Object.assign(Object.assign({}, features), { protocol: 'V1', protocolVersion: (_d = (_c = features.protocol_version) !== null && _c !== void 0 ? _c : previous === null || previous === void 0 ? void 0 : previous.protocolVersion) !== null && _d !== void 0 ? _d : 1, deviceType, firmwareType: getProtocolV1FirmwareType(features), model: (_e = features.model) !== null && _e !== void 0 ? _e : null, vendor: (_f = features.vendor) !== null && _f !== void 0 ? _f : null, deviceId: (_g = features.device_id) !== null && _g !== void 0 ? _g : null, serialNo, label: getProtocolV1Label(features), bleName, capabilities: (_h = features.capabilities) !== null && _h !== void 0 ? _h : [], mode: getProtocolV1Mode(features), initialized: (_j = features.initialized) !== null && _j !== void 0 ? _j : null, bootloaderMode: (_k = features.bootloader_mode) !== null && _k !== void 0 ? _k : null, unlocked: (_l = features.unlocked) !== null && _l !== void 0 ? _l : true, firmwarePresent: (_m = features.firmware_present) !== null && _m !== void 0 ? _m : null, passphraseProtection: (_o = features.passphrase_protection) !== null && _o !== void 0 ? _o : null, pinProtection: (_p = features.pin_protection) !== null && _p !== void 0 ? _p : null, backupRequired: (_q = features.needs_backup) !== null && _q !== void 0 ? _q : null, noBackup: (_r = features.no_backup) !== null && _r !== void 0 ? _r : null, unfinishedBackup: (_s = features.unfinished_backup) !== null && _s !== void 0 ? _s : null, recoveryMode: (_t = features.recovery_mode) !== null && _t !== void 0 ? _t : null, language: (_u = features.language) !== null && _u !== void 0 ? _u : null, bleEnabled: (_v = features.ble_enable) !== null && _v !== void 0 ? _v : null, sdCardPresent: (_w = features.sd_card_present) !== null && _w !== void 0 ? _w : null, sdProtection: (_x = features.sd_protection) !== null && _x !== void 0 ? _x : null, wipeCodeProtection: (_y = features.wipe_code_protection) !== null && _y !== void 0 ? _y : null, passphraseAlwaysOnDevice: (_z = features.passphrase_always_on_device) !== null && _z !== void 0 ? _z : null, attachToPinEnabled: (_1 = (_0 = features.attach_to_pin_user) !== null && _0 !== void 0 ? _0 : previous === null || previous === void 0 ? void 0 : previous.attachToPinEnabled) !== null && _1 !== void 0 ? _1 : null, unlockedAttachPin: (_3 = (_2 = features.unlocked_attach_pin) !== null && _2 !== void 0 ? _2 : previous === null || previous === void 0 ? void 0 : previous.unlockedAttachPin) !== null && _3 !== void 0 ? _3 : undefined, safetyChecks: (_4 = features.safety_checks) !== null && _4 !== void 0 ? _4 : null, autoLockDelayMs: (_5 = features.auto_lock_delay_ms) !== null && _5 !== void 0 ? _5 : null, autoShutdownDelayMs: (_6 = features.auto_shutdown_delay_ms) !== null && _6 !== void 0 ? _6 : null, displayRotation: (_7 = features.display_rotation) !== null && _7 !== void 0 ? _7 : null, experimentalFeatures: (_8 = features.experimental_features) !== null && _8 !== void 0 ? _8 : null, wallpaperPath: (_9 = previous === null || previous === void 0 ? void 0 : previous.wallpaperPath) !== null && _9 !== void 0 ? _9 : null, brightness: (_11 = (_10 = features.brightness_prcent) !== null && _10 !== void 0 ? _10 : previous === null || previous === void 0 ? void 0 : previous.brightness) !== null && _11 !== void 0 ? _11 : null, animationEnabled: (_12 = previous === null || previous === void 0 ? void 0 : previous.animationEnabled) !== null && _12 !== void 0 ? _12 : null, tapToWake: (_13 = previous === null || previous === void 0 ? void 0 : previous.tapToWake) !== null && _13 !== void 0 ? _13 : null, hapticFeedback: (_15 = (_14 = features.haptic_feedback) !== null && _14 !== void 0 ? _14 : previous === null || previous === void 0 ? void 0 : previous.hapticFeedback) !== null && _15 !== void 0 ? _15 : null, deviceNameDisplayEnabled: (_16 = previous === null || previous === void 0 ? void 0 : previous.deviceNameDisplayEnabled) !== null && _16 !== void 0 ? _16 : null, airgapMode: (_17 = previous === null || previous === void 0 ? void 0 : previous.airgapMode) !== null && _17 !== void 0 ? _17 : null, fidoEnabled: (_18 = previous === null || previous === void 0 ? void 0 : previous.fidoEnabled) !== null && _18 !== void 0 ? _18 : null, usbLockEnabled: (_19 = previous === null || previous === void 0 ? void 0 : previous.usbLockEnabled) !== null && _19 !== void 0 ? _19 : null, randomKeypad: (_20 = previous === null || previous === void 0 ? void 0 : previous.randomKeypad) !== null && _20 !== void 0 ? _20 : null, firmwareVersion,
|
|
42079
|
+
bootloaderVersion,
|
|
42080
|
+
boardVersion,
|
|
42081
|
+
bleVersion, se01Version: firstMeaningfulVersion(features.onekey_se01_version, previous === null || previous === void 0 ? void 0 : previous.se01Version), se02Version: firstMeaningfulVersion(features.onekey_se02_version, previous === null || previous === void 0 ? void 0 : previous.se02Version), se03Version: firstMeaningfulVersion(features.onekey_se03_version, previous === null || previous === void 0 ? void 0 : previous.se03Version), se04Version: firstMeaningfulVersion(features.onekey_se04_version, previous === null || previous === void 0 ? void 0 : previous.se04Version), se01BootVersion: firstMeaningfulVersion(features.onekey_se01_boot_version, previous === null || previous === void 0 ? void 0 : previous.se01BootVersion), se02BootVersion: firstMeaningfulVersion(features.onekey_se02_boot_version, previous === null || previous === void 0 ? void 0 : previous.se02BootVersion), se03BootVersion: firstMeaningfulVersion(features.onekey_se03_boot_version, previous === null || previous === void 0 ? void 0 : previous.se03BootVersion), se04BootVersion: firstMeaningfulVersion(features.onekey_se04_boot_version, previous === null || previous === void 0 ? void 0 : previous.se04BootVersion), seVersion: (_22 = (_21 = features.se_ver) !== null && _21 !== void 0 ? _21 : previous === null || previous === void 0 ? void 0 : previous.seVersion) !== null && _22 !== void 0 ? _22 : null, verify: {
|
|
42082
|
+
firmwareBuildId: (_23 = features.onekey_firmware_build_id) !== null && _23 !== void 0 ? _23 : (_24 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _24 === void 0 ? void 0 : _24.firmwareBuildId,
|
|
42083
|
+
firmwareHash: (_25 = features.onekey_firmware_hash) !== null && _25 !== void 0 ? _25 : (_26 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _26 === void 0 ? void 0 : _26.firmwareHash,
|
|
42084
|
+
bootloaderBuildId: (_27 = features.onekey_boot_build_id) !== null && _27 !== void 0 ? _27 : (_28 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _28 === void 0 ? void 0 : _28.bootloaderBuildId,
|
|
42085
|
+
bootloaderHash: (_29 = features.onekey_boot_hash) !== null && _29 !== void 0 ? _29 : (_30 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _30 === void 0 ? void 0 : _30.bootloaderHash,
|
|
42086
|
+
boardBuildId: (_31 = features.onekey_board_build_id) !== null && _31 !== void 0 ? _31 : (_32 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _32 === void 0 ? void 0 : _32.boardBuildId,
|
|
42087
|
+
boardHash: (_33 = features.onekey_board_hash) !== null && _33 !== void 0 ? _33 : (_34 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _34 === void 0 ? void 0 : _34.boardHash,
|
|
42088
|
+
bleBuildId: (_35 = features.onekey_ble_build_id) !== null && _35 !== void 0 ? _35 : (_36 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _36 === void 0 ? void 0 : _36.bleBuildId,
|
|
42089
|
+
bleHash: (_37 = features.onekey_ble_hash) !== null && _37 !== void 0 ? _37 : (_38 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _38 === void 0 ? void 0 : _38.bleHash,
|
|
42090
|
+
se01BuildId: (_39 = features.onekey_se01_build_id) !== null && _39 !== void 0 ? _39 : (_40 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _40 === void 0 ? void 0 : _40.se01BuildId,
|
|
42091
|
+
se01Hash: (_41 = features.onekey_se01_hash) !== null && _41 !== void 0 ? _41 : (_42 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _42 === void 0 ? void 0 : _42.se01Hash,
|
|
42092
|
+
se02BuildId: (_43 = features.onekey_se02_build_id) !== null && _43 !== void 0 ? _43 : (_44 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _44 === void 0 ? void 0 : _44.se02BuildId,
|
|
42093
|
+
se02Hash: (_45 = features.onekey_se02_hash) !== null && _45 !== void 0 ? _45 : (_46 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _46 === void 0 ? void 0 : _46.se02Hash,
|
|
42094
|
+
se03BuildId: (_47 = features.onekey_se03_build_id) !== null && _47 !== void 0 ? _47 : (_48 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _48 === void 0 ? void 0 : _48.se03BuildId,
|
|
42095
|
+
se03Hash: (_49 = features.onekey_se03_hash) !== null && _49 !== void 0 ? _49 : (_50 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _50 === void 0 ? void 0 : _50.se03Hash,
|
|
42096
|
+
se04BuildId: (_51 = features.onekey_se04_build_id) !== null && _51 !== void 0 ? _51 : (_52 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _52 === void 0 ? void 0 : _52.se04BuildId,
|
|
42097
|
+
se04Hash: (_53 = features.onekey_se04_hash) !== null && _53 !== void 0 ? _53 : (_54 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _54 === void 0 ? void 0 : _54.se04Hash,
|
|
42098
|
+
se01BootBuildId: (_55 = features.onekey_se01_boot_build_id) !== null && _55 !== void 0 ? _55 : (_56 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _56 === void 0 ? void 0 : _56.se01BootBuildId,
|
|
42099
|
+
se01BootHash: (_57 = features.onekey_se01_boot_hash) !== null && _57 !== void 0 ? _57 : (_58 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _58 === void 0 ? void 0 : _58.se01BootHash,
|
|
42100
|
+
se02BootBuildId: (_59 = features.onekey_se02_boot_build_id) !== null && _59 !== void 0 ? _59 : (_60 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _60 === void 0 ? void 0 : _60.se02BootBuildId,
|
|
42101
|
+
se02BootHash: (_61 = features.onekey_se02_boot_hash) !== null && _61 !== void 0 ? _61 : (_62 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _62 === void 0 ? void 0 : _62.se02BootHash,
|
|
42102
|
+
se03BootBuildId: (_63 = features.onekey_se03_boot_build_id) !== null && _63 !== void 0 ? _63 : (_64 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _64 === void 0 ? void 0 : _64.se03BootBuildId,
|
|
42103
|
+
se03BootHash: (_65 = features.onekey_se03_boot_hash) !== null && _65 !== void 0 ? _65 : (_66 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _66 === void 0 ? void 0 : _66.se03BootHash,
|
|
42104
|
+
se04BootBuildId: (_67 = features.onekey_se04_boot_build_id) !== null && _67 !== void 0 ? _67 : (_68 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _68 === void 0 ? void 0 : _68.se04BootBuildId,
|
|
42105
|
+
se04BootHash: (_69 = features.onekey_se04_boot_hash) !== null && _69 !== void 0 ? _69 : (_70 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _70 === void 0 ? void 0 : _70.se04BootHash,
|
|
42106
|
+
}, sessionId, session_id: sessionId !== null && sessionId !== void 0 ? sessionId : undefined, raw: {
|
|
42107
|
+
protocolV1Features,
|
|
42108
|
+
} });
|
|
42109
|
+
};
|
|
42110
|
+
|
|
42111
|
+
const definedEntries = (value) => Object.fromEntries(Object.entries(value).filter(([, fieldValue]) => fieldValue !== undefined));
|
|
42112
|
+
const imageVersion = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.version) !== null && _a !== void 0 ? _a : undefined; };
|
|
42113
|
+
const bytesToHex$2 = (value) => {
|
|
42114
|
+
if (!value)
|
|
42115
|
+
return undefined;
|
|
42116
|
+
if (typeof value === 'string')
|
|
42117
|
+
return value;
|
|
42118
|
+
if (value instanceof Uint8Array || Array.isArray(value)) {
|
|
42119
|
+
return Array.from(value)
|
|
42120
|
+
.map(byte => Number(byte).toString(16).padStart(2, '0'))
|
|
42121
|
+
.join('');
|
|
42122
|
+
}
|
|
42123
|
+
return undefined;
|
|
42124
|
+
};
|
|
42125
|
+
const imageBuildId = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.build_id) !== null && _a !== void 0 ? _a : undefined; };
|
|
42126
|
+
const imageHash = (image) => bytesToHex$2(image === null || image === void 0 ? void 0 : image.hash);
|
|
42127
|
+
const getFeaturesMode = (features) => {
|
|
42128
|
+
if (features.mode !== undefined && features.mode !== null)
|
|
42129
|
+
return features.mode;
|
|
42130
|
+
if (features.bootloaderMode === true)
|
|
42131
|
+
return 'bootloader';
|
|
42132
|
+
if (features.initialized === false)
|
|
42133
|
+
return 'notInitialized';
|
|
42134
|
+
if (features.initialized === true)
|
|
42135
|
+
return 'normal';
|
|
42136
|
+
return undefined;
|
|
42137
|
+
};
|
|
42138
|
+
const getProtocolV2StatusMode = (initialized) => {
|
|
42139
|
+
if (initialized === false)
|
|
42140
|
+
return 'notInitialized';
|
|
42141
|
+
if (initialized === true)
|
|
42142
|
+
return 'normal';
|
|
42143
|
+
return undefined;
|
|
42144
|
+
};
|
|
42145
|
+
const mapFeaturesToState = (features) => {
|
|
42146
|
+
var _a, _b, _c;
|
|
42147
|
+
return ({
|
|
42148
|
+
protocol: features.protocol,
|
|
42149
|
+
protocolVersion: features.protocolVersion,
|
|
42150
|
+
identity: {
|
|
42151
|
+
deviceType: features.deviceType,
|
|
42152
|
+
firmwareType: features.firmwareType,
|
|
42153
|
+
model: features.model,
|
|
42154
|
+
vendor: features.vendor,
|
|
42155
|
+
deviceId: features.deviceId,
|
|
42156
|
+
serialNo: features.serialNo,
|
|
42157
|
+
label: features.label,
|
|
42158
|
+
bleName: features.bleName,
|
|
42159
|
+
},
|
|
42160
|
+
status: {
|
|
42161
|
+
mode: getFeaturesMode(features),
|
|
42162
|
+
initialized: features.initialized,
|
|
42163
|
+
unlocked: features.unlocked,
|
|
42164
|
+
firmwarePresent: features.firmwarePresent,
|
|
42165
|
+
backupRequired: features.backupRequired,
|
|
42166
|
+
noBackup: features.noBackup,
|
|
42167
|
+
unfinishedBackup: features.unfinishedBackup,
|
|
42168
|
+
recoveryMode: features.recoveryMode,
|
|
42169
|
+
passphraseProtection: features.passphraseProtection,
|
|
42170
|
+
pinProtection: features.pinProtection,
|
|
42171
|
+
attachToPinEnabled: (_a = features.attachToPinEnabled) !== null && _a !== void 0 ? _a : null,
|
|
42172
|
+
unlockedAttachPin: (_b = features.unlockedAttachPin) !== null && _b !== void 0 ? _b : null,
|
|
42173
|
+
},
|
|
42174
|
+
settings: {
|
|
42175
|
+
language: features.language,
|
|
42176
|
+
bleEnabled: features.bleEnabled,
|
|
42177
|
+
sdCardPresent: features.sdCardPresent,
|
|
42178
|
+
sdProtection: features.sdProtection,
|
|
42179
|
+
wipeCodeProtection: features.wipeCodeProtection,
|
|
42180
|
+
passphraseAlwaysOnDevice: features.passphraseAlwaysOnDevice,
|
|
42181
|
+
safetyChecks: features.safetyChecks,
|
|
42182
|
+
autoLockDelayMs: features.autoLockDelayMs,
|
|
42183
|
+
autoShutdownDelayMs: features.autoShutdownDelayMs,
|
|
42184
|
+
displayRotation: features.displayRotation,
|
|
42185
|
+
experimentalFeatures: features.experimentalFeatures,
|
|
42186
|
+
wallpaperPath: features.wallpaperPath,
|
|
42187
|
+
brightness: features.brightness,
|
|
42188
|
+
animationEnabled: features.animationEnabled,
|
|
42189
|
+
tapToWake: features.tapToWake,
|
|
42190
|
+
hapticFeedback: features.hapticFeedback,
|
|
42191
|
+
deviceNameDisplayEnabled: features.deviceNameDisplayEnabled,
|
|
42192
|
+
airgapMode: features.airgapMode,
|
|
42193
|
+
fidoEnabled: features.fidoEnabled,
|
|
42194
|
+
usbLockEnabled: features.usbLockEnabled,
|
|
42195
|
+
randomKeypad: features.randomKeypad,
|
|
42196
|
+
},
|
|
42197
|
+
versions: {
|
|
42198
|
+
firmware: features.firmwareVersion,
|
|
42199
|
+
bootloader: features.bootloaderVersion,
|
|
42200
|
+
board: features.boardVersion,
|
|
42201
|
+
ble: features.bleVersion,
|
|
42202
|
+
se: features.seVersion,
|
|
42203
|
+
se01: features.se01Version,
|
|
42204
|
+
se02: features.se02Version,
|
|
42205
|
+
se03: features.se03Version,
|
|
42206
|
+
se04: features.se04Version,
|
|
42207
|
+
se01Boot: features.se01BootVersion,
|
|
42208
|
+
se02Boot: features.se02BootVersion,
|
|
42209
|
+
se03Boot: features.se03BootVersion,
|
|
42210
|
+
se04Boot: features.se04BootVersion,
|
|
42211
|
+
},
|
|
42212
|
+
capabilities: features.capabilities,
|
|
42213
|
+
verification: definedEntries((_c = features.verify) !== null && _c !== void 0 ? _c : {}),
|
|
42214
|
+
session: {
|
|
42215
|
+
sessionId: features.sessionId,
|
|
42216
|
+
passphraseState: features.passphraseState,
|
|
42217
|
+
},
|
|
42218
|
+
raw: features.raw,
|
|
42219
|
+
});
|
|
42220
|
+
};
|
|
42221
|
+
const meaningfulVersion = (version) => {
|
|
42222
|
+
if (!version || version === '0.0.0')
|
|
42223
|
+
return undefined;
|
|
42224
|
+
const parts = version.split('.');
|
|
42225
|
+
while (parts.length < 3)
|
|
42226
|
+
parts.push('0');
|
|
42227
|
+
return parts.map(part => (Number.isNaN(Number.parseInt(part, 10)) ? '0' : part)).join('.');
|
|
42228
|
+
};
|
|
42229
|
+
const mapProtocolV1OnekeyFeaturesToState = (features) => {
|
|
42230
|
+
const verification = definedEntries({
|
|
42231
|
+
firmwareBuildId: features.onekey_firmware_build_id,
|
|
42232
|
+
firmwareHash: features.onekey_firmware_hash,
|
|
42233
|
+
bootloaderBuildId: features.onekey_boot_build_id,
|
|
42234
|
+
bootloaderHash: features.onekey_boot_hash,
|
|
42235
|
+
boardBuildId: features.onekey_board_build_id,
|
|
42236
|
+
boardHash: features.onekey_board_hash,
|
|
42237
|
+
bleBuildId: features.onekey_ble_build_id,
|
|
42238
|
+
bleHash: features.onekey_ble_hash,
|
|
42239
|
+
se01BuildId: features.onekey_se01_build_id,
|
|
42240
|
+
se01Hash: features.onekey_se01_hash,
|
|
42241
|
+
se02BuildId: features.onekey_se02_build_id,
|
|
42242
|
+
se02Hash: features.onekey_se02_hash,
|
|
42243
|
+
se03BuildId: features.onekey_se03_build_id,
|
|
42244
|
+
se03Hash: features.onekey_se03_hash,
|
|
42245
|
+
se04BuildId: features.onekey_se04_build_id,
|
|
42246
|
+
se04Hash: features.onekey_se04_hash,
|
|
42247
|
+
se01BootBuildId: features.onekey_se01_boot_build_id,
|
|
42248
|
+
se01BootHash: features.onekey_se01_boot_hash,
|
|
42249
|
+
se02BootBuildId: features.onekey_se02_boot_build_id,
|
|
42250
|
+
se02BootHash: features.onekey_se02_boot_hash,
|
|
42251
|
+
se03BootBuildId: features.onekey_se03_boot_build_id,
|
|
42252
|
+
se03BootHash: features.onekey_se03_boot_hash,
|
|
42253
|
+
se04BootBuildId: features.onekey_se04_boot_build_id,
|
|
42254
|
+
se04BootHash: features.onekey_se04_boot_hash,
|
|
42255
|
+
});
|
|
42256
|
+
return Object.assign(Object.assign({ versions: definedEntries({
|
|
42257
|
+
firmware: meaningfulVersion(features.onekey_firmware_version),
|
|
42258
|
+
bootloader: meaningfulVersion(features.onekey_boot_version),
|
|
42259
|
+
board: meaningfulVersion(features.onekey_board_version),
|
|
42260
|
+
ble: meaningfulVersion(features.onekey_ble_version),
|
|
42261
|
+
se01: meaningfulVersion(features.onekey_se01_version),
|
|
42262
|
+
se02: meaningfulVersion(features.onekey_se02_version),
|
|
42263
|
+
se03: meaningfulVersion(features.onekey_se03_version),
|
|
42264
|
+
se04: meaningfulVersion(features.onekey_se04_version),
|
|
42265
|
+
se01Boot: meaningfulVersion(features.onekey_se01_boot_version),
|
|
42266
|
+
se02Boot: meaningfulVersion(features.onekey_se02_boot_version),
|
|
42267
|
+
se03Boot: meaningfulVersion(features.onekey_se03_boot_version),
|
|
42268
|
+
se04Boot: meaningfulVersion(features.onekey_se04_boot_version),
|
|
42269
|
+
}) }, (Object.keys(verification).length > 0 ? { verification } : {})), { raw: { protocolV1OneKeyFeatures: features } });
|
|
42270
|
+
};
|
|
42271
|
+
const mapProtocolV2DeviceInfoToState = (info, currentMode) => {
|
|
42272
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13;
|
|
42273
|
+
const romloader = isProtocolV2RomloaderDeviceInfo(info);
|
|
42274
|
+
const bootloader = isProtocolV2BootloaderDeviceInfo(info);
|
|
42275
|
+
const loader = romloader || bootloader;
|
|
42276
|
+
let mode = 'normal';
|
|
42277
|
+
if (romloader) {
|
|
42278
|
+
mode = 'romloader';
|
|
42279
|
+
}
|
|
42280
|
+
else if (bootloader) {
|
|
42281
|
+
mode = 'bootloader';
|
|
42282
|
+
}
|
|
42283
|
+
else if (currentMode === 'notInitialized' || currentMode === 'backupMode') {
|
|
42284
|
+
mode = currentMode;
|
|
42285
|
+
}
|
|
42286
|
+
return {
|
|
42287
|
+
protocol: 'V2',
|
|
42288
|
+
protocolVersion: info.protocol_version,
|
|
42289
|
+
identity: definedEntries({
|
|
42290
|
+
deviceType: hdShared.EDeviceType.Pro2,
|
|
42291
|
+
firmwareType: hdShared.EFirmwareType.Universal,
|
|
42292
|
+
model: 'pro2',
|
|
42293
|
+
vendor: 'onekey.so',
|
|
42294
|
+
serialNo: (_a = info.hw) === null || _a === void 0 ? void 0 : _a.serial_no,
|
|
42295
|
+
bleName: (_b = info.coprocessor) === null || _b === void 0 ? void 0 : _b.bt_adv_name,
|
|
42296
|
+
deviceId: loader ? null : undefined,
|
|
42297
|
+
}),
|
|
42298
|
+
status: loader
|
|
42299
|
+
? {
|
|
42300
|
+
mode,
|
|
42301
|
+
initialized: null,
|
|
42302
|
+
unlocked: null,
|
|
42303
|
+
firmwarePresent: null,
|
|
42304
|
+
backupRequired: null,
|
|
42305
|
+
noBackup: null,
|
|
42306
|
+
unfinishedBackup: null,
|
|
42307
|
+
recoveryMode: null,
|
|
42308
|
+
passphraseProtection: null,
|
|
42309
|
+
pinProtection: null,
|
|
42310
|
+
attachToPinEnabled: null,
|
|
42311
|
+
unlockedAttachPin: null,
|
|
42312
|
+
}
|
|
42313
|
+
: { mode },
|
|
42314
|
+
versions: definedEntries({
|
|
42315
|
+
firmware: imageVersion((_c = info.fw) === null || _c === void 0 ? void 0 : _c.application),
|
|
42316
|
+
bootloader: imageVersion((_d = info.fw) === null || _d === void 0 ? void 0 : _d.bootloader),
|
|
42317
|
+
board: imageVersion((_e = info.fw) === null || _e === void 0 ? void 0 : _e.romloader),
|
|
42318
|
+
ble: imageVersion((_f = info.coprocessor) === null || _f === void 0 ? void 0 : _f.application),
|
|
42319
|
+
se01: imageVersion((_g = info.se1) === null || _g === void 0 ? void 0 : _g.application),
|
|
42320
|
+
se02: imageVersion((_h = info.se2) === null || _h === void 0 ? void 0 : _h.application),
|
|
42321
|
+
se03: imageVersion((_j = info.se3) === null || _j === void 0 ? void 0 : _j.application),
|
|
42322
|
+
se04: imageVersion((_k = info.se4) === null || _k === void 0 ? void 0 : _k.application),
|
|
42323
|
+
se01Boot: imageVersion((_l = info.se1) === null || _l === void 0 ? void 0 : _l.bootloader),
|
|
42324
|
+
se02Boot: imageVersion((_m = info.se2) === null || _m === void 0 ? void 0 : _m.bootloader),
|
|
42325
|
+
se03Boot: imageVersion((_o = info.se3) === null || _o === void 0 ? void 0 : _o.bootloader),
|
|
42326
|
+
se04Boot: imageVersion((_p = info.se4) === null || _p === void 0 ? void 0 : _p.bootloader),
|
|
42327
|
+
}),
|
|
42328
|
+
verification: definedEntries({
|
|
42329
|
+
firmwareBuildId: imageBuildId((_q = info.fw) === null || _q === void 0 ? void 0 : _q.application),
|
|
42330
|
+
firmwareHash: imageHash((_r = info.fw) === null || _r === void 0 ? void 0 : _r.application),
|
|
42331
|
+
bootloaderBuildId: imageBuildId((_s = info.fw) === null || _s === void 0 ? void 0 : _s.bootloader),
|
|
42332
|
+
bootloaderHash: imageHash((_t = info.fw) === null || _t === void 0 ? void 0 : _t.bootloader),
|
|
42333
|
+
boardBuildId: imageBuildId((_u = info.fw) === null || _u === void 0 ? void 0 : _u.romloader),
|
|
42334
|
+
boardHash: imageHash((_v = info.fw) === null || _v === void 0 ? void 0 : _v.romloader),
|
|
42335
|
+
bleBuildId: imageBuildId((_w = info.coprocessor) === null || _w === void 0 ? void 0 : _w.application),
|
|
42336
|
+
bleHash: imageHash((_x = info.coprocessor) === null || _x === void 0 ? void 0 : _x.application),
|
|
42337
|
+
se01BuildId: imageBuildId((_y = info.se1) === null || _y === void 0 ? void 0 : _y.application),
|
|
42338
|
+
se01Hash: imageHash((_z = info.se1) === null || _z === void 0 ? void 0 : _z.application),
|
|
42339
|
+
se02BuildId: imageBuildId((_0 = info.se2) === null || _0 === void 0 ? void 0 : _0.application),
|
|
42340
|
+
se02Hash: imageHash((_1 = info.se2) === null || _1 === void 0 ? void 0 : _1.application),
|
|
42341
|
+
se03BuildId: imageBuildId((_2 = info.se3) === null || _2 === void 0 ? void 0 : _2.application),
|
|
42342
|
+
se03Hash: imageHash((_3 = info.se3) === null || _3 === void 0 ? void 0 : _3.application),
|
|
42343
|
+
se04BuildId: imageBuildId((_4 = info.se4) === null || _4 === void 0 ? void 0 : _4.application),
|
|
42344
|
+
se04Hash: imageHash((_5 = info.se4) === null || _5 === void 0 ? void 0 : _5.application),
|
|
42345
|
+
se01BootBuildId: imageBuildId((_6 = info.se1) === null || _6 === void 0 ? void 0 : _6.bootloader),
|
|
42346
|
+
se01BootHash: imageHash((_7 = info.se1) === null || _7 === void 0 ? void 0 : _7.bootloader),
|
|
42347
|
+
se02BootBuildId: imageBuildId((_8 = info.se2) === null || _8 === void 0 ? void 0 : _8.bootloader),
|
|
42348
|
+
se02BootHash: imageHash((_9 = info.se2) === null || _9 === void 0 ? void 0 : _9.bootloader),
|
|
42349
|
+
se03BootBuildId: imageBuildId((_10 = info.se3) === null || _10 === void 0 ? void 0 : _10.bootloader),
|
|
42350
|
+
se03BootHash: imageHash((_11 = info.se3) === null || _11 === void 0 ? void 0 : _11.bootloader),
|
|
42351
|
+
se04BootBuildId: imageBuildId((_12 = info.se4) === null || _12 === void 0 ? void 0 : _12.bootloader),
|
|
42352
|
+
se04BootHash: imageHash((_13 = info.se4) === null || _13 === void 0 ? void 0 : _13.bootloader),
|
|
42353
|
+
}),
|
|
42354
|
+
raw: Object.assign({ protocolV2DeviceInfo: info }, (loader ? { protocolV2DeviceStatus: null } : {})),
|
|
42355
|
+
};
|
|
42356
|
+
};
|
|
42357
|
+
const mapProtocolV2DeviceStatusToState = (status) => {
|
|
42358
|
+
var _a;
|
|
42359
|
+
return ({
|
|
42360
|
+
identity: definedEntries({ deviceId: status.device_id }),
|
|
42361
|
+
status: definedEntries({
|
|
42362
|
+
mode: getProtocolV2StatusMode(status.init_states),
|
|
42363
|
+
initialized: status.init_states,
|
|
42364
|
+
unlocked: status.unlocked,
|
|
42365
|
+
passphraseProtection: status.unlocked === true ? (_a = status.passphrase_enabled) !== null && _a !== void 0 ? _a : null : undefined,
|
|
42366
|
+
backupRequired: status.backup_required,
|
|
42367
|
+
attachToPinEnabled: status.attach_to_pin_enabled,
|
|
42368
|
+
unlockedAttachPin: status.unlocked_by_attach_to_pin,
|
|
42369
|
+
}),
|
|
42370
|
+
raw: { protocolV2DeviceStatus: status },
|
|
42371
|
+
});
|
|
42372
|
+
};
|
|
42373
|
+
const mapApplySettingsToState = (settings) => {
|
|
42374
|
+
const identity = definedEntries({ label: settings.label });
|
|
42375
|
+
const status = definedEntries({ passphraseProtection: settings.use_passphrase });
|
|
42376
|
+
const stateSettings = definedEntries({
|
|
42377
|
+
language: settings.language,
|
|
42378
|
+
autoLockDelayMs: settings.auto_lock_delay_ms,
|
|
42379
|
+
autoShutdownDelayMs: settings.auto_shutdown_delay_ms,
|
|
42380
|
+
displayRotation: settings.display_rotation,
|
|
42381
|
+
passphraseAlwaysOnDevice: settings.passphrase_always_on_device,
|
|
42382
|
+
safetyChecks: settings.safety_checks,
|
|
42383
|
+
experimentalFeatures: settings.experimental_features,
|
|
42384
|
+
hapticFeedback: settings.haptic_feedback,
|
|
42385
|
+
});
|
|
42386
|
+
return Object.assign(Object.assign(Object.assign({}, (Object.keys(identity).length ? { identity } : {})), (Object.keys(status).length ? { status } : {})), (Object.keys(stateSettings).length ? { settings: stateSettings } : {}));
|
|
42387
|
+
};
|
|
42388
|
+
const mapDeviceSettingsToState = (settings) => {
|
|
42389
|
+
const settingsWithExperimental = settings;
|
|
42390
|
+
const identity = definedEntries({ label: settings.label });
|
|
42391
|
+
const status = definedEntries({ passphraseProtection: settings.passphrase_enable });
|
|
42392
|
+
const stateSettings = definedEntries({
|
|
42393
|
+
bleEnabled: settings.bt_enable,
|
|
42394
|
+
language: settings.language,
|
|
42395
|
+
wallpaperPath: settings.wallpaper_path,
|
|
42396
|
+
brightness: settings.brightness,
|
|
42397
|
+
autoLockDelayMs: settings.autolock_delay_ms,
|
|
42398
|
+
autoShutdownDelayMs: settings.autoshutdown_delay_ms,
|
|
42399
|
+
animationEnabled: settings.animation_enable,
|
|
42400
|
+
tapToWake: settings.tap_to_wake,
|
|
42401
|
+
hapticFeedback: settings.haptic_feedback,
|
|
42402
|
+
deviceNameDisplayEnabled: settings.device_name_display_enabled,
|
|
42403
|
+
airgapMode: settings.airgap_mode,
|
|
42404
|
+
fidoEnabled: settings.fido_enabled,
|
|
42405
|
+
experimentalFeatures: settingsWithExperimental.experimental_features,
|
|
42406
|
+
usbLockEnabled: settings.usb_lock_enable,
|
|
42407
|
+
randomKeypad: settings.random_keypad,
|
|
42408
|
+
});
|
|
42409
|
+
return Object.assign(Object.assign(Object.assign({}, (Object.keys(identity).length ? { identity } : {})), (Object.keys(status).length ? { status } : {})), (Object.keys(stateSettings).length ? { settings: stateSettings } : {}));
|
|
42410
|
+
};
|
|
42411
|
+
const mapCommonSettingsToProtocolV2 = (settings) => definedEntries({
|
|
42412
|
+
label: settings.label,
|
|
42413
|
+
bt_enable: settings.bluetoothEnabled,
|
|
42414
|
+
language: settings.language,
|
|
42415
|
+
brightness: settings.brightness,
|
|
42416
|
+
autolock_delay_ms: settings.autoLockDelayMs,
|
|
42417
|
+
autoshutdown_delay_ms: settings.autoShutdownDelayMs,
|
|
42418
|
+
animation_enable: settings.animationEnabled,
|
|
42419
|
+
tap_to_wake: settings.tapToWake,
|
|
42420
|
+
haptic_feedback: settings.hapticFeedback,
|
|
42421
|
+
device_name_display_enabled: settings.deviceNameDisplayEnabled,
|
|
42422
|
+
fido_enabled: settings.fidoEnabled,
|
|
42423
|
+
usb_lock_enable: settings.usbLockEnabled,
|
|
42424
|
+
random_keypad: settings.randomKeypad,
|
|
42425
|
+
});
|
|
42426
|
+
|
|
42427
|
+
const getBootloaderMode = (state) => state.status.mode === 'bootloader' || state.status.mode === 'romloader';
|
|
42428
|
+
const projectFeatures = (state) => {
|
|
42429
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
42430
|
+
const snapshot = structuredClone(state);
|
|
42431
|
+
const rawFeatures = (_b = (_a = snapshot.raw) === null || _a === void 0 ? void 0 : _a.protocolV1Features) !== null && _b !== void 0 ? _b : {};
|
|
42432
|
+
const rawOneKeyFeatures = (_d = (_c = snapshot.raw) === null || _c === void 0 ? void 0 : _c.protocolV1OneKeyFeatures) !== null && _d !== void 0 ? _d : {};
|
|
42433
|
+
const sessionId = (_f = (_e = snapshot.session) === null || _e === void 0 ? void 0 : _e.sessionId) !== null && _f !== void 0 ? _f : null;
|
|
42434
|
+
const bootloaderMode = snapshot.protocol === 'V1'
|
|
42435
|
+
? (_g = rawFeatures.bootloader_mode) !== null && _g !== void 0 ? _g : null
|
|
42436
|
+
: getBootloaderMode(snapshot);
|
|
42437
|
+
return Object.assign(Object.assign(Object.assign({}, rawFeatures), rawOneKeyFeatures), { protocol: snapshot.protocol, protocolVersion: (_h = snapshot.protocolVersion) !== null && _h !== void 0 ? _h : (snapshot.protocol === 'V1' ? 1 : null), deviceType: snapshot.identity.deviceType, firmwareType: snapshot.identity.firmwareType, model: snapshot.identity.model, vendor: snapshot.identity.vendor, deviceId: snapshot.identity.deviceId, serialNo: snapshot.identity.serialNo, label: snapshot.identity.label, bleName: snapshot.identity.bleName, capabilities: snapshot.capabilities, mode: snapshot.status.mode, initialized: snapshot.status.initialized, bootloaderMode, unlocked: snapshot.status.unlocked, firmwarePresent: snapshot.status.firmwarePresent, passphraseProtection: snapshot.status.passphraseProtection, pinProtection: snapshot.status.pinProtection, backupRequired: snapshot.status.backupRequired, noBackup: snapshot.status.noBackup, unfinishedBackup: snapshot.status.unfinishedBackup, recoveryMode: snapshot.status.recoveryMode, attachToPinEnabled: snapshot.status.attachToPinEnabled, unlockedAttachPin: (_j = snapshot.status.unlockedAttachPin) !== null && _j !== void 0 ? _j : undefined, language: snapshot.settings.language, bleEnabled: snapshot.settings.bleEnabled, sdCardPresent: snapshot.settings.sdCardPresent, sdProtection: snapshot.settings.sdProtection, wipeCodeProtection: snapshot.settings.wipeCodeProtection, passphraseAlwaysOnDevice: snapshot.settings.passphraseAlwaysOnDevice, safetyChecks: snapshot.settings.safetyChecks, autoLockDelayMs: snapshot.settings.autoLockDelayMs, autoShutdownDelayMs: snapshot.settings.autoShutdownDelayMs, displayRotation: snapshot.settings.displayRotation, experimentalFeatures: snapshot.settings.experimentalFeatures, wallpaperPath: snapshot.settings.wallpaperPath, brightness: snapshot.settings.brightness, animationEnabled: snapshot.settings.animationEnabled, tapToWake: snapshot.settings.tapToWake, hapticFeedback: snapshot.settings.hapticFeedback, deviceNameDisplayEnabled: snapshot.settings.deviceNameDisplayEnabled, airgapMode: snapshot.settings.airgapMode, fidoEnabled: snapshot.settings.fidoEnabled, usbLockEnabled: snapshot.settings.usbLockEnabled, randomKeypad: snapshot.settings.randomKeypad, firmwareVersion: snapshot.versions.firmware, bootloaderVersion: snapshot.versions.bootloader, boardVersion: snapshot.versions.board, bleVersion: snapshot.versions.ble, se01Version: snapshot.versions.se01, se02Version: snapshot.versions.se02, se03Version: snapshot.versions.se03, se04Version: snapshot.versions.se04, se01BootVersion: snapshot.versions.se01Boot, se02BootVersion: snapshot.versions.se02Boot, se03BootVersion: snapshot.versions.se03Boot, se04BootVersion: snapshot.versions.se04Boot, seVersion: (_k = snapshot.versions.se) !== null && _k !== void 0 ? _k : null, verify: snapshot.verification, sessionId, passphraseState: (_l = snapshot.session) === null || _l === void 0 ? void 0 : _l.passphraseState, raw: snapshot.raw, device_id: (_m = snapshot.identity.deviceId) !== null && _m !== void 0 ? _m : undefined, session_id: sessionId !== null && sessionId !== void 0 ? sessionId : undefined, ble_name: (_o = snapshot.identity.bleName) !== null && _o !== void 0 ? _o : undefined, passphrase_protection: (_p = snapshot.status.passphraseProtection) !== null && _p !== void 0 ? _p : undefined, bootloader_mode: bootloaderMode });
|
|
42438
|
+
};
|
|
42439
|
+
|
|
42440
|
+
const PRODUCT_DISPLAY_NAMES = {
|
|
42441
|
+
[hdShared.EDeviceType.Classic]: 'OneKey Classic',
|
|
42442
|
+
[hdShared.EDeviceType.Classic1s]: 'OneKey Classic 1S',
|
|
42443
|
+
[hdShared.EDeviceType.ClassicPure]: 'OneKey Classic 1S Pure',
|
|
42444
|
+
[hdShared.EDeviceType.Mini]: 'OneKey Mini',
|
|
42445
|
+
[hdShared.EDeviceType.Touch]: 'OneKey Touch',
|
|
42446
|
+
[hdShared.EDeviceType.Pro]: 'OneKey Pro',
|
|
42447
|
+
[hdShared.EDeviceType.Pro2]: 'OneKey Pro 2',
|
|
42448
|
+
};
|
|
42449
|
+
const getModelDisplayName = (deviceType) => { var _a; return (_a = PRODUCT_DISPLAY_NAMES[deviceType]) !== null && _a !== void 0 ? _a : 'OneKey'; };
|
|
42450
|
+
const getDisplayName = (identity) => identity.label || identity.bleName || getModelDisplayName(identity.deviceType);
|
|
42451
|
+
function createEmptyDeviceState(identity = {}) {
|
|
42452
|
+
const normalizedIdentity = Object.assign({ deviceType: hdShared.EDeviceType.Unknown, firmwareType: hdShared.EFirmwareType.Universal, model: null, vendor: null, deviceId: null, serialNo: '', label: null, bleName: null, displayName: '' }, identity);
|
|
42453
|
+
normalizedIdentity.displayName = getDisplayName(normalizedIdentity);
|
|
42454
|
+
return {
|
|
42455
|
+
schemaVersion: 1,
|
|
42456
|
+
revision: 0,
|
|
42457
|
+
updatedAt: Date.now(),
|
|
42458
|
+
protocol: 'unknown',
|
|
42459
|
+
protocolVersion: null,
|
|
42460
|
+
identity: normalizedIdentity,
|
|
42461
|
+
status: {
|
|
42462
|
+
mode: 'unknown',
|
|
42463
|
+
initialized: null,
|
|
42464
|
+
unlocked: null,
|
|
42465
|
+
firmwarePresent: null,
|
|
42466
|
+
backupRequired: null,
|
|
42467
|
+
noBackup: null,
|
|
42468
|
+
unfinishedBackup: null,
|
|
42469
|
+
recoveryMode: null,
|
|
42470
|
+
passphraseProtection: null,
|
|
42471
|
+
pinProtection: null,
|
|
42472
|
+
attachToPinEnabled: null,
|
|
42473
|
+
unlockedAttachPin: null,
|
|
42474
|
+
},
|
|
42475
|
+
settings: {
|
|
42476
|
+
language: null,
|
|
42477
|
+
bleEnabled: null,
|
|
42478
|
+
sdCardPresent: null,
|
|
42479
|
+
sdProtection: null,
|
|
42480
|
+
wipeCodeProtection: null,
|
|
42481
|
+
passphraseAlwaysOnDevice: null,
|
|
42482
|
+
safetyChecks: null,
|
|
42483
|
+
autoLockDelayMs: null,
|
|
42484
|
+
autoShutdownDelayMs: null,
|
|
42485
|
+
displayRotation: null,
|
|
42486
|
+
experimentalFeatures: null,
|
|
42487
|
+
wallpaperPath: null,
|
|
42488
|
+
brightness: null,
|
|
42489
|
+
animationEnabled: null,
|
|
42490
|
+
tapToWake: null,
|
|
42491
|
+
hapticFeedback: null,
|
|
42492
|
+
deviceNameDisplayEnabled: null,
|
|
42493
|
+
airgapMode: null,
|
|
42494
|
+
fidoEnabled: null,
|
|
42495
|
+
usbLockEnabled: null,
|
|
42496
|
+
randomKeypad: null,
|
|
42497
|
+
},
|
|
42498
|
+
versions: {
|
|
42499
|
+
firmware: null,
|
|
42500
|
+
bootloader: null,
|
|
42501
|
+
board: null,
|
|
42502
|
+
ble: null,
|
|
42503
|
+
},
|
|
42504
|
+
capabilities: [],
|
|
42505
|
+
};
|
|
42506
|
+
}
|
|
42507
|
+
const isEqual = (left, right) => JSON.stringify(left) === JSON.stringify(right);
|
|
42508
|
+
const applySectionPatch = (target, patch, prefix, changedKeys) => {
|
|
42509
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
42510
|
+
if (value !== undefined && !isEqual(target[key], value)) {
|
|
42511
|
+
target[key] = value;
|
|
42512
|
+
changedKeys.push(`${prefix}.${String(key)}`);
|
|
42513
|
+
}
|
|
42514
|
+
}
|
|
42515
|
+
};
|
|
42516
|
+
class DeviceStateStore {
|
|
42517
|
+
constructor(initial) {
|
|
42518
|
+
this.state = initial ? structuredClone(initial) : undefined;
|
|
42519
|
+
}
|
|
42520
|
+
getState() {
|
|
42521
|
+
return this.state;
|
|
42522
|
+
}
|
|
42523
|
+
replace(state, source) {
|
|
42524
|
+
var _a, _b;
|
|
42525
|
+
const revision = ((_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a.revision) !== null && _b !== void 0 ? _b : 0) + 1;
|
|
42526
|
+
this.state = Object.assign(Object.assign({}, structuredClone(state)), { revision, updatedAt: Date.now() });
|
|
42527
|
+
return {
|
|
42528
|
+
state: this.state,
|
|
42529
|
+
revision,
|
|
42530
|
+
source,
|
|
42531
|
+
changedKeys: ['*'],
|
|
42532
|
+
};
|
|
42533
|
+
}
|
|
42534
|
+
update(patch, source) {
|
|
42535
|
+
var _a, _b, _c, _d, _e, _f;
|
|
42536
|
+
const next = structuredClone((_a = this.state) !== null && _a !== void 0 ? _a : createEmptyDeviceState());
|
|
42537
|
+
const changedKeys = [];
|
|
42538
|
+
if (patch.protocol !== undefined && patch.protocol !== next.protocol) {
|
|
42539
|
+
next.protocol = patch.protocol;
|
|
42540
|
+
changedKeys.push('protocol');
|
|
42541
|
+
}
|
|
42542
|
+
if (patch.protocolVersion !== undefined && patch.protocolVersion !== next.protocolVersion) {
|
|
42543
|
+
next.protocolVersion = patch.protocolVersion;
|
|
42544
|
+
changedKeys.push('protocolVersion');
|
|
42545
|
+
}
|
|
42546
|
+
if (patch.identity)
|
|
42547
|
+
applySectionPatch(next.identity, patch.identity, 'identity', changedKeys);
|
|
42548
|
+
if (patch.status)
|
|
42549
|
+
applySectionPatch(next.status, patch.status, 'status', changedKeys);
|
|
42550
|
+
if (patch.settings)
|
|
42551
|
+
applySectionPatch(next.settings, patch.settings, 'settings', changedKeys);
|
|
42552
|
+
if (patch.versions)
|
|
42553
|
+
applySectionPatch(next.versions, patch.versions, 'versions', changedKeys);
|
|
42554
|
+
if (patch.capabilities !== undefined && !isEqual(next.capabilities, patch.capabilities)) {
|
|
42555
|
+
next.capabilities = structuredClone(patch.capabilities);
|
|
42556
|
+
changedKeys.push('capabilities');
|
|
42557
|
+
}
|
|
42558
|
+
if (patch.verification !== undefined) {
|
|
42559
|
+
const mergedVerification = Object.assign(Object.assign({}, structuredClone((_b = next.verification) !== null && _b !== void 0 ? _b : {})), structuredClone(patch.verification));
|
|
42560
|
+
if (!isEqual(next.verification, mergedVerification)) {
|
|
42561
|
+
next.verification = mergedVerification;
|
|
42562
|
+
changedKeys.push('verification');
|
|
42563
|
+
}
|
|
42564
|
+
}
|
|
42565
|
+
if (patch.raw !== undefined) {
|
|
42566
|
+
const mergedRaw = structuredClone((_c = next.raw) !== null && _c !== void 0 ? _c : {});
|
|
42567
|
+
for (const [key, value] of Object.entries(patch.raw)) {
|
|
42568
|
+
if (value === null) {
|
|
42569
|
+
delete mergedRaw[key];
|
|
42570
|
+
}
|
|
42571
|
+
else if (value !== undefined) {
|
|
42572
|
+
mergedRaw[key] = structuredClone(value);
|
|
42573
|
+
}
|
|
42574
|
+
}
|
|
42575
|
+
if (!isEqual(next.raw, mergedRaw)) {
|
|
42576
|
+
next.raw = mergedRaw;
|
|
42577
|
+
changedKeys.push('raw');
|
|
42578
|
+
}
|
|
42579
|
+
}
|
|
42580
|
+
if (patch.session === null) {
|
|
42581
|
+
if (next.session !== undefined) {
|
|
42582
|
+
delete next.session;
|
|
42583
|
+
changedKeys.push('session');
|
|
42584
|
+
}
|
|
42585
|
+
}
|
|
42586
|
+
else if (patch.session) {
|
|
42587
|
+
const session = (_d = next.session) !== null && _d !== void 0 ? _d : { sessionId: null };
|
|
42588
|
+
applySectionPatch(session, patch.session, 'session', changedKeys);
|
|
42589
|
+
next.session = session;
|
|
42590
|
+
}
|
|
42591
|
+
const displayName = getDisplayName(next.identity);
|
|
42592
|
+
if (displayName !== next.identity.displayName) {
|
|
42593
|
+
next.identity.displayName = displayName;
|
|
42594
|
+
changedKeys.push('identity.displayName');
|
|
42595
|
+
}
|
|
42596
|
+
if (changedKeys.length > 0) {
|
|
42597
|
+
next.revision = ((_f = (_e = this.state) === null || _e === void 0 ? void 0 : _e.revision) !== null && _f !== void 0 ? _f : 0) + 1;
|
|
42598
|
+
next.updatedAt = Date.now();
|
|
42599
|
+
this.state = next;
|
|
42600
|
+
}
|
|
42601
|
+
else if (!this.state) {
|
|
42602
|
+
this.state = next;
|
|
42603
|
+
}
|
|
42604
|
+
return {
|
|
42605
|
+
state: this.state,
|
|
42606
|
+
revision: this.state.revision,
|
|
42607
|
+
source,
|
|
42608
|
+
changedKeys,
|
|
42609
|
+
};
|
|
42610
|
+
}
|
|
42611
|
+
clearSession(source) {
|
|
42612
|
+
var _a;
|
|
42613
|
+
if (!((_a = this.state) === null || _a === void 0 ? void 0 : _a.session))
|
|
42614
|
+
return undefined;
|
|
42615
|
+
return this.update({ session: null }, source);
|
|
42616
|
+
}
|
|
42617
|
+
}
|
|
42618
|
+
const createPublicDeviceState = (state) => {
|
|
42619
|
+
const snapshot = structuredClone(state);
|
|
42620
|
+
delete snapshot.raw;
|
|
42621
|
+
delete snapshot.session;
|
|
42622
|
+
return snapshot;
|
|
42623
|
+
};
|
|
42624
|
+
|
|
41559
42625
|
class DeviceWalletSessionStore {
|
|
41560
42626
|
constructor() {
|
|
41561
42627
|
this.walletSessions = new Map();
|
|
@@ -41635,565 +42701,34 @@ class DeviceWalletSessionStore {
|
|
|
41635
42701
|
}
|
|
41636
42702
|
const deviceWalletSessionStore = new DeviceWalletSessionStore();
|
|
41637
42703
|
|
|
41638
|
-
const isProtocolV2RomloaderDeviceInfo = (deviceInfo, deviceStatus) => {
|
|
41639
|
-
var _a, _b, _c;
|
|
41640
|
-
return !!deviceInfo &&
|
|
41641
|
-
deviceStatus == null &&
|
|
41642
|
-
((_a = deviceInfo.fw) === null || _a === void 0 ? void 0 : _a.romloader) != null &&
|
|
41643
|
-
((_b = deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.application) == null &&
|
|
41644
|
-
((_c = deviceInfo.fw) === null || _c === void 0 ? void 0 : _c.application_data) == null &&
|
|
41645
|
-
deviceInfo.coprocessor == null &&
|
|
41646
|
-
deviceInfo.se1 == null &&
|
|
41647
|
-
deviceInfo.se2 == null &&
|
|
41648
|
-
deviceInfo.se3 == null &&
|
|
41649
|
-
deviceInfo.se4 == null;
|
|
41650
|
-
};
|
|
41651
|
-
const isProtocolV2BootloaderDeviceInfo = (deviceInfo, deviceStatus) => !!deviceInfo &&
|
|
41652
|
-
deviceStatus == null &&
|
|
41653
|
-
!isProtocolV2RomloaderDeviceInfo(deviceInfo, deviceStatus);
|
|
41654
|
-
const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
|
|
41655
|
-
targets: {
|
|
41656
|
-
hw: true,
|
|
41657
|
-
fw: true,
|
|
41658
|
-
coprocessor: true,
|
|
41659
|
-
},
|
|
41660
|
-
types: {
|
|
41661
|
-
version: true,
|
|
41662
|
-
specific: true,
|
|
41663
|
-
},
|
|
41664
|
-
};
|
|
41665
|
-
const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
|
|
41666
|
-
targets: {
|
|
41667
|
-
hw: true,
|
|
41668
|
-
fw: true,
|
|
41669
|
-
coprocessor: true,
|
|
41670
|
-
se1: true,
|
|
41671
|
-
se2: true,
|
|
41672
|
-
se3: true,
|
|
41673
|
-
se4: true,
|
|
41674
|
-
},
|
|
41675
|
-
types: {
|
|
41676
|
-
version: true,
|
|
41677
|
-
specific: true,
|
|
41678
|
-
},
|
|
41679
|
-
};
|
|
41680
|
-
const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
|
|
41681
|
-
targets: {
|
|
41682
|
-
hw: true,
|
|
41683
|
-
fw: true,
|
|
41684
|
-
coprocessor: true,
|
|
41685
|
-
se1: true,
|
|
41686
|
-
se2: true,
|
|
41687
|
-
se3: true,
|
|
41688
|
-
se4: true,
|
|
41689
|
-
},
|
|
41690
|
-
types: {
|
|
41691
|
-
version: true,
|
|
41692
|
-
build_id: true,
|
|
41693
|
-
hash: true,
|
|
41694
|
-
specific: true,
|
|
41695
|
-
},
|
|
41696
|
-
};
|
|
41697
|
-
const PROTOCOL_V2_DEVICE_INFO_REQUEST = PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST;
|
|
41698
|
-
const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS = 10 * 1000;
|
|
41699
|
-
function requestProtocolV2DeviceInfo({ commands, timeoutMs = PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS, request = PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST, }) {
|
|
41700
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41701
|
-
const { message } = yield commands.typedCall('DeviceInfoGet', 'DeviceInfo', request, {
|
|
41702
|
-
timeoutMs,
|
|
41703
|
-
});
|
|
41704
|
-
return message;
|
|
41705
|
-
});
|
|
41706
|
-
}
|
|
41707
|
-
function requestProtocolV2DeviceStatus({ commands, }) {
|
|
41708
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41709
|
-
const { message } = yield commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
|
|
41710
|
-
return message;
|
|
41711
|
-
});
|
|
41712
|
-
}
|
|
41713
|
-
|
|
41714
|
-
const isMeaningfulVersion = (version) => Boolean(version && version !== '0.0.0');
|
|
41715
|
-
const firstMeaningfulVersion$1 = (...versions) => { var _a; return (_a = versions.find(isMeaningfulVersion)) !== null && _a !== void 0 ? _a : null; };
|
|
41716
|
-
const versionArrayToString = (version) => {
|
|
41717
|
-
if (!version || version.length === 0)
|
|
41718
|
-
return null;
|
|
41719
|
-
const value = version.join('.');
|
|
41720
|
-
return isMeaningfulVersion(value) ? value : null;
|
|
41721
|
-
};
|
|
41722
|
-
const bytesToHex$3 = (value) => {
|
|
41723
|
-
if (!value)
|
|
41724
|
-
return undefined;
|
|
41725
|
-
if (typeof value === 'string')
|
|
41726
|
-
return value;
|
|
41727
|
-
if (value instanceof Uint8Array) {
|
|
41728
|
-
return Array.from(value)
|
|
41729
|
-
.map(byte => byte.toString(16).padStart(2, '0'))
|
|
41730
|
-
.join('');
|
|
41731
|
-
}
|
|
41732
|
-
if (Array.isArray(value)) {
|
|
41733
|
-
return value.map(byte => Number(byte).toString(16).padStart(2, '0')).join('');
|
|
41734
|
-
}
|
|
41735
|
-
return undefined;
|
|
41736
|
-
};
|
|
41737
|
-
const getImageVersion$1 = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.version) !== null && _a !== void 0 ? _a : null; };
|
|
41738
|
-
const getImageBuildId$1 = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.build_id) !== null && _a !== void 0 ? _a : undefined; };
|
|
41739
|
-
const getImageHash$1 = (image) => bytesToHex$3(image === null || image === void 0 ? void 0 : image.hash);
|
|
41740
|
-
const shouldIncludeVerify = (scope) => scope === 'verify' || scope === 'full';
|
|
41741
|
-
const getDeviceMode = (features) => {
|
|
41742
|
-
if (!features)
|
|
41743
|
-
return 'unknown';
|
|
41744
|
-
if (features.bootloaderMode === true)
|
|
41745
|
-
return 'bootloader';
|
|
41746
|
-
if (features.initialized === false)
|
|
41747
|
-
return 'notInitialized';
|
|
41748
|
-
if (features.initialized === true)
|
|
41749
|
-
return 'normal';
|
|
41750
|
-
return 'unknown';
|
|
41751
|
-
};
|
|
41752
|
-
const getProtocolV2Mode = (deviceInfo, deviceStatus) => {
|
|
41753
|
-
if (isProtocolV2RomloaderDeviceInfo(deviceInfo, deviceStatus))
|
|
41754
|
-
return 'romloader';
|
|
41755
|
-
if (isProtocolV2BootloaderDeviceInfo(deviceInfo, deviceStatus))
|
|
41756
|
-
return 'bootloader';
|
|
41757
|
-
const initialized = deviceStatus === null || deviceStatus === void 0 ? void 0 : deviceStatus.init_states;
|
|
41758
|
-
if (initialized === false)
|
|
41759
|
-
return 'notInitialized';
|
|
41760
|
-
if (initialized === true)
|
|
41761
|
-
return 'normal';
|
|
41762
|
-
return 'unknown';
|
|
41763
|
-
};
|
|
41764
|
-
const normalizeV1Versions = (features, protocolV1OneKeyFeatures) => ({
|
|
41765
|
-
firmware: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_firmware_version, versionArrayToString(getDeviceFirmwareVersion(features))),
|
|
41766
|
-
bootloader: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_boot_version, versionArrayToString(getDeviceBootloaderVersion(features))),
|
|
41767
|
-
board: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_board_version, versionArrayToString(features ? getDeviceBoardloaderVersion(features) : undefined)),
|
|
41768
|
-
ble: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_ble_version, features === null || features === void 0 ? void 0 : features.bleVersion, versionArrayToString(features ? getDeviceBLEFirmwareVersion(features) : undefined)),
|
|
41769
|
-
se01: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_version, features === null || features === void 0 ? void 0 : features.se01Version),
|
|
41770
|
-
se02: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_version, features === null || features === void 0 ? void 0 : features.se02Version),
|
|
41771
|
-
se03: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_version, features === null || features === void 0 ? void 0 : features.se03Version),
|
|
41772
|
-
se04: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_version, features === null || features === void 0 ? void 0 : features.se04Version),
|
|
41773
|
-
se01Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_boot_version, features === null || features === void 0 ? void 0 : features.se01BootVersion),
|
|
41774
|
-
se02Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_boot_version, features === null || features === void 0 ? void 0 : features.se02BootVersion),
|
|
41775
|
-
se03Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_boot_version, features === null || features === void 0 ? void 0 : features.se03BootVersion),
|
|
41776
|
-
se04Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_boot_version, features === null || features === void 0 ? void 0 : features.se04BootVersion),
|
|
41777
|
-
});
|
|
41778
|
-
const normalizeV2Versions = (deviceInfo) => {
|
|
41779
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
41780
|
-
const info = deviceInfo;
|
|
41781
|
-
return {
|
|
41782
|
-
firmware: firstMeaningfulVersion$1(getImageVersion$1((_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application)),
|
|
41783
|
-
bootloader: firstMeaningfulVersion$1(getImageVersion$1((_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.bootloader)),
|
|
41784
|
-
board: firstMeaningfulVersion$1(getImageVersion$1((_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.romloader)),
|
|
41785
|
-
ble: firstMeaningfulVersion$1(getImageVersion$1((_d = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _d === void 0 ? void 0 : _d.application)),
|
|
41786
|
-
se01: firstMeaningfulVersion$1(getImageVersion$1((_e = info === null || info === void 0 ? void 0 : info.se1) === null || _e === void 0 ? void 0 : _e.application)),
|
|
41787
|
-
se02: firstMeaningfulVersion$1(getImageVersion$1((_f = info === null || info === void 0 ? void 0 : info.se2) === null || _f === void 0 ? void 0 : _f.application)),
|
|
41788
|
-
se03: firstMeaningfulVersion$1(getImageVersion$1((_g = info === null || info === void 0 ? void 0 : info.se3) === null || _g === void 0 ? void 0 : _g.application)),
|
|
41789
|
-
se04: firstMeaningfulVersion$1(getImageVersion$1((_h = info === null || info === void 0 ? void 0 : info.se4) === null || _h === void 0 ? void 0 : _h.application)),
|
|
41790
|
-
se01Boot: firstMeaningfulVersion$1(getImageVersion$1((_j = info === null || info === void 0 ? void 0 : info.se1) === null || _j === void 0 ? void 0 : _j.bootloader)),
|
|
41791
|
-
se02Boot: firstMeaningfulVersion$1(getImageVersion$1((_k = info === null || info === void 0 ? void 0 : info.se2) === null || _k === void 0 ? void 0 : _k.bootloader)),
|
|
41792
|
-
se03Boot: firstMeaningfulVersion$1(getImageVersion$1((_l = info === null || info === void 0 ? void 0 : info.se3) === null || _l === void 0 ? void 0 : _l.bootloader)),
|
|
41793
|
-
se04Boot: firstMeaningfulVersion$1(getImageVersion$1((_m = info === null || info === void 0 ? void 0 : info.se4) === null || _m === void 0 ? void 0 : _m.bootloader)),
|
|
41794
|
-
};
|
|
41795
|
-
};
|
|
41796
|
-
const normalizeV1Status = (features) => {
|
|
41797
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
41798
|
-
return ({
|
|
41799
|
-
mode: getDeviceMode(features),
|
|
41800
|
-
initialized: (_a = features === null || features === void 0 ? void 0 : features.initialized) !== null && _a !== void 0 ? _a : null,
|
|
41801
|
-
bootloaderMode: (_b = features === null || features === void 0 ? void 0 : features.bootloaderMode) !== null && _b !== void 0 ? _b : null,
|
|
41802
|
-
unlocked: (_c = features === null || features === void 0 ? void 0 : features.unlocked) !== null && _c !== void 0 ? _c : null,
|
|
41803
|
-
passphraseProtection: (_d = features === null || features === void 0 ? void 0 : features.passphraseProtection) !== null && _d !== void 0 ? _d : null,
|
|
41804
|
-
attachToPinEnabled: (_e = features === null || features === void 0 ? void 0 : features.attachToPinEnabled) !== null && _e !== void 0 ? _e : null,
|
|
41805
|
-
unlockedAttachPin: (_f = features === null || features === void 0 ? void 0 : features.unlockedAttachPin) !== null && _f !== void 0 ? _f : null,
|
|
41806
|
-
backupRequired: (_g = features === null || features === void 0 ? void 0 : features.backupRequired) !== null && _g !== void 0 ? _g : null,
|
|
41807
|
-
noBackup: (_h = features === null || features === void 0 ? void 0 : features.noBackup) !== null && _h !== void 0 ? _h : null,
|
|
41808
|
-
language: (_j = features === null || features === void 0 ? void 0 : features.language) !== null && _j !== void 0 ? _j : null,
|
|
41809
|
-
bleEnabled: (_k = features === null || features === void 0 ? void 0 : features.bleEnabled) !== null && _k !== void 0 ? _k : null,
|
|
41810
|
-
});
|
|
41811
|
-
};
|
|
41812
|
-
const normalizeV2Status = (deviceInfo, deviceStatus) => {
|
|
41813
|
-
var _a, _b, _c, _d, _e, _f;
|
|
41814
|
-
const status = deviceStatus;
|
|
41815
|
-
const bootloaderMode = isProtocolV2BootloaderDeviceInfo(deviceInfo, deviceStatus);
|
|
41816
|
-
return {
|
|
41817
|
-
mode: getProtocolV2Mode(deviceInfo, deviceStatus),
|
|
41818
|
-
initialized: (_a = status === null || status === void 0 ? void 0 : status.init_states) !== null && _a !== void 0 ? _a : null,
|
|
41819
|
-
bootloaderMode,
|
|
41820
|
-
unlocked: (_b = status === null || status === void 0 ? void 0 : status.unlocked) !== null && _b !== void 0 ? _b : null,
|
|
41821
|
-
passphraseProtection: (_c = status === null || status === void 0 ? void 0 : status.passphrase_enabled) !== null && _c !== void 0 ? _c : null,
|
|
41822
|
-
attachToPinEnabled: (_d = status === null || status === void 0 ? void 0 : status.attach_to_pin_enabled) !== null && _d !== void 0 ? _d : null,
|
|
41823
|
-
unlockedAttachPin: (_e = status === null || status === void 0 ? void 0 : status.unlocked_by_attach_to_pin) !== null && _e !== void 0 ? _e : null,
|
|
41824
|
-
backupRequired: (_f = status === null || status === void 0 ? void 0 : status.backup_required) !== null && _f !== void 0 ? _f : null,
|
|
41825
|
-
noBackup: null,
|
|
41826
|
-
language: null,
|
|
41827
|
-
bleEnabled: null,
|
|
41828
|
-
};
|
|
41829
|
-
};
|
|
41830
|
-
const normalizeV1Verify = (features, protocolV1OneKeyFeatures) => {
|
|
41831
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23;
|
|
41832
|
-
return ({
|
|
41833
|
-
firmwareBuildId: (_a = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_firmware_build_id) !== null && _a !== void 0 ? _a : (_b = features === null || features === void 0 ? void 0 : features.verify) === null || _b === void 0 ? void 0 : _b.firmwareBuildId,
|
|
41834
|
-
firmwareHash: (_c = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_firmware_hash) !== null && _c !== void 0 ? _c : (_d = features === null || features === void 0 ? void 0 : features.verify) === null || _d === void 0 ? void 0 : _d.firmwareHash,
|
|
41835
|
-
bootloaderBuildId: (_e = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_boot_build_id) !== null && _e !== void 0 ? _e : (_f = features === null || features === void 0 ? void 0 : features.verify) === null || _f === void 0 ? void 0 : _f.bootloaderBuildId,
|
|
41836
|
-
bootloaderHash: (_g = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_boot_hash) !== null && _g !== void 0 ? _g : (_h = features === null || features === void 0 ? void 0 : features.verify) === null || _h === void 0 ? void 0 : _h.bootloaderHash,
|
|
41837
|
-
boardBuildId: (_j = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_board_build_id) !== null && _j !== void 0 ? _j : (_k = features === null || features === void 0 ? void 0 : features.verify) === null || _k === void 0 ? void 0 : _k.boardBuildId,
|
|
41838
|
-
boardHash: (_l = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_board_hash) !== null && _l !== void 0 ? _l : (_m = features === null || features === void 0 ? void 0 : features.verify) === null || _m === void 0 ? void 0 : _m.boardHash,
|
|
41839
|
-
bleBuildId: (_o = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_ble_build_id) !== null && _o !== void 0 ? _o : (_p = features === null || features === void 0 ? void 0 : features.verify) === null || _p === void 0 ? void 0 : _p.bleBuildId,
|
|
41840
|
-
bleHash: (_q = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_ble_hash) !== null && _q !== void 0 ? _q : (_r = features === null || features === void 0 ? void 0 : features.verify) === null || _r === void 0 ? void 0 : _r.bleHash,
|
|
41841
|
-
se01BuildId: (_s = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_build_id) !== null && _s !== void 0 ? _s : (_t = features === null || features === void 0 ? void 0 : features.verify) === null || _t === void 0 ? void 0 : _t.se01BuildId,
|
|
41842
|
-
se01Hash: (_u = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_hash) !== null && _u !== void 0 ? _u : (_v = features === null || features === void 0 ? void 0 : features.verify) === null || _v === void 0 ? void 0 : _v.se01Hash,
|
|
41843
|
-
se02BuildId: (_w = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_build_id) !== null && _w !== void 0 ? _w : (_x = features === null || features === void 0 ? void 0 : features.verify) === null || _x === void 0 ? void 0 : _x.se02BuildId,
|
|
41844
|
-
se02Hash: (_y = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_hash) !== null && _y !== void 0 ? _y : (_z = features === null || features === void 0 ? void 0 : features.verify) === null || _z === void 0 ? void 0 : _z.se02Hash,
|
|
41845
|
-
se03BuildId: (_0 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_build_id) !== null && _0 !== void 0 ? _0 : (_1 = features === null || features === void 0 ? void 0 : features.verify) === null || _1 === void 0 ? void 0 : _1.se03BuildId,
|
|
41846
|
-
se03Hash: (_2 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_hash) !== null && _2 !== void 0 ? _2 : (_3 = features === null || features === void 0 ? void 0 : features.verify) === null || _3 === void 0 ? void 0 : _3.se03Hash,
|
|
41847
|
-
se04BuildId: (_4 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_build_id) !== null && _4 !== void 0 ? _4 : (_5 = features === null || features === void 0 ? void 0 : features.verify) === null || _5 === void 0 ? void 0 : _5.se04BuildId,
|
|
41848
|
-
se04Hash: (_6 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_hash) !== null && _6 !== void 0 ? _6 : (_7 = features === null || features === void 0 ? void 0 : features.verify) === null || _7 === void 0 ? void 0 : _7.se04Hash,
|
|
41849
|
-
se01BootBuildId: (_8 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_boot_build_id) !== null && _8 !== void 0 ? _8 : (_9 = features === null || features === void 0 ? void 0 : features.verify) === null || _9 === void 0 ? void 0 : _9.se01BootBuildId,
|
|
41850
|
-
se01BootHash: (_10 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_boot_hash) !== null && _10 !== void 0 ? _10 : (_11 = features === null || features === void 0 ? void 0 : features.verify) === null || _11 === void 0 ? void 0 : _11.se01BootHash,
|
|
41851
|
-
se02BootBuildId: (_12 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_boot_build_id) !== null && _12 !== void 0 ? _12 : (_13 = features === null || features === void 0 ? void 0 : features.verify) === null || _13 === void 0 ? void 0 : _13.se02BootBuildId,
|
|
41852
|
-
se02BootHash: (_14 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_boot_hash) !== null && _14 !== void 0 ? _14 : (_15 = features === null || features === void 0 ? void 0 : features.verify) === null || _15 === void 0 ? void 0 : _15.se02BootHash,
|
|
41853
|
-
se03BootBuildId: (_16 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_boot_build_id) !== null && _16 !== void 0 ? _16 : (_17 = features === null || features === void 0 ? void 0 : features.verify) === null || _17 === void 0 ? void 0 : _17.se03BootBuildId,
|
|
41854
|
-
se03BootHash: (_18 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_boot_hash) !== null && _18 !== void 0 ? _18 : (_19 = features === null || features === void 0 ? void 0 : features.verify) === null || _19 === void 0 ? void 0 : _19.se03BootHash,
|
|
41855
|
-
se04BootBuildId: (_20 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_boot_build_id) !== null && _20 !== void 0 ? _20 : (_21 = features === null || features === void 0 ? void 0 : features.verify) === null || _21 === void 0 ? void 0 : _21.se04BootBuildId,
|
|
41856
|
-
se04BootHash: (_22 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_boot_hash) !== null && _22 !== void 0 ? _22 : (_23 = features === null || features === void 0 ? void 0 : features.verify) === null || _23 === void 0 ? void 0 : _23.se04BootHash,
|
|
41857
|
-
});
|
|
41858
|
-
};
|
|
41859
|
-
const normalizeV2Verify = (deviceInfo) => {
|
|
41860
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
41861
|
-
const info = deviceInfo;
|
|
41862
|
-
return {
|
|
41863
|
-
firmwareBuildId: getImageBuildId$1((_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application),
|
|
41864
|
-
firmwareHash: getImageHash$1((_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.application),
|
|
41865
|
-
bootloaderBuildId: getImageBuildId$1((_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.bootloader),
|
|
41866
|
-
bootloaderHash: getImageHash$1((_d = info === null || info === void 0 ? void 0 : info.fw) === null || _d === void 0 ? void 0 : _d.bootloader),
|
|
41867
|
-
boardBuildId: getImageBuildId$1((_e = info === null || info === void 0 ? void 0 : info.fw) === null || _e === void 0 ? void 0 : _e.romloader),
|
|
41868
|
-
boardHash: getImageHash$1((_f = info === null || info === void 0 ? void 0 : info.fw) === null || _f === void 0 ? void 0 : _f.romloader),
|
|
41869
|
-
bleBuildId: getImageBuildId$1((_g = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _g === void 0 ? void 0 : _g.application),
|
|
41870
|
-
bleHash: getImageHash$1((_h = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _h === void 0 ? void 0 : _h.application),
|
|
41871
|
-
se01BuildId: getImageBuildId$1((_j = info === null || info === void 0 ? void 0 : info.se1) === null || _j === void 0 ? void 0 : _j.application),
|
|
41872
|
-
se01Hash: getImageHash$1((_k = info === null || info === void 0 ? void 0 : info.se1) === null || _k === void 0 ? void 0 : _k.application),
|
|
41873
|
-
se02BuildId: getImageBuildId$1((_l = info === null || info === void 0 ? void 0 : info.se2) === null || _l === void 0 ? void 0 : _l.application),
|
|
41874
|
-
se02Hash: getImageHash$1((_m = info === null || info === void 0 ? void 0 : info.se2) === null || _m === void 0 ? void 0 : _m.application),
|
|
41875
|
-
se03BuildId: getImageBuildId$1((_o = info === null || info === void 0 ? void 0 : info.se3) === null || _o === void 0 ? void 0 : _o.application),
|
|
41876
|
-
se03Hash: getImageHash$1((_p = info === null || info === void 0 ? void 0 : info.se3) === null || _p === void 0 ? void 0 : _p.application),
|
|
41877
|
-
se04BuildId: getImageBuildId$1((_q = info === null || info === void 0 ? void 0 : info.se4) === null || _q === void 0 ? void 0 : _q.application),
|
|
41878
|
-
se04Hash: getImageHash$1((_r = info === null || info === void 0 ? void 0 : info.se4) === null || _r === void 0 ? void 0 : _r.application),
|
|
41879
|
-
se01BootBuildId: getImageBuildId$1((_s = info === null || info === void 0 ? void 0 : info.se1) === null || _s === void 0 ? void 0 : _s.bootloader),
|
|
41880
|
-
se01BootHash: getImageHash$1((_t = info === null || info === void 0 ? void 0 : info.se1) === null || _t === void 0 ? void 0 : _t.bootloader),
|
|
41881
|
-
se02BootBuildId: getImageBuildId$1((_u = info === null || info === void 0 ? void 0 : info.se2) === null || _u === void 0 ? void 0 : _u.bootloader),
|
|
41882
|
-
se02BootHash: getImageHash$1((_v = info === null || info === void 0 ? void 0 : info.se2) === null || _v === void 0 ? void 0 : _v.bootloader),
|
|
41883
|
-
se03BootBuildId: getImageBuildId$1((_w = info === null || info === void 0 ? void 0 : info.se3) === null || _w === void 0 ? void 0 : _w.bootloader),
|
|
41884
|
-
se03BootHash: getImageHash$1((_x = info === null || info === void 0 ? void 0 : info.se3) === null || _x === void 0 ? void 0 : _x.bootloader),
|
|
41885
|
-
se04BootBuildId: getImageBuildId$1((_y = info === null || info === void 0 ? void 0 : info.se4) === null || _y === void 0 ? void 0 : _y.bootloader),
|
|
41886
|
-
se04BootHash: getImageHash$1((_z = info === null || info === void 0 ? void 0 : info.se4) === null || _z === void 0 ? void 0 : _z.bootloader),
|
|
41887
|
-
};
|
|
41888
|
-
};
|
|
41889
|
-
const normalizeRaw = ({ features, protocolV1OneKeyFeatures, protocolV2DeviceInfo, protocolV2DeviceStatus, }) => (Object.assign(Object.assign(Object.assign(Object.assign({}, (features ? { features } : {})), (protocolV1OneKeyFeatures ? { protocolV1OneKeyFeatures } : {})), (protocolV2DeviceInfo ? { protocolV2DeviceInfo } : {})), (protocolV2DeviceStatus ? { protocolV2DeviceStatus } : {})));
|
|
41890
|
-
function buildProfileFromProtocolV1({ protocol = 'V1', features, protocolV1OneKeyFeatures, sources = ['features'], scope = 'basic', includeRaw = false, }) {
|
|
41891
|
-
const sourceFeatures = features;
|
|
41892
|
-
const verify = normalizeV1Verify(sourceFeatures, protocolV1OneKeyFeatures);
|
|
41893
|
-
return Object.assign(Object.assign({ protocol,
|
|
41894
|
-
sources, deviceType: getDeviceType(sourceFeatures), firmwareType: getFirmwareType(sourceFeatures), deviceId: (sourceFeatures === null || sourceFeatures === void 0 ? void 0 : sourceFeatures.deviceId) || (sourceFeatures ? getDeviceUUID(sourceFeatures) : ''), serialNo: sourceFeatures ? getDeviceUUID(sourceFeatures) : '', label: getDeviceLabel(sourceFeatures), bleName: getDeviceBleName(sourceFeatures), status: normalizeV1Status(sourceFeatures), versions: normalizeV1Versions(sourceFeatures, protocolV1OneKeyFeatures) }, (shouldIncludeVerify(scope) ? { verify } : {})), (includeRaw
|
|
41895
|
-
? {
|
|
41896
|
-
raw: normalizeRaw({
|
|
41897
|
-
features,
|
|
41898
|
-
protocolV1OneKeyFeatures,
|
|
41899
|
-
}),
|
|
41900
|
-
}
|
|
41901
|
-
: {}));
|
|
41902
|
-
}
|
|
41903
|
-
function buildProfileFromProtocolV2({ deviceInfo, deviceStatus, sources = ['deviceInfo'], scope = 'basic', includeRaw = false, }) {
|
|
41904
|
-
var _a, _b, _c;
|
|
41905
|
-
const info = deviceInfo;
|
|
41906
|
-
const deviceId = (deviceStatus === null || deviceStatus === void 0 ? void 0 : deviceStatus.device_id) || '';
|
|
41907
|
-
const serialNo = ((_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.hw) === null || _a === void 0 ? void 0 : _a.serial_no) || '';
|
|
41908
|
-
const label = null;
|
|
41909
|
-
const bleName = (_c = (_b = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _b === void 0 ? void 0 : _b.bt_adv_name) !== null && _c !== void 0 ? _c : null;
|
|
41910
|
-
const verify = normalizeV2Verify(deviceInfo);
|
|
41911
|
-
return Object.assign(Object.assign({ protocol: 'V2', sources, deviceType: hdShared.EDeviceType.Pro2, firmwareType: hdShared.EFirmwareType.Universal, deviceId,
|
|
41912
|
-
serialNo,
|
|
41913
|
-
label,
|
|
41914
|
-
bleName, status: normalizeV2Status(deviceInfo, deviceStatus), versions: normalizeV2Versions(deviceInfo) }, (shouldIncludeVerify(scope) ? { verify } : {})), (includeRaw
|
|
41915
|
-
? {
|
|
41916
|
-
raw: normalizeRaw({
|
|
41917
|
-
protocolV2DeviceInfo: deviceInfo,
|
|
41918
|
-
protocolV2DeviceStatus: deviceStatus,
|
|
41919
|
-
}),
|
|
41920
|
-
}
|
|
41921
|
-
: {}));
|
|
41922
|
-
}
|
|
41923
|
-
|
|
41924
|
-
const getImageVersion = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.version) !== null && _a !== void 0 ? _a : null; };
|
|
41925
|
-
const bytesToHex$2 = (value) => {
|
|
41926
|
-
if (!value)
|
|
41927
|
-
return undefined;
|
|
41928
|
-
if (typeof value === 'string')
|
|
41929
|
-
return value;
|
|
41930
|
-
if (value instanceof Uint8Array) {
|
|
41931
|
-
return Array.from(value)
|
|
41932
|
-
.map(byte => byte.toString(16).padStart(2, '0'))
|
|
41933
|
-
.join('');
|
|
41934
|
-
}
|
|
41935
|
-
if (Array.isArray(value)) {
|
|
41936
|
-
return value.map(byte => Number(byte).toString(16).padStart(2, '0')).join('');
|
|
41937
|
-
}
|
|
41938
|
-
return undefined;
|
|
41939
|
-
};
|
|
41940
|
-
const getImageBuildId = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.build_id) !== null && _a !== void 0 ? _a : undefined; };
|
|
41941
|
-
const getImageHash = (image) => bytesToHex$2(image === null || image === void 0 ? void 0 : image.hash);
|
|
41942
|
-
const firstValue = (...values) => values.find(value => value !== undefined && value !== null);
|
|
41943
|
-
const firstMeaningfulVersion = (...versions) => { var _a; return (_a = versions.find(version => Boolean(version && version !== '0.0.0'))) !== null && _a !== void 0 ? _a : null; };
|
|
41944
|
-
const versionFromParts = (major, minor, patch) => [major, minor, patch].map(part => Number(part) || 0).join('.');
|
|
41945
|
-
const getProtocolV1Mode = (features) => {
|
|
41946
|
-
if (features.bootloader_mode === true)
|
|
41947
|
-
return 'bootloader';
|
|
41948
|
-
if (features.initialized === false)
|
|
41949
|
-
return 'notInitialized';
|
|
41950
|
-
if (features.initialized === true)
|
|
41951
|
-
return 'normal';
|
|
41952
|
-
return 'unknown';
|
|
41953
|
-
};
|
|
41954
|
-
const getProtocolV1DeviceType = (features) => {
|
|
41955
|
-
const onekeyDeviceType = features.onekey_device_type;
|
|
41956
|
-
switch (onekeyDeviceType) {
|
|
41957
|
-
case 'CLASSIC':
|
|
41958
|
-
return hdShared.EDeviceType.Classic;
|
|
41959
|
-
case 'CLASSIC1S':
|
|
41960
|
-
return hdShared.EDeviceType.Classic1s;
|
|
41961
|
-
case 'MINI':
|
|
41962
|
-
return hdShared.EDeviceType.Mini;
|
|
41963
|
-
case 'TOUCH':
|
|
41964
|
-
return hdShared.EDeviceType.Touch;
|
|
41965
|
-
case 'PRO':
|
|
41966
|
-
return hdShared.EDeviceType.Pro;
|
|
41967
|
-
case 'PRO2':
|
|
41968
|
-
case 'pro2':
|
|
41969
|
-
return hdShared.EDeviceType.Pro2;
|
|
41970
|
-
case 'PURE':
|
|
41971
|
-
return hdShared.EDeviceType.ClassicPure;
|
|
41972
|
-
}
|
|
41973
|
-
const serialNo = features.onekey_serial_no || features.onekey_serial || features.serial_no || '';
|
|
41974
|
-
const prefix = serialNo.slice(0, 2).toLowerCase();
|
|
41975
|
-
if (prefix === 'bi' || prefix === 'cl')
|
|
41976
|
-
return hdShared.EDeviceType.Classic;
|
|
41977
|
-
if (prefix === 'cp')
|
|
41978
|
-
return hdShared.EDeviceType.ClassicPure;
|
|
41979
|
-
if (prefix === 'mi')
|
|
41980
|
-
return hdShared.EDeviceType.Mini;
|
|
41981
|
-
if (prefix === 'tc')
|
|
41982
|
-
return hdShared.EDeviceType.Touch;
|
|
41983
|
-
if (prefix === 'pr')
|
|
41984
|
-
return hdShared.EDeviceType.Pro;
|
|
41985
|
-
if (prefix === 'p2')
|
|
41986
|
-
return hdShared.EDeviceType.Pro2;
|
|
41987
|
-
if (!serialNo && features.bootloader_mode === true && features.model === '1') {
|
|
41988
|
-
return hdShared.EDeviceType.Classic;
|
|
41989
|
-
}
|
|
41990
|
-
return hdShared.EDeviceType.Unknown;
|
|
41991
|
-
};
|
|
41992
|
-
const getProtocolV1FirmwareType = (features) => {
|
|
41993
|
-
if (features.fw_vendor === 'OneKey Bitcoin-only')
|
|
41994
|
-
return hdShared.EFirmwareType.BitcoinOnly;
|
|
41995
|
-
return hdShared.EFirmwareType.Universal;
|
|
41996
|
-
};
|
|
41997
|
-
const getProtocolV1Label = (features, deviceType, bleName) => {
|
|
41998
|
-
if (features.label)
|
|
41999
|
-
return features.label;
|
|
42000
|
-
if (bleName)
|
|
42001
|
-
return bleName;
|
|
42002
|
-
if (deviceType === hdShared.EDeviceType.Unknown)
|
|
42003
|
-
return null;
|
|
42004
|
-
if (deviceType === hdShared.EDeviceType.ClassicPure)
|
|
42005
|
-
return 'OneKey Classic 1S';
|
|
42006
|
-
return `OneKey ${deviceType.charAt(0).toUpperCase()}${deviceType.slice(1)}`;
|
|
42007
|
-
};
|
|
42008
|
-
const buildProtocolV1FeaturesPayload = (protocolV1Features, previous) => {
|
|
42009
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
|
|
42010
|
-
const features = protocolV1Features;
|
|
42011
|
-
const firmwareVersion = firstMeaningfulVersion(features.onekey_firmware_version, features.onekey_version, versionFromParts(features.major_version, features.minor_version, features.patch_version));
|
|
42012
|
-
const bootloaderVersion = firstMeaningfulVersion(features.onekey_boot_version, features.bootloader_version, features.bootloader_mode
|
|
42013
|
-
? versionFromParts(features.major_version, features.minor_version, features.patch_version)
|
|
42014
|
-
: null);
|
|
42015
|
-
const boardVersion = firstMeaningfulVersion(features.onekey_board_version, features.boardloader_version);
|
|
42016
|
-
const bleVersion = firstMeaningfulVersion(features.onekey_ble_version, features.ble_ver);
|
|
42017
|
-
const serialNo = features.onekey_serial_no || features.onekey_serial || features.serial_no || '';
|
|
42018
|
-
const bleName = features.onekey_ble_name || features.ble_name || null;
|
|
42019
|
-
const deviceType = getProtocolV1DeviceType(features);
|
|
42020
|
-
const sessionId = (_b = (_a = features.session_id) !== null && _a !== void 0 ? _a : previous === null || previous === void 0 ? void 0 : previous.sessionId) !== null && _b !== void 0 ? _b : null;
|
|
42021
|
-
return Object.assign(Object.assign({}, features), { protocol: 'V1', protocolVersion: (_d = (_c = features.protocol_version) !== null && _c !== void 0 ? _c : previous === null || previous === void 0 ? void 0 : previous.protocolVersion) !== null && _d !== void 0 ? _d : 1, deviceType, firmwareType: getProtocolV1FirmwareType(features), model: (_e = features.model) !== null && _e !== void 0 ? _e : null, vendor: (_f = features.vendor) !== null && _f !== void 0 ? _f : null, deviceId: (_g = features.device_id) !== null && _g !== void 0 ? _g : null, serialNo, label: getProtocolV1Label(features, deviceType, bleName), bleName, capabilities: (_h = features.capabilities) !== null && _h !== void 0 ? _h : [], mode: getProtocolV1Mode(features), initialized: (_j = features.initialized) !== null && _j !== void 0 ? _j : null, bootloaderMode: (_k = features.bootloader_mode) !== null && _k !== void 0 ? _k : null, unlocked: (_l = features.unlocked) !== null && _l !== void 0 ? _l : true, firmwarePresent: (_m = features.firmware_present) !== null && _m !== void 0 ? _m : null, passphraseProtection: (_o = features.passphrase_protection) !== null && _o !== void 0 ? _o : null, pinProtection: (_p = features.pin_protection) !== null && _p !== void 0 ? _p : null, backupRequired: (_q = features.needs_backup) !== null && _q !== void 0 ? _q : null, noBackup: (_r = features.no_backup) !== null && _r !== void 0 ? _r : null, unfinishedBackup: (_s = features.unfinished_backup) !== null && _s !== void 0 ? _s : null, recoveryMode: (_t = features.recovery_mode) !== null && _t !== void 0 ? _t : null, language: (_u = features.language) !== null && _u !== void 0 ? _u : null, bleEnabled: (_v = features.ble_enable) !== null && _v !== void 0 ? _v : null, sdCardPresent: (_w = features.sd_card_present) !== null && _w !== void 0 ? _w : null, sdProtection: (_x = features.sd_protection) !== null && _x !== void 0 ? _x : null, wipeCodeProtection: (_y = features.wipe_code_protection) !== null && _y !== void 0 ? _y : null, passphraseAlwaysOnDevice: (_z = features.passphrase_always_on_device) !== null && _z !== void 0 ? _z : null, safetyChecks: (_0 = features.safety_checks) !== null && _0 !== void 0 ? _0 : null, autoLockDelayMs: (_1 = features.auto_lock_delay_ms) !== null && _1 !== void 0 ? _1 : null, displayRotation: (_2 = features.display_rotation) !== null && _2 !== void 0 ? _2 : null, experimentalFeatures: (_3 = features.experimental_features) !== null && _3 !== void 0 ? _3 : null, firmwareVersion,
|
|
42022
|
-
bootloaderVersion,
|
|
42023
|
-
boardVersion,
|
|
42024
|
-
bleVersion, se01Version: firstMeaningfulVersion(features.onekey_se01_version), se02Version: firstMeaningfulVersion(features.onekey_se02_version), se03Version: firstMeaningfulVersion(features.onekey_se03_version), se04Version: firstMeaningfulVersion(features.onekey_se04_version), se01BootVersion: firstMeaningfulVersion(features.onekey_se01_boot_version), se02BootVersion: firstMeaningfulVersion(features.onekey_se02_boot_version), se03BootVersion: firstMeaningfulVersion(features.onekey_se03_boot_version), se04BootVersion: firstMeaningfulVersion(features.onekey_se04_boot_version), seVersion: (_4 = features.se_ver) !== null && _4 !== void 0 ? _4 : null, verify: {
|
|
42025
|
-
firmwareBuildId: features.onekey_firmware_build_id,
|
|
42026
|
-
firmwareHash: features.onekey_firmware_hash,
|
|
42027
|
-
bootloaderBuildId: features.onekey_boot_build_id,
|
|
42028
|
-
bootloaderHash: features.onekey_boot_hash,
|
|
42029
|
-
boardBuildId: features.onekey_board_build_id,
|
|
42030
|
-
boardHash: features.onekey_board_hash,
|
|
42031
|
-
bleBuildId: features.onekey_ble_build_id,
|
|
42032
|
-
bleHash: features.onekey_ble_hash,
|
|
42033
|
-
se01BuildId: features.onekey_se01_build_id,
|
|
42034
|
-
se01Hash: features.onekey_se01_hash,
|
|
42035
|
-
se02BuildId: features.onekey_se02_build_id,
|
|
42036
|
-
se02Hash: features.onekey_se02_hash,
|
|
42037
|
-
se03BuildId: features.onekey_se03_build_id,
|
|
42038
|
-
se03Hash: features.onekey_se03_hash,
|
|
42039
|
-
se04BuildId: features.onekey_se04_build_id,
|
|
42040
|
-
se04Hash: features.onekey_se04_hash,
|
|
42041
|
-
se01BootBuildId: features.onekey_se01_boot_build_id,
|
|
42042
|
-
se01BootHash: features.onekey_se01_boot_hash,
|
|
42043
|
-
se02BootBuildId: features.onekey_se02_boot_build_id,
|
|
42044
|
-
se02BootHash: features.onekey_se02_boot_hash,
|
|
42045
|
-
se03BootBuildId: features.onekey_se03_boot_build_id,
|
|
42046
|
-
se03BootHash: features.onekey_se03_boot_hash,
|
|
42047
|
-
se04BootBuildId: features.onekey_se04_boot_build_id,
|
|
42048
|
-
se04BootHash: features.onekey_se04_boot_hash,
|
|
42049
|
-
}, sessionId, session_id: sessionId !== null && sessionId !== void 0 ? sessionId : undefined, raw: {
|
|
42050
|
-
protocolV1Features,
|
|
42051
|
-
} });
|
|
42052
|
-
};
|
|
42053
|
-
const buildProtocolV2FeaturesPayload = ({ deviceInfo, deviceStatus, previous, }) => {
|
|
42054
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70;
|
|
42055
|
-
const info = deviceInfo;
|
|
42056
|
-
const fwApplication = (_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application;
|
|
42057
|
-
const fwBootloader = (_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.bootloader;
|
|
42058
|
-
const fwBoard = (_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.romloader;
|
|
42059
|
-
const bleApplication = (_d = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _d === void 0 ? void 0 : _d.application;
|
|
42060
|
-
const status = deviceStatus;
|
|
42061
|
-
const firmwareVersion = firstMeaningfulVersion(getImageVersion(fwApplication), previous === null || previous === void 0 ? void 0 : previous.firmwareVersion);
|
|
42062
|
-
const bootloaderVersion = firstMeaningfulVersion(getImageVersion(fwBootloader), previous === null || previous === void 0 ? void 0 : previous.bootloaderVersion);
|
|
42063
|
-
const boardVersion = firstMeaningfulVersion(getImageVersion(fwBoard), previous === null || previous === void 0 ? void 0 : previous.boardVersion);
|
|
42064
|
-
const bleVersion = firstMeaningfulVersion(getImageVersion(bleApplication), previous === null || previous === void 0 ? void 0 : previous.bleVersion);
|
|
42065
|
-
const deviceId = (_e = status === null || status === void 0 ? void 0 : status.device_id) !== null && _e !== void 0 ? _e : null;
|
|
42066
|
-
const serialNo = (_g = firstValue((_f = info === null || info === void 0 ? void 0 : info.hw) === null || _f === void 0 ? void 0 : _f.serial_no, previous === null || previous === void 0 ? void 0 : previous.serialNo)) !== null && _g !== void 0 ? _g : '';
|
|
42067
|
-
const label = (_h = previous === null || previous === void 0 ? void 0 : previous.label) !== null && _h !== void 0 ? _h : null;
|
|
42068
|
-
const bleName = firstValue((_j = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _j === void 0 ? void 0 : _j.bt_adv_name, previous === null || previous === void 0 ? void 0 : previous.bleName);
|
|
42069
|
-
const initialized = (_k = firstValue(status === null || status === void 0 ? void 0 : status.init_states, previous === null || previous === void 0 ? void 0 : previous.initialized)) !== null && _k !== void 0 ? _k : null;
|
|
42070
|
-
const passphraseProtection = (status === null || status === void 0 ? void 0 : status.unlocked) === true ? (_l = status.passphrase_enabled) !== null && _l !== void 0 ? _l : null : null;
|
|
42071
|
-
const language = (_m = previous === null || previous === void 0 ? void 0 : previous.language) !== null && _m !== void 0 ? _m : null;
|
|
42072
|
-
const backupRequired = (_o = firstValue(status === null || status === void 0 ? void 0 : status.backup_required, previous === null || previous === void 0 ? void 0 : previous.backupRequired)) !== null && _o !== void 0 ? _o : null;
|
|
42073
|
-
const bleEnabled = previous === null || previous === void 0 ? void 0 : previous.bleEnabled;
|
|
42074
|
-
const unlocked = (_p = firstValue(status === null || status === void 0 ? void 0 : status.unlocked, previous === null || previous === void 0 ? void 0 : previous.unlocked)) !== null && _p !== void 0 ? _p : null;
|
|
42075
|
-
const attachToPinEnabled = (_q = status === null || status === void 0 ? void 0 : status.attach_to_pin_enabled) !== null && _q !== void 0 ? _q : null;
|
|
42076
|
-
const unlockedAttachPin = (_r = status === null || status === void 0 ? void 0 : status.unlocked_by_attach_to_pin) !== null && _r !== void 0 ? _r : undefined;
|
|
42077
|
-
const romloaderMode = isProtocolV2RomloaderDeviceInfo(info, status);
|
|
42078
|
-
const bootloaderMode = isProtocolV2BootloaderDeviceInfo(info, status);
|
|
42079
|
-
let mode = 'unknown';
|
|
42080
|
-
if (romloaderMode) {
|
|
42081
|
-
mode = 'romloader';
|
|
42082
|
-
}
|
|
42083
|
-
else if (bootloaderMode) {
|
|
42084
|
-
mode = 'bootloader';
|
|
42085
|
-
}
|
|
42086
|
-
else if (initialized === false) {
|
|
42087
|
-
mode = 'notInitialized';
|
|
42088
|
-
}
|
|
42089
|
-
else if (initialized === true) {
|
|
42090
|
-
mode = 'normal';
|
|
42091
|
-
}
|
|
42092
|
-
return {
|
|
42093
|
-
protocol: 'V2',
|
|
42094
|
-
protocolVersion: (_t = (_s = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.protocol_version) !== null && _s !== void 0 ? _s : previous === null || previous === void 0 ? void 0 : previous.protocolVersion) !== null && _t !== void 0 ? _t : null,
|
|
42095
|
-
deviceType: hdShared.EDeviceType.Pro2,
|
|
42096
|
-
firmwareType: (_u = previous === null || previous === void 0 ? void 0 : previous.firmwareType) !== null && _u !== void 0 ? _u : hdShared.EFirmwareType.Universal,
|
|
42097
|
-
model: 'pro2',
|
|
42098
|
-
vendor: 'onekey.so',
|
|
42099
|
-
deviceId,
|
|
42100
|
-
serialNo,
|
|
42101
|
-
label,
|
|
42102
|
-
bleName: bleName !== null && bleName !== void 0 ? bleName : null,
|
|
42103
|
-
capabilities: [],
|
|
42104
|
-
mode,
|
|
42105
|
-
initialized,
|
|
42106
|
-
bootloaderMode,
|
|
42107
|
-
unlocked,
|
|
42108
|
-
firmwarePresent: (_v = previous === null || previous === void 0 ? void 0 : previous.firmwarePresent) !== null && _v !== void 0 ? _v : null,
|
|
42109
|
-
passphraseProtection,
|
|
42110
|
-
pinProtection: null,
|
|
42111
|
-
backupRequired,
|
|
42112
|
-
noBackup: null,
|
|
42113
|
-
unfinishedBackup: null,
|
|
42114
|
-
recoveryMode: null,
|
|
42115
|
-
language,
|
|
42116
|
-
bleEnabled: bleEnabled !== null && bleEnabled !== void 0 ? bleEnabled : null,
|
|
42117
|
-
sdCardPresent: null,
|
|
42118
|
-
sdProtection: null,
|
|
42119
|
-
wipeCodeProtection: null,
|
|
42120
|
-
passphraseAlwaysOnDevice: null,
|
|
42121
|
-
attachToPinEnabled,
|
|
42122
|
-
safetyChecks: null,
|
|
42123
|
-
autoLockDelayMs: null,
|
|
42124
|
-
displayRotation: null,
|
|
42125
|
-
experimentalFeatures: null,
|
|
42126
|
-
firmwareVersion,
|
|
42127
|
-
bootloaderVersion,
|
|
42128
|
-
boardVersion,
|
|
42129
|
-
bleVersion,
|
|
42130
|
-
se01Version: firstMeaningfulVersion(getImageVersion((_w = info === null || info === void 0 ? void 0 : info.se1) === null || _w === void 0 ? void 0 : _w.application), previous === null || previous === void 0 ? void 0 : previous.se01Version),
|
|
42131
|
-
se02Version: firstMeaningfulVersion(getImageVersion((_x = info === null || info === void 0 ? void 0 : info.se2) === null || _x === void 0 ? void 0 : _x.application), previous === null || previous === void 0 ? void 0 : previous.se02Version),
|
|
42132
|
-
se03Version: firstMeaningfulVersion(getImageVersion((_y = info === null || info === void 0 ? void 0 : info.se3) === null || _y === void 0 ? void 0 : _y.application), previous === null || previous === void 0 ? void 0 : previous.se03Version),
|
|
42133
|
-
se04Version: firstMeaningfulVersion(getImageVersion((_z = info === null || info === void 0 ? void 0 : info.se4) === null || _z === void 0 ? void 0 : _z.application), previous === null || previous === void 0 ? void 0 : previous.se04Version),
|
|
42134
|
-
se01BootVersion: firstMeaningfulVersion(getImageVersion((_0 = info === null || info === void 0 ? void 0 : info.se1) === null || _0 === void 0 ? void 0 : _0.bootloader), previous === null || previous === void 0 ? void 0 : previous.se01BootVersion),
|
|
42135
|
-
se02BootVersion: firstMeaningfulVersion(getImageVersion((_1 = info === null || info === void 0 ? void 0 : info.se2) === null || _1 === void 0 ? void 0 : _1.bootloader), previous === null || previous === void 0 ? void 0 : previous.se02BootVersion),
|
|
42136
|
-
se03BootVersion: firstMeaningfulVersion(getImageVersion((_2 = info === null || info === void 0 ? void 0 : info.se3) === null || _2 === void 0 ? void 0 : _2.bootloader), previous === null || previous === void 0 ? void 0 : previous.se03BootVersion),
|
|
42137
|
-
se04BootVersion: firstMeaningfulVersion(getImageVersion((_3 = info === null || info === void 0 ? void 0 : info.se4) === null || _3 === void 0 ? void 0 : _3.bootloader), previous === null || previous === void 0 ? void 0 : previous.se04BootVersion),
|
|
42138
|
-
seVersion: (_4 = previous === null || previous === void 0 ? void 0 : previous.seVersion) !== null && _4 !== void 0 ? _4 : null,
|
|
42139
|
-
verify: {
|
|
42140
|
-
firmwareBuildId: (_5 = getImageBuildId(fwApplication)) !== null && _5 !== void 0 ? _5 : (_6 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _6 === void 0 ? void 0 : _6.firmwareBuildId,
|
|
42141
|
-
firmwareHash: (_7 = getImageHash(fwApplication)) !== null && _7 !== void 0 ? _7 : (_8 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _8 === void 0 ? void 0 : _8.firmwareHash,
|
|
42142
|
-
bootloaderBuildId: (_9 = getImageBuildId(fwBootloader)) !== null && _9 !== void 0 ? _9 : (_10 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _10 === void 0 ? void 0 : _10.bootloaderBuildId,
|
|
42143
|
-
bootloaderHash: (_11 = getImageHash(fwBootloader)) !== null && _11 !== void 0 ? _11 : (_12 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _12 === void 0 ? void 0 : _12.bootloaderHash,
|
|
42144
|
-
boardBuildId: (_13 = getImageBuildId(fwBoard)) !== null && _13 !== void 0 ? _13 : (_14 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _14 === void 0 ? void 0 : _14.boardBuildId,
|
|
42145
|
-
boardHash: (_15 = getImageHash(fwBoard)) !== null && _15 !== void 0 ? _15 : (_16 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _16 === void 0 ? void 0 : _16.boardHash,
|
|
42146
|
-
bleBuildId: (_17 = getImageBuildId(bleApplication)) !== null && _17 !== void 0 ? _17 : (_18 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _18 === void 0 ? void 0 : _18.bleBuildId,
|
|
42147
|
-
bleHash: (_19 = getImageHash(bleApplication)) !== null && _19 !== void 0 ? _19 : (_20 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _20 === void 0 ? void 0 : _20.bleHash,
|
|
42148
|
-
se01BuildId: (_22 = getImageBuildId((_21 = info === null || info === void 0 ? void 0 : info.se1) === null || _21 === void 0 ? void 0 : _21.application)) !== null && _22 !== void 0 ? _22 : (_23 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _23 === void 0 ? void 0 : _23.se01BuildId,
|
|
42149
|
-
se01Hash: (_25 = getImageHash((_24 = info === null || info === void 0 ? void 0 : info.se1) === null || _24 === void 0 ? void 0 : _24.application)) !== null && _25 !== void 0 ? _25 : (_26 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _26 === void 0 ? void 0 : _26.se01Hash,
|
|
42150
|
-
se02BuildId: (_28 = getImageBuildId((_27 = info === null || info === void 0 ? void 0 : info.se2) === null || _27 === void 0 ? void 0 : _27.application)) !== null && _28 !== void 0 ? _28 : (_29 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _29 === void 0 ? void 0 : _29.se02BuildId,
|
|
42151
|
-
se02Hash: (_31 = getImageHash((_30 = info === null || info === void 0 ? void 0 : info.se2) === null || _30 === void 0 ? void 0 : _30.application)) !== null && _31 !== void 0 ? _31 : (_32 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _32 === void 0 ? void 0 : _32.se02Hash,
|
|
42152
|
-
se03BuildId: (_34 = getImageBuildId((_33 = info === null || info === void 0 ? void 0 : info.se3) === null || _33 === void 0 ? void 0 : _33.application)) !== null && _34 !== void 0 ? _34 : (_35 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _35 === void 0 ? void 0 : _35.se03BuildId,
|
|
42153
|
-
se03Hash: (_37 = getImageHash((_36 = info === null || info === void 0 ? void 0 : info.se3) === null || _36 === void 0 ? void 0 : _36.application)) !== null && _37 !== void 0 ? _37 : (_38 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _38 === void 0 ? void 0 : _38.se03Hash,
|
|
42154
|
-
se04BuildId: (_40 = getImageBuildId((_39 = info === null || info === void 0 ? void 0 : info.se4) === null || _39 === void 0 ? void 0 : _39.application)) !== null && _40 !== void 0 ? _40 : (_41 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _41 === void 0 ? void 0 : _41.se04BuildId,
|
|
42155
|
-
se04Hash: (_43 = getImageHash((_42 = info === null || info === void 0 ? void 0 : info.se4) === null || _42 === void 0 ? void 0 : _42.application)) !== null && _43 !== void 0 ? _43 : (_44 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _44 === void 0 ? void 0 : _44.se04Hash,
|
|
42156
|
-
se01BootBuildId: (_46 = getImageBuildId((_45 = info === null || info === void 0 ? void 0 : info.se1) === null || _45 === void 0 ? void 0 : _45.bootloader)) !== null && _46 !== void 0 ? _46 : (_47 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _47 === void 0 ? void 0 : _47.se01BootBuildId,
|
|
42157
|
-
se01BootHash: (_49 = getImageHash((_48 = info === null || info === void 0 ? void 0 : info.se1) === null || _48 === void 0 ? void 0 : _48.bootloader)) !== null && _49 !== void 0 ? _49 : (_50 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _50 === void 0 ? void 0 : _50.se01BootHash,
|
|
42158
|
-
se02BootBuildId: (_52 = getImageBuildId((_51 = info === null || info === void 0 ? void 0 : info.se2) === null || _51 === void 0 ? void 0 : _51.bootloader)) !== null && _52 !== void 0 ? _52 : (_53 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _53 === void 0 ? void 0 : _53.se02BootBuildId,
|
|
42159
|
-
se02BootHash: (_55 = getImageHash((_54 = info === null || info === void 0 ? void 0 : info.se2) === null || _54 === void 0 ? void 0 : _54.bootloader)) !== null && _55 !== void 0 ? _55 : (_56 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _56 === void 0 ? void 0 : _56.se02BootHash,
|
|
42160
|
-
se03BootBuildId: (_58 = getImageBuildId((_57 = info === null || info === void 0 ? void 0 : info.se3) === null || _57 === void 0 ? void 0 : _57.bootloader)) !== null && _58 !== void 0 ? _58 : (_59 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _59 === void 0 ? void 0 : _59.se03BootBuildId,
|
|
42161
|
-
se03BootHash: (_61 = getImageHash((_60 = info === null || info === void 0 ? void 0 : info.se3) === null || _60 === void 0 ? void 0 : _60.bootloader)) !== null && _61 !== void 0 ? _61 : (_62 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _62 === void 0 ? void 0 : _62.se03BootHash,
|
|
42162
|
-
se04BootBuildId: (_64 = getImageBuildId((_63 = info === null || info === void 0 ? void 0 : info.se4) === null || _63 === void 0 ? void 0 : _63.bootloader)) !== null && _64 !== void 0 ? _64 : (_65 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _65 === void 0 ? void 0 : _65.se04BootBuildId,
|
|
42163
|
-
se04BootHash: (_67 = getImageHash((_66 = info === null || info === void 0 ? void 0 : info.se4) === null || _66 === void 0 ? void 0 : _66.bootloader)) !== null && _67 !== void 0 ? _67 : (_68 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _68 === void 0 ? void 0 : _68.se04BootHash,
|
|
42164
|
-
},
|
|
42165
|
-
sessionId: (_69 = previous === null || previous === void 0 ? void 0 : previous.sessionId) !== null && _69 !== void 0 ? _69 : null,
|
|
42166
|
-
device_id: deviceId !== null && deviceId !== void 0 ? deviceId : undefined,
|
|
42167
|
-
session_id: (_70 = previous === null || previous === void 0 ? void 0 : previous.sessionId) !== null && _70 !== void 0 ? _70 : undefined,
|
|
42168
|
-
ble_name: bleName !== null && bleName !== void 0 ? bleName : undefined,
|
|
42169
|
-
onekey_device_type: 'PRO2',
|
|
42170
|
-
passphrase_protection: passphraseProtection !== null && passphraseProtection !== void 0 ? passphraseProtection : undefined,
|
|
42171
|
-
bootloader_mode: bootloaderMode,
|
|
42172
|
-
passphraseState: previous === null || previous === void 0 ? void 0 : previous.passphraseState,
|
|
42173
|
-
unlockedAttachPin,
|
|
42174
|
-
raw: {
|
|
42175
|
-
protocolV2DeviceInfo: deviceInfo,
|
|
42176
|
-
protocolV2DeviceStatus: deviceStatus,
|
|
42177
|
-
},
|
|
42178
|
-
};
|
|
42179
|
-
};
|
|
42180
|
-
|
|
42181
42704
|
const parseRunOptions = (options) => {
|
|
42182
42705
|
if (!options)
|
|
42183
42706
|
options = {};
|
|
42184
42707
|
return options;
|
|
42185
42708
|
};
|
|
42186
|
-
const Log$
|
|
42709
|
+
const Log$e = getLogger(exports.LoggerNames.Device);
|
|
42187
42710
|
function preloadSessionCache(deviceId, passphraseState, sessionId) {
|
|
42188
42711
|
deviceWalletSessionStore.set(deviceId, passphraseState, sessionId);
|
|
42189
42712
|
}
|
|
42190
42713
|
class Device extends events.exports {
|
|
42714
|
+
get state() {
|
|
42715
|
+
return this.stateStore.getState();
|
|
42716
|
+
}
|
|
42717
|
+
get features() {
|
|
42718
|
+
return this.state ? projectFeatures(this.state) : undefined;
|
|
42719
|
+
}
|
|
42720
|
+
set features(features) {
|
|
42721
|
+
this.stateStore = new DeviceStateStore();
|
|
42722
|
+
if (features) {
|
|
42723
|
+
this.stateStore.update(mapFeaturesToState(features), 'compatibility');
|
|
42724
|
+
}
|
|
42725
|
+
}
|
|
42191
42726
|
constructor(descriptor, sdkInstanceId) {
|
|
42192
42727
|
super();
|
|
42193
42728
|
this.deviceConnector = null;
|
|
42194
42729
|
this.deviceAcquired = false;
|
|
42195
|
-
this.
|
|
42196
|
-
this.
|
|
42730
|
+
this.stateStore = new DeviceStateStore();
|
|
42731
|
+
this.protocolV2StateNeedsReload = false;
|
|
42197
42732
|
this.externalState = [];
|
|
42198
42733
|
this.unavailableCapabilities = {};
|
|
42199
42734
|
this.instance = 0;
|
|
@@ -42205,7 +42740,7 @@ class Device extends events.exports {
|
|
|
42205
42740
|
this.sdkInstanceId = sdkInstanceId;
|
|
42206
42741
|
this.instanceId = generateInstanceId('Device', this.sdkInstanceId);
|
|
42207
42742
|
this.createdAt = Date.now();
|
|
42208
|
-
Log$
|
|
42743
|
+
Log$e.debug(`[Device] Created: ${this.instanceId}${this.sdkInstanceId ? ` for SDK: ${this.sdkInstanceId}` : ''}`);
|
|
42209
42744
|
}
|
|
42210
42745
|
static fromDescriptor(originalDescriptor, sdkInstanceId) {
|
|
42211
42746
|
const descriptor = Object.assign({}, originalDescriptor);
|
|
@@ -42223,6 +42758,7 @@ class Device extends events.exports {
|
|
|
42223
42758
|
const connectId = this.getConnectId();
|
|
42224
42759
|
const deviceId = this.getCurrentDeviceId() || null;
|
|
42225
42760
|
const { features } = this;
|
|
42761
|
+
const state = this.state ? createPublicDeviceState(this.state) : undefined;
|
|
42226
42762
|
return {
|
|
42227
42763
|
connectId: DataManager.isBleConnect(env) ? this.mainId || null : connectId,
|
|
42228
42764
|
uuid: serialNo,
|
|
@@ -42235,9 +42771,11 @@ class Device extends events.exports {
|
|
|
42235
42771
|
path: (_a = this.originalDescriptor) === null || _a === void 0 ? void 0 : _a.path,
|
|
42236
42772
|
bleName,
|
|
42237
42773
|
name: bleName || label || `OneKey ${deviceType === null || deviceType === void 0 ? void 0 : deviceType.toUpperCase()}`,
|
|
42774
|
+
displayName: label || bleName || `OneKey ${deviceType === null || deviceType === void 0 ? void 0 : deviceType.toUpperCase()}`,
|
|
42238
42775
|
label: label || 'OneKey',
|
|
42239
42776
|
mode: this.getMode(),
|
|
42240
42777
|
features,
|
|
42778
|
+
state,
|
|
42241
42779
|
sessionId: (_c = (_b = this.features) === null || _b === void 0 ? void 0 : _b.sessionId) !== null && _c !== void 0 ? _c : null,
|
|
42242
42780
|
firmwareVersion: this.getFirmwareVersion(),
|
|
42243
42781
|
bleFirmwareVersion: this.getBLEFirmwareVersion(),
|
|
@@ -42285,12 +42823,12 @@ class Device extends events.exports {
|
|
|
42285
42823
|
if (DataManager.isBleConnect(env)) {
|
|
42286
42824
|
acquireResult = yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.originalDescriptor.id, undefined, true, expectedProtocol));
|
|
42287
42825
|
this.mainId = (_b = acquireResult === null || acquireResult === void 0 ? void 0 : acquireResult.uuid) !== null && _b !== void 0 ? _b : '';
|
|
42288
|
-
Log$
|
|
42826
|
+
Log$e.debug('Expected uuid:', this.mainId);
|
|
42289
42827
|
}
|
|
42290
42828
|
else {
|
|
42291
42829
|
acquireResult = yield ((_c = this.deviceConnector) === null || _c === void 0 ? void 0 : _c.acquire(this.originalDescriptor.path, this.originalDescriptor.session, undefined, expectedProtocol));
|
|
42292
42830
|
this.mainId = acquireResult;
|
|
42293
|
-
Log$
|
|
42831
|
+
Log$e.debug('Expected session id:', this.mainId);
|
|
42294
42832
|
}
|
|
42295
42833
|
this.deviceAcquired = true;
|
|
42296
42834
|
this.updateDescriptor({ [mainIdKey]: this.mainId });
|
|
@@ -42325,11 +42863,11 @@ class Device extends events.exports {
|
|
|
42325
42863
|
(this.mainId && DataManager.isBleConnect(env))) {
|
|
42326
42864
|
if (this.pendingCallbackPromise) {
|
|
42327
42865
|
try {
|
|
42328
|
-
Log$
|
|
42866
|
+
Log$e.debug('Waiting for callback tasks to complete before releasing device (in release method)');
|
|
42329
42867
|
yield this.pendingCallbackPromise.promise;
|
|
42330
42868
|
}
|
|
42331
42869
|
catch (error) {
|
|
42332
|
-
Log$
|
|
42870
|
+
Log$e.error('Error waiting for callback tasks in release method:', error);
|
|
42333
42871
|
}
|
|
42334
42872
|
}
|
|
42335
42873
|
if (this.commands) {
|
|
@@ -42348,7 +42886,7 @@ class Device extends events.exports {
|
|
|
42348
42886
|
this.updateDescriptor({ session: null });
|
|
42349
42887
|
}
|
|
42350
42888
|
catch (err) {
|
|
42351
|
-
Log$
|
|
42889
|
+
Log$e.error('[Device] release error: ', err);
|
|
42352
42890
|
}
|
|
42353
42891
|
finally {
|
|
42354
42892
|
this.needReloadDevice = true;
|
|
@@ -42523,7 +43061,7 @@ class Device extends events.exports {
|
|
|
42523
43061
|
}
|
|
42524
43062
|
getInternalState(_deviceId) {
|
|
42525
43063
|
var _a;
|
|
42526
|
-
Log$
|
|
43064
|
+
Log$e.debug('getInternalState session param: ', `device_id: ${_deviceId}`, `features.deviceId: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.deviceId}`, `passphraseState: ${this.passphraseState}`);
|
|
42527
43065
|
const deviceId = this.getSessionCacheDeviceKey(_deviceId);
|
|
42528
43066
|
if (!deviceId)
|
|
42529
43067
|
return undefined;
|
|
@@ -42532,7 +43070,7 @@ class Device extends events.exports {
|
|
|
42532
43070
|
return deviceWalletSessionStore.get(deviceId, this.passphraseState);
|
|
42533
43071
|
}
|
|
42534
43072
|
updateInternalState(enablePassphrase, passphraseState, deviceId, sessionId = null, featuresSessionId = null) {
|
|
42535
|
-
Log$
|
|
43073
|
+
Log$e.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `passphraseState: ${passphraseState}`, `hasSessionId: ${Boolean(sessionId)}`, `hasFeaturesSessionId: ${Boolean(featuresSessionId)}`);
|
|
42536
43074
|
const cacheDeviceKey = this.getSessionCacheDeviceKey(deviceId);
|
|
42537
43075
|
if (!cacheDeviceKey)
|
|
42538
43076
|
return;
|
|
@@ -42544,7 +43082,7 @@ class Device extends events.exports {
|
|
|
42544
43082
|
}
|
|
42545
43083
|
setInternalState(state, initSession) {
|
|
42546
43084
|
var _a;
|
|
42547
|
-
Log$
|
|
43085
|
+
Log$e.debug('setInternalState session param: ', `hasState: ${Boolean(state)}`, `initSession: ${initSession}`, `deviceId: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.deviceId}`, `passphraseState: ${this.passphraseState}`);
|
|
42548
43086
|
if (!this.passphraseState && !initSession)
|
|
42549
43087
|
return;
|
|
42550
43088
|
const deviceId = this.getSessionCacheDeviceKey();
|
|
@@ -42558,7 +43096,7 @@ class Device extends events.exports {
|
|
|
42558
43096
|
}
|
|
42559
43097
|
}
|
|
42560
43098
|
clearInternalState(_deviceId) {
|
|
42561
|
-
Log$
|
|
43099
|
+
Log$e.debug('clearInternalState param: ', _deviceId);
|
|
42562
43100
|
const deviceId = this.getSessionCacheDeviceKey(_deviceId);
|
|
42563
43101
|
if (!deviceId)
|
|
42564
43102
|
return;
|
|
@@ -42568,16 +43106,18 @@ class Device extends events.exports {
|
|
|
42568
43106
|
}
|
|
42569
43107
|
}
|
|
42570
43108
|
initialize(options) {
|
|
43109
|
+
var _a;
|
|
42571
43110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42572
43111
|
if (this.isProtocolV2()) {
|
|
42573
43112
|
this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
|
|
42574
|
-
if (this.
|
|
42575
|
-
if (this.features.bootloaderMode) {
|
|
43113
|
+
if (this.state && !(options === null || options === void 0 ? void 0 : options.initSession) && !this.protocolV2StateNeedsReload) {
|
|
43114
|
+
if ((_a = this.features) === null || _a === void 0 ? void 0 : _a.bootloaderMode) {
|
|
42576
43115
|
return;
|
|
42577
43116
|
}
|
|
42578
43117
|
return;
|
|
42579
43118
|
}
|
|
42580
43119
|
yield this._initializeProtocolV2(options);
|
|
43120
|
+
this.protocolV2StateNeedsReload = false;
|
|
42581
43121
|
return;
|
|
42582
43122
|
}
|
|
42583
43123
|
this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
|
|
@@ -42610,31 +43150,24 @@ class Device extends events.exports {
|
|
|
42610
43150
|
yield TransportManager.reconfigure(this.features);
|
|
42611
43151
|
}
|
|
42612
43152
|
catch (error) {
|
|
42613
|
-
Log$
|
|
43153
|
+
Log$e.error('Initialization failed:', error);
|
|
42614
43154
|
throw error;
|
|
42615
43155
|
}
|
|
42616
43156
|
});
|
|
42617
43157
|
}
|
|
42618
43158
|
_initializeProtocolV2(options) {
|
|
42619
43159
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42620
|
-
Log$
|
|
43160
|
+
Log$e.debug('Initialize device via Protocol V2 features adapter');
|
|
42621
43161
|
try {
|
|
42622
43162
|
const deviceInfo = yield requestProtocolV2DeviceInfo({
|
|
42623
43163
|
commands: this.commands,
|
|
42624
43164
|
timeoutMs: options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs,
|
|
42625
43165
|
});
|
|
42626
|
-
const
|
|
42627
|
-
|
|
42628
|
-
}).catch(error => {
|
|
42629
|
-
Log$d.debug('Protocol V2 status unavailable during initialization:', error);
|
|
42630
|
-
return undefined;
|
|
42631
|
-
});
|
|
42632
|
-
const features = this.updateProtocolV2Features(deviceInfo, deviceStatus);
|
|
42633
|
-
Log$d.debug('Protocol V2 features:', features);
|
|
42634
|
-
this.featuresNeedsReload = false;
|
|
43166
|
+
const features = this.updateProtocolV2Features(deviceInfo, null);
|
|
43167
|
+
Log$e.debug('Protocol V2 features:', features);
|
|
42635
43168
|
}
|
|
42636
43169
|
catch (error) {
|
|
42637
|
-
Log$
|
|
43170
|
+
Log$e.error('Protocol V2 initialization failed:', error);
|
|
42638
43171
|
throw error;
|
|
42639
43172
|
}
|
|
42640
43173
|
});
|
|
@@ -42645,16 +43178,69 @@ class Device extends events.exports {
|
|
|
42645
43178
|
const deviceInfo = yield requestProtocolV2DeviceInfo({
|
|
42646
43179
|
commands: this.commands,
|
|
42647
43180
|
});
|
|
42648
|
-
|
|
42649
|
-
commands: this.commands,
|
|
42650
|
-
}).catch(() => undefined);
|
|
42651
|
-
return this.updateProtocolV2Features(deviceInfo, deviceStatus);
|
|
43181
|
+
return this.updateProtocolV2Features(deviceInfo, null);
|
|
42652
43182
|
}
|
|
42653
43183
|
const { message } = yield this.commands.typedCall('GetFeatures', 'Features', {});
|
|
42654
43184
|
this._updateFeatures(message);
|
|
42655
43185
|
return this.features;
|
|
42656
43186
|
});
|
|
42657
43187
|
}
|
|
43188
|
+
getDeviceState(params = {}) {
|
|
43189
|
+
var _a, _b, _c, _d;
|
|
43190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43191
|
+
const refresh = new Set((_a = params.refreshSections) !== null && _a !== void 0 ? _a : []);
|
|
43192
|
+
const getProtocolV2DeviceInfoRequest = () => {
|
|
43193
|
+
if (refresh.has('verification'))
|
|
43194
|
+
return PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST;
|
|
43195
|
+
if (refresh.has('versions'))
|
|
43196
|
+
return PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST;
|
|
43197
|
+
return PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST;
|
|
43198
|
+
};
|
|
43199
|
+
let initializedWithDeviceInfo = false;
|
|
43200
|
+
if (!this.state) {
|
|
43201
|
+
if (this.isProtocolV2()) {
|
|
43202
|
+
const deviceInfo = yield requestProtocolV2DeviceInfo({
|
|
43203
|
+
commands: this.commands,
|
|
43204
|
+
request: getProtocolV2DeviceInfoRequest(),
|
|
43205
|
+
});
|
|
43206
|
+
this.updateState(mapProtocolV2DeviceInfoToState(deviceInfo), 'device-info');
|
|
43207
|
+
initializedWithDeviceInfo = true;
|
|
43208
|
+
}
|
|
43209
|
+
else {
|
|
43210
|
+
yield this.getFeatures();
|
|
43211
|
+
}
|
|
43212
|
+
}
|
|
43213
|
+
else if (!this.isProtocolV2() && refresh.size > 0) {
|
|
43214
|
+
yield this.getFeatures();
|
|
43215
|
+
}
|
|
43216
|
+
if (!this.isProtocolV2() && refresh.has('verification')) {
|
|
43217
|
+
const { message } = yield this.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
|
|
43218
|
+
this.updateState(mapProtocolV1OnekeyFeaturesToState(message), 'device-info');
|
|
43219
|
+
}
|
|
43220
|
+
if (this.isProtocolV2()) {
|
|
43221
|
+
const refreshDeviceInfo = refresh.has('identity') || refresh.has('versions') || refresh.has('verification');
|
|
43222
|
+
if (refreshDeviceInfo && !initializedWithDeviceInfo) {
|
|
43223
|
+
const deviceInfo = yield requestProtocolV2DeviceInfo({
|
|
43224
|
+
commands: this.commands,
|
|
43225
|
+
request: getProtocolV2DeviceInfoRequest(),
|
|
43226
|
+
});
|
|
43227
|
+
this.updateState(mapProtocolV2DeviceInfoToState(deviceInfo, (_b = this.state) === null || _b === void 0 ? void 0 : _b.status.mode), 'device-info');
|
|
43228
|
+
}
|
|
43229
|
+
if (refresh.has('status') && ((_c = this.state) === null || _c === void 0 ? void 0 : _c.status.mode) === 'normal') {
|
|
43230
|
+
const status = yield requestProtocolV2DeviceStatus({ commands: this.commands });
|
|
43231
|
+
this.updateState(mapProtocolV2DeviceStatusToState(status), 'device-status');
|
|
43232
|
+
}
|
|
43233
|
+
if (refresh.has('settings') && ((_d = this.state) === null || _d === void 0 ? void 0 : _d.status.mode) === 'normal') {
|
|
43234
|
+
const { message } = yield this.commands.typedCall('DeviceSettingsGet', 'DeviceSettings', {});
|
|
43235
|
+
this.updateState(mapDeviceSettingsToState(message), 'apply-settings');
|
|
43236
|
+
}
|
|
43237
|
+
}
|
|
43238
|
+
if (!this.state) {
|
|
43239
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed);
|
|
43240
|
+
}
|
|
43241
|
+
return params.includeRaw ? structuredClone(this.state) : createPublicDeviceState(this.state);
|
|
43242
|
+
});
|
|
43243
|
+
}
|
|
42658
43244
|
_updateFeatures(protoFeatures, initSession) {
|
|
42659
43245
|
var _a, _b;
|
|
42660
43246
|
const previousCacheDeviceKey = this.getSessionCacheDeviceKey();
|
|
@@ -42666,7 +43252,7 @@ class Device extends events.exports {
|
|
|
42666
43252
|
}
|
|
42667
43253
|
feat.unlocked = (_b = feat.unlocked) !== null && _b !== void 0 ? _b : true;
|
|
42668
43254
|
feat = fixFeaturesFirmwareVersion(feat);
|
|
42669
|
-
this.
|
|
43255
|
+
this.updateState(mapFeaturesToState(feat), 'initialize');
|
|
42670
43256
|
const nextCacheDeviceKey = this.getSessionCacheDeviceKey();
|
|
42671
43257
|
if (previousCacheDeviceKey && nextCacheDeviceKey) {
|
|
42672
43258
|
deviceWalletSessionStore.migrateDeviceKey(previousCacheDeviceKey, nextCacheDeviceKey);
|
|
@@ -42674,35 +43260,118 @@ class Device extends events.exports {
|
|
|
42674
43260
|
if (feat.deviceId && feat.sessionId) {
|
|
42675
43261
|
this.setInternalState(feat.sessionId, initSession);
|
|
42676
43262
|
}
|
|
42677
|
-
|
|
42678
|
-
|
|
43263
|
+
}
|
|
43264
|
+
updateState(patch, source) {
|
|
43265
|
+
var _a;
|
|
43266
|
+
const result = this.stateStore.update(patch, source);
|
|
43267
|
+
if (result.changedKeys.length === 0)
|
|
43268
|
+
return result.state;
|
|
43269
|
+
const event = {
|
|
43270
|
+
connectId: (_a = this.getConnectId()) !== null && _a !== void 0 ? _a : null,
|
|
43271
|
+
state: createPublicDeviceState(result.state),
|
|
43272
|
+
revision: result.revision,
|
|
43273
|
+
source,
|
|
43274
|
+
changedKeys: result.changedKeys,
|
|
43275
|
+
};
|
|
43276
|
+
Log$e.debug('Device state patch committed', {
|
|
43277
|
+
source,
|
|
43278
|
+
keys: result.changedKeys,
|
|
43279
|
+
});
|
|
43280
|
+
this.emit(DEVICE.STATE, this, event);
|
|
43281
|
+
if (result.state.protocol === 'V1') {
|
|
43282
|
+
this.emit(DEVICE.FEATURES, this, projectFeatures(result.state));
|
|
43283
|
+
}
|
|
43284
|
+
return result.state;
|
|
43285
|
+
}
|
|
43286
|
+
clearCachedSession(deviceId, passphraseState) {
|
|
43287
|
+
const current = this.state;
|
|
43288
|
+
if (!(current === null || current === void 0 ? void 0 : current.session))
|
|
43289
|
+
return false;
|
|
43290
|
+
if (deviceId && current.identity.deviceId !== deviceId)
|
|
43291
|
+
return false;
|
|
43292
|
+
if (passphraseState && current.session.passphraseState !== passphraseState)
|
|
43293
|
+
return false;
|
|
43294
|
+
return this.stateStore.clearSession('session-clear') !== undefined;
|
|
43295
|
+
}
|
|
43296
|
+
updateFeaturesPatch(patch, source) {
|
|
43297
|
+
const currentFeatures = this.features;
|
|
43298
|
+
if (!currentFeatures)
|
|
43299
|
+
return undefined;
|
|
43300
|
+
const features = mergeDeviceFeaturesPatch(currentFeatures, patch);
|
|
43301
|
+
if (features === currentFeatures)
|
|
43302
|
+
return currentFeatures;
|
|
43303
|
+
const normalized = fixFeaturesFirmwareVersion(features);
|
|
43304
|
+
this.updateState(mapFeaturesToState(normalized), source);
|
|
43305
|
+
return this.features;
|
|
42679
43306
|
}
|
|
42680
43307
|
updateProtocolV2Features(deviceInfo, deviceStatus) {
|
|
42681
|
-
var _a
|
|
43308
|
+
var _a;
|
|
42682
43309
|
const previousCacheDeviceKey = this.getSessionCacheDeviceKey();
|
|
42683
|
-
|
|
42684
|
-
|
|
42685
|
-
|
|
42686
|
-
|
|
42687
|
-
deviceInfo,
|
|
42688
|
-
|
|
42689
|
-
previous: this.features,
|
|
42690
|
-
}));
|
|
42691
|
-
this.features = features;
|
|
43310
|
+
if (deviceStatus) {
|
|
43311
|
+
this.updateState(mapProtocolV2DeviceStatusToState(deviceStatus), 'device-status');
|
|
43312
|
+
}
|
|
43313
|
+
if (deviceInfo) {
|
|
43314
|
+
this.updateState(mapProtocolV2DeviceInfoToState(deviceInfo, (_a = this.state) === null || _a === void 0 ? void 0 : _a.status.mode), 'device-info');
|
|
43315
|
+
}
|
|
42692
43316
|
const nextCacheDeviceKey = this.getSessionCacheDeviceKey();
|
|
42693
43317
|
if (previousCacheDeviceKey && nextCacheDeviceKey) {
|
|
42694
43318
|
deviceWalletSessionStore.migrateDeviceKey(previousCacheDeviceKey, nextCacheDeviceKey);
|
|
42695
43319
|
}
|
|
42696
|
-
this.
|
|
42697
|
-
this.emit(DEVICE.FEATURES, this, features);
|
|
42698
|
-
return features;
|
|
43320
|
+
return this.features;
|
|
42699
43321
|
}
|
|
42700
43322
|
updateProtocolV2Status(status) {
|
|
42701
43323
|
var _a, _b, _c, _d;
|
|
42702
|
-
const previousDeviceInfo = (_b = (_a = this.
|
|
42703
|
-
const previousStatus = (_d = (_c = this.
|
|
43324
|
+
const previousDeviceInfo = (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.protocolV2DeviceInfo;
|
|
43325
|
+
const previousStatus = (_d = (_c = this.state) === null || _c === void 0 ? void 0 : _c.raw) === null || _d === void 0 ? void 0 : _d.protocolV2DeviceStatus;
|
|
42704
43326
|
return this.updateProtocolV2Features(previousDeviceInfo, Object.assign(Object.assign({}, previousStatus), status));
|
|
42705
43327
|
}
|
|
43328
|
+
markTransportDisconnected() {
|
|
43329
|
+
if (!this.isProtocolV2())
|
|
43330
|
+
return;
|
|
43331
|
+
this.protocolV2StateNeedsReload = true;
|
|
43332
|
+
this.clearPreInitialized();
|
|
43333
|
+
this.clearCachedSession();
|
|
43334
|
+
}
|
|
43335
|
+
markProtocolV2Reboot(rebootType) {
|
|
43336
|
+
if (!this.isProtocolV2())
|
|
43337
|
+
return;
|
|
43338
|
+
this.protocolV2StateNeedsReload = true;
|
|
43339
|
+
this.clearPreInitialized();
|
|
43340
|
+
let loaderMode;
|
|
43341
|
+
if (rebootType === hdTransport.DeviceRebootType.Bootloader) {
|
|
43342
|
+
loaderMode = 'bootloader';
|
|
43343
|
+
}
|
|
43344
|
+
else if (rebootType === hdTransport.DeviceRebootType.Romloader) {
|
|
43345
|
+
loaderMode = 'romloader';
|
|
43346
|
+
}
|
|
43347
|
+
if (loaderMode) {
|
|
43348
|
+
this.updateState({
|
|
43349
|
+
identity: { deviceId: null },
|
|
43350
|
+
status: {
|
|
43351
|
+
mode: loaderMode,
|
|
43352
|
+
initialized: null,
|
|
43353
|
+
unlocked: null,
|
|
43354
|
+
firmwarePresent: null,
|
|
43355
|
+
backupRequired: null,
|
|
43356
|
+
noBackup: null,
|
|
43357
|
+
unfinishedBackup: null,
|
|
43358
|
+
recoveryMode: null,
|
|
43359
|
+
passphraseProtection: null,
|
|
43360
|
+
pinProtection: null,
|
|
43361
|
+
attachToPinEnabled: null,
|
|
43362
|
+
unlockedAttachPin: null,
|
|
43363
|
+
},
|
|
43364
|
+
session: null,
|
|
43365
|
+
raw: { protocolV2DeviceStatus: null },
|
|
43366
|
+
}, 'transport-reconnect');
|
|
43367
|
+
return;
|
|
43368
|
+
}
|
|
43369
|
+
this.updateState({
|
|
43370
|
+
status: { mode: 'normal', unlocked: null },
|
|
43371
|
+
session: null,
|
|
43372
|
+
raw: { protocolV2DeviceStatus: null },
|
|
43373
|
+
}, 'transport-reconnect');
|
|
43374
|
+
}
|
|
42706
43375
|
updateDescriptor(descriptor, forceUpdate = false) {
|
|
42707
43376
|
var _a;
|
|
42708
43377
|
const env = DataManager.getSettings('env');
|
|
@@ -42730,7 +43399,7 @@ class Device extends events.exports {
|
|
|
42730
43399
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42731
43400
|
if (this.runPromise) {
|
|
42732
43401
|
yield this.interruptionFromOutside();
|
|
42733
|
-
Log$
|
|
43402
|
+
Log$e.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
|
|
42734
43403
|
}
|
|
42735
43404
|
options = parseRunOptions(options);
|
|
42736
43405
|
this.runPromise = hdShared.createDeferred(this._runInner.bind(this, fn, options));
|
|
@@ -42758,6 +43427,7 @@ class Device extends events.exports {
|
|
|
42758
43427
|
}
|
|
42759
43428
|
}
|
|
42760
43429
|
catch (error) {
|
|
43430
|
+
yield this.release();
|
|
42761
43431
|
this.runPromise = null;
|
|
42762
43432
|
if (error instanceof hdShared.HardwareError) {
|
|
42763
43433
|
return Promise.reject(error);
|
|
@@ -42788,7 +43458,7 @@ class Device extends events.exports {
|
|
|
42788
43458
|
yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.disconnect(this.mainId));
|
|
42789
43459
|
}
|
|
42790
43460
|
yield this.release();
|
|
42791
|
-
Log$
|
|
43461
|
+
Log$e.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
|
|
42792
43462
|
}
|
|
42793
43463
|
this.runPromise = null;
|
|
42794
43464
|
return;
|
|
@@ -42798,7 +43468,7 @@ class Device extends events.exports {
|
|
|
42798
43468
|
options.keepSession === false) {
|
|
42799
43469
|
this.keepSession = false;
|
|
42800
43470
|
yield this.release();
|
|
42801
|
-
Log$
|
|
43471
|
+
Log$e.debug('release device, mainId: ', this.mainId);
|
|
42802
43472
|
}
|
|
42803
43473
|
if (this.runPromise) {
|
|
42804
43474
|
this.runPromise.resolve();
|
|
@@ -42831,7 +43501,7 @@ class Device extends events.exports {
|
|
|
42831
43501
|
setCancelableAction(callback) {
|
|
42832
43502
|
this.cancelableAction = (e) => callback(e)
|
|
42833
43503
|
.catch(e2 => {
|
|
42834
|
-
Log$
|
|
43504
|
+
Log$e.debug('cancelableAction error', e2);
|
|
42835
43505
|
})
|
|
42836
43506
|
.finally(() => {
|
|
42837
43507
|
this.clearCancelableAction();
|
|
@@ -42841,16 +43511,24 @@ class Device extends events.exports {
|
|
|
42841
43511
|
this.cancelableAction = undefined;
|
|
42842
43512
|
}
|
|
42843
43513
|
getMode() {
|
|
42844
|
-
var _a, _b, _c;
|
|
42845
|
-
|
|
43514
|
+
var _a, _b, _c, _d;
|
|
43515
|
+
switch ((_a = this.state) === null || _a === void 0 ? void 0 : _a.status.mode) {
|
|
43516
|
+
case 'bootloader':
|
|
43517
|
+
case 'romloader':
|
|
43518
|
+
return exports.EOneKeyDeviceMode.bootloader;
|
|
43519
|
+
case 'notInitialized':
|
|
43520
|
+
return exports.EOneKeyDeviceMode.notInitialized;
|
|
43521
|
+
case 'backupMode':
|
|
43522
|
+
return exports.EOneKeyDeviceMode.backupMode;
|
|
43523
|
+
case 'normal':
|
|
43524
|
+
return exports.EOneKeyDeviceMode.normal;
|
|
43525
|
+
}
|
|
43526
|
+
if ((_b = this.features) === null || _b === void 0 ? void 0 : _b.bootloaderMode)
|
|
42846
43527
|
return exports.EOneKeyDeviceMode.bootloader;
|
|
42847
|
-
|
|
42848
|
-
if (!((_b = this.features) === null || _b === void 0 ? void 0 : _b.initialized)) {
|
|
43528
|
+
if (((_c = this.features) === null || _c === void 0 ? void 0 : _c.initialized) === false)
|
|
42849
43529
|
return exports.EOneKeyDeviceMode.notInitialized;
|
|
42850
|
-
|
|
42851
|
-
if ((_c = this.features) === null || _c === void 0 ? void 0 : _c.noBackup) {
|
|
43530
|
+
if ((_d = this.features) === null || _d === void 0 ? void 0 : _d.noBackup)
|
|
42852
43531
|
return exports.EOneKeyDeviceMode.backupMode;
|
|
42853
|
-
}
|
|
42854
43532
|
return exports.EOneKeyDeviceMode.normal;
|
|
42855
43533
|
}
|
|
42856
43534
|
getFirmwareVersion() {
|
|
@@ -42929,6 +43607,7 @@ class Device extends events.exports {
|
|
|
42929
43607
|
lockDevice() {
|
|
42930
43608
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42931
43609
|
const res = yield this.commands.typedCall('LockDevice', 'Success', {});
|
|
43610
|
+
this.updateState({ status: { unlocked: false } }, 'lock');
|
|
42932
43611
|
return res.message;
|
|
42933
43612
|
});
|
|
42934
43613
|
}
|
|
@@ -42957,8 +43636,7 @@ class Device extends events.exports {
|
|
|
42957
43636
|
}
|
|
42958
43637
|
throw error;
|
|
42959
43638
|
}
|
|
42960
|
-
|
|
42961
|
-
return this.updateProtocolV2Status(status);
|
|
43639
|
+
return this.updateFeaturesPatch({ unlocked: true }, 'unlock');
|
|
42962
43640
|
}
|
|
42963
43641
|
const firmwareVersion = (_c = this.getCurrentFirmwareVersionString()) !== null && _c !== void 0 ? _c : '0.0.0';
|
|
42964
43642
|
const versionRange = this.getCurrentMethodVersionRange(type => this.supportUnlockVersionRange()[type]);
|
|
@@ -42970,11 +43648,15 @@ class Device extends events.exports {
|
|
|
42970
43648
|
if (supportUnlock) {
|
|
42971
43649
|
const res = yield this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|
|
42972
43650
|
if (this.features) {
|
|
42973
|
-
this.
|
|
42974
|
-
|
|
42975
|
-
|
|
42976
|
-
|
|
42977
|
-
|
|
43651
|
+
this.updateState({
|
|
43652
|
+
status: {
|
|
43653
|
+
unlocked: res.message.unlocked == null ? null : res.message.unlocked,
|
|
43654
|
+
unlockedAttachPin: res.message.unlocked_attach_pin == null ? null : res.message.unlocked_attach_pin,
|
|
43655
|
+
passphraseProtection: res.message.passphrase_protection == null
|
|
43656
|
+
? null
|
|
43657
|
+
: res.message.passphrase_protection,
|
|
43658
|
+
},
|
|
43659
|
+
}, 'unlock');
|
|
42978
43660
|
return Promise.resolve(this.features);
|
|
42979
43661
|
}
|
|
42980
43662
|
const features = yield this.getFeatures();
|
|
@@ -43004,7 +43686,7 @@ class Device extends events.exports {
|
|
|
43004
43686
|
const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
|
|
43005
43687
|
const useErrorAttachPin = unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
|
|
43006
43688
|
const passphraseStateMismatch = !!passphraseState && passphraseState !== newPassphraseState;
|
|
43007
|
-
Log$
|
|
43689
|
+
Log$e.debug('Check passphrase state safety: ', {
|
|
43008
43690
|
passphraseState,
|
|
43009
43691
|
newPassphraseState,
|
|
43010
43692
|
unlockedAttachPin,
|
|
@@ -43035,6 +43717,15 @@ class Device extends events.exports {
|
|
|
43035
43717
|
}
|
|
43036
43718
|
}
|
|
43037
43719
|
|
|
43720
|
+
function checkLiveDeviceId(device, expectedDeviceId) {
|
|
43721
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43722
|
+
if (device.isProtocolV2()) {
|
|
43723
|
+
yield device.getDeviceState({ refreshSections: ['status'] });
|
|
43724
|
+
}
|
|
43725
|
+
return device.checkDeviceId(expectedDeviceId);
|
|
43726
|
+
});
|
|
43727
|
+
}
|
|
43728
|
+
|
|
43038
43729
|
class DeviceList extends events.exports {
|
|
43039
43730
|
constructor() {
|
|
43040
43731
|
super(...arguments);
|
|
@@ -43132,7 +43823,7 @@ const getBootloaderReleaseInfo = ({ features, willUpdateFirmwareVersion, firmwar
|
|
|
43132
43823
|
};
|
|
43133
43824
|
};
|
|
43134
43825
|
|
|
43135
|
-
const Log$
|
|
43826
|
+
const Log$d = getLogger(exports.LoggerNames.Method);
|
|
43136
43827
|
const isEvmLedgerLegacyPathWithHighIndex = (path) => {
|
|
43137
43828
|
let addressN;
|
|
43138
43829
|
if (typeof path === 'string') {
|
|
@@ -43206,7 +43897,7 @@ class BaseMethod {
|
|
|
43206
43897
|
setContext(context) {
|
|
43207
43898
|
this.sdkInstanceId = context.sdkInstanceId;
|
|
43208
43899
|
this.instanceId = generateInstanceId('Method', this.sdkInstanceId);
|
|
43209
|
-
Log$
|
|
43900
|
+
Log$d.debug(`[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}`);
|
|
43210
43901
|
}
|
|
43211
43902
|
setDevice(device) {
|
|
43212
43903
|
var _a, _b;
|
|
@@ -43226,7 +43917,7 @@ class BaseMethod {
|
|
|
43226
43917
|
if (device.commands) {
|
|
43227
43918
|
device.commands.currentResponseID = this.responseID;
|
|
43228
43919
|
}
|
|
43229
|
-
Log$
|
|
43920
|
+
Log$d.debug(`[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${(_b = device.commands) === null || _b === void 0 ? void 0 : _b.instanceId}`);
|
|
43230
43921
|
}
|
|
43231
43922
|
checkFirmwareRelease() {
|
|
43232
43923
|
if (!this.device || this.device.isProtocolV2())
|
|
@@ -43304,7 +43995,7 @@ class BaseMethod {
|
|
|
43304
43995
|
checkFlag = true;
|
|
43305
43996
|
}
|
|
43306
43997
|
if (checkFlag && this.device.getCurrentSafetyChecks() === 'Strict') {
|
|
43307
|
-
Log$
|
|
43998
|
+
Log$d.debug('will change safety_checks level');
|
|
43308
43999
|
yield this.device.commands.typedCall('ApplySettings', 'Success', {
|
|
43309
44000
|
safety_checks: 'PromptTemporarily',
|
|
43310
44001
|
});
|
|
@@ -43338,7 +44029,7 @@ class TestInitializeDeviceDuration extends BaseMethod {
|
|
|
43338
44029
|
}
|
|
43339
44030
|
}
|
|
43340
44031
|
|
|
43341
|
-
const Log$
|
|
44032
|
+
const Log$c = getLogger(exports.LoggerNames.Core);
|
|
43342
44033
|
const parseInitOptions$1 = (payload) => ({
|
|
43343
44034
|
initSession: payload === null || payload === void 0 ? void 0 : payload.initSession,
|
|
43344
44035
|
passphraseState: payload === null || payload === void 0 ? void 0 : payload.passphraseState,
|
|
@@ -43361,13 +44052,14 @@ class PreInitialize extends BaseMethod {
|
|
|
43361
44052
|
}
|
|
43362
44053
|
catch (_a) {
|
|
43363
44054
|
this.device.clearPreInitialized();
|
|
43364
|
-
Log$
|
|
44055
|
+
Log$c.debug('[PRE-INIT][FAILED]');
|
|
43365
44056
|
return false;
|
|
43366
44057
|
}
|
|
43367
44058
|
});
|
|
43368
44059
|
}
|
|
43369
44060
|
}
|
|
43370
44061
|
|
|
44062
|
+
const Log$b = getLogger(exports.LoggerNames.DevicePool);
|
|
43371
44063
|
class SearchDevices extends BaseMethod {
|
|
43372
44064
|
init() {
|
|
43373
44065
|
this.useDevice = false;
|
|
@@ -43394,9 +44086,22 @@ class SearchDevices extends BaseMethod {
|
|
|
43394
44086
|
}
|
|
43395
44087
|
return devices;
|
|
43396
44088
|
}
|
|
43397
|
-
const
|
|
43398
|
-
|
|
43399
|
-
|
|
44089
|
+
const deviceList = [];
|
|
44090
|
+
for (const descriptor of devicesDescriptor) {
|
|
44091
|
+
try {
|
|
44092
|
+
const result = yield DevicePool.getDevices([descriptor], descriptor.path, {
|
|
44093
|
+
connectProtocol: this.payload.connectProtocol,
|
|
44094
|
+
refreshRuntimeState: true,
|
|
44095
|
+
});
|
|
44096
|
+
deviceList.push(...result.deviceList);
|
|
44097
|
+
}
|
|
44098
|
+
catch (error) {
|
|
44099
|
+
const errorCode = error && typeof error === 'object' && 'errorCode' in error
|
|
44100
|
+
? error.errorCode
|
|
44101
|
+
: undefined;
|
|
44102
|
+
Log$b.debug('Skip unavailable device during search', Object.assign({ path: descriptor.path }, (errorCode !== undefined ? { errorCode } : {})));
|
|
44103
|
+
}
|
|
44104
|
+
}
|
|
43400
44105
|
return deviceList.map(device => device.toMessageObject());
|
|
43401
44106
|
});
|
|
43402
44107
|
}
|
|
@@ -43404,6 +44109,7 @@ class SearchDevices extends BaseMethod {
|
|
|
43404
44109
|
|
|
43405
44110
|
class GetFeatures extends BaseMethod {
|
|
43406
44111
|
init() {
|
|
44112
|
+
this.unlockPolicy = 'none';
|
|
43407
44113
|
this.allowDeviceMode = [
|
|
43408
44114
|
...this.allowDeviceMode,
|
|
43409
44115
|
UI_REQUEST.NOT_INITIALIZE,
|
|
@@ -43419,207 +44125,62 @@ class GetFeatures extends BaseMethod {
|
|
|
43419
44125
|
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceDetectInBootloaderMode));
|
|
43420
44126
|
}
|
|
43421
44127
|
if (this.device.isProtocolV2()) {
|
|
43422
|
-
|
|
44128
|
+
throw hdShared.createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
|
|
43423
44129
|
}
|
|
43424
|
-
|
|
44130
|
+
const state = yield this.device.getDeviceState({
|
|
44131
|
+
includeRaw: true,
|
|
44132
|
+
});
|
|
44133
|
+
return projectFeatures(state);
|
|
43425
44134
|
});
|
|
43426
44135
|
}
|
|
43427
44136
|
}
|
|
43428
44137
|
|
|
43429
|
-
const
|
|
43430
|
-
|
|
43431
|
-
|
|
43432
|
-
|
|
43433
|
-
FW_MGMT_TARGET_BOOTLOADER: 3,
|
|
43434
|
-
FW_MGMT_TARGET_APPLICATION_P1: 4,
|
|
43435
|
-
FW_MGMT_TARGET_APPLICATION_P2: 5,
|
|
43436
|
-
FW_MGMT_TARGET_COPROCESSOR: 6,
|
|
43437
|
-
FW_MGMT_TARGET_SE01: 7,
|
|
43438
|
-
FW_MGMT_TARGET_SE02: 8,
|
|
43439
|
-
FW_MGMT_TARGET_SE03: 9,
|
|
43440
|
-
FW_MGMT_TARGET_SE04: 10,
|
|
44138
|
+
const SCOPE_SECTIONS = {
|
|
44139
|
+
runtime: ['status'],
|
|
44140
|
+
settings: ['status', 'settings'],
|
|
44141
|
+
firmware: ['status', 'identity', 'versions', 'verification'],
|
|
43441
44142
|
};
|
|
43442
|
-
|
|
43443
|
-
|
|
43444
|
-
function isDeviceInfoScope(scope) {
|
|
43445
|
-
return typeof scope === 'string' && DEVICE_INFO_SCOPES.includes(scope);
|
|
43446
|
-
}
|
|
43447
|
-
function normalizeScope(scope) {
|
|
43448
|
-
if (scope === undefined || scope === null)
|
|
43449
|
-
return 'basic';
|
|
43450
|
-
if (isDeviceInfoScope(scope)) {
|
|
43451
|
-
return scope;
|
|
43452
|
-
}
|
|
43453
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Invalid getDeviceInfo scope: ${String(scope)}`);
|
|
43454
|
-
}
|
|
43455
|
-
function resolveProtocolV2DeviceInfoRequest(params) {
|
|
43456
|
-
if (params.scope === 'verify' || params.scope === 'full') {
|
|
43457
|
-
return PROTOCOL_V2_DEVICE_INFO_REQUEST;
|
|
43458
|
-
}
|
|
43459
|
-
if (params.scope === 'versions') {
|
|
43460
|
-
return PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST;
|
|
43461
|
-
}
|
|
43462
|
-
return PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST;
|
|
43463
|
-
}
|
|
43464
|
-
function shouldReadOnekeyFeatures(params) {
|
|
43465
|
-
return (params.includeRaw === true ||
|
|
43466
|
-
params.scope === 'versions' ||
|
|
43467
|
-
params.scope === 'verify' ||
|
|
43468
|
-
params.scope === 'full');
|
|
43469
|
-
}
|
|
43470
|
-
function supportOnekeyFeatures(features) {
|
|
43471
|
-
if (!features || features.bootloaderMode)
|
|
43472
|
-
return false;
|
|
43473
|
-
const deviceType = getDeviceType(features);
|
|
43474
|
-
return ![
|
|
43475
|
-
hdShared.EDeviceType.Unknown,
|
|
43476
|
-
hdShared.EDeviceType.Classic1s,
|
|
43477
|
-
hdShared.EDeviceType.ClassicPure,
|
|
43478
|
-
hdShared.EDeviceType.Pro2,
|
|
43479
|
-
].includes(deviceType);
|
|
43480
|
-
}
|
|
43481
|
-
function normalizeOnekeyFeatures(message) {
|
|
43482
|
-
if (message.onekey_firmware_version && !semver__default["default"].valid(message.onekey_firmware_version)) {
|
|
43483
|
-
message.onekey_firmware_version = fixVersion(message.onekey_firmware_version);
|
|
43484
|
-
}
|
|
43485
|
-
return message;
|
|
43486
|
-
}
|
|
43487
|
-
class GetDeviceInfo extends BaseMethod {
|
|
44143
|
+
const isLoaderMode = (mode) => mode === 'bootloader' || mode === 'romloader';
|
|
44144
|
+
class GetDeviceState extends BaseMethod {
|
|
43488
44145
|
init() {
|
|
44146
|
+
var _a;
|
|
44147
|
+
const scope = ((_a = this.payload.scope) !== null && _a !== void 0 ? _a : 'runtime');
|
|
44148
|
+
if (!Object.prototype.hasOwnProperty.call(SCOPE_SECTIONS, scope)) {
|
|
44149
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Unsupported device state scope: ${String(scope)}`);
|
|
44150
|
+
}
|
|
43489
44151
|
this.allowDeviceMode = [
|
|
43490
44152
|
...this.allowDeviceMode,
|
|
43491
44153
|
UI_REQUEST.NOT_INITIALIZE,
|
|
43492
44154
|
UI_REQUEST.BOOTLOADER,
|
|
43493
44155
|
];
|
|
44156
|
+
this.unlockPolicy = 'none';
|
|
43494
44157
|
this.useDevicePassphraseState = false;
|
|
43495
44158
|
this.skipForceUpdateCheck = true;
|
|
43496
|
-
this.params = {
|
|
43497
|
-
scope: normalizeScope(this.payload.scope),
|
|
43498
|
-
refresh: this.payload.refresh,
|
|
43499
|
-
includeRaw: this.payload.includeRaw,
|
|
43500
|
-
};
|
|
44159
|
+
this.params = { scope };
|
|
43501
44160
|
}
|
|
43502
44161
|
run() {
|
|
43503
44162
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43504
|
-
|
|
43505
|
-
|
|
43506
|
-
}
|
|
43507
|
-
return this.runProtocolV1();
|
|
43508
|
-
});
|
|
43509
|
-
}
|
|
43510
|
-
runProtocolV2() {
|
|
43511
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
43512
|
-
const sources = ['deviceInfo'];
|
|
43513
|
-
const protocolV2DeviceInfo = yield requestProtocolV2DeviceInfo({
|
|
43514
|
-
commands: this.device.commands,
|
|
43515
|
-
request: resolveProtocolV2DeviceInfoRequest(this.params),
|
|
43516
|
-
});
|
|
43517
|
-
const protocolV2DeviceStatus = yield requestProtocolV2DeviceStatus({
|
|
43518
|
-
commands: this.device.commands,
|
|
43519
|
-
}).catch(() => undefined);
|
|
43520
|
-
const profile = buildProfileFromProtocolV2({
|
|
43521
|
-
deviceInfo: protocolV2DeviceInfo,
|
|
43522
|
-
deviceStatus: protocolV2DeviceStatus,
|
|
43523
|
-
sources,
|
|
43524
|
-
scope: this.params.scope,
|
|
43525
|
-
includeRaw: this.params.includeRaw,
|
|
44163
|
+
const state = yield this.device.getDeviceState({
|
|
44164
|
+
refreshSections: SCOPE_SECTIONS[this.params.scope],
|
|
43526
44165
|
});
|
|
43527
|
-
this.
|
|
43528
|
-
|
|
44166
|
+
if (this.params.scope === 'settings' &&
|
|
44167
|
+
this.device.isProtocolV2() &&
|
|
44168
|
+
isLoaderMode(state.status.mode)) {
|
|
44169
|
+
throw hdShared.createDeviceNotSupportMethodError(`${this.name}:${this.params.scope}`, this.device.getCurrentFirmwareType());
|
|
44170
|
+
}
|
|
44171
|
+
return state;
|
|
43529
44172
|
});
|
|
43530
44173
|
}
|
|
43531
|
-
|
|
43532
|
-
|
|
43533
|
-
if (this.params.refresh === true) {
|
|
43534
|
-
yield this.device.getFeatures();
|
|
43535
|
-
}
|
|
43536
|
-
const sources = ['features'];
|
|
43537
|
-
const { features } = this.device;
|
|
43538
|
-
let protocolV1OneKeyFeatures;
|
|
43539
|
-
if (shouldReadOnekeyFeatures(this.params) && supportOnekeyFeatures(features)) {
|
|
43540
|
-
const { message } = yield this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
|
|
43541
|
-
protocolV1OneKeyFeatures = normalizeOnekeyFeatures(message);
|
|
43542
|
-
sources.push('protocolV1OneKeyFeatures');
|
|
43543
|
-
}
|
|
43544
|
-
const profile = buildProfileFromProtocolV1({
|
|
43545
|
-
protocol: 'V1',
|
|
43546
|
-
features,
|
|
43547
|
-
protocolV1OneKeyFeatures,
|
|
43548
|
-
sources,
|
|
43549
|
-
scope: this.params.scope,
|
|
43550
|
-
includeRaw: this.params.includeRaw,
|
|
43551
|
-
});
|
|
43552
|
-
return profile;
|
|
43553
|
-
});
|
|
43554
|
-
}
|
|
43555
|
-
}
|
|
43556
|
-
|
|
43557
|
-
const ONEKEY_FEATURE_KEYS = [
|
|
43558
|
-
'onekey_device_type',
|
|
43559
|
-
'onekey_board_version',
|
|
43560
|
-
'onekey_boot_version',
|
|
43561
|
-
'onekey_firmware_version',
|
|
43562
|
-
'onekey_board_hash',
|
|
43563
|
-
'onekey_boot_hash',
|
|
43564
|
-
'onekey_firmware_hash',
|
|
43565
|
-
'onekey_board_build_id',
|
|
43566
|
-
'onekey_boot_build_id',
|
|
43567
|
-
'onekey_firmware_build_id',
|
|
43568
|
-
'onekey_serial_no',
|
|
43569
|
-
'onekey_ble_name',
|
|
43570
|
-
'onekey_ble_version',
|
|
43571
|
-
'onekey_ble_build_id',
|
|
43572
|
-
'onekey_ble_hash',
|
|
43573
|
-
'onekey_se_type',
|
|
43574
|
-
'onekey_se01_state',
|
|
43575
|
-
'onekey_se02_state',
|
|
43576
|
-
'onekey_se03_state',
|
|
43577
|
-
'onekey_se04_state',
|
|
43578
|
-
'onekey_se01_version',
|
|
43579
|
-
'onekey_se02_version',
|
|
43580
|
-
'onekey_se03_version',
|
|
43581
|
-
'onekey_se04_version',
|
|
43582
|
-
'onekey_se01_hash',
|
|
43583
|
-
'onekey_se02_hash',
|
|
43584
|
-
'onekey_se03_hash',
|
|
43585
|
-
'onekey_se04_hash',
|
|
43586
|
-
'onekey_se01_build_id',
|
|
43587
|
-
'onekey_se02_build_id',
|
|
43588
|
-
'onekey_se03_build_id',
|
|
43589
|
-
'onekey_se04_build_id',
|
|
43590
|
-
'onekey_se01_boot_version',
|
|
43591
|
-
'onekey_se02_boot_version',
|
|
43592
|
-
'onekey_se03_boot_version',
|
|
43593
|
-
'onekey_se04_boot_version',
|
|
43594
|
-
'onekey_se01_boot_hash',
|
|
43595
|
-
'onekey_se02_boot_hash',
|
|
43596
|
-
'onekey_se03_boot_hash',
|
|
43597
|
-
'onekey_se04_boot_hash',
|
|
43598
|
-
'onekey_se01_boot_build_id',
|
|
43599
|
-
'onekey_se02_boot_build_id',
|
|
43600
|
-
'onekey_se03_boot_build_id',
|
|
43601
|
-
'onekey_se04_boot_build_id',
|
|
43602
|
-
];
|
|
44174
|
+
}
|
|
44175
|
+
|
|
43603
44176
|
function normalizeOnekeyFirmwareVersion(message) {
|
|
43604
44177
|
if (message.onekey_firmware_version && !semver__default["default"].valid(message.onekey_firmware_version)) {
|
|
43605
44178
|
message.onekey_firmware_version = fixVersion(message.onekey_firmware_version);
|
|
43606
44179
|
}
|
|
43607
44180
|
}
|
|
43608
|
-
function pickOnekeyFeatures(features) {
|
|
43609
|
-
const message = {};
|
|
43610
|
-
if (!features)
|
|
43611
|
-
return message;
|
|
43612
|
-
for (const key of ONEKEY_FEATURE_KEYS) {
|
|
43613
|
-
const value = features[key];
|
|
43614
|
-
if (value !== undefined && value !== null) {
|
|
43615
|
-
message[key] = value;
|
|
43616
|
-
}
|
|
43617
|
-
}
|
|
43618
|
-
normalizeOnekeyFirmwareVersion(message);
|
|
43619
|
-
return message;
|
|
43620
|
-
}
|
|
43621
44181
|
class GetOnekeyFeatures extends BaseMethod {
|
|
43622
44182
|
init() {
|
|
44183
|
+
this.unlockPolicy = 'none';
|
|
43623
44184
|
this.allowDeviceMode = [
|
|
43624
44185
|
...this.allowDeviceMode,
|
|
43625
44186
|
UI_REQUEST.NOT_INITIALIZE,
|
|
@@ -43631,12 +44192,7 @@ class GetOnekeyFeatures extends BaseMethod {
|
|
|
43631
44192
|
run() {
|
|
43632
44193
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43633
44194
|
if (this.device.isProtocolV2()) {
|
|
43634
|
-
|
|
43635
|
-
commands: this.device.commands,
|
|
43636
|
-
request: PROTOCOL_V2_DEVICE_INFO_REQUEST,
|
|
43637
|
-
});
|
|
43638
|
-
const features = this.device.updateProtocolV2Features(deviceInfo);
|
|
43639
|
-
return pickOnekeyFeatures(features);
|
|
44195
|
+
throw hdShared.createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
|
|
43640
44196
|
}
|
|
43641
44197
|
const { message } = yield this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
|
|
43642
44198
|
normalizeOnekeyFirmwareVersion(message);
|
|
@@ -43660,7 +44216,7 @@ class GetPassphraseState extends BaseMethod {
|
|
|
43660
44216
|
const passphraseProtection = this.device.getCurrentPassphraseProtection();
|
|
43661
44217
|
const deviceType = this.device.getCurrentDeviceType();
|
|
43662
44218
|
if (deviceType === hdShared.EDeviceType.Pro2) {
|
|
43663
|
-
return Promise.resolve(
|
|
44219
|
+
return Promise.resolve(passphraseState);
|
|
43664
44220
|
}
|
|
43665
44221
|
return Promise.resolve(deviceType === hdShared.EDeviceType.Pro || passphraseProtection === true ? passphraseState : undefined);
|
|
43666
44222
|
});
|
|
@@ -43714,6 +44270,9 @@ class ClearSessionCache extends BaseMethod {
|
|
|
43714
44270
|
else {
|
|
43715
44271
|
deviceWalletSessionStore.delete(deviceId, passphraseState);
|
|
43716
44272
|
}
|
|
44273
|
+
Object.values(DevicePool.devicesCache).forEach(device => {
|
|
44274
|
+
device.clearCachedSession(deviceId, passphraseState);
|
|
44275
|
+
});
|
|
43717
44276
|
return Promise.resolve({ cleared: true });
|
|
43718
44277
|
}
|
|
43719
44278
|
}
|
|
@@ -44273,6 +44832,7 @@ class DeviceRebootToBootloader extends BaseMethod {
|
|
|
44273
44832
|
const res = yield this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
44274
44833
|
reboot_type: hdTransport.DeviceRebootType.Bootloader,
|
|
44275
44834
|
});
|
|
44835
|
+
this.device.markProtocolV2Reboot(hdTransport.DeviceRebootType.Bootloader);
|
|
44276
44836
|
return Promise.resolve(res.message);
|
|
44277
44837
|
}
|
|
44278
44838
|
const res = yield this.device.commands.typedCall('RebootToBootloader', 'Success');
|
|
@@ -44302,6 +44862,7 @@ class DeviceRebootToBoardloader extends BaseMethod {
|
|
|
44302
44862
|
const res = yield this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
44303
44863
|
reboot_type: hdTransport.DeviceRebootType.Romloader,
|
|
44304
44864
|
});
|
|
44865
|
+
this.device.markProtocolV2Reboot(hdTransport.DeviceRebootType.Romloader);
|
|
44305
44866
|
return Promise.resolve(res.message);
|
|
44306
44867
|
}
|
|
44307
44868
|
const res = yield this.device.commands.typedCall('BixinOutMessageSE', 'Success');
|
|
@@ -44396,7 +44957,15 @@ class DeviceSettings extends BaseMethod {
|
|
|
44396
44957
|
{ name: 'experimentalFeatures', type: 'boolean' },
|
|
44397
44958
|
{ name: 'autoShutdownDelayMs', type: 'number' },
|
|
44398
44959
|
{ name: 'changeBrightness', type: 'boolean' },
|
|
44960
|
+
{ name: 'brightness', type: 'number' },
|
|
44399
44961
|
{ name: 'hapticFeedback', type: 'boolean' },
|
|
44962
|
+
{ name: 'bluetoothEnabled', type: 'boolean' },
|
|
44963
|
+
{ name: 'animationEnabled', type: 'boolean' },
|
|
44964
|
+
{ name: 'tapToWake', type: 'boolean' },
|
|
44965
|
+
{ name: 'deviceNameDisplayEnabled', type: 'boolean' },
|
|
44966
|
+
{ name: 'fidoEnabled', type: 'boolean' },
|
|
44967
|
+
{ name: 'usbLockEnabled', type: 'boolean' },
|
|
44968
|
+
{ name: 'randomKeypad', type: 'boolean' },
|
|
44400
44969
|
]);
|
|
44401
44970
|
this.params = Object.assign(Object.assign({ language: this.payload.language, label: this.payload.label, use_passphrase: this.payload.usePassphrase, homescreen: this.payload.homescreen, _passphrase_source: this.payload.passphraseSource, auto_lock_delay_ms: this.payload.autoLockDelayMs, display_rotation: this.payload.displayRotation, passphrase_always_on_device: this.payload.passphraseAlwaysOnDevice, safety_checks: this.payload.safetyChecks, experimental_features: this.payload.experimentalFeatures, auto_shutdown_delay_ms: this.payload.autoShutdownDelayMs }, (this.payload.changeBrightness
|
|
44402
44971
|
? { change_brightness: this.payload.changeBrightness }
|
|
@@ -44416,7 +44985,19 @@ class DeviceSettings extends BaseMethod {
|
|
|
44416
44985
|
var _a, _b, _c, _d, _e;
|
|
44417
44986
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44418
44987
|
try {
|
|
44988
|
+
if (this.device.isProtocolV2()) {
|
|
44989
|
+
const settings = mapCommonSettingsToProtocolV2(this.payload);
|
|
44990
|
+
if (Object.keys(settings).length === 0) {
|
|
44991
|
+
throw invalidParameter('No Protocol V2 compatible setting provided.');
|
|
44992
|
+
}
|
|
44993
|
+
const res = yield this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
|
|
44994
|
+
settings,
|
|
44995
|
+
});
|
|
44996
|
+
this.device.updateState(mapDeviceSettingsToState(settings), 'apply-settings');
|
|
44997
|
+
return res.message;
|
|
44998
|
+
}
|
|
44419
44999
|
const res = yield this.device.commands.typedCall('ApplySettings', 'Success', Object.assign({}, this.params));
|
|
45000
|
+
this.device.updateState(mapApplySettingsToState(this.params), 'apply-settings');
|
|
44420
45001
|
return res.message;
|
|
44421
45002
|
}
|
|
44422
45003
|
catch (error) {
|
|
@@ -46562,6 +47143,20 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
46562
47143
|
}
|
|
46563
47144
|
}
|
|
46564
47145
|
|
|
47146
|
+
const ProtocolV2FirmwareTargetType = {
|
|
47147
|
+
FW_MGMT_TARGET_INVALID: 0,
|
|
47148
|
+
FW_MGMT_TARGET_CRATE: 1,
|
|
47149
|
+
FW_MGMT_TARGET_ROMLOADER: 2,
|
|
47150
|
+
FW_MGMT_TARGET_BOOTLOADER: 3,
|
|
47151
|
+
FW_MGMT_TARGET_APPLICATION_P1: 4,
|
|
47152
|
+
FW_MGMT_TARGET_APPLICATION_P2: 5,
|
|
47153
|
+
FW_MGMT_TARGET_COPROCESSOR: 6,
|
|
47154
|
+
FW_MGMT_TARGET_SE01: 7,
|
|
47155
|
+
FW_MGMT_TARGET_SE02: 8,
|
|
47156
|
+
FW_MGMT_TARGET_SE03: 9,
|
|
47157
|
+
FW_MGMT_TARGET_SE04: 10,
|
|
47158
|
+
};
|
|
47159
|
+
|
|
46565
47160
|
const DEVICE_REBOOT_TYPES = {
|
|
46566
47161
|
Normal: hdTransport.DeviceRebootType.Normal,
|
|
46567
47162
|
normal: hdTransport.DeviceRebootType.Normal,
|
|
@@ -47319,9 +47914,10 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
47319
47914
|
return !!((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.bootloaderMode);
|
|
47320
47915
|
}
|
|
47321
47916
|
enterProtocolV2BootloaderMode() {
|
|
47917
|
+
var _a;
|
|
47322
47918
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47323
|
-
if (this.isProtocolV2BootloaderMode()) {
|
|
47324
|
-
Log$5.debug('Protocol V2 device is already in
|
|
47919
|
+
if (this.isProtocolV2BootloaderMode() || ((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.mode) === 'romloader') {
|
|
47920
|
+
Log$5.debug('Protocol V2 device is already in loader mode, skip reboot to bootloader');
|
|
47325
47921
|
return false;
|
|
47326
47922
|
}
|
|
47327
47923
|
try {
|
|
@@ -47477,12 +48073,15 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
47477
48073
|
var _a;
|
|
47478
48074
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47479
48075
|
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
47480
|
-
const { message: deviceStatus } = yield typedCall('DeviceStatusGet', 'DeviceStatus', {}, { timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT });
|
|
47481
48076
|
const deviceInfo = yield requestProtocolV2DeviceInfo({
|
|
47482
48077
|
commands: this.device.getCommands(),
|
|
47483
48078
|
timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
|
|
47484
|
-
request: PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
|
|
47485
48079
|
});
|
|
48080
|
+
if (isProtocolV2LoaderDeviceInfo(deviceInfo, null)) {
|
|
48081
|
+
this.device.updateProtocolV2Features(deviceInfo, null);
|
|
48082
|
+
return false;
|
|
48083
|
+
}
|
|
48084
|
+
const { message: deviceStatus } = yield typedCall('DeviceStatusGet', 'DeviceStatus', {}, { timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT });
|
|
47486
48085
|
const features = this.device.updateProtocolV2Features(deviceInfo, deviceStatus);
|
|
47487
48086
|
assertProtocolV2ReconnectIdentity(this.protocolV2ExpectedDeviceId, (_a = features.deviceId) !== null && _a !== void 0 ? _a : undefined);
|
|
47488
48087
|
if (this.isProtocolV2NormalModeFeatures(features)) {
|
|
@@ -47781,10 +48380,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
47781
48380
|
const res = yield typedCall('DeviceReboot', 'Success', {
|
|
47782
48381
|
reboot_type: rebootType,
|
|
47783
48382
|
});
|
|
48383
|
+
this.device.markProtocolV2Reboot(rebootType);
|
|
47784
48384
|
return res.message;
|
|
47785
48385
|
}
|
|
47786
48386
|
catch (error) {
|
|
47787
48387
|
if (isProtocolV2DeviceDisconnectedError(error) || isProtocolV2ReconnectProbeError(error)) {
|
|
48388
|
+
this.device.markProtocolV2Reboot(rebootType);
|
|
47788
48389
|
return { message: 'Device rebooted successfully' };
|
|
47789
48390
|
}
|
|
47790
48391
|
throw error;
|
|
@@ -47909,113 +48510,16 @@ class DeviceReboot extends BaseMethod {
|
|
|
47909
48510
|
run() {
|
|
47910
48511
|
var _a;
|
|
47911
48512
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48513
|
+
const rebootType = normalizeRebootType((_a = this.params.reboot_type) !== null && _a !== void 0 ? _a : this.params.rebootType);
|
|
47912
48514
|
const res = yield this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
47913
|
-
reboot_type:
|
|
48515
|
+
reboot_type: rebootType,
|
|
47914
48516
|
});
|
|
48517
|
+
this.device.markProtocolV2Reboot(rebootType);
|
|
47915
48518
|
return Promise.resolve(res.message);
|
|
47916
48519
|
});
|
|
47917
48520
|
}
|
|
47918
48521
|
}
|
|
47919
48522
|
|
|
47920
|
-
const TARGET_KEYS = [
|
|
47921
|
-
'hw',
|
|
47922
|
-
'fw',
|
|
47923
|
-
'coprocessor',
|
|
47924
|
-
'se1',
|
|
47925
|
-
'se2',
|
|
47926
|
-
'se3',
|
|
47927
|
-
'se4',
|
|
47928
|
-
'status',
|
|
47929
|
-
];
|
|
47930
|
-
const TYPE_KEYS = ['version', 'build_id', 'hash', 'specific'];
|
|
47931
|
-
const DEFAULT_TARGETS = {
|
|
47932
|
-
hw: true,
|
|
47933
|
-
fw: true,
|
|
47934
|
-
coprocessor: true,
|
|
47935
|
-
};
|
|
47936
|
-
const DEFAULT_TYPES = {
|
|
47937
|
-
version: true,
|
|
47938
|
-
specific: true,
|
|
47939
|
-
};
|
|
47940
|
-
function pickBooleanKeys(value, keys) {
|
|
47941
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
47942
|
-
return undefined;
|
|
47943
|
-
const source = value;
|
|
47944
|
-
const result = {};
|
|
47945
|
-
let hasKey = false;
|
|
47946
|
-
for (const key of keys) {
|
|
47947
|
-
if (source[key]) {
|
|
47948
|
-
result[key] = true;
|
|
47949
|
-
hasKey = true;
|
|
47950
|
-
}
|
|
47951
|
-
}
|
|
47952
|
-
return hasKey ? result : undefined;
|
|
47953
|
-
}
|
|
47954
|
-
function assertKnownKeys(value, keys, name) {
|
|
47955
|
-
if (value == null)
|
|
47956
|
-
return;
|
|
47957
|
-
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
47958
|
-
throw invalidParameter(`Parameter [${name}] must be an object.`);
|
|
47959
|
-
}
|
|
47960
|
-
const allowed = new Set(keys);
|
|
47961
|
-
const unknownKeys = Object.keys(value).filter(key => !allowed.has(key));
|
|
47962
|
-
if (unknownKeys.length > 0) {
|
|
47963
|
-
throw invalidParameter(`Parameter [${name}] contains unsupported key(s): ${unknownKeys.join(', ')}.`);
|
|
47964
|
-
}
|
|
47965
|
-
}
|
|
47966
|
-
function normalizeTargets(value) {
|
|
47967
|
-
assertKnownKeys(value, TARGET_KEYS.map(key => String(key)), 'targets');
|
|
47968
|
-
return pickBooleanKeys(value, TARGET_KEYS);
|
|
47969
|
-
}
|
|
47970
|
-
function normalizeTypes(value) {
|
|
47971
|
-
assertKnownKeys(value, TYPE_KEYS.map(key => String(key)), 'types');
|
|
47972
|
-
return pickBooleanKeys(value, TYPE_KEYS);
|
|
47973
|
-
}
|
|
47974
|
-
class DeviceInfoGet extends BaseMethod {
|
|
47975
|
-
init() {
|
|
47976
|
-
var _a, _b;
|
|
47977
|
-
this.requireProtocolV2 = true;
|
|
47978
|
-
this.allowDeviceMode = [
|
|
47979
|
-
...this.allowDeviceMode,
|
|
47980
|
-
UI_REQUEST.NOT_INITIALIZE,
|
|
47981
|
-
UI_REQUEST.BOOTLOADER,
|
|
47982
|
-
];
|
|
47983
|
-
this.useDevicePassphraseState = false;
|
|
47984
|
-
this.skipForceUpdateCheck = true;
|
|
47985
|
-
this.params = {
|
|
47986
|
-
targets: (_a = normalizeTargets(this.payload.targets)) !== null && _a !== void 0 ? _a : DEFAULT_TARGETS,
|
|
47987
|
-
types: (_b = normalizeTypes(this.payload.types)) !== null && _b !== void 0 ? _b : DEFAULT_TYPES,
|
|
47988
|
-
};
|
|
47989
|
-
}
|
|
47990
|
-
run() {
|
|
47991
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47992
|
-
if (!this.device.isProtocolV2()) {
|
|
47993
|
-
throw hdShared.createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
|
|
47994
|
-
}
|
|
47995
|
-
const res = yield this.device.commands.typedCall('DeviceInfoGet', 'DeviceInfo', {
|
|
47996
|
-
targets: this.params.targets,
|
|
47997
|
-
types: this.params.types,
|
|
47998
|
-
}, { timeoutMs: PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS });
|
|
47999
|
-
return Promise.resolve(res.message);
|
|
48000
|
-
});
|
|
48001
|
-
}
|
|
48002
|
-
}
|
|
48003
|
-
|
|
48004
|
-
class DeviceStatusGet extends BaseMethod {
|
|
48005
|
-
init() {
|
|
48006
|
-
this.requireProtocolV2 = true;
|
|
48007
|
-
this.useDevicePassphraseState = false;
|
|
48008
|
-
this.skipForceUpdateCheck = true;
|
|
48009
|
-
}
|
|
48010
|
-
run() {
|
|
48011
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48012
|
-
const { message } = yield this.device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
|
|
48013
|
-
this.device.updateProtocolV2Status(message);
|
|
48014
|
-
return message;
|
|
48015
|
-
});
|
|
48016
|
-
}
|
|
48017
|
-
}
|
|
48018
|
-
|
|
48019
48523
|
class DeviceGetOnboardingStatus extends BaseMethod {
|
|
48020
48524
|
init() {
|
|
48021
48525
|
this.requireProtocolV2 = true;
|
|
@@ -48212,22 +48716,6 @@ class DeviceFactoryInfoGet extends BaseMethod {
|
|
|
48212
48716
|
}
|
|
48213
48717
|
}
|
|
48214
48718
|
|
|
48215
|
-
class DeviceSettingsGet extends BaseMethod {
|
|
48216
|
-
init() {
|
|
48217
|
-
this.requireProtocolV2 = true;
|
|
48218
|
-
this.unlockPolicy = 'retry-on-locked';
|
|
48219
|
-
this.skipForceUpdateCheck = true;
|
|
48220
|
-
this.useDevicePassphraseState = false;
|
|
48221
|
-
this.params = undefined;
|
|
48222
|
-
}
|
|
48223
|
-
run() {
|
|
48224
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48225
|
-
const res = yield this.device.commands.typedCall('DeviceSettingsGet', 'DeviceSettings', {});
|
|
48226
|
-
return Promise.resolve(res.message);
|
|
48227
|
-
});
|
|
48228
|
-
}
|
|
48229
|
-
}
|
|
48230
|
-
|
|
48231
48719
|
class DeviceSettingsSet extends BaseMethod {
|
|
48232
48720
|
init() {
|
|
48233
48721
|
const { settings } = this.payload;
|
|
@@ -48257,6 +48745,7 @@ class DeviceSettingsSet extends BaseMethod {
|
|
|
48257
48745
|
run() {
|
|
48258
48746
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48259
48747
|
const res = yield this.device.commands.typedCall('DeviceSettingsSet', 'Success', this.params);
|
|
48748
|
+
this.device.updateState(mapDeviceSettingsToState(this.params.settings), 'apply-settings');
|
|
48260
48749
|
return Promise.resolve(res.message);
|
|
48261
48750
|
});
|
|
48262
48751
|
}
|
|
@@ -56027,6 +56516,9 @@ function getSigOpCountsHash(transaction, sighashType) {
|
|
|
56027
56516
|
function hashTxOut(hashWriter, output) {
|
|
56028
56517
|
hashWriter.writeUInt64LE(output.satoshis);
|
|
56029
56518
|
hashWriter.writeUInt16LE(0);
|
|
56519
|
+
if (output.script === undefined) {
|
|
56520
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Kaspa legacy sighash requires output.script');
|
|
56521
|
+
}
|
|
56030
56522
|
hashWriter.writeVarBytes(Buffer.from(output.script, 'hex'));
|
|
56031
56523
|
}
|
|
56032
56524
|
function getOutputsHash(transaction, inputNumber, sighashType) {
|
|
@@ -56054,6 +56546,9 @@ function serialize(transaction, inputNumber) {
|
|
|
56054
56546
|
const input = transaction.inputs[inputNumber];
|
|
56055
56547
|
hashOutpoint(hashWriter, input);
|
|
56056
56548
|
hashWriter.writeUInt16LE(0);
|
|
56549
|
+
if (input.output.script === undefined) {
|
|
56550
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Kaspa legacy sighash requires input.output.script');
|
|
56551
|
+
}
|
|
56057
56552
|
hashWriter.writeVarBytes(Buffer.from(input.output.script, 'hex'));
|
|
56058
56553
|
hashWriter.writeUInt64LE(input.output.satoshis);
|
|
56059
56554
|
hashWriter.writeUInt64LE(input.sequenceNumber);
|
|
@@ -56070,25 +56565,31 @@ function serialize(transaction, inputNumber) {
|
|
|
56070
56565
|
};
|
|
56071
56566
|
}
|
|
56072
56567
|
|
|
56568
|
+
const P2PK_SCRIPT = /^(20[0-9a-f]{64}ac|21[0-9a-f]{66}ab)$/i;
|
|
56569
|
+
const isStreamableScript = (script) => !script || P2PK_SCRIPT.test(script);
|
|
56073
56570
|
class KaspaSignTransaction extends BaseMethod {
|
|
56074
56571
|
constructor() {
|
|
56075
56572
|
super(...arguments);
|
|
56076
56573
|
this.hasBundle = false;
|
|
56574
|
+
this.supportsLegacy = false;
|
|
56575
|
+
this.supportsStreaming = false;
|
|
56077
56576
|
}
|
|
56078
56577
|
init() {
|
|
56079
|
-
var _a, _b, _c, _d, _e;
|
|
56578
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
56080
56579
|
this.checkDeviceId = true;
|
|
56081
56580
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
56082
56581
|
this.allowUsePreInitialize = true;
|
|
56083
56582
|
const payload = this.payload;
|
|
56084
56583
|
validateParams(payload, [
|
|
56085
56584
|
{ name: 'version', type: 'number' },
|
|
56086
|
-
{ name: 'sigHashType', type: 'number'
|
|
56585
|
+
{ name: 'sigHashType', type: 'number' },
|
|
56087
56586
|
{ name: 'inputs', type: 'array', required: true },
|
|
56088
56587
|
{ name: 'outputs', type: 'array', required: true },
|
|
56089
56588
|
{ name: 'lockTime', required: true },
|
|
56090
56589
|
{ name: 'sigOpCount', type: 'number' },
|
|
56091
56590
|
{ name: 'subNetworkID', type: 'string' },
|
|
56591
|
+
{ name: 'payload', type: 'hexString' },
|
|
56592
|
+
{ name: 'refTxs', type: 'array', allowEmpty: true },
|
|
56092
56593
|
{ name: 'useTweak', type: 'boolean' },
|
|
56093
56594
|
]);
|
|
56094
56595
|
const inputs = payload.inputs.map(input => {
|
|
@@ -56099,20 +56600,47 @@ class KaspaSignTransaction extends BaseMethod {
|
|
|
56099
56600
|
{ name: 'outputIndex', type: 'number', required: true },
|
|
56100
56601
|
{ name: 'sequenceNumber', required: true },
|
|
56101
56602
|
]);
|
|
56603
|
+
validateParams(input.output, [{ name: 'satoshis', required: true }]);
|
|
56102
56604
|
const addressN = validatePath(input.path, 3);
|
|
56103
56605
|
return Object.assign(Object.assign({}, input), { path: addressN, sigOpCount: (_a = input.sigOpCount) !== null && _a !== void 0 ? _a : 1 });
|
|
56104
56606
|
});
|
|
56607
|
+
(_a = payload.refTxs) === null || _a === void 0 ? void 0 : _a.forEach(refTx => {
|
|
56608
|
+
validateParams(refTx, [
|
|
56609
|
+
{ name: 'txId', type: 'string', required: true },
|
|
56610
|
+
{ name: 'version', type: 'number', required: true },
|
|
56611
|
+
{ name: 'inputs', type: 'array', required: true, allowEmpty: true },
|
|
56612
|
+
{ name: 'outputs', type: 'array', required: true, allowEmpty: true },
|
|
56613
|
+
{ name: 'payload', type: 'hexString' },
|
|
56614
|
+
]);
|
|
56615
|
+
});
|
|
56105
56616
|
const outputs = payload.outputs.map(output => {
|
|
56106
56617
|
var _a;
|
|
56107
56618
|
validateParams(output, [
|
|
56108
56619
|
{ name: 'satoshis', required: true },
|
|
56109
|
-
{ name: '
|
|
56620
|
+
{ name: 'address', type: 'string' },
|
|
56621
|
+
{ name: 'script', type: 'string' },
|
|
56110
56622
|
{ name: 'scriptVersion', type: 'number' },
|
|
56111
56623
|
]);
|
|
56112
|
-
return Object.assign(Object.assign({}, output), { scriptVersion: (_a = output.scriptVersion) !== null && _a !== void 0 ? _a : 0 });
|
|
56624
|
+
return Object.assign(Object.assign({}, output), { addressN: output.addressN ? validatePath(output.addressN, 3) : undefined, scriptVersion: (_a = output.scriptVersion) !== null && _a !== void 0 ? _a : 0 });
|
|
56113
56625
|
});
|
|
56114
56626
|
this.params = Object.assign(Object.assign({}, payload), { inputs,
|
|
56115
|
-
outputs, scheme: (
|
|
56627
|
+
outputs, scheme: (_b = payload.scheme) !== null && _b !== void 0 ? _b : 'schnorr', prefix: (_c = payload.prefix) !== null && _c !== void 0 ? _c : 'kaspa', sigHashType: (_d = payload.sigHashType) !== null && _d !== void 0 ? _d : SignatureType.SIGHASH_ALL | SignatureType.SIGHASH_FORKID, sigOpCount: (_e = payload.sigOpCount) !== null && _e !== void 0 ? _e : 1, subNetworkID: (_f = payload.subNetworkID) !== null && _f !== void 0 ? _f : utils.bytesToHex(zeroSubnetworkID()), gas: (_g = payload.gas) !== null && _g !== void 0 ? _g : 0, useTweak: payload.useTweak });
|
|
56628
|
+
this.supportsLegacy =
|
|
56629
|
+
this.params.outputs.every(output => !!output.script) &&
|
|
56630
|
+
this.params.inputs.every(input => !!input.output.script) &&
|
|
56631
|
+
!this.params.payload &&
|
|
56632
|
+
Number((_h = this.params.gas) !== null && _h !== void 0 ? _h : 0) === 0 &&
|
|
56633
|
+
/^0*$/.test((_j = this.params.subNetworkID) !== null && _j !== void 0 ? _j : '');
|
|
56634
|
+
const isDefaultSigHashType = this.params.sigHashType === SignatureType.SIGHASH_ALL ||
|
|
56635
|
+
this.params.sigHashType === (SignatureType.SIGHASH_ALL | SignatureType.SIGHASH_FORKID);
|
|
56636
|
+
this.supportsStreaming =
|
|
56637
|
+
isDefaultSigHashType &&
|
|
56638
|
+
this.params.outputs.every(output => !!output.address || !!output.addressN) &&
|
|
56639
|
+
this.params.inputs.every(input => isStreamableScript(input.output.script)) &&
|
|
56640
|
+
this.params.outputs.every(output => isStreamableScript(output.script));
|
|
56641
|
+
if (!this.supportsLegacy && !this.supportsStreaming) {
|
|
56642
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'KaspaSignTransaction: outputs require either address/addressN (streaming protocol) or script (legacy protocol)');
|
|
56643
|
+
}
|
|
56116
56644
|
}
|
|
56117
56645
|
getVersionRange() {
|
|
56118
56646
|
return {
|
|
@@ -56161,23 +56689,197 @@ class KaspaSignTransaction extends BaseMethod {
|
|
|
56161
56689
|
return signature;
|
|
56162
56690
|
});
|
|
56163
56691
|
}
|
|
56692
|
+
ackPrevRequest(typedCall, request, requestIndex) {
|
|
56693
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
56694
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56695
|
+
const prevTxId = ((_a = request.prev_tx_id) !== null && _a !== void 0 ? _a : '').toLowerCase();
|
|
56696
|
+
const refTx = ((_b = this.params.refTxs) !== null && _b !== void 0 ? _b : []).find(tx => tx.txId.toLowerCase() === prevTxId);
|
|
56697
|
+
if (!refTx) {
|
|
56698
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `KaspaSignTransaction: device requested previous transaction ${prevTxId || '(unknown)'}; provide it via refTxs`);
|
|
56699
|
+
}
|
|
56700
|
+
const requestType = request.request_type;
|
|
56701
|
+
if (requestType === 'KASPA_TX_PREV_META') {
|
|
56702
|
+
return typedCall('KaspaTxAckPrevMeta', 'KaspaTxRequest', {
|
|
56703
|
+
version: refTx.version,
|
|
56704
|
+
input_count: refTx.inputs.length,
|
|
56705
|
+
output_count: refTx.outputs.length,
|
|
56706
|
+
lock_time: ((_c = refTx.lockTime) !== null && _c !== void 0 ? _c : 0),
|
|
56707
|
+
subnetwork_id: (_d = refTx.subNetworkID) !== null && _d !== void 0 ? _d : utils.bytesToHex(zeroSubnetworkID()),
|
|
56708
|
+
gas: ((_e = refTx.gas) !== null && _e !== void 0 ? _e : 0),
|
|
56709
|
+
payload_length: ((_f = refTx.payload) !== null && _f !== void 0 ? _f : '').length / 2,
|
|
56710
|
+
});
|
|
56711
|
+
}
|
|
56712
|
+
if (requestType === 'KASPA_TX_INPUT') {
|
|
56713
|
+
const input = refTx.inputs[requestIndex];
|
|
56714
|
+
if (!input) {
|
|
56715
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested input ${requestIndex} of previous tx out of range`);
|
|
56716
|
+
}
|
|
56717
|
+
return typedCall('KaspaTxAckPrevInput', 'KaspaTxRequest', {
|
|
56718
|
+
previous_outpoint: {
|
|
56719
|
+
tx_id: input.prevTxId,
|
|
56720
|
+
index: input.outputIndex,
|
|
56721
|
+
},
|
|
56722
|
+
sequence: input.sequenceNumber,
|
|
56723
|
+
});
|
|
56724
|
+
}
|
|
56725
|
+
if (requestType === 'KASPA_TX_OUTPUT') {
|
|
56726
|
+
const output = refTx.outputs[requestIndex];
|
|
56727
|
+
if (!output) {
|
|
56728
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested output ${requestIndex} of previous tx out of range`);
|
|
56729
|
+
}
|
|
56730
|
+
return typedCall('KaspaTxAckPrevOutput', 'KaspaTxRequest', {
|
|
56731
|
+
amount: output.satoshis,
|
|
56732
|
+
script_version: (_g = output.scriptVersion) !== null && _g !== void 0 ? _g : 0,
|
|
56733
|
+
script_public_key: output.script,
|
|
56734
|
+
});
|
|
56735
|
+
}
|
|
56736
|
+
if (requestType === 'KASPA_TX_PAYLOAD') {
|
|
56737
|
+
const payloadHex = (_h = refTx.payload) !== null && _h !== void 0 ? _h : '';
|
|
56738
|
+
const payloadLength = payloadHex.length / 2;
|
|
56739
|
+
const length = (_j = request.request_payload_length) !== null && _j !== void 0 ? _j : payloadLength - requestIndex;
|
|
56740
|
+
return typedCall('KaspaTxAckPayloadChunk', 'KaspaTxRequest', {
|
|
56741
|
+
payload_chunk: payloadHex.substring(requestIndex * 2, (requestIndex + length) * 2),
|
|
56742
|
+
});
|
|
56743
|
+
}
|
|
56744
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: unknown previous-tx request type ${requestType !== null && requestType !== void 0 ? requestType : 'undefined'}`);
|
|
56745
|
+
});
|
|
56746
|
+
}
|
|
56747
|
+
signTxStream(typedCall, firstResponse) {
|
|
56748
|
+
var _a, _b, _c, _d, _e;
|
|
56749
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56750
|
+
const { params } = this;
|
|
56751
|
+
const signatures = [];
|
|
56752
|
+
const inputScriptType = params.scheme === 'ecdsa' ? 'KASPA_SPEND_P2PK_ECDSA' : 'KASPA_SPEND_P2PK_SCHNORR';
|
|
56753
|
+
const saveSignature = (signature) => {
|
|
56754
|
+
if (signature && typeof signature.signature_index === 'number' && signature.signature) {
|
|
56755
|
+
signatures[signature.signature_index] = {
|
|
56756
|
+
index: signature.signature_index,
|
|
56757
|
+
signature: signature.signature,
|
|
56758
|
+
};
|
|
56759
|
+
}
|
|
56760
|
+
};
|
|
56761
|
+
const payloadHex = (_a = params.payload) !== null && _a !== void 0 ? _a : '';
|
|
56762
|
+
const payloadLength = payloadHex.length / 2;
|
|
56763
|
+
let response = firstResponse;
|
|
56764
|
+
while (true) {
|
|
56765
|
+
const request = response.message;
|
|
56766
|
+
saveSignature(request.signature);
|
|
56767
|
+
const requestType = request.request_type;
|
|
56768
|
+
if (requestType === 'KASPA_TX_FINISHED') {
|
|
56769
|
+
break;
|
|
56770
|
+
}
|
|
56771
|
+
const requestIndex = (_b = request.request_index) !== null && _b !== void 0 ? _b : 0;
|
|
56772
|
+
if (request.prev_tx_id || requestType === 'KASPA_TX_PREV_META') {
|
|
56773
|
+
response = yield this.ackPrevRequest(typedCall, request, requestIndex);
|
|
56774
|
+
}
|
|
56775
|
+
else if (requestType === 'KASPA_TX_INPUT') {
|
|
56776
|
+
const input = params.inputs[requestIndex];
|
|
56777
|
+
if (!input) {
|
|
56778
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested input ${requestIndex} out of range`);
|
|
56779
|
+
}
|
|
56780
|
+
response = yield typedCall('KaspaTxAckInput', 'KaspaTxRequest', {
|
|
56781
|
+
address_n: input.path,
|
|
56782
|
+
previous_outpoint: {
|
|
56783
|
+
tx_id: input.prevTxId,
|
|
56784
|
+
index: input.outputIndex,
|
|
56785
|
+
},
|
|
56786
|
+
amount: input.output.satoshis,
|
|
56787
|
+
sequence: input.sequenceNumber,
|
|
56788
|
+
sig_op_count: (_c = input.sigOpCount) !== null && _c !== void 0 ? _c : 1,
|
|
56789
|
+
script_type: inputScriptType,
|
|
56790
|
+
use_tweak: params.useTweak,
|
|
56791
|
+
});
|
|
56792
|
+
}
|
|
56793
|
+
else if (requestType === 'KASPA_TX_OUTPUT') {
|
|
56794
|
+
const output = params.outputs[requestIndex];
|
|
56795
|
+
if (!output) {
|
|
56796
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested output ${requestIndex} out of range`);
|
|
56797
|
+
}
|
|
56798
|
+
const isChange = !!output.addressN;
|
|
56799
|
+
response = yield typedCall('KaspaTxAckOutput', 'KaspaTxRequest', {
|
|
56800
|
+
script_type: isChange ? 'KASPA_PAYTOCHANGE' : 'KASPA_PAYTOADDRESS',
|
|
56801
|
+
amount: output.satoshis,
|
|
56802
|
+
address_n: (_d = output.addressN) !== null && _d !== void 0 ? _d : [],
|
|
56803
|
+
address: output.address,
|
|
56804
|
+
scheme: params.scheme,
|
|
56805
|
+
use_tweak: params.useTweak,
|
|
56806
|
+
});
|
|
56807
|
+
}
|
|
56808
|
+
else if (requestType === 'KASPA_TX_PAYLOAD') {
|
|
56809
|
+
const offset = requestIndex;
|
|
56810
|
+
const length = (_e = request.request_payload_length) !== null && _e !== void 0 ? _e : payloadLength - offset;
|
|
56811
|
+
const chunk = payloadHex.substring(offset * 2, (offset + length) * 2);
|
|
56812
|
+
response = yield typedCall('KaspaTxAckPayloadChunk', 'KaspaTxRequest', {
|
|
56813
|
+
payload_chunk: chunk,
|
|
56814
|
+
});
|
|
56815
|
+
}
|
|
56816
|
+
else {
|
|
56817
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: unknown request type ${requestType !== null && requestType !== void 0 ? requestType : 'undefined'}`);
|
|
56818
|
+
}
|
|
56819
|
+
}
|
|
56820
|
+
const collected = signatures.filter(Boolean);
|
|
56821
|
+
if (collected.length !== params.inputs.length) {
|
|
56822
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: expected ${params.inputs.length} signatures, received ${collected.length}`);
|
|
56823
|
+
}
|
|
56824
|
+
return collected;
|
|
56825
|
+
});
|
|
56826
|
+
}
|
|
56164
56827
|
run() {
|
|
56828
|
+
var _a, _b, _c;
|
|
56165
56829
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56166
56830
|
this.checkFeatureVersionLimit(() => this.params.useTweak === false, () => this.getUseTweakVersionRange(), {
|
|
56167
56831
|
strictCheckDeviceSupport: true,
|
|
56168
56832
|
});
|
|
56169
|
-
const { raw: rawMessage } = serialize(this.params, 0);
|
|
56170
|
-
const input = this.params.inputs[0];
|
|
56171
56833
|
const { device, params } = this;
|
|
56172
|
-
const
|
|
56173
|
-
|
|
56174
|
-
|
|
56175
|
-
|
|
56176
|
-
|
|
56177
|
-
|
|
56178
|
-
|
|
56179
|
-
|
|
56180
|
-
|
|
56834
|
+
const payloadHex = (_a = params.payload) !== null && _a !== void 0 ? _a : '';
|
|
56835
|
+
const hasRefTxs = ((_c = (_b = params.refTxs) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0;
|
|
56836
|
+
const streamingReady = this.supportsStreaming && (hasRefTxs || !this.supportsLegacy);
|
|
56837
|
+
const streamingFields = streamingReady
|
|
56838
|
+
? {
|
|
56839
|
+
output_count: params.outputs.length,
|
|
56840
|
+
version: params.version,
|
|
56841
|
+
lock_time: params.lockTime,
|
|
56842
|
+
subnetwork_id: params.subNetworkID,
|
|
56843
|
+
gas: params.gas,
|
|
56844
|
+
payload_length: payloadHex.length / 2,
|
|
56845
|
+
}
|
|
56846
|
+
: {};
|
|
56847
|
+
const legacyFields = this.supportsLegacy
|
|
56848
|
+
? { raw_message: utils.bytesToHex(serialize(params, 0).raw) }
|
|
56849
|
+
: {};
|
|
56850
|
+
let response;
|
|
56851
|
+
try {
|
|
56852
|
+
response = yield device.commands.typedCall('KaspaSignTx', ['KaspaTxRequest', 'KaspaTxInputRequest', 'KaspaSignedTx'], Object.assign(Object.assign({ address_n: params.inputs[0].path, scheme: params.scheme, prefix: params.prefix, input_count: params.inputs.length, use_tweak: params.useTweak }, streamingFields), legacyFields));
|
|
56853
|
+
}
|
|
56854
|
+
catch (error) {
|
|
56855
|
+
if (!this.supportsLegacy &&
|
|
56856
|
+
error instanceof hdShared.HardwareError &&
|
|
56857
|
+
error.errorCode === hdShared.HardwareErrorCode.RuntimeError &&
|
|
56858
|
+
String(error.message).includes('Failure_DataError')) {
|
|
56859
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNeedUpgradeFirmware, 'KaspaSignTransaction: this transaction requires firmware with Kaspa streaming support');
|
|
56860
|
+
}
|
|
56861
|
+
throw error;
|
|
56862
|
+
}
|
|
56863
|
+
const typedCall = device.commands.typedCall.bind(device.commands);
|
|
56864
|
+
if (response.type === 'KaspaTxRequest') {
|
|
56865
|
+
if (!this.supportsStreaming) {
|
|
56866
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'KaspaSignTransaction: device firmware uses the streaming protocol; every output requires address or addressN');
|
|
56867
|
+
}
|
|
56868
|
+
try {
|
|
56869
|
+
return yield this.signTxStream(typedCall, response);
|
|
56870
|
+
}
|
|
56871
|
+
catch (error) {
|
|
56872
|
+
if (error instanceof hdShared.HardwareError &&
|
|
56873
|
+
String(error.message).toLowerCase().includes('previous transaction id mismatch')) {
|
|
56874
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.KaspaPrevTxIdMismatch, String(error.message));
|
|
56875
|
+
}
|
|
56876
|
+
throw error;
|
|
56877
|
+
}
|
|
56878
|
+
}
|
|
56879
|
+
if (!this.supportsLegacy) {
|
|
56880
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'KaspaSignTransaction: device chose the legacy protocol but the transaction is not legacy-signable');
|
|
56881
|
+
}
|
|
56882
|
+
return this.processTxRequest(typedCall, response, 0, []);
|
|
56181
56883
|
});
|
|
56182
56884
|
}
|
|
56183
56885
|
}
|
|
@@ -58035,7 +58737,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
58035
58737
|
preInitialize: PreInitialize,
|
|
58036
58738
|
searchDevices: SearchDevices,
|
|
58037
58739
|
getFeatures: GetFeatures,
|
|
58038
|
-
|
|
58740
|
+
getDeviceState: GetDeviceState,
|
|
58039
58741
|
getOnekeyFeatures: GetOnekeyFeatures,
|
|
58040
58742
|
getPassphraseState: GetPassphraseState,
|
|
58041
58743
|
getLogs: GetLogs,
|
|
@@ -58075,15 +58777,12 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
58075
58777
|
protocolInfoRequest: ProtocolInfoRequest,
|
|
58076
58778
|
ping: Ping,
|
|
58077
58779
|
deviceReboot: DeviceReboot,
|
|
58078
|
-
deviceInfoGet: DeviceInfoGet,
|
|
58079
|
-
deviceStatusGet: DeviceStatusGet,
|
|
58080
58780
|
deviceGetOnboardingStatus: DeviceGetOnboardingStatus,
|
|
58081
58781
|
deviceSessionOpen: DeviceSessionOpen,
|
|
58082
58782
|
deviceFirmwareUpdate: DeviceFirmwareUpdate,
|
|
58083
58783
|
deviceGetFirmwareUpdateStatus: DeviceGetFirmwareUpdateStatus,
|
|
58084
58784
|
deviceFactoryInfoSet: DeviceFactoryInfoSet,
|
|
58085
58785
|
deviceFactoryInfoGet: DeviceFactoryInfoGet,
|
|
58086
|
-
deviceSettingsGet: DeviceSettingsGet,
|
|
58087
58786
|
deviceSettingsSet: DeviceSettingsSet,
|
|
58088
58787
|
deviceSettingsPageShow: DeviceSettingsPageShow,
|
|
58089
58788
|
deviceUploadWallpaper: DeviceUploadWallpaper,
|
|
@@ -58198,12 +58897,139 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
58198
58897
|
neoSignTransaction: NeoSignTransaction
|
|
58199
58898
|
});
|
|
58200
58899
|
|
|
58900
|
+
const TARGET_KEYS = [
|
|
58901
|
+
'hw',
|
|
58902
|
+
'fw',
|
|
58903
|
+
'coprocessor',
|
|
58904
|
+
'se1',
|
|
58905
|
+
'se2',
|
|
58906
|
+
'se3',
|
|
58907
|
+
'se4',
|
|
58908
|
+
];
|
|
58909
|
+
const TYPE_KEYS = ['version', 'build_id', 'hash', 'specific'];
|
|
58910
|
+
const DEFAULT_TARGETS = {
|
|
58911
|
+
hw: true,
|
|
58912
|
+
fw: true,
|
|
58913
|
+
coprocessor: true,
|
|
58914
|
+
};
|
|
58915
|
+
const DEFAULT_TYPES = {
|
|
58916
|
+
version: true,
|
|
58917
|
+
specific: true,
|
|
58918
|
+
};
|
|
58919
|
+
function pickBooleanKeys(value, keys) {
|
|
58920
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
58921
|
+
return undefined;
|
|
58922
|
+
const source = value;
|
|
58923
|
+
const result = {};
|
|
58924
|
+
let hasKey = false;
|
|
58925
|
+
for (const key of keys) {
|
|
58926
|
+
if (source[key]) {
|
|
58927
|
+
result[key] = true;
|
|
58928
|
+
hasKey = true;
|
|
58929
|
+
}
|
|
58930
|
+
}
|
|
58931
|
+
return hasKey ? result : undefined;
|
|
58932
|
+
}
|
|
58933
|
+
function assertKnownKeys(value, keys, name) {
|
|
58934
|
+
if (value == null)
|
|
58935
|
+
return;
|
|
58936
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
58937
|
+
throw invalidParameter(`Parameter [${name}] must be an object.`);
|
|
58938
|
+
}
|
|
58939
|
+
const allowed = new Set(keys);
|
|
58940
|
+
const unknownKeys = Object.keys(value).filter(key => !allowed.has(key));
|
|
58941
|
+
if (unknownKeys.length > 0) {
|
|
58942
|
+
throw invalidParameter(`Parameter [${name}] contains unsupported key(s): ${unknownKeys.join(', ')}.`);
|
|
58943
|
+
}
|
|
58944
|
+
}
|
|
58945
|
+
function normalizeTargets(value) {
|
|
58946
|
+
assertKnownKeys(value, TARGET_KEYS.map(key => String(key)), 'targets');
|
|
58947
|
+
return pickBooleanKeys(value, TARGET_KEYS);
|
|
58948
|
+
}
|
|
58949
|
+
function normalizeTypes(value) {
|
|
58950
|
+
assertKnownKeys(value, TYPE_KEYS.map(key => String(key)), 'types');
|
|
58951
|
+
return pickBooleanKeys(value, TYPE_KEYS);
|
|
58952
|
+
}
|
|
58953
|
+
class DeviceInfoGet extends BaseMethod {
|
|
58954
|
+
init() {
|
|
58955
|
+
var _a, _b;
|
|
58956
|
+
this.requireProtocolV2 = true;
|
|
58957
|
+
this.unlockPolicy = 'none';
|
|
58958
|
+
this.allowDeviceMode = [
|
|
58959
|
+
...this.allowDeviceMode,
|
|
58960
|
+
UI_REQUEST.NOT_INITIALIZE,
|
|
58961
|
+
UI_REQUEST.BOOTLOADER,
|
|
58962
|
+
];
|
|
58963
|
+
this.useDevicePassphraseState = false;
|
|
58964
|
+
this.skipForceUpdateCheck = true;
|
|
58965
|
+
this.params = {
|
|
58966
|
+
targets: (_a = normalizeTargets(this.payload.targets)) !== null && _a !== void 0 ? _a : DEFAULT_TARGETS,
|
|
58967
|
+
types: (_b = normalizeTypes(this.payload.types)) !== null && _b !== void 0 ? _b : DEFAULT_TYPES,
|
|
58968
|
+
};
|
|
58969
|
+
}
|
|
58970
|
+
run() {
|
|
58971
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58972
|
+
if (!this.device.isProtocolV2()) {
|
|
58973
|
+
throw hdShared.createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
|
|
58974
|
+
}
|
|
58975
|
+
const res = yield this.device.commands.typedCall('DeviceInfoGet', 'DeviceInfo', {
|
|
58976
|
+
targets: this.params.targets,
|
|
58977
|
+
types: this.params.types,
|
|
58978
|
+
}, { timeoutMs: PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS });
|
|
58979
|
+
return Promise.resolve(res.message);
|
|
58980
|
+
});
|
|
58981
|
+
}
|
|
58982
|
+
}
|
|
58983
|
+
|
|
58984
|
+
class DeviceStatusGet extends BaseMethod {
|
|
58985
|
+
init() {
|
|
58986
|
+
this.requireProtocolV2 = true;
|
|
58987
|
+
this.unlockPolicy = 'none';
|
|
58988
|
+
this.useDevicePassphraseState = false;
|
|
58989
|
+
this.skipForceUpdateCheck = true;
|
|
58990
|
+
}
|
|
58991
|
+
run() {
|
|
58992
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58993
|
+
const { message } = yield this.device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
|
|
58994
|
+
this.device.updateProtocolV2Status(message);
|
|
58995
|
+
return message;
|
|
58996
|
+
});
|
|
58997
|
+
}
|
|
58998
|
+
}
|
|
58999
|
+
|
|
59000
|
+
class DeviceSettingsGet extends BaseMethod {
|
|
59001
|
+
init() {
|
|
59002
|
+
this.requireProtocolV2 = true;
|
|
59003
|
+
this.unlockPolicy = 'none';
|
|
59004
|
+
this.skipForceUpdateCheck = true;
|
|
59005
|
+
this.useDevicePassphraseState = false;
|
|
59006
|
+
this.params = undefined;
|
|
59007
|
+
}
|
|
59008
|
+
run() {
|
|
59009
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59010
|
+
const res = yield this.device.commands.typedCall('DeviceSettingsGet', 'DeviceSettings', {});
|
|
59011
|
+
this.device.updateState(mapDeviceSettingsToState(res.message), 'apply-settings');
|
|
59012
|
+
return Promise.resolve(res.message);
|
|
59013
|
+
});
|
|
59014
|
+
}
|
|
59015
|
+
}
|
|
59016
|
+
|
|
59017
|
+
var InternalApiMethods = /*#__PURE__*/Object.freeze({
|
|
59018
|
+
__proto__: null,
|
|
59019
|
+
deviceInfoGet: DeviceInfoGet,
|
|
59020
|
+
deviceStatusGet: DeviceStatusGet,
|
|
59021
|
+
deviceSettingsGet: DeviceSettingsGet
|
|
59022
|
+
});
|
|
59023
|
+
|
|
59024
|
+
const publicMethodRegistry = ApiMethods;
|
|
59025
|
+
const internalMethodRegistry = InternalApiMethods;
|
|
58201
59026
|
function findMethod(message) {
|
|
59027
|
+
var _a;
|
|
58202
59028
|
const { method } = message.payload;
|
|
58203
59029
|
if (typeof method !== 'string') {
|
|
58204
59030
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Method is not set');
|
|
58205
59031
|
}
|
|
58206
|
-
const MethodConstructor =
|
|
59032
|
+
const MethodConstructor = (_a = publicMethodRegistry[method]) !== null && _a !== void 0 ? _a : internalMethodRegistry[method];
|
|
58207
59033
|
if (MethodConstructor) {
|
|
58208
59034
|
return new MethodConstructor(message);
|
|
58209
59035
|
}
|
|
@@ -58906,6 +59732,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
58906
59732
|
attachPinOnDevice: onEnterAttachPinOnDeviceHandler,
|
|
58907
59733
|
});
|
|
58908
59734
|
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
59735
|
+
device.on(DEVICE.STATE, onDeviceStateHandler);
|
|
58909
59736
|
device.on(DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE, onSelectDeviceInBootloaderForWebDeviceHandler);
|
|
58910
59737
|
const protocolV2UiCoordinator = new ProtocolV2UiInteractionCoordinator(device, postMessage);
|
|
58911
59738
|
device.on(DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE, onSelectDeviceForSwitchFirmwareWebDeviceHandler);
|
|
@@ -58990,7 +59817,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
58990
59817
|
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceUnexpectedMode, unexpectedMode));
|
|
58991
59818
|
}
|
|
58992
59819
|
if (method.deviceId && method.checkDeviceId) {
|
|
58993
|
-
const isSameDeviceID = device
|
|
59820
|
+
const isSameDeviceID = yield checkLiveDeviceId(device, method.deviceId);
|
|
58994
59821
|
if (!isSameDeviceID) {
|
|
58995
59822
|
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckDeviceIdError));
|
|
58996
59823
|
}
|
|
@@ -59497,6 +60324,9 @@ const onDeviceButtonHandler = (...[device, request]) => {
|
|
|
59497
60324
|
const onDeviceFeaturesHandler = (...[_, features]) => {
|
|
59498
60325
|
postMessage(createDeviceMessage(DEVICE.FEATURES, Object.assign({}, features)));
|
|
59499
60326
|
};
|
|
60327
|
+
const onDeviceStateHandler = (...[_, stateEvent]) => {
|
|
60328
|
+
postMessage(createDeviceMessage(DEVICE.STATE, stateEvent));
|
|
60329
|
+
};
|
|
59500
60330
|
const onDevicePassphraseHandler = (...[device, requestPayload, callback]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59501
60331
|
Log.debug('onDevicePassphraseHandler');
|
|
59502
60332
|
const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PASSPHRASE, device);
|