openwallet-foundation / credo-ts

Typescript framework for building decentralized identity and verifiable credential solutions
https://credo.js.org
Apache License 2.0
262 stars 199 forks source link

Correctly type the return values when creating schemas, credential definitions and dids #1465

Open auer-martin opened 1 year ago

auer-martin commented 1 year ago

The return types are not correctly typed, and therefore need to be casted. See the snippet below.

          (await agent.modules.anoncreds.registerCredentialDefinition<IndyVdrRegisterCredentialDefinitionOptions>(
            {
              credentialDefinition,
              options: {
                endorserMode: 'external',
                endorserDid,
              },
            }
          )) as IndyVdrRegisterCredentialDefinitionReturn
hs2361 commented 1 year ago

Hi @2mau, I'm new to AFJ and I'd like to start contributing by working on this issue. From what I found, https://github.com/hyperledger/aries-framework-javascript/blob/bd4932d34f7314a6d49097b6460c7570e1ebc7a8/packages/indy-vdr/src/anoncreds/IndyVdrAnonCredsRegistry.ts#L307-L310

the function signature does seem to have the correct types. Could you please elaborate as to what changes this issue is supposed to encompass, since I'm new to the code base?

auer-martin commented 1 year ago

Hi, @hs2361. I'll try to explain the problem to you in more detail, but I'm not 100% sure if this is the right way. Maybe @TimoGlastra can also take a look at this problem, and give his opinion.

For anoncreds, there is an API called AnoncredsApi which is the public-facing part. In this file, you can find the registerCredentialDefinition and registerSchema functions. Currently, registerCredentialDefinition allows Providing a generic Type T to type its input values. The issue is that by typing the Input values as IndyVdrRegisterCredentialDefinitionOptions the return value should become IndyVdrRegisterCredentialDefinitionReturn, but instead the more Generic RegisterCredentialDefinitionReturn type is used, that is why the cast is required. In the IndyVdrAnonCredsRegistry (the snippet you posted), the typing is still correct, but it is not correctly propagated towards the public-facing part of the API.

I think we need to find solutions here in multiple places.