Last active
February 22, 2018 19:11
-
-
Save mattcollier/61356d296b2a46cc825320c0c215b322 to your computer and use it in GitHub Desktop.
abc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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