gameutils

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2019 License: GPL-3.0, LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSig = errors.New("invalid transaction v, r, s values")
)

Functions

func HashToInt

func HashToInt(hash []byte, c elliptic.Curve) *big.Int

HashToInt hash转为一个曲线上的整数

func PublicKeyImpl

func PublicKeyImpl(Sign SignData, hash common.Hash) ([]byte, error)

func PublicKeyVerify

func PublicKeyVerify(pd *PublicKeyData) (result int)

Types

type BetData

type BetData struct {
	Bet     uint64
	BetSeat SeatID
	DeskID  []byte
	ID      SeatID
}

betDat 下注

type BetSignData

type BetSignData struct {
	BetStateHash string
	Sign         string
	DeskID       string
	ID           SeatID
}

type CallCardData

type CallCardData struct {
	Num      uint
	CallSeat SeatID
	DeskID   string
	Signs    string
	ID       SeatID
}

callCardData 收到callCardData更新牌点游标

type Card

type Card = uint32

type ChangeSeatData

type ChangeSeatData struct {
	GameAddress common.Address
	Desk        DeskID

	ID      UserID
	Address common.Address

	OldSeat SeatID
	NewSeat SeatID
}

type CheckOutData

type CheckOutData struct {
	CokData CheckOutKeyData
	CooData CheckOutOriginalData
	Sign    []byte //对CooData 的签名
}

type CheckOutKeyData

type CheckOutKeyData struct {
	Cursor []uint
	K      []*PublicKey
	E      []*big.Int
	Z      []*big.Int
}

CheckOutKeyData 弃牌玩家发出的密钥

type CheckOutOriginalData

type CheckOutOriginalData struct {
	DeskID []byte
	ID     SeatID
	CsData CheckOutSignData
}

type CheckOutSignData

type CheckOutSignData struct {
	ContractAddr common.Address
	TableID      uint64
	Hand         uint32
}

type DealCardData

type DealCardData struct {
	Cursor []uint
	SeatTo SeatID
	Open   bool
	DeskID string
	Signs  string
	ID     SeatID
}

dealCardData 给自己发明牌或者发公共明牌时才发消息

type DealOP

type DealOP struct {
	SeatTo   SeatID
	Currsors []uint
	Open     uint
}

type DealOPBackup

type DealOPBackup struct {
	Currsor uint
	DOps    []DealOP
}

type DeskCommonData

type DeskCommonData struct {
	Points []*PointPair //洗完后的牌点点对
	//不能用map,map无法用rlp编码,
	PointSumMapCard []EcPoint //同OriginalPoint,只是没转换成点对,不需要转换成点对
	PublicCards     []Card    //桌子上公共的牌,从消息列表中无法获取的
	BetData         []GameBetData
	BetData2        []byte
	CurTurn         SeatID

	FoldSeats []SeatID //FoldSeats跟FoldMsg相当于map
	FoldMsg   []MsgWrap
}

用于下注共识签名和公证,与其它阶段的区分开,下注前的阶段的只需要一个数据,后面都需要多个

type DeskID

type DeskID = uint32

type EcPoint

type EcPoint struct {
	//X, Y *big.Int
	PointBytes [65]byte //secp256k1.S256().Marshal(point.X, point.Y)
}

func PointVerify

func PointVerify(pd *EcPointData) (result int, ep []*EcPoint)

type EcPointData

type EcPointData struct {
	//Points []*EcPoint
	PHash [][]byte
	PSign [][]byte
	ID    SeatID
}

ecPointData 牌点消息

type FinalShuffSignData

type FinalShuffSignData struct {
	SfPointHash []byte
	Sign        []byte
	DeskID      []byte
	ID          SeatID
}

type GameBetData

type GameBetData struct {
	ID       SeatID
	Balance  uint64
	Turnbet  uint64
	Totalbet uint64
	Fold     bool
	AllIn    bool
}

type Judgment

