跳至主要内容
本页面使用机器翻译自英语,可能包含错误或不清楚的语言。如需最准确的信息,请参阅英文原文。由于更新频繁,部分内容可能与英文原文有出入。请加入我们在 Crowdin 上的努力,帮助我们改进本页面的翻译。 (Crowdin translation page, Contributing guide)

Address

用于转换公共地址和公共密钥的工具。

从**@kaiachain/ethers-ext软件包中导入getCompressedPublicKey**。

从 "账户 "对象中,您可以使用 "address_from_private_key "获取公共地址,或使用 "compressed_key "获取压缩公共密钥

根据未压缩公钥的 xy 坐标,可以使用 compressed_key_from_xycompressed_key_and_address_from_xy 获取公钥和地址。

address_utils.py

from eth_account import Account
from web3py_ext.klaytn_account.utils import compressed_key_from_xy, address_from_private_key, compressed_key, \
compressed_key_and_address_from_xy
def main():
private_key=Account.from_key("0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8")
print("Public key from private key",address_from_private_key(private_key))
print("Compress key from private key"、compressed_key(private_key))
x = "0xdc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd"
y = "0xaf06ca34ae8714cf3dae06bacdb78c7c2d4054bd38961d40853cd5f15955da79"
print("Compress public key from x、y", compressed_key_from_xy(x, y))
print("Compress public key and address from x,y", compressed_key_and_address_from_xy(x, y))
main()

output

❯ python address_utils.py
Public key from private key 0xa2a8854b1802d8cd5de631e690817c253d6a9153
Compress key from private key 0x03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd
Compress key from x,y 03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd
Compress key and address from x,y ('0x03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd', '0xA2a8854b1802D8Cd5De631E690817c253d6a9153')

让这个页面变得更好