Support posting signature to service

This commit is contained in:
Kgothatso 2019-12-04 21:47:33 +02:00
parent a05e1ba48e
commit 04d7675c20
3 changed files with 19 additions and 2 deletions

View File

@ -1,5 +1,6 @@
const persistence = require("../persistence/persistence"); const persistence = require("../persistence/persistence");
const cryptoUtil = require("../cryptoUtil"); const cryptoUtil = require("../cryptoUtil");
const postSignature = require("./post-signature");
module.exports.authenticate = function(challenge, authenticationRequest, argv) { module.exports.authenticate = function(challenge, authenticationRequest, argv) {
persistence().LoadDB() persistence().LoadDB()
@ -46,8 +47,13 @@ module.exports.authenticate = function(challenge, authenticationRequest, argv) {
var challengeDerivationPath = `${lock.extendedPublicKey.derivationPath}/${challenge.derivationPath.split("c/")[1]}`; var challengeDerivationPath = `${lock.extendedPublicKey.derivationPath}/${challenge.derivationPath.split("c/")[1]}`;
const signature = cryptoUtil.signMessage(walletXpriv, challengeDerivationPath, challenge.message) const signature = cryptoUtil.signMessage(walletXpriv, challengeDerivationPath, challenge.message).toString('hex');
console.log("Signature: ", signature.toString('hex')); console.log("Signature: ", signature);
postSignature.postSignature(authenticationRequest.responseEndpoint, {
id: challenge.id,
signature: signature
})
} else { } else {
console.error("Challenge not signed by registered service."); console.error("Challenge not signed by registered service.");
} }

View File

@ -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);
})
}

View File

@ -13,6 +13,7 @@
"bip39": "^3.0.2", "bip39": "^3.0.2",
"config": "^3.2.4", "config": "^3.2.4",
"nanoid": "^2.1.7", "nanoid": "^2.1.7",
"needle": "^2.4.0",
"sequelize": "^5.21.2", "sequelize": "^5.21.2",
"sqlite3": "^4.1.0", "sqlite3": "^4.1.0",
"yargs": "^15.0.2" "yargs": "^15.0.2"