From 2899b4b004664f42431fef61af769957f6d63095 Mon Sep 17 00:00:00 2001 From: Sai Ranjit Tummalapalli Date: Wed, 21 Feb 2024 13:22:18 +0530 Subject: [PATCH] feat: add question answer module Signed-off-by: Sai Ranjit Tummalapalli --- packages/ssi/package.json | 1 + packages/ssi/src/agent/agent.ts | 4 +- packages/ssi/src/index.ts | 7 ++- packages/ssi/src/questionAnswer/index.ts | 1 + .../ssi/src/questionAnswer/questionAnswer.ts | 50 +++++++++++++++++++ pnpm-lock.yaml | 49 +++--------------- 6 files changed, 67 insertions(+), 45 deletions(-) create mode 100644 packages/ssi/src/questionAnswer/index.ts create mode 100644 packages/ssi/src/questionAnswer/questionAnswer.ts diff --git a/packages/ssi/package.json b/packages/ssi/package.json index 8567588..5f500d8 100644 --- a/packages/ssi/package.json +++ b/packages/ssi/package.json @@ -30,6 +30,7 @@ "@aries-framework/core": "0.4.2", "@aries-framework/indy-vdr": "0.4.2", "@aries-framework/push-notifications": "^0.6.0", + "@aries-framework/question-answer": "0.4.2", "@aries-framework/react-hooks": "0.5.0", "@aries-framework/react-native": "0.4.2" }, diff --git a/packages/ssi/src/agent/agent.ts b/packages/ssi/src/agent/agent.ts index 058b0f1..2e0c621 100644 --- a/packages/ssi/src/agent/agent.ts +++ b/packages/ssi/src/agent/agent.ts @@ -39,6 +39,7 @@ import { IndyVdrSovDidResolver } from '@aries-framework/indy-vdr' import { PushNotificationsFcmModule } from '@aries-framework/push-notifications' +import { QuestionAnswerModule } from '@aries-framework/question-answer' import { agentDependencies } from '@aries-framework/react-native' import { anoncreds } from '@hyperledger/anoncreds-react-native' import { ariesAskar } from '@hyperledger/aries-askar-react-native' @@ -99,7 +100,8 @@ export const getAgentModules = ( connections: new ConnectionsModule({ autoAcceptConnections: true }), - pushNotificationsFcm: new PushNotificationsFcmModule() + pushNotificationsFcm: new PushNotificationsFcmModule(), + questionAnswer: new QuestionAnswerModule() } } diff --git a/packages/ssi/src/index.ts b/packages/ssi/src/index.ts index 018218c..cb17abb 100644 --- a/packages/ssi/src/index.ts +++ b/packages/ssi/src/index.ts @@ -77,7 +77,8 @@ import { ConnectionEventTypes, CredentialEventTypes, ProofEventTypes, - Query + Query, + utils } from '@aries-framework/core' import { GetCredentialsForRequestReturn, @@ -103,6 +104,7 @@ export * from './proofs' export * from './basicMessages' export * from './pushNotifications' export * from './genericRecords' +export * from './questionAnswer' // Core export { LogLevel, @@ -152,7 +154,8 @@ export { ProofEventTypes, GenericRecord, SaveGenericRecordOption, - Query + Query, + utils } // Anoncreds export { diff --git a/packages/ssi/src/questionAnswer/index.ts b/packages/ssi/src/questionAnswer/index.ts new file mode 100644 index 0000000..1e34884 --- /dev/null +++ b/packages/ssi/src/questionAnswer/index.ts @@ -0,0 +1 @@ +export * from './questionAnswer' diff --git a/packages/ssi/src/questionAnswer/questionAnswer.ts b/packages/ssi/src/questionAnswer/questionAnswer.ts new file mode 100644 index 0000000..d112a90 --- /dev/null +++ b/packages/ssi/src/questionAnswer/questionAnswer.ts @@ -0,0 +1,50 @@ +import type { Agent, Query } from '@aries-framework/core' +import type { QuestionAnswerRecord, ValidResponse } from '@aries-framework/question-answer' + +export type SendQuestionConfig = { + question: string + validResponses: ValidResponse[] + detail?: string +} + +/** + * Sends a question to the connection with the given connection id. + * + * @param agent The agent instance . + * @param connectionId The connection id. + * @param config The question to send. + */ +export const sendQuestion = async (agent: Agent, connectionId: string, config: SendQuestionConfig) => { + return agent.modules.questionAnswer.sendQuestion(connectionId, config) +} + +/** + * Sends an answer to the question with the given question record id. + * + * @param agent The agent instance. + * @param questionRecordId The question record id. + * @param response The response to send. + */ +export const sendAnswer = async (agent: Agent, questionRecordId: string, response: string) => { + return agent.modules.questionAnswer.sendAnswer(questionRecordId, response) +} + +/** + * Retrieves the question record with the given id. + * + * @param agent The agent instance. + * @param query The query to use to find the question record. + */ +export const getQuestion = async (agent: Agent, query: Query) => { + return agent.modules.questionAnswer.findAllByQuery(query) +} + +/** + * Retrieves the question answer record with the given id. + * + * @param agent The agent instance. + * @param questionAnswerRecordId The question record id. + */ +export const getQuestionAnswerRecordById = async (agent: Agent, questionRecordId: string) => { + return agent.modules.questionAnswer.findById(questionRecordId) +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e9cdbef..158b8b0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -83,6 +83,9 @@ importers: '@aries-framework/push-notifications': specifier: ^0.6.0 version: 0.6.0(@aries-framework/core@0.4.2) + '@aries-framework/question-answer': + specifier: 0.4.2 + version: 0.4.2(expo@49.0.13)(react-native@0.71.13) '@aries-framework/react-hooks': specifier: 0.5.0 version: 0.5.0(@aries-framework/core@0.4.2)(expo@49.0.13)(react-native@0.71.13)(react@18.2.0) @@ -179,44 +182,6 @@ packages: - web-streams-polyfill dev: false - /@aries-framework/core@0.4.1(expo@49.0.13)(react-native@0.71.13): - resolution: {integrity: sha512-5DV4Drbqjs1u0j06swMFtsVPyEwJJ9XB1h0XvHOfZKDrYKujVY0zkfpzDJrqKWw8I7B5L7K56XFKlRJ3jRCBNA==} - dependencies: - '@digitalcredentials/jsonld': 5.2.2(expo@49.0.13)(react-native@0.71.13) - '@digitalcredentials/jsonld-signatures': 9.3.2(expo@49.0.13)(react-native@0.71.13) - '@digitalcredentials/vc': 1.1.2(expo@49.0.13)(react-native@0.71.13) - '@multiformats/base-x': 4.0.1 - '@stablelib/ed25519': 1.0.3 - '@stablelib/random': 1.0.2 - '@stablelib/sha256': 1.0.1 - '@types/ws': 8.5.6 - abort-controller: 3.0.0 - big-integer: 1.6.51 - borc: 3.0.0 - buffer: 6.0.3 - class-transformer: 0.5.1 - class-validator: 0.14.0 - did-resolver: 4.1.0 - lru_map: 0.4.1 - luxon: 3.4.3 - make-error: 1.3.6 - node-fetch: 2.7.0 - object-inspect: 1.12.3 - query-string: 7.1.3 - reflect-metadata: 0.1.13 - rxjs: 7.8.1 - tsyringe: 4.8.0 - uuid: 9.0.1 - varint: 6.0.0 - web-did-resolver: 2.0.27 - transitivePeerDependencies: - - domexception - - encoding - - expo - - react-native - - web-streams-polyfill - dev: false - /@aries-framework/core@0.4.2(expo@49.0.13)(react-native@0.71.13): resolution: {integrity: sha512-2qmDRkxD5vnPlcMjVTqu/Wxog9bUVU+tSr+7mgANgJ9q170FuoSuChU7WA5VCKEdmbRIM4BmvsnTlU8Y+iQ07A==} dependencies: @@ -283,10 +248,10 @@ packages: tsyringe: 4.8.0 dev: false - /@aries-framework/question-answer@0.4.1(expo@49.0.13)(react-native@0.71.13): - resolution: {integrity: sha512-6AZ2E5A1HVXQ2Ss2BZPxyMzncWTp6giCiGh2FURXNoHHXt46K6x1h8rDqNmNv4Hvp+/ciurG2CFlmL2sulFteg==} + /@aries-framework/question-answer@0.4.2(expo@49.0.13)(react-native@0.71.13): + resolution: {integrity: sha512-rk1ODjPjOjDsjUuEJ/A8vkiW3MPpCoQk1SaVrUVKvtyPFN52oPWvzANImGHFce0E/S440yBxYIr152JlRELb0w==} dependencies: - '@aries-framework/core': 0.4.1(expo@49.0.13)(react-native@0.71.13) + '@aries-framework/core': 0.4.2(expo@49.0.13)(react-native@0.71.13) class-transformer: 0.5.1 class-validator: 0.14.0 rxjs: 7.8.1 @@ -305,7 +270,7 @@ packages: react: '>=17.0.0 <19.0.0' dependencies: '@aries-framework/core': 0.4.2(expo@49.0.13)(react-native@0.71.13) - '@aries-framework/question-answer': 0.4.1(expo@49.0.13)(react-native@0.71.13) + '@aries-framework/question-answer': 0.4.2(expo@49.0.13)(react-native@0.71.13) '@types/node-fetch': 2.6.6 react: 18.2.0 rxjs: 7.8.1