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: add createResource endpoint [DEV-4605][DEV-4636] #366

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
34 changes: 29 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ The purpose of this service is to provide a [Universal Registrar driver](https:/

## 📖 Endpoints

- `/create`
- `/update`
- `/deactivate`
- `/create-resource`
- `/api-docs`
- POST `/create`
- POST `/update`
- POST `/deactivate`
- POST `/{did}/create-resource`
- POST `/createResource`
- POST `/updateResource`
- GET `/key-pair`
- GET `/did-document`
- GET `/properties`
- GET `/methods`
- GET `/traits`

## 🧑‍💻🛠 Developer Guide

Expand Down Expand Up @@ -65,6 +71,24 @@ npm run build
npm start
```

### 🛠 Testing

This repository contains the playwright tests for unit and integration testing.
Add any additional tests in the `tests` directory.

You must set up these two env vars before running test:

1. `TEST_PRIVATE_KEY` : Private key for signing the requests
2. `TEST_PUBLIC_KEY` : Corresponding public key

Then execute the tests

```bash
npm run test
# if tests faile because of parallelism, run
npm run test -- --workers=1
```

## 🐞 Bug reports & 🤔 feature requests

If you notice anything not behaving how you expected, or would like to make a suggestion / request for a new feature, please create a [**new issue**](https://github.com/cheqd/did-registrar/issues/new/choose) and let us know.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 46 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express from 'express';
import express, { Request, Response } from 'express';
import Helmet from 'helmet';
import swaggerUI from 'swagger-ui-express';

Expand All @@ -8,6 +8,7 @@ import { DidController } from './controllers/did.js';
import { CheqdController } from './controllers/cheqd.js';
import { ResourceController } from './controllers/resource.js';
import { CheqdRegistrar } from './service/cheqd.js';
import { MethodSpecificIdAlgo, VerificationMethods } from '@cheqd/sdk';

class App {
public express: express.Application;
Expand All @@ -29,6 +30,27 @@ class App {
private routes() {
const app = this.express;
const URL_PREFIX = '/1.0';
const staticTraits = {
cheqd: {
updatable: true,
deactivatable: true,
enumerable: true,
historyAvailable: true,
humanReadable: false,
},
};
const properties = {
cheqd: {
supportedVerificationMethods: [
VerificationMethods.Ed255192020,
VerificationMethods.Ed255192018,
VerificationMethods.JWK,
],
supportedAlgorithm: [MethodSpecificIdAlgo.Base58, MethodSpecificIdAlgo.Uuid],
localStoreTTL: process.env.LOCAL_STORE_TTL,
},
};
const didMethods = ['cheqd'];

app.get('/', (req, res) => res.redirect('api-docs'));

Expand Down Expand Up @@ -58,6 +80,29 @@ class App {
new ResourceController().create
);

app.post(
`${URL_PREFIX}/createResource`,
ResourceController.createResourceValidator,
DidController.commonValidator,
new ResourceController().createResource
);
app.post(
`${URL_PREFIX}/updateResource`,
ResourceController.updateResourceValidator,
DidController.commonValidator,
new ResourceController().updateResource
);

app.get(`${URL_PREFIX}/methods`, (req: Request, res: Response) => {
res.status(200).json(didMethods);
});
app.get(`${URL_PREFIX}/properties`, (req: Request, res: Response) => {
res.status(200).json(properties);
});
app.get(`${URL_PREFIX}/traits`, (req: Request, res: Response) => {
res.status(200).json(staticTraits);
});

// cheqd-helpers
app.get(`${URL_PREFIX}/key-pair`, new CheqdController().generateKeys);
app.get(`${URL_PREFIX}/did-document`, CheqdController.didDocValidator, new CheqdController().generateDidDoc);
Expand Down
Loading
Loading