model

package
v0.0.0-...-b732009 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCredentialHash

func GenerateCredentialHash(cred *Credential) []byte

GenerateCredentialHash creates a hash of the credential data for integrity

func RevokeCredential

func RevokeCredential(s *Student, cred Credential) error

RevokeCredential revokes a credential of the student

func ValidateCredentialData

func ValidateCredentialData(cred *Credential) error

ValidateCredentialData ensures the credential fields are valid.

Types

type Admin

type Admin struct {
	AdminID string `json:"admin_id"`
	Name    string `json:"name"`
}

func (*Admin) AddCredentialAdmin

func (a *Admin) AddCredentialAdmin(s *Student, credentialType CredentialType, issuer string, dateIssued time.Time) bool

AddCredentialAdmin adds a new academic credential to the student's list of academic credentials

func (*Admin) AddNewStudent

func (a *Admin) AddNewStudent(id int, firstName, lastName string, birthDate time.Time, studentNum int, chain *StudentChain) (*Student, error)

type Block

type Block struct {
	Index     int
	Timestamp string
	Data      []byte
	Hash      []byte
	PrevHash  []byte
}

Block represents a block in the blockchain.

func CreateBlock

func CreateBlock(index int, blockData []byte, prevHash []byte) *Block

CreateBlock creates a new block with the given data and previous hash.

func Genesis

func Genesis() *Block

Genesis creates the first block in the blockchain.

func (*Block) DeriveHash

func (b *Block) DeriveHash()

DeriveHash generates a hash for the block using its index, timestamp, data, and previous hash.

func (*Block) Serialize

func (b *Block) Serialize() ([]byte, error)

Serialize serializes the block into a JSON byte slice.

func (*Block) SetPrevHash

func (b *Block) SetPrevHash(prevHash []byte)

SetPrevHash sets the previous hash for the block.

type BlockChain

type BlockChain struct {
	Blocks []Block
}

BlockChain structure contains a slice of blocks.

func NewBlockChain

func NewBlockChain() *BlockChain

NewBlockChain creates a blockchain with the genesis block.

func (*BlockChain) AddBlock

func (chain *BlockChain) AddBlock(blockData []byte)

AddBlock adds a new block to the blockchain.

func (*BlockChain) FindCredentialByID

func (chain *BlockChain) FindCredentialByID(id string) (*Credential, error)

FindCredentialByID searches the blockchain for a credential with the given ID.

type Credential

type Credential struct {
	ID         string         `json:"id"`
	Type       CredentialType `json:"type"`
	Issuer     string         `json:"issuer"`
	DateIssued time.Time      `json:"date_issued"`
	Hash       []byte         `json:"hash"`
	Status     string         `json:"status"`
}

Credential represents an individual credential.

func (*Credential) Serialize

func (cred *Credential) Serialize() []byte

Serialize converts the Credential to a custom byte array format

type CredentialChain

type CredentialChain struct {
	BlockChain
}

CredentialChain is an alias for BlockChain, which stores credentials.

func (*CredentialChain) AddCredential

func (chain *CredentialChain) AddCredential(cred *Credential) error

AddCredential adds a new credential to the blockchain.

func (*CredentialChain) VerifyCredential

func (chain *CredentialChain) VerifyCredential(id string) (bool, error)

VerifyCredential checks if a credential exists in the blockchain.

type CredentialType

type CredentialType int

CredentialType enumeration

const (
	Academic CredentialType = iota
	NonAcademic
	Certificate
	Diploma
)

func (CredentialType) String

func (ct CredentialType) String() string

type Student

type Student struct {
	ID          int           `json:"user_id"`
	LastName    string        `json:"last_name"`
	FirstName   string        `json:"first_name"`
	BirthDate   time.Time     `json:"birth_date"`
	StudentID   int           `json:"student_id"`
	Credentials []*Credential `json:"credentials,omitempty"`
}

func (*Student) AddCredential

func (s *Student) AddCredential(credentialType CredentialType, issuer string, dataIssued time.Time) bool

AddCredential adds a new credential to the student's list of non-academic credentials

type StudentChain

type StudentChain struct {
	Students map[int]*Student
}

func (*StudentChain) FindStudentByID

func (chain *StudentChain) FindStudentByID(id int) (*Student, error)

FindStudentByID should find and return a student by ID (this needs to be implemented)

func (*StudentChain) UpdateStudentCredentials

func (chain *StudentChain) UpdateStudentCredentials(id int, newCredential Credential) bool

UpdateStudentCredentials updates the credentials of the student

Jump to

Keyboard shortcuts

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