Skip to content

Commit

Permalink
Merge pull request #61 from BigWhaleLabs/new-email
Browse files Browse the repository at this point in the history
use new email
  • Loading branch information
T-Damer authored Nov 13, 2023
2 parents 6672d5a + 33de9bb commit 48f89e7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"dependencies": {
"@big-whale-labs/constants": "^0.2.25",
"@big-whale-labs/ketl-email": "^0.3.1",
"@big-whale-labs/ketl-email": "^0.4.1",
"@big-whale-labs/seal-cred-email": "^1.1.2",
"@hapi/boom": "^10.0.0",
"@koa/cors": "^4.0.0",
Expand Down
19 changes: 9 additions & 10 deletions src/controllers/verify-ketl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import checkInvite from '@/helpers/ketl/checkInvite'
import fetchUserProfile from '@/helpers/twitter/fetchUserProfile'
import getAttestationHash from '@/helpers/signatures/getAttestationHash'
import getBalance from '@/helpers/getBalance'
import getEmailDomain from '@/helpers/getEmailDomain'
import handleInvitationError from '@/helpers/handleInvitationError'
import hexlifyString from '@/helpers/hexlifyString'
import sendEmail from '@/helpers/sendEmail'
Expand Down Expand Up @@ -56,8 +55,9 @@ export default class VerifyKetlController {
async sendMultipleEmailAttestation(
@Ctx() ctx: Context,
@Body({ required: true })
{ email, types }: AttestationTypeList & Email
body: AttestationTypeList & Email
) {
const { email, types } = body
const secret = []

for (const type of types) {
Expand All @@ -81,33 +81,32 @@ export default class VerifyKetlController {
if (!secret.length)
return ctx.throw(notFound(handleInvitationError('email')))

const domain = getEmailDomain(email)
const fullSecret = secret.join('')

void sendEmail({
domain,
forKetl: true,
secret: secret.join(''),
subject: "Here's your signup code!",
secret: fullSecret,
subject: "Here's your invite code!",
to: email,
})
}

@Post('/email-unique')
async sendUniqueEmail(
@Body({ required: true })
{ email, type }: AttestationType & Email
body: AttestationType & Email
) {
const { email, type } = body
const attestationHash = await getAttestationHash(
VerificationType.email,
hexlifyString(email)
)
const { signature } = await signAttestationMessage(type, attestationHash)
const domain = getEmailDomain(email)

void sendEmail({
domain,
forKetl: true,
secret: `${type}${attestationHash}${signature}`,
subject: "Here's signup code!",
subject: "Here's your invite code!",
to: email,
})
}
Expand Down
1 change: 0 additions & 1 deletion src/controllers/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export default class VerifyController {
const domainBytes = padZeroesOnRightUint8(utils.toUtf8Bytes(domain), 90)
const signature = await eddsaSigFromString(domainBytes)
void sendEmail({
domain,
secret: signature,
subject: "Here's your token!",
to: email,
Expand Down
10 changes: 6 additions & 4 deletions src/helpers/sendEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createTransport } from 'nodemailer'
import { inviteCode } from '@big-whale-labs/ketl-email'
import { generateTokenHtml as scEmail } from '@big-whale-labs/seal-cred-email'
import env from '@/helpers/env'
import getEmailDomain from '@/helpers/getEmailDomain'

const user = env.SMTP_USER
const pass = env.SMTP_PASS
Expand All @@ -27,7 +28,6 @@ const emailerMailgun = createTransport(
)

export default async function ({
domain,
forKetl,
secret,
subject,
Expand All @@ -36,13 +36,15 @@ export default async function ({
to: string
subject: string
secret: string
domain: string
forKetl?: boolean
}) {
try {
const { html } = forKetl
? inviteCode({ domain, secret })
: scEmail({ domain, secret })
? inviteCode({
inviteCode: secret,
value: to,
})
: scEmail({ domain: getEmailDomain(to), secret })

const from = forKetl ? 'Ketl' : 'SealCred'
const fromEmail = forKetl
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ __metadata:
languageName: node
linkType: hard

"@big-whale-labs/ketl-email@npm:^0.3.1":
version: 0.3.1
resolution: "@big-whale-labs/ketl-email@npm:0.3.1"
"@big-whale-labs/ketl-email@npm:^0.4.1":
version: 0.4.1
resolution: "@big-whale-labs/ketl-email@npm:0.4.1"
dependencies:
dotenv: ^16.3.1
envalid: ^7.3.1
Expand All @@ -52,7 +52,7 @@ __metadata:
react: ^18.2.0
react-dom: ^18.2.0
source-map-support: ^0.5.21
checksum: 6b99f253a4c01c489497cf553b2a81e299a27c0dde9256d1c95e08cd8fb541847a06519ca048bb467cf5feed80b62ddf626eeea98d34dbf91da0c52d79c47240
checksum: 2781cebcf07feac50de2d7890d14c159444f772e51be1832ca70ed6918dcdc8968189dfa74e3f043263ffd171da080b7c582a13d044df60f0e4a22572edfffb8
languageName: node
linkType: hard

Expand Down Expand Up @@ -1741,7 +1741,7 @@ __metadata:
dependencies:
"@big-whale-labs/bwl-eslint-backend": ^1.0.3
"@big-whale-labs/constants": ^0.2.25
"@big-whale-labs/ketl-email": ^0.3.1
"@big-whale-labs/ketl-email": ^0.4.1
"@big-whale-labs/prettier-config": ^1.1.3
"@big-whale-labs/seal-cred-email": ^1.1.2
"@hapi/boom": ^10.0.0
Expand Down

0 comments on commit 48f89e7

Please sign in to comment.