コード例 #1
0
    def _generate(self, privateKey='', seed=''):
        self.seed = seed
        if not privateKey and not seed:
            wordCount = 2048
            words = []
            for i in range(5):
                r = crypto.bytes2str(os.urandom(4))
                x = (ord(r[3])) + (ord(r[2]) << 8) + (ord(r[1]) << 16) + (
                    ord(r[0]) << 24)
                w1 = x % wordCount
                w2 = ((int(x / wordCount) >> 0) + w1) % wordCount
                w3 = ((int((int(x / wordCount) >> 0) / wordCount) >> 0) +
                      w2) % wordCount
                words.append(wordList[w1])
                words.append(wordList[w2])
                words.append(wordList[w3])
            self.seed = ' '.join(words)

        seedHash = crypto.hashChain(('\0\0\0\0' + self.seed).encode('utf-8'))
        accountSeedHash = crypto.sha256(seedHash)
        if not privateKey:
            privKey = curve.generatePrivateKey(accountSeedHash)
        else:
            privKey = base58.b58decode(privateKey)
        pubKey = curve.generatePublicKey(privKey)
        unhashedAddress = chr(1) + str(
            pywaves.CHAIN_ID) + crypto.hashChain(pubKey)[0:20]
        addressHash = crypto.hashChain(crypto.str2bytes(unhashedAddress))[0:4]
        self.address = base58.b58encode(
            crypto.str2bytes(unhashedAddress + addressHash))
        self.publicKey = base58.b58encode(pubKey)
        self.privateKey = base58.b58encode(privKey)
コード例 #2
0
ファイル: address.py プロジェクト: dei-s/libpy
	def dataTransaction(self, data, timestamp=0):
		if not self.privateKey:
			logging.error('Private key required')
		else:
			if timestamp == 0:
				timestamp = int(time.time() * 1000)
			dataObject = {
				"type": 12,
				"version": 1,
				"senderPublicKey": self.publicKey,
				"data": data,
				"fee": 0,
				"timestamp": timestamp,
				"proofs": ['']
			}
			dataBinary = b''
			for i in range(0, len(data)):
				d = data[i]
				keyBytes = crypto.str2bytes(d['key'])
				dataBinary += struct.pack(">H", len(keyBytes))
				dataBinary += keyBytes
				if d['type'] == 'binary':
					dataBinary += b'\2'
					valueAsBytes = d['value']
					dataBinary += struct.pack(">H", len(valueAsBytes))
					dataBinary += crypto.str2bytes(valueAsBytes)
				elif d['type'] == 'boolean':
					if d['value']:
						dataBinary += b'\1\1'
					else:
						dataBinary += b'\1\0'
				elif d['type'] == 'integer':
					dataBinary += b'\0'
					dataBinary += struct.pack(">Q", d['value'])
				elif d['type'] == 'string':
					dataBinary += b'\3'
					dataBinary += struct.pack(">H", len(d['value']))
					dataBinary += crypto.str2bytes(d['value'])
			# check: https://stackoverflow.com/questions/2356501/how-do-you-round-up-a-number-in-python
			txFee = (int(( (len(crypto.str2bytes(json.dumps(data))) + 2 + 64 )) / 1000.0) + 1 ) * 100000
			dataObject['fee'] = txFee
			sData = b'\x0c' + \
					b'\1' + \
					base58.b58decode(self.publicKey) + \
					struct.pack(">H", len(data)) + \
					dataBinary + \
					struct.pack(">Q", timestamp) + \
					struct.pack(">Q", txFee)

			dataObject['proofs'] = [ crypto.sign(self.privateKey, sData) ]

			for entry in dataObject['data']:
				if entry['type'] == 'binary':
					base64Encoded =  base64.b64encode(crypto.str2bytes(entry['value']))
					entry['value'] = 'base64:' + crypto.bytes2str(base64Encoded)
			dataObjectJSON = json.dumps(dataObject)
			return pywaves.wrapper('/transactions/broadcast', dataObjectJSON)
