Skip to content

Commit

Permalink
Merge branch 'main' into feat/many-credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
vplasencia committed Jun 27, 2024
2 parents 16dcfa3 + 45c1d07 commit 214e9a0
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 35 deletions.
4 changes: 2 additions & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"build": "nest build"
},
"dependencies": {
"@bandada/credentials": "2.2.9",
"@bandada/utils": "2.2.9",
"@bandada/credentials": "2.2.10",
"@bandada/utils": "2.2.10",
"@ethersproject/hash": "^5.7.0",
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
Expand Down
4 changes: 2 additions & 2 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"preview": "vite preview"
},
"dependencies": {
"@bandada/api-sdk": "2.2.9",
"@bandada/utils": "2.2.9",
"@bandada/api-sdk": "2.2.10",
"@bandada/utils": "2.2.10",
"@chakra-ui/react": "^2.5.1",
"@chakra-ui/styled-system": "^2.0.0",
"@chakra-ui/theme-tools": "^2.0.16",
Expand Down
2 changes: 1 addition & 1 deletion apps/contracts/contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bandada/contracts",
"version": "2.2.9",
"version": "2.2.10",
"description": "Bandada smart contracts to manage off-chain groups and verify their zero-knowledge proofs.",
"license": "MIT",
"files": [
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"preview": "vite preview"
},
"dependencies": {
"@bandada/credentials": "2.2.9",
"@bandada/utils": "2.2.9",
"@bandada/credentials": "2.2.10",
"@bandada/utils": "2.2.10",
"@chakra-ui/icons": "^2.1.1",
"@chakra-ui/react": "^2.5.1",
"@chakra-ui/styled-system": "^2.0.0",
Expand Down
24 changes: 24 additions & 0 deletions apps/docs/docs/api-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,27 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc"

const invite = await apiSdk.getInvite(inviteCode)
```

## Get credential group join URL

\# **getCredentialGroupJoinUrl**(): _string_

Returns a custom URL string for joining a credential group.

```ts
import { DashboardUrl } from "@bandada/api-sdk"

const dashboardUrl = DashboardUrl.DEV
const groupId = "10402173435763029700781503965100"
const commitment = "1"
const providerName = "github"
const redirectUri = "http://localhost:3003"

const url = apiSdk.getCredentialGroupJoinUrl(
dashboardUrl,
groupId,
commitment,
providerName,
redirectUri
)
```
24 changes: 24 additions & 0 deletions libs/api-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,27 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc"

const invite = await apiSdk.getInvite(inviteCode)
```

## Get credential group join URL

\# **getCredentialGroupJoinUrl**(): _string_

Returns a custom URL string for joining a credential group.

```ts
import { DashboardUrl } from "@bandada/api-sdk"

const dashboardUrl = DashboardUrl.DEV
const groupId = "10402173435763029700781503965100"
const commitment = "1"
const providerName = "github"
const redirectUri = "http://localhost:3003"

const url = apiSdk.getCredentialGroupJoinUrl(
dashboardUrl,
groupId,
commitment,
providerName,
redirectUri
)
```
4 changes: 2 additions & 2 deletions libs/api-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bandada/api-sdk",
"version": "2.2.9",
"version": "2.2.10",
"description": "A Typescript SDK for the Bandada API.",
"license": "MIT",
"main": "dist/index.node.js",
Expand Down Expand Up @@ -30,7 +30,7 @@
"access": "public"
},
"dependencies": {
"@bandada/utils": "2.2.9"
"@bandada/utils": "2.2.10"
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.0.0",
Expand Down
33 changes: 31 additions & 2 deletions libs/api-sdk/src/apiSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
Group,
Invite,
GroupCreationDetails,
GroupUpdateDetails
GroupUpdateDetails,
DashboardUrl
} from "./types"
import checkParameter from "./checkParameter"
import {
Expand All @@ -22,7 +23,8 @@ import {
removeMemberByApiKey,
removeMembersByApiKey,
getGroupsByAdminId,
getGroupsByMemberId
getGroupsByMemberId,
getCredentialGroupJoinUrl
} from "./groups"
import { createInvite, getInvite } from "./invites"

Expand Down Expand Up @@ -350,4 +352,31 @@ export default class ApiSdk {

return invite
}

/**
* Generate a custom url for joining a credential group.
* @param dashboardUrl Dashboard base url.
* @param groupId Group id.
* @param commitment Identity commitment.
* @param providerName Group credential provider name.
* @param redirectUri Redirect uri.
* @returns Url string.
*/
getCredentialGroupJoinUrl(
dashboardUrl: DashboardUrl,
groupId: string,
commitment: string,
providerName: string,
redirectUri?: string
): string {
const url = getCredentialGroupJoinUrl(
dashboardUrl,
groupId,
commitment,
providerName,
redirectUri
)

return url
}
}
32 changes: 31 additions & 1 deletion libs/api-sdk/src/groups.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { request } from "@bandada/utils"
import type { GroupCreationDetails, Group, GroupUpdateDetails } from "./types"
import type {
GroupCreationDetails,
Group,
GroupUpdateDetails,
DashboardUrl
} from "./types"

const url = "/groups"

Expand Down Expand Up @@ -371,3 +376,28 @@ export async function removeMembersByApiKey(

await request(requestUrl, newConfig)
}

/**
* Generate a custorm url for joining a credential group.
* @param dashboardUrl Dashboard url.
* @param groupId Group id.
* @param commitment Identity commitment.
* @param providerName Group credential provider name.
* @param redirectUri Redirect uri.
* @returns Url string.
*/
export function getCredentialGroupJoinUrl(
dashboardUrl: DashboardUrl,
groupId: string,
commitment: string,
providerName: string,
redirectUri?: string
): string {
let resultUrl = `${dashboardUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}`

if (redirectUri) {
resultUrl += `&redirect_uri=${redirectUri}?redirect=true`
}

return resultUrl
}
26 changes: 25 additions & 1 deletion libs/api-sdk/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
Group,
GroupUpdateDetails,
Invite,
SupportedUrl
SupportedUrl,
DashboardUrl
} from "./types"
import checkParameter from "./checkParameter"

