通过以太坊命令行客户端geth可以很简单的获得一个以太坊地址,如下:
An Etheria address xff0c; xff1a below;
地址0x8011cf2892985cdc58f447063bc6a089ba89f514 (20字节16进制)就是新生成的以太坊地址。
Address 0x8011cf2892985cdc58f447063bc6a089ba89f514 & #xff08; 20 byte ) is the newly generated ethercom address.
从以太坊源码 https://github.com/ethereum/go-ethereum 出发,分析地址生成过程
运行命令 :geth account new
程序入口在 https://github.com/ethereum/go-ethereum/blob/master/cmd/geth/main.go
Start with <#xff0c > analysis of address generation
running command & #xff1a; geth account new
at https://gethub.com/etheum/go-etheum/blob/master/cm/geth/main.go
账户相关的命令在 https://github.com/ethereum/go-ethereum/blob/master/cmd/geth/accountcmd.go 里,
新建账户命令为new:
Account-related commands at https://github.com/etheum/go-etheum/blob/master/cmd/geth/acaccountcmd.go & #xff0c;
new account commands are new:
关键:new一个新账户的时候,会调用accountCreate:
由此可见,accountCreate分为三个步骤,其中最关键的为第三步
(1)获取配置
(2)解析用户密码
(3)生成地址
This can be seen in xff0c; acaccountCreate divided into three steps xff0c;
& #xff08; 2xff09; parsing user passwords
& #xff08; 3xff09; generating address
第三步生成地址调用的keystore.StoreKey:
程序位置在 https://github.com/ethereum/go-ethereum/blob/master/accounts/keystore/keystore_passphrase.go
Step 3 generates the call for Keystore. StoreKey:
application location at https://gethub.com/otherium/go-etherium/blob/master/accounts/keystore/keystore_passprase.go
直接调用了storeNewKey 创建新账户
程序位置:https://github.com/ethereum/go-ethereum/blob/master/accounts/keystore/key.go
Direct call to storeNewKey to create a new account
application locationxff1a; https://github.com/otherium/go-etherium/blob/master/accounts/keystore/key.go
可以看到,newKey创建新账户时,
1、由secp256k1曲线生成私钥,是由32字节随机数组成
2、采用椭圆曲线数字签名算法(ECDSA)将私钥映射成公钥,一个私钥只能映射出一个公钥。
3、然后由公钥算出地址并构建一个自定义的Key
xff0c; newKey created a new account xff0c;
1; private key generated by a secp256k1 curve xff0c; 32 by random number
, digital signature algorithm using an elliptical curve xff08; ECDSAff09; private key mapping into a public key xff0c; a private key can only map a public key.
3 and then a public key calculates the address and constructs a custom Key.
3
继续看公钥是怎样算出地址并构建一个自定义的Key
Keep looking at how the public key calculates the address and builds a custom Key.
由公钥算出地址是由crypto.PubkeyToAddress完成的:
代码位置:https://github.com/ethereum/go-ethereum/blob/master/crypto/crypto.go
The addresses calculated by the public key were completed by crypto. PubkeyToAddress & #xff1a;
code location & #xff1a; https://github.com/otherium/go-otherium/blob/ Master/crypto/crypto.go
可以看到公钥(64字节)经过Keccak-256单向散列函数变成了32字节,然后取后20字节作为地址。本质上是从32字节的私钥映射到20字节的公共地址。这意味着一个账户可以有不止一个私钥。
You can see a public key xff08; 64 byte xff09; a single hash function from Keccak-256 becomes a 32 byte xff0c; then the last 20 bytes are taken as an address. The private key map is essentially from 32 bytes to a 20 byte public address. This means that an account can have more than one private key.
以太坊地址的生成过程如下:
The following is the process of generating the address: #xff1a;
- 由secp256k1曲线生成私钥,是由32字节的随机数生成
- 采用椭圆曲线数字签名算法(ECDSA)将私钥(32字节)映射成公钥(65字节)。
- 公钥(去掉04后剩下64字节)经过Keccak-256单向散列函数变成了32字节,然后取后20字节作为地址
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论