IPFS integration with PERSONA

Created by

Vlad Tomsa

Sep 13, 2018

This document highlights current implementation of the IPFS module to Persona blockchain.

  1. Uploading a file to IPFS

Uploading files to IPFS will be possible only when a client creates a “CREATE ATTRIBUTE” transaction, where the `attributType` field is of type `file` and the attribute value is the file data that will be uploaded to IPFS. These fields are mandatory, on the `asset` field on the transaction.

Example of assets:

**"asset"**:{  

      **"attribute"**:[  

         {  

            **"owner"**:"LcSsQnxLSNyLYwaMdXHERa3t4G7nnR8Y15",

            **"type"**:"identity-card",

            **"value"**:"FORM_DATA_HERE"

         }

      ]

   }

Note: The value field should have the encrypted file data. Our blockchain isn’t responsible for encrypting the file.

Upload steps:

  1. The client creates a “CREATE_ATTRIBUTE” transaction and send it to a random peer in the network.

  2. The peer receives the request, verifies the transaction data. If this transaction has an IPFS related attribute type, it extracts the file data from the request body, and send’s this file to a Random Seed available on the network.

  3. The Seed receives the file and uploads it to the IPFS network.

Note: We chose this implementation so that we can “control” that each IPFS file uploaded on our network is available (we control the seeds).

  1. The IPFS network returns the file’s associated IPFS hash to the Seed. This seed will add the hash to it’s own IPFS HASH QUEUE (see ‘Transaction confirmation’)

  2. The seed returns the IPFS hash to the peer that initiated the file upload. Once this peer receives the hash, it replaces the requested transaction attribute value with this hash, creates a transaction with the requested data and adds it to the transaction pool.

  3. A confirmation is sent back to the client.

Transaction confirmation

IPFS has a garbage collection mechanism that removes an uploaded file if it’s not accessed. In order to permanently keep the file on the network it needs to be pinned.

We implemented the pin action once a transaction, containing IPFS data, is being forged and added to the blockchain.

  1. Each transaction that is getting applied to the blockchain will be verified by each node on our network (including the seed that was responsible for adding the data on IPFS).

  2. Every node has an IPFS HASH QUEUE that stores every IPFS upload it performed.

  3. If the node receives a transaction that contains an IPFS hash, it will check it’s queue. If the hash is found, a pin request will be made to the IPFS network.

See: modules/transactions.js: Transactions.prototype.apply