Skip to content

Commit

Permalink
NodeJS wrapper: Expose createServiceV2 (#756)
Browse files Browse the repository at this point in the history
*NodeJS wrapper:  Expose createServiceV2

Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
  • Loading branch information
mirgee authored Feb 19, 2023
1 parent 494b14c commit 2c0ec21
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ jobs:
brew install openssl
brew install zeromq
brew install libsodium
brew install pkg-config
- name: "Build libvcx.dylib"
run: cargo build --release
- name: "Publish artifact libvcx.dylib"
Expand Down Expand Up @@ -709,7 +710,7 @@ jobs:
- host: macos-latest
target: x86_64-apple-darwin
build: |
brew install openssl zmq
brew install openssl zmq pkg-config
npm run build:napi
strip -x *.node
- host: macos-latest
Expand Down
2 changes: 1 addition & 1 deletion ci/libvcx.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ RUN cp /usr/share/zoneinfo/UTC /etc/localtime && echo UTC > /etc/timezone
ENV TZ=UTC

RUN echo 'https://dl-cdn.alpinelinux.org/alpine/v3.17/main' >> /etc/apk/repositories
RUN apk add --no-cache nodejs=18.12.1-r0
RUN apk add --no-cache nodejs=18.14.1-r0

USER node
20 changes: 19 additions & 1 deletion libvcx/src/api_vcx/api_global/ledger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use aries_vcx::common::ledger::transactions::{get_service, write_endpoint_legacy};
use aries_vcx::common::ledger::service_didsov::{DidSovServiceType, EndpointDidSov};
use aries_vcx::common::ledger::transactions::{get_service, write_endpoint, write_endpoint_legacy};
use aries_vcx::global::settings::CONFIG_INSTITUTION_DID;
use aries_vcx::messages::diddoc::aries::service::AriesService;
use aries_vcx::messages::protocols::connection::did::Did;
Expand Down Expand Up @@ -47,6 +48,23 @@ pub async fn ledger_write_endpoint_legacy(
Ok(service)
}

pub async fn ledger_write_endpoint(
target_did: &str,
routing_keys: Vec<String>,
endpoint: String,
) -> LibvcxResult<EndpointDidSov> {
let service = EndpointDidSov::create()
.set_service_endpoint(endpoint)
.set_types(Some(vec![
DidSovServiceType::Endpoint,
DidSovServiceType::DidCommunication,
]))
.set_routing_keys(Some(routing_keys));
let profile = get_main_profile()?;
write_endpoint(&profile, target_did, &service).await?;
Ok(service)
}

pub async fn ledger_get_service(target_did: &str) -> LibvcxResult<AriesService> {
let target_did = Did::new(target_did)?;
let profile = get_main_profile()?;
Expand Down
18 changes: 18 additions & 0 deletions wrappers/node/src/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export interface IAriesService {
serviceEndpoint: string;
}

export interface IAriesServiceV2 {
endpoint: string;
routingKeys?: string[];
types?: string[];
}

export async function provisionCloudAgent(configAgent: object): Promise<string> {
try {
return await ffi.provisionCloudAgent(JSON.stringify(configAgent));
Expand Down Expand Up @@ -165,6 +171,18 @@ export async function createService(
}
}

export async function createServiceV2(
target_did: string,
endpoint: string,
routingKeys: string[],
): Promise<IAriesServiceV2> {
try {
return JSON.parse(await ffi.createServiceV2(target_did, routingKeys, endpoint));
} catch (err: any) {
throw new VCXInternalError(err);
}
}

export async function getServiceFromLedger(did: string): Promise<IAriesService> {
try {
return JSON.parse(await ffi.getServiceFromLedger(did));
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 @@ -92,6 +92,7 @@ export function issuerCredentialGetThreadId(credentialHandle: number): string
export function getLedgerAuthorAgreement(): Promise<string>
export function setActiveTxnAuthorAgreementMeta(text: string | undefined | null, version: string | undefined | null, hash: string | undefined | null, accMechType: string, timeOfAcceptance: number): void
export function createService(targetDid: string, recipientKeys: Array<string>, routingKeys: Array<string>, endpoint: string): Promise<string>
export function createServiceV2(targetDid: string, routingKeys: Array<string>, endpoint: string): Promise<string>
export function getServiceFromLedger(targetDid: string): Promise<string>
export function getVerkeyFromLedger(did: string): Promise<string>
export function getLedgerTxn(seqNo: number, submitterDid?: string | undefined | null): Promise<string>
Expand Down
3 changes: 2 additions & 1 deletion wrappers/vcx-napi-rs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,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, getServiceFromLedger, 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, proofGetProofMsg, proofRelease, proofSendRequest, proofSendRequestNonmediated, proofGetRequestMsg, proofSerialize, proofDeserialize, v2ProofUpdateState, v2ProofUpdateStateWithMessage, proofUpdateStateWithMessageNonmediated, proofGetState, proofGetProofState, 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, issuerCredentialSendCredential, issuerCredentialSendCredentialNonmediated, issuerCredentialSendOfferV2, issuerCredentialSendOfferNonmediated, issuerCredentialMarkOfferMsgSent, issuerCredentialBuildOfferMsgV2, issuerCredentialGetOfferMsg, issuerCredentialRelease, issuerCredentialGetThreadId, getLedgerAuthorAgreement, setActiveTxnAuthorAgreementMeta, createService, createServiceV2, getServiceFromLedger, 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, proofGetProofMsg, proofRelease, proofSendRequest, proofSendRequestNonmediated, proofGetRequestMsg, proofSerialize, proofDeserialize, v2ProofUpdateState, v2ProofUpdateStateWithMessage, proofUpdateStateWithMessageNonmediated, proofGetState, proofGetProofState, 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 @@ -337,6 +337,7 @@ module.exports.issuerCredentialGetThreadId = issuerCredentialGetThreadId
module.exports.getLedgerAuthorAgreement = getLedgerAuthorAgreement
module.exports.setActiveTxnAuthorAgreementMeta = setActiveTxnAuthorAgreementMeta
module.exports.createService = createService
module.exports.createServiceV2 = createServiceV2
module.exports.getServiceFromLedger = getServiceFromLedger
module.exports.getVerkeyFromLedger = getVerkeyFromLedger
module.exports.getLedgerTxn = getLedgerTxn
Expand Down
8 changes: 8 additions & 0 deletions wrappers/vcx-napi-rs/src/api/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ async fn create_service(
Ok(json!(res).to_string())
}

#[napi]
async fn create_service_v2(target_did: String, routing_keys: Vec<String>, endpoint: String) -> napi::Result<String> {
let res = ledger::ledger_write_endpoint(&target_did, routing_keys, endpoint)
.await
.map_err(to_napi_err)?;
Ok(json!(res).to_string())
}

#[napi]
async fn get_service_from_ledger(target_did: String) -> napi::Result<String> {
let res = ledger::ledger_get_service(&target_did).await.map_err(to_napi_err)?;
Expand Down

0 comments on commit 2c0ec21

Please sign in to comment.