Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recovery device type checks based on alias #1222

Merged
merged 15 commits into from
Feb 14, 2023

Conversation

frederikrothenberger
Copy link
Contributor

@frederikrothenberger frederikrothenberger commented Feb 13, 2023

This PR fixes checks for recovery devices and recovery phrases that
were based on the device name. This change is required because the
public endpoints no longer give information about the alias.

This PR also includes some typing improvements around the alias being
stripped on the public 'lookup' endpoint.

This PR fixes checks for recovery devices and recovery phrases that
were based on the device name. This change is required because the
public endpoints no longer give information about the alias.

This PR also includes some typing improvements around the alias being
stripped on the public 'lookup'  endpoint.
@frederikrothenberger frederikrothenberger force-pushed the frederik/fix-recovery-checks branch from dd2b8de to bf87c11 Compare February 13, 2023 16:36
@frederikrothenberger
Copy link
Contributor Author

FYI: Screenshot changes happen because the showcase had capitalized recovery device names (whereas the actual recovery setup code did not capitalize the second word).

import { DeviceData } from "../../generated/internet_identity_types";

export const recoveryDeviceToLabel = (
device: Omit<DeviceData, "alias">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can enforce that device has the correct purpose and key_type here and mostly avoid runtime errors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented that in commit 517e9e4f0c51d68828fa4029e087770018a83674 but it seems quite involved. Please have a look, maybe there is a way to simplify.

@frederikrothenberger frederikrothenberger force-pushed the frederik/fix-recovery-checks branch 2 times, most recently from 766b53a to cf11d31 Compare February 14, 2023 08:34
@frederikrothenberger frederikrothenberger force-pushed the frederik/fix-recovery-checks branch from cf11d31 to 517e9e4 Compare February 14, 2023 08:35
src/frontend/src/utils/iiConnection.ts Outdated Show resolved Hide resolved
src/frontend/src/utils/recoveryDevice.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,17 @@
import { DeviceData, Purpose } from "../../generated/internet_identity_types";

export type RecoveryDevice = Omit<DeviceData, "alias"> & {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do RecoveryDevices never have an alias? Also, there are a few occurrences of RecoveryDevice & Omit<DeviceData, "alias"> and RecoveryDevice & DeviceData here and in other modules. Shouldn't these all just be RecoveryDevice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically they do have an alias, in particular when interacting with authenticated canister calls (i.e. add and update) the alias is required.

Agreed, RecoveryDevice & Omit<DeviceData, "alias"> is redundant. Thanks for pointing it out. However, RecoveryDevice & DeviceData is not, as this combines the existence of alias with the restriction on purpose.

@frederikrothenberger frederikrothenberger force-pushed the frederik/fix-recovery-checks branch from d3ce482 to 24b23df Compare February 14, 2023 10:22
@@ -118,8 +128,14 @@ export const deviceSettings = async (
device,
isOnlyDevice,
back: resolve,
protectDevice: () =>
protectDevice(userNumber, connection, device, isOnlyDevice, resolve),
protectDevice: (recoveryDevice: DeviceData & RecoveryDevice) =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it unfortunate that protectDevice now needs to take a device but I get it that it needs a RecoveryDevice. We'll be remodelling the device settings page soon so not a big problem.

src/frontend/src/utils/iiConnection.ts Show resolved Hide resolved
@frederikrothenberger frederikrothenberger added this pull request to the merge queue Feb 14, 2023
Merged via the queue into main with commit 06fbc3a Feb 14, 2023
@frederikrothenberger frederikrothenberger deleted the frederik/fix-recovery-checks branch February 14, 2023 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants