@@ -376,6 +376,17 @@ func (ks keystore) ImportPubKey(uid, armor string) error {
376
376
return nil
377
377
}
378
378
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.
379
390
func (ks keystore ) Sign (uid string , msg []byte , signMode signing.SignMode ) ([]byte , types.PubKey , error ) {
380
391
k , err := ks .Key (uid )
381
392
if err != nil {
@@ -536,6 +547,19 @@ func (ks keystore) List() ([]*Record, error) {
536
547
return ks .MigrateAll ()
537
548
}
538
549
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.
539
563
func (ks keystore ) NewMnemonic (uid string , language Language , hdPath , bip39Passphrase string , algo SignatureAlgo ) (* Record , string , error ) {
540
564
if language != English {
541
565
return nil , "" , ErrUnsupportedLanguage
@@ -707,6 +731,15 @@ func newFileBackendKeyringConfig(name, dir string, buf io.Reader) keyring.Config
707
731
}
708
732
}
709
733
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.
710
743
func newRealPrompt (dir string , buf io.Reader ) func (string ) (string , error ) {
711
744
return func (prompt string ) (string , error ) {
712
745
keyhashStored := false
@@ -896,6 +929,7 @@ func (ks keystore) writeMultisigKey(name string, pk types.PubKey) (*Record, erro
896
929
return k , ks .writeRecord (k )
897
930
}
898
931
932
+ // MigrateAll migrates all legacy key information stored in the keystore to the new Record format.
899
933
func (ks keystore ) MigrateAll () ([]* Record , error ) {
900
934
keys , err := ks .db .Keys ()
901
935
if err != nil {
@@ -1008,6 +1042,16 @@ func (ks keystore) SetItem(item keyring.Item) error {
1008
1042
return ks .db .Set (item )
1009
1043
}
1010
1044
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.
1011
1055
func (ks keystore ) convertFromLegacyInfo (info LegacyInfo ) (* Record , error ) {
1012
1056
if info == nil {
1013
1057
return nil , errorsmod .Wrap (ErrLegacyToRecord , "info is nil" )
0 commit comments