@onekeyfe/hd-core 1.2.0-alpha.67 → 1.2.0-alpha.68
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__/AllNetworkGetAddressBase.tracing.test.ts +313 -0
- package/__tests__/DeviceCommands.test.ts +59 -13
- package/__tests__/DeviceEventRegistration.test.ts +6 -0
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +198 -3
- package/__tests__/core-initialization.test.ts +23 -0
- package/__tests__/device-connector-protocol.test.ts +81 -0
- package/__tests__/device-lifecycle-events.test.ts +105 -3
- package/__tests__/device-pool-state.test.ts +22 -0
- package/__tests__/device-settings.test.ts +39 -18
- package/__tests__/device-state-contract.test.ts +1 -0
- package/__tests__/device-state-mapper.test.ts +13 -1
- package/__tests__/device-utils.test.ts +48 -1
- package/__tests__/deviceSettings.test.ts +11 -1
- package/__tests__/deviceUploadNft.test.ts +316 -0
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +5 -0
- package/__tests__/get-device-state.test.ts +132 -12
- package/__tests__/homescreen.test.ts +41 -1
- package/__tests__/kaspa-use-tweak-pro2.test.ts +2 -2
- package/__tests__/kaspaSignTransaction.test.ts +3 -26
- package/__tests__/logBlockEvent.test.ts +1 -1
- package/__tests__/method-protocol-support.test.ts +19 -0
- package/__tests__/open-wallet-session.test.ts +568 -37
- package/__tests__/pro2Nft.test.ts +108 -0
- package/__tests__/protocol-binding.test.ts +89 -0
- package/__tests__/protocol-v2-resources.test.ts +340 -0
- package/__tests__/protocol-v2-ui-lifecycle.test.ts +91 -0
- package/__tests__/protocol-v2-unlock-policy.test.ts +300 -37
- package/__tests__/protocol-v2.test.ts +1449 -867
- package/__tests__/protocolV2FileWrite.test.ts +152 -0
- package/__tests__/protocolV2UiInteraction.test.ts +63 -0
- package/__tests__/public-pro2-api-boundary.test.ts +1 -0
- package/__tests__/search-devices.test.ts +12 -3
- package/__tests__/tron-sign-message-init.test.ts +2 -2
- package/__tests__/uiProgressThrottle.test.ts +74 -0
- package/__tests__/uiPromiseRegistry.test.ts +115 -0
- package/dist/api/BaseMethod.d.ts +3 -1
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts +2 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/DetectDeviceConnectProtocol.d.ts +7 -0
- package/dist/api/DetectDeviceConnectProtocol.d.ts.map +1 -0
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +11 -4
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +2 -2
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +4 -3
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +9 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaGetAddress.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotGetAddress.d.ts +1 -1
- package/dist/api/polkadot/networks.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +31 -0
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -0
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/solana/SolSignMessage.d.ts +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +2 -2
- package/dist/api/sui/SuiGetAddress.d.ts +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +1 -1
- package/dist/api/ton/TonSignMessage.d.ts +1 -1
- package/dist/api/ton/TonSignProof.d.ts +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +2 -2
- package/dist/api/tron/TronSignTransaction.d.ts +1 -1
- package/dist/core/deviceEventRegistration.d.ts +2 -0
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/uiPromiseRegistry.d.ts +6 -0
- package/dist/core/uiPromiseRegistry.d.ts.map +1 -0
- package/dist/data-manager/DataManager.d.ts +9 -3
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +29 -5
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +2 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/deviceProfile/protocolV2DeviceIdentity.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/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-promise.d.ts +4 -2
- package/dist/events/ui-promise.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +31 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/events/ui-response.d.ts +10 -2
- package/dist/events/ui-response.d.ts.map +1 -1
- package/dist/index.d.ts +243 -69
- package/dist/index.js +2563 -1217
- package/dist/inject.d.ts +6 -1
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +0 -4
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/resources.d.ts +30 -0
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +7 -4
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +1 -3
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +22 -0
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +6 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +3 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/detectDeviceConnectProtocol.d.ts +4 -0
- package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +1 -0
- package/dist/types/api/deviceUnlock.d.ts +5 -1
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +1 -0
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +4 -2
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +6 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -0
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +2 -2
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +1 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +38 -8
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +4 -0
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/homescreen.d.ts +4 -0
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2Nft.d.ts +31 -0
- package/dist/utils/pro2Nft.d.ts.map +1 -0
- package/dist/utils/pro2Wallpaper.d.ts +10 -0
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
- package/dist/utils/uiProgressThrottle.d.ts +3 -0
- package/dist/utils/uiProgressThrottle.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +8 -10
- package/src/api/CheckAllFirmwareRelease.ts +61 -11
- package/src/api/DetectDeviceConnectProtocol.ts +18 -0
- package/src/api/FirmwareUpdate.ts +6 -2
- package/src/api/FirmwareUpdateV2.ts +5 -2
- package/src/api/FirmwareUpdateV3.ts +6 -2
- package/src/api/FirmwareUpdateV4.ts +463 -258
- package/src/api/GetPassphraseState.ts +7 -1
- package/src/api/OpenWalletSession.ts +71 -17
- package/src/api/SearchDevices.ts +3 -1
- package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +36 -11
- package/src/api/device/DeviceSettings.ts +5 -4
- package/src/api/device/DeviceUnlock.ts +8 -3
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -12
- package/src/api/firmware/uploadFirmware.ts +17 -4
- package/src/api/helpers/protocolV2FileWrite.ts +202 -63
- package/src/api/index.ts +2 -0
- package/src/api/kaspa/KaspaGetAddress.ts +1 -1
- package/src/api/kaspa/KaspaSignTransaction.ts +2 -13
- package/src/api/polkadot/networks.ts +3 -3
- package/src/api/protocol-v2/DeviceUploadNft.ts +197 -0
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +3 -1
- package/src/api/protocol-v2/helpers.ts +1 -1
- package/src/api/solana/SolSignMessage.ts +1 -1
- package/src/api/solana/SolSignOffchainMessage.ts +1 -1
- package/src/api/solana/SolSignTransaction.ts +2 -2
- package/src/api/sui/SuiGetAddress.ts +1 -1
- package/src/api/sui/SuiGetPublicKey.ts +1 -1
- package/src/api/sui/SuiSignMessage.ts +1 -1
- package/src/api/sui/SuiSignTransaction.ts +1 -1
- package/src/api/ton/TonGetAddress.ts +1 -1
- package/src/api/ton/TonSignMessage.ts +1 -1
- package/src/api/ton/TonSignProof.ts +1 -1
- package/src/api/tron/TronSignMessage.ts +2 -2
- package/src/api/tron/TronSignTransaction.ts +1 -1
- package/src/core/deviceEventRegistration.ts +4 -0
- package/src/core/index.ts +213 -111
- package/src/core/uiPromiseRegistry.ts +63 -0
- package/src/data/messages/messages-protocol-v2.json +25 -0
- package/src/data-manager/DataManager.ts +88 -11
- package/src/data-manager/TransportManager.ts +6 -0
- package/src/device/Device.ts +273 -43
- package/src/device/DeviceCommands.ts +31 -4
- package/src/device/DeviceConnector.ts +33 -13
- package/src/device/DevicePool.ts +21 -7
- package/src/deviceProfile/buildDeviceFeatures.ts +2 -2
- package/src/deviceProfile/protocolV2DeviceIdentity.ts +3 -0
- package/src/events/device.ts +4 -0
- package/src/events/logBlockEvent.ts +1 -0
- package/src/events/ui-promise.ts +4 -2
- package/src/events/ui-request.ts +36 -2
- package/src/events/ui-response.ts +12 -2
- package/src/inject.ts +58 -2
- package/src/lowLevelInject.ts +6 -3
- package/src/protocols/protocol-v2/features.ts +10 -7
- package/src/protocols/protocol-v2/firmware.ts +2 -0
- package/src/protocols/protocol-v2/resources.ts +390 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +46 -6
- package/src/protocols/protocol-v2/unlockPolicy.ts +1 -105
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +131 -0
- package/src/protocols/protocol-v2/walletSession.ts +214 -36
- package/src/topLevelInject.ts +6 -3
- package/src/types/api/checkAllFirmwareRelease.ts +3 -1
- package/src/types/api/detectDeviceConnectProtocol.ts +6 -0
- package/src/types/api/deviceUnlock.ts +12 -1
- package/src/types/api/export.ts +1 -0
- package/src/types/api/firmwareUpdate.ts +6 -3
- package/src/types/api/index.ts +13 -0
- package/src/types/api/protocolV2.ts +13 -0
- package/src/types/device.ts +15 -3
- package/src/types/params.ts +7 -1
- package/src/types/settings.ts +60 -9
- package/src/utils/deviceFeaturesCompat.ts +5 -0
- package/src/utils/deviceFeaturesUtils.ts +14 -3
- package/src/utils/deviceInfoUtils.ts +2 -0
- package/src/utils/deviceSettings.ts +3 -0
- package/src/utils/homescreen.ts +32 -6
- package/src/utils/index.ts +6 -1
- package/src/utils/pro2Nft.ts +142 -0
- package/src/utils/pro2Wallpaper.ts +35 -8
- package/src/utils/uiProgressThrottle.ts +63 -0
- package/dist/api/firmware/progressThrottle.d.ts +0 -3
- package/dist/api/firmware/progressThrottle.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +0 -2
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +0 -10
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +0 -1
- package/src/api/firmware/progressThrottle.ts +0 -44
- package/src/protocols/protocol-v2/lockedError.ts +0 -10
- package/src/protocols/protocol-v2/unlockRetry.ts +0 -109
|
@@ -1,45 +1,308 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
|
+
|
|
3
|
+
import ConfluxSignMessageCIP23 from '../src/api/conflux/ConfluxSignMessageCIP23';
|
|
4
|
+
import DeviceLock from '../src/api/device/DeviceLock';
|
|
5
|
+
import OpenWalletSession from '../src/api/OpenWalletSession';
|
|
6
|
+
import { runMethodWithUnlockPolicy } from '../src/protocols/protocol-v2/unlockPolicyRunner';
|
|
6
7
|
|
|
7
8
|
jest.mock('../src/data/config', () => ({
|
|
8
9
|
DEFAULT_DOMAIN: 'https://example.com/',
|
|
9
10
|
getSDKVersion: () => '0.0.0-test',
|
|
10
11
|
}));
|
|
11
12
|
|
|
12
|
-
describe('Protocol V2
|
|
13
|
-
test('
|
|
14
|
-
const
|
|
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
|
-
|
|
13
|
+
describe('Protocol V2 unlock semantics', () => {
|
|
14
|
+
test('wallet business methods inherit the wallet-session unlock requirement', () => {
|
|
15
|
+
const method = new ConfluxSignMessageCIP23({
|
|
16
|
+
id: 1,
|
|
17
|
+
payload: { method: 'confluxSignMessageCIP23' },
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
expect(method.useDevicePassphraseState).toBe(true);
|
|
21
|
+
expect(method.unlockPolicy).toBe('none');
|
|
22
|
+
expect(method.getSupportedProtocols()).toContain('V2');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('lock-free Protocol V2 controls explicitly opt out of wallet-session handling', () => {
|
|
26
|
+
const method = new DeviceLock({
|
|
27
|
+
id: 1,
|
|
28
|
+
payload: { method: 'deviceLock' },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
method.init();
|
|
32
|
+
|
|
33
|
+
expect(method.useDevicePassphraseState).toBe(false);
|
|
34
|
+
expect(method.unlockPolicy).toBe('none');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('pre-unlocks openWalletSession before opening or restoring a wallet session', async () => {
|
|
38
|
+
const method = new OpenWalletSession({
|
|
39
|
+
id: 1,
|
|
40
|
+
payload: { method: 'openWalletSession', mode: 'standard' },
|
|
41
|
+
});
|
|
42
|
+
method.init();
|
|
43
|
+
const run = jest.fn().mockResolvedValue({ walletType: 'standard' });
|
|
44
|
+
method.run = run as any;
|
|
45
|
+
const features = { unlocked: false };
|
|
46
|
+
const device = {
|
|
47
|
+
features,
|
|
48
|
+
commands: {
|
|
49
|
+
typedCall: jest.fn().mockResolvedValue({ message: { unlocked: false } }),
|
|
50
|
+
},
|
|
51
|
+
isProtocolV2: () => true,
|
|
52
|
+
isBootloader: () => false,
|
|
53
|
+
isRomloader: () => false,
|
|
54
|
+
updateProtocolV2Status: jest.fn(() => features),
|
|
55
|
+
unlockDevice: jest.fn().mockImplementation(() => {
|
|
56
|
+
features.unlocked = true;
|
|
57
|
+
return Promise.resolve(features);
|
|
58
|
+
}),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
await expect(runMethodWithUnlockPolicy(method, device as any)).resolves.toEqual({
|
|
62
|
+
walletType: 'standard',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
expect(method.unlockPolicy).toBe('unlock-before-run');
|
|
66
|
+
expect(device.unlockDevice).toHaveBeenCalledTimes(1);
|
|
67
|
+
expect(run).toHaveBeenCalledTimes(1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('pre-unlocks an unregistered wallet business method', async () => {
|
|
71
|
+
const features = { unlocked: false };
|
|
72
|
+
const method = {
|
|
73
|
+
name: 'newWalletBusinessMethod',
|
|
74
|
+
unlockPolicy: 'none',
|
|
75
|
+
useDevicePassphraseState: true,
|
|
76
|
+
run: jest.fn().mockResolvedValue({ message: 'ok' }),
|
|
77
|
+
};
|
|
78
|
+
const device = {
|
|
79
|
+
features,
|
|
80
|
+
commands: {
|
|
81
|
+
typedCall: jest.fn().mockResolvedValue({ message: { unlocked: false } }),
|
|
82
|
+
},
|
|
83
|
+
isProtocolV2: () => true,
|
|
84
|
+
isBootloader: () => false,
|
|
85
|
+
isRomloader: () => false,
|
|
86
|
+
updateProtocolV2Status: jest.fn(() => features),
|
|
87
|
+
unlockDevice: jest.fn().mockImplementation(() => {
|
|
88
|
+
features.unlocked = true;
|
|
89
|
+
return Promise.resolve(features);
|
|
90
|
+
}),
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
await expect(runMethodWithUnlockPolicy(method as any, device as any)).resolves.toEqual({
|
|
94
|
+
message: 'ok',
|
|
95
|
+
});
|
|
96
|
+
expect(device.unlockDevice).toHaveBeenCalledTimes(1);
|
|
97
|
+
expect(method.run).toHaveBeenCalledTimes(1);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('allows either PIN type when pre-unlocking a known hidden wallet', async () => {
|
|
101
|
+
const features = { unlocked: false };
|
|
102
|
+
const method = {
|
|
103
|
+
name: 'btcGetAddress',
|
|
104
|
+
unlockPolicy: 'none',
|
|
105
|
+
useDevicePassphraseState: true,
|
|
106
|
+
payload: { passphraseState: 'expected-hidden-wallet-state' },
|
|
107
|
+
run: jest.fn().mockResolvedValue({ address: 'bc1qexample' }),
|
|
108
|
+
};
|
|
109
|
+
const device = {
|
|
110
|
+
features,
|
|
111
|
+
commands: {
|
|
112
|
+
typedCall: jest.fn().mockResolvedValue({ message: { unlocked: false } }),
|
|
113
|
+
},
|
|
114
|
+
isProtocolV2: () => true,
|
|
115
|
+
isBootloader: () => false,
|
|
116
|
+
isRomloader: () => false,
|
|
117
|
+
updateProtocolV2Status: jest.fn(() => features),
|
|
118
|
+
unlockDevice: jest.fn().mockImplementation(() => {
|
|
119
|
+
features.unlocked = true;
|
|
120
|
+
return Promise.resolve(features);
|
|
121
|
+
}),
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
await expect(runMethodWithUnlockPolicy(method as any, device as any)).resolves.toEqual({
|
|
125
|
+
address: 'bc1qexample',
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
expect(device.unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Any, expect.any(Object));
|
|
129
|
+
expect(method.run).toHaveBeenCalledTimes(1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('does not let an unrelated control opt into Any with a passphraseState-shaped field', async () => {
|
|
133
|
+
const features = { unlocked: false };
|
|
134
|
+
const method = {
|
|
135
|
+
name: 'securityControl',
|
|
136
|
+
unlockPolicy: 'unlock-before-run',
|
|
137
|
+
useDevicePassphraseState: false,
|
|
138
|
+
payload: { passphraseState: 'untrusted-field' },
|
|
139
|
+
run: jest.fn().mockResolvedValue({ message: 'ok' }),
|
|
140
|
+
};
|
|
141
|
+
const device = {
|
|
142
|
+
features,
|
|
143
|
+
commands: {
|
|
144
|
+
typedCall: jest.fn().mockResolvedValue({ message: { unlocked: false } }),
|
|
145
|
+
},
|
|
146
|
+
isProtocolV2: () => true,
|
|
147
|
+
isBootloader: () => false,
|
|
148
|
+
isRomloader: () => false,
|
|
149
|
+
updateProtocolV2Status: jest.fn(() => features),
|
|
150
|
+
unlockDevice: jest.fn().mockImplementation(() => {
|
|
151
|
+
features.unlocked = true;
|
|
152
|
+
return Promise.resolve(features);
|
|
153
|
+
}),
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
await expect(runMethodWithUnlockPolicy(method as any, device as any)).resolves.toEqual({
|
|
157
|
+
message: 'ok',
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
expect(device.unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Main, expect.any(Object));
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('pre-unlocks a locked standard wallet before wallet-session preparation', async () => {
|
|
164
|
+
const calls: string[] = [];
|
|
165
|
+
const features = {
|
|
166
|
+
unlocked: false,
|
|
167
|
+
passphraseProtection: true,
|
|
168
|
+
};
|
|
169
|
+
const method = {
|
|
170
|
+
name: 'btcGetPublicKey',
|
|
171
|
+
unlockPolicy: 'none',
|
|
172
|
+
useDevicePassphraseState: true,
|
|
173
|
+
payload: { useEmptyPassphrase: true },
|
|
174
|
+
run: jest.fn().mockImplementation(() => {
|
|
175
|
+
calls.push('run');
|
|
176
|
+
return Promise.resolve({ message: 'ok' });
|
|
177
|
+
}),
|
|
178
|
+
};
|
|
179
|
+
const device = {
|
|
180
|
+
features,
|
|
181
|
+
commands: {
|
|
182
|
+
typedCall: jest.fn().mockImplementation(() => {
|
|
183
|
+
calls.push('status');
|
|
184
|
+
return Promise.resolve({
|
|
185
|
+
message: {
|
|
186
|
+
unlocked: false,
|
|
187
|
+
passphraseProtection: true,
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}),
|
|
191
|
+
},
|
|
192
|
+
isProtocolV2: () => true,
|
|
193
|
+
isBootloader: () => false,
|
|
194
|
+
isRomloader: () => false,
|
|
195
|
+
updateProtocolV2Status: jest.fn(() => features),
|
|
196
|
+
unlockDevice: jest.fn().mockImplementation(() => {
|
|
197
|
+
calls.push('pre-unlock');
|
|
198
|
+
features.unlocked = true;
|
|
199
|
+
return Promise.resolve(features);
|
|
200
|
+
}),
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
await expect(
|
|
204
|
+
runMethodWithUnlockPolicy(method as any, device as any, {
|
|
205
|
+
prepare: () => {
|
|
206
|
+
calls.push('prepare');
|
|
207
|
+
expect(features.unlocked).toBe(true);
|
|
208
|
+
return Promise.resolve();
|
|
209
|
+
},
|
|
210
|
+
})
|
|
211
|
+
).resolves.toEqual({ message: 'ok' });
|
|
212
|
+
|
|
213
|
+
expect(calls).toEqual(['status', 'pre-unlock', 'prepare', 'run']);
|
|
214
|
+
expect(device.unlockDevice).toHaveBeenCalledTimes(1);
|
|
215
|
+
expect(device.unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Main, expect.any(Object));
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test('reuses a Main PIN selected by pre-unlock when locked status hides passphrase state', async () => {
|
|
219
|
+
const calls: string[] = [];
|
|
220
|
+
const features: {
|
|
221
|
+
unlocked: boolean;
|
|
222
|
+
passphraseProtection?: boolean;
|
|
223
|
+
unlockedAttachPin?: boolean;
|
|
224
|
+
} = {
|
|
225
|
+
unlocked: false,
|
|
226
|
+
};
|
|
227
|
+
const method: any = {
|
|
228
|
+
name: 'btcGetPublicKey',
|
|
229
|
+
unlockPolicy: 'none',
|
|
230
|
+
useDevicePassphraseState: true,
|
|
231
|
+
payload: { useEmptyPassphrase: true },
|
|
232
|
+
run: jest.fn().mockImplementation(() => {
|
|
233
|
+
calls.push('run');
|
|
234
|
+
return Promise.resolve({ message: 'ok' });
|
|
235
|
+
}),
|
|
236
|
+
};
|
|
237
|
+
const device = {
|
|
238
|
+
features,
|
|
239
|
+
commands: {
|
|
240
|
+
typedCall: jest.fn().mockImplementation(() => {
|
|
241
|
+
calls.push('status');
|
|
242
|
+
return Promise.resolve({
|
|
243
|
+
message: {
|
|
244
|
+
unlocked: false,
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
}),
|
|
248
|
+
},
|
|
249
|
+
isProtocolV2: () => true,
|
|
250
|
+
isBootloader: () => false,
|
|
251
|
+
isRomloader: () => false,
|
|
252
|
+
updateProtocolV2Status: jest.fn(() => features),
|
|
253
|
+
unlockDevice: jest.fn().mockImplementation(() => {
|
|
254
|
+
calls.push('main-pin');
|
|
255
|
+
features.unlocked = true;
|
|
256
|
+
features.passphraseProtection = true;
|
|
257
|
+
features.unlockedAttachPin = false;
|
|
258
|
+
return Promise.resolve(features);
|
|
259
|
+
}),
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
await expect(
|
|
263
|
+
runMethodWithUnlockPolicy(method, device as any, {
|
|
264
|
+
prepare: async () => {
|
|
265
|
+
if (!(features.unlocked && features.unlockedAttachPin === false)) {
|
|
266
|
+
await device.unlockDevice();
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
})
|
|
270
|
+
).resolves.toEqual({ message: 'ok' });
|
|
271
|
+
|
|
272
|
+
expect(calls).toEqual(['status', 'main-pin', 'run']);
|
|
273
|
+
expect(device.unlockDevice).toHaveBeenCalledTimes(1);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test('runs fresh-status validation before starting unlock', async () => {
|
|
277
|
+
const identityError = new Error('Unexpected device');
|
|
278
|
+
const method = {
|
|
279
|
+
name: 'walletBusinessMethod',
|
|
280
|
+
unlockPolicy: 'none',
|
|
281
|
+
useDevicePassphraseState: true,
|
|
282
|
+
run: jest.fn(),
|
|
283
|
+
};
|
|
284
|
+
const features = { unlocked: false };
|
|
285
|
+
const device = {
|
|
286
|
+
features,
|
|
287
|
+
commands: {
|
|
288
|
+
typedCall: jest.fn().mockResolvedValue({ message: { unlocked: false } }),
|
|
289
|
+
},
|
|
290
|
+
isProtocolV2: () => true,
|
|
291
|
+
isBootloader: () => false,
|
|
292
|
+
isRomloader: () => false,
|
|
293
|
+
updateProtocolV2Status: jest.fn(() => features),
|
|
294
|
+
unlockDevice: jest.fn(),
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
await expect(
|
|
298
|
+
runMethodWithUnlockPolicy(method as any, device as any, {
|
|
299
|
+
afterStatusBeforeUnlock: () => {
|
|
300
|
+
throw identityError;
|
|
301
|
+
},
|
|
302
|
+
})
|
|
303
|
+
).rejects.toBe(identityError);
|
|
304
|
+
|
|
305
|
+
expect(device.unlockDevice).not.toHaveBeenCalled();
|
|
306
|
+
expect(method.run).not.toHaveBeenCalled();
|
|
44
307
|
});
|
|
45
308
|
});
|