keys/keybase.go
func (kb dbKeybase) Sign(name, passphrase string, msg []byte) (sig crypto.Signature, pub crypto.PubKey, err error) {
	info, err := kb.Get(name)
	if err != nil {
		return
	}
	var priv crypto.PrivKey
	switch info.(type) {
	case localInfo:
		linfo := info.(localInfo)
		if linfo.PrivKeyArmor == "" {
			err = fmt.Errorf("private key not available")
			return
		}
		priv, err = unarmorDecryptPrivKey(linfo.PrivKeyArmor, passphrase)
		if err != nil {
			return nil, nil, err
		}
	case ledgerInfo:
		linfo := info.(ledgerInfo)
		priv, err = crypto.NewPrivKeyLedgerSecp256k1(linfo.Path)
		if err != nil {
			return
		}
	case offlineInfo:
		linfo := info.(offlineInfo)
		fmt.Printf("Bytes to sign:\n%s", msg)
		buf := bufio.NewReader(os.Stdin)
		fmt.Printf("\nEnter Amino-encoded signature:\n")
		// Will block until user inputs the signature
		signed, err := buf.ReadString('\n')
		if err != nil {
			return nil, nil, err
		}
		cdc.MustUnmarshalBinary([]byte(signed), sig)
		return sig, linfo.GetPubKey(), nil
	}
	sig, err = priv.Sign(msg)
	if err != nil {
		return nil, nil, err
	}
	pub = priv.PubKey()
	return sig, pub, nil
}
func (kb dbKeybase) Sign(name, passphrase string, msg []byte) (sig crypto.Signature, pub crypto.PubKey, err error) {
	info, err := kb.Get(name)
	if err != nil {
		return
	}
	var priv crypto.PrivKey
	switch info.(type) {
	case localInfo:
		linfo := info.(localInfo)
		if linfo.PrivKeyArmor == "" {
			err = fmt.Errorf("private key not available")
			return
		}
		priv, err = unarmorDecryptPrivKey(linfo.PrivKeyArmor, passphrase)
		if err != nil {
			return nil, nil, err
		}
	case ledgerInfo:
		linfo := info.(ledgerInfo)
		priv, err = crypto.NewPrivKeyLedgerSecp256k1(linfo.Path)
		if err != nil {
			return
		}
	case offlineInfo:
		linfo := info.(offlineInfo)
		fmt.Printf("Bytes to sign:\n%s", msg)
		buf := bufio.NewReader(os.Stdin)
		fmt.Printf("\nEnter Amino-encoded signature:\n")
		// Will block until user inputs the signature
		signed, err := buf.ReadString('\n')
		if err != nil {
			return nil, nil, err
		}
		cdc.MustUnmarshalBinary([]byte(signed), sig)
		return sig, linfo.GetPubKey(), nil
	}
	sig, err = priv.Sign(msg)
	if err != nil {
		return nil, nil, err
	}
	pub = priv.PubKey()
	return sig, pub, nil
}
func ( kb dbKeybase ) Sign ( name , passphrase string , msg [ ] byte ) ( sig crypto . Signature , pub crypto . PubKey , err error ) { info , err := kb . Get ( name ) if err != nil { return } var priv crypto . PrivKey switch info . ( type ) { case localInfo : linfo := info . ( localInfo ) if linfo . PrivKeyArmor == " " { err = fmt . Errorf ( " " ) return } priv , err = unarmorDecryptPrivKey ( linfo . PrivKeyArmor , passphrase ) if err != nil { return nil , nil , err } case ledgerInfo : linfo := info . ( ledgerInfo ) priv , err = crypto . NewPrivKeyLedgerSecp256k1 ( linfo . Path ) if err != nil { return } case offlineInfo : linfo := info . ( offlineInfo ) fmt . Printf ( " \n " , msg ) buf := bufio . NewReader ( os . Stdin ) fmt . Printf ( " \n \n " ) // Will block until user inputs the signature signed , err := buf . ReadString ( '\n' ) if err != nil { return nil , nil , err } cdc . MustUnmarshalBinary ( [ ] byte ( signed ) , sig ) return sig , linfo . GetPubKey ( ) , nil } sig , err = priv . Sign ( msg ) if err != nil { return nil , nil , err } pub = priv . PubKey ( ) return sig , pub , nil }
// Sign signs the msg with the named key.
// It returns an error if the key doesn't exist or the decryption fails.
Sign signs the msg with the named key . It returns an error if the key doesn t exist or the decryption fails .