forked from fbsobreira/gotron-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
creation.go
43 lines (38 loc) · 1.07 KB
/
creation.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
package account
import (
"github.com/atong007/gotron-sdk/pkg/keys"
"github.com/atong007/gotron-sdk/pkg/mnemonic"
"github.com/atong007/gotron-sdk/pkg/store"
)
// Creation struct for account
type Creation struct {
Name string
Passphrase string
Mnemonic string
MnemonicPassphrase string
HdAccountNumber *uint32
HdIndexNumber *uint32
}
// New create new name
func New() string {
return "New Account"
}
// IsValidPassphrase check if strong
func IsValidPassphrase(pass string) bool {
// TODO: force strong password
return true
}
// CreateNewLocalAccount assumes all the inputs are valid, legitmate
func CreateNewLocalAccount(candidate *Creation) error {
ks := store.FromAccountName(candidate.Name)
if candidate.Mnemonic == "" {
candidate.Mnemonic = mnemonic.Generate()
}
// Hardcoded index of 0 for brandnew account.
private, _ := keys.FromMnemonicSeedAndPassphrase(candidate.Mnemonic, candidate.MnemonicPassphrase, 0)
_, err := ks.ImportECDSA(private.ToECDSA(), candidate.Passphrase)
if err != nil {
return err
}
return nil
}