Skip to content

Commit

Permalink
refactor: move the blockchain credential supported networks to the ba…
Browse files Browse the repository at this point in the history
…ndada utils package

Since the supported networks are attached to the infrastructure and not to the credential package,
they have been to the bandada utils package.

re #443
  • Loading branch information
vplasencia committed Mar 25, 2024
1 parent 631d303 commit a08d082
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
15 changes: 8 additions & 7 deletions apps/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ TWITTER_REDIRECT_URI=
TWITTER_CLIENT_ID=
TWITTER_CLIENT_SECRET=

# The network name must be the same as the supportedNetworks in blockchain provider
# but with capital letters and an underscore instead of a space to separate words.

BLOCKCHAIN_SEPOLIA_RPC_URL=
BLOCKCHAIN_POLYGON_MUMBAI_RPC_URL=
BLOCKCHAIN_OPTIMISM_SEPOLIA_RPC_URL=
BLOCKCHAIN_ARBITRUM_SEPOLIA_RPC_URL=
# The network name must be the same as the blockchainCredentialNetworks in `getSupportedNetworks`
# in the `@bandada/utils` package but with capital letters and an underscore instead of a space
# to separate words.

SEPOLIA_RPC_URL=
POLYGON_MUMBAI_RPC_URL=
OPTIMISM_SEPOLIA_RPC_URL=
ARBITRUM_SEPOLIA_RPC_URL=
3 changes: 2 additions & 1 deletion apps/api/src/app/credentials/credentials.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ jest.mock("@bandada/utils", () => ({
logs: ["1"]
}),
getGroups: () => []
})
}),
blockchainCredentialNetworks: ["Sepolia"]
}))

jest.mock("@bandada/credentials", () => ({
Expand Down
14 changes: 11 additions & 3 deletions apps/api/src/app/credentials/credentials.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Web2Context,
BlockchainContext
} from "@bandada/credentials"
import { blockchainCredentialNetworks } from "@bandada/utils"
import { id } from "@ethersproject/hash"
import {
BadRequestException,
Expand Down Expand Up @@ -106,14 +107,21 @@ export class CredentialsService {

if (address) {
const { network } = JSON.parse(group.credentials).criteria

if (
!blockchainCredentialNetworks.some(
(n) => n.toLowerCase() === network.toLowerCase()
)
) {
throw new BadRequestException(`The network is not supported`)
}

const networkEnvVariableName = (network as string)
.split(" ")
.join("_")
.toUpperCase()
const web3providerRpcURL =
process.env[
`${providerName.toUpperCase()}_${networkEnvVariableName}_RPC_URL`
]
process.env[`${networkEnvVariableName}_RPC_URL`]

const jsonRpcProvider = await (
provider as BlockchainProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
validators,
providers,
Provider,
BlockchainProvider
} from "@bandada/credentials"
import { validators } from "@bandada/credentials"
import { blockchainCredentialNetworks } from "@bandada/utils"
import {
Box,
Button,
Expand Down Expand Up @@ -248,13 +244,7 @@ export default function AccessModeStep({
})
}
>
{(
providers.find(
(provider: Provider) =>
provider.name ===
"blockchain"
) as BlockchainProvider
).supportedNetworks.map(
{blockchainCredentialNetworks.map(
(network: string) => (
<option value={network}>
{network}
Expand Down
9 changes: 1 addition & 8 deletions libs/credentials/src/providers/blockchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ const provider: BlockchainProvider = {
const jsonRpcProvider = getJsonRpcProvider(url)

return jsonRpcProvider
},

supportedNetworks: [
"Sepolia",
"Polygon Mumbai",
"Optimism Sepolia",
"Arbitrum Sepolia"
]
}
}

export default provider
1 change: 0 additions & 1 deletion libs/credentials/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export interface Web2Provider extends Provider {
export interface BlockchainProvider extends Provider {
getAddress: (message: string, signature: string) => Promise<BigNumberish>
getJsonRpcProvider: (url: string) => Promise<any>
supportedNetworks: string[]
}

export interface EASProvider extends Provider {
Expand Down
6 changes: 6 additions & 0 deletions libs/utils/src/getSupportedNetworks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const blockchainCredentialNetworks: string[] = [
"Sepolia",
"Polygon Mumbai",
"Optimism Sepolia",
"Arbitrum Sepolia"
]
4 changes: 3 additions & 1 deletion libs/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import getWallet from "./getWallet"
import getBandadaContract, { BandadaContract } from "./getBandadaContract"
import request from "./request"
import shortenAddress from "./shortenAddress"
import { blockchainCredentialNetworks } from "./getSupportedNetworks"

export * from "./types/index"
export {
Expand All @@ -23,5 +24,6 @@ export {
CONTRACT_ADDRESSES,
getContractAddresses,
SemaphoreABI,
BandadaABI
BandadaABI,
blockchainCredentialNetworks
}

0 comments on commit a08d082

Please sign in to comment.