articles

Base58Check encoding - Bitcoin Wiki Bitcoin address base58 encoding

Содержание статьи

This definition comes from the technical glossary.

Definition

The method used in Bitcoin for converting 160-bit hashes into P2PKH and P2SH addresses. Also used in other parts of Bitcoin, such as encoding private keys for backup in WIP format. Not the same as other base58 implementations.

Synonyms

Not To Be Confused With

  • P2PKH address

  • P2SH address

  • IP address

Это интересно:

Bitaddress.org

From Bitcoin Wiki

Conversion from ECDSA public key to Bitcoin Address

This article may be too technical for some users. The more basic article on Bitcoin Addresses may be more appropriate.

A Bitcoin address is a 160-bit hash of the public portion of a public/private ECDSA keypair. Using public-key cryptography, you can "sign" data with your private key and anyone who knows your public key can verify that the signature is valid.

A new keypair is generated for each receiving address (with newer HD wallets, this is done deterministically). The public key and their associated private keys (or the seed needed to generate them) are stored in the wallet data file. This is the only file users should need to backup. A "send" transaction to a specific Bitcoin address requires that the corresponding wallet knows the private key implementing it. This has the implication that if you create an address and receive coins to that address, then restore the wallet from an earlier backup, before the address was generated, then the coins received with that address are lost; this is not an issue for HD wallets where all addresses are generated from a single seed. Addresses are added to an address key pool prior to being used for receiving coins. If you lose your wallet entirely, all of your coins are lost and can never be recovered.

Bitcoin allows you to create as many addresses as you want, and use a new one for every transaction. There is no "master address": the "Your Bitcoin address" area in some wallet UIs has no special importance. It's only there for your convenience, and it should change automatically when used.

Bitcoin addresses contain a built-in check code, so it's generally not possible to send Bitcoins to a mistyped address. However, if the address is well-formed but no one owns it (or the owner lost their wallet.dat), any coins sent to that address will be lost forever.

Hash values and the checksum data are converted to an alpha-numeric representation using a custom scheme: the Base58Check encoding scheme. Under Base58Check, addresses can contain all alphanumeric characters except 0, O, I, and l. Normal addresses currently always start with 1 (addresses from script hashes use 3), though this might change in a future version. Testnet addresses usually start with m or n. Mainline addresses can be 25-34 characters in length, and testnet addresses can be 26-34 characters in length. Most addresses are 33 or 34 characters long.

Collisions (lack thereof)

Since Bitcoin addresses are basically random numbers, it is possible, although extremely unlikely, for two people to independently generate the same address. This is called a collision. If this happens, then both the original owner of the address and the colliding owner could spend money sent to that address. It would not be possible for the colliding person to spend the original owner's entire wallet (or vice versa). If you were to intentionally try to make a collision, it would currently take 2^107 times longer to generate a colliding Bitcoin address than to generate a block. As long as the signing and hashing algorithms remain cryptographically strong, it will likely always be more profitable to collect generations and transaction fees than to try to create collisions, as demonstrated by projects like the Large Bitcoin Collider which attempt to generate address collisions.

It is more likely that the Earth is destroyed in the next 5 seconds, than that a collision occur in the next millenium.

How to create Bitcoin Address

0 - Having a private ECDSA key

 18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725

1 - Take the corresponding public key generated with it (65 bytes, 1 byte 0x04, 32 bytes corresponding to X coordinate, 32 bytes corresponding to Y coordinate)

 0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6

2 - Perform SHA-256 hashing on the public key

 600FFE422B4E00731A59557A5CCA46CC183944191006324A447BDB2D98D4B408

3 - Perform RIPEMD-160 hashing on the result of SHA-256

 010966776006953D5567439E5E39F86A0D273BEE

4 - Add version byte in front of RIPEMD-160 hash (0x00 for Main Network)

 00010966776006953D5567439E5E39F86A0D273BEE

(note that below steps are the Base58Check encoding, which has multiple library options available implementing it)
5 - Perform SHA-256 hash on the extended RIPEMD-160 result

 445C7A8007A93D8733188288BB320A8FE2DEBD2AE1B47F0F50BC10BAE845C094

6 - Perform SHA-256 hash on the result of the previous SHA-256 hash

 D61967F63C7DD183914A4AE452C9F6AD5D462CE3D277798075B107615C1A8A30

