Documentation ¶
Overview ¶
package chain present Invitation Chain and its Block and other methods. Invitation Chain is meant to be used as part of a communication protocol. At this level we don't think where chains are stored either.
Index ¶
- Constants
- Variables
- func CommonInviter(c1, c2 Chain) (level int)
- func EqualBlocks(b1, b2 Block) bool
- func Hops(lhs, rhs Chain) (int, int)
- func NewVerifyBlock(pinCode int) (Block, Block)
- func SameInviter(c1, c2 Chain) bool
- func SameRoot(c1, c2 Chain) bool
- type Block
- type Chain
- func (c Chain) Bytes() []byte
- func (c Chain) Challenge(pinCode int, f func(d []byte) crypto.Signature) bool
- func (c Chain) Clone() Chain
- func (c Chain) Hops(their Chain) (int, int)
- func (c Chain) Invite(invitersKey crypto.Key, inviteesPubKey crypto.PubKey, position int) (nc Chain)
- func (c Chain) IsInviterFor(invitee Chain) bool
- func (c Chain) IsNil() bool
- func (c Chain) LeafPubKey() crypto.PubKey
- func (c Chain) Len() int
- func (c Chain) OneHop(their Chain) bool
- func (c Chain) Verify() bool
- type Pair
Constants ¶
const NotConnected = -1
NotConnected tells that chains aren't connected at all, i.e. we don't have any route to other.
Variables ¶
var Nil = Chain{Blocks: nil}
Functions ¶
func CommonInviter ¶
CommonInviter returns inviter's distance (current level) from chain's root if inviter exists. If not it returns NotConnected
func EqualBlocks ¶
func NewVerifyBlock ¶
NewVerifyBlock returns two randomized Blocks that can be used for verification or challenges, etc. First block is for challenge, i.e. pinCode is unknown aka 0, and second block is for actual signing where pincode is set to Position field. By this we can send pincode by other, safe channel.
func SameInviter ¶
Types ¶
type Block ¶
type Block struct { HashToPrev []byte // check the size later InviteePubKey crypto.PubKey // TODO: check the type later? InvitersSignature crypto.Signature // TODO: check the type Position int }
func NewBlockFromData ¶
func (Block) ExcludeSign ¶
type Chain ¶
type Chain struct {
Blocks []Block // Blocks is exported variable for serialization
}
Chain is the data type for Invitation Chain, it's ID is rootPubKey
func NewChainFromData ¶
func NewRootChain ¶
func (Chain) Challenge ¶
Challenge offers a method and placeholder for challenging other chain holder. Most common cases is that caller of the function implements the closure where it calls other party over the network to sign the challenge which is readily build and randomized.
func (Chain) Hops ¶
Hops returns hops and common inviter's level if that exists. If not both return values are NotConnected.
func (Chain) Invite ¶
func (c Chain) Invite( invitersKey crypto.Key, inviteesPubKey crypto.PubKey, position int, ) (nc Chain)
Invite is called for the inviter's chain. Inviter's key is needed for signing the new link/block which includes inviteesPubKey and position in the chain. A new chain is returned. The chain will be given for the invitee.
func (Chain) IsInviterFor ¶
func (Chain) LeafPubKey ¶
type Pair ¶
type Pair struct {
Chain1, Chain2 Chain
}
Pair is helper struct to handle chain pairs. It offers helper methods to calculate hops between two chains. Pair and Chain are summetric.