From 829750db023ad03dd882fef614af676fc284a618 Mon Sep 17 00:00:00 2001 From: Chris Marslender Date: Tue, 19 Mar 2024 17:10:47 -0500 Subject: [PATCH] Add get_keys (#117) --- pkg/rpc/daemon.go | 29 +++++++++++++++++++++++++++++ pkg/types/keychain.go | 25 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 pkg/types/keychain.go diff --git a/pkg/rpc/daemon.go b/pkg/rpc/daemon.go index 57576ab..3cf2d67 100644 --- a/pkg/rpc/daemon.go +++ b/pkg/rpc/daemon.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/chia-network/go-chia-libs/pkg/rpcinterface" + "github.com/chia-network/go-chia-libs/pkg/types" ) // DaemonService encapsulates direct daemon RPC methods @@ -37,3 +38,31 @@ func (s *DaemonService) GetNetworkInfo(opts *GetNetworkInfoOptions) (*GetNetwork return r, resp, nil } + +// GetKeysOptions configures how keys are returned in get_keys +type GetKeysOptions struct { + IncludeSecrets bool `json:"include_secrets"` +} + +// GetKeysResponse response from get_keys RPC call +type GetKeysResponse struct { + Response + Keys []types.KeyData `json:"keys"` +} + +// GetKeys returns key information +func (s *DaemonService) GetKeys(opts *GetKeysOptions) (*GetKeysResponse, *http.Response, error) { + request, err := s.NewRequest("get_keys", opts) + if err != nil { + return nil, nil, err + } + + r := &GetKeysResponse{} + + resp, err := s.Do(request, r) + if err != nil { + return nil, resp, err + } + + return r, resp, nil +} diff --git a/pkg/types/keychain.go b/pkg/types/keychain.go new file mode 100644 index 0000000..d507b0c --- /dev/null +++ b/pkg/types/keychain.go @@ -0,0 +1,25 @@ +package types + +import ( + "github.com/samber/mo" +) + +// PrivateKey is a chia_rs type that represents a private key +type PrivateKey struct { + // @TODO CHIA_RS BINDINGS: Add when we have the rust -> go bindings +} + +// KeyDataSecrets contains the secret portion of key data +type KeyDataSecrets struct { + Mnemonic []string `json:"mnemonic" streamable:""` + Entropy []byte `json:"entropy" streamable:""` + PrivateKey PrivateKey `json:"PrivateKey" streamable:""` +} + +// KeyData is the KeyData type from chia-blockchain +type KeyData struct { + Fingerprint uint32 `json:"fingerprint" streamable:""` + PublicKey G1Element `json:"public_key" streamable:""` + Label mo.Option[string] `json:"label" streamable:""` + Secrets mo.Option[KeyDataSecrets] `json:"secrets" streamable:""` +}