jsonld-signatures
Advanced tools
Comparing version 0.2.3 to 0.2.4
{ | ||
"name": "jsonld-signatures", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "An implementation of the Linked Data Signatures specification for JSON-LD in the browser.", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -126,3 +126,2 @@ /** | ||
var nonce = options.nonce || null; | ||
var output = _deepClone(input); | ||
@@ -153,3 +152,3 @@ if(typeof privateKeyPem !== 'string') { | ||
normalize: function(callback) { | ||
jsonld.normalize(output, {format: 'application/nquads'}, callback); | ||
jsonld.normalize(input, {format: 'application/nquads'}, callback); | ||
}, | ||
@@ -180,25 +179,36 @@ sign: ['normalize', function(callback, results) { | ||
}, callback); | ||
}], | ||
compact: ['sign', function(callback, results) { | ||
// create signature info | ||
var signature = { | ||
'@context': api.SECURITY_CONTEXT_URL, | ||
type: 'GraphSignature2012', | ||
creator: creator, | ||
created: date, | ||
signatureValue: results.sign | ||
}; | ||
if(domain !== null) { | ||
signature.domain = domain; | ||
} | ||
if(nonce !== null) { | ||
signature.nonce = nonce; | ||
} | ||
var tmp = { | ||
'https://w3id.org/security#signature': signature | ||
}; | ||
var ctx = jsonld.getValues(input, '@context'); | ||
jsonld.compact(tmp, ctx, function(err, compacted) { | ||
callback(err, compacted); | ||
}); | ||
}], | ||
addSignature: ['compact', function(callback, results) { | ||
var output = _deepClone(input); | ||
delete results.compact['@context']; | ||
var signatureKey = Object.keys(results.compact)[0]; | ||
// TODO: support multiple signatures | ||
output[signatureKey] = results.compact[signatureKey]; | ||
callback(null, output); | ||
}] | ||
}, function(err, results) { | ||
if(err) { | ||
return callback(err); | ||
} | ||
// create signature info | ||
var signature = { | ||
'@context': api.SECURITY_CONTEXT_URL, | ||
type: 'GraphSignature2012', | ||
creator: creator, | ||
created: date, | ||
signatureValue: results.sign | ||
}; | ||
if(domain !== null) { | ||
signature.domain = domain; | ||
} | ||
if(nonce !== null) { | ||
signature.nonce = nonce; | ||
} | ||
// TODO: support multiple signatures | ||
output.signature = signature; | ||
callback(null, output); | ||
callback(err, results.addSignature); | ||
}); | ||
@@ -205,0 +215,0 @@ }; |
{ | ||
"name": "jsonld-signatures", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "An implementation of the Linked Data Signatures specification for JSON-LD in node.js.", | ||
@@ -45,3 +45,3 @@ "homepage": "http://github.com/digitalbazaar/jsonld-signatures", | ||
"jsdom": "~0.7.0", | ||
"jsonld": "~0.3.10", | ||
"jsonld": "~0.3.15", | ||
"node-forge": "~0.6.18", | ||
@@ -48,0 +48,0 @@ "pkginfo": "~0.3.0", |
@@ -47,4 +47,7 @@ /** | ||
if(url === 'https://w3id.org/security/v1') { | ||
callback(null, {contextUrl: null, document: securityContext, | ||
documentUrl: 'https://web-payments.org/contexts/security-v1.jsonld'}); | ||
callback(null, { | ||
contextUrl: null, | ||
document: securityContext, | ||
documentUrl: 'https://web-payments.org/contexts/security-v1.jsonld' | ||
}); | ||
} | ||
@@ -72,18 +75,4 @@ }; | ||
// the test document that will be signed | ||
var testDocument = { | ||
"@context": { | ||
schema: 'http://schema.org/', | ||
name: 'schema:name', | ||
homepage: 'schema:url', | ||
image: 'schema:image' | ||
}, | ||
name: 'Manu Sporny', | ||
homepage: 'https://manu.sporny.org/', | ||
image: 'https://manu.sporny.org/images/manu.png' | ||
}; | ||
// run tests | ||
describe('JSON-LD Signatures', function() { | ||
var testDocumentSigned = {}; | ||
var testPublicKeyUrl = 'https://example.com/i/alice/keys/1'; | ||
@@ -113,5 +102,5 @@ var testPublicKeyPem = | ||
var testPublicKey = { | ||
"@context": jsigs.SECURITY_CONTEXT_URL, | ||
'@id': testPublicKeyUrl, | ||
'@type': 'CryptographicKey', | ||
'@context': jsigs.SECURITY_CONTEXT_URL, | ||
id: testPublicKeyUrl, | ||
type: 'CryptographicKey', | ||
owner: 'https://example.com/i/alice', | ||
@@ -121,31 +110,95 @@ publicKeyPem: testPublicKeyPem | ||
var testPublicKeyOwner = { | ||
"@context": jsigs.SECURITY_CONTEXT_URL, | ||
'@id': 'https://example.com/i/alice', | ||
'@context': jsigs.SECURITY_CONTEXT_URL, | ||
id: 'https://example.com/i/alice', | ||
publicKey: [testPublicKey] | ||
}; | ||
it('should successfully sign a local document', function(done) { | ||
jsigs.sign(testDocument, { | ||
privateKeyPem: testPrivateKeyPem, | ||
creator: testPublicKeyUrl | ||
}, function(err, signedDocument) { | ||
assert.ifError(err); | ||
assert.notEqual(signedDocument.signature, undefined, | ||
'signature was not created'); | ||
assert.equal(signedDocument.signature.creator, testPublicKeyUrl, | ||
'creator key for signature is wrong'); | ||
testDocumentSigned = signedDocument; | ||
done(); | ||
describe('signing and verify w/o security context', function() { | ||
// the test document that will be signed | ||
var testDocument = { | ||
'@context': { | ||
schema: 'http://schema.org/', | ||
name: 'schema:name', | ||
homepage: 'schema:url', | ||
image: 'schema:image' | ||
}, | ||
name: 'Manu Sporny', | ||
homepage: 'https://manu.sporny.org/', | ||
image: 'https://manu.sporny.org/images/manu.png' | ||
}; | ||
var testDocumentSigned = {}; | ||
it('should successfully sign a local document', function(done) { | ||
jsigs.sign(testDocument, { | ||
privateKeyPem: testPrivateKeyPem, | ||
creator: testPublicKeyUrl | ||
}, function(err, signedDocument) { | ||
assert.ifError(err); | ||
assert.notEqual( | ||
signedDocument['https://w3id.org/security#signature'], undefined, | ||
'signature was not created'); | ||
assert.equal( | ||
signedDocument['https://w3id.org/security#signature'] | ||
['http://purl.org/dc/terms/creator']['@id'], testPublicKeyUrl, | ||
'creator key for signature is wrong'); | ||
testDocumentSigned = signedDocument; | ||
done(); | ||
}); | ||
}); | ||
it('should successfully verify a local signed document', function(done) { | ||
jsigs.verify(testDocumentSigned, { | ||
publicKey: testPublicKey, | ||
publicKeyOwner: testPublicKeyOwner | ||
}, function(err, verified) { | ||
assert.ifError(err); | ||
assert.equal(verified, true, 'signature verification failed'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should successfully verify a local signed document', function(done) { | ||
jsigs.verify(testDocumentSigned, { | ||
publicKey: testPublicKey, | ||
publicKeyOwner: testPublicKeyOwner | ||
}, function(err, verified) { | ||
assert.ifError(err); | ||
assert.equal(verified, true, 'signature verification failed'); | ||
done(); | ||
describe('signing and verify w/security context', function() { | ||
// the test document that will be signed | ||
var testDocument = { | ||
'@context': [{ | ||
schema: 'http://schema.org/', | ||
name: 'schema:name', | ||
homepage: 'schema:url', | ||
image: 'schema:image' | ||
}, jsigs.SECURITY_CONTEXT_URL], | ||
name: 'Manu Sporny', | ||
homepage: 'https://manu.sporny.org/', | ||
image: 'https://manu.sporny.org/images/manu.png' | ||
}; | ||
var testDocumentSigned = {}; | ||
it('should successfully sign a local document', function(done) { | ||
jsigs.sign(testDocument, { | ||
privateKeyPem: testPrivateKeyPem, | ||
creator: testPublicKeyUrl | ||
}, function(err, signedDocument) { | ||
assert.ifError(err); | ||
assert.notEqual(signedDocument.signature, undefined, | ||
'signature was not created'); | ||
assert.equal(signedDocument.signature.creator, testPublicKeyUrl, | ||
'creator key for signature is wrong'); | ||
testDocumentSigned = signedDocument; | ||
done(); | ||
}); | ||
}); | ||
it('should successfully verify a local signed document', function(done) { | ||
jsigs.verify(testDocumentSigned, { | ||
publicKey: testPublicKey, | ||
publicKeyOwner: testPublicKeyOwner | ||
}, function(err, verified) { | ||
assert.ifError(err); | ||
assert.equal(verified, true, 'signature verification failed'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -163,2 +216,5 @@ }); | ||
"@context": { | ||
"id": "@id", | ||
"type": "@type", | ||
"dc": "http://purl.org/dc/terms/", | ||
@@ -172,39 +228,26 @@ "sec": "https://w3id.org/security#", | ||
"credential": {"@id": "sec:credential", "@type": "@id"}, | ||
"cipherAlgorithm": "sec:cipherAlgorithm", | ||
"cipherData": "sec:cipherData", | ||
"cipherKey": "sec:cipherKey", | ||
"created": { | ||
"@id": "dc:created", | ||
"@type": "xsd:dateTime" | ||
}, | ||
"claim": {"@id": "sec:claim", "@type": "@id"}, | ||
"created": {"@id": "dc:created", "@type": "xsd:dateTime"}, | ||
"creator": {"@id": "dc:creator", "@type": "@id"}, | ||
"digestAlgorithm": "sec:digestAlgorithm", | ||
"digestValue": "sec:digestValue", | ||
"domain": "sec:domain", | ||
"encryptionKey": "sec:encryptionKey", | ||
"expiration": { | ||
"@id": "sec:expiration", | ||
"@type": "xsd:dateTime" | ||
}, | ||
"expiration": {"@id": "sec:expiration", "@type": "xsd:dateTime"}, | ||
"expires": {"@id": "sec:expiration", "@type": "xsd:dateTime"}, | ||
"initializationVector": "sec:initializationVector", | ||
"nonce": "sec:nonce", | ||
"normalizationAlgorithm": "sec:normalizationAlgorithm", | ||
"owner": { | ||
"@id": "sec:owner", | ||
"@type": "@id" | ||
}, | ||
"owner": {"@id": "sec:owner", "@type": "@id"}, | ||
"password": "sec:password", | ||
"privateKey": {"@id": "sec:privateKey", "@type": "@id"}, | ||
"privateKeyPem": "sec:privateKeyPem", | ||
"publicKey": { | ||
"@id": "sec:publicKey", | ||
"@type": "@id" | ||
}, | ||
"publicKey": {"@id": "sec:publicKey", "@type": "@id"}, | ||
"publicKeyPem": "sec:publicKeyPem", | ||
"publicKeyService": { | ||
"@id": "sec:publicKeyService", | ||
"@type": "@id" | ||
}, | ||
"revoked": { | ||
"@id": "sec:revoked", | ||
"@type": "xsd:dateTime" | ||
}, | ||
"publicKeyService": {"@id": "sec:publicKeyService", "@type": "@id"}, | ||
"revoked": {"@id": "sec:revoked", "@type": "xsd:dateTime"}, | ||
"signature": "sec:signature", | ||
@@ -211,0 +254,0 @@ "signatureAlgorithm": "sec:signingAlgorithm", |
60359
1279
Updatedjsonld@~0.3.15