Skip to content

Commit

Permalink
feat(api): add create easAttestation credential group to api
Browse files Browse the repository at this point in the history
  • Loading branch information
waddaboo committed Oct 10, 2024
1 parent b2e1485 commit 53bb68b
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 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,9 @@ import {
Web2Provider,
providers,
Web2Context,
BlockchainContext
BlockchainContext,
EASContext,
EASNetworks
} from "@bandada/credentials"
import { blockchainCredentialSupportedNetworks } from "@bandada/utils"
import { id } from "@ethersproject/hash"
Expand Down Expand Up @@ -139,7 +141,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 +173,14 @@ export class CredentialsService {
jsonRpcProvider
}

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

// Check if the same account has already joined the group.
accountHash = id(address + groupId)
} else {
Expand Down Expand Up @@ -259,30 +269,44 @@ 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, minAttestations } = JSON.parse(
group.credentials
).criteria

if (network) {
const supportedNetwork =
blockchainCredentialSupportedNetworks.find(
(n) => n.name.toLowerCase() === network.toLowerCase()
)

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 (minAttestations) {
context = {
network: EASNetworks.ETHEREUM_SEPOLIA,
address: address[0]
}
}

// Check if the same account has already joined the group.
Expand Down

0 comments on commit 53bb68b

Please sign in to comment.