Skip to content

Commit

Permalink
feat: add option to use indy vdr proxy (#1182)
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce McMath <[email protected]>
  • Loading branch information
bryce-mcmath authored Jun 27, 2024
1 parent 001c6c5 commit 2cda573
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/legacy/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@react-navigation/native": "6.0.6",
"@react-navigation/stack": "6.0.11",
"axios": "^1.4.0",
"credo-ts-indy-vdr-proxy-client": "0.1.2",
"i18next": "^21.4.0",
"lodash.flatten": "^4.4.0",
"lodash.startcase": "^4.4.0",
Expand Down
48 changes: 42 additions & 6 deletions packages/legacy/core/App/utils/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,42 @@ import {
ProofsModule,
V2CredentialProtocol,
V2ProofProtocol,
DidsModule,
} from '@credo-ts/core'
import { IndyVdrAnonCredsRegistry, IndyVdrModule, IndyVdrPoolConfig } from '@credo-ts/indy-vdr'
import { PushNotificationsApnsModule, PushNotificationsFcmModule } from '@credo-ts/push-notifications'
import { useAgent } from '@credo-ts/react-hooks'
import { anoncreds } from '@hyperledger/anoncreds-react-native'
import { ariesAskar } from '@hyperledger/aries-askar-react-native'
import { indyVdr } from '@hyperledger/indy-vdr-react-native'
import { IndyVdrProxyAnonCredsRegistry, IndyVdrProxyDidResolver, CacheSettings } from 'credo-ts-indy-vdr-proxy-client'

interface GetAgentModulesOptions {
indyNetworks: IndyVdrPoolConfig[]
mediatorInvitationUrl?: string
txnCache?: { capacity: number; expiryOffsetMs: number; path?: string }
proxyBaseUrl?: string
proxyCacheSettings?: CacheSettings
}

export type BifoldAgent = Agent<ReturnType<typeof getAgentModules>>

export function getAgentModules({ indyNetworks, mediatorInvitationUrl, txnCache }: GetAgentModulesOptions) {
/**
* Constructs the modules to be used in the agent setup
* @param indyNetworks
* @param mediatorInvitationUrl determine which mediator to use
* @param txnCache optional local cache config for indyvdr
* @param proxyBaseUrl optional indy vdr proxy url to sidestep ZMQ firewall issues
* @param proxyCacheSettings optional cache settings for the proxy
* @returns modules to be used in agent setup
*/
export function getAgentModules({
indyNetworks,
mediatorInvitationUrl,
txnCache,
proxyBaseUrl,
proxyCacheSettings,
}: GetAgentModulesOptions) {
const indyCredentialFormat = new LegacyIndyCredentialFormatService()
const indyProofFormat = new LegacyIndyProofFormatService()

Expand All @@ -49,14 +68,10 @@ export function getAgentModules({ indyNetworks, mediatorInvitationUrl, txnCache
})
}

return {
const modules = {
askar: new AskarModule({
ariesAskar,
}),
anoncreds: new AnonCredsModule({
anoncreds,
registries: [new IndyVdrAnonCredsRegistry()],
}),
indyVdr: new IndyVdrModule({
indyVdr,
networks: indyNetworks as [IndyVdrPoolConfig],
Expand Down Expand Up @@ -97,6 +112,27 @@ export function getAgentModules({ indyNetworks, mediatorInvitationUrl, txnCache
pushNotificationsFcm: new PushNotificationsFcmModule(),
pushNotificationsApns: new PushNotificationsApnsModule(),
}

if (proxyBaseUrl) {
return {
...modules,
anoncreds: new AnonCredsModule({
anoncreds,
registries: [new IndyVdrProxyAnonCredsRegistry({ proxyBaseUrl, cacheOptions: proxyCacheSettings })],
}),
dids: new DidsModule({
resolvers: [new IndyVdrProxyDidResolver(proxyBaseUrl)],
}),
}
}

return {
...modules,
anoncreds: new AnonCredsModule({
anoncreds,
registries: [new IndyVdrAnonCredsRegistry()],
}),
}
}

interface MyAgentContextInterface {
Expand Down
2 changes: 2 additions & 0 deletions packages/legacy/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"babel-jest": "^27.5.1",
"babel-plugin-module-resolver": "^5.0.0",
"commitlint": "^17.7.1",
"credo-ts-indy-vdr-proxy-client": "0.1.2",
"eslint": "^8.48.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.28.1",
Expand Down Expand Up @@ -174,6 +175,7 @@
"@react-navigation/native": "6.0.6",
"@react-navigation/stack": "6.0.11",
"axios": "^1.4.0",
"credo-ts-indy-vdr-proxy-client": "0.1.2",
"i18next": "^21.4.0",
"lodash.flatten": "^4.4.0",
"lodash.startcase": "^4.4.0",
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4476,6 +4476,7 @@ __metadata:
babel-jest: ^27.5.1
babel-plugin-module-resolver: ^5.0.0
commitlint: ^17.7.1
credo-ts-indy-vdr-proxy-client: 0.1.2
eslint: ^8.48.0
eslint-import-resolver-typescript: ^2.5.0
eslint-plugin-import: ^2.28.1
Expand Down Expand Up @@ -4563,6 +4564,7 @@ __metadata:
"@react-navigation/native": 6.0.6
"@react-navigation/stack": 6.0.11
axios: ^1.4.0
credo-ts-indy-vdr-proxy-client: 0.1.2
i18next: ^21.4.0
lodash.flatten: ^4.4.0
lodash.startcase: ^4.4.0
Expand Down Expand Up @@ -8351,6 +8353,7 @@ __metadata:
"@types/react-native": 0.71.5
axios: ^1.4.0
babel-plugin-module-resolver: ^5.0.0
credo-ts-indy-vdr-proxy-client: 0.1.2
eslint: ^8.48.0
eslint-import-resolver-typescript: ^2.5.0
i18next: ^21.4.0
Expand Down Expand Up @@ -10622,6 +10625,17 @@ __metadata:
languageName: node
linkType: hard

"credo-ts-indy-vdr-proxy-client@npm:0.1.2":
version: 0.1.2
resolution: "credo-ts-indy-vdr-proxy-client@npm:0.1.2"
dependencies:
"@credo-ts/anoncreds": 0.5.3
"@credo-ts/core": 0.5.3
uuid: ^9.0.0
checksum: ee005b26786ff9562150b42d6a8166610ffb72f4f6674672401eb70a3a0db1d2b462ef3af667ba6802c1c65a4673f5215b92f9ae086cfe4463e36d5b57981c8a
languageName: node
linkType: hard

"cross-fetch@npm:^3.1.5":
version: 3.1.5
resolution: "cross-fetch@npm:3.1.5"
Expand Down

0 comments on commit 2cda573

Please sign in to comment.