• This repository has been archived on 11/Aug/2021
  • Stars
    star
    119
  • Rank 297,930 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The JavaScript Implementation of IPLD

⛔️ DEPRECATED: This module has been superseded by multiformats

IPLD hex logo

The JavaScript implementation of the IPLD

Travis CI Coverage Status Dependency Status js-standard-style Greenkeeper badge

The JavaScript implementation of the IPLD, InterPlanetary Linked-Data

Project Status

This project is considered stable, but alpha quality implementation. The IPLD strategy for persistence and integration with IPFS has evolved since this package was created. This package will be deprecated once the new strategy is fully implemented. You can read more about the new strategy in Issue #260

IPLD Team Management

Tech Lead

Volker Mische

Lead Maintainer

Volker Mische

Table of Contents

Install

> npm install --save ipld

Usage

const Ipld = require('ipld')
const IpfsRepo = require('ipfs-repo')
const IpfsBlockService = require('ipfs-block-service')

const initIpld = async (ipfsRepoPath) => {
  const repo = new IpfsRepo(ipfsRepoPath)
  await repo.init({})
  await repo.open()
  const blockService = new IpfsBlockService(repo)
  return new Ipld({blockService: blockService})
}

initIpld('/tmp/ipfsrepo2')
  .then((ipld) => {
    // Do something with the `ipld`, e.g. `ipld.get(…)`
  })
  .catch((error) => {
    console.error(error)
  })

API

The IPLD API works strictly with CIDs and deserialized IPLD Nodes. Interacting with the binary data happens on lower levels. To access the binary data directly, use the Block API.

All methods that return an async iterator return one that got extended with convenience methods:

  • iter.first(): Return the first item only
  • iter.last(): Return the last item only
  • iter.all(): Return all items as array

Example:

const result = ipld.getMany([cid1, cid2])
const node1 = await result.first()

IPLD constructor

Creates and returns an instance of IPLD.

const ipld = new Ipld(options)

The options is an object with any of these properties:

options.blockService
Type Default
ipfs.BlockService instance Required (no default)

Example:

const blockService = new IpfsBlockService(repo)
const ipld = new Ipld({blockService: blockService})
options.formats
Type Default
Array of IPLD Format implementations [require('ipld-dag-cbor'), require('ipld-dag-pb'), require('ipld-raw')]

By default only the dag-cbor), dag-pb) and raw) IPLD Formats are supported. Other formats need to be added manually. Here is an example if you want to have support for ipld-git only:

const ipldGit = require('ipld-git')

const ipld = new Ipld({
  formats: [ipldGit],
  …
})
options.loadFormat(codec)
Type Default
async Function null

Function to dynamically load an IPLD Format. It is passed a codec, the multicodec code of the IPLD format to load and returns an IPLD Format implementation. For example:

const multicodec = require('multicodec')
const ipld = new Ipld({
  async loadFormat (codec) {
    if (codec === multicodec.GIT_RAW) {
      return require('ipld-git')
    } else {
      throw new Error('unable to load format ' + multicodec.print[codec])
    }
  }
})

.put(node, format, options)

Stores the given IPLD Node of a recognized IPLD Format.

  • node (Object): the deserialized IPLD node that should be inserted.
  • format (multicodec, required): the multicodec of the format that IPLD Node should be encoded in.
  • options is an object with the following properties:
    • hashAlg (multicodec, default: hash algorithm of the given multicodec): the hashing algorithm that is used to calculate the CID.
    • cidVersion (number, default: 1): the CID version to use.
    • onlyHash (boolean, default: false): if true the serialized form of the IPLD Node will not be passed to the underlying block store.
    • signal (AbortSignal): a signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns a Promise with the CID of the serialized IPLD Node.

.putMany(nodes, format, options)

Stores the given IPLD Nodes of a recognized IPLD Format.

  • nodes (AsyncIterable<Object>): deserialized IPLD nodes that should be inserted.
  • format (multicodec, required): the multicodec of the format that IPLD Node should be encoded in.
  • options is applied to any of the nodes and is an object with the following properties:
    • hashAlg (multicodec, default: hash algorithm of the given multicodec): the hashing algorithm that is used to calculate the CID.
    • cidVersion (number, default: 1): the CID version to use.
    • onlyHash (boolean, default: false): if true the serialized form of the IPLD Node will not be passed to the underlying block store.
    • signal (AbortSignal): a signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns an async iterator with the CIDs of the serialized IPLD Nodes. The iterator will throw an exception on the first error that occurs.

