jsonld-signatures
Advanced tools
Comparing version 10.0.0 to 11.0.0
/*! | ||
* Copyright (c) 2010-2018 Digital Bazaar, Inc. All rights reserved. | ||
* Copyright (c) 2010-2022 Digital Bazaar, Inc. All rights reserved. | ||
*/ | ||
@@ -40,7 +40,3 @@ 'use strict'; | ||
* | ||
* @param {function} [options.expansionMap] - A custom expansion map that is | ||
* passed to the JSON-LD processor; by default a function that will throw | ||
* an error when unmapped properties are detected in the input, use `false` | ||
* to turn this off and allow unmapped properties to be dropped or use a | ||
* custom function. | ||
* @param {function} [options.expansionMap] - NOT SUPPORTED; do not use. | ||
* @param {boolean} [options.addSuiteContext=true] - Toggles the default | ||
@@ -55,2 +51,5 @@ * behavior of each signature suite enforcing the presence of its own | ||
} = {}) { | ||
if(expansionMap) { | ||
throw new Error('"expansionMap" not supported.'); | ||
} | ||
if(typeof document !== 'object') { | ||
@@ -65,4 +64,3 @@ throw new TypeError('The "document" parameter must be an object.'); | ||
try { | ||
return await new ProofSet().add( | ||
document, {suite, purpose, documentLoader, expansionMap}); | ||
return await new ProofSet().add(document, {suite, purpose, documentLoader}); | ||
} catch(e) { | ||
@@ -87,3 +85,4 @@ if(!documentLoader && e.name === 'jsonld.InvalidUrl') { | ||
* | ||
* @param {LinkedDataSignature|LinkedDataSignature[]} suite - | ||
* @param {object} options - The options to use. | ||
* @param {LinkedDataSignature|LinkedDataSignature[]} options.suite - | ||
* Acceptable signature suite instances for verifying the proof(s). | ||
@@ -97,9 +96,5 @@ * | ||
* | ||
* @param {function} [documentLoader] - A custom document loader, | ||
* @param {function} [options.documentLoader] - A custom document loader, | ||
* `Promise<RemoteDocument> documentLoader(url)`. | ||
* @param {function} [expansionMap] - A custom expansion map that is | ||
* passed to the JSON-LD processor; by default a function that will throw | ||
* an error when unmapped properties are detected in the input, use `false` | ||
* to turn this off and allow unmapped properties to be dropped or use a | ||
* custom function. | ||
* @param {function} [options.expansionMap] - NOT SUPPORTED; do not use. | ||
* | ||
@@ -115,3 +110,7 @@ * @return {Promise<{verified: boolean, results: Array, | ||
api.verify = async function verify(document, { | ||
suite, purpose, documentLoader, expansionMap} = {}) { | ||
suite, purpose, documentLoader, expansionMap | ||
} = {}) { | ||
if(expansionMap) { | ||
throw new Error('"expansionMap" not supported.'); | ||
} | ||
if(typeof document !== 'object') { | ||
@@ -121,3 +120,3 @@ throw new TypeError('The "document" parameter must be an object.'); | ||
const result = await new ProofSet().verify( | ||
document, {suite, purpose, documentLoader, expansionMap}); | ||
document, {suite, purpose, documentLoader}); | ||
const {error} = result; | ||
@@ -146,2 +145,1 @@ if(error) { | ||
Object.assign(api, require('./documentLoader')); | ||
/*! | ||
* Copyright (c) 2018 Digital Bazaar, Inc. All rights reserved. | ||
* Copyright (c) 2018-2022 Digital Bazaar, Inc. All rights reserved. | ||
*/ | ||
@@ -10,3 +10,2 @@ 'use strict'; | ||
const {serializeError} = require('serialize-error'); | ||
const strictExpansionMap = require('./expansionMap'); | ||
@@ -39,7 +38,2 @@ module.exports = class ProofSet { | ||
* `Promise<RemoteDocument> documentLoader(url)`. | ||
* @param [expansionMap] {function} A custom expansion map that is | ||
* passed to the JSON-LD processor; by default a function that will throw | ||
* an error when unmapped properties are detected in the input, use `false` | ||
* to turn this off and allow unmapped properties to be dropped or use a | ||
* custom function. | ||
* | ||
@@ -49,3 +43,3 @@ * @return {Promise<object>} resolves with the signed document, with | ||
*/ | ||
async add(document, {suite, purpose, documentLoader, expansionMap} = {}) { | ||
async add(document, {suite, purpose, documentLoader} = {}) { | ||
if(!suite) { | ||
@@ -63,7 +57,2 @@ throw new TypeError('"options.suite" is required.'); | ||
} | ||
if(expansionMap === undefined) { | ||
expansionMap = strictExpansionMap; | ||
} else if(expansionMap === false) { | ||
expansionMap = undefined; | ||
} | ||
@@ -80,3 +69,3 @@ // preprocess document to prepare to remove existing proofs | ||
const proof = await suite.createProof({ | ||
document: input, purpose, documentLoader, expansionMap | ||
document: input, purpose, documentLoader | ||
}); | ||
@@ -111,7 +100,2 @@ | ||
* `Promise<RemoteDocument> documentLoader(url)`. | ||
* @param {function} [expansionMap] - A custom expansion map that is | ||
* passed to the JSON-LD processor; by default a function that will throw | ||
* an error when unmapped properties are detected in the input, use `false` | ||
* to turn this off and allow unmapped properties to be dropped or use a | ||
* custom function. | ||
* | ||
@@ -124,3 +108,3 @@ * @return {Promise<{verified: boolean, results: Array, error: *}>} resolves | ||
*/ | ||
async verify(document, {suite, purpose, documentLoader, expansionMap} = {}) { | ||
async verify(document, {suite, purpose, documentLoader} = {}) { | ||
if(!suite) { | ||
@@ -142,7 +126,2 @@ throw new TypeError('"options.suite" is required.'); | ||
} | ||
if(expansionMap === undefined) { | ||
expansionMap = strictExpansionMap; | ||
} else if(expansionMap === false) { | ||
expansionMap = undefined; | ||
} | ||
@@ -154,11 +133,9 @@ try { | ||
// get proofs from document | ||
const {proofSet, document: doc} = await _getProofs({ | ||
document, documentLoader, expansionMap | ||
}); | ||
const {proofSet, document: doc} = await _getProofs( | ||
{document, documentLoader}); | ||
document = doc; | ||
// verify proofs | ||
const results = await _verify({ | ||
document, suites, proofSet, purpose, documentLoader, expansionMap | ||
}); | ||
const results = await _verify( | ||
{document, suites, proofSet, purpose, documentLoader}); | ||
if(results.length === 0) { | ||
@@ -213,3 +190,3 @@ const error = new Error( | ||
async function _verify({ | ||
document, suites, proofSet, purpose, documentLoader, expansionMap | ||
document, suites, proofSet, purpose, documentLoader | ||
}) { | ||
@@ -223,3 +200,3 @@ // map each purpose to at least one proof to verify | ||
purposeToProofs, proofToSuite, purpose, proofSet, suites, | ||
suiteMatchQueue, document, documentLoader, expansionMap | ||
suiteMatchQueue, document, documentLoader | ||
}))); | ||
@@ -247,5 +224,4 @@ | ||
}; | ||
const {verified, verificationMethod, error} = await suite.verifyProof({ | ||
proof, document, purpose, documentLoader, expansionMap | ||
}); | ||
const {verified, verificationMethod, error} = await suite.verifyProof( | ||
{proof, document, purpose, documentLoader}); | ||
if(!vm) { | ||
@@ -283,3 +259,3 @@ vm = verificationMethod; | ||
purposeResult = await purpose.validate(proof, { | ||
document, suite, verificationMethod, documentLoader, expansionMap | ||
document, suite, verificationMethod, documentLoader | ||
}); | ||
@@ -332,7 +308,7 @@ } catch(error) { | ||
purposeToProofs, proofToSuite, purpose, proofSet, suites, | ||
suiteMatchQueue, document, documentLoader, expansionMap | ||
suiteMatchQueue, document, documentLoader | ||
}) { | ||
for(const proof of proofSet) { | ||
// first check if the proof matches the purpose; if it doesn't continue | ||
if(!await purpose.match(proof, {document, documentLoader, expansionMap})) { | ||
if(!await purpose.match(proof, {document, documentLoader})) { | ||
continue; | ||
@@ -356,3 +332,3 @@ } | ||
if(!promise) { | ||
promise = s.matchProof({proof, document, documentLoader, expansionMap}); | ||
promise = s.matchProof({proof, document, documentLoader}); | ||
matchingProofs.set(proof, promise); | ||
@@ -359,0 +335,0 @@ } |
/*! | ||
* Copyright (c) 2018 Digital Bazaar, Inc. All rights reserved. | ||
* Copyright (c) 2018-2022 Digital Bazaar, Inc. All rights reserved. | ||
*/ | ||
@@ -111,3 +111,3 @@ 'use strict'; | ||
} | ||
}, {documentLoader, compactToRelative: false}); | ||
}, {documentLoader, compactToRelative: false, safe: true}); | ||
} | ||
@@ -114,0 +114,0 @@ result.controller = document; |
@@ -46,3 +46,7 @@ /*! | ||
proof, {/*document, suite, verificationMethod, | ||
documentLoader, expansionMap*/}) { | ||
documentLoader,*/ expansionMap}) { | ||
if(expansionMap) { | ||
throw new Error('"expansionMap" not supported.'); | ||
} | ||
try { | ||
@@ -77,3 +81,6 @@ // check expiration | ||
*/ | ||
async update(proof, {/*document, suite, documentLoader, expansionMap */}) { | ||
async update(proof, {/*document, suite, documentLoader,*/ expansionMap}) { | ||
if(expansionMap) { | ||
throw new Error('"expansionMap" not supported.'); | ||
} | ||
proof.proofPurpose = this.term; | ||
@@ -92,5 +99,8 @@ return proof; | ||
*/ | ||
async match(proof, {/* document, documentLoader, expansionMap */}) { | ||
async match(proof, {/* document, documentLoader,*/ expansionMap}) { | ||
if(expansionMap) { | ||
throw new Error('"expansionMap" not supported.'); | ||
} | ||
return proof.proofPurpose === this.term; | ||
} | ||
}; |
/*! | ||
* Copyright (c) 2018 Digital Bazaar, Inc. All rights reserved. | ||
* Copyright (c) 2018-2022 Digital Bazaar, Inc. All rights reserved. | ||
*/ | ||
@@ -15,6 +15,7 @@ 'use strict'; | ||
/** | ||
* @param document {object} to be signed. | ||
* @param purpose {ProofPurpose} | ||
* @param documentLoader {function} | ||
* @param expansionMap {function} | ||
* @param {object} options - The options to use. | ||
* @param {object} options.document - The document to be signed. | ||
* @param {ProofPurpose} options.purpose - The proof purpose instance. | ||
* @param {function} options.documentLoader - The document loader to use. | ||
* @param {function} options.expansionMap - NOT SUPPORTED; do not use. | ||
* | ||
@@ -30,7 +31,8 @@ * @returns {Promise<object>} Resolves with the created proof object. | ||
/** | ||
* @param proof {object} the proof to be verified. | ||
* @param document {object} the document the proof applies to. | ||
* @param purpose {ProofPurpose} | ||
* @param documentLoader {function} | ||
* @param expansionMap {function} | ||
* @param {object} options - The options to use. | ||
* @param {object} options.proof - The proof to be verified. | ||
* @param {object} options.document - The document the proof applies to. | ||
* @param {ProofPurpose} options.purpose - The proof purpose instance. | ||
* @param {function} options.documentLoader - The document loader to use. | ||
* @param {function} options.expansionMap - NOT SUPPORTED; do not use. | ||
* | ||
@@ -48,4 +50,4 @@ * @returns {Promise<{object}>} Resolves with the verification result. | ||
* | ||
* @param {object} options - Options hashmap. | ||
* @param {object} options.proof | ||
* @param {object} options - The options to use. | ||
* @param {object} options.proof - The proof to match. | ||
* | ||
@@ -52,0 +54,0 @@ * @returns {Promise<boolean>} Whether a match for the proof was found. |
@@ -86,6 +86,7 @@ /*! | ||
/** | ||
* @param document {object} to be signed. | ||
* @param purpose {ProofPurpose} | ||
* @param documentLoader {function} | ||
* @param expansionMap {function} | ||
* @param {object} options - The options to use. | ||
* @param {object} options.document - The document to be signed. | ||
* @param {ProofPurpose} options.purpose - The proof purpose instance. | ||
* @param {function} options.documentLoader - The document loader to use. | ||
* @param {function} options.expansionMap - NOT SUPPORTED; do not use. | ||
* | ||
@@ -95,2 +96,6 @@ * @returns {Promise<object>} Resolves with the created proof object. | ||
async createProof({document, purpose, documentLoader, expansionMap}) { | ||
if(expansionMap) { | ||
throw new Error('"expansionMap" not supported.'); | ||
} | ||
// build proof (currently known as `signature options` in spec) | ||
@@ -128,5 +133,3 @@ let proof; | ||
// add any extensions to proof (mostly for legacy support) | ||
proof = await this.updateProof({ | ||
document, proof, purpose, documentLoader, expansionMap | ||
}); | ||
proof = await this.updateProof({document, proof, purpose, documentLoader}); | ||
@@ -137,12 +140,10 @@ // allow purpose to update the proof; the `proof` is in the | ||
proof = await purpose.update( | ||
proof, {document, suite: this, documentLoader, expansionMap}); | ||
proof, {document, suite: this, documentLoader}); | ||
// create data to sign | ||
const verifyData = await this.createVerifyData({ | ||
document, proof, documentLoader, expansionMap | ||
}); | ||
const verifyData = await this.createVerifyData( | ||
{document, proof, documentLoader}); | ||
// sign data | ||
proof = await this.sign( | ||
{verifyData, document, proof, documentLoader, expansionMap}); | ||
proof = await this.sign({verifyData, document, proof, documentLoader}); | ||
@@ -153,10 +154,12 @@ return proof; | ||
/** | ||
* @param document {object} to be signed. | ||
* @param purpose {ProofPurpose} | ||
* @param documentLoader {function} | ||
* @param expansionMap {function} | ||
* @param {object} options - The options to use. | ||
* @param {object} options.proof - The proof to be updated. | ||
* @param {function} options.expansionMap - NOT SUPPORTED; do not use. | ||
* | ||
* @returns {Promise<object>} Resolves with the created proof object. | ||
*/ | ||
async updateProof({proof}) { | ||
async updateProof({proof, expansionMap}) { | ||
if(expansionMap) { | ||
throw new Error('"expansionMap" not supported.'); | ||
} | ||
// extending classes may do more | ||
@@ -167,6 +170,8 @@ return proof; | ||
/** | ||
* @param proof {object} the proof to be verified. | ||
* @param document {object} the document the proof applies to. | ||
* @param documentLoader {function} | ||
* @param expansionMap {function} | ||
* @param {object} options - The options to use. | ||
* @param {object} options.proof - The proof to be verified. | ||
* @param {object} options.document - The document the proof applies to. | ||
* @param {ProofPurpose} options.purpose - The proof purpose instance. | ||
* @param {function} options.documentLoader - The document loader to use. | ||
* @param {function} options.expansionMap - NOT SUPPORTED; do not use. | ||
* | ||
@@ -176,2 +181,6 @@ * @returns {Promise<{object}>} Resolves with the verification result. | ||
async verifyProof({proof, document, documentLoader, expansionMap}) { | ||
if(expansionMap) { | ||
throw new Error('"expansionMap" not supported.'); | ||
} | ||
try { | ||
@@ -201,7 +210,14 @@ // create data to verify | ||
async canonize(input, {documentLoader, expansionMap, skipExpansion}) { | ||
if(expansionMap) { | ||
throw new Error('"expansionMap" not supported.'); | ||
} | ||
return jsonld.canonize(input, { | ||
algorithm: 'URDNA2015', | ||
// do not resolve any relative URLs or terms, throw errors instead | ||
base: null, | ||
format: 'application/n-quads', | ||
documentLoader, | ||
expansionMap, | ||
// throw errors if any values would be dropped due to missing | ||
// definitions or relative URLs | ||
safe: true, | ||
skipExpansion, | ||
@@ -213,2 +229,5 @@ useNative: this.useNativeCanonize | ||
async canonizeProof(proof, {document, documentLoader, expansionMap}) { | ||
if(expansionMap) { | ||
throw new Error('"expansionMap" not supported.'); | ||
} | ||
// `jws`,`signatureValue`,`proofValue` must not be included in the proof | ||
@@ -231,6 +250,7 @@ // options | ||
/** | ||
* @param document {object} to be signed/verified. | ||
* @param proof {object} | ||
* @param documentLoader {function} | ||
* @param expansionMap {function} | ||
* @param {object} options - The options to use. | ||
* @param {object} options.document - The document to be signed/verified. | ||
* @param {object} options.proof - The proof to be verified. | ||
* @param {function} options.documentLoader - The document loader to use. | ||
* @param {function} options.expansionMap - NOT SUPPORTED; do not use. | ||
* | ||
@@ -240,2 +260,5 @@ * @returns {Promise<{Uint8Array}>}. | ||
async createVerifyData({document, proof, documentLoader, expansionMap}) { | ||
if(expansionMap) { | ||
throw new Error('"expansionMap" not supported.'); | ||
} | ||
// get cached document hash | ||
@@ -291,3 +314,3 @@ let cachedDocHash; | ||
id: verificationMethod | ||
}, {documentLoader, compactToRelative: false}); | ||
}, {documentLoader, compactToRelative: false, safe: true}); | ||
if(!framed) { | ||
@@ -294,0 +317,0 @@ throw new Error(`Verification method ${verificationMethod} not found.`); |
{ | ||
"name": "jsonld-signatures", | ||
"version": "10.0.0", | ||
"version": "11.0.0", | ||
"description": "An implementation of the Linked Data Signatures specifications for JSON-LD in JavaScript.", | ||
@@ -31,5 +31,5 @@ "homepage": "https://github.com/digitalbazaar/jsonld-signatures", | ||
"dependencies": { | ||
"jsonld": "^6.0.0", | ||
"jsonld": "^8.0.0", | ||
"security-context": "^4.0.0", | ||
"serialize-error": "^8.0.1" | ||
"serialize-error": "^8.1.0" | ||
}, | ||
@@ -36,0 +36,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61674
21
1377
+ Addedjsonld@8.3.3(transitive)
- Removedjsonld@6.0.0(transitive)
Updatedjsonld@^8.0.0
Updatedserialize-error@^8.1.0