/
messages.go
140 lines (124 loc) · 4.58 KB
/
messages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package claimsrv
import (
"crypto/ecdsa"
common3 "github.com/iden3/go-iden3/common"
"github.com/iden3/go-iden3/core"
"github.com/iden3/go-iden3/merkletree"
"github.com/iden3/go-iden3/utils"
)
// BytesSignedMsg contains the value and its signature in Hex representation
type BytesSignedMsg struct {
ValueHex string `json:"valueHex" binding:"required"` // claim.Bytes() in a hex format
Signature *utils.SignatureEthMsg `json:"signatureHex" binding:"required"`
KSignPk *utils.PublicKey `json:"kSignPK" binding:"required"`
}
// ClaimBasicMsg contains a core.ClaimBasic with its signature in Hex
type ClaimBasicMsg struct {
ClaimBasic core.ClaimBasic `binding:"required"`
Signature *utils.SignatureEthMsg `binding:"required"`
}
// ClaimAssignNameMsg contains a core.ClaimAssignName with its signature in Hex
type ClaimAssignNameMsg struct {
ClaimAssignName core.ClaimAssignName `binding:"required"`
Signature *utils.SignatureEthMsg `binding:"required"`
}
// ClaimAuthorizeKSignSecp256k1Msg contains a core.ClaimAuthorizeKSignP256 with its signature in Hex
type ClaimAuthorizeKSignSecp256k1Msg struct {
ClaimAuthorizeKSignSecp256k1 core.ClaimAuthorizeKSignSecp256k1 `binding:"required"`
Signature *utils.SignatureEthMsg `binding:"required"`
KSignP256 *ecdsa.PublicKey `binding:"required"`
}
// SetRootMsg contains the data to set the SetRootClaim with its signature in Hex
type SetRootMsg struct {
Root string `binding:"required"`
Id string `binding:"required"`
KSignPk *utils.PublicKey `binding:"required"`
Timestamp int64 `binding:"required"`
Signature *utils.SignatureEthMsg `binding:"required"`
}
// ClaimValueMsg contains a core.ClaimValue with its signature in Hex
type ClaimValueMsg struct {
ClaimValue merkletree.Entry `binding:"required"`
Signature *utils.SignatureEthMsg `binding:"required"`
KSignPk *utils.PublicKey `binding:"required"`
}
// TODO: Remove in next refactor
// ProofTreeLeaf contains all the parameters needed to proof that a Leaf is in a merkletree with a given Root
type ProofTreeLeaf struct {
Leaf []byte
Proof []byte
Root merkletree.Hash
}
// TODO: Remove in next refactor
// ProofTreeLeafHex is the same data structure than ProofTreeLeaf but in Hexadecimal string representation
type ProofTreeLeafHex struct {
Leaf string
Proof string
Root string
}
// TODO: Remove in next refactor
func (plh *ProofTreeLeafHex) Unhex() ProofTreeLeaf {
var r ProofTreeLeaf
r.Leaf, _ = common3.HexDecode(plh.Leaf)
r.Proof, _ = common3.HexDecode(plh.Proof)
rootBytes, _ := common3.HexDecode(plh.Root)
copy(r.Root[:], rootBytes[:32])
return r
}
// TODO: Remove in next refactor
// Hex returns a ProofTreeLeafHex data structure
func (pl *ProofTreeLeaf) Hex() ProofTreeLeafHex {
r := ProofTreeLeafHex{
common3.HexEncode(pl.Leaf),
common3.HexEncode(pl.Proof),
pl.Root.Hex(),
}
return r
}
// TODO: Remove in next refactor
// ProofClaimUser is the proof of a claim in the Identity MerkleTree, and the SetRootClaim of that MerkleTree inside the Relay's MerkleTree. Also with the proofs of non revocation of both claims
type ProofClaimUser struct {
ClaimProof ProofTreeLeaf
SetRootClaimProof ProofTreeLeaf
ClaimNonRevocationProof ProofTreeLeaf
SetRootClaimNonRevocationProof ProofTreeLeaf
Date int64
Signature []byte // signature of the Root of the Relay
}
// TODO: Remove in next refactor
type ProofClaimUserHex struct {
ClaimProof ProofTreeLeafHex
SetRootClaimProof ProofTreeLeafHex
ClaimNonRevocationProof ProofTreeLeafHex
SetRootClaimNonRevocationProof ProofTreeLeafHex
Date int64
Signature string // signature of the Root of the Relay
}
// TODO: Remove in next refactor
func (pc *ProofClaimUser) Hex() ProofClaimUserHex {
r := ProofClaimUserHex{
pc.ClaimProof.Hex(),
pc.SetRootClaimProof.Hex(),
pc.ClaimNonRevocationProof.Hex(),
pc.SetRootClaimNonRevocationProof.Hex(),
pc.Date,
common3.HexEncode(pc.Signature),
}
return r
}
// TODO: Remove in next refactor
func (pch *ProofClaimUserHex) Unhex() (ProofClaimUser, error) {
sigBytes, err := common3.HexDecode(pch.Signature)
if err != nil {
return ProofClaimUser{}, err
}
r := ProofClaimUser{
pch.ClaimProof.Unhex(),
pch.SetRootClaimProof.Unhex(),
pch.ClaimNonRevocationProof.Unhex(),
pch.SetRootClaimNonRevocationProof.Unhex(),
pch.Date,
sigBytes,
}
return r, nil
}