jsonld-signatures
Advanced tools
Comparing version 2.0.1 to 2.1.0
# jsonld-signatures ChangeLog | ||
## 2.1.0 - 2018-02-14 | ||
### Added | ||
- Expose `suites` on main API to allow for other libs to | ||
create plugins that extend them. | ||
### Changed | ||
- Do not require `creator` option. | ||
### Fixed | ||
- Only include `publicKey` in result if `creator` is present. | ||
- Do not override `created` in `proof` option if `date` is not | ||
given in `options`. | ||
## 2.0.1 - 2018-02-13 | ||
@@ -4,0 +18,0 @@ |
@@ -7,8 +7,13 @@ "use strict"; | ||
}, "https://w3id.org/security/v1", { | ||
"Ed25519Signature2018": "sec:Ed25519Signature2018", | ||
"EquihashProof2018": "sec:EquihashProof2018", | ||
"RsaSignature2018": "sec:RsaSignature2018", | ||
"equihashParameterK": { "@id": "sec:equihashParameterK", "@type": "xsd:integer" }, | ||
"equihashParameterN": { "@id": "sec:equihashParameterN", "@type": "xsd:integer" }, | ||
"jws": "sec:jws", | ||
"proof": { "@id": "sec:proof", "@type": "@id", "@container": "@graph" }, | ||
"proofPurpose": { "@id": "sec:proofPurpose", "@type": "@vocab" } | ||
"proofPurpose": { "@id": "sec:proofPurpose", "@type": "@vocab" }, | ||
"proofValue": "sec:proofValue" | ||
}] | ||
}; |
@@ -79,5 +79,5 @@ 'use strict'; | ||
Object.assign(api, constants); | ||
api.SUPPORTED_ALGORITHMS = ['EcdsaKoblitzSignature2016', 'Ed25519Signature2018', 'GraphSignature2012', 'LinkedDataSignature2015', 'RsaSignature2018']; | ||
/* Core API */ | ||
api.suites = suites; | ||
@@ -89,9 +89,11 @@ /** | ||
* @param [options] options to use: | ||
* privateKeyPem A PEM-encoded private key. | ||
* creator the URL to the paired public key. | ||
* algorithm the algorithm to use, eg: 'Ed25519Signature2018', | ||
* 'RsaSignature2018'. | ||
* [privateKeyPem] A PEM-encoded private key. | ||
* [privateKeyBase58] A base85-encoded (Bitcoin/IPFS alphabet) | ||
* private key. | ||
* [creator] the URL to the paired public key. | ||
* [date] an optional date to override the signature date with. | ||
* [domain] an optional domain to include in the signature. | ||
* [nonce] an optional nonce to include in the signature. | ||
* [algorithm] the algorithm to use, eg: 'GraphSignature2012', | ||
* 'LinkedDataSignature2015' (default: 'GraphSignature2012'). | ||
* [expansionMap] a custom expansion map that is passed | ||
@@ -120,5 +122,7 @@ * to the JSON-LD processor; by default a function that will | ||
const SUPPORTED_ALGORITHMS = _getSupportedAlgorithms(); | ||
const algorithm = options.algorithm; | ||
if (api.SUPPORTED_ALGORITHMS.indexOf(algorithm) === -1) { | ||
throw new Error('Unsupported algorithm "' + algorithm + '"; ' + '"options.algorithm" must be one of: ' + JSON.stringify(api.SUPPORTED_ALGORITHMS)); | ||
if (SUPPORTED_ALGORITHMS.indexOf(algorithm) === -1) { | ||
throw new Error('Unsupported algorithm "' + algorithm + '"; ' + '"options.algorithm" must be one of: ' + JSON.stringify(SUPPORTED_ALGORITHMS)); | ||
} | ||
@@ -242,2 +246,3 @@ | ||
// create a promise for each signature to be verified | ||
const SUPPORTED_ALGORITHMS = _getSupportedAlgorithms(); | ||
const results = yield Promise.all(proofs.map(function (proof) { | ||
@@ -247,4 +252,4 @@ return _asyncToGenerator(function* () { | ||
const algorithm = jsonld.getValues(proof.doc, 'type')[0] || ''; | ||
if (api.SUPPORTED_ALGORITHMS.indexOf(algorithm) === -1) { | ||
throw new Error('Unsupported signature algorithm "' + algorithm + '"; ' + 'supported algorithms are: ' + JSON.stringify(api.SUPPORTED_ALGORITHMS)); | ||
if (SUPPORTED_ALGORITHMS.indexOf(algorithm) === -1) { | ||
throw new Error('Unsupported signature algorithm "' + algorithm + '"; ' + 'supported algorithms are: ' + JSON.stringify(SUPPORTED_ALGORITHMS)); | ||
} | ||
@@ -269,3 +274,5 @@ | ||
results.forEach(function (result, i) { | ||
result.publicKey = proofs[i].doc.creator; | ||
if (proofs[i].doc.creator) { | ||
result.publicKey = proofs[i].doc.creator; | ||
} | ||
}); | ||
@@ -286,2 +293,7 @@ | ||
function _getSupportedAlgorithms() { | ||
// every suite is supported except the base class | ||
return Object.keys(api.suites).filter(s => s !== 'LinkedDataSignature'); | ||
} | ||
function _addEmbeddedContextDocumentLoader(options) { | ||
@@ -288,0 +300,0 @@ options = Object.assign({}, options); |
@@ -120,3 +120,2 @@ /** | ||
// optimize using node libraries | ||
// optimize using node libraries | ||
const ed25519 = require('ed25519'); | ||
@@ -123,0 +122,0 @@ const bs58 = require('bs58'); |
@@ -81,9 +81,7 @@ /* | ||
return _asyncToGenerator(function* () { | ||
// set default options | ||
options = Object.assign({ | ||
date: new Date() | ||
}, options || {}); | ||
// copy options for setting defaults | ||
options = Object.assign({}, options || {}); | ||
// validate common options | ||
if (typeof options.creator !== 'string') { | ||
if ('creator' in options && typeof options.creator !== 'string') { | ||
throw new TypeError('"options.creator" must be a URL string.'); | ||
@@ -98,8 +96,2 @@ } | ||
// ensure date is in string format | ||
if (typeof date !== 'string') { | ||
// TODO: parse non-string date and force to w3c format? | ||
options.date = util.w3cDate(options.date); | ||
} | ||
// disallow dropping properties when expanding by default | ||
@@ -129,2 +121,13 @@ if (options.expansionMap !== false) { | ||
// set default `now` date if not given in `proof` or `options` | ||
if (!('created' in proof) && !('date' in options)) { | ||
options.date = new Date(); | ||
} | ||
// ensure date is in string format | ||
if ('date' in options && typeof options.date !== 'string') { | ||
// TODO: parse non-string date and force to w3c format? | ||
options.date = util.w3cDate(options.date); | ||
} | ||
// ensure algorithm is set | ||
@@ -134,4 +137,8 @@ proof.type = options.algorithm; | ||
// add API overrides | ||
proof.creator = options.creator; | ||
proof.created = options.date; | ||
if ('date' in options) { | ||
proof.created = options.date; | ||
} | ||
if ('creator' in options) { | ||
proof.creator = options.creator; | ||
} | ||
if ('domain' in options) { | ||
@@ -145,3 +152,3 @@ proof.domain = options.domain; | ||
// produce data to sign | ||
options = Object.assign({}, options, { proof }); | ||
options.proof = proof; | ||
const verifyData = yield _this3.createVerifyData(input, options); | ||
@@ -148,0 +155,0 @@ |
@@ -5,8 +5,13 @@ module.exports = { | ||
}, "https://w3id.org/security/v1", { | ||
"Ed25519Signature2018": "sec:Ed25519Signature2018", | ||
"EquihashProof2018": "sec:EquihashProof2018", | ||
"RsaSignature2018": "sec:RsaSignature2018", | ||
"equihashParameterK": {"@id": "sec:equihashParameterK", "@type": "xsd:integer"}, | ||
"equihashParameterN": {"@id": "sec:equihashParameterN", "@type": "xsd:integer"}, | ||
"jws": "sec:jws", | ||
"proof": {"@id": "sec:proof", "@type": "@id", "@container": "@graph"}, | ||
"proofPurpose": {"@id": "sec:proofPurpose", "@type": "@vocab"} | ||
"proofPurpose": {"@id": "sec:proofPurpose", "@type": "@vocab"}, | ||
"proofValue": "sec:proofValue" | ||
}] | ||
}; |
@@ -77,11 +77,5 @@ /** | ||
Object.assign(api, constants); | ||
api.SUPPORTED_ALGORITHMS = [ | ||
'EcdsaKoblitzSignature2016', | ||
'Ed25519Signature2018', | ||
'GraphSignature2012', | ||
'LinkedDataSignature2015', | ||
'RsaSignature2018' | ||
]; | ||
/* Core API */ | ||
api.suites = suites; | ||
@@ -93,9 +87,11 @@ /** | ||
* @param [options] options to use: | ||
* privateKeyPem A PEM-encoded private key. | ||
* creator the URL to the paired public key. | ||
* algorithm the algorithm to use, eg: 'Ed25519Signature2018', | ||
* 'RsaSignature2018'. | ||
* [privateKeyPem] A PEM-encoded private key. | ||
* [privateKeyBase58] A base85-encoded (Bitcoin/IPFS alphabet) | ||
* private key. | ||
* [creator] the URL to the paired public key. | ||
* [date] an optional date to override the signature date with. | ||
* [domain] an optional domain to include in the signature. | ||
* [nonce] an optional nonce to include in the signature. | ||
* [algorithm] the algorithm to use, eg: 'GraphSignature2012', | ||
* 'LinkedDataSignature2015' (default: 'GraphSignature2012'). | ||
* [expansionMap] a custom expansion map that is passed | ||
@@ -123,8 +119,10 @@ * to the JSON-LD processor; by default a function that will | ||
const SUPPORTED_ALGORITHMS = _getSupportedAlgorithms(); | ||
const algorithm = options.algorithm; | ||
if(api.SUPPORTED_ALGORITHMS.indexOf(algorithm) === -1) { | ||
if(SUPPORTED_ALGORITHMS.indexOf(algorithm) === -1) { | ||
throw new Error( | ||
'Unsupported algorithm "' + algorithm + '"; ' + | ||
'"options.algorithm" must be one of: ' + | ||
JSON.stringify(api.SUPPORTED_ALGORITHMS)); | ||
JSON.stringify(SUPPORTED_ALGORITHMS)); | ||
} | ||
@@ -252,10 +250,11 @@ | ||
// create a promise for each signature to be verified | ||
const SUPPORTED_ALGORITHMS = _getSupportedAlgorithms(); | ||
const results = await Promise.all(proofs.map(proof => (async () => { | ||
try { | ||
const algorithm = jsonld.getValues(proof.doc, 'type')[0] || ''; | ||
if(api.SUPPORTED_ALGORITHMS.indexOf(algorithm) === -1) { | ||
if(SUPPORTED_ALGORITHMS.indexOf(algorithm) === -1) { | ||
throw new Error( | ||
'Unsupported signature algorithm "' + algorithm + | ||
'"; ' + 'supported algorithms are: ' + | ||
JSON.stringify(api.SUPPORTED_ALGORITHMS)); | ||
JSON.stringify(SUPPORTED_ALGORITHMS)); | ||
} | ||
@@ -280,3 +279,5 @@ | ||
results.forEach((result, i) => { | ||
result.publicKey = proofs[i].doc.creator; | ||
if(proofs[i].doc.creator) { | ||
result.publicKey = proofs[i].doc.creator; | ||
} | ||
}); | ||
@@ -290,2 +291,7 @@ | ||
function _getSupportedAlgorithms() { | ||
// every suite is supported except the base class | ||
return Object.keys(api.suites).filter(s => s !== 'LinkedDataSignature'); | ||
} | ||
function _addEmbeddedContextDocumentLoader(options) { | ||
@@ -292,0 +298,0 @@ options = Object.assign({}, options); |
@@ -108,3 +108,2 @@ /** | ||
// optimize using node libraries | ||
// optimize using node libraries | ||
const ed25519 = require('ed25519'); | ||
@@ -111,0 +110,0 @@ const bs58 = require('bs58'); |
@@ -70,9 +70,7 @@ /* | ||
async sign(input, options) { | ||
// set default options | ||
options = Object.assign({ | ||
date: new Date() | ||
}, options || {}); | ||
// copy options for setting defaults | ||
options = Object.assign({}, options || {}); | ||
// validate common options | ||
if(typeof options.creator !== 'string') { | ||
if('creator' in options && typeof options.creator !== 'string') { | ||
throw new TypeError('"options.creator" must be a URL string.'); | ||
@@ -87,8 +85,2 @@ } | ||
// ensure date is in string format | ||
if(typeof date !== 'string') { | ||
// TODO: parse non-string date and force to w3c format? | ||
options.date = util.w3cDate(options.date); | ||
} | ||
// disallow dropping properties when expanding by default | ||
@@ -121,2 +113,13 @@ if(options.expansionMap !== false) { | ||
// set default `now` date if not given in `proof` or `options` | ||
if(!('created' in proof) && !('date' in options)) { | ||
options.date = new Date(); | ||
} | ||
// ensure date is in string format | ||
if('date' in options && typeof options.date !== 'string') { | ||
// TODO: parse non-string date and force to w3c format? | ||
options.date = util.w3cDate(options.date); | ||
} | ||
// ensure algorithm is set | ||
@@ -126,4 +129,8 @@ proof.type = options.algorithm; | ||
// add API overrides | ||
proof.creator = options.creator; | ||
proof.created = options.date; | ||
if('date' in options) { | ||
proof.created = options.date; | ||
} | ||
if('creator' in options) { | ||
proof.creator = options.creator; | ||
} | ||
if('domain' in options) { | ||
@@ -137,3 +144,3 @@ proof.domain = options.domain; | ||
// produce data to sign | ||
options = Object.assign({}, options, {proof}); | ||
options.proof = proof; | ||
const verifyData = await this.createVerifyData(input, options); | ||
@@ -140,0 +147,0 @@ |
{ | ||
"name": "jsonld-signatures", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "An implementation of the Linked Data Signatures specifications for JSON-LD in JavaScript.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/digitalbazaar/jsonld-signatures", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
394443
7590