Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
issue license WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmattgray committed Mar 23, 2022
1 parent 9b74007 commit b745a70
Show file tree
Hide file tree
Showing 21 changed files with 742 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@
*/

export default function ColumnLeftWrap() {
// const setStoreDataFn = (resData) => {
// setRecords(() => {
// const verifiedProofs = resData.filter(
// (record) => record.state === 'done'
// )
// const presentations = resData.filter(
// (record) => record.state === 'presentation-received'
// )
// verifiedProofs.forEach((verified) => {
// const presentation = verified.by_format.pres.indy.requested_proof
// // console.log(presentation)
// // startFetchHandlerCredOffer(
// // origin,
// // verified.connection_id,
// // licenseCredDefId,
// // presentation.revealed_attrs['0_id_uuid'].raw,
// // presentation.revealed_attrs['0_type_uuid'].raw,
// // 'expiry',
// // setStatusIssueCred,
// // setDataIssueCred
// // )
// })
// return resData
// })
// }
//const intervalIdFetch = startGetRecordsHandler(origin, setStoreDataFn)
// if (statusRecordEvents !== 'started') clearInterval(intervalIdFetch)
// return function clear() {
// return clearInterval(intervalIdFetch)
//}

return (
<>
<div className="col-md-6">
Expand Down
7 changes: 7 additions & 0 deletions src/components/AgentAuthority/ContentWrap/ContentWrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
import ColumnLeftWrap from '../ColumnLeft/ColumnLeftWrap'
import ColumnRightWrap from '../ColumnRight/ColumnRightWrap'

import ProofRequest from '../RequestProof'
import Verify from '../Verify'
import IssueLicense from '../IssueLicense'

export default function ContentWrap({ origin }) {
return (
<>
<ProofRequest origin={origin} />
<Verify origin={origin} />
<IssueLicense origin={origin} />
<ColumnLeftWrap origin={origin} />
<ColumnRightWrap origin={origin} />
</>
Expand Down
76 changes: 76 additions & 0 deletions src/components/AgentAuthority/IssueLicense/IssueLicense.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Listens for verified presentation proofs and issues a license
*/
import { useEffect, useState } from 'react'
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'

export default function IssueLicense({ origin }) {
const [licenseCredDefId, setLicenseCredDefId] = useState('')
const [statusRecords, errorRecords, startGetRecordsHandler] =
useGetLoopedPresentProofRecords()
const [errorIssueCred, startFetchHandlerCredOffer] =
usePostIssueCredentialSendOffer()

useEffect(() => {
const sendCredOffers = (verifiedProofs) => {
verifiedProofs.forEach((verified) => {
const presentation = verified.by_format.pres.indy.requested_proof
console.log(presentation.predicates['0_expiration_dateint_GE_uui'])
startFetchHandlerCredOffer(
origin,
verified.connection_id,
licenseCredDefId,
presentation.revealed_attrs['0_id_uuid'].raw,
presentation.revealed_attrs['0_type_uuid'].raw,
'expiry',
() => {},
() => {}
)
})
}
const intervalIdFetch = startGetRecordsHandler(
origin,
'done',
sendCredOffers
)
if (statusRecords !== 'started') clearInterval(intervalIdFetch)
return function clear() {
return clearInterval(intervalIdFetch)
}
}, [
origin,
statusRecords,
startFetchHandlerCredOffer,
startGetRecordsHandler,
licenseCredDefId,
])

return (
<>
<LicenseCredDef
origin={origin}
setLicenseCredDefId={setLicenseCredDefId}
/>
<div
className={errorRecords || errorIssueCred ? 'd-block' : 'd-none'}
style={{
position: 'fixed',
width: '10%',
height: '10%',
inset: 0,
backgroundColor: 'rgba(0,0,0,0.5)',
zIndex: 100,
}}
>
<div className="text-light m-2 p-2">
<small>
{errorRecords}
{errorIssueCred}
</small>
</div>
</div>
</>
)
}
1 change: 1 addition & 0 deletions src/components/AgentAuthority/IssueLicense/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './IssueLicense'
72 changes: 72 additions & 0 deletions src/components/AgentAuthority/LicenseCredDef/LicenseCredDef.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* 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'

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 (
<>
<div
className={`${
errorDefinitionsCreated || errorPostSchema || errorPostCredDefs
? '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>
{errorDefinitionsCreated}
{errorPostSchema}
{errorPostCredDefs}
</small>
</div>
</div>
</>
)
}
1 change: 1 addition & 0 deletions src/components/AgentAuthority/LicenseCredDef/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './LicenseCredDef'
80 changes: 80 additions & 0 deletions src/components/AgentAuthority/RequestProof/RequestProof.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* 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'

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 (
<>
<div
className={
errorRecords || errorRequest || errorDelete ? 'd-block' : 'd-none'
}
style={{
position: 'fixed',
width: '10%',
height: '10%',
inset: 0,
backgroundColor: 'rgba(0,0,0,0.5)',
zIndex: 100,
}}
>
<div className="text-light m-2 p-2">
<small>
{errorRecords}
{errorRequest}
{errorDelete}
</small>
</div>
</div>
</>
)
}
1 change: 1 addition & 0 deletions src/components/AgentAuthority/RequestProof/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './RequestProof'
58 changes: 58 additions & 0 deletions src/components/AgentAuthority/Verify/Verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* 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'

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 (
<>
<div
className={errorRecords || errorVerify ? 'd-block' : 'd-none'}
style={{
position: 'fixed',
width: '10%',
height: '10%',
inset: 0,
backgroundColor: 'rgba(0,0,0,0.5)',
zIndex: 100,
}}
>
<div className="text-light m-2 p-2">
<small>
{errorRecords}
{errorVerify}
</small>
</div>
</div>
</>
)
}
1 change: 1 addition & 0 deletions src/components/AgentAuthority/Verify/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Verify'
35 changes: 35 additions & 0 deletions src/components/Common/Misc/ErrorBox/ErrorBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export default function ErrorBox({ children, visibility, content }) {
const clickReloadHandler = () => {
window.location.reload()
}
return (
<div
className={`modal ${visibility ? 'show' : ''}`}
id="error"
aria-modal="true"
style={
visibility
? { display: 'block', backgroundColor: 'rgb(0,0,0,0.5)' }
: {}
}
>
<div className="modal-dialog modal-dialog-centered">
<div className="modal-content">
<div className="modal-body">
<div className="my-3">{children || content}</div>
</div>
<div className="modal-footer" data-dismiss="modal">
<button
href="./"
onClick={clickReloadHandler}
type="button"
className="btn btn-danger"
>
Reload
</button>
</div>
</div>
</div>
</div>
)
}
1 change: 1 addition & 0 deletions src/components/Common/Misc/ErrorBox/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './ErrorBox'
Loading

0 comments on commit b745a70

Please sign in to comment.