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

update ketl/unique-balance method #57

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 22 additions & 43 deletions src/controllers/verify-ketl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import AttestationType from '@/validators/AttestationType'
import AttestationTypeList from '@/validators/AttestationTypeList'
import BalanceUniqueVerifyBody from '@/validators/BalanceUniqueVerifyBody'
import Email from '@/validators/Email'
import OrangeDAOTokenAddress from '@/validators/OrangeDAOTokenAddress'
import Signature from '@/validators/Signature'
import Token from '@/validators/Token'
import TwitterBody from '@/validators/TwitterBody'
Expand Down Expand Up @@ -160,61 +159,41 @@ export default class VerifyKetlController {

@Post('/balance-unique')
@Version('0.2.2')
async multipleBalanceAttestation(
async multipleBalanceAttestationSimplified(
@Ctx() ctx: Context,
@Body({ required: true })
{
message,
ownerAddress,
signature,
threshold,
tokenAddress = zeroAddress,
tokenId,
types,
}: BalanceUniqueVerifyBody &
Signature &
AttestationTypeList &
OrangeDAOTokenAddress
body: Signature & AttestationTypeList
) {
const { message, signature, types } = body
const signerAddress = ethers.utils
.verifyMessage(message, signature)
.toLowerCase()

if (signerAddress.toLowerCase() !== ownerAddress.toLowerCase()) {
return ctx.throw(badRequest('Invalid ownerAddress'))
}

try {
const balance = await getBalance(
polygonProvider,
ownerAddress,
tokenAddress,
tokenId
)
if (balance.lt(threshold)) {
return ctx.throw(badRequest('Not enough balance'))
}
} catch (e) {
console.error(e)
return ctx.throw(badRequest("Can't fetch the balances"))
}

const attestations = []
for (const type of types) {
for (const contract of [YC_ALUM_NFT_CONTRACT, KETL_BWL_NFT_CONTRACT]) {
const attestationHash = await getAttestationHash(
VerificationType.balance,
hexlifyString(signerAddress),
threshold,
hexlifyString(contract)
)
const record = await signAttestationMessage(type, attestationHash)
const hasInvite = await checkInvite(type, attestationHash)
if (hasInvite) attestations.push(record)
for (const tokenAddress of [
YC_ALUM_NFT_CONTRACT,
KETL_BWL_NFT_CONTRACT,
]) {
try {
const attestationHash = await getAttestationHash(
VerificationType.balance,
hexlifyString(signerAddress),
1,
hexlifyString(tokenAddress)
)
const record = await signAttestationMessage(type, attestationHash)
const hasInvite = await checkInvite(type, attestationHash)
if (hasInvite) attestations.push(record)
} catch (e) {
console.error(e)
}
}
}

if (!attestations.length)
return ctx.throw(notFound(handleInvitationError('wallet')))

return Promise.all(attestations)
}

Expand Down
4 changes: 3 additions & 1 deletion src/helpers/signatures/getAttestationHash.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import poseidonHash from '@/helpers/signatures/poseidonHash'

export default function getAttestationHash(...attestation: string[]) {
export default function getAttestationHash(
...attestation: (string | number)[]
) {
return poseidonHash(attestation, true)
}
Loading