PHPackages                             accredifysg/php-rdf-canonicalize - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. accredifysg/php-rdf-canonicalize

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

accredifysg/php-rdf-canonicalize
================================

A PHP implementation of the W3C RDF Dataset Canonicalization (RDFC-1.0) algorithm.

v1.0.0(1mo ago)0182MITPHPPHP ^8.2CI passing

Since Jun 11Pushed 6d agoCompare

[ Source](https://github.com/Accredifysg/PHP-RDF-Canonicalize)[ Packagist](https://packagist.org/packages/accredifysg/php-rdf-canonicalize)[ Docs](https://github.com/accredifysg/php-rdf-canonicalize)[ RSS](/packages/accredifysg-php-rdf-canonicalize/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (5)Used By (0)

PHP-RDF-Canonicalize
====================

[](#php-rdf-canonicalize)

[![CI](https://camo.githubusercontent.com/5fa09bd069eeeb0a789ac59c5f30ecee9f0a6b085ffbb4fe7258d4d25ee9b5f7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f61636372656469667973672f7068702d7264662d63616e6f6e6963616c697a652f63692e796d6c3f6272616e63683d6d61696e)](https://camo.githubusercontent.com/5fa09bd069eeeb0a789ac59c5f30ecee9f0a6b085ffbb4fe7258d4d25ee9b5f7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f61636372656469667973672f7068702d7264662d63616e6f6e6963616c697a652f63692e796d6c3f6272616e63683d6d61696e)[![Packagist Version](https://camo.githubusercontent.com/b50cbdbe81833a67fbac8175c728066e28ed38d63b7bf879b1f6a26967d45e0b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61636372656469667973672f7068702d7264662d63616e6f6e6963616c697a65)](https://camo.githubusercontent.com/b50cbdbe81833a67fbac8175c728066e28ed38d63b7bf879b1f6a26967d45e0b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61636372656469667973672f7068702d7264662d63616e6f6e6963616c697a65)[![PHP Version](https://camo.githubusercontent.com/01d4145459302dbe901a5a97c21c42a61a15ccd9bc5284c62f7247d5353435b7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f61636372656469667973672f7068702d7264662d63616e6f6e6963616c697a65)](https://camo.githubusercontent.com/01d4145459302dbe901a5a97c21c42a61a15ccd9bc5284c62f7247d5353435b7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f61636372656469667973672f7068702d7264662d63616e6f6e6963616c697a65)[![License](https://camo.githubusercontent.com/70cdbe0bb47fd811d14d593ab6cc2a4328730fd00de5b49df0ed0c855613ec9a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61636372656469667973672f7068702d7264662d63616e6f6e6963616c697a65)](https://camo.githubusercontent.com/70cdbe0bb47fd811d14d593ab6cc2a4328730fd00de5b49df0ed0c855613ec9a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61636372656469667973672f7068702d7264662d63616e6f6e6963616c697a65)[![W3C rdf-canon](https://camo.githubusercontent.com/b0f2e0032ecd97263d689ec611aa1ff98a7b852c4aa1a397ebfacdb983776349/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5733432532307264662d2d63616e6f6e2d383625324638362d627269676874677265656e)](https://camo.githubusercontent.com/b0f2e0032ecd97263d689ec611aa1ff98a7b852c4aa1a397ebfacdb983776349/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5733432532307264662d2d63616e6f6e2d383625324638362d627269676874677265656e)

A PHP implementation of the W3C [RDF Dataset Canonicalization (RDFC-1.0)](https://www.w3.org/TR/rdf-canon/)algorithm (the standard that supersedes URDNA2015).

> **Status: stable (1.0).** Extracted from `accredifysg/verifiable-credentials-php`(mirroring how `accredifysg/php-json-ld` was), and **fully conformant with the W3C rdf-canon suite (86/86)**. The public API **and** the canonical output are covered by [Semantic Versioning](https://semver.org/) — breaking either bumps the major version. The output is consensus-critical: VC's `eddsa-rdfc-2022`and `ecdsa-sd-2023` signatures are computed over it — see [Parity](#parity-with-verifiable-credentials-php).

What it does
------------

[](#what-it-does)

RDFC-1.0 takes an RDF dataset and produces a canonical (deterministic) serialization, so that two datasets that are equal up to blank-node relabelling serialise to exactly the same bytes. That canonical form is what gets hashed and signed by Data Integrity cryptographic suites.

This package operates purely on an **RDF dataset expressed as N-Quads**:

```
N-Quads string  ──►  RDFC10  ──►  canonical N-Quads

```

Converting JSON-LD to N-Quads (the `toRdf` algorithm) is **out of scope** and is the caller's responsibility — use [`accredifysg/php-json-ld`](https://github.com/accredifysg/php-json-ld)'s `toRdf()` for that. This package intentionally has **no dependency** on php-json-ld.

Installation
------------

[](#installation)

```
composer require accredifysg/php-rdf-canonicalize:^1.0
```

Requires **PHP 8.2+** with the `hash` (SHA-256) and `mbstring` extensions.

Usage
-----

[](#usage)

```
use Accredify\RdfCanonicalize\RDFC10;

$nquads = toNQuads();
$canonical = (new RDFC10)->canonicalize($nquads, ['inputFormat' => 'application/n-quads']);
```

### Hash algorithm

[](#hash-algorithm)

RDFC-1.0 uses SHA-256 by default. Pass the spec's optional SHA-384 profile (or any algorithm `hash_algos()` reports) via the constructor:

```
$canonical = (new RDFC10(hashAlgorithm: 'sha384'))->canonicalize($nquads);
```

### Components

[](#components)

The N-Quads I/O is factored into two reusable, composable classes that `RDFC10`uses internally and accepts via its constructor:

- `NQuadsParser` — N-Quads string → `RdfQuad[]`
- `NQuadsSerializer` — `RdfTerm` components → a canonical N-Quad line

Scope
-----

[](#scope)

- RDF Dataset Canonicalization (RDFC-1.0) over N-Quads — **full W3C conformance (86/86)**.
- SHA-256 (default) and SHA-384 hash profiles, via the `hashAlgorithm`constructor option.

Out of scope for the 1.x line: JSON-LD → N-Quads conversion (use php-json-ld).

Parity with verifiable-credentials-php
--------------------------------------

[](#parity-with-verifiable-credentials-php)

The canonical output is a **frozen, consensus-critical contract**: VC's `eddsa-rdfc-2022` and `ecdsa-sd-2023` suites sign over it. For the N-Quads VC actually produces (via php-json-ld's `toRdf`), the output is **byte-for-byte identical** to the implementation VC originally shipped — verified by replaying the full pipeline over real signed credentials (see [`tools/corpus-replay.php`](tools/corpus-replay.php)).

[`tests/ParityTest.php`](tests/ParityTest.php) locks this with exact-byte fixtures. Under SemVer, **changing the canonical output is a major version bump**, paired with a coordinated regeneration of VC's signed fixtures.

Conformance
-----------

[](#conformance)

Tested against the official [W3C rdf-canon test suite](https://github.com/w3c/rdf-canon), pulled in as a git submodule at `tests/w3c/`. See [`tests/W3c/README.md`](tests/W3c/README.md) for the harness layout.

```
git submodule update --init --recursive   # once

composer test       # unit tests + parity lock (the default gate)
composer test:w3c   # W3C conformance (full — gates CI)
composer test:all   # both
```

### Score (v1.0.0) — full conformance

[](#score-v100--full-conformance)

Test typeW3C suitePassingEval6464Map (identifiers)2121NegativeEval11**Total****86****86**The W3C suite **gates CI** (no allowlist — every case passes). The canonical output is frozen under SemVer; a future change would be a major version bump plus a coordinated regeneration of VC's signed fixtures. See the [CHANGELOG](CHANGELOG.md) for the 0.x → 1.0 conformance history.

License
-------

[](#license)

[MIT](LICENSE) © Accredify

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance95

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

46d ago

Major Versions

v0.2.0 → v1.0.02026-06-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/baf5a0854c8d40389bb8d2177472f8d5d2fa063ec1a57064df36a9b819fac868?d=identicon)[skydudie](/maintainers/skydudie)

---

Top Contributors

[![skydudie](https://avatars.githubusercontent.com/u/28289296?v=4)](https://github.com/skydudie "skydudie (11 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (9 commits)")[![rezaramadhan](https://avatars.githubusercontent.com/u/15650702?v=4)](https://github.com/rezaramadhan "rezaramadhan (4 commits)")

---

Tags

W3CRDFSemantic WebLinked DataCanonicalizationn-quadsrdfc-1.0rdfc10urdna2015nquads

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/accredifysg-php-rdf-canonicalize/health.svg)

```
[![Health](https://phpackages.com/badges/accredifysg-php-rdf-canonicalize/health.svg)](https://phpackages.com/packages/accredifysg-php-rdf-canonicalize)
```

###  Alternatives

[easyrdf/easyrdf

EasyRdf is a PHP library designed to make it easy to consume and produce RDF.

62432.1M50](/packages/easyrdf-easyrdf)[digitalbazaar/json-ld

A JSON-LD Processor and API implementation in PHP.

28661.1k1](/packages/digitalbazaar-json-ld)[pietercolpaert/hardf

A fast parser for RDF serializations such as turtle, n-triples, n-quads, trig and N3

38165.0k12](/packages/pietercolpaert-hardf)[aksw/erfurt

PHP/Zend based Semantic Web API for Social Semantic Software

416.8k1](/packages/aksw-erfurt)[sweetrdf/easyrdf

EasyRdf is a PHP library designed to make it easy to consume and produce RDF.

261.5M14](/packages/sweetrdf-easyrdf)[t1gor/robots-txt-parser

PHP class to parse robots.txt rules according to Google, Yandex, W3C and The Web Robots Pages specifications.

85501.8k4](/packages/t1gor-robots-txt-parser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
