Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dids #27

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions packages/ssi/src/dids/dids.ts
Original file line number Diff line number Diff line change
@@ -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 <T extends DidCreateOptions = DidCreateOptions>(agent: Agent, options: T) => {
return agent.dids.create<T>(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
}
1 change: 1 addition & 0 deletions packages/ssi/src/dids/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dids'
11 changes: 9 additions & 2 deletions packages/ssi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ import {
DidRecord,
W3cJsonLdVerifiableCredential,
DifPexCredentialsForRequest,
DidDocument
DidDocument,
KeyDidCreateOptions,
PeerDidCreateOptions,
JwkDidCreateOptions
} from '@credo-ts/core'
import {
GetCredentialsForRequestReturn,
Expand Down Expand Up @@ -124,6 +127,7 @@ export * from './pushNotifications'
export * from './genericRecords'
export * from './questionAnswer'
export * from './w3cCredentials'
export * from './dids'
// Core
export {
LogLevel,
Expand Down Expand Up @@ -186,7 +190,10 @@ export {
DidRecord,
W3cJsonLdVerifiableCredential,
DifPexCredentialsForRequest,
DidDocument
DidDocument,
KeyDidCreateOptions,
PeerDidCreateOptions,
JwkDidCreateOptions
}
// Anoncreds
export {
Expand Down
Loading