Skip to content

Commit

Permalink
Use rdf-canonize library directly to use RDFC-1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Aug 1, 2024
1 parent 567c8cf commit fc2518e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ jobs:
- name: Generate coverage report
run: npm run coverage-ci
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
with:
file: ./coverage/lcov.info
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# jsonld-signatures ChangeLog

## 11.3.0 - 2024-08-dd

### Changed
- Use `rdf-canonize` directly to get latest updates and avoid reliance
on `jsonld` package to provide it indirectly.

## 11.2.1 - 2023-05-14

### Fixed
Expand Down
16 changes: 13 additions & 3 deletions lib/suites/LinkedDataSignature.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*!
* Copyright (c) 2017-2023 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2017-2024 Digital Bazaar, Inc. All rights reserved.
*/
'use strict';

const constants = require('../constants');
const jsonld = require('jsonld');
const rdfCanonize = require('rdf-canonize');
const util = require('../util');
const {sha256digest} = require('../sha256digest');
const LinkedDataProof = require('./LinkedDataProof');
Expand Down Expand Up @@ -212,8 +213,8 @@ module.exports = class LinkedDataSignature extends LinkedDataProof {
if(expansionMap) {
throw new Error('"expansionMap" not supported.');
}
return jsonld.canonize(input, {
algorithm: 'URDNA2015',
return _canonize(input, {
algorithm: 'RDFC-1.0',
// do not resolve any relative URLs or terms, throw errors instead
base: null,
format: 'application/n-quads',
Expand Down Expand Up @@ -460,3 +461,12 @@ function _processSignatureParams({key, signer, verifier}) {

return vm;
}

async function _canonize(input, options) {
// convert to RDF dataset and do canonicalization
const opts = {...options};
delete opts.format;
opts.produceGeneralizedRdf = false;
const dataset = await jsonld.toRDF(input, opts);
return rdfCanonize.canonize(dataset, options);
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dependencies": {
"@digitalbazaar/security-context": "^1.0.0",
"jsonld": "^8.0.0",
"rdf-canonize": "^4.0.1",
"serialize-error": "^8.1.0"
},
"devDependencies": {
Expand All @@ -51,7 +52,7 @@
"webpack": "^5.73.0"
},
"engines": {
"node": ">=14"
"node": ">=18"
},
"keywords": [
"JSON",
Expand Down

0 comments on commit fc2518e

Please sign in to comment.