dhiway / cord.js

Cord JS API
Apache License 2.0
36 stars 48 forks source link

support for nested selective disclosure #109

Closed smohan-dw closed 1 year ago

smohan-dw commented 1 year ago

Support for nested selective disclosure by using a flattened content model. This PR also has a breaking change on createPresentation call. not supported - selective disclosure of array values

interface CreatePresentationOptions {
  document: IDocument;
  signCallback: SignCallback;
  selectedAttributes?: string[];
  challenge?: string;
}

Modified createPresentation function:

export async function createPresentation({
  document,
  signCallback,
  selectedAttributes = [],
  challenge,
}: CreatePresentationOptions): Promise<IDocumentPresentation> {
  // ... (rest of the function remains unchanged)
}

We can now call the function with just the properties you need. It makes the call more readable and easily extensible.

const presentation = await createPresentation({
    document: document,
    signCallback: async ({ data }) => ({
      signature: holderKeys.authentication.sign(data),
      keyType: holderKeys.authentication.type,
      keyUri: `${holderDid.uri}${holderDid.authentication[0].id}`,
    }),
    // selectedAttributes: ['name', 'id', 'address.pin', 'address.location', 'address'],
    challenge: challenge
});

In the call above, we can easily omit selectedAttributes. If you want to include selectedAttributes, you can add that property to the options object.

This structure allows for much cleaner function calls, especially when a function has several parameters, and some of them are optional. We should refactor other calls to follow this model.

amarts commented 1 year ago

Yet to run the tests, and understand it more. Don't yet merge. ETA: 9th, Aug, 2023