7 - Take the first 4 bytes of the second SHA-256 hash. This is the address checksum

 D61967F6

8 - Add the 4 checksum bytes from stage 7 at the end of extended RIPEMD-160 hash from stage 4. This is the 25-byte binary Bitcoin Address.

 00010966776006953D5567439E5E39F86A0D273BEED61967F6

9 - Convert the result from a byte string into a base58 string using Base58Check encoding. This is the most commonly used Bitcoin Address format

 16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM

See Also

фрибиткоин.

Bitcoinaddress validation - Rosetta Code

JavaScript component that's used to generate relevant addresses, wallet import formats, BIP32 encodings, and base 58 check encoding used by various crypto currencies. The difference between this and base58 check encoding is not much other than base 58 check encoding specifies that the version should only have one byte. This means that base 58 check encoding technically would NOT work for BIP 32 addresses, but this module does work with BIP 32 addresses.

Works in Node.js and the browser.

Installation

npm install coinstring --save

Examples

Note: You'd commonly use this package in conjunction with coininfo.

Convert Private Key to Bitcoin Wallet Import Format

var cs = require('coinstring') var privateKeyHex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd"
var privateKeyHexBuf = new Buffer(privateKeyHex, 'hex')
var version = 0x80; //Bitcoin private key console.log(cs.encode(privateKeyHexBuf, version)) // => 5Hx15HFGyep2CfPxsJKe2fXJsCVn5DEiyoeGGF6JZjGbTRnqfiD

Convert hash160 (aka pubKeyHash) to Bitcoin Address

var cs = require('coinstring') var hash160 = "3c176e659bea0f29a3e9bf7880c112b1b31b4dc8" //hash representing uncompressed
var hash160Buf = new Buffer(hash160, 'hex')
var version = 0x00; //Bitcoin public address console.log(cs.encode(hash160Buf, version)); // => 16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS

Convert Private Key to Compressed Bitcoin Wallet Import Format

var cs = require('coinstring') var privateKeyHex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd" //for compressed, append "01"
privateKeyHex += '01' var privateKeyHexBuf = new Buffer(privateKeyHex, 'hex')
var version = 0x80 //Bitcoin private key console.log(cs.encode(privateKeyHexBuf, version))
// => KwomKti1X3tYJUUMb1TGSM2mrZk1wb1aHisUNHCQXTZq5auC2qc3

Convert hash160 (aka pubkeyhash) to Dogecoin Address

var cs = require('coinstring') var hash160 = "3c176e659bea0f29a3e9bf7880c112b1b31b4dc8" //hash representing uncompressed
var hash160Buf = new Buffer(hash160, 'hex')
var version = 0x1E //Dogecoin public address console.log(cs.encode(hash160Buf, version)) // => DAcq9oJpZZAjr56RmF7Y5zmWboZWQ4HAsW

Encode BIP 32 Bitcoin Private Key

Base 58 check encoding cannot typically enocde these since it requires the version to only be one byte. Read more about BIP32 here.

var cs = require('coinstring') var data = "000000000000000000873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d50800e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35" var buffer = new Buffer(data, 'hex')
var version = new Buffer('0488ade4', 'hex') //0488ade4 is a consant listed in the aforementioned bip32 wiki. console.log(cs.encode(buffer, version)) // => xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi

Decode Bitcoin Private Wallet Import Format (WIF) to private key

var cs = require('coinstring') var res = cs.decode('5Hx15HFGyep2CfPxsJKe2fXJsCVn5DEiyoeGGF6JZjGbTRnqfiD')
console.log(res.version.toString('hex')) // => 80
console.log(res.payload.toString('hex')) // => 1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd

Functional Goodies

coinstring also has some functional goodies.

Function to Generate Bitcoin Wallet Import Format

var cs = require('coinstring') var privateKeyHex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd";
var privateKeyHexBuf = new Buffer(privateKeyHex, 'hex')
var version = 0x80 //Bitcoin private key var toBtcWif = cs.createEncoder(version) //later in your program
console.log(toBtcWif(privateKeyHexBuf)) // => 5Hx15HFGyep2CfPxsJKe2fXJsCVn5DEiyoeGGF6JZjGbTRnqfiD

