client

package
v0.0.0-...-52bbd4c Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2019 License: GPL-3.0 Imports: 31 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGroupKeyFromAddress

func GetGroupKeyFromAddress(address ethcommon.Address, ctx *UserContext) error

GetGroupKeyFromAddress tries to get the group key of a group with the given address

func NewAccount

func NewAccount(username string, storage *fs.Storage) (interfaces.IAccount, error)

NewAccount creates a new empty account without any smart contract data

func NewAccountFromStorage

func NewAccountFromStorage(storage *fs.Storage, backend chequebook.Backend) (interfaces.IAccount, error)

NewAccountFromStorage loads an existing account from disk

func NewGroup

func NewGroup(address ethcommon.Address, groupName string, storage *fs.Storage) interfaces.IGroup

NewGroup creates a new Group with the given parameters

func NewGroupFromMeta

func NewGroupFromMeta(meta *meta.GroupMeta, storage *fs.Storage) interfaces.IGroup

NewGroupFromMeta creates a new Group from an existing GroupMeta file stored on disk

Types

type Account

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

Account is a wrapper object around a smart contract of type Account

func (*Account) Boxer

func (acc *Account) Boxer() tribecrypto.AnonymBoxer

Boxer returns the private key of the account

func (*Account) Contract

func (acc *Account) Contract() *ethacc.Account

Contract returns the smart contract of the account

func (*Account) ContractAddress

func (acc *Account) ContractAddress() ethcommon.Address

ContractAddress returns the address of its smart contract

func (*Account) Name

func (acc *Account) Name() string

Name returns the name attribute of the account contract

func (*Account) Save

func (acc *Account) Save() error

Save saves acc.AccountData on disk

func (*Account) SetContract

func (acc *Account) SetContract(address ethcommon.Address, backend chequebook.Backend) error

SetContract stores the smart contract address of an account and its smart contract object

type AccountData

type AccountData struct {
	Name            string
	ContractAddress ethcommon.Address
	Boxer           tribecrypto.AnonymBoxer // might be deleted if libp2p is encrypted
}

AccountData represents those data of an account object that can be saved on disk

type Auth

type Auth struct {
	Address ethcommon.Address
	TxOpts  *bind.TransactOpts
	// contains filtered or unexported fields
}

Auth stores all the information of an Ethereum account with which one can sign transactions

func NewAuth

func NewAuth(mnemonic string) (*Auth, error)

NewAuth creates an Auth object from a mnemonic

func (*Auth) Sign

func (auth *Auth) Sign(hash []byte) ([]byte, error)

Sign signs a hash with its Ethereum account's private key

type Eth

type Eth struct {
	Auth    *Auth
	App     *ethapp.FileTribeDApp
	Backend chequebook.Backend
}

Eth is a collection of those objects that are necessary for performing operations on the blockchain such as authentication data, DApp contract and a full ethereum node

type FileView

type FileView struct {
	Name        string
	WriteAccess []MemberView
}

FileView is a view of a file objects. These objects are sent back to main.go when it lists the group repository

type Group

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

Group is the mirror object of a Group smart contract

func (*Group) AddMember

func (g *Group) AddMember(account ethcommon.Address)

AddMember adds an account to the member list

func (*Group) Address

func (g *Group) Address() ethcommon.Address

Address returns the group's smart contract address

func (*Group) Boxer

func (g *Group) Boxer() tribecrypto.SymmetricKey

Boxer returns the group key

func (*Group) CountMembers

func (g *Group) CountMembers() int

CountMembers returns the number of members

func (*Group) Encode

func (g *Group) Encode() ([]byte, error)

Encode encodes the Group

func (*Group) EncryptedIpfsHash

func (g *Group) EncryptedIpfsHash() []byte

EncryptedIpfsHash returns the group's current encrypted IPFS hash

func (*Group) IpfsHash

func (g *Group) IpfsHash() string

IpfsHash returns the group's current IPFS hash

func (*Group) IsMember

func (g *Group) IsMember(account ethcommon.Address) bool

IsMember checks if an account is a group member or not

func (*Group) Members

func (g *Group) Members() []ethcommon.Address

Members returns the list of members

func (*Group) Name

func (g *Group) Name() string

Name returns the group name

func (*Group) RemoveMember

func (g *Group) RemoveMember(account ethcommon.Address)

RemoveMember removes an account from the member list

func (*Group) Save

func (g *Group) Save() error

Save saves the Group to disk

func (*Group) SetBoxer

func (g *Group) SetBoxer(boxer tribecrypto.SymmetricKey)

SetBoxer is a setter for the group key

func (*Group) SetIpfsHash

func (g *Group) SetIpfsHash(encIpfsHash []byte) error

