File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 11package keyring
22
33import (
4+ "fmt"
45 "io"
6+ "path/filepath"
7+ "reflect"
8+ "unsafe"
59
610 "github.com/99designs/keyring"
711
812 sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring"
913)
1014
15+ const keyringDirPrefix = "e2ee-keyring-%s"
16+
1117type Keyring interface {
1218 Get (string ) ([]byte , error )
1319 Set (string , []byte ) error
@@ -26,6 +32,20 @@ func New(
2632 return nil , err
2733 }
2834 db = kr .DB ()
35+ switch backend {
36+ case sdkkeyring .BackendTest , sdkkeyring .BackendFile :
37+ fileDir := filepath .Join (rootDir , fmt .Sprintf (keyringDirPrefix , backend ))
38+ el := reflect .ValueOf (db ).Elem ()
39+ if f := el .FieldByName ("dir" ); f .IsValid () {
40+ reflect .NewAt (f .Type (), unsafe .Pointer (f .UnsafeAddr ())).Elem ().SetString (fileDir )
41+ }
42+ case sdkkeyring .BackendPass :
43+ prefix := fmt .Sprintf (keyringDirPrefix , serviceName )
44+ el := reflect .ValueOf (db ).Elem ()
45+ if f := el .FieldByName ("prefix" ); f .IsValid () {
46+ reflect .NewAt (f .Type (), unsafe .Pointer (f .UnsafeAddr ())).Elem ().SetString (prefix )
47+ }
48+ }
2949 }
3050 return newKeystore (db , backend ), nil
3151}
You can’t perform that action at this time.
0 commit comments