diff --git a/CHANGELOG.md b/CHANGELOG.md index f218eca..605500e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/canonize.js b/lib/canonize.js index 868c257..26b8937 100644 --- a/lib/canonize.js +++ b/lib/canonize.js @@ -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); } diff --git a/package.json b/package.json index 1c8ebac..5634c4c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/Ecdsa2019Cryptosuite.spec.js b/test/Ecdsa2019Cryptosuite.spec.js index 8ea2e13..2443fc0 100644 --- a/test/Ecdsa2019Cryptosuite.spec.js +++ b/test/Ecdsa2019Cryptosuite.spec.js @@ -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'; @@ -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; @@ -40,6 +40,7 @@ describe('Ecdsa2019Cryptosuite', () => { result = await ecdsa2019Cryptosuite.canonize( unsignedCredential, {documentLoader}); } catch(e) { + console.log('e', e); error = e; }