-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddress.go
More file actions
162 lines (133 loc) · 6.08 KB
/
address.go
File metadata and controls
162 lines (133 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package coins
import (
"encoding/hex"
"errors"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/bech32"
"github.com/sonr-io/coins/aptos"
"github.com/sonr-io/coins/bitcoin"
"github.com/sonr-io/coins/cosmos/atom"
"github.com/sonr-io/coins/cosmos/axelar"
"github.com/sonr-io/coins/cosmos/cronos"
"github.com/sonr-io/coins/cosmos/evmos"
"github.com/sonr-io/coins/cosmos/iris"
"github.com/sonr-io/coins/cosmos/juno"
"github.com/sonr-io/coins/cosmos/kava"
"github.com/sonr-io/coins/cosmos/kujira"
"github.com/sonr-io/coins/cosmos/okc"
"github.com/sonr-io/coins/cosmos/osmo"
"github.com/sonr-io/coins/cosmos/secret"
"github.com/sonr-io/coins/cosmos/sei"
"github.com/sonr-io/coins/cosmos/stargaze"
"github.com/sonr-io/coins/cosmos/tia"
"github.com/sonr-io/coins/ethereum"
"github.com/sonr-io/coins/filecoin"
"github.com/sonr-io/coins/solana"
)
var errUnimplemented = errors.New("unimplemented")
// AptosAddressFromPublicKey returns the Aptos address from the public key
func AptosAddressFromPublicKey(publicKey []byte) (string, error) {
return aptos.NewPubKeyAddress(hex.EncodeToString(publicKey), true)
}
// AtomAddressFromPublicKey returns the Atom address from the public key
func AtomAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, atom.HRP)
}
// AxelarAddressFromPublicKey returns the Axelar address from the public key
func AxelarAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, axelar.HRP)
}
// AvaxAddressFromPublicKey returns the Avax address from the public key
func AvaxAddressFromPublicKey(publicKey []byte) (string, error) {
return "", errUnimplemented
}
// BitcoinAddressFromPublicKey returns the Bitcoin address from the public key
func BitcoinAddressFromPublicKey(publicKey []byte) (string, error) {
mainNetParams := bitcoin.GetBTCMainNetParams()
return bitcoin.PubKeyToAddr(publicKey, bitcoin.TAPROOT, mainNetParams)
}
// CosmosAddressFromPublicKey returns the Cosmos address from the public key
func CosmosAddressFromPublicKey(publicKey []byte, hrp string) (string, error) {
bytes := btcutil.Hash160(publicKey)
return bech32.EncodeFromBase256(hrp, bytes)
}
// CronosAddressFromPublicKey returns the Cronos address from the public key
func CronosAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, cronos.HRP)
}
// EthereumAddressFromPublicKey returns the Ethereum address from the public key
func EthereumAddressFromPublicKey(publicKey []byte) (string, error) {
return ethereum.GetAddress(hex.EncodeToString(publicKey)), nil
}
// EvmosAddressFromPublicKey returns the Evmos address from the public key
func EvmosAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, evmos.HRP)
}
// FilecoinAddressFromPublicKey returns the Filecoin address from the public key
func FilecoinAddressFromPublicKey(publicKey []byte) (string, error) {
return filecoin.GetAddressByPublicKey(hex.EncodeToString(publicKey), filecoin.MainnetPrefix)
}
// HeliumAddressFromPublicKey returns the Helium address from the publicKey
func HeliumAddressFromPublicKey(publicKey []byte) (string, error) {
return "", errUnimplemented
}
// IrisAddressFromPublicKey returns the Iris address from the public key
func IrisAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, iris.HRP)
}
// JunoAddressFromPublicKey returns the Juno address from the public key
func JunoAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, juno.HRP)
}
// KavaAddressFromPublicKey returns the Kava address from the public key
func KavaAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, kava.HRP)
}
// KujiraAddressFromPublicKey returns the Kujira address from the public key
func KujiraAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, kujira.HRP)
}
// OkcAddressFromPublicKey returns the Okc address from the public key
func OkcAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, okc.HRP)
}
// OsmoAddressFromPublicKey returns the Osmo address from the public key
func OsmoAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, osmo.HRP)
}
// PolkadotAddressFromPublicKey returns the Polkadot address from the public key
func PolkadotAddressFromPublicKey(publicKey []byte) (string, error) {
return "", errUnimplemented
}
// SecretAddressFromPublicKey returns the Secret address from the public key
func SecretAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, secret.HRP)
}
// SeiAddressFromPublicKey returns the Sei address from the public key
func SeiAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, sei.HRP)
}
// SolanaAddressFromPublicKey returns the Solana address from the public key
func SolanaAddressFromPublicKey(publicKey []byte) (string, error) {
return solana.NewAddressByPublic(hex.EncodeToString(publicKey))
}
// SolanaAddressFromPublicKey returns the Solana address from the public key
func SonrAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, "idx")
}
// StargazeAddressFromPublicKey returns the Stargaze address from the public key
func StargazeAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, stargaze.HRP)
}
// SuiAddressFromPublicKey returns the Sui address from the public key
func SuiAddressFromPublicKey(publicKey []byte) (string, error) {
return "", errUnimplemented
}
// TezosAddressFromPublicKey returns the Tezos address from the public key
func TezosAddressFromPublicKey(publicKey []byte) (string, error) {
return "", errUnimplemented
}
// TiaAddressFromPublicKey returns the Tia address from the public key
func TiaAddressFromPublicKey(publicKey []byte) (string, error) {
return CosmosAddressFromPublicKey(publicKey, tia.HRP)
}