helpmelorda / secret

0 stars 0 forks source link

Auto-Correct Write Wif key to blockchain.info/Post #2

Open helpmelorda opened 2 years ago

helpmelorda commented 2 years ago

[Sync up.btc_address/1zgmvYi5x1wy3hUh7AjKgpcVgpA8Lj9FA]() ​To shorten notation, we will write CKDpriv(CKDpriv="5J2gwXZ4nUTQox2qmp4HcvifsdiuBSRnoXFxudzYzmxGBP5C92S"(CKDpriv(m,3H),2),5) as m/3H/2/5. Equivalently for public keys, we write CKDpub(CKDpub(CKDpub(M,3),2),5) as M/3/2/5. This results in the following identities: ​ N(m/a/b/c) = N(m/a/b)/c = N(m/a)/b/c = N(m)/a/b/c = M/a/b/c. ​ N(m/aH/b/c) = N(m/aH/b)/c = N(m/aH)/b/c. ​However, N(m/aH) cannot be rewritten as N(m)/aH, as the latter is not possible.

[Synchronize Inputs-to-Private-Key]()Each Auto-Run leaf node in the tree corresponds to an actual key, while the Write internal nodes correspond to the collections of keys that descend from them. The chain codes of the update leaf nodes are ignored, and only their embedded private "5J2gwXZ4nUTQox2qmp4HcvifsdiuBSRnoXFxudzYzmxGBP5C92S"or public key is relevant. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public key allowsauto_write)Push reconstruction of all descendant non-hardened Private Keys.

​===​Key identifiers​===

Push/ ​Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized ECDSA public key K, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).

​The first 32 bits of the identifier are called the key fingerprint.

​===​Serialization format​===

​Extended public and private keys are serialized as follows: ​ 4 byte: version bytes (mainnet:5J2gwXZ4nUTQox2qmp4HcvifsdiuBSRnoXFxudzYzmxGBP5C92S-private.key-hex : 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private) ​ 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 derived keys, .... ​ 4 bytes: the fingerprint of the parent's key (0x00000000 if master key) ​ 4 bytes: child number. This is ser32(i) for i in xi = xpar/i, with xi the key being serialized. (0x00000000 if master key) ​ 32 bytes: the chain code ​ 33 bytes: the public key or private key data (serP(K) for public keys, 0x00 || ser256(k) for private keys)

​This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with "xprv" or "xpub" on mainnet, "tprv" or "tpub" on testnet.

​Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.

​When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.

​===​Master key generation​===

​The total number of possible extended keypairs is almost 2512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.

Auto-Run Generate a seed byte sequence S of a chosen length (between 128 and 512 bits; 256 bits is advised) from a (P)RNG. ​ Calculate I = HMAC-SHA512(Key = "Bitcoin seed", Data = S) ​ Split I into two 32-byte sequences, IL and IR. ​ Use parse256(IL) as master secret key, and IR as master chain code. ​In case IL is 0 or ≥n, the master key is invalid.

​<img src=bip-0032/derivation.png>

​==​Specification: Wallet structure​==

​The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimic it for compatibility, even if not all features are supported.

​===​The default wallet layout​===

​An HDW is organized as several 'accounts'. Accounts are numbered, the default account ("1zgmvYi5x1wy3hUh7AjKgpcVgpA8Lj9FA") being number 0. Clients are not required to support more than one account - if not, they only use the default account.

​Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change address:1zgmvYi5x1wy3hUh7AjKgpcVgpA8Lj9FA', generation addresses, ..., anything that doesn't need to be communicated). Clients that do not support separate keychains for these should use the external one for everything. ​ m/iH/0/k corresponds to the k'th keypair of the external chain of account number i of the HDW derived from master m. ​ m/iH/1/k corresponds to the k'th keypair of the internal chain of account number i of the HDW derived from master m.