-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add endpoint to return document nullifier from hash
- Loading branch information
1 parent
9195aef
commit 458dcc6
Showing
9 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
allOf: | ||
- $ref: '#/components/schemas/DocumentNullifierKey' | ||
- type: object | ||
required: | ||
- attributes | ||
properties: | ||
attributes: | ||
type: object | ||
required: | ||
- document_nullifier_hash | ||
properties: | ||
document_nullifier_hash: | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type: object | ||
required: | ||
- id | ||
- type | ||
properties: | ||
id: | ||
type: string | ||
type: | ||
type: string | ||
enum: | ||
- nullifiers |
34 changes: 34 additions & 0 deletions
34
docs/spec/paths/intergrations@identity-provider-service@[email protected]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
get: | ||
tags: | ||
- Document Nullifier | ||
summary: Document Nullifier retrieving | ||
operationId: document-nullifier | ||
parameters: | ||
- in: query | ||
name: dg2_hash | ||
required: true | ||
schema: | ||
type: string | ||
responses: | ||
'200': | ||
description: Success | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
data: | ||
type: object | ||
$ref: '#/components/schemas/DocumentNullifier' | ||
'500': | ||
description: Internal Error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Errors' | ||
'400': | ||
description: Bad Request Error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Errors' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package handlers | ||
|
||
import ( | ||
"encoding/hex" | ||
"github.com/iden3/go-iden3-crypto/poseidon" | ||
"github.com/rarimo/passport-identity-provider/internal/service/api/requests" | ||
"github.com/rarimo/passport-identity-provider/resources" | ||
"gitlab.com/distributed_lab/ape" | ||
"gitlab.com/distributed_lab/ape/problems" | ||
"math/big" | ||
"net/http" | ||
) | ||
|
||
func GetDocumentNullifier(w http.ResponseWriter, r *http.Request) { | ||
req, err := requests.NewGetDocumentNullifierRequest(r) | ||
if err != nil { | ||
ape.RenderErr(w, problems.BadRequest(err)...) | ||
return | ||
} | ||
|
||
dg2HashBytes, err := hex.DecodeString(req.DG2Hash) | ||
if err != nil { | ||
ape.RenderErr(w, problems.BadRequest(err)...) | ||
return | ||
} | ||
|
||
nullifierHashInput := make([]*big.Int, 0) | ||
if len(dg2HashBytes) >= 32 { | ||
// break data in a half | ||
nullifierHashInput = append(nullifierHashInput, new(big.Int).SetBytes(dg2HashBytes[:len(dg2HashBytes)/2])) | ||
nullifierHashInput = append(nullifierHashInput, new(big.Int).SetBytes(dg2HashBytes[len(dg2HashBytes)/2:])) | ||
} else { | ||
nullifierHashInput = append(nullifierHashInput, new(big.Int).SetBytes(dg2HashBytes)) | ||
} | ||
|
||
nullifierHashInput = append(nullifierHashInput, VerifierConfig(r).Blinder) | ||
|
||
nullifierHash, err := poseidon.Hash(nullifierHashInput) | ||
if err != nil { | ||
Log(r).WithError(err).Error("failed to hash via Poseidon") | ||
ape.RenderErr(w, problems.InternalError()) | ||
return | ||
} | ||
|
||
response := resources.DocumentNullifierResponse{ | ||
Data: resources.DocumentNullifier{ | ||
Key: resources.Key{ | ||
Type: resources.NULLIFIERS, | ||
}, | ||
Attributes: resources.DocumentNullifierAttributes{ | ||
DocumentNullifierHash: nullifierHash.String(), | ||
}, | ||
}, | ||
} | ||
|
||
ape.Render(w, response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package requests | ||
|
||
import ( | ||
validation "github.com/go-ozzo/ozzo-validation/v4" | ||
"gitlab.com/distributed_lab/logan/v3/errors" | ||
"gitlab.com/distributed_lab/urlval" | ||
"net/http" | ||
) | ||
|
||
type GetDocumentNullifierRequest struct { | ||
DG2Hash string `url:"dg2_hash"` | ||
} | ||
|
||
func NewGetDocumentNullifierRequest(r *http.Request) (GetDocumentNullifierRequest, error) { | ||
var req GetDocumentNullifierRequest | ||
|
||
err := urlval.Decode(r.URL.Query(), &req) | ||
if err != nil { | ||
return GetDocumentNullifierRequest{}, errors.Wrap(err, "failed to decode url") | ||
} | ||
|
||
return req, validateGetDocumentNullifierRequest(req) | ||
} | ||
|
||
func validateGetDocumentNullifierRequest(r GetDocumentNullifierRequest) error { | ||
return validation.Errors{ | ||
"/dg2_hash": validation.Validate(r.DG2Hash, validation.Required), | ||
}.Filter() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* GENERATED. Do not modify. Your changes might be overwritten! | ||
*/ | ||
|
||
package resources | ||
|
||
type DocumentNullifier struct { | ||
Key | ||
Attributes DocumentNullifierAttributes `json:"attributes"` | ||
} | ||
type DocumentNullifierResponse struct { | ||
Data DocumentNullifier `json:"data"` | ||
Included Included `json:"included"` | ||
} | ||
|
||
type DocumentNullifierListResponse struct { | ||
Data []DocumentNullifier `json:"data"` | ||
Included Included `json:"included"` | ||
Links *Links `json:"links"` | ||
} | ||
|
||
// MustDocumentNullifier - returns DocumentNullifier from include collection. | ||
// if entry with specified key does not exist - returns nil | ||
// if entry with specified key exists but type or ID mismatches - panics | ||
func (c *Included) MustDocumentNullifier(key Key) *DocumentNullifier { | ||
var documentNullifier DocumentNullifier | ||
if c.tryFindEntry(key, &documentNullifier) { | ||
return &documentNullifier | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* GENERATED. Do not modify. Your changes might be overwritten! | ||
*/ | ||
|
||
package resources | ||
|
||
type DocumentNullifierAttributes struct { | ||
DocumentNullifierHash string `json:"document_nullifier_hash"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters