Skip to content

Commit

Permalink
updated swagger based on recent change in ssi sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
varsha766 committed Dec 7, 2023
1 parent 725f2c2 commit f2045ca
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 137 deletions.
3 changes: 2 additions & 1 deletion src/credential/controllers/credential.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
CreateCredentialDto,
CreateCredentialResponse,
ResolveCredential,
ResolvedCredentialStatus,
} from '../dto/create-credential.dto';
import { UpdateCredentialDto } from '../dto/update-credential.dto';
import {
Expand Down Expand Up @@ -246,7 +247,7 @@ export class CredentialController {
@Patch('status/:credentialId')
@ApiOkResponse({
description: 'Credential Updated',
type: ResolveCredential,
type: ResolvedCredentialStatus,
})
@ApiNotFoundResponse({
status: 404,
Expand Down
108 changes: 62 additions & 46 deletions src/credential/dto/create-credential.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,16 @@ export class CredentialProof {
proofValue: string;
}

class Claim {
export class CredStatus {
@ApiProperty({
name: '@context',
description: 'context',
example: [
'https://raw.githubusercontent.com/hypersign-protocol/hypersign-contexts/main/CredentialStatus.jsonld',
'https://w3id.org/security/suites/ed25519-2020/v1',
],
})
'@context': Array<string>;
@ApiProperty({
name: 'id',
description: 'Credential id',
Expand All @@ -209,27 +218,6 @@ class Claim {
@IsString()
@IsVcId()
id: string;
@ApiProperty({
name: 'currentStatus',
description: 'Status of credential',
example: 'vc:hid:testnet:................',
})
currentStatus: string;
@ApiProperty({
name: 'statusReason',
description: 'Reason of current status',
example: 'Credential is active',
})
statusReason: string;
}
export class CredStatus {
@ApiProperty({
name: 'claim',
description: ' ',
type: Claim,
})
@Type(() => Claim)
claim: Claim | undefined;
@ApiProperty({
name: 'issuer',
description: 'did of the one who issue the credential',
Expand All @@ -245,31 +233,57 @@ export class CredStatus {
})
@IsString()
issuanceDate: string;

@ApiProperty({
name: 'expirationDate',
description: 'Date on which credential will expire',
example: '2023-01-25T16:59:21Z',
name: 'remarks',
description: 'Reason of current status',
example: 'Credential is active',
})
@IsString()
expirationDate: string;
@IsNotEmpty()
remarks: string;

@ApiProperty({
name: 'credentialHash',
description: 'Hash of credential',
example: 'ae93886f2a............3f6d1c6ae4..........393d43730',
name: 'credentialMerkleRootHash',
description: 'Merkle root hash of the credential',
example:
'c20c512a0e5a12616faa0911dde385fb57fac2f5aad6173a6b1010fngrgtlhkjtrrjowlrjttryju',
})
@IsString()
credentialHash: string;
@IsNotEmpty()
credentialMerkleRootHash: string;

@ApiProperty({
name: 'proof',
description: 'Proof of credential',
type: CredentialProof,
})
proof: CredentialProof;
}
export class CredDoc {
@ApiProperty({
description: 'Context',
example: [
'https://www.w3.org/2018/credentials/v1',
{
hs: 'https://api.jagrat.hypersign.id/hypersign-protocol/hidnode/ssi/schema/sch:hid:testnet:...........:1.0:',
},
{
name: 'hs:name',
'@context': {
'@protected': true,
'@version': 1.1,
id: '@id',
type: '@type',
RailwayTicketSchema: {
'@context': {
'@propagate': true,
'@protected': true,
xsd: 'http://www.w3.org/2001/XMLSchema#',
name: {
'@id': 'https://hypersign-schema.org/name',
'@type': 'xsd:string',
},
},
'@id': 'https://hypersign-schema.org',
},
},
},
'https://w3id.org/security/suites/ed25519-2020/v1',
],
Expand Down Expand Up @@ -380,25 +394,27 @@ export class CreateCredentialResponse {
persist: boolean;
}

export class CredProof extends CredentialProof {
export class ResolvedCredentialStatus extends CredStatus {
@ApiProperty({
name: 'updated',
description: 'Date on which credential has updated',
example: '2023-01-25T17:01:02Z',
name: 'revoked',
description: 'Set to true if credential is revoked',
example: false,
})
@IsString()
updated: string;
}

class ResolvedCredentialStatus extends CredStatus {
revoked: boolean;
@ApiProperty({
name: 'suspended',
description: 'Set to true if credential is suspended',
example: false,
})
suspended: boolean;
@ApiProperty({
name: 'proof',
description: 'proof of credential',
type: CredProof,
type: CredentialProof,
})
@Type(() => CredProof)
@Type(() => CredentialProof)
@ValidateNested({ each: true })
proof: CredProof;
proof: CredentialProof;
}
export class ResolveCredential {
@ApiProperty({
Expand Down
11 changes: 1 addition & 10 deletions src/credential/dto/register-credential.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { CredProof, CredStatus, Namespace } from './create-credential.dto';
import { CredStatus, Namespace } from './create-credential.dto';
import { Type } from 'class-transformer';
import { IsEnum, ValidateNested } from 'class-validator';

Expand All @@ -13,15 +13,6 @@ export class RegisterCredentialStatusDto {
@Type(() => CredStatus)
@ValidateNested({ each: true })
credentialStatus: CredStatus;
@ApiProperty({
name: 'credentialStatusProof',
description: 'Status proof of the credential',
required: true,
type: CredProof,
})
@Type(() => CredProof)
@ValidateNested({ each: true })
credentialStatusProof: CredProof;
@ApiProperty({
name: 'namespace',
description: 'Namespace',
Expand Down
50 changes: 46 additions & 4 deletions src/credential/dto/verify-credential.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,66 @@ class CredResultProof extends CredentialProof {
description: '',
example: [
'https://www.w3.org/2018/credentials/v1',
'https://raw.githubusercontent.com/hypersign-protocol/hypersign-contexts/main/HypersignCredentialStatus2023.jsonld',
{
hs: 'https://api.jagrat.hypersign.id/hypersign-protocol/hidnode/ssi/schema/sch:hid:testnet:z3KX4ZqoizKTaED645aV4aE8dBbnSpmQYe3xfzVBJadPY:1.0:',
},
{
name: 'hs:name',
'@context': {
'@protected': true,
'@version': 1.1,
id: '@id',
type: '@type',
RailwayTicketSchema: {
'@context': {
'@propagate': true,
'@protected': true,
xsd: 'http://www.w3.org/2001/XMLSchema#',
name: {
'@id': 'https://hypersign-schema.org/name',
'@type': 'xsd:string',
},
},
'@id': 'https://hypersign-schema.org',
},
},
},
'https://w3id.org/security/suites/ed25519-2020/v1',
],
})
'@context': Array<string>;
}

class Controller {
@ApiProperty({
name: '@context',
description: 'issuer didDoc id',
example: ['https://www.w3.org/ns/did/v1'],
})
'@contexts': string[];
@ApiProperty({
name: 'id',
description: 'issuer didDoc id',
example: 'did:hid:testnet:zrstybdkfbjg..........',
})
id: boolean;
@ApiProperty({
name: 'assertionMethod',
description: '',
example: ['did:hid:testnet:zrstybdkfbjg..........'],
})
assertionMethod: string[];
}
class PurposeResult {
@ApiProperty({
name: 'valid',
description: '',
example: true,
})
valid: boolean;
@ApiProperty({
name: 'controller',
description: '',
type: Controller,
})
controller: Controller;
}
class VerificationMethod {
@ApiProperty({
Expand Down
7 changes: 4 additions & 3 deletions src/credential/services/credential.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,7 @@ export class CredentialService {
'CredentialService',
);

const { credentialStatus, credentialStatusProof, namespace } =
registerCredentialDto;
const { credentialStatus, namespace } = registerCredentialDto;
const { kmsId } = appDetail;
Logger.log(
'registerCredentialStatus() method: initialising edv service',
Expand All @@ -436,9 +435,11 @@ export class CredentialService {
'registerCredentialStatus() method: before calling hypersignVC.registerCredentialStatus to register credential status on chain',
'CredentialService',
);
const { proof } = credentialStatus;
delete credentialStatus['proof'];
registeredVC = await hypersignVC.registerCredentialStatus({
credentialStatus,
credentialStatusProof,
credentialStatusProof: proof,
});
} catch (e) {
Logger.error(
Expand Down
63 changes: 0 additions & 63 deletions src/did/dto/update-did.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
IsArray,
IsEmpty,
IsEnum,
IsNotEmpty,
IsNotEmptyObject,
IsOptional,
IsString,
Matches,
ValidateIf,
ValidateNested,
} from 'class-validator';
import { IsDid } from 'src/utils/customDecorator/did.decorator';
Expand Down Expand Up @@ -40,43 +37,6 @@ export class ClientSpec {
adr036SignerAddress: string;
}

// export class SignInfo {
// @ApiProperty({
// description: 'Verification Method id for did registration',
// example: 'did:hid:testnet:........#key-${idx}',
// required: true,
// })
// @ValidateVerificationMethodId()
// @IsString()
// @Matches(/^[a-zA-Z0-9\:]*testnet[a-zA-Z0-9\-:#]*$/, {
// message: "Did's namespace should be testnet",
// })
// verification_method_id: string;

// @ApiProperty({
// description: 'Signature for clientSpec',
// example: 'afafljagahgp9agjagknaglkj/kagka=',
// name: 'signature',
// required: true,
// })
// @ValidateIf((o, value) => o.clientSpec !== undefined)
// @IsNotEmpty()
// @IsString()
// signature: string;

// @ApiProperty({
// description: 'ClienSpec ',
// example: {
// type: IClientSpec['cosmos-ADR036'],
// adr036SignerAddress: 'bech32address',
// },
// type: ClientSpec,
// name: 'clientSpec',
// })
// @Type(() => ClientSpec)
// @ValidateNested({ each: true })
// clientSpec: ClientSpec;
// }
export class verificationMethod {
@ApiProperty({
description: 'Verification Method id',
Expand Down Expand Up @@ -148,9 +108,6 @@ export class DidDoc {
@IsArray()
'@context'?: Array<string>;

// @IsOptional()
// @IsArray()
// 'context': Array<string>;
@ApiProperty({
description: 'id',
example: 'did:hid:method:......',
Expand Down Expand Up @@ -286,26 +243,6 @@ export class UpdateDidDto {
message: "Did's namespace should be testnet",
})
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: 'Sign Info',
example: [
Expand Down
Loading

0 comments on commit f2045ca

Please sign in to comment.