From 0e54f5daae5257b956659bf0e3c7cb11fa0126f7 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Thu, 6 Apr 2023 10:27:26 +0200 Subject: [PATCH 1/3] Add get_revocation_id for IssuerCredential Signed-off-by: Patrik Stas --- .../src/services/service-cred-issuer.js | 7 ++++++- agents/node/vcxagent-core/test/utils/faber.js | 3 ++- aries_vcx/src/handlers/issuance/issuer.rs | 14 ++++++++++++++ .../src/api_vcx/api_handle/issuer_credential.rs | 6 ++++++ wrappers/node/src/api/issuer-credential.ts | 13 ++++++++++++- wrappers/vcx-napi-rs/index.d.ts | 1 + wrappers/vcx-napi-rs/index.js | 9 ++++++++- wrappers/vcx-napi-rs/src/api/issuer_credential.rs | 5 +++++ 8 files changed, 54 insertions(+), 4 deletions(-) diff --git a/agents/node/vcxagent-core/src/services/service-cred-issuer.js b/agents/node/vcxagent-core/src/services/service-cred-issuer.js index 24266a0296..dcb88fc366 100644 --- a/agents/node/vcxagent-core/src/services/service-cred-issuer.js +++ b/agents/node/vcxagent-core/src/services/service-cred-issuer.js @@ -98,10 +98,14 @@ module.exports.createServiceCredIssuer = function createServiceCredIssuer ({ log async function getRevRegId (issuerCredId) { const issuerCred = await loadIssuerCredential(issuerCredId) - logger.info(`Getting rev reg id for credential ${issuerCredId}`) return issuerCred.getRevRegId() } + async function getRevocationId (issuerCredId) { + const issuerCred = await loadIssuerCredential(issuerCredId) + return issuerCred.getRevRevocationId() + } + async function _progressIssuerCredentialToState (issuerCredential, connection, credentialStateTarget, attemptsThreshold, timeoutMs) { async function progressToAcceptedState () { if (await issuerCredential.updateStateV2(connection) !== credentialStateTarget) { @@ -158,6 +162,7 @@ module.exports.createServiceCredIssuer = function createServiceCredIssuer ({ log revokeCredentialLocal, credentialUpdate, getVcxCredentialIssuer, + getRevocationId, listIds, printInfo, diff --git a/agents/node/vcxagent-core/test/utils/faber.js b/agents/node/vcxagent-core/test/utils/faber.js index 876196859f..11b6025d09 100644 --- a/agents/node/vcxagent-core/test/utils/faber.js +++ b/agents/node/vcxagent-core/test/utils/faber.js @@ -221,7 +221,8 @@ module.exports.createFaber = async function createFaber (serviceEndpoint = 'http logger.info('Issuer sending credential') expect(await vcxAgent.serviceCredIssuer.sendCredential(issuerCredId, connectionId)).toBe(IssuerStateType.CredentialSent) - logger.info('Credential sent') + const revocationId = await vcxAgent.serviceCredIssuer.getRevocationId(issuerCredId) + logger.info(`Sent credential with revocation id ${revocationId}`) await vcxAgent.agentShutdownVcx() } diff --git a/aries_vcx/src/handlers/issuance/issuer.rs b/aries_vcx/src/handlers/issuance/issuer.rs index fcf14d3deb..95bd5b558d 100644 --- a/aries_vcx/src/handlers/issuance/issuer.rs +++ b/aries_vcx/src/handlers/issuance/issuer.rs @@ -209,6 +209,20 @@ impl Issuer { self.issuer_sm.find_message_to_handle(messages) } + pub fn get_revocation_id(&self) -> VcxResult { + self.issuer_sm + .get_revocation_info() + .ok_or(AriesVcxError::from_msg( + AriesVcxErrorKind::InvalidState, + "Credential is has not yet been created", + ))? + .cred_rev_id + .ok_or(AriesVcxError::from_msg( + AriesVcxErrorKind::InvalidState, + "Credential is has not yet been created or is irrevocable", + )) + } + pub async fn revoke_credential_local(&self, profile: &Arc) -> VcxResult<()> { let revocation_info: RevocationInfoV1 = self.issuer_sm.get_revocation_info().ok_or(AriesVcxError::from_msg( AriesVcxErrorKind::InvalidState, diff --git a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs index e9c4d4f372..372e36eeba 100644 --- a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs @@ -103,6 +103,12 @@ pub fn get_credential_status(handle: u32) -> LibvcxResult { }) } +pub fn get_revocation_id(handle: u32) -> LibvcxResult { + ISSUER_CREDENTIAL_MAP.get(handle, |credential| { + credential.get_revocation_id().map_err(|err| err.into()) + }) +} + pub fn release(handle: u32) -> LibvcxResult<()> { ISSUER_CREDENTIAL_MAP .release(handle) diff --git a/wrappers/node/src/api/issuer-credential.ts b/wrappers/node/src/api/issuer-credential.ts index 04c6bfa76b..c34e919615 100644 --- a/wrappers/node/src/api/issuer-credential.ts +++ b/wrappers/node/src/api/issuer-credential.ts @@ -68,7 +68,10 @@ export class IssuerCredential extends VcxBaseWithState { + public async updateStateWithMessageNonmediated( + connection: NonmediatedConnection, + message: string, + ): Promise { try { return await ffi.issuerCredentialUpdateStateWithMessageNonmediated( this.handle, @@ -179,6 +182,14 @@ export class IssuerCredential extends VcxBaseWithState export function issuerCredentialIsRevokable(handleCredential: number): boolean +export function issuerCredentialGetRevocationId(handleCredential: number): string export function issuerCredentialSendCredential(handleCredential: number, handleConnection: number): Promise export function issuerCredentialSendCredentialNonmediated(handleCredential: number, handleConnection: number): Promise export function issuerCredentialSendOfferV2(handleCredential: number, handleConnection: number): Promise diff --git a/wrappers/vcx-napi-rs/index.js b/wrappers/vcx-napi-rs/index.js index cb315baf7e..5c447ce4b0 100644 --- a/wrappers/vcx-napi-rs/index.js +++ b/wrappers/vcx-napi-rs/index.js @@ -1,3 +1,9 @@ +/* tslint:disable */ +/* eslint-disable */ +/* prettier-ignore */ + +/* auto-generated by NAPI-RS */ + const { existsSync, readFileSync } = require('fs') const { join } = require('path') @@ -246,7 +252,7 @@ if (!nativeBinding) { throw new Error(`Failed to load native binding`) } -const { updateWebhookUrl, createAgencyClientForMainWallet, provisionCloudAgent, messagesUpdateStatus, generatePublicInvitation, connectionCreateInviter, connectionCreateInvitee, connectionGetThreadId, connectionGetPairwiseInfo, connectionGetRemoteDid, connectionGetRemoteVk, connectionGetState, connectionGetInvitation, connectionProcessInvite, connectionProcessRequest, connectionProcessResponse, connectionProcessAck, connectionProcessProblemReport, connectionSendResponse, connectionSendRequest, connectionSendAck, connectionSendGenericMessage, connectionSendAriesMessage, connectionCreateInvite, connectionSerialize, connectionDeserialize, connectionRelease, credentialCreateWithOffer, credentialRelease, credentialSendRequest, credentialDeclineOffer, credentialSerialize, credentialDeserialize, v2CredentialUpdateStateWithMessage, v2CredentialUpdateState, credentialGetState, credentialGetOffers, credentialGetAttributes, credentialGetAttachment, credentialGetTailsLocation, credentialGetTailsHash, credentialGetRevRegId, credentialGetThreadId, credentialdefCreateV2, credentialdefPublish, credentialdefDeserialize, credentialdefRelease, credentialdefSerialize, credentialdefGetCredDefId, credentialdefUpdateState, credentialdefGetState, disclosedProofCreateWithRequest, disclosedProofRelease, disclosedProofSendProof, disclosedProofRejectProof, disclosedProofGetProofMsg, disclosedProofSerialize, disclosedProofDeserialize, v2DisclosedProofUpdateState, v2DisclosedProofUpdateStateWithMessage, disclosedProofGetState, disclosedProofGetRequests, disclosedProofRetrieveCredentials, disclosedProofGetProofRequestAttachment, disclosedProofGenerateProof, disclosedProofDeclinePresentationRequest, disclosedProofGetThreadId, issuerCredentialDeserialize, issuerCredentialSerialize, issuerCredentialUpdateStateV2, issuerCredentialUpdateStateWithMessageV2, issuerCredentialUpdateStateWithMessageNonmediated, issuerCredentialGetState, issuerCredentialGetRevRegId, issuerCredentialCreate, issuerCredentialRevokeLocal, issuerCredentialIsRevokable, issuerCredentialSendCredential, issuerCredentialSendCredentialNonmediated, issuerCredentialSendOfferV2, issuerCredentialSendOfferNonmediated, issuerCredentialMarkOfferMsgSent, issuerCredentialBuildOfferMsgV2, issuerCredentialGetOfferMsg, issuerCredentialRelease, issuerCredentialGetThreadId, getLedgerAuthorAgreement, setActiveTxnAuthorAgreementMeta, createService, createServiceV2, getServiceFromLedger, getAttrFromLedger, clearAttrFromLedger, getVerkeyFromLedger, getLedgerTxn, initDefaultLogger, mediatedConnectionGeneratePublicInvite, mediatedConnectionGetPwDid, mediatedConnectionGetTheirPwDid, mediatedConnectionGetThreadId, mediatedConnectionGetState, mediatedConnectionGetSourceId, mediatedConnectionCreate, mediatedConnectionCreateWithInvite, mediatedConnectionSendMessage, mediatedConnectionCreateWithConnectionRequestV2, mediatedConnectionSendHandshakeReuse, mediatedConnectionUpdateStateWithMessage, mediatedConnectionHandleMessage, mediatedConnectionUpdateState, mediatedConnectionDeleteConnection, mediatedConnectionConnect, mediatedConnectionSerialize, mediatedConnectionDeserialize, mediatedConnectionRelease, mediatedConnectionInviteDetails, mediatedConnectionSendPing, mediatedConnectionSendDiscoveryFeatures, mediatedConnectionInfo, mediatedConnectionMessagesDownload, mediatedConnectionSignData, mediatedConnectionVerifySignature, outOfBandBuildHandshakeReuseAcceptedMsg, outOfBandReceiverCreate, outOfBandReceiverExtractMessage, outOfBandReceiverConnectionExists, outOfBandReceiverNonmediatedConnectionExists, outOfBandReceiverBuildConnection, outOfBandReceiverGetThreadId, outOfBandReceiverSerialize, outOfBandReceiverDeserialize, outOfBandReceiverRelease, outOfBandSenderCreate, outOfBandSenderAppendMessage, outOfBandSenderAppendService, outOfBandSenderAppendServiceDid, outOfBandSenderToMessage, outOfBandSenderGetThreadId, outOfBandSenderSerialize, outOfBandSenderDeserialize, outOfBandSenderRelease, openMainPool, closeMainPool, proofCreate, proofGetPresentationMsg, proofGetPresentationRequestAttachment, proofGetPresentationAttachment, proofRelease, proofSendRequest, proofSendRequestNonmediated, proofGetRequestMsg, proofSerialize, proofDeserialize, v2ProofUpdateState, v2ProofUpdateStateWithMessage, proofUpdateStateWithMessageNonmediated, proofGetState, proofGetVerificationStatus, proofGetThreadId, markPresentationRequestMsgSent, revocationRegistryCreate, revocationRegistryPublish, revocationRegistryPublishRevocations, revocationRegistryGetRevRegId, revocationRegistryGetTailsHash, revocationRegistrySerialize, revocationRegistryDeserialize, revocationRegistryRelease, schemaGetAttributes, schemaPrepareForEndorser, schemaCreate, schemaGetSchemaId, schemaDeserialize, schemaSerialize, schemaRelease, schemaUpdateState, schemaGetState, enableMocks, trustpingBuildResponseMsg, trustpingBuildPing, shutdown, getVersion, walletOpenAsMain, walletCreateMain, walletCloseMain, vcxInitIssuerConfig, configureIssuerWallet, unpack, createPairwiseInfo, walletImport, walletExport, getVerkeyFromWallet, rotateVerkey, rotateVerkeyStart, rotateVerkeyApply } = nativeBinding +const { updateWebhookUrl, createAgencyClientForMainWallet, provisionCloudAgent, messagesUpdateStatus, generatePublicInvitation, connectionCreateInviter, connectionCreateInvitee, connectionGetThreadId, connectionGetPairwiseInfo, connectionGetRemoteDid, connectionGetRemoteVk, connectionGetState, connectionGetInvitation, connectionProcessInvite, connectionProcessRequest, connectionProcessResponse, connectionProcessAck, connectionProcessProblemReport, connectionSendResponse, connectionSendRequest, connectionSendAck, connectionSendGenericMessage, connectionSendAriesMessage, connectionCreateInvite, connectionSerialize, connectionDeserialize, connectionRelease, credentialCreateWithOffer, credentialRelease, credentialSendRequest, credentialDeclineOffer, credentialSerialize, credentialDeserialize, v2CredentialUpdateStateWithMessage, v2CredentialUpdateState, credentialGetState, credentialGetOffers, credentialGetAttributes, credentialGetAttachment, credentialGetTailsLocation, credentialGetTailsHash, credentialGetRevRegId, credentialGetThreadId, credentialdefCreateV2, credentialdefPublish, credentialdefDeserialize, credentialdefRelease, credentialdefSerialize, credentialdefGetCredDefId, credentialdefUpdateState, credentialdefGetState, disclosedProofCreateWithRequest, disclosedProofRelease, disclosedProofSendProof, disclosedProofRejectProof, disclosedProofGetProofMsg, disclosedProofSerialize, disclosedProofDeserialize, v2DisclosedProofUpdateState, v2DisclosedProofUpdateStateWithMessage, disclosedProofGetState, disclosedProofGetRequests, disclosedProofRetrieveCredentials, disclosedProofGetProofRequestAttachment, disclosedProofGenerateProof, disclosedProofDeclinePresentationRequest, disclosedProofGetThreadId, issuerCredentialDeserialize, issuerCredentialSerialize, issuerCredentialUpdateStateV2, issuerCredentialUpdateStateWithMessageV2, issuerCredentialUpdateStateWithMessageNonmediated, issuerCredentialGetState, issuerCredentialGetRevRegId, issuerCredentialCreate, issuerCredentialRevokeLocal, issuerCredentialIsRevokable, issuerCredentialGetRevocationId, issuerCredentialSendCredential, issuerCredentialSendCredentialNonmediated, issuerCredentialSendOfferV2, issuerCredentialSendOfferNonmediated, issuerCredentialMarkOfferMsgSent, issuerCredentialBuildOfferMsgV2, issuerCredentialGetOfferMsg, issuerCredentialRelease, issuerCredentialGetThreadId, getLedgerAuthorAgreement, setActiveTxnAuthorAgreementMeta, createService, createServiceV2, getServiceFromLedger, getAttrFromLedger, clearAttrFromLedger, getVerkeyFromLedger, getLedgerTxn, initDefaultLogger, mediatedConnectionGeneratePublicInvite, mediatedConnectionGetPwDid, mediatedConnectionGetTheirPwDid, mediatedConnectionGetThreadId, mediatedConnectionGetState, mediatedConnectionGetSourceId, mediatedConnectionCreate, mediatedConnectionCreateWithInvite, mediatedConnectionSendMessage, mediatedConnectionCreateWithConnectionRequestV2, mediatedConnectionSendHandshakeReuse, mediatedConnectionUpdateStateWithMessage, mediatedConnectionHandleMessage, mediatedConnectionUpdateState, mediatedConnectionDeleteConnection, mediatedConnectionConnect, mediatedConnectionSerialize, mediatedConnectionDeserialize, mediatedConnectionRelease, mediatedConnectionInviteDetails, mediatedConnectionSendPing, mediatedConnectionSendDiscoveryFeatures, mediatedConnectionInfo, mediatedConnectionMessagesDownload, mediatedConnectionSignData, mediatedConnectionVerifySignature, outOfBandBuildHandshakeReuseAcceptedMsg, outOfBandReceiverCreate, outOfBandReceiverExtractMessage, outOfBandReceiverConnectionExists, outOfBandReceiverNonmediatedConnectionExists, outOfBandReceiverBuildConnection, outOfBandReceiverGetThreadId, outOfBandReceiverSerialize, outOfBandReceiverDeserialize, outOfBandReceiverRelease, outOfBandSenderCreate, outOfBandSenderAppendMessage, outOfBandSenderAppendService, outOfBandSenderAppendServiceDid, outOfBandSenderToMessage, outOfBandSenderGetThreadId, outOfBandSenderSerialize, outOfBandSenderDeserialize, outOfBandSenderRelease, openMainPool, closeMainPool, proofCreate, proofGetPresentationMsg, proofGetPresentationRequestAttachment, proofGetPresentationAttachment, proofRelease, proofSendRequest, proofSendRequestNonmediated, proofGetRequestMsg, proofSerialize, proofDeserialize, v2ProofUpdateState, v2ProofUpdateStateWithMessage, proofUpdateStateWithMessageNonmediated, proofGetState, proofGetVerificationStatus, proofGetThreadId, markPresentationRequestMsgSent, revocationRegistryCreate, revocationRegistryPublish, revocationRegistryPublishRevocations, revocationRegistryGetRevRegId, revocationRegistryGetTailsHash, revocationRegistrySerialize, revocationRegistryDeserialize, revocationRegistryRelease, schemaGetAttributes, schemaPrepareForEndorser, schemaCreate, schemaGetSchemaId, schemaDeserialize, schemaSerialize, schemaRelease, schemaUpdateState, schemaGetState, enableMocks, trustpingBuildResponseMsg, trustpingBuildPing, shutdown, getVersion, walletOpenAsMain, walletCreateMain, walletCloseMain, vcxInitIssuerConfig, configureIssuerWallet, unpack, createPairwiseInfo, walletImport, walletExport, getVerkeyFromWallet, rotateVerkey, rotateVerkeyStart, rotateVerkeyApply } = nativeBinding module.exports.updateWebhookUrl = updateWebhookUrl module.exports.createAgencyClientForMainWallet = createAgencyClientForMainWallet @@ -325,6 +331,7 @@ module.exports.issuerCredentialGetRevRegId = issuerCredentialGetRevRegId module.exports.issuerCredentialCreate = issuerCredentialCreate module.exports.issuerCredentialRevokeLocal = issuerCredentialRevokeLocal module.exports.issuerCredentialIsRevokable = issuerCredentialIsRevokable +module.exports.issuerCredentialGetRevocationId = issuerCredentialGetRevocationId module.exports.issuerCredentialSendCredential = issuerCredentialSendCredential module.exports.issuerCredentialSendCredentialNonmediated = issuerCredentialSendCredentialNonmediated module.exports.issuerCredentialSendOfferV2 = issuerCredentialSendOfferV2 diff --git a/wrappers/vcx-napi-rs/src/api/issuer_credential.rs b/wrappers/vcx-napi-rs/src/api/issuer_credential.rs index b6a0617bb4..0891003bb6 100644 --- a/wrappers/vcx-napi-rs/src/api/issuer_credential.rs +++ b/wrappers/vcx-napi-rs/src/api/issuer_credential.rs @@ -70,6 +70,11 @@ fn issuer_credential_is_revokable(handle_credential: u32) -> napi::Result issuer_credential::is_revokable(handle_credential).map_err(to_napi_err) } +#[napi] +fn issuer_credential_get_revocation_id(handle_credential: u32) -> napi::Result { + issuer_credential::get_revocation_id(handle_credential).map_err(to_napi_err) +} + #[napi] async fn issuer_credential_send_credential(handle_credential: u32, handle_connection: u32) -> napi::Result { issuer_credential::send_credential(handle_credential, handle_connection) From 01d8ebf454c51c22f374d2a79ecbe9c36565b44e Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Thu, 6 Apr 2023 16:57:47 +0200 Subject: [PATCH 2/3] Fix typo Signed-off-by: Patrik Stas --- aries_vcx/src/handlers/issuance/issuer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aries_vcx/src/handlers/issuance/issuer.rs b/aries_vcx/src/handlers/issuance/issuer.rs index 95bd5b558d..bd5a02f914 100644 --- a/aries_vcx/src/handlers/issuance/issuer.rs +++ b/aries_vcx/src/handlers/issuance/issuer.rs @@ -214,12 +214,12 @@ impl Issuer { .get_revocation_info() .ok_or(AriesVcxError::from_msg( AriesVcxErrorKind::InvalidState, - "Credential is has not yet been created", + "Credential has not yet been created", ))? .cred_rev_id .ok_or(AriesVcxError::from_msg( AriesVcxErrorKind::InvalidState, - "Credential is has not yet been created or is irrevocable", + "Credential has not yet been created or is irrevocable", )) } From ff828e5782659a3713ddb4e5f902aba9cf42df26 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Thu, 6 Apr 2023 17:10:18 +0200 Subject: [PATCH 3/3] Fix JS wrapper method name Signed-off-by: Patrik Stas --- agents/node/vcxagent-core/src/services/service-cred-issuer.js | 2 +- wrappers/node/src/api/issuer-credential.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/agents/node/vcxagent-core/src/services/service-cred-issuer.js b/agents/node/vcxagent-core/src/services/service-cred-issuer.js index dcb88fc366..635c4140d8 100644 --- a/agents/node/vcxagent-core/src/services/service-cred-issuer.js +++ b/agents/node/vcxagent-core/src/services/service-cred-issuer.js @@ -103,7 +103,7 @@ module.exports.createServiceCredIssuer = function createServiceCredIssuer ({ log async function getRevocationId (issuerCredId) { const issuerCred = await loadIssuerCredential(issuerCredId) - return issuerCred.getRevRevocationId() + return issuerCred.getRevocationId() } async function _progressIssuerCredentialToState (issuerCredential, connection, credentialStateTarget, attemptsThreshold, timeoutMs) { diff --git a/wrappers/node/src/api/issuer-credential.ts b/wrappers/node/src/api/issuer-credential.ts index c34e919615..d94d617ac0 100644 --- a/wrappers/node/src/api/issuer-credential.ts +++ b/wrappers/node/src/api/issuer-credential.ts @@ -182,7 +182,7 @@ export class IssuerCredential extends VcxBaseWithState