class FlaskStarter():
    def __init__(self):
        self.app = Flask(__name__)
        self.cryptor = NooCrypto()

        @self.app.route('/start/generatePair', methods=['GET','POST'])
        def generatePair():
            if not request:
                abort(400)

            self.cryptor.generateKeys()

            return json.dumps({"PRIVATE": self.cryptor.getPrivateKey(), "PUBLIC": self.cryptor.getPublicKey()}, separators=(',', ':'))

        @self.app.route('/start/setPrivate', methods=['GET','POST'])
        def setPrivate():
            if not request:
                abort(400)

            private = request.args.get('private')
            password = request.args.get('password')

            crf = cryptoFernet(password)
            token = crf.crypt(private)
            pFile = open("PRIVATE", "w")
            pFile.write(token.decode())

            return json.dumps({"PRIVATE": self.cryptor.getPrivateKey(), "PUBLIC": self.cryptor.getPublicKey()}, separators=(',', ':'))

    def run(self):
        self.app.run(host='0.0.0.0', port=8080)
    def createPrecommitBlock(cryptor:NooCrypto, ver:str, transactions:set, bheight):
        jtransactions = []
        for tran in transactions:
            jtransactions.append(json.loads(tran))

        block = json.dumps({'TT': 'BL', 'SENDER': cryptor.getPublicKey(), 'VERSION': ver, 'TCOUNT': len(jtransactions), "BHEIGHT": bheight, 'TRANSACTIONS':jtransactions}, separators=(',', ':'))
        sign = cryptor.signMessage(block)
        jblock = json.loads(block)
        jblock.update({'SIGNATURE':sign})

        return json.dumps(jblock, separators=(',', ':'))
 def createPurifierBlock(cryptor:NooCrypto, addressList:list, keyList:list, bheight:int):
     temp = json.dumps({'TT': 'PURIFIER', 'SENDER': cryptor.getPublicKey(), 'CLEAN_LIST': addressList, 'CLEAN_KEY_LIST': keyList, "BHEIGHT": bheight}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
 def giveAllSizeBlock(cryptor:NooCrypto, NBH:int):
     temp = json.dumps({'TT': 'ASB', 'SENDER': cryptor.getPublicKey(), "NBH": NBH}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
 def chooserTransaction(cryptor:NooCrypto, blockchain_height): # Транзакция выбора ноды для работы
     temp = json.dumps({'TT': 'CT', 'SENDER': cryptor.getPublicKey(), "NBH": blockchain_height, "TST": str(int(time.time()))}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
 def createSignaturePrecommitedBlock(cryptor:NooCrypto, pblock:str, hash:str):
     temp = json.dumps({'TT': 'SG', 'SENDER': cryptor.getPublicKey(), 'HASH': hash,'SIGNPB': cryptor.signMessage(pblock)}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
 def createCommitBlockForResendHash(cryptor:NooCrypto, block:str, bheight:int):
     block = json.dumps({'TT': 'CBRH', 'SENDER': cryptor.getPublicKey(), "HASH":NooTree.hash(block), "STEM_SIGNATURE": cryptor.signMessage(block), "BHEIGHT": bheight}, separators=(',', ':'))
     sign = cryptor.signMessage(block)
     jblock = json.loads(block)
     jblock.update({'SIGNATURE':sign})
     return json.dumps(jblock, separators=(',', ':'))
 def createCommitBlockForResend(cryptor:NooCrypto, block:str):
     block = json.dumps({'TT': 'CBR', 'SENDER': cryptor.getPublicKey(), "BLOCK" :json.loads(block)}, separators=(',', ':'))
     sign = cryptor.signMessage(block)
     jblock = json.loads(block)
     jblock.update({'SIGNATURE':sign})
     return json.dumps(jblock, separators=(',', ':'))
 def benchmarkTesting(cryptor:NooCrypto, uuid:str):
     temp = json.dumps({'TT': 'BT', 'SENDER': cryptor.getPublicKey(), 'START': uuid}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
 def applicantTransacton(cryptor:NooCrypto, ip:str): # Транзакция заявка на участие в следующем туре валидации
     temp = json.dumps({'TT': 'AT', 'SENDER': cryptor.getPublicKey(), 'IPADR': ip, "TST": str(int(time.time()))}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
 def standartTransacton(cryptor:NooCrypto, reciever:str, token_count:int, token_type:str): # Стандартная транзакция перевода средств
     temp = json.dumps({'TT': 'ST', 'SENDER': cryptor.getPublicKey(), 'RECEIVER': reciever, 'TTOKEN':token_type, 'CTOKEN': str(token_count), "TST": str(int(time.time()))}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
 def universalPacket(cryptor:NooCrypto, type:str, value):
     temp = json.dumps({'TT': type, 'DATA': value, 'SENDER': cryptor.getPublicKey()}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
 def badAnswer(cryptor:NooCrypto):
     temp = json.dumps({'TT': 'BAN', 'SENDER': cryptor.getPublicKey()}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
 def myBenchmarkResult(cryptor:NooCrypto, result:str, start:str):
     temp = json.dumps({'TT': 'MBR', 'SENDER': cryptor.getPublicKey(), 'RESULT': result, 'START': start}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
 def createCommitBlock(cryptor:NooCrypto, preCommitedBlock:str, signs:list):
     block = json.dumps({'TT': 'CB', 'SENDER': cryptor.getPublicKey(), "BLOCK" :json.loads(preCommitedBlock), "SIGNATURES":signs}, separators=(',', ':'))
     sign = cryptor.signMessage(block)
     jblock = json.loads(block)
     jblock.update({'SIGNATURE':sign})
     return json.dumps(jblock, separators=(',', ':'))
Beispiel #16
0
class FlaskStarter():
    def __init__(self):
        self.app = Flask(__name__)
        self.cryptor = NooCrypto()

        @self.app.route('/img/<path:path>')
        def send_img(path):
            return send_from_directory('static/img', path)

        @self.app.route('/js/<path:path>')
        def send_js(path):
            return send_from_directory('static/js', path)

        @self.app.route('/css/<path:path>')
        def send_css(path):
            return send_from_directory('static/css', path)

        @self.app.route('/static/<path:path>')
        def send_html(path):
            return send_from_directory('static', path)

        @self.app.route('/start/generatePair', methods=['GET', 'POST'])
        def generatePair():
            if not request:
                abort(400)

            self.cryptor.generateKeys()

            return json.dumps(
                {
                    "PRIVATE": self.cryptor.getPrivateKey(),
                    "PUBLIC": self.cryptor.getPublicKey()
                },
                separators=(',', ':'))

        @self.app.route('/start/setPrivate', methods=['GET', 'POST'])
        def setPrivate():
            if not request:
                abort(400)

            private = request.args.get('private')
            password = request.args.get('password')

            crf = cryptoFernet(password)
            token = crf.crypt(private)
            pFile = open("PRIVATE", "w")
            pFile.write(token.decode())

            return json.dumps({}, separators=(',', ':'))

        @self.app.route('/start/startSlave', methods=['GET', 'POST'])
        def startSlave():
            if not request:
                abort(400)

            password = request.args.get('password')
            os.system("slaveNode.py " + password)
            os.system("<%START BINARY COMMAND%>")

            print("RETURN!")

            return json.dumps({"START": "OK"}, separators=(',', ':'))

        @self.app.route('/start/getPrivateStatus', methods=['GET', 'POST'])
        def getPrivateStatus():
            if not request:
                abort(400)

            if os.path.exists("PRIVATE"):
                return json.dumps({"PRIVATE": True}, separators=(',', ':'))
            else:
                return json.dumps({"PRIVATE": False}, separators=(',', ':'))

    def run(self):
        self.app.run(host='0.0.0.0', port=8080)
 def createСomplaint(cryptor:NooCrypto, evidence_block:str, evidence_transaction:str):
     temp = json.dumps({'TT': 'COMPLAINT', 'SENDER': cryptor.getPublicKey(), 'EVIDENCE_BLOCK': evidence_block, 'EVIDENCE_TRANSACTION': evidence_transaction}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))