-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add credentials and proofs modules with dedicated functions
Signed-off-by: Sai Ranjit Tummalapalli <sairanjit.tummalapalli@ayanworks.com>
- Loading branch information
Showing
5 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import type { | ||
V1CredentialProtocol, | ||
LegacyIndyCredentialFormatService, | ||
AnonCredsCredentialFormatService | ||
} from '@aries-framework/anoncreds' | ||
import type { | ||
AcceptCredentialOfferOptions, | ||
CredentialExchangeRecord, | ||
DeleteCredentialOptions, | ||
JsonLdCredentialFormatService, | ||
SendCredentialProblemReportOptions, | ||
V2CredentialProtocol | ||
} from '@aries-framework/core' | ||
|
||
import { useAdeyaAgent } from '../providers' | ||
|
||
/** | ||
* Retrieves all credential exchange records from the agent. | ||
* | ||
* @returns A promise that resolves to an array of credential exchange records. | ||
*/ | ||
export const getAllCredentialExchangeRecords = async () => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.credentials.getAll() | ||
} | ||
|
||
/** | ||
* Retrieves the formatted data for a given credential record ID. | ||
* | ||
* @param credentialRecordId The ID of the credential record to retrieve formatted data for. | ||
* @returns A Promise that resolves with the formatted data for the given credential record ID. | ||
*/ | ||
export const getFormattedCredentialData = async (credentialRecordId: string) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.credentials.getFormatData(credentialRecordId) | ||
} | ||
|
||
/** | ||
* Accepts a credential offer. | ||
* | ||
* @param options - The options for accepting the credential offer. | ||
* @returns A promise that resolves with the accepted credential. | ||
*/ | ||
export const acceptCredentialOffer = async ( | ||
options: AcceptCredentialOfferOptions< | ||
( | ||
| V1CredentialProtocol | ||
| V2CredentialProtocol< | ||
(LegacyIndyCredentialFormatService | AnonCredsCredentialFormatService | JsonLdCredentialFormatService)[] | ||
> | ||
)[] | ||
> | ||
) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.credentials.acceptOffer(options) | ||
} | ||
|
||
/** | ||
* Updates a credential exchange record. | ||
* | ||
* @param credentialRecord The credential exchange record to update. | ||
* @returns A promise that resolves with the updated credential exchange record. | ||
*/ | ||
export const updateCredentialExchangeRecord = async (credentialRecord: CredentialExchangeRecord) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.credentials.update(credentialRecord) | ||
} | ||
|
||
/** | ||
* Declines a credential offer. | ||
* | ||
* @param credentialId The ID of the credential offer to decline. | ||
* @returns A Promise that resolves CredentialExchangeRecord when the credential offer has been declined. | ||
*/ | ||
export const declineCredentialOffer = async (credentialId: string) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.credentials.declineOffer(credentialId) | ||
} | ||
|
||
/** | ||
* Deletes a credential exchange record with the given ID. | ||
* @param credentialRecordId The ID of the credential exchange record to delete. | ||
* @param options Optional parameters for deleting the credential exchange record. | ||
* | ||
* @returns void | ||
*/ | ||
export const deleteCredentialExchangeRecordById = async ( | ||
credentialRecordId: string, | ||
options?: DeleteCredentialOptions | ||
) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.credentials.deleteById(credentialRecordId, options) | ||
} | ||
|
||
/** | ||
* Sends a problem report for a credential to Agent. | ||
* | ||
* @param options - The options for sending the problem report. | ||
* @returns A Promise that resolves CredentialExchangeRecord when the problem report has been sent. | ||
*/ | ||
export const sendCredentialProblemReport = async (options: SendCredentialProblemReportOptions) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.credentials.sendProblemReport(options) | ||
} | ||
|
||
// W3C Credential | ||
|
||
/** | ||
* Retrieves a W3C credential record by its ID. | ||
* | ||
* @param credentialRecordId The ID of the credential record to retrieve. | ||
* @returns A Promise that resolves to the retrieved w3c credential record. | ||
*/ | ||
export const getW3cCredentialRecordById = async (credentialRecordId: string) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.w3cCredentials.getCredentialRecordById(credentialRecordId) | ||
} | ||
|
||
/** | ||
* Retrieves all W3C credential records from the agent. | ||
* | ||
* @returns A promise that resolves to an array of W3C credential records. | ||
*/ | ||
export const getAllW3cCredentialRecords = async () => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.w3cCredentials.getAllCredentialRecords() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './credentials' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './proofs' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import type { | ||
V1ProofProtocol, | ||
LegacyIndyProofFormatService, | ||
AnonCredsProofFormatService | ||
} from '@aries-framework/anoncreds' | ||
import type { | ||
AcceptProofRequestOptions, | ||
CreateProofRequestOptions, | ||
DeclineProofRequestOptions, | ||
GetCredentialsForProofRequestOptions, | ||
ProofExchangeRecord, | ||
RequestProofOptions, | ||
SelectCredentialsForProofRequestOptions, | ||
SendProofProblemReportOptions, | ||
V2ProofProtocol | ||
} from '@aries-framework/core' | ||
|
||
import { useAdeyaAgent } from 'src/providers' | ||
|
||
export type ProofFormats = ( | ||
| V1ProofProtocol | ||
| V2ProofProtocol<(LegacyIndyProofFormatService | AnonCredsProofFormatService)[]> | ||
)[] | ||
|
||
/** | ||
* Retrieves the formatted data for a proof record with the given ID. | ||
* | ||
* @param proofRecordId The ID of the proof record to retrieve format data for. | ||
* @returns A Promise that resolves with the format data for the proof record. | ||
*/ | ||
export const getProofFormatData = async (proofRecordId: string) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.proofs.getFormatData(proofRecordId) | ||
} | ||
|
||
/** | ||
* Retrieves the available credentials for a proof request. | ||
* | ||
* @param options The options for retrieving the credentials. | ||
* @returns A Promise that resolves with the credentials for the proof request. | ||
*/ | ||
export const getCredentialsForProofRequest = async (options: GetCredentialsForProofRequestOptions<ProofFormats>) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.proofs.getCredentialsForRequest(options) | ||
} | ||
|
||
/** | ||
* Select the credentials to be used for a proof request. | ||
* | ||
* @param options - The options for selecting the credentials. | ||
* @returns A promise that resolves to the selected credentials. | ||
*/ | ||
export const selectCredentialsForProofRequest = async ( | ||
options: SelectCredentialsForProofRequestOptions<ProofFormats> | ||
) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.proofs.selectCredentialsForRequest(options) | ||
} | ||
|
||
/** | ||
* Retrieves the proof request agent message associated with the given proof record ID. | ||
* | ||
* @param proofRecordId The ID of the proof record to retrieve the request message for. | ||
* @returns A Promise that resolves to the proof request message. | ||
*/ | ||
export const getProofRequestAgentMessage = async (proofRecordId: string) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.proofs.findRequestMessage(proofRecordId) | ||
} | ||
|
||
/** | ||
* Creates a proof request. | ||
* | ||
* @param options - The options for creating the proof request. | ||
* @returns A promise that resolves to the created proof request. | ||
*/ | ||
export const createProofRequest = async (options: CreateProofRequestOptions<ProofFormats>) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.proofs.createRequest(options) | ||
} | ||
|
||
/** | ||
* Requests a proof. | ||
* | ||
* @param options - The options for requesting the proof. | ||
* @returns A Promise that resolves with the ProofExchangeRecord | ||
*/ | ||
export const requestProof = async (options: RequestProofOptions<ProofFormats>) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.proofs.requestProof(options) | ||
} | ||
|
||
/** | ||
* Update a proof exchange record. | ||
* | ||
* @param proofRecord The proof exchange record to update. | ||
* @returns void. | ||
*/ | ||
export const updateProofRecord = (proofRecord: ProofExchangeRecord) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.proofs.update(proofRecord) | ||
} | ||
|
||
/** | ||
* Accepts a proof request . | ||
* | ||
* @param options - The options for accepting the proof request. | ||
* @returns A Promise that resolves with the result of accepting the proof request. | ||
*/ | ||
export const acceptProofRequest = async (options: AcceptProofRequestOptions<ProofFormats>) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.proofs.acceptRequest(options) | ||
} | ||
|
||
/** | ||
* Decline a proof request. | ||
* | ||
* @param options - The options for declining the proof request. | ||
* @returns A Promise that resolves ProofExchangeRecord of declining the proof request. | ||
*/ | ||
export const declineProofRequest = async (options: DeclineProofRequestOptions) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.proofs.declineRequest(options) | ||
} | ||
|
||
/** | ||
* Sends a problem report for a proof to Agent. | ||
* | ||
* @param options - The options for sending the problem report. | ||
* @returns A Promise that resolves ProofExchangeRecord when the problem report has been sent. | ||
*/ | ||
export const sendProofProblemReport = async (options: SendProofProblemReportOptions) => { | ||
const { agent } = useAdeyaAgent() | ||
|
||
return agent.proofs.sendProblemReport(options) | ||
} |