I realize that we should the library "amazon-qldb-driver-nodejs".
How to compute commit digest aws qldb with sendcommand using php
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: https://stackoverflow.com/questions/63773966.
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 https://amzn.github.io/ion-hash/docs/spec.html 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.
HOW TO set up the required IAM permissions for WorkMail??asked 6 months ago
How do I see commit history for a specific file in codecommit?asked 6 days ago
How does Slurm sync files between compute and master nodes?Accepted Answerasked 2 years ago
Control Lambda Compute for large trafficAccepted Answerasked 4 months ago
How do I create a role for AWS Batch using the CLIasked 2 months ago
How to create feed document XML to change the price of a ASIN for a seller?asked 2 days ago
AWS ParallelCluster - changing compute node config after cluster creationasked 2 months ago
How to enroll for MSK Serverlessasked 7 months ago
CommitDigest for CommitTransactionasked 2 years ago
Compute optimizer take so longAccepted Answerasked a month ago