Skip to content

Commit

Permalink
feat: getRegisteredEmail endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
schmanu committed Feb 20, 2024
1 parent f421aa0 commit 000faa2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
22 changes: 22 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type { DecodedDataResponse } from './types/decoded-data'
import type { SafeMessage, SafeMessageListPage } from './types/safe-messages'
import { DEFAULT_BASE_URL } from './config'
import type { DelegateResponse, DelegatesRequest } from './types/delegates'
import type { GetEmailResponse } from './types/emails'

export * from './types/safe-info'
export * from './types/safe-apps'
Expand Down Expand Up @@ -498,4 +499,25 @@ export function verifyEmail(
})
}

/**
* 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
*/
export function getRegisteredEmail(
chainId: string,
safeAddress: string,
signerAddress: string,
headers: operations['get_email']['parameters']['headers'],
): Promise<GetEmailResponse> {
return getEndpoint(baseUrl, '/v1/chains/{chainId}/safes/{safe_address}/emails/{signer}', {
path: { chainId, safe_address: safeAddress, signer: signerAddress },
headers,
})
}

/* eslint-enable @typescript-eslint/explicit-module-boundary-types */
25 changes: 21 additions & 4 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ import type { DelegateResponse, DelegatesRequest } from './delegates'
import type { RegisterNotificationsRequest } from './notifications'
import type {
ChangeEmailRequestBody,
GetEmailResponse,
RegisterEmailRequestBody,
RegisterEmailRequestHeader,
AuthorizationEmailRequestHeader,
VerifyEmailRequestBody,
} from './emails'

Expand Down Expand Up @@ -92,7 +93,7 @@ export interface DeleteEndpoint extends Endpoint {
}

interface PathRegistry {
[key: string]: GetEndpoint | PostEndpoint | PutEndpoint | (GetEndpoint & PostEndpoint) | DeleteEndpoint
[key: string]: GetEndpoint | PostEndpoint | PutEndpoint | DeleteEndpoint
}

export interface paths extends PathRegistry {
Expand Down Expand Up @@ -357,6 +358,7 @@ export interface paths extends PathRegistry {
}
'/v1/chains/{chainId}/safes/{safe_address}/emails/{signer}': {
put: operations['change_email']
get: operations['get_email']
parameters: {
path: {
chainId: string
Expand Down Expand Up @@ -893,7 +895,7 @@ export interface operations {
safe_address: string
}
body: RegisterEmailRequestBody
headers: RegisterEmailRequestHeader
headers: AuthorizationEmailRequestHeader
}
responses: {
200: {
Expand All @@ -909,7 +911,7 @@ export interface operations {
signer: string
}
body: ChangeEmailRequestBody
headers: RegisterEmailRequestHeader
headers: AuthorizationEmailRequestHeader
}
responses: {
200: {
Expand All @@ -920,6 +922,21 @@ export interface operations {
}
}
}
get_email: {
parameters: {
path: {
chainId: string
safe_address: string
signer: string
}
headers: AuthorizationEmailRequestHeader
}
responses: {
200: {
schema: GetEmailResponse
}
}
}
verify_resend: {
parameters: {
path: {
Expand Down
7 changes: 6 additions & 1 deletion src/types/emails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ export type ChangeEmailRequestBody = {
emailAddress: string
}

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

export type VerifyEmailRequestBody = {
code: string
}

export type GetEmailResponse = {
email: string
verified: boolean
}

0 comments on commit 000faa2

Please sign in to comment.