From 09061b72e609d39ed91b639cc3876a56c54db0aa Mon Sep 17 00:00:00 2001 From: Sai Ranjit Tummalapalli Date: Thu, 16 Nov 2023 16:37:18 +0530 Subject: [PATCH] feat: add out-of-band methods to delete and fetch records (#16) * feat: add oob methods to delete and fetch records Signed-off-by: Sai Ranjit Tummalapalli * docs: update docs Signed-off-by: Sai Ranjit Tummalapalli --------- Signed-off-by: Sai Ranjit Tummalapalli --- packages/ssi/README.md | 46 ++++++++++++++------- packages/ssi/src/connections/connections.ts | 26 +++++++++++- packages/ssi/src/index.ts | 6 ++- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/packages/ssi/README.md b/packages/ssi/README.md index ba7f1ba..ffeb6de 100644 --- a/packages/ssi/README.md +++ b/packages/ssi/README.md @@ -3,17 +3,19 @@ [![npm](https://img.shields.io/npm/v/@adeya/ssi.svg)](https://www.npmjs.com/package/@adeya/ssi) [![npm](https://img.shields.io/npm/v/@adeya/ssi/alpha.svg)](https://www.npmjs.com/package/@adeya/ssi) -- [Installing](#installing) -- [Usage](#usage) -- [API](#api) - - [Agent](#agent) - - [Wallet](#wallet) - - [Connections](#connections) - - [Credentials](#credentials) - - [Proofs](#proofs) - - [BasicMessages](#basicmessages) - - [PushNotifications](#pushnotifications) - - [Hooks](#hooks) +- [@adeya/ssi](#adeyassi) + - [Installing](#installing) + - [Peer Dependencies](#peer-dependencies) + - [Usage](#usage) + - [API](#api) + - [Agent](#agent) + - [Wallet](#wallet) + - [Connections](#connections) + - [Credentials](#credentials) + - [Proofs](#proofs) + - [BasicMessages](#basicmessages) + - [PushNotifications](#pushnotifications) + - [Hooks](#hooks) ## Installing @@ -201,12 +203,28 @@ import { findOutOfBandRecordById } from '@adeya/ssi' const record = await findOutOfBandRecordById(agent, recordId) ``` -- deleteConnectionById - Delete a connection by id. +- findByReceivedInvitationId - Find an out of band record by received invitation id. ```ts -import { deleteConnectionById } from '@adeya/ssi' +import { findByReceivedInvitationId } from '@adeya/ssi' -await deleteConnectionById(agent, connectionId) +const record = await findByReceivedInvitationId(agent, receivedInvitationId) +``` + +- deleteConnectionRecordById - Delete a connection record by id. + +```ts +import { deleteConnectionRecordById } from '@adeya/ssi' + +await deleteConnectionRecordById(agent, connectionId) +``` + +- deleteOobRecordById - Delete a out-of-band record by id. + +```ts +import { deleteOobRecordById } from '@adeya/ssi' + +await deleteOobRecordById(agent, outOfBandId) ``` ### Credentials diff --git a/packages/ssi/src/connections/connections.ts b/packages/ssi/src/connections/connections.ts index f57f732..d460e53 100644 --- a/packages/ssi/src/connections/connections.ts +++ b/packages/ssi/src/connections/connections.ts @@ -176,12 +176,34 @@ export const findOutOfBandRecordById = async (agent: Agent, connectionId: string } /** - * Deletes a connection by its ID. + * Finds an out-of-band record by its invitation ID. + * + * @param agent The agent instance to use for finding the out-of-band record. + * @param receivedInvitationId The ID of the invitation to find. + * @returns A Promise that resolves to the out-of-band record with the given ID. + */ +export const findByReceivedInvitationId = async (agent: Agent, receivedInvitationId: string) => { + return agent.oob.findByReceivedInvitationId(receivedInvitationId) +} + +/** + * Deletes a connection record by its ID. * * @param connectionId The ID of the connection to be deleted. * @returns A boolean indicating whether the connection was successfully deleted or not. */ -export const deleteConnectionById = async (agent: Agent, connectionId: string) => { +export const deleteConnectionRecordById = async (agent: Agent, connectionId: string) => { await agent.connections.deleteById(connectionId) return true } + +/** + * Deletes an out-of-band record by its ID. + * + * @param outOfBandId The ID of the out-of-band record to be deleted. + * @returns A boolean indicating whether the out-of-band record was successfully deleted or not. + */ +export const deleteOobRecordById = async (agent: Agent, outOfBandId: string) => { + await agent.oob.deleteById(outOfBandId) + return true +} diff --git a/packages/ssi/src/index.ts b/packages/ssi/src/index.ts index afd3307..dd7bc72 100644 --- a/packages/ssi/src/index.ts +++ b/packages/ssi/src/index.ts @@ -65,7 +65,8 @@ import { V2ProofProtocol, ConnectionsModule, Agent, - BasicMessageRepository + BasicMessageRepository, + AriesFrameworkError } from '@aries-framework/core' import { GetCredentialsForRequestReturn, @@ -129,7 +130,8 @@ export { V2ProofProtocol, ConnectionsModule, Agent, - BasicMessageRepository + BasicMessageRepository, + AriesFrameworkError } // Anoncreds export {