Blockchain + Digital Signature

A distributed register to store static records and/or dynamic transaction data without central coordination by using a consensus-based mechanism to check the validity of transactions. A blockchain is a distributed database that maintains a continuously growing list of data records that cannot be tampered.
Blockchain is a public ledger of all transaction made with Bitcoin. Blockchain’s intent is to replace an external, trusted third party certificate authorities, and also prevent anyone from being able to go backward and cover their tracks if they corrupted an entry.

The technology works on the following properties:

1) Log replication – To create resiliency, log-based replication is increasingly used for distributed systems to replicate logs to all peers in the network.

2) Provable Value Chain – The values stored in the blockchain can be digital currency (such as the widely known Bitcoin), data, documents, and other assets. Hash chains are kept for each block providing a history of changes, which helps protect data integrity of the block asset.

3) Public-key Cryptography – Blockchain uses different types of cryptography including ECDSA and elliptic curve to authenticate transactions.

4) Decentralized transaction ledger – The ledger is blockchain and is maintained without a central authority, and acts as a decentralized reconciliation system.

Blockchain with Digital signatures have become a key control in many organizations security strategy, relying on the use of certificates and complex mathematical algorithms to provide authenticity of the data and protection against forgery.

But, suppose a company wants to accept Bitcoins for its trades. Now, because of security reasons, the company would not want that only a single employee will have access to the company’s Bitcoin wallet’s password. Any transaction should need approval from more than one employees of the company. A multisignature address is created for that purpose.

A multisignature address is an address associated with more than one ECDSA private keys. So, in an m-of-n address, when a Bitcoin address is generated, it is associated with n private keys. And, at least m private keys will be required to make a transaction possible.


And this concept can be used in making digital signatures. One can create a multisignature m-of-n address using n private keys and use that to record digital signature of documents in a blockchain. Anyone can verify the digital signature using public keys, but to make the digital signature one would need at least m private keys, out of n private keys associated with the multisignature address. By using private keys between the signer and the recipient, data transactions can be maintained by only approved parties.

Image Source :

Posted in Scala | Leave a comment

Introduction of Blockchain


“Blockchain is more than just ICT innovation, but facilitates new types of economic organization and governance. Suggests two approaches to economics of blockchain: innovation-centred and governance-centred. Argues that the governance approach—based in new institutional economics and public choice economics—is most promising, because it models blockchain as a new technology for creating spontaneous organizations, ie new types of economies.”

Primavera De Fillippi, Academic, researcher, author and thought leader

Sometimes people consider bitcoin and blockchain as one but the bitcoins are digital crypto-currency and blockchain are the technology that enables digital currency from one individual to another. Blockchains solves the problem in money transfer. Today if a person wants to transfer his or her money to another person then it is done through a third trusted party which takes time and fees for the transferring money.

The blockchain was conceptualized by Satoshi Nakamoto in 2008 and implemented as a core component of bitcoin but now it is also used for other crypto-currency, online signature services and many other applications.

Blockchain is a peer to peer technology that protects the integrity of a digital piece of information. It is a form of distributed public ledger or database that maintains a list of blocks. Each block contains a hash(A hash algorithm turns an arbitrarily-large amount of data into a fixed-length hash) of previous block hence creates a chronological order. Every node gets a copy of the ledger and each time any transaction occurs it is broadcast over the blockchain network. Whenever any node connects with the network it gets automatically downloaded.

Blockchain has two main concepts:

  • Distributed Network

  • Shared Ledger

Distributed Network

  • A decentralized peer-to-peer architecture

  • Every node in decentralized system has a copy of the blockchain.

Shared Legder

  • Database shared across network.

  • It is open for public.

  • Secure as it is public.

There are also few problems with blockchain like storage and synchronization, everytime a new block appends into blockchain very quickly but on the other hand it also has various advantages like faster transaction, transparency, lower transaction cost and much more.

Image Source: Inside Bitcoins

Posted in Blockchain | Leave a comment

Insurance needs to wake up to blockchains!

In an interesting discussion that we were having with our banking client, their insurance department kept bragging about the state of the art technology that they were building. Head of Insurance was eager enough to call it InsurTech enabled and very sophisticated. However, surprisingly when I mentioned IoT and Blockchain and how it could impact the sector, the person drew a blank ( Well, to be fair, he did mention that he had heard it before, but isn’t that what you see when you are in-front of several peers)

I was curios to see how the sector in general thinks and this report from PWC does confirm to the bias that i had.

As you would see, Blockchain does find a mention even though it is a much much lower than what you would expect. Insurers, like banks, are intermediaries and, at first glance, there is great potential for insurers to use blockchain technology to streamline payments of premiums and claims.

Aso of today, Actuaries and underwriters are now heavily dependent on the data. This data can be brought to them from a lot of sensors now. For example in telematics, insurers are using data from sensors to price motor risk more accurately, reducing the premiums of young safe drivers, and this technology is spreading to other types of cover, such as home insurance.

