ProofOfPhone at Oracles

This commit is contained in:
viktor 2017-06-30 18:19:54 +03:00
parent 2d1829f31e
commit 6bf5eeacaf
29 changed files with 4115 additions and 1017 deletions

View File

@ -5,25 +5,19 @@ var twilio = require('twilio');
var mongodb = require('mongodb');
var bodyParser = require('body-parser');
var fs = require('fs');
var Web3 = require('web3');
var crypto = require('crypto');
var Web3 = require('web3');
var config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
var twilioClient = twilio(config.sendSMS.twilio.accountSIDLive, config.sendSMS.twilio.authTokenLive);
var MongoClient = mongodb.MongoClient;
var provider = require('./helpers/basicauthhttpprovider');
var web3;
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
if (config.environment == "live") {
web3 = new Web3(new provider(config.smartContract.rpc[config.environment], config.smartContract.rpc.user, config.smartContract.rpc.pass));
}
else
web3 = new Web3(new Web3.providers.HttpProvider(config.smartContract.rpc[config.environment]));
web3 = new Web3(new Web3.providers.HttpProvider(config.Ethereum[config.environment].rpc));
}
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
@ -38,10 +32,6 @@ app.bodyParser = bodyParser;
app.twilioClient = twilioClient;
app.web3 = web3;
app.crypto = crypto;
app.contractAddress = config.smartContract.contractAddress[config.environment];
app.contractWallet = config.smartContract.wallet[config.environment];
app.MongoClient = MongoClient;
function errorHandler(err, req, res, next) {
@ -69,9 +59,8 @@ app.use(express.static(__dirname + '/public'));
app.set('view engine', 'pug');
require('./helpers/commonHelper')(app);
require('./helpers/etherHelper')(app);
require('./controllers/index')(app);
app.listen(app.get('port'), function () {
console.log('Node app is running on port', app.get('port'));
console.log('ProofOfPhone is running on port', app.get('port'));
});

View File

@ -3,35 +3,21 @@ module.exports = function (app) {
var MongoClient = app.MongoClient;
var mongodbConnectionString = app.config.mongodbConnectionString;
var randomInt = app.randomInt;
var attachToContract = app.attachToContract;
var generateError = app.generateError;
var web3 = app.web3;
app.get('/', function(request, response) {
attachToContract(function(err, contract) {
if (err) {
console.log(err);
response.render("index", {
address: app.contractAddress
});
return;
}
response.render("index", {
address: app.contractAddress
});
});
response.render("index");
});
app.post('/sendCodeBySMS', function(request, response) {
console.log(request.body);
var globalToken = request.body.globalToken;
if (globalToken != app.config.globalToken) {
generateError(response, 401, "Unauthorized", "Wrong app token");
return;
}
if (globalToken != app.config.globalToken) return generateError(response, 401, "Unauthorized", "Wrong app token");
var to = request.body.to;
var code = randomInt(100000,1000000);
console.log("code:" + code);
twilioClient.messages.create({
body: code,
to: "+" + to,
@ -39,101 +25,21 @@ module.exports = function (app) {
}, function(err, message) {
if (err) {
console.log(err);
generateError(response, 500, "Can't send sms", err.message);
return;
return generateError(response, 500, "Can't send sms", err.message);
}
console.log("message.sid: " + message.sid);
insertSentCodeToDB(to, code, function(err) {
if (err) {
console.log(err);
generateError(response, 500, "Can't insert code to db", err.message);
return;
}
var token = "0x" + web3.sha3(code.toString());
console.log("sms code:" + code);
response.send({
success : {
code : 200,
title : "Success",
message : "SMS successfully sent"
}
});
});
});
});
function insertSentCodeToDB(phone, code, cb) {
MongoClient.connect(mongodbConnectionString, function(err, db) {
if(err) return cb(err);
var collection = db.collection('PhoneCodes');
collection.remove({phone: phone}, function(err, result) {
if (err) {
db.close();
return cb(err);
}
collection.insert({phone: phone, code: code}, function(err, docs) {
db.close();
if (err) return cb(err);
cb(null);
});
});
});
}
app.post("/verifyCodeFromSMS", function(request, response) {
console.log(request.body);
var globalToken = request.body.globalToken;
var code = request.body.code;
var phone = request.body.phone;
if (globalToken != app.config.globalToken) {
generateError(response, 401, "Unauthorized", "Wrong app token");
return;
}
MongoClient.connect(mongodbConnectionString, function(err, db) {
if (err) {
generateError(response, 500, "Error", err.message);
return;
}
var collection = db.collection('PhoneCodes');
collection.find({"code": parseInt(code), "phone": phone }, function(err, cursor) {
if (err) {
console.log(err);
generateError(response, 500, "Error", "Wrong code");
return;
}
cursor.toArray(function(err, results) {
console.log(err);
if (!results) {
generateError(response, 500, "Error", "Wrong code");
return;
}
if (results.length == 0) {
generateError(response, 500, "Error", "Wrong code");
return;
}
var hash = app.crypto.createHmac('sha256', app.config.salt)
.update(code)
.digest('hex');
console.log(hash);
console.log(results);
var result = results[0];
response.send({
success : {
code : 200,
message: hash
}
});
db.close();
});
});
console.log("sms code:" + code);
response.send({
success : {
code : 200,
title : "Success",
message : "SMS successfully sent",
token: token
}
});
});
});
}

View File

@ -1,146 +0,0 @@
/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file httpprovider.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
* Fabian Vogelsteller <fabian@ethdev.com>
* @date 2015
*/
"use strict";
var errors = require('web3/lib/web3/errors');
// workaround to use httpprovider in different envs
var XMLHttpRequest; // jshint ignore: line
// browser
if (typeof window !== 'undefined' && window.XMLHttpRequest) {
XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line
// node
} else {
XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line
}
/**
* HttpProvider should be used to send rpc calls over http
*/
var HttpProvider = function (host, user, pass) {
this.host = host || 'http://localhost:8545';
this.authorizationHeader = 'Basic ' + (new Buffer(user + ':' + pass)).toString('base64');
this.user = user;
this.pass = pass;
};
/**
* Should be called to prepare new XMLHttpRequest
*
* @method prepareRequest
* @param {Boolean} true if request should be async
* @return {XMLHttpRequest} object
*/
HttpProvider.prototype.prepareRequest = function (async) {
var request = new XMLHttpRequest();
request.open('POST', this.host, async);
request.setRequestHeader('Content-Type','application/json');
request.setRequestHeader('Authorization', this.authorizationHeader);
return request;
};
/**
* Should be called to make sync request
*
* @method send
* @param {Object} payload
* @return {Object} result
*/
HttpProvider.prototype.send = function (payload) {
var request = this.prepareRequest(false);
try {
request.send(JSON.stringify(payload));
} catch(error) {
throw errors.InvalidConnection(this.host);
}
var result = request.responseText;
try {
result = JSON.parse(result);
} catch(e) {
throw errors.InvalidResponse(request.responseText);
}
return result;
};
/**
* Should be used to make async request
*
* @method sendAsync
* @param {Object} payload
* @param {Function} callback triggered on end with (err, result)
*/
HttpProvider.prototype.sendAsync = function (payload, callback) {
var request = this.prepareRequest(true);
request.onreadystatechange = function() {
if (request.readyState === 4) {
var result = request.responseText;
var error = null;
try {
result = JSON.parse(result);
} catch(e) {
error = errors.InvalidResponse(request.responseText);
}
callback(error, result);
}
};
try {
request.send(JSON.stringify(payload));
} catch(error) {
callback(errors.InvalidConnection(this.host));
}
};
/**
* Synchronously tries to make Http request
*
* @method isConnected
* @return {Boolean} returns true if request haven't failed. Otherwise false
*/
HttpProvider.prototype.isConnected = function() {
try {
this.send({
id: 9999999999,
jsonrpc: '2.0',
method: 'net_listening',
params: []
});
return true;
} catch(e) {
return false;
}
};
module.exports = HttpProvider;

View File

@ -1,173 +0,0 @@
module.exports = function (app) {
var web3 = app.web3;
var generateError = app.generateError;
var contract;
app.attachToContract = attachToContract;
var contractABI = app.config.smartContract.abi;
function attachToContract(cb) {
if(!web3.isConnected()) {
if (cb) cb({code: 200, title: "Error", message: "check RPC"}, null);
return;
}
console.log(web3.eth.accounts);
web3.eth.defaultAccount = web3.eth.accounts[0];
console.log("web3.eth.defaultAccount:");
console.log(web3.eth.defaultAccount);
var MyContract = web3.eth.contract(contractABI);
contract = MyContract.at(app.contractAddress);
if (cb) cb(null, contract);
}
function newPhoneToAddr(wallet, phone, cb) {
if(!web3.isConnected()) {
if (cb) cb({code: 500, title: "Error", message: "check RPC"}, null);
return;
}
contract.newPhoneToAddr.sendTransaction(wallet, phone, {gas: 100000, from: web3.eth.defaultAccount}, function(err, result) {
cb(err, result);
});
}
app.post('/newPhoneToAddr', function(request, response) {
var globalToken = request.body.globalToken;
if (globalToken != app.config.globalToken) {
generateError(response, 401, "Unauthorized", "Wrong app token");
return;
}
var phone = parseInt(request.body.phone);
var wallet = request.body.wallet;
var code = request.body.code;
console.log(wallet);
console.log(request.body.wallet);
var isHex = /^0x[0-9A-Fa-f]{40}$/i.test(wallet);
if (!isHex) {
generateError(response, 500, "Error", "Not valid address");
return;
}
if (!contract) {
generateError(response, 500, "Error", "RPC doesn't work");
return;
}
contract.getPaymentByAddress.call(wallet, function(err, val) {
console.log("err:");
console.log(err);
console.log("val:");
console.log(val);
if (val <= 0) {
generateError(response, 1000, "Warning", "Payment wasn't sent yet");
return;
}
contract.getPaymentDataByAddress.call(wallet, function(err, paymentData) {
console.log("err:");
console.log(err);
console.log("paymentData:");
console.log(paymentData);
var hash = app.crypto.createHmac('sha256', app.config.salt)
.update(code)
.digest('hex');
console.log("hash:");
console.log(hash);
//var hashBuf = new Buffer(hash, 'binary').toString('hex');
//console.log("hashBuf:");
//console.log(hashBuf.toString());
console.log(paymentData.substring(2) + " == " + hash);
if (paymentData.substring(2) != hash) {
generateError(response, 1000, "Warning", "Sent message doesn't match with the one displayed on the page");
return;
}
newPhoneToAddr(wallet, phone, function(err, result) {
console.log(err);
console.log(result);
response.send({
success : {
code : 200,
title : "Success",
message : "Phone successfully joined"
}
});
});
});
});
});
app.post('/getPhoneByAddress', function(request, response) {
var globalToken = request.body.globalToken;
if (globalToken != app.config.globalToken) {
generateError(response, 401, "Unauthorized", "Wrong app token");
return;
}
var wallet = request.body.wallet;
var isHex = /^0x[0-9A-Fa-f]{40}$/i.test(wallet);
if (!isHex) {
generateError(response, 500, "Error", "Not valid address");
return;
}
if (!contract) {
generateError(response, 500, "Error", "RPC doesn't work");
return;
}
var phone = contract.getPhoneByAddress.call(wallet, function(err, obj) {
console.log("err:");
console.log(err);
console.log("obj:");
console.log(obj);
response.send({
success : {
code : 200,
title : "Success",
message : "Phone successfully joined",
phone: obj
}
});
});
});
app.post('/getAddressByPhone', function(request, response) {
var globalToken = request.body.globalToken;
if (globalToken != app.config.globalToken) {
generateError(response, 401, "Unauthorized", "Wrong app token");
return;
}
if (!contract) {
generateError(response, 500, "Error", "RPC doesn't work");
return;
}
var phone = parseInt(request.body.phone);
var address = contract.phones.call(phone, function(err, address) {
console.log(address);
response.send({
success : {
code : 200,
title : "Success",
message : "Phone successfully joined",
addr: address
}
});
});
});
};

View File

@ -96,7 +96,7 @@ div.inputContainer {
input.POPInput {
font-family: 'Open Sans', sans-serif;
height: 56px;
width: 400px;
width: 340px;
border: none;
font-size: 14px;
border-radius: 5px;
@ -109,6 +109,8 @@ input.POPInput:focus {
outline-width: 2px;*/
/*box-shadow: 0 0 0 1pt rgb(87,196,223);*/
padding-left: 48px;
width: 338px;
height: 52px;
border: 2px solid rgb(87,196,223) !important;
}
input.POPInput.POPInputPhone {

File diff suppressed because one or more lines are too long

1
web/public/css/sweetalert2.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -20,7 +20,7 @@ gulp.task('javascript', function() {
], {base: '.'}))
.pipe(include())
.pipe(concat('application.js'))
.pipe(uglify())
//.pipe(uglify())
.pipe(gulp.dest('javascripts'));
});

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -1,26 +0,0 @@
function addPhoneToWallet(phone, wallet, code, changeStepNumber, cb) {
$.post("/newPhoneToAddr", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"phone": phone,
"wallet": wallet,
"code": code
}, function( data ) {
cb();
if (data.success) {
changeStepNumber(+1, null);
} else if (data.error.code == 1000) {
swal({
title: "Warning",
text: data.error.message,
type: "warning"
});
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
});
}

View File

@ -0,0 +1,19 @@
function addToken(web3, config, sender, phoneNumber, token, cb) {
console.log(web3);
attachToContract(web3, config, function(err, contract) {
newTokenTX(web3, contract, sender, phoneNumber, token, function(err, txHash) {
//console.log("newTokenTX:");
//console.log("result: " + txHash);
cb(err, txHash);
});
});
}
function newTokenTX(web3, contract, sender, phoneNumber, token, cb) {
if (!web3.isConnected()) return cb({code: 500, title: "Error", message: "check RPC"}, null);
contract.newToken.sendTransaction(phoneNumber, token, {gas: 800000, from: sender}, function(err, result) {
cb(err, result);
});
}

View File

@ -0,0 +1,18 @@
function showAlert(err, msg) {
if (!err) {
swal({
title: "Error",
text: msg,
type: "error"
});
}
else {
if (err.type != "REQUEST_REJECTED") {
swal({
title: "Error",
text: msg,
type: "error"
});
}
}
}

View File

@ -0,0 +1,32 @@
function attachToContract(web3, config, cb) {
if(!web3.isConnected()) {
if (cb) cb({code: 200, title: "Error", message: "check RPC"}, null);
return;
}
console.log(web3.eth.accounts);
web3.eth.defaultAccount = web3.eth.accounts[0];
console.log("web3.eth.defaultAccount:");
console.log(web3.eth.defaultAccount);
var MyContract = web3.eth.contract(config.Ethereum.contracts.ProofOfPhone.abi);
contract = MyContract.at(config.Ethereum[config.environment].contractAddress);
if (cb) cb(null, contract);
}
function getTxCallBack(txHash, cb) {
web3.eth.getTransaction(txHash, function(err, txDetails) {
if (err) console.log(err);
if (!txDetails) {
setTimeout(function() {
getTxCallBack(txHash, cb);
}, 2000);
} else if (!txDetails.blockNumber) {
setTimeout(function() {
getTxCallBack(txHash, cb);
}, 2000)
} else cb();
});
};

View File

@ -0,0 +1,35 @@
//check current network page is connected to. Alerts, if not Oracles network
function checkNetworkVersion(web3, cb) {
var msgNotOracles = "You aren't connected to Oracles network. Please, switch on Oracles plugin and choose Oracles network. Check Oracles network <a href='https://github.com/oraclesorg/oracles-wiki' target='blank'>wiki</a> for more info.";
web3.version.getNetwork(function(err, netId) {
if (err)
console.log(err);
console.log("netId: " + netId);
switch (netId) {
case "1": {
console.log('This is mainnet');
swal("Warning", msgNotOracles, "warning");
cb(false);
} break;
case "2": {
console.log('This is the deprecated Morden test network.');
swal("Warning", msgNotOracles, "warning");
cb(false);
} break;
case "3": {
console.log('This is the ropsten test network.');
swal("Warning", msgNotOracles, "warning");
cb(false);
} break;
case "12648430": {
console.log('This is Oracles from Metamask');
cb(true);
} break;
default: {
console.log('This is an unknown network.');
swal("Warning", msgNotOracles, "warning");
cb(false);
} break;
}
})
}

View File

@ -0,0 +1,37 @@
function deployContract(web3, config, sender) {
var contractABI = config.Ethereum.contracts.ProofOfPhone.abi;
var compiled = config.Ethereum.contracts.ProofOfPhone.bin;
console.log(web3.eth.accounts);
web3.eth.defaultAccount = web3.eth.accounts[0];
var gasWillUsed = web3.eth.estimateGas({
from: web3.eth.defaultAccount,
data: compiled
}, function(err, gasWillUsed) {
console.log(gasWillUsed);
gasWillUsed += 30000;
var proofOfPhoneContract = web3.eth.contract(contractABI);
proofOfPhoneContract.new(
{
data: compiled,
gas: gasWillUsed,
from: sender
}, function(err, contract) {
if (!err) {
if (typeof contract.address != 'undefined') {
console.log("contract:");
console.log(contract);
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
} else {
console.log(contract.transactionHash);
}
} else {
console.log("error:");
console.log(err);
}
});
});
}

View File

@ -0,0 +1,12 @@
//get current account chosen in MetaMask or opened at Parity
function getAccounts(cb) {
web3.eth.getAccounts(function(err, accounts) {
if (err) {
$(".loading-container").hide();
showAlert(err, err.message);
return;
}
cb(accounts);
});
}

View File

@ -1,27 +1,23 @@
function getAddressByPhone(phone, changeStepNumber, cb) {
$.post("/getAddressByPhone", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"phone": phone
}, function( data ) {
cb();
if (data.success) {
if (data.success.addr != "0x0000000000000000000000000000000000000000") {
POPInputWallet.val(data.success.addr);
changeStepNumber(null, 4);
} else {
swal({
title: "Warning",
text: "This phone wasn't set for any wallet yet",
type: "warning"
});
function getAddressByPhone(web3, config, sender, phoneNumber, cb) {
attachToContract(web3, config, function(err, contract) {
getAddressByPhoneCall(web3, contract, sender, phoneNumber, function(err, addr) {
if (err) {
console.log("error: " + err);
cb(err);
return;
}
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
console.log("getAddressByPhoneCall:");
console.log("addr: " + addr);
cb(null, addr);
});
});
}
function getAddressByPhoneCall(web3, contract, sender, phoneNumber, cb) {
if (!web3.isConnected()) cb({code: 500, title: "Error", message: "check RPC"}, null);
contract.getAddressByPhone.call(phoneNumber, {from: sender}, function(err, result) {
cb(err, result);
});
}

View File

@ -0,0 +1,6 @@
//gets config file with address of Oracles contract
function getConfig(cb) {
$.getJSON("./javascripts/config.json", function(config) {
cb(config);
});
}

View File

@ -1,28 +1,23 @@
function getPhoneByAddress(wallet, changeStepNumber, cb) {
$.post("/getPhoneByAddress", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"wallet": wallet
}, function( data ) {
cb();
if (data.success) {
if (data.success.phone != 0) {
POPInputPhone.val(data.success.phone);
changeStepNumber(null, 4);
} else {
swal({
title: "Warning",
text: "Phone wasn't set for this wallet yet",
type: "warning"
});
function getPhoneByAddress(web3, config, sender, addr, cb) {
attachToContract(web3, config, function(err, contract) {
getPhoneByAddressCall(web3, contract, sender, addr, function(err, phone) {
if (err) {
console.log("error: " + err);
cb(err);
return;
}
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
console.log("getPhoneByAddressCall:");
console.log("phone: " + phone);
cb(null, phone);
});
});
}
function getPhoneByAddressCall(web3, contract, sender, addr, cb) {
if (!web3.isConnected()) cb({code: 500, title: "Error", message: "check RPC"}, null);
contract.getPhoneByAddress.call(addr, {from: sender}, function(err, result) {
cb(err, result);
});
}

View File

@ -0,0 +1,22 @@
//gets web3 object from MetaMask or Parity
function getWeb3(callback) {
if (typeof window.web3 === 'undefined') {
// no web3, use fallback
console.error("Please use a web3 browser");
var msgNotEthereum = "You aren't connected to Oracles Network. Please, switch on Oracles plugin and refresh the page. Check Oracles network <a href='https://github.com/oraclesorg/oracles-wiki' target='blank'>wiki</a> for more info.";
swal("Warning", msgNotEthereum, "warning");
callback(myWeb3, false);
} else {
// window.web3 == web3 most of the time. Don't override the provided,
// web3, just wrap it in your Web3.
var myWeb3 = new Web3(window.web3.currentProvider);
// the default account doesn't seem to be persisted, copy it to our
// new instance
myWeb3.eth.defaultAccount = window.web3.eth.defaultAccount;
checkNetworkVersion(myWeb3, function(isOraclesNetwork) {
callback(myWeb3, isOraclesNetwork);
});
}
}

View File

@ -1,452 +1,482 @@
$(document).ready(function() {
var stepNum = $('#stepNum');
var stepLabel = $('.POPLabel');
var stepTitle = $('.POPTitle');
var inputContainer = $('.inputContainer');
var POPInputPhone = $('.POPInputPhone');
var POPInputSMS = $('.POPInputSMS');
var POPInputWallet = $('.POPInputWallet');
var POPSubmit = $('#POPSubmit');
var radioContainer = $('.radioContainer');
var POPradios = $('.POPradio');
var phoneRadio = $('#phoneRadio');
var walletRadio = $('#walletRadio');
var POPBottomDescriptionContainer = $('.POPBottomDescriptionContainer');
var successContainer = $('.successContainer');
var successTableCellWalletValue = $('.successTableCellWalletValue');
var successTableCellPhoneValue = $('.successTableCellPhoneValue');
var token = $('#token');
var loader = $('.loader');
var middleMainContainerInner = $('.middleMainContainerInner');
var bottomDesc = $('#bottomDesc');
var bottomDescAddition = $('#bottomDescAddition');
var bottomDescAddition2 = $('#bottomDescAddition2');
var githubRibbon = $('.githubRibbon');
var copyTable = $('.copyTable');
var copyTableCellWalletValue1 = $('.copyTableCellWalletValue1');
var copyTableCellWalletValue2 = $('.copyTableCellWalletValue2');
var POPTitleContainer = $('.POPTitleContainer');
var POPTitleContainerShortend = $('.POPTitleContainerShortend');
var POPDescContainer = $('.POPDescContainer');
var POPDescContainerShortend = $('.POPDescContainerShortend');
var step1CopyTable = $('#step1CopyTable');
var step3CopyTable = $('#step3CopyTable');
var checkButton = $('#verifyButton');
//location.reload();
var topLabel = $('.topLabel');
var bottomLabelRight = $('.bottomLabelRight');
var homeButton = $('.homeButton');
var shareButton = $('.shareButton');
var copyHashTable = $('#copyHashTable');
var hashToAddress = "";
var checkboxContainer = $(".checkboxContainer");
var POPcheckbox = $(".POPcheckbox");
var privacyPolicyCheckbox = $("#privacyPolicyCheckbox");
var addressVal = $("#addressVal");
var wallet = QueryString.wallet;
if (wallet) {
POPInputWallet.val(wallet);
changeStepNumber(null, 5);
walletRadioCheck();
getPhoneByAddress(POPInputWallet.val(), changeStepNumber, function(err, output) {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
if (!err) {
if (output != 0) {
POPInputPhone.val(output);
changeStepNumber(null, 4);
}
}
//launches main application
function startDapp(web3, isOraclesNetwork) {
console.log(web3);
var sender;
$(function() {
if (!isOraclesNetwork) return;
getAccounts(function(accounts) {
getConfig(function(config) {
getConfigCallBack(web3, accounts, config);
});
});
}
var clientCopyWallet = new ZeroClipboard( document.getElementById("copyWallet") );
var stepNum = $('#stepNum');
var stepLabel = $('.POPLabel');
var stepTitle = $('.POPTitle');
clientCopyWallet.on( "ready", function( readyEvent ) {
clientCopyWallet.on( "beforecopy", function( event ) {
var addr = addressVal.text();
$("#copyWallet").attr("data-clipboard-text",addr);
});
clientCopyWallet.on( "aftercopy", function( event ) {
Materialize.toast('Address copied to buffer', 3000, 'rounded');
});
});
var inputContainer = $('.inputContainer');
var POPInputPhone = $('.POPInputPhone');
var POPInputSMS = $('.POPInputSMS');
var POPInputWallet = $('.POPInputWallet');
var POPSubmit = $('#POPSubmit');
var clientShare = new ZeroClipboard( document.getElementById("POPShare") );
var radioContainer = $('.radioContainer');
var POPradios = $('.POPradio');
var phoneRadio = $('#phoneRadio');
var walletRadio = $('#walletRadio');
clientShare.on( "ready", function( readyEvent ) {
clientShare.on( "beforecopy", function( event ) {
var host = "https://"+window.location.hostname;
var newUrl = host + "/?wallet=" + successTableCellWalletValue.text().trim();
$("#POPShare").attr("data-clipboard-text",newUrl);
});
clientShare.on( "aftercopy", function( event ) {
Materialize.toast('url copied to buffer', 3000, 'rounded');
});
});
var POPBottomDescriptionContainer = $('.POPBottomDescriptionContainer');
var successContainer = $('.successContainer');
var successTableCellWalletValue = $('.successTableCellWalletValue');
var successTableCellPhoneValue = $('.successTableCellPhoneValue');
var token = $('#token');
var loader = $('.loader');
var middleMainContainerInner = $('.middleMainContainerInner');
var bottomDesc = $('#bottomDesc');
var bottomDescAddition = $('#bottomDescAddition');
var bottomDescAddition2 = $('#bottomDescAddition2');
var githubRibbon = $('.githubRibbon');
var copyTable = $('.copyTable');
var copyTableCellWalletValue1 = $('.copyTableCellWalletValue1');
copyTableCellWalletValue1.text("0xf7e9626dbaeb1a6c8b3d02379eb54b81f16e785f");
var copyTableCellWalletValue2 = $('.copyTableCellWalletValue2');
phoneRadio.click(function(e) {
phoneRadioCheck();
});
var POPTitleContainer = $('.POPTitleContainer');
var POPTitleContainerShortend = $('.POPTitleContainerShortend');
var POPDescContainer = $('.POPDescContainer');
var POPDescContainerShortend = $('.POPDescContainerShortend');
POPcheckbox.click(function(e) {
if ($(this).find(".POPcheckboxSelected")[0]) {
$(this).find(".POPcheckboxSelected").addClass("POPcheckboxUnselected");
$(this).find(".POPcheckboxSelected").removeClass("POPcheckboxSelected");
privacyPolicyCheckbox.prop( "checked", false );
} else {
$(this).find(".POPcheckboxUnselected").addClass("POPcheckboxSelected");
$(this).find(".POPcheckboxUnselected").removeClass("POPcheckboxUnselected");
privacyPolicyCheckbox.prop( "checked", true );
}
});
var step1CopyTable = $('#step1CopyTable');
var step3CopyTable = $('#step3CopyTable');
var checkButton = $('#verifyButton');
function phoneRadioCheck() {
POPradios.each(function(e) {
$(this).find('.POPRadioInner').removeClass('POPradioSelected');
$(this).find('.POPRadioInner').addClass('POPradioUnselected');
});
phoneRadio.find('.POPRadioInner').removeClass('POPradioUnselected');
phoneRadio.find('.POPRadioInner').addClass('POPradioSelected');
POPInputPhone.removeClass('hide');
POPInputPhone.focus();
POPInputWallet.addClass('hide');
$("#radioCheckPhone").prop("checked", true);
}
var topLabel = $('.topLabel');
var bottomLabelRight = $('.bottomLabelRight');
var homeButton = $('.homeButton');
var shareButton = $('.shareButton');
var copyHashTable = $('#copyHashTable');
var checkboxContainer = $(".checkboxContainer");
var POPcheckbox = $(".POPcheckbox");
var privacyPolicyCheckbox = $("#privacyPolicyCheckbox");
walletRadio.click(function(e) {
walletRadioCheck();
});
var addressVal = $("#addressVal");
function walletRadioCheck() {
POPradios.each(function(e) {
$(this).find('.POPRadioInner').removeClass('POPradioSelected');
$(this).find('.POPRadioInner').addClass('POPradioUnselected');
});
walletRadio.find('.POPRadioInner').removeClass('POPradioUnselected');
walletRadio.find('.POPRadioInner').addClass('POPradioSelected');
POPInputWallet.removeClass('hide');
POPInputWallet.focus();
POPInputPhone.addClass('hide');
$("#radioCheckWallet").prop("checked", true);
}
function getConfigCallBack(web3, accounts, config) {
console.log(accounts);
if (accounts.length == 1) {
sender = accounts[0];
POPInputWallet.val(sender);
} else {
swal("Warning", "You haven't chosen any account in Oracles plugin. Please, choose your account in Oracles plugin and reload the page. Check Oracles network <a href='https://github.com/oraclesorg/oracles-wiki' target='blank'>wiki</a> for more info.", "warning");
}
topLabel.click(function(e) {
location.reload();
});
var wallet = QueryString.wallet;
if (wallet) {
POPInputWallet.val(wallet);
changeStepNumber(null, 4);
walletRadioCheck();
getPhoneByAddress(web3, config, sender, POPInputWallet.val(), function(err, phone) {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
if (!err) {
if (phone != 0) {
POPInputPhone.val(phone);
changeStepNumber(null, 3);
}
}
});
}
bottomLabelRight.click(function(e) {
location.reload();
});
var clientCopyWallet = new ZeroClipboard( document.getElementById("copyWallet") );
githubRibbon.click(function(e) {
window.open("https://github.com/blocknotary/proofofphone", "_blank");
});
clientCopyWallet.on( "ready", function( readyEvent ) {
clientCopyWallet.on( "beforecopy", function( event ) {
var addr = addressVal.text();
$("#copyWallet").attr("data-clipboard-text",addr);
});
clientCopyWallet.on( "aftercopy", function( event ) {
Materialize.toast('Address copied to buffer', 3000, 'rounded');
});
});
homeButton.click(function(e) {
location.reload();
});
var clientShare = new ZeroClipboard( document.getElementById("POPShare") );
checkButton.click(function(e) {
changeStepNumber(null, 5);
});
clientShare.on( "ready", function( readyEvent ) {
clientShare.on( "beforecopy", function( event ) {
var host = "https://"+window.location.hostname;
var newUrl = host + "/?wallet=" + successTableCellWalletValue.text().trim();
$("#POPShare").attr("data-clipboard-text",newUrl);
});
clientShare.on( "aftercopy", function( event ) {
Materialize.toast('url copied to buffer', 3000, 'rounded');
});
});
POPSubmit.click(function(e) {
submit();
});
phoneRadio.click(function(e) {
phoneRadioCheck();
});
POPInputPhone.keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
POPSubmit.click();
return false;
}
});
POPcheckbox.click(function(e) {
if ($(this).find(".POPcheckboxSelected")[0]) {
$(this).find(".POPcheckboxSelected").addClass("POPcheckboxUnselected");
$(this).find(".POPcheckboxSelected").removeClass("POPcheckboxSelected");
privacyPolicyCheckbox.prop( "checked", false );
} else {
$(this).find(".POPcheckboxUnselected").addClass("POPcheckboxSelected");
$(this).find(".POPcheckboxUnselected").removeClass("POPcheckboxUnselected");
privacyPolicyCheckbox.prop( "checked", true );
}
});
POPInputSMS.keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
POPSubmit.click();
return false;
}
});
walletRadio.click(function(e) {
walletRadioCheck();
});
POPInputWallet.keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
POPSubmit.click();
return false;
}
});
topLabel.click(function(e) {
location.reload();
});
function submit() {
var visibleInput = $('input:visible');
var curStepNum = parseInt(stepNum.val());
if (visibleInput.val() != "") {
middleMainContainerInner.fadeOut(500);
loader.removeClass('hide');
switch(curStepNum) {
bottomLabelRight.click(function(e) {
location.reload();
});
githubRibbon.click(function(e) {
window.open("https://github.com/blocknotary/proofofphone", "_blank");
});
homeButton.click(function(e) {
location.reload();
});
checkButton.click(function(e) {
changeStepNumber(null, 4);
});
POPSubmit.click(function(e) {
submit(config, sender);
});
POPInputPhone.keypress(function (e) {
var key = e.which;
if (key == 13) { // the enter key code
POPSubmit.click();
return false;
}
});
POPInputSMS.keypress(function (e) {
var key = e.which;
if (key == 13) { // the enter key code
POPSubmit.click();
return false;
}
});
POPInputWallet.keypress(function (e) {
var key = e.which;
if (key == 13) { // the enter key code
POPSubmit.click();
return false;
}
});
}
function phoneRadioCheck() {
POPradios.each(function(e) {
$(this).find('.POPRadioInner').removeClass('POPradioSelected');
$(this).find('.POPRadioInner').addClass('POPradioUnselected');
});
phoneRadio.find('.POPRadioInner').removeClass('POPradioUnselected');
phoneRadio.find('.POPRadioInner').addClass('POPradioSelected');
POPInputPhone.removeClass('hide');
POPInputPhone.focus();
POPInputWallet.addClass('hide');
$("#radioCheckPhone").prop("checked", true);
}
function walletRadioCheck() {
POPradios.each(function(e) {
$(this).find('.POPRadioInner').removeClass('POPradioSelected');
$(this).find('.POPRadioInner').addClass('POPradioUnselected');
});
walletRadio.find('.POPRadioInner').removeClass('POPradioUnselected');
walletRadio.find('.POPRadioInner').addClass('POPradioSelected');
POPInputWallet.removeClass('hide');
POPInputWallet.focus();
POPInputPhone.addClass('hide');
$("#radioCheckWallet").prop("checked", true);
}
function submit(config, sender) {
var visibleInput = $('input:visible');
var curStepNum = parseInt(stepNum.val());
if (visibleInput.val() != "") {
middleMainContainerInner.fadeOut(500);
loader.removeClass('hide');
switch(curStepNum) {
case 1: {
var phoneNumber = parseInt(visibleInput.val());
sendCodeBySMS(phoneNumber, function(err, token) {
if (err) {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
return showAlert(err, err.message);
}
addToken(web3, config, sender, phoneNumber, token, function(err, txHash) {
if (err) {
if (err.type != "REQUEST_REJECTED") showAlert(err, err.message);
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
return;
}
if (txHash) {
getTxCallBack(txHash, function() {
changeStepNumber(+1, null);
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
swal({
title: "Success",
text: "Code successfully sent by SMS",
type: "success"
});
});
}
});
});
} break;
case 2: {
var code = POPInputSMS.val();
var token = web3.sha3(code);
verifyCodeFromSMS(web3, config, sender, token, function(err, txHash) {
if (err) {
if (err.type != "REQUEST_REJECTED") showAlert(null, "Invalid code entered");
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
return;
}
if (txHash) {
getTxCallBack(txHash, function() {
changeStepNumber(+1, null);
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
});
}
});
} break;
case 4:
{
var radioVal = $('input[name=radioCheck]:checked').val();
if (radioVal == "wallet") {
getPhoneByAddress(web3, config, sender, POPInputWallet.val(), function(err, phone) {
if (err) return showAlert(err, err.message);
console.log(phone);
if (phone != 0) {
POPInputPhone.val(phone);
changeStepNumber(null, 3);
} else {
swal({
title: "Warning",
text: "Phone wasn't set for this wallet yet",
type: "warning"
});
}
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
});
} else {
getAddressByPhone(web3, config, sender, POPInputPhone.val(), function(err, addr) {
if (err) return showAlert(err, err.message);
if (addr != "0x0000000000000000000000000000000000000000" && addr != "0x") {
POPInputWallet.val(addr);
changeStepNumber(null, 3);
} else {
swal({
title: "Warning",
text: "This phone wasn't set for any wallet yet",
type: "warning"
});
}
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
});
}
}
break;
default:
{
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
}
break;
}
} else visibleInput.focus();
}
function changeStepNumber(addition, absolute) {
var newStepVal = 0;
if (addition) newStepVal = parseInt(stepNum.val()) + addition;
else newStepVal = absolute;
stepNum.val(newStepVal);
var newStepNum = parseInt(stepNum.val());
stepLabel.text("Step " + newStepNum);
switch(newStepNum) {
case 1:
sendCodeBySMS(visibleInput.val(), changeStepNumber, function() {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
});
{
stepTitle.text("Submit your phone number");
bottomDesc.text("Enter a phone number you'd like to join with your Ethereum address. We will send you an SMS. After verification, we will ask you to deposit a service fee of 0.1 ether to a smart contract at the address");
stepLabel.removeClass("hide");
radioContainer.addClass("hide");
inputContainer.show();
POPBottomDescriptionContainer.show();
POPInputPhone.removeClass('hide');
POPInputPhone.focus();
POPInputSMS.addClass('hide');
POPInputWallet.addClass('hide');
POPBottomDescriptionContainer.removeClass("hide");
copyTable.show();
step1CopyTable.removeClass("hide");
step3CopyTable.addClass("hide");
bottomDescAddition.addClass("hide");
copyHashTable.addClass("hide");
successContainer.addClass("hide");
POPTitleContainerShortend.addClass("POPTitleContainer");
POPTitleContainerShortend.removeClass("POPTitleContainerShortend");
POPDescContainerShortend.addClass("POPDescContainer");
POPDescContainerShortend.removeClass("POPDescContainerShortend");
checkboxContainer.removeClass("hide");
}
break;
case 2:
verifyCodeFromSMS(POPInputSMS.val(), POPInputPhone.val(), changeStepNumber, function() {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
});
{
stepTitle.text("Submit received code");
bottomDesc.text("Copy the code from the SMS to continue");
stepLabel.removeClass("hide");
radioContainer.addClass("hide");
inputContainer.show();
POPBottomDescriptionContainer.show();
POPInputPhone.addClass('hide');
POPInputSMS.removeClass('hide');
POPInputSMS.focus();
POPInputWallet.addClass('hide');
POPBottomDescriptionContainer.removeClass("hide");
step1CopyTable.addClass("hide");
step3CopyTable.addClass("hide");
bottomDescAddition.addClass("hide");
copyHashTable.addClass("hide");
successContainer.addClass("hide");
POPTitleContainerShortend.addClass("POPTitleContainer");
POPTitleContainerShortend.removeClass("POPTitleContainerShortend");
POPDescContainerShortend.addClass("POPDescContainer");
POPDescContainerShortend.removeClass("POPDescContainerShortend");
checkboxContainer.addClass("hide");
}
break;
case 3:
addPhoneToWallet(POPInputPhone.val(), POPInputWallet.val(), POPInputSMS.val(), changeStepNumber, function() {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
});
break;
case 5:
{
var radioVal = $('input[name=radioCheck]:checked').val();
if (radioVal == "wallet") {
getPhoneByAddress(POPInputWallet.val(), changeStepNumber, function() {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
});
} else {
getAddressByPhone(POPInputPhone.val(), changeStepNumber, function() {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
});
}
stepTitle.text("Success");
stepLabel.addClass("hide");
POPBottomDescriptionContainer.hide();
bottomDescAddition2.html('There is a smart contract deployed to the Oracles network. You can find it here:\
<table cellspacing="0" cellpadding="0" class="copyTable nomargin" style="display: table;"><tbody class="copyTableBody"><tr><td class="copyTableCellWalletValue2">'
+ copyTableCellWalletValue1.text() +
'</td><td id="copyWallet3" data-clipboard-text="'+ copyTableCellWalletValue1.text() + '" class="copyTableCellCopyButton"></td></tr></tbody></table>This contract has the following public method signature:\
hasPhone (address _addr).<br/>\
If the _addr is registered in the contract\'s Phone Registry, the hasPhone method returns true. Otherwise it returns false.');
successTableCellWalletValue.text(POPInputWallet.val());
successTableCellPhoneValue.text(POPInputPhone.val());
radioContainer.addClass("hide");
inputContainer.hide();
POPBottomDescriptionContainer.addClass("hide");
step1CopyTable.addClass("hide");
step3CopyTable.addClass("hide");
bottomDescAddition.addClass("hide");
bottomDescAddition2.removeClass("hide");
copyHashTable.addClass("hide");
successContainer.removeClass("hide");
POPTitleContainerShortend.addClass("POPTitleContainer");
POPTitleContainerShortend.removeClass("POPTitleContainerShortend");
POPDescContainerShortend.addClass("POPDescContainer");
POPDescContainerShortend.removeClass("POPDescContainerShortend");
checkboxContainer.addClass("hide");
var clientCopyWallet3 = new ZeroClipboard( $("#copyWallet3")[0] );
clientCopyWallet3.on( "ready", function( readyEvent ) {
clientCopyWallet3.on( "aftercopy", function( event ) {
Materialize.toast('Address copied to buffer', 3000, 'rounded');
});
});
}
break;
case 4:
{
stepTitle.text("Check");
bottomDesc.html('Enter a phone number or an Ethereum address to continue. <br/>\
There is a smart contract deployed to the Oracles network. You can find it here:\
<table cellspacing="0" cellpadding="0" class="copyTable nomargin" style="display: table;"><tbody class="copyTableBody"><tr><td class="copyTableCellWalletValue2">'
+ copyTableCellWalletValue1.text() +
'</td><td id="copyWallet2" data-clipboard-text="'+ copyTableCellWalletValue1.text() + '" class="copyTableCellCopyButton"></td></tr></tbody></table>This contract has the following public method signature:\
hasPhone (address _addr).<br/>\
If the _addr is registered in the contract\'s Phone Registry, the hasPhone method returns true. Otherwise it returns false.');
POPBottomDescriptionContainer.show();
stepLabel.addClass("hide");
phoneRadioCheck();
radioContainer.removeClass("hide");
inputContainer.show();
POPBottomDescriptionContainer.show();
POPInputPhone.removeClass('hide');
POPInputPhone.focus();
POPInputSMS.addClass('hide');
POPInputWallet.addClass('hide');
POPBottomDescriptionContainer.removeClass("hide");
step1CopyTable.addClass("hide");
step3CopyTable.addClass("hide");
bottomDescAddition.addClass("hide");
bottomDescAddition2.addClass("hide");
copyHashTable.addClass("hide");
successContainer.addClass("hide");
POPTitleContainer.addClass("POPTitleContainerShortend");
POPTitleContainer.removeClass("POPTitleContainer");
POPDescContainer.addClass("POPDescContainerShortend");
POPDescContainer.removeClass("POPDescContainer");
var clientCopyWallet2 = new ZeroClipboard( $("#copyWallet2")[0] );
console.log(clientCopyWallet2);
clientCopyWallet2.on( "ready", function( readyEvent ) {
clientCopyWallet2.on( "aftercopy", function( event ) {
Materialize.toast('Address copied to buffer', 3000, 'rounded');
});
});
checkboxContainer.addClass("hide");
}
break;
default:
{
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
stepTitle.text("Submit your phone number");
stepLabel.removeClass("hide");
POPBottomDescriptionContainer.removeClass("hide");
step1CopyTable.addClass("hide");
step3CopyTable.addClass("hide");
bottomDescAddition.addClass("hide");
bottomDescAddition2.addClass("hide");
copyHashTable.addClass("hide");
successContainer.addClass("hide");
}
break;
}
} else visibleInput.focus();
}
function changeStepNumber(addition, absolute) {
console.log(hashToAddress);
var newStepVal = 0;
if (addition) newStepVal = parseInt(stepNum.val()) + addition;
else newStepVal = absolute;
stepNum.val(newStepVal);
var newStepNum = parseInt(stepNum.val());
stepLabel.text("Step " + newStepNum);
switch(newStepNum) {
case 1:
{
stepTitle.text("Submit your phone number");
bottomDesc.text("Enter a phone number you'd like to join with your Ethereum address. We will send you an SMS. After verification, we will ask you to deposit a service fee of 0.1 ether to a smart contract at the address");
stepLabel.removeClass("hide");
radioContainer.addClass("hide");
inputContainer.show();
POPBottomDescriptionContainer.show();
POPInputPhone.removeClass('hide');
POPInputPhone.focus();
POPInputSMS.addClass('hide');
POPInputWallet.addClass('hide');
POPBottomDescriptionContainer.removeClass("hide");
copyTable.show();
step1CopyTable.removeClass("hide");
step3CopyTable.addClass("hide");
bottomDescAddition.addClass("hide");
copyHashTable.addClass("hide");
successContainer.addClass("hide");
POPTitleContainerShortend.addClass("POPTitleContainer");
POPTitleContainerShortend.removeClass("POPTitleContainerShortend");
POPDescContainerShortend.addClass("POPDescContainer");
POPDescContainerShortend.removeClass("POPDescContainerShortend");
checkboxContainer.removeClass("hide");
}
break;
case 2:
{
stepTitle.text("Submit received code");
bottomDesc.text("Copy the code from the SMS to continue");
stepLabel.removeClass("hide");
radioContainer.addClass("hide");
inputContainer.show();
POPBottomDescriptionContainer.show();
POPInputPhone.addClass('hide');
POPInputSMS.removeClass('hide');
POPInputSMS.focus();
POPInputWallet.addClass('hide');
POPBottomDescriptionContainer.removeClass("hide");
step1CopyTable.addClass("hide");
step3CopyTable.addClass("hide");
bottomDescAddition.addClass("hide");
copyHashTable.addClass("hide");
successContainer.addClass("hide");
POPTitleContainerShortend.addClass("POPTitleContainer");
POPTitleContainerShortend.removeClass("POPTitleContainerShortend");
POPDescContainerShortend.addClass("POPDescContainer");
POPDescContainerShortend.removeClass("POPDescContainerShortend");
checkboxContainer.addClass("hide");
}
break;
case 3:
{
stepTitle.text("Submit your Ethereum address");
bottomDesc.text("Deposit service fee of 0.1 ETH to a smart contract with a message");
$("#hashVal").text(hashToAddress);
var clientCopyHash = new ZeroClipboard( document.getElementById("hashCopy") );
clientCopyHash.on( "ready", function( readyEvent ) {
clientCopyHash.on( "beforecopy", function( event ) {
$("#hashCopy").attr("data-clipboard-text", hashToAddress);
});
clientCopyHash.on( "aftercopy", function( event ) {
Materialize.toast('message copied to buffer', 3000, 'rounded');
});
});
bottomDescAddition.html("at the address");
stepLabel.removeClass("hide");
radioContainer.addClass("hide");
inputContainer.show();
POPBottomDescriptionContainer.show();
POPInputPhone.addClass('hide');
POPInputSMS.addClass('hide');
POPInputWallet.removeClass('hide');
POPInputWallet.focus();
POPBottomDescriptionContainer.removeClass("hide");
step1CopyTable.addClass("hide");
step3CopyTable.removeClass("hide");
bottomDescAddition.removeClass("hide");
copyHashTable.removeClass("hide");
successContainer.addClass("hide");
POPTitleContainerShortend.addClass("POPTitleContainer");
POPTitleContainerShortend.removeClass("POPTitleContainerShortend");
POPDescContainerShortend.addClass("POPDescContainer");
POPDescContainerShortend.removeClass("POPDescContainerShortend");
checkboxContainer.addClass("hide");
}
break;
case 4:
{
stepTitle.text("Success");
stepLabel.addClass("hide");
POPBottomDescriptionContainer.hide();
/*bottomDescAddition2.html('There is a smart contract has the following public method signature:\
<table cellspacing="0" cellpadding="0" class="copyTable nomargin" style="display: table;"><tbody class="copyTableBody"><tr><td class="copyTableCellWalletValue1">\
hasPhone (address _addr)\
</td></tr></tbody></table>\
If the _addr is registered in the contract\'s Phone Registry, the hasPhone method returns true. Otherwise it returns false.');
*/
bottomDescAddition2.html('There is a smart contract deployed to the public ethereum Blockchain. You can find it here:\
<table cellspacing="0" cellpadding="0" class="copyTable nomargin" style="display: table;"><tbody class="copyTableBody"><tr><td class="copyTableCellWalletValue2">'
+ copyTableCellWalletValue1.text() +
'</td><td id="copyWallet3" data-clipboard-text="'+ copyTableCellWalletValue1.text() + '" class="copyTableCellCopyButton"></td></tr></tbody></table>This contract has the following public method signature:\
hasPhone (address _addr).<br/>\
If the _addr is registered in the contract\'s Phone Registry, the hasPhone method returns true. Otherwise it returns false.');
successTableCellWalletValue.text(POPInputWallet.val());
successTableCellPhoneValue.text(POPInputPhone.val());
radioContainer.addClass("hide");
inputContainer.hide();
POPBottomDescriptionContainer.addClass("hide");
step1CopyTable.addClass("hide");
step3CopyTable.addClass("hide");
bottomDescAddition.addClass("hide");
bottomDescAddition2.removeClass("hide");
copyHashTable.addClass("hide");
successContainer.removeClass("hide");
POPTitleContainerShortend.addClass("POPTitleContainer");
POPTitleContainerShortend.removeClass("POPTitleContainerShortend");
POPDescContainerShortend.addClass("POPDescContainer");
POPDescContainerShortend.removeClass("POPDescContainerShortend");
checkboxContainer.addClass("hide");
var clientCopyWallet3 = new ZeroClipboard( $("#copyWallet3")[0] );
clientCopyWallet3.on( "ready", function( readyEvent ) {
clientCopyWallet3.on( "aftercopy", function( event ) {
Materialize.toast('Address copied to buffer', 3000, 'rounded');
});
});
}
break;
case 5:
{
stepTitle.text("Check");
bottomDesc.html('Enter a phone number or an ethereum address to continue. <br/>\
There is a smart contract deployed to the public ethereum Blockchain. You can find it here:\
<table cellspacing="0" cellpadding="0" class="copyTable nomargin" style="display: table;"><tbody class="copyTableBody"><tr><td class="copyTableCellWalletValue2">'
+ copyTableCellWalletValue1.text() +
'</td><td id="copyWallet2" data-clipboard-text="'+ copyTableCellWalletValue1.text() + '" class="copyTableCellCopyButton"></td></tr></tbody></table>This contract has the following public method signature:\
hasPhone (address _addr).<br/>\
If the _addr is registered in the contract\'s Phone Registry, the hasPhone method returns true. Otherwise it returns false.');
POPBottomDescriptionContainer.show();
stepLabel.addClass("hide");
phoneRadioCheck();
radioContainer.removeClass("hide");
inputContainer.show();
POPBottomDescriptionContainer.show();
POPInputPhone.removeClass('hide');
POPInputPhone.focus();
POPInputSMS.addClass('hide');
POPInputWallet.addClass('hide');
POPBottomDescriptionContainer.removeClass("hide");
step1CopyTable.addClass("hide");
step3CopyTable.addClass("hide");
bottomDescAddition.addClass("hide");
bottomDescAddition2.addClass("hide");
copyHashTable.addClass("hide");
successContainer.addClass("hide");
POPTitleContainer.addClass("POPTitleContainerShortend");
POPTitleContainer.removeClass("POPTitleContainer");
POPDescContainer.addClass("POPDescContainerShortend");
POPDescContainer.removeClass("POPDescContainer");
var clientCopyWallet2 = new ZeroClipboard( $("#copyWallet2")[0] );
console.log(clientCopyWallet2);
clientCopyWallet2.on( "ready", function( readyEvent ) {
clientCopyWallet2.on( "aftercopy", function( event ) {
Materialize.toast('Address copied to buffer', 3000, 'rounded');
});
});
checkboxContainer.addClass("hide");
}
break;
default:
{
stepTitle.text("Submit your phone number");
stepLabel.removeClass("hide");
POPBottomDescriptionContainer.removeClass("hide");
step1CopyTable.addClass("hide");
step3CopyTable.addClass("hide");
bottomDescAddition.addClass("hide");
bottomDescAddition2.addClass("hide");
copyHashTable.addClass("hide");
successContainer.addClass("hide");
}
break;
}
}
});
}
window.addEventListener('load', function() {
getWeb3(startDapp);
});

View File

@ -1,23 +1,11 @@
function sendCodeBySMS(phone, changeStepNumber, cb) {
function sendCodeBySMS(phone, cb) {
//cb(null, "0xc888c9ce9e098d5864d3ded6ebcc140a12142263bace3a23a36f9905f12bd64a");
$.post("/sendCodeBySMS", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"to": phone
}, function( data ) {
console.log( data );
if (data.success) {
changeStepNumber(+1, null);
token.val(data.success.code);
swal({
title: "Success",
text: "Code successfully sent by SMS",
type: "success"
});
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
console.log( data );
if (data.success) cb(null, data.success.token);
else cb(data.error, null);
});
}

View File

@ -1,27 +1,24 @@
function verifyCodeFromSMS(code, phone, changeStepNumber, cb) {
$.post("/verifyCodeFromSMS", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"code": code,
"phone": phone
}, function( data ) {
cb();
console.log( data );
if (data.success) {
hashToAddress = data.success.message;
console.log(hashToAddress);
changeStepNumber(+1, null);
token.val(data.success.code);
swal({
title: "Success",
text: "Code successfully verified",
type: "success"
});
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
function verifyCodeFromSMS(web3, config, sender, token, cb) {
activatePair(web3, config, sender, token, function(err, txHash) {
cb(err, txHash);
});
}
function activatePair(web3, config, sender, token, cb) {
attachToContract(web3, config, function(err, contract) {
activatePairTX(web3, contract, sender, token, function(err, txHash) {
//console.log("activatePairTX:");
//console.log("result: " + txHash);
cb(err, txHash);
});
});
}
function activatePairTX(web3, contract, sender, token, cb) {
if (!web3.isConnected()) cb({code: 500, title: "Error", message: "check RPC"}, null);
contract.activatePair.sendTransaction(token, {gas: 800000, from: sender}, function(err, result) {
cb(err, result);
});
}

View File

@ -0,0 +1,17 @@
{
"environment": "dev",
"Ethereum": {
"dev": {
"contractAddress": "0x9bdf3f3d61f23f0d4eba9fff950b8facb6628fc3"
},
"live": {
"contractAddress": "0x9bdf3f3d61f23f0d4eba9fff950b8facb6628fc3"
},
"contracts": {
"ProofOfPhone": {
"bin": "0x6060604052341561000c57fe5b5b6106438061001c6000396000f30060606040523615610081576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806303679666146100835780633404fe32146100e357806371d01c73146101105780639fbebee51461015a578063b958a5e11461017e578063ceaecc84146101c8578063fe97ee8814610228575bfe5b341561008b57fe5b6100a16004808035906020019091905050610276565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156100eb57fe5b61010e6004808035906020019091908035600019169060200190919050506102b4565b005b341561011857fe5b610144600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610354565b6040518082815260200191505060405180910390f35b341561016257fe5b61017c60048080356000191690602001909190505061036c565b005b341561018657fe5b6101b2600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610537565b6040518082815260200191505060405180910390f35b34156101d057fe5b6101e66004808035906020019091905050610581565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561023057fe5b61025c600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506105b4565b604051808215151515815260200191505060405180910390f35b60006001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505b919050565b6040604051908101604052808381526020013373ffffffffffffffffffffffffffffffffffffffff168152506002600083600019166000191681526020019081526020016000206000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055509050505b5050565b60006020528060005260406000206000915090505481565b3373ffffffffffffffffffffffffffffffffffffffff1660026000836000191660001916815260200190815260200160002060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415156103e55760006000fd5b60026000826000191660001916815260200190815260200160002060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166001600060026000856000191660001916815260200190815260200160002060000154815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600260008260001916600019168152602001908152602001600020600001546000600060026000856000191660001916815260200190815260200160002060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b50565b6000600060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490505b919050565b60016020528060005260406000206000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60006000600060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415156106085760019050610612565b60009050610612565b5b9190505600a165627a7a7230582007f136df6454b733e1e101a03dccfd4fd2ad950dcba0025499b3f7a16c993ca50029",
"abi": [{"constant":true,"inputs":[{"name":"phone","type":"uint256"}],"name":"getAddressByPhone","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"phone","type":"uint256"},{"name":"codeToken","type":"bytes32"}],"name":"newToken","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"addressPhonePair","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"codeToken","type":"bytes32"}],"name":"activatePair","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"getPhoneByAddress","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"phoneAddressPair","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"hasPhone","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"}]
}
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
//=require ZeroClipboard.js
//=require jquery.min.js
//=require materialize.min.js
//=require sweetalert.min.js
//=require web3.js
//=require ZeroClipboard.js
//=require materialize.min.js

1
web/public/javascripts/vendor/web3.js vendored Executable file

File diff suppressed because one or more lines are too long

View File

@ -1,20 +1,20 @@
doctype html
html
head
title Proof of Phone
link(href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700', rel='stylesheet', type='text/css').
link(href="img/favicon.ico",rel="icon" type="image/x-icon").
link(rel="stylesheet",href="/css/materialize.css").
link(rel="stylesheet", href="/css/header.css").
link(rel="stylesheet", href="/css/index.css").
link(rel="stylesheet", href="/css/loader.css").
link(rel="stylesheet",href="/css/sweetalert.css").
link(rel="stylesheet",href="./css/materialize.css").
link(rel="stylesheet", href="./css/header.css").
link(rel="stylesheet", href="./css/index.css").
link(rel="stylesheet", href="./css/loader.css").
link(rel="stylesheet",href="./css/sweetalert2.min.css").
meta(property="og:site_name", content="Proof of Phone").
meta(property="og:title", content="Join your phone number and ethereum address.").
meta(property="og:description", content="Proof of phone is a smart oracle developed for the Ethereum blockchain to serve as a simple form of KYC (Know-Your-Customer).").
meta(property="og:description", content="Proof of phone is a smart oracle developed for the Oracles network to serve as a simple form of KYC (Know-Your-Customer).").
meta(property="og:url", content="https://www.proofofphone.com").
meta(property="og:image", content= "https://dl.dropboxusercontent.com/s/zzudapto6w9ch3g/proof.png").
meta(property="fb:app_id" content="947082938740795").
<!-- Yandex.Metrika counter --> <script type="text/javascript"> (function (d, w, c) { (w[c] = w[c] || []).push(function() { try { w.yaCounter37176425 = new Ya.Metrika({ id:37176425, clickmap:true, trackLinks:true, accurateTrackBounce:true, webvisor:true, trackHash:true }); } catch(e) { } }); var n = d.getElementsByTagName("script")[0], s = d.createElement("script"), f = function () { n.parentNode.insertBefore(s, n); }; s.type = "text/javascript"; s.async = true; s.src = "https://mc.yandex.ru/metrika/watch.js"; if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); } })(document, window, "yandex_metrika_callbacks"); </script> <noscript><div><img src="https://mc.yandex.ru/watch/37176425" style="position:absolute; left:-9999px;" alt="" /></div></noscript> <!-- /Yandex.Metrika counter -->
body.mainBody
include ./top.pug
div.middleMainContainer
@ -40,7 +40,7 @@ html
div.POPTitleContainer
label.POPTitle Submit your phone number
div.POPDescContainer.marginBottom2
label#topDesc.POPDesc Proof of phone is a smart oracle developed for the Ethereum blockchain to serve as a simple form of KYC (Know-Your-Customer).
label#topDesc.POPDesc Proof of phone is a smart oracle developed for the Oracles network to serve as a simple form of KYC (Know-Your-Customer).
div.inputContainer
div.radioContainer.hide
input(type="radio", id="radioCheckPhone", name="radioCheck", value="phone").hide
@ -70,7 +70,7 @@ html
div.POPTitleContainer.marginBottom1
label.POPTitle2 How does it work?
div.POPDescContainer
label#bottomDesc.POPDesc Enter a phone number you'd like to join with your Ethereum address. We will send you an SMS. After verification, we will ask you to deposit a service fee of 0.1 ether to a smart contract at the address
label#bottomDesc.POPDesc Enter a phone number you'd like to join with your Ethereum address. We will send you an SMS. After verification, your address will be joined to your phone.
table#copyHashTable(cellspacing="0" cellpadding="0").copyTable.nomargin.hide
tbody.copyTableBody
tr
@ -88,7 +88,7 @@ html
table#step1CopyTable(cellspacing="0" cellpadding="0").copyTable.marginTop1
tbody.copyTableBody
tr
td.copyTableCellWalletValue1= address
td.copyTableCellWalletValue1.hide
div.successContainer.hide
table(cellspacing="0" cellpadding="0").successTable
tbody.successTableBody
@ -113,4 +113,5 @@ html
div.loader-i.loader-i_left-bottom
div.loader-i.loader-i_right-bottom
include ./bottom.pug
script(type="text/javascript" src="/javascripts/application.js").
script(src="./javascripts/sweetalert2.min.js" type="text/javascript").
script(src="./javascripts/application.js?v=1.4" type="text/javascript").