Skip to content

Commit

Permalink
chore: adding params for on chain v3 circuits
Browse files Browse the repository at this point in the history
  • Loading branch information
javip97 committed Jan 25, 2024
1 parent 259723d commit 8ac15de
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
26 changes: 18 additions & 8 deletions api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ info:
servers:
- description: Local
url: http://localhost:3010
- description: Dev
url: https://verifier-backend-dev.polygonid.me

tags:
- name: Verifier
description: Collection of endpoints related to Verifier
- name: Public
description: Public endpoints for integrators
- name: Internal
description: Internal endpoints

paths:
/:
get:
summary: Get the documentation
operationId: GetDocumentation
x-internal: true
tags:
- Internal
responses:
200:
description: success and returns the documentation in HTML format
Expand All @@ -27,6 +33,8 @@ paths:
get:
summary: Health Check
operationId: Health
tags:
- Internal
responses:
'200':
description: All services are running
Expand All @@ -37,14 +45,16 @@ paths:
'500':
$ref: '#/components/responses/500'



/sign-in:
post:
summary: Sign in
operationId: Sign in
description: |
Sign in with a verification request
tags:
- Verifier
- Public
requestBody:
content:
application/json:
Expand Down Expand Up @@ -121,7 +131,7 @@ paths:
summary: Get Status
operationId: Status
tags:
- Verifier
- Public
parameters:
- $ref: '#/components/parameters/sessionID'
responses:
Expand All @@ -141,7 +151,7 @@ paths:
summary: Store QRCode
operationId: QRStore
tags:
- Verifier
- Public
requestBody:
content:
application/json:
Expand All @@ -162,7 +172,7 @@ paths:
summary: Get QRCode from store
operationId: GetQRCodeFromStore
tags:
- Verifier
- Public
parameters:
- $ref: '#/components/parameters/id'
responses:
Expand All @@ -182,7 +192,7 @@ paths:
summary: Callback
operationId: Callback
tags:
- Verifier
- Internal
parameters:
- $ref: '#/components/parameters/sessionID'
requestBody:
Expand Down Expand Up @@ -453,7 +463,7 @@ components:
type: object
example:
{
"nullifierSessionId": "123443290439234342342423423423423"
"nullifierSessionID": "123443290439234342342423423423423"
}

TransactionDataResponse:
Expand Down
33 changes: 25 additions & 8 deletions internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
mumbaiNetwork = "80001"
mainnetNetwork = "137"
defaultReason = "for testing purposes"
defaultBigIntBase = 10
)

// Server represents the API server
Expand Down Expand Up @@ -372,11 +373,15 @@ func getAuthReqQRCode(request protocol.AuthorizationRequestMessage) QRCode {
func getInvokeContractQRCode(request protocol.ContractInvokeRequestMessage) QRCode {
scopes := make([]Scope, 0, len(request.Body.Scope))
for _, scope := range request.Body.Scope {
scopes = append(scopes, Scope{
sc := Scope{
CircuitId: scope.CircuitID,
Id: scope.ID,
Query: scope.Query,
})
}
if scope.Params != nil {
sc.Params = common.ToPointer(scope.Params)
}
scopes = append(scopes, sc)
}

qrCode := QRCode{
Expand Down Expand Up @@ -472,7 +477,6 @@ func validateRequestQuery(offChainRequest bool, scope []ScopeRequest) error {
}

func getAuthRequestOffChain(req SignInRequestObject, cfg config.Config, sessionID uuid.UUID) (protocol.AuthorizationRequestMessage, error) {
const defaultBigIntBase = 10
if err := validateOffChainRequest(req); err != nil {
return protocol.AuthorizationRequestMessage{}, err
}
Expand All @@ -494,13 +498,13 @@ func getAuthRequestOffChain(req SignInRequestObject, cfg config.Config, sessionI
}
if scope.Params != nil {
params := *scope.Params
val, ok := params["nullifierSessionId"]
val, ok := params["nullifierSessionID"]
if !ok {
return protocol.AuthorizationRequestMessage{}, errors.New("nullifierSessionId is empty")
return protocol.AuthorizationRequestMessage{}, errors.New("nullifierSessionID is empty")
}
nullifierSessionID := new(big.Int)
if _, ok := nullifierSessionID.SetString(val.(string), defaultBigIntBase); !ok {
return protocol.AuthorizationRequestMessage{}, errors.New("nullifierSessionId is not a valid big integer")
return protocol.AuthorizationRequestMessage{}, errors.New("nullifierSessionID is not a valid big integer")
}
mtpProofRequest.Params = *scope.Params
}
Expand Down Expand Up @@ -544,11 +548,24 @@ func getContractInvokeRequestOnChain(req SignInRequestObject, cfg config.Config)

mtpProofRequests := make([]protocol.ZeroKnowledgeProofRequest, 0, len(req.Body.Scope))
for _, scope := range req.Body.Scope {
mtpProofRequests = append(mtpProofRequests, protocol.ZeroKnowledgeProofRequest{
zkProofReq := protocol.ZeroKnowledgeProofRequest{
ID: scope.Id,
CircuitID: scope.CircuitId,
Query: scope.Query,
})
}
if scope.Params != nil {
params := *scope.Params
val, ok := params["nullifierSessionID"]
if !ok {
return protocol.ContractInvokeRequestMessage{}, errors.New("nullifierSessionID is empty")
}
nullifierSessionID := new(big.Int)
if _, ok := nullifierSessionID.SetString(val.(string), defaultBigIntBase); !ok {
return protocol.ContractInvokeRequestMessage{}, errors.New("nullifierSessionID is not a valid big integer")
}
zkProofReq.Params = *scope.Params
}
mtpProofRequests = append(mtpProofRequests, zkProofReq)
}

transactionData := protocol.TransactionData{
Expand Down
8 changes: 4 additions & 4 deletions internal/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func TestSignIn(t *testing.T) {
"proofType": "BJJSignature2021"
}`),
Params: common.ToPointer(map[string]interface{}{
"nullifierSessionId": big.NewInt(100).String(),
"nullifierSessionID": big.NewInt(100).String(),
}),
},
},
Expand All @@ -293,7 +293,7 @@ func TestSignIn(t *testing.T) {
"proofType": "BJJSignature2021",
},
Params: common.ToPointer(map[string]interface{}{
"nullifierSessionId": big.NewInt(100).String(),
"nullifierSessionID": big.NewInt(100).String(),
}),
},
},
Expand Down Expand Up @@ -621,7 +621,7 @@ func TestSignIn(t *testing.T) {
"proofType": "BJJSignature2021"
}`),
Params: common.ToPointer(map[string]interface{}{
"nullifierSessionId": "invalid",
"nullifierSessionID": "invalid",
}),
},
},
Expand All @@ -631,7 +631,7 @@ func TestSignIn(t *testing.T) {
httpCode: http.StatusBadRequest,
SignInResponseObject: SignIn400JSONResponse{
N400JSONResponse{
Message: "nullifierSessionId is not a valid big integer",
Message: "nullifierSessionID is not a valid big integer",
},
},
},
Expand Down

0 comments on commit 8ac15de

Please sign in to comment.