-
Notifications
You must be signed in to change notification settings - Fork 5
/
private_key.go
53 lines (45 loc) · 1.59 KB
/
private_key.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
44
45
46
47
48
49
50
51
52
53
package payd
import (
"context"
"time"
"github.com/libsv/go-bk/bip32"
)
// PrivateKey describes a named private key.
type PrivateKey struct {
UserID uint64 `db:"user_id"`
// Name of the private key.
Name string `db:"name"`
// Xprv is the private key.
Xprv string `db:"xprv"`
// CreatedAt is the date/time when the key was stored.
CreatedAt time.Time `db:"createdAt"`
}
// KeyArgs defines all arguments required to get a key.
type KeyArgs struct {
// Name is the name of the key to return.
Name string `db:"name"`
// user id associated with this key.
UserID uint64 `db:"user_id"`
}
// PrivateKeyService can be implemented to get and create PrivateKeys.
type PrivateKeyService interface {
// Create will create a new private key if it doesn't exist already.
Create(ctx context.Context, keyName string, userID uint64) error
// PrivateKey will return a private key.
PrivateKey(ctx context.Context, keyName string, userID uint64) (*bip32.ExtendedKey, error)
}
// PrivateKeyReader reads private info from a data store.
type PrivateKeyReader interface {
// PrivateKey can be used to return an existing private key.
PrivateKey(ctx context.Context, args KeyArgs) (*PrivateKey, error)
}
// PrivateKeyWriter will add private key to the datastore.
type PrivateKeyWriter interface {
// PrivateKeyCreate will add a new private key to the data store.
PrivateKeyCreate(ctx context.Context, req PrivateKey) (*PrivateKey, error)
}
// PrivateKeyReaderWriter describes a data store that can be implemented to get and store private keys.
type PrivateKeyReaderWriter interface {
PrivateKeyReader
PrivateKeyWriter
}