本文整理汇总了Python中ecdsa.VerifyingKey.from_public_point方法的典型用法代码示例。如果您正苦于以下问题:Python VerifyingKey.from_public_point方法的具体用法?Python VerifyingKey.from_public_point怎么用?Python VerifyingKey.from_public_point使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ecdsa.VerifyingKey
的用法示例。
在下文中一共展示了VerifyingKey.from_public_point方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_material
# 需要导入模块: from ecdsa import VerifyingKey [as 别名]
# 或者: from ecdsa.VerifyingKey import from_public_point [as 别名]
def create_material(self, bits, d=None, x=None, y=None):
curve = self.curve_for_bits(bits)
if d:
return SigningKey.from_secret_exponent(d, curve)
if x and y:
point = ec.Point(curve.curve, x, y, curve.order)
return VerifyingKey.from_public_point(point, curve)
示例2: from_point
# 需要导入模块: from ecdsa import VerifyingKey [as 别名]
# 或者: from ecdsa.VerifyingKey import from_public_point [as 别名]
def from_point(cls, point, network=BitcoinMainNet, **kwargs):
"""Create a PublicKey from a point on the SECP256k1 curve.
:param point: A point on the SECP256k1 curve.
:type point: SECP256k1.point
"""
verifying_key = VerifyingKey.from_public_point(point, curve=SECP256k1)
return cls.from_verifying_key(verifying_key, network=network, **kwargs)
示例3: from_sec
# 需要导入模块: from ecdsa import VerifyingKey [as 别名]
# 或者: from ecdsa.VerifyingKey import from_public_point [as 别名]
def from_sec(string, curve=curves.SECP256k1, hashfunc=sha1, validate_point=True):
"""Convert a public key in SEC binary format to a verifying key."""
# based on code from https://github.com/richardkiss/pycoin
if string.startswith(b("\x04")):
# uncompressed
return VerifyingKey.from_string(string[1:], curve, hashfunc, validate_point)
elif string.startswith(b("\x02")) or string.startswith(b("\x03")):
# compressed
is_even = string.startswith(b("\x02"))
x = string_to_number(string[1:])
order = curve.order
p = curve.curve.p()
alpha = (pow(x, 3, p) + (curve.curve.a() * x) + curve.curve.b()) % p
beta = square_root_mod_prime(alpha, p)
if is_even == bool(beta & 1):
y = p - beta
else:
y = beta
if validate_point:
assert ecdsa.point_is_valid(curve.generator, x, y)
point = ellipticcurve.Point(curve.curve, x, y, order)
return VerifyingKey.from_public_point(point, curve, hashfunc)
示例4: get_ecdsa_verifying_key
# 需要导入模块: from ecdsa import VerifyingKey [as 别名]
# 或者: from ecdsa.VerifyingKey import from_public_point [as 别名]
def get_ecdsa_verifying_key(pub):
#some shenanigans required to validate a transaction sig; see
#python.ecdsa PR #54. This will be a lot simpler when that's merged.
#https://github.com/warner/python-ecdsa/pull/54/files
if not pub[0] in ["\x02", "\x03"]:
log.debug("Invalid pubkey")
return None
is_even = pub.startswith('\x02')
x = string_to_number(pub[1:])
order = SECP256k1.order
p = SECP256k1.curve.p()
alpha = (pow(x, 3, p) + (SECP256k1.curve.a() * x) + SECP256k1.curve.b()) % p
beta = square_root_mod_prime(alpha, p)
if is_even == bool(beta & 1):
y = p - beta
else:
y = beta
if not point_is_valid(SECP256k1.generator, x, y):
return None
point = Point(SECP256k1.curve, x, y, order)
return VerifyingKey.from_public_point(point, SECP256k1,
hashfunc=hashlib.sha256)
示例5: from_pair
# 需要导入模块: from ecdsa import VerifyingKey [as 别名]
# 或者: from ecdsa.VerifyingKey import from_public_point [as 别名]
def from_pair(cls, pair):
x, y = pair
point = Point(curve=SECP256k1.curve, x=x, y=y, order=SECP256k1.order)
key = VerifyingKey.from_public_point(point, curve=SECP256k1)
return cls(key)