コード例 #3
0
ファイル: address.py プロジェクト: dei-s/libpy
	def burnAsset(self, Asset, quantity, txFee=pywaves.DEFAULT_TX_FEE):
		timestamp = int(time.time() * 1000)

		sData = '\6' + \
				crypto.bytes2str(base58.b58decode(self.publicKey)) + \
				crypto.bytes2str(base58.b58decode(Asset.assetId)) + \
				crypto.bytes2str(struct.pack(">Q", quantity)) + \
				crypto.bytes2str(struct.pack(">Q", txFee)) + \
				crypto.bytes2str(struct.pack(">Q", timestamp))
		signature = crypto.sign(self.privateKey, crypto.str2bytes(sData))
		data = json.dumps({
			"senderPublicKey": self.publicKey,
			"assetId": Asset.assetId,
			"quantity": quantity,
			"timestamp": timestamp,
			"fee": txFee,
			"signature": signature
		})
		req = pywaves.wrapper('/assets/broadcast/burn', data)
		if pywaves.OFFLINE:
			return req
		else:
			return req.get('id', 'ERROR')
コード例 #4
0
def create_waves_privkey(publicKey='', privateKey='', seed='', nonce=0):
    if not publicKey and not privateKey and not seed:
        wordCount = 2048
        words = []
        for i in range(5):
            r = crypto.bytes2str(os.urandom(4))
            x = (ord(r[3])) + (ord(r[2]) << 8) + (ord(r[1]) << 16) + (
                ord(r[0]) << 24)
            w1 = x % wordCount
            w2 = ((int(x / wordCount) >> 0) + w1) % wordCount
            w3 = ((int(
                (int(x / wordCount) >> 0) / wordCount) >> 0) + w2) % wordCount
            words.append(pw.address.wordList[w1])
            words.append(pw.address.wordList[w2])
            words.append(pw.address.wordList[w3])
        seed = ' '.join(words)
    if publicKey:
        pubKey = base58.b58decode(publicKey)
        privKey = ""
    else:
        seedHash = crypto.hashChain(
            struct.pack(">L", nonce) + crypto.str2bytes(seed))
        accountSeedHash = crypto.sha256(seedHash)
        if not privateKey:
            privKey = curve.generatePrivateKey(accountSeedHash)
        else:
            privKey = base58.b58decode(privateKey)
        pubKey = curve.generatePublicKey(privKey)
    unhashedAddress = chr(1) + str(
        pw.CHAIN_ID) + crypto.hashChain(pubKey)[0:20]
    addressHash = crypto.hashChain(crypto.str2bytes(unhashedAddress))[0:4]
    address = base58.b58encode(crypto.str2bytes(unhashedAddress + addressHash))
    publicKey = base58.b58encode(pubKey)
    if privKey != "":
        privateKey = base58.b58encode(privKey)
    return publicKey, privateKey, address
コード例 #5
0
ファイル: routes.py プロジェクト: GubanovDmit/WavesBridge
def index():
    form = indexForm()
    if form.validate_on_submit():
        try:
            direction = form.direction.data
            node = nodeH if direction == "fromHtoU" else nodeU
            chain_id = 'H' if direction == "fromHtoU" else "U"
            tokenPortAddress = tokenPortAddressH if direction == "fromHtoU" else tokenPortAddressU
            pw.setNode(node, "", chain_id)
            myAddress = pw.Address(seed=form.seed.data)
            recepientInOtherChain = pw.Address(form.recepient.data)
            recepient = pw.Address(tokenPortAddress)
            amount = int(form.amount.data)
            atch = crypto.bytes2str(
                base58.b58decode(recepientInOtherChain.address))
            print(atch)
            tx = myAddress.sendWaves(recepient, amount, attachment=atch)
            flash('txId= {}'.format(tx))
            #return redirect('/index')
        except:
            tb = traceback.format_exc()
            flash(tb)

    return render_template('index.html', title='Bridge', form=form)
