feat: `AccountInfo` extended with `privateKey` property

This commit is contained in:
Sale Djenic 2022-10-28 11:30:00 +02:00 committed by saledjenic
parent c1c7d2dbf6
commit 006d0ba847
1 changed files with 7 additions and 4 deletions

View File

@ -28,10 +28,12 @@ func NewAccount(privateKey *ecdsa.PrivateKey, extKey *extkeys.ExtendedKey) Accou
} }
func (a *Account) ToAccountInfo() AccountInfo { func (a *Account) ToAccountInfo() AccountInfo {
privateKeyHex := types.EncodeHex(crypto.FromECDSA(a.privateKey))
publicKeyHex := types.EncodeHex(crypto.FromECDSAPub(&a.privateKey.PublicKey)) publicKeyHex := types.EncodeHex(crypto.FromECDSAPub(&a.privateKey.PublicKey))
addressHex := crypto.PubkeyToAddress(a.privateKey.PublicKey).Hex() addressHex := crypto.PubkeyToAddress(a.privateKey.PublicKey).Hex()
return AccountInfo{ return AccountInfo{
PrivateKey: privateKeyHex,
PublicKey: publicKeyHex, PublicKey: publicKeyHex,
Address: addressHex, Address: addressHex,
} }
@ -58,6 +60,7 @@ func (a *Account) ToGeneratedAccountInfo(id string, mnemonic string) GeneratedAc
// AccountInfo contains a PublicKey and an Address of an account. // AccountInfo contains a PublicKey and an Address of an account.
type AccountInfo struct { type AccountInfo struct {
PrivateKey string `json:"privateKey"`
PublicKey string `json:"publicKey"` PublicKey string `json:"publicKey"`
Address string `json:"address"` Address string `json:"address"`
} }