Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_keys daemon endpoint #117

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:""`
}