mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 11:45:50 +00:00
Key Derivation polish
- Fix address encoding diagram - Add key derivation diagrams - Clean up text for key formatting
This commit is contained in:
@@ -89,11 +89,11 @@ For more information on each of these objects, see the [Ledger Format Reference]
|
||||
|
||||
[[Source]<br>](https://github.com/ripple/rippled/blob/35fa20a110e3d43ffc1e9e664fc9017b6f2747ae/src/ripple/protocol/impl/AccountID.cpp#L109-L140 "Source")
|
||||
|
||||
XRP Ledger addresses are encoded using [base58](https://en.wikipedia.org/wiki/Base58) with the Ripple _dictionary_: `rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz`. Since the XRP Ledger encodes several types of keys with base58, it prefixes the encoded data with a one-byte "type prefix" (also called a "version prefix") to distinguish them. The type prefix causes addresses to usually start with different letters in base58 format.
|
||||
XRP Ledger addresses are encoded using [base58](https://en.wikipedia.org/wiki/Base58) with the _dictionary_ `rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz`. Since the XRP Ledger encodes several types of keys with base58, it prefixes the encoded data with a one-byte "type prefix" (also called a "version prefix") to distinguish them. The type prefix causes addresses to usually start with different letters in base58 format.
|
||||
|
||||
The following diagram shows the relationship between keys and addresses:
|
||||
|
||||

|
||||
[](img/address-encoding.png)
|
||||
|
||||
The formula for calculating an XRP Ledger address from a public key is as follows. For the complete example code, see [`encode_address.js`](https://github.com/ripple/ripple-dev-portal/blob/master/content/_code-samples/address_encoding/encode_address.js). For the process of deriving a public key from a passphrase or seed value, see [Key Derivation](cryptographic-keys.html#key-derivation).
|
||||
|
||||
|
||||
@@ -134,12 +134,12 @@ The key derivation processes described here are implemented in multiple places a
|
||||
### Ed25519 Key Derivation
|
||||
[[Source]](https://github.com/ripple/rippled/blob/fc7ecd672a3b9748bfea52ce65996e324553c05f/src/ripple/protocol/impl/SecretKey.cpp#L203 "Source")
|
||||
|
||||
![]
|
||||
|
||||
All 32-byte numbers are valid Ed25519 private keys, so Ed25519 private key derivation is a single step:
|
||||
[](img/key-derivation-ed25519.png)
|
||||
|
||||
1. Calculate the [SHA-512Half][] of the seed value. The result is the 32-byte private key.
|
||||
|
||||
**Tip:** All 32-byte numbers are valid Ed25519 private keys. However, only numbers that are chosen randomly enough are secure enough to be used as private keys.
|
||||
|
||||
2. To calculate an Ed25519 public key, use the standard public key derivation for [Ed25519](https://ed25519.cr.yp.to/software.html) to derive the 32-byte public key.
|
||||
|
||||
**Caution:** As always with cryptographic algorithms, use a standard, well-known, publicly-audited implementation whenever possible. For example, [OpenSSL](https://www.openssl.org/) has implementations of core Ed25519 and secp256k1 functions.
|
||||
@@ -155,6 +155,8 @@ All 32-byte numbers are valid Ed25519 private keys, so Ed25519 private key deriv
|
||||
### secp256k1 Key Derivation
|
||||
[[Source]](https://github.com/ripple/rippled/blob/develop/src/ripple/crypto/impl/GenerateDeterministicKey.cpp "Source")
|
||||
|
||||
[](img/key-derivation-secp256k1.png)
|
||||
|
||||
Key derivation for secp256k1 XRP Ledger account keys involves more steps than Ed25519 key derivation for a couple reasons:
|
||||
|
||||
- Not all 32-byte numbers are valid secp256k1 private keys.
|
||||
@@ -201,9 +203,9 @@ The steps to derive the XRP Ledger's secp256k1 account key pair from a seed valu
|
||||
|
||||
4. Derive the master public key pair by adding the intermediate public key to the root public key. Similarly, derive the private key by adding the intermediate private key to the root private key.
|
||||
|
||||
- An ECDSA private key is just a very large integer chosen at random, so you can calculate the sum of two private keys by summing them modulo the secp256k1 modulus.
|
||||
- An ECDSA private key is just a very large integer, so you can calculate the sum of two private keys by summing them modulo the secp256k1 modulus.
|
||||
|
||||
- An ECDSA public key is a point on the elliptic curve, so you should use a well-established elliptic curve implementation to sum the points.
|
||||
- An ECDSA public key is a point on the elliptic curve, so you should use elliptic curve math to sum the points.
|
||||
|
||||
**Tip:** You don't need any private keys to derive the master public key. You can do so using only the root public key.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user