Skip to content

Aries Cloud Agent Python Java Client Library

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
license-header.txt
Notifications You must be signed in to change notification settings

hyperledger-labs/acapy-java-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ACA-PY Java Client Library

License CI/CD Maven Central

Convenience library based on okhttp and gson to interact with aries cloud agent python (aca-py) instances.

Use it in your project

<dependency>
   <groupId>network.idu.acapy</groupId>
   <artifactId>aries-client-python</artifactId>
   <version>0.10.0</version>
</dependency>

FAQ

  1. Why don't you use swagger codegen?

    For a long time aca-py's swagger.json was not really in sync with the code base. This has been hugely improved lately, so I started to generate model classes based on the stable releases found on dockerhub. There are still issues with complex structures, so one can not simply use the models 1:1, instead each one has to be checked manually before using it. This is tedious work and might take a while to complete. Also, the api is complex so that I found it useful to introduce helper methods directly in the model classes to make them more accessible.

  2. Why is endpoint X, or field Y missing?

    aca-py's api is changing rapidly with each release, and until most of the classes are using the generated models this can happen. So, if you are missing something create a PR with a fix or open an issue.

Version Compatibility

Client Version ACA-PY Version
0.10.0 0.10.x
0.8.0 0.8.0
0.7.0 0.7.0
0.7.6 0.7.1, 0.7.2
>= 0.7.18 0.7.3
>= 0.7.25 0.7.4
>= 0.7.32 0.7.5

Implemented Endpoints

