Skip to content

Commit

Permalink
feat(cheqd): Add CheqdApi (#2007)
Browse files Browse the repository at this point in the history
Signed-off-by: DaevMithran <[email protected]>
  • Loading branch information
DaevMithran authored Aug 27, 2024
1 parent 0bcb623 commit 4485dc9
Show file tree
Hide file tree
Showing 5 changed files with 6,147 additions and 8,651 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-geese-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@credo-ts/cheqd": patch
---

add cheqd api to allow creation of DID-Linked resources
23 changes: 23 additions & 0 deletions packages/cheqd/src/CheqdApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { AgentContext } from '@credo-ts/core'
import { injectable } from 'tsyringe'

import { CheqdCreateResourceOptions, CheqdDidRegistrar, CheqdDidResolver } from './dids'

@injectable()
export class CheqdApi {
private agentContext: AgentContext

public constructor(agentContext: AgentContext) {
this.agentContext = agentContext
}

public async createResource(did: string, options: CheqdCreateResourceOptions) {
const cheqdDidRegistrar = this.agentContext.dependencyManager.resolve(CheqdDidRegistrar)
return await cheqdDidRegistrar.createResource(this.agentContext, did, options)
}

public async resolveResource(resourceUrl: string) {
const cheqdDidResolver = this.agentContext.dependencyManager.resolve(CheqdDidResolver)
return await cheqdDidResolver.resolveResource(this.agentContext, resourceUrl)
}
}
2 changes: 2 additions & 0 deletions packages/cheqd/src/CheqdModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import type { AgentContext, DependencyManager, Module } from '@credo-ts/core'

import { AgentConfig, Buffer } from '@credo-ts/core'

import { CheqdApi } from './CheqdApi'
import { CheqdModuleConfig } from './CheqdModuleConfig'
import { CheqdLedgerService } from './ledger'

export class CheqdModule implements Module {
public readonly config: CheqdModuleConfig
public readonly api = CheqdApi

public constructor(config: CheqdModuleConfigOptions) {
this.config = new CheqdModuleConfig(config)
Expand Down
5 changes: 4 additions & 1 deletion packages/cheqd/src/dids/CheqdDidRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,11 @@ export interface CheqdDidDeactivateOptions extends DidCreateOptions {
}
}

export interface CheqdCreateResourceOptions extends Omit<Partial<MsgCreateResourcePayload>, 'data'> {
export interface CheqdCreateResourceOptions extends Pick<MsgCreateResourcePayload, 'id' | 'name' | 'resourceType'> {
data: string | Uint8Array | object
collectionId?: MsgCreateResourcePayload['collectionId']
version?: MsgCreateResourcePayload['version']
alsoKnownAs?: MsgCreateResourcePayload['alsoKnownAs']
}

interface IVerificationMethod {
Expand Down
Loading

0 comments on commit 4485dc9

Please sign in to comment.