diff --git a/libs/askar/src/askar-rest/rest.controller.ts b/libs/askar/src/askar-rest/rest.controller.ts index d6e208587137e1fa71e61cb98e1a96e3f3270408..08434836bbed345f53ca11eb001a2368a18a4d63 100644 --- a/libs/askar/src/askar-rest/rest.controller.ts +++ b/libs/askar/src/askar-rest/rest.controller.ts @@ -84,7 +84,7 @@ export class RestController { return this.agentService.getProofById(data.id); } - @Post(`/credential/proof/accept`) + @Post(`/credential/c/proof/accept`) acceptProof(@Body() acceptProofRequestDto: ProofReqDto) { return this.agentService.acceptProof(acceptProofRequestDto); } diff --git a/libs/askar/src/askar/agent.service.ts b/libs/askar/src/askar/agent.service.ts index f470fff76a1a7765954769de9e119573fbb5ff03..f99ee05eefb27807583eb944d8014351d845bae7 100644 --- a/libs/askar/src/askar/agent.service.ts +++ b/libs/askar/src/askar/agent.service.ts @@ -21,6 +21,7 @@ import { } from "@ocm-engine/dtos"; import { AutoAcceptProof, + ConnectionRecord, CredentialState, JsonEncoder, ProofState, @@ -66,10 +67,10 @@ export class AgentService { }; async fetchConnections() { - let agentResponse = await this.askar.agent.connections.getAll(); + const agentResponse = await this.askar.agent.connections.getAll(); - let connectionArray = agentResponse.map((singleConnectionRes) => { - let connectionResponse = new ConnectionRecordDto(); + const connectionArray = agentResponse.map((singleConnectionRes) => { + const connectionResponse = new ConnectionRecordDto(); connectionResponse.id = singleConnectionRes.id; connectionResponse.state = singleConnectionRes.state; connectionResponse.connectionName = singleConnectionRes.theirLabel; @@ -79,25 +80,24 @@ export class AgentService { connectionResponse.outOfBandId = singleConnectionRes.outOfBandId; connectionResponse.createdAt = singleConnectionRes.createdAt; - - return connectionResponse - }) + return connectionResponse; + }); if (connectionArray.length < 1) { throw new ConnectionNotFoundError(); } - return connectionArray + return connectionArray; } getConnectionById = async (id: string) => { - let agentResponse = await this.askar.agent.connections.findById(id); + const agentResponse = await this.askar.agent.connections.findById(id); if (!agentResponse) { throw new ConnectionNotFoundError(); } - let connectionResponse = new ConnectionRecordDto(); + const connectionResponse = new ConnectionRecordDto(); connectionResponse.id = agentResponse.id; connectionResponse.state = agentResponse.state; connectionResponse.connectionName = agentResponse.theirLabel; @@ -107,47 +107,49 @@ export class AgentService { connectionResponse.outOfBandId = agentResponse.outOfBandId; connectionResponse.createdAt = agentResponse.createdAt; - - return connectionResponse + return connectionResponse; }; fetchSchemas = async () => { - let agentResponse = await this.askar.agent.modules.anoncreds.getCreatedSchemas({}); + const agentResponse = + await this.askar.agent.modules.anoncreds.getCreatedSchemas({}); - let schemaResponse = agentResponse.map((singleSchemaRes) => { - let schemaResponse = new SchemaRecordDto(); + const schemaResponse = agentResponse.map((singleSchemaRes) => { + const schemaResponse = new SchemaRecordDto(); schemaResponse.id = singleSchemaRes.schemaId; schemaResponse.name = singleSchemaRes.schema.name; schemaResponse.attributes = singleSchemaRes.schema.attrNames; schemaResponse.version = singleSchemaRes.schema.version; schemaResponse.issuerId = singleSchemaRes.schema.issuerId; schemaResponse.methodName = singleSchemaRes.methodName; - - return schemaResponse - }) + + return schemaResponse; + }); if (schemaResponse.length < 1) { - throw new SchemaNotFoundError() + throw new SchemaNotFoundError(); } - return schemaResponse + return schemaResponse; }; getSchemaById = async (schemaId: string) => { - let agentResponse = await this.askar.agent.modules.anoncreds.getSchema(schemaId); + const agentResponse = await this.askar.agent.modules.anoncreds.getSchema( + schemaId, + ); if (!agentResponse || !agentResponse.schema) { throw new SchemaNotFoundError(); } - let schemaResponse = new SchemaRecordDto(); + const schemaResponse = new SchemaRecordDto(); schemaResponse.id = agentResponse.schemaId; schemaResponse.name = agentResponse.schema.name; schemaResponse.attributes = agentResponse.schema.attrNames; schemaResponse.version = agentResponse.schema.version; schemaResponse.issuerId = agentResponse.schema.issuerId; - return schemaResponse + return schemaResponse; }; createSchema = async (schema: CreateSchemaRequestDto) => { @@ -199,8 +201,7 @@ export class AgentService { } const response = new CreddefRecordDto(); - response.id = - credDef.credentialDefinitionState.credentialDefinitionId; + response.id = credDef.credentialDefinitionState.credentialDefinitionId; response.schemaId = credDef.credentialDefinitionState.credentialDefinition.schemaId; response.issuerId = @@ -334,7 +335,6 @@ export class AgentService { requested_attributes: requestedAttributes, }, }, - autoAcceptProof: AutoAcceptProof.ContentApproved, }); console.log({ proofRecord }); @@ -345,9 +345,8 @@ export class AgentService { domain: this.askar.agentConfig.agentPeerAddress, }); - return { + return { proofUrl: invitationUrl, - proofId: proofRecord.id }; } @@ -413,7 +412,7 @@ export class AgentService { return proofResponse; }; - acceptProof = async (acceptProofDto: ProofReqDto) => { + acceptProof = async (acceptProofDto: ProofReqDto) => { if (acceptProofDto.proofUrl) { return this.acceptOobProof(acceptProofDto.proofUrl); } @@ -421,50 +420,26 @@ export class AgentService { }; acceptOobProof = async (url: string) => { - // const param = url.split("d_m=")[1]; - - // const t = JsonEncoder.fromBase64(param); - - // await this.askar.agent.receiveMessage(t); - - let acceptFromUrl = await this.askar.agent.oob.receiveInvitationFromUrl(url); - - console.log('acc------------acceptFromUrl', acceptFromUrl) + await this.askar.agent.oob.receiveInvitationFromUrl(url, { + autoAcceptConnection: false, + autoAcceptInvitation: true, + // reuseConnection: true, + }); const record = await waitForProofExchangeRecordSubject(this.askar.agentR, { state: ProofState.RequestReceived, }); - console.log('---record state changed-----', record); - - // INFO: - // selectCredentialsForRequest method is used to handle proof proposals - // proof requests need to be handled with getCredentialsForRequest - const requestedCredentials = - await this.askar.agent.proofs.getCredentialsForRequest({ + await this.askar.agent.proofs.selectCredentialsForRequest({ proofRecordId: record.id, }); - console.log('++++++++++requestedcredentials', requestedCredentials); - - - // REVIEW: if we use getCredentialsForRequest the proofFormats type complains - // and the only way to match it is to pass it the attributes ??? - - // "name": "AriesFrameworkError", - // "message": "Proof record is in invalid state request-received. Valid states are: proposal-sent." - // REQUEST-RECEIVED IS THE VALID STATE! const acceptedRecord = await this.askar.agent.proofs.acceptRequest({ proofRecordId: record.id, - proofFormats: requestedCredentials.proofFormats.anoncreds?.attributes, - autoAcceptProof: AutoAcceptProof.ContentApproved, + proofFormats: requestedCredentials.proofFormats, }); - - console.log('=======acceptedRecord======', acceptedRecord); - - const response = new ProofRecordDto(); response.id = acceptedRecord.id; diff --git a/libs/dtos/src/dtos/generics/base.record.dto.ts b/libs/dtos/src/dtos/generics/base.record.dto.ts index 0fad391fff69db5b6b2a32ae5a4f437ac5c47a27..29dee3da16c8066aaf99e770067d83c290dca1c0 100644 --- a/libs/dtos/src/dtos/generics/base.record.dto.ts +++ b/libs/dtos/src/dtos/generics/base.record.dto.ts @@ -1,10 +1,6 @@ - import { IsDateString, IsNotEmpty, IsString } from "class-validator"; - - export class BaseRecordDto { - @IsString() @IsNotEmpty() id: string; @@ -12,7 +8,7 @@ export class BaseRecordDto { @IsDateString() @IsNotEmpty() createdAt: Date; - + @IsDateString() updatedAt?: Date; -} \ No newline at end of file +} diff --git a/libs/dtos/src/dtos/generics/schema.record.dto.ts b/libs/dtos/src/dtos/generics/schema.record.dto.ts index c9b51297523b09ca8c1917e37e42a7fa5a6a0599..506b124bad07b2bbc47c454ff7b7ceb5d50c6041 100644 --- a/libs/dtos/src/dtos/generics/schema.record.dto.ts +++ b/libs/dtos/src/dtos/generics/schema.record.dto.ts @@ -1,14 +1,12 @@ -import { ArrayMinSize, IsArray, IsNotEmpty, IsString } from "class-validator"; +import { ArrayMinSize, IsNotEmpty, IsString } from "class-validator"; import { BaseRecordDto } from "./base.record.dto"; - export class SchemaRecordDto extends BaseRecordDto { @IsString() @IsNotEmpty() name: string; @IsNotEmpty() - @IsArray() @IsString({ each: true }) @ArrayMinSize(1) attributes: string[]; @@ -22,4 +20,4 @@ export class SchemaRecordDto extends BaseRecordDto { @IsString() methodName?: string; -} \ No newline at end of file +} diff --git a/libs/dtos/src/dtos/requests/create.schema.request.dto.ts b/libs/dtos/src/dtos/requests/create.schema.request.dto.ts index 431179e3f0dcbd585c23d43d33e61faad5fb7216..28f2c5b7ad7a4c8c412835996f811d9fec389aff 100644 --- a/libs/dtos/src/dtos/requests/create.schema.request.dto.ts +++ b/libs/dtos/src/dtos/requests/create.schema.request.dto.ts @@ -1,4 +1,10 @@ -import { ArrayMinSize, IsArray, IsNotEmpty, IsString, Matches, ValidateNested } from "class-validator"; +import { + ArrayMinSize, + IsNotEmpty, + ValidateNested, + IsString, + Matches, +} from "class-validator"; export class CreateSchemaRequestDto { //@example "my test schema" @@ -7,8 +13,6 @@ export class CreateSchemaRequestDto { name: string; //@example ['first_name, last_name'] - @IsNotEmpty() - @IsArray() @ArrayMinSize(1) @ValidateNested({ each: true }) @IsString() diff --git a/libs/dtos/src/dtos/requests/proof.req.dto.ts b/libs/dtos/src/dtos/requests/proof.req.dto.ts index 063d3b0b33e2dc6eb0db729f3406010974a3d41c..cdeb0fd09b265e37c84eb91495d8a7903cb36cbf 100644 --- a/libs/dtos/src/dtos/requests/proof.req.dto.ts +++ b/libs/dtos/src/dtos/requests/proof.req.dto.ts @@ -1,14 +1,13 @@ import { IsNotEmpty, IsString, ValidateIf } from "class-validator"; - export class ProofReqDto { - @ValidateIf((o) => o.proofUrl === undefined, { always: true }) @IsString() @IsNotEmpty() + @ValidateIf((o) => o.proofUrl === undefined) proofId: string; - @ValidateIf((o) => o.proofId === undefined, { always: true }) @IsString() @IsNotEmpty() + @ValidateIf((o) => o.proofId === undefined) proofUrl: string; -} \ No newline at end of file +}