Closed janrtvld closed 1 year ago
You need to provide the credentials module with the correct typing to work. By default the OfferCredentialOptions
interface doesn't have any formats / protocol versions. Two options.
Use the agent method input (will help if the types change)
@Post('/offer-credential')
public async offerCredential(@Body() options: Parameters<Agent['credentials']['offerCredential']>[0]) {
try {
const credential = await this.agent.credentials.offerCredential(options)
return credential.toJSON()
} catch (error) {
...
}
Add the needed types to the interface
@Post('/offer-credential')
public async offerCredential(@Body() options: OfferCredentialOptions<[IndyCredentialFormat], [V1CredentialService, V2CredentialService]>) {
try {
const credential = await this.agent.credentials.offerCredential(options)
return credential.toJSON()
} catch (error) {
...
}
However this was one of the issues I opened in TSOA as it doesn't infer the type of the interface correctly. It will infer it as:
{
protocolVersion: string
credentialFormats: {}
}
While it should actually be a deeply nested type. To get around this, I had to declare it like this manually:
type CredentialFormats = [IndyCredentialFormat]
type CredentialServices = [V1CredentialService, V2CredentialService]
interface OfferCredentialOptions {
// update to ProtocolVersionType<CredentialServices> once https://github.com/hyperledger/aries-framework-javascript/pull/903 has been merged
protocolVersion: ProtocolVersionType<CredentialFormats, CredentialServices>
credentialFormats: CredentialFormatPayload<CredentialFormats, 'createOffer'>
autoAcceptCredential?: AutoAcceptCredential
comment?: string
}
I'm getting the following error when using the OfferCredentialOptions
you've described:
{
"message": "something went wrong",
"error": {
"message": "No credential service registered for protocol version V1",
"name": "AriesFrameworkError",
"stack": "AriesFrameworkError: No credential service registered for protocol version V1\n at CredentialsModule.getService (/Users/jan/Developer/aries-framework-javascript-ext/node_modules/@aries-framework/core/src/modules/credentials/CredentialsModule.ts:135:13)\n at CredentialsModule.offerCredential (/Users/jan/Developer/aries-framework-javascript-ext/node_modules/@aries-framework/core/src/modules/credentials/CredentialsModule.ts:253:26)\n at CredentialController.offerCredential (/Users/jan/Developer/aries-framework-javascript-ext/packages/rest/src/controllers/credentials/file:/Users/jan/Developer/aries-framework-javascript-ext/packages/rest/src/controllers/credentials/CredentialController.ts:152:26)"
}
}
Payload:
{
"connectionId":"2aecf74c-3073-4f98-9acb-92415d096834",
"protocolVersion":"V1",
"credentialFormats":{
"indy":{
"credentialDefinitionId":"q7ATwTYbQDgiigVijUAej:3:CL:351756:string",
"attributes":[
{
"name":"string",
"value":"test"
}
]
}
}
}
Same error if i put in V2
. Any idea where this is coming from?
it should be v1
;)
Im trying to convert the rest api to use AFJ interfaces. In this case im using the
OfferCredentialOptions
interface to offer a credential.I'm getting the following type error:
If i serialise it it works fine.