account

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PROOF_REPOSITORY_BASE_NAME       = "inox.run-iamhuman"
	UNENCODED_CHALLENGE_VALUE_LENGTH = 6
)
View Source
const (
	CHALLENGE_ATTEMPT_TIMEOUT    = time.Minute
	HOSTER_API_REQUEST_TIMEOUT   = 5 * time.Second
	MAX_HOSTER_API_RESPONSE_SIZE = 20_000
	TOKEN_ACK_WAIT_TIMEOUT       = 2 * time.Second
)
View Source
const (
	ANON_ACCOUNT_TOKEN_ID_LENGTH = 32
)

Variables

View Source
var (
	ErrUnsupportedProofHoster = errors.New("unsupported proof hoster")

	PROOF_HOSTER_NAMES = map[ProofHoster]string{
		Github: "Github",
		Gitlab: "Gitlab",
	}
	PROOF_REPOSITORY_NAME_TEMPLATES = map[ProofHoster]*template.Template{
		Github: parseTemplate("github-repo-name", PROOF_REPOSITORY_BASE_NAME+"-{{.ChallValue}}"),
		Gitlab: parseTemplate("gitlab-repo-name", PROOF_REPOSITORY_BASE_NAME+"-{{.ChallValue}}"),
	}
	PROOF_HOSTER_CHALLENGE_EXPLANATION_TEMPLATES = map[ProofHoster]*template.Template{
		Github: parseTemplate("github-challenge",
			"Go to https://github.com/new?name={{.RepoName}} and click on Create Repository (public). One donce, input your GitHub username (not your display name !)."),
		Gitlab: parseTemplate("gitlab-challenge",
			"Go to https://gitlab.com/projects/new#blank_project and create a public repository named `{{.RepoName}}` "+
				"with a description value of {{.ChallValue}}. Make sure to select your username for the `Project URL` parameter. Once done, input your GitLab username (not your display name !)."),
	}
	PROOF_LOCATION_TEMPLATES = map[ProofHoster]*template.Template{
		Github: parseTemplate("github-api-endpoint", "https://api.github.com/repos/{{.Username}}/{{.RepoName}}"),
		Gitlab: parseTemplate("gitlab-api-endpoint", "https://gitlab.com/api/v4/projects/{{.Username}}%2F{{.RepoName}}"),
	}
)
View Source
var (
	ErrAccountCreationFailed                       = errors.New("account creation failed")
	ErrAccountCreationFailedInternalError          = fmt.Errorf("%w: internal error", ErrAccountCreationFailed)
	ErrAccountCreationFailedUsernameDoesNotMatch   = fmt.Errorf("%w: username does not match", ErrAccountCreationFailed)
	ErrAccountCreationFailedChallValueDoesNotMatch = fmt.Errorf("%w: challenge value does not match", ErrAccountCreationFailed)
)
View Source
var (
	INFO_HASH_PARAMS = argon2id.Params{
		Memory:      64 * 1024,
		Iterations:  1,
		Parallelism: 1,
		SaltLength:  32,
		KeyLength:   16,
	}
)
View Source
var (
	UnknownAccountToken = errors.New("unknown account token")
)

Functions

func CreateAnonymousAccountInteractively

func CreateAnonymousAccountInteractively(ctx *core.Context, hosterName string, conn *Connection, db *AnonymousAccountDatabase) error

CreateAnonymousAccountInteractively communicates with conn to create an anonymous account interactively.

Types

type AnonAccountCreation

type AnonAccountCreation struct {
	Hoster         ProofHoster
	UserIdOnHoster string
}

type AnonymousAccount

type AnonymousAccount struct {
	ULID string `json:"id"`

	//hex-encoded argon2id hash of concatenated information, the salt and the hashing parameters are stored in the string.
	InformationHash string `json:"informationHash"`

	//a hex-encoded sha256 hash is used because the token is a random string and we want the hashing to be very fast.
	TokenHash TokenHash `json:"tokenHash"`
}

func NewAnonAccount

func NewAnonAccount(input AnonAccountCreation) (account *AnonymousAccount, hexEncodedToken string, _ error)

type AnonymousAccountDatabase

type AnonymousAccountDatabase struct {
	// contains filtered or unexported fields
}

func OpenAnonymousAccountDatabase

func OpenAnonymousAccountDatabase(ctx *core.Context, path core.Path, fls afs.Filesystem) (*AnonymousAccountDatabase, error)

func (*AnonymousAccountDatabase) Close

func (db *AnonymousAccountDatabase) Close(ctx *core.Context) error

func (*AnonymousAccountDatabase) GetAccount

func (db *AnonymousAccountDatabase) GetAccount(ctx *core.Context, cleartextToken string) (*AnonymousAccount, error)

func (*AnonymousAccountDatabase) Persist

func (db *AnonymousAccountDatabase) Persist(ctx *core.Context, account *AnonymousAccount) error

type Connection

type Connection struct {
	PrintFn  func(text string)
	ReadChan chan string
}

type ProofHoster

type ProofHoster int
const (
	Github ProofHoster = iota + 1
	Gitlab
)

func (ProofHoster) String

func (h ProofHoster) String() string

type ProofRepoNameTemplateContext

type ProofRepoNameTemplateContext struct {
	ChallValue string
}

type TokenHash

type TokenHash string

func HashCleartextToken

func HashCleartextToken(token string) (TokenHash, error)

Jump to

Keyboard shortcuts

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