forked from ArkEcosystem/go-crypto
/
address.go
42 lines (31 loc) · 851 Bytes
/
address.go
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
// This file is part of PHANTOM Go Crypto.
//
// (c) PhantomChain <info@phantom.org>
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
package crypto
import (
"github.com/PhantomChain/go-crypto/crypto/base58"
)
func AddressFromPassphrase(passphrase string) (string, error) {
privateKey, err := PrivateKeyFromPassphrase(passphrase)
if err != nil {
return "", err
}
return privateKey.ToAddress(), nil
}
func AddressToBytes(address string) ([]byte, error) {
bytes, err := base58.Decode(address)
if err != nil {
return nil, err
}
return bytes, nil
}
func ValidateAddress(address string) (bool, error) {
bytes, err := AddressToBytes(address)
if err != nil {
return false, err
}
return Byte2Hex(GetNetwork().Version) == Hex2Byte(bytes[:1]), nil
}