Skip to content

Commit 007d595

Browse files
authored
Merge branch 'main' into hieu/bankv2/create_denom
2 parents b20efbe + 77254b7 commit 007d595

File tree

13 files changed

+155
-102
lines changed

13 files changed

+155
-102
lines changed

collections/quad.go

-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ type quadKeyCodec[K1, K2, K3, K4 any] struct {
106106

107107
type jsonQuadKey [4]json.RawMessage
108108

109-
110109
// EncodeJSON encodes Quads to json
111110
func (t quadKeyCodec[K1, K2, K3, K4]) EncodeJSON(value Quad[K1, K2, K3, K4]) ([]byte, error) {
112111
json1, err := t.keyCodec1.EncodeJSON(*value.k1)
@@ -210,7 +209,6 @@ func (t quadKeyCodec[K1, K2, K3, K4]) KeyType() string {
210209
return fmt.Sprintf("Quad[%s,%s,%s,%s]", t.keyCodec1.KeyType(), t.keyCodec2.KeyType(), t.keyCodec3.KeyType(), t.keyCodec4.KeyType())
211210
}
212211

213-
214212
func (t quadKeyCodec[K1, K2, K3, K4]) Encode(buffer []byte, key Quad[K1, K2, K3, K4]) (int, error) {
215213
writtenTotal := 0
216214
if key.k1 != nil {
@@ -244,7 +242,6 @@ func (t quadKeyCodec[K1, K2, K3, K4]) Encode(buffer []byte, key Quad[K1, K2, K3,
244242
return writtenTotal, nil
245243
}
246244

247-
248245
func (t quadKeyCodec[K1, K2, K3, K4]) Decode(buffer []byte) (int, Quad[K1, K2, K3, K4], error) {
249246
readTotal := 0
250247
read, key1, err := t.keyCodec1.DecodeNonTerminal(buffer)

crypto/codec/pubkey.go

+16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ import (
1111
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
1212
)
1313

14+
// PubKeyToProto converts a JSON public key (in `cryptokeys.JSONPubkey` format) to its corresponding protobuf public key type.
15+
//
16+
// Parameters:
17+
// - pk: A `cryptokeys.JSONPubkey` containing the public key and its type.
18+
//
19+
// Returns:
20+
// - cryptotypes.PubKey: The protobuf public key corresponding to the provided JSON public key.
21+
// - error: An error if the key type is invalid or unsupported.
1422
func PubKeyToProto(pk cryptokeys.JSONPubkey) (cryptotypes.PubKey, error) {
1523
switch pk.KeyType {
1624
case ed25519.PubKeyName:
@@ -30,6 +38,14 @@ func PubKeyToProto(pk cryptokeys.JSONPubkey) (cryptotypes.PubKey, error) {
3038
}
3139
}
3240

41+
// PubKeyFromProto converts a protobuf public key (in `cryptotypes.PubKey` format) to a JSON public key format (`cryptokeys.JSONPubkey`).
42+
//
43+
// Parameters:
44+
// - pk: A `cryptotypes.PubKey` which is the protobuf representation of a public key.
45+
//
46+
// Returns:
47+
// - cryptokeys.JSONPubkey: The JSON-formatted public key corresponding to the provided protobuf public key.
48+
// - error: An error if the key type is invalid or unsupported.
3349
func PubKeyFromProto(pk cryptotypes.PubKey) (cryptokeys.JSONPubkey, error) {
3450
switch pk := pk.(type) {
3551
case *ed25519.PubKey:

crypto/hd/hdpath.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ func derivePrivateKey(privKeyBytes, chainCode [32]byte, index uint32, harden boo
230230
pubkeyBytes := ecPub.SerializeCompressed()
231231
data = pubkeyBytes
232232

233-
/* By using btcec, we can remove the dependency on tendermint/crypto/secp256k1
234-
pubkey := secp256k1.PrivKeySecp256k1(privKeyBytes).PubKey()
235-
public := pubkey.(secp256k1.PubKeySecp256k1)
236-
data = public[:]
237-
*/
233+
// By using btcec, we can remove the dependency on tendermint/crypto/secp256k1
234+
// pubkey := secp256k1.PrivKeySecp256k1(privKeyBytes).PubKey()
235+
// public := pubkey.(secp256k1.PubKeySecp256k1)
236+
// data = public[:]
237+
238238
}
239239

240240
data = append(data, uint32ToBytes(index)...)

crypto/keyring/keyring.go

+44
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,17 @@ func (ks keystore) ImportPubKey(uid, armor string) error {
376376
return nil
377377
}
378378

379+
// Sign signs a message using the private key associated with the provided UID.
380+
//
381+
// Parameters:
382+
// - uid: The unique identifier of the account/key to use for signing.
383+
// - msg: The message or data to be signed.
384+
// - signMode: The signing mode that specifies how the message should be signed.
385+
//
386+
// Returns:
387+
// - []byte: The generated signature.
388+
// - types.PubKey: The public key corresponding to the private key used for signing.
389+
// - error: Any error encountered during the signing process.
379390
func (ks keystore) Sign(uid string, msg []byte, signMode signing.SignMode) ([]byte, types.PubKey, error) {
380391
k, err := ks.Key(uid)
381392
if err != nil {
@@ -536,6 +547,19 @@ func (ks keystore) List() ([]*Record, error) {
536547
return ks.MigrateAll()
537548
}
538549

550+
// NewMnemonic generates a new mnemonic and derives a new account from it.
551+
//
552+
// Parameters:
553+
// - uid: A unique identifier for the account.
554+
// - language: The language for the mnemonic (only English is supported).
555+
// - hdPath: The hierarchical deterministic (HD) path for key derivation.
556+
// - bip39Passphrase: The passphrase used in conjunction with the mnemonic for BIP-39.
557+
// - algo: The signature algorithm used for signing keys.
558+
//
559+
// Returns:
560+
// - *Record: A new key record that contains the private and public key information.
561+
// - string: The generated mnemonic phrase.
562+
// - error: Any error encountered during the process.
539563
func (ks keystore) NewMnemonic(uid string, language Language, hdPath, bip39Passphrase string, algo SignatureAlgo) (*Record, string, error) {
540564
if language != English {
541565
return nil, "", ErrUnsupportedLanguage
@@ -707,6 +731,15 @@ func newFileBackendKeyringConfig(name, dir string, buf io.Reader) keyring.Config
707731
}
708732
}
709733

734+
// newRealPrompt creates a password prompt function to retrieve or create a passphrase
735+
// for the keyring system.
736+
//
737+
// Parameters:
738+
// - dir: The directory where the keyhash file is stored.
739+
// - buf: An io.Reader input, typically used for reading user input (e.g., the passphrase).
740+
//
741+
// Returns:
742+
// - A function that accepts a prompt string and returns the passphrase or an error.
710743
func newRealPrompt(dir string, buf io.Reader) func(string) (string, error) {
711744
return func(prompt string) (string, error) {
712745
keyhashStored := false
@@ -896,6 +929,7 @@ func (ks keystore) writeMultisigKey(name string, pk types.PubKey) (*Record, erro
896929
return k, ks.writeRecord(k)
897930
}
898931

932+
// MigrateAll migrates all legacy key information stored in the keystore to the new Record format.
899933
func (ks keystore) MigrateAll() ([]*Record, error) {
900934
keys, err := ks.db.Keys()
901935
if err != nil {
@@ -1008,6 +1042,16 @@ func (ks keystore) SetItem(item keyring.Item) error {
10081042
return ks.db.Set(item)
10091043
}
10101044

1045+
// convertFromLegacyInfo converts a legacy account info (LegacyInfo) into a new Record format.
1046+
// It handles different types of legacy info and creates the corresponding Record based on the type.
1047+
//
1048+
// Parameters:
1049+
// - info: The legacy account information (LegacyInfo) that needs to be converted.
1050+
// It provides the name, public key, and other data depending on the type of account.
1051+
1052+
// Returns:
1053+
// - *Record: A pointer to the newly created Record that corresponds to the legacy account info.
1054+
// - error: An error if the conversion fails due to invalid info or an unsupported account type.
10111055
func (ks keystore) convertFromLegacyInfo(info LegacyInfo) (*Record, error) {
10121056
if info == nil {
10131057
return nil, errorsmod.Wrap(ErrLegacyToRecord, "info is nil")

crypto/keyring/record.go

+7
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ func extractPrivKeyFromRecord(k *Record) (cryptotypes.PrivKey, error) {
128128
return extractPrivKeyFromLocal(rl)
129129
}
130130

131+
// extractPrivKeyFromLocal extracts the private key from a local record.
132+
// It checks if the private key is available in the provided Record_Local instance.
133+
// Parameters:
134+
// - rl: A pointer to a Record_Local instance from which the private key will be extracted.
135+
// Returns:
136+
// - priv: The extracted cryptotypes.PrivKey if successful.
137+
// - error: An error if the private key is not available or if the casting fails.
131138
func extractPrivKeyFromLocal(rl *Record_Local) (cryptotypes.PrivKey, error) {
132139
if rl.PrivKey == nil {
133140
return nil, ErrPrivKeyNotAvailable

0 commit comments

Comments
 (0)