Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bithalo committed Nov 16, 2024
1 parent f3a5f3b commit b9d355b
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 66 deletions.
4 changes: 2 additions & 2 deletions extractedText.txt
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,6 @@
"Fortunately, every user has a public key for encryption which can be used to verify their requests like an API key. Nodes will have different rate limits based on the amount of funds deposited and requests allowed per week. This prevents spam because it validates every genuine user.": true,
"In order to interact with nodes and users it is requested that you register a separate encryption key so requests can be validated and secured. Also at this time it is highly recommended to register contact information such as an email address so users may contact you when involved in a contract. Would you like to do that now?": true,
"How would you like to connect to validate orders using AI?": true,
"Enter your 'Session Key' which is shown when you load your local server.": true,
"Session Key cannot be blank": true
"Enter your 'Gateway public key' which is shown in your browser when you load your local server.": true,
"Key cannot be blank": true
}
127 changes: 76 additions & 51 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3989,8 +3989,13 @@ <h6>${translateThis("Transaction Pending")}</h6>
showMain('markets');
var web3 = [];
var DDEcontract = "";
//var DDEaddy = "0xc1620929B151ecB45beB7093AfFb1F9A359656d9"; //Sepolia testnet is default market view
var DDEaddy = "0x213DB7D60F33f3D1Ca9e13F298Ac6578d5Fc20fc" //Polygon is default market view
var testNetView = false;
var DDEaddy;
if(testNetView) {
DDEaddy = "0xc1620929B151ecB45beB7093AfFb1F9A359656d9"; //Sepolia testnet is default market view
} else {
DDEaddy = "0x213DB7D60F33f3D1Ca9e13F298Ac6578d5Fc20fc" //Polygon is default market view
}
var myaccounts = "";
var userpubkey = "";
var userprivkey = "";
Expand All @@ -4006,38 +4011,50 @@ <h6>${translateThis("Transaction Pending")}</h6>
var currentMarketsLength = 0;
var gasPrice = "";
var CurrentTimeStamp = new Date().getTime();
//var tokens = [
// {
// address: "0xA66857Da8d75BE2363968a3B01BfE1f417B28202",
// token: "ETH",
// image: "eth.png",
// decimals: "18"
// },
// {
// address: "0xD7567f0841Aae04833C8c004e8685cBF9F1a6b11",
// token: "WALRUS",
// image: "walrus.png",
// decimals: "8"
// }
//];
var tokens = [
{
address: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
token: "POL",
image: "matic.png",
decimals: "18"
},
{
address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
token: "DAI",
image: "dai.png",
decimals: "18"
}
];
//var tokennames = {"0xA66857Da8d75BE2363968a3B01BfE1f417B28202":"ETH","0xD7567f0841Aae04833C8c004e8685cBF9F1a6b11":"WALRUS"}
var tokennames = {"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270":"POL","0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063":"DAI"}
//web3 = new Web3("https://rpc.ankr.com/eth_sepolia");
web3 = new Web3("https://rpc.ankr.com/polygon");
var tokens;
if(testNetView) {
tokens = [
{
address: "0xA66857Da8d75BE2363968a3B01BfE1f417B28202",
token: "ETH",
image: "eth.png",
decimals: "18"
},
{
address: "0xD7567f0841Aae04833C8c004e8685cBF9F1a6b11",
token: "WALRUS",
image: "walrus.png",
decimals: "8"
}
];
} else {
tokens = [
{
address: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
token: "POL",
image: "matic.png",
decimals: "18"
},
{
address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
token: "DAI",
image: "dai.png",
decimals: "18"
}
];
}
var tokennames;
if(testNetView) {
tokennames = {"0xA66857Da8d75BE2363968a3B01BfE1f417B28202":"ETH","0xD7567f0841Aae04833C8c004e8685cBF9F1a6b11":"WALRUS"}
} else {
tokennames = {"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270":"POL","0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063":"DAI"}
}
var web3;
if(testNetView) {
web3 = new Web3("https://rpc.ankr.com/eth_sepolia");
} else {
web3 = new Web3("https://rpc.ankr.com/polygon");
}
var referral = "0x0000000000000000000000000000000000000000";
var baseFee = 0;
var myFavorites = [];
Expand Down Expand Up @@ -4870,7 +4887,10 @@ <h6>${translateThis("Transaction Pending")}</h6>

