Skip to content

Commit

Permalink
Use rdf-canonize directly to use RDFC-1.0 algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Aug 1, 2024
1 parent 9e9e2af commit e4a60a4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# @digitalbazaar/ecdsa-rdfc-2019-cryptosuite Changelog

## 1.1.0 - 2024-08-dd

### Changed
- Use `rdf-canonize` directly to use `RDFC-1.0` algorithm.

## 1.0.1 - 2023-11-13

### Fixed
Expand Down
17 changes: 13 additions & 4 deletions lib/canonize.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
/*!
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2023-2024 Digital Bazaar, Inc. All rights reserved.
*/
import * as rdfCanonize from 'rdf-canonize';
import jsonld from 'jsonld';

export async function canonize(input, options) {
return jsonld.canonize(input, {
algorithm: 'URDNA2015',
// convert to RDF dataset and do canonicalization
options = {
algorithm: 'RDFC-1.0',
format: 'application/n-quads',
base: null,
safe: true,
...options
});
};
const opts = {...options, produceGeneralizedRdf: false};
delete opts.format;
opts.produceGeneralizedRdf = false;
const dataset = await jsonld.toRDF(input, opts);
return rdfCanonize.canonize(dataset, options);
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
],
"dependencies": {
"@digitalbazaar/ecdsa-multikey": "^1.6.0",
"jsonld": "^8.3.1"
"jsonld": "^8.3.1",
"rdf-canonize": "^4.0.1"
},
"devDependencies": {
"@digitalbazaar/data-integrity": "^2.0.0",
"@digitalbazaar/data-integrity-context": "^2.0.0",
"@digitalbazaar/multikey-context": "^1.0.0",
"@digitalbazaar/multikey-context": "^2.0.1",
"@digitalbazaar/security-document-loader": "^2.0.0",
"c8": "^7.11.3",
"chai": "^4.3.6",
Expand Down
5 changes: 3 additions & 2 deletions test/Ecdsa2019Cryptosuite.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2023-2024 Digital Bazaar, Inc. All rights reserved.
*/
import {expect} from 'chai';

Expand Down Expand Up @@ -31,7 +31,7 @@ describe('Ecdsa2019Cryptosuite', () => {
});

describe('canonize()', () => {
it('should canonize using URDNA2015 w/ n-quads', async () => {
it('should canonize using RDFC-1.0 w/ n-quads', async () => {
const unsignedCredential = JSON.parse(JSON.stringify(credential));

let result;
Expand All @@ -40,6 +40,7 @@ describe('Ecdsa2019Cryptosuite', () => {
result = await ecdsa2019Cryptosuite.canonize(
unsignedCredential, {documentLoader});
} catch(e) {
console.log('e', e);
error = e;
}

Expand Down

0 comments on commit e4a60a4

Please sign in to comment.