forked from goat-systems/go-tezos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goTezosCrypto.go
44 lines (36 loc) · 985 Bytes
/
goTezosCrypto.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
43
44
package goTezos
import (
"github.com/GoKillers/libsodium-go/cryptosign"
"github.com/GoKillers/libsodium-go/cryptogenerichash"
"gitlab.com/tulpenhaendler/hellotezos/base58check"
"strings"
)
type KeyPair struct {
Sk string
Pk string
Address string
}
func (this *GoTezos) addPrefix(b []byte, p []byte) []byte {
p = append(p, b...)
return p
}
func (this *GoTezos) GenerateAddress() KeyPair {
var pkhr []byte
sk, pk, _ := cryptosign.CryptoSignKeyPair()
pkhr, _ = generichash.CryptoGenericHash(20, pk, []byte{})
address := base58check.Encode("00", this.addPrefix(pkhr, []byte{6, 161, 159}))
res := KeyPair{
Sk:base58check.Encode("00", this.addPrefix(sk, []byte{43, 246, 78, 7})),
Pk:base58check.Encode("00", this.addPrefix(pk, []byte{13, 15, 37, 217})),
Address:address,
}
return res
}
func (this *GoTezos) VanityAddressPrefix(prefix string) KeyPair {
for {
addr := this.GenerateAddress()
if strings.HasPrefix(addr.Address,prefix) {
return addr
}
}
}