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

Use rdf-canonize library directly to use RDFC-1.0. #181

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 13 additions & 12 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: [16.x]
node-version: [20.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- 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 @@ -24,11 +24,11 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- 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 @@ -42,9 +42,9 @@ jobs:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- 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 @@ -56,18 +56,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
node-version: [20.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- 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
- 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
Loading