SetIpfsHash decrypts an encrypted IPFS hash and stores both the decrypted one and the encrypted one. Note that it is not enough to only receive ipfsHash and encrypt it and use that as encryptedIpfsHash because the encryption uses a random element when producing the cipher text, therefore on each instance of the ipfs-share daemon, the ecnryptedIpfsHash's will be different

func (*Group) Update

func (g *Group) Update(name string, members []ethcommon.Address, encIpfsHash []byte) error

Update updates the Group data with the provided parameters

type GroupContext

type GroupContext struct {
	Group           interfaces.IGroup
	P2P             *com.P2PManager
	Repo            *fs.GroupRepo
	GroupConnection *com.GroupConnection
	AddressBook     *common.AddressBook

	Ipfs         ipfsapi.IIpfs
	Storage      *fs.Storage
	Transactions *List
	// contains filtered or unexported fields
}

GroupContext represents a groups current state and is responsible for all the communication, storage, encryption work

func NewGroupContext

func NewGroupContext(config *GroupContextConfig) (*GroupContext, error)

NewGroupContext creates a GroupContext with data described in the provided configuration object

func (*GroupContext) Address

func (groupCtx *GroupContext) Address() ethcommon.Address

Address returns the smart contract address of the group

func (*GroupContext) CommitChanges

func (groupCtx *GroupContext) CommitChanges() error

CommitChanges collects all changes in the group's root directory, creates a path from it and commits the changes on the blockchain

func (*GroupContext) GrantWriteAccess

func (groupCtx *GroupContext) GrantWriteAccess(filePath string, user ethcommon.Address) error

GrantWriteAccess adds the defined user to the write ACL in the file meta

func (*GroupContext) HandleGroupInvitationAcceptedEvents

func (groupCtx *GroupContext) HandleGroupInvitationAcceptedEvents(group *ethgroup.Group)

HandleGroupInvitationAcceptedEvents listens to GroupInvitationAccepted events on the blockchain and adds the new member to the group, if it receives one

func (*GroupContext) HandleGroupInvitationSentEvents

func (groupCtx *GroupContext) HandleGroupInvitationSentEvents(group *ethgroup.Group)

HandleGroupInvitationSentEvents listens to GroupInvitationSent events on the blockchain

func (*GroupContext) HandleIpfsHashChangedEvents

func (groupCtx *GroupContext) HandleIpfsHashChangedEvents(group *ethgroup.Group)

HandleIpfsHashChangedEvents listens to IpfsHashChanged events on the blockchain and if it receives one, it updates the group IPFS hash and fetches its contents

func (*GroupContext) HandleNewConsensusEvents

func (groupCtx *GroupContext) HandleNewConsensusEvents(group *ethgroup.Group)

HandleNewConsensusEvents listens to NewConsensus events on the blockchain and checks if the target of the consensus is correct. If so it approves it

func (*GroupContext) Invite

func (groupCtx *GroupContext) Invite(newMember ethcommon.Address, hasInviteRight bool) error

Invite invokes the 'Invite' method of the group on the blockchain

func (*GroupContext) Leave

func (groupCtx *GroupContext) Leave() error

Leave invokes the 'Leave' operation of the group on the blockchain

func (*GroupContext) ListFiles

func (groupCtx *GroupContext) ListFiles() []FileView

ListFiles returns a list of type string with the group files

func (*GroupContext) ListMembers

func (groupCtx *GroupContext) ListMembers() []MemberView

ListMembers returns a list of the members addresses

func (*GroupContext) Name

func (groupCtx *GroupContext) Name() string

Name returns the group name

func (*GroupContext) RevokeWriteAccess

func (groupCtx *GroupContext) RevokeWriteAccess(filePath string, user ethcommon.Address) error

RevokeWriteAccess removes the defined user from the write ACL in the file meta

func (*GroupContext) Save

func (groupCtx *GroupContext) Save() error

Save stores group data on disk

func (*GroupContext) Stop

func (groupCtx *GroupContext) Stop()

Stop kills all IPFS pubsub group connection - NOT USED

func (*GroupContext) Update

func (groupCtx *GroupContext) Update() error

Update fetches all the current group information from the blockchain and refreshes the GroupContext with its contents

type GroupContextConfig

type GroupContextConfig struct {
	Group        interfaces.IGroup
	Account      interfaces.IAccount
	P2P          *com.P2PManager
	AddressBook  *common.AddressBook
	Eth          *GroupEth
	Ipfs         ipfsapi.IIpfs
	Storage      *fs.Storage
	Transactions *List
}

GroupContextConfig is a configuration struct for creating GroupContext

type GroupEth

type GroupEth struct {
	*Eth
	Group *ethgroup.Group
}

GroupEth stores a GroupContract and a pointer to all the general Eth data

type IGroupFacade

