Commit ab280829 authored by Hidde-Jan Jongsma's avatar Hidde-Jan Jongsma

Initial commit

parents
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint',
],
root: true,
env: {
node: true,
jest: true,
},
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
\ No newline at end of file
{
"singleQuote": true,
"trailingComma": "all"
}
\ No newline at end of file
FROM node:10
RUN npm install --global @nestjs/cli
RUN mkdir -p /app/node_modules && chown -R node:node /app
USER node
# Create Directory for the Container
WORKDIR /app
# Only copy the package.json and yarn.lock to work directory
COPY package.json package-lock.json ./
# Install all Packages
RUN npm install
# Copy all other source code to work directory
COPY . ./
ENV SSI_SERVER_URL=https://path/to/my/server
EXPOSE 3000
# need to build at runtime because config.ts might be replaced/mounted
CMD [ "npm", "run", "start:dev" ]
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
</p>
[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master
[travis-url]: https://travis-ci.org/nestjs/nest
[linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux
[linux-url]: https://travis-ci.org/nestjs/nest
<p align="center">A progressive <a href="http://nodejs.org" target="blank">Node.js</a> framework for building efficient and scalable server-side applications, heavily inspired by <a href="https://angular.io" target="blank">Angular</a>.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a>
<a href="https://travis-ci.org/nestjs/nest"><img src="https://api.travis-ci.org/nestjs/nest.svg?branch=master" alt="Travis" /></a>
<a href="https://travis-ci.org/nestjs/nest"><img src="https://img.shields.io/travis/nestjs/nest/master.svg?label=linux" alt="Linux" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5" alt="Coverage" /></a>
<a href="https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/nestjs/nestjs.svg" alt="Gitter" /></a>
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a>
<a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
## Description
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
## Installation
```bash
$ npm install
```
## Running the app
```bash
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
```
## Test
```bash
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
```
## Support
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
## Stay in touch
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)
## License
Nest is [MIT licensed](LICENSE).
File added
{
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
This diff is collapsed.
{
"name": "ssi-service-backend",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^7.0.0",
"@nestjs/core": "^7.0.0",
"@nestjs/platform-express": "^7.0.0",
"@nestjs/typeorm": "^7.0.0",
"class-transformer": "^0.2.3",
"class-validator": "^0.12.2",
"jolocom-lib": "^4.1.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.5.4",
"sqlite3": "^4.2.0",
"typeorm": "^0.2.24"
},
"devDependencies": {
"@nestjs/cli": "^7.0.0",
"@nestjs/schematics": "^7.0.0",
"@nestjs/testing": "^7.0.0",
"@types/express": "^4.17.3",
"@types/jest": "25.1.4",
"@types/node": "^13.9.1",
"@types/supertest": "^2.0.8",
"@typescript-eslint/eslint-plugin": "^2.23.0",
"@typescript-eslint/parser": "^2.23.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.1",
"jest": "^25.1.0",
"prettier": "^1.19.1",
"supertest": "^4.0.2",
"ts-jest": "25.2.1",
"ts-loader": "^6.2.1",
"ts-node": "^8.6.2",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.7.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getHello(): string {
return this.appService.getHello();
}
}
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { WalletModule } from './wallet/wallet.module';
import { OrganizationsModule } from './organizations/organizations.module';
import { ConnectorsModule } from './connectors/connectors.module';
import { RequestsModule } from './requests/requests.module';
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'sqlite',
database: './dev.sqlite3',
synchronize: true,
autoLoadEntities: true,
}),
WalletModule,
OrganizationsModule,
ConnectorsModule,
RequestsModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
getServerBaseUrl(): string {
return process.env.SSI_SERVER_URL || 'http://localhost:3000';
}
getIrmaUrl(): string {
return process.env.IRMA_SERVER_URL || 'http://localhost:8989';
}
getUrl(path: string): string {
return new URL(path, this.getServerBaseUrl()).toString();
}
}
import { Organization } from 'src/organizations/organization.entity';
/**
* Interface describing a Connector that can be used by the SSI-service
* e.g. connectors for Jolocom, IRMA, ...
*/
export interface ConnectorService {
type: string;
/**
* Method for registering an organisation to use a certain SSI implementation
* E.g. for Jolocom a self-sovereign identity must be created and anchored on Ethereum (see: https://jolocom-lib.readthedocs.io/en/latest/gettingStarted.html#how-to-create-a-self-sovereign-identity)
* Other implementations might require other initialization steps
*/
registerOrganization(org: Organization): Promise<void>;
// registerRoutes(root: string, app: Express): void;
// processCredentialIssueRequest(request: CredentialIssueRequest): Promise<void>;
// processCredentialVerifyRequest(
// request: CredentialVerifyRequest,
// ): Promise<void>;
}
import { Module } from '@nestjs/common';
import { JolocomModule } from './jolocom/jolocom.module';
import { IrmaModule } from './irma/irma.module';
import { ConnectorsService } from './connectors.service';
@Module({
imports: [JolocomModule, IrmaModule],
providers: [ConnectorsService],
exports: [ConnectorsService],
})
export class ConnectorsModule {}
import { Test, TestingModule } from '@nestjs/testing';
import { ConnectorsService } from './connectors.service';
describe('ConnectorsService', () => {
let service: ConnectorsService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ConnectorsService],
}).compile();
service = module.get<ConnectorsService>(ConnectorsService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { Injectable } from '@nestjs/common';
import { JolocomService } from './jolocom/jolocom.service';
import { IrmaService } from './irma/irma.service';
import { ConnectorService } from './connector-service.interface';
@Injectable()
export class ConnectorsService {
private connectors: ConnectorService[] = [];
constructor(
private jolocomService: JolocomService,
private irmaService: IrmaService,
) {
this.connectors.push(this.jolocomService);
this.connectors.push(this.irmaService);
}
getConnector(type: string) {
return this.connectors.find(connector => connector.type === type);
}
}
import { Module } from '@nestjs/common';
import { IrmaService } from './irma.service';
@Module({
providers: [IrmaService],
exports: [IrmaService],
})
export class IrmaModule {}
import { Test, TestingModule } from '@nestjs/testing';
import { IrmaService } from './irma.service';
describe('IrmaService', () => {
let service: IrmaService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [IrmaService],
}).compile();
service = module.get<IrmaService>(IrmaService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { Injectable } from '@nestjs/common';
import { ConnectorService } from '../connector-service.interface';
import { Organization } from 'src/organizations/organization.entity';
@Injectable()
export class IrmaService implements ConnectorService {
type = 'irma';
async registerOrganization(organization: Organization) {
return;
}
}
import { Module } from '@nestjs/common';
import { JolocomService } from './jolocom.service';
@Module({
providers: [JolocomService],
exports: [JolocomService],
})
export class JolocomModule {}
import { Test, TestingModule } from '@nestjs/testing';
import { JolocomService } from './jolocom.service';
describe('JolocomService', () => {
let service: JolocomService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [JolocomService],
}).compile();
service = module.get<JolocomService>(JolocomService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { Injectable } from '@nestjs/common';
import { ConnectorService } from '../connector-service.interface';
import { Organization } from 'src/organizations/organization.entity';
@Injectable()
export class JolocomService implements ConnectorService {
type = 'jolocom';
async registerOrganization(organization: Organization) {
return;
}
}
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe());
await app.listen(3000);
}
bootstrap();
import { IsNotEmpty, IsString } from 'class-validator';
export class CreateOrganizationDto {
@IsString()
@IsNotEmpty()
name: string;
}
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
import { randomBytes } from 'crypto';
const JWT_SECRET_BITS = 32;
@Entity()
export class Organization {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column()
sharedSecret: string;
static randomSecret(): string {
return randomBytes(JWT_SECRET_BITS).toString('hex');
}
}
import { Test, TestingModule } from '@nestjs/testing';
import { OrganizationsController } from './organizations.controller';
describe('Organizations Controller', () => {
let controller: OrganizationsController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [OrganizationsController],
}).compile();
controller = module.get<OrganizationsController>(OrganizationsController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
import { Controller, Get, Body, Post } from '@nestjs/common';
import { OrganizationsService } from './organizations.service';
import { CreateOrganizationDto } from './create-organization.dto';
@Controller('organizations')
export class OrganizationsController {
constructor(private organizationsService: OrganizationsService) {}
@Get()
index() {
return this.organizationsService.findAll();
}
@Post()
create(@Body() organizationParams: CreateOrganizationDto) {
return this.organizationsService.createFromName(organizationParams.name);
}
}
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { OrganizationsController } from './organizations.controller';
import { OrganizationsService } from './organizations.service';
import { Organization } from './organization.entity';
@Module({
imports: [TypeOrmModule.forFeature([Organization])],
controllers: [OrganizationsController],
providers: [OrganizationsService],
})
export class OrganizationsModule {}
import { Test, TestingModule } from '@nestjs/testing';
import { OrganizationsService } from './organizations.service';
describe('OrganizationsService', () => {
let service: OrganizationsService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [OrganizationsService],
}).compile();
service = module.get<OrganizationsService>(OrganizationsService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Organization } from './organization.entity';