Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rest)!: update AFJ to 0.4.0 #222

Prev Previous commit
Next Next commit
Configuration improvements
Signed-off-by: Matthew Dean <matthew.dean@digicatapult.org.uk>
  • Loading branch information
mattdean-digicatapult committed Aug 21, 2023
commit 0418ab9abf430ee3a57be5a9590a62019654c1bb
19 changes: 13 additions & 6 deletions packages/rest/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@ const parsed = yargs
})
.option('indy-ledger', {
array: true,
// TODO: this default is invalid, fixme
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem here is that you cannot pass an empty array to IndyVdrModule's network object, right?. I think you can instance IndyVdrModule only in case this object has at least a network. Otherwise it will not be meaningful to have such module (as it will not be able to resolve or register any did/anoncreds object).

So my suggestion here is to first prepare agent modules and then instantiate the Agent passing them in constructor parameters (like we did in AFJ demo or tests with getXXAgentModules()).

default: [],
coerce: (items: unknown[]) => items.map((i) => (typeof i === 'string' ? JSON.parse(i) : i)),
})
.option('public-did-seed', {
string: true,
})
.option('endpoint', {
array: true,
})
.option('log-level', {
number: true,
default: 3,
})
.option('use-legacy-did-sov-prefix', {
.option('use-did-sov-prefix-where-allowed', {
boolean: true,
default: false,
})
.option('use-did-key-in-protocols', {
boolean: true,
default: true,
})
.option('outbound-transport', {
default: [],
choices: ['http', 'ws'],
Expand Down Expand Up @@ -88,6 +90,10 @@ const parsed = yargs
choices: ['always', 'never', 'contentApproved'],
default: 'never',
})
.option('auto-update-storage-on-startup', {
boolean: true,
default: true,
})
.option('connection-image-url', {
string: true,
})
Expand All @@ -110,13 +116,14 @@ export async function runCliServer() {
key: parsed['wallet-key'],
},
indyLedgers: parsed['indy-ledger'],
publicDidSeed: parsed['public-did-seed'],
endpoints: parsed.endpoint,
autoAcceptConnections: parsed['auto-accept-connections'],
autoAcceptCredentials: parsed['auto-accept-credentials'],
autoAcceptProofs: parsed['auto-accept-proofs'],
autoUpdateStorageOnStartup: parsed['auto-update-storage-on-startup'],
autoAcceptMediationRequests: parsed['auto-accept-mediation-requests'],
useLegacyDidSovPrefix: parsed['use-legacy-did-sov-prefix'],
useDidKeyInProtocols: parsed['use-did-key-in-protocols'],
useDidSovPrefixWhereAllowed: parsed['use-legacy-did-sov-prefix'],
logLevel: parsed['log-level'],
inboundTransports: parsed['inbound-transport'],
outboundTransports: parsed['outbound-transport'],
Expand Down
20 changes: 14 additions & 6 deletions packages/rest/src/cliAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
CredentialsModule,
AutoAcceptCredential,
AutoAcceptProof,
MediatorModule,
} from '@aries-framework/core'
import { IndyVdrAnonCredsRegistry, IndyVdrModule } from '@aries-framework/indy-vdr'
import { agentDependencies, HttpInboundTransport, WsInboundTransport } from '@aries-framework/node'
Expand Down Expand Up @@ -45,14 +46,14 @@ const outboundTransportMapping = {
export interface AriesRestConfig {
label: string
walletConfig: WalletConfig
// TODO: is there a sane default to keep this optional
indyLedgers: [IndyVdrPoolConfig, ...IndyVdrPoolConfig[]]
publicDidSeed?: string
endpoints?: string[]
autoAcceptConnections?: boolean
autoAcceptCredentials?: AutoAcceptCredential
autoAcceptProofs?: AutoAcceptProof
useLegacyDidSovPrefix?: boolean
autoUpdateStorageOnStartup?: boolean
useDidKeyInProtocols?: boolean
useDidSovPrefixWhereAllowed?: boolean
logLevel?: LogLevel
inboundTransports?: InboundTransport[]
outboundTransports?: Transports[]
Expand All @@ -78,6 +79,10 @@ export async function runRestAgent(restConfig: AriesRestConfig) {
webhookUrl,
adminPort,
indyLedgers,
autoAcceptConnections = true,
autoAcceptCredentials = AutoAcceptCredential.ContentApproved,
autoAcceptMediationRequests = true,
autoAcceptProofs = AutoAcceptProof.ContentApproved,
...afjConfig
} = restConfig

Expand All @@ -93,13 +98,13 @@ export async function runRestAgent(restConfig: AriesRestConfig) {
dependencies: agentDependencies,
modules: {
connections: new ConnectionsModule({
autoAcceptConnections: true,
autoAcceptConnections,
}),
proofs: new ProofsModule({
autoAcceptProofs: AutoAcceptProof.ContentApproved,
autoAcceptProofs,
}),
credentials: new CredentialsModule({
autoAcceptCredentials: AutoAcceptCredential.ContentApproved,
autoAcceptCredentials,
}),
indyVdr: new IndyVdrModule({
indyVdr,
Expand All @@ -114,6 +119,9 @@ export async function runRestAgent(restConfig: AriesRestConfig) {
askar: new AskarModule({
ariesAskar,
}),
mediator: new MediatorModule({
autoAcceptMediationRequests,
}),
},
})

Expand Down
5 changes: 5 additions & 0 deletions packages/rest/src/utils/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
CredentialsModule,
HttpOutboundTransport,
LogLevel,
MediatorModule,
ProofsModule,
} from '@aries-framework/core'
import { IndyVdrAnonCredsRegistry, IndyVdrModule } from '@aries-framework/indy-vdr'
Expand All @@ -32,6 +33,7 @@ export type RestAgent = Agent<{
anoncredsRs: AnonCredsRsModule
anoncreds: AnonCredsModule
askar: AskarModule
mediator: MediatorModule
}>

export const genesisPath = process.env.GENESIS_TXN_PATH
Expand Down Expand Up @@ -81,6 +83,9 @@ export const setupAgent = async ({ name, endpoints, port }: { name: string; endp
askar: new AskarModule({
ariesAskar,
}),
mediator: new MediatorModule({
autoAcceptMediationRequests: true,
}),
},
})

Expand Down