Skip to content

Conversation

@schmanu
Copy link
Contributor

@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

@schmanu schmanu requested a review from fmrsabino February 19, 2024 15:27
@github-actions
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

@schmanu schmanu requested a review from iamacook February 19, 2024 15:58

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

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
Contributor 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
Contributor

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
Contributor

@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.

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}

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}


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
Contributor 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.

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
Contributor 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

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.

4 participants