Expand Down Expand Up @@ -582,6 +583,29 @@ describe("Bandada API SDK", () => {
expect(res).toBeUndefined()
})
})

describe("#getCredentialGroupJoinUrl", () => {
it("Should generate a custom url for joining a credential group", async () => {
const dashboardUrl = DashboardUrl.DEV
const groupId = "10402173435763029700781503965100"
const commitment = "1"
const providerName = "github"
const redirectUri = "http://localhost:3003"

apiSdk = new ApiSdk(SupportedUrl.DEV)
const res = apiSdk.getCredentialGroupJoinUrl(
dashboardUrl,
groupId,
commitment,
providerName,
redirectUri
)

const url = `${dashboardUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}&redirect_uri=${redirectUri}?redirect=true`

expect(res).toBe(url)
})
})
})
})
describe("Invites", () => {
Expand Down
6 changes: 6 additions & 0 deletions libs/api-sdk/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ export enum SupportedUrl {
PROD = "https://api.bandada.pse.dev",
STAGING = "https://api-staging.bandada.pse.dev"
}

export enum DashboardUrl {
DEV = "http://localhost:3001",
PROD = "https://app.bandada.pse.dev",
STAGING = "https://app-staging.bandada.pse.dev"
}
4 changes: 2 additions & 2 deletions libs/credentials/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bandada/credentials",
"version": "2.2.9",
"version": "2.2.10",
"description": "Bandada library to validate users' credentials.",
"license": "MIT",
"main": "dist/index.node.js",
Expand Down Expand Up @@ -30,7 +30,7 @@
"access": "public"
},
"dependencies": {
"@bandada/utils": "2.2.9",
"@bandada/utils": "2.2.10",
"ethers": "5.7.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ describe("BlockchainBalance", () => {
}

it("Should return true if an account has a balance greater than or equal to 10", async () => {
jsonRpcProviderMocked.getBalance.mockReturnValue(BigNumber.from(12))
jsonRpcProviderMocked.getBalance.mockReturnValue(
BigNumber.from("12000000000000000000")
)

const result = await validateCredentials(
{
Expand All @@ -28,7 +30,9 @@ describe("BlockchainBalance", () => {
})

it("Should return true if an account has a balance greater than or equal to 10 using the block number", async () => {
jsonRpcProviderMocked.getBalance.mockReturnValue(BigNumber.from(12))
jsonRpcProviderMocked.getBalance.mockReturnValue(
BigNumber.from("12000000000000000000")
)

const result = await validateCredentials(
{
Expand Down
9 changes: 6 additions & 3 deletions libs/credentials/src/validators/blockchainBalance/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber } from "ethers"
import { utils } from "ethers"
import { BlockchainContext, Validator } from "../.."

export type Criteria = {
Expand Down Expand Up @@ -38,13 +38,16 @@ const validator: Validator = {
? criteria.blockNumber
: undefined

const balance = await (
const balanceWei = await (
context as BlockchainContext
).jsonRpcProvider.getBalance(
(context as BlockchainContext).address,
blockNumber
)
return balance >= BigNumber.from(criteria.minBalance)

const balanceETH = utils.formatEther(balanceWei)

return parseFloat(balanceETH) >= parseFloat(criteria.minBalance)
}
throw new Error("No address value found")
}
Expand Down
4 changes: 2 additions & 2 deletions libs/hardhat/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bandada/hardhat",
"version": "2.2.9",
"version": "2.2.10",
"description": "A Hardhat plugin which provides tasks to deploy Bandada contracts.",
"license": "MIT",
"main": "dist/index.node.js",
Expand Down Expand Up @@ -40,7 +40,7 @@
"typescript": "^4.9.5"
},
"peerDependencies": {
"@bandada/contracts": "2.2.9",
"@bandada/contracts": "2.2.10",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@semaphore-protocol/contracts": "3.4.0",
"ethers": "^5.4.7",
Expand Down
2 changes: 1 addition & 1 deletion libs/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bandada/utils",
"version": "2.2.9",
"version": "2.2.10",
"description": "General Bandada utility functions.",
"license": "MIT",
"main": "dist/index.node.js",
Expand Down
Loading

0 comments on commit 214e9a0

Please sign in to comment.