accredifysg/php-rdf-canonicalize 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

accredifysg/php-rdf-canonicalize

Composer 安装命令:

composer require accredifysg/php-rdf-canonicalize

包简介

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

README 文档

README

CI Packagist Version PHP Version License W3C rdf-canon

A PHP implementation of the W3C RDF Dataset Canonicalization (RDFC-1.0) 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 — 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.

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's toRdf() for that. This package intentionally has no dependency on php-json-ld.

Installation

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

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

Usage

use Accredify\RdfCanonicalize\RDFC10;

$nquads = <<<NQ
_:b0 <https://schema.org/name> "John Doe" .
_:b0 <https://schema.org/knows> _:b1 .
_:b1 <https://schema.org/name> "Jane Doe" .
NQ;

$canonical = (new RDFC10)->canonicalize($nquads);

// $canonical is a sorted list of canonical N-Quads, one per element.
echo implode('', $canonical);
// _:c14n0 <https://schema.org/knows> _:c14n1 .
// _:c14n0 <https://schema.org/name> "John Doe" .
// _:c14n1 <https://schema.org/name> "Jane Doe" .

RDFC10 implements Accredify\RdfCanonicalize\Contracts\Canonicalizer. After canonicalising, getCanonicalIdMap() returns the map of original → canonical blank node identifiers.

Pairing it with php-json-ld to canonicalise a JSON-LD document:

use Accredify\JsonLd\JsonLdProcessor;
use Accredify\RdfCanonicalize\RDFC10;

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

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

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[]
  • NQuadsSerializerRdfTerm components → a canonical N-Quad line

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

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).

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

Tested against the official W3C rdf-canon test suite, pulled in as a git submodule at tests/w3c/. See 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

Test type W3C suite Passing
Eval 64 64
Map (identifiers) 21 21
NegativeEval 1 1
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 for the 0.x → 1.0 conformance history.

License

MIT © Accredify

accredifysg/php-rdf-canonicalize 适用场景与选型建议

accredifysg/php-rdf-canonicalize 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「W3C」 「RDF」 「n-quads」 「Canonicalization」 「linked-data」 「semantic-web」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 accredifysg/php-rdf-canonicalize 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 accredifysg/php-rdf-canonicalize 我们能提供哪些服务?
定制开发 / 二次开发

基于 accredifysg/php-rdf-canonicalize 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 25
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 43
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-11