mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-11-16 11:46:45 +01:00
Mohammed Sohail
eba329eefa
* All postgres related functions now live in internal/store. * Updated queries.sql file to match struct order (readibility) * Moved keystore -> store * Moved queries -> store * Removed pkg/postgres
54 lines
852 B
Go
54 lines
852 B
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"crypto/ecdsa"
|
|
|
|
eth_crypto "github.com/celo-org/celo-blockchain/crypto"
|
|
"github.com/grassrootseconomics/cic-custodial/pkg/keypair"
|
|
)
|
|
|
|
func (s *PgStore) WriteKeyPair(
|
|
ctx context.Context,
|
|
keypair keypair.Key,
|
|
) (uint, error) {
|
|
var (
|
|
id uint
|
|
)
|
|
|
|
if err := s.db.QueryRow(
|
|
ctx,
|
|
s.queries.WriteKeyPair,
|
|
keypair.Public,
|
|
keypair.Private,
|
|
).Scan(&id); err != nil {
|
|
return id, err
|
|
}
|
|
|
|
return id, nil
|
|
}
|
|
|
|
func (s *PgStore) LoadPrivateKey(
|
|
ctx context.Context,
|
|
publicKey string,
|
|
) (*ecdsa.PrivateKey, error) {
|
|
var (
|
|
privateKeyString string
|
|
)
|
|
|
|
if err := s.db.QueryRow(
|
|
ctx,
|
|
s.queries.LoadKeyPair,
|
|
publicKey,
|
|
).Scan(&privateKeyString); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
privateKey, err := eth_crypto.HexToECDSA(privateKeyString)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return privateKey, nil
|
|
}
|