Skip to content

Commit

Permalink
feat: deleted attestation services (#4)
Browse files Browse the repository at this point in the history
Signed-off-by: owner <[email protected]>
  • Loading branch information
JavaDeveloper456788 authored Jan 9, 2025
1 parent 573c53c commit b17b219
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 714 deletions.
13 changes: 3 additions & 10 deletions app/container-imp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import AddCredentialSlider from './src/components/AddCredentialSlider'
import EmptyList from './src/components/EmptyList'
import HomeFooterView from './src/components/HomeFooterView'
import HomeHeaderView from './src/components/HomeHeaderView'
import { AttestationRestrictions, autoDisableRemoteLoggingIntervalInMinutes } from './src/constants'
import { autoDisableRemoteLoggingIntervalInMinutes } from './src/constants'
import { activate, deactivate, setup, status } from './src/helpers/PushNotificationsHelper'
import { expirationOverrideInMinutes } from './src/helpers/utils'
import { useNotifications } from './src/hooks/notifications'
Expand All @@ -56,10 +56,9 @@ import { pages } from './src/screens/OnboardingPages'
import Preface from './src/screens/Preface'
import Splash from './src/screens/Splash'
import Terms, { TermsVersion } from './src/screens/Terms'
import { AttestationMonitor, allCredDefIds } from './src/services/attestation'

import { BCLocalStorageKeys, BCState, IASEnvironment, RemoteDebuggingState, Unified, initialState } from './src/store'

const attestationCredDefIds = allCredDefIds(AttestationRestrictions)
const helpLink = 'https://www2.gov.bc.ca/gov/content/governments/government-id/bc-wallet/help'

export interface AppState {
Expand Down Expand Up @@ -112,11 +111,6 @@ export class AppContainer implements Container {
const logger = new RemoteLogger(logOptions)
logger.startEventListeners()

const options = {
shouldHandleProofRequestAutomatically: true,
}

this._container.registerInstance(TOKENS.UTIL_ATTESTATION_MONITOR, new AttestationMonitor(logger, options))
// Here you can register any component to override components in core package
// Example: Replacing button in core with custom button
this._container.registerInstance(TOKENS.SCREEN_PREFACE, Preface)
Expand Down Expand Up @@ -214,10 +208,9 @@ export class AppContainer implements Container {
showScanHelp: true,
showScanButton: true,
showDetailsInfo: true,
contactHideList: ['BCAttestationService'],
proofTemplateBaseUrl: Config.PROOF_TEMPLATE_URL,
// Credential Definition IDs
credentialHideList: attestationCredDefIds,

enablePushNotifications: {
status: status,
setup: setup,
Expand Down
21 changes: 0 additions & 21 deletions app/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,3 @@ export const autoDisableRemoteLoggingIntervalInMinutes = 60
export const surveyMonkeyUrl = 'https://www.surveymonkey.com/r/7BMHJL8'
export const surveyMonkeyExitUrl = 'https://www.surveymonkey.com/survey-thanks'
export const hitSlop = { top: 44, bottom: 44, left: 44, right: 44 }
interface AttestationRestrictionEnvironment {
credDefIDs: readonly string[]
invitationUrl: string
}
export const AttestationRestrictions: { [key: string]: AttestationRestrictionEnvironment } = {
Development: {
credDefIDs: ['NXp6XcGeCR2MviWuY51Dva:3:CL:33557:bcwallet', 'NXp6XcGeCR2MviWuY51Dva:3:CL:33557:bcwallet_dev_v2'],
invitationUrl:
'https://traction-acapy-dev.apps.silver.devops.gov.bc.ca?c_i=eyJAdHlwZSI6ICJodHRwczovL2RpZGNvbW0ub3JnL2Nvbm5lY3Rpb25zLzEuMC9pbnZpdGF0aW9uIiwgIkBpZCI6ICI0OGRkNzViNi0wMGI4LTQwZGItOTYxNy01MWIwNDZhZDI0MmEiLCAibGFiZWwiOiAiQkNBdHRlc3RhdGlvblNlcnZpY2VfREVWIiwgInJlY2lwaWVudEtleXMiOiBbIkVjZ0Q5VzRTVGVxa21zU1pOWUpBUEdRV2Y0d25IRFR5U01UUFJDdHpYRUVaIl0sICJzZXJ2aWNlRW5kcG9pbnQiOiAiaHR0cHM6Ly90cmFjdGlvbi1hY2FweS1kZXYuYXBwcy5zaWx2ZXIuZGV2b3BzLmdvdi5iYy5jYSIsICJpbWFnZVVybCI6ICJodHRwOi8vZXhhbXBsZS5jb20vIn0=',
},
Test: {
credDefIDs: ['RycQpZ9b4NaXuT5ZGjXkUE:3:CL:120:bcwallet', 'RycQpZ9b4NaXuT5ZGjXkUE:3:CL:120:bcwallet_test_v2'],
invitationUrl:
'https://traction-acapy-test.apps.silver.devops.gov.bc.ca?c_i=eyJAdHlwZSI6ICJodHRwczovL2RpZGNvbW0ub3JnL2Nvbm5lY3Rpb25zLzEuMC9pbnZpdGF0aW9uIiwgIkBpZCI6ICJkYzc1YTExMy1iZGM5LTRmNGEtYjM1YS04NTIyNzQ1ZjdkOTEiLCAibGFiZWwiOiAiQkNBdHRlc3RhdGlvblNlcnZpY2UiLCAicmVjaXBpZW50S2V5cyI6IFsiOVRmYm45c2drYlZvdGNQaWpSYm1oeEVuZnVteWNvVVl0ZHJ5dWpiN242cHEiXSwgInNlcnZpY2VFbmRwb2ludCI6ICJodHRwczovL3RyYWN0aW9uLWFjYXB5LXRlc3QuYXBwcy5zaWx2ZXIuZGV2b3BzLmdvdi5iYy5jYSJ9',
},
Production: {
credDefIDs: ['XqaRXJt4sXE6TRpfGpVbGw:3:CL:655:bcwallet'],
invitationUrl:
'https://traction-acapy-prod.apps.silver.devops.gov.bc.ca?c_i=eyJAdHlwZSI6ICJodHRwczovL2RpZGNvbW0ub3JnL2Nvbm5lY3Rpb25zLzEuMC9pbnZpdGF0aW9uIiwgIkBpZCI6ICI0NjhkODE1ZC04OWY3LTQ4MGYtOGE1Yy1kNDllMjYyMjg4YTkiLCAibGFiZWwiOiAiQkNBdHRlc3RhdGlvblNlcnZpY2UiLCAicmVjaXBpZW50S2V5cyI6IFsiQ2pKbTkzVnRrcURSRTNROTVUeXpGN2lhNVRCdlJrVTU4MWNHZXZYU0FHaWoiXSwgInNlcnZpY2VFbmRwb2ludCI6ICJodHRwczovL3RyYWN0aW9uLWFjYXB5LXByb2QuYXBwcy5zaWx2ZXIuZGV2b3BzLmdvdi5iYy5jYSJ9',
},
} as const
12 changes: 3 additions & 9 deletions app/src/hooks/initialize-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ const useInitializeBCAgent = () => {
const { setAgent } = useAgent()
const [store, dispatch] = useStore<BCState>()
const { walletSecret } = useAuth()
const [logger, indyLedgers, attestationMonitor, credDefs, schemas] = useServices([
const [logger, indyLedgers, credDefs, schemas] = useServices([
TOKENS.UTIL_LOGGER,
TOKENS.UTIL_LEDGERS,
TOKENS.UTIL_ATTESTATION_MONITOR,

TOKENS.CACHE_CRED_DEFS,
TOKENS.CACHE_SCHEMAS,
])
Expand Down Expand Up @@ -187,16 +187,11 @@ const useInitializeBCAgent = () => {

logger.info('Creating link secret if required...')
await createLinkSecretIfRequired(newAgent)

if (store.preferences.usePushNotifications) {
logger.info('Activating push notifications...')
activate(newAgent)
}

// In case the old attestationMonitor is still active, stop it and start a new one
logger.info('Starting attestation monitor...')
attestationMonitor?.stop()
attestationMonitor?.start(newAgent)

logger.info('Setting new agent...')
setAgent(newAgent)
Expand All @@ -211,7 +206,6 @@ const useInitializeBCAgent = () => {
walletSecret,
logger,
indyLedgers,
attestationMonitor,
])

return { initializeAgent }
Expand Down
36 changes: 4 additions & 32 deletions app/src/hooks/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,23 @@ import {
CredentialExchangeRecord as CredentialRecord,
CredentialState,
ProofExchangeRecord,
ProofState,
} from '@credo-ts/core'
import { useCredentialByState, useProofByState, useBasicMessages, useAgent } from '@credo-ts/react-hooks'
import { BifoldAgent } from '@hyperledger/aries-bifold-core'
import { useCredentialByState, useBasicMessages } from '@credo-ts/react-hooks'
import {
BasicMessageMetadata,
CredentialMetadata,
basicMessageCustomMetadata,
credentialCustomMetadata,
} from '@hyperledger/aries-bifold-core/App/types/metadata'
import { ProofCustomMetadata, ProofMetadata } from '@hyperledger/aries-bifold-verifier'
import { useEffect, useState } from 'react'

import { AttestationRestrictions } from '../constants'
import { isProofRequestingAttestation } from '../services/attestation'

export const useNotifications = (): Array<BasicMessageRecord | CredentialRecord | ProofExchangeRecord> => {
const { agent } = useAgent()
const offers = useCredentialByState(CredentialState.OfferReceived)
const proofsRequested = useProofByState(ProofState.RequestReceived)
const [nonAttestationProofs, setNonAttestationProofs] = useState<ProofExchangeRecord[]>([])
const [notifications, setNotifications] = useState([])
const { records: basicMessages } = useBasicMessages()

const credsReceived = useCredentialByState(CredentialState.CredentialReceived)
const credsDone = useCredentialByState(CredentialState.Done)
const proofsDone = useProofByState([ProofState.Done, ProofState.PresentationReceived])

useEffect(() => {
// get all unseen messages
Expand All @@ -55,32 +45,14 @@ export const useNotifications = (): Array<BasicMessageRecord | CredentialRecord
return cred
}
})
const proofs = nonAttestationProofs.filter((proof) => {
return (
![ProofState.Done, ProofState.PresentationReceived].includes(proof.state) ||
(proof.isVerified !== undefined &&
!(proof.metadata.data[ProofMetadata.customMetadata] as ProofCustomMetadata)?.details_seen)
)
})
const notif = [...messagesToShow, ...offers, ...proofs, ...revoked].sort(

const notif = [...messagesToShow, ...offers, ...revoked].sort(
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
)

const notificationsWithCustom = [...notif]
setNotifications(notificationsWithCustom as never[])
}, [offers, credsReceived, credsDone, basicMessages, nonAttestationProofs])

useEffect(() => {
Promise.all(
[...proofsRequested, ...proofsDone].map(async (proof: ProofExchangeRecord) => {
const isAttestation = await isProofRequestingAttestation(proof, agent as BifoldAgent, AttestationRestrictions)
return {
value: proof,
include: !isAttestation,
}
})
).then((val) => setNonAttestationProofs(val.filter((v) => v.include).map((data) => data.value)))
}, [proofsRequested, proofsDone, agent])
}, [offers, credsReceived, credsDone, basicMessages])

return notifications
}
Loading

0 comments on commit b17b219

Please sign in to comment.