How to register file into blockchain with Ubuntu 20.04

Register files into blockchain using a shell script.

In a nutshell:

1) Install prerequisites:

sudo apt-get install libcryptx-perl jq


2) install Bitcoin core

sudo snap install bitcoin-core


3) clone the ByteStamp github repo

git clone https://github.com/bytestamp/bt.git


4) make the script executable

chmod +x bt/bt


5) depending on your environment, put the script in your path

sudo cp bt/bt /usr/bin

Done!

Now you can do

bt FILEs


This will list BlockChain information about FILEs

If no file is registered to BlockChain then register FILEs

A third party can drag and drop the files to https://go.bytestamp.net to verify them or use the windows software available at https://blockchain.bytestamp.net

The script is self-explaining and can be used to understand how to connect to ByteStamp web services with any programming language.

A deeper insight about registering into blockchain

ByteStamp is a service that lets you register file into blockchain since 2014.

When a file is registered into blockchain, its content is inextricably linked to the blockchain block in which it is stored. This occurs because the unique fingerprint of this file, its digest, is encapsulated within the blockchain and confirmed by miners together the transactions info.

The ByteStampProof

The way ByteStamp achieves this is to generate a particular digest, called ByteStampMD5, that comes out from the fusion of three hashes algorithms:

  • MD5
  • SHA512
  • Keccak-512

In this way, we avoid MD5 collisions that occurs when two different files have the same digest.

Indeed, in order to verify a file against ByteStamp, you have to generate its ByteStampMD5 and not the normal MD5. As you can read in the script, the ByteStampMD5 is generated client side and ByteStamp receives only the digest, not the file itself. So nobody know what you are registering in blockchain.

When the ByteStampMD5 is confirmed with the block, we obtain the ByteStampProof, i.e. the proof of existence of that file. If a ByteStampMD5 was confirmed in a block at a date/time, of course the unique file that generates that ByteStampMD5 had to exist at that time.

This file can be anything: an invoice, a picture, an idea. In this way can be proved that a job was made before a date/time.

The original author, who carefully preserved the file, can prove his ByteStampProof to anyone.

ByteStamp Digital Assets

But with ByteStamp we can do much more of the simple proof of existence of a file. ByteStamp offers several services for let you link a file or a text into the blockchain in different modes to archive different purposes.

One of this is the possibility to become the owner of the file registered into the blockchain.

Becoming the owner of a file stored into blockchain let you to prove not only when anyone did a file, but also who did it.

When a file registered with ByteStamp has an owner, it becomes a ByteStamp Digital Asset.

This is what the shell script does. It not only registers your files for ByteStampProof, but it also makes them ByteStamp Digital Assets that belong to you.

When you want to create a ByteStamp Digital Asset, these steps occur:

  1. You do a request to ByteStamp to create a ByteStamp Digital Asset
  2. ByteStamp create a message that is a declaration that a ByteStampMD5 belongs to your ByteStamp Address
  3. You sign this message with your private key
  4. The message and the signature are stored in blockchain forever

In this way, everyone can read in the blockchain that a ByteStamp Digital Asset belong to a ByteStamp Address, because everyone can verify the signature written in the blockchain.

The owner is the sole that can transfer the ownership, and each property transfer is written in the blockchain and signed by the owner. So everyone can read that the transaction is legit.

The first that creates a ByteStamp Digital Asset can take its ownership even without a previous owner.

The ByteStamp Address is a normal Bitcoin address that is used to sign messages that create or transfer a ByteStamp Digital Asset. The signature is generated from a normal Bitcoin wallet, so only you own your private key. ByteStamp only writes in blockchain what you signed, and no one can sign for you.

In this way, you can exchange a ByteStamp Digital Asset through the blockchain.

As like as with Bitcoin you can exchange bitcoins, that are money, with ByteStamp you can exchange any file, that can be everything. And each transaction is backed by the blockchain and by the asymmetric key cryptography.

The ByteStamp Protocol

When you call a ByteStamp web service, you have to respect a particular protocol to authenticate and let ByteStamp to accept your commands.

ByteStamp has its own protocol because it authenticates clients in a decentralized manner.

Maybe also the word “authenticate” is not correctly used here.

What you have to do is to sign the command with your private key.

Then, both your ByteStamp Address and your signature are put in the headers of the post request. ByteStamp verifies the signature of the command against the ByteStamp Address and so it verifies that the command was really sent from your ByteStamp Address.

When ByteStamp responds to you, it also signs the command but with its private key. So the client can verify ByteStamp identity against ByteStamp public key.

Besides, other two parameters are required to communicate with ByteStamp: the UTC time and the ByteStampMD5 of the command concatenated with the previous one.

This ByteStampMD5 is a digest generated by the current command and by the digest of the previous command, to be sure that the command was sent from that client and in the right sequence.

What ByteStamp does with this protocol, is to bring at a web service level what cryptocurrencies do at a transaction level:

  • as like as you have to sign a Bitcoin transaction to spend your bitcoins, you have to sign the ByteStamp command before to send it
  • in both cases we use Public and Private keys to verify and sign messages
  • each call to ByteStamp WebService has a ByteStampMD5 generated upon the previous call, in the same way a BlockChain has the hash of each block generated upon the hash of previous block

In this way we can verify ByteStamp web service requests and answers in a decentralized way. It would work even without SSL, that requires a central authority that identifies you.

Besides, even clients identify ByteStamp through its public key. In this way, also clients are sure of ByteStamp identity in a decentralized manner.

Let’s think, for instance, at someone that changes DNS record of your DNS server, making you connect to a fake ByteStamp web service. In this scenario the ByteStamp client (such as this script) does not work anymore because ByteStamp signature is not verified.

Thank You for reading.