model

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const EXPIRED_IN = time.Hour * 24 * 3

EXPIRED_IN is the time after which a proof is considered expired and should perform revalidate.

Variables

View Source
var (
	DB *gorm.DB
	// Since this service is mostly run as a lambda, we don't need
	// to init an array here.  When lambda scaled to a very large
	// number, servers in `read_only_hosts` will be used evenly.
	ReadOnlyDB *gorm.DB
)

Functions

func Init

func Init()

Init initializes DB connection instance and do migration at startup.

func MarshalPersona

func MarshalPersona(persona any) string

MarshalPersona accepts *ecdsa.Pubkey | string type of pubkey, returns a string to be stored into DB.

func MarshalSignature

func MarshalSignature(signature []byte) string

MarshalSignature converts []byte signature into string.

Types

type Proof

type Proof struct {
	ID            int64 `gorm:"primarykey"`
	CreatedAt     time.Time
	LastCheckedAt time.Time
	IsValid       bool
	InvalidReason string

	ProofChainID int64 `gorm:"index"`
	ProofChain   ProofChain
	// Persona is public key of user persona (string, /0x[0-9a-f]{130}/)
	Persona  string         `gorm:"index;not null"`
	Platform types.Platform `gorm:"index;not null"`
	Identity string         `gorm:"index;not null"`
	AltID    string         `gorm:"column:alt_id;index"`
	Location string         `gorm:"not null"`
}

Proof is final proof state of a user (persona).

func FindAllProofByPersona

func FindAllProofByPersona(persona any, orderBy string) (proofs []Proof, err error)

func (*Proof) IsOutdated

func (proof *Proof) IsOutdated() bool

IsOutdated returns true if proof is outdated and should do a revalidate.

func (*Proof) Revalidate

func (proof *Proof) Revalidate() (err error)

Revalidate validates current proof, will update `IsValid` and `LastCheckedAt`. Must be used after `DB.Preload("ProofChain")`.

func (Proof) TableName

func (Proof) TableName() string

type ProofChain

type ProofChain struct {
	ID               int64          `gorm:"primarykey"`
	CreatedAt        time.Time      `gorm:"column:created_at"`
	Action           types.Action   `gorm:"index;not null"`
	Persona          string         `gorm:"index;not null"`
	Identity         string         `gorm:"index;not null"`
	AltID            string         `gorm:"column:alt_id;index"`
	Platform         types.Platform `gorm:"index;not null"`
	Location         string         `gorm:"not null"`
	Signature        string         `gorm:"not null"`
	SignaturePayload string         `gorm:"column:signature_payload"`
	Extra            datatypes.JSON `gorm:"default:'{}'"`
	Uuid             string         `gorm:"index;column:uuid"`
	ArweaveID        string         `gorm:"column:arweave_id;not null;default:''"`
	PreviousID       sql.NullInt64  `gorm:"index"`
	Previous         *ProofChain
}

ProofChain is a chain of a persona's proof modification log.

func ProofChainCreateFromValidator

func ProofChainCreateFromValidator(validator *validator.Base) (pc *ProofChain, err error)

func ProofChainFindBySignature

func ProofChainFindBySignature(signature string) (pc *ProofChain, err error)

func ProofChainFindLatest

func ProofChainFindLatest(persona string) (pc *ProofChain, err error)

func (*ProofChain) Apply

func (pc *ProofChain) Apply() (err error)

Apply applies current ProofChain modification to Proof model.

func (*ProofChain) Pubkey

func (pc *ProofChain) Pubkey() *ecdsa.PublicKey

func (*ProofChain) RestoreValidator

func (pc *ProofChain) RestoreValidator() (v *validator.Base, err error)

RestoreValidator rebuilds `validator.Base` from current `ProofChain` record.

func (*ProofChain) SignatureBytes

func (pc *ProofChain) SignatureBytes() (sig []byte)

func (ProofChain) TableName

func (ProofChain) TableName() string

func (*ProofChain) ToProofChainItem

func (pc *ProofChain) ToProofChainItem() ProofChainItem

type ProofChainArweaveDocument

type ProofChainArweaveDocument struct {
	Avatar            string         `json:"avatar"`
	Action            types.Action   `json:"action"`
	Platform          types.Platform `json:"platform"`
	Identity          string         `json:"identity"`
	AltID             string         `json:"alt_id"`
	ProofLocation     string         `json:"proof_location"`
	CreatedAt         string         `json:"created_at"`
	Signature         string         `json:"signature"`
	SignaturePayload  string         `json:"signature_payload"`
	Uuid              string         `json:"uuid"`
	Extra             datatypes.JSON `json:"extra"`
	PreviousUuid      string         `json:"previous_uuid"`
	PreviousArweaveID string         `json:"previous_arweave_id"`
}

Arweave data ID

type ProofChainItem

type ProofChainItem struct {
	Action           types.Action   `json:"action"`
	Platform         types.Platform `json:"platform"`
	Identity         string         `json:"identity"`
	AltID            string         `json:"alt_id"`
	ProofLocation    string         `json:"proof_location"`
	CreatedAt        string         `json:"created_at"`
	Signature        string         `json:"signature"`
	SignaturePayload string         `json:"signature_payload"`
	Uuid             string         `json:"uuid"`
	Extra            datatypes.JSON `json:"extra"`
	ArweaveID        string         `json:"arweave_id"`
}

Output version of the proof chain

func ProofChainFindByPersona

func ProofChainFindByPersona(persona string, all_data bool, from int, limit int) (total int64, rs []ProofChainItem, err error)

Jump to

Keyboard shortcuts

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