type IGroupFacade interface {
	Address() ethcommon.Address
	Name() string
	GrantWriteAccess(filePath string, user ethcommon.Address) error
	RevokeWriteAccess(filePath string, user ethcommon.Address) error
	CommitChanges() error
	Invite(user ethcommon.Address, hasInviteRigth bool) error
	Leave() error
	ListFiles() []FileView
	ListMembers() []MemberView
}

IGroupFacade is an interface to main.go through which it can communicate with a GroupContext

type IUserFacade

type IUserFacade interface {
	SignUp(username string) error
	CreateGroup(groupname string) error
	AcceptInvitation(groupAddress ethcommon.Address) error
	User() interfaces.IAccount
	Groups() []IGroupFacade
	SignOut()
	Transactions() ([]*types.Transaction, error)
}

IUserFacade is an interface through which main.go can communicate with its UserContext

type MemberView

type MemberView struct {
	Name    string
	Address string
}

MemberView is a view of a group member. These objects are sent back to main.go when it lists group members

type UserContext

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

UserContext stores all the user data and it is responsible for handling communication, events, encryption, etc.

func NewUserContext

func NewUserContext(auth *Auth, backend chequebook.Backend, appContractAddress ethcommon.Address, ipfs ipfsapi.IIpfs, p2pPort string) (*UserContext, error)

NewUserContext creates a new UserContext with the data provided

func (*UserContext) AcceptInvitation

func (ctx *UserContext) AcceptInvitation(groupAddress ethcommon.Address) error

AcceptInvitation accepts a group invitation

func (*UserContext) BuildGroups

func (ctx *UserContext) BuildGroups() error

BuildGroups builds up all groups found on disk

func (*UserContext) CreateGroup

func (ctx *UserContext) CreateGroup(groupname string) error

CreateGroup creates a group through a blockchain method invoke

func (*UserContext) GetBoxerOfGroup

func (ctx *UserContext) GetBoxerOfGroup(group ethcommon.Address) (tribecrypto.SymmetricKey, error)

GetBoxerOfGroup returns the secret key of the given group. It is used by communication sessions that have no direct access to GroupContexts

func (*UserContext) GetProposedBoxerOfGroup

func (ctx *UserContext) GetProposedBoxerOfGroup(group ethcommon.Address, proposer ethcommon.Address) (tribecrypto.SymmetricKey, error)

GetProposedBoxerOfGroup returns the secret key of the given group. It is used by communication sessions that have no direct access to GroupContexts

func (*UserContext) Groups

func (ctx *UserContext) Groups() []IGroupFacade

Groups returns a list of group facades

func (*UserContext) HandleAccountCreatedEvents

func (ctx *UserContext) HandleAccountCreatedEvents(app *ethapp.FileTribeDApp)

HandleAccountCreatedEvents listens to 'AccountCreated' blockchain events and if one belongs to the current user, creates its appropriate UserContext

func (*UserContext) HandleGroupCreatedEvents

func (ctx *UserContext) HandleGroupCreatedEvents(acc *ethacc.Account)

HandleGroupCreatedEvents listens to GroupCreated blockchain events and upon receiving one, it creates the group's appropriate GroupContext

func (*UserContext) HandleGroupInvitationEvents

func (ctx *UserContext) HandleGroupInvitationEvents(acc *ethacc.Account)

HandleGroupInvitationEvents listens to GroupCreated blockchain events and upon receiving one, it stores the invitation

func (*UserContext) HandleInvitationAcceptedEvents

func (ctx *UserContext) HandleInvitationAcceptedEvents(acc *ethacc.Account)

HandleInvitationAcceptedEvents listens to InvitationAccapted blockchain events and upon receiving one, it tries to get the group key and upon its success it creates the group's appropriate GroupContext

func (*UserContext) Init

func (ctx *UserContext) Init(acc interfaces.IAccount) error

Init initializes a UserContext: it starts the P2P manager and the event handlers

func (*UserContext) IsMember

func (ctx *UserContext) IsMember(group ethcommon.Address, account ethcommon.Address) error

IsMember returns whether a given user is a member of a given group or not. It is used by communication sessions that have no direct access to GroupContexts.

func (*UserContext) ListFiles

func (ctx *UserContext) ListFiles() map[string][]string

ListFiles lists the files names in the account's repository

func (*UserContext) Save

func (ctx *UserContext) Save() error

Save saves all UserContext data

func (*UserContext) SignOut

func (ctx *UserContext) SignOut()

SignOut tries to gracefully stop all started threads and processes

func (*UserContext) SignUp

func (ctx *UserContext) SignUp(username string) error

SignUp creates a new Account, saves it and registers it on the blockchain

func (*UserContext) Transactions

func (ctx *UserContext) Transactions() ([]*types.Transaction, error)

Transactions returns a list of transactions initiated by the user

func (*UserContext) User

func (ctx *UserContext) User() interfaces.IAccount

User returns the Account interface

Directories

Path Synopsis
fs

Jump to

Keyboard shortcuts

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