json_ld_processor 1.0.4

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

JSON-LD Processor according to JSON-LD Processing API 1.1 with support for URDNA2015 normalization.

Json LD Processing Library

This package implements the JSON-LD Processing algorithms 1.1 and the URDNA2015 Canonicalization algorithm in pure Dart.

Important Note: This package is work-in-progress. Not all algorithms are implemented for now and not everything works perfect (See Implementation Status). But in general it works.

Usage

Map<String, dynamic> input = {}; //a valid Json-ld document
//expansion
var expanded = await JsonLdProcessor.expand(input);
//flattening
var flattened = await JsonLdProcessor.flatten(input);
//toRdf
var rdf = await JsonLdProcessor.toRdf(input);
//normalize (URDNA2015) with additional options
var normalized = await JsonLdProcessor.normalize(input, options: JsonLdOptions(safeMode: true));

SafeMode Option

As the implementor of the normalization algorithms URDNA2015 and URGNA2012 in java showed in his repo, using json-ld and normalization for signing there are some security flaws. In some cases the documents could be manipulated and the signatures stays correct. One reasons for this can be found in the expansion algorithm. If a property of the input document can't be expanded to an IRI or keyword, it is dropped and so not included in the normalized dataset.To be able to throw an exception in this case, there is a safeMode option. It is default set to false. But if it is true, the exception is thrown. If not, the property is dropped as standardized. I recommend setting it to true, if you normalize a json-ld document before signing.

Note: The idea introducing this option is borrowed from the JavaScript implementation which powers the JSON-LD Playground as well. This option is not part of the standard yet.

Implementation Status and Test Coverage

AlgorithmTests passedTests failedNotes
expand3638
flatten551one failed, because of missing compaction algorithm
compact94149needs bugfixing
fromRdf00not implemented yet
toRdf40630rdfDirection option is not implemented yet
normalize621

Run tests

The test data is taken from here for json-ld api test and here for normalization tests. Therefore you need to clone these two repos next to this, if you would like to run the tests.

Future Plans

  • remove bugs
  • implement Compaction and fromRdf
  • support framing