Skip to content

Commit

Permalink
Merge pull request #105 from hypersign-protocol/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Vishwas1 authored Oct 18, 2023
2 parents d686082 + 58dc821 commit 0497149
Show file tree
Hide file tree
Showing 37 changed files with 1,446 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Dockerfile
.dockerignore
docker-compose.yml
./node_modules
# .env
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:16
WORKDIR /usr/src/app
COPY ./package.json .
COPY ./yarn.lock .
COPY ./tsconfig.json .
RUN yarn
# RUN yarn build:nest
COPY . .
CMD ["yarn", "start:dev"]






1 change: 1 addition & 0 deletions dev.env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PORT=
DATABASE_CONNECTION_PATH=
HID_NETWORK_RPC=
HID_NETWORK_API=
Expand Down
121 changes: 121 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
version: '3.9'

services:

# MongoDB services
entity_db:
container_name: entity_db
image: mongo:latest
restart: always
volumes:
- entity_db:/data/db

# EDV service
edv.service.id:
container_name: edv.service.id
build: /Users/hermit/code/hm/hs/hypersign-edv-service
environment:
PORT: 3002
HOST: edv.service.id:3002
SSL: false
ABSOULTE_URL: edv.service.id:3002
DATA_VAULT: './.encData'
DB_URL: mongodb://entity_db:27017/test
depends_on:
- entity_db

# Entity API service
api.entity.id:
container_name: api.entity.id
build: .
ports:
- 3001:3001
environment:
DATABASE_CONNECTION_PATH: mongodb://entity_db:27017/admin
HID_NETWORK_RPC: https://rpc.jagrat.hypersign.id/
HID_NETWORK_API: https://api.jagrat.hypersign.id/
HID_NETWORK_NAMESPACE: testnet
EDV_BASE_URL: http://edv.service.id:3002
EDV_CONFIG_DIR: '.api-edv-config'
EDV_DID_FILE_PATH: '.api-edv-config/edv-did.json'
EDV_KEY_FILE_PATH: '.api-edv-config/edv-keys.json'
MNEMONIC: 'parade erase firm goose old elegant sausage sweet stuff view goddess total museum hidden worry usual rug foster uncover cradle govern swing muscle unable'
JWT_SECRET: '76JpMGuSf0ejzi4OFHpe'
WHITELISTED_CORS: '["http://localhost:9001","https://entity.hypersign.id","http://localhost:3001","https://api.entity.hypersign.id"]'
STUDIO_SERVER_JWT_SECRET: 00c2c433-a077-4e68-b19c-1234f014a510
depends_on:
- entity_db
- edv.service.id

# Entity Studio Service
studio.server.id:
container_name: studio.server.id
build: /Users/hermit/code/hm/hs/studio/server
ports:
- 9000:9000
environment:
NODE_ENV: development
PORT: 9000
HOST: localhost
LOG_FILEPATH: ./log/studio-server.log
LOG_DIR: ./log
LOG_TIMESTAMP_FORMAT: 'YYYY-MM-DD HH:mm:ss.SSS'
LOG_LEVEL: debug
DATABASE_FILEPATH: ./db/studio-server.db
DID_METHOD_NAME: hs
DID_PREFIX: did
JWT_SECRET: my\$ecreEtKeY@123
STUDIO_SERVER_BASE_URL: http://studio.server.id
NODE_SERVER_BASE_URL: http://localhost:5000/
NODE_SERVER_DID_CREATE_EP: api/did/create_tmp
NODE_SERVER_SCHEMA_CREATE_EP: api/schema/create
MAIL_HOST: smtp.gmail.com
MAIL_PORT: 65
MAIL_USERNAME: [email protected]
MAIL_PASSWORD: examplePassw00rd1@
MAIL_NAME: 'Hypersign Admin'
DB_URL: mongodb://entity_db:27017/studio-server
WALLET_WEB_HOOK: http://studio.server.id/api/v1/schema/status
WALLET_WEB_HOOK_CREAD: http://studio.server.id/api/v1/credential/status
ACCEPTANCE_URL: http://studio.server.id/deeplink.html?deeplink=hypersign:deeplink?url=
PATH_TO_ISSUE_CRED: api/v1/credential/walletAccepct
WALLET_WEB_HOOK_ORG_DID: http://studio.server.id/api/v1/org/status
ORG_SERVICE_END_POINT: http://studio.server.id/api/v1/org/
SSE_CLIENT_URL: http://localhost:9001
WHITELISTED_CORS: '["http://studio.server.id","http://localhost:9001","http://192.168.29.12:9001", "https://localhost:9001", "http://192.168.29.209:9001", "http://entity.hypersign.id","https://entity.hypersign.id","http://localhost:9001", "https://wallet-stage.hypersign.id", "http://localhost:4999","192.168.29.13","http://localhost:1234","http://localhost:4000", "*"]'
SCHEMA_RESOLVER: https://api.jagrat.hypersign.id/hypersign-protocol/hidnode/ssi/schema/
depends_on:
- entity_db

