Skip to content

Commit

Permalink
backword compitiblity
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratap2018 committed Aug 14, 2024
1 parent af59a73 commit c742093
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 67 deletions.
100 changes: 74 additions & 26 deletions src/credential/services/credential.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ export class CredentialService {
private readonly txnService: TxSendModuleService,
) {}

async checkAllowence(address) {
const url =
this.config.get('HID_NETWORK_API') +
'/cosmos/feegrant/v1beta1/allowances/' +
address;

const resp = await fetch(url);

const res = await resp.json();
if (resp.status === 200) {
if (res.allowances.length > 0) {
return true;
} else {
return false;
}
}
return false;
}

async create(createCredentialDto: CreateCredentialDto, appDetail) {
Logger.log('create() method: starts....', 'CredentialService');
const {
Expand Down Expand Up @@ -341,31 +360,47 @@ export class CredentialService {
'update() method: before calling hypersignVC.updateCredentialStatus to update cred status on chain',
'CredentialService',
);
const updateCredenital: any = await hypersignVC.updateCredentialStatus({
credentialStatus,
issuerDid,
verificationMethodId,
privateKeyMultibase,
status: statusChange,
statusReason,
readonly: true,
});

console.log(
updateCredenital?.credentialStatus,
updateCredenital?.proofValue,
);

await this.txnService.sendUpdateVC(
updateCredenital?.credentialStatus,
updateCredenital?.proofValue,
const { wallet, address } = await this.hidWallet.generateWallet(

Check warning on line 364 in src/credential/services/credential.service.ts

View workflow job for this annotation

GitHub Actions / build

'wallet' is assigned a value but never used
appMenemonic,
);
let updatedCredResult;
if (await this.checkAllowence(address)) {
const updateCredenital: any = await hypersignVC.updateCredentialStatus({
credentialStatus,
issuerDid,
verificationMethodId,
privateKeyMultibase,
status: statusChange,
statusReason,
readonly: true,
});

await this.txnService.sendUpdateVC(
updateCredenital?.credentialStatus,
updateCredenital?.proofValue,
appMenemonic,
);
} else {
updatedCredResult = await hypersignVC.updateCredentialStatus({
credentialStatus,
issuerDid,
verificationMethodId,
privateKeyMultibase,
status: statusChange,
statusReason,
readonly: false,
});
}

// await this.credentialRepository.findOneAndUpdate(
// { appId: appDetail.appId, credentialId: id },
// { transactionHash: updatedCredResult.transactionHash },
// );
await this.credentialRepository.findOneAndUpdate(
{ appId: appDetail.appId, credentialId: id },
{
transactionHash: updatedCredResult?.transactionHash
? updatedCredResult?.transactionHash
: '',
},
);
Logger.log('update() method: ends....', 'CredentialService');

return await hypersignVC.resolveCredentialStatus({
Expand Down Expand Up @@ -461,13 +496,26 @@ export class CredentialService {
);

const { proof } = credentialStatus;

delete credentialStatus['proof'];
// registeredVC = await hypersignVC.registerCredentialStatus({
// credentialStatus,
// credentialStatusProof: proof,
// });

await this.txnService.sendVCTxn(credentialStatus, proof, appMenemonic);
const { wallet, address } = await this.hidWallet.generateWallet(

Check warning on line 502 in src/credential/services/credential.service.ts

View workflow job for this annotation

GitHub Actions / build

'wallet' is assigned a value but never used
appMenemonic,
);

const hypersignVC = await this.credentialSSIService.initateHypersignVC(
appMenemonic,
namespace,
);

if (await this.checkAllowence(address)) {
await this.txnService.sendVCTxn(credentialStatus, proof, appMenemonic);
} else {
registeredVC = await hypersignVC.registerCredentialStatus({
credentialStatus,
credentialStatusProof: proof,
});
}

const registredCredential = await this.registrationStatus(credentialId);
Logger.log('Registred Credential', registredCredential);
Expand Down
119 changes: 89 additions & 30 deletions src/did/services/did.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ export class DidService {
private readonly txnService: TxSendModuleService,
) {}

async checkAllowence(address) {
const url =
this.config.get('HID_NETWORK_API') +
'/cosmos/feegrant/v1beta1/allowances/' +
address;

const resp = await fetch(url);

const res = await resp.json();
if (resp.status === 200) {
if (res.allowances.length > 0) {
return true;
} else {
return false;
}
}
return false;
}

// TODO: need to fix this once ed25519 is finished.
async createByClientSpec(createDidDto: CreateDidDto, appDetail) {
Logger.log('createByClientSpec() method: starts....', 'DidService');
Expand Down Expand Up @@ -369,29 +388,38 @@ export class DidService {
seed: seed,
});
const regDidDocument = registerDidDto.didDocument as Did;
const params = {
didDocument: regDidDocument,
privateKeyMultibase,
verificationMethodId: verificationMethodId,
};

Logger.log(
'register() method: before calling hypersignDid.register ',
'DidService',
);

const didDocPreserved = {};
Object.assign(didDocPreserved, didDocument);
const signInfos = await hypersignDid.createSignInfos({
didDocument,
privateKeyMultibase,
verificationMethodId: verificationMethodId,
});
await this.txnService.sendDIDTxn(
didDocument,
signInfos,
verificationMethodId,
const params = {
didDocument: didDocPreserved,
privateKeyMultibase,
verificationMethodId: verificationMethodId,
};

const { wallet, address } = await this.hidWallet.generateWallet(
appMenemonic,
);
if (await this.checkAllowence(address)) {
await this.txnService.sendDIDTxn(
didDocument,
signInfos,
verificationMethodId,
appMenemonic,
);
} else {
registerDidDoc = await hypersignDid.register(params);
}

// registerDidDoc = await hypersignDid.register(params);
data = await this.didRepositiory.findOneAndUpdate(
{ did: didDocument['id'] },
{
Expand Down Expand Up @@ -633,36 +661,67 @@ export class DidService {
});

try {
updatedDid = await hypersignDid.update({
didDocument: updateDidDto.didDocument as Did,
privateKeyMultibase,
verificationMethodId: resolvedDid['verificationMethod'][0].id,
versionId: updatedDidDocMetaData.versionId,
readonly: true,
});
const { wallet, address } = await this.hidWallet.generateWallet(
appMenemonic,
);

if (!updateDidDto.deactivate) {
Logger.debug(
'updateDid() method: before calling hypersignDid.update to update did',
'DidService',
);

await this.txnService.sendDIDUpdate(
updatedDid.didDocument,
updatedDid.signInfos,
updatedDid.versionId,
appMenemonic,
);
if ((await this.checkAllowence(address)) == false) {
updatedDid = await hypersignDid.update({
didDocument: updateDidDto.didDocument as Did,
privateKeyMultibase,
verificationMethodId: resolvedDid['verificationMethod'][0].id,
versionId: updatedDidDocMetaData.versionId,
readonly: false,
});
} else {
updatedDid = await hypersignDid.update({
didDocument: updateDidDto.didDocument as Did,
privateKeyMultibase,
verificationMethodId: resolvedDid['verificationMethod'][0].id,
versionId: updatedDidDocMetaData.versionId,
readonly: true,
});
await this.txnService.sendDIDUpdate(
updatedDid.didDocument,
updatedDid.signInfos,
updatedDid.versionId,
appMenemonic,
);
}
} else {
Logger.debug(
'updateDid() method: before calling hypersignDid.deactivate to deactivate did',
'DidService',
);
await this.txnService.sendDIDDeactivate(
updatedDid.didDocument,
updatedDid.signInfos,
updatedDid.versionId,
appMenemonic,
);

if ((await this.checkAllowence(address)) == false) {
updatedDid = await hypersignDid.deactivate({
didDocument: updateDidDto.didDocument as Did,
privateKeyMultibase,
verificationMethodId: resolvedDid['verificationMethod'][0].id,
versionId: updatedDidDocMetaData.versionId,
});
} else {
updatedDid = await hypersignDid.update({
didDocument: updateDidDto.didDocument as Did,
privateKeyMultibase,
verificationMethodId: resolvedDid['verificationMethod'][0].id,
versionId: updatedDidDocMetaData.versionId,
readonly: true,
});
await this.txnService.sendDIDDeactivate(
updatedDid.didDocument,
updatedDid.signInfos,
updatedDid.versionId,
appMenemonic,
);
}
}
} catch (error) {
Logger.error(
Expand Down
50 changes: 39 additions & 11 deletions src/schema/services/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ export class SchemaService {
private readonly didRepositiory: DidRepository,
private readonly txnService: TxSendModuleService,
) {}

async checkAllowence(address) {
const url =
this.config.get('HID_NETWORK_API') +
'/cosmos/feegrant/v1beta1/allowances/' +
address;

const resp = await fetch(url);

const res = await resp.json();
if (resp.status === 200) {
if (res.allowances.length > 0) {
return true;
} else {
return false;
}
}
return false;
}
async create(
createSchemaDto: CreateSchemaDto,
appDetail,
Expand Down Expand Up @@ -94,17 +113,22 @@ export class SchemaService {
'SchemaService',
);

// const registeredSchema = await hypersignSchema.register({
// schema: signedSchema,
// });

let registeredSchema;

await this.txnService.sendSchemaTxn(
generatedSchema,
signedSchema.proof,
const { wallet, address } = await this.hidWallet.generateWallet(
appMenemonic,
);
let registeredSchema;

if (await this.checkAllowence(address)) {
await this.txnService.sendSchemaTxn(
generatedSchema,
signedSchema.proof,
appMenemonic,
);
} else {
registeredSchema = await hypersignSchema.register({
schema: signedSchema,
});
}

Logger.log(
'create() method: storing schema information to DB',
Expand All @@ -114,13 +138,17 @@ export class SchemaService {
schemaId: signedSchema.id,
appId: appDetail.appId,
authorDid: author,
transactionHash: '',
transactionHash: registeredSchema['transactionHash']
? registeredSchema['transactionHash']
: '',
});
Logger.log('create() method: ends', 'SchemaService');

return {
schemaId: signedSchema.id,
transactionHash: '',
transactionHash: registeredSchema['transactionHash']
? registeredSchema['transactionHash']
: '',
};
} catch (error) {
Logger.error(
Expand Down

0 comments on commit c742093

Please sign in to comment.