Beispiel #1
0
 def generate_master(cls, seed=None, testnet=False, num_random_bytes=32):
     if seed is None:
         seed = os.urandom(num_random_bytes)
     I = hmac_sha512('Bitcoin seed', seed).digest()
     IL = I[:32]
     IR = I[32:]
     ki = decode_bigint(IL)
     return HDPrivKey(ki, IR, testnet=testnet)
Beispiel #2
0
 def generate_master(cls, seed=None, testnet=False, num_random_bytes=32):
     if seed is None:
         seed = os.urandom(num_random_bytes)
     I = hmac_sha512('Bitcoin seed', seed).digest()
     IL = I[:32]
     IR = I[32:]
     ki = decode_bigint(IL)
     return HDPrivKey(ki, IR, testnet=testnet)
Beispiel #3
0
 def derive_child(self, i):
     high_bit = i & PUBLIC_DERIVATION_BIT
     if high_bit:
         I = hmac_sha512(self.chain_code, '\x00' + encode_bigint(self.key) + struct.pack('>L', i)).digest()
     else:
         I = hmac_sha512(self.chain_code, encode_pub_compressed(priv_to_pub(self.key)) + struct.pack('>L', i)).digest()
     IL = decode_bigint(I[:32])
     if IL >= secp256k1.order:
         raise Error('invalid key')
     IR = I[32:]
     ki = (IL + self.key) % secp256k1.order
     if ki == 0:
         raise Error('invalid key')
     ci = IR
     return HDPrivKey(ki, ci, self.depth + 1, i, self.fingerprint(), self.V_T[self.version])
Beispiel #4
0
    def derive_child(self, i):
        if i & PUBLIC_DERIVATION_BIT:
            raise Error('Invalid i (%r)' % (i,))
        else:
            I = hmac_sha512(self.chain_code, encode_pub_compressed(self.key) + struct.pack('>L', i)).digest()
        IL = decode_bigint(I[:32])
        if IL >= secp256k1.order:
            raise Error('invalid key')
        IR = I[32:]

        Ki = IL * secp256k1.generator + self.key
        #if Ki == INFINITY:
        #    raise Error('invalid key')
        ci = IR
        return HDPubKey(Ki, ci, self.depth + 1, i, self.fingerprint(), self.V_T[self.version])
Beispiel #5
0
    def derive_child(self, i):
        if i & PUBLIC_DERIVATION_BIT:
            raise Error('Invalid i (%r)' % (i, ))
        else:
            I = hmac_sha512(
                self.chain_code,
                encode_pub_compressed(self.key) +
                struct.pack('>L', i)).digest()
        IL = decode_bigint(I[:32])
        if IL >= secp256k1.order:
            raise Error('invalid key')
        IR = I[32:]

        Ki = IL * secp256k1.generator + self.key
        #if Ki == INFINITY:
        #    raise Error('invalid key')
        ci = IR
        return HDPubKey(Ki, ci, self.depth + 1, i, self.fingerprint(),
                        self.V_T[self.version])
Beispiel #6
0
 def derive_child(self, i):
     high_bit = i & PUBLIC_DERIVATION_BIT
     if high_bit:
         I = hmac_sha512(
             self.chain_code, '\x00' + encode_bigint(self.key) +
             struct.pack('>L', i)).digest()
     else:
         I = hmac_sha512(
             self.chain_code,
             encode_pub_compressed(priv_to_pub(self.key)) +
             struct.pack('>L', i)).digest()
     IL = decode_bigint(I[:32])
     if IL >= secp256k1.order:
         raise Error('invalid key')
     IR = I[32:]
     ki = (IL + self.key) % secp256k1.order
     if ki == 0:
         raise Error('invalid key')
     ci = IR
     return HDPrivKey(ki, ci, self.depth + 1, i, self.fingerprint(),
                      self.V_T[self.version])
Beispiel #7
0
 def unserialize_key(cls, raw):
     key_type = raw[0]
     if key_type != '\x00':
         raise TypeError('key_type should be \\x00, not %r' % (key_type, ))
     return decode_bigint(raw[1:])
Beispiel #8
0
 def unserialize_key(cls, raw):
     key_type = raw[0]
     if key_type != '\x00':
         raise TypeError('key_type should be \\x00, not %r' % (key_type,))
     return decode_bigint(raw[1:])