Skip to content

Instantly share code, notes, and snippets.

@mattcollier
Last active February 22, 2018 19:11
Show Gist options
  • Save mattcollier/61356d296b2a46cc825320c0c215b322 to your computer and use it in GitHub Desktop.
Save mattcollier/61356d296b2a46cc825320c0c215b322 to your computer and use it in GitHub Desktop.
abc
node_modules
'use strict';
const async = require('async');
const jsigs = require('jsonld-signatures');
const doc = {
"@context": "https://w3id.org/webledger/v1",
"type": "ContinuityMergeEvent",
"parentHash": [
"ni:///sha-256;Xk0ruJlbQTpFOyzbsl_KL8vKQiahMj7t9h-v70BMwAQ"
]
};
const publicKey = {
'@context': 'https://w3id.org/security/v2',
"id": "https://bedrock.local:18443/consensus/continuity2017/voters/F4rr5sgJztzZdVNFiWWAJS3rsudfuZTC7qcL2wuJmoZd",
"owner": "https://bedrock.local:18443/consensus/continuity2017/voters/F4rr5sgJztzZdVNFiWWAJS3rsudfuZTC7qcL2wuJmoZd",
"publicKeyBase58": "F4rr5sgJztzZdVNFiWWAJS3rsudfuZTC7qcL2wuJmoZd",
"privateKey": {
"privateKeyBase58": "5spKh9FymFFasSnzAgR6sZvcTmE9qb6H8ewhaNa8bjMVypjfsFqeTRFoAGKvDyuYN664ydrKEsBLpNJmcsPwkxHR"
},
type: "CryptographicKey"
};
async.auto({
sign: callback => jsigs.sign(doc, {
algorithm: 'Ed25519Signature2018',
privateKeyBase58: publicKey.privateKey.privateKeyBase58,
creator: publicKey.id
}, (err, result) => {
console.log('SIGNED', result);
callback(null, result);
}),
verify: ['sign', (results, callback) => jsigs.verify(results.sign, {
getPublicKey: _getPublicKey,
getPublicKeyOwner: _getPublicKeyOwner,
// checkTimestamp: false
}, (err, result) => {
console.log('VERIFY', JSON.stringify(result, null, 2));
callback();
})],
});
function _getPublicKey(publicKeyId, options, callback) {
callback(null, publicKey);
}
function _getPublicKeyOwner(owner, options, callback) {
const keyOwner = {
'@context': 'https://w3id.org/webledger/v1',
type: 'Identity',
id: owner,
publicKey
};
return callback(null, keyOwner);
}
{
"name": "a",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"async": "^2.6.0",
"jsonld-signatures": "digitalbazaar/jsonld-signatures#master"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment