diff --git a/libvcx/src/api_vcx/api_global/ledger.rs b/libvcx/src/api_vcx/api_global/ledger.rs index 97baae3c56..c7e41b7c9e 100644 --- a/libvcx/src/api_vcx/api_global/ledger.rs +++ b/libvcx/src/api_vcx/api_global/ledger.rs @@ -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; @@ -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, + endpoint: String, +) -> LibvcxResult { + 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 { let target_did = Did::new(target_did)?; let profile = get_main_profile()?; diff --git a/wrappers/node/src/api/utils.ts b/wrappers/node/src/api/utils.ts index 4869f6866d..a02a070fe9 100644 --- a/wrappers/node/src/api/utils.ts +++ b/wrappers/node/src/api/utils.ts @@ -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 { try { return await ffi.provisionCloudAgent(JSON.stringify(configAgent)); @@ -165,6 +171,18 @@ export async function createService( } } +export async function createServiceV2( + target_did: string, + endpoint: string, + routingKeys: string[], +): Promise { + 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 { try { return JSON.parse(await ffi.getServiceFromLedger(did)); diff --git a/wrappers/vcx-napi-rs/index.d.ts b/wrappers/vcx-napi-rs/index.d.ts index 9bbb18519c..499e11b5f6 100644 --- a/wrappers/vcx-napi-rs/index.d.ts +++ b/wrappers/vcx-napi-rs/index.d.ts @@ -92,6 +92,7 @@ export function issuerCredentialGetThreadId(credentialHandle: number): string export function getLedgerAuthorAgreement(): Promise 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, routingKeys: Array, endpoint: string): Promise +export function createServiceV2(targetDid: string, routingKeys: Array, endpoint: string): Promise export function getServiceFromLedger(targetDid: string): Promise export function getVerkeyFromLedger(did: string): Promise export function getLedgerTxn(seqNo: number, submitterDid?: string | undefined | null): Promise diff --git a/wrappers/vcx-napi-rs/index.js b/wrappers/vcx-napi-rs/index.js index 4422c17542..db1bf78bac 100644 --- a/wrappers/vcx-napi-rs/index.js +++ b/wrappers/vcx-napi-rs/index.js @@ -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 @@ -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 diff --git a/wrappers/vcx-napi-rs/src/api/ledger.rs b/wrappers/vcx-napi-rs/src/api/ledger.rs index 5f2b4c29d7..bd28ecb9eb 100644 --- a/wrappers/vcx-napi-rs/src/api/ledger.rs +++ b/wrappers/vcx-napi-rs/src/api/ledger.rs @@ -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, endpoint: String) -> napi::Result { + 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 { let res = ledger::ledger_get_service(&target_did).await.map_err(to_napi_err)?;