Socket
Socket
Sign inDemoInstall

rdf-canonize

Package Overview
Dependencies
1
Maintainers
4
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.1 to 3.3.0

96

lib/index.js

@@ -6,3 +6,3 @@ /**

* BSD 3-Clause License
* Copyright (c) 2016-2021 Digital Bazaar, Inc.
* Copyright (c) 2016-2022 Digital Bazaar, Inc.
* All rights reserved.

@@ -49,8 +49,5 @@ *

const api = {};
module.exports = api;
// expose helpers
api.NQuads = require('./NQuads');
api.IdentifierIssuer = require('./IdentifierIssuer');
exports.NQuads = require('./NQuads');
exports.IdentifierIssuer = require('./IdentifierIssuer');

@@ -64,3 +61,3 @@ /**

*/
api._rdfCanonizeNative = function(api) {
exports._rdfCanonizeNative = function(api) {
if(api) {

@@ -75,20 +72,25 @@ rdfCanonizeNative = api;

*
* @param dataset the dataset to canonize.
* @param options the options to use:
* algorithm the canonicalization algorithm to use, `URDNA2015` or
* `URGNA2012`.
* [useNative] use native implementation (default: false).
* [maxDeepIterations=Infinity] the maximum number of times to run
* deep comparison algorithms (such as the N-Degree Hash Quads
* algorithm used in URDNA2015) before bailing out and throwing an
* error; this is a useful setting for preventing wasted CPU cycles
* or DoS when canonizing meaningless or potentially malicious
* datasets, a recommended value is `1`.
* @param {Array} dataset - The dataset to canonize.
* @param {object} options - The options to use:
* {string} algorithm - The canonicalization algorithm to use, `URDNA2015` or
* `URGNA2012`.
* {Function} [createMessageDigest] - A factory function for creating a
* `MessageDigest` interface that overrides the built-in message digest
* implementation used by the canonize algorithm; note that using a hash
* algorithm (or HMAC algorithm) that differs from the one specified by
* the canonize algorithm will result in different output.
* {boolean} [useNative=false] - Use native implementation.
* {number} [maxDeepIterations=Infinity] - The maximum number of times to run
* deep comparison algorithms (such as the N-Degree Hash Quads algorithm
* used in URDNA2015) before bailing out and throwing an error; this is a
* useful setting for preventing wasted CPU cycles or DoS when canonizing
* meaningless or potentially malicious datasets, a recommended value is
* `1`.
*
* @return a Promise that resolves to the canonicalized RDF Dataset.
*/
api.canonize = async function(dataset, options) {
exports.canonize = async function(dataset, options) {
// back-compat with legacy dataset
if(!Array.isArray(dataset)) {
dataset = api.NQuads.legacyDatasetToQuads(dataset);
dataset = exports.NQuads.legacyDatasetToQuads(dataset);
}

@@ -100,3 +102,6 @@

}
// TODO: convert native algorithm to Promise-based async
if(options.createMessageDigest) {
throw new Error(
'"createMessageDigest" cannot be used with "useNative".');
}
return new Promise((resolve, reject) =>

@@ -111,2 +116,6 @@ rdfCanonizeNative.canonize(dataset, options, (err, canonical) =>

if(options.algorithm === 'URGNA2012') {
if(options.createMessageDigest) {
throw new Error(
'"createMessageDigest" cannot be used with "URGNA2012".');
}
return new URGNA2012(options).main(dataset);

@@ -126,27 +135,36 @@ }

*
* @param dataset the dataset to canonize.
* @param options the options to use:
* algorithm the canonicalization algorithm to use, `URDNA2015` or
* `URGNA2012`.
* [useNative] use native implementation (default: false).
* [maxDeepIterations=Infinity] the maximum number of times to run
* deep comparison algorithms (such as the N-Degree Hash Quads
* algorithm used in URDNA2015) before bailing out and throwing an
* error; this is a useful setting for preventing wasted CPU cycles
* or DoS when canonizing meaningless or potentially malicious
* datasets, a recommended value is `1`.
* @param {Array} dataset - The dataset to canonize.
* @param {object} options - The options to use:
* {string} algorithm - The canonicalization algorithm to use, `URDNA2015` or
* `URGNA2012`.
* {Function} [createMessageDigest] - A factory function for creating a
* `MessageDigest` interface that overrides the built-in message digest
* implementation used by the canonize algorithm; note that using a hash
* algorithm (or HMAC algorithm) that differs from the one specified by
* the canonize algorithm will result in different output.
* {boolean} [useNative=false] - Use native implementation.
* {number} [maxDeepIterations=Infinity] - The maximum number of times to run
* deep comparison algorithms (such as the N-Degree Hash Quads algorithm
* used in URDNA2015) before bailing out and throwing an error; this is a
* useful setting for preventing wasted CPU cycles or DoS when canonizing
* meaningless or potentially malicious datasets, a recommended value is
* `1`.
*
* @return the RDF dataset in canonical form.
*/
api._canonizeSync = function(dataset, options) {
exports._canonizeSync = function(dataset, options) {
// back-compat with legacy dataset
if(!Array.isArray(dataset)) {
dataset = api.NQuads.legacyDatasetToQuads(dataset);
dataset = exports.NQuads.legacyDatasetToQuads(dataset);
}
if(options.useNative) {
if(rdfCanonizeNative) {
return rdfCanonizeNative.canonizeSync(dataset, options);
if(!rdfCanonizeNative) {
throw new Error('rdf-canonize-native not available');
}
throw new Error('rdf-canonize-native not available');
if(options.createMessageDigest) {
throw new Error(
'"createMessageDigest" cannot be used with "useNative".');
}
return rdfCanonizeNative.canonizeSync(dataset, options);
}

@@ -157,2 +175,6 @@ if(options.algorithm === 'URDNA2015') {

if(options.algorithm === 'URGNA2012') {
if(options.createMessageDigest) {
throw new Error(
'"createMessageDigest" cannot be used with "URGNA2012".');
}
return new URGNA2012Sync(options).main(dataset);

@@ -159,0 +181,0 @@ }

@@ -1,3 +0,3 @@

/*
* Copyright (c) 2016-2021 Digital Bazaar, Inc. All rights reserved.
/*!
* Copyright (c) 2016-2022 Digital Bazaar, Inc. All rights reserved.
*/

@@ -10,4 +10,2 @@ 'use strict';

// TODO: synchronous version no longer supported in browser
module.exports = class MessageDigest {

@@ -14,0 +12,0 @@ /**

@@ -1,3 +0,3 @@

/*
* Copyright (c) 2016-2021 Digital Bazaar, Inc. All rights reserved.
/*!
* Copyright (c) 2016-2022 Digital Bazaar, Inc. All rights reserved.
*/

@@ -4,0 +4,0 @@ 'use strict';

@@ -1,8 +0,6 @@

/*
* Copyright (c) 2016-2021 Digital Bazaar, Inc. All rights reserved.
/*!
* Copyright (c) 2016-2022 Digital Bazaar, Inc. All rights reserved.
*/
'use strict';
// TODO: convert to ES6 iterable?
module.exports = class Permuter {

@@ -9,0 +7,0 @@ /**

@@ -1,2 +0,2 @@

/*
/*!
* Copyright (c) 2016-2022 Digital Bazaar, Inc. All rights reserved.

@@ -12,7 +12,10 @@ */

module.exports = class URDNA2015 {
constructor({maxDeepIterations = Infinity} = {}) {
constructor({
createMessageDigest = () => new MessageDigest('sha256'),
maxDeepIterations = Infinity
} = {}) {
this.name = 'URDNA2015';
this.blankNodeInfo = new Map();
this.canonicalIssuer = new IdentifierIssuer('_:c14n');
this.hashAlgorithm = 'sha256';
this.createMessageDigest = createMessageDigest;
this.maxDeepIterations = maxDeepIterations;

@@ -208,3 +211,3 @@ this.quads = null;

// through the hash algorithm.
const md = new MessageDigest(this.hashAlgorithm);
const md = this.createMessageDigest();
for(const nquad of nquads) {

@@ -234,3 +237,3 @@ md.update(nquad);

// Note: We use a hash object instead.
const md = new MessageDigest(this.hashAlgorithm);
const md = this.createMessageDigest();
md.update(position);

@@ -264,3 +267,3 @@

// Note: 2) and 3) handled within `createHashToRelated`
const md = new MessageDigest(this.hashAlgorithm);
const md = this.createMessageDigest();
const hashToRelated = await this.createHashToRelated(id, issuer);

@@ -267,0 +270,0 @@

@@ -1,2 +0,2 @@

/*
/*!
* Copyright (c) 2016-2022 Digital Bazaar, Inc. All rights reserved.

@@ -7,2 +7,4 @@ */

const IdentifierIssuer = require('./IdentifierIssuer');
// FIXME: do not import; convert to requiring a
// hash factory
const MessageDigest = require('./MessageDigest');

@@ -13,7 +15,10 @@ const Permuter = require('./Permuter');

module.exports = class URDNA2015Sync {
constructor({maxDeepIterations = Infinity} = {}) {
constructor({
createMessageDigest = () => new MessageDigest('sha256'),
maxDeepIterations = Infinity
} = {}) {
this.name = 'URDNA2015';
this.blankNodeInfo = new Map();
this.canonicalIssuer = new IdentifierIssuer('_:c14n');
this.hashAlgorithm = 'sha256';
this.createMessageDigest = createMessageDigest;
this.maxDeepIterations = maxDeepIterations;

@@ -204,3 +209,3 @@ this.quads = null;

// through the hash algorithm.
const md = new MessageDigest(this.hashAlgorithm);
const md = this.createMessageDigest();
for(const nquad of nquads) {

@@ -230,3 +235,3 @@ md.update(nquad);

// Note: We use a hash object instead.
const md = new MessageDigest(this.hashAlgorithm);
const md = this.createMessageDigest();
md.update(position);

@@ -260,3 +265,3 @@

// Note: 2) and 3) handled within `createHashToRelated`
const md = new MessageDigest(this.hashAlgorithm);
const md = this.createMessageDigest();
const hashToRelated = this.createHashToRelated(id, issuer);

@@ -263,0 +268,0 @@

@@ -1,6 +0,7 @@

/*
* Copyright (c) 2016-2021 Digital Bazaar, Inc. All rights reserved.
/*!
* Copyright (c) 2016-2022 Digital Bazaar, Inc. All rights reserved.
*/
'use strict';
const MessageDigest = require('./MessageDigest');
const URDNA2015 = require('./URDNA2015');

@@ -12,3 +13,3 @@

this.name = 'URGNA2012';
this.hashAlgorithm = 'sha1';
this.createMessageDigest = () => new MessageDigest('sha1');
}

@@ -15,0 +16,0 @@

@@ -1,2 +0,2 @@

/*
/*!
* Copyright (c) 2016-2021 Digital Bazaar, Inc. All rights reserved.

@@ -6,2 +6,3 @@ */

const MessageDigest = require('./MessageDigest');
const URDNA2015Sync = require('./URDNA2015Sync');

@@ -13,3 +14,3 @@

this.name = 'URGNA2012';
this.hashAlgorithm = 'sha1';
this.createMessageDigest = () => new MessageDigest('sha1');
}

@@ -16,0 +17,0 @@

{
"name": "rdf-canonize",
"version": "3.2.1",
"version": "3.3.0",
"description": "An implementation of the RDF Dataset Normalization Algorithm in JavaScript",

@@ -54,3 +54,3 @@ "homepage": "https://github.com/digitalbazaar/rdf-canonize",

"scripts": {
"fetch-test-suite": "if [ ! -e test-suites/rdf-dataset-canonicalization ]; then git clone --depth 1 https://github.com/json-ld/rdf-dataset-canonicalization.git test-suites/rdf-dataset-canonicalization; fi",
"fetch-test-suite": "if [ ! -e test-suites/rdf-dataset-canonicalization ]; then git clone --depth 1 https://github.com/w3c-ccg/rdf-dataset-canonicalization.git test-suites/rdf-dataset-canonicalization; fi",
"test": "npm run test-node",

@@ -57,0 +57,0 @@ "test-node": "NODE_ENV=test mocha -R spec --check-leaks",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc