Skip to content

Commit

Permalink
chore: add secp256k1 key interface
Browse files Browse the repository at this point in the history
  • Loading branch information
eum602 committed Apr 23, 2023
1 parent ac0cc6b commit 646d293
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lacpass-key-manager",
"version": "0.0.7",
"version": "0.0.8",
"description": "Rest api for laccpass key manager",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/secp256k1.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { JsonController, Post, BadRequestError } from 'routing-controllers';
import { Service } from 'typedi';
import { Secp256k1Service } from '../services/secp256k1.service';
import { Secp256k1DbService } from '../services/secp256k1Db.service';
import { ErrorsMessages } from '../constants/errorMessages';

@JsonController('/secp256k1')
@Service()
export class Secp256k1Controller {
constructor(private readonly secp256k1Service: Secp256k1Service) {}
constructor(private readonly secp256k1Service: Secp256k1DbService) {}

@Post('/')
async create(): Promise<any> {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { Secp256k1Service } from './services/secp256k1.service';
export { Secp256k1DbService } from './services/secp256k1Db.service';
export { Secp256k1Service } from './services/interfaces/Secp256k1';
export { Secp256k1 } from './entities/secp256k1.entity';
11 changes: 11 additions & 0 deletions src/services/interfaces/Secp256k1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type key = {
keyId: string;
address: string;
};
export interface Secp256k1Service {
show(id: string): Promise<any>;

createKey(): Promise<key>;

deleteKey(id: string): Promise<any>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import { getRepository } from 'typeorm';
import { Secp256k1 } from '../entities/secp256k1.entity';
import { ethers } from 'ethers';
import { EntityMapper } from '@clients/mapper/entityMapper.service';
import { Secp256k1Service, key } from './interfaces/Secp256k1';

@Service()
export class Secp256k1Service {
export class Secp256k1DbService implements Secp256k1Service {
private readonly secp256k1Repository = getRepository<Secp256k1>(Secp256k1);

show(id: string) {
return this.secp256k1Repository.findOne(id);
}

async createKey() {
async createKey(): Promise<key> {
const secp256k1 = EntityMapper.mapTo(Secp256k1, {});
const account = ethers.Wallet.createRandom();
secp256k1.key = account.privateKey;
Expand Down

0 comments on commit 646d293

Please sign in to comment.