Skip to content

Commit

Permalink
feat: Update swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed May 12, 2023
1 parent d3c036a commit 3772b9e
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 38 deletions.
14 changes: 9 additions & 5 deletions src/controllers/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ export class CustomerController {
const kid = (await Identity.instance.createKey('Secp256k1')).kid
const customer = await CustomerService.instance.create(response.locals.customerId, kid)
if(!customer) {
return response.status(500).json({
return response.status(400).json({
error: `Error creating customer. Please try again`
})
}
const { account, ...res } = customer
return response.status(200).json(res)
return response.status(200).json({
customerId: customer.customerId,
address: customer.address
})
} catch (error) {
return response.status(500).json({
error: `Error creating customer ${error}`
Expand All @@ -38,8 +40,10 @@ export class CustomerController {
try {
const result = await CustomerService.instance.get(response.locals.customerId)
if(result && !Array.isArray(result)) {
const { account, ...res } = result
return response.status(200).json(res)
return response.status(200).json({
customerId: result.customerId,
address: result.address
})
}

return response.status(400).json({
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class IssuerController {
}

public async createDid(request: Request, response: Response) {
const { options, secret, alias } = request.body
const { options, secret } = request.body
const { methodSpecificIdAlgo, network, versionId = v4()} = options
const verificationMethod = secret?.verificationMethod
let didDocument: DIDDocument
Expand All @@ -63,7 +63,7 @@ export class IssuerController {
})
}

const did = await Identity.instance.createDid(network, didDocument, alias, response.locals.customerId)
const did = await Identity.instance.createDid(network, didDocument, response.locals.customerId)
await CustomerService.instance.update(response.locals.customerId, { kids, dids: [did.did] })
return response.status(200).json(did)
} catch (error) {
Expand Down
5 changes: 2 additions & 3 deletions src/services/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Resolver, ResolverRegistry } from 'did-resolver'
import { CheqdDIDProvider, getResolver as CheqdDidResolver } from '@cheqd/did-provider-cheqd'
import { v4 } from 'uuid'

import { cheqdDidRegex, DefaultResolverUrl, DefaultRPCUrl } from '../types/types'
import { cheqdDidRegex, DefaultRPCUrl } from '../types/types'
import { CheqdNetwork } from '@cheqd/sdk'
import { Connection } from '../database/connection/connection'
import { CustomerEntity } from '../database/entities/customer.entity'
Expand Down Expand Up @@ -149,15 +149,14 @@ export class Identity {
return await this.privateStore!.get({ alias: kid })
}

async createDid(network: string, didDocument: DIDDocument, alias: string = v4(), agentId?: string): Promise<IIdentifier> {
async createDid(network: string, didDocument: DIDDocument, agentId?: string): Promise<IIdentifier> {
try {
const agentService = agentId ? await this.create_agent(agentId) : this.agent
if (!agentService) throw new Error('No initialised agent found.')

const [kms] = await agentService.keyManagerGetKeyManagementSystems()

const identifier: IIdentifier = await agentService.didManagerCreate({
alias,
provider: `did:cheqd:${network}`,
kms,
options: {
Expand Down
253 changes: 225 additions & 28 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,160 @@
}
],
"paths": {
"/key": {
"post": {
"tags": [
"Key"
],
"summary": "Create a Keypair",
"security": [
{
"bearerAuth": []
}
],
"responses": {
"200": {
"description": "The request was successful",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/KeyResult"
}
}
}
},
"400": {
"description": "A problem with the input fields has occurred. Additional state information plus metadata may be available in the response body.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InvalidRequest"
},
"example": {
"error": "Invalid Request"
}
}
}
},
"401": {
"$ref": "#/components/schemas/UnauthorizedError"
},
"500": {
"description": "An internal error has occurred. Additional state information plus metadata may be available in the response body.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InvalidRequest"
},
"example": {
"error": "Internal Error"
}
}
}
}
}
},
"get": {
"tags": [
"Key"
],
"summary": "List keypairs",
"security": [
{
"bearerAuth": []
}
],
"responses": {
"200": {
"description": "The request was successful",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
},
"401": {
"$ref": "#/components/schemas/UnauthorizedError"
},
"500": {
"description": "An internal error has occurred. Additional state information plus metadata may be available in the response body.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InvalidRequest"
},
"example": {
"error": "Internal Error"
}
}
}
}
}
}
},
"/key/{kid}": {
"get": {
"tags": [
"Key"
],
"summary": "Fetch keypair",
"security": [
{
"bearerAuth": []
}
],
"parameters": [
{
"in": "path",
"name": "kid",
"schema": {
"type": "string"
},
"required": true
}
],
"responses": {
"200": {
"description": "The request was successful",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/KeyResult"
}
}
}
},
"401": {
"$ref": "#/components/schemas/UnauthorizedError"
},
"500": {
"description": "An internal error has occurred. Additional state information plus metadata may be available in the response body.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InvalidRequest"
},
"example": {
"error": "Internal Error"
}
}
}
}
}
}
},
"/did": {
"post": {
"tags": [
"DID"
],
"summary": "Create a DID",
"description": "<p>This endpoint creates a DID by taking DID document as an input.</p>",
"description": "<p>This endpoint creates a DID by taking DID document or a verification method as an input.</p>",
"security": [
{
"bearerAuth": []
Expand All @@ -36,12 +183,53 @@
"application/json": {
"schema": {
"type": "object",
"required": [
"options"
],
"properties": {
"options": {
"type": "object",
"properties": {
"network": {
"type": "string",
"enum": [
"testnet",
"mainnet"
]
},
"methodSpecificIdAlgo": {
"type": "string",
"enum": [
"base58btc",
"uuid"
]
}
}
},
"secret": {
"type": "object",
"properties": {
"verificationMethod": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"Ed25519VerificationKey2020",
"JsonWebKey2020",
"Ed25519VerificationKey2018"
]
},
"id": {
"type": "string",
"example": "key-1"
}
}
}
}
},
"didDocument": {
"$ref": "#/components/schemas/DidDocument"
},
"alias": {
"type": "string"
}
}
}
Expand Down Expand Up @@ -72,6 +260,9 @@
}
}
},
"401": {
"$ref": "#/components/schemas/UnauthorizedError"
},
"500": {
"description": "An internal error has occurred. Additional state information plus metadata may be available in the response body.",
"content": {
Expand Down Expand Up @@ -125,6 +316,9 @@
}
}
},
"401": {
"$ref": "#/components/schemas/UnauthorizedError"
},
"500": {
"description": "An internal error has occurred. Additional state information plus metadata may be available in the response body.",
"content": {
Expand Down Expand Up @@ -187,6 +381,9 @@
}
}
},
"401": {
"$ref": "#/components/schemas/UnauthorizedError"
},
"500": {
"description": "An internal error has occurred. Additional state information plus metadata may be available in the response body.",
"content": {
Expand Down Expand Up @@ -248,6 +445,9 @@
}
}
},
"401": {
"$ref": "#/components/schemas/UnauthorizedError"
},
"500": {
"description": "An internal error has occurred. Additional state information plus metadata may be available in the response body.",
"content": {
Expand Down Expand Up @@ -315,6 +515,9 @@
}
}
},
"401": {
"$ref": "#/components/schemas/UnauthorizedError"
},
"500": {
"description": "An internal error has occurred. Additional state information plus metadata may be available in the response body.",
"content": {
Expand Down Expand Up @@ -472,6 +675,24 @@
}
}
},
"KeyResult": {
"type": "object",
"properties": {
"kid": {
"type": "string"
},
"type": {
"type": "string",
"enum": [
"Ed25519",
"Secp256k1"
]
},
"publicKeyHex": {
"type": "string"
}
}
},
"DidDocument": {
"description": "This input field contains either a complete DID document, or an incremental change (diff) to a DID document. See <a href=\"https://identity.foundation/did-registration/#diddocument\">https://identity.foundation/did-registration/#diddocument</a>.",
"type": "object",
Expand Down Expand Up @@ -750,30 +971,6 @@
},
"address": {
"type": "string"
},
"kids": {
"type": "array",
"items": {
"type": "string"
}
},
"dids": {
"type": "array",
"items": {
"type": "string"
}
},
"claimIds": {
"type": "array",
"items": {
"type": "string"
}
},
"presentationIds": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
Expand Down

0 comments on commit 3772b9e

Please sign in to comment.