Compare commits
2 Commits
a05e1ba48e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d9705577c | ||
|
|
04d7675c20 |
@@ -13,6 +13,10 @@ module.exports.builder = (yargs) => {
|
||||
describe: 'Challenge to sign',
|
||||
type: 'string'
|
||||
})
|
||||
.option('p', {
|
||||
describe: 'will post signature to response endpoint',
|
||||
type: 'boolean'
|
||||
})
|
||||
.demandOption(['challenge'])
|
||||
.argv;
|
||||
}
|
||||
|
||||
@@ -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,15 @@ 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);
|
||||
|
||||
if(argv.p) {
|
||||
postSignature.postSignature(authenticationRequest.responseEndpoint, {
|
||||
id: challenge.id,
|
||||
signature: signature
|
||||
})
|
||||
}
|
||||
} else {
|
||||
console.error("Challenge not signed by registered service.");
|
||||
}
|
||||
|
||||
10
lib/core/logic/post-signature.js
Normal file
10
lib/core/logic/post-signature.js
Normal 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);
|
||||
})
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user