Skip to content

Commit

Permalink
feat: added deactivateDidEndpoint function according to decentralized…
Browse files Browse the repository at this point in the history
…-identity's universal-registrar and renamed previous method as deleteDidEndpoint and marked it as deprecated
  • Loading branch information
sksadjad committed Apr 26, 2024
1 parent 9f7c78f commit 39a6601
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
44 changes: 43 additions & 1 deletion packages/uni-resolver-registrar-api/src/api-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { v4 } from 'uuid'
import {
CreateState,
DidRegistrationCreateRequest,
DidRegistrationDeactivateRequest,
DidStateValue,
ICreateDidEndpointOpts,
IGlobalDidWebEndpointOpts,
Expand Down Expand Up @@ -167,7 +168,13 @@ export function resolveDidEndpoint(router: Router, context: IRequiredContext, op
})
}

export function deactivateDidEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
/**
* @deprecated
* @param router
* @param context
* @param opts
*/
export function deleteDidEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
if (opts?.enabled === false) {
console.log(`Deactivate DID endpoint is disabled`)
return
Expand All @@ -191,6 +198,41 @@ export function deactivateDidEndpoint(router: Router, context: IRequiredContext,
})
}

export function deactivateDidEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
if (opts?.enabled === false) {
console.log('Deactivate DID endpoint is disabled')
return
}

router.post(opts?.path ?? '/deactivate', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
try {
const deactivateRequest: DidRegistrationDeactivateRequest = request.body
if (!deactivateRequest) {
return sendErrorResponse(response, 400, 'Invalid request body', { state: 'failed' })
}

const { did, jobId = v4() } = deactivateRequest
if (!did) {
return sendErrorResponse(response, 400, 'No DID provided', { state: 'failed' })
}

const result = await context.agent.didManagerDelete({ did })
if (!result) {
return sendErrorResponse(response, 404, `DID ${did} not found`, { state: 'failed' })
}

response.status(200).json({
state: 'finished',
did,
jobId,
})
return response.send()
} catch (e) {
return sendErrorResponse(response, 500, e.message as string, { state: 'failed', errorDetails: e })
}
})
}

/**
* Endpoint that eases DID web resolution, by mapping did-web paths to stored agent DIDs.
*
Expand Down
6 changes: 3 additions & 3 deletions packages/uni-resolver-registrar-api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export interface DidRegistrationUpdateRequest {

export interface DidRegistrationDeactivateRequest {
did: string
jobId: string
options: DidRegistrationOptions
secret: DidRegistrationSecret
jobId?: string
options?: DidRegistrationOptions
secret?: DidRegistrationSecret
}

export type DidDocumentOperation = 'setDidDocument' | 'addToDidDocument' | 'removeFromDidDocument' | string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { copyGlobalAuthToEndpoints, ExpressSupport } from '@sphereon/ssi-express
import { TAgent } from '@veramo/core'

import express, { Express, Router } from 'express'
import { createDidEndpoint, deactivateDidEndpoint, getDidMethodsEndpoint, resolveDidEndpoint } from './api-functions'
import { createDidEndpoint, deleteDidEndpoint, deactivateDidEndpoint, getDidMethodsEndpoint, resolveDidEndpoint } from './api-functions'
import { IDidAPIOpts, IRequiredPlugins } from './types'

export class UniResolverApiServer {
Expand Down Expand Up @@ -34,7 +34,8 @@ export class UniResolverApiServer {
}
if (features.includes('did-persist')) {
createDidEndpoint(this.router, context, opts?.endpointOpts?.createDid)
deactivateDidEndpoint(this.router, context, opts?.endpointOpts?.deactivateDid) // not in spec.
deleteDidEndpoint(this.router, context, opts?.endpointOpts?.deactivateDid) // not in spec.
deactivateDidEndpoint(this.router, context, opts?.endpointOpts?.deactivateDid)
}
this._express.use(opts?.endpointOpts?.basePath ?? '', this.router)
}
Expand Down

0 comments on commit 39a6601

Please sign in to comment.