From 88ee201b32a6c4e7748ce02bcaa28603d51346c7 Mon Sep 17 00:00:00 2001 From: Pratap2018 Date: Wed, 14 Aug 2024 19:34:56 +0530 Subject: [PATCH] remove hardcoding --- src/credential/services/credential.service.ts | 46 +------------------ .../services/credential.ssi.service.ts | 5 +- src/did/services/did.service.ts | 2 +- src/schema/services/schema.service.ts | 32 +++++++------ 4 files changed, 22 insertions(+), 63 deletions(-) diff --git a/src/credential/services/credential.service.ts b/src/credential/services/credential.service.ts index 650ce769..aa351241 100644 --- a/src/credential/services/credential.service.ts +++ b/src/credential/services/credential.service.ts @@ -166,7 +166,7 @@ export class CredentialService { const credStatus = { credentialStatus, - namespace: 'testnet', + namespace: nameSpace, } as RegisterCredentialStatusDto; if (registerCredentialStatus) { await this.registerCredentialStatus(credStatus, appDetail); @@ -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, @@ -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}`, @@ -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); - }); - } } diff --git a/src/credential/services/credential.ssi.service.ts b/src/credential/services/credential.ssi.service.ts index d74c9ece..742043bb 100644 --- a/src/credential/services/credential.ssi.service.ts +++ b/src/credential/services/credential.ssi.service.ts @@ -10,10 +10,7 @@ export class CredentialSSIService { private readonly config: ConfigService, private readonly hidWallet: HidWalletService, ) {} - async initateHypersignVC( - mnemonic: string, - namespace: string, - ): Promise { + async initateHypersignVC(mnemonic: string,namespace: string): Promise { Logger.log('InitateHypersignVC(): starts....', 'CredentialSSIService'); const nodeRpcEndpoint = this.config.get('HID_NETWORK_RPC'); const nodeRestEndpoint = this.config.get('HID_NETWORK_API'); diff --git a/src/did/services/did.service.ts b/src/did/services/did.service.ts index 4316994c..0c6cf606 100644 --- a/src/did/services/did.service.ts +++ b/src/did/services/did.service.ts @@ -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({ diff --git a/src/schema/services/schema.service.ts b/src/schema/services/schema.service.ts index 78237a0c..6a04b78c 100644 --- a/src/schema/services/schema.service.ts +++ b/src/schema/services/schema.service.ts @@ -251,26 +251,30 @@ 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'); @@ -278,6 +282,6 @@ export class SchemaService { } Logger.log('registerSchema() method: ends....', 'SchemaService'); - return { status: 'Transaction sent' }; + return { transactionHash: registeredSchema?.transactionHash }; } }