Skip to content

Commit

Permalink
Grouped VCs with metadata per request (#30)
Browse files Browse the repository at this point in the history
* load grouped credential claim ids with metadata per request wip
  • Loading branch information
lukachi authored Jan 30, 2024
1 parent f0ffe34 commit 915d626
Show file tree
Hide file tree
Showing 11 changed files with 716 additions and 361 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@mui/icons-material": "^5.14.19",
"@mui/material": "^5.14.20",
"@mui/x-date-pickers": "^6.18.7",
"@rarimo/rarime-connector": "2.0.1",
"@rarimo/rarime-connector": "^2.0.1",
"@walletconnect/modal": "^2.6.2",
"copy-to-clipboard": "^3.3.3",
"i18next": "^22.4.3",
Expand Down
58 changes: 53 additions & 5 deletions src/api/modules/orgs/helpers/org-groups-requests.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { W3CCredential } from '@rarimo/rarime-connector'

import { api } from '@/api/clients'
import {
CredentialRequest,
GroupedCredentials,
OrgClaimIDMap,
OrgGroupCreatedRequest,
OrgGroupRequest,
OrgGroupRequestClaim,
OrgGroupRequestFilters,
OrgGroupRequestMetadata,
OrgGroupRequestPublishing,
OrgGroupRequestQueryParams,
OrgGroupVCsMetadata,
OrgGroupVCMap,
OrgUserRoles,
} from '@/api/modules/orgs'
import { DUMMY_ORG_GROUP_REQUESTS } from '@/api/modules/orgs/mocks'
import { getTargetProperty, loadAndParseCredentialSchema } from '@/api/modules/zkp'
import {
getClaimIdFromVC,
getTargetProperty,
loadAndParseCredentialSchema,
} from '@/api/modules/zkp'
import { ApiServicePaths } from '@/enums/api'

const fakeLoadRequestsAll = async (query?: OrgGroupRequestQueryParams) => {
Expand Down Expand Up @@ -155,7 +164,7 @@ export const verifyOrgGroupRequest = async ({
activationDate?: string
expirationDate?: string
role: OrgUserRoles
metadata: OrgGroupVCsMetadata
metadata: OrgGroupRequestMetadata
}) => {
const { data } = await api.post<OrgGroupRequest>(
`${ApiServicePaths.Orgs}/v1/orgs/${orgId}/groups/${groupId}/requests/${reqId}`,
Expand Down Expand Up @@ -222,8 +231,8 @@ export const getOrgGroupPublishingRequests = async ({

export const loadOrgGroupReqMetadataById = async (
metadataId: string,
): Promise<OrgGroupVCsMetadata> => {
const { data } = await api.get<OrgGroupVCsMetadata>(
): Promise<OrgGroupRequestMetadata> => {
const { data } = await api.get<OrgGroupRequestMetadata>(
`${ApiServicePaths.Orgs}/v1/orgs/metadata/${metadataId}`,
)

Expand Down Expand Up @@ -277,3 +286,42 @@ export const getOrgGroupRequestClaims = async ({

return data
}

export const getMetadataBatch = async (vcs: W3CCredential[]): Promise<GroupedCredentials> => {
const orgsToClaimIdsMap = vcs.reduce((acc, vc) => {
const issuerDID = vc.issuer

if (!acc[issuerDID]) acc[issuerDID] = []

acc[issuerDID].push(getClaimIdFromVC(vc))

return acc
}, {} as OrgClaimIDMap)

const { data } = await api.get<GroupedCredentials>(`${ApiServicePaths.Orgs}/v1/orgs/metadata`, {
query: {
orgsToClaimIdsMap,
},
})

return data

// return DUMMY_ORG_GROUP_METADATAS // FIXME: remove
}

export const groupVCsToOrgGroups = (
groupedVCs: GroupedCredentials,
vcs: W3CCredential[],
): OrgGroupVCMap => {
return groupedVCs.grouped_credentials.map(org => ({
orgDID: org.org_did,
groups: org.groups.map(group => ({
groupID: group.group_id,
requests: group.requests.map(req => ({
reqID: req.req_id,
vcs: vcs.filter(vc => req.claim_ids.includes(getClaimIdFromVC(vc))),
metadata: req.metadata,
})),
})),
}))
}
240 changes: 239 additions & 1 deletion src/api/modules/orgs/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { W3CCredential } from '@rarimo/rarime-connector'

import {
GroupedCredentials,
OrgGroupCreatedRequest,
OrgGroupRequest,
OrgGroupRequestMetadata,
OrgGroupRequestStatuses,
OrgsStatuses,
} from '@/api/modules/orgs'
Expand Down Expand Up @@ -401,7 +405,6 @@ export const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
},
]

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const DUMMY_CREATED_REQUEST: OrgGroupCreatedRequest = {
id: '9d6a5063-684e-4ab4-b49a-82cdceadf63f',
type: 'invitations-email',
Expand All @@ -413,3 +416,238 @@ export const DUMMY_CREATED_REQUEST: OrgGroupCreatedRequest = {
request: DUMMY_ORG_GROUP_REQUESTS[0],
claim_id: '',
}

type FakeOrgSystem = {
did: string
groups: {
id: string
requests: {
id: string
claim_ids: string[]
metadata: OrgGroupRequestMetadata
}[]
}[]
}

const FAKE_ORG_DETAILS: FakeOrgSystem[] = [
{
did: 'did:iden3:readonly:tUDjWxnVJNi7t3FudukqrUcNwF5KVGoWgim5pp2jV',
groups: [
{
id: 'c3106e8a-0c26-4a83-9579-144cb3f190e0',
requests: [
{
id: '80d43159-1c6c-4507-b89d-3a2652899484',
claim_ids: [
'a572e693-a32f-423f-9436-80062cd52210',
'507dfc87-faff-477a-9371-cb76c9827e26',
],
metadata: {
title: 'Civic',
subtitle: 'Civic',
appearance: {
background: '#000000',
},
},
},
],
},

{
id: 'dede6c65-f9e2-4971-8b5e-0de953432fb4',
requests: [
{
id: '06858a9d-bee3-44e5-b348-4f4dd62eb225',
claim_ids: [
'c6389a9a-a74a-4d93-8411-b4526a4443bc',
'e3324cac-382b-4171-ab27-5a8711f273b8',
],
metadata: {
title: 'Civic',
subtitle: 'Civic',
appearance: {
background: '#000000',
},
},
},
],
},
],
},

{
did: 'did:iden3:readonly:tLd8sbb1xTSvi2wtRF4TUVcfDUr8ppYMohLqjhGQT',
groups: [
{
id: '88ea3292-079b-4c64-9afe-5ed09fac0d41',
requests: [
{
id: '49607e53-af3e-40c6-ac56-ed400e382a29',
claim_ids: [
'842e41bd-8f77-4aca-b8a2-cf6a19d38de9',
'ca65e641-835a-4f4d-8074-e4ef1fac0510',
],
metadata: {
title: 'Civic',
subtitle: 'Civic',
appearance: {
background: '#000000',
},
},
},
],
},

{
id: 'e098d80a-6998-493b-97b7-9861dd62ad93',
requests: [
{
id: 'cf5bc955-fb21-4dc3-b1ed-4524506cd85f',
claim_ids: ['e4246361-49f3-4db9-961c-39f7cdc0701e'],
metadata: {
title: 'Civic',
subtitle: 'Civic',
appearance: {
background: '#000000',
},
},
},
],
},
],
},
]

const createFakeVCs = (org: FakeOrgSystem): W3CCredential[] => {
return org.groups.reduce((groupsAcc, group) => {
return [
...groupsAcc,
...group.requests.reduce((reqsAcc, req) => {
return [
...reqsAcc,
...req.claim_ids.reduce(
(claimsAcc, claimId) => [
...claimsAcc,
{
id: `https://issuer.polygon.robotornot.mainnet-beta.rarimo.com/v1/credentials/${claimId}`,
'@context': [
'https://ipfs.rarimo.com/ipfs/QmYCGiCoDn9WVoSwUBA8XLhgjzbeYLWZPfoM3scdtkWpfF',
'https://schema.iden3.io/core/jsonld/iden3proofs.jsonld',
'https://ipfs.rarimo.com/ipfs/QmWP3bM4oBoD26zrjeGas9v3as6cgpG1hhCPZhySsPuNiH',
],
type: ['VerifiableCredential', 'IdentityProviders'],
issuanceDate: '2023-12-27T15:12:03.195946265Z',
credentialSubject: {
address: '0xa58174F5632bD281C4639877Dd46AdA3F784d299',
id: 'did:iden3:readonly:tKRuUKu3feUEktA38mxN2jdEkbgSAHjq8fVqAGmkw',
isNatural: 1,
groupID: group.id,
provider: 'Civic',
providerMetadata:
'{"gitcoinPassportData":{"score":"","additionalData":""},"worldcoinData":{"score":"","additionalData":""},"civicGatekeeperNetworkId":4}',
type: 'IdentityProviders',
},
credentialStatus: {
id: 'https://issuer.polygon.robotornot.mainnet-beta.rarimo.com/v1/credentials/revocation/status/1129467401',
revocationNonce: 1129467401,
type: 'SparseMerkleTreeProof',
},
issuer: org.did,
credentialSchema: {
id: 'https://ipfs.rarimo.com/ipfs/QmPC6cerSfgk9mYqQtEB8SE9UAsQRiPPNKjVJu2byWkNPW',
type: 'JsonSchema2023',
},
proof: [
{
type: 'BJJSignature2021',
issuerData: {
id: 'did:iden3:tLd8sbb1xTSvi2wtRF4TUVcfDUr8ppYMohLqjhGQT',
updateUrl:
'https://issuer.polygon.robotornot.mainnet-beta.rarimo.com/v1/claims/a780d2fd-22ec-435e-8f05-eae04205c2d9/mtp',
state: {
claimsTreeRoot:
'9747653320df0cd590ee5b84f87bbbe2c3b286b62ba9a1645cda0d6d59742024',
value: 'cd96cf691736b9bd8904bd7c8908a1fb634062297c94017175a9542de8fbac0a',
},
authCoreClaim:
'cca3371a6cb1b715004407e325bd993c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009b96a8f6eeb9cca85294c178d2ea6cc3d971e806b26f313cac4308eebbd00b0b8dc52c8622de9aee96eff59fde209fc688c76a638029a7cdb1b9010c249737090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
mtp: {
existence: true,
siblings: [],
},
credentialStatus: {
id: 'https://api.polygon.rarimo.com/v1/did%3Aiden3%3AtLd8sbb1xTSvi2wtRF4TUVcfDUr8ppYMohLqjhGQT/claims/revocation/status/0',
revocationNonce: 0,
type: 'SparseMerkleTreeProof',
},
},
coreClaim:
'11d9dcf5ebe39bd8b48f0d9e2d8132142200000000000000000000000000000001001c6ea583cf8393cabe190396c1428391fde2246b880a481ac6150f350c00408bcde0f64fcf379010c9885a36c00f3124f6bbdc3f669e483929a90dff312d0000000000000000000000000000000000000000000000000000000000000000094e524300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
signature:
'24c67126d134e12de026295f0e92e22318bd9f0c454bab6eb2c629b8781c5a90533b253fa91e1c4b6f0c4bb409acb9b60aaf332d6c16e3d82c069f718e2c7e03',
},
{
id: `https://issuer.polygon.robotornot.mainnet-beta.rarimo.com/v1/claims/${claimId}/mtp`,
type: 'Iden3SparseMerkleTreeProof',
issuerData: {
id: 'did:iden3:readonly:tLd8sbb1xTSvi2wtRF4TUVcfDUr8ppYMohLqjhGQT',
updateUrl:
'https://issuer.polygon.robotornot.mainnet-beta.rarimo.com/v1/claims/a780d2fd-22ec-435e-8f05-eae04205c2d9/mtp',
state: {
txId: '0x4be69036944695559bffe8fafbb113d8d7b7497f616e220508f8db481ebeea90',
blockTimestamp: 1703689934,
blockNumber: 2706885,
rootOfRoots:
'00bc6e7d7a0fccfb06618ac1309d1c156da1b4ce76c3975b676171ab623a7923',
claimsTreeRoot:
'6f63784a2b3f91664dcb9ab8d66239bad0fc3f6679e78398a16d55abf36c4803',
revocationTreeRoot:
'0000000000000000000000000000000000000000000000000000000000000000',
value: '8676fb494b59f081f8dbc9ef1d0dab470553f393124f598af7cc24418bb51f13',
},
},
coreClaim:
'11d9dcf5ebe39bd8b48f0d9e2d8132142200000000000000000000000000000001001c6ea583cf8393cabe190396c1428391fde2246b880a481ac6150f350c00408bcde0f64fcf379010c9885a36c00f3124f6bbdc3f669e483929a90dff312d0000000000000000000000000000000000000000000000000000000000000000094e524300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
mtp: {
existence: true,
siblings: [
'17010377152295787254839147192723456178717024842623631635098729138057250157857',
'12924307196045514835805694216473888713984093662867270379704014977671451413733',
'13765287829368037334904404318011085970482157641299944550152516041284595059530',
'4053105853098359984576731540894779782443463526190358561995782139032844723698',
'15540039145788727156803576062336874679245346750303902320717021313597528296534',
'14898882455300258436710420051560762698440442210786728184710165011392858797788',
'8327390683815162909081363747977245175578535850347783814223021121903306972814',
],
},
},
],
},
],
[] as W3CCredential[],
),
]
}, [] as W3CCredential[]),
]
}, [] as W3CCredential[])
}

export const DUMMY_VCS: W3CCredential[] = [
...FAKE_ORG_DETAILS.reduce((acc, org) => [...acc, ...createFakeVCs(org)], [] as W3CCredential[]),
]

export const DUMMY_ORG_GROUP_METADATAS: GroupedCredentials = {
id: 'b0dc3814-e754-4596-a117-c4a07dfc65ef',
type: 'grouped_credentials',
grouped_credentials: FAKE_ORG_DETAILS.map(org => ({
org_did: org.did,
groups: org.groups.map(group => ({
group_id: group.id,
requests: group.requests.map(req => ({
req_id: req.id,
claim_ids: req.claim_ids,
metadata: req.metadata,
})),
})),
})),
}
3 changes: 1 addition & 2 deletions src/api/modules/orgs/types/org-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { OrgGroupIncludes } from '@/api/modules/orgs'
export type OrgGroupMetadata = {
name: string
description: string
// TODO: other metadata e. g. styles
}

export type OrgGroupVCsMetadata = {
export type OrgGroupRequestMetadata = {
title: string
subtitle: string
appearance: {
Expand Down
Loading

0 comments on commit 915d626

Please sign in to comment.