示例#1
0
    def fromSeed(seed = None):
        if seed is None:
            seed = os.urandom(MIN_SEED_LEN)

        if len(seed) < MIN_SEED_LEN:
            raise ValueError("HDPublicKey seed must be at least 32 bytes long")

        signed64 = hmac.new(HMAC_MAGIC_KEY, seed, hashlib.sha512).digest()

        return HDPublicKey(pubkey = PublicKey.from_bytes(signed64[:32]), chain = signed64[32:])
示例#2
0
    def fromSeed(seed=None):
        if seed is None:
            seed = os.urandom(MIN_SEED_LEN)

        if len(seed) < MIN_SEED_LEN:
            raise ValueError("HDPublicKey seed must be at least 32 bytes long")

        signed64 = hmac.new(HMAC_MAGIC_KEY, seed, hashlib.sha512).digest()

        return HDPublicKey(pubkey=PublicKey.from_bytes(signed64[:32]),
                           chain=signed64[32:])
示例#3
0
    def from_string(b58_str):
        data = utils.encoding.a2b_hashed_base58(b58_str) # TODO checksum?

        chain   = data[HDPublicKey.ChainCodeStart : HDPublicKey.ChainCodeEnd]
        depth   = int_from_bytes(data[HDPublicKey.DepthStart : HDPublicKey.DepthEnd])
        index   = int_from_bytes(data[HDPublicKey.ChildIndexStart : HDPublicKey.ChildIndexEnd])
        parent  = int_from_bytes(data[HDPublicKey.ParentFingerPrintStart : HDPublicKey.ParentFingerPrintEnd])

        # The version field is used to deduce the network:
        version = int_from_bytes(data[HDPublicKey.VersionStart:HDPublicKey.VersionEnd])
        network = Network.get_by_field('hd_public_key', version)
        pubkey  = PublicKey.from_bytes(data[HDPublicKey.PublicKeyStart : HDPublicKey.PublicKeyEnd], network)

        return HDPublicKey(pubkey, chain, depth, index, parent, network)
示例#4
0
    def from_string(b58_str):
        data = utils.encoding.a2b_hashed_base58(b58_str)  # TODO checksum?

        chain = data[HDPublicKey.ChainCodeStart:HDPublicKey.ChainCodeEnd]
        depth = int_from_bytes(
            data[HDPublicKey.DepthStart:HDPublicKey.DepthEnd])
        index = int_from_bytes(
            data[HDPublicKey.ChildIndexStart:HDPublicKey.ChildIndexEnd])
        parent = int_from_bytes(
            data[HDPublicKey.ParentFingerPrintStart:HDPublicKey.
                 ParentFingerPrintEnd])

        # The version field is used to deduce the network:
        version = int_from_bytes(
            data[HDPublicKey.VersionStart:HDPublicKey.VersionEnd])
        network = Network.get_by_field('hd_public_key', version)
        pubkey = PublicKey.from_bytes(
            data[HDPublicKey.PublicKeyStart:HDPublicKey.PublicKeyEnd], network)

        return HDPublicKey(pubkey, chain, depth, index, parent, network)