Skip to content

Commit

Permalink
update credentialStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratap2018 committed Aug 7, 2024
1 parent 14f41bd commit 6946bcd
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/credential/services/credential.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,18 +337,31 @@ export class CredentialService {
'update() method: before calling hypersignVC.updateCredentialStatus to update cred status on chain',
'CredentialService',
);
const updatedCredResult = await hypersignVC.updateCredentialStatus({
const updateCredenital: any = await hypersignVC.updateCredentialStatus({
credentialStatus,
issuerDid,
verificationMethodId,
privateKeyMultibase,
status: statusChange,
statusReason,
readonly: true,
});
await this.credentialRepository.findOneAndUpdate(
{ appId: appDetail.appId, credentialId: id },
{ transactionHash: updatedCredResult.transactionHash },

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

await this.txnService.sendUpdateVC(
updateCredenital?.credentialStatus,
updateCredenital?.proofValue,
appMenemonic,
);

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

return await hypersignVC.resolveCredentialStatus({
Expand Down Expand Up @@ -437,10 +450,6 @@ export class CredentialService {
let registeredVC: { transactionHash: string };
try {
const appMenemonic = await getAppMenemonic(kmsId);
const hypersignVC = await this.credentialSSIService.initateHypersignVC(
appMenemonic,
namespace,
);
Logger.log(
'registerCredentialStatus() method: before calling hypersignVC.registerCredentialStatus to register credential status on chain',
'CredentialService',
Expand Down
69 changes: 69 additions & 0 deletions src/tx-send-module/tx-send-module.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import amqp, { ChannelWrapper } from 'amqp-connection-manager';
import {
MsgRegisterDID,
MsgRegisterCredentialStatus,
MsgUpdateCredentialStatus,
} from 'hs-ssi-sdk/build/libs/generated/ssi/tx';
import { DidSSIService } from 'src/did/services/did.ssi.service';
import { HidWalletService } from 'src/hid-wallet/services/hid-wallet.service';
Expand Down Expand Up @@ -119,6 +120,74 @@ export class TxSendModuleService {
});
}

async prepareUpdateCredentialStatus(credentialStatus, proofValue, address) {
return MsgUpdateCredentialStatus.fromPartial({
credentialStatusDocument: credentialStatus,
credentialStatusProof: credentialStatus,
txAuthor: address,
});
}

async sendUpdateVC(credentialStatus, proofValue, granteeMnemonic) {
if (!this.channel) {
await this.connect();
}
const { wallet, address } = await this.hidWalletService.generateWallet(
granteeMnemonic,
);
const msgUpdateCredentialStatus = await this.prepareUpdateCredentialStatus(
credentialStatus,
proofValue,
address,
);

const authExecMsg: MsgExec = {
grantee: address,
msgs: [
{
typeUrl: '/hypersign.ssi.v1.MsgUpdateCredentialStatus',
value: MsgUpdateCredentialStatus.encode(
msgUpdateCredentialStatus,
).finish(),
},
],
};

const fee = {
amount: [
{
denom: 'uhid',
amount: '100',
},
],
gas: '500000',
granter: this.granterAddress, // NOTE: It is VERY IMPORTANT to explicitly pass granter's address
};

const txMsg = {
typeUrl: '/cosmos.authz.v1beta1.MsgExec',
value: authExecMsg,
};

const data = {
type: 'CRED_UPDATE',
txMsg,
};

const queue = 'TXN_QUEUE_' + address;
await this.channel.assertQueue(queue, {
durable: false,
});

const sendToQueue1 = await this.channel.sendToQueue(
queue,
Buffer.from(JSON.stringify(data)),
);

await this.invokeTxnController(address, granteeMnemonic);
console.log(sendToQueue1);
}

async sendVCTxn(credentialStatus, credentialStatusProof, granteeMnemonic) {
if (!this.channel) {
await this.connect();
Expand Down

0 comments on commit 6946bcd

Please sign in to comment.