# Entity Studio FrontEnd
studio.ui:
container_name: studio.ui
build: /Users/hermit/code/hm/hs/studio-frontend
ports:
- 9001:80
environment:
NODE_ENV: development
VUE_APP_TITLE: 'Entity Studio'
VUE_APP_DESC: 'A portal to issue and verify credentials on Hypersign Identity network!'
VUE_APP_VERSION: v1.0
VUE_APP_STUDIO_SERVER_BASE_URL: http://localhost:9000/
VUE_APP_STUDIO_SERVER_BASE_WS: ws://localhost:9000/
VUE_APP_NODE_SERVER_BASE_URL: https://rpc.jagrat.hypersign.id/
VUE_APP_NODE_SERVER_BASE_URL_REST: https://api.jagrat.hypersign.id/
VUE_APP_SCHEMA_GET_EP_REST: hypersign-protocol/hidnode/ssi/schema/
VUE_APP_ACCPCT_CRED_EP: api/v1/credential/send
VUE_APP_EXPLORER_BASE_URL: https://explorer.hypersign.id/
VUE_APP_STUDIO_SERVER_SAVE_SCHEMA: api/v1/schema
VUE_APP_SCHEMA_LIST_EP: api/v1/schema
VUE_APP_STUDIO_SERVER_CRED_LIST_EP: api/v1/credential/org
VUE_APP_STUDIO_SERVER_CRED_ISSUE_EP: api/v1/credential
VUE_APP_WEB_WALLET_ADDRESS: https://wallet-stage.hypersign.id
VUE_APP_PRESENTATION_TEMPLATE_EP: api/v1/presentation/template
VUE_APP_SSE: http://localhost:9000/
VUE_APP_STUDIO_API_SERVER_HOST: http://localhost:3001
depends_on:
- studio.server.id
- api.entity.id

