/rholang-files-module

Rholang module/contract to manage files or any other kind of resource on the blockchain.

Primary LanguageJavaScriptMIT LicenseMIT

Rholang files module

Files module to manage files on the blockchain. Basically it can be anything other than files, the contract creates a map on chain, this map has write access provided to only one identity (private key).

Mountains with fog

Setup and file upload

# Install dependencies
$ npm i

# Rename .env.example to .env, and edit url/ports values
# The default values are valid values for deploying to, and reading from the testnet

# Initiate module (will issue blockchain transaction)
$ node deploy_file_module.js --private-key aaa

# Add a file (will issue blockchain transaction)
$ node add_file --file ./README.MD --mime-type text/markdown --private-key aaa --registry-uri bbb

# Read a file (free)
$ node read_file --file-address bbb.index

Node (add file script): If you do not provide the paramter --file-id it will be set with the default value index. You can set it to RANDOM (--file-id RANDOM) to have a random value generated (8 characters).

General structure and addresses

Addresses

The address system for such a system is based first on the registry URI, and then on an arbitrary file id/name. Some address examples :

registry_uri.file_id_or_name

3gsz44jg3dowfqoq8y5ap33u891yrw7bjdmrtnnhnrhzitwcfa4a9o.166efceb071746d589d5ed4a90213ec6 3gsz44jg3dowfqoq8y5ap33u891yrw7bjdmrtnnhnrhzitwcfa4a9o.e8becb4e6469f19defb7c75105828959 3gsz44jg3dowfqoq8y5ap33u891yrw7bjdmrtnnhnrhzitwcfa4a9o.monster 3gsz44jg3dowfqoq8y5ap33u891yrw7bjdmrtnnhnrhzitwcfa4a9o.important_document

File representation on chain

Files are represented as a gzipped and base64 string of the following object (see add_file.js:112)

{
  mimeType: mimeType, // string ex: application/json
  name: name, // string ex: package.json
  data: data, // string base64(fs.readFileSync())
  signature: signature, // string, generated by the private key used to sign the deploy
}

Files module

The files module in rholang has the following structure :

{
  "registryUri": registry URI for reading, updating or adding files,
  "publicKey": "bbbababacda454545349090990",
  "nonce": "abcdff45f45f45aaaa56cdaaa",
  "files": {
    "0001" : registry URI (string),
    "0002" : registry URI (string),
    "monster" : registry URI (string),
  },
  "version": "0.4"
}

The nonce is changed each time there is an operation on the files module. A signature provided in the payload is checked each time an operation on the files module is done (add/update).

Each file can be retreived through a channel exposed to the registry.

TODO :

  • Check the signature against the entire payload instead of the hash of the nonce
  • Add update file capability