From 99ba31bda560cdce76ee79cf71493e823527b92e Mon Sep 17 00:00:00 2001 From: Sai Ranjit Tummalapalli Date: Wed, 5 Jun 2024 16:38:21 +0530 Subject: [PATCH] feat: dids Signed-off-by: Sai Ranjit Tummalapalli --- packages/ssi/src/dids/dids.ts | 77 ++++++++++++++++++++++++++++++++++ packages/ssi/src/dids/index.ts | 1 + packages/ssi/src/index.ts | 11 ++++- 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 packages/ssi/src/dids/dids.ts create mode 100644 packages/ssi/src/dids/index.ts diff --git a/packages/ssi/src/dids/dids.ts b/packages/ssi/src/dids/dids.ts new file mode 100644 index 0000000..b38c74a --- /dev/null +++ b/packages/ssi/src/dids/dids.ts @@ -0,0 +1,77 @@ +import type { Agent, DidCreateOptions, DidResolutionOptions, ImportDidOptions } from '@credo-ts/core' + +/** + * Create a new DID. + * + * @param agent The agent instance. + * @returns A promise that resolves to the created DID. + */ +export const createDid = async (agent: Agent, options: T) => { + return agent.dids.create(options) +} + +/** + * Resolve a DID. + * + * @param agent The agent instance to use for resolving the DID. + * @param did The DID to resolve. + * @param options The options for resolving the DID. + * @returns A promise that resolves to the resolved DID. + */ +export const resolveDid = async (agent: Agent, did: string, options?: DidResolutionOptions) => { + return agent.dids.resolve(did, options) +} + +/** + * Resolve a DID Document. + * + * @param agent The agent instance to use for resolving the DID. + * @param did The DID to resolve. + * @returns A promise that resolves to the resolved DID Document. + */ +export const resolveDidDocument = async (agent: Agent, didUrl: string) => { + return agent.dids.resolveDidDocument(didUrl) +} + +/** + * Retrieve all DIDs. + * + * @param agent The agent instance to use for retrieving the DIDs. + * @returns A promise that resolves to an array of DIDs. + */ +export const getCreatedDids = async ( + agent: Agent, + options?: { method?: string | undefined; did?: string | undefined } +) => { + return agent.dids.getCreatedDids(options) +} + +/** + * import DID. + * + * @param agent The agent instance. + * @returns void. + */ +export const importDid = async (agent: Agent, options: ImportDidOptions) => { + return agent.dids.import(options) +} + +/** + * Get supported DID registrar methods. + * + * @param agent The agent instance. + * @returns supported did registrar methods. + */ +export const getSupportedDidRegistrarMethods = async (agent: Agent) => { + return agent.dids.supportedRegistrarMethods +} + +/** + * Get supported DID resolver methods. + * + * @param agent The agent instance. + * @returns supported did resolver methods. + */ +export const getSupportedDidResolverMethods = async (agent: Agent) => { + return agent.dids.supportedResolverMethods +} diff --git a/packages/ssi/src/dids/index.ts b/packages/ssi/src/dids/index.ts new file mode 100644 index 0000000..73c06ef --- /dev/null +++ b/packages/ssi/src/dids/index.ts @@ -0,0 +1 @@ +export * from './dids' diff --git a/packages/ssi/src/index.ts b/packages/ssi/src/index.ts index 885cf3f..5eaf9c1 100644 --- a/packages/ssi/src/index.ts +++ b/packages/ssi/src/index.ts @@ -89,7 +89,10 @@ import { DidRecord, W3cJsonLdVerifiableCredential, DifPexCredentialsForRequest, - DidDocument + DidDocument, + KeyDidCreateOptions, + PeerDidCreateOptions, + JwkDidCreateOptions } from '@credo-ts/core' import { GetCredentialsForRequestReturn, @@ -124,6 +127,7 @@ export * from './pushNotifications' export * from './genericRecords' export * from './questionAnswer' export * from './w3cCredentials' +export * from './dids' // Core export { LogLevel, @@ -186,7 +190,10 @@ export { DidRecord, W3cJsonLdVerifiableCredential, DifPexCredentialsForRequest, - DidDocument + DidDocument, + KeyDidCreateOptions, + PeerDidCreateOptions, + JwkDidCreateOptions } // Anoncreds export {