-
Notifications
You must be signed in to change notification settings - Fork 2
/
address_exchain.go
34 lines (28 loc) · 973 Bytes
/
address_exchain.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
package types
import (
"crypto/sha256"
"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/errors"
"github.com/fibonacci-chain/fbc/libs/tendermint/crypto"
)
// MustBech32ifyAccPub returns the result of Bech32ifyAccPub panicing on failure.
func MustBech32ifyAccPub(pub crypto.PubKey) string {
return MustBech32ifyPubKey(Bech32PubKeyTypeAccPub, pub)
}
// Derive derives a new address from the main `address` and a derivation `key`.
func Derive(address []byte, key []byte) []byte {
return Hash(UnsafeBytesToStr(address), key)
}
// Hash creates a new address from address type and key
func Hash(typ string, key []byte) []byte {
hasher := sha256.New()
_, err := hasher.Write(UnsafeStrToBytes(typ))
// the error always nil, it's here only to satisfy the io.Writer interface
errors.AssertNil(err)
th := hasher.Sum(nil)
hasher.Reset()
_, err = hasher.Write(th)
errors.AssertNil(err)
_, err = hasher.Write(key)
errors.AssertNil(err)
return hasher.Sum(nil)
}