forked from hashgraph/hedera-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (59 loc) · 2.14 KB
/
main.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
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
package main
import (
"fmt"
"strings"
"github.com/hashgraph/hedera-sdk-go/v2"
)
func main() {
// Generate 24 word mnemonic
mnemonic24, err := hedera.GenerateMnemonic24()
if err != nil {
println(err.Error(), ": error generating 24 word mnemonic")
return
}
// Generate 12 word mnemonic
mnemonic12, err := hedera.GenerateMnemonic12()
if err != nil {
println(err.Error(), ": error generating 12 word mnemonic")
return
}
// Given legacy string
legacyString := "jolly,kidnap,tom,lawn,drunk,chick,optic,lust,mutter,mole,bride,galley,dense,member,sage,neural,widow,decide,curb,aboard,margin,manure"
// Initializing a legacy mnemonic from legacy string
mnemonicLegacy, err := hedera.NewMnemonic(strings.Split(legacyString, ","))
if err != nil {
println(err.Error(), ": error generating mnemonic from legacy string")
return
}
fmt.Printf("mnemonic 24 word = %v\n", mnemonic24)
fmt.Printf("mnemonic 12 word = %v\n", mnemonic12)
fmt.Printf("mnemonic legacy = %v\n", mnemonicLegacy)
// Creating a Private Key from 24 word mnemonic with an optional passphrase
privateKey24, err := mnemonic24.ToPrivateKey( /* passphrase */ "")
if err != nil {
println(err.Error(), ": error converting 24 word mnemonic to PrivateKey")
return
}
// Creating a Private Key from 12 word mnemonic with an optional passphrase
privateKey12, err := mnemonic12.ToPrivateKey( /* passphrase */ "")
if err != nil {
println(err.Error(), ": error converting 12 word mnemonic to PrivateKey")
return
}
// ToLegacyPrivateKey() doesn't support a passphrase
privateLegacy, err := mnemonicLegacy.ToLegacyPrivateKey()
if err != nil {
println(err.Error(), ": error converting legacy mnemonic to PrivateKey")
return
}
// Retrieving the Public Key
publicKey24 := privateKey24.PublicKey()
publicKey12 := privateKey12.PublicKey()
publicLegacy := privateLegacy.PublicKey()
fmt.Printf("private 24 word = %v\n", privateKey24)
fmt.Printf("public 24 word = %v\n", publicKey24)
fmt.Printf("private 12 word = %v\n", privateKey12)
fmt.Printf("public 12 word = %v\n", publicKey12)
fmt.Printf("private legacy = %v\n", privateLegacy)
fmt.Printf("public legacy = %v\n", publicLegacy)
}