Skip to content

Commit e4a60a4

Browse files
committed
Use rdf-canonize directly to use RDFC-1.0 algorithm.
1 parent 9e9e2af commit e4a60a4

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# @digitalbazaar/ecdsa-rdfc-2019-cryptosuite Changelog
22

3+
## 1.1.0 - 2024-08-dd
4+
5+
### Changed
6+
- Use `rdf-canonize` directly to use `RDFC-1.0` algorithm.
7+
38
## 1.0.1 - 2023-11-13
49

510
### Fixed

lib/canonize.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
/*!
2-
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
2+
* Copyright (c) 2023-2024 Digital Bazaar, Inc. All rights reserved.
33
*/
4+
import * as rdfCanonize from 'rdf-canonize';
45
import jsonld from 'jsonld';
56

67
export async function canonize(input, options) {
7-
return jsonld.canonize(input, {
8-
algorithm: 'URDNA2015',
8+
// convert to RDF dataset and do canonicalization
9+
options = {
10+
algorithm: 'RDFC-1.0',
911
format: 'application/n-quads',
12+
base: null,
13+
safe: true,
1014
...options
11-
});
15+
};
16+
const opts = {...options, produceGeneralizedRdf: false};
17+
delete opts.format;
18+
opts.produceGeneralizedRdf = false;
19+
const dataset = await jsonld.toRDF(input, opts);
20+
return rdfCanonize.canonize(dataset, options);
1221
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
],
1616
"dependencies": {
1717
"@digitalbazaar/ecdsa-multikey": "^1.6.0",
18-
"jsonld": "^8.3.1"
18+
"jsonld": "^8.3.1",
19+
"rdf-canonize": "^4.0.1"
1920
},
2021
"devDependencies": {
2122
"@digitalbazaar/data-integrity": "^2.0.0",
2223
"@digitalbazaar/data-integrity-context": "^2.0.0",
23-
"@digitalbazaar/multikey-context": "^1.0.0",
24+
"@digitalbazaar/multikey-context": "^2.0.1",
2425
"@digitalbazaar/security-document-loader": "^2.0.0",
2526
"c8": "^7.11.3",
2627
"chai": "^4.3.6",

test/Ecdsa2019Cryptosuite.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
2+
* Copyright (c) 2023-2024 Digital Bazaar, Inc. All rights reserved.
33
*/
44
import {expect} from 'chai';
55

@@ -31,7 +31,7 @@ describe('Ecdsa2019Cryptosuite', () => {
3131
});
3232

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

3737
let result;
@@ -40,6 +40,7 @@ describe('Ecdsa2019Cryptosuite', () => {
4040
result = await ecdsa2019Cryptosuite.canonize(
4141
unsignedCredential, {documentLoader});
4242
} catch(e) {
43+
console.log('e', e);
4344
error = e;
4445
}
4546

0 commit comments

Comments
 (0)