From 04d7675c2029bd77a010cc46404ad0f6352f03ed Mon Sep 17 00:00:00 2001 From: Kgothatso Date: Wed, 4 Dec 2019 21:47:33 +0200 Subject: [PATCH] Support posting signature to service --- lib/core/logic/authentication.js | 10 ++++++++-- lib/core/logic/post-signature.js | 10 ++++++++++ package.json | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 lib/core/logic/post-signature.js diff --git a/lib/core/logic/authentication.js b/lib/core/logic/authentication.js index 943fb02..44666fe 100644 --- a/lib/core/logic/authentication.js +++ b/lib/core/logic/authentication.js @@ -1,5 +1,6 @@ const persistence = require("../persistence/persistence"); const cryptoUtil = require("../cryptoUtil"); +const postSignature = require("./post-signature"); module.exports.authenticate = function(challenge, authenticationRequest, argv) { persistence().LoadDB() @@ -46,8 +47,13 @@ module.exports.authenticate = function(challenge, authenticationRequest, argv) { var challengeDerivationPath = `${lock.extendedPublicKey.derivationPath}/${challenge.derivationPath.split("c/")[1]}`; - const signature = cryptoUtil.signMessage(walletXpriv, challengeDerivationPath, challenge.message) - console.log("Signature: ", signature.toString('hex')); + const signature = cryptoUtil.signMessage(walletXpriv, challengeDerivationPath, challenge.message).toString('hex'); + console.log("Signature: ", signature); + + postSignature.postSignature(authenticationRequest.responseEndpoint, { + id: challenge.id, + signature: signature + }) } else { console.error("Challenge not signed by registered service."); } diff --git a/lib/core/logic/post-signature.js b/lib/core/logic/post-signature.js new file mode 100644 index 0000000..a83b6b4 --- /dev/null +++ b/lib/core/logic/post-signature.js @@ -0,0 +1,10 @@ +const needle = require('needle'); +module.exports.postSignature = function(endpoint, signature) { + needle('post', endpoint, signature, { json: true }) + .then(response => { + console.log("Response: ", response.statusMessage); + console.log("Body: ", response.body); + }).catch(error => { + console.error("Failed to sign request: ", error); + }) +} \ No newline at end of file diff --git a/package.json b/package.json index dd0a14b..f1d128c 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "bip39": "^3.0.2", "config": "^3.2.4", "nanoid": "^2.1.7", + "needle": "^2.4.0", "sequelize": "^5.21.2", "sqlite3": "^4.1.0", "yargs": "^15.0.2"