def getRawTx(self) -> bytes:
        rawTx = b""
        for inp in self.inputs:
            rawTx += inp.prevTxHash
            rawTx += int_to_bytes(inp.outputIndex)
            rawTx += inp.signature

        for op in self.outputs:
            rawTx += decimal_to_bytes(op.value)
            rawTx += int_to_bytes(op.address.e)
            rawTx += int_to_bytes(op.address.n)

        return rawTx
def choose_fragments(seq_num, seq_len, checksum):
    # The first `seq_len` parts are the "pure" fragments, not mixed with any
    # others. This means that if you only generate the first `seq_len` parts,
    # then you have all the parts you need to decode the message.
    if seq_num <= seq_len:
        return set([seq_num - 1])
    else:
        seed = int_to_bytes(seq_num) + int_to_bytes(checksum)
        rng = Xoshiro256.from_bytes(seed)
        degree = choose_degree(seq_len, rng)
        indexes = []

        for i in range(seq_len):
            indexes.append(i)
        shuffled_indexes = shuffled(indexes, rng)
        return set(shuffled_indexes[0:degree])
    def getRawDataToSign(self, index: int) -> bytes:
        # produces data repr for  ith=index input and all outputs
        sigData = b""
        if index > len(self._inputs):
            return sigData

        inp = self.inputs[index]
        sigData += inp.prevTxHash
        sigData += int_to_bytes(inp.outputIndex)

        for op in self.outputs:
            sigData += decimal_to_bytes(op.value)
            # using pycryptodome lib
            # e: RSA public exponent
            sigData += int_to_bytes(op.address.e)
            # n: RSA modulus
            sigData += int_to_bytes(op.address.n)

        return sigData
Beispiel #4
0
def decode(v):

	#	count number of leading zeroes
	z = 0
	while v[z] == __b58chars[0]:
		z += 1

	long_value = 0
	for c in v:
		long_value *= __b58base
		long_value += __b58inv[c]

	result = utils.int_to_bytes(long_value)
	result = z * '\0' + result
	return result
Beispiel #5
0
	def serialize_int64(self, value):
		return utils.int_to_bytes(value, size=8)
Beispiel #6
0
	def decode(self, v):
		v = xlate(v, self.inv)
		p = zero_padding(v)
		t = utils.bytes_to_int(v, BASE)
		v = utils.int_to_bytes(t)
		return p + v
Beispiel #7
0
	def encode(self, v):
		p = zero_padding(v)
		t = utils.bytes_to_int(v)
		v = utils.int_to_bytes(t, BASE)
		return xlate(p + v, self.fwd)