type Judgment struct {
	//From     common.Address //公证者地址,合约中保存了
	GameOver bool           //是否结束游戏
	DeskID   []byte         //牌点求和哈希值
	TableCtr uint64         //合约中table id
	Result   map[SeatID]int //相关人的奖惩,正数为奖,负数为罚,执行结果由合约通知相关人

	MakeUp map[int]*MsgWrap //补齐的消息,包括消息应该被放的位置

}

type KeyCardData

type KeyCardData struct {
	Cursor []uint
	K      []*PublicKey
	E      []*big.Int
	Z      []*big.Int
	OP     uint
	SeatTo SeatID
	DeskID []byte
	ID     SeatID
}

keyCardData 收到dealCardData 找出对应牌点的密钥,发回去。

type KeyType

type KeyType = ecdsa.PrivateKey

type LeaveData

type LeaveData struct {
	Seat SeatID
}

type LogicData

type LogicData struct {
	SrcSeat SeatID
	Code    MsgCodeType
	Data    []byte
}

type MsgAck

type MsgAck struct {
	Deskid   DeskID
	DestSeat SeatID
	SrcSeat  SeatID

	MsgCode MsgCodeType //消息类型  code = 自定义的消息类型
	SeqNum  uint32
}

type MsgCodeType

type MsgCodeType = uint64
const (
	// Protocol messages belonging to poker1
	StatusMsgCode MsgCodeType = 0x00

	TransferMsgCode MsgCodeType = 0x01

	AckMsgCode MsgCodeType = 0x02

	DiffMsgCode MsgCodeType = 0x03 //提交分歧给公证者

	NotifySubmitMsgCode MsgCodeType = 0x04 //通知另一方提交公证

	//游戏开始前座位与状态消息
	SitDownMsgCode          MsgCodeType = 0x10
	SitDownResultMsgCode    MsgCodeType = 0x11
	OnSitDownMsgCode        MsgCodeType = 0x12
	LeaveMsgCode            MsgCodeType = 0x13
	ChangeSeatMsgCode       MsgCodeType = 0x14
	ChangeSeatResultMsgCode MsgCodeType = 0x15
)

for message wrap

const (
	GameMsgWapDataCode MsgCodeType = 0x20 //游戏层消息包装

	EcPointDataCode MsgCodeType = 0x21 //牌点生成消息

	SumPointSignDataCode MsgCodeType = 0x22 //牌点和签名消息

	PublicKeyDataCode MsgCodeType = 0x23 //生成公钥消息

	SumpublicKeySignDataCode MsgCodeType = 0x24 //公钥和签名消息

	ShuffleDataCode MsgCodeType = 0x25 //洗牌消息

	FinalshuffleSignDataCode MsgCodeType = 0x26 //最终洗牌结果签名消息

	KeyCardDataCode MsgCodeType = 0x27 // 密钥消息

)

for gamengine

type MsgData

type MsgData struct {
	Data []byte
}

func (*MsgData) Decode

func (s *MsgData) Decode(data interface{}) error

type MsgWrap

type MsgWrap struct {
	GameAddress common.Address
	Deskid      DeskID //桌子ID
	Hand        uint64 //局数

	DestSeats []SeatID //期望接收消息的位置
	SrcSeat   SeatID   //发送消息的位置
	Handler   SeatID   //需要处理的位置

	MsgCode MsgCodeType //消息类型  send code = 自定义的消息类型  ack code =2
	SeqNum  uint32      //消息序号

	//Data interface{}
	Data []byte //消息内容

	Sign      SignData //签名
	InterSign SignData //inter签名
}

func (*MsgWrap) Hash

func (msg *MsgWrap) Hash() common.Hash

Hash returns the hash to be sned by the sender. It does not uniquely identify the transaction.

func (*MsgWrap) PublicKey

func (msg *MsgWrap) PublicKey() ([]byte, error)

func (*MsgWrap) Signature

func (msg *MsgWrap) Signature(ks *keystore.KeyStore, address common.Address) error

func (*MsgWrap) SignatureInter

func (msg *MsgWrap) SignatureInter(ks *keystore.KeyStore, address common.Address) error

func (*MsgWrap) VerifySignature

func (msg *MsgWrap) VerifySignature() bool

func (*MsgWrap) VerifySignatureInter