Till date, Insurance sector, amongst other similar sectors is ridden by huge unaccountable losses in light of fraudulent claims.

As Deloitte mentioned,

Continue reading

Posted in Scala | Leave a comment

What would kill Uber, Airbnb, TripAdvisor in one go?

What do Uber, Airbnb, TripAdvisor, PayPal etc have in common. Right, they are super successful and highly valued and …. ?

Uber and Airbnb fall in the category of Shared Economy. Paypal has changed the way financial transactions are carried out and TripAdvisor makes the rating and booking of hotels and trips easier. So, what is the common theme? The common theme is that all of these are centralised, they control (we can debate this) what gets published and who gets the maximum attention (we can debate this as well). So say Airbnb decides tomorrow that person X in San Francisco should get better hits than person Y then they have the potential to do that. Again, I am not way suggesting that they are doing this but they do have the right (well, err ..?) and the potential because there are like a central authority now. For that matter, we have made them almost like banks, governments and visa.

Ok, and who can disrupt this business model. It is Blockchain.

So what is Block chain, as a starter, it is completely decentralised. It is not stored on any central location. It is distributed across volunteer machines in a true P2P fashion across the world. It is encrypted with public key and private key and is impossible to tamper with (well, until you implement it incorrectly, see DAO hack)

Let us see how it would work for say Uber. So now, instead of centralised Uber, we have an Uber in which all the people who want to drive  a car for living attach that meta with their profile in the Blockchain. So say there are 10,000 people in Toronto who register on the distributed block chain (remember no centralisation here) their intention to drive when hired. Now when a passenger wants a ride, there is a filter which finds the city and the driver on the basis of reputation on the Blockchain and gives us the result. Further, if along with driving I also put my intent to rent out my extra room on the block chain then if someone wants to book a room then they specify the filter in the same way on the blockchain and get back the listing of all the rooms that they would be interested in.

Continue reading

Posted in Scala | Tagged | 4 Comments

Quick example of a block in the blockchain

Further to our earlier post, which describes the data structure of a block in the blockchain, here is a quick example of what does the block look like



Relating it back to the post, it contains the

  1. Size, Version, Bits and Height in the chain as to where it belongs
  2. Number of transactions
  3. Merkle root
  4. Timestamp
  5. Link to the previous block
  6. Mining Difficulty
  7. Nonce
  8. And a list of all the transactions in the block.

Again, each transaction has the following format

Screenshot from 2016-11-28 18-16-28.png

Again as per the details in the earlier post, amongst the technical information, it contains the size, mine time and the block that it is a part of , along with the details of the coinbase in input and output.

Posted in Blockchain, Scala | Tagged , | Leave a comment

BigData Specifications – Part 1 : Configuring MySql Metastore in Apache Hive

Apache Hive is used as a data warehouse over Hadoop to provide users a way to load, analyze and query the data from various resources. Data is stored into databases or file systems like HDFS (Hadoop Distributed File System). Hive can use Spark SQL or HiveQL for the implementation of queries.

Now Hive uses its metastore which contains the following information,

  • Ids of tables,
  • Ids of databases,
  • Time of creation,
  • Table names,
  • Type of the table,
  • And its owner’s names

Hive metastore is constructed with the following,

Metastore DB

It is defined as and Relational Database Management System (RDBMS), which contains the metadata for the schema and the two major types of tables as,

  • Managed tables,
  • External tables

Metastore Service

Metastore runs a background service as metastore service which is used to perform the database operations and manage the metastore data and storing of the data into Hive Tables.


Hive basically uses the HDFS to store the data retrieved into the tables, usually under the directory user/hive/warehouse.

Steps to setup MySQL metastore

Install the MySQL server (Optional if already installed)

Install MySQL java connector

sudo apt-get install libmysql-java

If you are using the Spark’s internal hive, then copy the connector jar file into Spark’s lib folder as

cp /usr/share/java/mysql-connector-java.jar $SPARK_HOME/lib/mysql-connector-java.jar

If you are using the hive apart from Spark, then copy the connector jar file into Hive’s lib folder as

cp /usr/share/java/mysql-connector-java.jar $HIVE_HOME/lib/mysql-connector-java.jar
Now we will use the script hive-schema-0.14.0.mysql.sql  the script according to the version of hive to create the initial schema for metastore database as below,
First create the database as metastore and load the initial schema as,
mysql> CREATE DATABASE metastore;
mysql> USE metastore;
mysql> SOURCE PATH-TO-SCRIPT/hive-schema-0.14.0.mysql.sql;
Then create a user for hive and grant the permissions to it,
mysql> CREATE USER 'hiveuser'@'%' IDENTIFIED BY 'hivepassword';
mysql> GRANT all on *.* to 'hiveuser'@localhost identified by 'hivepassword';
mysql> flush privileges;
Now just put the below code and create the hive-site.xml file in $HIVE_HOME or $SPARK_HOME/conf folder,
      <description>metadata is stored in a MySQL server</description>
      <description>MySQL JDBC driver class</description>
      <description>user name for connecting to mysql server</description>
      <description>password for connecting to mysql server</description>

