Skip to content

Commit 99ba633

Browse files
chore: add test for saveDelegatedIdentityKey
1 parent cd3e1e8 commit 99ba633

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

suite-common/suite-sync/src/refreshSuiteSyncKeys.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ type RefreshSuiteSyncKeysParams = {
2525
device: TrezorDevice;
2626
};
2727

28-
export type DeviceDoesNotSupportSuiteSyncErr = {
29-
type: 'DeviceDoesNotSupportSuiteSyncErr';
28+
export type RefreshSuiteKeysUnavailable = {
29+
type: 'RefreshSuiteKeysUnavailable';
3030
};
3131

32-
export const DeviceDoesNotSupportSuiteSyncErr = (): DeviceDoesNotSupportSuiteSyncErr => ({
33-
type: 'DeviceDoesNotSupportSuiteSyncErr',
32+
/**
33+
* Device is not connected or device is in a state/configuration, that does not
34+
* support Suite Sync.
35+
*/
36+
export const RefreshSuiteKeysUnavailable = (): RefreshSuiteKeysUnavailable => ({
37+
type: 'RefreshSuiteKeysUnavailable',
3438
});
3539

3640
export type RefreshSuiteSyncKeys = (
@@ -40,7 +44,7 @@ export type RefreshSuiteSyncKeys = (
4044
void,
4145
| DeviceError
4246
| DeviceCancelledErr
43-
| DeviceDoesNotSupportSuiteSyncErr
47+
| RefreshSuiteKeysUnavailable
4448
| ProofOfDelegatedSignFailed
4549
| CreateSuiteSyncOwnerError
4650
>
@@ -63,7 +67,7 @@ export const createRefreshSuiteSyncKeys =
6367
device.mode !== 'normal' || // bootloader,
6468
!isTrezorDeviceWithState(device)
6569
) {
66-
return err(DeviceDoesNotSupportSuiteSyncErr());
70+
return err(RefreshSuiteKeysUnavailable());
6771
}
6872

6973
const delegatedKeyResult = await deps.ensureDelegatedIdentityKey({ device });
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { EncryptableBranded, asEncryptedHex } from '@suite-common/secure-storage';
2+
import { asDelegatedIdentityKey } from '@suite-common/suite-types';
3+
import { ok } from '@trezor/type-utils';
4+
5+
import { createSaveDelegatedIdentityKey } from '../saveDelegatedIdentityKey';
6+
7+
describe(createSaveDelegatedIdentityKey.name, () => {
8+
it('saves the encrypted value to the store', async () => {
9+
const actions: unknown[] = [];
10+
11+
const saveDelegatedIdentityKey = createSaveDelegatedIdentityKey({
12+
dispatch: (action: unknown) => actions.push(action),
13+
secureStorage: {
14+
encrypt: <T extends EncryptableBranded>({ value }: { value: T }) =>
15+
Promise.resolve(ok(asEncryptedHex<T>(`${value}-<encrypted>`))),
16+
decrypt: () => {
17+
throw new Error('Not expected!');
18+
},
19+
},
20+
});
21+
22+
await saveDelegatedIdentityKey({
23+
deviceId: 'device-123',
24+
delegatedIdentityKey: asDelegatedIdentityKey('delegatedKey'),
25+
});
26+
27+
expect(actions).toStrictEqual([
28+
{
29+
payload: { delegatedKey: 'delegatedKey-<encrypted>', deviceId: 'device-123' },
30+
type: '@suite/device/setDelegatedIdentityKey',
31+
},
32+
]);
33+
});
34+
});

0 commit comments

Comments
 (0)