func (msg *MsgWrap) VerifySignatureInter() bool

type NotaireContext

type NotaireContext struct {
	GameAddress common.Address //标识游戏,公证者可根据此项下载lua代码,还有房间abi等
	Version     uint8
	Wt          *Witness //
	From        SeatID   //谁提交上来的
	Hand        uint32

	MsgList  []MsgWrap //上一次共识到现在出现异常时收集的消息列表
	DeskID   []byte    //牌点求和哈希值
	TableCtr uint64    //合约中table id

	Sign SignData //签名
}

func (*NotaireContext) Hash

func (nc *NotaireContext) Hash() common.Hash

Hash returns the hash to be sned by the sender. It does not uniquely identify the transaction.

func (*NotaireContext) PublicKey

func (nc *NotaireContext) PublicKey() ([]byte, error)

func (*NotaireContext) Signature

func (nc *NotaireContext) Signature(ks *keystore.KeyStore, address common.Address) error

func (*NotaireContext) VerifySignature

func (nc *NotaireContext) VerifySignature() bool

type NotairePK

type NotairePK struct {
	ID SeatID
	Pk *PublicKey
}

type NotaireSign

type NotaireSign struct {
	ID   SeatID
	Sign []byte
}

type NotifyNotaryData

type NotifyNotaryData struct {
	DeskID []byte
	ID     SeatID
}

type PointPair

type PointPair struct {
	C1 *PublicKey
	C2 *PublicKey
}

type PublicKey

type PublicKey struct {
	X *big.Int
	Y *big.Int
}

type PublicKeyData

type PublicKeyData struct {
	Key    *PublicKey
	E      *big.Int
	Z      *big.Int
	DeskID []byte
	ID     SeatID
}

publicKeyData 公钥消息

type SeatID

type SeatID = uint8 //int8无法序列化

SeatID int//http://colobu.com/2017/06/26/learn-go-type-aliases/ 了解 Go 1.9 的类型别名

type SettleSignData

type SettleSignData struct {
	SeHash string
	Sign   string
	DeskID string
	ID     SeatID
}

type ShuffleData

type ShuffleData struct {
	Points []*PointPair
	E      *big.Int
	Z      *big.Int
	DeskID []byte
	ID     SeatID
}

shuffleData 洗牌消息

type ShuffleDataRsp

type ShuffleDataRsp struct {
	ID SeatID
}

shuffleDataRsp 回复消息

type SignData

type SignData struct {

	// Signature values
	V *big.Int `json:"v" gencodec:"required"`
	R *big.Int `json:"r" gencodec:"required"`
	S *big.Int `json:"s" gencodec:"required"`
}

type SitData

type SitData struct {
	GameAddress common.Address
	Desk        DeskID
	Seat        SeatID
	ID          UserID
	Address     common.Address
}

SitData 成员是要公开的,即首字母大写,否则会失败

type SitReusltData

type SitReusltData struct {
	SeatList []*SitData
}

type StatusData

type StatusData struct {
	ProtocolVersion uint32
	NetworkId       uint64
}

statusData is the network packet for the status message.

type SumpointSignData

type SumpointSignData struct {
	PointHash []byte
	Sign      []byte
	DeskID    []byte
	ID        SeatID
}

type SumpublicKeySignData

type SumpublicKeySignData struct {
	SkeyHash []byte
	Sign     []byte
	DeskID   []byte
	ID       SeatID
}

sumpublicKeyDataRsp 公钥求和生成共识

type UserID

type UserID = string

type Witness

type Witness struct {
	CheckState uint //上一次达成共识的状态 这里是Po_check
	Data       []byte
	SignData   []byte         //签名的数据hash
	Sign       []*NotaireSign //各个玩家的签名

	PublicKey []*NotairePK //各个玩家的公钥,没有达成公钥共识,为空。
	SumPkey   *PublicKey   //公钥和,没有达成公钥共识时,为空

	OriginalPoint []*PointPair //初始牌点,没有洗过的牌点对
	ShufflePoint  []*PointPair //洗牌后的牌点
}

Jump to

Keyboard shortcuts

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