Method Endpoint Implemented
action-menu
POST /action-menu/{conn_id}/close βœ…
POST /action-menu/{conn_id}/fetch βœ…
POST /action-menu/{conn_id}/perform βœ…
POST /action-menu/{conn_id}/request βœ…
POST /action-menu/{conn_id}/send-menu βœ…
basicmessage
POST /connections/{conn_id}/send-message βœ…
connection
GET /connections βœ…
POST /connections/create-invitation βœ…
POST /connections/create-static βœ…
POST /connections/receive-invitation βœ…
GET /connections/{conn_id}} βœ…
DELETE /connections/{conn_id} βœ…
POST /connections/{conn_id}/accept-invitation βœ…
POST /connections/{conn_id}/accept-request βœ…
GET /connections/{conn_id}/endpoints βœ…
POST /connections/{conn_id}/establish-inbound/{ref_id} βœ…
GET /connections/{conn_id}/metadata βœ…
POST /connections/{conn_id}/metadata βœ…
credential-definition
POST /credential-definitions βœ…
GET /credential-definitions/created βœ…
GET /credential-definitions/{cred_def_id} βœ…
POST /credential-definitions/{cred_def_id}/write_record βœ…
credentials
GET /credentials/mime-types/{credential_id} βœ…
GET /credentials/revoked/{credential_id} βœ…
GET /credential/w3c/{credential_id} βœ…
DELETE /credential/w3c/{credential_id} βœ…
GET /credential/{credential_id} βœ…
DELETE /credential/{credential_id} βœ…
GET /credentials βœ…
POST /credentials/w3c βœ…
did-exchange
POST /didexchange/create-request βœ…
POST /didexchange/receive-request βœ…
POST /didexchange/{conn_id}/accept-invitation βœ…
POST /didexchange/{conn_id}/accept-request βœ…
POST /didexchange/{conn_id}/reject βœ…
discover-features
GET /discover-features/query βœ…
GET /discover-features/records βœ…
discover-features v2.0
GET /discover-features-2.0/queries βœ…
GET /discover-features-2.0/records βœ…
endorse-transaction
POST /transaction/{tran_id}/resend βœ…
POST /transactions βœ…
POST /transactions/create-request βœ…
POST /transactions/{conn_id}/set-endorser-info βœ…
POST /transactions/{conn_id}/set-endorser-role βœ…
POST /transactions/{tran_id} βœ…
POST /transactions/{tran_id}/cancel βœ…
POST /transactions/{tran_id}/endorse βœ…
POST /transactions/{tran_id}/refuse βœ…
POST /transactions/{tran_id}/write βœ…
introduction
POST /connections/{conn_id}/start-introduction βœ…
issue-credential v1.0
POST /issue-credential/create βœ…
POST /issue-credential/create-offer βœ…
GET /issue-credential/records βœ…
GET /issue-credential/records/{cred_ex_id} βœ…
DELETE /issue-credential/records/{cred_ex_id} βœ…
POST /issue-credential/records/{cred_ex_id}/issue βœ…
POST /issue-credential/records/{cred_ex_id}/problem-report βœ…
POST /issue-credential/records/{cred_ex_id}/send-offer βœ…
POST /issue-credential/records/{cred_ex_id}/send-request βœ…
POST /issue-credential/records/{cred_ex_id}/store βœ…
POST /issue-credential/send βœ…
POST /issue-credential/send-offer βœ…
POST /issue-credential/send-proposal βœ…
issue-credential v2.0
POST /issue-credential-2.0/create βœ…
POST /issue-credential-2.0/create-offer βœ…
GET /issue-credential-2.0/records βœ…
GET /issue-credential-2.0/records/{cred_ex_id} βœ…
DELETE /issue-credential-2.0/records/{cred_ex_id} βœ…
POST /issue-credential-2.0/records/{cred_ex_id}/issue βœ…
POST /issue-credential-2.0/records/{cred_ex_id}/problem-report βœ…
POST /issue-credential-2.0/records/{cred_ex_id}/send-offer βœ…
POST /issue-credential-2.0/records/{cred_ex_id}/send-request βœ…
POST /issue-credential-2.0/records/{cred_ex_id}/store βœ…
POST /issue-credential-2.0/send βœ…
POST /issue-credential-2.0/send-offer βœ…
POST /issue-credential-2.0/send-proposal βœ…
POST /issue-credential-2.0/send-request βœ…
jsonld
POST /jsonld/sign βœ…
POST /jsonld/verify βœ…
ledger
GET /ledger/config βœ…
GET /ledger/did-endpoint βœ…
GET /ledger/did-verkey βœ…
GET /ledger/get-nym-role βœ…
GET /ledger/get-write-ledger βœ…
GET /ledger/get-write-ledgers βœ…
POST /ledger/register-nym βœ…
PATCH /ledger/rotate-public-did-keypair βœ…
GET /ledger/taa βœ…
POST /ledger/taa/accept βœ…
POST /ledger/{ledger_id}/set-write-ledger βœ…
mediation
GET /mediation/default-mediator βœ…
DELETE /mediation/default-mediator βœ…
GET /mediation/keylists βœ…
POST /mediation/keylists/{mediation_id}/send-keylist-query βœ…
POST /mediation/keylists/{mediation_id}/send-keylist-update βœ…
POST /mediation/request/{conn_id} βœ…
GET /mediation/requests βœ…
GET /mediation/requests/{mediation_id} βœ…
DELETE /mediation/requests/{mediation_id} βœ…
POST /mediation/requests/{mediation_id}/deny βœ…
POST /mediation/requests/{mediation_id}/grant βœ…
POST /mediation/update-keylist/{conn_id} βœ…
PUT /mediation/{mediation_id}/default-mediator βœ…
multitenancy
POST /multitenancy/wallet βœ…
GET /multitenancy/wallet/{wallet_id} βœ…
PUT /multitenancy/wallet/{wallet_id} βœ…
POST /multitenancy/wallet/{wallet_id}/remove βœ…
POST /multitenancy/wallet/{wallet_id}/token βœ…
GET /multitenancy/wallets βœ…
out-of-band
POST /out-of-band/create-invitation βœ…
POST /out-of-band/receive-invitation βœ…
present-proof v1.0
POST /present-proof/create-request βœ…
GET /present-proof/records βœ…
GET /present-proof/records/{pres_ex_id} βœ…
DELETE /present-proof/records/{pres_ex_id} βœ…
GET /present-proof/records/{pres_ex_id}/credentials βœ…
POST /present-proof/records/{pres_ex_id}/problem-report βœ…
POST /present-proof/records/{pres_ex_id}/send-presentation βœ…
POST /present-proof/records/{pres_ex_id}/send-request βœ…
POST /present-proof/records/{pres_ex_id}/verify-presentation βœ…
POST /present-proof/send-proposal βœ…
POST /present-proof/send-request βœ…
present-proof v2.0
POST /present-proof-2.0/create-request βœ…
GET /present-proof-2.0/records βœ…
GET /present-proof-2.0/records/{pres_ex_id} βœ…
DELETE /present-proof-2.0/records/{pres_ex_id} βœ…
GET /present-proof-2.0/records/{pres_ex_id}/credentials βœ…
POST /present-proof-2.0/records/{pres_ex_id}/problem-report βœ…
POST /present-proof-2.0/records/{pres_ex_id}/send-presentation βœ…
POST /present-proof-2.0/records/{pres_ex_id}/send-request βœ…
POST /present-proof-2.0/records/{pres_ex_id}/verify-presentation βœ…
POST /present-proof-2.0/send-proposal βœ…
POST /present-proof-2.0/send-request βœ…
resolver
GET /resolver/resolve/{did} βœ…
revocation
GET /revocation/active-registry/{cred_def_id} βœ…
POST /revocation/active-registry/{cred_def_id}/rotate βœ…
POST /revocation/clear-pending-revocations βœ…
POST /revocation/create-registry βœ…
GET /revocation/credential-record βœ…
POST /revocation/publish-revocations βœ…
GET /revocation/registries/created βœ…
DELETE /revocation/registry/delete-tails-file βœ…
GET /revocation/registry/{rev_reg_id} βœ…
PATCH /revocation/registry/{rev_reg_id} βœ…
POST /revocation/registry/{rev_reg_id}/definition βœ…
POST /revocation/registry/{rev_reg_id}/entry βœ…
PUT /revocation/registry/{rev_reg_id}/fix-revocation-entry-state βœ…
GET /revocation/registry/{rev_reg_id}/issued βœ…
GET /revocation/registry/{rev_reg_id}/issued/details βœ…
GET /revocation/registry/{rev_reg_id}/issued/indy_recs βœ…
PATCH /revocation/registry/{rev_reg_id}/set-state βœ…
PUT /revocation/registry/{rev_reg_id}/tails-file βœ…
GET /revocation/registry/{rev_reg_id}/tails-file βœ…
POST /revocation/revoke βœ…
schema
POST /schemas βœ…
GET /schemas/created βœ…
GET /schemas/{schema_id} βœ…
POST /schemas/{schema_id}/write_record βœ…
settings
PUT /settings βœ…
GET /settings βœ…
trustping
POST /connections/{conn_id}/send-ping βœ…
wallet
GET /wallet/did βœ…
POST /wallet/did/create βœ…
PATCH /wallet/did/local/rotate-keypair βœ…
GET /wallet/did/public βœ…
POST /wallet/did/public βœ…
GET /wallet/get-did-endpoint βœ…
POST /wallet/jwt/sign βœ…
POST /wallet/jwt/verify βœ…
POST /wallet/set-did-endpoint βœ…
server
GET /plugins βœ…
GET /shutdown βœ…
GET /status βœ…
GET /status/config βœ…
GET /status/live βœ…
GET /status/ready βœ…
POST /status/reset βœ…

