Socket
Socket
Sign inDemoInstall

github.com/decred/dcrd/hdkeychain/v3

Package Overview
Dependencies
15
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/decred/dcrd/hdkeychain/v3

Package hdkeychain provides an API for Decred hierarchical deterministic extended keys (based on BIP0032). The ability to implement hierarchical deterministic wallets depends on the ability to create and derive hierarchical deterministic extended keys. At a high level, this package provides support for those hierarchical deterministic extended keys by providing an ExtendedKey type and supporting functions. Each extended key can either be a private or public extended key which itself is capable of deriving a child extended key. Whether an extended key is a private or public extended key can be determined with the IsPrivate function. In order to create and sign transactions, or provide others with addresses to send funds to, the underlying key and address material must be accessible. This package provides the SerializedPubKey and SerializedPrivKey functions for this purpose. The caller may then create the desired address types. As previously mentioned, the extended keys are hierarchical meaning they are used to form a tree. The root of that tree is called the master node and this package provides the NewMaster function to create it from a cryptographically random seed. The GenerateSeed function is provided as a convenient way to create a random seed for use with the NewMaster function. Once you have created a tree root (or have deserialized an extended key as discussed later), the child extended keys can be derived by using either the Child or ChildBIP32Std function. The difference is described in the following section. These functions support deriving both normal (non-hardened) and hardened child extended keys. In order to derive a hardened extended key, use the HardenedKeyStart constant + the hardened key number as the index to the Child function. This provides the ability to cascade the keys into a tree and hence generate the hierarchical deterministic key chains. The Child function derives extended keys with a modified scheme based on BIP0032, whereas ChildBIP32Std produces keys that strictly conform to the standard. Specifically, the Decred variation strips leading zeros of a private key, causing subsequent child keys to differ from the keys expected by standard BIP0032. The ChildBIP32Std method retains leading zeros, ensuring the child keys expected by BIP0032 are derived. The Child function must be used for Decred wallet key derivation for legacy reasons. A private extended key can be used to derive both hardened and non-hardened (normal) child private and public extended keys. A public extended key can only be used to derive non-hardened child public extended keys. As enumerated in BIP0032 "knowledge of the extended public key plus any non-hardened private key descending from it is equivalent to knowing the extended private key (and thus every private and public key descending from it). This means that extended public keys must be treated more carefully than regular public keys. It is also the reason for the existence of hardened keys, and why they are used for the account level in the tree. This way, a leak of an account-specific (or below) private key never risks compromising the master or other accounts." A private extended key can be converted to a new instance of the corresponding public extended key with the Neuter function. The original extended key is not modified. A public extended key is still capable of deriving non-hardened child public extended keys. Extended keys are serialized and deserialized with the String and NewKeyFromString functions. The serialized key is a Base58-encoded string which looks like the following: Extended keys are much like normal Decred addresses in that they have version bytes which tie them to a specific network. The network that an extended key is associated with is specified when creating and decoding the key. In the case of decoding, an error will be returned if a given encoded extended key is not for the specified network. This example demonstrates the audits use case in BIP0032. This example demonstrates the default hierarchical deterministic wallet layout as described in BIP0032. This example demonstrates how to generate a cryptographically random seed then use it to create a new master node (extended key).


Version published

Readme

Source

hdkeychain

Build Status ISC License Doc

Package hdkeychain provides an API for Decred hierarchical deterministic extended keys (based on BIP0032).

A comprehensive suite of tests is provided to ensure proper functionality.

Feature Overview

  • Full BIP0032 implementation
  • Single type for private and public extended keys
  • Convenient cryptographically secure seed generation
  • Simple creation of master nodes
  • Support for multi-layer derivation
  • Easy serialization and deserialization for both private and public extended keys
  • Support for custom networks by accepting a network parameters interface
  • Allows obtaining the underlying serialized secp256k1 pubkeys and privkeys directly so they can either be used directly or optionally converted to the secp256k1 types which provide powerful tools for working with them to do things like sign transactions and generate payment scripts
  • Uses the highly-optimized secp256k1 package
  • Code examples including:
    • Generating a cryptographically secure random seed and deriving a master node from it
    • Default HD wallet layout as described by BIP0032
    • Audits use case as described by BIP0032
  • Comprehensive test coverage including the BIP0032 test vectors
  • Benchmarks

BIP0032 Conformity

Two different child key derivation functions are provided: the Child function derives extended keys using a modified scheme based on BIP0032, whereas ChildBIP32Std produces keys that strictly conform to the standard. The Child function should be used for Decred wallet key derivation for legacy reasons.

Installation and Updating

This package is part of the github.com/decred/dcrd/hdkeychain/v3 module. Use the standard go tooling for working with modules to incorporate it.

Examples

License

Package hdkeychain is licensed under the copyfree ISC License.

FAQs

Last updated on 08 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc