core

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2019 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeText = iota
	TypeDOB
)
View Source
const (
	UserStatusNormal = iota
)

Variables

View Source
var (
	ErrMsgFromInvalidUser = errors.New("msg from invalid user")
	ErrMsgAlreadyExist    = errors.New("msg already exist")
	ErrMsgNotFound        = errors.New("msg not found")
	ErrTPAlreadyExist     = errors.New("time proof already exist")
)
View Source
var (
	ErrUserAlreadyExist = errors.New("user already exist")
)

Functions

func VerifyMsg

func VerifyMsg(msg Message) (bool, error)

Types

type Auth

type Auth struct {
	crypto.PublicKey
}

func (Auth) MarshalJSON

func (a Auth) MarshalJSON() ([]byte, error)

func (*Auth) UnmarshalJSON

func (a *Auth) UnmarshalJSON(input []byte) error

type DOBMsgContent

type DOBMsgContent struct {
	User    User
	Parents [2]ParentSig
}

func CreateDOBMsgContent

func CreateDOBMsgContent(name string, extra string, auth *Auth) (*DOBMsgContent, error)

func (*DOBMsgContent) SignByParent

func (mv *DOBMsgContent) SignByParent(user *User, privKey crypto.PrivateKey) error

type Group

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

func NewUserDag

func NewUserDag(Eve, Adam *User) (*Group, error)

func (*Group) Add

func (ud *Group) Add(user *User) error

func (*Group) GetUserByID

func (ud *Group) GetUserByID(uid common.Hash) *User

type Message

type Message struct {
	SenderID  common.Hash       `json:"senderID"`
	Reference []*MsgReference   `json:"reference"`
	Value     *MsgValue         `json:"value"`
	Signature *crypto.Signature `json:"signature"`
}

func CreateMsg

func CreateMsg(user *User, value *MsgValue, privKey *crypto.PrivateKey, refs ...*MsgReference) (*Message, error)

func (Message) ChildrenID

func (msg Message) ChildrenID() []common.Hash

always return nil for msg

func (Message) ID

func (msg Message) ID() common.Hash

func (Message) ParentsID

func (msg Message) ParentsID() []common.Hash

ParentsID return the parents id Parents are the message referenced by this Message

type MsgReference

type MsgReference struct {
	SenderID common.Hash `json:"senderID"`
	MsgID    common.Hash `json:"msgID"`
}

type MsgValue

type MsgValue struct {
	ContentType int
	Content     []byte
}

type ParentSig

type ParentSig struct {
	PID common.Hash
	Sig []byte
}

type TimeProof

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

TimeProof value of vertex contain in dag is sequence number

type Universe

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

Universe Vertex of utD is time proof, ID of Vertex is the ID of user which msg set as the time proof, Reference of Vertex is source which this time proof split from Vertex of ugD is group, ID of Vertex is the ID of time proof which this group valid, Reference of Vertex is same with time proof reference

func NewUniverse

func NewUniverse(group *Group, msg *Message) (*Universe, error)

NewUniverse create Universe the msg will also be used to create time proof as msg.SenderID

func (*Universe) Add

func (md *Universe) Add(msg *Message) error

Add will check if the msg from valid user, add new msg into Universe, and update time proof if msg.SenderID is belong to time proof

func (*Universe) AddUniverse

func (md *Universe) AddUniverse(msg *Message) error

AddTimeProof will get all messages save in Universe with same msg.SenderID and build the time proof by those messages

func (*Universe) CheckUserValid

func (md *Universe) CheckUserValid(userID common.Hash) bool

CheckUserValid check if the user valid in this Universe the msg.SenderID must valid in at least one tpDAG

func (*Universe) GetMaxSeq

func (md *Universe) GetMaxSeq(userID common.Hash) uint64

GetMaxSeq will return the max time proof sequence for time proof by the userID

func (*Universe) GetMsgByID

func (md *Universe) GetMsgByID(mid interface{}) *Message

GetMsgByID will return the msg by msg.ID() nil will be return if msg not exist

func (*Universe) GetUserDAG

func (md *Universe) GetUserDAG() *Group

GetUserDAG return userDAG by time proof userID

type UniverseGroup

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

UniverseGroup value of vertex contain in dag is user status

type User

type User struct {
	Name     string   `json:"name"`
	DOBExtra string   `json:"extra"`
	Auth     *Auth    `json:"auth"`
	DOBMsg   *Message `json:"dobMsg"`
}

func CreateNewUser

func CreateNewUser(msg *Message) (*User, error)

CreateNewUser create new user by cosign message The msg must be signed by user in local user dag. Both parents must be in the local use dag. Both parents fit the nature rules. The BOD struct signed by both parents.

func CreateRootUsers

func CreateRootUsers(key crypto.PublicKey) ([2]*User, error)

CreateRootUser try to create two root users by public key One Male user and one female user,

func (User) Gender

func (u User) Gender() bool

Gender return the gender of user, true = male = end of ID is odd

func (User) ID

func (u User) ID() common.Hash

ID return the vertex.id, related to parents and value of the vertex ID cloud use as address of user account

func (*User) MarshalJSON

func (u *User) MarshalJSON() ([]byte, error)

func (User) ParentsID

func (u User) ParentsID() [2]common.Hash

ParentsID return the ID of user parents, res[0] should be the female parent (id end by even) res[1] should be the male parent (id end by odd)

func (*User) UnmarshalJSON

func (u *User) UnmarshalJSON(input []byte) error

func (User) Value

func (u User) Value() interface{}

Value return the vertex.value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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