Client Examples

Sending Requests: Create the aca-py Rest Client

The rest client is used to send requests against aca-py's admin rest endpoint.

Related aca-py config flags are: --admin <host> <port>, --admin-api-key <api-key>

The default assumes you are running against a single wallet. In case of multi tenancy with base and sub wallets the bearerToken needs to be set as well.

Example aca-py config flags:

--admin 0.0.0.0 8031
--admin-api-key secret

Example client builder:

AriesClient ac = AriesClient
        .builder()
        .url("http://localhost:8031") // optional - defaults to localhost:8031
        .apiKey("secret") // optional - admin api key if set
        .bearerToken("123.456.789") // optional - jwt token - only when running in multi tenant mode
        .build();

Receiving Events: Webhook and Websocket Handler Support

With aca-py you have three options on how to receive status changes:

  1. Poll the rest API - this is not recommended
  2. Register a webhook URL
  3. Connect to aca-py's websocket

Webhook

Related aca-py config flag: --webhook-url <url#api_key>

Single Tenant Controller Example

If running a single wallet and not in multi tenant mode.

Example aca-py config flag: --webhook-url http://localhost:8080/webhook

@Controller
public class WebhookController {

   private EventHandler handler = new EventHandler.DefaultEventHandler();

   @Post("/webhook/topic/{topic}")
   public void handleWebhookEvent(
           @PathVariable String topic,
           @Body String payload) {
      handler.handleEvent(topic, payload);
   }
}
Multi Tenant Example

If running in multi tenant mode.

Example aca-py config flags:

--webhook-url http://localhost:8080/webhook
--multitenant
--jwt-secret 1234
--multitenant-admin

Example multi tenant webhook controller

@Controller
public class WebhookController {

   private EventHandler handler = new TenantAwareEventHandler.DefaultTenantAwareEventHandler();

   @Post("/webhook/topic/{topic}")
   public void handleWebhookEvent(
           @PathVariable String topic,
           @Body String payload,
           HttpRequest request) {
      String walletId = request.getHeaders().get("x-wallet-id");
      handler.handleEvent(walletId, topic, payload);
   }
}

Websocket

If the admin api is enabled aca-py also supports a websocket endpoint under ws(s)://<host>:<admin-port>/ws

Example aca-py config flag: --admin 0.0.0.0 8031

To connect with the websocket you can use the AriesWebSocketClient like:

@Factory
public class AriesSocketFactory {

   @Value("${acapy.ws.url}")
   private String url;
   @Value("${acapy.admin.apiKey}")
   private String apiKey;
   
