|
1 | 1 | package keygen |
2 | 2 |
|
3 | 3 | import ( |
4 | | - bcrypto "github.com/bnb-chain/tss-lib/crypto" |
| 4 | + "bytes" |
| 5 | + "strings" |
5 | 6 |
|
| 7 | + "github.com/bnb-chain/tss-lib/crypto" |
| 8 | + |
| 9 | + "github.com/zeta-chain/go-tss/blame" |
6 | 10 | "github.com/zeta-chain/go-tss/common" |
7 | 11 | "github.com/zeta-chain/go-tss/p2p" |
8 | 12 | ) |
9 | 13 |
|
10 | | -type TssKeyGen interface { |
11 | | - GenerateNewKey(keygenReq Request) (*bcrypto.ECPoint, error) |
| 14 | +// Service TSS key generation service |
| 15 | +type Service interface { |
| 16 | + GenerateNewKey(request Request) (*crypto.ECPoint, error) |
12 | 17 | GetTssKeyGenChannels() chan *p2p.Message |
13 | 18 | GetTssCommonStruct() *common.TssCommon |
14 | 19 | } |
| 20 | + |
| 21 | +// Request request to do keygen |
| 22 | +type Request struct { |
| 23 | + Keys []string `json:"keys"` |
| 24 | + BlockHeight int64 `json:"block_height"` |
| 25 | + Version string `json:"tss_version"` |
| 26 | + Algo common.Algo `json:"algo,omitempty"` |
| 27 | +} |
| 28 | + |
| 29 | +// NewRequest constructs Request. |
| 30 | +func NewRequest(keys []string, blockHeight int64, version string, algo common.Algo) Request { |
| 31 | + return Request{ |
| 32 | + Keys: keys, |
| 33 | + BlockHeight: blockHeight, |
| 34 | + Version: version, |
| 35 | + Algo: algo, |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +// MsgID returns the hash of the request. |
| 40 | +func (r *Request) MsgID() (string, error) { |
| 41 | + var b bytes.Buffer |
| 42 | + |
| 43 | + b.WriteString(r.Version) |
| 44 | + b.WriteByte(';') |
| 45 | + b.WriteString(string(r.Algo)) |
| 46 | + b.WriteByte(';') |
| 47 | + b.WriteString(strings.Join(r.Keys, ",")) |
| 48 | + |
| 49 | + return common.MsgToHashString(b.Bytes()) |
| 50 | +} |
| 51 | + |
| 52 | +// Response keygen response |
| 53 | +type Response struct { |
| 54 | + Algo common.Algo `json:"algo"` |
| 55 | + PubKey string `json:"pub_key"` |
| 56 | + PoolAddress string `json:"pool_address"` |
| 57 | + Status common.Status `json:"status"` |
| 58 | + Blame blame.Blame `json:"blame"` |
| 59 | +} |
| 60 | + |
| 61 | +// NewResponse create a new instance of keygen.Response |
| 62 | +func NewResponse(algo common.Algo, pk, addr string, status common.Status, blame blame.Blame) Response { |
| 63 | + return Response{ |
| 64 | + Algo: algo, |
| 65 | + PubKey: pk, |
| 66 | + PoolAddress: addr, |
| 67 | + Status: status, |
| 68 | + Blame: blame, |
| 69 | + } |
| 70 | +} |
0 commit comments