chain

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 6 Imported by: 0

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

View Source
const NotConnected = -1

NotConnected tells that chains aren't connected at all, i.e. we don't have any route to other.

Variables

View Source
var Nil = Chain{Blocks: nil}

Functions

func CommonInviter

func CommonInviter(c1, c2 Chain) (level int)

CommonInviter returns inviter's distance (current level) from chain's root if inviter exists. If not it returns NotConnected

func EqualBlocks

func EqualBlocks(b1, b2 Block) bool

func Hops

func Hops(lhs, rhs Chain) (int, int)

func NewVerifyBlock

func NewVerifyBlock(pinCode int) (Block, Block)

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

func SameInviter(c1, c2 Chain) bool

func SameRoot

func SameRoot(c1, c2 Chain) bool

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 NewBlockFromData(d []byte) (b Block)

func (Block) Bytes

func (b Block) Bytes() []byte

func (Block) ExcludeSign

func (b Block) ExcludeSign() Block

func (Block) VerifySign

func (b Block) VerifySign(invitersPubKey crypto.PubKey) bool

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 NewChainFromData(d []byte) (c Chain)

func NewRootChain

func NewRootChain(rootPubKey crypto.PubKey) Chain

func (Chain) Bytes

func (c Chain) Bytes() []byte

func (Chain) Challenge

func (c Chain) Challenge(pinCode int, f func(d []byte) crypto.Signature) bool

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) Clone

func (c Chain) Clone() Chain

func (Chain) Hops

func (c Chain) Hops(their Chain) (int, int)

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 (c Chain) IsInviterFor(invitee Chain) bool

func (Chain) IsNil

func (c Chain) IsNil() bool

func (Chain) LeafPubKey

func (c Chain) LeafPubKey() crypto.PubKey

func (Chain) Len

func (c Chain) Len() int

func (Chain) OneHop

func (c Chain) OneHop(their Chain) bool

func (Chain) Verify

func (c Chain) Verify() bool

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.

func (Pair) CommonInviter

func (p Pair) CommonInviter() int

func (Pair) Hops

func (p Pair) Hops() (int, int)

func (Pair) OneHop

func (p Pair) OneHop() bool

Jump to

Keyboard shortcuts

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