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

Updated sdk #123

Merged
merged 6 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46,489 changes: 46,489 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:newman": "newman run studio-api.postman_collection.json",
"test:newman": "ts-node ./test/promptValue.ts && newman run studio-api.postman_collection.json -e environment.json",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
Expand All @@ -41,12 +41,13 @@
"express-session": "^1.17.3",
"fs": "^0.0.1-security",
"hid-hd-wallet": "git+https://github.com/hypersign-protocol/hid-hd-wallet.git#main",
"hs-ssi-sdk": "7.0.1",
"hs-ssi-sdk": "github:hypersign-protocol/hid-ssi-js-sdk#testcase/bjj",
"hypersign-edv-client": "github:hypersign-protocol/hypersign-edv-client#develop",
"mongoose": "^6.8.3",
"passport": "^0.6.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"readline-sync": "^1.4.10",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0",
"swagger-ui-express": "^4.6.0"
Expand Down
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
107 changes: 62 additions & 45 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,26 +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,
})
claim: Claim | undefined;
@ApiProperty({
name: 'issuer',
description: 'did of the one who issue the credential',
Expand All @@ -244,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 @@ -379,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
1 change: 1 addition & 0 deletions src/did/dto/addVm.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class AddVMResponse extends DidDoc {
},
],
})
@Type(() => verificationMethod)
verificationMethod: Array<verificationMethod>;
@ApiProperty({
description: 'authentication',
Expand Down
4 changes: 2 additions & 2 deletions src/did/dto/create-did.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiHideProperty, ApiProperty } from '@nestjs/swagger';
import { Exclude, Transform, Type } from 'class-transformer';
import { Exclude, Type } from 'class-transformer';
import {
IsArray,
IsBoolean,
Expand Down Expand Up @@ -137,7 +137,7 @@ class MetaData {
})
@ValidateNested()
@Type(() => DidDoc)
didDocument: DidDoc;
didDocument: Partial<DidDoc>;
}
export class CreateDidResponse {
@ApiProperty({
Expand Down
9 changes: 8 additions & 1 deletion src/did/dto/register-did.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
name: 'signature',
required: true,
})
@ValidateIf((o, value) => o.clientSpec !== undefined)

Check warning on line 56 in src/did/dto/register-did.dto.ts

View workflow job for this annotation

GitHub Actions / build

'value' is defined but never used
@IsNotEmpty()
@IsString()
signature: string;
Expand All @@ -70,6 +70,13 @@
@Type(() => ClientSpec)
@ValidateNested({ each: true })
clientSpec: ClientSpec;
@ApiProperty({
description: 'created',
example: '2023-01-23T13:45:17Z',
})
@IsString()
@IsNotEmpty()
created: string;
}
export class RegisterDidDto {
@ApiProperty({
Expand All @@ -80,7 +87,7 @@
@IsNotEmptyObject()
@Type(() => DidDoc)
@ValidateNested({ each: true })
didDocument: DidDoc;
didDocument: Partial<DidDoc>;

@ApiProperty({
description: 'Verification Method id for did registration',
Expand Down Expand Up @@ -111,7 +118,7 @@
name: 'signature',
required: false,
})
@ValidateIf((o, value) => o.clientSpec !== undefined)

Check warning on line 121 in src/did/dto/register-did.dto.ts

View workflow job for this annotation

GitHub Actions / build

'value' is defined but never used
@IsNotEmpty()
@IsString()
signature?: string;
Expand Down
Loading
Loading