-
Notifications
You must be signed in to change notification settings - Fork 13
/
solana.go
37 lines (31 loc) · 900 Bytes
/
solana.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
package coincodec
import (
"errors"
"github.com/wealdtech/go-slip44"
)
const (
SolanaAddressLength = 32
)
func init() {
toBytesMap[slip44.SOLANA] = SolanaDecodeToBytes
toStringMap[slip44.SOLANA] = SolanaEncodeToString
}
// SolanaDecodeToBytes converts the input string to a byte array
func SolanaDecodeToBytes(input string) ([]byte, error) {
decoded, err := Base58Decode(input, Base58DefaultAlphabet)
if err != nil {
return nil, err
}
if len(decoded) != SolanaAddressLength {
return nil, errors.New("Invalid length")
}
return decoded, nil
}
// SolanaEncodeToString converts the input byte array to a string representation of the Solana address.
func SolanaEncodeToString(data []byte) (string, error) {
if len(data) != SolanaAddressLength {
return "", errors.New("Invalid decoded address length")
}
encoded := Base58Encode(data, Base58DefaultAlphabet)
return encoded, nil
}