Skip to content

Commit

Permalink
fix-did
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratap2018 committed Dec 30, 2024
1 parent 0c4016b commit 881c83c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/did/dto/create-did.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
} from 'class-validator';
import { RegistrationStatus } from '../schemas/did.schema';
import { DidDoc } from '../dto/update-did.dto';
import { IsDid } from 'src/utils/customDecorator/did.decorator';
import {
IsDid,
IsMethodSpecificId,
} from 'src/utils/customDecorator/did.decorator';
import { ValidatePublicKeyMultibase } from 'src/utils/customDecorator/pubKeyMultibase.decorator';
import { IVerificationRelationships, IKeyType } from 'hs-ssi-sdk';
import { IsKeyTypeArrayOrSingle } from 'src/utils/customDecorator/keyType.decorator';
Expand Down Expand Up @@ -105,6 +108,7 @@ export class CreateDidDto {
@IsString()
@MinLength(32)
@MaxLength(48)
@IsMethodSpecificId()
@ApiProperty({
name: 'methodSpecificId',
description: 'MethodSpecificId to be added in did',
Expand Down
3 changes: 3 additions & 0 deletions src/did/services/did.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,9 @@ export class DidService {
'resolveDid() method: before calling hypersignDid.generate',
'DidService',
);
console.log(methodSpecificId);
console.log(publicKeyMultibase);

resolvedDid = await hypersignDid.generate({
methodSpecificId,
publicKeyMultibase,
Expand Down
43 changes: 43 additions & 0 deletions src/utils/customDecorator/did.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,46 @@ export const IsDid = (): PropertyDecorator => {
},
);
};

export const IsMethodSpecificId = (): PropertyDecorator => {
return applyDecorators(
SetMetadata('isMethodSpecificId', true),
(target: object, propertyKey: string | symbol) => {
let original = target[propertyKey];
const descriptor: PropertyDescriptor = {
get: () => original,
set: (val: any) => {
if (val.trim() === '') {
throw new BadRequestException([
`${propertyKey.toString()} cannot be empty`,
]);
}

const did = val;
if (did.includes('did:hid:')) {
throw new BadRequestException([
`Invalid ${propertyKey.toString()}`,
]);
}
if (did.includes('hid')) {
throw new BadRequestException([
`Invalid ${propertyKey.toString()}`,
]);
}
if (did.includes(':')) {
throw new BadRequestException([
`Invalid ${propertyKey.toString()}`,
]);
}
if (did.includes('.')) {
throw new BadRequestException([
`Invalid ${propertyKey.toString()}`,
]);
}
original = val;
},
};
Object.defineProperty(target, propertyKey, descriptor);
},
);
};

0 comments on commit 881c83c

Please sign in to comment.