@onekeyfe/hd-core 1.2.0-alpha.16 → 1.2.0-alpha.18
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__/deviceFeaturesUtils.test.ts +27 -0
- package/__tests__/evmLedgerLegacySafety.test.ts +3 -0
- package/__tests__/homescreen.test.ts +24 -0
- package/__tests__/kaspaSignTransaction.test.ts +591 -0
- package/__tests__/protocol-v2.test.ts +1006 -204
- package/__tests__/protocolV2FileWrite.test.ts +28 -3
- package/__tests__/protocolV2UiInteraction.test.ts +266 -0
- package/dist/api/BaseMethod.d.ts +4 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +3 -3
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetDeviceInfo.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts.map +1 -1
- package/dist/api/device/DeviceCancel.d.ts.map +1 -1
- package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
- package/dist/api/device/DeviceLock.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +1 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts +28 -0
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSettingsPageShow.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/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/core/deviceEventRegistration.d.ts +1 -0
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +3 -3
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +7 -5
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts +2 -2
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts +6 -2
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceProfile.d.ts +3 -2
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
- package/dist/events/device.d.ts +4 -0
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +18 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +85 -15
- package/dist/index.js +1515 -554
- package/dist/protocols/protocol-v2/features.d.ts +6 -18
- 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/uiInteraction.d.ts +39 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +5 -3
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +2 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/api/getDeviceInfo.d.ts +2 -1
- package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +2 -2
- 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 +4 -2
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +2 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +10 -2
- package/src/api/FirmwareUpdateV4.ts +27 -73
- package/src/api/GetDeviceInfo.ts +9 -2
- package/src/api/GetPassphraseState.ts +5 -2
- package/src/api/UploadPortfolio.ts +2 -0
- package/src/api/device/DeviceCancel.ts +1 -0
- package/src/api/device/DeviceChangePin.ts +23 -0
- package/src/api/device/DeviceLock.ts +1 -0
- package/src/api/device/DeviceUnlock.ts +9 -0
- package/src/api/device/DeviceWipe.ts +18 -0
- package/src/api/helpers/protocolV2FileWrite.ts +35 -11
- package/src/api/index.ts +1 -1
- package/src/api/kaspa/KaspaSignTransaction.ts +341 -22
- package/src/api/kaspa/helpers/TransferSerialize.ts +14 -0
- package/src/api/protocol-v2/DeviceInfoGet.ts +0 -1
- package/src/api/protocol-v2/DeviceSessionOpen.ts +100 -0
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +9 -1
- package/src/api/protocol-v2/DeviceSettingsSet.ts +11 -1
- package/src/api/protocol-v2/DeviceStatusGet.ts +1 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +2 -1
- package/src/core/deviceEventRegistration.ts +2 -0
- package/src/core/index.ts +36 -3
- package/src/data/messages/messages-protocol-v2.json +122 -23
- package/src/data/messages/messages.json +286 -1
- package/src/device/Device.ts +33 -41
- package/src/device/DeviceCommands.ts +22 -4
- package/src/device/DevicePool.ts +14 -6
- package/src/deviceProfile/buildDeviceFeatures.ts +21 -9
- package/src/deviceProfile/buildDeviceProfile.ts +27 -11
- package/src/events/device.ts +4 -0
- package/src/events/ui-request.ts +24 -2
- package/src/inject.ts +2 -2
- package/src/protocols/protocol-v2/features.ts +27 -20
- package/src/protocols/protocol-v2/index.ts +0 -1
- package/src/protocols/protocol-v2/uiInteraction.ts +209 -0
- package/src/protocols/protocol-v2/unlockRetry.ts +43 -3
- package/src/protocols/protocol-v2/walletSession.ts +122 -31
- package/src/types/api/getDeviceInfo.ts +6 -1
- package/src/types/api/index.ts +2 -2
- package/src/types/api/kaspaSignTransaction.ts +40 -2
- package/src/types/api/protocolV2.ts +5 -3
- package/src/types/device.ts +6 -1
- package/src/utils/deviceFeaturesUtils.ts +13 -0
- package/src/utils/homescreen.ts +10 -0
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts.map +0 -1
- package/src/api/protocol-v2/DeviceSessionGet.ts +0 -15
package/dist/index.js
CHANGED
|
@@ -146,7 +146,7 @@ const createCoreApi = (call) => ({
|
|
|
146
146
|
deviceInfoGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceInfoGet' })),
|
|
147
147
|
deviceStatusGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceStatusGet' })),
|
|
148
148
|
deviceGetOnboardingStatus: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceGetOnboardingStatus' })),
|
|
149
|
-
|
|
149
|
+
deviceSessionOpen: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceSessionOpen' })),
|
|
150
150
|
deviceFirmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFirmwareUpdate' })),
|
|
151
151
|
deviceGetFirmwareUpdateStatus: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceGetFirmwareUpdateStatus' })),
|
|
152
152
|
deviceFactoryInfoSet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFactoryInfoSet' })),
|
|
@@ -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,
|
|
@@ -25779,7 +26064,7 @@ var nested = {
|
|
|
25779
26064
|
MessageType_DeviceStatus: 60603,
|
|
25780
26065
|
MessageType_DevGetOnboardingStatus: 60604,
|
|
25781
26066
|
MessageType_DevOnboardingStatus: 60605,
|
|
25782
|
-
|
|
26067
|
+
MessageType_DeviceSessionOpen: 60606,
|
|
25783
26068
|
MessageType_DeviceSession: 60607,
|
|
25784
26069
|
MessageType_DeviceSessionAskPin: 60608,
|
|
25785
26070
|
MessageType_FilesystemPermissionFix: 60800,
|
|
@@ -37765,14 +38050,77 @@ var nested = {
|
|
|
37765
38050
|
}
|
|
37766
38051
|
}
|
|
37767
38052
|
},
|
|
37768
|
-
|
|
38053
|
+
DeviceSessionResume: {
|
|
37769
38054
|
fields: {
|
|
37770
38055
|
session_id: {
|
|
38056
|
+
rule: "required",
|
|
37771
38057
|
type: "bytes",
|
|
37772
38058
|
id: 1
|
|
37773
38059
|
}
|
|
37774
38060
|
}
|
|
37775
38061
|
},
|
|
38062
|
+
DeviceHostPassphrase: {
|
|
38063
|
+
fields: {
|
|
38064
|
+
passphrase: {
|
|
38065
|
+
rule: "required",
|
|
38066
|
+
type: "string",
|
|
38067
|
+
id: 1
|
|
38068
|
+
}
|
|
38069
|
+
}
|
|
38070
|
+
},
|
|
38071
|
+
DevicePassphraseOnDevice: {
|
|
38072
|
+
fields: {
|
|
38073
|
+
}
|
|
38074
|
+
},
|
|
38075
|
+
DeviceAttachPinOnDevice: {
|
|
38076
|
+
fields: {
|
|
38077
|
+
}
|
|
38078
|
+
},
|
|
38079
|
+
DeviceWalletSelect: {
|
|
38080
|
+
oneofs: {
|
|
38081
|
+
access: {
|
|
38082
|
+
oneof: [
|
|
38083
|
+
"host_passphrase",
|
|
38084
|
+
"passphrase_on_device",
|
|
38085
|
+
"attach_pin_on_device"
|
|
38086
|
+
]
|
|
38087
|
+
}
|
|
38088
|
+
},
|
|
38089
|
+
fields: {
|
|
38090
|
+
host_passphrase: {
|
|
38091
|
+
type: "DeviceHostPassphrase",
|
|
38092
|
+
id: 1
|
|
38093
|
+
},
|
|
38094
|
+
passphrase_on_device: {
|
|
38095
|
+
type: "DevicePassphraseOnDevice",
|
|
38096
|
+
id: 2
|
|
38097
|
+
},
|
|
38098
|
+
attach_pin_on_device: {
|
|
38099
|
+
type: "DeviceAttachPinOnDevice",
|
|
38100
|
+
id: 3
|
|
38101
|
+
}
|
|
38102
|
+
}
|
|
38103
|
+
},
|
|
38104
|
+
DeviceSessionOpen: {
|
|
38105
|
+
oneofs: {
|
|
38106
|
+
mode: {
|
|
38107
|
+
oneof: [
|
|
38108
|
+
"resume",
|
|
38109
|
+
"select"
|
|
38110
|
+
]
|
|
38111
|
+
}
|
|
38112
|
+
},
|
|
38113
|
+
fields: {
|
|
38114
|
+
resume: {
|
|
38115
|
+
type: "DeviceSessionResume",
|
|
38116
|
+
id: 1
|
|
38117
|
+
},
|
|
38118
|
+
select: {
|
|
38119
|
+
type: "DeviceWalletSelect",
|
|
38120
|
+
id: 2
|
|
38121
|
+
}
|
|
38122
|
+
}
|
|
38123
|
+
},
|
|
37776
38124
|
DeviceSession: {
|
|
37777
38125
|
fields: {
|
|
37778
38126
|
session_id: {
|
|
@@ -37830,21 +38178,59 @@ var nested = {
|
|
|
37830
38178
|
fields: {
|
|
37831
38179
|
}
|
|
37832
38180
|
},
|
|
37833
|
-
|
|
38181
|
+
DevOnboardingStep: {
|
|
37834
38182
|
values: {
|
|
37835
|
-
|
|
37836
|
-
|
|
37837
|
-
|
|
37838
|
-
|
|
37839
|
-
|
|
37840
|
-
|
|
37841
|
-
|
|
37842
|
-
|
|
37843
|
-
|
|
37844
|
-
|
|
37845
|
-
|
|
37846
|
-
|
|
37847
|
-
|
|
38183
|
+
DEV_ONBOARDING_STEP_UNKNOWN: 0,
|
|
38184
|
+
DEV_ONBOARDING_STEP_CHECKING: 1,
|
|
38185
|
+
DEV_ONBOARDING_STEP_PERSONALIZATION: 2,
|
|
38186
|
+
DEV_ONBOARDING_STEP_PIN: 3,
|
|
38187
|
+
DEV_ONBOARDING_STEP_SETUP: 4,
|
|
38188
|
+
DEV_ONBOARDING_STEP_DONE: 5
|
|
38189
|
+
}
|
|
38190
|
+
},
|
|
38191
|
+
DevOnboardingPhase: {
|
|
38192
|
+
values: {
|
|
38193
|
+
DEV_ONBOARDING_PHASE_UNKNOWN: 0,
|
|
38194
|
+
DEV_ONBOARDING_PHASE_SAFETY_CHECK: 1,
|
|
38195
|
+
DEV_ONBOARDING_PHASE_PIN_SETUP: 2,
|
|
38196
|
+
DEV_ONBOARDING_PHASE_FINGERPRINT_SETUP: 3,
|
|
38197
|
+
DEV_ONBOARDING_PHASE_SETUP_CHOICE: 4,
|
|
38198
|
+
DEV_ONBOARDING_PHASE_WALLET_CREATE_START: 5,
|
|
38199
|
+
DEV_ONBOARDING_PHASE_RECOVERY_PHRASE_VIEW: 6,
|
|
38200
|
+
DEV_ONBOARDING_PHASE_RECOVERY_PHRASE_CONFIRM: 7,
|
|
38201
|
+
DEV_ONBOARDING_PHASE_RESTORE_METHOD_CHOICE: 8,
|
|
38202
|
+
DEV_ONBOARDING_PHASE_RECOVERY_PHRASE_RESTORE: 9,
|
|
38203
|
+
DEV_ONBOARDING_PHASE_SEEDCARD_RESTORE: 10,
|
|
38204
|
+
DEV_ONBOARDING_PHASE_WALLET_READY: 11,
|
|
38205
|
+
DEV_ONBOARDING_PHASE_SEEDCARD_BACKUP_PROMPT: 12,
|
|
38206
|
+
DEV_ONBOARDING_PHASE_SEEDCARD_BACKUP: 13
|
|
38207
|
+
}
|
|
38208
|
+
},
|
|
38209
|
+
DevOnboardingSetupKind: {
|
|
38210
|
+
values: {
|
|
38211
|
+
DEV_ONBOARDING_SETUP_KIND_UNKNOWN: 0,
|
|
38212
|
+
DEV_ONBOARDING_SETUP_KIND_CHOICE: 1,
|
|
38213
|
+
DEV_ONBOARDING_SETUP_KIND_CREATE: 2,
|
|
38214
|
+
DEV_ONBOARDING_SETUP_KIND_RESTORE: 3
|
|
38215
|
+
}
|
|
38216
|
+
},
|
|
38217
|
+
DevOnboardingSetupMethod: {
|
|
38218
|
+
values: {
|
|
38219
|
+
DEV_ONBOARDING_SETUP_METHOD_UNKNOWN: 0,
|
|
38220
|
+
DEV_ONBOARDING_SETUP_METHOD_RECOVERY_PHRASE: 1,
|
|
38221
|
+
DEV_ONBOARDING_SETUP_METHOD_SEEDCARD: 2
|
|
38222
|
+
}
|
|
38223
|
+
},
|
|
38224
|
+
DevOnboardingSetupStatus: {
|
|
38225
|
+
fields: {
|
|
38226
|
+
kind: {
|
|
38227
|
+
type: "DevOnboardingSetupKind",
|
|
38228
|
+
id: 1
|
|
38229
|
+
},
|
|
38230
|
+
method: {
|
|
38231
|
+
type: "DevOnboardingSetupMethod",
|
|
38232
|
+
id: 2
|
|
38233
|
+
}
|
|
37848
38234
|
}
|
|
37849
38235
|
},
|
|
37850
38236
|
DevGetOnboardingStatus: {
|
|
@@ -37853,18 +38239,25 @@ var nested = {
|
|
|
37853
38239
|
},
|
|
37854
38240
|
DevOnboardingStatus: {
|
|
37855
38241
|
fields: {
|
|
37856
|
-
|
|
37857
|
-
|
|
37858
|
-
type: "DevOnboardingStage",
|
|
38242
|
+
step: {
|
|
38243
|
+
type: "DevOnboardingStep",
|
|
37859
38244
|
id: 1
|
|
37860
38245
|
},
|
|
37861
|
-
|
|
37862
|
-
type: "
|
|
38246
|
+
phase: {
|
|
38247
|
+
type: "DevOnboardingPhase",
|
|
37863
38248
|
id: 2
|
|
37864
38249
|
},
|
|
37865
|
-
|
|
37866
|
-
type: "
|
|
38250
|
+
setup: {
|
|
38251
|
+
type: "DevOnboardingSetupStatus",
|
|
37867
38252
|
id: 3
|
|
38253
|
+
},
|
|
38254
|
+
pin_set: {
|
|
38255
|
+
type: "bool",
|
|
38256
|
+
id: 4
|
|
38257
|
+
},
|
|
38258
|
+
wallet_initialized: {
|
|
38259
|
+
type: "bool",
|
|
38260
|
+
id: 5
|
|
37868
38261
|
}
|
|
37869
38262
|
}
|
|
37870
38263
|
},
|
|
@@ -39250,6 +39643,197 @@ const PROTOBUF_MESSAGE_CONFIG = {
|
|
|
39250
39643
|
],
|
|
39251
39644
|
};
|
|
39252
39645
|
|
|
39646
|
+
const CORE_EVENT = 'CORE_EVENT';
|
|
39647
|
+
const parseMessage = (messageData) => {
|
|
39648
|
+
const { data } = messageData;
|
|
39649
|
+
const message = {
|
|
39650
|
+
event: data.event,
|
|
39651
|
+
type: data.type,
|
|
39652
|
+
payload: data.payload,
|
|
39653
|
+
};
|
|
39654
|
+
if (typeof messageData.id === 'number') {
|
|
39655
|
+
message.id = messageData.id;
|
|
39656
|
+
}
|
|
39657
|
+
if (typeof message.success === 'boolean') {
|
|
39658
|
+
message.success = data.success;
|
|
39659
|
+
}
|
|
39660
|
+
return message;
|
|
39661
|
+
};
|
|
39662
|
+
const createErrorMessage = (error) => {
|
|
39663
|
+
let payload = { error: error.message, code: error.code };
|
|
39664
|
+
if (error instanceof hdShared.HardwareError) {
|
|
39665
|
+
payload = { error: error.message, code: error.errorCode };
|
|
39666
|
+
}
|
|
39667
|
+
return {
|
|
39668
|
+
success: false,
|
|
39669
|
+
payload,
|
|
39670
|
+
};
|
|
39671
|
+
};
|
|
39672
|
+
|
|
39673
|
+
const UI_EVENT = 'UI_EVENT';
|
|
39674
|
+
const UI_REQUEST = {
|
|
39675
|
+
REQUEST_PIN: 'ui-request_pin',
|
|
39676
|
+
INVALID_PIN: 'ui-invalid_pin',
|
|
39677
|
+
REQUEST_BUTTON: 'ui-button',
|
|
39678
|
+
REQUEST_PASSPHRASE: 'ui-request_passphrase',
|
|
39679
|
+
REQUEST_PASSPHRASE_ON_DEVICE: 'ui-request_passphrase_on_device',
|
|
39680
|
+
REQUEST_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE: 'ui-request_select_device_in_bootloader_for_web_device',
|
|
39681
|
+
REQUEST_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE: 'ui-request_select_device_for_switch_firmware_web_device',
|
|
39682
|
+
CLOSE_UI_WINDOW: 'ui-close_window',
|
|
39683
|
+
CLOSE_UI_PIN_WINDOW: 'ui-close_pin_window',
|
|
39684
|
+
DEVICE_PROGRESS: 'ui-device_progress',
|
|
39685
|
+
BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
|
|
39686
|
+
BLUETOOTH_UNSUPPORTED: 'ui-bluetooth_unsupported',
|
|
39687
|
+
BLUETOOTH_POWERED_OFF: 'ui-bluetooth_powered_off',
|
|
39688
|
+
BLUETOOTH_CHARACTERISTIC_NOTIFY_CHANGE_FAILURE: 'ui-bluetooth_characteristic_notify_change_failure',
|
|
39689
|
+
LOCATION_PERMISSION: 'ui-location_permission',
|
|
39690
|
+
LOCATION_SERVICE_PERMISSION: 'ui-location_service_permission',
|
|
39691
|
+
FIRMWARE_PROCESSING: 'ui-firmware-processing',
|
|
39692
|
+
FIRMWARE_PROGRESS: 'ui-firmware-progress',
|
|
39693
|
+
FIRMWARE_TIP: 'ui-firmware-tip',
|
|
39694
|
+
PREVIOUS_ADDRESS_RESULT: 'ui-previous_address_result',
|
|
39695
|
+
WEB_DEVICE_PROMPT_ACCESS_PERMISSION: 'ui-web_device_prompt_access_permission',
|
|
39696
|
+
BOOTLOADER: 'ui-device_bootloader_mode',
|
|
39697
|
+
NOT_IN_BOOTLOADER: 'ui-device_not_in_bootloader_mode',
|
|
39698
|
+
REQUIRE_MODE: 'ui-device_require_mode',
|
|
39699
|
+
NOT_INITIALIZE: 'ui-device_not_initialized',
|
|
39700
|
+
SEEDLESS: 'ui-device_seedless',
|
|
39701
|
+
FIRMWARE_OLD: 'ui-device_firmware_old',
|
|
39702
|
+
FIRMWARE_NOT_SUPPORTED: 'ui-device_firmware_unsupported',
|
|
39703
|
+
FIRMWARE_NOT_COMPATIBLE: 'ui-device_firmware_not_compatible',
|
|
39704
|
+
FIRMWARE_NOT_INSTALLED: 'ui-device_firmware_not_installed',
|
|
39705
|
+
NOT_USE_ONEKEY_DEVICE: 'ui-device_please_use_onekey_device',
|
|
39706
|
+
};
|
|
39707
|
+
exports.FirmwareUpdateTipMessage = void 0;
|
|
39708
|
+
(function (FirmwareUpdateTipMessage) {
|
|
39709
|
+
FirmwareUpdateTipMessage["CheckLatestUiResource"] = "CheckLatestUiResource";
|
|
39710
|
+
FirmwareUpdateTipMessage["StartDownloadFirmware"] = "StartDownloadFirmware";
|
|
39711
|
+
FirmwareUpdateTipMessage["FinishDownloadFirmware"] = "FinishDownloadFirmware";
|
|
39712
|
+
FirmwareUpdateTipMessage["DownloadLatestUiResource"] = "DownloadLatestUiResource";
|
|
39713
|
+
FirmwareUpdateTipMessage["DownloadFirmware"] = "DownloadFirmware";
|
|
39714
|
+
FirmwareUpdateTipMessage["DownloadBleFirmware"] = "DownloadBleFirmware";
|
|
39715
|
+
FirmwareUpdateTipMessage["DownloadLatestBootloaderResource"] = "DownloadLatestBootloaderResource";
|
|
39716
|
+
FirmwareUpdateTipMessage["DownloadLatestUiResourceSuccess"] = "DownloadLatestUiResourceSuccess";
|
|
39717
|
+
FirmwareUpdateTipMessage["DownloadFirmwareSuccess"] = "DownloadFirmwareSuccess";
|
|
39718
|
+
FirmwareUpdateTipMessage["DownloadBleFirmwareSuccess"] = "DownloadBleFirmwareSuccess";
|
|
39719
|
+
FirmwareUpdateTipMessage["DownloadLatestBootloaderResourceSuccess"] = "DownloadLatestBootloaderResourceSuccess";
|
|
39720
|
+
FirmwareUpdateTipMessage["AutoRebootToBootloader"] = "AutoRebootToBootloader";
|
|
39721
|
+
FirmwareUpdateTipMessage["GoToBootloaderSuccess"] = "GoToBootloaderSuccess";
|
|
39722
|
+
FirmwareUpdateTipMessage["SelectDeviceInBootloaderForWebDevice"] = "SelectDeviceInBootloaderForWebDevice";
|
|
39723
|
+
FirmwareUpdateTipMessage["SwitchFirmwareReconnectDevice"] = "SwitchFirmwareReconnectDevice";
|
|
39724
|
+
FirmwareUpdateTipMessage["ConfirmOnDevice"] = "ConfirmOnDevice";
|
|
39725
|
+
FirmwareUpdateTipMessage["FirmwareEraseSuccess"] = "FirmwareEraseSuccess";
|
|
39726
|
+
FirmwareUpdateTipMessage["StartTransferData"] = "StartTransferData";
|
|
39727
|
+
FirmwareUpdateTipMessage["InstallingFirmware"] = "InstallingFirmware";
|
|
39728
|
+
FirmwareUpdateTipMessage["UpdateBootloader"] = "UpdateBootloader";
|
|
39729
|
+
FirmwareUpdateTipMessage["UpdateBootloaderSuccess"] = "UpdateBootloaderSuccess";
|
|
39730
|
+
FirmwareUpdateTipMessage["UpdateSysResource"] = "UpdateSysResource";
|
|
39731
|
+
FirmwareUpdateTipMessage["UpdateSysResourceSuccess"] = "UpdateSysResourceSuccess";
|
|
39732
|
+
FirmwareUpdateTipMessage["FirmwareUpdating"] = "FirmwareUpdating";
|
|
39733
|
+
FirmwareUpdateTipMessage["FirmwareUpdateCompleted"] = "FirmwareUpdateCompleted";
|
|
39734
|
+
})(exports.FirmwareUpdateTipMessage || (exports.FirmwareUpdateTipMessage = {}));
|
|
39735
|
+
const createUiMessage = (type, payload) => ({
|
|
39736
|
+
event: UI_EVENT,
|
|
39737
|
+
type,
|
|
39738
|
+
payload,
|
|
39739
|
+
});
|
|
39740
|
+
|
|
39741
|
+
const IFRAME = {
|
|
39742
|
+
INIT: 'iframe-init',
|
|
39743
|
+
INIT_BRIDGE: 'iframe-init-bridge',
|
|
39744
|
+
CALL: 'iframe-call',
|
|
39745
|
+
CANCEL: 'iframe-cancel',
|
|
39746
|
+
CANCEL_OPERATION: 'iframe-cancel-operation',
|
|
39747
|
+
SWITCH_TRANSPORT: 'iframe-switch-transport',
|
|
39748
|
+
CALLBACK: 'iframe-callback',
|
|
39749
|
+
};
|
|
39750
|
+
const createIFrameMessage = (type, payload) => ({
|
|
39751
|
+
event: UI_EVENT,
|
|
39752
|
+
type,
|
|
39753
|
+
payload,
|
|
39754
|
+
});
|
|
39755
|
+
|
|
39756
|
+
const RESPONSE_EVENT = 'RESPONSE_EVENT';
|
|
39757
|
+
const createResponseMessage = (id, success, payload) => ({
|
|
39758
|
+
event: RESPONSE_EVENT,
|
|
39759
|
+
type: RESPONSE_EVENT,
|
|
39760
|
+
id,
|
|
39761
|
+
success,
|
|
39762
|
+
payload: success ? payload : hdShared.serializeError(payload),
|
|
39763
|
+
});
|
|
39764
|
+
|
|
39765
|
+
const UI_RESPONSE = {
|
|
39766
|
+
RECEIVE_PIN: 'ui-receive_pin',
|
|
39767
|
+
RECEIVE_PASSPHRASE: 'ui-receive_passphrase',
|
|
39768
|
+
SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE: 'ui-receive_select-device-in-bootloader-for-web-device',
|
|
39769
|
+
SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE: 'ui-receive_select-device-for-switch-firmware-web-device',
|
|
39770
|
+
};
|
|
39771
|
+
const createUiResponse = (type, payload) => ({
|
|
39772
|
+
event: UI_EVENT,
|
|
39773
|
+
type,
|
|
39774
|
+
payload,
|
|
39775
|
+
});
|
|
39776
|
+
|
|
39777
|
+
const DEVICE_EVENT = 'DEVICE_EVENT';
|
|
39778
|
+
const DEVICE = {
|
|
39779
|
+
CONNECT: 'device-connect',
|
|
39780
|
+
CONNECT_UNACQUIRED: 'device-connect_unacquired',
|
|
39781
|
+
DISCONNECT: 'device-disconnect',
|
|
39782
|
+
CHANGED: 'device-changed',
|
|
39783
|
+
ACQUIRE: 'device-acquire',
|
|
39784
|
+
RELEASE: 'device-release',
|
|
39785
|
+
ACQUIRED: 'device-acquired',
|
|
39786
|
+
RELEASED: 'device-released',
|
|
39787
|
+
USED_ELSEWHERE: 'device-used_elsewhere',
|
|
39788
|
+
UNREADABLE: 'unreadable-device',
|
|
39789
|
+
LOADING: 'device-loading',
|
|
39790
|
+
BUTTON: 'button',
|
|
39791
|
+
PIN: 'pin',
|
|
39792
|
+
PASSPHRASE: 'passphrase',
|
|
39793
|
+
PASSPHRASE_ON_DEVICE: 'passphrase_on_device',
|
|
39794
|
+
ATTACH_PIN_ON_DEVICE: 'attach_pin_on_device',
|
|
39795
|
+
WORD: 'word',
|
|
39796
|
+
SUPPORT_FEATURES: 'support_features',
|
|
39797
|
+
SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE: 'select_device_in_bootloader_for_web_device',
|
|
39798
|
+
SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE: 'select_device_for_switch_firmware_web_device',
|
|
39799
|
+
FEATURES: 'features',
|
|
39800
|
+
};
|
|
39801
|
+
const createDeviceMessage = (type, payload) => ({
|
|
39802
|
+
event: DEVICE_EVENT,
|
|
39803
|
+
type,
|
|
39804
|
+
payload,
|
|
39805
|
+
});
|
|
39806
|
+
|
|
39807
|
+
const FIRMWARE_EVENT = 'FIRMWARE_EVENT';
|
|
39808
|
+
const FIRMWARE = {
|
|
39809
|
+
RELEASE_INFO: 'firmware-release-info',
|
|
39810
|
+
BLE_RELEASE_INFO: 'ble-firmware-release-info',
|
|
39811
|
+
};
|
|
39812
|
+
const createFirmwareMessage = (type, payload) => ({
|
|
39813
|
+
event: FIRMWARE_EVENT,
|
|
39814
|
+
type,
|
|
39815
|
+
payload,
|
|
39816
|
+
});
|
|
39817
|
+
|
|
39818
|
+
const LogBlockEvent = new Set([
|
|
39819
|
+
UI_RESPONSE.RECEIVE_PIN,
|
|
39820
|
+
UI_RESPONSE.RECEIVE_PASSPHRASE,
|
|
39821
|
+
]);
|
|
39822
|
+
const LogBlockMethod = new Set(['evmSignTypedData']);
|
|
39823
|
+
function getLogBlockLabel(message) {
|
|
39824
|
+
if (!message || typeof message !== 'object')
|
|
39825
|
+
return undefined;
|
|
39826
|
+
const { type, payload, method } = message;
|
|
39827
|
+
if (type && LogBlockEvent.has(type)) {
|
|
39828
|
+
return type;
|
|
39829
|
+
}
|
|
39830
|
+
const methodName = method !== null && method !== void 0 ? method : payload === null || payload === void 0 ? void 0 : payload.method;
|
|
39831
|
+
if (methodName && LogBlockMethod.has(methodName)) {
|
|
39832
|
+
return methodName;
|
|
39833
|
+
}
|
|
39834
|
+
return undefined;
|
|
39835
|
+
}
|
|
39836
|
+
|
|
39253
39837
|
function isDeviceLockedError(error) {
|
|
39254
39838
|
return (typeof error === 'object' &&
|
|
39255
39839
|
error !== null &&
|
|
@@ -39271,7 +39855,14 @@ const getErrorText = (error) => {
|
|
|
39271
39855
|
return String(error !== null && error !== void 0 ? error : '');
|
|
39272
39856
|
};
|
|
39273
39857
|
const isProtocolV2InvalidSessionError = (error) => getErrorText(error).toLowerCase().includes('failure_invalidsession');
|
|
39274
|
-
|
|
39858
|
+
const normalizeHostPassphrase = (passphrase) => {
|
|
39859
|
+
const normalized = (passphrase !== null && passphrase !== void 0 ? passphrase : '').normalize('NFKD');
|
|
39860
|
+
if (!normalized || normalized.includes('\0') || normalized.length > 50) {
|
|
39861
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Invalid hidden wallet passphrase.');
|
|
39862
|
+
}
|
|
39863
|
+
return normalized;
|
|
39864
|
+
};
|
|
39865
|
+
function requestProtocolV2DeviceStatus$1(device) {
|
|
39275
39866
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39276
39867
|
const { message } = yield device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
|
|
39277
39868
|
return message;
|
|
@@ -39279,57 +39870,118 @@ function requestProtocolV2DeviceStatus(device) {
|
|
|
39279
39870
|
}
|
|
39280
39871
|
function refreshProtocolV2DeviceStatus(device) {
|
|
39281
39872
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39282
|
-
const status = yield requestProtocolV2DeviceStatus(device);
|
|
39873
|
+
const status = yield requestProtocolV2DeviceStatus$1(device);
|
|
39283
39874
|
return device.updateProtocolV2Status(status);
|
|
39284
39875
|
});
|
|
39285
39876
|
}
|
|
39877
|
+
const openDeviceSession = (device, request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39878
|
+
try {
|
|
39879
|
+
return yield device.commands.typedCall('DeviceSessionOpen', 'DeviceSession', request);
|
|
39880
|
+
}
|
|
39881
|
+
catch (error) {
|
|
39882
|
+
if (!isDeviceLockedError(error)) {
|
|
39883
|
+
throw error;
|
|
39884
|
+
}
|
|
39885
|
+
yield device.unlockDevice();
|
|
39886
|
+
return device.commands.typedCall('DeviceSessionOpen', 'DeviceSession', request);
|
|
39887
|
+
}
|
|
39888
|
+
});
|
|
39889
|
+
const createHiddenWalletRequest = (response) => {
|
|
39890
|
+
if (response.attachPinOnDevice) {
|
|
39891
|
+
return {
|
|
39892
|
+
request: {
|
|
39893
|
+
select: {
|
|
39894
|
+
attach_pin_on_device: {},
|
|
39895
|
+
},
|
|
39896
|
+
},
|
|
39897
|
+
deviceEvent: DEVICE.ATTACH_PIN_ON_DEVICE,
|
|
39898
|
+
};
|
|
39899
|
+
}
|
|
39900
|
+
if (response.passphraseOnDevice) {
|
|
39901
|
+
return {
|
|
39902
|
+
request: {
|
|
39903
|
+
select: {
|
|
39904
|
+
passphrase_on_device: {},
|
|
39905
|
+
},
|
|
39906
|
+
},
|
|
39907
|
+
deviceEvent: DEVICE.PASSPHRASE_ON_DEVICE,
|
|
39908
|
+
};
|
|
39909
|
+
}
|
|
39910
|
+
return {
|
|
39911
|
+
request: {
|
|
39912
|
+
select: {
|
|
39913
|
+
host_passphrase: { passphrase: normalizeHostPassphrase(response.passphrase) },
|
|
39914
|
+
},
|
|
39915
|
+
},
|
|
39916
|
+
};
|
|
39917
|
+
};
|
|
39918
|
+
const openSelectedHiddenWallet = (device, promptPayload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39919
|
+
const response = yield device.commands.promptPassphrase(promptPayload, {
|
|
39920
|
+
cancelDeviceOnReject: false,
|
|
39921
|
+
});
|
|
39922
|
+
const { request, deviceEvent } = createHiddenWalletRequest(response);
|
|
39923
|
+
if (deviceEvent) {
|
|
39924
|
+
device.emit(deviceEvent, device, promptPayload);
|
|
39925
|
+
}
|
|
39926
|
+
return openDeviceSession(device, request);
|
|
39927
|
+
});
|
|
39286
39928
|
function getProtocolV2WalletSession(device, options) {
|
|
39287
|
-
var _a, _b, _c, _d;
|
|
39929
|
+
var _a, _b, _c, _d, _e, _f;
|
|
39288
39930
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39289
39931
|
if (options === null || options === void 0 ? void 0 : options.initSession) {
|
|
39290
39932
|
device.clearInternalState();
|
|
39291
39933
|
}
|
|
39292
|
-
|
|
39934
|
+
const expectedPassphraseState = (_a = options === null || options === void 0 ? void 0 : options.expectedPassphraseState) !== null && _a !== void 0 ? _a : device.passphraseState;
|
|
39293
39935
|
try {
|
|
39294
|
-
|
|
39295
|
-
|
|
39936
|
+
if (((_b = device.features) === null || _b === void 0 ? void 0 : _b.unlocked) === false) {
|
|
39937
|
+
yield device.unlockDevice();
|
|
39938
|
+
}
|
|
39939
|
+
if ((options === null || options === void 0 ? void 0 : options.onlyMainPin) || device.getCurrentPassphraseProtection() === false) {
|
|
39940
|
+
return {
|
|
39941
|
+
passphraseState: undefined,
|
|
39942
|
+
newSession: undefined,
|
|
39943
|
+
unlockedAttachPin: false,
|
|
39944
|
+
};
|
|
39945
|
+
}
|
|
39946
|
+
const cachedSessionId = typeof device.getInternalState === 'function' ? device.getInternalState() : undefined;
|
|
39947
|
+
let response;
|
|
39948
|
+
let recoveryFailed = false;
|
|
39949
|
+
if (cachedSessionId && expectedPassphraseState) {
|
|
39296
39950
|
try {
|
|
39297
|
-
|
|
39951
|
+
response = yield openDeviceSession(device, {
|
|
39952
|
+
resume: { session_id: cachedSessionId },
|
|
39953
|
+
});
|
|
39298
39954
|
}
|
|
39299
39955
|
catch (error) {
|
|
39300
|
-
if (!
|
|
39956
|
+
if (!isProtocolV2InvalidSessionError(error)) {
|
|
39301
39957
|
throw error;
|
|
39302
39958
|
}
|
|
39303
39959
|
device.clearInternalState();
|
|
39304
|
-
|
|
39305
|
-
return requestDeviceSession();
|
|
39960
|
+
recoveryFailed = true;
|
|
39306
39961
|
}
|
|
39307
|
-
});
|
|
39308
|
-
let response;
|
|
39309
|
-
try {
|
|
39310
|
-
response = yield requestWalletSession();
|
|
39311
39962
|
}
|
|
39312
|
-
|
|
39313
|
-
|
|
39314
|
-
|
|
39315
|
-
|
|
39316
|
-
|
|
39317
|
-
|
|
39963
|
+
if (!response) {
|
|
39964
|
+
const promptPayload = {
|
|
39965
|
+
source: 'wallet-session-coordinator',
|
|
39966
|
+
reason: recoveryFailed ? 'session-recovery' : 'open-wallet',
|
|
39967
|
+
expectedPassphraseState,
|
|
39968
|
+
existsAttachPinUser: ((_c = device.features) === null || _c === void 0 ? void 0 : _c.attachToPinEnabled) === true,
|
|
39969
|
+
};
|
|
39970
|
+
response = yield openSelectedHiddenWallet(device, promptPayload);
|
|
39318
39971
|
}
|
|
39319
39972
|
const { message } = response;
|
|
39320
|
-
if (
|
|
39321
|
-
options.expectedPassphraseState !== message.btc_test_address) {
|
|
39973
|
+
if (expectedPassphraseState && expectedPassphraseState !== message.btc_test_address) {
|
|
39322
39974
|
device.clearInternalState();
|
|
39323
39975
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
39324
39976
|
}
|
|
39325
39977
|
if (message.btc_test_address && device.getCurrentPassphraseProtection() !== true) {
|
|
39326
39978
|
yield refreshProtocolV2DeviceStatus(device);
|
|
39327
39979
|
}
|
|
39328
|
-
device.updateInternalState(
|
|
39980
|
+
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);
|
|
39329
39981
|
return {
|
|
39330
39982
|
passphraseState: message.btc_test_address,
|
|
39331
39983
|
newSession: message.session_id,
|
|
39332
|
-
unlockedAttachPin: (
|
|
39984
|
+
unlockedAttachPin: (_f = (_e = device.features) === null || _e === void 0 ? void 0 : _e.unlockedAttachPin) !== null && _f !== void 0 ? _f : undefined,
|
|
39333
39985
|
};
|
|
39334
39986
|
}
|
|
39335
39987
|
catch (error) {
|
|
@@ -39350,6 +40002,14 @@ const getSupportProtocolV1MessageSchema = (features) => {
|
|
|
39350
40002
|
};
|
|
39351
40003
|
const currentDeviceVersion = getDeviceFirmwareVersion(features).join('.');
|
|
39352
40004
|
const deviceType = getDeviceType(features);
|
|
40005
|
+
if (features.bootloaderMode === true &&
|
|
40006
|
+
features.firmwarePresent === false &&
|
|
40007
|
+
DeviceModelToTypes.model_mini.includes(deviceType)) {
|
|
40008
|
+
return {
|
|
40009
|
+
messages: DataManager.messages.v1CurrentSchema,
|
|
40010
|
+
protocolV1MessageSchema: 'v1CurrentSchema',
|
|
40011
|
+
};
|
|
40012
|
+
}
|
|
39353
40013
|
const deviceVersionConfigs = PROTOBUF_MESSAGE_CONFIG[deviceType] ||
|
|
39354
40014
|
(DeviceTypeToModels[deviceType] &&
|
|
39355
40015
|
DeviceTypeToModels[deviceType]
|
|
@@ -39392,6 +40052,7 @@ const getPassphraseStateWithRefreshDeviceInfo = (device, options) => __awaiter(v
|
|
|
39392
40052
|
return getProtocolV2WalletSession(device, {
|
|
39393
40053
|
initSession: options === null || options === void 0 ? void 0 : options.initSession,
|
|
39394
40054
|
expectedPassphraseState: options === null || options === void 0 ? void 0 : options.expectPassphraseState,
|
|
40055
|
+
onlyMainPin: options === null || options === void 0 ? void 0 : options.onlyMainPin,
|
|
39395
40056
|
});
|
|
39396
40057
|
}
|
|
39397
40058
|
const { features } = device;
|
|
@@ -39429,6 +40090,7 @@ const getPassphraseState = (device, options) => __awaiter(void 0, void 0, void 0
|
|
|
39429
40090
|
return getProtocolV2WalletSession(device, {
|
|
39430
40091
|
initSession: options === null || options === void 0 ? void 0 : options.initSession,
|
|
39431
40092
|
expectedPassphraseState: options === null || options === void 0 ? void 0 : options.expectPassphraseState,
|
|
40093
|
+
onlyMainPin: options === null || options === void 0 ? void 0 : options.onlyMainPin,
|
|
39432
40094
|
});
|
|
39433
40095
|
}
|
|
39434
40096
|
const supportAttachPinCapability = existCapability(features, hdTransport.Enum_Capability.Capability_AttachToPin);
|
|
@@ -39831,6 +40493,93 @@ const getAutoShutDownOptions = (_deviceType) => {
|
|
|
39831
40493
|
}
|
|
39832
40494
|
};
|
|
39833
40495
|
|
|
40496
|
+
const PRO2_WALLPAPER_WIDTH = 604;
|
|
40497
|
+
const PRO2_WALLPAPER_HEIGHT = 1024;
|
|
40498
|
+
const COLOR_FORMAT_RGB565 = 0x12;
|
|
40499
|
+
const COLOR_FORMAT_RGB565A8 = 0x14;
|
|
40500
|
+
const RED_THRESHOLD = [
|
|
40501
|
+
1, 7, 3, 5, 0, 8, 2, 6, 7, 1, 5, 3, 8, 0, 6, 2, 3, 5, 0, 8, 2, 6, 1, 7, 5, 3, 8,
|
|
40502
|
+
0, 6, 2, 7, 1, 0, 8, 2, 6, 1, 7, 3, 5, 8, 0, 6, 2, 7, 1, 5, 3, 2, 6, 1, 7, 3, 5, 0,
|
|
40503
|
+
8, 6, 2, 7, 1, 5, 3, 8, 0,
|
|
40504
|
+
];
|
|
40505
|
+
const GREEN_THRESHOLD = [
|
|
40506
|
+
1, 3, 2, 2, 3, 1, 2, 2, 2, 2, 0, 4, 2, 2, 4, 0, 3, 1, 2, 2, 1, 3, 2, 2, 2, 2, 4,
|
|
40507
|
+
0, 2, 2, 0, 4, 1, 3, 2, 2, 3, 1, 2, 2, 2, 2, 0, 4, 2, 2, 4, 0, 3, 1, 2, 2, 1, 3, 2,
|
|
40508
|
+
2, 2, 2, 4, 0, 2, 2, 0, 4,
|
|
40509
|
+
];
|
|
40510
|
+
const BLUE_THRESHOLD = [
|
|
40511
|
+
5, 3, 8, 0, 6, 2, 7, 1, 3, 5, 0, 8, 2, 6, 1, 7, 8, 0, 6, 2, 7, 1, 5, 3, 0, 8, 2,
|
|
40512
|
+
6, 1, 7, 3, 5, 6, 2, 7, 1, 5, 3, 8, 0, 2, 6, 1, 7, 3, 5, 0, 8, 7, 1, 5, 3, 8, 0, 6,
|
|
40513
|
+
2, 1, 7, 3, 5, 0, 8, 2, 6,
|
|
40514
|
+
];
|
|
40515
|
+
function invalidParameter$2(message) {
|
|
40516
|
+
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, message);
|
|
40517
|
+
}
|
|
40518
|
+
function asBytes(rgba) {
|
|
40519
|
+
return rgba instanceof Uint8Array ? rgba : new Uint8Array(rgba);
|
|
40520
|
+
}
|
|
40521
|
+
function align(value, boundary) {
|
|
40522
|
+
return Math.ceil(value / boundary) * boundary;
|
|
40523
|
+
}
|
|
40524
|
+
function encodePro2Wallpaper(options) {
|
|
40525
|
+
const { width, height } = options;
|
|
40526
|
+
if (!Number.isInteger(width) || width <= 0 || width > 0xffff) {
|
|
40527
|
+
throw invalidParameter$2('Wallpaper width must be an integer between 1 and 65535.');
|
|
40528
|
+
}
|
|
40529
|
+
if (!Number.isInteger(height) || height <= 0 || height > 0xffff) {
|
|
40530
|
+
throw invalidParameter$2('Wallpaper height must be an integer between 1 and 65535.');
|
|
40531
|
+
}
|
|
40532
|
+
const rgba = asBytes(options.rgba);
|
|
40533
|
+
const expectedLength = width * height * 4;
|
|
40534
|
+
if (rgba.byteLength !== expectedLength) {
|
|
40535
|
+
throw invalidParameter$2(`Wallpaper RGBA data length must be ${expectedLength} bytes, received ${rgba.byteLength}.`);
|
|
40536
|
+
}
|
|
40537
|
+
let hasTransparency = false;
|
|
40538
|
+
for (let index = 3; index < rgba.length; index += 4) {
|
|
40539
|
+
if (rgba[index] !== 0xff) {
|
|
40540
|
+
hasTransparency = true;
|
|
40541
|
+
break;
|
|
40542
|
+
}
|
|
40543
|
+
}
|
|
40544
|
+
const colorFormat = hasTransparency ? 'RGB565A8' : 'RGB565';
|
|
40545
|
+
const stride = align(width * 2, 4);
|
|
40546
|
+
const alphaStride = stride / 2;
|
|
40547
|
+
const rgbSize = stride * height;
|
|
40548
|
+
const alphaSize = hasTransparency ? alphaStride * height : 0;
|
|
40549
|
+
const data = new Uint8Array(12 + rgbSize + alphaSize);
|
|
40550
|
+
const view = new DataView(data.buffer);
|
|
40551
|
+
data[0] = 0x19;
|
|
40552
|
+
data[1] = hasTransparency ? COLOR_FORMAT_RGB565A8 : COLOR_FORMAT_RGB565;
|
|
40553
|
+
view.setUint16(2, 0, true);
|
|
40554
|
+
view.setUint16(4, width, true);
|
|
40555
|
+
view.setUint16(6, height, true);
|
|
40556
|
+
view.setUint16(8, stride, true);
|
|
40557
|
+
view.setUint16(10, 0, true);
|
|
40558
|
+
for (let y = 0; y < height; y += 1) {
|
|
40559
|
+
for (let x = 0; x < width; x += 1) {
|
|
40560
|
+
const sourceOffset = (y * width + x) * 4;
|
|
40561
|
+
const thresholdIndex = ((y & 7) << 3) + (x & 7);
|
|
40562
|
+
let red = Math.min(rgba[sourceOffset] + RED_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
|
|
40563
|
+
let green = Math.min(rgba[sourceOffset + 1] + GREEN_THRESHOLD[thresholdIndex], 0xff) & 0xfc;
|
|
40564
|
+
let blue = Math.min(rgba[sourceOffset + 2] + BLUE_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
|
|
40565
|
+
if (!hasTransparency) {
|
|
40566
|
+
const alpha = rgba[sourceOffset + 3];
|
|
40567
|
+
red = (red * alpha) >> 8;
|
|
40568
|
+
green = (green * alpha) >> 8;
|
|
40569
|
+
blue = (blue * alpha) >> 8;
|
|
40570
|
+
}
|
|
40571
|
+
const rgb565 = ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3);
|
|
40572
|
+
const rgbOffset = 12 + y * stride + x * 2;
|
|
40573
|
+
data[rgbOffset] = rgb565 & 0xff;
|
|
40574
|
+
data[rgbOffset + 1] = rgb565 >> 8;
|
|
40575
|
+
if (hasTransparency) {
|
|
40576
|
+
data[12 + rgbSize + y * alphaStride + x] = rgba[sourceOffset + 3];
|
|
40577
|
+
}
|
|
40578
|
+
}
|
|
40579
|
+
}
|
|
40580
|
+
return { data, colorFormat };
|
|
40581
|
+
}
|
|
40582
|
+
|
|
39834
40583
|
const getT1Data = () => ({
|
|
39835
40584
|
default: {
|
|
39836
40585
|
name: 'default',
|
|
@@ -40114,6 +40863,14 @@ const getHomeScreenDefaultList = (features) => {
|
|
|
40114
40863
|
return Object.keys(data);
|
|
40115
40864
|
};
|
|
40116
40865
|
const getHomeScreenSize = ({ deviceType, homeScreenType, thumbnail, }) => {
|
|
40866
|
+
if (deviceType === hdShared.EDeviceType.Pro2) {
|
|
40867
|
+
return thumbnail
|
|
40868
|
+
? undefined
|
|
40869
|
+
: {
|
|
40870
|
+
width: PRO2_WALLPAPER_WIDTH,
|
|
40871
|
+
height: PRO2_WALLPAPER_HEIGHT,
|
|
40872
|
+
};
|
|
40873
|
+
}
|
|
40117
40874
|
const sizes = {
|
|
40118
40875
|
touch: {
|
|
40119
40876
|
thumbnail: {
|
|
@@ -40136,93 +40893,6 @@ const getHomeScreenSize = ({ deviceType, homeScreenType, thumbnail, }) => {
|
|
|
40136
40893
|
return thumbnail ? deviceConfig.thumbnail[homeScreenType] : deviceConfig.full;
|
|
40137
40894
|
};
|
|
40138
40895
|
|
|
40139
|
-
const PRO2_WALLPAPER_WIDTH = 604;
|
|
40140
|
-
const PRO2_WALLPAPER_HEIGHT = 1024;
|
|
40141
|
-
const COLOR_FORMAT_RGB565 = 0x12;
|
|
40142
|
-
const COLOR_FORMAT_RGB565A8 = 0x14;
|
|
40143
|
-
const RED_THRESHOLD = [
|
|
40144
|
-
1, 7, 3, 5, 0, 8, 2, 6, 7, 1, 5, 3, 8, 0, 6, 2, 3, 5, 0, 8, 2, 6, 1, 7, 5, 3, 8,
|
|
40145
|
-
0, 6, 2, 7, 1, 0, 8, 2, 6, 1, 7, 3, 5, 8, 0, 6, 2, 7, 1, 5, 3, 2, 6, 1, 7, 3, 5, 0,
|
|
40146
|
-
8, 6, 2, 7, 1, 5, 3, 8, 0,
|
|
40147
|
-
];
|
|
40148
|
-
const GREEN_THRESHOLD = [
|
|
40149
|
-
1, 3, 2, 2, 3, 1, 2, 2, 2, 2, 0, 4, 2, 2, 4, 0, 3, 1, 2, 2, 1, 3, 2, 2, 2, 2, 4,
|
|
40150
|
-
0, 2, 2, 0, 4, 1, 3, 2, 2, 3, 1, 2, 2, 2, 2, 0, 4, 2, 2, 4, 0, 3, 1, 2, 2, 1, 3, 2,
|
|
40151
|
-
2, 2, 2, 4, 0, 2, 2, 0, 4,
|
|
40152
|
-
];
|
|
40153
|
-
const BLUE_THRESHOLD = [
|
|
40154
|
-
5, 3, 8, 0, 6, 2, 7, 1, 3, 5, 0, 8, 2, 6, 1, 7, 8, 0, 6, 2, 7, 1, 5, 3, 0, 8, 2,
|
|
40155
|
-
6, 1, 7, 3, 5, 6, 2, 7, 1, 5, 3, 8, 0, 2, 6, 1, 7, 3, 5, 0, 8, 7, 1, 5, 3, 8, 0, 6,
|
|
40156
|
-
2, 1, 7, 3, 5, 0, 8, 2, 6,
|
|
40157
|
-
];
|
|
40158
|
-
function invalidParameter$2(message) {
|
|
40159
|
-
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, message);
|
|
40160
|
-
}
|
|
40161
|
-
function asBytes(rgba) {
|
|
40162
|
-
return rgba instanceof Uint8Array ? rgba : new Uint8Array(rgba);
|
|
40163
|
-
}
|
|
40164
|
-
function align(value, boundary) {
|
|
40165
|
-
return Math.ceil(value / boundary) * boundary;
|
|
40166
|
-
}
|
|
40167
|
-
function encodePro2Wallpaper(options) {
|
|
40168
|
-
const { width, height } = options;
|
|
40169
|
-
if (!Number.isInteger(width) || width <= 0 || width > 0xffff) {
|
|
40170
|
-
throw invalidParameter$2('Wallpaper width must be an integer between 1 and 65535.');
|
|
40171
|
-
}
|
|
40172
|
-
if (!Number.isInteger(height) || height <= 0 || height > 0xffff) {
|
|
40173
|
-
throw invalidParameter$2('Wallpaper height must be an integer between 1 and 65535.');
|
|
40174
|
-
}
|
|
40175
|
-
const rgba = asBytes(options.rgba);
|
|
40176
|
-
const expectedLength = width * height * 4;
|
|
40177
|
-
if (rgba.byteLength !== expectedLength) {
|
|
40178
|
-
throw invalidParameter$2(`Wallpaper RGBA data length must be ${expectedLength} bytes, received ${rgba.byteLength}.`);
|
|
40179
|
-
}
|
|
40180
|
-
let hasTransparency = false;
|
|
40181
|
-
for (let index = 3; index < rgba.length; index += 4) {
|
|
40182
|
-
if (rgba[index] !== 0xff) {
|
|
40183
|
-
hasTransparency = true;
|
|
40184
|
-
break;
|
|
40185
|
-
}
|
|
40186
|
-
}
|
|
40187
|
-
const colorFormat = hasTransparency ? 'RGB565A8' : 'RGB565';
|
|
40188
|
-
const stride = align(width * 2, 4);
|
|
40189
|
-
const alphaStride = stride / 2;
|
|
40190
|
-
const rgbSize = stride * height;
|
|
40191
|
-
const alphaSize = hasTransparency ? alphaStride * height : 0;
|
|
40192
|
-
const data = new Uint8Array(12 + rgbSize + alphaSize);
|
|
40193
|
-
const view = new DataView(data.buffer);
|
|
40194
|
-
data[0] = 0x19;
|
|
40195
|
-
data[1] = hasTransparency ? COLOR_FORMAT_RGB565A8 : COLOR_FORMAT_RGB565;
|
|
40196
|
-
view.setUint16(2, 0, true);
|
|
40197
|
-
view.setUint16(4, width, true);
|
|
40198
|
-
view.setUint16(6, height, true);
|
|
40199
|
-
view.setUint16(8, stride, true);
|
|
40200
|
-
view.setUint16(10, 0, true);
|
|
40201
|
-
for (let y = 0; y < height; y += 1) {
|
|
40202
|
-
for (let x = 0; x < width; x += 1) {
|
|
40203
|
-
const sourceOffset = (y * width + x) * 4;
|
|
40204
|
-
const thresholdIndex = ((y & 7) << 3) + (x & 7);
|
|
40205
|
-
let red = Math.min(rgba[sourceOffset] + RED_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
|
|
40206
|
-
let green = Math.min(rgba[sourceOffset + 1] + GREEN_THRESHOLD[thresholdIndex], 0xff) & 0xfc;
|
|
40207
|
-
let blue = Math.min(rgba[sourceOffset + 2] + BLUE_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
|
|
40208
|
-
if (!hasTransparency) {
|
|
40209
|
-
const alpha = rgba[sourceOffset + 3];
|
|
40210
|
-
red = (red * alpha) >> 8;
|
|
40211
|
-
green = (green * alpha) >> 8;
|
|
40212
|
-
blue = (blue * alpha) >> 8;
|
|
40213
|
-
}
|
|
40214
|
-
const rgb565 = ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3);
|
|
40215
|
-
const rgbOffset = 12 + y * stride + x * 2;
|
|
40216
|
-
data[rgbOffset] = rgb565 & 0xff;
|
|
40217
|
-
data[rgbOffset + 1] = rgb565 >> 8;
|
|
40218
|
-
if (hasTransparency) {
|
|
40219
|
-
data[12 + rgbSize + y * alphaStride + x] = rgba[sourceOffset + 3];
|
|
40220
|
-
}
|
|
40221
|
-
}
|
|
40222
|
-
}
|
|
40223
|
-
return { data, colorFormat };
|
|
40224
|
-
}
|
|
40225
|
-
|
|
40226
40896
|
const isBleConnect = (env) => env === 'react-native' || env === 'lowlevel';
|
|
40227
40897
|
const wait = (ms) => new Promise(resolve => {
|
|
40228
40898
|
setTimeout(resolve, ms);
|
|
@@ -40252,196 +40922,6 @@ const getDefectiveDeviceInfo = (features) => {
|
|
|
40252
40922
|
};
|
|
40253
40923
|
};
|
|
40254
40924
|
|
|
40255
|
-
const CORE_EVENT = 'CORE_EVENT';
|
|
40256
|
-
const parseMessage = (messageData) => {
|
|
40257
|
-
const { data } = messageData;
|
|
40258
|
-
const message = {
|
|
40259
|
-
event: data.event,
|
|
40260
|
-
type: data.type,
|
|
40261
|
-
payload: data.payload,
|
|
40262
|
-
};
|
|
40263
|
-
if (typeof messageData.id === 'number') {
|
|
40264
|
-
message.id = messageData.id;
|
|
40265
|
-
}
|
|
40266
|
-
if (typeof message.success === 'boolean') {
|
|
40267
|
-
message.success = data.success;
|
|
40268
|
-
}
|
|
40269
|
-
return message;
|
|
40270
|
-
};
|
|
40271
|
-
const createErrorMessage = (error) => {
|
|
40272
|
-
let payload = { error: error.message, code: error.code };
|
|
40273
|
-
if (error instanceof hdShared.HardwareError) {
|
|
40274
|
-
payload = { error: error.message, code: error.errorCode };
|
|
40275
|
-
}
|
|
40276
|
-
return {
|
|
40277
|
-
success: false,
|
|
40278
|
-
payload,
|
|
40279
|
-
};
|
|
40280
|
-
};
|
|
40281
|
-
|
|
40282
|
-
const UI_EVENT = 'UI_EVENT';
|
|
40283
|
-
const UI_REQUEST = {
|
|
40284
|
-
REQUEST_PIN: 'ui-request_pin',
|
|
40285
|
-
INVALID_PIN: 'ui-invalid_pin',
|
|
40286
|
-
REQUEST_BUTTON: 'ui-button',
|
|
40287
|
-
REQUEST_PASSPHRASE: 'ui-request_passphrase',
|
|
40288
|
-
REQUEST_PASSPHRASE_ON_DEVICE: 'ui-request_passphrase_on_device',
|
|
40289
|
-
REQUEST_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE: 'ui-request_select_device_in_bootloader_for_web_device',
|
|
40290
|
-
REQUEST_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE: 'ui-request_select_device_for_switch_firmware_web_device',
|
|
40291
|
-
CLOSE_UI_WINDOW: 'ui-close_window',
|
|
40292
|
-
CLOSE_UI_PIN_WINDOW: 'ui-close_pin_window',
|
|
40293
|
-
DEVICE_PROGRESS: 'ui-device_progress',
|
|
40294
|
-
BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
|
|
40295
|
-
BLUETOOTH_UNSUPPORTED: 'ui-bluetooth_unsupported',
|
|
40296
|
-
BLUETOOTH_POWERED_OFF: 'ui-bluetooth_powered_off',
|
|
40297
|
-
BLUETOOTH_CHARACTERISTIC_NOTIFY_CHANGE_FAILURE: 'ui-bluetooth_characteristic_notify_change_failure',
|
|
40298
|
-
LOCATION_PERMISSION: 'ui-location_permission',
|
|
40299
|
-
LOCATION_SERVICE_PERMISSION: 'ui-location_service_permission',
|
|
40300
|
-
FIRMWARE_PROCESSING: 'ui-firmware-processing',
|
|
40301
|
-
FIRMWARE_PROGRESS: 'ui-firmware-progress',
|
|
40302
|
-
FIRMWARE_TIP: 'ui-firmware-tip',
|
|
40303
|
-
PREVIOUS_ADDRESS_RESULT: 'ui-previous_address_result',
|
|
40304
|
-
WEB_DEVICE_PROMPT_ACCESS_PERMISSION: 'ui-web_device_prompt_access_permission',
|
|
40305
|
-
BOOTLOADER: 'ui-device_bootloader_mode',
|
|
40306
|
-
NOT_IN_BOOTLOADER: 'ui-device_not_in_bootloader_mode',
|
|
40307
|
-
REQUIRE_MODE: 'ui-device_require_mode',
|
|
40308
|
-
NOT_INITIALIZE: 'ui-device_not_initialized',
|
|
40309
|
-
SEEDLESS: 'ui-device_seedless',
|
|
40310
|
-
FIRMWARE_OLD: 'ui-device_firmware_old',
|
|
40311
|
-
FIRMWARE_NOT_SUPPORTED: 'ui-device_firmware_unsupported',
|
|
40312
|
-
FIRMWARE_NOT_COMPATIBLE: 'ui-device_firmware_not_compatible',
|
|
40313
|
-
FIRMWARE_NOT_INSTALLED: 'ui-device_firmware_not_installed',
|
|
40314
|
-
NOT_USE_ONEKEY_DEVICE: 'ui-device_please_use_onekey_device',
|
|
40315
|
-
};
|
|
40316
|
-
exports.FirmwareUpdateTipMessage = void 0;
|
|
40317
|
-
(function (FirmwareUpdateTipMessage) {
|
|
40318
|
-
FirmwareUpdateTipMessage["CheckLatestUiResource"] = "CheckLatestUiResource";
|
|
40319
|
-
FirmwareUpdateTipMessage["StartDownloadFirmware"] = "StartDownloadFirmware";
|
|
40320
|
-
FirmwareUpdateTipMessage["FinishDownloadFirmware"] = "FinishDownloadFirmware";
|
|
40321
|
-
FirmwareUpdateTipMessage["DownloadLatestUiResource"] = "DownloadLatestUiResource";
|
|
40322
|
-
FirmwareUpdateTipMessage["DownloadFirmware"] = "DownloadFirmware";
|
|
40323
|
-
FirmwareUpdateTipMessage["DownloadBleFirmware"] = "DownloadBleFirmware";
|
|
40324
|
-
FirmwareUpdateTipMessage["DownloadLatestBootloaderResource"] = "DownloadLatestBootloaderResource";
|
|
40325
|
-
FirmwareUpdateTipMessage["DownloadLatestUiResourceSuccess"] = "DownloadLatestUiResourceSuccess";
|
|
40326
|
-
FirmwareUpdateTipMessage["DownloadFirmwareSuccess"] = "DownloadFirmwareSuccess";
|
|
40327
|
-
FirmwareUpdateTipMessage["DownloadBleFirmwareSuccess"] = "DownloadBleFirmwareSuccess";
|
|
40328
|
-
FirmwareUpdateTipMessage["DownloadLatestBootloaderResourceSuccess"] = "DownloadLatestBootloaderResourceSuccess";
|
|
40329
|
-
FirmwareUpdateTipMessage["AutoRebootToBootloader"] = "AutoRebootToBootloader";
|
|
40330
|
-
FirmwareUpdateTipMessage["GoToBootloaderSuccess"] = "GoToBootloaderSuccess";
|
|
40331
|
-
FirmwareUpdateTipMessage["SelectDeviceInBootloaderForWebDevice"] = "SelectDeviceInBootloaderForWebDevice";
|
|
40332
|
-
FirmwareUpdateTipMessage["SwitchFirmwareReconnectDevice"] = "SwitchFirmwareReconnectDevice";
|
|
40333
|
-
FirmwareUpdateTipMessage["ConfirmOnDevice"] = "ConfirmOnDevice";
|
|
40334
|
-
FirmwareUpdateTipMessage["FirmwareEraseSuccess"] = "FirmwareEraseSuccess";
|
|
40335
|
-
FirmwareUpdateTipMessage["StartTransferData"] = "StartTransferData";
|
|
40336
|
-
FirmwareUpdateTipMessage["InstallingFirmware"] = "InstallingFirmware";
|
|
40337
|
-
FirmwareUpdateTipMessage["UpdateBootloader"] = "UpdateBootloader";
|
|
40338
|
-
FirmwareUpdateTipMessage["UpdateBootloaderSuccess"] = "UpdateBootloaderSuccess";
|
|
40339
|
-
FirmwareUpdateTipMessage["UpdateSysResource"] = "UpdateSysResource";
|
|
40340
|
-
FirmwareUpdateTipMessage["UpdateSysResourceSuccess"] = "UpdateSysResourceSuccess";
|
|
40341
|
-
FirmwareUpdateTipMessage["FirmwareUpdating"] = "FirmwareUpdating";
|
|
40342
|
-
FirmwareUpdateTipMessage["FirmwareUpdateCompleted"] = "FirmwareUpdateCompleted";
|
|
40343
|
-
})(exports.FirmwareUpdateTipMessage || (exports.FirmwareUpdateTipMessage = {}));
|
|
40344
|
-
const createUiMessage = (type, payload) => ({
|
|
40345
|
-
event: UI_EVENT,
|
|
40346
|
-
type,
|
|
40347
|
-
payload,
|
|
40348
|
-
});
|
|
40349
|
-
|
|
40350
|
-
const IFRAME = {
|
|
40351
|
-
INIT: 'iframe-init',
|
|
40352
|
-
INIT_BRIDGE: 'iframe-init-bridge',
|
|
40353
|
-
CALL: 'iframe-call',
|
|
40354
|
-
CANCEL: 'iframe-cancel',
|
|
40355
|
-
CANCEL_OPERATION: 'iframe-cancel-operation',
|
|
40356
|
-
SWITCH_TRANSPORT: 'iframe-switch-transport',
|
|
40357
|
-
CALLBACK: 'iframe-callback',
|
|
40358
|
-
};
|
|
40359
|
-
const createIFrameMessage = (type, payload) => ({
|
|
40360
|
-
event: UI_EVENT,
|
|
40361
|
-
type,
|
|
40362
|
-
payload,
|
|
40363
|
-
});
|
|
40364
|
-
|
|
40365
|
-
const RESPONSE_EVENT = 'RESPONSE_EVENT';
|
|
40366
|
-
const createResponseMessage = (id, success, payload) => ({
|
|
40367
|
-
event: RESPONSE_EVENT,
|
|
40368
|
-
type: RESPONSE_EVENT,
|
|
40369
|
-
id,
|
|
40370
|
-
success,
|
|
40371
|
-
payload: success ? payload : hdShared.serializeError(payload),
|
|
40372
|
-
});
|
|
40373
|
-
|
|
40374
|
-
const UI_RESPONSE = {
|
|
40375
|
-
RECEIVE_PIN: 'ui-receive_pin',
|
|
40376
|
-
RECEIVE_PASSPHRASE: 'ui-receive_passphrase',
|
|
40377
|
-
SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE: 'ui-receive_select-device-in-bootloader-for-web-device',
|
|
40378
|
-
SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE: 'ui-receive_select-device-for-switch-firmware-web-device',
|
|
40379
|
-
};
|
|
40380
|
-
const createUiResponse = (type, payload) => ({
|
|
40381
|
-
event: UI_EVENT,
|
|
40382
|
-
type,
|
|
40383
|
-
payload,
|
|
40384
|
-
});
|
|
40385
|
-
|
|
40386
|
-
const DEVICE_EVENT = 'DEVICE_EVENT';
|
|
40387
|
-
const DEVICE = {
|
|
40388
|
-
CONNECT: 'device-connect',
|
|
40389
|
-
CONNECT_UNACQUIRED: 'device-connect_unacquired',
|
|
40390
|
-
DISCONNECT: 'device-disconnect',
|
|
40391
|
-
CHANGED: 'device-changed',
|
|
40392
|
-
ACQUIRE: 'device-acquire',
|
|
40393
|
-
RELEASE: 'device-release',
|
|
40394
|
-
ACQUIRED: 'device-acquired',
|
|
40395
|
-
RELEASED: 'device-released',
|
|
40396
|
-
USED_ELSEWHERE: 'device-used_elsewhere',
|
|
40397
|
-
UNREADABLE: 'unreadable-device',
|
|
40398
|
-
LOADING: 'device-loading',
|
|
40399
|
-
BUTTON: 'button',
|
|
40400
|
-
PIN: 'pin',
|
|
40401
|
-
PASSPHRASE: 'passphrase',
|
|
40402
|
-
PASSPHRASE_ON_DEVICE: 'passphrase_on_device',
|
|
40403
|
-
WORD: 'word',
|
|
40404
|
-
SUPPORT_FEATURES: 'support_features',
|
|
40405
|
-
SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE: 'select_device_in_bootloader_for_web_device',
|
|
40406
|
-
SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE: 'select_device_for_switch_firmware_web_device',
|
|
40407
|
-
FEATURES: 'features',
|
|
40408
|
-
};
|
|
40409
|
-
const createDeviceMessage = (type, payload) => ({
|
|
40410
|
-
event: DEVICE_EVENT,
|
|
40411
|
-
type,
|
|
40412
|
-
payload,
|
|
40413
|
-
});
|
|
40414
|
-
|
|
40415
|
-
const FIRMWARE_EVENT = 'FIRMWARE_EVENT';
|
|
40416
|
-
const FIRMWARE = {
|
|
40417
|
-
RELEASE_INFO: 'firmware-release-info',
|
|
40418
|
-
BLE_RELEASE_INFO: 'ble-firmware-release-info',
|
|
40419
|
-
};
|
|
40420
|
-
const createFirmwareMessage = (type, payload) => ({
|
|
40421
|
-
event: FIRMWARE_EVENT,
|
|
40422
|
-
type,
|
|
40423
|
-
payload,
|
|
40424
|
-
});
|
|
40425
|
-
|
|
40426
|
-
const LogBlockEvent = new Set([
|
|
40427
|
-
UI_RESPONSE.RECEIVE_PIN,
|
|
40428
|
-
UI_RESPONSE.RECEIVE_PASSPHRASE,
|
|
40429
|
-
]);
|
|
40430
|
-
const LogBlockMethod = new Set(['evmSignTypedData']);
|
|
40431
|
-
function getLogBlockLabel(message) {
|
|
40432
|
-
if (!message || typeof message !== 'object')
|
|
40433
|
-
return undefined;
|
|
40434
|
-
const { type, payload, method } = message;
|
|
40435
|
-
if (type && LogBlockEvent.has(type)) {
|
|
40436
|
-
return type;
|
|
40437
|
-
}
|
|
40438
|
-
const methodName = method !== null && method !== void 0 ? method : payload === null || payload === void 0 ? void 0 : payload.method;
|
|
40439
|
-
if (methodName && LogBlockMethod.has(methodName)) {
|
|
40440
|
-
return methodName;
|
|
40441
|
-
}
|
|
40442
|
-
return undefined;
|
|
40443
|
-
}
|
|
40444
|
-
|
|
40445
40925
|
const Log$g = getLogger(exports.LoggerNames.DevicePool);
|
|
40446
40926
|
const getDiff = (current, descriptors) => {
|
|
40447
40927
|
const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
|
|
@@ -40484,8 +40964,7 @@ class DevicePool extends events.exports {
|
|
|
40484
40964
|
this.connector = connector;
|
|
40485
40965
|
}
|
|
40486
40966
|
static getDevices(descriptorList, connectId, initOptions) {
|
|
40487
|
-
var _a,
|
|
40488
|
-
var _b, e_1, _c, _d;
|
|
40967
|
+
var _a, e_1, _b, _c;
|
|
40489
40968
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40490
40969
|
const devices = {};
|
|
40491
40970
|
const deviceList = [];
|
|
@@ -40497,17 +40976,21 @@ class DevicePool extends events.exports {
|
|
|
40497
40976
|
device.updateDescriptor(exist, true);
|
|
40498
40977
|
devices[connectId] = device;
|
|
40499
40978
|
deviceList.push(device);
|
|
40500
|
-
yield this._checkDevicePool(initOptions);
|
|
40979
|
+
yield this._checkDevicePool(initOptions, connectId);
|
|
40501
40980
|
return { devices, deviceList };
|
|
40502
40981
|
}
|
|
40503
40982
|
Log$g.debug('found device in cache, but path is different: ', connectId);
|
|
40504
40983
|
}
|
|
40505
40984
|
}
|
|
40985
|
+
const matchedDescriptor = connectId
|
|
40986
|
+
? descriptorList.find(descriptor => descriptor.path === connectId)
|
|
40987
|
+
: undefined;
|
|
40988
|
+
const descriptorsToInitialize = matchedDescriptor ? [matchedDescriptor] : descriptorList;
|
|
40506
40989
|
try {
|
|
40507
|
-
for (
|
|
40508
|
-
|
|
40509
|
-
|
|
40510
|
-
const descriptor =
|
|
40990
|
+
for (var _d = true, descriptorsToInitialize_1 = __asyncValues(descriptorsToInitialize), descriptorsToInitialize_1_1; descriptorsToInitialize_1_1 = yield descriptorsToInitialize_1.next(), _a = descriptorsToInitialize_1_1.done, !_a; _d = true) {
|
|
40991
|
+
_c = descriptorsToInitialize_1_1.value;
|
|
40992
|
+
_d = false;
|
|
40993
|
+
const descriptor = _c;
|
|
40511
40994
|
const device = yield this._createDevice(descriptor, initOptions);
|
|
40512
40995
|
const connectId = device.getConnectId();
|
|
40513
40996
|
if (connectId) {
|
|
@@ -40524,11 +41007,11 @@ class DevicePool extends events.exports {
|
|
|
40524
41007
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
40525
41008
|
finally {
|
|
40526
41009
|
try {
|
|
40527
|
-
if (!
|
|
41010
|
+
if (!_d && !_a && (_b = descriptorsToInitialize_1.return)) yield _b.call(descriptorsToInitialize_1);
|
|
40528
41011
|
}
|
|
40529
41012
|
finally { if (e_1) throw e_1.error; }
|
|
40530
41013
|
}
|
|
40531
|
-
yield this._checkDevicePool(initOptions);
|
|
41014
|
+
yield this._checkDevicePool(initOptions, matchedDescriptor ? connectId : undefined);
|
|
40532
41015
|
return { devices, deviceList };
|
|
40533
41016
|
});
|
|
40534
41017
|
}
|
|
@@ -40550,16 +41033,19 @@ class DevicePool extends events.exports {
|
|
|
40550
41033
|
return device;
|
|
40551
41034
|
});
|
|
40552
41035
|
}
|
|
40553
|
-
static _checkDevicePool(initOptions) {
|
|
41036
|
+
static _checkDevicePool(initOptions, connectId) {
|
|
40554
41037
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40555
|
-
yield this._sendConnectMessage(initOptions);
|
|
41038
|
+
yield this._sendConnectMessage(initOptions, connectId);
|
|
40556
41039
|
this._sendDisconnectMessage();
|
|
40557
41040
|
});
|
|
40558
41041
|
}
|
|
40559
|
-
static _sendConnectMessage(initOptions) {
|
|
41042
|
+
static _sendConnectMessage(initOptions, connectId) {
|
|
40560
41043
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40561
41044
|
for (let i = this.connectedPool.length - 1; i >= 0; i--) {
|
|
40562
41045
|
const descriptor = this.connectedPool[i];
|
|
41046
|
+
if (connectId && descriptor.path !== connectId) {
|
|
41047
|
+
continue;
|
|
41048
|
+
}
|
|
40563
41049
|
const device = yield this._createDevice(descriptor, initOptions);
|
|
40564
41050
|
Log$g.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
|
|
40565
41051
|
this.emitter.emit(DEVICE.CONNECT, device);
|
|
@@ -41246,7 +41732,7 @@ class DeviceCommands {
|
|
|
41246
41732
|
}
|
|
41247
41733
|
if (res.type === 'PassphraseRequest') {
|
|
41248
41734
|
const existsAttachPinUser = res.message.exists_attach_pin_user;
|
|
41249
|
-
return this.
|
|
41735
|
+
return this.promptPassphrase({
|
|
41250
41736
|
existsAttachPinUser,
|
|
41251
41737
|
}).then(response => {
|
|
41252
41738
|
const { passphrase, passphraseOnDevice, attachPinOnDevice } = response;
|
|
@@ -41310,22 +41796,31 @@ class DeviceCommands {
|
|
|
41310
41796
|
}
|
|
41311
41797
|
});
|
|
41312
41798
|
}
|
|
41313
|
-
|
|
41799
|
+
promptPassphrase(options, promptOptions = {}) {
|
|
41314
41800
|
return new Promise((resolve, reject) => {
|
|
41315
|
-
const cancelAndReject = (_error) =>
|
|
41316
|
-
|
|
41317
|
-
|
|
41318
|
-
|
|
41319
|
-
|
|
41320
|
-
|
|
41321
|
-
|
|
41322
|
-
|
|
41801
|
+
const cancelAndReject = (_error) => {
|
|
41802
|
+
const rejectWithCancelledError = () => {
|
|
41803
|
+
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled, `${DEVICE.PASSPHRASE} canceled`));
|
|
41804
|
+
};
|
|
41805
|
+
if (promptOptions.cancelDeviceOnReject === false) {
|
|
41806
|
+
rejectWithCancelledError();
|
|
41807
|
+
return Promise.resolve();
|
|
41808
|
+
}
|
|
41809
|
+
return cancelDeviceInPrompt(this.device, false)
|
|
41810
|
+
.then(onCancel => {
|
|
41811
|
+
const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled, `${DEVICE.PASSPHRASE} canceled`);
|
|
41812
|
+
if (onCancel) {
|
|
41813
|
+
const { payload } = onCancel || {};
|
|
41814
|
+
reject(error || new Error(payload === null || payload === void 0 ? void 0 : payload.message));
|
|
41815
|
+
}
|
|
41816
|
+
else {
|
|
41817
|
+
reject(error);
|
|
41818
|
+
}
|
|
41819
|
+
})
|
|
41820
|
+
.catch(error => {
|
|
41323
41821
|
reject(error);
|
|
41324
|
-
}
|
|
41325
|
-
}
|
|
41326
|
-
.catch(error => {
|
|
41327
|
-
reject(error);
|
|
41328
|
-
});
|
|
41822
|
+
});
|
|
41823
|
+
};
|
|
41329
41824
|
if (this.device.listenerCount(DEVICE.PASSPHRASE) > 0) {
|
|
41330
41825
|
this.device.setCancelableAction(cancelAndReject);
|
|
41331
41826
|
this.device.emit(DEVICE.PASSPHRASE, this.device, options, (response, error) => {
|
|
@@ -41425,10 +41920,10 @@ class DeviceWalletSessionStore {
|
|
|
41425
41920
|
}
|
|
41426
41921
|
const deviceWalletSessionStore = new DeviceWalletSessionStore();
|
|
41427
41922
|
|
|
41428
|
-
const isProtocolV2RomloaderDeviceInfo = (deviceInfo) => {
|
|
41923
|
+
const isProtocolV2RomloaderDeviceInfo = (deviceInfo, deviceStatus) => {
|
|
41429
41924
|
var _a, _b, _c;
|
|
41430
41925
|
return !!deviceInfo &&
|
|
41431
|
-
|
|
41926
|
+
deviceStatus == null &&
|
|
41432
41927
|
((_a = deviceInfo.fw) === null || _a === void 0 ? void 0 : _a.romloader) != null &&
|
|
41433
41928
|
((_b = deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.application) == null &&
|
|
41434
41929
|
((_c = deviceInfo.fw) === null || _c === void 0 ? void 0 : _c.application_data) == null &&
|
|
@@ -41438,24 +41933,14 @@ const isProtocolV2RomloaderDeviceInfo = (deviceInfo) => {
|
|
|
41438
41933
|
deviceInfo.se3 == null &&
|
|
41439
41934
|
deviceInfo.se4 == null;
|
|
41440
41935
|
};
|
|
41441
|
-
const isProtocolV2BootloaderDeviceInfo = (deviceInfo) => !!deviceInfo &&
|
|
41936
|
+
const isProtocolV2BootloaderDeviceInfo = (deviceInfo, deviceStatus) => !!deviceInfo &&
|
|
41937
|
+
deviceStatus == null &&
|
|
41938
|
+
!isProtocolV2RomloaderDeviceInfo(deviceInfo, deviceStatus);
|
|
41442
41939
|
const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
|
|
41443
41940
|
targets: {
|
|
41444
41941
|
hw: true,
|
|
41445
41942
|
fw: true,
|
|
41446
41943
|
coprocessor: true,
|
|
41447
|
-
status: true,
|
|
41448
|
-
},
|
|
41449
|
-
types: {
|
|
41450
|
-
version: true,
|
|
41451
|
-
specific: true,
|
|
41452
|
-
},
|
|
41453
|
-
};
|
|
41454
|
-
const PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST = {
|
|
41455
|
-
targets: {
|
|
41456
|
-
hw: true,
|
|
41457
|
-
coprocessor: true,
|
|
41458
|
-
status: true,
|
|
41459
41944
|
},
|
|
41460
41945
|
types: {
|
|
41461
41946
|
version: true,
|
|
@@ -41471,7 +41956,6 @@ const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
|
|
|
41471
41956
|
se2: true,
|
|
41472
41957
|
se3: true,
|
|
41473
41958
|
se4: true,
|
|
41474
|
-
status: true,
|
|
41475
41959
|
},
|
|
41476
41960
|
types: {
|
|
41477
41961
|
version: true,
|
|
@@ -41487,7 +41971,6 @@ const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
|
|
|
41487
41971
|
se2: true,
|
|
41488
41972
|
se3: true,
|
|
41489
41973
|
se4: true,
|
|
41490
|
-
status: true,
|
|
41491
41974
|
},
|
|
41492
41975
|
types: {
|
|
41493
41976
|
version: true,
|
|
@@ -41506,6 +41989,12 @@ function requestProtocolV2DeviceInfo({ commands, timeoutMs = PROTOCOL_V2_DEVICE_
|
|
|
41506
41989
|
return message;
|
|
41507
41990
|
});
|
|
41508
41991
|
}
|
|
41992
|
+
function requestProtocolV2DeviceStatus({ commands, }) {
|
|
41993
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41994
|
+
const { message } = yield commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
|
|
41995
|
+
return message;
|
|
41996
|
+
});
|
|
41997
|
+
}
|
|
41509
41998
|
|
|
41510
41999
|
const isMeaningfulVersion = (version) => Boolean(version && version !== '0.0.0');
|
|
41511
42000
|
const firstMeaningfulVersion$1 = (...versions) => { var _a; return (_a = versions.find(isMeaningfulVersion)) !== null && _a !== void 0 ? _a : null; };
|
|
@@ -41545,13 +42034,12 @@ const getDeviceMode = (features) => {
|
|
|
41545
42034
|
return 'normal';
|
|
41546
42035
|
return 'unknown';
|
|
41547
42036
|
};
|
|
41548
|
-
const getProtocolV2Mode = (deviceInfo) => {
|
|
41549
|
-
|
|
41550
|
-
if (isProtocolV2RomloaderDeviceInfo(deviceInfo))
|
|
42037
|
+
const getProtocolV2Mode = (deviceInfo, deviceStatus) => {
|
|
42038
|
+
if (isProtocolV2RomloaderDeviceInfo(deviceInfo, deviceStatus))
|
|
41551
42039
|
return 'romloader';
|
|
41552
|
-
if (isProtocolV2BootloaderDeviceInfo(deviceInfo))
|
|
42040
|
+
if (isProtocolV2BootloaderDeviceInfo(deviceInfo, deviceStatus))
|
|
41553
42041
|
return 'bootloader';
|
|
41554
|
-
const initialized =
|
|
42042
|
+
const initialized = deviceStatus === null || deviceStatus === void 0 ? void 0 : deviceStatus.init_states;
|
|
41555
42043
|
if (initialized === false)
|
|
41556
42044
|
return 'notInitialized';
|
|
41557
42045
|
if (initialized === true)
|
|
@@ -41606,12 +42094,12 @@ const normalizeV1Status = (features) => {
|
|
|
41606
42094
|
bleEnabled: (_k = features === null || features === void 0 ? void 0 : features.bleEnabled) !== null && _k !== void 0 ? _k : null,
|
|
41607
42095
|
});
|
|
41608
42096
|
};
|
|
41609
|
-
const normalizeV2Status = (deviceInfo) => {
|
|
42097
|
+
const normalizeV2Status = (deviceInfo, deviceStatus) => {
|
|
41610
42098
|
var _a, _b, _c, _d, _e, _f;
|
|
41611
|
-
const status =
|
|
41612
|
-
const bootloaderMode = isProtocolV2BootloaderDeviceInfo(deviceInfo);
|
|
42099
|
+
const status = deviceStatus;
|
|
42100
|
+
const bootloaderMode = isProtocolV2BootloaderDeviceInfo(deviceInfo, deviceStatus);
|
|
41613
42101
|
return {
|
|
41614
|
-
mode: getProtocolV2Mode(deviceInfo),
|
|
42102
|
+
mode: getProtocolV2Mode(deviceInfo, deviceStatus),
|
|
41615
42103
|
initialized: (_a = status === null || status === void 0 ? void 0 : status.init_states) !== null && _a !== void 0 ? _a : null,
|
|
41616
42104
|
bootloaderMode,
|
|
41617
42105
|
unlocked: (_b = status === null || status === void 0 ? void 0 : status.unlocked) !== null && _b !== void 0 ? _b : null,
|
|
@@ -41683,7 +42171,7 @@ const normalizeV2Verify = (deviceInfo) => {
|
|
|
41683
42171
|
se04BootHash: getImageHash$1((_z = info === null || info === void 0 ? void 0 : info.se4) === null || _z === void 0 ? void 0 : _z.bootloader),
|
|
41684
42172
|
};
|
|
41685
42173
|
};
|
|
41686
|
-
const normalizeRaw = ({ features, protocolV1OneKeyFeatures, protocolV2DeviceInfo, }) => (Object.assign(Object.assign(Object.assign({}, (features ? { features } : {})), (protocolV1OneKeyFeatures ? { protocolV1OneKeyFeatures } : {})), (protocolV2DeviceInfo ? { protocolV2DeviceInfo } : {})));
|
|
42174
|
+
const normalizeRaw = ({ features, protocolV1OneKeyFeatures, protocolV2DeviceInfo, protocolV2DeviceStatus, }) => (Object.assign(Object.assign(Object.assign(Object.assign({}, (features ? { features } : {})), (protocolV1OneKeyFeatures ? { protocolV1OneKeyFeatures } : {})), (protocolV2DeviceInfo ? { protocolV2DeviceInfo } : {})), (protocolV2DeviceStatus ? { protocolV2DeviceStatus } : {})));
|
|
41687
42175
|
function buildProfileFromProtocolV1({ protocol = 'V1', features, protocolV1OneKeyFeatures, sources = ['features'], scope = 'basic', includeRaw = false, }) {
|
|
41688
42176
|
const sourceFeatures = features;
|
|
41689
42177
|
const verify = normalizeV1Verify(sourceFeatures, protocolV1OneKeyFeatures);
|
|
@@ -41697,21 +42185,22 @@ function buildProfileFromProtocolV1({ protocol = 'V1', features, protocolV1OneKe
|
|
|
41697
42185
|
}
|
|
41698
42186
|
: {}));
|
|
41699
42187
|
}
|
|
41700
|
-
function buildProfileFromProtocolV2({ deviceInfo, sources = ['deviceInfo'], scope = 'basic', includeRaw = false, }) {
|
|
41701
|
-
var _a, _b, _c
|
|
42188
|
+
function buildProfileFromProtocolV2({ deviceInfo, deviceStatus, sources = ['deviceInfo'], scope = 'basic', includeRaw = false, }) {
|
|
42189
|
+
var _a, _b, _c;
|
|
41702
42190
|
const info = deviceInfo;
|
|
41703
|
-
const deviceId = (
|
|
41704
|
-
const serialNo = ((
|
|
42191
|
+
const deviceId = (deviceStatus === null || deviceStatus === void 0 ? void 0 : deviceStatus.device_id) || '';
|
|
42192
|
+
const serialNo = ((_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.hw) === null || _a === void 0 ? void 0 : _a.serial_no) || '';
|
|
41705
42193
|
const label = null;
|
|
41706
|
-
const bleName = (
|
|
42194
|
+
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;
|
|
41707
42195
|
const verify = normalizeV2Verify(deviceInfo);
|
|
41708
42196
|
return Object.assign(Object.assign({ protocol: 'V2', sources, deviceType: hdShared.EDeviceType.Pro2, firmwareType: hdShared.EFirmwareType.Universal, deviceId,
|
|
41709
42197
|
serialNo,
|
|
41710
42198
|
label,
|
|
41711
|
-
bleName, status: normalizeV2Status(deviceInfo), versions: normalizeV2Versions(deviceInfo) }, (shouldIncludeVerify(scope) ? { verify } : {})), (includeRaw
|
|
42199
|
+
bleName, status: normalizeV2Status(deviceInfo, deviceStatus), versions: normalizeV2Versions(deviceInfo) }, (shouldIncludeVerify(scope) ? { verify } : {})), (includeRaw
|
|
41712
42200
|
? {
|
|
41713
42201
|
raw: normalizeRaw({
|
|
41714
42202
|
protocolV2DeviceInfo: deviceInfo,
|
|
42203
|
+
protocolV2DeviceStatus: deviceStatus,
|
|
41715
42204
|
}),
|
|
41716
42205
|
}
|
|
41717
42206
|
: {}));
|
|
@@ -41846,14 +42335,14 @@ const buildProtocolV1FeaturesPayload = (protocolV1Features, previous) => {
|
|
|
41846
42335
|
protocolV1Features,
|
|
41847
42336
|
} });
|
|
41848
42337
|
};
|
|
41849
|
-
const buildProtocolV2FeaturesPayload = (deviceInfo, previous) => {
|
|
42338
|
+
const buildProtocolV2FeaturesPayload = ({ deviceInfo, deviceStatus, previous, }) => {
|
|
41850
42339
|
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;
|
|
41851
42340
|
const info = deviceInfo;
|
|
41852
42341
|
const fwApplication = (_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application;
|
|
41853
42342
|
const fwBootloader = (_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.bootloader;
|
|
41854
42343
|
const fwBoard = (_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.romloader;
|
|
41855
42344
|
const bleApplication = (_d = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _d === void 0 ? void 0 : _d.application;
|
|
41856
|
-
const status =
|
|
42345
|
+
const status = deviceStatus;
|
|
41857
42346
|
const firmwareVersion = firstMeaningfulVersion(getImageVersion(fwApplication), previous === null || previous === void 0 ? void 0 : previous.firmwareVersion);
|
|
41858
42347
|
const bootloaderVersion = firstMeaningfulVersion(getImageVersion(fwBootloader), previous === null || previous === void 0 ? void 0 : previous.bootloaderVersion);
|
|
41859
42348
|
const boardVersion = firstMeaningfulVersion(getImageVersion(fwBoard), previous === null || previous === void 0 ? void 0 : previous.boardVersion);
|
|
@@ -41863,15 +42352,15 @@ const buildProtocolV2FeaturesPayload = (deviceInfo, previous) => {
|
|
|
41863
42352
|
const label = (_h = previous === null || previous === void 0 ? void 0 : previous.label) !== null && _h !== void 0 ? _h : null;
|
|
41864
42353
|
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);
|
|
41865
42354
|
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;
|
|
41866
|
-
const passphraseProtection = (
|
|
42355
|
+
const passphraseProtection = (status === null || status === void 0 ? void 0 : status.unlocked) === true ? (_l = status.passphrase_enabled) !== null && _l !== void 0 ? _l : null : null;
|
|
41867
42356
|
const language = (_m = previous === null || previous === void 0 ? void 0 : previous.language) !== null && _m !== void 0 ? _m : null;
|
|
41868
42357
|
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;
|
|
41869
42358
|
const bleEnabled = previous === null || previous === void 0 ? void 0 : previous.bleEnabled;
|
|
41870
42359
|
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;
|
|
41871
42360
|
const attachToPinEnabled = (_q = status === null || status === void 0 ? void 0 : status.attach_to_pin_enabled) !== null && _q !== void 0 ? _q : null;
|
|
41872
42361
|
const unlockedAttachPin = (_r = status === null || status === void 0 ? void 0 : status.unlocked_by_attach_to_pin) !== null && _r !== void 0 ? _r : undefined;
|
|
41873
|
-
const romloaderMode = isProtocolV2RomloaderDeviceInfo(info);
|
|
41874
|
-
const bootloaderMode = isProtocolV2BootloaderDeviceInfo(info);
|
|
42362
|
+
const romloaderMode = isProtocolV2RomloaderDeviceInfo(info, status);
|
|
42363
|
+
const bootloaderMode = isProtocolV2BootloaderDeviceInfo(info, status);
|
|
41875
42364
|
let mode = 'unknown';
|
|
41876
42365
|
if (romloaderMode) {
|
|
41877
42366
|
mode = 'romloader';
|
|
@@ -41969,6 +42458,7 @@ const buildProtocolV2FeaturesPayload = (deviceInfo, previous) => {
|
|
|
41969
42458
|
unlockedAttachPin,
|
|
41970
42459
|
raw: {
|
|
41971
42460
|
protocolV2DeviceInfo: deviceInfo,
|
|
42461
|
+
protocolV2DeviceStatus: deviceStatus,
|
|
41972
42462
|
},
|
|
41973
42463
|
};
|
|
41974
42464
|
};
|
|
@@ -42370,7 +42860,6 @@ class Device extends events.exports {
|
|
|
42370
42860
|
if (this.features.bootloaderMode) {
|
|
42371
42861
|
return;
|
|
42372
42862
|
}
|
|
42373
|
-
yield this._refreshProtocolV2Status(options);
|
|
42374
42863
|
return;
|
|
42375
42864
|
}
|
|
42376
42865
|
yield this._initializeProtocolV2(options);
|
|
@@ -42419,7 +42908,13 @@ class Device extends events.exports {
|
|
|
42419
42908
|
commands: this.commands,
|
|
42420
42909
|
timeoutMs: options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs,
|
|
42421
42910
|
});
|
|
42422
|
-
const
|
|
42911
|
+
const deviceStatus = yield requestProtocolV2DeviceStatus({
|
|
42912
|
+
commands: this.commands,
|
|
42913
|
+
}).catch(error => {
|
|
42914
|
+
Log$d.debug('Protocol V2 status unavailable during initialization:', error);
|
|
42915
|
+
return undefined;
|
|
42916
|
+
});
|
|
42917
|
+
const features = this.updateProtocolV2Features(deviceInfo, deviceStatus);
|
|
42423
42918
|
Log$d.debug('Protocol V2 features:', features);
|
|
42424
42919
|
this.featuresNeedsReload = false;
|
|
42425
42920
|
}
|
|
@@ -42429,30 +42924,16 @@ class Device extends events.exports {
|
|
|
42429
42924
|
}
|
|
42430
42925
|
});
|
|
42431
42926
|
}
|
|
42432
|
-
_refreshProtocolV2Status(options) {
|
|
42433
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42434
|
-
try {
|
|
42435
|
-
const deviceInfo = yield requestProtocolV2DeviceInfo({
|
|
42436
|
-
commands: this.commands,
|
|
42437
|
-
request: PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST,
|
|
42438
|
-
timeoutMs: options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs,
|
|
42439
|
-
});
|
|
42440
|
-
const features = this.updateProtocolV2Features(deviceInfo);
|
|
42441
|
-
Log$d.debug('Protocol V2 features (status refresh):', features);
|
|
42442
|
-
}
|
|
42443
|
-
catch (error) {
|
|
42444
|
-
Log$d.error('Protocol V2 status refresh failed:', error);
|
|
42445
|
-
throw error;
|
|
42446
|
-
}
|
|
42447
|
-
});
|
|
42448
|
-
}
|
|
42449
42927
|
getFeatures() {
|
|
42450
42928
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42451
42929
|
if (this.isProtocolV2()) {
|
|
42452
42930
|
const deviceInfo = yield requestProtocolV2DeviceInfo({
|
|
42453
42931
|
commands: this.commands,
|
|
42454
42932
|
});
|
|
42455
|
-
|
|
42933
|
+
const deviceStatus = yield requestProtocolV2DeviceStatus({
|
|
42934
|
+
commands: this.commands,
|
|
42935
|
+
}).catch(() => undefined);
|
|
42936
|
+
return this.updateProtocolV2Features(deviceInfo, deviceStatus);
|
|
42456
42937
|
}
|
|
42457
42938
|
const { message } = yield this.commands.typedCall('GetFeatures', 'Features', {});
|
|
42458
42939
|
this._updateFeatures(message);
|
|
@@ -42481,9 +42962,17 @@ class Device extends events.exports {
|
|
|
42481
42962
|
this.featuresNeedsReload = false;
|
|
42482
42963
|
this.emit(DEVICE.FEATURES, this, feat);
|
|
42483
42964
|
}
|
|
42484
|
-
updateProtocolV2Features(deviceInfo) {
|
|
42965
|
+
updateProtocolV2Features(deviceInfo, deviceStatus) {
|
|
42966
|
+
var _a, _b;
|
|
42485
42967
|
const previousCacheDeviceKey = this.getSessionCacheDeviceKey();
|
|
42486
|
-
const
|
|
42968
|
+
const resolvedDeviceStatus = deviceStatus === undefined
|
|
42969
|
+
? (_b = (_a = this.features) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.protocolV2DeviceStatus
|
|
42970
|
+
: deviceStatus !== null && deviceStatus !== void 0 ? deviceStatus : undefined;
|
|
42971
|
+
const features = fixFeaturesFirmwareVersion(buildProtocolV2FeaturesPayload({
|
|
42972
|
+
deviceInfo,
|
|
42973
|
+
deviceStatus: resolvedDeviceStatus,
|
|
42974
|
+
previous: this.features,
|
|
42975
|
+
}));
|
|
42487
42976
|
this.features = features;
|
|
42488
42977
|
const nextCacheDeviceKey = this.getSessionCacheDeviceKey();
|
|
42489
42978
|
if (previousCacheDeviceKey && nextCacheDeviceKey) {
|
|
@@ -42494,10 +42983,10 @@ class Device extends events.exports {
|
|
|
42494
42983
|
return features;
|
|
42495
42984
|
}
|
|
42496
42985
|
updateProtocolV2Status(status) {
|
|
42497
|
-
var _a, _b, _c, _d
|
|
42986
|
+
var _a, _b, _c, _d;
|
|
42498
42987
|
const previousDeviceInfo = (_b = (_a = this.features) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.protocolV2DeviceInfo;
|
|
42499
|
-
const previousStatus =
|
|
42500
|
-
return this.updateProtocolV2Features(
|
|
42988
|
+
const previousStatus = (_d = (_c = this.features) === null || _c === void 0 ? void 0 : _c.raw) === null || _d === void 0 ? void 0 : _d.protocolV2DeviceStatus;
|
|
42989
|
+
return this.updateProtocolV2Features(previousDeviceInfo, Object.assign(Object.assign({}, previousStatus), status));
|
|
42501
42990
|
}
|
|
42502
42991
|
updateDescriptor(descriptor, forceUpdate = false) {
|
|
42503
42992
|
var _a;
|
|
@@ -42740,7 +43229,9 @@ class Device extends events.exports {
|
|
|
42740
43229
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42741
43230
|
if (this.isProtocolV2()) {
|
|
42742
43231
|
try {
|
|
42743
|
-
yield this.commands.typedCall('DeviceSessionAskPin', 'Success'
|
|
43232
|
+
yield this.commands.typedCall('DeviceSessionAskPin', 'Success', undefined, {
|
|
43233
|
+
timeoutMs: 120000,
|
|
43234
|
+
});
|
|
42744
43235
|
}
|
|
42745
43236
|
catch (error) {
|
|
42746
43237
|
const errorText = error instanceof Error
|
|
@@ -42975,7 +43466,8 @@ class BaseMethod {
|
|
|
42975
43466
|
this.preWarmTtl = 60 * 1000;
|
|
42976
43467
|
this.strictCheckDeviceSupport = false;
|
|
42977
43468
|
this.requireProtocolV2 = false;
|
|
42978
|
-
this.unlockPolicy = '
|
|
43469
|
+
this.unlockPolicy = 'retry-on-locked';
|
|
43470
|
+
this.protocolV2UiMode = 'auto';
|
|
42979
43471
|
this.temporarySafetyCheckPrompted = false;
|
|
42980
43472
|
this.postPreviousAddressMessage = (data) => {
|
|
42981
43473
|
this.postMessage(createUiMessage(UI_REQUEST.PREVIOUS_ADDRESS_RESULT, {
|
|
@@ -43307,13 +43799,17 @@ class GetDeviceInfo extends BaseMethod {
|
|
|
43307
43799
|
commands: this.device.commands,
|
|
43308
43800
|
request: resolveProtocolV2DeviceInfoRequest(this.params),
|
|
43309
43801
|
});
|
|
43802
|
+
const protocolV2DeviceStatus = yield requestProtocolV2DeviceStatus({
|
|
43803
|
+
commands: this.device.commands,
|
|
43804
|
+
}).catch(() => undefined);
|
|
43310
43805
|
const profile = buildProfileFromProtocolV2({
|
|
43311
43806
|
deviceInfo: protocolV2DeviceInfo,
|
|
43807
|
+
deviceStatus: protocolV2DeviceStatus,
|
|
43312
43808
|
sources,
|
|
43313
43809
|
scope: this.params.scope,
|
|
43314
43810
|
includeRaw: this.params.includeRaw,
|
|
43315
43811
|
});
|
|
43316
|
-
this.device.updateProtocolV2Features(protocolV2DeviceInfo);
|
|
43812
|
+
this.device.updateProtocolV2Features(protocolV2DeviceInfo, protocolV2DeviceStatus);
|
|
43317
43813
|
return profile;
|
|
43318
43814
|
});
|
|
43319
43815
|
}
|
|
@@ -43448,8 +43944,10 @@ class GetPassphraseState extends BaseMethod {
|
|
|
43448
43944
|
});
|
|
43449
43945
|
const passphraseProtection = this.device.getCurrentPassphraseProtection();
|
|
43450
43946
|
const deviceType = this.device.getCurrentDeviceType();
|
|
43451
|
-
|
|
43452
|
-
|
|
43947
|
+
if (deviceType === hdShared.EDeviceType.Pro2) {
|
|
43948
|
+
return Promise.resolve(passphraseProtection === true ? passphraseState : undefined);
|
|
43949
|
+
}
|
|
43950
|
+
return Promise.resolve(deviceType === hdShared.EDeviceType.Pro || passphraseProtection === true ? passphraseState : undefined);
|
|
43453
43951
|
});
|
|
43454
43952
|
}
|
|
43455
43953
|
}
|
|
@@ -43951,6 +44449,45 @@ function validateResult(result, nonNullableFields, options) {
|
|
|
43951
44449
|
}
|
|
43952
44450
|
}
|
|
43953
44451
|
|
|
44452
|
+
const invalidParameter = (message) => hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, message);
|
|
44453
|
+
function validateNonEmptyString(value, name) {
|
|
44454
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
44455
|
+
throw invalidParameter(`Parameter [${name}] is required and must be a non-empty string.`);
|
|
44456
|
+
}
|
|
44457
|
+
return value;
|
|
44458
|
+
}
|
|
44459
|
+
function validateNonNegativeInteger(value, name, defaultValue) {
|
|
44460
|
+
if (value === undefined || value === null) {
|
|
44461
|
+
if (defaultValue !== undefined)
|
|
44462
|
+
return defaultValue;
|
|
44463
|
+
throw invalidParameter(`Missing required parameter: ${name}`);
|
|
44464
|
+
}
|
|
44465
|
+
const numeric = typeof value === 'string' && value.trim() !== '' ? Number(value) : value;
|
|
44466
|
+
if (typeof numeric !== 'number' || !Number.isSafeInteger(numeric) || numeric < 0) {
|
|
44467
|
+
throw invalidParameter(`Parameter [${name}] must be a non-negative integer.`);
|
|
44468
|
+
}
|
|
44469
|
+
return numeric;
|
|
44470
|
+
}
|
|
44471
|
+
function validateOptionalNonNegativeInteger(value, name) {
|
|
44472
|
+
if (value === undefined || value === null)
|
|
44473
|
+
return undefined;
|
|
44474
|
+
return validateNonNegativeInteger(value, name);
|
|
44475
|
+
}
|
|
44476
|
+
function validateOptionalPercentage(value, name) {
|
|
44477
|
+
const numeric = validateOptionalNonNegativeInteger(value, name);
|
|
44478
|
+
if (numeric === undefined)
|
|
44479
|
+
return undefined;
|
|
44480
|
+
if (numeric > 100) {
|
|
44481
|
+
throw invalidParameter(`Parameter [${name}] must be between 0 and 100.`);
|
|
44482
|
+
}
|
|
44483
|
+
return numeric;
|
|
44484
|
+
}
|
|
44485
|
+
function validateRequiredData(value, name) {
|
|
44486
|
+
if (value === undefined || value === null) {
|
|
44487
|
+
throw invalidParameter(`Missing required parameter: ${name}`);
|
|
44488
|
+
}
|
|
44489
|
+
}
|
|
44490
|
+
|
|
43954
44491
|
class DeviceChangePin extends BaseMethod {
|
|
43955
44492
|
init() {
|
|
43956
44493
|
this.useDevicePassphraseState = false;
|
|
@@ -43958,9 +44495,26 @@ class DeviceChangePin extends BaseMethod {
|
|
|
43958
44495
|
this.params = {
|
|
43959
44496
|
remove: this.payload.remove,
|
|
43960
44497
|
};
|
|
44498
|
+
this.protocolV2UiInteraction = {
|
|
44499
|
+
request: 'button',
|
|
44500
|
+
source: 'method-lifecycle',
|
|
44501
|
+
reason: 'change-pin',
|
|
44502
|
+
completion: 'operation-completed',
|
|
44503
|
+
deviceOnly: true,
|
|
44504
|
+
page: hdTransport.DeviceSettingsPage.DevicePinChange,
|
|
44505
|
+
};
|
|
43961
44506
|
}
|
|
43962
44507
|
run() {
|
|
43963
44508
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44509
|
+
if (this.device.isProtocolV2()) {
|
|
44510
|
+
if (this.params.remove) {
|
|
44511
|
+
throw invalidParameter('Parameter [remove=true] is not supported by the Pro2 device PIN page.');
|
|
44512
|
+
}
|
|
44513
|
+
const res = yield this.device.commands.typedCall('DeviceSettingsPageShow', 'Success', {
|
|
44514
|
+
page: hdTransport.DeviceSettingsPage.DevicePinChange,
|
|
44515
|
+
});
|
|
44516
|
+
return Promise.resolve(res.message);
|
|
44517
|
+
}
|
|
43964
44518
|
const res = yield this.device.commands.typedCall('ChangePin', 'Success', Object.assign({}, this.params));
|
|
43965
44519
|
return Promise.resolve(res.message);
|
|
43966
44520
|
});
|
|
@@ -44404,9 +44958,24 @@ class DeviceVerify extends BaseMethod {
|
|
|
44404
44958
|
class DeviceWipe extends BaseMethod {
|
|
44405
44959
|
init() {
|
|
44406
44960
|
this.useDevicePassphraseState = false;
|
|
44961
|
+
this.protocolV2UiInteraction = {
|
|
44962
|
+
request: 'button',
|
|
44963
|
+
source: 'method-lifecycle',
|
|
44964
|
+
reason: 'device-management',
|
|
44965
|
+
completion: 'operation-completed',
|
|
44966
|
+
deviceOnly: true,
|
|
44967
|
+
page: hdTransport.DeviceSettingsPage.DeviceReset,
|
|
44968
|
+
operation: 'wipe-device',
|
|
44969
|
+
};
|
|
44407
44970
|
}
|
|
44408
44971
|
run() {
|
|
44409
44972
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44973
|
+
if (this.device.isProtocolV2()) {
|
|
44974
|
+
const res = yield this.device.commands.typedCall('DeviceSettingsPageShow', 'Success', {
|
|
44975
|
+
page: hdTransport.DeviceSettingsPage.DeviceReset,
|
|
44976
|
+
});
|
|
44977
|
+
return Promise.resolve(res.message);
|
|
44978
|
+
}
|
|
44410
44979
|
const res = yield this.device.commands.typedCall('WipeDevice', 'Success');
|
|
44411
44980
|
return Promise.resolve(res.message);
|
|
44412
44981
|
});
|
|
@@ -45347,6 +45916,7 @@ class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod {
|
|
|
45347
45916
|
class DeviceLock extends BaseMethod {
|
|
45348
45917
|
init() {
|
|
45349
45918
|
this.useDevicePassphraseState = false;
|
|
45919
|
+
this.unlockPolicy = 'none';
|
|
45350
45920
|
}
|
|
45351
45921
|
run() {
|
|
45352
45922
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -45358,6 +45928,15 @@ class DeviceLock extends BaseMethod {
|
|
|
45358
45928
|
class DeviceUnlock extends BaseMethod {
|
|
45359
45929
|
init() {
|
|
45360
45930
|
this.useDevicePassphraseState = false;
|
|
45931
|
+
this.unlockPolicy = 'none';
|
|
45932
|
+
this.protocolV2UiInteraction = {
|
|
45933
|
+
request: 'pin',
|
|
45934
|
+
source: 'method-lifecycle',
|
|
45935
|
+
reason: 'device-unlock',
|
|
45936
|
+
completion: 'operation-completed',
|
|
45937
|
+
deviceOnly: true,
|
|
45938
|
+
operation: 'unlock-device',
|
|
45939
|
+
};
|
|
45361
45940
|
}
|
|
45362
45941
|
run() {
|
|
45363
45942
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -45369,6 +45948,7 @@ class DeviceUnlock extends BaseMethod {
|
|
|
45369
45948
|
class DeviceCancel extends BaseMethod {
|
|
45370
45949
|
init() {
|
|
45371
45950
|
this.useDevicePassphraseState = false;
|
|
45951
|
+
this.unlockPolicy = 'none';
|
|
45372
45952
|
}
|
|
45373
45953
|
run() {
|
|
45374
45954
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -46267,45 +46847,6 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
46267
46847
|
}
|
|
46268
46848
|
}
|
|
46269
46849
|
|
|
46270
|
-
const invalidParameter = (message) => hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, message);
|
|
46271
|
-
function validateNonEmptyString(value, name) {
|
|
46272
|
-
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
46273
|
-
throw invalidParameter(`Parameter [${name}] is required and must be a non-empty string.`);
|
|
46274
|
-
}
|
|
46275
|
-
return value;
|
|
46276
|
-
}
|
|
46277
|
-
function validateNonNegativeInteger(value, name, defaultValue) {
|
|
46278
|
-
if (value === undefined || value === null) {
|
|
46279
|
-
if (defaultValue !== undefined)
|
|
46280
|
-
return defaultValue;
|
|
46281
|
-
throw invalidParameter(`Missing required parameter: ${name}`);
|
|
46282
|
-
}
|
|
46283
|
-
const numeric = typeof value === 'string' && value.trim() !== '' ? Number(value) : value;
|
|
46284
|
-
if (typeof numeric !== 'number' || !Number.isSafeInteger(numeric) || numeric < 0) {
|
|
46285
|
-
throw invalidParameter(`Parameter [${name}] must be a non-negative integer.`);
|
|
46286
|
-
}
|
|
46287
|
-
return numeric;
|
|
46288
|
-
}
|
|
46289
|
-
function validateOptionalNonNegativeInteger(value, name) {
|
|
46290
|
-
if (value === undefined || value === null)
|
|
46291
|
-
return undefined;
|
|
46292
|
-
return validateNonNegativeInteger(value, name);
|
|
46293
|
-
}
|
|
46294
|
-
function validateOptionalPercentage(value, name) {
|
|
46295
|
-
const numeric = validateOptionalNonNegativeInteger(value, name);
|
|
46296
|
-
if (numeric === undefined)
|
|
46297
|
-
return undefined;
|
|
46298
|
-
if (numeric > 100) {
|
|
46299
|
-
throw invalidParameter(`Parameter [${name}] must be between 0 and 100.`);
|
|
46300
|
-
}
|
|
46301
|
-
return numeric;
|
|
46302
|
-
}
|
|
46303
|
-
function validateRequiredData(value, name) {
|
|
46304
|
-
if (value === undefined || value === null) {
|
|
46305
|
-
throw invalidParameter(`Missing required parameter: ${name}`);
|
|
46306
|
-
}
|
|
46307
|
-
}
|
|
46308
|
-
|
|
46309
46850
|
const DEVICE_REBOOT_TYPES = {
|
|
46310
46851
|
Normal: hdTransport.DeviceRebootType.Normal,
|
|
46311
46852
|
normal: hdTransport.DeviceRebootType.Normal,
|
|
@@ -46539,15 +47080,6 @@ const isProtocolV2ReconnectProbeError = (error) => {
|
|
|
46539
47080
|
return ((message.includes('device protocol mismatch') && message.includes('expected v2')) ||
|
|
46540
47081
|
message.includes('did not respond to expected protocol'));
|
|
46541
47082
|
};
|
|
46542
|
-
const isProtocolV2PollingTransientError = (error) => {
|
|
46543
|
-
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
46544
|
-
return (isProtocolV2DeviceDisconnectedError(error) ||
|
|
46545
|
-
isProtocolV2ReconnectProbeError(error) ||
|
|
46546
|
-
message.includes('libusb_transfer_timed_out') ||
|
|
46547
|
-
(message.includes('response timeout') && message.includes('devicefirmwareupdatestatusget')) ||
|
|
46548
|
-
message.includes('device not found') ||
|
|
46549
|
-
message.includes('transportnotfound'));
|
|
46550
|
-
};
|
|
46551
47083
|
const isProtocolV2StartUpdateTransientError = (error) => {
|
|
46552
47084
|
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
46553
47085
|
return (isProtocolV2DeviceDisconnectedError(error) ||
|
|
@@ -46656,10 +47188,12 @@ const parseProtocolV2OkppHeader = (bytes) => {
|
|
|
46656
47188
|
headerHash: bytesToHex(bytes.slice(PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET, PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET + PROTOCOL_V2_OKPP_HASH_SIZE)),
|
|
46657
47189
|
};
|
|
46658
47190
|
};
|
|
46659
|
-
const assertProtocolV2ReconnectIdentity = (expectedDeviceId, actualDeviceId) => {
|
|
47191
|
+
const assertProtocolV2ReconnectIdentity = (expectedDeviceId, actualDeviceId, options = {}) => {
|
|
46660
47192
|
if (!expectedDeviceId)
|
|
46661
47193
|
return;
|
|
46662
47194
|
if (!actualDeviceId) {
|
|
47195
|
+
if (options.allowMissingActual)
|
|
47196
|
+
return;
|
|
46663
47197
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, 'Protocol V2 reconnect identity unavailable');
|
|
46664
47198
|
}
|
|
46665
47199
|
if (actualDeviceId !== expectedDeviceId) {
|
|
@@ -47104,8 +47638,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
47104
47638
|
commands: this.device.getCommands(),
|
|
47105
47639
|
timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
|
|
47106
47640
|
});
|
|
47107
|
-
const features = this.device.updateProtocolV2Features(deviceInfo);
|
|
47108
|
-
assertProtocolV2ReconnectIdentity(this.protocolV2ExpectedDeviceId, (_a = features.deviceId) !== null && _a !== void 0 ? _a : undefined);
|
|
47641
|
+
const features = this.device.updateProtocolV2Features(deviceInfo, null);
|
|
47642
|
+
assertProtocolV2ReconnectIdentity(this.protocolV2ExpectedDeviceId, (_a = features.deviceId) !== null && _a !== void 0 ? _a : undefined, { allowMissingActual: !!features.bootloaderMode });
|
|
47109
47643
|
if (features === null || features === void 0 ? void 0 : features.bootloaderMode) {
|
|
47110
47644
|
return features;
|
|
47111
47645
|
}
|
|
@@ -47221,34 +47755,20 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
47221
47755
|
}
|
|
47222
47756
|
});
|
|
47223
47757
|
}
|
|
47224
|
-
queryProtocolV2FirmwareUpdateStatus() {
|
|
47225
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47226
|
-
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
47227
|
-
return typedCall('DeviceFirmwareUpdateStatusGet', 'DeviceFirmwareUpdateStatus', {}, {
|
|
47228
|
-
timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
|
|
47229
|
-
});
|
|
47230
|
-
});
|
|
47231
|
-
}
|
|
47232
|
-
pingProtocolV2Device() {
|
|
47233
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47234
|
-
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
47235
|
-
yield typedCall('Ping', 'Success', { message: 'firmware-update' }, {
|
|
47236
|
-
timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
|
|
47237
|
-
});
|
|
47238
|
-
});
|
|
47239
|
-
}
|
|
47240
47758
|
isProtocolV2NormalModeFeatures(features) {
|
|
47241
47759
|
return !!features && !features.bootloaderMode && features.mode !== 'bootloader';
|
|
47242
47760
|
}
|
|
47243
47761
|
probeProtocolV2NormalMode() {
|
|
47244
47762
|
var _a;
|
|
47245
47763
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47764
|
+
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
47765
|
+
const { message: deviceStatus } = yield typedCall('DeviceStatusGet', 'DeviceStatus', {}, { timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT });
|
|
47246
47766
|
const deviceInfo = yield requestProtocolV2DeviceInfo({
|
|
47247
47767
|
commands: this.device.getCommands(),
|
|
47248
47768
|
timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
|
|
47249
47769
|
request: PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
|
|
47250
47770
|
});
|
|
47251
|
-
const features = this.device.updateProtocolV2Features(deviceInfo);
|
|
47771
|
+
const features = this.device.updateProtocolV2Features(deviceInfo, deviceStatus);
|
|
47252
47772
|
assertProtocolV2ReconnectIdentity(this.protocolV2ExpectedDeviceId, (_a = features.deviceId) !== null && _a !== void 0 ? _a : undefined);
|
|
47253
47773
|
if (this.isProtocolV2NormalModeFeatures(features)) {
|
|
47254
47774
|
Log$5.log('Protocol V2 firmware install finished; device is back in normal mode');
|
|
@@ -47285,51 +47805,29 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
47285
47805
|
return false;
|
|
47286
47806
|
}
|
|
47287
47807
|
waitForProtocolV2FirmwareUpdateComplete(targets, startResponse) {
|
|
47288
|
-
var _a
|
|
47808
|
+
var _a;
|
|
47289
47809
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47290
47810
|
const expectedTargetIds = new Set(targets.map(target => target.target_id));
|
|
47291
47811
|
if ((startResponse === null || startResponse === void 0 ? void 0 : startResponse.type) === 'DeviceFirmwareUpdateStatus') {
|
|
47292
47812
|
const statusTargets = ((_a = startResponse.message.records) !== null && _a !== void 0 ? _a : []);
|
|
47293
|
-
|
|
47294
|
-
return;
|
|
47295
|
-
}
|
|
47813
|
+
this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds);
|
|
47296
47814
|
}
|
|
47297
47815
|
const startTime = Date.now();
|
|
47298
47816
|
let lastError;
|
|
47299
47817
|
while (Date.now() - startTime < PROTOCOL_V2_INSTALL_TIMEOUT) {
|
|
47300
47818
|
try {
|
|
47301
|
-
|
|
47302
|
-
|
|
47303
|
-
if (this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds)) {
|
|
47819
|
+
yield this.reconnectProtocolV2Device();
|
|
47820
|
+
if (yield this.probeProtocolV2NormalMode()) {
|
|
47304
47821
|
return;
|
|
47305
47822
|
}
|
|
47823
|
+
lastError = new Error('Protocol V2 device is reachable but is not in normal mode');
|
|
47306
47824
|
}
|
|
47307
47825
|
catch (error) {
|
|
47308
47826
|
lastError = error;
|
|
47309
47827
|
if (error instanceof hdShared.HardwareError && error.errorCode === hdShared.HardwareErrorCode.FirmwareError) {
|
|
47310
47828
|
throw error;
|
|
47311
47829
|
}
|
|
47312
|
-
Log$5.log('Protocol V2 firmware install
|
|
47313
|
-
if (isProtocolV2PollingTransientError(error)) {
|
|
47314
|
-
try {
|
|
47315
|
-
yield this.reconnectProtocolV2Device();
|
|
47316
|
-
if (yield this.probeProtocolV2NormalMode()) {
|
|
47317
|
-
return;
|
|
47318
|
-
}
|
|
47319
|
-
}
|
|
47320
|
-
catch (reconnectError) {
|
|
47321
|
-
lastError = reconnectError;
|
|
47322
|
-
Log$5.log('Protocol V2 firmware install reconnect/normal-mode probe failed: ', reconnectError);
|
|
47323
|
-
}
|
|
47324
|
-
try {
|
|
47325
|
-
yield this.pingProtocolV2Device();
|
|
47326
|
-
Log$5.log('Protocol V2 firmware status unavailable, Ping is ready');
|
|
47327
|
-
}
|
|
47328
|
-
catch (pingError) {
|
|
47329
|
-
lastError = pingError;
|
|
47330
|
-
Log$5.log('Protocol V2 firmware install Ping polling failed: ', pingError);
|
|
47331
|
-
}
|
|
47332
|
-
}
|
|
47830
|
+
Log$5.log('Protocol V2 firmware install device readiness probe failed: ', error);
|
|
47333
47831
|
}
|
|
47334
47832
|
yield hdShared.wait(1000);
|
|
47335
47833
|
}
|
|
@@ -47412,8 +47910,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
47412
47910
|
yield this.device.acquire(PROTOCOL_V2_CONNECT_PROTOCOL, { throwOnRunPromiseError: true });
|
|
47413
47911
|
this.device.commands.disposed = false;
|
|
47414
47912
|
this.device.getCommands().mainId = (_c = this.device.mainId) !== null && _c !== void 0 ? _c : '';
|
|
47415
|
-
|
|
47416
|
-
assertProtocolV2ReconnectIdentity(this.protocolV2ExpectedDeviceId, this.device.getCurrentDeviceId());
|
|
47913
|
+
assertProtocolV2ReconnectIdentity(this.protocolV2ExpectedDeviceId, this.device.getCurrentDeviceId(), { allowMissingActual: this.isProtocolV2BootloaderMode() });
|
|
47417
47914
|
return;
|
|
47418
47915
|
}
|
|
47419
47916
|
const { deviceList } = yield DevicePool.getDevices(devicesDescriptor, undefined, {
|
|
@@ -47427,8 +47924,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
47427
47924
|
yield this.device.acquire(PROTOCOL_V2_CONNECT_PROTOCOL, { throwOnRunPromiseError: true });
|
|
47428
47925
|
this.device.commands.disposed = false;
|
|
47429
47926
|
this.device.getCommands().mainId = (_d = this.device.mainId) !== null && _d !== void 0 ? _d : '';
|
|
47430
|
-
|
|
47431
|
-
assertProtocolV2ReconnectIdentity(this.protocolV2ExpectedDeviceId, this.device.getCurrentDeviceId());
|
|
47927
|
+
assertProtocolV2ReconnectIdentity(this.protocolV2ExpectedDeviceId, this.device.getCurrentDeviceId(), { allowMissingActual: this.isProtocolV2BootloaderMode() });
|
|
47432
47928
|
});
|
|
47433
47929
|
}
|
|
47434
47930
|
protocolV2CommonUpdateProcess(params) {
|
|
@@ -47721,7 +48217,6 @@ const DEFAULT_TARGETS = {
|
|
|
47721
48217
|
hw: true,
|
|
47722
48218
|
fw: true,
|
|
47723
48219
|
coprocessor: true,
|
|
47724
|
-
status: true,
|
|
47725
48220
|
};
|
|
47726
48221
|
const DEFAULT_TYPES = {
|
|
47727
48222
|
version: true,
|
|
@@ -47800,6 +48295,7 @@ class DeviceStatusGet extends BaseMethod {
|
|
|
47800
48295
|
run() {
|
|
47801
48296
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47802
48297
|
const { message } = yield this.device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
|
|
48298
|
+
this.device.updateProtocolV2Status(message);
|
|
47803
48299
|
return message;
|
|
47804
48300
|
});
|
|
47805
48301
|
}
|
|
@@ -47819,16 +48315,59 @@ class DeviceGetOnboardingStatus extends BaseMethod {
|
|
|
47819
48315
|
}
|
|
47820
48316
|
}
|
|
47821
48317
|
|
|
47822
|
-
|
|
48318
|
+
const isRecord = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
48319
|
+
const normalizeParams = (payload) => {
|
|
48320
|
+
const hasResume = payload.resume !== undefined;
|
|
48321
|
+
const hasSelect = payload.select !== undefined;
|
|
48322
|
+
if (hasResume === hasSelect) {
|
|
48323
|
+
throw invalidParameter('DeviceSessionOpen requires exactly one of [resume] or [select].');
|
|
48324
|
+
}
|
|
48325
|
+
if (hasResume) {
|
|
48326
|
+
if (!isRecord(payload.resume) || typeof payload.resume.session_id !== 'string') {
|
|
48327
|
+
throw invalidParameter('Parameter [resume.session_id] must be a non-empty string.');
|
|
48328
|
+
}
|
|
48329
|
+
const sessionId = payload.resume.session_id.trim();
|
|
48330
|
+
if (!sessionId) {
|
|
48331
|
+
throw invalidParameter('Parameter [resume.session_id] must be a non-empty string.');
|
|
48332
|
+
}
|
|
48333
|
+
return { resume: { session_id: sessionId } };
|
|
48334
|
+
}
|
|
48335
|
+
if (!isRecord(payload.select)) {
|
|
48336
|
+
throw invalidParameter('Parameter [select] must be a hidden-wallet selection object.');
|
|
48337
|
+
}
|
|
48338
|
+
const { select } = payload;
|
|
48339
|
+
const accessKeys = ['host_passphrase', 'passphrase_on_device', 'attach_pin_on_device'];
|
|
48340
|
+
const selected = accessKeys.filter(key => select[key] !== undefined);
|
|
48341
|
+
const unknown = Object.keys(select).filter(key => !accessKeys.includes(key));
|
|
48342
|
+
if (unknown.length > 0 || selected.length !== 1) {
|
|
48343
|
+
throw invalidParameter('Parameter [select] requires exactly one hidden-wallet access mode.');
|
|
48344
|
+
}
|
|
48345
|
+
if (selected[0] === 'host_passphrase') {
|
|
48346
|
+
const host = select.host_passphrase;
|
|
48347
|
+
if (!isRecord(host) || typeof host.passphrase !== 'string') {
|
|
48348
|
+
throw invalidParameter('Parameter [select.host_passphrase.passphrase] is required.');
|
|
48349
|
+
}
|
|
48350
|
+
const passphrase = host.passphrase.normalize('NFKD');
|
|
48351
|
+
if (!passphrase || passphrase.includes('\0') || passphrase.length > 50) {
|
|
48352
|
+
throw invalidParameter('Parameter [select.host_passphrase.passphrase] is invalid.');
|
|
48353
|
+
}
|
|
48354
|
+
return { select: { host_passphrase: { passphrase } } };
|
|
48355
|
+
}
|
|
48356
|
+
if (selected[0] === 'passphrase_on_device') {
|
|
48357
|
+
return { select: { passphrase_on_device: {} } };
|
|
48358
|
+
}
|
|
48359
|
+
return { select: { attach_pin_on_device: {} } };
|
|
48360
|
+
};
|
|
48361
|
+
class DeviceSessionOpen extends BaseMethod {
|
|
47823
48362
|
init() {
|
|
47824
48363
|
this.requireProtocolV2 = true;
|
|
47825
48364
|
this.useDevicePassphraseState = false;
|
|
47826
48365
|
this.skipForceUpdateCheck = true;
|
|
47827
|
-
this.params =
|
|
48366
|
+
this.params = normalizeParams(this.payload);
|
|
47828
48367
|
}
|
|
47829
48368
|
run() {
|
|
47830
48369
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47831
|
-
const { message } = yield this.device.commands.typedCall('
|
|
48370
|
+
const { message } = yield this.device.commands.typedCall('DeviceSessionOpen', 'DeviceSession', this.params);
|
|
47832
48371
|
return message;
|
|
47833
48372
|
});
|
|
47834
48373
|
}
|
|
@@ -47976,7 +48515,7 @@ class DeviceSettingsGet extends BaseMethod {
|
|
|
47976
48515
|
|
|
47977
48516
|
class DeviceSettingsSet extends BaseMethod {
|
|
47978
48517
|
init() {
|
|
47979
|
-
const settings = this.payload
|
|
48518
|
+
const { settings } = this.payload;
|
|
47980
48519
|
if (!settings || typeof settings !== 'object' || Array.isArray(settings)) {
|
|
47981
48520
|
throw invalidParameter('Parameter [settings] must be an object.');
|
|
47982
48521
|
}
|
|
@@ -47989,6 +48528,16 @@ class DeviceSettingsSet extends BaseMethod {
|
|
|
47989
48528
|
this.skipForceUpdateCheck = true;
|
|
47990
48529
|
this.useDevicePassphraseState = false;
|
|
47991
48530
|
this.params = { settings: supported };
|
|
48531
|
+
if (typeof supported.label === 'string') {
|
|
48532
|
+
this.protocolV2UiInteraction = {
|
|
48533
|
+
request: 'button',
|
|
48534
|
+
source: 'method-lifecycle',
|
|
48535
|
+
reason: 'device-management',
|
|
48536
|
+
completion: 'operation-completed',
|
|
48537
|
+
deviceOnly: true,
|
|
48538
|
+
operation: 'change-label',
|
|
48539
|
+
};
|
|
48540
|
+
}
|
|
47992
48541
|
}
|
|
47993
48542
|
run() {
|
|
47994
48543
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -48022,6 +48571,14 @@ class DeviceSettingsPageShow extends BaseMethod {
|
|
|
48022
48571
|
page: normalizePage(this.payload.page),
|
|
48023
48572
|
field_name: (_a = this.payload.field_name) !== null && _a !== void 0 ? _a : this.payload.fieldName,
|
|
48024
48573
|
};
|
|
48574
|
+
this.protocolV2UiInteraction = {
|
|
48575
|
+
request: 'button',
|
|
48576
|
+
source: 'method-lifecycle',
|
|
48577
|
+
reason: 'settings-page',
|
|
48578
|
+
completion: 'operation-completed',
|
|
48579
|
+
deviceOnly: true,
|
|
48580
|
+
page: this.params.page,
|
|
48581
|
+
};
|
|
48025
48582
|
}
|
|
48026
48583
|
run() {
|
|
48027
48584
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -48032,6 +48589,15 @@ class DeviceSettingsPageShow extends BaseMethod {
|
|
|
48032
48589
|
}
|
|
48033
48590
|
|
|
48034
48591
|
const MIN_FILE_CHUNK_SIZE = 64;
|
|
48592
|
+
function isRetryableFileWriteTimeout(error) {
|
|
48593
|
+
var _a, _b;
|
|
48594
|
+
if (!error || typeof error !== 'object')
|
|
48595
|
+
return false;
|
|
48596
|
+
const candidate = error;
|
|
48597
|
+
const code = (_a = candidate.errorCode) !== null && _a !== void 0 ? _a : candidate.code;
|
|
48598
|
+
return (code === hdShared.HardwareErrorCode.BleTimeoutError ||
|
|
48599
|
+
/Lowlevel response timeout/i.test((_b = candidate.message) !== null && _b !== void 0 ? _b : ''));
|
|
48600
|
+
}
|
|
48035
48601
|
function getProtocolV2FileChunkLimit() {
|
|
48036
48602
|
const env = DataManager.getSettings('env');
|
|
48037
48603
|
return env && DataManager.isBleConnect(env)
|
|
@@ -48079,7 +48645,7 @@ function getConfirmedProgress(processed, total, written, length) {
|
|
|
48079
48645
|
return 100;
|
|
48080
48646
|
}
|
|
48081
48647
|
function writeProtocolV2File(options) {
|
|
48082
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
48648
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
48083
48649
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48084
48650
|
(_a = options.throwIfAborted) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
48085
48651
|
const data = yield dataToUint8Array(options.data);
|
|
@@ -48101,15 +48667,30 @@ function writeProtocolV2File(options) {
|
|
|
48101
48667
|
const chunk = data.slice(written, Math.min(written + chunkSize, dataLength));
|
|
48102
48668
|
const offset = startOffset + written;
|
|
48103
48669
|
const progress = (_d = options.uiPercentage) !== null && _d !== void 0 ? _d : getDeviceTransferProgress$1(offset, offset + chunk.byteLength, totalSize);
|
|
48104
|
-
const
|
|
48670
|
+
const request = {
|
|
48105
48671
|
file: { path: options.path, offset, total_size: totalSize, data: chunk },
|
|
48106
48672
|
overwrite: chunks === 0 ? (_e = options.overwrite) !== null && _e !== void 0 ? _e : false : false,
|
|
48107
48673
|
append: (_f = options.append) !== null && _f !== void 0 ? _f : false,
|
|
48108
48674
|
ui_percentage: progress,
|
|
48109
|
-
}
|
|
48110
|
-
(_g = options.
|
|
48675
|
+
};
|
|
48676
|
+
const maxChunkRetries = Math.max(Math.floor((_g = options.maxChunkRetries) !== null && _g !== void 0 ? _g : 0), 0);
|
|
48677
|
+
let retryCount = 0;
|
|
48678
|
+
let response;
|
|
48679
|
+
while (true) {
|
|
48680
|
+
try {
|
|
48681
|
+
response = yield options.commands.typedCall('FilesystemFileWrite', 'FilesystemFile', request, { timeoutMs: options.timeoutMs });
|
|
48682
|
+
break;
|
|
48683
|
+
}
|
|
48684
|
+
catch (error) {
|
|
48685
|
+
if (retryCount >= maxChunkRetries || !isRetryableFileWriteTimeout(error))
|
|
48686
|
+
throw error;
|
|
48687
|
+
retryCount += 1;
|
|
48688
|
+
(_h = options.throwIfAborted) === null || _h === void 0 ? void 0 : _h.call(options);
|
|
48689
|
+
}
|
|
48690
|
+
}
|
|
48691
|
+
(_j = options.throwIfAborted) === null || _j === void 0 ? void 0 : _j.call(options);
|
|
48111
48692
|
lastMessage = response.message;
|
|
48112
|
-
const rawProcessedByte = (
|
|
48693
|
+
const rawProcessedByte = (_k = response.message) === null || _k === void 0 ? void 0 : _k.processed_byte;
|
|
48113
48694
|
const processedByte = Number(rawProcessedByte);
|
|
48114
48695
|
if (rawProcessedByte !== undefined &&
|
|
48115
48696
|
(!Number.isFinite(processedByte) ||
|
|
@@ -48122,7 +48703,7 @@ function writeProtocolV2File(options) {
|
|
|
48122
48703
|
chunks += 1;
|
|
48123
48704
|
const elapsedMs = Date.now() - startTime;
|
|
48124
48705
|
const transferredBytes = Math.min(written, dataLength);
|
|
48125
|
-
(
|
|
48706
|
+
(_l = options.onProgress) === null || _l === void 0 ? void 0 : _l.call(options, {
|
|
48126
48707
|
progress: getConfirmedProgress(startOffset + written, totalSize, written, dataLength),
|
|
48127
48708
|
transferredBytes,
|
|
48128
48709
|
totalBytes: dataLength,
|
|
@@ -48134,7 +48715,7 @@ function writeProtocolV2File(options) {
|
|
|
48134
48715
|
});
|
|
48135
48716
|
}
|
|
48136
48717
|
|
|
48137
|
-
const WALLPAPER_DIRECTORY = '
|
|
48718
|
+
const WALLPAPER_DIRECTORY = 'vol1:/wallpapers';
|
|
48138
48719
|
const SAFE_FILE_NAME = /^[A-Za-z0-9_-]+(?:\.bin)?$/;
|
|
48139
48720
|
function normalizeFileName(fileName, data) {
|
|
48140
48721
|
if (fileName !== undefined && (!fileName || !SAFE_FILE_NAME.test(fileName))) {
|
|
@@ -48202,6 +48783,7 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
48202
48783
|
data: encoded.data,
|
|
48203
48784
|
totalSize: encoded.data.byteLength,
|
|
48204
48785
|
chunkSize: this.params.chunkSize,
|
|
48786
|
+
maxChunkRetries: 3,
|
|
48205
48787
|
overwrite: true,
|
|
48206
48788
|
append: false,
|
|
48207
48789
|
throwIfAborted: () => this.throwIfAborted(),
|
|
@@ -48548,6 +49130,7 @@ class UploadPortfolio extends FileWrite {
|
|
|
48548
49130
|
this.payload = Object.assign(Object.assign({}, this.payload), { path: PORTFOLIO_PENDING_PATH, offset: 0, data: packageBytes, chunkSize: PORTFOLIO_CHUNK_SIZE, overwrite: true, append: false, emitProgress: false, timeoutMs });
|
|
48549
49131
|
super.init();
|
|
48550
49132
|
this.unlockPolicy = 'retry-on-locked';
|
|
49133
|
+
this.protocolV2UiMode = 'none';
|
|
48551
49134
|
}
|
|
48552
49135
|
run() {
|
|
48553
49136
|
const _super = Object.create(null, {
|
|
@@ -55729,6 +56312,9 @@ function getSigOpCountsHash(transaction, sighashType) {
|
|
|
55729
56312
|
function hashTxOut(hashWriter, output) {
|
|
55730
56313
|
hashWriter.writeUInt64LE(output.satoshis);
|
|
55731
56314
|
hashWriter.writeUInt16LE(0);
|
|
56315
|
+
if (output.script === undefined) {
|
|
56316
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Kaspa legacy sighash requires output.script');
|
|
56317
|
+
}
|
|
55732
56318
|
hashWriter.writeVarBytes(Buffer.from(output.script, 'hex'));
|
|
55733
56319
|
}
|
|
55734
56320
|
function getOutputsHash(transaction, inputNumber, sighashType) {
|
|
@@ -55756,6 +56342,9 @@ function serialize(transaction, inputNumber) {
|
|
|
55756
56342
|
const input = transaction.inputs[inputNumber];
|
|
55757
56343
|
hashOutpoint(hashWriter, input);
|
|
55758
56344
|
hashWriter.writeUInt16LE(0);
|
|
56345
|
+
if (input.output.script === undefined) {
|
|
56346
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Kaspa legacy sighash requires input.output.script');
|
|
56347
|
+
}
|
|
55759
56348
|
hashWriter.writeVarBytes(Buffer.from(input.output.script, 'hex'));
|
|
55760
56349
|
hashWriter.writeUInt64LE(input.output.satoshis);
|
|
55761
56350
|
hashWriter.writeUInt64LE(input.sequenceNumber);
|
|
@@ -55772,25 +56361,31 @@ function serialize(transaction, inputNumber) {
|
|
|
55772
56361
|
};
|
|
55773
56362
|
}
|
|
55774
56363
|
|
|
56364
|
+
const P2PK_SCRIPT = /^(20[0-9a-f]{64}ac|21[0-9a-f]{66}ab)$/i;
|
|
56365
|
+
const isStreamableScript = (script) => !script || P2PK_SCRIPT.test(script);
|
|
55775
56366
|
class KaspaSignTransaction extends BaseMethod {
|
|
55776
56367
|
constructor() {
|
|
55777
56368
|
super(...arguments);
|
|
55778
56369
|
this.hasBundle = false;
|
|
56370
|
+
this.supportsLegacy = false;
|
|
56371
|
+
this.supportsStreaming = false;
|
|
55779
56372
|
}
|
|
55780
56373
|
init() {
|
|
55781
|
-
var _a, _b, _c, _d, _e;
|
|
56374
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
55782
56375
|
this.checkDeviceId = true;
|
|
55783
56376
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
55784
56377
|
this.allowUsePreInitialize = true;
|
|
55785
56378
|
const payload = this.payload;
|
|
55786
56379
|
validateParams(payload, [
|
|
55787
56380
|
{ name: 'version', type: 'number' },
|
|
55788
|
-
{ name: 'sigHashType', type: 'number'
|
|
56381
|
+
{ name: 'sigHashType', type: 'number' },
|
|
55789
56382
|
{ name: 'inputs', type: 'array', required: true },
|
|
55790
56383
|
{ name: 'outputs', type: 'array', required: true },
|
|
55791
56384
|
{ name: 'lockTime', required: true },
|
|
55792
56385
|
{ name: 'sigOpCount', type: 'number' },
|
|
55793
56386
|
{ name: 'subNetworkID', type: 'string' },
|
|
56387
|
+
{ name: 'payload', type: 'hexString' },
|
|
56388
|
+
{ name: 'refTxs', type: 'array', allowEmpty: true },
|
|
55794
56389
|
{ name: 'useTweak', type: 'boolean' },
|
|
55795
56390
|
]);
|
|
55796
56391
|
const inputs = payload.inputs.map(input => {
|
|
@@ -55801,20 +56396,47 @@ class KaspaSignTransaction extends BaseMethod {
|
|
|
55801
56396
|
{ name: 'outputIndex', type: 'number', required: true },
|
|
55802
56397
|
{ name: 'sequenceNumber', required: true },
|
|
55803
56398
|
]);
|
|
56399
|
+
validateParams(input.output, [{ name: 'satoshis', required: true }]);
|
|
55804
56400
|
const addressN = validatePath(input.path, 3);
|
|
55805
56401
|
return Object.assign(Object.assign({}, input), { path: addressN, sigOpCount: (_a = input.sigOpCount) !== null && _a !== void 0 ? _a : 1 });
|
|
55806
56402
|
});
|
|
56403
|
+
(_a = payload.refTxs) === null || _a === void 0 ? void 0 : _a.forEach(refTx => {
|
|
56404
|
+
validateParams(refTx, [
|
|
56405
|
+
{ name: 'txId', type: 'string', required: true },
|
|
56406
|
+
{ name: 'version', type: 'number', required: true },
|
|
56407
|
+
{ name: 'inputs', type: 'array', required: true, allowEmpty: true },
|
|
56408
|
+
{ name: 'outputs', type: 'array', required: true, allowEmpty: true },
|
|
56409
|
+
{ name: 'payload', type: 'hexString' },
|
|
56410
|
+
]);
|
|
56411
|
+
});
|
|
55807
56412
|
const outputs = payload.outputs.map(output => {
|
|
55808
56413
|
var _a;
|
|
55809
56414
|
validateParams(output, [
|
|
55810
56415
|
{ name: 'satoshis', required: true },
|
|
55811
|
-
{ name: '
|
|
56416
|
+
{ name: 'address', type: 'string' },
|
|
56417
|
+
{ name: 'script', type: 'string' },
|
|
55812
56418
|
{ name: 'scriptVersion', type: 'number' },
|
|
55813
56419
|
]);
|
|
55814
|
-
return Object.assign(Object.assign({}, output), { scriptVersion: (_a = output.scriptVersion) !== null && _a !== void 0 ? _a : 0 });
|
|
56420
|
+
return Object.assign(Object.assign({}, output), { addressN: output.addressN ? validatePath(output.addressN, 3) : undefined, scriptVersion: (_a = output.scriptVersion) !== null && _a !== void 0 ? _a : 0 });
|
|
55815
56421
|
});
|
|
55816
56422
|
this.params = Object.assign(Object.assign({}, payload), { inputs,
|
|
55817
|
-
outputs, scheme: (
|
|
56423
|
+
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 });
|
|
56424
|
+
this.supportsLegacy =
|
|
56425
|
+
this.params.outputs.every(output => !!output.script) &&
|
|
56426
|
+
this.params.inputs.every(input => !!input.output.script) &&
|
|
56427
|
+
!this.params.payload &&
|
|
56428
|
+
Number((_h = this.params.gas) !== null && _h !== void 0 ? _h : 0) === 0 &&
|
|
56429
|
+
/^0*$/.test((_j = this.params.subNetworkID) !== null && _j !== void 0 ? _j : '');
|
|
56430
|
+
const isDefaultSigHashType = this.params.sigHashType === SignatureType.SIGHASH_ALL ||
|
|
56431
|
+
this.params.sigHashType === (SignatureType.SIGHASH_ALL | SignatureType.SIGHASH_FORKID);
|
|
56432
|
+
this.supportsStreaming =
|
|
56433
|
+
isDefaultSigHashType &&
|
|
56434
|
+
this.params.outputs.every(output => !!output.address || !!output.addressN) &&
|
|
56435
|
+
this.params.inputs.every(input => isStreamableScript(input.output.script)) &&
|
|
56436
|
+
this.params.outputs.every(output => isStreamableScript(output.script));
|
|
56437
|
+
if (!this.supportsLegacy && !this.supportsStreaming) {
|
|
56438
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'KaspaSignTransaction: outputs require either address/addressN (streaming protocol) or script (legacy protocol)');
|
|
56439
|
+
}
|
|
55818
56440
|
}
|
|
55819
56441
|
getVersionRange() {
|
|
55820
56442
|
return {
|
|
@@ -55863,23 +56485,197 @@ class KaspaSignTransaction extends BaseMethod {
|
|
|
55863
56485
|
return signature;
|
|
55864
56486
|
});
|
|
55865
56487
|
}
|
|
56488
|
+
ackPrevRequest(typedCall, request, requestIndex) {
|
|
56489
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
56490
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56491
|
+
const prevTxId = ((_a = request.prev_tx_id) !== null && _a !== void 0 ? _a : '').toLowerCase();
|
|
56492
|
+
const refTx = ((_b = this.params.refTxs) !== null && _b !== void 0 ? _b : []).find(tx => tx.txId.toLowerCase() === prevTxId);
|
|
56493
|
+
if (!refTx) {
|
|
56494
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `KaspaSignTransaction: device requested previous transaction ${prevTxId || '(unknown)'}; provide it via refTxs`);
|
|
56495
|
+
}
|
|
56496
|
+
const requestType = request.request_type;
|
|
56497
|
+
if (requestType === 'KASPA_TX_PREV_META') {
|
|
56498
|
+
return typedCall('KaspaTxAckPrevMeta', 'KaspaTxRequest', {
|
|
56499
|
+
version: refTx.version,
|
|
56500
|
+
input_count: refTx.inputs.length,
|
|
56501
|
+
output_count: refTx.outputs.length,
|
|
56502
|
+
lock_time: ((_c = refTx.lockTime) !== null && _c !== void 0 ? _c : 0),
|
|
56503
|
+
subnetwork_id: (_d = refTx.subNetworkID) !== null && _d !== void 0 ? _d : utils.bytesToHex(zeroSubnetworkID()),
|
|
56504
|
+
gas: ((_e = refTx.gas) !== null && _e !== void 0 ? _e : 0),
|
|
56505
|
+
payload_length: ((_f = refTx.payload) !== null && _f !== void 0 ? _f : '').length / 2,
|
|
56506
|
+
});
|
|
56507
|
+
}
|
|
56508
|
+
if (requestType === 'KASPA_TX_INPUT') {
|
|
56509
|
+
const input = refTx.inputs[requestIndex];
|
|
56510
|
+
if (!input) {
|
|
56511
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested input ${requestIndex} of previous tx out of range`);
|
|
56512
|
+
}
|
|
56513
|
+
return typedCall('KaspaTxAckPrevInput', 'KaspaTxRequest', {
|
|
56514
|
+
previous_outpoint: {
|
|
56515
|
+
tx_id: input.prevTxId,
|
|
56516
|
+
index: input.outputIndex,
|
|
56517
|
+
},
|
|
56518
|
+
sequence: input.sequenceNumber,
|
|
56519
|
+
});
|
|
56520
|
+
}
|
|
56521
|
+
if (requestType === 'KASPA_TX_OUTPUT') {
|
|
56522
|
+
const output = refTx.outputs[requestIndex];
|
|
56523
|
+
if (!output) {
|
|
56524
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested output ${requestIndex} of previous tx out of range`);
|
|
56525
|
+
}
|
|
56526
|
+
return typedCall('KaspaTxAckPrevOutput', 'KaspaTxRequest', {
|
|
56527
|
+
amount: output.satoshis,
|
|
56528
|
+
script_version: (_g = output.scriptVersion) !== null && _g !== void 0 ? _g : 0,
|
|
56529
|
+
script_public_key: output.script,
|
|
56530
|
+
});
|
|
56531
|
+
}
|
|
56532
|
+
if (requestType === 'KASPA_TX_PAYLOAD') {
|
|
56533
|
+
const payloadHex = (_h = refTx.payload) !== null && _h !== void 0 ? _h : '';
|
|
56534
|
+
const payloadLength = payloadHex.length / 2;
|
|
56535
|
+
const length = (_j = request.request_payload_length) !== null && _j !== void 0 ? _j : payloadLength - requestIndex;
|
|
56536
|
+
return typedCall('KaspaTxAckPayloadChunk', 'KaspaTxRequest', {
|
|
56537
|
+
payload_chunk: payloadHex.substring(requestIndex * 2, (requestIndex + length) * 2),
|
|
56538
|
+
});
|
|
56539
|
+
}
|
|
56540
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: unknown previous-tx request type ${requestType !== null && requestType !== void 0 ? requestType : 'undefined'}`);
|
|
56541
|
+
});
|
|
56542
|
+
}
|
|
56543
|
+
signTxStream(typedCall, firstResponse) {
|
|
56544
|
+
var _a, _b, _c, _d, _e;
|
|
56545
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56546
|
+
const { params } = this;
|
|
56547
|
+
const signatures = [];
|
|
56548
|
+
const inputScriptType = params.scheme === 'ecdsa' ? 'KASPA_SPEND_P2PK_ECDSA' : 'KASPA_SPEND_P2PK_SCHNORR';
|
|
56549
|
+
const saveSignature = (signature) => {
|
|
56550
|
+
if (signature && typeof signature.signature_index === 'number' && signature.signature) {
|
|
56551
|
+
signatures[signature.signature_index] = {
|
|
56552
|
+
index: signature.signature_index,
|
|
56553
|
+
signature: signature.signature,
|
|
56554
|
+
};
|
|
56555
|
+
}
|
|
56556
|
+
};
|
|
56557
|
+
const payloadHex = (_a = params.payload) !== null && _a !== void 0 ? _a : '';
|
|
56558
|
+
const payloadLength = payloadHex.length / 2;
|
|
56559
|
+
let response = firstResponse;
|
|
56560
|
+
while (true) {
|
|
56561
|
+
const request = response.message;
|
|
56562
|
+
saveSignature(request.signature);
|
|
56563
|
+
const requestType = request.request_type;
|
|
56564
|
+
if (requestType === 'KASPA_TX_FINISHED') {
|
|
56565
|
+
break;
|
|
56566
|
+
}
|
|
56567
|
+
const requestIndex = (_b = request.request_index) !== null && _b !== void 0 ? _b : 0;
|
|
56568
|
+
if (request.prev_tx_id || requestType === 'KASPA_TX_PREV_META') {
|
|
56569
|
+
response = yield this.ackPrevRequest(typedCall, request, requestIndex);
|
|
56570
|
+
}
|
|
56571
|
+
else if (requestType === 'KASPA_TX_INPUT') {
|
|
56572
|
+
const input = params.inputs[requestIndex];
|
|
56573
|
+
if (!input) {
|
|
56574
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested input ${requestIndex} out of range`);
|
|
56575
|
+
}
|
|
56576
|
+
response = yield typedCall('KaspaTxAckInput', 'KaspaTxRequest', {
|
|
56577
|
+
address_n: input.path,
|
|
56578
|
+
previous_outpoint: {
|
|
56579
|
+
tx_id: input.prevTxId,
|
|
56580
|
+
index: input.outputIndex,
|
|
56581
|
+
},
|
|
56582
|
+
amount: input.output.satoshis,
|
|
56583
|
+
sequence: input.sequenceNumber,
|
|
56584
|
+
sig_op_count: (_c = input.sigOpCount) !== null && _c !== void 0 ? _c : 1,
|
|
56585
|
+
script_type: inputScriptType,
|
|
56586
|
+
use_tweak: params.useTweak,
|
|
56587
|
+
});
|
|
56588
|
+
}
|
|
56589
|
+
else if (requestType === 'KASPA_TX_OUTPUT') {
|
|
56590
|
+
const output = params.outputs[requestIndex];
|
|
56591
|
+
if (!output) {
|
|
56592
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested output ${requestIndex} out of range`);
|
|
56593
|
+
}
|
|
56594
|
+
const isChange = !!output.addressN;
|
|
56595
|
+
response = yield typedCall('KaspaTxAckOutput', 'KaspaTxRequest', {
|
|
56596
|
+
script_type: isChange ? 'KASPA_PAYTOCHANGE' : 'KASPA_PAYTOADDRESS',
|
|
56597
|
+
amount: output.satoshis,
|
|
56598
|
+
address_n: (_d = output.addressN) !== null && _d !== void 0 ? _d : [],
|
|
56599
|
+
address: output.address,
|
|
56600
|
+
scheme: params.scheme,
|
|
56601
|
+
use_tweak: params.useTweak,
|
|
56602
|
+
});
|
|
56603
|
+
}
|
|
56604
|
+
else if (requestType === 'KASPA_TX_PAYLOAD') {
|
|
56605
|
+
const offset = requestIndex;
|
|
56606
|
+
const length = (_e = request.request_payload_length) !== null && _e !== void 0 ? _e : payloadLength - offset;
|
|
56607
|
+
const chunk = payloadHex.substring(offset * 2, (offset + length) * 2);
|
|
56608
|
+
response = yield typedCall('KaspaTxAckPayloadChunk', 'KaspaTxRequest', {
|
|
56609
|
+
payload_chunk: chunk,
|
|
56610
|
+
});
|
|
56611
|
+
}
|
|
56612
|
+
else {
|
|
56613
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: unknown request type ${requestType !== null && requestType !== void 0 ? requestType : 'undefined'}`);
|
|
56614
|
+
}
|
|
56615
|
+
}
|
|
56616
|
+
const collected = signatures.filter(Boolean);
|
|
56617
|
+
if (collected.length !== params.inputs.length) {
|
|
56618
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: expected ${params.inputs.length} signatures, received ${collected.length}`);
|
|
56619
|
+
}
|
|
56620
|
+
return collected;
|
|
56621
|
+
});
|
|
56622
|
+
}
|
|
55866
56623
|
run() {
|
|
56624
|
+
var _a, _b, _c;
|
|
55867
56625
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55868
56626
|
this.checkFeatureVersionLimit(() => this.params.useTweak === false, () => this.getUseTweakVersionRange(), {
|
|
55869
56627
|
strictCheckDeviceSupport: true,
|
|
55870
56628
|
});
|
|
55871
|
-
const { raw: rawMessage } = serialize(this.params, 0);
|
|
55872
|
-
const input = this.params.inputs[0];
|
|
55873
56629
|
const { device, params } = this;
|
|
55874
|
-
const
|
|
55875
|
-
|
|
55876
|
-
|
|
55877
|
-
|
|
55878
|
-
|
|
55879
|
-
|
|
55880
|
-
|
|
55881
|
-
|
|
55882
|
-
|
|
56630
|
+
const payloadHex = (_a = params.payload) !== null && _a !== void 0 ? _a : '';
|
|
56631
|
+
const hasRefTxs = ((_c = (_b = params.refTxs) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0;
|
|
56632
|
+
const streamingReady = this.supportsStreaming && (hasRefTxs || !this.supportsLegacy);
|
|
56633
|
+
const streamingFields = streamingReady
|
|
56634
|
+
? {
|
|
56635
|
+
output_count: params.outputs.length,
|
|
56636
|
+
version: params.version,
|
|
56637
|
+
lock_time: params.lockTime,
|
|
56638
|
+
subnetwork_id: params.subNetworkID,
|
|
56639
|
+
gas: params.gas,
|
|
56640
|
+
payload_length: payloadHex.length / 2,
|
|
56641
|
+
}
|
|
56642
|
+
: {};
|
|
56643
|
+
const legacyFields = this.supportsLegacy
|
|
56644
|
+
? { raw_message: utils.bytesToHex(serialize(params, 0).raw) }
|
|
56645
|
+
: {};
|
|
56646
|
+
let response;
|
|
56647
|
+
try {
|
|
56648
|
+
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));
|
|
56649
|
+
}
|
|
56650
|
+
catch (error) {
|
|
56651
|
+
if (!this.supportsLegacy &&
|
|
56652
|
+
error instanceof hdShared.HardwareError &&
|
|
56653
|
+
error.errorCode === hdShared.HardwareErrorCode.RuntimeError &&
|
|
56654
|
+
String(error.message).includes('Failure_DataError')) {
|
|
56655
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNeedUpgradeFirmware, 'KaspaSignTransaction: this transaction requires firmware with Kaspa streaming support');
|
|
56656
|
+
}
|
|
56657
|
+
throw error;
|
|
56658
|
+
}
|
|
56659
|
+
const typedCall = device.commands.typedCall.bind(device.commands);
|
|
56660
|
+
if (response.type === 'KaspaTxRequest') {
|
|
56661
|
+
if (!this.supportsStreaming) {
|
|
56662
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'KaspaSignTransaction: device firmware uses the streaming protocol; every output requires address or addressN');
|
|
56663
|
+
}
|
|
56664
|
+
try {
|
|
56665
|
+
return yield this.signTxStream(typedCall, response);
|
|
56666
|
+
}
|
|
56667
|
+
catch (error) {
|
|
56668
|
+
if (error instanceof hdShared.HardwareError &&
|
|
56669
|
+
String(error.message).toLowerCase().includes('previous transaction id mismatch')) {
|
|
56670
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.KaspaPrevTxIdMismatch, String(error.message));
|
|
56671
|
+
}
|
|
56672
|
+
throw error;
|
|
56673
|
+
}
|
|
56674
|
+
}
|
|
56675
|
+
if (!this.supportsLegacy) {
|
|
56676
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'KaspaSignTransaction: device chose the legacy protocol but the transaction is not legacy-signable');
|
|
56677
|
+
}
|
|
56678
|
+
return this.processTxRequest(typedCall, response, 0, []);
|
|
55883
56679
|
});
|
|
55884
56680
|
}
|
|
55885
56681
|
}
|
|
@@ -57780,7 +58576,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
57780
58576
|
deviceInfoGet: DeviceInfoGet,
|
|
57781
58577
|
deviceStatusGet: DeviceStatusGet,
|
|
57782
58578
|
deviceGetOnboardingStatus: DeviceGetOnboardingStatus,
|
|
57783
|
-
|
|
58579
|
+
deviceSessionOpen: DeviceSessionOpen,
|
|
57784
58580
|
deviceFirmwareUpdate: DeviceFirmwareUpdate,
|
|
57785
58581
|
deviceGetFirmwareUpdateStatus: DeviceGetFirmwareUpdateStatus,
|
|
57786
58582
|
deviceFactoryInfoSet: DeviceFactoryInfoSet,
|
|
@@ -58174,6 +58970,7 @@ function registerHardwareUiEventListeners(device, handlers) {
|
|
|
58174
58970
|
device.on(DEVICE.BUTTON, handlers.button);
|
|
58175
58971
|
device.on(DEVICE.PASSPHRASE, handlers.passphrase);
|
|
58176
58972
|
device.on(DEVICE.PASSPHRASE_ON_DEVICE, handlers.passphraseOnDevice);
|
|
58973
|
+
device.on(DEVICE.ATTACH_PIN_ON_DEVICE, handlers.attachPinOnDevice);
|
|
58177
58974
|
return true;
|
|
58178
58975
|
}
|
|
58179
58976
|
|
|
@@ -58199,9 +58996,147 @@ const getSynchronize = (mutex) => {
|
|
|
58199
58996
|
return (action, lockId) => lock(lockId).then(unlock => Promise.resolve().then(action).finally(unlock));
|
|
58200
58997
|
};
|
|
58201
58998
|
|
|
58999
|
+
const isProtocolV2UiEnabled = (method) => method.protocolV2UiMode !== 'none';
|
|
59000
|
+
const getDisplayState = (value) => {
|
|
59001
|
+
const visited = new Set();
|
|
59002
|
+
let seen = false;
|
|
59003
|
+
let enabled = false;
|
|
59004
|
+
const visit = (current) => {
|
|
59005
|
+
if (current == null || typeof current !== 'object')
|
|
59006
|
+
return;
|
|
59007
|
+
if (visited.has(current))
|
|
59008
|
+
return;
|
|
59009
|
+
visited.add(current);
|
|
59010
|
+
if (Array.isArray(current)) {
|
|
59011
|
+
current.forEach(visit);
|
|
59012
|
+
return;
|
|
59013
|
+
}
|
|
59014
|
+
Object.entries(current).forEach(([key, item]) => {
|
|
59015
|
+
if ((key === 'show_display' || key === 'showOnOneKey') && typeof item === 'boolean') {
|
|
59016
|
+
seen = true;
|
|
59017
|
+
enabled || (enabled = item);
|
|
59018
|
+
return;
|
|
59019
|
+
}
|
|
59020
|
+
visit(item);
|
|
59021
|
+
});
|
|
59022
|
+
};
|
|
59023
|
+
visit(value);
|
|
59024
|
+
return { seen, enabled };
|
|
59025
|
+
};
|
|
59026
|
+
const createMethodInteraction = (reason, operation) => ({
|
|
59027
|
+
request: 'button',
|
|
59028
|
+
source: 'method-lifecycle',
|
|
59029
|
+
reason,
|
|
59030
|
+
completion: 'operation-completed',
|
|
59031
|
+
deviceOnly: true,
|
|
59032
|
+
operation,
|
|
59033
|
+
});
|
|
59034
|
+
const hasCipherConfirmation = (value) => {
|
|
59035
|
+
if (Array.isArray(value))
|
|
59036
|
+
return value.some(hasCipherConfirmation);
|
|
59037
|
+
if (value == null || typeof value !== 'object')
|
|
59038
|
+
return false;
|
|
59039
|
+
const params = value;
|
|
59040
|
+
return params.encrypt === true ? params.ask_on_encrypt === true : params.ask_on_decrypt === true;
|
|
59041
|
+
};
|
|
59042
|
+
const resolveProtocolV2UiInteraction = (method) => {
|
|
59043
|
+
if (method.protocolV2UiInteraction)
|
|
59044
|
+
return method.protocolV2UiInteraction;
|
|
59045
|
+
const operation = method.name;
|
|
59046
|
+
if (!operation)
|
|
59047
|
+
return undefined;
|
|
59048
|
+
const isAddress = /getAddress(?:ByLoop)?$/i.test(operation);
|
|
59049
|
+
const isPublicKey = /getPublicKey$/i.test(operation);
|
|
59050
|
+
if (isAddress || isPublicKey) {
|
|
59051
|
+
const paramsDisplay = getDisplayState(method.params);
|
|
59052
|
+
const payloadDisplay = getDisplayState(method.payload);
|
|
59053
|
+
const display = paramsDisplay.seen ? paramsDisplay : payloadDisplay;
|
|
59054
|
+
const shouldDisplay = display.seen ? display.enabled : isAddress;
|
|
59055
|
+
if (!shouldDisplay)
|
|
59056
|
+
return undefined;
|
|
59057
|
+
return createMethodInteraction(isAddress ? 'address-confirmation' : 'public-key-confirmation', operation);
|
|
59058
|
+
}
|
|
59059
|
+
if (/sign/i.test(operation) || /verifyMessage$/i.test(operation) || operation === 'lnurlAuth') {
|
|
59060
|
+
return createMethodInteraction('signing-confirmation', operation);
|
|
59061
|
+
}
|
|
59062
|
+
if (operation === 'nostrEncryptMessage' || operation === 'nostrDecryptMessage') {
|
|
59063
|
+
const display = getDisplayState(method.params);
|
|
59064
|
+
if (!display.enabled)
|
|
59065
|
+
return undefined;
|
|
59066
|
+
return createMethodInteraction('signing-confirmation', operation);
|
|
59067
|
+
}
|
|
59068
|
+
if (operation === 'cipherKeyValue' && hasCipherConfirmation(method.params)) {
|
|
59069
|
+
return createMethodInteraction('signing-confirmation', operation);
|
|
59070
|
+
}
|
|
59071
|
+
return undefined;
|
|
59072
|
+
};
|
|
59073
|
+
class ProtocolV2UiInteractionCoordinator {
|
|
59074
|
+
constructor(device, postMessage) {
|
|
59075
|
+
this.opened = false;
|
|
59076
|
+
this.closed = false;
|
|
59077
|
+
this.device = device;
|
|
59078
|
+
this.postMessage = postMessage;
|
|
59079
|
+
}
|
|
59080
|
+
enterMethodInteraction(interaction) {
|
|
59081
|
+
var _a, _b;
|
|
59082
|
+
this.methodInteraction = interaction;
|
|
59083
|
+
if (!interaction)
|
|
59084
|
+
return;
|
|
59085
|
+
const { request } = interaction, metadata = __rest(interaction, ["request"]);
|
|
59086
|
+
this.emit(request === 'pin' ? UI_REQUEST.REQUEST_PIN : UI_REQUEST.REQUEST_BUTTON, Object.assign({ device: this.device.toMessageObject() }, metadata), `method:${request}:${interaction.reason}:${(_a = interaction.page) !== null && _a !== void 0 ? _a : ''}:${(_b = interaction.operation) !== null && _b !== void 0 ? _b : ''}`);
|
|
59087
|
+
}
|
|
59088
|
+
enterUnlockInteraction(method) {
|
|
59089
|
+
this.emit(UI_REQUEST.REQUEST_PIN, {
|
|
59090
|
+
device: this.device.toMessageObject(),
|
|
59091
|
+
source: 'unlock-coordinator',
|
|
59092
|
+
reason: 'device-locked',
|
|
59093
|
+
deviceOnly: true,
|
|
59094
|
+
method,
|
|
59095
|
+
}, `unlock:${method !== null && method !== void 0 ? method : ''}`);
|
|
59096
|
+
}
|
|
59097
|
+
resumeMethodInteraction() {
|
|
59098
|
+
this.enterMethodInteraction(this.methodInteraction);
|
|
59099
|
+
}
|
|
59100
|
+
close() {
|
|
59101
|
+
if (!this.device.isProtocolV2() || !this.opened || this.closed)
|
|
59102
|
+
return;
|
|
59103
|
+
this.closed = true;
|
|
59104
|
+
this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW));
|
|
59105
|
+
}
|
|
59106
|
+
emit(type, payload, phase) {
|
|
59107
|
+
if (!this.device.isProtocolV2() || this.closed || this.currentPhase === phase)
|
|
59108
|
+
return;
|
|
59109
|
+
this.currentPhase = phase;
|
|
59110
|
+
this.opened = true;
|
|
59111
|
+
const message = type === UI_REQUEST.REQUEST_BUTTON
|
|
59112
|
+
? createUiMessage(UI_REQUEST.REQUEST_BUTTON, payload)
|
|
59113
|
+
: createUiMessage(UI_REQUEST.REQUEST_PIN, payload);
|
|
59114
|
+
this.postMessage(message);
|
|
59115
|
+
}
|
|
59116
|
+
}
|
|
59117
|
+
|
|
58202
59118
|
const Log$1 = getLogger(exports.LoggerNames.Core);
|
|
58203
|
-
function runMethodWithUnlockRetry(method, device) {
|
|
59119
|
+
function runMethodWithUnlockRetry(method, device, uiCoordinator) {
|
|
59120
|
+
var _a;
|
|
58204
59121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59122
|
+
const shouldEmitUi = isProtocolV2UiEnabled(method);
|
|
59123
|
+
const shouldUnlockBeforeRun = device.isProtocolV2() &&
|
|
59124
|
+
method.unlockPolicy === 'retry-on-locked' &&
|
|
59125
|
+
((_a = device.features) === null || _a === void 0 ? void 0 : _a.unlocked) === false;
|
|
59126
|
+
if (shouldUnlockBeforeRun) {
|
|
59127
|
+
if (shouldEmitUi) {
|
|
59128
|
+
uiCoordinator === null || uiCoordinator === void 0 ? void 0 : uiCoordinator.enterUnlockInteraction(method.name);
|
|
59129
|
+
}
|
|
59130
|
+
yield device.unlockDevice();
|
|
59131
|
+
Log$1.debug('Protocol V2 pre-unlock completed', { method: method.name });
|
|
59132
|
+
if (shouldEmitUi) {
|
|
59133
|
+
uiCoordinator === null || uiCoordinator === void 0 ? void 0 : uiCoordinator.enterMethodInteraction(resolveProtocolV2UiInteraction(method));
|
|
59134
|
+
}
|
|
59135
|
+
return method.run();
|
|
59136
|
+
}
|
|
59137
|
+
if (shouldEmitUi) {
|
|
59138
|
+
uiCoordinator === null || uiCoordinator === void 0 ? void 0 : uiCoordinator.enterMethodInteraction(resolveProtocolV2UiInteraction(method));
|
|
59139
|
+
}
|
|
58205
59140
|
try {
|
|
58206
59141
|
return yield method.run();
|
|
58207
59142
|
}
|
|
@@ -58212,8 +59147,14 @@ function runMethodWithUnlockRetry(method, device) {
|
|
|
58212
59147
|
throw error;
|
|
58213
59148
|
}
|
|
58214
59149
|
Log$1.debug('Protocol V2 unlock retry triggered', { method: method.name });
|
|
59150
|
+
if (shouldEmitUi) {
|
|
59151
|
+
uiCoordinator === null || uiCoordinator === void 0 ? void 0 : uiCoordinator.enterUnlockInteraction(method.name);
|
|
59152
|
+
}
|
|
58215
59153
|
yield device.unlockDevice();
|
|
58216
59154
|
Log$1.debug('Protocol V2 unlock completed', { method: method.name });
|
|
59155
|
+
if (shouldEmitUi) {
|
|
59156
|
+
uiCoordinator === null || uiCoordinator === void 0 ? void 0 : uiCoordinator.resumeMethodInteraction();
|
|
59157
|
+
}
|
|
58217
59158
|
try {
|
|
58218
59159
|
const response = yield method.run();
|
|
58219
59160
|
Log$1.debug('Protocol V2 method retry completed', { method: method.name, success: true });
|
|
@@ -58460,9 +59401,11 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
58460
59401
|
? onEmptyPassphraseHandler
|
|
58461
59402
|
: onDevicePassphraseHandler,
|
|
58462
59403
|
passphraseOnDevice: onEnterPassphraseOnDeviceHandler,
|
|
59404
|
+
attachPinOnDevice: onEnterAttachPinOnDeviceHandler,
|
|
58463
59405
|
});
|
|
58464
59406
|
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
58465
59407
|
device.on(DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE, onSelectDeviceInBootloaderForWebDeviceHandler);
|
|
59408
|
+
const protocolV2UiCoordinator = new ProtocolV2UiInteractionCoordinator(device, postMessage);
|
|
58466
59409
|
device.on(DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE, onSelectDeviceForSwitchFirmwareWebDeviceHandler);
|
|
58467
59410
|
try {
|
|
58468
59411
|
if (method.connectId) {
|
|
@@ -58582,7 +59525,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
58582
59525
|
}
|
|
58583
59526
|
(_p = (_o = method.device) === null || _o === void 0 ? void 0 : _o.commands) === null || _p === void 0 ? void 0 : _p.checkDisposed();
|
|
58584
59527
|
try {
|
|
58585
|
-
const response = yield runMethodWithUnlockRetry(method, device);
|
|
59528
|
+
const response = yield runMethodWithUnlockRetry(method, device, protocolV2UiCoordinator);
|
|
58586
59529
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
58587
59530
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
58588
59531
|
completeMethodRequestContext(method);
|
|
@@ -58597,6 +59540,9 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
58597
59540
|
throw error;
|
|
58598
59541
|
}
|
|
58599
59542
|
}
|
|
59543
|
+
finally {
|
|
59544
|
+
protocolV2UiCoordinator.close();
|
|
59545
|
+
}
|
|
58600
59546
|
});
|
|
58601
59547
|
Log.debug('Call API - Device Run: ', device.mainId);
|
|
58602
59548
|
const runOptions = Object.assign({ keepSession: method.payload.keepSession, skipInitialize: canSkipInitialize(method, device) }, parseInitOptions(method));
|
|
@@ -58626,7 +59572,9 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
58626
59572
|
}
|
|
58627
59573
|
}
|
|
58628
59574
|
requestQueue.releaseTask(method.responseID);
|
|
58629
|
-
|
|
59575
|
+
if (isProtocolV2UiEnabled(method)) {
|
|
59576
|
+
closePopup();
|
|
59577
|
+
}
|
|
58630
59578
|
cleanup();
|
|
58631
59579
|
if (device) {
|
|
58632
59580
|
const stillActive = getActiveRequestsByDeviceInstance(device.instanceId);
|
|
@@ -59054,6 +60002,9 @@ const onDevicePassphraseHandler = (...[device, requestPayload, callback]) => __a
|
|
|
59054
60002
|
device: device.toMessageObject(),
|
|
59055
60003
|
passphraseState: device.passphraseState,
|
|
59056
60004
|
existsAttachPinUser: requestPayload.existsAttachPinUser,
|
|
60005
|
+
source: requestPayload.source,
|
|
60006
|
+
reason: requestPayload.reason,
|
|
60007
|
+
expectedPassphraseState: requestPayload.expectedPassphraseState,
|
|
59057
60008
|
}));
|
|
59058
60009
|
const uiResp = yield uiPromise.promise;
|
|
59059
60010
|
const { value, passphraseOnDevice, save, attachPinOnDevice } = uiResp.payload;
|
|
@@ -59068,10 +60019,20 @@ const onEmptyPassphraseHandler = (...[_, , callback]) => {
|
|
|
59068
60019
|
Log.debug('onEmptyPassphraseHandler');
|
|
59069
60020
|
callback({ passphrase: '' });
|
|
59070
60021
|
};
|
|
59071
|
-
const onEnterPassphraseOnDeviceHandler = (...[device]) => {
|
|
60022
|
+
const onEnterPassphraseOnDeviceHandler = (...[device, requestPayload]) => {
|
|
59072
60023
|
postMessage(createUiMessage(UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE, {
|
|
59073
60024
|
device: device.toMessageObject(),
|
|
59074
60025
|
passphraseState: device.passphraseState,
|
|
60026
|
+
source: requestPayload === null || requestPayload === void 0 ? void 0 : requestPayload.source,
|
|
60027
|
+
reason: requestPayload === null || requestPayload === void 0 ? void 0 : requestPayload.reason,
|
|
60028
|
+
}));
|
|
60029
|
+
};
|
|
60030
|
+
const onEnterAttachPinOnDeviceHandler = (...[device, requestPayload]) => {
|
|
60031
|
+
postMessage(createUiMessage(UI_REQUEST.REQUEST_PIN, {
|
|
60032
|
+
device: device.toMessageObject(),
|
|
60033
|
+
type: 'ButtonRequest_AttachPin',
|
|
60034
|
+
source: requestPayload === null || requestPayload === void 0 ? void 0 : requestPayload.source,
|
|
60035
|
+
reason: requestPayload === null || requestPayload === void 0 ? void 0 : requestPayload.reason,
|
|
59075
60036
|
}));
|
|
59076
60037
|
};
|
|
59077
60038
|
const onSelectDeviceInBootloaderForWebDeviceHandler = (...[device, callback]) => __awaiter(void 0, void 0, void 0, function* () {
|