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 Identity service #218

Merged
merged 43 commits into from
Jul 5, 2023

Conversation

techsavvyash
Copy link
Contributor

@techsavvyash techsavvyash commented Apr 18, 2023

Description

This PR contains the code for the identity service.

@techsavvyash techsavvyash marked this pull request as draft April 18, 2023 12:42
@techsavvyash techsavvyash marked this pull request as ready for review June 15, 2023 08:57
jwksRequestsPerMinute: 5,
jwksUri: process.env.JWKS_URI,
}),
algorithms: ['RS256'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let this be configurable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added as an env var


async generateDID(doc: GenerateDidDTO): Promise<DIDDocument> {
// Create private/public key pair
const authnKeys = await ION.generateKeyPair('Ed25519');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it configurable.
RSA or ED

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added as a env var

console.log(authnKeys);

// Create a UUID for the DID using uuidv4
const didUri = 'did:ulp:' + uuid();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ULP keyword and make it configurable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done refer: 6af1cd1

didDoc: JSON.stringify(document),
},
});
this.vault.writePvtKey(authnKeys.privateJwk, didUri)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await is missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also error handlings are missing,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

Comment on lines 51 to 71
// const did = new ION.DID({
// content: content,
// });

// const anchorRequestBody = await did.generateRequest();
// const didUri: string = await did.getURI('short');
// const anchorRequest = new ION.AnchorRequest(anchorRequestBody);
// const anchorResponse = await anchorRequest.submit();
// if (anchorResponse) {
// await this.prisma.identity.create({
// data: {
// id: didUri,
// didDoc: anchorResponse as DIDDocument,
// privateKey: authnKeys.privateJwk,
// },
// });

// return anchorResponse;
// } else {
// throw new Error('err');
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented codes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@@ -0,0 +1,45 @@
node() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be present within the repo. I think this can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the jenkins file we created to deploy the service to the internal samagra devops pipelines. Do we need to remove this entirely so can we keep this as alternate deployment strategy ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the file has been resolved as per discussion during the standup

"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add appropriate license.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added MIT License

}
}

// @Patch('/update/:id')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete if not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

authentication: ['auth-key'],
};
// print the document using pretty json
console.log(JSON.stringify(document, null, 2));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

}
}

// async resolveDID(id: string): Promise<DIDDocument> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments should be removed everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

private vault = new Vault( {
https: false,
baseUrl: `${process.env.VAULT_ADDR}/v1`,
rootPath: `${process.env.VAULT_ADDR}/v1/kv`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be made configurable throughout. We can have vault address and root path as two env variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added as env vars

@@ -0,0 +1,15 @@
import { ApiProperty } from "@nestjs/swagger";

export class RegisterUserDTO {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have OTP and password within a DTO. These should be handled by the authentication provider. Only consent should be transmitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a mock aadhar service, this code has been removed from the service

feat: Add targets for identity-service
}

async resolveDID(id: string): Promise<any> {
console.log('did in resolveDID: ', id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use nest js logger, and leverage different log levels

@tejash-jl
Copy link
Member

  • docker-compose file is missing with vault & db service

@tejash-jl
Copy link
Member

  • Enable JWT auth for APIs,

@tejash-jl
Copy link
Member

tejash-jl commented Jun 21, 2023

@techsavvyash can you share the API spec for this service?

@@ -0,0 +1,36 @@
import { BadRequestException, Body, Controller, Get, Param, Post } from '@nestjs/common';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these APIS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, these were written to enable a mock aadhar based login flow to create DIDs, and have been removed

@ApiInternalServerErrorResponse({ description: 'Internal Server Error' })
@Post('/sign')
sign(@Body() body: SignJsonDTO) {
console.log('tjis')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unwanted logs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@ApiOperation({ summary: 'Verify a signed VC' })
@Post('/verify')
verify(@Body() body: VerifyJsonDTO) {
return this.VcService.sign(body.DID, body.payload);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does it call sign function for verify?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has been resolved

@srprasanna srprasanna changed the base branch from main to release-2.0.0 July 4, 2023 04:09
@srprasanna
Copy link
Collaborator

@techsavvyash Please add a readme with the list of supported environment variables as well. This way it will be easy to document at a later point.

@srprasanna
Copy link
Collaborator

@techsavvyash can you also share the coverage metrics?

@techsavvyash
Copy link
Contributor Author

@techsavvyash Please add a readme with the list of supported environment variables as well. This way it will be easy to document at a later point.

have added a .env.sample

@techsavvyash
Copy link
Contributor Author

@techsavvyash can you also share the coverage metrics?
WhatsApp Image 2023-07-03 at 12 41 17 PM

@srprasanna srprasanna merged commit ed43c7d into Sunbird-RC:release-2.0.0 Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Released
Development

Successfully merging this pull request may close these issues.

4 participants