From 9dfb61380fa6423cb05e04d981ec0694b7a899b8 Mon Sep 17 00:00:00 2001 From: Sai Ranjit Tummalapalli Date: Mon, 16 Oct 2023 17:33:17 +0530 Subject: [PATCH] docs: add all modules usage (#12) * feat: add credentials and proofs modules with dedicated functions Signed-off-by: Sai Ranjit Tummalapalli * chore: upgrade aries-framework packages to 0.4.2 Signed-off-by: Sai Ranjit Tummalapalli * refactor: remove isWalletImportable method Signed-off-by: Sai Ranjit Tummalapalli * fix: provider import in proof module Signed-off-by: Sai Ranjit Tummalapalli * fix: add agent param in all the methods Signed-off-by: Sai Ranjit Tummalapalli * feat: add basic message and notifications module Signed-off-by: Sai Ranjit Tummalapalli * docs: add all modules usage Signed-off-by: Sai Ranjit Tummalapalli * refactor: imports of all modules Signed-off-by: Sai Ranjit Tummalapalli * docs: add link to readme Signed-off-by: Sai Ranjit Tummalapalli * fix: doc link Signed-off-by: Sai Ranjit Tummalapalli --------- Signed-off-by: Sai Ranjit Tummalapalli --- README.md | 25 +- packages/ssi/README.md | 396 ++++++++++++++++++ packages/ssi/src/{ => agent}/agent.ts | 11 +- packages/ssi/src/agent/index.ts | 1 + .../ssi/src/basicMessages/basicMessages.ts | 4 +- packages/ssi/src/connections/connections.ts | 28 +- packages/ssi/src/credentials/credentials.ts | 41 +- packages/ssi/src/index.ts | 66 ++- packages/ssi/src/proofs/proofs.ts | 48 +-- packages/ssi/src/providers/AgentProvider.tsx | 4 +- .../pushNotifications/pushNotifications.ts | 8 +- packages/ssi/src/wallet/wallet.ts | 19 +- 12 files changed, 542 insertions(+), 109 deletions(-) create mode 100644 packages/ssi/README.md rename packages/ssi/src/{ => agent}/agent.ts (93%) create mode 100644 packages/ssi/src/agent/index.ts diff --git a/README.md b/README.md index bd63734..7a0a252 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,26 @@ -# adeya-sdk +# ADEYA SDK [![Pipeline](https://github.com/credebl/adeya-sdk/actions/workflows/pipeline.yaml/badge.svg?branch=main)](https://github.com/credebl/adeya-sdk/actions/workflows/pipeline.yaml) + +### Packages + + + + + + + + + + + + +
PackageStable VersionUnstable Version
@adeya/ssi + + @adeya/ssi version + + + + @adeya/ssi version + +
diff --git a/packages/ssi/README.md b/packages/ssi/README.md new file mode 100644 index 0000000..ba7f1ba --- /dev/null +++ b/packages/ssi/README.md @@ -0,0 +1,396 @@ +# @adeya/ssi + +[![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) + +## Installing + +```sh +npm install @adeya/ssi + +# or + +yarn add @adeya/ssi + +# or + +pnpm add @adeya/ssi +``` + +## Peer Dependencies + +- We also need to add the peer dependencies of this package to our App. + +``` +"dependencies": { + ... + "@hyperledger/anoncreds-react-native": "^0.1.0", + "@hyperledger/aries-askar-react-native": "^0.1.1", + "@hyperledger/indy-vdr-react-native": "^0.1.0", +} +``` + +## Usage + +```ts +import { useAdeyaAgent } from '@adeya/ssi' + +const { agent } = useAdeyaAgent() +``` + +## API + +### Agent + +- initializeAgent - Initialize the agent with the given `Config` and `Agent Modules` + +```ts +import { initializeAgent } from '@adeya/ssi' + +const config: InitConfig = { + label: 'ADEYA Wallet', + walletConfig: { + id: 'adeya-wallet', + key: 'adeya-wallet-key' + }, + logger: new ConsoleLogger(LogLevel.debug), + autoUpdateStorageOnStartup: true +} + +const agent = await initializeAgent({ + agentConfig: config, + modules: getAgentModules(mediatorUrl, indyLedgers) +}) +``` + +- getAgentModules - Get the default agent modules. + +```ts +import { getAgentModules } from '@adeya/ssi' + +const modules = getAgentModules(mediatorUrl, indyLedgers) +``` + +- AdeyaAgent - The agent instance type. + +```ts +import { AdeyaAgent } from '@adeya/ssi' +``` + +### Wallet + +- isWalletPinCorrect - Check if the wallet pin is correct. + +```ts +import { isWalletPinCorrect } from '@adeya/ssi' + +const isCorrect = await isWalletPinCorrect(walletConfig) +``` + +- exportWallet - Export the wallet. + +```ts +import { exportWallet } from '@adeya/ssi' + +await exportWallet(agent, exportConfig) +``` + +- importWalletWithAgent - Import the wallet and start the agent. + +```ts +import { importWalletWithAgent } from '@adeya/ssi' + +const agent = await importWalletWithAgent({ + importConfig, + agentConfig, + modules +}) +``` + +### Connections + +- createLegacyInvitation - Create a legacy invitation. + +```ts +import { createLegacyInvitation } from '@adeya/ssi' + +const connection = await createLegacyInvitation(agent, domain, config) +``` + +- createLegacyConnectionlessInvitation - Create a legacy connectionless invitation. + +```ts +import { createLegacyConnectionlessInvitation } from '@adeya/ssi' + +const connection = await createLegacyConnectionlessInvitation(agent, config) +``` + +- createInvitation - Create an invitation. + +```ts +import { createInvitation } from '@adeya/ssi' + +const connection = await createInvitation(agent, domain, config) +``` + +- acceptInvitation - Accept an invitation. + +```ts +import { acceptInvitation } from '@adeya/ssi' + +const connection = await acceptInvitation(agent, invitation, config) +``` + +- parseInvitationFromUrl - Parse an invitation from a url. + +```ts +import { parseInvitationFromUrl } from '@adeya/ssi' + +const invitation = await parseInvitationFromUrl(agent, invitationUrl) +``` + +- acceptInvitationFromUrl - Accept an invitation from a url. + +```ts +import { acceptInvitationFromUrl } from '@adeya/ssi' + +const connection = await acceptInvitationFromUrl(agent, invitationUrl, config) +``` + +- getAllConnections - Get all connections. + +```ts +import { getAllConnections } from '@adeya/ssi' + +const connections = await getAllConnections(agent) +``` + +- getConnectionById - Get a connection by id. + +```ts +import { getConnectionById } from '@adeya/ssi' + +const connection = await getConnectionById(agent, connectionId) +``` + +- findConnectionById - Find a connection by id. + +```ts +import { findConnectionById } from '@adeya/ssi' + +const connection = await findConnectionById(agent, connectionId) +``` + +- findOutOfBandRecordById - Find an out of band record by id. + +```ts +import { findOutOfBandRecordById } from '@adeya/ssi' + +const record = await findOutOfBandRecordById(agent, recordId) +``` + +- deleteConnectionById - Delete a connection by id. + +```ts +import { deleteConnectionById } from '@adeya/ssi' + +await deleteConnectionById(agent, connectionId) +``` + +### Credentials + +- getAllCredentialExchangeRecords - Get all credential exchange records. + +```ts +import { getAllCredentialExchangeRecords } from '@adeya/ssi' + +const records = await getAllCredentialExchangeRecords(agent) +``` + +- getFormattedCredentialData - Retrieves the formatted data for a given credential record ID. + +```ts +import { getFormattedCredentialData } from '@adeya/ssi' + +const formattedData = await getFormattedCredentialData(agent, credentialRecordId) +``` + +- acceptCredentialOffer - Accept a credential offer. + +```ts +import { acceptCredentialOffer } from '@adeya/ssi' + +const credential = await acceptCredentialOffer(agent, options) +``` + +- updateCredentialExchangeRecord - Update a credential exchange record. + +```ts +import { updateCredentialExchangeRecord } from '@adeya/ssi' + +await updateCredentialExchangeRecord(agent, credentialRecord) +``` + +- declineCredentialOffer - Decline a credential offer. + +```ts +import { declineCredentialOffer } from '@adeya/ssi' + +const record = await declineCredentialOffer(agent, credentialRecordId) +``` + +- deleteCredentialExchangeRecordById - Delete a credential exchange record by id. + +```ts +import { deleteCredentialExchangeRecordById } from '@adeya/ssi' + +await deleteCredentialExchangeRecordById(agent, credentialRecordId, options) +``` + +- sendCredentialProblemReport - Send a credential problem report. + +```ts +import { sendCredentialProblemReport } from '@adeya/ssi' + +const record = await sendCredentialProblemReport(agent, options) +``` + +- getW3cCredentialRecordById - Get a W3C credential record by id. + +```ts +import { getW3cCredentialRecordById } from '@adeya/ssi' + +const record = await getW3cCredentialRecordById(agent, credentialRecordId) +``` + +- getAllW3cCredentialRecords - Get all W3C credential records. + +```ts +import { getAllW3cCredentialRecords } from '@adeya/ssi' + +const records = await getAllW3cCredentialRecords(agent) +``` + +### Proofs + +- getProofFormatData - Get proof format data. + +```ts +import { getProofFormatData } from '@adeya/ssi' + +const data = await getProofFormatData(agent, proofRecordId) +``` + +- getCredentialsForProofRequest - Get credentials for a proof request. + +```ts +import { getCredentialsForProofRequest } from '@adeya/ssi' + +const credentials = await getCredentialsForProofRequest(agent, options) +``` + +- selectCredentialsForProofRequest - Select credentials for a proof request. + +```ts +import { selectCredentialsForProofRequest } from '@adeya/ssi' + +const credentials = await selectCredentialsForProofRequest(agent, options) +``` + +- getProofRequestAgentMessage - Get a proof request agent message. + +```ts +import { getProofRequestAgentMessage } from '@adeya/ssi' + +const message = await getProofRequestAgentMessage(agent, proofRecordId) +``` + +- createProofRequest - Create a proof request. + +```ts +import { createProofRequest } from '@adeya/ssi' + +const proofRequest = await createProofRequest(agent, options) +``` + +- requestProof - Request a proof. + +```ts +import { requestProof } from '@adeya/ssi' + +const proof = await requestProof(agent, options) +``` + +- updateProofRecord - Update a proof record. + +```ts +import { updateProofRecord } from '@adeya/ssi' + +await updateProofRecord(agent, proofRecord) +``` + +- acceptProofRequest - Accept a proof request. + +```ts +import { acceptProofRequest } from '@adeya/ssi' + +const proof = await acceptProofRequest(agent, options) +``` + +- declineProofRequest - Decline a proof request. + +```ts +import { declineProofRequest } from '@adeya/ssi' + +const proof = await declineProofRequest(agent, options) +``` + +- sendProofProblemReport - Send a proof problem report. + +```ts +import { sendProofProblemReport } from '@adeya/ssi' + +const proof = await sendProofProblemReport(agent, options) +``` + +### BasicMessages + +- sendBasicMessage - Send a basic message. + +```ts +import { sendBasicMessage } from '@adeya/ssi' + +const record = await sendBasicMessage(agent, options) +``` + +### PushNotifications + +- setPushNotificationDeviceInfo - Set the push notification device info. + +```ts +import { setPushNotificationDeviceInfo } from '@adeya/ssi' + +await setPushNotificationDeviceInfo(agent, options) +``` + +### Hooks + +- useAdeyaAgent - React hook to get the agent instance. + +```ts +import { useAdeyaAgent } from '@adeya/ssi' + +const { agent } = useAdeyaAgent() +``` diff --git a/packages/ssi/src/agent.ts b/packages/ssi/src/agent/agent.ts similarity index 93% rename from packages/ssi/src/agent.ts rename to packages/ssi/src/agent/agent.ts index c3ec8af..058b0f1 100644 --- a/packages/ssi/src/agent.ts +++ b/packages/ssi/src/agent/agent.ts @@ -1,4 +1,5 @@ import type { InitConfig } from '@aries-framework/core' +import type { AgentModulesInput } from '@aries-framework/core/build/agent/AgentModules' import type { IndyVdrPoolConfig } from '@aries-framework/indy-vdr' import { @@ -104,12 +105,10 @@ export const getAgentModules = ( export const initializeAgent = async ({ agentConfig, - mediatorInvitationUrl, - indyNetworks + modules }: { agentConfig: InitConfig - mediatorInvitationUrl: string - indyNetworks: [IndyVdrPoolConfig, ...IndyVdrPoolConfig[]] + modules: AgentModulesInput }) => { const agent = new Agent({ dependencies: agentDependencies, @@ -117,7 +116,7 @@ export const initializeAgent = async ({ autoUpdateStorageOnStartup: true, ...agentConfig }, - modules: getAgentModules(mediatorInvitationUrl, indyNetworks) + modules }) agent.registerOutboundTransport(new HttpOutboundTransport()) @@ -127,5 +126,3 @@ export const initializeAgent = async ({ return agent } - -export type AdeyaAgent = Awaited> diff --git a/packages/ssi/src/agent/index.ts b/packages/ssi/src/agent/index.ts new file mode 100644 index 0000000..c9209a5 --- /dev/null +++ b/packages/ssi/src/agent/index.ts @@ -0,0 +1 @@ +export * from './agent' diff --git a/packages/ssi/src/basicMessages/basicMessages.ts b/packages/ssi/src/basicMessages/basicMessages.ts index c7d9d7f..db8a532 100644 --- a/packages/ssi/src/basicMessages/basicMessages.ts +++ b/packages/ssi/src/basicMessages/basicMessages.ts @@ -1,4 +1,4 @@ -import type { AdeyaAgent } from '../agent' +import type { Agent } from '@aries-framework/core' /** * Sends a basic message to the connection with the given connection id. @@ -7,6 +7,6 @@ import type { AdeyaAgent } from '../agent' * @param connectionId The connection id. * @param message The message to send. */ -export const sendBasicMessage = async (agent: AdeyaAgent, connectionId: string, message: string) => { +export const sendBasicMessage = async (agent: Agent, connectionId: string, message: string) => { return agent.basicMessages.sendMessage(connectionId, message) } diff --git a/packages/ssi/src/connections/connections.ts b/packages/ssi/src/connections/connections.ts index 584396d..f57f732 100644 --- a/packages/ssi/src/connections/connections.ts +++ b/packages/ssi/src/connections/connections.ts @@ -1,5 +1,5 @@ -import type { AdeyaAgent } from '../agent' import type { + Agent, AgentMessage, ConnectionInvitationMessage, CreateLegacyInvitationConfig, @@ -17,11 +17,7 @@ import type { * @param config configuration of how a connection invitation should be created * @returns out-of-band record and connection invitation together with invitationUrl */ -export const createLegacyInvitation = async ( - agent: AdeyaAgent, - domain: string, - config?: CreateLegacyInvitationConfig -) => { +export const createLegacyInvitation = async (agent: Agent, domain: string, config?: CreateLegacyInvitationConfig) => { const record = await agent.oob.createLegacyInvitation(config) const invitationUrl = record.invitation.toUrl({ domain }) @@ -46,7 +42,7 @@ export const createLegacyInvitation = async ( * @returns A Promise that resolves to the created invitation. */ export const createLegacyConnectionlessInvitation = async ( - agent: AdeyaAgent, + agent: Agent, config: { recordId?: string | undefined message: AgentMessage @@ -65,7 +61,7 @@ export const createLegacyConnectionlessInvitation = async ( * @param config Optional configuration for the invitation. * @returns An object containing the invitation record, the invitation object, and the invitation URL. */ -export const createInvitation = async (agent: AdeyaAgent, domain: string, config?: CreateOutOfBandInvitationConfig) => { +export const createInvitation = async (agent: Agent, domain: string, config?: CreateOutOfBandInvitationConfig) => { const record = await agent.oob.createInvitation(config) const invitationUrl = record.outOfBandInvitation.toUrl({ domain }) @@ -87,7 +83,7 @@ export const createInvitation = async (agent: AdeyaAgent, domain: string, config * @returns The connection record. */ export const acceptInvitation = async ( - agent: AdeyaAgent, + agent: Agent, invitation: ConnectionInvitationMessage | OutOfBandInvitation, config?: ReceiveOutOfBandInvitationConfig ) => { @@ -103,7 +99,7 @@ export const acceptInvitation = async ( * @param invitationUrl The URL of the invitation to parse. * @returns A Promise that resolves with the parsed invitation. */ -export const parseInvitationFromUrl = async (agent: AdeyaAgent, invitationUrl: string) => { +export const parseInvitationFromUrl = async (agent: Agent, invitationUrl: string) => { return agent.oob.parseInvitation(invitationUrl) } @@ -117,7 +113,7 @@ export const parseInvitationFromUrl = async (agent: AdeyaAgent, invitationUrl: s * @throws An error if the invitation cannot be parsed from the URL or if the connection does not have an ID. */ export const acceptInvitationFromUrl = async ( - agent: AdeyaAgent, + agent: Agent, invitationUrl: string, config?: ReceiveOutOfBandInvitationConfig ) => { @@ -142,7 +138,7 @@ export const acceptInvitationFromUrl = async ( * @param agent The agent instance to use for retrieving the connections. * @returns A promise that resolves to an array of Connection objects. */ -export const getAllConnections = async (agent: AdeyaAgent) => { +export const getAllConnections = async (agent: Agent) => { return agent.connections.getAll() } @@ -153,7 +149,7 @@ export const getAllConnections = async (agent: AdeyaAgent) => { * @param connectionId The ID of the connection to retrieve. * @returns A Promise that resolves to the connection object. */ -export const getConnectionById = async (agent: AdeyaAgent, connectionId: string) => { +export const getConnectionById = async (agent: Agent, connectionId: string) => { return agent.connections.getById(connectionId) } @@ -164,7 +160,7 @@ export const getConnectionById = async (agent: AdeyaAgent, connectionId: string) * @param connectionId The ID of the connection to find. * @returns A Promise that resolves with the connection object, or null if not found. */ -export const findConnectionById = async (agent: AdeyaAgent, connectionId: string) => { +export const findConnectionById = async (agent: Agent, connectionId: string) => { return await agent.connections.findById(connectionId) } @@ -175,7 +171,7 @@ export const findConnectionById = async (agent: AdeyaAgent, connectionId: string * @param connectionId The ID of the connection to find. * @returns A Promise that resolves to the out-of-band record with the given ID. */ -export const findOutOfBandRecordById = async (agent: AdeyaAgent, connectionId: string) => { +export const findOutOfBandRecordById = async (agent: Agent, connectionId: string) => { return agent.oob.findById(connectionId) } @@ -185,7 +181,7 @@ export const findOutOfBandRecordById = async (agent: AdeyaAgent, connectionId: s * @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: AdeyaAgent, connectionId: string) => { +export const deleteConnectionById = async (agent: Agent, connectionId: string) => { await agent.connections.deleteById(connectionId) return true } diff --git a/packages/ssi/src/credentials/credentials.ts b/packages/ssi/src/credentials/credentials.ts index 8b81c2d..56e297f 100644 --- a/packages/ssi/src/credentials/credentials.ts +++ b/packages/ssi/src/credentials/credentials.ts @@ -1,16 +1,10 @@ -import type { AdeyaAgent } from '../agent' -import type { - V1CredentialProtocol, - LegacyIndyCredentialFormatService, - AnonCredsCredentialFormatService -} from '@aries-framework/anoncreds' import type { AcceptCredentialOfferOptions, + Agent, CredentialExchangeRecord, + CredentialProtocol, DeleteCredentialOptions, - JsonLdCredentialFormatService, - SendCredentialProblemReportOptions, - V2CredentialProtocol + SendCredentialProblemReportOptions } from '@aries-framework/core' /** @@ -19,7 +13,7 @@ import type { * @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 getAllCredentialExchangeRecords = async (agent: AdeyaAgent) => { +export const getAllCredentialExchangeRecords = async (agent: Agent) => { return agent.credentials.getAll() } @@ -30,7 +24,7 @@ export const getAllCredentialExchangeRecords = async (agent: AdeyaAgent) => { * @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 (agent: AdeyaAgent, credentialRecordId: string) => { +export const getFormattedCredentialData = async (agent: Agent, credentialRecordId: string) => { return agent.credentials.getFormatData(credentialRecordId) } @@ -41,16 +35,9 @@ export const getFormattedCredentialData = async (agent: AdeyaAgent, credentialRe * @param options - The options for accepting the credential offer. * @returns A promise that resolves with the accepted credential. */ -export const acceptCredentialOffer = async ( - agent: AdeyaAgent, - options: AcceptCredentialOfferOptions< - ( - | V1CredentialProtocol - | V2CredentialProtocol< - (LegacyIndyCredentialFormatService | AnonCredsCredentialFormatService | JsonLdCredentialFormatService)[] - > - )[] - > +export const acceptCredentialOffer = async ( + agent: Agent, + options: AcceptCredentialOfferOptions ) => { return agent.credentials.acceptOffer(options) } @@ -62,7 +49,7 @@ export const acceptCredentialOffer = async ( * @param credentialRecord The credential exchange record to update. * @returns A promise that resolves with the updated credential exchange record. */ -export const updateCredentialExchangeRecord = async (agent: AdeyaAgent, credentialRecord: CredentialExchangeRecord) => { +export const updateCredentialExchangeRecord = async (agent: Agent, credentialRecord: CredentialExchangeRecord) => { return agent.credentials.update(credentialRecord) } @@ -73,7 +60,7 @@ export const updateCredentialExchangeRecord = async (agent: AdeyaAgent, credenti * @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 (agent: AdeyaAgent, credentialId: string) => { +export const declineCredentialOffer = async (agent: Agent, credentialId: string) => { return agent.credentials.declineOffer(credentialId) } @@ -87,7 +74,7 @@ export const declineCredentialOffer = async (agent: AdeyaAgent, credentialId: st * @returns void */ export const deleteCredentialExchangeRecordById = async ( - agent: AdeyaAgent, + agent: Agent, credentialRecordId: string, options?: DeleteCredentialOptions ) => { @@ -101,7 +88,7 @@ export const deleteCredentialExchangeRecordById = async ( * @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 (agent: AdeyaAgent, options: SendCredentialProblemReportOptions) => { +export const sendCredentialProblemReport = async (agent: Agent, options: SendCredentialProblemReportOptions) => { return agent.credentials.sendProblemReport(options) } @@ -114,7 +101,7 @@ export const sendCredentialProblemReport = async (agent: AdeyaAgent, options: Se * @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 (agent: AdeyaAgent, credentialRecordId: string) => { +export const getW3cCredentialRecordById = async (agent: Agent, credentialRecordId: string) => { return agent.w3cCredentials.getCredentialRecordById(credentialRecordId) } @@ -123,6 +110,6 @@ export const getW3cCredentialRecordById = async (agent: AdeyaAgent, credentialRe * * @returns A promise that resolves to an array of W3C credential records. */ -export const getAllW3cCredentialRecords = async (agent: AdeyaAgent) => { +export const getAllW3cCredentialRecords = async (agent: Agent) => { return agent.w3cCredentials.getAllCredentialRecords() } diff --git a/packages/ssi/src/index.ts b/packages/ssi/src/index.ts index f86e6c3..a2228a5 100644 --- a/packages/ssi/src/index.ts +++ b/packages/ssi/src/index.ts @@ -18,10 +18,17 @@ import { AnonCredsRequestedAttribute, AnonCredsRequestedPredicate, LegacyIndyProofRequest, - AnonCredsProofRequest + AnonCredsProofRequest, + AnonCredsModule, + V1CredentialProtocol, + LegacyIndyCredentialFormatService, + AnonCredsCredentialFormatService, + V1ProofProtocol } from '@aries-framework/anoncreds' import { AnonCredsCredentialMetadataKey } from '@aries-framework/anoncreds/build/utils/metadata' // Core +import { AnonCredsRsModule } from '@aries-framework/anoncreds-rs' +import { AskarModule } from '@aries-framework/askar' import { LogLevel, ConsoleLogger, @@ -42,15 +49,36 @@ import { ProofFormatPayload, AgentMessage, AutoAcceptProof, - ConnectionType + ConnectionType, + MediationRecipientModule, + MediatorPickupStrategy, + DidsModule, + JwkDidRegistrar, + WebDidResolver, + JwkDidResolver, + CredentialsModule, + AutoAcceptCredential, + V2CredentialProtocol, + JsonLdCredentialFormatService, + ProofsModule, + V2ProofProtocol, + ConnectionsModule } from '@aries-framework/core' import { GetCredentialsForRequestReturn, ProofFormatDataMessagePayload } from '@aries-framework/core/build/modules/proofs/protocol/ProofProtocolOptions' // Indy VDR -import { IndyVdrPoolConfig } from '@aries-framework/indy-vdr' +import { + IndyVdrAnonCredsRegistry, + IndyVdrIndyDidResolver, + IndyVdrModule, + IndyVdrPoolConfig, + IndyVdrSovDidResolver +} from '@aries-framework/indy-vdr' +import { PushNotificationsFcmModule } from '@aries-framework/push-notifications' +export * from './agent' export * from './providers' export * from './hooks' export * from './wallet' @@ -59,13 +87,11 @@ export * from './credentials' export * from './proofs' export * from './basicMessages' export * from './pushNotifications' -export { initializeAgent, AdeyaAgent } from './agent' // Core export { LogLevel, ConsoleLogger, InitConfig, - IndyVdrPoolConfig, BasicMessageRecord, ConnectionRecord, OutOfBandRecord, @@ -85,7 +111,20 @@ export { AutoAcceptProof, ConnectionType, GetCredentialsForRequestReturn, - ProofFormatDataMessagePayload + ProofFormatDataMessagePayload, + MediationRecipientModule, + MediatorPickupStrategy, + DidsModule, + JwkDidRegistrar, + WebDidResolver, + JwkDidResolver, + CredentialsModule, + AutoAcceptCredential, + V2CredentialProtocol, + JsonLdCredentialFormatService, + ProofsModule, + V2ProofProtocol, + ConnectionsModule } // Anoncreds export { @@ -106,5 +145,18 @@ export { AnonCredsRequestedPredicate, LegacyIndyProofRequest, AnonCredsProofRequest, - AnonCredsCredentialMetadataKey + AnonCredsCredentialMetadataKey, + AnonCredsModule, + V1CredentialProtocol, + LegacyIndyCredentialFormatService, + AnonCredsCredentialFormatService, + V1ProofProtocol } +// Indy Vdr +export { IndyVdrAnonCredsRegistry, IndyVdrPoolConfig, IndyVdrIndyDidResolver, IndyVdrModule, IndyVdrSovDidResolver } +// Askar +export { AskarModule } +// Anoncreds RS +export { AnonCredsRsModule } +// Push Notifications +export { PushNotificationsFcmModule } diff --git a/packages/ssi/src/proofs/proofs.ts b/packages/ssi/src/proofs/proofs.ts index aef0a39..7a32266 100644 --- a/packages/ssi/src/proofs/proofs.ts +++ b/packages/ssi/src/proofs/proofs.ts @@ -1,26 +1,17 @@ -import type { AdeyaAgent } from '../agent' -import type { - V1ProofProtocol, - LegacyIndyProofFormatService, - AnonCredsProofFormatService -} from '@aries-framework/anoncreds' import type { AcceptProofRequestOptions, + Agent, CreateProofRequestOptions, DeclineProofRequestOptions, + DefaultProofProtocols, GetCredentialsForProofRequestOptions, ProofExchangeRecord, + ProofProtocol, RequestProofOptions, SelectCredentialsForProofRequestOptions, - SendProofProblemReportOptions, - V2ProofProtocol + SendProofProblemReportOptions } from '@aries-framework/core' -export type ProofFormats = ( - | V1ProofProtocol - | V2ProofProtocol<(LegacyIndyProofFormatService | AnonCredsProofFormatService)[]> -)[] - /** * Retrieves the formatted data for a proof record with the given ID. * @@ -28,7 +19,7 @@ export type ProofFormats = ( * @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 (agent: AdeyaAgent, proofRecordId: string) => { +export const getProofFormatData = async (agent: Agent, proofRecordId: string) => { return agent.proofs.getFormatData(proofRecordId) } @@ -39,9 +30,9 @@ export const getProofFormatData = async (agent: AdeyaAgent, proofRecordId: strin * @param options The options for retrieving the credentials. * @returns A Promise that resolves with the credentials for the proof request. */ -export const getCredentialsForProofRequest = async ( - agent: AdeyaAgent, - options: GetCredentialsForProofRequestOptions +export const getCredentialsForProofRequest = async ( + agent: Agent, + options: GetCredentialsForProofRequestOptions ) => { return agent.proofs.getCredentialsForRequest(options) } @@ -53,9 +44,9 @@ export const getCredentialsForProofRequest = async ( * @param options - The options for selecting the credentials. * @returns A promise that resolves to the selected credentials. */ -export const selectCredentialsForProofRequest = async ( - agent: AdeyaAgent, - options: SelectCredentialsForProofRequestOptions +export const selectCredentialsForProofRequest = async ( + agent: Agent, + options: SelectCredentialsForProofRequestOptions ) => { return agent.proofs.selectCredentialsForRequest(options) } @@ -67,7 +58,7 @@ export const selectCredentialsForProofRequest = async ( * @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 (agent: AdeyaAgent, proofRecordId: string) => { +export const getProofRequestAgentMessage = async (agent: Agent, proofRecordId: string) => { return agent.proofs.findRequestMessage(proofRecordId) } @@ -78,7 +69,7 @@ export const getProofRequestAgentMessage = async (agent: AdeyaAgent, proofRecord * @param options - The options for creating the proof request. * @returns A promise that resolves to the created proof request. */ -export const createProofRequest = async (agent: AdeyaAgent, options: CreateProofRequestOptions) => { +export const createProofRequest = async (agent: Agent, options: CreateProofRequestOptions) => { return agent.proofs.createRequest(options) } @@ -89,7 +80,7 @@ export const createProofRequest = async (agent: AdeyaAgent, options: CreateProof * @param options - The options for requesting the proof. * @returns A Promise that resolves with the ProofExchangeRecord */ -export const requestProof = async (agent: AdeyaAgent, options: RequestProofOptions) => { +export const requestProof = async (agent: Agent, options: RequestProofOptions) => { return agent.proofs.requestProof(options) } @@ -100,7 +91,7 @@ export const requestProof = async (agent: AdeyaAgent, options: RequestProofOptio * @param proofRecord The proof exchange record to update. * @returns void. */ -export const updateProofRecord = (agent: AdeyaAgent, proofRecord: ProofExchangeRecord) => { +export const updateProofRecord = (agent: Agent, proofRecord: ProofExchangeRecord) => { return agent.proofs.update(proofRecord) } @@ -111,7 +102,10 @@ export const updateProofRecord = (agent: AdeyaAgent, proofRecord: ProofExchangeR * @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 (agent: AdeyaAgent, options: AcceptProofRequestOptions) => { +export const acceptProofRequest = async ( + agent: Agent, + options: AcceptProofRequestOptions +) => { return agent.proofs.acceptRequest(options) } @@ -122,7 +116,7 @@ export const acceptProofRequest = async (agent: AdeyaAgent, options: AcceptProof * @param options - The options for declining the proof request. * @returns A Promise that resolves ProofExchangeRecord of declining the proof request. */ -export const declineProofRequest = async (agent: AdeyaAgent, options: DeclineProofRequestOptions) => { +export const declineProofRequest = async (agent: Agent, options: DeclineProofRequestOptions) => { return agent.proofs.declineRequest(options) } @@ -132,6 +126,6 @@ export const declineProofRequest = async (agent: AdeyaAgent, options: DeclinePro * @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 (agent: AdeyaAgent, options: SendProofProblemReportOptions) => { +export const sendProofProblemReport = async (agent: Agent, options: SendProofProblemReportOptions) => { return agent.proofs.sendProblemReport(options) } diff --git a/packages/ssi/src/providers/AgentProvider.tsx b/packages/ssi/src/providers/AgentProvider.tsx index 7b3f48c..8b4aa2a 100644 --- a/packages/ssi/src/providers/AgentProvider.tsx +++ b/packages/ssi/src/providers/AgentProvider.tsx @@ -1,10 +1,10 @@ -import type { AdeyaAgent } from '../agent' +import type { Agent } from '@aries-framework/core' import AgentProvider, { useAgent } from '@aries-framework/react-hooks' const useAdeyaAgent: () => { loading: boolean - agent: AdeyaAgent + agent: Agent } = useAgent export { useAdeyaAgent, AgentProvider as AdeyaAgentProvider } diff --git a/packages/ssi/src/pushNotifications/pushNotifications.ts b/packages/ssi/src/pushNotifications/pushNotifications.ts index 5701da9..12ce6ba 100644 --- a/packages/ssi/src/pushNotifications/pushNotifications.ts +++ b/packages/ssi/src/pushNotifications/pushNotifications.ts @@ -1,4 +1,4 @@ -import type { AdeyaAgent } from '../agent' +import type { Agent } from '@aries-framework/core' import type { FcmDeviceInfo } from '@aries-framework/push-notifications' /** @@ -9,10 +9,6 @@ import type { FcmDeviceInfo } from '@aries-framework/push-notifications' * @param deviceInfo - The device information for push notifications. * @returns void. */ -export const setPushNotificationDeviceInfo = async ( - agent: AdeyaAgent, - connectionId: string, - deviceInfo: FcmDeviceInfo -) => { +export const setPushNotificationDeviceInfo = async (agent: Agent, connectionId: string, deviceInfo: FcmDeviceInfo) => { return agent.modules.pushNotificationsFcm.setDeviceInfo(connectionId, deviceInfo) } diff --git a/packages/ssi/src/wallet/wallet.ts b/packages/ssi/src/wallet/wallet.ts index 6700f5b..02620cb 100644 --- a/packages/ssi/src/wallet/wallet.ts +++ b/packages/ssi/src/wallet/wallet.ts @@ -1,9 +1,8 @@ // NOTE: We need to import these to be able to use the AskarWallet in this file. import '@hyperledger/aries-askar-react-native' -import type { AdeyaAgent } from '../agent' import type { InitConfig } from '@aries-framework/core' -import type { IndyVdrPoolConfig } from '@aries-framework/indy-vdr' +import type { AgentModulesInput } from '@aries-framework/core/build/agent/AgentModules' import { AskarWallet } from '@aries-framework/askar' import { @@ -18,13 +17,10 @@ import { } from '@aries-framework/core' import { agentDependencies } from '@aries-framework/react-native' -import { getAgentModules } from '../agent' - interface WalletImportConfigWithAgent { agentConfig: InitConfig importConfig: WalletExportImportConfig - mediatorInvitationUrl: string - indyNetworks: [IndyVdrPoolConfig, ...IndyVdrPoolConfig[]] + modules: AgentModulesInput } /** @@ -59,7 +55,7 @@ export const isWalletPinCorrect = async (walletConfig: WalletConfig) => { * @param agent The agent. * @param exportConfig The configuration for exporting the wallet. */ -export const exportWallet = async (agent: AdeyaAgent, exportConfig: WalletExportImportConfig) => { +export const exportWallet = async (agent: Agent, exportConfig: WalletExportImportConfig) => { await agent.wallet.export(exportConfig) } @@ -73,12 +69,7 @@ export const exportWallet = async (agent: AdeyaAgent, exportConfig: WalletExport * @returns The agent with the imported wallet. * @throws An error if the passphrase is invalid. */ -export const importWalletWithAgent = async ({ - importConfig, - agentConfig, - mediatorInvitationUrl, - indyNetworks -}: WalletImportConfigWithAgent) => { +export const importWalletWithAgent = async ({ importConfig, agentConfig, modules }: WalletImportConfigWithAgent) => { if (!agentConfig.walletConfig?.id || !agentConfig.walletConfig.key) { // Cannot find wallet id/key in agent config, so we cannot import the wallet return @@ -94,7 +85,7 @@ export const importWalletWithAgent = async ({ autoUpdateStorageOnStartup: true, ...agentConfig }, - modules: getAgentModules(mediatorInvitationUrl, indyNetworks) + modules }) agent.registerOutboundTransport(new HttpOutboundTransport())