Skip to content

Commit

Permalink
Implemented SEP010 authetication
Browse files Browse the repository at this point in the history
  • Loading branch information
Gbubemi Agbeyegbe committed Jun 3, 2024
1 parent 79977ec commit 6a6c91c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
16 changes: 16 additions & 0 deletions Authenticate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const StellarSDK = require('stellar-sdk');
const Authetication = require('./SEP10');

let accountSecret = 'SECRET-KEY';
let account = StellarSDK.Keypair.fromSecret(accountSecret);

Authetication.challenge(account)
.then((signed) => {
console.log('signed: ' + signed);

Authetication.token(signed)
.then((token) => {
console.log('token: ' + token);
})
});

66 changes: 66 additions & 0 deletions SEP10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const fetch = require('node-fetch');
const StellarSDK = require('stellar-sdk');
const querystring = require('querystring');

const networkPassphrase = 'Public Global Stellar Network ; September 2015';

const url = 'https://api.cowrie.exchange/web_auth';

module.exports = {
challenge: (account) => {
var query = querystring.stringify({ account: account.publicKey()});
var api = url + '?' + query;
console.log(api);

var signed =

fetch(api, { method: 'GET' }
).then((response) => {
console.log('HTTP: ' + response.status);

if(response.status == 200) {
return response.json();
}
else {
throw response.ststausText;
}
}).then((body) => {
//console.log('body: ' + JSON.stringify(body));
var transaction = StellarSDK.TransactionBuilder.fromXDR(body.transaction, networkPassphrase);
transaction.sign(account);
return transaction.toXDR();
}).catch((error) => {
console.log(error);
});

return signed;
},

token: (transaction) => {
var post = JSON.stringify({ transaction: transaction });
var api = url;
console.log(api);
console.log(post);

var jwt =

fetch(api, { method: 'POST', headers: {'Content-Type': 'application/json'}, body: post }
).then((response) => {
console.log('HTTP: ' + response.status);

if(response.status == 200) {
return response.json();
}
else {
throw response.ststausText;
}
}).then((body) => {
//console.log('body: ' + JSON.stringify(body));
return body.token;
}).catch((error) => {
console.log(error);
});

return jwt;
}
}
4 changes: 2 additions & 2 deletions SendNGNT.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const StellarSDK = require('stellar-sdk');
const horizon = new StellarSDK.Server('https://horizon-testnet.stellar.org');
StellarSDK.Network.useTestNetwork();
const horizon = new StellarSDK.Server('https://horizon.stellar.org');
StellarSDK.Network.usePublicNetwork();

let NGNT = {asset:'NGNT', issuer: 'GAWODAROMJ33V5YDFY3NPYTHVYQG7MJXVJ2ND3AOGIHYRWINES6ACCPD'};

Expand Down

0 comments on commit 6a6c91c

Please sign in to comment.