Skip to content

Commit

Permalink
Merge pull request #62 from hypersign-protocol/HSSTUD-50
Browse files Browse the repository at this point in the history
use walletAddress in place of address and fixed not able to register …
  • Loading branch information
varsha766 authored Feb 20, 2023
2 parents 977e97c + 3f8751e commit 5ed42a2
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 215 deletions.
5 changes: 2 additions & 3 deletions src/app-auth/app-auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { TrimMiddleware } from 'src/utils/middleware/trim.middleware';
MongooseModule.forFeature([{ name: App.name, schema: AppSchema }]),
HidWalletModule,
EdvModule,

JwtModule.register({}),
],
providers: [
Expand All @@ -41,11 +41,10 @@ import { TrimMiddleware } from 'src/utils/middleware/trim.middleware';
JwtStrategy,
JwtStrategyApp,
AppAuthApiKeyService,

],
controllers: [AppAuthController, AppOAuthController],

exports: [AppAuthService, AppRepository,AppAuthApiKeyService],
exports: [AppAuthService, AppRepository, AppAuthApiKeyService],
})
export class AppAuthModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
Expand Down
2 changes: 1 addition & 1 deletion src/app-auth/services/app-auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class AppAuthService {
userId: string,
): Promise<createAppResponse> {
const { mnemonic, address } = await this.hidWalletService.generateWallet();
const appId=await this.appAuthApiKeyService.generateAppId()
const appId = await this.appAuthApiKeyService.generateAppId();
const edvId = 'hs:apiservice:edv:' + appId;
await this.edvService.init(edvId);
const document: EdvDocsDto = {
Expand Down
32 changes: 15 additions & 17 deletions src/did/controllers/did.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,31 +134,29 @@ export class DidController {
required: false,
})
create(@Body() createDidDto: CreateDidDto, @Req() req: any) {
const { options } = createDidDto;
const { options } = createDidDto;
const appDetail = req.user;
switch (options?.keyType) {
case IKeyType.EcdsaSecp256k1RecoveryMethod2020:{

case IKeyType.EcdsaSecp256k1RecoveryMethod2020: {
return this.didService.createByClientSpec(createDidDto, appDetail);

break;
}

case IKeyType.EcdsaSecp256k1VerificationKey2019:
{

throw new NotFoundException({
message: [`${options.keyType} is not supported`, `Feature coming soon`],
error: 'Not Supported',
status: 404,
});
}

case IKeyType.EcdsaSecp256k1VerificationKey2019: {
throw new NotFoundException({
message: [
`${options.keyType} is not supported`,
`Feature coming soon`,
],
error: 'Not Supported',
status: 404,
});
}

default:
return this.didService.create(createDidDto, appDetail);

}

}

@ApiCreatedResponse({
Expand All @@ -172,9 +170,9 @@ export class DidController {
})
@Post('/register')
@UsePipes(ValidationPipe)
register(@Body() registerDidDto: RegisterDidDto,@Req() req:any){
register(@Body() registerDidDto: RegisterDidDto, @Req() req: any) {
const appDetail = req.user;
return this.didService.register(registerDidDto,appDetail)
return this.didService.register(registerDidDto, appDetail);
}

@UsePipes(ValidationPipe)
Expand Down
57 changes: 31 additions & 26 deletions src/did/dto/create-did.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,63 @@ import {
import { RegistrationStatus } from '../schemas/did.schema';
import { DidDoc } from '../dto/update-did.dto';
import { IsDid } from 'src/utils/customDecorator/did.decorator';
import { Optional } from '@nestjs/common';

export enum IKeyType {
Ed25519VerificationKey2020 = 'Ed25519VerificationKey2020',
EcdsaSecp256k1VerificationKey2019 = 'EcdsaSecp256k1VerificationKey2019',
EcdsaSecp256k1RecoveryMethod2020 = 'EcdsaSecp256k1RecoveryMethod2020',
}


export class Options {
@ApiProperty({
description:
'Verification Method Keytype Ed25519VerificationKey2020 or EcdsaSecp256k1RecoveryMethod2020',
example: 'keyType:EcdsaSecp256k1RecoveryMethod2020',
name: 'keyType',
required: false,
})
@ValidateIf((o) => o.keyType !== undefined)
@IsEnum(IKeyType)
keyType: IKeyType;


@ApiProperty({
name:'chainId',
example:'0x1',
description:"Chain Id"
name: 'chainId',
example: '0x1',
description: 'Chain Id',
required: false,
})
@IsOptional()
@IsString()
chainId:string;
chainId?: string;

@ApiProperty({
name:'publicKey',
example:`z76tzt4XCb6FNqC3CPZvsxRfEDX5HHQc2VPux4DeZYndW`,
description:"Public Key extracted from keplr"
name: 'publicKey',
example: `z76tzt4XCb6FNqC3CPZvsxRfEDX5HHQc2VPux4DeZYndW`,
description: 'Public Key extracted from keplr',
required: false,
})

@IsOptional()
@Type(()=>Uint8Array || String)
publicKey?:Uint8Array | string;
@Type(() => Uint8Array || String)
publicKey?: Uint8Array | string;

@ApiProperty({
name:'address',
example:`0x01978e553Df0C54A63e2E063DFFe71c688d91C76`,
description:"Checksum address from web3 wallet"
name: 'walletAddress',
example: `0x01978e553Df0C54A63e2E063DFFe71c688d91C76`,
description: 'Checksum address from web3 wallet',
required: false,
})
@IsOptional()
@IsString()
address:string

walletAddress?: string;
@ApiProperty({
name: 'register',
example: true,
description: 'If set to true did will be registerd on blockchain',
required: false,
})
@IsOptional()
@IsBoolean()
register:boolean
register?: boolean;
}
export class CreateDidDto {
@ApiProperty({
Expand All @@ -91,13 +96,13 @@ export class CreateDidDto {
@ApiProperty({
name: 'options',
description: ' keyType used for verification',
required: false,
example: {
keyType: 'Ed25519VerificationKey2020',
chainId:'0x1',
publicKey:'z76tzt4XCb6FNqC3CPZvsxRfEDX5HHQc2VPux4DeZYndW',
address:'0x01978e553Df0C54A63e2E063DFFe71c688d91C76',
register:false

chainId: '0x1',
publicKey: 'z76tzt4XCb6FNqC3CPZvsxRfEDX5HHQc2VPux4DeZYndW',
walletAddress: '0x01978e553Df0C54A63e2E063DFFe71c688d91C76',
register: false,
},
})
@IsOptional()
Expand All @@ -106,7 +111,7 @@ export class CreateDidDto {
@ValidateNested({
each: true,
})
options: Options;
options?: Options;
}

export class TxnHash {
Expand Down Expand Up @@ -140,7 +145,7 @@ export class CreateDidResponse {
description: 'Transaction Has',
example: 'XYAIFLKFLKHSLFHKLAOHFOAIHG..........',
})
@IsString()
@IsString()
transactionHash: string;

@ApiProperty({
Expand Down
111 changes: 52 additions & 59 deletions src/did/dto/register-did.dto.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,57 @@
import { ApiHideProperty, ApiProperty } from "@nestjs/swagger";
import { DidDoc, UpdateDidDto } from "./update-did.dto";
import { IsArray, IsEnum, IsNotEmpty, IsOptional, IsString, ValidateNested } from "class-validator";
import { Type } from "class-transformer";
import { ValidateVerificationMethodId } from "src/utils/customDecorator/vmId.decorator";
import { type } from "os";
import { ApiProperty } from '@nestjs/swagger';
import { DidDoc } from './update-did.dto';
import { IsEnum, IsOptional, IsString, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
import { ValidateVerificationMethodId } from 'src/utils/customDecorator/vmId.decorator';

export enum IClientSpec {
'eth-personalSign' = 'eth-personalSign',
'cosmos-ADR036' = 'cosmos-ADR036',
'eth-personalSign' = 'eth-personalSign',
'cosmos-ADR036' = 'cosmos-ADR036',
}
export class RegisterDidDto {
@ApiProperty({
description: 'Did doc to be updated',
type: DidDoc,
})
@Type(() => DidDoc)
@ValidateNested({each:true})
didDocument: DidDoc;

@ApiProperty({
description: 'Verification Method id for did updation',
example: 'did:hid:testnet:........#key-${idx}',
required:true
})
@ValidateVerificationMethodId()
@IsString()
verificationMethodId: string;


@ApiProperty({
description:
"IClientSpec 'eth-personalSign' or 'cosmos-ADR036'",
example: 'eth-personalSign',
name: 'clientSpec',
})
@IsOptional()
@IsEnum(IClientSpec)
clientSpec: IClientSpec;


@ApiProperty({
description:
"Signature for clientSpec",
example: 'afafljagahgp9agjagknaglkj/kagka=',
name: 'signature',
})
@IsOptional()
@IsString()
signature: string;
@ApiProperty({
description:
"Signature for clientSpec cosmos-ADR036",
example: "hid148273582",
name: 'address',
})
@IsOptional()
@IsString()
address: string


@ApiProperty({
description: 'Did doc to be updated',
type: DidDoc,
})
@Type(() => DidDoc)
@ValidateNested({ each: true })
didDocument: DidDoc;

@ApiProperty({
description: 'Verification Method id for did updation',
example: 'did:hid:testnet:........#key-${idx}',
required: true,
})
@ValidateVerificationMethodId()
@IsString()
verificationMethodId: string;

@ApiProperty({
description: "IClientSpec 'eth-personalSign' or 'cosmos-ADR036'",
example: 'eth-personalSign',
name: 'clientSpec',
required: false,
})
@IsOptional()
@IsEnum(IClientSpec)
clientSpec?: IClientSpec;

@ApiProperty({
description: 'Signature for clientSpec',
example: 'afafljagahgp9agjagknaglkj/kagka=',
name: 'signature',
required: false,
})
@IsOptional()
@IsString()
signature?: string;
@ApiProperty({
description: 'Checksum address from web3 wallet',
example: 'hid148273582',
name: 'address',
required: false,
})
@IsOptional()
@IsString()
address?: string;
}


Loading

0 comments on commit 5ed42a2

Please sign in to comment.