-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add accepting nested routes * email verification flow * update connector * Refactored credential helpers * add enums for zkp, zkp api refactored structure * rename auth store methods and auth api types * update auth helpers
- Loading branch information
Showing
31 changed files
with
775 additions
and
492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { ZKProof } from '@rarimo/rarime-connector' | ||
|
||
import { api, OrgUserRoles } from '@/api' | ||
import { AuthTokensGroup } from '@/api/modules/auth' | ||
import { ApiServicePaths } from '@/enums/api' | ||
|
||
export const authorizeUser = async ({ | ||
role, | ||
userDid, | ||
orgDid, | ||
groupId, | ||
zkProof, | ||
}: { | ||
role: OrgUserRoles | ||
userDid: string | ||
orgDid: string | ||
groupId: string | ||
zkProof: ZKProof | ||
}) => { | ||
const { data } = await api.post<AuthTokensGroup>(`${ApiServicePaths.Auth}/v1/authorize`, { | ||
body: { | ||
data: { | ||
id: userDid, | ||
type: 'authorize', | ||
attributes: { | ||
proof: { | ||
role: role, | ||
group: groupId, | ||
issuer: orgDid, | ||
proof: zkProof, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
return data | ||
} | ||
|
||
export const refreshJwt = async () => { | ||
const { data } = await api.get<AuthTokensGroup>(`${ApiServicePaths.Auth}/v1/refresh`) | ||
|
||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './authorize' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './helpers' | ||
export * from './types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export type AuthTokensGroup = { | ||
id: string | ||
type: 'token' | ||
accessToken: { | ||
token: string | ||
tokenType: 'access' | ||
} | ||
refreshToken: { | ||
token: string | ||
tokenType: 'access' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export enum Operators { | ||
NOOP = 0, | ||
EQ = 1, | ||
LT = 2, | ||
GT = 3, | ||
IN = 4, | ||
NIN = 5, | ||
NE = 6, | ||
} | ||
|
||
export enum QueryOperators { | ||
$noop = Operators.NOOP, | ||
$eq = Operators.EQ, | ||
$lt = Operators.LT, | ||
$gt = Operators.GT, | ||
$in = Operators.IN, | ||
$nin = Operators.NIN, | ||
$ne = Operators.NE, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { CreateProofRequestParams } from '@rarimo/rarime-connector/dist/types' | ||
|
||
import { OrgUserRoles } from '@/api' | ||
import { QueryOperators } from '@/api/modules/zkp' | ||
|
||
export const buildAuthorizeRequest = ({ | ||
providerAddress, | ||
isAdmin, | ||
}: { | ||
providerAddress: string | ||
isAdmin: boolean | ||
}): CreateProofRequestParams => { | ||
return { | ||
circuitId: 'credentialAtomicQueryMTPV2', | ||
accountAddress: providerAddress, | ||
issuerDid: 'config.issuerDid', // TODO: implement | ||
|
||
query: { | ||
allowedIssuers: ['*'], | ||
credentialSubject: { | ||
role: { | ||
// FIXME: how to other roles will work | ||
[QueryOperators.$eq]: isAdmin ? OrgUserRoles.Admin : OrgUserRoles.Undefined, | ||
}, | ||
}, | ||
type: ['VerifiableCredentials', 'Role'], | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { fetcher } from '@distributedlab/fetcher' | ||
import type { SaveCredentialsRequestParams } from '@rarimo/rarime-connector' | ||
import omit from 'lodash/omit' | ||
|
||
import { api } from '@/api' | ||
import { CredentialSubject, VCSchema } from '@/api/modules/zkp' | ||
|
||
export const getClaimOffer = async (userDid: string, claimTypeUrn: string) => { | ||
const { data } = await api.get<SaveCredentialsRequestParams>( | ||
`/v1/credentials/${userDid}/${claimTypeUrn}`, | ||
) | ||
|
||
return data | ||
} | ||
|
||
export const loadAndParseCredentialSchema = async ( | ||
schemaUrl: string, | ||
credentialSubject?: CredentialSubject, | ||
): Promise<{ | ||
key: string | ||
type: string | ||
value: string | ||
}> => { | ||
const { data } = await fetcher.get<VCSchema>(schemaUrl) | ||
|
||
const [key, { type }] = Object.entries( | ||
omit(data?.properties.credentialSubject.properties, 'id'), | ||
)[0] | ||
|
||
return { | ||
key, | ||
type, | ||
value: credentialSubject?.[key] ?? '', | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './builders' | ||
export * from './credentials' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './enums' | ||
export * from './helpers' | ||
export * from './types' |
Oops, something went wrong.