Name: jsonld-signatures
Owner: Digital Bazaar, Inc.
Description: An implementation of the Linked Data Signatures specification for JSON-LD. Works in the browser and node.js.
Created: 2014-11-26 17:45:39.0
Updated: 2017-12-01 00:01:37.0
Pushed: 2017-10-12 22:49:51.0
Homepage: null
Size: 202
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
An implementation of the Linked Data Signatures specification for JSON-LD. This software works in all modern browsers as well as node.js via npm.
Install with npm:
install jsonld-signatures
In Node.js, include the library like this:
jsonld = require('jsonld');
jsig = require('jsonld-signatures');
.use('jsonld', jsonld);
In a browser environment, include jsonld
, forge
, and
dist/jsonld-signatures.min.js
via script tag or other mechanism.
o generate the next two lines, run the following command:
penssl genrsa -out key.pem; cat key.pem; openssl rsa -in key.pem -pubout -out pubkey.pem; cat pubkey.pem; rm key.pem pubkey.pem
or an example of how to specify these keys, look at [key-example]:
testPublicKeyPem = "-----BEGIN PUBLIC KEY-----\r\n...";
testPrivateKeyPem = "-----BEGIN PRIVATE KEY-----\r\n...";
pecify the public key object
testPublicKey = {
context': jsig.SECURITY_CONTEXT_URL,
id': 'https://example.com/i/alice/keys/1',
ner: 'https://example.com/i/alice',
blicKeyPem: testPublicKeyPem
pecify the public key owner object
testPublicKeyOwner = {
context": jsig.SECURITY_CONTEXT_URL,
id': 'https://example.com/i/alice',
blicKey: [testPublicKey]
reate the JSON-LD document that should be signed
testDocument = {
context": {
schema: 'http://schema.org/',
name: 'schema:name',
homepage: 'schema:url',
image: 'schema:image'
me: 'Manu Sporny',
mepage: 'https://manu.sporny.org/',
age: 'https://manu.sporny.org/images/manu.png'
ign the document and then verify the signed document
.sign(testDocument, {
ivateKeyPem: testPrivateKeyPem,
eator: 'https://example.com/i/alice/keys/1'
unction(err, signedDocument) {
(err) {
return console.log('Signing error:', err);
nsole.log('Signed document:', signedDocument);
verify the signed document
ig.verify(signedDocument, {
publicKey: testPublicKey,
publicKeyOwner: testPublicKeyOwner,
function(err, verified) {
if(err) {
return console.log('Signature verification error:', err);
}
console.log('Signature is valid:', verified);
;
erification
sign = jsig.promises.sign(testDocument, {
ivateKeyPem: testPrivateKeyPem,
eator: 'https://example.com/i/alice/keys/1'
.then(function(signedDocument) {...}, function(err) {...});
verify = jsig.promises.verify(signedDocument, {
blicKey: testPublicKey,
blicKeyOwner: testPublicKeyOwner
fy.then(function(verified) {...}, function(err) {...});
Commercial support for this library is available upon request from Digital Bazaar: support@digitalbazaar.com
The source code for the JavaScript implementation of the JSON-LD Signatures API is available at:
https://github.com/digitalbazaar/jsonld-signatures
This library includes a sample testing utility which may be used to verify that changes to the processor maintain the correct output.
To run the sample tests you will need to get the test suite files by cloning the jsonld-signatures repository hosted on GitHub.
https://github.com/digitalbazaar/jsonld-signatures/
Run the Node.js tests using the following command:
npm run test
Run browser tests using PhantomJS using the following command:
npm run test-karma
Run browser tests using a selection of browsers using the following command:
npm run test-karma -- --browsers Firefox,Chrome,PhantomJS
Code coverage of node tests can be generated in coverage/
:
npm run coverage