-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"content": [ | ||
{ | ||
"alsoKnownAs": [ | ||
"C4GT", | ||
"https://www.codeforgovtech.in/" | ||
], | ||
"services": [ | ||
{ | ||
"id": "C4GT", | ||
"type": "IdentityHub", | ||
"serviceEndpoint": { | ||
"@context": "schema.c4gt.acknowledgment", | ||
"@type": "UserServiceEndpoint", | ||
"instance": [ | ||
"https://www.codeforgovtech.in" | ||
] | ||
} | ||
} | ||
], | ||
"method": "C4GT" | ||
} | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { IdentityController } from './identity.controller'; | ||
|
||
describe('IdentityController', () => { | ||
let controller: IdentityController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [IdentityController], | ||
}).compile(); | ||
|
||
controller = module.get<IdentityController>(IdentityController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Controller, Post, Get, Body, Param } from '@nestjs/common'; | ||
import { IdentityService } from './identity.service'; | ||
|
||
@Controller('identity') | ||
export class IdentityController { | ||
constructor(private readonly identityService: IdentityService) {} | ||
|
||
@Post('generate') | ||
async generateIdentity() { | ||
return this.identityService.generateIdentity(); | ||
} | ||
|
||
@Get('resolve/:did') | ||
async resolveIdentity(@Param('did') did: string) { | ||
return this.identityService.resolveIdentity(did); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { IdentityService } from './identity.service'; | ||
import { IdentityController } from './identity.controller'; | ||
import { HttpModule } from '@nestjs/axios'; | ||
|
||
@Module({ | ||
imports: [HttpModule], | ||
providers: [IdentityService], | ||
controllers: [IdentityController] | ||
}) | ||
export class IdentityModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { IdentityService } from './identity.service'; | ||
|
||
describe('IdentityService', () => { | ||
let service: IdentityService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [IdentityService], | ||
}).compile(); | ||
|
||
service = module.get<IdentityService>(IdentityService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { HttpService } from '@nestjs/axios'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import axios from 'axios'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
interface RCWIdentityConfig { | ||
baseUrl: string; | ||
} | ||
|
||
@Injectable() | ||
export class IdentityService { | ||
private readonly config; | ||
|
||
constructor( | ||
private readonly configService: ConfigService, | ||
private readonly httpService: HttpService | ||
) { | ||
this.config = this.configService.get<RCWIdentityConfig>('identityService'); | ||
} | ||
|
||
async generateIdentity() { | ||
try { | ||
const configPath = path.resolve(__dirname, '../config.json'); | ||
const requestBody = JSON.parse(fs.readFileSync(configPath, 'utf8')); | ||
|
||
const generateUrl = `${this.config.baseUrl}/did/generate`; | ||
|
||
const response = await this.httpService.axiosRef.post(generateUrl, requestBody, { | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Error generating identity:', error.message); | ||
throw error.response?.data || error.message; | ||
} | ||
} | ||
|
||
async resolveIdentity(did: string) { | ||
try { | ||
const url = `${this.config.baseUrl}/did/resolve/${did}`; | ||
const response = await this.httpService.axiosRef.get(url, { | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Error resolving identity:', error.message); | ||
throw error.response?.data || error.message; | ||
} | ||
} | ||
} |