By using AWS re:Post, you agree to the Terms of Use
/CommitDigest for CommitTransaction/

CommitDigest for CommitTransaction


How to compute CommitDigest for the CommitTransaction for the QLDB.sendCommand operation?
I just need to know how to compute the commit digest in Javascript.

asked 2 years ago5 views
3 Answers

I realize that we should the library "amazon-qldb-driver-nodejs".

answered 2 years ago

How to compute commit digest aws qldb with sendcommand using php

answered 2 years ago

Hi Aliq,

Sorry for the late response. We highly recommend using one of the existing drivers, if possible to build QLDB applications which handles the complexity of computing the CommitDigest. The drivers are available in Python, Nodejs, Java, .Net and Golang. PHP driver is not available at this moment.

See below answer for a similar question in StackOverflow:

The mechanism of computing CommitDigest works in the following way: For every transaction (which can contain multiple PartiQL statements) the client has to compute CommitDigest(using the algorithm noted below). At the same time, QLDB also computes CommitDigest using the same algorithm, on the server side. When you then decide to commit the transaction, you have to pass your CommitDigest to QLDB (via CommitTransaction API). If the CommitDigest you passed is same as the CommitDigest QLDB computed, then your transaction gets committed(assuming no other error), else QLDB will reject your transaction.

The CommitDigest computation relies on the ability to compute IonHash. Computing the IonHash is non-trivial and usually done by IonHash libraries. Unfortunately, there is no IonHash library for PHP. If you wish to implement one yourself, you can have a look at the IonHash specification as a starting point to compute IonHash. Once you have a way to compute the IonHash, you can implement the algorithm to compute the CommitDigest, similar to the one done by other QLDB drivers.

Marc had outlined the motivation behind CommitDigest and the algorithm, in an answer to a similar question, when QLDB did not have a driver for Node.js: How to get/compute CommitDigest when committing a transaction in AWS QLDB?.

I encourage you to read his full answer to get more context. Quoting a relevant snippet from his answer

The algorithm is also pretty straight-forward: a hash value is seeded with the transaction id and then updated with the QLDB ‘dot’ operator. Each update ‘dots’ in the statement hash (sha256 of the PartiQL string) as well as the IonHash of all of the bind values. The dot operator is the way QLDB merges hash values (this is the same operator used in the verification APIs) and is defined as the hash of the concatenation of the two hashes, ordered by the (signed, little-endian) byte-wise comparison between the two hashes. The client and server run this algorithm in lock-step and the server will only process the commit command if the value the client passes matches what the server computed. In this way, the server will never commit a transaction that isn’t exactly what the client requested.

Please note that when Marc wrote the answer, although there was no Node.js driver for QLDB, the ion-hash-js library was available, which is not the case for PHP.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions