Some checks failed
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
Build & Push SDK Proto Builder / build (push) Has been cancelled
89 lines
2.6 KiB
Go
89 lines
2.6 KiB
Go
package keys
|
|
|
|
import (
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
// Use protobuf interface marshaler rather then generic JSON
|
|
|
|
// KeyOutput defines a structure wrapping around an Info object used for output
|
|
// functionality.
|
|
type KeyOutput struct {
|
|
Name string `json:"name" yaml:"name"`
|
|
Type string `json:"type" yaml:"type"`
|
|
Address string `json:"address" yaml:"address"`
|
|
PubKey string `json:"pubkey" yaml:"pubkey"`
|
|
Mnemonic string `json:"mnemonic,omitempty" yaml:"mnemonic"`
|
|
}
|
|
|
|
// NewKeyOutput creates a default KeyOutput instance without Mnemonic, Threshold and PubKeys
|
|
func NewKeyOutput(name string, keyType keyring.KeyType, a sdk.Address, pk cryptotypes.PubKey) (KeyOutput, error) {
|
|
apk, err := codectypes.NewAnyWithValue(pk)
|
|
if err != nil {
|
|
return KeyOutput{}, err
|
|
}
|
|
bz, err := codec.ProtoMarshalJSON(apk, nil)
|
|
if err != nil {
|
|
return KeyOutput{}, err
|
|
}
|
|
return KeyOutput{
|
|
Name: name,
|
|
Type: keyType.String(),
|
|
Address: a.String(),
|
|
PubKey: string(bz),
|
|
}, nil
|
|
}
|
|
|
|
// MkConsKeyOutput create a KeyOutput in with "cons" Bech32 prefixes.
|
|
func MkConsKeyOutput(k *keyring.Record) (KeyOutput, error) {
|
|
pk, err := k.GetPubKey()
|
|
if err != nil {
|
|
return KeyOutput{}, err
|
|
}
|
|
addr := sdk.ConsAddress(pk.Address())
|
|
return NewKeyOutput(k.Name, k.GetType(), addr, pk)
|
|
}
|
|
|
|
// MkValKeyOutput create a KeyOutput in with "val" Bech32 prefixes.
|
|
func MkValKeyOutput(k *keyring.Record) (KeyOutput, error) {
|
|
pk, err := k.GetPubKey()
|
|
if err != nil {
|
|
return KeyOutput{}, err
|
|
}
|
|
|
|
addr := sdk.ValAddress(pk.Address())
|
|
|
|
return NewKeyOutput(k.Name, k.GetType(), addr, pk)
|
|
}
|
|
|
|
// MkAccKeyOutput create a KeyOutput in with "acc" Bech32 prefixes. If the
|
|
// public key is a multisig public key, then the threshold and constituent
|
|
// public keys will be added.
|
|
func MkAccKeyOutput(k *keyring.Record) (KeyOutput, error) {
|
|
pk, err := k.GetPubKey()
|
|
if err != nil {
|
|
return KeyOutput{}, err
|
|
}
|
|
addr := sdk.AccAddress(pk.Address())
|
|
return NewKeyOutput(k.Name, k.GetType(), addr, pk)
|
|
}
|
|
|
|
// MkAccKeysOutput returns a slice of KeyOutput objects, each with the "acc"
|
|
// Bech32 prefixes, given a slice of Record objects. It returns an error if any
|
|
// call to MkKeyOutput fails.
|
|
func MkAccKeysOutput(records []*keyring.Record) ([]KeyOutput, error) {
|
|
kos := make([]KeyOutput, len(records))
|
|
var err error
|
|
for i, r := range records {
|
|
kos[i], err = MkAccKeyOutput(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return kos, nil
|
|
}
|