You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
package keystore
|
|
|
|
import (
|
|
"fmt"
|
|
"math/big"
|
|
"sync"
|
|
|
|
"github.com/harmony-one/harmony/accounts"
|
|
"github.com/harmony-one/harmony/accounts/keystore"
|
|
"github.com/harmony-one/harmony/core/types"
|
|
)
|
|
|
|
var (
|
|
// DefaultKeyStoreDir is the default directory of the keystore
|
|
DefaultKeyStoreDir = ".hmy/keystore"
|
|
onceForKeyStore sync.Once
|
|
scryptN = keystore.StandardScryptN
|
|
scryptP = keystore.StandardScryptP
|
|
hmyKeystore *keystore.KeyStore
|
|
hmyPass string
|
|
)
|
|
|
|
// GetHmyKeyStore returns the only keystore of the node
|
|
func GetHmyKeyStore() *keystore.KeyStore {
|
|
onceForKeyStore.Do(func() {
|
|
hmyKeystore = keystore.NewKeyStore(DefaultKeyStoreDir, scryptN, scryptP)
|
|
})
|
|
return hmyKeystore
|
|
}
|
|
|
|
// SetHmyPass set the passphrase
|
|
func SetHmyPass(pass string) {
|
|
hmyPass = pass
|
|
}
|
|
|
|
// Unlock unlocks the account using passphrase
|
|
func Unlock(account accounts.Account) {
|
|
if hmyKeystore != nil {
|
|
hmyKeystore.Unlock(account, hmyPass)
|
|
}
|
|
}
|
|
|
|
// SignTx signs transaction using account key
|
|
func SignTx(account accounts.Account, tx *types.Transaction) (*types.Transaction, error) {
|
|
if hmyKeystore != nil {
|
|
return hmyKeystore.SignTx(account, tx, big.NewInt(1)) // TODO: use chainID from config
|
|
}
|
|
return tx, fmt.Errorf("un-initialized keystore")
|
|
}
|
|
|