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

Add EAS Attestation credentials to API and Dashboard #574

Merged
merged 14 commits into from
Oct 11, 2024
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
56 changes: 38 additions & 18 deletions apps/api/src/app/credentials/credentials.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
Web2Provider,
providers,
Web2Context,
BlockchainContext
BlockchainContext,
EASContext
} from "@bandada/credentials"
import { blockchainCredentialSupportedNetworks } from "@bandada/utils"
import { id } from "@ethersproject/hash"
Expand Down Expand Up @@ -139,7 +140,7 @@ export class CredentialsService {
} = this.oAuthState.get(credentialOAuthState))
const provider = getProvider(providerName)

let context: Web2Context | BlockchainContext
let context: Web2Context | BlockchainContext | EASContext

if (address && credentialProvider === "blockchain") {
const { network } = credentials.credentials[i].criteria
Expand Down Expand Up @@ -171,6 +172,13 @@ export class CredentialsService {
jsonRpcProvider
}

// Check if the same account has already joined the group.
accountHash = id(address + groupId)
} else if (address && credentialProvider === "eas") {
context = {
address: address[0]
}

// Check if the same account has already joined the group.
accountHash = id(address + groupId)
} else {
Expand Down Expand Up @@ -259,30 +267,42 @@ export class CredentialsService {

let accountHash: string

let context: Web2Context | BlockchainContext
let context: Web2Context | BlockchainContext | EASContext

if (address) {
const { network } = JSON.parse(group.credentials).criteria
const { network, minBalance, minTransactions, minAttestations } =
JSON.parse(group.credentials).criteria

const supportedNetwork = blockchainCredentialSupportedNetworks.find(
(n) => n.name.toLowerCase() === network.toLowerCase()
)
if (network && (minBalance || minTransactions)) {
const supportedNetwork =
blockchainCredentialSupportedNetworks.find(
(n) => n.name.toLowerCase() === network.toLowerCase()
)

if (supportedNetwork === undefined)
throw new BadRequestException(`The network is not supported`)
if (supportedNetwork === undefined)
throw new BadRequestException(
`The network is not supported`
)

const networkEnvVariableName = supportedNetwork.id.toUpperCase()
const networkEnvVariableName = supportedNetwork.id.toUpperCase()

const web3providerRpcURL =
process.env[`${networkEnvVariableName}_RPC_URL`]
const web3providerRpcURL =
process.env[`${networkEnvVariableName}_RPC_URL`]

const jsonRpcProvider = await (
provider as BlockchainProvider
).getJsonRpcProvider(web3providerRpcURL)
const jsonRpcProvider = await (
provider as BlockchainProvider
).getJsonRpcProvider(web3providerRpcURL)

context = {
address: address[0],
jsonRpcProvider
context = {
address: address[0],
jsonRpcProvider
}
}

if (network && minAttestations) {
context = {
address: address[0]
}
}

// Check if the same account has already joined the group.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { validators } from "@bandada/credentials"
import { blockchainCredentialSupportedNetworks } from "@bandada/utils"
import {
blockchainCredentialSupportedNetworks,
easCredentialSupportedNetworks
} from "@bandada/utils"
import {
Box,
Button,
Expand Down Expand Up @@ -254,15 +257,30 @@ export default function AccessModeStep({
})
}
>
{blockchainCredentialSupportedNetworks.map(
(network: any) => (
<option
value={network.name}
>
{network.name}
</option>
)
)}
{validators[_validator]
.criteriaABI.minAttestations
? easCredentialSupportedNetworks.map(
(network: any) => (
<option
value={
network.id
}
>
{network.name}
</option>
)
)
: blockchainCredentialSupportedNetworks.map(
(network: any) => (
<option
value={
network.name
}
>
{network.name}
</option>
)
)}
</Select>
)}
{parameter[1].type === "boolean" && (
Expand Down
8 changes: 5 additions & 3 deletions apps/dashboard/src/pages/credentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
blockchain,
Web2Provider,
twitter,
github
github,
eas
} from "@bandada/credentials"
import { Flex, Text, Button } from "@chakra-ui/react"
import { useEffect, useState, useCallback, useContext } from "react"
Expand Down Expand Up @@ -175,9 +176,10 @@ export default function CredentialsPage() {
clientRedirectUri
)

// If the credential is blockchain
// If the credential is blockchain or eas attestations
if (
providerName === blockchain.name &&
(providerName === blockchain.name ||
providerName === eas.name) &&
isLoggedInAdmin() &&
state
) {
Expand Down
8 changes: 6 additions & 2 deletions libs/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import getWallet from "./getWallet"
import getBandadaContract, { BandadaContract } from "./getBandadaContract"
import request from "./request"
import shortenAddress from "./shortenAddress"
import { blockchainCredentialSupportedNetworks } from "./getSupportedNetworks"
import {
blockchainCredentialSupportedNetworks,
easCredentialSupportedNetworks
} from "./getSupportedNetworks"

export {
ApiKeyActions,
Expand All @@ -30,5 +33,6 @@ export {
getContractAddresses,
SemaphoreABI,
BandadaABI,
blockchainCredentialSupportedNetworks
blockchainCredentialSupportedNetworks,
easCredentialSupportedNetworks
}
Loading