Documentation ¶
Index ¶
- Variables
- func Base64File(filename string) (string, error)
- func CleanAndExpandPath(path string) string
- func ConvertBodyToByteArray(r io.Reader, print bool) []byte
- func ConvertDigest(d string) ([sha256.Size]byte, bool)
- func ConvertSignature(s string) ([identity.SignatureSize]byte, error)
- func ConvertStringToken(token string) ([]byte, error)
- func DcrStringToAtoms(dcrstr string) (uint64, error)
- func DeriveChildAddress(params *chaincfg.Params, xpub string, index uint32) (string, error)
- func Digest(b []byte) []byte
- func DigestFile(filename string) (string, error)
- func DigestFileBytes(filename string) ([]byte, error)
- func FQDN() string
- func FileExists(name string) bool
- func FormatJSON(v interface{}) string
- func GenCertPair(curve elliptic.Curve, org, certFile, keyFile string) error
- func GetErrorFromJSON(r io.Reader) (interface{}, error)
- func IsDigest(digest string) bool
- func LoadEncryptionKey(log slog.Logger, keyFile string) (*[32]byte, error)
- func LoadFile(filename string) (mimeType string, digest string, payload string, err error)
- func LoadFile2(filename string) (string, []byte, error)
- func MerkleRoot(digests []string) (*[sha256.Size]byte, error)
- func MimeFile(filename string) (string, error)
- func NewHTTPClient(skipVerify bool, certPath string) (*http.Client, error)
- func NormalizeAddress(addr, defaultPort string) string
- func ParseGetParams(r *http.Request, dst interface{}) error
- func Random(n int) ([]byte, error)
- func RandomUint64() (uint64, error)
- func Regexp(supportedChars []string, lengthMin, lengthMax uint64) (*regexp.Regexp, error)
- func RemoteAddr(r *http.Request) string
- func RespBody(r *http.Response) []byte
- func RespondRaw(w http.ResponseWriter, code int, payload []byte)
- func RespondWithError(w http.ResponseWriter, code int, message string)
- func RespondWithJSON(w http.ResponseWriter, code int, payload interface{})
- func ShortToken(token []byte) ([]byte, error)
- func ShortTokenEncode(token []byte) (string, error)
- func ShortTokenSize() int
- func ShortTokenString(token string) (string, error)
- func StackTrace(err error) (string, bool)
- func TokenDecode(tokenType, token string) ([]byte, error)
- func TokenDecodeAnyLength(tokenType, token string) ([]byte, error)
- func TokenEncode(token []byte) string
- func TokenIsFullLength(tokenType string, token []byte) bool
- func TokenRegexp() string
- func TokenToPrefix(token string) string
- func TokensToPrefixes(tokens []string) []string
- func VerifyChallenge(id *identity.PublicIdentity, challenge []byte, signature string) error
- func VerifyMessage(address, message, signature string, net *chaincfg.Params) (bool, error)
- func VerifySignature(signature, pubKey, msg string) error
- func Zero(in []byte)
- type Argon2Params
- type ErrorStatusT
- type SignatureError
Constants ¶
This section is empty.
Variables ¶
var ( // TokenTypeGit represents a token from the politeiad git backend. TokenTypeGit = "git" // TokenTypeTstore represents a token from the politeiad tstore // backend. TokenTypeTstore = "tstore" )
var ErrorStatuses = map[ErrorStatusT]string{ ErrorStatusInvalid: "signature error invalid", ErrorStatusPublicKeyInvalid: "public key invalid", ErrorStatusSignatureInvalid: "signature invalid", }
ErrorStatuses contains the human readable signature error messages.
Functions ¶
func Base64File ¶
Base64File returns the base64 content of a file.
func CleanAndExpandPath ¶
CleanAndExpandPath expands environment variables and leading ~ in the passed path, cleans the result, and returns it.
func ConvertBodyToByteArray ¶
ConvertBodyToByteArray converts a response body into a byte array and optionally prints it to stdout.
func ConvertDigest ¶
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 ¶
ConvertStringToken verifies and converts a string token to a proper sized byte slice. This function accepts both the full length token and token prefixes.
func DcrStringToAtoms ¶ added in v1.3.0
DcrStringToAtoms converts a DCR amount as a string into a uint64 representing atoms. Supported input variations: "1", ".1", "0.1".
func DeriveChildAddress ¶ added in v1.3.0
DeriveChildAddress derives a child address using the provided xpub and index.
func DigestFile ¶
DigestFile returns the SHA256 of a file.
func DigestFileBytes ¶
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 FileExists ¶
FilesExists reports whether the named file or directory exists.
func FormatJSON ¶ added in v1.0.0
func FormatJSON(v interface{}) string
FormatJSON returns a pretty printed JSON string for the provided structure.
func GenCertPair ¶
GenCertPair generates a key/cert pair to the paths provided.
func GetErrorFromJSON ¶
GetErrorFromJSON returns the error that is embedded in a JSON reply.
func LoadEncryptionKey ¶ added in v1.0.0
LoadEncryptionKey loads the encryption key at the provided file path. If a key does not exists at the file path then a new secretbox key is created and saved to the file path before returning the key.
func LoadFile ¶
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 MerkleRoot ¶ added in v1.0.0
MerkleRoot computes and returns the merkle root of the provided digests. The digests should be hex encoded SHA256 digests.
func NewHTTPClient ¶ added in v1.0.0
NewHTTPClient returns a new http Client.
func NormalizeAddress ¶
NormalizeAddress returns addr with the passed default port appended if there is not already a port specified.
func ParseGetParams ¶
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 RandomUint64 ¶
RandomInt returns a random unsigned integer.
func RemoteAddr ¶ added in v1.0.0
RemoteAddr returns a string of the remote address, i.e. the address that sent the request.
func RespondRaw ¶ added in v0.2.0
func RespondRaw(w http.ResponseWriter, code int, payload []byte)
func RespondWithError ¶
func RespondWithError(w http.ResponseWriter, code int, message string)
func RespondWithJSON ¶
func RespondWithJSON(w http.ResponseWriter, code int, payload interface{})
func ShortToken ¶ added in v1.0.0
ShortToken returns the short version of a token.
func ShortTokenEncode ¶ added in v1.0.0
ShortTokenEncode returns the hex encoded shortened token.
func ShortTokenSize ¶ added in v1.0.0
func ShortTokenSize() int
ShortTokenSize returns the size, in bytes, of a politeiad short token.
func ShortTokenString ¶ added in v1.0.0
ShortTokenString takes a hex encoded token and returns the shortened token for it.
func StackTrace ¶ added in v1.1.0
StackTrace returns the stack trace for a pkg/errors error. The returned bool indicates whether the provided error is a pkg/errors error. Stack traces are not available for stdlib errors.
func TokenDecode ¶ added in v1.0.0
TokenDecode decodes a full length token. An error is returned if the token is not a full length, hex token.
func TokenDecodeAnyLength ¶ added in v1.0.0
TokenDecodeAnyLength decodes both short tokens and full length tokens.
func TokenEncode ¶ added in v1.0.0
TokenEncode returns the hex encoded token. Its possible that padding has been added to the token when it was originally decode in order to make it valid hex. This function checks for padding and removes it before encoding the token.
func TokenIsFullLength ¶ added in v1.0.0
TokenIsFullLength returns whether a token is a valid, full length politeiad censorship token.
func TokenRegexp ¶ added in v1.0.0
func TokenRegexp() string
TokenRegexp returns the string regexp that is used to match tokens.
func TokenToPrefix ¶ added in v0.2.0
TokenToPrefix returns a substring a token of length pd.TokenPrefixLength, or the token itself, whichever is shorter.
func TokensToPrefixes ¶ added in v0.2.0
TokensToPrefixes calls TokenToPrefix on a slice of tokens.
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 VerifyMessage ¶ added in v1.0.0
VerifyMessage verifies a message that was signed using a decred P2PKH address.
Copied from: github.com/decred/dcrd/blob/0fc55252f912756c23e641839b1001c21442c38a/rpcserver.go#L5605
func VerifySignature ¶ added in v1.0.0
VerifySignature verifies a hex encoded Ed25519 signature.
Types ¶
type Argon2Params ¶ added in v1.0.0
type Argon2Params struct { Time uint32 `json:"time"` Memory uint32 `json:"memory"` Threads uint8 `json:"threads"` KeyLen uint32 `json:"keylen"` Salt []byte `json:"salt"` }
Argon2Params represent the argon2 key derivation parameters that are used to derive various keys in politeia.
func NewArgon2Params ¶ added in v1.0.0
func NewArgon2Params() Argon2Params
NewArgon2Params returns a new Argon2Params with default values.
type ErrorStatusT ¶ added in v1.0.0
type ErrorStatusT int
ErrorStatusT represents an error that occurred during signature validation.
const ( // ErrorStatusInvalid is an invalid error status. ErrorStatusInvalid ErrorStatusT = 0 // ErrorStatusPublicKeyInvalid is returned when a public key is not // a hex encoded ed25519 public key. ErrorStatusPublicKeyInvalid ErrorStatusT = 1 // ErrorStatusSignatureInvalid is returned when a signature is // either not a valid hex encoded ed25519 signature or the // signature is wrong for the provided public key and message. ErrorStatusSignatureInvalid ErrorStatusT = 2 )
type SignatureError ¶ added in v1.0.0
type SignatureError struct { ErrorCode ErrorStatusT ErrorContext string }
SignatureError represents an error that was caused while verifying a signature.
func (SignatureError) Error ¶ added in v1.0.0
func (e SignatureError) Error() string
Error satisfies the error interface.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package version provides a single location to house the version information for dcrd and other utilities provided in the same repository.
|
Package version provides a single location to house the version information for dcrd and other utilities provided in the same repository. |