Skip to content

Commit bdb89f2

Browse files
authored
fix: Issue for wallet creation with existing DID and Seed (#1394)
* fix/creation of wallet using existing did Signed-off-by: Sujit <[email protected]> * fix/change the for loop with retry function Signed-off-by: Sujit <[email protected]> * fix/pr comments Signed-off-by: Sujit <[email protected]> --------- Signed-off-by: Sujit <[email protected]>
1 parent 79ada17 commit bdb89f2

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

apps/agent-service/src/agent-service.service.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,21 @@ export class AgentServiceService {
11561156
return tenantDetails;
11571157
}
11581158

1159+
private async handleCreateDid(
1160+
agentEndpoint: string,
1161+
didPayload: Record<string, string>,
1162+
apiKey: string
1163+
): Promise<ICreateTenant> {
1164+
try {
1165+
return await this.commonService.httpPost(`${agentEndpoint}${CommonConstants.URL_AGENT_WRITE_DID}`, didPayload, {
1166+
headers: { authorization: apiKey }
1167+
});
1168+
} catch (error) {
1169+
this.logger.error('Error creating did:', error.message || error);
1170+
throw new RpcException(error.response ? error.response : error);
1171+
}
1172+
}
1173+
11591174
/**
11601175
* Create tenant wallet on the agent
11611176
* @param _createDID
@@ -1164,13 +1179,24 @@ export class AgentServiceService {
11641179
private async _createDID(didCreateOption): Promise<ICreateTenant> {
11651180
const { didPayload, agentEndpoint, apiKey } = didCreateOption;
11661181
// Invoke an API request from the agent to create multi-tenant agent
1167-
const didDetails = await this.commonService.httpPost(
1168-
`${agentEndpoint}${CommonConstants.URL_AGENT_WRITE_DID}`,
1169-
didPayload,
1170-
{ headers: { authorization: apiKey } }
1171-
);
1182+
1183+
//To Do : this is a temporary fix in normal case the api should return correct data in first attempt , to be removed in future on fixing did/write api response
1184+
const retryOptions = {
1185+
retries: 2
1186+
};
1187+
1188+
const didDetails = await retry(async () => {
1189+
const data = await this.handleCreateDid(agentEndpoint, didPayload, apiKey);
1190+
if (data?.didDocument || data?.didDoc) {
1191+
return data;
1192+
}
1193+
1194+
throw new Error('Invalid response, retrying...');
1195+
}, retryOptions);
1196+
11721197
return didDetails;
11731198
}
1199+
11741200
private async createSocketInstance(): Promise<Socket> {
11751201
return io(`${process.env.SOCKET_HOST}`, {
11761202
reconnection: true,

apps/agent-service/src/interface/agent-service.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ export interface ICreateTenant {
434434
tenantRecord: ITenantRecord;
435435
did: string;
436436
verkey: string;
437+
didDocument?: Record<string, string>;
438+
didDoc?: Record<string, string>;
437439
}
438440

439441
export interface IOrgAgent {

0 commit comments

Comments
 (0)