diff --git a/TODO b/TODO index 58c35cb110c3789c4b1a7e9fc172586524f97fb4..81390d50e5eb26d313e262001e26229d682b898f 100644 --- a/TODO +++ b/TODO @@ -18,7 +18,7 @@ Protocol implementation: ✔ REST service to store a OpenPGP certificate in AA format, with signature of it AA format too - pks/add @done (13-07-12 01:20) 2) Managing Amendment submission: - ☐ REST service to push root certificates used to initialize Amendment Chain - udc/amendments/init + ✔ REST service to view root certificates used to initialize Amendment Chain - udc/amendments/init @done (13-07-12 23:55) ☐ REST service for receiving an Amendment data structure - udc/amendments/submit ☐ Check Amendment structure ☐ Check Amendment eligibility according to the Node rules (notably UD amount) diff --git a/lib/amendments.js b/lib/amendments.js new file mode 100644 index 0000000000000000000000000000000000000000..73808e918171db99628b67093a428c5592529970 --- /dev/null +++ b/lib/amendments.js @@ -0,0 +1,40 @@ +var fs = require('fs'), +util = require('util'), +async = require('async'), +orm = require('orm'), +_ = require('underscore'), +stream = require('stream'); + +module.exports.init = function (initKeys, req, res) { + var PublicKey = req.models.PublicKey; + var pubkeys = []; + async.forEach(initKeys, function (initkey, done) { + var pk = new PublicKey({ raw:initkey.data }); + pk.construct(function (err) { + pubkeys.push(pk); + done(err); + }); + }, function (err) { + if(err) + res.send(503, err); + else{ + res.writeHead(200, {"Content-type": "text/plain"}); + res.end(JSON.stringify(pubkeys)); + } + }); +}; + +module.exports.submit = function (req, res) { +}; + +module.exports.members = function (req, res) { +}; + +module.exports.self = function (req, res) { +}; + +module.exports.voters = function (req, res) { +}; + +module.exports.vote = function (req, res) { +}; \ No newline at end of file diff --git a/lib/configurer.js b/lib/configurer.js new file mode 100644 index 0000000000000000000000000000000000000000..63c2700c48387d2d918c78a60b5bbc6e99d9ba4d --- /dev/null +++ b/lib/configurer.js @@ -0,0 +1,28 @@ +var async = require('async'); +var fs = require('fs'); + +function Configurer(config) { + + this.config = config; + + this.parseFiles = function (callback) { + var obj = this; + if (obj.config.initKeys) { + async.forEach(obj.config.initKeys, function(file, done){ + fs.readFile(file.path, {encoding: "utf8"}, function (err, data) { + file.data = data; + done(err); + }); + }, + callback); + } + else{ + callback(); + } + return this; + }; +} + +module.exports = function (config) { + return new Configurer(config); +}; \ No newline at end of file diff --git a/lib/nodecoin.js b/lib/nodecoin.js index 8f722aaed0fc8784d9183a4e681309c8c35ec46d..132c9eba85a4d154adf9774e9f27653859072e38 100644 --- a/lib/nodecoin.js +++ b/lib/nodecoin.js @@ -1,15 +1,16 @@ -var pks = require('./pks'), -udc = require('./udc'), -express = require('express'), -orm = require('orm'), -async = require('async'), -config = require('../config'), -path = require('path'), -_ = require('underscore'), -nodecoin = require('../lib/nodecoin'); +var pks = require('./pks'), +amend = require('./amendments'), +express = require('express'), +orm = require('orm'), +async = require('async'), +config = require('../config'), +path = require('path'), +_ = require('underscore'), +nodecoin = require('../lib/nodecoin'); +configurer = require('../lib/configurer'); module.exports.pks = pks; -module.exports.udc = udc; +module.exports.amendments = amend; module.exports.express = { route: function(app){ @@ -22,7 +23,7 @@ module.exports.express = { app.get( '/pks/lookup', pks.lookup); app.get( '/pks/add', pks.add.get); app.post( '/pks/add', pks.add.post); - app.post( '/udc/amendments/init', notImplemented); + app.get( '/udc/amendments/init', _(amend.init).partial(app.get('config').initKeys)); app.post( '/udc/amendments/submit', notImplemented); app.post( '/udc/amendments/vote', notImplemented); app.get( '/udc/amendments/view/:amendment_id/members', notImplemented); @@ -49,7 +50,17 @@ module.exports.express = { } }; + configurer(config).parseFiles(function (err) { + if(!err){ + console.log("Initkeys loaded."); + } + else{ + console.log(err); + } + }); + // all environments + app.set('config', config); app.set('port', process.env.PORT || config.server.port); app.use(express.favicon(__dirname + '/../public/favicon.ico')); app.use(express.static(__dirname + '/../public')); diff --git a/lib/udc.js b/lib/udc.js deleted file mode 100644 index a0995453769c8a76594b879c09c58064530c155a..0000000000000000000000000000000000000000 --- a/lib/udc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = {}; \ No newline at end of file diff --git a/protocol.md b/protocol.md index d01ac4b710570957bc8bd29b6c83cad4aa0eaed3..76ef0518c2bac23c2ebf5313dfd43beda35f56a1 100644 --- a/protocol.md +++ b/protocol.md @@ -298,7 +298,7 @@ This URL is used to manage OpenPGP certificates, making NodeCoin acting **like** ### udc/* This URL pattern manages all the data used by NodeCoin based on the PKS. -* `amendments/init` is used to POST the initial keys used to forge the initial amendment (aka. Monetary Contract). +* `amendments/init` is used to GET the initial keys used to forge the initial amendment (aka. Monetary Contract). * `amendments/submit` is used to POST an amendment with the required signatures (votes) in ASCII-Armored format. * `amendments/view/[AMENDMENT_ID]/members` is a Merkle URL referencing to the members of the Web of Trust. * `amendments/view/[AMENDMENT_ID]/self` shows the raw data of the amendment with the given `[AMENDMENT_ID]`.