diff --git a/packages/legacy/core/App/container-api.ts b/packages/legacy/core/App/container-api.ts index 8601347654..dea3ba7fe6 100644 --- a/packages/legacy/core/App/container-api.ts +++ b/packages/legacy/core/App/container-api.ts @@ -58,6 +58,11 @@ export const OBJECT_TOKENS = { OBJECT_ONBOARDING_CONFIG: 'object.onboarding-config', } as const +export const CACHE_TOKENS = { + CACHE_CRED_DEFS: 'cache.cred-defs', + CACHE_SCHEMAS: 'cache.schemas', +} as const + export const UTILITY_TOKENS = { UTIL_LOGGER: 'utility.logger', UTIL_OCA_RESOLVER: 'utility.oca-resolver', @@ -74,6 +79,7 @@ export const TOKENS = { ...COMP_TOKENS, ...LOAD_STATE_TOKENS, ...OBJECT_TOKENS, + ...CACHE_TOKENS, ...UTILITY_TOKENS, } as const @@ -93,6 +99,8 @@ export type TokenMapping = { [TOKENS.LOAD_STATE]: LoadStateFn [TOKENS.COMP_BUTTON]: Button [TOKENS.OBJECT_ONBOARDING_CONFIG]: ScreenOptionsType + [TOKENS.CACHE_CRED_DEFS]: { did: string; id: string }[] + [TOKENS.CACHE_SCHEMAS]: { did: string; id: string }[] [TOKENS.UTIL_LOGGER]: BaseLogger [TOKENS.UTIL_OCA_RESOLVER]: OCABundleResolverType [TOKENS.UTIL_LEDGERS]: IndyVdrPoolConfig[] diff --git a/packages/legacy/core/App/container-impl.ts b/packages/legacy/core/App/container-impl.ts index d4fb7b44e2..ea08f3a5aa 100644 --- a/packages/legacy/core/App/container-impl.ts +++ b/packages/legacy/core/App/container-impl.ts @@ -59,6 +59,8 @@ export class MainContainer implements Container { this._container.registerInstance(TOKENS.UTIL_OCA_RESOLVER, new DefaultOCABundleResolver(bundle)) this._container.registerInstance(TOKENS.UTIL_LEDGERS, defaultIndyLedgers) this._container.registerInstance(TOKENS.UTIL_PROOF_TEMPLATE, useProofRequestTemplates) + this._container.registerInstance(TOKENS.CACHE_CRED_DEFS, []) + this._container.registerInstance(TOKENS.CACHE_SCHEMAS, []) this._container.registerInstance( TOKENS.FN_ONBOARDING_DONE, (dispatch: React.Dispatch>, navigation: StackNavigationProp) => { diff --git a/packages/legacy/core/App/screens/Splash.tsx b/packages/legacy/core/App/screens/Splash.tsx index 6a1b876de0..7497abc18f 100644 --- a/packages/legacy/core/App/screens/Splash.tsx +++ b/packages/legacy/core/App/screens/Splash.tsx @@ -1,13 +1,16 @@ import { Agent, HttpOutboundTransport, WsOutboundTransport } from '@credo-ts/core' +import { IndyVdrPoolService } from '@credo-ts/indy-vdr/build/pool' import { useAgent } from '@credo-ts/react-hooks' import { agentDependencies } from '@credo-ts/react-native' import { RemoteOCABundleResolver } from '@hyperledger/aries-oca/build/legacy' +import { GetCredentialDefinitionRequest, GetSchemaRequest } from '@hyperledger/indy-vdr-shared' import { useNavigation } from '@react-navigation/core' import { CommonActions } from '@react-navigation/native' import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { DeviceEventEmitter, StyleSheet } from 'react-native' import { Config } from 'react-native-config' +import { CachesDirectoryPath } from 'react-native-fs' import { SafeAreaView } from 'react-native-safe-area-context' import { EventTypes } from '../constants' @@ -232,6 +235,11 @@ const Splash: React.FC = () => { modules: getAgentModules({ indyNetworks: indyLedgers, mediatorInvitationUrl: Config.MEDIATOR_URL, + txnCache: { + capacity: 1000, + expiryOffsetMs: 1000 * 60 * 60 * 24 * 7, + path: CachesDirectoryPath + '/txn-cache', + }, }), }) const wsTransport = new WsOutboundTransport() @@ -257,6 +265,22 @@ const Splash: React.FC = () => { await createLinkSecretIfRequired(newAgent) + const credDefs = container.resolve(TOKENS.CACHE_CRED_DEFS) + const schemas = container.resolve(TOKENS.CACHE_SCHEMAS) + + const poolService = newAgent.dependencyManager.resolve(IndyVdrPoolService) + credDefs.forEach(async ({ did, id }) => { + const pool = await poolService.getPoolForDid(newAgent.context, did) + const credDefRequest = new GetCredentialDefinitionRequest({ credentialDefinitionId: id }) + await pool.pool.submitRequest(credDefRequest) + }) + + schemas.forEach(async ({ did, id }) => { + const pool = await poolService.getPoolForDid(newAgent.context, did) + const schemaRequest = new GetSchemaRequest({ schemaId: id }) + await pool.pool.submitRequest(schemaRequest) + }) + setAgent(newAgent) navigation.dispatch( CommonActions.reset({ diff --git a/packages/legacy/core/package.json b/packages/legacy/core/package.json index 2e45ab5a66..1bade51925 100644 --- a/packages/legacy/core/package.json +++ b/packages/legacy/core/package.json @@ -61,6 +61,7 @@ "@hyperledger/aries-bifold-verifier": "^1.0.0", "@hyperledger/aries-oca": "^1.0.0", "@hyperledger/indy-vdr-react-native": "0.2.2", + "@hyperledger/indy-vdr-shared": "0.2.2", "@react-native-async-storage/async-storage": "1.15.11", "@react-native-community/eslint-config": "^3.2.0", "@react-native-community/eslint-plugin": "^1.3.0", @@ -165,6 +166,7 @@ "@hyperledger/aries-bifold-verifier": "^1.0.0", "@hyperledger/aries-oca": "^1.0.0", "@hyperledger/indy-vdr-react-native": "0.2.2", + "@hyperledger/indy-vdr-shared": "0.2.2", "@react-native-async-storage/async-storage": "1.15.11", "@react-native-community/masked-view": "0.1.11", "@react-native-community/netinfo": "^9.3.0", diff --git a/yarn.lock b/yarn.lock index ac754be499..af057ab5b2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4451,6 +4451,7 @@ __metadata: "@hyperledger/aries-bifold-verifier": ^1.0.0 "@hyperledger/aries-oca": ^1.0.0 "@hyperledger/indy-vdr-react-native": 0.2.2 + "@hyperledger/indy-vdr-shared": 0.2.2 "@react-native-async-storage/async-storage": 1.15.11 "@react-native-community/eslint-config": ^3.2.0 "@react-native-community/eslint-plugin": ^1.3.0 @@ -4554,6 +4555,7 @@ __metadata: "@hyperledger/aries-bifold-verifier": ^1.0.0 "@hyperledger/aries-oca": ^1.0.0 "@hyperledger/indy-vdr-react-native": 0.2.2 + "@hyperledger/indy-vdr-shared": 0.2.2 "@react-native-async-storage/async-storage": 1.15.11 "@react-native-community/masked-view": 0.1.11 "@react-native-community/netinfo": ^9.3.0