Function to Parse Bitcoin Wallet Import Format

var cs = require('coinstring'); var wif = "5Hx15HFGyep2CfPxsJKe2fXJsCVn5DEiyoeGGF6JZjGbTRnqfiD"
var version = 0x80 //Bitcoin private key var fromBtcWif = cs.createDecoder(version) //later in your program
console.log(fromBtcWif(wif).payload.toString('hex')) // => 51184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd
var cs = require('coinstring'); var hash160 = "3c176e659bea0f29a3e9bf7880c112b1b31b4dc8" //hash representing uncompressed
var hash160Buf = new Buffer(hash160, 'hex')
var version = 0x6F //Bitcoin Testnet Address var testnetAddressValidator = cs.createValidator(version)
console.log(testnetAddressValidator("mkzgubTA5Ahi6BPSkE6MN9pEafRutznkMe")) // => true

API

coinstring exports the following six functions:

encode(payload, [version])

Used to convert either a hash160 or private key into an address or wallet import format string respectively.

  • payload: A Buffer, Array, or Uint8Array of bytes, either the hash160 or private key.
  • version: Optional. Can be prepended to payload. Is an integer representing the version or a Buffer if version is greater than one byte. The case where it's typically greater than one byte is for working with BIP32.

Returns the base58 encoded value of type string.

decode(base58str, [version])

It is the inverse of the encode() function i.e. it converts the address or wallet import format into a Buffer of bytes. It throws if the address or wallet import format is not valid. Not valid means that the version doesn't match, or the checksum is incorrect.

  • base58str: A string that is either the wallet import format or public address.
  • version: Is an integer representing the version or Buffer. See below for more information.

Returns the decoded base58 payload of type Buffer. If version was passed to input, it is chopped off on the output.

isValid(base58str, version)

Validates whether the address string or wallet import format string is valid.

  • base58str: A string that is either the wallet import format or public address.
  • version: Is an integer representing the version or Buffer. See below for more information.

Returns a true or false.

createEncoder(version)

Returns a function that takes as input the payload like from encode() above.

createDecoder(version)

Returns a function that takes as input the base58str like from decode() above.

createValidator(version)

Returns a function that takes as input the base58str like from isValid() above.

List of Common Crypto Currency Versions

The following is a table of common crypto currency versions. It may seem a bit user unfriendly to have to input the number instead of something like "BTC"; we agree. Another module will be created to address this. In the meantime, use the table below.

Crypto CoinPublic AddressPrivate Wallet Import Format
Bitcoin 0x00 0x80
Bitcoin Script Hash 0x05 N/A
Bitcoin Testnet 0x6E 0xEF
Bitcoin Testnet Script Hash 0xC4 N/A
Dogecoin 0x1E 0x9E
Litecoin 0x30 0xB0
Namecoin 0x34 0xB4

You may also want to just use the module coininfo instead.

References

  • http://procbits.com/2013/08/27/generating-a-bitcoin-address-with-javascript
  • http://brainwallet.org/
bitcoinaliens как вывести.

Generating a Bitcoin address - Complementary Currency .

NetworkParameters- base58 improve this answer. Normal addresses currently always start with 1 addresses from script hashes use 3 address, though this might change in a future version. Decode " ab0 " bitcoin. All the code from this post is available here. Cryptography ; using System. I encoding found anything exept for the Base

mayzus financial services ltd bitcoin price »

withdraw bitcoin address combinations

I'm writing some code to learn more about the bitcoin processes. It is the inverse of the encode function i. I think I can help you. Create a gist now Instantly share code, notes, and snippets. A string that is either the wallet import format or public address. Under Base58Check, addresses can contain all alphanumeric characters except 0, O, I, and l.

bitcoin current value gbp »

bitcoin block mds

Reload to refresh your session. Ok that does make bitcoin sense, but I still think I am getting the wrong big integer as is bigger than a bit number. Contracts ; using Address. These are big-endian most significant byte encoding. BlockCopy arr, 0result, base58, arr. Here's how it works: Base58Check encoding From Bitcoin Wiki.

epicon x2 lo r litecoin price »

Blockchain/Bitcoin for beginners 8: Bitcoin addresses, public key hash, P2PKH transactions

<< Go back to the previous page

Похожие статьи