Skip to content

Commit

Permalink
Merge pull request #5 from iden3/feature/support-fetch-request
Browse files Browse the repository at this point in the history
Feature/support fetch request
  • Loading branch information
vmidyllic authored Jan 11, 2022
2 parents c718413 + d4ef511 commit 4aa706b
Show file tree
Hide file tree
Showing 18 changed files with 391 additions and 167 deletions.
1 change: 0 additions & 1 deletion circuits/circuits.go

This file was deleted.

9 changes: 0 additions & 9 deletions circuits/metadata.go

This file was deleted.

12 changes: 0 additions & 12 deletions circuits/verification_keys.go

This file was deleted.

4 changes: 2 additions & 2 deletions communication/auth/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func ExtractMetadata(message types.Message) (token *UserToken, err error) {
if err != nil {
return nil, fmt.Errorf("proof with type %s is not valid. %s", proof.Type, err.Error())
}
err = token.update(string(proof.CircuitID), proof.ProofMetadata)
err = token.Update(string(proof.CircuitID), proof.ProofMetadata)

if err != nil {
return nil, fmt.Errorf("can't provide user token %s", err.Error())
Expand All @@ -119,7 +119,7 @@ func ExtractMetadata(message types.Message) (token *UserToken, err error) {
if err != nil {
return nil, fmt.Errorf("proof with type %s is not valid. %s", proof.Type, err.Error())
}
err = token.update(proof.KeyType, proof.ProofMetadata)
err = token.Update(proof.KeyType, proof.ProofMetadata)
if err != nil {
return nil, fmt.Errorf("can't provide user token %s", err.Error())
}
Expand Down
68 changes: 21 additions & 47 deletions communication/auth/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package auth

import (
"context"
"github.com/iden3/go-iden3-auth/circuits"
"github.com/iden3/go-circuits"
"github.com/iden3/go-iden3-auth/types"
"github.com/stretchr/testify/assert"
"os"
Expand All @@ -17,54 +17,28 @@ func TestVerify(t *testing.T) {

zkpProof := types.ZeroKnowledgeProof{
Type: types.ZeroKnowledgeProofType,
CircuitID: types.KycBySignaturesCircuitID,
CircuitID: circuits.KycBySignaturesCircuitID,
}

zkpProof.ProofData = &types.ProofData{
A: []string{"15410252994758206156331933443865902387659457159831652500594192431349076893658",
"20150829872771081060142254046116588090324284033366663360366174697329414878949",
A: []string{"10441536817202584897377823144827964642356918402871315490038163167310235469676",
"3188873104904010906845899057040012497857652125001996465924027367142766788060",
"1"},
B: [][]string{{"9417153075860115376893693247142868897300054298656960914587138216866082643706",
"10202816620941554744739718000741718724240818496129635422271960203010394413915",
}, {"15503138617167966595249072003849677537923997283726290430496888985000900792650",
"6173958614668002844023250887062625456639056306855696879145959593623787348506",
B: [][]string{{"10259767950868305572343651918722890484304440255374794205464892311274784569874",
"18113532891970083775734522192028652126404157383671158241782353379080674688210",
}, {
"20011188305329655231409527762393912898857036946232895893305954758470171745705",
"19212224402431449690017436050830610655559646158634403540885275057516508525272",
}, {
"1",
"0",
}},
C: []string{
"14084349531001200150970271267870661180690655641091539571582685666559667846160",
"6506935406401708938070550600218341978561747347886649538986407400386963731317",
C: []string{"17410066358263445906462947561105622363737416663317734129930901016400750644236",
"10889346016675221860511647187111664354773325795907973404602900127856769668544",
"1",
},
}
zkpProof.PubSignals = []string{
"26592849444054787445766572449338308165040390141345377877344569181291872256",
"12345",
"164414642845063686862221124543185217840281790633605788367384240953047711744",
"20826763141600863538041346956386832863527621891653741934199228821528372364336",
"840",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"164414642845063686862221124543185217840281790633605788367384240953047711744",
"20826763141600863538041346956386832863527621891653741934199228821528372364336",
"2021",
"4",
"25",
"18",
}
zkpProof.PubSignals = []string{"12345", "372902514040400364441393275265861152892555341750332828757240276565437644800", "19443506635601976434000063402326775248489014592264899338419890539515181882284", "840", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "372902514040400364441393275265861152892555341750332828757240276565437644800", "19443506635601976434000063402326775248489014592264899338419890539515181882284", "2021", "4", "25"}
message.Data.Scope = []interface{}{zkpProof}

err := Verify(&message)
Expand All @@ -79,7 +53,7 @@ func TestVerifyWrongMessage(t *testing.T) {

zkpProofRequest := types.ZeroKnowledgeProofRequest{
Type: types.ZeroKnowledgeProofType,
CircuitID: types.KycBySignaturesCircuitID,
CircuitID: circuits.KycBySignaturesCircuitID,
Rules: map[string]interface{}{},
}
message.Data.Scope = []types.TypedScope{zkpProofRequest}
Expand All @@ -94,7 +68,7 @@ func TestCreateAuthorizationRequest(t *testing.T) {
aud := "1125GJqgw6YEsKFwj63GY87MMxPL9kwDKxPUiwMLNZ"
zkpProofRequest := types.ZeroKnowledgeProofRequest{
Type: types.ZeroKnowledgeProofType,
CircuitID: types.KycBySignaturesCircuitID,
CircuitID: circuits.KycBySignaturesCircuitID,
Rules: map[string]interface{}{
"challenge": 12345678,
"countryBlacklist": []int{840},
Expand Down Expand Up @@ -127,12 +101,12 @@ func TestExtractData(t *testing.T) {

zkpProof := types.ZeroKnowledgeProof{
Type: types.ZeroKnowledgeProofType,
CircuitID: types.KycBySignaturesCircuitID,
CircuitID: circuits.KycBySignaturesCircuitID,
CircuitData: &types.CircuitData{
ID: types.KycBySignaturesCircuitID,
ID: circuits.KycBySignaturesCircuitID,
Description: "test",
VerificationKey: circuits.KYCBySignatureVerificationKey,
Metadata: circuits.KYCBySignaturePublicSignalsSchema,
VerificationKey: circuits.KycBySignaturesVerificationKey,
Metadata: circuits.KycBySignaturesPublicSignalsSchema,
},
}
zkpProof.PubSignals = []string{
Expand Down Expand Up @@ -186,7 +160,7 @@ func TestExtractData(t *testing.T) {
token, err := ExtractMetadata(&message)
assert.Nil(t, err)

assert.Equal(t, "12345", token.Challenge)
assert.Equal(t, "26592849444054787445766572449338308165040390141345377877344569181291872256", token.Challenge)

}

Expand All @@ -198,7 +172,7 @@ func TestVerifyMessageWithAuthProof(t *testing.T) {

zkpProof := types.ZeroKnowledgeProof{
Type: types.ZeroKnowledgeProofType,
CircuitID: types.AuthCircuitID,
CircuitID: circuits.AuthCircuitID,
}

zkpProof.ProofData = &types.ProofData{
Expand Down
3 changes: 2 additions & 1 deletion communication/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ type UserToken struct {
Scope map[string]map[string]interface{}
}

func (token *UserToken) update(scopeID string, metadata types.ProofMetadata) error {
// Update adds new metadata to user token
func (token *UserToken) Update(scopeID string, metadata types.ProofMetadata) error {

if token.Challenge != "" && token.Challenge != metadata.AuthData.AuthenticationChallenge {
return errors.New("different challenges were used for authentication")
Expand Down
Loading

0 comments on commit 4aa706b

Please sign in to comment.