core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

README

core

GoDoc GoReport Travis License Chat Mentioned in Awesome Go

Package core provides ...

Overview

This package ...

Documentation

Index

Constants

View Source
const (
	// LeakedPrivateKey is the evidence can prove a private key has been leaked.
	// Usually contain 1 anonymous msg(TypeText), the content is private key
	// and 1 msg sign by this private key.
	LeakedPrivateKey = iota

	// ExcessiveBirth is the evidence can prove a user build msg try to create next
	// new user against the nature rule.
	ExcessiveBirth
)
View Source
const (
	// TypeText is the content without any functions, not just text
	TypeText = iota
	// TypeBirth is the type which contain the cosign to create new user in pdu
	TypeBirth
	// TypeEvidence is the type which contain the illegal evidence of user
	TypeEvidence
)
View Source
const (
	// DefaultDimensionNum is the default number of demension for calculating distance
	DefaultDimensionNum = 4
	// DefaultPerimeter is the default perimeter of universe for calculating distance
	DefaultPerimeter = 1e+10
	// MaxDimensionNum is the max number of demension
	MaxDimensionNum = 11
)
View Source
const (
	// UserStatusNormal is the status of user, will be add more later, like punished...
	UserStatusNormal = iota
)

Variables

View Source
var (
	// ErrUserNotExist returns fail to find a user
	ErrUserNotExist = errors.New("user not exist")

	// ErrMsgAlreadyExist returns try to add a message which already exist in universe
	ErrMsgAlreadyExist = errors.New("msg already exist")

	// ErrMsgNotFound returns fail to find a message
	ErrMsgNotFound = errors.New("msg not found")

	// ErrTPAlreadyExist returns time proof message already exist
	ErrTPAlreadyExist = errors.New("time proof already exist")

	// ErrUserAlreadyExist returns try a add a user who is already exist in unverse
	ErrUserAlreadyExist = errors.New("user already exist")

	// ErrNotSupportYet returns not support temp
	ErrNotSupportYet = errors.New("not error, just not support yet")

	// ErrNewUserAddFail returns add new user fail for unknown reason
	ErrNewUserAddFail = errors.New("new user add fail")

	// ErrCreateSpaceTimeFail returns when create space time fail
	ErrCreateSpaceTimeFail = errors.New("create space time fail")

	// ErrAddUserToSpaceTimeFail returns when add user to space time fail
	ErrAddUserToSpaceTimeFail = errors.New("add user to space time fail")

	// ErrCreateRootUserFail returns when create root user fail
	ErrCreateRootUserFail = errors.New("create root user fail")

	// ErrContentTypeNotBirth returns when try to add user from a not birth message
	ErrContentTypeNotBirth = errors.New("content type is not TypeBirth")

	// ErrDimensionNumberNotSuitable returns if the dimension is zero or too large
	ErrDimensionNumberNotSuitable = errors.New("number of dimension is not suitable")

	// ErrPerimeterIsZero returns if perimeter is zero
	ErrPerimeterIsZero = errors.New("perimeter should not be zero")
)

Functions

func VerifyMsg

func VerifyMsg(msg Message) (bool, error)

VerifyMsg is used to valid the msg and the user

Types

type Auth

type Auth struct {
	crypto.PublicKey
}

Auth contain public key

func (Auth) MarshalJSON

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

MarshalJSON marshal public key to json

func (*Auth) UnmarshalJSON

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

UnmarshalJSON is used to unmarshal json

type ContentBirth added in v0.1.0

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

ContentBirth is the birth msg content, which can create new user

func CreateContentBirth added in v0.1.0

func CreateContentBirth(name string, extra string, auth *Auth) (*ContentBirth, error)

CreateContentBirth create the birth msg content , which usually from the new user, not sign by parents yet

func (*ContentBirth) SignByParent added in v0.1.0

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

SignByParent used to sign the birth msg by both parents

type ContentEvidence added in v0.1.0

type ContentEvidence struct {
	EvidenceType int
	Msgs         []*Message
}

ContentEvidence is the evidence of user illegal behavior, Recevier can punish the user by there own will. SenderID can be nil, for anonymous evidence

func CreateContentEvidence added in v0.1.0

func CreateContentEvidence(evidenceType int, msgs []*Message) *ContentEvidence

CreateContentEvidence create the evidence msg content contain proof of user illeagal behavior

func CreateEBCE added in v0.1.0

func CreateEBCE(msgs ...*Message) (*ContentEvidence, error)

CreateEBCE creaste the evidence of ExcessiveBirth

func CreateLPCE added in v0.1.0

func CreateLPCE(privKey crypto.PrivateKey, msg *Message) (*ContentEvidence, error)

CreateLPCE create the evidence of leaked privatekey

type Message

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

Message is valid msg in pdu

func CreateMsg

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

CreateMsg used to create a new msg by user in universe

func (Message) ChildrenID

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

ChildrenID always return nil for msg (useless in pdu)

func (Message) ID

func (msg Message) ID() common.Hash

ID is the id of msg based on content and author info

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"`
}

MsgReference is the msg before current msg

type MsgValue

type MsgValue struct {
	ContentType int
	Content     []byte
}

MsgValue is the mas value

type ParentSig

type ParentSig struct {
	UserID    common.Hash
	Signature []byte
}

ParentSig contains the signature from both parents

