Description
In this tutorial we will be learning about IPLD and CIDs which are used in IPFS(Inter Planetary File System). First some background, a CID is a Content Identifier. CID at their core are just a data structure that resolves a hash to the file that generated. IPLD, Interplanetary Linked Data, uses CID's recursively to structure data using various standards, for example DAG-JSON is JSON made up of CIDs.
We will be generating CID's manually using three different tools and validating that they all produce the same output.
This is a requirement for my CGFS Persona Schema
Source Code
Question Engine Memes are CID's
The Question Engine - QE application I am working on has RBAC. This means that some data shared by someone to someone else is not supposed to be uploaded to the public internet. But if that data was uploaded to the internet it would use the same CID. This also allows data that is shared privately then later shared publicly and not have to update any private references to it.
Learn more about CID's
Goals of This Tutorial
- Install Kubo the Go IPFS implementation
- Managing Raw Files in IPFS
- Add files to IPFS using Kugo and get CID
- Use JavaScript to produce CID + CAR of raw image file
- Use Python to produce CID + CAR using raw image file
- DAG-JSON and IPFS
- Use JavaScript to produce CID of DAG-JSON
- Use Python to produce CID of DAG-JSON
- Managing Folders in IPFS
Install Kugo
Just follow this -> Kubo | IPFS Docs
Add files to IPFS using Kugo and get CID
mkdir test
cd test
cat "helloworld" > helloworld
ipfs add --cid-version 0 helloworld
# added QmUZ6YmQSmu9CV7KAT2tj6UEeGacD8MvB7wXKEWKG584Gn helloworld
ipfs cat QmUZ6YmQSmu9CV7KAT2tj6UEeGacD8MvB7wXKEWKG584Gn
ipfs add --cid-version 1 helloworld
# added bafybeic4kzhlnhbbxw76qpodl7w7rwxyj7gyv4sybdz5f6wfaf5nfezew4 helloworld
ipfs cat bafybeic4kzhlnhbbxw76qpodl7w7rwxyj7gyv4sybdz5f6wfaf5nfezew4
Use JavaScript to produce CID + CAR of DAG-JSON
TODO
JavaScript Libraries
# Optional: Create npm package
npm init -y
npm install multiformats
npm install @ipld/dag-json
npm install @ipld/dag-pb # for CIDv0
npm install ajv
npm install ajv-formats
Python Libraries
# Optional: Setup python virtual environment
python3 -m pip install virtualenv
python3 -m venv env
source env/bin/activate
python3 -m pip install multiformats[full]
python3 -m pip install dag-json
python3 -m pip install jsonschema
python3 -m pip install jsonschema[format]
Managing Raw Files in IPFS
DAG-JSON and IPFS
Links
Sources
- Possible to determine if a file is present on IPFS by calculating its hash? - Stack Overflow
- alanshaw/ipfs-only-hash: #️⃣ Just enough code to calculate the IPFS hash for some data
- javascript - Node-less way to generate a CID that matches IPFS-Desktop CID - Stack Overflow