Skip to content

Commit

Permalink
Add get_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender committed Mar 19, 2024
1 parent 4cd4273 commit c392c2e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/rpc/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
25 changes: 25 additions & 0 deletions pkg/types/keychain.go
Original file line number Diff line number Diff line change
@@ -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:""`
}

0 comments on commit c392c2e

Please sign in to comment.