Anchoring relational data to the blockchain with Proofable

Guy Harrison
ProvenDB
Published in
5 min readSep 16, 2020

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.

But what if you already have a non-MongoDB database system and want to add blockchain-based integrity to it? This is one of the scenarios where Proofable comes to the rescue. Proofable allows you to anchor any digital data — where ever it might be stored — to your choice of blockchain. Proofable will enable you to prove millions of digital assets in a single transaction, removing the cost and performance barriers inherent in native blockchain APIs.

Proofable creates a chain of trust between your application data and a blockchain of your choice

In this article, I’ll use Proofable to anchor data held in a PostgresSQL database. While this example is PostgresSQL-specific, the general approach can be used for any relational, or for that matter NoSQL, database.

Using Proofable — just running on my laptop — I managed to anchor one million contract documents to the Hedera blockchain in just under 100 seconds.

Requirement

In this example, we have a database that is used to store digital contracts. The contracts table has this simple definition:

As you can see, the table has an auto-incrementing primary key, a JSON document containing meta-data, and a binary column for the digital document.

For our imaginary Contract management application, it’s essential that we be able to prove that the contracts stored in the database have not been tampered with or corrupted and that the creation date of the contracts can be verified. Proofable is a perfect way for us to do this.

Implementation

Proofable can be called from a variety of APIs and SDKs, including REST, gRPC and with SDKs for Go and NodeJS. In this example, I’m going to use the NodeJS API.

First I need to set up a free Proofable account at http://proofable.io. The easiest way to get started is to download the CLI and authenticate using OAuth:

Once we’ve authenticated, we can install the proofable-SDK using npm:

npm i proofable

In our NodeJS code, we establish a connection to proofable (and to PostgreSQL as well) with the following code:

Now that we have connected to both PostgreSQL and Proofable, we can start anchoring data in PostgresSQL to our blockchains. I created a control table inside PostgresSQL to keep track of the data anchoring. It has this simple structure:

This table will store the “trie” structures — which are data structures that tie the PostgreSQL data to the blockchain entry. You can read more about tries here. In short, the trie is the link between potentially millions of rows of data in your database and a single entry anchored to a blockchain. You can prove all or any of the rows against the blockchain proof using this structure.

The mainline for our solution looks like this:

On line 2, we pull data out of the table that has not already been anchored. The control table contains the maximum key value from the previous proof, so we r the primary keys with a higher value. The data is returned as key-value pairs with the value being a hash of the entire row of data.

On line 6, we create a trie and anchor it to our choice of blockchain. Here we've used Hedera HashGraph because it's very fast and economical. You could also have chosen Ethereum, Bitcoin, Elastos or GoChain (and more to come!).

On line 7, we store that trie back into the control table.

If we want to confirm that the data integrity is intact, we can call a validate routine:

On lines 1–2 we simply extract the last trie from the proofableAnchors control table. Then we validate that trie on line 3. The validate routine compares the hashes in the trie with the hashes from the live database and checks that the blockchain anchor hash is valid. If all goes well, we get a valid result:

If some tampering occurred, the verify routine would identify the primary key value for the tampered record (line 22):

In this example — which you can get here: — I’ve amalgamated several low-level proofable calls for simplicities sake. For instance, the anchorData function above is implemented using several lower-level Proofable calls:

Check out this example and the node SDK documentation if you want to understand these lower-level calls.

This is a relatively simple example. In a future post, I’ll show how to generate trust certificates for individual data elements and how to create a hook into Postgres Change Data Capture so that there’s no need to manually track new data. But even from this simple example, we’ve been able to add a chain of trust between our PostgresSQL data and the immutable and trustworthy Blockchain transactions.

Proofable has massive advantages over a DIY blockchain anchoring solution. In particular:

  • Proofable can anchor massive amounts of data very rapidly. This example program — just running on my laptop — managed to anchor one million contracts to the Hedera blockchain in just under 100 seconds.
  • With Proofable, you don’t’ have to worry about setting up a crypto wallet or buying cryptocurrency. The free Proofable service handles all that for you. You can anchor millions of digital assets to multiple public BlockChain using the free Proofable service.
  • Proofable gives you easy access to multiple blockchains — Bitcoin, Hedera, Ethereum, GoChain, and more to come!

Proofable is a framework for certifying digital assets to public Blockchains. Using proofable, you can anchor thousands of digital assets quickly and economically in a single transaction. Proofable certificates can be used to detect tampering or to prove the integrity and origin of any digital asset — legal documents, financial instruments, intellectual property and more. Get a free account today at proofable.io.

--

--

Guy Harrison
ProvenDB

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