Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
page_type languages products urlFragment
sample
java
azure
confidential-ledger-java-samples

Azure Confidential Ledger client library samples for Java

Azure Confidential Ledger samples are a set of self-contained Java programs that demonstrate interacting with Azure self-contained service using the client library. Each sample focuses on a specific scenario and can be executed independently.

Key concepts

Key concepts are explained in detail here.

Getting started

Getting started explained in detail here.

Examples

ConfidentialLedgerCertificateClientBuilder confidentialLedgerCertificateClientbuilder = new ConfidentialLedgerCertificateClientBuilder()
    .certificateEndpoint("https://identity.confidential-ledger.core.azure.com")
    .credential(new DefaultAzureCredentialBuilder().build())
    .httpClient(HttpClient.createDefault());
        
ConfidentialLedgerCertificateClient confidentialLedgerCertificateClient = confidentialLedgerCertificateClientbuilder.buildClient();

String ledgerId = "java-tests";
Response<BinaryData> ledgerCertificateWithResponse = confidentialLedgerCertificateClient
    .getLedgerIdentityWithResponse(ledgerId, null);
BinaryData certificateResponse = ledgerCertificateWithResponse.getValue();
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(certificateResponse.toBytes());
String ledgerTlsCertificate = jsonNode.get("ledgerTlsCertificate").asText();


SslContext sslContext = SslContextBuilder.forClient()
    .trustManager(new ByteArrayInputStream(ledgerTlsCertificate.getBytes(StandardCharsets.UTF_8))).build();
reactor.netty.http.client.HttpClient reactorClient = reactor.netty.http.client.HttpClient.create()
    .secure(sslContextSpec -> sslContextSpec.sslContext(sslContext));
HttpClient httpClient = new NettyAsyncHttpClientBuilder(reactorClient).wiretap(true).build();

ConfidentialLedgerClient confidentialLedgerClient =
    new ConfidentialLedgerClientBuilder()
            .credential(new DefaultAzureCredentialBuilder().build())
            .httpClient(httpClient)
            .ledgerEndpoint("https://my-ledger.confidential-ledger.azure.com")
            .buildClient();

The following sections provide code samples covering common scenario operations with the Azure Confidential Ledger client library.

All of these samples need the endpoint to your Confidential Ledger resource, and your Confidential Ledger API key.

File Name Description
ConfidentialLedgerClientSample.java Sample code to configure your client base with
CreateOrUpdateUserSample.java Add a user to a ledger or update an existing user
DeleteUserSample.java Delete a user from a ledger
ListCollectionIdsSample.java Get a list of all collection ids for a ledger
ListConsortiumMembersSample.java Get all consortium members for a ledger
GetConstitutionSample.java Get the constitution for a ledger
GetCurrentLedgerEntrySample.java Get the most recent ledger entry
GetEnclaveQuotesSample.java Get the enclave quotes for a ledger
GetLedgerEntriesSample.java List ledger entries in the confidential ledger
GetLedgerEntrySample.java Get a specific ledger entry
GetLedgerIdentitySample.java Get the identity of a ledger
GetReceiptSample.java Get a receipt from a transaction
GetTransactionStatusSample.java Get the status of a ledger entry
GetUserSample.java Get specific user data from a ledger
PostLedgerEntrySample.java Add a ledger entry. This also contains a more robust example of response handling.

Troubleshooting

Troubleshooting steps can be found here.

Next steps

See Next steps.

Contributing

If you would like to become an active contributor to this project please refer to our Contribution Guidelines for more information.