github.com/annchain/OG@v0.0.9/account/key.go (about)

     1  package account
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/annchain/OG/common/crypto"
     6  	"github.com/annchain/OG/common/encryption"
     7  	"github.com/annchain/OG/deprecated/ogcrypto"
     8  )
     9  
    10  func SavePrivateKey(path string, content string) {
    11  	vault := encryption.NewVault([]byte(content))
    12  	if err := vault.Dump(path, ""); err != nil {
    13  		fmt.Println(fmt.Sprintf("error on saving privkey to %s: %v", path, err))
    14  		panic(err)
    15  	}
    16  }
    17  
    18  func GenAccount() (crypto.PrivateKey, crypto.PublicKey) {
    19  	signer := &ogcrypto.SignerSecp256k1{}
    20  	pub, priv := signer.RandomKeyPair()
    21  
    22  	return priv, pub
    23  }
    24  
    25  func RandomAccount() *Account {
    26  	sk, pk := GenAccount()
    27  	signer := crypto.NewSigner(sk.Type)
    28  
    29  	return &Account{
    30  		Id:          0,
    31  		PrivateKey:  sk,
    32  		PublicKey:   pk,
    33  		Address:     signer.Address(pk),
    34  		InitBalance: 0,
    35  	}
    36  }