Skip to content

Commit

Permalink
Merge pull request #574 from bandada-infra/feat/dashboard-credentials
Browse files Browse the repository at this point in the history
Add EAS Attestation credentials to API and Dashboard
  • Loading branch information
vplasencia authored Oct 11, 2024
2 parents 707581a + 9863009 commit d525575
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 31 deletions.
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

0 comments on commit d525575

Please sign in to comment.