Skip to content

Commit

Permalink
remove hardcoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratap2018 committed Aug 14, 2024
1 parent c742093 commit 88ee201
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 63 deletions.
46 changes: 2 additions & 44 deletions src/credential/services/credential.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class CredentialService {

const credStatus = {
credentialStatus,
namespace: 'testnet',
namespace: nameSpace,
} as RegisterCredentialStatusDto;
if (registerCredentialStatus) {
await this.registerCredentialStatus(credStatus, appDetail);
Expand Down Expand Up @@ -344,7 +344,7 @@ export class CredentialService {
? namespace
: this.config.get('NETWORK')
? this.config.get('NETWORK')
: 'testnet';
: namespace;
const hypersignVC = await this.credentialSSIService.initateHypersignVC(
appMenemonic,
nameSpace,
Expand Down Expand Up @@ -516,9 +516,6 @@ export class CredentialService {
credentialStatusProof: proof,
});
}

const registredCredential = await this.registrationStatus(credentialId);
Logger.log('Registred Credential', registredCredential);
} catch (e) {
Logger.error(
`registerCredentialStatus() method: Error ${e.message}`,
Expand All @@ -532,43 +529,4 @@ export class CredentialService {
);
return { transactionHash: registeredVC?.transactionHash };
}

async registrationStatus(credId) {
return new Promise((resolve, reject) => {
const interval = 5000; // Interval in milliseconds (e.g., 5000ms = 5 seconds)
const maxAttempts = 20; // Maximum number of attempts before rejecting
let attempts = 0;

const intervalId = setInterval(async () => {
attempts++;

try {
// Assume resolveCredential is a method that checks the status and returns a response
const response = await fetch(
this.config.get('HID_NETWORK_API') +
'/hypersign-protocol/hidnode/ssi/credential/' +
credId,
);

if (response.status == 200) {
const resp = await response.json();
// Assuming status 200 means success
clearInterval(intervalId); // Stop the interval
resolve(resp); // Resolve the promise with the successful response
} else {
console.log(
`Attempt ${attempts}: Status not successful, retrying...`,
);
}
} catch (error) {
console.log(`Attempt ${attempts}: Error occurred, retrying...`);
}

if (attempts >= maxAttempts) {
clearInterval(intervalId); // Stop the interval after max attempts
reject(new Error('Maximum attempts reached, registration failed'));
}
}, interval);
});
}
}
5 changes: 1 addition & 4 deletions src/credential/services/credential.ssi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ export class CredentialSSIService {
private readonly config: ConfigService,
private readonly hidWallet: HidWalletService,
) {}
async initateHypersignVC(
mnemonic: string,
namespace: string,
): Promise<HypersignVerifiableCredential> {
async initateHypersignVC(mnemonic: string,namespace: string): Promise<HypersignVerifiableCredential> {
Logger.log('InitateHypersignVC(): starts....', 'CredentialSSIService');
const nodeRpcEndpoint = this.config.get('HID_NETWORK_RPC');
const nodeRestEndpoint = this.config.get('HID_NETWORK_API');
Expand Down
2 changes: 1 addition & 1 deletion src/did/services/did.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ export class DidService {
const mnemonic = await getAppMenemonic(kmsId);
const hypersignDid = await this.didSSIService.initiateHypersignDid(
mnemonic,
'testnet',
this.config.get('NETWORK') ? this.config.get('NETWORK') : 'testnet',
);

const didInfo = await this.didRepositiory.findOne({
Expand Down
32 changes: 18 additions & 14 deletions src/schema/services/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,33 +251,37 @@ export class SchemaService {
}

const appMenemonic = await getAppMenemonic(kmsId);
// const namespace = Namespace.testnet;
const namespace = Namespace.testnet;
Logger.log('registerSchema() method: initialising hypersignSchema');

// const hypersignSchema = await this.schemaSSIservice.initiateHypersignSchema(
// appMenemonic,
// namespace,
// );
const hypersignSchema = await this.schemaSSIservice.initiateHypersignSchema(
appMenemonic,
namespace,
);
schemaDocument['proof'] = schemaProof;
Logger.log('registerSchema() method: registering schema on the blockchain');
let registeredSchema;
try {
// registeredSchema = await hypersignSchema.register({
// schema: schemaDocument,
// });

const ack = await this.txnService.sendSchemaTxn(
registerSchemaDto.schemaDocument,
registerSchemaDto.schemaProof,
const { wallet, address } = await this.hidWallet.generateWallet(
appMenemonic,
);
if (ack == true) {
if (await this.checkAllowence(address)) {
await this.txnService.sendSchemaTxn(
registerSchemaDto.schemaDocument,
registerSchemaDto.schemaProof,
appMenemonic,
);
} else {
registeredSchema = await hypersignSchema.register({
schema: schemaDocument,
});
}
} catch (e) {
Logger.error('registerSchema() method: Error while registering schema');
throw new BadRequestException([e.message]);
}
Logger.log('registerSchema() method: ends....', 'SchemaService');

return { status: 'Transaction sent' };
return { transactionHash: registeredSchema?.transactionHash };
}
}

0 comments on commit 88ee201

Please sign in to comment.