由于存在公钥有两种形式,那么一个公钥便对应两个地址。这两个地址都可由同一私钥签署交易。' T* F% L3 i2 U
公钥生成地址的算法:
Version = 1 byte of 0 (zero); on the test network, this is 1 byte of 111
Key hash = Version concatenated with RIPEMD-160(SHA-256(public key))
Checksum = 1st 4 bytes of SHA-256(SHA-256(Key hash))
Bitcoin Address = Base58Encode(Key hash concatenated with Checksum)' G* Q" G- u/ @/ i: S& i) ~. f4 e
下图是非压缩公钥生成地址的过程: n, t/ `& I4 Y" W0 V, S. Y: b
- o" o2 C+ E1 q1 C7 M
对于压缩公钥生成地址时,则只取公钥的X部分即可。
推导关系3 d0 p2 ?7 N5 u% u
三者推导关系:私钥 >> 公钥 >> 两个地址。过程均不可逆。拥有私钥便拥有一切,但通常为了方便,会把对应的公钥、地址也存储起来。2 H$ h5 i' a1 U' P9 g% V
-----------------------以下来源于百度http://zhidao.baidu.com/link?url=-iAaP8yzPO7NI4ruKOtmowXhR4FONK5cdx7IqFWkHuCwA8XFt9I82LOlGAGoJko06gQxs5qI0lKtvr8ndC0Qp76eW0rg_lx7CTf9FVyaF2u ---------------
比特币地址的生成过程
(说明: 有些数字以"0x"开头,意思是此数字使用十六进制表示法。"0x"本身没有任何含义,它是C语言流传下来的,约定俗成的写法,比如0xA就是十进制的10。另外,1个字节 = 8位二进制 = 2位十六进制)。
第一步,随机选取一个32字节的数、大小介于1 ~ 0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4141之间,作为私钥。" c+ w: o, Y F5 |
18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725
第二步,使用椭圆曲线加密算法(ECDSA-secp256k1)计算私钥所对应的非压缩公钥。 (共65字节, 1字节 0x04, 32字节为x坐标,32字节为y坐标)关于公钥压缩、非压缩的问题另文说明。$ @) K( p7 a: @2 H- N
0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B/ A6 F0 L1 Q) U5 R9 Y
23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6% Q! n# i: v/ z8 z) X
第三步,计算公钥的 SHA-256 哈希值$ t/ n3 v) O( ^& O
600FFE422B4E00731A59557A5CCA46CC183944191006324A447BDB2D98D4B408( o. n) n1 K1 C: R
第四步,取上一步结果,计算 RIPEMD-160 哈希值
010966776006953D5567439E5E39F86A0D273BEE! L0 [- ?9 k+ R# x4 j+ \( v$ C
第五步,取上一步结果,前面加入地址版本号(比特币主网版本号“0x00”)
00010966776006953D5567439E5E39F86A0D273BEE
第六步,取上一步结果,计算 SHA-256 哈希值8 P8 c' Y3 y% y4 Q4 v
445C7A8007A93D8733188288BB320A8FE2DEBD2AE1B47F0F50BC10BAE845C094
第七步,取上一步结果,再计算一下 SHA-256 哈希值(哈哈)
D61967F63C7DD183914A4AE452C9F6AD5D462CE3D277798075B107615C1A8A30
第八步,取上一步结果的前4个字节(8位十六进制)
D61967F6
第九步,把这4个字节加在第五步的结果后面,作为校验(这就是比特币地址的16进制形态)。% v( _) C+ \# t+ k3 o* z6 E
00010966776006953D5567439E5E39F86A0D273BEED61967F6
第十步,用base58表示法变换一下地址(这就是最常见的比特币地址形态)。
16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM
------------------------------来自于以太坊黄皮书-------------------------------------------------------3 v- i8 h6 j) d, X8 b
以太坊地址生成算法& ], p0 r# K# l. Z
0 \8 o0 p0 r4 u8 W9 p
------------------------------来自于以太坊白皮书------------------------------------------------------------------------+ a5 j5 w7 i# ~! T9 I+ }
https://github.com/ethereum/wiki/wiki/White-Paper#ethereum-accounts i# R4 y! A4 P
Ethereum Accounts
In Ethereum, the state is made up of objects called “accounts”, with each account having a 20-byte address and state transitions being direct transfers of value and information between accounts.
以太坊中,账户包含20字节的地址,以及账户之间价值和信息的传递的状态转换。6 ~9 ?1 H* D$ y4 j( s& L
An Ethereum account contains four fields:* _$ Y* A, K& X# k3 O! P
The nonce, a counter used to make sure each transaction can only be processed once( Y! `- l$ Q: C: n5 c0 F; M; N
The account’s current ether balance
The account’s contract code, if present' E9 `! V1 b5 v, X
The account’s storage (empty by default)1 Y( M% ^/ ?5 {0 D3 }
以太坊账户包含4个部分:
nonce 是一个计数器用于确保每笔交易只被处理一次
账户当前以太币数量3 L _5 Z0 V: h( m
合约代码, R7 b: W& O7 H
以太坊存储空间?
“Ether” is the main internal crypto-fuel of Ethereum, and is used to pay transaction fees.
以太币是以太坊中的主要密码货币,用于支付交易费用) q, j1 }0 _+ c* c( n2 r, o/ w
In general, there are two types of accounts: externally owned accounts, controlled by private keys, and contract accounts, controlled by their contract code. An externally owned account has no code, and one can send messages from an externally owned account by creating and signing a transaction; in a contract account, every time the contract account receives a message its code activates, allowing it to read and write to internal storage and send other messages or create contracts in turn. X' A" ` g9 E8 v4 n, X: y; B( p
以太坊中有两种账户:外部用户的账户,通过私钥控制;智能合约账户,通过合约代码控制。
外部用户账户不包含代码,用户可以通过创建和签署交易来给外部用户账户发送信息。" [: }6 X2 r* c' H7 }9 @
合约账户,每次接受到信息时,合约代码开始工作,允许读取、写入内部存储,已结发送信息,或者反过来创建合约。
Note that “contracts” in Ethereum should not be seen as something that should be “fulfilled” or “complied with”; rather, they are more like “autonomous agents” that live inside of the Ethereum execution environment, always executing a specific piece of code when “poked” by a message or transaction, and having direct control over their own ether balance and their own key/value store to keep track of persistent variables.0 ]. c5 ^7 }! n" P* j
注意以太坊中的合约不应该被视为某种可以被完成,被遵守的恭喜。它们更像是以太坊环境的自治代理机构。能够直接控制它们的以太币和秘钥来追踪持续变量。
成为第一个吐槽的人