Là Con Gái Phải Xinh
  • Đăng Nhập
No Result
View All Result
  • Trang chủ
  • Mỹ Phẩm
  • Nước hoa
  • Nước hoa hồng
  • Phụ kiện làm đẹp
Là Con Gái Phải Xinh
No Result
View All Result
Home CRYPTOCURRENCY

Ethereum: How to get the derived public key from xpub?

by Thủy Tiên Anna
11 Tháng Hai, 2025
in CRYPTOCURRENCY
Share on FacebookShare on Twitter

Generating a new derived public key using XPub in Python

As of Ethereum 2.0, the xpub format has been deprecated and replaced by xprv. However, some older contracts still use xpub to store their private keys. In this article, we will show you how to generate a new derived public key (new_pub) from an existing xpub using Python.

What is XPub?

XPub is a standardized format for storing Ethereum private keys in the XRPDB (XRPL) database. While it is no longer widely used, it can still be useful when working with older contracts that require this format.

Deriving a new derived public key from XPub using Python

We will use the cryptography library to perform the derivation. Here is an example code snippet:

from cryptography.hazmat.primitives import serialization

from cryptography.hazmat.backends import default_backend

def derive_new_pub(xpub, new_path):

"""

Derives a new derived public key (new_pub) from an existing xpub.

Arguments:

xpub (str): The xpub private key.

new_path (str): The path to the new derived public key in the XRPDB.

Returns:

bytes: The new derived public key.

"""






Load the existing private key

with open(xpub, "rb") as f_in:

private_key = serialization.load_pem_private_key(

f_in.read(),

password=None,

backend=default_backend()

)


Derive a new derived public key (new_pub)

new_priv = private_key.new_path(new_path)


Save the new private key to disk

with open("new_pub.pvt", "wb") as f_out:

f_out.write(new_priv.public_bytes(

encoding=serialization.Encoding.PEM,

format=serialization.PrivateFormat.PKCS8,

encryption_algorithm=serialization.NoEncryption()

))

return new_priv.public_bytes(

encoding=serialization.Encoding.X962,

format=serialization.PublicFormat.SubjectPublicKeyInfo

)

This function takes two arguments:

  • xpub: The existing xpub private key as a string.
  • new_path: The path to the new derived public key in the XRPDB.

The function loads the existing private key using cryptography and derives a new derived public key (new_pub) by calling private_key.new_path(new_path). Finally, it saves the new private key to disk in PEM format.

Example Use Case

Assuming you have an xpub private key stored in a file called xpub.txt, you can derive a new derived public key using the following code:

new_pub = derive_new_pub("xpub.txt", "new_derived.pub")

This will generate a new derived public key (new_derived.pub) that can be used to sign messages or verify transactions.

Note

While this library provides a simple way to derive a new derived public key, it is essential to ensure that the existing xpub private key is properly formatted and has not been compromised. Always exercise caution when handling sensitive information, especially in production environments.

Thủy Tiên Anna

Thủy Tiên Anna

Liên quan Posts

CRYPTOCURRENCY

The Importance Of Community Engagement In The Success Of Avalanche (AVAX)

4 Tháng Ba, 2025

Strength of Community Involvement: Unlocking the Full Potential of Avalanche (Avax) In The Rapidly Developing World of Cryptocurrencies, A Successful...

CRYPTOCURRENCY

The Impact Of Hyperliquid (HYPE) On Market Dynamics And Trading Strategies

4 Tháng Ba, 2025

The Rise of Hyperliquid (HEPE): Understanding the Impact of Market Dynamics and Trading Strategies We resent there, a new player...

CRYPTOCURRENCY

How Governance Tokens Impact The Value Of Avalanche (AVAX)

4 Tháng Ba, 2025

The Rise of Governance Tokens and their Impact on Avalanche (AVAX) As the world becomes increasingly digital, cryptocurrencies have gained...

CRYPTOCURRENCY

What To Know About Digital Wallets Before You Start Trading

4 Tháng Ba, 2025

negot to Knw to kowal Walletal Walles Bephtal Yu Stating Cryptocurration * The World of Cryptody has Has Exploded in...

CRYPTOCURRENCY

Market Dynamics And Their Influence On Ethereum Classic (ETC)

4 Tháng Ba, 2025

Cryptocurrency Market Dynamics: Understanding Their Impact on Ethereum Classic (ETC) The world of cryptocurrency has been rapidly evolving in recent...

CRYPTOCURRENCY

The Role Of Smart Contracts In Enhancing Security For Stellar (XLM)

4 Tháng Ba, 2025

Here's a topic summary: Smart Contracts and Star (XLM) Smart contracts are self-exhibited contracts with conditions of agreement written directly...

Next Post

Ethereum: How do I pass signers when enabling module for my safe?

NFT, BEP2, Ethereum Classic (ETC)

Generative Models: A Game-Changer for NFT Creators

Trả lời Hủy

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Là Con Gái Phải Xinh

Cùng Con Gái Phải Xinh làm đẹp và chia sẽ phương pháp làm đẹp của riêng mình các chị em nhé!

© 2019 Con Gai Phai Xinh

No Result
View All Result
  • Trang chủ
  • Mỹ Phẩm
  • Nước hoa
  • Nước hoa hồng
  • Phụ kiện làm đẹp

© 2019 Con Gai Phai Xinh

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Go to mobile version