   @Singleton
   @Bean(preDestroy = "closeWebsocket")
   public AriesWebSocketClient ariesWebSocketClient() {
      return AriesWebSocketClient
              .builder()
              .url(url) // optional - defaults to ws://localhost:8031/ws
              .apiKey(apiKey) // optional - admin api key if set
              .handler(new EventHandler.DefaultEventHandler()) // optional - your handler implementation
              // .bearerToken(bearer) // optional - jwt token - only when running in multi tenant mode
              .build();
   }
}

Writing Custom Event Handlers

To add your own event handler implementation to use in webhooks or in the websocket client, you can either extend or instantiate one of the following classes:

  1. EventHandler
  2. TenantAwareEventHandler
  3. ReactiveEventHandler

All classes take care of type conversion so that you can immediately start implementing your business logic.

Basic EventHandler

@Singleton
public class MyHandler extends EventHandler {
    @Override
    public void handleProof(PresentationExchangeRecord proof) {
        if (proof.roleIsVerifierAndVerified()) {    // received a validated proof
            MyCredential myCredential = proof.from(MyCredential.class);
            // If the presentation is based on multiple credentials this can be done multiple times
            // given that the POJO is annotated with @AttributeGroup e.g.
            MyOtherCredential otherCredential = proof.from(MyOtherCredential.class);
        }
    }
}

Reactive Event Handler

As the websocket client already implements the EventHandler interface you can directly use it like:

AriesWebSocketClient ws = AriesWebSocketClient.builder().build();

// do some stuff, create a connection, or receive invitation

// blocking wait 
ConnectionRecord active = ws.connection()
    .filter(ConnectionRecord::stateIsActive)
    .blockFirst(Duration.ofSeconds(5));
// none blocking
ws.connection()
    .filter(ConnectionRecord::stateIsActive)
    .subscribe(System.out::println);

A Word on Credential POJO's

The library assumes credentials are flat Pojo's like:

@Data @NoArgsConstructor @Builder
@AttributeGroupName("referent") // the referent that should be matched in the proof request
public final class MyCredential {
   private String street;

   @AttributeName("e-mail")
   private String email;       // schema attribute name is e-mail

   @AttributeName(excluded = true)
   private String comment;     // internal field
}

How fields are serialised/deserialized can be changed by using the @AttributeName or @AttributeGroupName annotations.

Create a connection

ac.connectionsReceiveInvitation(
        ReceiveInvitationRequest.builder()
            .did(did)
            .label(label)
            .build(), 
        ConnectionReceiveInvitationFilter
            .builder()
            .alias("alias")
            .build())    
.ifPresent(connection -> {
    log.debug("{}", connection.getConnectionId());
});

Issue a Credential

MyCredential myCredential = MyCredential
        .builder()
        .email("test@myexample.com")
        .build();
ac.issueCredentialSend(
        new V1CredentialProposalRequest(connectionId, credentialdefinitionId, myCredential));

Present Proof Request

PresentProofRequest proofRequest = PresentProofRequestHelper.buildForEachAttribute(
    connectionId,
    MyCredential.class,
    ProofRestrictions.builder()
        .credentialDefinitionId(credentialDefinitionId)
        .build());
ac.presentProofSendRequest(proofRequest);

Build Connectionless Proof Request

Connectionless proofs are more a thing of mobile wallets, because mostly they involve something that is presented to a human like a barcode, but the java client supports this by providing models and builders.

A flow has the usually following steps:

  1. The user is presented with a QRCode that contains an invitation URL like: https://myhost.com/url/1234
  2. The server side HTTP handler of this URL responds with an HTTP.FOUND response that has the proof request encoded in the m parameter
  3. The mobile wallet tries to match a stored credential, and then responds with a proof presentation if possible
  4. The server side WebhookHandler waits for the proof and then triggers further actions
@Get("/url/{requestId}")
public HttpResponse<Object> connectionLessProof(@QueryValue String requestId) {
    boolean matchingRequest = false; // TODO manage request states
    String proofRequestBase64 = ""; // TODO on how to build this see the example below
    if (matchingRequest) {
        return HttpResponse
                .status(HttpStatus.FOUND)
                .header("location", deploymentUri + "?m=" + proofRequestBase64;
    }
    return HttpResponse.notFound();
}

Proof Request Builder Example

ProofRequestPresentationBuilder builder = new ProofRequestPresentationBuilder(ariesClient);

PresentProofRequest presentProofRequest = PresentProofRequestHelper.buildForEachAttribute(
        connectionId,
        List.of("name", "email"),
        ProofRestrictions
            .builder()
            .schemaId("WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0")
            .build());

Optional<String> base64 = builder.buildRequest(presentProofRequest);

About

Aries Cloud Agent Python Java Client Library

Topics

Resources

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
license-header.txt

Stars

Watchers

Forks

Packages

No packages published