Skip to content

Commit

Permalink
feat: proxy setup (#2089)
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce McMath <[email protected]>
  • Loading branch information
bryce-mcmath authored Jul 29, 2024
1 parent 9142f09 commit 0a0226a
Show file tree
Hide file tree
Showing 13 changed files with 232 additions and 119 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
"OCA_URL"
"PROOF_TEMPLATE_URL"
"MEDIATOR_USE_PUSH_NOTIFICATIONS"
"INDY_VDR_PROXY_URL"
)
for var in "${required_env_vars[@]}"; do
if [ -z "${!var}" ]; then
Expand All @@ -74,6 +75,7 @@ jobs:
OCA_URL: ${{ vars.OCA_URL }}
PROOF_TEMPLATE_URL: ${{ vars.PROOF_TEMPLATE_URL }}
MEDIATOR_USE_PUSH_NOTIFICATIONS: ${{ vars.MEDIATOR_USE_PUSH_NOTIFICATIONS }}
INDY_VDR_PROXY_URL: ${{ vars.INDY_VDR_PROXY_URL }}

build-ios:
needs: [check-secrets, check-vars]
Expand Down Expand Up @@ -162,6 +164,7 @@ jobs:
OCA_URL: ${{ vars.OCA_URL }}
PROOF_TEMPLATE_URL: ${{ vars.PROOF_TEMPLATE_URL }}
REMOTE_LOGGING_URL: ${{ secrets.REMOTE_LOGGING_URL }}
INDY_VDR_PROXY_URL: ${{ vars.INDY_VDR_PROXY_URL }}
run: |
echo "MEDIATOR_USE_PUSH_NOTIFICATIONS=${MEDIATOR_USE_PUSH_NOTIFICATIONS}" >.env
echo "MEDIATOR_URL=${MEDIATOR_URL}" >>.env
Expand All @@ -170,6 +173,7 @@ jobs:
echo "OCA_URL=${OCA_URL}" >>.env
echo "PROOF_TEMPLATE_URL=${PROOF_TEMPLATE_URL}" >>.env
echo "REMOTE_LOGGING_URL=${REMOTE_LOGGING_URL}" >>.env
echo "INDY_VDR_PROXY_URL=${INDY_VDR_PROXY_URL}" >>.env
- name: Update APS environment
run: |
Expand Down Expand Up @@ -273,6 +277,7 @@ jobs:
OCA_URL: ${{ vars.OCA_URL }}
PROOF_TEMPLATE_URL: ${{ vars.PROOF_TEMPLATE_URL }}
REMOTE_LOGGING_URL: ${{ secrets.REMOTE_LOGGING_URL }}
INDY_VDR_PROXY_URL: ${{ vars.INDY_VDR_PROXY_URL }}
run: |
echo "MEDIATOR_USE_PUSH_NOTIFICATIONS=${MEDIATOR_USE_PUSH_NOTIFICATIONS}" >.env
echo "MEDIATOR_URL=${MEDIATOR_URL}" >>.env
Expand All @@ -281,6 +286,7 @@ jobs:
echo "OCA_URL=${OCA_URL}" >>.env
echo "PROOF_TEMPLATE_URL=${PROOF_TEMPLATE_URL}" >>.env
echo "REMOTE_LOGGING_URL=${REMOTE_LOGGING_URL}" >>.env
echo "INDY_VDR_PROXY_URL=${INDY_VDR_PROXY_URL}" >>.env
- name: Create release keystore
working-directory: app/android/app
Expand Down
4 changes: 4 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ In the `./app/` directory copy the .env.sample `cp .env.sample .env`

```
MEDIATOR_URL=<url>
OCA_URL=<url>
MEDIATOR_USE_PUSH_NOTIFICATIONS=false
PROOF_TEMPLATE_URL=<url>
REMOTE_LOGGING_URL=<url>
INDY_VDR_PROXY_URL=<url>
```

