bip32.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:electrumx 作者: kyuupichan 项目源码 文件源码
def _verifying_key_from_pubkey(cls, pubkey):
        '''Converts a 33-byte compressed pubkey into an ecdsa.VerifyingKey
        object'''
        if not isinstance(pubkey, (bytes, bytearray)):
            raise TypeError('pubkey must be raw bytes')
        if len(pubkey) != 33:
            raise ValueError('pubkey must be 33 bytes')
        if pubkey[0] not in (2, 3):
            raise ValueError('invalid pubkey prefix byte')
        curve = cls.CURVE.curve

        is_odd = pubkey[0] == 3
        x = bytes_to_int(pubkey[1:])

        # p is the finite field order
        a, b, p = curve.a(), curve.b(), curve.p()
        y2 = pow(x, 3, p) + b
        assert a == 0  # Otherwise y2 += a * pow(x, 2, p)
        y = NT.square_root_mod_prime(y2 % p, p)
        if bool(y & 1) != is_odd:
            y = p - y
        point = EC.Point(curve, x, y)

        return ecdsa.VerifyingKey.from_public_point(point, curve=cls.CURVE)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号