Skip to content
Snippets Groups Projects

chore: abstract dtos to encompass a wider range of use cases and fix for out of band proof requests

Closed Boyan Tsolov requested to merge core-dtos into main
All threads resolved!
Compare and Show latest version
6 files
+ 49
77
Compare changes
  • Side-by-side
  • Inline
Files
6
@@ -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;
Loading