cosmos 账户地址格式
cosmos里关于账户地址有三种不同的格式,我们看一看
[ec2-user@ip-172-31-30-153 ~]$ gaiacli keys show wall-e --bech=cons -o json --bech=acc | jq
{
"name": "wall-e",
"type": "local",
"address": "cosmos1hk4ze3hqwg62w89gmee3hj72u7wrap0a2ts87u",
"pub_key": "cosmospub1addwnpepq272xswjqka4wm6x8nvuwshdquh0q8xrxlafz7lj32snvtg2jswl6x5ywwu"
}
[ec2-user@ip-172-31-30-153 ~]$ gaiacli keys show wall-e --bech=cons -o json --bech=val | jq
{
"name": "wall-e",
"type": "local",
"address": "cosmosvaloper1hk4ze3hqwg62w89gmee3hj72u7wrap0a0lyjj0",
"pub_key": "cosmosvaloperpub1addwnpepq272xswjqka4wm6x8nvuwshdquh0q8xrxlafz7lj32snvtg2jswl60hprp0"
}
[ec2-user@ip-172-31-30-153 ~]$ gaiacli keys show wall-e --bech=cons -o json --bech=cons | jq
{
"name": "wall-e",
"type": "local",
"address": "cosmosvalcons1hk4ze3hqwg62w89gmee3hj72u7wrap0amvhw7w",
"pub_key": "cosmosvalconspub1addwnpepq272xswjqka4wm6x8nvuwshdquh0q8xrxlafz7lj32snvtg2jswl6fc4n96"
}
下面的内容是源码中找到的文档,一看就明白
docs/spec/other/bech32.md
HRP | Definition |
---|---|
cosmos | Cosmos Account Address |
cosmospub | Cosmos Account Public Key |
cosmosvalcons | Cosmos Validator Consensus Address |
cosmosvalconspub | Cosmos Validator Consensus Public Key |
cosmosvaloper | Cosmos Validator Operator Address |
cosmosvaloperpub | Cosmos Validator Operator Public Key |
我们来看一下bech32
https://github.com/btcsuite/btcutil/blob/master/bech32/bech32.go
// Encode encodes a byte slice into a bech32 string with the
// human-readable part hrb. Note that the bytes must each encode 5 bits
// (base32).
func Encode(hrp string, data []byte) (string, error) {
// Calculate the checksum of the data and append it at the end.
checksum := bech32Checksum(hrp, data)
combined := append(data, checksum...)
// The resulting bech32 string is the concatenation of the hrp, the
// separator 1, data and checksum. Everything after the separator is
// represented using the specified charset.
dataChars, err := toChars(combined)
if err != nil {
return "", fmt.Errorf("unable to convert data bytes to chars: "+
"%v", err)
}
return hrp + "1" + dataChars, nil
}
代码逻辑还是很简单的,主要是看最后一行代码,在bech32格式中会有一个常量1
,这个很有意思,为什么不是0呢,1
有些字体中看起来和l
很像啊