ethereum/EIPs-55 Mixed-case checksum address encoding
| eip | title | author | type | category | status | created |
|---|---|---|---|---|---|---|
|
55
|
Mixed-case checksum address encoding
|
Vitalik Buterin
|
Standards Track
|
ERC
|
Final
|
2016-01-14
|
Specification(python)
from ethereum import utils def checksum_encode(addr): # Takes a -byte binary address as input
o = ''
v = utils.big_endian_to_int(utils.sha3(addr.hex()))
for i, c in enumerate(addr.hex()):
if c in ''://就是如果address在i位置上的值是数字的话,就不做任何改变
o += c
else: //但是如果是字符的话,就要另进行判断,(2**(255 - 4*i))这个的二进制的结果就是从后向前数的255 - 4*i个位置上的值为1,即是为了实现从前往后数为4*i位置的数字
o += c.upper() if (v & (**( - *i))) else c.lower()//255的原因是hash的v有32bytes,即32*8=256,从0开始
//所以意思是如果小写十六进制地址的散列v的第4*i位也是1,则以大写形式打印,否则以小写形式打印。
return '0x'+o def test(addrstr):
assert(addrstr == checksum_encode(bytes.fromhex(addrstr[:]))) test('0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed')
test('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359')
test('0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB')
test('0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb')
注意:v = utils.big_endian_to_int(utils.sha3(addr.hex()))
所谓的大端模式(Big-endian),是指数据的高字节,保存在内存的低地址中,而数据的低字节,保存在内存的高地址中,这样的存储模式有点儿类似于把数据当作字符串顺序处理:地址由小向大增加,而数据从高位往低位放;比如1234,如果是数字的话应该从低位开始读4321(即小端模式);但是这里为大端模式,所以读法就是1234。这是为了顺序处理addr的hash值
In English, convert the address to hex, but if the ith digit is a letter (ie. it's one of abcdef) print it in uppercase if the 4*ith bit of the hash of the lowercase hexadecimal address is 1 otherwise print it in lowercase.
Rationale
Benefits:
- Backwards compatible with many hex parsers that accept mixed case, allowing it to be easily introduced over time
- Keeps the length at 40 characters。 address长度为40个字符
- On average there will be 15 check bits per address, and the net probability that a randomly generated address if mistyped will accidentally pass a check is 0.0247%. This is a ~50x improvement over ICAP, but not as good as a 4-byte check code. 上面bit的转换效率没有字节的转化效率快,所以下面实现的是半字节(16进制一字符4bits)形式的转换方法:
例子:
const createKeccakHash = require('keccak');
function toChecksumAddress (address) {
address = address.toLowerCase().replace('0x', '');
console.log(address);
var hash = createKeccakHash('keccak256').update(address).digest('hex');//update就是输入要加密的值,digest就是将加密好的hash值以16进制的形式输出
console.log(hash);//5cfac663f45837b409c4d3dc1cef5f4759734f4989dd53a31b1265734c0b28f4,64个
var ret = '0x';
for (var i = ; i < address.length; i++) {//所以只用得到hash的前40个字符
if (parseInt(hash[i], ) >= ) {//即将16进制的hash[i]转化成10进制的数值后与8进行比较,如果在i位置的hash的值大于或等于8,相应位置的address的值就换成大写,否则就还是小写
ret += address[i].toUpperCase();//其实就是根据得到的hash值来相应将address转换成大小写皆有的形式
console.log('if');
console.log(ret);
} else {
ret += address[i];
console.log('else');
console.log(ret);
}
}
return ret;
}
var addr = '0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359';//去掉0x是40个
console.log(toChecksumAddress(addr));
这里的例子address是16进制的,当然,如果the hex address encoded as ASCII,那么就写成:
var hash = createKeccakHash('keccak256').update(Buffer.from(address.toLowerCase(), 'ascii')).digest()
Adoption
| Wallet | displays checksummed addresses | rejects invalid mixed-case | rejects too short | rejects too long |
|---|---|---|---|---|
| Etherwall 2.0.1 | Yes | Yes | Yes | Yes |
| Jaxx 1.2.17 | No | Yes | Yes | Yes |
| MetaMask 3.7.8 | Yes | Yes | Yes | Yes |
| Mist 0.8.10 | Yes | Yes | Yes | Yes |
| MyEtherWallet v3.9.4 | Yes | Yes | Yes | Yes |
| Parity 1.6.6-beta (UI) | Yes | Yes | Yes | Yes |
Exchange support for mixed-case address checksums, as of 2017-05-27:
| Exchange | displays checksummed deposit addresses | rejects invalid mixed-case | rejects too short | rejects too long |
|---|---|---|---|---|
| Bitfinex | No | Yes | Yes | Yes |
| Coinbase | Yes | No | Yes | Yes |
| GDAX | Yes | Yes | Yes | Yes |
| Kraken | No | No | Yes | Yes |
| Poloniex | No | No | Yes | Yes |
| Shapeshift | No | No | Yes | Yes |
References
- EIP 55 issue and discussion https://github.com/ethereum/eips/issues/55
- Python implementation in
ethereum-utils - Ethereumjs-util implementation https://github.com/ethereumjs/ethereumjs-util/blob/75f529458bc7dc84f85fd0446d0fac92d991c262/index.js#L452-L466
/**
* Returns a checksummed address
* @param {String} address
* @return {String}
*/
exports.toChecksumAddress = function (address) {
address = exports.stripHexPrefix(address).toLowerCase()
var hash = exports.sha3(address).toString('hex')
var ret = '0x' for (var i = ; i < address.length; i++) {
if (parseInt(hash[i], ) >= ) {
ret += address[i].toUpperCase()
} else {
ret += address[i]
}
} return ret
}
4.Swift implementation in EthereumKit
ethereum/EIPs-55 Mixed-case checksum address encoding的更多相关文章
- 【转】干货 | 【虚拟货币钱包】从 BIP32、BIP39、BIP44 到 Ethereum HD Wallet
虚拟货币钱包 钱包顾名思义是存放$$$.但在虚拟货币世界有点不一样,我的帐户资讯(像是我有多少钱)是储存在区块链上,实际存在钱包中的是我的帐户对应的 key.有了这把 key 我就可以在虚拟货币世界证 ...
- ethereum/EIPs-1271 smart contract
https://github.com/PhABC/EIPs/blob/is-valid-signature/EIPS/eip-1271.md Standard Signature Validation ...
- ethereum/EIPs-1078 Universal login / signup using ENS subdomains
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1078.md eip title author discussions-to status ...
- Ethereum HD Wallet(虚拟货币钱包)-BIP32、BIP39、BIP44
1.使用HD钱包的好处(链接:https://www.jianshu.com/p/53405db83c16) 备份更容易 传统钱包的问题是一个钱包可能存有一堆密钥地址,每个地址都有一些比特币.这样备份 ...
- go ethereum源码分析 PartIV Transaction相关
核心数据结构: core.types.transaction.go type Transaction struct { data txdata // caches hash atomic.Value ...
- ethereum/EIPs-100 挖矿难度计算
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-100.md 创世纪区块的难度是131,072,有一个特殊的公式用来计算之后的每个块的难度. ...
- ethereum/EIPs-191 Signed Data Standard
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-191.md eip title author status type category c ...
- ethereum/EIPs-161 State trie clearing
EIP 161: State trie clearing - makes it possible to remove a large number of empty accounts that wer ...
- ethereum/EIPs-725
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-725.md eip title author discussions-to status ...
随机推荐
- 看到他我一下子就悟了-- Lambda表达式
一直对Lambda表达式似懂非懂,平常也用过,就是不太明白有时候还要百度.周六去图书馆看书,看到下面这几句话,一下子就悟了: Lambda表达式(匿名函数),基本形式: (intput paramte ...
- MVC中子页面如何引用模板页中的jquery脚本
MVC中子页面如何引用模板页中的jquery脚本 最近在学习mvc,遇到了一个问题:在html页面中写js代码,都是引用mvc5自带的jquery脚本,虽然一拖(将指定的jquery脚本如 jquer ...
- Java_多项式加法
题目内容: 一个多项式可以表达为x的各次幂与系数乘积的和,比如: 2x6+3x5+12x3+6x+20 现在,你的程序要读入两个多项式,然后输出这两个多项式的和,也就是把对应的幂上的系数相加然后输出. ...
- Archlinux/Manjaro使用笔记-使用makepkg安装软件 报错:未找到strip分割所需的二进制文件 的解决方法
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 使用archlinux或manjaro安装aurman时遇到如下报错 错误:未找到strip分割所需的二进制文件 原因:未安装g ...
- D3.js 制作中国地图
from: http://d3.decembercafe.org/pages/map/index.html GeoJSON is a format for encoding a variety of ...
- postgresql-10.1-3-windows-x64 安装之后,起动pgAdmin 4问题(win10)
运行pgAdmin出现”pgAdmin 4 the application server could not be contant“ 窗口. 参考:https://stackoverflow.com ...
- ionic 开发解决ios上qq客服链接不跳转或者跳转到appstore
不能跳转的情况需要 在ionic项目根目录下,打开config.xml文件,在<access origin="*" />后添加<allow-navigation ...
- Apex的对象共享
Apex的对象共享 在Apex中,每个对象都有一个"共享"对象,其中存储了该对象的共享设定. 这种共享对象以"share"结尾.比如Account的共享对象是A ...
- webrtc学习: 部署stun和turn服务器
webrtc的P2P穿透部分是由libjingle实现的. 步骤顺序大概是这样的: 1. 尝试直连. 2. 通过stun服务器进行穿透 3. 无法穿透则通过turn服务器中转. stun 服务器比较简 ...
- WindowsErrorCode
0 操作成功完成.1 功能错误.2 系统找不到指定的文件.3 系统找不到指定的路径.4 系统无法打开文件.5 拒绝访问.6 句柄无效.7 存储控制块被损坏.8 存储空间不足, 无法处理此命令.9 存储 ...