Skip to content

Commit

Permalink
Make ClaimWithSigAndMTPProof.SignatureProof & ClaimWithSigAndMTPProof…
Browse files Browse the repository at this point in the history
….IncProof fields optional
  • Loading branch information
olomix committed Nov 20, 2023
1 parent 75d2c64 commit dffd68a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
16 changes: 16 additions & 0 deletions credentialAtomicQueryV3.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ func (a AtomicQueryV3Inputs) Validate() error {

switch a.ProofType {
case SigProotType:
if a.Claim.SignatureProof == nil {
return errors.New(ErrorEmptySignatureProof)
}

if a.Claim.SignatureProof.IssuerAuthIncProof.Proof == nil {
return errors.New(ErrorEmptyIssuerAuthClaimProof)
}
Expand All @@ -141,6 +145,10 @@ func (a AtomicQueryV3Inputs) Validate() error {
return errors.New(ErrorEmptyClaimSignature)
}
case MTPProofType:
if a.Claim.IncProof == nil {
return errors.New(ErrorEmptyMTPProof)
}

if a.Claim.IncProof.Proof == nil {
return errors.New(ErrorEmptyClaimProof)
}
Expand Down Expand Up @@ -212,6 +220,10 @@ func (a AtomicQueryV3Inputs) InputsMarshal() ([]byte, error) {
case SigProotType:
s.ProofType = "1"

if a.Claim.SignatureProof == nil {
return nil, errors.New(ErrorEmptySignatureProof)
}

s.IssuerClaimSignatureR8X = a.Claim.SignatureProof.Signature.R8.X.String()
s.IssuerClaimSignatureR8Y = a.Claim.SignatureProof.Signature.R8.Y.String()
s.IssuerClaimSignatureS = a.Claim.SignatureProof.Signature.S.String()
Expand All @@ -235,6 +247,10 @@ func (a AtomicQueryV3Inputs) InputsMarshal() ([]byte, error) {
case MTPProofType:
s.ProofType = "2"

if a.Claim.IncProof == nil {
return nil, errors.New(ErrorEmptyMTPProof)
}

s.IssuerClaimMtp = CircomSiblings(a.Claim.IncProof.Proof, a.GetMTLevel())
s.IssuerClaimClaimsTreeRoot = a.Claim.IncProof.TreeState.ClaimsRoot
s.IssuerClaimRevTreeRoot = a.Claim.IncProof.TreeState.RevocationRoot
Expand Down
16 changes: 16 additions & 0 deletions credentialAtomicQueryV3OnChain.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ func (a AtomicQueryV3OnChainInputs) Validate() error {

switch a.ProofType {
case SigProotType:
if a.Claim.SignatureProof == nil {
return errors.New(ErrorEmptySignatureProof)
}

if a.Claim.SignatureProof.IssuerAuthIncProof.Proof == nil {
return errors.New(ErrorEmptyIssuerAuthClaimProof)
}
Expand All @@ -197,6 +201,10 @@ func (a AtomicQueryV3OnChainInputs) Validate() error {
return errors.New(ErrorEmptyClaimSignature)
}
case MTPProofType:
if a.Claim.IncProof == nil {
return errors.New(ErrorEmptyMTPProof)
}

if a.Claim.IncProof.Proof == nil {
return errors.New(ErrorEmptyClaimProof)
}
Expand Down Expand Up @@ -285,6 +293,10 @@ func (a AtomicQueryV3OnChainInputs) InputsMarshal() ([]byte, error) {
case SigProotType:
s.ProofType = "1"

if a.Claim.SignatureProof == nil {
return nil, errors.New(ErrorEmptySignatureProof)
}

s.IssuerClaimSignatureR8X = a.Claim.SignatureProof.Signature.R8.X.String()
s.IssuerClaimSignatureR8Y = a.Claim.SignatureProof.Signature.R8.Y.String()
s.IssuerClaimSignatureS = a.Claim.SignatureProof.Signature.S.String()
Expand All @@ -308,6 +320,10 @@ func (a AtomicQueryV3OnChainInputs) InputsMarshal() ([]byte, error) {
case MTPProofType:
s.ProofType = "2"

if a.Claim.IncProof == nil {
return nil, errors.New(ErrorEmptyMTPProof)
}

s.IssuerClaimMtp = CircomSiblings(a.Claim.IncProof.Proof, a.GetMTLevel())
s.IssuerClaimClaimsTreeRoot = a.Claim.IncProof.TreeState.ClaimsRoot
s.IssuerClaimRevTreeRoot = a.Claim.IncProof.TreeState.RevocationRoot
Expand Down
4 changes: 2 additions & 2 deletions credentialAtomicQueryV3OnChain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestAttrQueryV3OnChain_SigPart_PrepareInputs(t *testing.T) {
},
Proof: issuerClaimNonRevMtp,
},
SignatureProof: BJJSignatureProof{
SignatureProof: &BJJSignatureProof{
Signature: claimSig,
IssuerAuthClaim: issuer.AuthClaim,
IssuerAuthIncProof: MTProof{
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestAttrQueryV3OnChain_MTPPart_PrepareInputs(t *testing.T) {
Claim: ClaimWithSigAndMTPProof{
IssuerID: &issuer.ID,
Claim: claim,
IncProof: MTProof{
IncProof: &MTProof{
Proof: issuerClaimMtp,
TreeState: TreeState{
State: issuer.State(t),
Expand Down
4 changes: 2 additions & 2 deletions credentialAtomicQueryV3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestAttrQueryV3_SigPart_PrepareInputs(t *testing.T) {
},
Proof: issuerClaimNonRevMtp,
},
SignatureProof: BJJSignatureProof{
SignatureProof: &BJJSignatureProof{
Signature: claimSig,
IssuerAuthClaim: issuer.AuthClaim,
IssuerAuthIncProof: MTProof{
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestAttrQueryV3_MTPPart_PrepareInputs(t *testing.T) {
Claim: ClaimWithSigAndMTPProof{
IssuerID: &issuer.ID,
Claim: claim,
IncProof: MTProof{
IncProof: &MTProof{
Proof: issuerClaimMtp,
TreeState: TreeState{
State: issuer.State(t),
Expand Down
2 changes: 2 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ const (
ErrorEmptyGISTProof = "empty GIST identity mtp proof"
ErrorEmptyRequestID = "empty request ID"
ErrorInvalidProofType = "invalid proof type"
ErrorEmptySignatureProof = "empty signature proof"
ErrorEmptyMTPProof = "empty MTP proof"
)
10 changes: 5 additions & 5 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
)

type ClaimWithSigAndMTPProof struct {
IssuerID *core.ID `json:"issuerID"`
Claim *core.Claim `json:"claim"`
NonRevProof MTProof `json:"nonRevProof"` // Claim non revocation proof
SignatureProof BJJSignatureProof `json:"signatureProof"`
IncProof MTProof `json:"incProof"` // proof of inclusion `Claim` to the issuer claims tree
IssuerID *core.ID `json:"issuerID"`
Claim *core.Claim `json:"claim"`
NonRevProof MTProof `json:"nonRevProof"` // Claim non revocation proof
SignatureProof *BJJSignatureProof `json:"signatureProof"`
IncProof *MTProof `json:"incProof"` // proof of inclusion `Claim` to the issuer claims tree
}

type ClaimWithSigProof struct {
Expand Down

0 comments on commit dffd68a

Please sign in to comment.