2

I'm trying to connect and execute statements to Amazon QLDB using Node.js. In order to achieve this, I need to complete the final step which is calculating the commit digest. I have no idea how to do this.

I've thoroughly researched the QLDB Sessions javascript API here: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/QLDBSession.html but there was nothing out there about calculating the commit digest. I happened to find another question on stack overflow here: How to get/compute CommitDigest when committing a transaction in AWS QLDB?. I tried understanding the comments and messing around with the ion-hash-js library to see if I can create a commit digest, but each time I ran the code I kept getting errors. The OP did not provide any feedback on what worked/didn't work, so I'm stuck here.

const AWS = require('aws-sdk');

const qldb = new AWS.QLDB({apiVersion: '2019-01-02', region: 'us-east-1'});
var qldbSession = new AWS.QLDBSession({apiVersion: '2019-07-11', region: 'us-east-1'});


const ionHashJS = require("ion-hash-js/dist/commonjs/es5/src/IonHash");
const ionJs = require('ion-js')


async function execute(){

let sessionToken;
let transactionId;
let digest;


// ** Start Session **
await qldbSession.sendCommand({
    StartSession: {
        LedgerName: 'Vehicle-Registration'
    }
}).promise().then(data => {
    sessionToken = data.StartSession.SessionToken
})

// ** Start Transaction **
await qldbSession.sendCommand({
    StartTransaction: {},
    SessionToken: sessionToken
}).promise().then(data => {
    transactionId = data.StartTransaction.TransactionId
})

// ** Insert Document **
await qldbSession.sendCommand({
    ExecuteStatement: {
        TransactionId: transactionId,
        Statement: `CREATE TABLE Vehicle`
    },
    SessionToken: sessionToken
}).promise().then(data => {
    console.log(data)
})

// ** Get Ledger Digest **
await qldb.getDigest({
    Name: 'Vehicle-Registration'
}).promise().then(data => {
    digest = data.Digest

}).catch(err => console.log(err))




// ** Commit Transaction **
await qldbSession.sendCommand({
CommitTransaction: {
    TransactionId: transactionId,
    CommitDigest: digest // <-- How to compute?
},
SessionToken: sessionToken}).promise().then(data => {console.log(data)}).catch(err => console.log(err))

}

execute();

I keep receiving a "Digests don't match" error

Med
  • 31
  • 4
  • Possible duplicate of [How to get/compute CommitDigest when committing a transaction in AWS QLDB?](https://stackoverflow.com/questions/57937869/how-to-get-compute-commitdigest-when-committing-a-transaction-in-aws-qldb) – Alko Oct 07 '19 at 06:51
  • Nothing they said made sense to me. And the OP did not provide any further feedback on whether or not the suggestions even worked. The post seemed dead in general, so I decided to make my own post to address the problem. – Med Oct 07 '19 at 08:03
  • I noticed the source is basically copied from that question and its still not answered. I would also like to know how to do that, but opening new questions won't make any difference. Upvote the question and engage in the discusion to push it higher. – Alko Oct 07 '19 at 08:24
  • Not really copied. I'm actually just using the aws javascript sdk methods. I don't have enough reputation points to perform either or :/ – Med Oct 07 '19 at 21:02
  • 1
    Hi @Med, I don't think that question is "dead", rather there is no real update to share yet. The QLDB team is working on a Node.js driver which will solve these problems for you out of the box. While I can't share a date with you, I can tell you it is work that is in flight and you should expect to see something relatively soon. – Marc Oct 29 '19 at 20:30
  • 1
    See @Sid's answer. The Node.js driver is now available, albeit at 0.1. – Marc Nov 20 '19 at 18:20

1 Answers1

6

Thanks for your interest in Amazon QLDB.

The QLDB driver for NodeJS is now available in preview on GitHub. You can see details here https://docs.aws.amazon.com/qldb/latest/developerguide/getting-started.nodejs.html.

The driver handles calculation of the commit hash. We would recommend you to us the PooledQldbDriver implementation that provides session pooling capabilities and convenience methods for handling OCC retries in a transparent manner. Details on how the PooledQldbDriver can be added as a dependency is available in the GitHub README.md.

We shall look forward to your feedback.

Thanks, Sid

Sid Sanyal
  • 61
  • 2