Skip to content

Commit 5858198

Browse files
Remove expansionMap (deprecated).
1 parent b124892 commit 5858198

8 files changed

+43
-87
lines changed

lib/ProofSet.js

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const constants = require('./constants');
77
const jsonld = require('jsonld');
88
const {extendContextLoader, strictDocumentLoader} = require('./documentLoader');
99
const {serializeError} = require('serialize-error');
10-
const strictExpansionMap = require('./expansionMap');
1110

1211
module.exports = class ProofSet {
1312
/**
@@ -35,16 +34,11 @@ module.exports = class ProofSet {
3534
*
3635
* @param [documentLoader] {function} a custom document loader,
3736
* `Promise<RemoteDocument> documentLoader(url)`.
38-
* @param [expansionMap] {function} A custom expansion map that is
39-
* passed to the JSON-LD processor; by default a function that will throw
40-
* an error when unmapped properties are detected in the input, use `false`
41-
* to turn this off and allow unmapped properties to be dropped or use a
42-
* custom function.
4337
*
4438
* @return {Promise<object>} resolves with the signed document, with
4539
* the signature in the top-level `proof` property.
4640
*/
47-
async add(document, {suite, purpose, documentLoader, expansionMap} = {}) {
41+
async add(document, {suite, purpose, documentLoader} = {}) {
4842
if(!suite) {
4943
throw new TypeError('"options.suite" is required.');
5044
}
@@ -57,9 +51,6 @@ module.exports = class ProofSet {
5751
} else {
5852
documentLoader = strictDocumentLoader;
5953
}
60-
if(expansionMap !== false) {
61-
expansionMap = strictExpansionMap;
62-
}
6354

6455
// preprocess document to prepare to remove existing proofs
6556
// let input;
@@ -71,7 +62,7 @@ module.exports = class ProofSet {
7162
// create the new proof (suites MUST output a proof using the security-v2
7263
// `@context`)
7364
const proof = await suite.createProof({
74-
document: input, purpose, documentLoader, expansionMap
65+
document: input, purpose, documentLoader
7566
});
7667

7768
jsonld.addValue(document, 'proof', proof);
@@ -101,19 +92,14 @@ module.exports = class ProofSet {
10192
*
10293
* @param {function} [documentLoader] a custom document loader,
10394
* `Promise<RemoteDocument> documentLoader(url)`.
104-
* @param {function} [expansionMap] - A custom expansion map that is
105-
* passed to the JSON-LD processor; by default a function that will throw
106-
* an error when unmapped properties are detected in the input, use `false`
107-
* to turn this off and allow unmapped properties to be dropped or use a
108-
* custom function.
10995
*
11096
* @return {Promise<{verified: boolean, results: Array, error: *}>} resolves
11197
* with an object with a `verified`boolean property that is `true` if at
11298
* least one proof matching the given purpose and suite verifies and `false`
11399
* otherwise; a `results` property with an array of detailed results;
114100
* if `false` an `error` property will be present.
115101
*/
116-
async verify(document, {suite, purpose, documentLoader, expansionMap} = {}) {
102+
async verify(document, {suite, purpose, documentLoader} = {}) {
117103
if(!suite) {
118104
throw new TypeError('"options.suite" is required.');
119105
}
@@ -130,23 +116,20 @@ module.exports = class ProofSet {
130116
} else {
131117
documentLoader = strictDocumentLoader;
132118
}
133-
if(expansionMap !== false) {
134-
expansionMap = strictExpansionMap;
135-
}
136119

137120
try {
138121
// shallow copy to allow for removal of proof set prior to canonize
139122
document = {...document};
140123

141124
// get proofs from document
142125
const {proofSet, document: doc} = await _getProofs({
143-
document, documentLoader, expansionMap
126+
document, documentLoader
144127
});
145128
document = doc;
146129

147130
// verify proofs
148131
const results = await _verify({
149-
document, suites, proofSet, purpose, documentLoader, expansionMap
132+
document, suites, proofSet, purpose, documentLoader
150133
});
151134
if(results.length === 0) {
152135
const error = new Error(
@@ -197,7 +180,7 @@ async function _getProofs({document}) {
197180
}
198181

199182
async function _verify({
200-
document, suites, proofSet, purpose, documentLoader, expansionMap
183+
document, suites, proofSet, purpose, documentLoader
201184
}) {
202185
// map each purpose to at least one proof to verify
203186
const purposes = Array.isArray(purpose) ? purpose : [purpose];
@@ -206,7 +189,7 @@ async function _verify({
206189
const suiteMatchQueue = new Map();
207190
await Promise.all(purposes.map(purpose => _matchProofSet({
208191
purposeToProofs, proofToSuite, purpose, proofSet, suites,
209-
suiteMatchQueue, document, documentLoader, expansionMap
192+
suiteMatchQueue, document, documentLoader
210193
})));
211194

212195
// every purpose must have at least one matching proof or verify will fail
@@ -230,7 +213,7 @@ async function _verify({
230213
}
231214
};
232215
const {verified, verificationMethod, error} = await suite.verifyProof({
233-
proof, document, purpose, documentLoader, expansionMap
216+
proof, document, purpose, documentLoader
234217
});
235218
if(!vm) {
236219
vm = verificationMethod;
@@ -264,7 +247,7 @@ async function _verify({
264247
let purposeResult;
265248
try {
266249
purposeResult = await purpose.validate(proof, {
267-
document, suite, verificationMethod, documentLoader, expansionMap
250+
document, suite, verificationMethod, documentLoader
268251
});
269252
} catch(error) {
270253
purposeResult = {valid: false, error};
@@ -312,11 +295,11 @@ function _makeSerializable(error) {
312295

313296
async function _matchProofSet({
314297
purposeToProofs, proofToSuite, purpose, proofSet, suites,
315-
suiteMatchQueue, document, documentLoader, expansionMap
298+
suiteMatchQueue, document, documentLoader
316299
}) {
317300
for(const proof of proofSet) {
318301
// first check if the proof matches the purpose; if it doesn't continue
319-
if(!await purpose.match(proof, {document, documentLoader, expansionMap})) {
302+
if(!await purpose.match(proof, {document, documentLoader})) {
320303
continue;
321304
}
322305

@@ -335,7 +318,7 @@ async function _matchProofSet({
335318
}
336319
let promise = matchingProofs.get(proof);
337320
if(!promise) {
338-
promise = s.matchProof({proof, document, documentLoader, expansionMap});
321+
promise = s.matchProof({proof, document, documentLoader});
339322
matchingProofs.set(proof, promise);
340323
}
341324
if(await promise) {

lib/jsonld-signatures.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,14 @@ const VerificationError = require('./VerificationError');
3636
* and other relevant URLs needed for the proof.
3737
*
3838
* Advanced optional parameters and overrides:
39-
*
40-
* @param {function} [options.expansionMap] - A custom expansion map that is
41-
* passed to the JSON-LD processor; by default a function that will throw
42-
* an error when unmapped properties are detected in the input, use `false`
43-
* to turn this off and allow unmapped properties to be dropped or use a
44-
* custom function.
4539
* @param {boolean} [options.addSuiteContext=true] - Toggles the default
4640
* behavior of each signature suite enforcing the presence of its own
4741
* `@context` (if it is not present, it's added to the context list).
4842
*
4943
* @returns {Promise<object>} Resolves with signed document.
5044
*/
5145
api.sign = async function sign(document, {
52-
suite, purpose, documentLoader, expansionMap, addSuiteContext = true
46+
suite, purpose, documentLoader, addSuiteContext = true
5347
} = {}) {
5448
if(typeof document !== 'object') {
5549
throw new TypeError('The "document" parameter must be an object.');
@@ -61,7 +55,7 @@ api.sign = async function sign(document, {
6155

6256
try {
6357
return await new ProofSet().add(
64-
document, {suite, purpose, documentLoader, expansionMap});
58+
document, {suite, purpose, documentLoader});
6559
} catch(e) {
6660
if(!documentLoader && e.name === 'jsonld.InvalidUrl') {
6761
const {details: {url}} = e;
@@ -92,11 +86,6 @@ api.sign = async function sign(document, {
9286
*
9387
* @param {function} [documentLoader] - A custom document loader,
9488
* `Promise<RemoteDocument> documentLoader(url)`.
95-
* @param {function} [expansionMap] - A custom expansion map that is
96-
* passed to the JSON-LD processor; by default a function that will throw
97-
* an error when unmapped properties are detected in the input, use `false`
98-
* to turn this off and allow unmapped properties to be dropped or use a
99-
* custom function.
10089
*
10190
* @return {Promise<{verified: boolean, results: Array,
10291
* error: VerificationError}>}
@@ -107,12 +96,12 @@ api.sign = async function sign(document, {
10796
* containing all of the errors that occurred during the verification process.
10897
*/
10998
api.verify = async function verify(document, {
110-
suite, purpose, documentLoader, expansionMap} = {}) {
99+
suite, purpose, documentLoader} = {}) {
111100
if(typeof document !== 'object') {
112101
throw new TypeError('The "document" parameter must be an object.');
113102
}
114103
const result = await new ProofSet().verify(
115-
document, {suite, purpose, documentLoader, expansionMap});
104+
document, {suite, purpose, documentLoader});
116105
const {error} = result;
117106
if(error) {
118107
if(!documentLoader && error.name === 'jsonld.InvalidUrl') {
@@ -136,4 +125,3 @@ api.purposes = require('./purposes').purposes;
136125

137126
// expose document loader helpers
138127
Object.assign(api, require('./documentLoader'));
139-

lib/purposes/AuthenticationProofPurpose.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = class AuthenticationProofPurpose extends
2121
this.domain = domain;
2222
}
2323

24-
async validate(proof, {verificationMethod, documentLoader, expansionMap}) {
24+
async validate(proof, {verificationMethod, documentLoader}) {
2525
try {
2626
// check challenge
2727
if(proof.challenge !== this.challenge) {
@@ -36,15 +36,15 @@ module.exports = class AuthenticationProofPurpose extends
3636
}
3737

3838
return super.validate(
39-
proof, {verificationMethod, documentLoader, expansionMap});
39+
proof, {verificationMethod, documentLoader});
4040
} catch(error) {
4141
return {valid: false, error};
4242
}
4343
}
4444

45-
async update(proof, {document, suite, documentLoader, expansionMap}) {
45+
async update(proof, {document, suite, documentLoader}) {
4646
proof = await super.update(
47-
proof, {document, suite, documentLoader, expansionMap});
47+
proof, {document, suite, documentLoader});
4848
proof.challenge = this.challenge;
4949
if(this.domain !== undefined) {
5050
proof.domain = this.domain;

lib/purposes/ControllerProofPurpose.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,16 @@ module.exports = class ControllerProofPurpose extends ProofPurpose {
5454
* @param proof
5555
* @param verificationMethod
5656
* @param documentLoader
57-
* @param expansionMap
5857
*
5958
* @throws {Error} If verification method not authorized by controller
6059
* @throws {Error} If proof's created timestamp is out of range
6160
*
6261
* @returns {Promise<{valid: boolean, error: Error}>}
6362
*/
64-
async validate(proof, {verificationMethod, documentLoader, expansionMap}) {
63+
async validate(proof, {verificationMethod, documentLoader}) {
6564
try {
6665
const result = await super.validate(
67-
proof, {verificationMethod, documentLoader, expansionMap});
66+
proof, {verificationMethod, documentLoader});
6867
if(!result.valid) {
6968
throw result.error;
7069
}
@@ -97,8 +96,6 @@ module.exports = class ControllerProofPurpose extends ProofPurpose {
9796
(Array.isArray(document['@context']) &&
9897
document['@context'][0] === DID_CONTEXT_V1));
9998
if(mustFrame) {
100-
// Note: `expansionMap` is intentionally not passed; we can safely
101-
// drop properties here and must allow for it
10299
document = await jsonld.frame(document, {
103100
'@context': constants.SECURITY_CONTEXT_URL,
104101
id: controllerId,

lib/purposes/ProofPurpose.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = class ProofPurpose {
4343
*/
4444
async validate(
4545
proof, {/*document, suite, verificationMethod,
46-
documentLoader, expansionMap*/}) {
46+
documentLoader*/}) {
4747
try {
4848
// check expiration
4949
if(this.maxTimestampDelta !== Infinity) {
@@ -73,7 +73,7 @@ module.exports = class ProofPurpose {
7373
* @return {Promise<object>} resolves to the proof instance (in the
7474
* `constants.SECURITY_CONTEXT_URL`.
7575
*/
76-
async update(proof, {/*document, suite, documentLoader, expansionMap */}) {
76+
async update(proof, {/*document, suite, documentLoader*/}) {
7777
proof.proofPurpose = this.term;
7878
return proof;
7979
}
@@ -87,7 +87,7 @@ module.exports = class ProofPurpose {
8787
*
8888
* @return {Promise<boolean>} `true` if there's a match, `false` if not.
8989
*/
90-
async match(proof, {/* document, documentLoader, expansionMap */}) {
90+
async match(proof, {/* document, documentLoader */}) {
9191
return proof.proofPurpose === this.term;
9292
}
9393
};

lib/suites/LinkedDataProof.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ module.exports = class LinkedDataProof {
1515
* @param document {object} to be signed.
1616
* @param purpose {ProofPurpose}
1717
* @param documentLoader {function}
18-
* @param expansionMap {function}
1918
*
2019
* @returns {Promise<object>} Resolves with the created proof object.
2120
*/
2221
async createProof({
23-
/* document, purpose, documentLoader, expansionMap */
22+
/* document, purpose, documentLoader */
2423
}) {
2524
throw new Error('"createProof" must be implemented in a derived class.');
2625
}
@@ -30,12 +29,11 @@ module.exports = class LinkedDataProof {
3029
* @param document {object} the document the proof applies to.
3130
* @param purpose {ProofPurpose}
3231
* @param documentLoader {function}
33-
* @param expansionMap {function}
3432
*
3533
* @returns {Promise<{object}>} Resolves with the verification result.
3634
*/
3735
async verifyProof({
38-
/* proof, document, purpose, documentLoader, expansionMap */
36+
/* proof, document, purpose, documentLoader */
3937
}) {
4038
throw new Error('"verifyProof" must be implemented in a derived class.');
4139
}
@@ -49,7 +47,7 @@ module.exports = class LinkedDataProof {
4947
* @returns {Promise<boolean>} Whether a match for the proof was found.
5048
*/
5149
async matchProof({
52-
proof /*, document, purpose, documentLoader, expansionMap */
50+
proof /*, document, purpose, documentLoader */
5351
}) {
5452
return proof.type === this.type;
5553
}

0 commit comments

Comments
 (0)