如何在 Python 中根据给定的签名、ethAddress 和 private_key 计算出 stark key、r 和 s?

问题描述 投票:0回答:0

我尝试了来自 chatgpt 的这些答案:

from web3.auto import w3
from starkware.crypto.signature import pedersen_hash
from starkware.crypto.signature.signature import Signature
from starkware.starkware_utils.signature import get_signing_key, stark_sign

private_key = ''
wallet = ''
signature = ''

hashed_data = pedersen_hash(int(private_key, 16), int(wallet, 16))
signing_key = get_signing_key(int(private_key, 16))
sig = Signature.from_bytes(bytes.fromhex(signature[2:]))
stark_key, r, s = stark_sign(w3, hashed_data, sig, signing_key)

print("starkKey:", stark_key.hex())
print("r:", hex(r))
print("s:", hex(s))

不幸的是,starkware 库不可用

还有这个:

from py_ecc.secp256k1 import secp256k1
from hashlib import sha256

private_key = ''
wallet = ''
signature = ''


sig = bytes.fromhex(signature[2:])
pk = bytes.fromhex(private_key)
pub = secp256k1.privtopub(pk)
msg = f"{wallet.lower()}-starkex"
msg_hash = sha256(msg.encode()).digest()
r, s = secp256k1.raw_sign(msg_hash, pk)
assert secp256k1.raw_verify(msg_hash, sig, pub)
pub_hex = "04" + pub.hex()
stark_pub_key = pedersen_hash(int(pub_hex, 16), int(wallet, 16))
stark_pub_key_hex = hex(stark_pub_key)[2:]
stark_priv_key = pedersen_hash(int(pk.hex(), 16), int(wallet, 16))
stark_priv_key_hex = hex(stark_priv_key)[2:]
stark_sig = stark_sign(sig, pk, msg_hash)
stark_sig_hex = stark_sig.to_hex()

print(f"Stark public key: {stark_pub_key_hex}")
print(f"Stark private key: {stark_priv_key_hex}")
print(f"Stark signature: {stark_sig_hex}")

这些功能未知的地方pedersen_hashstark_sign

有人有什么想法吗?谢谢

key ethereum digital-signature signature
© www.soinside.com 2019 - 2024. All rights reserved.