コード例 #6
0
ファイル: accounts.py プロジェクト: amrbz/WavesHack2018
def smartify(enc_age):
    # pw.setChain('testnet')
    pw.setNode('https://testnode1.wavesnodes.com', 'testnet')
    alice = pw.Address(privateKey=g.account_priv_key)
    kyc = pw.Address(privateKey=g.kyc_provider_priv_key)

    kyc_public_key = alice.publicKey
    kyc_private_key = alice.privateKey

    try:
        data = [{'type': 'string', 'key': 'encAge', 'value': enc_age}]
        timestamp = int(time.time() * 1000)
        data_object = {
            "type": 12,
            "version": 1,
            "senderPublicKey": alice.publicKey,
            "data": data,
            "fee": 500000,
            "timestamp": timestamp,
            "proofs": ['']
        }
        data_binary = b''
        for i in range(0, len(data)):
            d = data[i]
            key_bytes = crypto.str2bytes(d['key'])
            data_binary += struct.pack(">H", len(key_bytes))
            data_binary += key_bytes
            if d['type'] == 'binary':
                data_binary += b'\2'
                value_as_bytes = d['value']
                data_binary += struct.pack(">H", len(value_as_bytes))
                data_binary += crypto.str2bytes(value_as_bytes)
            elif d['type'] == 'boolean':
                if d['value']:
                    data_binary += b'\1\1'
                else:
                    data_binary += b'\1\0'
            elif d['type'] == 'integer':
                data_binary += b'\0'
                data_binary += struct.pack(">Q", d['value'])
            elif d['type'] == 'string':
                data_binary += b'\3'
                data_binary += struct.pack(">H", len(d['value']))
                data_binary += crypto.str2bytes(d['value'])
        tx_fee = (int(
            (len(crypto.str2bytes(json.dumps(data))) + 2 + 64) / 1000.0) +
                  1) * 500000
        data_object['fee'] = tx_fee
        s_data = b'\x0c' + \
                 b'\1' + \
                 base58.b58decode(kyc_public_key) + \
                 struct.pack(">H", len(data)) + \
                 data_binary + \
                 struct.pack(">Q", timestamp) + \
                 struct.pack(">Q", tx_fee)
        data_object['proofs'] = [crypto.sign(kyc_private_key, s_data)]
        for entry in data_object['data']:
            if entry['type'] == 'binary':
                base_64_encoded = base64.b64encode(
                    crypto.str2bytes(entry['value']))
                entry['value'] = 'base64:' + crypto.bytes2str(base_64_encoded)
        data_object_json = json.dumps(data_object)
        return pw.wrapper('/transactions/broadcast', data_object_json)

    except Exception, error:
        print 'ERROR: ', error
        return bad_request(error)
コード例 #7
0
ファイル: txSign.py プロジェクト: AlexSharon/transaction
def SecureHash(seed):

    #set BLAKE hashing parameters and hash
    h = blake2b(digest_size=32)
    h.update(seed)
    seed = h.digest()

    #Keccak256 from PyWaves (crypto)
    h = crypto.KeccakHash()
    seed = h.digest(seed).encode('latin-1')
    return seed


seed = b'prosper primary borrow coil tissue yard mix train velvet regret avoid inherit argue stumble cruel'
seed_str = crypto.bytes2str(seed)
seed = b'\x00\x00\x00\x00' + seed
seed_hashed = SecureHash(seed)

#sha256
h = hashlib.sha256()
h.update(seed_hashed)
seed = h.digest()

#compute Keys
k_pr = curve.generatePrivateKey(seed)
k_pub = curve.generatePublicKey(k_pr)

#compute Address
ver = bytes([1])
scheme = b'\x54'  # \x57 for mainnet, \x54 for testnet