Anchoring PostgreSQL data on the blockchain with the ProvenDB SDK

Guy Harrison
ProvenDB
Published in
3 min readAug 19, 2021

The immutability of public blockchains represents a real breakthrough in trusted data management. For the first time, we can be sure that what is written cannot be overwritten — allowing us to be sure of the integrity and origin of our data.

Unfortunately, Blockchains don’t offer the performance or functionality of database systems, so they are not a good foundation for modern applications. For this reason, we created ProvenDB — a MongoDB compatible database service that uses public blockchains to ensure data integrity and proof of origin.

The ProvenDB database is the backbone of our offerings, but we also offer an SDK that allows you to anchor data wherever it may be. We’ve built a dedicated adaptor for Oracle, but if we don’t provide an adaptor for your specific data storage solution, you can use the SDK to Do It Yourself.

Proofs created by ProvenDB can be used to attest to the provenance, and integrity of the data in your database. You can use these proofs to definitively prove the origin of your data and prove that it has not been tampered with.

Let’s look at an example using PostgreSQL.

Installation

For the JavaScript SDK, we simply need to run the following command to install the SDK:

npm install provendb-sdk-node

To use the ProvenDB SDK, you will also need an API key.

To generate an API key, you will need a provendb.com account. To create an account, navigate to https://www.provendb.com/app/signup/compliance and follow the prompts to create a free account.

All calls to the Compliance Vault API require you to provide an API key in the header. To generate an API Key, log in to the provendb.com UI and navigate to the Database/Settings page in the left-hand navigation bar.

Connecting to ProvenDB

In our application code, we need to include the provendb-sdk-node and pg libraries as well as fs:

Now we connect to the ProvenDB anchor service and to the PostgreSQL database:

In this example, the anchor key that we obtained earlier is supplied via an environment variable.

Getting the data

We extract the data from the PostgreSQL database that we want to anchor using basic SQL:

Next, we create a Merkle tree from the data returned by PostgreSQL:

Key values are constructed with the primary key of each row as the key and a buffer from the concatenation of all the rows columns as the value. The “value” will be hashed as the tree is created.

Anchor the data

Now we anchor that proof to a public blockchain — in this case, HEDERA Hashgraph:

treeWithProof.json contains the Merkle tree as well as a Chainpoint formatted document showing how the tree is anchored to the blockchain. Here's an abridged version of that file:

The SDK contains methods for creating proofs for individual database rows and to validate that the data in a proof has not changed. Check out the documentation for more information about the SDK.

ProvenDB uses Blockchain technology to provide the world’s first entirely trustworthy database. Immutable versions of database state are anchored to the Blockchain, delivering an unparalleled level of data integrity. ProvenDB allows developers to build high-performance applications that include cryptographic proof of data integrity and provenance without having to understand Blockchain programming complexities. Setup a free account today at ProvenDB.com.

--

--

Guy Harrison
ProvenDB

CTO at ProvenDB.com. Author of many books on database technology. Hopeless old geek. http://guyharrison.net