async function saveAPI(setAPI = '') {
const myCurrentChainId = DOMPurify.sanitize(await web3.eth.net.getId());
var mySelectedAPI = setAPI;
var mySelectedAPI = '';
if(setAPI == 'a' || setAPI == 'b') {
mySelectedAPI = setAPI;
}
if(mySelectedAPI == '') {
mySelectedAPI = document.getElementById('connectMethod').value;
}
Expand All @@ -4879,7 +4899,7 @@ <h6>${translateThis("Transaction Pending")}</h6>
var APIKEYS = localStorage.getItem(myaccounts + DDEaddy + myCurrentChainId + ":apiKeys") || "none";
var newkeys = true;
if(APIKEYS != "none") {
if(setAPI != '') {
if(setAPI == 'a' || setAPI == 'b') {
newkeys = false;
} else {
await Swal.fire({
Expand Down Expand Up @@ -5910,16 +5930,22 @@ <h6>${translateThis("Transaction Pending")}</h6>
request.chain = DOMPurify.sanitize(await web3.eth.net.getId());
if(hash == '') {
request.hash = hashObject(JSON.stringify(orderData));
} else {
request.hash = hash;
}
request.publicKey = userpubkey;
const timestamp = new Date().getTime();
const padding = Crypto.SHA256(timestamp).substring(0, 16); //Pad to avoid chosen cipher attack
var finalMessage = cryptico.encrypt(JSON.stringify(orderData) + "#*#*#" + timestamp + padding, gatewayList[currentGateway]['pub'], userprivkey).cipher;
var gatewayPub = gatewayList[currentGateway]['pub'];
if(window.globalPublicKey) {
gatewayPub = window.globalPublicKey;
}
var finalMessage = cryptico.encrypt(JSON.stringify(orderData) + "#*#*#" + timestamp + padding, gatewayPub, userprivkey).cipher;
request.message = finalMessage;
if(ipfs != '') {
request.ipfs = true;
}
if(window.globalSessionKey) {
if(window.globalPublicKey) {
return localVerify(request);
}
const requestData = {
Expand All @@ -5936,7 +5962,7 @@ <h6>${translateThis("Transaction Pending")}</h6>
var errorMessage = "Error parsing response";
for(var x=0; x<maxtries; x++) {
try {
if(x.toString() in checkThis) {
if(x.toString() in checkedThis) {
continue;
}
checkedThis[x.toString()] = 1;
Expand Down Expand Up @@ -6135,23 +6161,24 @@ <h6>${translateThis("Transaction Pending")}</h6>
icon: 'question',
}).then(async (result) => {
if (result.isConfirmed) {
Swal.fire({
await Swal.fire({
title: translateThis("Login/connect"),
text: translateThis("Enter your 'Session Key' which is shown when you load your local server."),
input: 'text',
inputPlaceholder: 'Session Key',
html:
'<p>' + translateThis("Enter your 'Gateway public key' which is shown in your browser when you load your local server.") + '</p>' +
'<input id="gateway-key" class="swal2-input" placeholder="Gateway Public Key">',
showCancelButton: true,
confirmButtonText: 'Submit',
preConfirm: (value) => {
if (!value) {
Swal.showValidationMessage('Session Key cannot be blank');
preConfirm: () => {
const gatewayKey = document.getElementById('gateway-key').value;
if (!gatewayKey) {
Swal.showValidationMessage('Key cannot be blank');
return false;
}
return value;
return { gatewayKey };
}
}).then((result) => {
if (result.isConfirmed) {
window.globalSessionKey = sessionKey;
window.globalPublicKey = result.value.gatewayKey;
}
});
} else {
Expand All @@ -6176,7 +6203,7 @@ <h6>${translateThis("Transaction Pending")}</h6>
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({action: 'verify', item: '', value, key: window.globalSessionKey}),
body: JSON.stringify({action: 'verify', item: '', value, key: ''}),
})
.then(response => {
if (response.data.result) {
Expand Down Expand Up @@ -7054,7 +7081,6 @@ <h6>${translateThis("Transaction Pending")}</h6>
searchThis = [];
try {
await DDEcontract3.methods.markets(index).call().then(async function (hash) {
console.log(index)
hash = DOMPurify.sanitize(hash);
if(checkedHashes[hash] === false) {
trueLength -= 1;
Expand Down Expand Up @@ -7191,7 +7217,6 @@ <h6>${translateThis("Transaction Pending")}</h6>
} else {
if(DOMPurify.sanitize(data.sender) == myaccounts) {
var message = cryptico.decrypt(testdata['sender'].cipher, userprivkey).plaintext;
console.log(message)
var padding = message.split("#*#*#")[1];
if(padding.length > 30) {
text = message.split("#*#*#")[0];
Expand Down
57 changes: 46 additions & 11 deletions node/Readme.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
Must have ssh for your system which is natively supported in most operating systems
and its easy to set up.

_________________________________________________________________________________________
_____________________________________________________________________________________________
Set up NGROK
_________________________________________________________________________________________
_____________________________________________________________________________________________

To generate your key:
ssh-keygen -t rsa

Then sign up for ngrok, register your key and make ngrok.yml and follow their instructions
Then sign up for ngrok, and follow instructions to make ngrok.yml and place it in the same
directory as your files. Then create a custom domain on ngrok. The line below listed
here starts the server however you will run it at a later step through the bat file.
ngrok http --url=your-custom-url.ngrok-free.app 9000

_________________________________________________________________________________________
_____________________________________________________________________________________________
Or set up localhost.run
_________________________________________________________________________________________
_____________________________________________________________________________________________

Alternatively you can use localhost.run
Localhost.run server setup:
Expand All @@ -30,11 +32,11 @@ Or to skip key for above steps type:
ssh -o ServerAliveInterval=60 -R 80:localhost:9000 [email protected]
Then you can take requests by the link it provides

_________________________________________________________________________________________
_____________________________________________________________________________________________
Then set up config file, index and bat file
__________________________________________________________________________________________
_____________________________________________________________________________________________

To set up your servers details and API keys, edit the config.js file in static directory
To set up your servers details and API keys, edit the config.js file in static directory.
If needed ctrl + f5 hard refresh gecko and restart server for changes to take effect.
Your password should be the same one you use to log into BitBay web markets as a node.
Also you public key should be registered so users know how to connect to you.
Expand All @@ -48,7 +50,8 @@ For security do not put sensitive files in the "static" directory

Next, so people can connect and test with the generic account you can replace the line
var serverPublicKey = ""
in the index.html file so you and any users can test the server remotely by visiting the
in the index.html file with the same public key shown when you log into BitBay with
the same password. Doing this allows users to test the server remotely by visiting the
ngrok page link. Also replace the line in index.html that says
var apiUrl = "https://your-custom-url.ngrok-free.app/api";
with the URL of your ngrok server
Expand All @@ -65,10 +68,42 @@ python server.py
Otherwise you may use the prebuilt server executable. For security you may choose to download
your own copies of ngrok.exe and of geckodriver.exe as well

_________________________________________________________________________________________
_____________________________________________________________________________________________
Run the server
__________________________________________________________________________________________
_____________________________________________________________________________________________

Finally load "pythonserver.bat" which will automatically boot up your ngrok server and
your python server. You are of course able to edit the python code and index to run different
apis or use different locally run AI models.

_____________________________________________________________________________________________
Join the community of nodes
_____________________________________________________________________________________________

You may finally share your nodes Polygon or Ethereum address (seen during BitBay web markets
login) as well as your public key and custom ngrok server URL with the BitBay community to be
potentially added to the pool of affiliates. However to be an affiliate you must also be an
active user of the markets. Affiliates do not have to be nodes and may also be marketers.
However when a user doesn't select an affiliate one may be selected randomly among the nodes.

_____________________________________________________________________________________________
Run BitBay web markets simultaneously
_____________________________________________________________________________________________

To allow moderation results to be accessible when your node is offline and to reduce load on
your server, log into BitBay web markets using your password and it should say you are a node.
Then, it will automatically start to build an IPFS database which is shared with users.
There will be gas costs to post this data to the blockchain however it is affordable and you
can choose how many times a day you will scan orders and post the data. Eventually this
data could even be used to improve searches. However, your node must be online for new orders
since they pin to IPFS using your Pinata API or your custom IPFS node.

_____________________________________________________________________________________________
Custom AI models
_____________________________________________________________________________________________

By modifying some of the Python code, a custom AI model could be used for moderation assuming
you are skilled at making a robust set of prompts that have been battle tested for accuracy.
This can be used for image moderation and text moderation(for example using Molmo). Lastly,
you can set up your own IPFS node to reduce the reliance on services like Pinata. This will
allow you to run the entire system at home without having to pay for API keys.
3 changes: 3 additions & 0 deletions node/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@
if (typeof window.globalSessionKey == 'undefined' || window.globalSessionKey == null) {
return {'error':'Server not ready'};
}
if (request.publicKey == '') {
return {'error':'No public key set or the order requested has not been checked yet'};
}
const requestToVerify = document.getElementById("verifyRequest").value;
if(request=='') {
request = JSON.parse(requestToVerify);
Expand Down
Binary file modified node/server.exe
Binary file not shown.
8 changes: 6 additions & 2 deletions node/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import random
import binascii
import traceback
import time
from waitress import serve
from flask_cors import CORS # Import flask-cors

Expand Down Expand Up @@ -108,10 +109,13 @@ def handle_post():
response = {"action": "set", "item": item, "success": success}
elif action == 'verify':
try:
print("Incoming request")
print("Incoming request: " + str(time.time()))
json_data = json.dumps(value)
if 'hash' in value and value['hash'] in reqdb:
json_data2 = json.loads(json_data)
if 'hash' in json_data2 and json_data2['hash'] in reqdb:
return jsonify({"result": json.loads(reqdb[value['hash']])});
if 'publicKey' in json_data2 and json_data2['publicKey'] == '':
return jsonify({"error": "No public key set or the order requested has not been checked yet"}), 500
hex_data = '"'+binascii.hexlify(json_data.encode('utf-8')).decode('utf-8')+'"'
with nonce_lock:
current_nonce = nonce
Expand Down

0 comments on commit b9d355b

Please sign in to comment.