.resolve(cid, path, options)

Retrieves IPLD Nodes along the path that is rooted at cid.

  • cid (CID, required): the CID the resolving starts.
  • path (IPLD Path, required): the path that should be resolved.
  • options an optional object that may have the following properties:
    • signal (AbortSignal): a signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns an async iterator of all the IPLD Nodes that were traversed during the path resolving. Every element is an object with these fields:

  • remainderPath (string): the part of the path that wasn’t resolved yet.
  • value (*): the value where the resolved path points to. If further traversing is possible, then the value is a CID object linking to another IPLD Node. If it was possible to fully resolve the path, value is the value the path points to. So if you need the CID of the IPLD Node you’re currently at, just take the value of the previously returned IPLD Node.

.get(cid, options)

Retrieve an IPLD Node.

  • cid (CID): the CID of the IPLD Node that should be retrieved.
  • options an optional object that may have the following properties:
    • signal (AbortSignal): a signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns a Promise with the IPLD Node that correspond to the given cid.

Throws an error if the IPLD Node can’t be retrieved.

.getMany(cids, options)

Retrieve several IPLD Nodes at once.

  • cids (AsyncIterable<CID>): the CIDs of the IPLD Nodes that should be retrieved.
  • options an optional object that may have the following properties:
    • signal (AbortSignal): a signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns an async iterator with the IPLD Nodes that correspond to the given cids.

Throws an error if a IPLD Node can’t be retrieved.

.remove(cid, options)

Remove an IPLD Node by the given cid

  • cid (CID): the CIDs of the IPLD Node that should be removed.
  • options an optional object that may have the following properties:
    • signal (AbortSignal): a signal that can be used to abort any long-lived operations that are started as a result of this operation.

Throws an error if the IPLD Node can’t be removed.

.removeMany(cids, options)

Remove IPLD Nodes by the given cids

  • cids (AsyncIterable<CID>): the CIDs of the IPLD Nodes that should be removed.
  • options an optional object that may have the following properties:
    • signal (AbortSignal): a signal that can be used to abort any long-lived operations that are started as a result of this operation.

Throws an error if any of the Blocks can’t be removed. This operation is not atomic, some Blocks might have already been removed.

.tree(cid, [path], [options])

Returns all the paths that can be resolved into.

  • cid (CID, required): the CID to get the paths from.
  • path (IPLD Path, default: ''): the path to start to retrieve the other paths from.
  • options:
    • recursive (bool, default: false): whether to get the paths recursively or not. false resolves only the paths of the given CID.
    • signal (AbortSignal): a signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns an async iterator of all the paths (as Strings) you could resolve into.

.addFormat(ipldFormatImplementation)

Add support for an IPLD Format

  • ipldFormatImplementation (IPLD Format, required): the implementation of an IPLD Format.

Returns the IPLD instance. This way you can chain addFormat() calls.

.getFormat(codec)

Return the implementation for an IPLD Format

  • codec (multicodec, required): the codec of the IPLD Format to return the implementation from.

If the implementation is not present in the current list of resolvers, the loadFormat function passed as an option to the constructor of this module will be invoked and it's output added to the list of available resolvers.

.removeFormat(codec)

Remove support for an IPLD Format

  • codec (multicodec, required): the codec of the IPLD Format to remove.

Returns the IPLD instance. This way you can chain removeFormat() calls.

Properties

defaultOptions

Default options for IPLD.

Packages

Listing of dependencies from the IPLD ecosystem.

This table is generated using the module package-table with package-table --data=package-list.json.

Package Version Deps CI Coverage Lead Maintainer
IPLD Formats
ipld-bitcoin npm Deps Travis CI codecov Volker Mische
ipld-dag-cbor npm Deps Travis CI codecov Volker Mische
ipld-dag-pb npm Deps Travis CI codecov Volker Mische
ipld-ethereum npm Deps Travis CI codecov Volker Mische
ipld-git npm Deps Travis CI codecov Volker Mische
ipld-raw npm Deps Travis CI codecov Volker Mische
ipld-zcash npm Deps Travis CI codecov Volker Mische
Data Types (non IPLD specific)
multihashes npm Deps Travis CI codecov David Dias
ipfs-block npm Deps Travis CI codecov Volker Mische
Storage
ipfs-repo npm Deps Travis CI codecov Jacob Heun
interface-datastore npm Deps Travis CI codecov Pedro Teixeira
ipfs-block-service npm Deps Travis CI codecov Volker Mische

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

License

MIT

More Repositories

1

ipld

InterPlanetary Linked Data
Nunjucks
1,261
star
2

specs

Content-addressed, authenticated, immutable data structures
JavaScript
592
star
3

go-car

A content addressible archive utility
Go
148
star
4

libipld

Rust IPLD library
Rust
135
star
5

go-ipld-prime

Golang interfaces for the IPLD Data Model, with core Codecs included, IPLD Schemas support, and some handy functional transforms tools.
Go
132
star
6

explore.ipld.io

Explore the Merkle Forest from the comfort of your browser
JavaScript
122
star
7

js-ipld-dag-pb

JavaScript Implementation of the MerkleDAG Nodes with Protobuf.
JavaScript
69
star
8

js-ipld-dag-cbor

JavaScript implementation of the IPLD dag-cbor format.
JavaScript
53
star
9

js-car

Content Addressable aRchive format reader and writer for JavaScript
JavaScript
42
star
10

js-ipld-ethereum

JavaScript Implementation of All Ethereum IPLD formats
JavaScript
40
star
11

java-cid

Java implementation of Content Identifier
Java
39
star
12

js-ipld-graph-builder

Provides an efficient way to build and manipulate IPLD DAGs as JSON
JavaScript
38
star
13

py-cid

Self-describing content-addressed identifiers for distributed systems implementation in Python
Python
36
star
14

js-ipld-git

JavaScript
34
star
15

go-ipld-deprecated

Golang IPLD Dev Entry Point Repo
Go
32
star
16

docs

All you need to know about IPLD
JavaScript
31
star
17

ipld-examples

30
star
18

interface-ipld-format

A interface you can follow to implement a valid IPLD format, resolvable through the IPLD Resolver (available in IPFS)
29
star
19

js-dag-cbor

dag-cbor codec for IPLD
JavaScript
27
star
20

js-dag-ucan

UCAN codec for IPLD
JavaScript
22
star
21

website

Official website for IPLD
HTML
22
star
22

go-ipld-btc

ipld handlers for bitcoin
Go
22
star
23

legacy-unixfs-v2

This repository contains deprecated / legacy Unixfs "V2" discussions.
21
star
24

go-ipldtool

A fine gadget
Go
17
star
25

frisbii

An experimental minimal IPLD data provider for the IPFS network
Go
17
star
26

edelweiss

Decentralized Protocol Compiler
Go
16
star
27

js-dag-json

JSON Directed Acyclic Graph for IPLD
JavaScript
15
star
28

go-storethehash

Storage for hashes, targeted at content addressable systems
Go
13
star
29

js-ipld-block

Implementation of the Block data structure in JavaScript.
JavaScript
13
star
30

js-ipld-bitcoin

JavaScript implementation of Bitcoin IPLD formats
JavaScript
12
star
31

js-dag-pb

An implementation of the DAG-PB spec for JavaScript (for use with multiformats or @ipld/block)
JavaScript
12
star
32

js-ipld-cli

Interact with IPLD on the command line
JavaScript
12
star
33

go-ipld-graphql

Graphql queries over IPLD schemas
Go
11
star
34

js-ipld-eth-block

JavaScript Implementation of the IPLD format - Ethereum Block
JavaScript
11
star
35

js-ipld-zcash

JavaScript implementation of Zcash IPLD formats
JavaScript
11
star
36

py-ipld-dag

Merkle DAG implementation for IPLD in Python
Python
11
star
37

js-ipld-schema

IPLD Schema Implementation: parser and utilities
JavaScript
11
star
38

roadmap

IPLD Project Roadmap
10
star
39

js-examples

JavaScript IPLD Examples
JavaScript
9
star
40

go-ipld

Golang IPLD Dev Entry Point Repo
9
star
41

wasm-ipld

Tools and examples of IPLD codecs and ADLs in WASM callable from hosts
Rust
8
star
42

research

Research repo for the IPLD github org
TeX
8
star
43

js-ipld-torrent-file

JavaScript implementation of the Torrent IPLD format
8
star
44

serde_ipld_dagcbor

DAG-CBOR implementation for Serde
Rust
8
star
45

go-codec-dagpb

An implementation of the DAG-PB spec for Go
Go
7
star
46

java-ipld-cbor

A Java implementation of the IPLD cbor format
Java
7
star
47

codec-fixtures

Fixtures for testing standard IPLD codecs
JavaScript
7
star
48

js-unixfs

UnixFS Directed Acyclic Graph for IPLD
JavaScript
7
star
49

js-ipld-stack

EXPERIMENTAL: Next JS IPLD authoring stack
JavaScript
7
star
50

team-mgmt

IPLD Team Planning, Management & Coordination threads
6
star
51

js-ipld-selector

JavaScript
6
star
52

eth-hash-to-cid

Utility to convert ethereum hashes to CID (Content IDentifier)
JavaScript
6
star
53

js-block

IPLD Block Interface
JavaScript
6
star
54

js-ipld-raw

JavaScript implementation of the IPLD raw format.
JavaScript
5
star
55

js-printify

Convert a decoded IPLD value to a colored printable string
JavaScript
5
star
56

js-unixfsv2

IPLD unixfs-v2 Implementation
JavaScript
4
star
57

go-ipld-adl-hamt

Go
4
star
58

replication

Discussions and proposals regarding IPLD replication.
4
star
59

js-bitcoin

JavaScript Bitcoin data multiformats codecs and utilities for IPLD
JavaScript
4
star
60

go-ipld-schema

Implementation of an ipld schema parser
Go
4
star
61

go-datalark

Use IPLD from Starlark -- read and write data, and play programmagically in an interpreted language!
Go
4
star
62

react-ipld

React components for IPLD
JavaScript
4
star
63

rust-ipld-core

This crate provides core types for interoperating with IPLD.
Rust
4
star
64

js-composites

WIP: IPLD Composites
JavaScript
4
star
65

js-ipld-eth-tx-trie

JavaScript
3
star
66

js-ipld-eth-tx

JavaScript
3
star
67

serde_ipld_dagjson

IPLD DAG-JSON support for Serde.
Rust
3
star
68

ipld-in-memory

🧠 IPLD in your RAM
JavaScript
3
star
69

cid-cbor

Spec for Content Identifiers (CIDs) in CBOR for IANA CBOR Tag registry
3
star
70

js-schema-gen

Generate type interfaces from IPLD Schema
JavaScript
2
star
71

js-iq

Experimental: IPLD Query
JavaScript
2
star
72

js-ipld-torrent-info

JavaScript implementation of the Torrent File IPLD format
2
star
73

js-codec-interface

IPLD Codec Interface
JavaScript
2
star
74

go-fixtureplate

Tools to generate and inspect IPLD data to assist in testing
Go
2
star
75

js-ipld-bencode

JavaScript implementation of the bencode IPLD format
2
star
76

go-walker

Walker provides an alternate, parellizable and controllable way to execute selectors
Go
2
star
77

js-schema-validation

Validate decoded data against an IPLD Schema
JavaScript
1
star
78

js-datastore-car

Content Addressable aRchive format reader and writer
JavaScript
1
star
79

auto

Org level automation.
JavaScript
1
star
80

js-ipld-garbage

Generate garbage objects conformant with the IPLD Data Model
JavaScript
1
star
81

grants

IPLD Grants for Research and Development
1
star
82

go-selector-store

A simple store to record selector traversals
Go
1
star
83

rust-ipld-dagpb

IPLD DAG-PB codec.
Rust
1
star
84

github-mgmt

TypeScript
1
star