type SpaceTime added in v0.1.0

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

SpaceTime contain time proof of this space time and the user info who is valid in this space time

func NewSpaceTime added in v0.1.0

func NewSpaceTime(u *Universe, msg *Message, ref *MsgReference) (*SpaceTime, error)

NewSpaceTime create the new space-time

func (*SpaceTime) AddUser added in v0.1.0

func (s *SpaceTime) AddUser(ref *MsgReference, contentBirth ContentBirth, user *User) error

AddUser add user info to this space time

func (SpaceTime) GetUserIDs added in v0.1.0

func (s SpaceTime) GetUserIDs() (userIDs []common.Hash)

GetUserIDs returns users ID of space-time

func (SpaceTime) GetUserInfo added in v0.1.0

func (s SpaceTime) GetUserInfo(userID common.Hash) *UserInfo

GetUserInfo returns userInfo in current space-time by userID

func (*SpaceTime) UpdateTimeProof added in v0.1.0

func (s *SpaceTime) UpdateTimeProof(msg *Message) error

UpdateTimeProof update the tp info

type Universe

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

Universe is the struct contain all the information can be received and validated. It is built with two precreate users as root users. Any message should be validated before add into msgD, which is a DAG used to store message. If new user create from valid message, the user should add into userD, a DAG used to store all users. The universe contain at least one spacetime, each spacetime base on one user msg as time line. validation of message mean this message should be valid at least in one of spacetime in stD. Information in local universe is only part of information in whole decentralized system.

func NewUniverse

func NewUniverse(Eve, Adam *User) (*Universe, error)

NewUniverse create Universe with two user with diff gender as root users

func (*Universe) AddMsg added in v0.1.0

func (u *Universe) AddMsg(msg *Message) error

AddMsg will check if the message from valid user, who is validated in at least one spacetime (in stD). Then new message will be added into Universe and update time proof if msg.SenderID is any spacetime based on.

func (*Universe) AddSpaceTime added in v0.1.0

func (u *Universe) AddSpaceTime(msg *Message, ref *MsgReference) error

AddSpaceTime will add spacetime in Universe with msg.SenderID, and follow the time sequence from ref.

func (Universe) CheckUserExist added in v0.1.0

func (u Universe) CheckUserExist(userID common.Hash) bool

CheckUserExist check if the user valid in the Universe

func (Universe) GetMaxSeq

func (u Universe) GetMaxSeq(spacetimeID common.Hash) uint64

GetMaxSeq return the max time proof sequence

func (Universe) GetMsgByID

func (u Universe) GetMsgByID(msgID interface{}) *Message

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

func (*Universe) GetSpaceTimeIDs added in v0.1.0

func (u *Universe) GetSpaceTimeIDs() []common.Hash

GetSpaceTimeIDs get ids in of spacetime (list of msg.SenderID of each spacetime)

func (Universe) GetUserByID added in v0.1.0

func (u Universe) GetUserByID(userID common.Hash) *User

GetUserByID return the user from userD, not userInfo by space time

func (Universe) GetUserIDs added in v0.1.0

func (u Universe) GetUserIDs(spacetimeID common.Hash) []common.Hash

GetUserIDs return userIDs in this space time

func (Universe) GetUserInfo added in v0.1.0

func (u Universe) GetUserInfo(userID common.Hash, spacetimeID common.Hash) *UserInfo

GetUserInfo return the user info in space time return nil if not find user

type User

type User struct {
	Name       string   `json:"name"`
	BirthExtra string   `json:"extra"`
	Auth       *Auth    `json:"auth"`
	BirthMsg   *Message `json:"birthMsg"`
	LifeTime   uint64   `json:"lifeTime"`
}

User is the author of any msg in pdu

func CreateNewUser

func CreateNewUser(universe *Universe, 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 Birth struct signed by both parents.

func CreateRootUser added in v0.1.0

func CreateRootUser(key crypto.PublicKey, name, extra string) *User

CreateRootUser try to create root user by public key Gender of the root user is depend on key,name and extra

func (User) Distance added in v0.1.0

func (u User) Distance(location common.Hash, dimension int, perimeter *big.Int) (distance *big.Int, err error)

Distance return the distance from user to common.Hash base on setting perimeter and dimension

func (User) Gender

func (u User) Gender() bool

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

func (User) GetCoordinates added in v0.1.0

func (u User) GetCoordinates(location common.Hash, dimension int, perimeter *big.Int) ([]*big.Int, error)

GetCoordinates returns the coordinates of location, use u.ID as origin point

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)

MarshalJSON marshal user to json

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) StandardDistance added in v0.1.0

func (u User) StandardDistance(location common.Hash) (distance *big.Int, err error)

StandardDistance return the distance from user to common.Hash base on default setting perimeter and dimension

func (*User) UnmarshalJSON

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

UnmarshalJSON is used to unmarshal json

func (User) Value

func (u User) Value() interface{}

Value return the vertex.value

type UserInfo added in v0.1.0

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

UserInfo contain the information except pass by BirthMsg the state related to nature rule is start by nature the other state start by local

func NewUserInfo added in v0.1.0

func NewUserInfo(name string, life uint64, BirthSeq uint64) *UserInfo

NewUserInfo create new user info for userstate in space time

func (UserInfo) String added in v0.1.0

func (ui UserInfo) String() string

String used to print user info

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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