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

feat: register, change and verify email addresses #148

Merged
merged 8 commits into from
Feb 22, 2024
Merged

feat: register, change and verify email addresses #148

merged 8 commits into from
Feb 22, 2024

Conversation

schmanu
Copy link
Member

@schmanu schmanu commented Feb 19, 2024

New Endpoints

  • register email address for signer
  • change email address for signer
  • re-send verification code
  • verify email address

Other changes

  • Some of the new endpoints require params in header fields. Therefore this PR adds header params to the api operations.

Links

Copy link

github-actions bot commented Feb 19, 2024

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action


export type RegisterEmailRequestHeader = {
['Safe-Wallet-Signature']: string
['Safe-Wallet-Signature-Timestamp']: string
Copy link
Member

Choose a reason for hiding this comment

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

In the API spec, this is of type number

Copy link
Member Author

Choose a reason for hiding this comment

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

Headers are always passed as strings, that's why I set the type for headers to always be Record<string ,string> Otherwise we have to map over the values and call toString()

Copy link
Member

Choose a reason for hiding this comment

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

So in web-core we would send Date.now().toString() as the header parameter. Will this be handled correctly by the controller in CGW? @fmrsabino

Choose a reason for hiding this comment

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

So in web-core we would send Date.now().toString() as the header parameter. Will this be handled correctly by the controller in CGW? @fmrsabino

This is totally fine. We validate if it's a number and do proper conversion 👍
https://github.com/safe-global/safe-client-gateway/blob/d1d59c40226973bb64f481b0656ce61feefef46d/src/routes/email/guards/timestamp.guard.ts#L16-L18

Copy link
Member

@usame-algan usame-algan left a comment

Choose a reason for hiding this comment

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

Looks good so far!

I suggest to also add a deleteEmail function since we need that on the wallet side as well (API Spec)

For future iterations we will need a way to unsubscribe from notifications too but I would leave it as out-of-scope here.

src/index.ts Outdated
Comment on lines 502 to 510
/**
* Gets the registered email address of the signer
*
* @param chainId
* @param safeAddress
* @param signerAddress address of the owner of the Safe
*
* @returns email address and verified flag
*/

Choose a reason for hiding this comment

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

Since it's mentioned in the other authenticated endpoints. This one also requires a signature: email-retrieval-{chainId}-{safe}-{signer}-{timestamp}

src/index.ts Outdated
Comment on lines 523 to 530
/**
* Delete a registered email address for the signer
*
* @param chainId
* @param safeAddress
* @param signerAddress
* @param headers
*/

Choose a reason for hiding this comment

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

Same as my comment above. Signature would be email-delete-{chainId}-{safe}-{signer}-{timestamp}

@@ -70,6 +78,13 @@ export interface PostEndpoint extends Endpoint {
}
}

export interface PutEndpoint extends Endpoint {
put: {
parameters: PostParams | null

Choose a reason for hiding this comment

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

What does PostParams represent under the PutEndpoint?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not duplicate the types here as they are identical.
The Params represent what kind of parameters the endpoints accept:
In both cases

  • body params
  • header params
  • query params

headers: AuthorizationEmailRequestHeader
}
responses: {
200: {

Choose a reason for hiding this comment

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

Here it should be 201.

Comment on lines +917 to +924
responses: {
200: {
schema: void
}
202: {
schema: void
}
}

Choose a reason for hiding this comment

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

Does this only include successful responses? If so then only 202 should be expected. There are client related error codes returned under other conditions though.

src/types/api.ts Outdated
Comment on lines 950 to 959
responses: {
202: {
schema: void
}
200: {
schema: void
}
429: unknown
409: unknown
}

Choose a reason for hiding this comment

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

FYI: After safe-global/safe-client-gateway#1181 is merged, only 202 will be returned.

Comment on lines +975 to +977
200: {
schema: void
}

Choose a reason for hiding this comment

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

This status code is not expected to be returned on this endpoint.

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently our types enforce a 200 response code this. We should look into how to make them more flexible.
Probably the success-return type could be expressed through generics instead of using the 200 code return type.


export type RegisterEmailRequestHeader = {
['Safe-Wallet-Signature']: string
['Safe-Wallet-Signature-Timestamp']: string

Choose a reason for hiding this comment

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

So in web-core we would send Date.now().toString() as the header parameter. Will this be handled correctly by the controller in CGW? @fmrsabino

This is totally fine. We validate if it's a number and do proper conversion 👍
https://github.com/safe-global/safe-client-gateway/blob/d1d59c40226973bb64f481b0656ce61feefef46d/src/routes/email/guards/timestamp.guard.ts#L16-L18

@usame-algan usame-algan merged commit e7f7d64 into main Feb 22, 2024
4 checks passed
@usame-algan usame-algan deleted the emails branch February 22, 2024 08:28
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.

3 participants