Push notifications can be used locally if the mediator service has the firebase plugin and it's configured correctly.
Expand Down
5 changes: 4 additions & 1 deletion app/.env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
OCA_URL=https://raw.githubusercontent.com/bcgov/aries-oca-bundles/main/
MEDIATOR_URL=https://f326-207-194-65-204.ngrok.io?c_i=eyJAdHlwZSI6ICJodHRwczovL2RpZGNvbW0ub3JnL2Nvbm5lY3Rpb25zLzEuMC9pbnZpdGF0aW9uIiwgIkBpZCI6ICI2MjQ0ZThiNS0wNWYzLTRhYWItYjM1Yy1lYWVlMWNmZTAyM2MiLCAicmVjaXBpZW50S2V5cyI6IFsiQ3lqM1BHRUJzQ3RyUGFtTTQyRngza3BlYmR2QWdNd1lGejlFS3RmNnlUN3giXSwgImxhYmVsIjogIk1lZGlhdG9yIiwgInNlcnZpY2VFbmRwb2ludCI6ICJodHRwczovL2YzMjYtMjA3LTE5NC02NS0yMDQubmdyb2suaW8ifQ==
MEDIATOR_USE_PUSH_NOTIFICATIONS=false
MEDIATOR_USE_PUSH_NOTIFICATIONS=false
PROOF_TEMPLATE_URL=
REMOTE_LOGGING_URL=
INDY_VDR_PROXY_URL=
4 changes: 3 additions & 1 deletion app/container-imp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class AppContainer implements Container {
let tours = initialState.tours
let onboarding = initialState.onboarding
let personCredOfferDissmissed = initialState.dismissPersonCredentialOffer
let { environment, remoteDebugging } = initialState.developer
let { environment, remoteDebugging, enableProxy } = initialState.developer

await Promise.all([
loadLoginAttempt().then((data) => {
Expand All @@ -191,6 +191,7 @@ export class AppContainer implements Container {
),
loadState<IASEnvironment>(BCLocalStorageKeys.Environment, (val) => (environment = val)),
loadState<RemoteDebuggingState>(BCLocalStorageKeys.RemoteDebugging, (val) => (remoteDebugging = val)),
loadState<boolean>(BCLocalStorageKeys.EnableProxy, (val) => (enableProxy = val)),
])
const state: BCState = {
...initialState,
Expand All @@ -207,6 +208,7 @@ export class AppContainer implements Container {
enabledAt: remoteDebugging.enabledAt ? new Date(remoteDebugging.enabledAt) : undefined,
sessionId: remoteDebugging.sessionId,
},
enableProxy,
},
}

Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@react-navigation/stack": "6.0.11",
"axios": "1.4.0",
"buffer": "6.0.3",
"credo-ts-indy-vdr-proxy-client": "0.1.2",
"credo-ts-indy-vdr-proxy-client": "0.1.3",
"i18next": "21.10.0",
"lodash.flatten": "4.4.0",
"lodash.merge": "4.6.2",
Expand Down
136 changes: 136 additions & 0 deletions app/src/helpers/bc-agent-modules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import {
AnonCredsCredentialFormatService,
AnonCredsModule,
AnonCredsProofFormatService,
DataIntegrityCredentialFormatService,
LegacyIndyCredentialFormatService,
LegacyIndyProofFormatService,
V1CredentialProtocol,
V1ProofProtocol,
} from '@credo-ts/anoncreds'
import { AskarModule } from '@credo-ts/askar'
import {
Agent,
AutoAcceptCredential,
AutoAcceptProof,
ConnectionsModule,
CredentialsModule,
DidsModule,
DifPresentationExchangeProofFormatService,
MediationRecipientModule,
MediatorPickupStrategy,
ProofsModule,
V2CredentialProtocol,
V2ProofProtocol,
} from '@credo-ts/core'
import { DrpcModule } from '@credo-ts/drpc'
import { IndyVdrAnonCredsRegistry, IndyVdrModule, IndyVdrPoolConfig } from '@credo-ts/indy-vdr'
import { PushNotificationsApnsModule, PushNotificationsFcmModule } from '@credo-ts/push-notifications'
import { anoncreds } from '@hyperledger/anoncreds-react-native'
import { ariesAskar } from '@hyperledger/aries-askar-react-native'
import { indyVdr } from '@hyperledger/indy-vdr-react-native'
import { IndyVdrProxyDidResolver, IndyVdrProxyAnonCredsRegistry, CacheSettings } from 'credo-ts-indy-vdr-proxy-client'

export type BCAgent = Agent<ReturnType<typeof getBCAgentModules>>

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

/**
* 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 enableProxy boolean from the store to determine if proxy should be used
* @param proxyBaseUrl URL of indy vdr proxy
* @param proxyCacheSettings settings for above mentioned proxy client caching
* @returns modules to be used in agent setup
*/
export function getBCAgentModules({
indyNetworks,
mediatorInvitationUrl,
txnCache,
enableProxy,
proxyBaseUrl,
proxyCacheSettings,
}: GetBCAgentModulesOptions) {
const indyCredentialFormat = new LegacyIndyCredentialFormatService()
const indyProofFormat = new LegacyIndyProofFormatService()

if (txnCache) {
indyVdr.setLedgerTxnCache({
capacity: txnCache.capacity,
expiry_offset_ms: txnCache.expiryOffsetMs,
path: txnCache.path,
})
}

const modules = {
askar: new AskarModule({
ariesAskar,
}),
anoncreds: new AnonCredsModule({
anoncreds,
registries: [new IndyVdrAnonCredsRegistry()],
}),
indyVdr: new IndyVdrModule({
indyVdr,
networks: indyNetworks as [IndyVdrPoolConfig],
}),
connections: new ConnectionsModule({
autoAcceptConnections: true,
}),
credentials: new CredentialsModule({
autoAcceptCredentials: AutoAcceptCredential.ContentApproved,
credentialProtocols: [
new V1CredentialProtocol({ indyCredentialFormat }),
new V2CredentialProtocol({
credentialFormats: [
indyCredentialFormat,
new AnonCredsCredentialFormatService(),
new DataIntegrityCredentialFormatService(),
],
}),
],
}),
proofs: new ProofsModule({
autoAcceptProofs: AutoAcceptProof.ContentApproved,
proofProtocols: [
new V1ProofProtocol({ indyProofFormat }),
new V2ProofProtocol({
proofFormats: [
indyProofFormat,
new AnonCredsProofFormatService(),
new DifPresentationExchangeProofFormatService(),
],
}),
],
}),
mediationRecipient: new MediationRecipientModule({
mediatorInvitationUrl: mediatorInvitationUrl,
mediatorPickupStrategy: MediatorPickupStrategy.Implicit,
}),
pushNotificationsFcm: new PushNotificationsFcmModule(),
pushNotificationsApns: new PushNotificationsApnsModule(),
dids: new DidsModule(),
drpc: new DrpcModule(),
}

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

return modules
}
1 change: 1 addition & 0 deletions app/src/localization/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const translation = {
"DeveloperMode": "Developer mode",
"Toggle": "Toggle Developer Mode",
"AttestationSupport": "Attestation support",
"EnableProxy": "Enable proxy",
},
"Tips": {
"Header": "Tips",
Expand Down
1 change: 1 addition & 0 deletions app/src/localization/fr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const translation = {
"DeveloperMode": "Mode développeur",
"Toggle": "Activer/Désactiver le mode développeur",
"AttestationSupport": "Soutien d'attestation",
"EnableProxy": "Enable proxy (FR)",
},
"Tips": {
"Header": "Conseils",
Expand Down
1 change: 1 addition & 0 deletions app/src/localization/pt-br/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const translation = {
"DeveloperMode": "Developer mode",
"Toggle": "Toggle Developer Mode",
"AttestationSupport": "Attestation support (PT-BR)",
"EnableProxy": "Enable proxy (PT-BR)",
},
"Tips": {
"Header": "Tips (PT-BR)",
Expand Down
23 changes: 23 additions & 0 deletions app/src/screens/Developer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const Settings: React.FC = () => {
const [preventAutoLock, setPreventAutoLock] = useState(!!store.preferences.preventAutoLock)
const [remoteLoggingEnabled, setRemoteLoggingEnabled] = useState(logger?.remoteLoggingEnabled)
const [enableShareableLink, setEnableShareableLink] = useState(!!store.preferences.enableShareableLink)
const [enableProxy, setEnableProxy] = useState(!!store.developer.enableProxy)
const navigation = useNavigation()

const styles = StyleSheet.create({
Expand Down Expand Up @@ -251,6 +252,14 @@ const Settings: React.FC = () => {
setEnableShareableLink((previousState) => !previousState)
}

const toggleEnableProxySwitch = () => {
dispatch({
type: BCDispatchAction.TOGGLE_PROXY,
payload: [!enableProxy],
})
setEnableProxy((previousState) => !previousState)
}

return (
<SafeAreaView edges={['bottom', 'left', 'right']}>
<Modal
Expand Down Expand Up @@ -427,6 +436,20 @@ const Settings: React.FC = () => {
disabled={!store.authentication.didAuthenticate}
/>
</SectionRow>

<SectionRow
title={t('Developer.EnableProxy')}
accessibilityLabel={t('Developer.EnableProxy')}
testID={testIdWithKey('ToggleEnableProxy')}
>
<Switch
trackColor={{ false: ColorPallet.grayscale.lightGrey, true: ColorPallet.brand.primaryDisabled }}
thumbColor={enableProxy ? ColorPallet.brand.primary : ColorPallet.grayscale.mediumGrey}
ios_backgroundColor={ColorPallet.grayscale.lightGrey}
onValueChange={toggleEnableProxySwitch}
value={enableProxy}
/>
</SectionRow>
</ScrollView>
</SafeAreaView>
)
Expand Down
34 changes: 20 additions & 14 deletions app/src/screens/Splash.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Agent, HttpOutboundTransport, MediatorPickupStrategy, WsOutboundTransport } from '@credo-ts/core'
import { DrpcModule } from '@credo-ts/drpc'
import { IndyVdrPoolConfig, IndyVdrPoolService } from '@credo-ts/indy-vdr/build/pool'
import { useAgent } from '@credo-ts/react-hooks'
import { agentDependencies } from '@credo-ts/react-native'
Expand All @@ -17,7 +16,6 @@ import {
testIdWithKey,
didMigrateToAskar,
migrateToAskar,
getAgentModules,
createLinkSecretIfRequired,
TOKENS,
useContainer,
Expand All @@ -37,6 +35,7 @@ import { SafeAreaView } from 'react-native-safe-area-context'
import ProgressBar from '../components/ProgressBar'
import TipCarousel from '../components/TipCarousel'
import { activate } from '../helpers/PushNotificationsHelper'
import { getBCAgentModules } from '../helpers/bc-agent-modules'
import { useAttestation } from '../hooks/useAttestation'
import { BCState, BCLocalStorageKeys } from '../store'

Expand Down Expand Up @@ -342,20 +341,27 @@ const Splash = () => {
autoAcceptConnections: true,
},
dependencies: agentDependencies,
modules: {
...getAgentModules({
indyNetworks: ledgers,
mediatorInvitationUrl: Config.MEDIATOR_URL,
txnCache: {
capacity: 1000,
expiryOffsetMs: 1000 * 60 * 60 * 24 * 7,
path: CachesDirectoryPath + '/txn-cache',
},
}),
drpc: new DrpcModule(),
},
modules: getBCAgentModules({
indyNetworks: ledgers,
mediatorInvitationUrl: Config.MEDIATOR_URL,
txnCache: {
capacity: 1000,
expiryOffsetMs: 1000 * 60 * 60 * 24 * 7,
path: CachesDirectoryPath + '/txn-cache',
},
enableProxy: store.developer.enableProxy,
proxyBaseUrl: Config.INDY_VDR_PROXY_URL,
proxyCacheSettings: {
allowCaching: true,
cacheDurationInSeconds: 60 * 60 * 24 * 7,
},
}),
}

logger.info(
store.developer.enableProxy && Config.INDY_VDR_PROXY_URL ? 'VDR Proxy enabled' : 'VDR Proxy disabled'
)

const newAgent = new Agent(options)
const wsTransport = new WsOutboundTransport()
const httpTransport = new HttpOutboundTransport()
Expand Down
Loading

0 comments on commit 0a0226a

Please sign in to comment.