Skip to content

Commit

Permalink
feat: add generic record methods (#18)
Browse files Browse the repository at this point in the history
Signed-off-by: Sai Ranjit Tummalapalli <sairanjit.tummalapalli@ayanworks.com>
  • Loading branch information
sairanjit authored Jan 8, 2024
1 parent a709626 commit 1a55bb9
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/ssi/src/credentials/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
CredentialExchangeRecord,
CredentialProtocol,
DeleteCredentialOptions,
ProposeCredentialOptions,
SendCredentialProblemReportOptions
} from '@aries-framework/core'

Expand All @@ -28,6 +29,17 @@ export const getFormattedCredentialData = async (agent: Agent, credentialRecordI
return agent.credentials.getFormatData(credentialRecordId)
}

/**
* Propose a credential to connection.
*
* @param agent The agent instance to use for accepting the credential offer.
* @param options - The options for proposing the credential.
* @returns A promise that resolves with the proposed credential.
*/
export const proposeCredential = async (agent: Agent, options: ProposeCredentialOptions<[]>) => {
return agent.credentials.proposeCredential(options)
}

/**
* Accepts a credential offer.
*
Expand Down
79 changes: 79 additions & 0 deletions packages/ssi/src/genericRecords/genericRecords.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import type { Agent, Query } from '@aries-framework/core'
import type {
GenericRecord,
SaveGenericRecordOption
} from '@aries-framework/core/build/modules/generic-records/repository/GenericRecord'

/**
* Retrieves all credential exchange records from the agent.
*
* @param agent The agent instance to use for retrieving the credential exchange records.
* @returns A promise that resolves to an array of credential exchange records.
*/
export const addWalletRecord = async (agent: Agent, options: SaveGenericRecordOption) => {
return agent.genericRecords.save(options)
}

/**
* Retrieves the generic record for a given record ID.
* @param agent The agent instance to use for retrieving the generic record.
* @param id The ID of the generic record to retrieve.
* @returns A Promise that resolves with the generic record for the given ID.
*/
export const findWalletRecordById = async (agent: Agent, id: string) => {
return agent.genericRecords.findById(id)
}

/**
* Retrieves all generic records from the agent.
*
* @param agent The agent instance to use for retrieving the generic records.
* @returns A promise that resolves to an array of generic records.
*/
export const getAllWalletRecords = async (agent: Agent) => {
return agent.genericRecords.getAll()
}

/**
* Updates a generic record.
*
* @param agent The agent instance to use for updating the generic record.
* @param record The generic record to update.
* @returns A promise that resolves with the updated generic record.
*/
export const updateWalletRecord = async (agent: Agent, record: GenericRecord) => {
return agent.genericRecords.update(record)
}

/**
* Deletes a generic record.
*
* @param agent The agent instance to use for deleting the generic record.
* @param record The generic record to delete.
* @returns A promise that resolves with the deleted generic record.
*/
export const deleteWalletRecord = async (agent: Agent, record: GenericRecord) => {
return agent.genericRecords.delete(record)
}

/**
* Deletes a generic record by ID.
*
* @param agent The agent instance to use for deleting the generic record.
* @param id The ID of the generic record to delete.
* @returns A promise that resolves with the deleted generic record.
*/
export const deleteWalletRecordById = async (agent: Agent, id: string) => {
return agent.genericRecords.deleteById(id)
}

/**
* Retrieves all generic records from the agent that match the given query.
*
* @param agent The agent instance to use for retrieving the generic records.
* @param query The query to use for retrieving the generic records.
* @returns A promise that resolves to an array of generic records.
*/
export const findWalletRecordsByQuery = async (agent: Agent, query: Query<GenericRecord>) => {
return agent.genericRecords.findAllByQuery(query)
}
1 change: 1 addition & 0 deletions packages/ssi/src/genericRecords/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './genericRecords'
1 change: 1 addition & 0 deletions packages/ssi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export * from './credentials'
export * from './proofs'
export * from './basicMessages'
export * from './pushNotifications'
export * from './genericRecords'
// Core
export {
LogLevel,
Expand Down
12 changes: 12 additions & 0 deletions packages/ssi/src/proofs/proofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
GetCredentialsForProofRequestOptions,
ProofExchangeRecord,
ProofProtocol,
ProposeProofOptions,
RequestProofOptions,
SelectCredentialsForProofRequestOptions,
SendProofProblemReportOptions
Expand Down Expand Up @@ -62,6 +63,17 @@ export const getProofRequestAgentMessage = async (agent: Agent, proofRecordId: s
return agent.proofs.findRequestMessage(proofRecordId)
}

/**
* Propose a proof to connection.
*
* @param agent The agent instance to use for proposing the proof.
* @param options - The options for proposing the proof.
* @returns A promise that resolves with the proposed proof.
*/
export const proposeProof = async (agent: Agent, options: ProposeProofOptions<DefaultProofProtocols>) => {
return agent.proofs.proposeProof(options)
}

/**
* Creates a proof request.
*
Expand Down

0 comments on commit 1a55bb9

Please sign in to comment.