Skip to content

Commit

Permalink
Add tails methods to java and ios wrappers (#264)
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com>
  • Loading branch information
mirgee authored Apr 15, 2021
1 parent fe4bab4 commit 3117815
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 6 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ jobs:
bash -c '(cd $HOME/libvcx && \
DISALLOW_V1=true RUST_TEST_THREADS=1 TEST_POOL_IP=127.0.0.1 cargo test --release --features "pool_tests agency_v2")'
test-libvcx-image-agency_pool_tests:
runs-on: ubuntu-latest
needs: [workflow-setup, build-image-indypool, build-image-libvcx]
Expand Down
7 changes: 3 additions & 4 deletions agents/node/vcxagent-core/src/utils/proofs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ module.exports.holderSelectCredentialsForProof = async function holderSelectCred
const selectedCreds = { attrs: {} }
logger.debug(`Resolved credentials for proof = ${JSON.stringify(resolvedCreds, null, 2)}`)

let unresolvedRequirements = []
for (const attrName of Object.keys(resolvedCreds.attrs)) {
const attrCredInfo = resolvedCreds.attrs[attrName]
const unresolvedRequirements = []
for (const [attrName, attrCredInfo] of Object.entries(resolvedCreds.attrs)) {
if (Array.isArray(attrCredInfo) === false) {
throw Error('Unexpected data, expected attrCredInfo to be an array.')
}
Expand All @@ -34,7 +33,7 @@ module.exports.holderSelectCredentialsForProof = async function holderSelectCred
if (selectedCreds) {
logger.debug(`Selected credentials:\n${JSON.stringify(selectedCreds, null, 2)}`)
}
return {selectedCreds, unresolvedRequirements}
return { selectedCreds, unresolvedRequirements }
}

module.exports.extractProofRequestAttachement = function extractProofRequestAttachement (proofRequest) {
Expand Down
2 changes: 1 addition & 1 deletion agents/node/vcxagent-core/test/utils/alice.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports.createAlice = async function createAlice () {

async function sendHolderProof (proofRequest, _mapRevRegId) {
await vcxAgent.agentInitVcx()
const mapRevRegId = _mapRevRegId || ((_revRegId) => { throw Error('Tails file should not be need') })
const mapRevRegId = _mapRevRegId || ((_revRegId) => { throw Error('Tails file should not be needed') })
await vcxAgent.serviceProver.buildDisclosedProof(disclosedProofId, proofRequest)
const { selectedCreds } = await vcxAgent.serviceProver.selectCredentials(disclosedProofId, mapRevRegId)
const selfAttestedAttrs = { attribute_3: 'Smith' }
Expand Down
9 changes: 9 additions & 0 deletions wrappers/ios/vcx/ConnectMeVcx.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ extern void VcxWrapperCommonNumberStringCallback(vcx_command_handle_t xcommand_h
- (void)credentialGetAttachment:(VcxHandle)credentialHandle
completion:(void (^)(NSError *error, NSString *attach))completion;

- (void)credentialGetTailsLocation:(VcxHandle)credentialHandle
completion:(void (^)(NSError *error, NSString *tailsLocation))completion;

- (void)credentialGetTailsHash:(VcxHandle)credentialHandle
completion:(void (^)(NSError *error, NSString *tailsHash))completion;

- (void)credentialGetRevRegId:(VcxHandle)credentialHandle
completion:(void (^)(NSError *error, NSString *revRegId))completion;

- (void)credentialSerialize:(NSInteger)credentialHandle
completion:(void (^)(NSError *error, NSString *state))completion;

Expand Down
51 changes: 51 additions & 0 deletions wrappers/ios/vcx/ConnectMeVcx.m
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,57 @@ - (void)credentialGetAttachment:(VcxHandle)credentialHandle
}
}

- (void)credentialGetTailsLocation:(VcxHandle)credentialHandle
completion:(void (^)(NSError *error, NSString *tailsLocation))completion{
vcx_error_t ret;
vcx_command_handle_t handle = [[VcxCallbacks sharedInstance] createCommandHandleFor:completion];

ret = vcx_credential_get_tails_location(handle, credentialHandle, VcxWrapperCommonStringCallback);

if( ret != 0 )
{
[[VcxCallbacks sharedInstance] deleteCommandHandleFor: handle];

dispatch_async(dispatch_get_main_queue(), ^{
completion([NSError errorFromVcxError: ret],nil);
});
}
}

- (void)credentialGetTailsHash:(VcxHandle)credentialHandle
completion:(void (^)(NSError *error, NSString *tailsHash))completion{
vcx_error_t ret;
vcx_command_handle_t handle = [[VcxCallbacks sharedInstance] createCommandHandleFor:completion];

ret = vcx_credential_get_tails_hash(handle, credentialHandle, VcxWrapperCommonStringCallback);

if( ret != 0 )
{
[[VcxCallbacks sharedInstance] deleteCommandHandleFor: handle];

dispatch_async(dispatch_get_main_queue(), ^{
completion([NSError errorFromVcxError: ret],nil);
});
}
}

- (void)credentialGetRevRegId:(VcxHandle)credentialHandle
completion:(void (^)(NSError *error, NSString *revRegId))completion{
vcx_error_t ret;
vcx_command_handle_t handle = [[VcxCallbacks sharedInstance] createCommandHandleFor:completion];

ret = vcx_credential_get_rev_reg_id(handle, credentialHandle, VcxWrapperCommonStringCallback);

if( ret != 0 )
{
[[VcxCallbacks sharedInstance] deleteCommandHandleFor: handle];

dispatch_async(dispatch_get_main_queue(), ^{
completion([NSError errorFromVcxError: ret],nil);
});
}
}

- (void)generateProof:(NSString *)proofRequestId
requestedAttrs:(NSString *)requestedAttrs
requestedPredicates:(NSString *)requestedPredicates
Expand Down
6 changes: 6 additions & 0 deletions wrappers/ios/vcx/include/libvcx.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ vcx_error_t vcx_credential_get_attributes(vcx_command_handle_t handle, vcx_crede

vcx_error_t vcx_credential_get_attachment(vcx_command_handle_t handle, vcx_credential_handle_t credential_handle, void (*cb)(vcx_command_handle_t command_handle, vcx_error_t err, const char *attachment));

vcx_error_t vcx_credential_get_tails_location(vcx_command_handle_t handle, vcx_credential_handle_t credential_handle, void (*cb)(vcx_command_handle_t command_handle, vcx_error_t err, const char *tailsLocation));

vcx_error_t vcx_credential_get_tails_hash(vcx_command_handle_t handle, vcx_credential_handle_t credential_handle, void (*cb)(vcx_command_handle_t command_handle, vcx_error_t err, const char *tailsHash));

vcx_error_t vcx_credential_get_rev_reg_id(vcx_command_handle_t handle, vcx_credential_handle_t credential_handle, void (*cb)(vcx_command_handle_t command_handle, vcx_error_t err, const char *revRegId));

/** Updates the state of the credential from the agency. */
vcx_error_t vcx_credential_update_state(vcx_command_handle_t command_handle, vcx_credential_handle_t credential_handle, void (*cb)(vcx_command_handle_t xcommand_handle, vcx_error_t err, vcx_state_t state));

Expand Down
6 changes: 6 additions & 0 deletions wrappers/java/src/main/java/com/evernym/sdk/vcx/LibVcx.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,12 @@ public interface API extends Library {

public int vcx_credential_get_attachment(int command_handle, int credential_handle, Callback cb);

public int vcx_credential_get_tails_location(int command_handle, int credential_handle, Callback cb);

public int vcx_credential_get_tails_hash(int command_handle, int credential_handle, Callback cb);

public int vcx_credential_get_rev_reg_id(int command_handle, int credential_handle, Callback cb);

/** Populates status with the current State of this credential. */
public int vcx_credential_serialize(int command_handle, int credential_handle, Callback cb);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,78 @@ public static CompletableFuture<String> credentialGetAttachment(
return future;
}

private static Callback credentialGetTailsLocationCB = new Callback() {
@SuppressWarnings({"unused", "unchecked"})
public void callback(int command_handle, int err, String tailsLocation) {
logger.debug("credentialGetTailsLocationCB() called with: command_handle = [" + command_handle + "], err = [" + err + "], tailsLocation = [" + tailsLocation + "]");
CompletableFuture<String> future = (CompletableFuture<String>) removeFuture(command_handle);
if (!checkCallback(future, err)) return;
future.complete(tailsLocation);
}
};

public static CompletableFuture<String> credentialGetTailsLocation(
int credentialHandle
) throws VcxException {
ParamGuard.notNull(credentialHandle, "credentialHandle");
logger.debug("credentialGetTailsLocation() called with: credentialHandle = [" + credentialHandle + "]");
CompletableFuture<String> future = new CompletableFuture<String>();
int commandHandle = addFuture(future);

int result = LibVcx.api.vcx_credential_get_tails_location(commandHandle, credentialHandle, credentialGetTailsLocationCB);
checkResult(result);

return future;
}

private static Callback credentialGetTailsHashCB = new Callback() {
@SuppressWarnings({"unused", "unchecked"})
public void callback(int command_handle, int err, String tailsHash) {
logger.debug("credentialGetTailsHashCB() called with: command_handle = [" + command_handle + "], err = [" + err + "], tailsHash = [" + tailsHash + "]");
CompletableFuture<String> future = (CompletableFuture<String>) removeFuture(command_handle);
if (!checkCallback(future, err)) return;
future.complete(tailsHash);
}
};

public static CompletableFuture<String> credentialGetTailsHash(
int credentialHandle
) throws VcxException {
ParamGuard.notNull(credentialHandle, "credentialHandle");
logger.debug("credentialGetTailsHash() called with: credentialHandle = [" + credentialHandle + "]");
CompletableFuture<String> future = new CompletableFuture<String>();
int commandHandle = addFuture(future);

int result = LibVcx.api.vcx_credential_get_tails_hash(commandHandle, credentialHandle, credentialGetTailsHashCB);
checkResult(result);

return future;
}

private static Callback credentialGetRevRegIdCB = new Callback() {
@SuppressWarnings({"unused", "unchecked"})
public void callback(int command_handle, int err, String revRegId) {
logger.debug("credentialGetRevRegIdCB() called with: command_handle = [" + command_handle + "], err = [" + err + "], revRegId = [" + revRegId + "]");
CompletableFuture<String> future = (CompletableFuture<String>) removeFuture(command_handle);
if (!checkCallback(future, err)) return;
future.complete(revRegId);
}
};

public static CompletableFuture<String> credentialGetRevRegId(
int credentialHandle
) throws VcxException {
ParamGuard.notNull(credentialHandle, "credentialHandle");
logger.debug("credentialGetRevRegId() called with: credentialHandle = [" + credentialHandle + "]");
CompletableFuture<String> future = new CompletableFuture<String>();
int commandHandle = addFuture(future);

int result = LibVcx.api.vcx_credential_get_rev_reg_id(commandHandle, credentialHandle, credentialGetRevRegIdCB);
checkResult(result);

return future;
}

public static int credentialRelease(int credentialHandle) throws VcxException {
ParamGuard.notNull(credentialHandle, "credentialHandle");
logger.debug("credentialRelease() called with: credentialHandle = [" + credentialHandle + "]");
Expand Down

0 comments on commit 3117815

Please sign in to comment.