Skip to content

Commit

Permalink
Add get_revocation_id for IssuerCredential (#793)
Browse files Browse the repository at this point in the history
* Add get_revocation_id for IssuerCredential

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Fix typo

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Fix JS wrapper method name

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

---------

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas authored Apr 7, 2023
1 parent 0b22360 commit 2f45045
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.getRevocationId()
}

async function _progressIssuerCredentialToState (issuerCredential, connection, credentialStateTarget, attemptsThreshold, timeoutMs) {
async function progressToAcceptedState () {
if (await issuerCredential.updateStateV2(connection) !== credentialStateTarget) {
Expand Down Expand Up @@ -158,6 +162,7 @@ module.exports.createServiceCredIssuer = function createServiceCredIssuer ({ log
revokeCredentialLocal,
credentialUpdate,
getVcxCredentialIssuer,
getRevocationId,

listIds,
printInfo,
Expand Down
3 changes: 2 additions & 1 deletion agents/node/vcxagent-core/test/utils/faber.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
14 changes: 14 additions & 0 deletions aries_vcx/src/handlers/issuance/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ impl Issuer {
self.issuer_sm.find_message_to_handle(messages)
}

pub fn get_revocation_id(&self) -> VcxResult<String> {
self.issuer_sm
.get_revocation_info()
.ok_or(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidState,
"Credential has not yet been created",
))?
.cred_rev_id
.ok_or(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidState,
"Credential has not yet been created or is irrevocable",
))
}

pub async fn revoke_credential_local(&self, profile: &Arc<dyn Profile>) -> VcxResult<()> {
let revocation_info: RevocationInfoV1 = self.issuer_sm.get_revocation_info().ok_or(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidState,
Expand Down
6 changes: 6 additions & 0 deletions libvcx_core/src/api_vcx/api_handle/issuer_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ pub fn get_credential_status(handle: u32) -> LibvcxResult<u32> {
})
}

pub fn get_revocation_id(handle: u32) -> LibvcxResult<String> {
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)
Expand Down
13 changes: 12 additions & 1 deletion wrappers/node/src/api/issuer-credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export class IssuerCredential extends VcxBaseWithState<IIssuerCredentialData, Is
}
}

public async updateStateWithMessageNonmediated(connection: NonmediatedConnection, message: string): Promise<number> {
public async updateStateWithMessageNonmediated(
connection: NonmediatedConnection,
message: string,
): Promise<number> {
try {
return await ffi.issuerCredentialUpdateStateWithMessageNonmediated(
this.handle,
Expand Down Expand Up @@ -179,6 +182,14 @@ export class IssuerCredential extends VcxBaseWithState<IIssuerCredentialData, Is
}
}

public getRevocationId(): string {
try {
return ffi.issuerCredentialGetRevocationId(this.handle);
} catch (err: any) {
throw new VCXInternalError(err);
}
}

protected _setHandle(handle: number): void {
super._setHandle(handle);
}
Expand Down
1 change: 1 addition & 0 deletions wrappers/vcx-napi-rs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export function issuerCredentialGetRevRegId(handleCredential: number): string
export function issuerCredentialCreate(sourceId: string): number
export function issuerCredentialRevokeLocal(handleCredential: number): Promise<void>
export function issuerCredentialIsRevokable(handleCredential: number): boolean
export function issuerCredentialGetRevocationId(handleCredential: number): string
export function issuerCredentialSendCredential(handleCredential: number, handleConnection: number): Promise<number>
export function issuerCredentialSendCredentialNonmediated(handleCredential: number, handleConnection: number): Promise<number>
export function issuerCredentialSendOfferV2(handleCredential: number, handleConnection: number): Promise<void>
Expand Down
9 changes: 8 additions & 1 deletion wrappers/vcx-napi-rs/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/* tslint:disable */
/* eslint-disable */
/* prettier-ignore */

/* auto-generated by NAPI-RS */

const { existsSync, readFileSync } = require('fs')
const { join } = require('path')

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions wrappers/vcx-napi-rs/src/api/issuer_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ fn issuer_credential_is_revokable(handle_credential: u32) -> napi::Result<bool>
issuer_credential::is_revokable(handle_credential).map_err(to_napi_err)
}

#[napi]
fn issuer_credential_get_revocation_id(handle_credential: u32) -> napi::Result<String> {
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<u32> {
issuer_credential::send_credential(handle_credential, handle_connection)
Expand Down

0 comments on commit 2f45045

Please sign in to comment.