cmd

package
v0.0.0-...-7f85523 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MgmtCmd = &cobra.Command{
	Use:   "manage",
	Short: "administrativa for did:twit docs",
	Long:  `create and view did:twit documents`,
	RunE: func(cmd *cobra.Command, args []string) error {
		db, err := storage.NewConnection()
		if err != nil {
			fmt.Println("Problem initiating storage")
			return err
		}
		dids, err := db.ListDIDs()
		if err != nil {
			return err
		}
		printDIDs(dids)
		return nil
	},
}
View Source
var RootCmd = &cobra.Command{
	Use:   "did-twit-cli",
	Short: "The did:twit cli",
	Long:  `A utility for using the did:twit DID method for your Twitter username. Helps you create a did:twit document and generate Tweets.`,
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println(cmd.UsageString())

	},
}
View Source
var TweetCmd = &cobra.Command{
	Use:   "tweet",
	Short: "create a tweet for a given did",
	Long:  `create a tweet for a given did`,
	RunE: func(cmd *cobra.Command, args []string) error {
		didTwit := viper.GetString(didFlag)
		if didTwit == "" {
			return errors.New("must supply a user to author the tweet with the \"--did\" flag")
		}

		create := viper.GetBool(createFlag)
		var text string
		if create {
			text = createTweet(didTwit)
		} else {
			text = viper.GetString(tweetFlag)
		}
		if text == "" {
			return errors.New("tweet text cannot be empty. supply text with the \"--tweet\" flag")
		}

		db, err := storage.NewConnection()
		if err != nil {
			fmt.Println("Problem initiating storage")
			return err
		}
		didPrivKey, err := db.Read(didTwit)
		if err != nil || *didPrivKey == "" {
			fmt.Printf("Key could not be found for did: %s", didTwit)
			return err
		}

		privKey := base58.Decode(*didPrivKey)
		t, err := tweet.SignTweet(privKey, didTwit, text)
		if err != nil {
			fmt.Println("Problem signing tweet")
			return err
		}
		tweetTxt, err := tweet.GenerateTweetText(*t)
		if err != nil {
			fmt.Println("Problem generating tweet text")
			return err
		}
		fmt.Printf("Copy & Paste the following text into Twitter: \n"+
			"------------------------------------\n"+
			"%s"+
			"\n------------------------------------", *tweetTxt)
		return nil
	},
}
View Source
var VerifyCmd = &cobra.Command{
	Use:   "verify",
	Short: "verify a tweet for a given did",
	Long:  `verify a tweet for a given did`,
	RunE: func(cmd *cobra.Command, args []string) error {
		didTwit := viper.GetString(didFlag)
		if didTwit == "" {
			return errors.New("must supply the author of the tweet")
		}

		text := viper.GetString(tweetFlag)
		if text == "" {
			return errors.New("tweet text cannot be empty")
		}

		t, err := tweet.ReconstructTweet(text)
		if err != nil {
			fmt.Println("Could not reconstruct tweet")
			return err
		}

		pubKey, err := did.ExpandDID(didTwit)
		if err != nil {
			fmt.Printf("Author DID could not be expanded: %s\n", didTwit)
			return err
		}
		if err := tweet.VerifyTweet(*t, pubKey); err != nil {
			fmt.Printf("Tweet not valid for the given author: %s\n", didTwit)
			return err
		}

		fmt.Println("Tweet valid.")
		return nil
	},
}

Functions

This section is empty.

Types

type IsRequired

type IsRequired bool
const (
	Required    IsRequired = true
	NotRequired IsRequired = false
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL