Skip to content

Commit

Permalink
Corrects old masked email pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
betimshahini committed Jan 20, 2024
1 parent b2d8d5f commit ad632e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion platform/account/src/jsonrpc/methods/getMaskedAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const getMaskedAddressMethod: GetMaskedAddressMethod = async ({
const node = new EmailAccount(ctx.account, ctx.env)
return node.getMaskedAddress(
input.clientId,
ctx.env.INTERNAL_RELAY_DISTRIBUTION_KEY
ctx.env.INTERNAL_RELAY_DISTRIBUTION_KEY,
ctx.env.INTERNAL_RELAY_DKIM_DOMAIN
)
}
9 changes: 6 additions & 3 deletions platform/account/src/nodes/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,17 @@ export default class EmailAccount {

async getMaskedAddress(
clientId: string,
distributionKey: string
distributionKey: string,
relayDomain: string
): Promise<string> {
const relayPattern = `.${distributionKey}@${relayDomain}`
const key = `masked-address/${clientId}`
const stored = await this.node.storage.get<string>(key)
if (stored) return stored
//Generates new masked email if there's an existing one using old pattern
if (stored && stored.endsWith(relayPattern)) return stored
const bits = generateRandomString(6)
const words = randomWords.generate(3).join('-')
const address = `${words}-${bits}.${distributionKey}@rollup.email`
const address = `${words}-${bits}${relayPattern}`
await this.node.storage.put<string>(key, address)
return address
}
Expand Down

0 comments on commit ad632e5

Please sign in to comment.