How to use the mnemonic.secretsharing.points_to_secret_int function in mnemonic

To help you get started, we’ve selected a few mnemonic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github trezor / python-mnemonic / mnemonic / shamir.py View on Github external
def combine(self, shares):
        words = set([len(x.split(' ')) for x in shares])
        if len(words) != 1:
            raise Exception('Inconsistent number of words')
        datalen = list(words)[0] * 4 // 3 - 1
        shares = [binascii.hexlify(self.mnemo.to_entropy(x)) for x in shares]
        if sys.version > '3':
            if set([int(chr(x[0]), 16) for x in shares]) != set([len(shares)]):
                raise Exception('Number of shares does not match the threshold')
            points = [(int(chr(x[1]), 16), int(x[2:], 16)) for x in shares]
        else:
            if set([int(x[0], 16) for x in shares]) != set([len(shares)]):
                raise Exception('Number of shares does not match the threshold')
            points = [(int(x[1], 16), int(x[2:], 16)) for x in shares]
        prime = self.primes[datalen]
        r = points_to_secret_int(points, prime)
        r = hex(r)[2:]
        if r.endswith('L'):
            r = r[:-1]
        r = r.zfill(datalen * 2)
        return binascii.unhexlify(r)