Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.x changes and more #74

Merged
merged 76 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
f31fe71
Add `canonicalIdMap` option to `canonize`.
dlongley May 14, 2023
f8b3dad
Add `inputFormat` option.
davidlehn May 19, 2023
4277bee
Add inputFormat tests.
davidlehn May 19, 2023
b179ea7
Add canonicalIdMap test.
davidlehn May 19, 2023
ef9f9d7
Adjust doc.
davidlehn May 19, 2023
5fe9328
Update test name.
davidlehn May 19, 2023
2a93336
Fix quoting style.
davidlehn May 19, 2023
94dd4f9
Fix typo.
davidlehn May 19, 2023
23240e4
Rework canonicalIdMap param doc.
davidlehn May 19, 2023
4cb8485
Update changelog.
davidlehn May 19, 2023
0c3118a
Revert inputFormat change.
davidlehn May 19, 2023
9398a29
Update changelog.
davidlehn May 19, 2023
dfc581f
Release 3.4.0.
davidlehn May 19, 2023
c38a58f
Start 3.4.1-0.
davidlehn May 19, 2023
dcec36e
Update action versions.
davidlehn Jun 22, 2023
8f4854c
Update node test verisons.
davidlehn Jun 22, 2023
21d4121
Restore inputFormat change.
davidlehn Jun 22, 2023
00b0ffe
Fix changelog.
davidlehn Jun 22, 2023
5c75499
Revert to nsolid@0.0.0.
davidlehn Jun 22, 2023
453dad7
Enable misc tests.
davidlehn Jun 22, 2023
20e68a1
Exit tests non-zero status code on error.
davidlehn Jun 23, 2023
abdcb51
Refactor more test code to async/await.
davidlehn Jun 23, 2023
8f1e48c
Fix throw style.
davidlehn Jun 23, 2023
0005994
Throw on unknown test type.
davidlehn Jun 23, 2023
d5ba6ea
Update dependencies.
davidlehn Jun 23, 2023
767b2dc
Add eslint jsdoc support.
davidlehn Jun 23, 2023
1ddbfb3
Change "URDNA2015" to "RDFC-1.0" to match spec.
davidlehn Jun 22, 2023
7d24e1a
Imrpove URDNA2015 support.
davidlehn Jun 23, 2023
788e0f5
Update changelog and docs.
davidlehn Jun 23, 2023
b9110a1
Escape and unescape data, support 8 char unicode.
davidlehn Mar 1, 2023
639eb20
Update to latest rdf-canon N-Quads canonical form.
davidlehn Apr 19, 2023
d78fdc3
Update canonical output warning.
davidlehn May 3, 2023
b9a38c7
Optimize N-Quads escape replacement.
davidlehn Apr 19, 2023
47b3297
Fix changelog typos.
davidlehn Jun 22, 2023
e4f57bc
Fix lint issues.
davidlehn Jun 23, 2023
20e1e37
Fix test name.
davidlehn Jun 23, 2023
7ea0b02
Fix trace mode typo.
davidlehn Jun 23, 2023
620466c
Remove support for legacy dataset format.
davidlehn Aug 25, 2023
729109c
Update URL to https.
davidlehn Aug 25, 2023
bcb94e0
Add complexity control.
davidlehn Aug 26, 2023
3b2f353
Add missing option doc.
davidlehn Aug 26, 2023
4d04cf9
Update 4.7 code to match spec.
davidlehn Aug 26, 2023
492950a
Fix typo.
davidlehn Aug 26, 2023
ba09d1f
Cleanups.
davidlehn Aug 26, 2023
f2b7471
Fix test datasets.
davidlehn Aug 26, 2023
181782d
Update test runner.
davidlehn Aug 26, 2023
032b4eb
Remove internal `_:` prefix from `BlankNodes`.
davidlehn Aug 26, 2023
1ecc176
Add complexity tests.
davidlehn Aug 26, 2023
2029bf4
Support hash algorithm option.
davidlehn Sep 1, 2023
5dddfd5
Check output `format` parameter.
davidlehn Sep 15, 2023
1199841
Update `inputFormat` handling.
davidlehn Sep 15, 2023
d7735b9
Add API parameter tests.
davidlehn Sep 15, 2023
00535fe
Update examples.
davidlehn Sep 15, 2023
0f0866b
Update complexity controls.
davidlehn Sep 15, 2023
b1815d6
Fix typo and cleanup formating.
davidlehn Sep 15, 2023
5f16971
Support generalized RDF N-Quads serialization.
davidlehn Sep 15, 2023
efb97cc
Cleanups and fix typos.
davidlehn Sep 19, 2023
2c74677
Update changelog.
davidlehn Sep 19, 2023
69bccd4
Change maximum deep iterations error text.
davidlehn Sep 19, 2023
54c7578
Fix typo.
davidlehn Sep 19, 2023
a8b9536
Test and coverage updates.
davidlehn Sep 19, 2023
8e19406
Internal rename from URDNA2015 to RDFC10.
davidlehn Sep 15, 2023
beabb51
Fix package description.
davidlehn Sep 15, 2023
dff263d
Add EARL Turtle test result mode.
davidlehn Sep 15, 2023
489c6ba
Add React Native support and instructions.
dmitrizagidulin Aug 11, 2023
98082a4
Rephrase polyfill instructions.
dmitrizagidulin Aug 18, 2023
79ba207
Update README.md (remove TextDecoder).
dmitrizagidulin Aug 21, 2023
c583247
Move RN usage to Examples section.
dmitrizagidulin Aug 22, 2023
d65b18a
Remove support for Node.js < 18.
davidlehn Sep 19, 2023
934544c
Replace `delay` with built-in `setTimeout`.
davidlehn Sep 19, 2023
25a9fd7
Update dependencies.
davidlehn Sep 19, 2023
cf3643c
Remove debugging.
davidlehn Oct 5, 2023
758d29c
Add tests.
davidlehn Oct 5, 2023
a01c5ae
Add `EARL_OFFICIAL` env var.
davidlehn Oct 5, 2023
5a0de35
Update dependencies.
davidlehn Nov 16, 2023
c998bc7
Cleanup changelog.
davidlehn Nov 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ module.exports = {
node: true
},
extends: [
'digitalbazaar'
'digitalbazaar',
'digitalbazaar/jsdoc'
],
rules: {
'jsdoc/require-description-complete-sentence': 'off'
},
ignorePatterns: [
'test-suites'
]
Expand Down
26 changes: 13 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
node-version: [18.x]
node-version: [20.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand All @@ -23,11 +23,11 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install
Expand All @@ -41,12 +41,12 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
node-version: [18.x]
node-version: [20.x]
bundler: [webpack, browserify]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install
Expand All @@ -63,11 +63,11 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
node-version: [18.x]
node-version: [20.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install
Expand All @@ -77,7 +77,7 @@ jobs:
- name: Generate coverage report
run: npm run coverage-ci
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
file: ./coverage/lcov.info
fail_ci_if_error: true
45 changes: 42 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,38 @@

### Added
- Test with karma.
- Test with Node.js 20.x.
- Add `inputFormat` option. Use "application/n-quads" for a N-Quads string that
will be parsed. Omit option for a JSON dataset or legacy dataset. This can
simplify a common case of using the internal parser to generate a dataset.
- **NOTE**: The `inputFormat` option was previously ignored and is now used.
Any calling code that was passing in an incorrect value needs to be fixed.

### Changed
- **BREAKING**: Change algorithm name from "URDNA2015" to "RDFC-1.0" to match
spec changes. Use of "URDNA2015" is now deprecated and an alias for
"RDFC-1.0". An API option `rejectURDNA2015` is available to disable
"URDNA2015" support. A global `RDF_CANONIZE_TRACE_URDNA2015` is available to
developers to trace calls that use "URDNA2015". See the README for important
compatibility notes and API details.
- **BREAKING**: Use latest [rdf-canon][] N-Quads canonical form. This can
change the canonical output! There is an expanded set of literal string
control characters that are escaped as an `ECHAR` or `UCHAR` instead of using
a native representation.
- Previously: the canonical N-Quads form used here was encoding `\u000A`
(`\n`), `\u000D` (`\r`), `\u0022` (`"`), and `\u005C` (`\`) as `ECHARs`:
`\n`, `\r`, `\"`, and `\\`, All other characters were represented as native
Unicode.
- Now: the output also encodes `\u0008` (`\b`), `\u0009` (`\t`), `\u000C`
(`\f`) as `ECHARs` `\b`, `\t`, and `\f`, and encodes the "control"
characters in the range of `\u0000-\u001F` and `\u007F` as `UCHARs`
`\u00xx`. All other characters are represented as native Unicode.
- **BREAKING**: Use `globalThis` to access `crypto` in browsers. Use a polyfill
if your environment doesn't support `globalThis`.
- Update tooling.
- Update for latest [rdf-canon][] changes: test suite location, README, links,
and identifiers.
- More closly align test code with the version in [jsonld.js][].
- More closely align test code with the version in [jsonld.js][].
- Use combined test/benchmark system.
- Support running multiple test jobs in parallel.
- Refactor `MessageDigest-browser.js` to `MessageDigest-webcrypto.js` so it can
Expand All @@ -22,17 +46,23 @@
- Node.js using the improved browser algorithm can be ~4-9% faster overall.
- Node.js native `Buffer` conversion can be ~5-12% faster overall.
- Optimize a N-Quads serialization call.
- Optimize N-Quads escape/unescape:
- Optimize N-Quads escape/unescape calling replace:
- Run regex test before doing a replace call.
- Performance difference depends on data and how often escape/unescape would
need to be called. A benchmark test data showed ~3-5% overall improvement.
- Optimize N-Quads escape replacement:
- Use a pre-computed map of replacement values.
- Performance difference depends on the number of replacements. The
[rdf-canon][] escaping test showed up to 15% improvement.

### Fixed
- Disable native lib tests in a browser.
- Disable sync tests in a browser. The sync code attempts to use the async
webcrypto calls and produces invalid results. It is an error that this
doesn't fail, but sync code is currently only for testing.
- Fix various testing and benchmark bugs.
- Escape and unescape all data.
- Support 8 hex char Unicode values.

### Removed
- **BREAKING**: Remove URGNA2012 support. [rdf-canon][] no longer supports or
Expand All @@ -45,6 +75,15 @@
- Remove `benchmark/benchmark.js` tool in favor of combined test system and
benchmarking control via environment vars.

## 3.4.0 - 2023-05-19

### Added
- Allow `canonicalIdMap` to be passed to `canonize` which will be populated by
the canonical identifier issuer with the bnode identifier mapping generated
by the canonicalization algorithm. This feature is particularly useful when
the resulting bnode labels need to be changed for use cases such as selective
disclosure.

## 3.3.0 - 2022-09-17

### Added
Expand Down Expand Up @@ -159,7 +198,7 @@
### Changed
- Improve N-Quads parsing.
- Unescape literals.
- Handle unicode escapes.
- Handle Unicode escapes.
- N-Quad serialization optimization.
- Varies based on input by roughly ~1-2x.
- **BREAKING**: Remove `rdf-canonize-native` as a dependency. The native
Expand Down
49 changes: 44 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
[![Build status](https://img.shields.io/github/actions/workflow/status/digitalbazaar/rdf-canonize/main.yml)](https://github.com/digitalbazaar/rdf-canonize/actions/workflows/main.yml)
[![Coverage status](https://img.shields.io/codecov/c/github/digitalbazaar/rdf-canonize)](https://codecov.io/gh/digitalbazaar/rdf-canonize)

An implementation of the [RDF Dataset Canonicalization Algorithm][] in JavaScript.
An implementation of the [RDF Dataset Canonicalization][] specification in
JavaScript.

Introduction
------------

...
See the [RDF Dataset Canonicalization][] specification for details on the
specification and algorithm this library implements.

Installation
------------
Expand Down Expand Up @@ -60,16 +62,50 @@ const dataset = {
};

// canonize a data set with a particular algorithm with async/await
const canonical = await canonize.canonize(dataset, {algorithm: 'URDNA2015'});
const canonical = await canonize.canonize(dataset, {algorithm: 'RDFC-1.0'});

// canonize a data set with a particular algorithm and force use of the
// native implementation
const canonical = await canonize.canonize(dataset, {
algorithm: 'URDNA2015',
algorithm: 'RDFC-1.0',
useNative: true
});
```

Algorithm Support
-----------------

* "[RDFC-1.0][]": Supported.
* Primary algorithm in the [RDF Dataset Canonicalization][] specification.
* "[URDNA2015][]": Deprecated and supported as an alias for "RDFC-1.0".
* Former algorithm name that evolved into "RDFC-1.0".
* **NOTE**: There are minor differences in the [canonical N-Quads
form](https://w3c.github.io/rdf-canon/spec/#canonical-quads) that *could*
cause canonical output differences in some cases. See the 4.0.0 changelog
or code for details. If strict "URDNA2015" support is required, use a 3.x
version of this library.
* See the migration section below if you have code that uses the "URDNA2015"
algorithm name.
* "[URGNA2012][]": No longer supported.
* Older algorithm with significant differences from newer algorithms.
* Use older versions versions of this library if support is needed.

URDNA2015 Migration
-------------------

* The deprecated "URDNA2015" algorithm name is currently supported as an alias
for "RDFC-1.0".
* There is a minor difference that could cause compatibilty issues. It is
considered an edge case that will not be an issue in practice. See above for
details.
* Two tools are currently provided to help transition to "RDFC-1.0":
* If the API option `rejectURDNA2015` is truthy, it will cause an error to be
thrown if "URDNA2015" is used.
* If the global `RDF_CANONIZE_TRACE_URDNA2015` is truthy, it will cause
`console.trace()` to be called when "URDNA2015" is used. This is designed
for *development use only* to find where "URDNA2015" is being used. It
could be *very* verbose.

Related Modules
---------------

Expand Down Expand Up @@ -127,6 +163,9 @@ Commercial support for this library is available upon request from

[Digital Bazaar]: https://digitalbazaar.com/
[JSON-LD]: https://json-ld.org/
[RDF Dataset Canonicalization Algorithm]: https://w3c.github.io/rdf-canon/spec/
[RDF Dataset Canonicalization]: https://w3c.github.io/rdf-canon/spec/
[RDFC-1.0]: https://w3c.github.io/rdf-canon/spec/
[URDNA2015]: https://w3c.github.io/rdf-canon/spec/#urdna2015
[URGNA2012]: https://w3c.github.io/rdf-canon/spec/#urgna2012
[jsonld.js]: https://github.com/digitalbazaar/jsonld.js
[rdf-canonize-native]: https://github.com/digitalbazaar/rdf-canonize-native
2 changes: 1 addition & 1 deletion bench-nsolid.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const KEYS = ['subject', 'predicate', 'object', 'graph'];
//const count = 1000000; // ~30 secs
for(let i = 0; i < count; ++i) {
/*const result = */await canonize(quads, {
algorithm: 'URDNA2015',
algorithm: 'RDFC-1.0',
usePureJavaScript: true
});
//console.log(result);
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function(config) {
preprocessors.push(bundler);
preprocessors.push('sourcemap');
} else {
throw Error('Unknown bundler');
throw new Error('Unknown bundler');
}

config.set({
Expand Down
21 changes: 11 additions & 10 deletions lib/IdentifierIssuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ module.exports = class IdentifierIssuer {
* Creates a new IdentifierIssuer. A IdentifierIssuer issues unique
* identifiers, keeping track of any previously issued identifiers.
*
* @param prefix the prefix to use ('<prefix><counter>').
* @param existing an existing Map to use.
* @param counter the counter to use.
* @param {string} prefix - The prefix to use ('<prefix><counter>').
* @param {Map} [existing] - An existing Map to use.
* @param {number} [counter] - The counter to use.
*/
constructor(prefix, existing = new Map(), counter = 0) {
this.prefix = prefix;
Expand All @@ -21,7 +21,7 @@ module.exports = class IdentifierIssuer {
/**
* Copies this IdentifierIssuer.
*
* @return a copy of this IdentifierIssuer.
* @returns {object} - A copy of this IdentifierIssuer.
*/
clone() {
const {prefix, _existing, counter} = this;
Expand All @@ -32,9 +32,9 @@ module.exports = class IdentifierIssuer {
* Gets the new identifier for the given old identifier, where if no old
* identifier is given a new identifier will be generated.
*
* @param [old] the old identifier to get the new identifier for.
* @param {string} [old] - The old identifier to get the new identifier for.
*
* @return the new identifier.
* @returns {string} - The new identifier.
*/
getId(old) {
// return existing old identifier
Expand All @@ -59,10 +59,10 @@ module.exports = class IdentifierIssuer {
* Returns true if the given old identifer has already been assigned a new
* identifier.
*
* @param old the old identifier to check.
* @param {string} old - The old identifier to check.
*
* @return true if the old identifier has been assigned a new identifier,
* false if not.
* @returns {boolean} - True if the old identifier has been assigned a new
* identifier, false if not.
*/
hasId(old) {
return this._existing.has(old);
Expand All @@ -72,7 +72,8 @@ module.exports = class IdentifierIssuer {
* Returns all of the IDs that have been issued new IDs in the order in
* which they were issued new IDs.
*
* @return the list of old IDs that has been issued new IDs in order.
* @returns {Array} - The list of old IDs that has been issued new IDs in
* order.
*/
getOldIds() {
return [...this._existing.keys()];
Expand Down
2 changes: 1 addition & 1 deletion lib/MessageDigest-webcrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = class MessageDigest {
/**
* Creates a new WebCrypto API MessageDigest.
*
* @param algorithm the algorithm to use.
* @param {string} algorithm - The algorithm to use.
*/
constructor(algorithm) {
// check if crypto.subtle is available
Expand Down
2 changes: 1 addition & 1 deletion lib/MessageDigest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = class MessageDigest {
/**
* Creates a new MessageDigest.
*
* @param algorithm the algorithm to use.
* @param {string} algorithm - The algorithm to use.
*/
constructor(algorithm) {
this.md = crypto.createHash(algorithm);
Expand Down
Loading