-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gbubemi Agbeyegbe
committed
Jun 3, 2024
1 parent
79977ec
commit 6a6c91c
Showing
3 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters