diff --git a/README.md b/README.md index 1e5c171..e58aed4 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,10 @@ See https://en.bitcoin.it/wiki/Identity_protocol_v1 for complete details. In each request, the client includes a nonce to prevent replay attacks. The client signs the full url with the request body concatenated if there is one. The signature -is included in the x-signature header and the public key is included in the -x-pubkey header. +is included in the `x-signature` header and the public key is included in the +`x-identity` header. -The server verifies that the signature is valid and that it matches the public key. +The server verifies that the signature is valid and that it matches the identity (the public key). It then computes the SIN from the public key, and sees whether that SIN has access to the requested resource. The nonce is checked to make sure it is higher than the previously used nonce. @@ -135,7 +135,7 @@ for(k in keys) { var options = { url: url, headers: { - 'x-pubkey': bitauth.getPublicKeyFromPrivateKey(keys[k]), + 'x-identity': bitauth.getPublicKeyFromPrivateKey(keys[k]), 'x-signature': bitauth.sign(dataToSign, keys[k]) } }; @@ -161,7 +161,7 @@ for(k in keys) { var options = { url: url, headers: { - 'x-pubkey': bitauth.getPublicKeyFromPrivateKey(keys[k]), + 'x-identity': bitauth.getPublicKeyFromPrivateKey(keys[k]), 'x-signature': bitauth.sign(dataToSign, keys[k]) }, json: data diff --git a/examples/client.js b/examples/client.js index 95bec5e..ae678f0 100644 --- a/examples/client.js +++ b/examples/client.js @@ -15,7 +15,7 @@ for(k in keys) { var options = { url: url, headers: { - 'x-pubkey': bitauth.getPublicKeyFromPrivateKey(keys[k]), + 'x-identity': bitauth.getPublicKeyFromPrivateKey(keys[k]), 'x-signature': bitauth.sign(dataToSign, keys[k]) } }; @@ -41,7 +41,7 @@ for(k in keys) { var options = { url: url, headers: { - 'x-pubkey': bitauth.getPublicKeyFromPrivateKey(keys[k]), + 'x-identity': bitauth.getPublicKeyFromPrivateKey(keys[k]), 'x-signature': bitauth.sign(dataToSign, keys[k]) }, json: data @@ -55,4 +55,4 @@ for(k in keys) { console.log(body); } }); -} \ No newline at end of file +} diff --git a/examples/server.js b/examples/server.js index a9e382c..cfa8e47 100644 --- a/examples/server.js +++ b/examples/server.js @@ -32,4 +32,4 @@ app.get('/pizzas', function(req, res) { res.send(200, pizzas); }); -app.listen(3000); \ No newline at end of file +app.listen(3000); diff --git a/lib/middleware/bitauth.js b/lib/middleware/bitauth.js index b15fb86..7399e17 100644 --- a/lib/middleware/bitauth.js +++ b/lib/middleware/bitauth.js @@ -1,24 +1,24 @@ var bitauth = require('../bitauth'); module.exports = function(req, res, next) { - if(req.headers && req.headers['x-pubkey'] && req.headers['x-signature']) { + if(req.headers && req.headers['x-identity'] && req.headers['x-signature']) { // Check signature is valid // First construct data to check signature on var fullUrl = req.protocol + '://' + req.get('host') + req.url; var data = fullUrl + req.rawBody; - bitauth.verifySignature(data, req.headers['x-pubkey'], req.headers['x-signature'], function(err, result) { + bitauth.verifySignature(data, req.headers['x-identity'], req.headers['x-signature'], function(err, result) { if(err || !result) { return res.send(400, {error: 'Invalid signature'}); } // Get the SIN from the public key - var sin = bitauth.getSinFromPublicKey(req.headers['x-pubkey']); - if(!sin) return res.send(400, {error: 'Bad public key'}); + var sin = bitauth.getSinFromPublicKey(req.headers['x-identity']); + if(!sin) return res.send(400, {error: 'Bad public key from identity'}); req.sin = sin; next(); }); } else { next(); } -}; \ No newline at end of file +};