示例#1
0
    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])
示例#3
0
    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
示例#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
示例#5
0
	def serialize_int64(self, value):
		return utils.int_to_bytes(value, size=8)
示例#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
示例#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)