util

package
v0.0.0-...-6d444a5 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2018 License: ISC Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64File

func Base64File(filename string) (string, error)

Base64File returns the base64 content of a file.

func ConvertBodyToByteArray

func ConvertBodyToByteArray(r io.Reader, print bool) []byte

ConvertBodyToByteArray converts a response body into a byte array and optionally prints it to stdout.

func ConvertDigest

func ConvertDigest(d string) ([sha256.Size]byte, bool)

ConvertDigest converts a string into a digest.

func ConvertSignature

func ConvertSignature(s string) ([identity.SignatureSize]byte, error)

ConvertSignature converts a hex encoded signature to a proper sized byte slice.

func ConvertStringToken

func ConvertStringToken(token string) ([]byte, error)

ConvertStringToken verifies and converts a string token to a proper sized []byte.

func CreateProposalTitleRegex

func CreateProposalTitleRegex() string

CreateProposalTitleRegex returns a regex string for matching the proposal name

func DerivePaywallAddress

func DerivePaywallAddress(params *chaincfg.Params, xpub string, index uint32) (string, error)

DerivePaywallAddress derives a paywall address using the provided xpub and index.

func Digest

func Digest(b []byte) []byte

Digest returns the SHA256 of a byte slice.

func DigestFile

func DigestFile(filename string) (string, error)

DigestFile returns the SHA256 of a file.

func DigestFileBytes

func DigestFileBytes(filename string) ([]byte, error)

DigestFileBytes returns the SHA256 of a file.

func FQDN

func FQDN() string

FQDN returns the fully qualified domain name of the machine it is running on.

func GenCertPair

func GenCertPair(curve elliptic.Curve, org, certFile, keyFile string) error

GenCertPair generates a key/cert pair to the paths provided.

func GetErrorFromJSON

func GetErrorFromJSON(r io.Reader) (interface{}, error)

GetErrorFromJSON returns the error that is embedded in a JSON reply.

func GetProposalName

func GetProposalName(payload string) (string, error)

ProposalName returns a proposal name

func IdentityFromString

func IdentityFromString(id string) (*identity.PublicIdentity, error)

IdentityFromString converts a string public key into a public identity structure.

func IsDigest

func IsDigest(digest string) bool

IsDigest determines if a string is a valid SHA256 digest.

func IsValidProposalName

func IsValidProposalName(str string) bool

IsValidProposalName reports whether str is a valid proposal name

func LoadFile

func LoadFile(filename string) (mimeType string, digest string, payload string, err error)

LoadFile loads a file of disk and returns the MIME type, the sha256 digest and the payload encoded as base64. If any of the intermediary operations fail the function will return an error instead.

func MimeFile

func MimeFile(filename string) (string, error)

MimeFile returns the MIME type of a file.

func NewClient

func NewClient(skipVerify bool, certFilename string) (*http.Client, error)

NewClient returns a new http.Client instance

func NormalizeAddress

func NormalizeAddress(addr, defaultPort string) string

NormalizeAddress returns addr with the passed default port appended if there is not already a port specified.

func ParseGetParams

func ParseGetParams(r *http.Request, dst interface{}) error

ParseGetParams parses the query params from the GET request into a struct. This method requires the struct type to be defined with `schema` tags.

func PayWithTestnetFaucet

func PayWithTestnetFaucet(faucetURL string, address string, amount uint64, overridetoken string) (string, error)

PayWithTestnetFaucet makes a request to the testnet faucet.

func Random

func Random(n int) ([]byte, error)

Random returns a variable number of bytes of random data.

func RemoteIdentity

func RemoteIdentity(skipTLSVerify bool, host, cert string) (*identity.PublicIdentity, error)

RemoteIdentity fetches the identity from politeiad.

func RespondWithCopy

func RespondWithCopy(w http.ResponseWriter, code int, contentType string, body []byte) error

func RespondWithError

func RespondWithError(w http.ResponseWriter, code int, message string)

func RespondWithJSON

func RespondWithJSON(w http.ResponseWriter, code int, payload interface{})

func Timestamp

func Timestamp(host string, digests []*[sha256.Size]byte) error

Timestamp sends a Timestamp request to the provided host. The caller is responsible for assembling the host string based on what net to use.

func Verify

func Verify(host string, digests []string) (*v1.VerifyReply, error)

Verify sends a dcrtime Verify command to the provided host. It checks and validates the entire reply. A single failure is considered terminal and an error is returned. If the reply is valid it is returned to the caller for further processing. This means that the caller can be assured that all checks have been done and the data is readily usable.

func VerifyChallenge

func VerifyChallenge(id *identity.PublicIdentity, challenge []byte, signature string) error

VerifyChallenge checks that the signature returned from politeiad is the challenge signed with the given identity.

func VerifyTxWithBlockExplorers

func VerifyTxWithBlockExplorers(address string, amount uint64, txid string, txnotbefore int64) (confirmed bool, err error)

VerifyTxWithBlockExplorers verifies that the passed transaction id is a valid transaction that can be confirmed on a public block explorer.

Types

type BEBackupTransaction

type BEBackupTransaction struct {
	Address       string      `json:"address"`       // Transaction address
	TxId          string      `json:"txid"`          // Transaction id
	Amount        json.Number `json:"amount"`        // Transaction amount (in DCR)
	Confirmations uint64      `json:"confirmations"` // Number of confirmations
	Timestamp     int64       `json:"ts"`            // Transaction timestamp
}

BEBackupTransaction is an object representing a transaction; it's part of the data returned from the URL for the backup block explorer when fetching the transactions for an address.

type BEPrimaryTransaction

type BEPrimaryTransaction struct {
	TxId          string                     `json:"txid"`          // Transaction id
	Vout          []BEPrimaryTransactionVout `json:"vout"`          // Transaction outputs
	Confirmations uint64                     `json:"confirmations"` // Number of confirmations
	Timestamp     int64                      `json:"time"`          // Transaction timestamp
}

BEPrimaryTransaction is an object representing a transaction; it's part of the data returned from the URL for the primary block explorer when fetching the transactions for an address.

type BEPrimaryTransactionScriptPubkey

type BEPrimaryTransactionScriptPubkey struct {
	Addresses []string `json:"addresses"` // Array of transaction input addresses
}

BEPrimaryTransactionScriptPubkey holds the script info for a transaction.

type BEPrimaryTransactionVout

type BEPrimaryTransactionVout struct {
	Amount       json.Number                      `json:"value"`        // Transaction amount (in DCR)
	ScriptPubkey BEPrimaryTransactionScriptPubkey `json:"scriptPubkey"` // Transaction script info
}

BEPrimaryTransactionVout holds the transaction amount information.

type FaucetResponse

type FaucetResponse struct {
	Txid  string
	Error string
}

FaucetResponse represents the expected JSON response from the testnet faucet.

type PaywallGatewayNewOrderResponse

type PaywallGatewayNewOrderResponse struct {
	Error         string
	OrderID       string
	PaywallAmount uint64
}

PaywallGatewayNewOrderResponse respresents the expected JSON response to a PaywallGatewayNewOrder command.

Jump to

Keyboard shortcuts

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