Skip to content

Commit

Permalink
docs: Update Readme (#74)
Browse files Browse the repository at this point in the history
* docs: Update Readme

* feat: Update swagger
  • Loading branch information
DaevMithran authored Jan 31, 2023
1 parent e9333c4 commit 07d6629
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 11 deletions.
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,55 @@ The purpose of this service is to provide a [Universal Registrar driver](https:/

- `/create`
- `/update`
- `/deactivate`
- `/create-resource`
- `/api-docs`

## 🧑‍💻🛠 Developer Guide

### Setup

To build and run in Docker, use the [Dockerfile](Dockerfile) provided.
#### Environment variable configuration

Environment variables needed for the Registrar are

1. `FEE_PAYER_TESTNET_MNEMONIC` : The cosmos payer mnemonic for the Cheqd Mainnet
2. `FEE_PAYER_MAINNET_MNEMONIC` : The cosmos payer mnemonic for the Cheqd Tesnet, By default it's the Testnet Faucet
3. `LOCAL_STORE_TTL` (default: `600`): The time in seconds for the registrar to store data in cache
4. `PORT` (default: `3000`): The port number


Clone the repository

```bash
git clone [email protected]:cheqd/did-registrar.git
cd did-registrar
```

***

### Running a DID Registrar Using Docker

Build Docker container image using Dockerfile:

```bash
docker build --target cheqd-did-registrar . --tag did-registrar:local
```

Run the Docker container (modify according to your own build tags and other desired parameters):

```bash
docker run -it did-registrar:local
```

***

### Running a DID Registrar Locally

```bash
docker build -t cheqd-did-registrar .
npm install
npm run build
npm start
```

## 🐞 Bug reports & 🤔 feature requests
Expand Down
8 changes: 4 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class App {
app.get('/', (req, res) => res.redirect('api-docs'))

// did-registrar
app.post(`${URL_PREFIX}/create`, DidController.didDocValidator, new DidController().create)
app.post(`${URL_PREFIX}/update`, DidController.updateValidator, DidController.didDocValidator, new DidController().update)
app.post(`${URL_PREFIX}/deactivate`, DidController.deactivateValidator, new DidController().deactivate)
app.post(`${URL_PREFIX}/:did/create-resource`, ResourceController.createValidator, new ResourceController().create)
app.post(`${URL_PREFIX}/create`, DidController.createValidator, DidController.commonValidator, new DidController().create)
app.post(`${URL_PREFIX}/update`, DidController.updateValidator, DidController.commonValidator, new DidController().update)
app.post(`${URL_PREFIX}/deactivate`, DidController.deactivateValidator, DidController.commonValidator, new DidController().deactivate)
app.post(`${URL_PREFIX}/:did/create-resource`, ResourceController.createValidator, DidController.commonValidator, new ResourceController().create)

// cheqd-helpers
app.get(`${URL_PREFIX}/key-pair`, new CheqdController().generateKeys)
Expand Down
11 changes: 9 additions & 2 deletions src/controllers/did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,28 @@ import { LocalStore } from './store'

export class DidController {

public static didDocValidator = [
public static createValidator = [
check('didDocument').custom((value, {req})=>{
if(!req.body.jobId && value) {
const {valid} = validateSpecCompliantPayload(value)
return valid
}
return true
}).withMessage(Messages.InvalidDidDocument),
}).withMessage(Messages.InvalidDidDocument)
]

public static commonValidator = [
check('options.versionId').optional().isString().withMessage(Messages.InvalidOptions),
check('secret.signingResponse').optional().isArray().withMessage(Messages.InvalidSecret),
check('secret.signingResponse.*.signature').isString().withMessage(Messages.InvalidSecret),
check('secret.signingResponse.*.verificationMethodId').isString().withMessage(Messages.InvalidSecret)
]

public static updateValidator = [
check('didDocument').optional().isArray().custom((value, {req})=>{
const {valid} = validateSpecCompliantPayload(value[0])
return valid
}).withMessage(Messages.InvalidDidDocument),
check('jobId').custom((value, {req})=>value || (req.body.did && req.body.didDocument)).withMessage(Messages.Invalid),
check('did').optional().isString().withMessage(Messages.InvalidDid).contains('did:cheqd:').withMessage(Messages.InvalidDid),
check('didDocumentOperation').optional().isArray().custom((value) => value[0] === DidDocumentOperation.Set && value.length == 1 ).withMessage('Only Set operation is supported')
Expand Down
11 changes: 9 additions & 2 deletions src/controllers/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import { DIDDocument } from '@cheqd/sdk/build/types';
import { MsgCreateResourcePayload } from '@cheqd/ts-proto/cheqd/resource/v2';

import NodeCache from 'node-cache'
import * as dotenv from 'dotenv'

import { IState } from '../types/types';

dotenv.config()

let {
LOCAL_STORE_TTL
} = process.env

export class LocalStore {
private cache: NodeCache

Expand All @@ -15,15 +22,15 @@ export class LocalStore {
}

setItem(key: string, data: IDidDocData) {
this.cache.set(key, data, 600)
this.cache.set(key, data, LOCAL_STORE_TTL || 600)
}

getItem(key: string) {
return this.cache.get(key) as IDidDocData | undefined
}

setResource(key: string, data: IResourceData) {
this.cache.set(key, data, 600)
this.cache.set(key, data, LOCAL_STORE_TTL || 600)
}

getResource(key: string) {
Expand Down
2 changes: 2 additions & 0 deletions src/types/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ declare global {
interface ProcessEnv {
FEE_PAYER_TESTNET_MNEMONIC: string
FEE_PAYER_MAINNET_MNEMONIC: string
LOCAL_STORE_TTL: number
PORT: number
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
"$ref": "#/components/schemas/Options"
},
"secret": {
"$ref": "#/components/schemas/SigningResponse"
"$ref": "#/components/schemas/Secret"
},
"didDocument": {
"$ref": "#/components/schemas/DidDocument"
Expand Down

0 comments on commit 07d6629

Please sign in to comment.