After we create a table in hive, we can see the metadata by executing the following queries in MySQL,

mysql> use metastore;
mysql> select * from TBLS;

Keep blogging ….


Posted in Scala | Tagged , , , , , , , , , | Leave a comment

BlockChain Internals: Data Storage

A BlockChain is a public ledger that create a digital ledger of transactions and share it among a distributed network of computers. BlockChain uses cryptography to allow each participant on the network to manipulate the ledger in a secure way without the need for a central authority.

BlockChain is just an data structure i.e. how logically data can be put together and stored. BlockChain in context of data structure is similar to Book. Lets take a look how BlockChain stores data :-

  • BlockChain uses Merkle Tree to Store the data in distributed manner.
  • You can think a Block as a page in the Book. just like a page contains header and content similarly Block also contains Header and Content.
  • Header contains the data about the block (we will read later).
  • Content contains the transaction data and data related to mining rewards.

Header of the Block :- Header of the Block stores the following informations :-

  • Technical Data :- it contains Version , size of the block and Magic ID.
  • Previous Block Hash :- it contains hash of previous block header generated by 2 times applying SHA256 algorithm.
  • Merkle Root :- it contains the single hash of the Block.
  • Time Stamp :- it contains the time stamp when the block is created.
  • Difficulty Target :- this data is related to mining how hard it is to mine the block.
  • Nonce :- A random number.

Continue reading

Posted in Scala | 1 Comment

Are we really eliminating central authorities with blockchain?

There is a lot of promise around blockchains. While we at DeepChains do subscribe to the philosophy and would be eager to provide business solutions to meet the industry needs but there has been a lot of double talk, it seems with blockchains.

The premise of blockchain is the following

  • No central registration – No big papa.
  • Decentralized – there is no single point of failure.
  • Safe – Encrypted and secure.
  • Private – My data as an individual is not held by a central authority. I choose what to share
  • Secure – end-to-end encrypted communication routed over Tor.
  • Open – Open source code

However, for all the so-called currency exchanges, this does not seem to be the case. Let us understand the premise of Bitcoins philosophy first. If you look at the image below, we are trying to get rid of any central agencies,


We are trying to get rid of any paperwork that needs to be submitted to these central agencies which make me share more information than what i need to.

Screenshot from 2016-11-27 13-38-03.png

and I need to be working without any central control in a true P2P manner.


However, let us cut to the current state of things with any blockchain enabled exchange that we are talking about. The current set of exchanges work on the concept of centralisation. They would become the man in the middle instead. So now we take out the banks but we have these men in the middle which would peddle less money than the traditional banks but peddle nevertheless. They would keep your information and subver the ideal blockchain model.

Continue reading

Posted in Blockchain, Scala | Tagged , , , | 2 Comments

Introduction to MultiChain : BlockChains

MultiChain is a platform that enable us to create and deploy private BlockChain that can be used either within a Organization or between Organizations. MultiChain provides a simple API and command-line interface thats make it easy to maintain and deploy.

The main aim of MultiChain is :-

  • to ensure that visibility of BlockChain‘s activity must be kept within the chosen participants.
  • to control over which transaction are permitted.
  • to enable more secure mining with proof of work and its associated cost.
  • the BlockChain system only store transaction related to participants.

Hand-shaking process in MultiChain :- Hand-shaking process in MultiChain take place when two BlockChain nodes Connect

  • Each node present its identity as a public address on the permitted list.
  • Each node verify that other’s address is on its own permitted list.
  • Each node sends a challenge message to other party.
  • Each node sends back a signature of the challenge message providing there ownership of the private key corresponding to the public address they presented.

If any of the node is not satisfying with the results then it aborts the peer-to-peer connection.

Mining in MultiChain :- MultiChain restricts miner to a set of identifiable entities. MultiChain introduce a parameter called “mining diversity” which is constrains by

0 <= mining diversity <= 1. The Validity of block is verified by :

Continue reading

Posted in Scala | Leave a comment

Knolx : Realm Mobile Database

Hi guys,

Knoldus organized a knolx session on the topic : Realm Mobile Database.

A better mobile database means better apps. Realm is a mobile database that runs directly inside phones, tablets or wearables. It saves data in minutes so you can build mobile apps in a fraction of time. It is a simple alternative to SQLite and Core Data. It works on all major mobile platforms to provide offline-first functionality & data persistence through an easy-to-use API.

Here is the link for the slides:

You can also watch the video of the session at this link:


Posted in database, Java | Leave a comment