This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
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.
- Loading branch information
1 parent
9b74007
commit fbc168c
Showing
23 changed files
with
676 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
81 changes: 81 additions & 0 deletions
81
src/components/AgentAuthority/IssueLicense/IssueLicense.js
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,81 @@ | ||
/** | ||
* Listens for verified presentation proofs and issues a license | ||
*/ | ||
import { useEffect, useState } from 'react' | ||
import moment from 'moment' | ||
import LicenseCredDef from '../LicenseCredDef' | ||
import useGetLoopedPresentProofRecords from '../../../interface/hooks/use-get-looped-present-proof-records' | ||
import usePostIssueCredentialSendOffer from '../../../interface/hooks/use-post-issue-credential-send-offer' | ||
import useDeleteRecord from '../../../interface/hooks/use-delete-record' | ||
import Error from '../../Common/Misc/Error' | ||
|
||
export default function IssueLicense({ origin }) { | ||
const [licenseCredDefId, setLicenseCredDefId] = useState('') | ||
const [statusRecords, errorRecords, startGetRecordsHandler] = | ||
useGetLoopedPresentProofRecords() | ||
const [errorIssueCred, startFetchHandlerCredOffer] = | ||
usePostIssueCredentialSendOffer() | ||
const [errorDelete, startDeleteHandler] = useDeleteRecord() | ||
|
||
useEffect(() => { | ||
const sendCredOffers = (verifiedProofs) => { | ||
verifiedProofs.forEach((verified) => { | ||
const { | ||
by_format: { | ||
pres: { | ||
indy: { | ||
requested_proof: { revealed_attrs: attributes }, | ||
}, | ||
}, | ||
}, | ||
} = verified | ||
|
||
const expiry = moment().add(2, 'years').format('YYYYMMDD') | ||
|
||
startFetchHandlerCredOffer( | ||
origin, | ||
verified.connection_id, | ||
licenseCredDefId, | ||
attributes['0_id_uuid'].raw, | ||
attributes['0_type_uuid'].raw, | ||
expiry, | ||
() => {}, | ||
() => { | ||
startDeleteHandler( | ||
origin, | ||
verified.pres_ex_id, | ||
() => {}, | ||
() => {} | ||
) | ||
} | ||
) | ||
}) | ||
} | ||
const intervalIdFetch = startGetRecordsHandler( | ||
origin, | ||
'done', | ||
sendCredOffers | ||
) | ||
if (statusRecords !== 'started') clearInterval(intervalIdFetch) | ||
return function clear() { | ||
return clearInterval(intervalIdFetch) | ||
} | ||
}, [ | ||
origin, | ||
statusRecords, | ||
startFetchHandlerCredOffer, | ||
startGetRecordsHandler, | ||
licenseCredDefId, | ||
startDeleteHandler, | ||
]) | ||
|
||
return ( | ||
<> | ||
<LicenseCredDef | ||
origin={origin} | ||
setLicenseCredDefId={setLicenseCredDefId} | ||
/> | ||
<Error errors={[errorIssueCred, errorRecords, errorDelete]} /> | ||
</> | ||
) | ||
} |
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 { default } from './IssueLicense' |
51 changes: 51 additions & 0 deletions
51
src/components/AgentAuthority/LicenseCredDef/LicenseCredDef.js
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,51 @@ | ||
/** | ||
* Get or create the credential definitions for the | ||
* license issued by the authority | ||
*/ | ||
import { useEffect } from 'react' | ||
|
||
import { AUTHORITY_LABEL, LICENSE_SCHEMA_NAME } from '../../../utils/env.js' | ||
import useGetCredDefinitionsCreated from '../../../interface/hooks/use-get-cred-definitions-created' | ||
import usePostSchemas from '../../../interface/hooks/use-post-schemas' | ||
import usePostCredentialDefinitions from '../../../interface/hooks/use-post-credential-definitions' | ||
import Error from '../../Common/Misc/Error' | ||
|
||
export default function LicenseCredDef({ origin, setLicenseCredDefId }) { | ||
const [errorDefinitionsCreated, startFetchHandlerDefinitionsCreated] = | ||
useGetCredDefinitionsCreated() | ||
|
||
const [errorPostSchema, startPostSchema] = usePostSchemas() | ||
const [errorPostCredDefs, startPostCredDef] = usePostCredentialDefinitions() | ||
|
||
useEffect(() => { | ||
startFetchHandlerDefinitionsCreated(origin, (credDefIds) => { | ||
const licenseCredDefId = credDefIds.find((credDefId) => | ||
credDefId.includes(LICENSE_SCHEMA_NAME) | ||
) | ||
if (licenseCredDefId) { | ||
setLicenseCredDefId(licenseCredDefId) | ||
} else { | ||
startPostSchema(origin, LICENSE_SCHEMA_NAME, (schemaId) => { | ||
startPostCredDef( | ||
origin, | ||
schemaId, | ||
AUTHORITY_LABEL, | ||
setLicenseCredDefId | ||
) | ||
}) | ||
} | ||
}) | ||
}, [ | ||
origin, | ||
startFetchHandlerDefinitionsCreated, | ||
startPostSchema, | ||
startPostCredDef, | ||
setLicenseCredDefId, | ||
]) | ||
|
||
return ( | ||
<Error | ||
errors={[errorDefinitionsCreated, errorPostSchema, errorPostCredDefs]} | ||
/> | ||
) | ||
} |
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 { default } from './LicenseCredDef' |
57 changes: 57 additions & 0 deletions
57
src/components/AgentAuthority/RequestProof/RequestProof.js
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,57 @@ | ||
/** | ||
* Listens for presentation proof proposals and sends requests in response, then deletes the original proposal | ||
*/ | ||
import { useEffect } from 'react' | ||
import useGetLoopedPresentProofRecords from '../../../interface/hooks/use-get-looped-present-proof-records' | ||
import useDeleteRecord from '../../../interface/hooks/use-delete-record' | ||
import usePostPresentProofSendRequest from '../../../interface/hooks/use-post-present-proof-send-request' | ||
import Error from '../../Common/Misc/Error' | ||
|
||
export default function RequestProof({ origin }) { | ||
const [statusRecords, errorRecords, startGetRecordsHandler] = | ||
useGetLoopedPresentProofRecords() | ||
const [errorRequest, startFetchHandlerRequest] = | ||
usePostPresentProofSendRequest() | ||
const [errorDelete, startDeleteHandler] = useDeleteRecord() | ||
|
||
useEffect(() => { | ||
const sendRequests = (proposals) => { | ||
console.log(proposals) | ||
proposals.forEach((proposal) => { | ||
startFetchHandlerRequest({ | ||
origin, | ||
comment: proposal.pres_proposal.comment, | ||
connectionId: proposal.connection_id, | ||
proposal: proposal.by_format.pres_proposal.indy, | ||
validity: new Date().toISOString().split('T')[0], | ||
setStatus: () => {}, | ||
setStoreData: () => { | ||
startDeleteHandler( | ||
origin, | ||
proposal.pres_ex_id, | ||
() => {}, | ||
() => {} | ||
) | ||
}, | ||
}) | ||
}) | ||
} | ||
const intervalIdFetch = startGetRecordsHandler( | ||
origin, | ||
'proposal-received', | ||
sendRequests | ||
) | ||
if (statusRecords !== 'started') clearInterval(intervalIdFetch) | ||
return function clear() { | ||
return clearInterval(intervalIdFetch) | ||
} | ||
}, [ | ||
origin, | ||
statusRecords, | ||
startFetchHandlerRequest, | ||
startGetRecordsHandler, | ||
startDeleteHandler, | ||
]) | ||
|
||
return <Error errors={[errorRecords, errorRequest, errorDelete]} /> | ||
} |
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 { default } from './RequestProof' |
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,38 @@ | ||
/** | ||
* Listens for presentation proofs and verifies them | ||
*/ | ||
import { useEffect } from 'react' | ||
import useGetLoopedPresentProofRecords from '../../../interface/hooks/use-get-looped-present-proof-records' | ||
import usePostPresentProofRecordsVerifyPresentation from '../../../interface/hooks/use-post-present-proof-records-verify-presentation' | ||
import Error from '../../Common/Misc/Error' | ||
|
||
export default function Verify({ origin }) { | ||
const [statusRecords, errorRecords, startGetRecordsHandler] = | ||
useGetLoopedPresentProofRecords() | ||
const [errorVerify, startFetchHandlerVerify] = | ||
usePostPresentProofRecordsVerifyPresentation() | ||
|
||
useEffect(() => { | ||
const sendVerifications = (presentations) => { | ||
presentations.forEach((presentation) => { | ||
startFetchHandlerVerify( | ||
origin, | ||
presentation.pres_ex_id, | ||
() => {}, | ||
() => {} | ||
) | ||
}) | ||
} | ||
const intervalIdFetch = startGetRecordsHandler( | ||
origin, | ||
'presentation-received', | ||
sendVerifications | ||
) | ||
if (statusRecords !== 'started') clearInterval(intervalIdFetch) | ||
return function clear() { | ||
return clearInterval(intervalIdFetch) | ||
} | ||
}, [origin, statusRecords, startFetchHandlerVerify, startGetRecordsHandler]) | ||
|
||
return <Error errors={[errorRecords, errorVerify]} /> | ||
} |
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 { default } from './Verify' |
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,23 @@ | ||
export default function Error({ errors }) { | ||
return ( | ||
<> | ||
<div | ||
className={`${ | ||
errors.some((error) => error != undefined) ? 'd-block' : 'd-none' | ||
}`} | ||
style={{ | ||
position: 'fixed', | ||
width: '10%', | ||
height: '10%', | ||
inset: '0px', | ||
backgroundColor: 'rgba(0, 0, 0, 0.5)', | ||
zIndex: 100, | ||
}} | ||
> | ||
<div className="text-light m-2 p-2"> | ||
<small>{errors.toString()}</small> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} |
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 { default } from './Error' |
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,26 @@ | ||
/** | ||
* It returns a function that can be used to delete a connection. | ||
*/ | ||
import { useCallback, useState } from 'react' | ||
import del from '../api/helpers/del' | ||
|
||
export default function useDeleteRecord() { | ||
const path = '/present-proof-2.0/records/' | ||
const transformData = (retrievedData) => retrievedData | ||
const [error, setError] = useState(null) | ||
const onStartFetch = useCallback( | ||
(origin, presExId, setStatus, setStoreData) => { | ||
del( | ||
origin, | ||
path + presExId, | ||
{}, | ||
setStatus, | ||
setError, | ||
setStoreData, | ||
transformData | ||
) | ||
}, | ||
[] | ||
) | ||
return [error, onStartFetch] | ||
} |
Oops, something went wrong.