volumes:
entity_db: {}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"class-validator": "^0.14.0",
"fs": "^0.0.1-security",
"hid-hd-wallet": "git+https://github.com/hypersign-protocol/hid-hd-wallet.git#ssi-integration",
"hs-ssi-sdk": "git+https://github.com/hypersign-protocol/hid-ssi-js-sdk.git#HSSTUD-219",
"hs-ssi-sdk": "git+https://github.com/hypersign-protocol/hid-ssi-js-sdk.git#recent_development",
"hypersign-edv-client": "git+https://[email protected]/hypersign-protocol/hypersign-edv-client.git#authentication",
"mongoose": "^6.8.3",
"passport": "^0.6.0",
Expand All @@ -63,6 +63,7 @@
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^8.0.0",
"jest": "29.3.1",
"newman": "^5.3.2",
"prettier": "^2.3.2",
Expand All @@ -72,8 +73,7 @@
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.1",
"typescript": "^4.7.4",
"husky": "^8.0.0"
"typescript": "^4.7.4"
},
"jest": {
"moduleFileExtensions": [
Expand Down
16 changes: 16 additions & 0 deletions src/app-auth/controllers/app-auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Req,
Delete,
Headers,
Logger,
} from '@nestjs/common';
import { CreateAppDto } from 'src/app-auth/dtos/create-app.dto';
import {
Expand Down Expand Up @@ -85,6 +86,7 @@ export class AppAuthController {
@Req() req: any,
@Query() pageOption: PaginationDto,
): Promise<App[]> {
Logger.log('getApps() method: starts', 'AppAuthController');
const userId = req.user.userId;
const appList: any = await this.appAuthService.getAllApps(
userId,
Expand Down Expand Up @@ -116,6 +118,8 @@ export class AppAuthController {

@Param('appId') appId: string,
): Promise<App> {
Logger.log('getAppById() method: starts', 'AppAuthController');

const userId = req.user.userId;

const app = await this.appAuthService.getAppById(appId, userId);
Expand All @@ -142,6 +146,8 @@ export class AppAuthController {
@Req() req: any,
@Body() createAppDto: CreateAppDto,
): Promise<createAppResponse> {
Logger.log('register() method: starts', 'AppAuthController');

const userId = req.user.userId;

return this.appAuthService.createAnApp(createAppDto, userId);
Expand Down Expand Up @@ -173,6 +179,11 @@ export class AppAuthController {
@Param('appId') appId: string,
@Body() updateAppDto: UpdateAppDto,
): Promise<App> {
Logger.log(
'App-auth controller: update() method: starts',
'AppAuthController',
);

const userId = req.user.userId;

const app = await this.appAuthService.getAppById(appId, userId);
Expand Down Expand Up @@ -200,6 +211,8 @@ export class AppAuthController {
@Req() req: any,
@Param('appId') appId: string,
): Promise<App> {
Logger.log('deleteApp() method: starts', 'AppAuthController');

const userId = req.user.userId;
const app = await this.appAuthService.deleteApp(appId, userId);
return app;
Expand All @@ -216,6 +229,8 @@ export class AppAuthController {
type: AppError,
})
async reGenerateAppSecretKey(@Req() req: any, @Param('appId') appId: string) {
Logger.log('reGenerateAppSecretKey() method: starts', 'AppAuthController');

const userId = req.user.userId;

const app = await this.appAuthService.getAppById(appId, userId);
Expand Down Expand Up @@ -263,6 +278,7 @@ export class AppOAuthController {
@Headers('X-Api-Secret-Key') apiSectretKey: string,
@AppSecretHeader() appSecreatKey,
): Promise<{ access_token; expiresIn; tokenType }> {
Logger.log('reGenerateAppSecretKey() method: starts', 'AppOAuthController');
return this.appAuthService.generateAccessToken(appSecreatKey);
}
}
13 changes: 13 additions & 0 deletions src/app-auth/middlewares/cors.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Injectable,
Logger,
NestMiddleware,
UnauthorizedException,
} from '@nestjs/common';
Expand All @@ -9,9 +10,17 @@ import { AppRepository } from 'src/app-auth/repositories/app.repository';
export class WhitelistAppCorsMiddleware implements NestMiddleware {
constructor(private readonly appRepositiory: AppRepository) {}
async use(req: Request, res: Response, next: NextFunction) {
Logger.log(
'WhitelistAppCorsMiddleware: checking if call is form whitelisted domain starts',
'Middleware',
);
const whitelistedOrigins = process.env.WHITELISTED_CORS;
const apiSecretKey = req.headers['x-api-secret-key'] as string;
const origin = req.header('Origin');
Logger.debug(
`WhitelistAppCorsMiddleware: request is comming from ${origin}`,
'Middleware',
);
if (whitelistedOrigins.includes(origin)) {
return next();
} else if (apiSecretKey !== '' && apiSecretKey != undefined) {
Expand All @@ -26,6 +35,10 @@ export class WhitelistAppCorsMiddleware implements NestMiddleware {
return next();
}
if (!appDetail.whitelistedCors.includes(origin)) {
Logger.error(
'WhitelistAppCorsMiddleware: Error: origin mismatch',
'Middleware',
);
throw new UnauthorizedException(['Origin mismatch']);
}
return next();
Expand Down
27 changes: 26 additions & 1 deletion src/app-auth/repositories/app.repository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { App, AppDocument } from '../schemas/app.schema';
import { FilterQuery, Model } from 'mongoose';
import { InjectModel } from '@nestjs/mongoose';
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';

@Injectable()
export class AppRepository {
Expand All @@ -10,9 +10,19 @@ export class AppRepository {
) {}

async findOne(appFilterQuery: FilterQuery<App>): Promise<App> {
Logger.log(
'findOne() method: starts, finding particular app from db',
'AppRepository',
);

return this.appModel.findOne(appFilterQuery);
}
async find(appsFilterQuery: FilterQuery<App>): Promise<App[]> {
Logger.log(
'find() method: starts, finding list of apps from db',
'AppRepository',
);

return this.appModel.aggregate([
{ $match: { userId: appsFilterQuery.userId } },
{
Expand Down Expand Up @@ -40,6 +50,11 @@ export class AppRepository {
}

async create(app: App): Promise<App> {
Logger.log(
'create() method: starts, adding app data to db',
'AppRepository',
);

const newapp = new this.appModel(app);
return newapp.save();
}
Expand All @@ -48,10 +63,20 @@ export class AppRepository {
appFilterQuery: FilterQuery<App>,
app: Partial<App>,
): Promise<App> {
Logger.log(
'findOneAndUpdate() method: starts, update app data to db',
'AppRepository',
);

return this.appModel.findOneAndUpdate(appFilterQuery, app, { new: true });
}

async findOneAndDelete(appFilterQuery: FilterQuery<App>): Promise<App> {
Logger.log(
'findOneAndDelete() method: starts, delete app data to db',
'AppRepository',
);

return this.appModel.findOneAndDelete(appFilterQuery);
}
}
11 changes: 10 additions & 1 deletion src/app-auth/services/app-auth-apikey.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import * as crypto from 'crypto';
import { AppAuthSecretService } from './app-auth-passord.service';

@Injectable()
export class AppAuthApiKeyService {
constructor(private readonly appAuthService: AppAuthSecretService) {}
private generateRandomString(length: number): string {
Logger.log(
'generateRandomString() method: starts....',
'AppAuthApiKeyService',
);

return crypto
.randomBytes(Math.ceil(length / 2))
.toString('hex')
.slice(0, length);
}

async generateApiKey() {
Logger.log('generateApiKey() method: starts....', 'AppAuthApiKeyService');

const apiSecretKey = this.generateRandomString(29);
const secret = this.generateRandomString(97);
const toHash = apiSecretKey + '.' + secret;
Expand All @@ -24,6 +31,8 @@ export class AppAuthApiKeyService {
};
}
async generateAppId() {
Logger.log('generateAppId() method: starts....', 'AppAuthApiKeyService');

return await this.generateRandomString(36);
}
}
Loading

0 comments on commit 0497149

Please sign in to comment.