From bdbf22a84341543f4085c55e285e7168f8cd0e18 Mon Sep 17 00:00:00 2001 From: vmidyllic <74898029+vmidyllic@users.noreply.github.com> Date: Tue, 11 Jan 2022 16:56:01 +0200 Subject: [PATCH 1/2] support fetch request, get rid of circuits --- circuits/circuits.go | 1 - circuits/metadata.go | 9 -- circuits/verification_keys.go | 12 -- communication/auth/service.go | 4 +- communication/auth/service_test.go | 18 +-- communication/auth/token.go | 3 +- communication/credentials/fetch.go | 166 +++++++++++++++++++++++ communication/credentials/fetch_test.go | 104 ++++++++++++++ communication/packer/plain_test.go | 27 ++-- go.mod | 2 + go.sum | 3 + proofs/zeroknowledge/handlers/circuit.go | 7 +- proofs/zeroknowledge/proof.go | 22 +-- proofs/zeroknowledge/proof_test.go | 5 +- types/circuits.go | 18 +-- types/message.go | 27 +++- types/proof.go | 14 +- verification/proof_test.go | 4 +- 18 files changed, 363 insertions(+), 83 deletions(-) delete mode 100644 circuits/circuits.go delete mode 100644 circuits/metadata.go delete mode 100644 circuits/verification_keys.go create mode 100644 communication/credentials/fetch.go create mode 100644 communication/credentials/fetch_test.go diff --git a/circuits/circuits.go b/circuits/circuits.go deleted file mode 100644 index e79e433..0000000 --- a/circuits/circuits.go +++ /dev/null @@ -1 +0,0 @@ -package circuits diff --git a/circuits/metadata.go b/circuits/metadata.go deleted file mode 100644 index a3a2dff..0000000 --- a/circuits/metadata.go +++ /dev/null @@ -1,9 +0,0 @@ -package circuits - -const ( - // KYCBySignaturePublicSignalsSchema is schema to parse json data for additional information - KYCBySignaturePublicSignalsSchema string = `{"user_identifier":0,"challenge":1,"countryClaimIssuerId":2,"countryClaimIssuerBBJIdenState":3,"countryBlacklist_1":4,"countryBlacklist_2":5,"countryBlacklist_3":6,"countryBlacklist_4":7,"countryBlacklist_5":8,"countryBlacklist_6":9,"countryBlacklist_7":10,"countryBlacklist_8":11,"countryBlacklist_9":12,"countryBlacklist_10":13,"countryBlacklist_11":14,"countryBlacklist_12":15,"countryBlacklist_13":16,"countryBlacklist_14":17,"countryBlacklist_15":18,"countryBlacklist_16":19,"birthdayClaimIssuerId":20,"birthdayClaimIssuerBBJIdenState":21,"currentYear":22,"currentMonth":23,"currentDay":24,"minAge":25}` - - // AuthenticationPublicSignalsSchema is schema to parse json data for additional information in auth circuit - AuthenticationPublicSignalsSchema string = `{"user_identifier":0,"challenge":1,"user_state":2}` -) diff --git a/circuits/verification_keys.go b/circuits/verification_keys.go deleted file mode 100644 index dc9f731..0000000 --- a/circuits/verification_keys.go +++ /dev/null @@ -1,12 +0,0 @@ -package circuits - -import ( - "github.com/iden3/go-iden3-auth/types" -) - -const ( - // KYCBySignatureVerificationKey is verification key to verify kycBysSignature circuit - KYCBySignatureVerificationKey types.VerificationKeyJSON = `{"protocol":"groth16","curve":"bn128","nPublic":26,"vk_alfa_1":["20491192805390485299153009773594534940189261866228447918068658471970481763042","9383485363053290200918347156157836566562967994039712273449902621266178545958","1"],"vk_beta_2":[["6375614351688725206403948262868962793625744043794305715222011528459656738731","4252822878758300859123897981450591353533073413197771768651442665752259397132"],["10505242626370262277552901082094356697409835680220590971873171140371331206856","21847035105528745403288232691147584728191162732299865338377159692350059136679"],["1","0"]],"vk_gamma_2":[["10857046999023057135944570762232829481370756359578518086990519993285655852781","11559732032986387107991004021392285783925812861821192530917403151452391805634"],["8495653923123431417604973247489272438418190587263600148770280649306958101930","4082367875863433681332203403145435568316851327593401208105741076214120093531"],["1","0"]],"vk_delta_2":[["19128064920055492247805374985983083930165378749179480909913816724406615335296","19288160050156725733802379244448689099841958569866762821564854312784709506393"],["17428331044619925399916395861726985657968925788307219189262474327320267761426","2419828576521667459164020710642577668561374285085862557553780257161628012160"],["1","0"]],"vk_alphabeta_12":[[["2029413683389138792403550203267699914886160938906632433982220835551125967885","21072700047562757817161031222997517981543347628379360635925549008442030252106"],["5940354580057074848093997050200682056184807770593307860589430076672439820312","12156638873931618554171829126792193045421052652279363021382169897324752428276"],["7898200236362823042373859371574133993780991612861777490112507062703164551277","7074218545237549455313236346927434013100842096812539264420499035217050630853"]],[["7077479683546002997211712695946002074877511277312570035766170199895071832130","10093483419865920389913245021038182291233451549023025229112148274109565435465"],["4595479056700221319381530156280926371456704509942304414423590385166031118820","19831328484489333784475432780421641293929726139240675179672856274388269393268"],["11934129596455521040620786944827826205713621633706285934057045369193958244500","8037395052364110730298837004334506829870972346962140206007064471173334027475"]]],"IC":[["939914628341458097516560836826640061417412666479488218276452351605045261272","15618548428001333556505887616624363833376841092682878676319870665446762679381","1"],["19702481984208948066905921949401701892622081248277421181828805140556810527961","591249296144528568644572307700485352989887758126147542074984634824580349790","1"],["21597213372011691592118423761747260467136980646123047205544845233948785583454","5196511894272462787215205652324772860730227888212475230176185917563588975089","1"],["19947365043590033317698858174466422267665557198488278124968639335975352349566","6888103996945586203623646000310666601467283622375764292824085463872350533111","1"],["929770654496063678443820024355937299267629214892684305904187689767724951073","6221018702137222207323223468439959521912038660689132882244771195851036027436","1"],["15310074104932801501644246260897669637226023081793799067952914365167212169682","5879166969760669151358319200626715484518003603727122733880632094958992877599","1"],["17971643265209741168572406785554242786918944839698650229434685581374741153049","3868842795321072870819307332638694135310027298425990065378780298275327376227","1"],["495745971801346882197336692718840760523647268109405134318265470241548603318","21130030807975271815094195118605945442199078822769333781275642658294010578431","1"],["15761017688632999952168047278435514149120694920182536586342231270126590704103","21392966441954723879763377537982650705338045410646499550683341262986076462497","1"],["14761637176340383428252649965810248295683877890169419113056281631580002773413","6731526493847224925576121390364151881861699044372365347469588873402831839941","1"],["15851835685574472775862827117616441786754152565801802145266865670177972669062","15874065945662487959415069605527499236937033588760848794428995176829519629867","1"],["17373726396273537796870417619744542499830071779785286088433182026540191523591","9161378079365747151628520286205749938233800006194631547321283555989284857225","1"],["13312905596080705851601635638064751396651919659332733234631412807907395745857","1260373832423040695616485404682224203278851493376258227901013628705543689541","1"],["6131427624040614882789546287840649427398137387259427267973401956189842853429","3972267586492425100185156855077534857818312507309978391302972105444087606453","1"],["21198228523344347205296190384150182495468439418409269811101629880033140307176","15096741571751104933099141427282568324191338977008173304759099173470273098928","1"],["3222590932508072780326303585610580402925045277262286309448642463994919513778","16639917920181277326312669550618803226863219580774101180998300717248211138561","1"],["2087448661411056266461299935931047190539985050070525918870157796554208345315","7856861375719716246409097742827048670200813977983835009772546370489019665395","1"],["19937371855088628377463856848053459016326089130102447720252506729674313901644","8472010261302839748150687516534356087779781288686922969203004672254591955186","1"],["554270891896844532066866172748318370009985132578090355693920520674291649645","10699156451760641087986249338477737746414757627181053986536524135969186196189","1"],["5465061226051267980642510344843071304798020617742311187173887598903006967820","11893193670297230058362002712839315440501820807975395434613315133500764621711","1"],["14641687371361924497352317469887183845134509606912861194557692030600273165435","17270925897527243275922678840690882543817991761890068516463770595105142817757","1"],["17297740399105498043635452523970204725442613466771891216931543851047613222062","11970135855505351357087071704234862227389490581222449923825910728832852829134","1"],["13963696747816354569374969450817020976298346550369939668146041309950121851602","3334597054598802667360397783523455682253476471939428640736044957691532983596","1"],["16921733156938179995722747086695678352508229050490088523030962286491935657587","19580663880552112182040173817092822585729774224638798300122624436719055011580","1"],["3332736485186613668142732636026375877311430630177998823651523088195510999347","8443620575343412122110287749388130100175803277925508709171151849001928250366","1"],["11005060412361570098083562497542120757858345364067259480244409487317856148376","20901994404640877101828132182462220444734163309092115188931910219812283716947","1"],["1367787598278437985643819431598330931335252418212065257020911130676301915360","7732341683215070702836276408170949477995243447094745409006552425064825017753","1"]]}` - // AuthenticationVerificationKey is verification key to verify auth circuit - AuthenticationVerificationKey types.VerificationKeyJSON = `{"protocol":"groth16","curve":"bn128","nPublic":3,"vk_alfa_1":["20491192805390485299153009773594534940189261866228447918068658471970481763042","9383485363053290200918347156157836566562967994039712273449902621266178545958","1"],"vk_beta_2":[["6375614351688725206403948262868962793625744043794305715222011528459656738731","4252822878758300859123897981450591353533073413197771768651442665752259397132"],["10505242626370262277552901082094356697409835680220590971873171140371331206856","21847035105528745403288232691147584728191162732299865338377159692350059136679"],["1","0"]],"vk_gamma_2":[["10857046999023057135944570762232829481370756359578518086990519993285655852781","11559732032986387107991004021392285783925812861821192530917403151452391805634"],["8495653923123431417604973247489272438418190587263600148770280649306958101930","4082367875863433681332203403145435568316851327593401208105741076214120093531"],["1","0"]],"vk_delta_2":[["16387671798576480847932379819368843257678774489163367102047295322423178277439","15478621310993617330780932378621004627680344811935882106064140147879135785043"],["4146651263272097482536403796145548707747481190068871240594136126762097388871","11898970623369189142377715638481376908544077570871221847177598703669075982080"],["1","0"]],"vk_alphabeta_12":[[["2029413683389138792403550203267699914886160938906632433982220835551125967885","21072700047562757817161031222997517981543347628379360635925549008442030252106"],["5940354580057074848093997050200682056184807770593307860589430076672439820312","12156638873931618554171829126792193045421052652279363021382169897324752428276"],["7898200236362823042373859371574133993780991612861777490112507062703164551277","7074218545237549455313236346927434013100842096812539264420499035217050630853"]],[["7077479683546002997211712695946002074877511277312570035766170199895071832130","10093483419865920389913245021038182291233451549023025229112148274109565435465"],["4595479056700221319381530156280926371456704509942304414423590385166031118820","19831328484489333784475432780421641293929726139240675179672856274388269393268"],["11934129596455521040620786944827826205713621633706285934057045369193958244500","8037395052364110730298837004334506829870972346962140206007064471173334027475"]]],"IC":[["19297919417399184394532324181597658329834075232866100019152812814859397268431","14699022357013157061045807542966925633990406674376276222050022522196639447960","1"],["6388362365563994994798769018624399476157773300166350845180279774476505983730","1217648947419151894183447372833203907938938673770764619682641601131531973167","1"],["3126272743831125875461477201504235660379019590657876897422768240259895227533","2925084377602205004508382849819352668757030527242022365611757402467366851533","1"],["17387847174228245327715232848798152616407267392716933941868769226711928740481","1096675226219651075629157873641324617572268342063247490094549328342254389311","1"]]}` -) diff --git a/communication/auth/service.go b/communication/auth/service.go index cd52d50..0dfa362 100644 --- a/communication/auth/service.go +++ b/communication/auth/service.go @@ -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()) @@ -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()) } diff --git a/communication/auth/service_test.go b/communication/auth/service_test.go index bb7c8aa..33486ca 100644 --- a/communication/auth/service_test.go +++ b/communication/auth/service_test.go @@ -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" @@ -17,7 +17,7 @@ func TestVerify(t *testing.T) { zkpProof := types.ZeroKnowledgeProof{ Type: types.ZeroKnowledgeProofType, - CircuitID: types.KycBySignaturesCircuitID, + CircuitID: circuits.KycBySignaturesCircuitID, } zkpProof.ProofData = &types.ProofData{ A: []string{"15410252994758206156331933443865902387659457159831652500594192431349076893658", @@ -79,7 +79,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} @@ -94,7 +94,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}, @@ -127,12 +127,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{ @@ -198,7 +198,7 @@ func TestVerifyMessageWithAuthProof(t *testing.T) { zkpProof := types.ZeroKnowledgeProof{ Type: types.ZeroKnowledgeProofType, - CircuitID: types.AuthCircuitID, + CircuitID: circuits.AuthCircuitID, } zkpProof.ProofData = &types.ProofData{ diff --git a/communication/auth/token.go b/communication/auth/token.go index 79a1b29..4801d49 100644 --- a/communication/auth/token.go +++ b/communication/auth/token.go @@ -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") diff --git a/communication/credentials/fetch.go b/communication/credentials/fetch.go new file mode 100644 index 0000000..01d963e --- /dev/null +++ b/communication/credentials/fetch.go @@ -0,0 +1,166 @@ +package credentials + +import ( + "encoding/json" + "fmt" + "github.com/iden3/go-iden3-auth/communication/auth" + "github.com/iden3/go-iden3-auth/communication/protocol" + "github.com/iden3/go-iden3-auth/proofs/signature" + "github.com/iden3/go-iden3-auth/proofs/zeroknowledge" + "github.com/iden3/go-iden3-auth/types" + "github.com/pkg/errors" +) + +const ( + // Name represents name of the service + Name = "credential-service" + // CredentialFetchRequestMessageType defines credential request type of the communication protocol + CredentialFetchRequestMessageType types.ProtocolMessage = protocol.ProtocolName + "/credential-fetch-request/v1" +) + +// VerifyCredentialFetchRequest only proofs of a verification of credential fetch request message +func VerifyCredentialFetchRequest(message types.Message) (err error) { + if message.GetType() != CredentialFetchRequestMessageType { + return fmt.Errorf("%s doesn't support %s message type", Name, (message).GetType()) + } + + var fetchRequestData types.CredentialFetchRequestMessageData + + switch message.GetData().(type) { + case json.RawMessage: + err = json.Unmarshal(message.GetData().(json.RawMessage), &fetchRequestData) + if err != nil { + return err + } + case types.CredentialFetchRequestMessageData: + fetchRequestData = message.GetData().(types.CredentialFetchRequestMessageData) + } + + if fetchRequestData.ClaimID == "" { + return errors.New("no claim field in fetch request") + } + + if fetchRequestData.Schema == "" { + return errors.New("no claim schema field in fetch request") + } + + for _, s := range fetchRequestData.Scope { + var typedScope types.TypedScope + typedScope, err = toTypedScope(s) + if err != nil { + return err + } + switch proof := typedScope.(type) { + case types.ZeroKnowledgeProof: + err = zeroknowledge.VerifyProof(&proof) + if err != nil { + return fmt.Errorf("proof with type %s is not valid. %s", proof.Type, err.Error()) + } + case types.SignatureProof: + err = signature.VerifyProof(&proof) + if err != nil { + return fmt.Errorf("proof with type %s is not valid. %s", proof.Type, err.Error()) + } + default: + return errors.New("unknown proof") + } + } + return nil +} + +// ExtractMetadataFromCredentialFetchRequest extract CredentialFetch specific fetchCredToken from provided proofs +func ExtractMetadataFromCredentialFetchRequest(message types.Message) (fetchCredToken *CredentialFetchUserToken, err error) { + if message.GetType() != CredentialFetchRequestMessageType { + return nil, fmt.Errorf("%s doesn't support %s message type", Name, message.GetType()) + } + var fetchRequestData types.CredentialFetchRequestMessageData + + switch message.GetData().(type) { + case json.RawMessage: + err = json.Unmarshal(message.GetData().(json.RawMessage), &fetchRequestData) + if err != nil { + return nil, err + } + case types.CredentialFetchRequestMessageData: + fetchRequestData = message.GetData().(types.CredentialFetchRequestMessageData) + } + fetchCredToken = &CredentialFetchUserToken{ + ClaimID: fetchRequestData.ClaimID, + ClaimSchema: fetchRequestData.Schema, + } + fetchCredToken.Scope = map[string]map[string]interface{}{} + for _, s := range fetchRequestData.Scope { + + var typedScope types.TypedScope + typedScope, err = toTypedScope(s) + if err != nil { + return nil, err + } + switch proof := typedScope.(type) { + case types.ZeroKnowledgeProof: + err = zeroknowledge.ExtractMetadata(&proof) + if err != nil { + return nil, fmt.Errorf("proof with type %s is not valid. %s", proof.Type, err.Error()) + } + err = fetchCredToken.Update(string(proof.CircuitID), proof.ProofMetadata) + + if err != nil { + return nil, fmt.Errorf("can't provide user fetchCredToken %s", err.Error()) + } + + case types.SignatureProof: + err = signature.ExtractMetadata(&proof) + if err != nil { + return nil, fmt.Errorf("proof with type %s is not valid. %s", proof.Type, err.Error()) + } + err = fetchCredToken.Update(proof.KeyType, proof.ProofMetadata) + if err != nil { + return nil, fmt.Errorf("can't provide user fetchCredToken %s", err.Error()) + } + } + } + return fetchCredToken, nil +} + +func toTypedScope(value interface{}) (types.TypedScope, error) { + switch obj := value.(type) { + case map[string]interface{}: + scopeMap, ok := value.(map[string]interface{}) + if !ok { + return nil, errors.New("scope object is not a map") + } + b, err := json.Marshal(value) + if err != nil { + return nil, errors.Wrap(err, "can't marshall scope obj") + } + switch types.ProofType(scopeMap["type"].(string)) { + case types.ZeroKnowledgeProofType: + var zkp types.ZeroKnowledgeProof + err = json.Unmarshal(b, &zkp) + if err != nil { + return nil, errors.Wrap(err, "can't unmarshall to zkp proof") + } + return zkp, nil + case types.SignatureProofType: + var sig types.SignatureProof + err = json.Unmarshal(b, &sig) + if err != nil { + return nil, errors.Wrap(err, "can't unmarshall to signature proof") + } + return sig, nil + default: + return nil, errors.Errorf("proof type is not supported: %s ", scopeMap["type"]) + } + case types.TypedScope: + return obj, nil + default: + return nil, errors.Errorf("scope object type is not supported %v", value) + } +} + +// CredentialFetchUserToken is token to fetch credential +type CredentialFetchUserToken struct { + ClaimID string `json:"claim_id"` + ClaimSchema string `json:"claim_schema"` + auth.UserToken +} diff --git a/communication/credentials/fetch_test.go b/communication/credentials/fetch_test.go new file mode 100644 index 0000000..7efb7bd --- /dev/null +++ b/communication/credentials/fetch_test.go @@ -0,0 +1,104 @@ +package credentials + +import ( + "github.com/iden3/go-circuits" + "github.com/iden3/go-iden3-auth/types" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestVerifyCredentialFetchRequest(t *testing.T) { + + var message types.CredentialFetchRequest + message.Type = CredentialFetchRequestMessageType + message.Data = types.CredentialFetchRequestMessageData{} + + zkpProof := types.ZeroKnowledgeProof{ + Type: types.ZeroKnowledgeProofType, + CircuitID: circuits.AuthCircuitID, + } + + zkpProof.ProofData = &types.ProofData{ + A: []string{ + "18936271973117240691705559585769592974936923569213179030272017872877809039923", + "18422345941126925346404589344471685526481812474926428421192486541362664918772", + "1"}, + B: [][]string{ + { + "21330507917605771112737495332384182754017872671331663255035774134477307177657", + "11462448334617588029347704885403867272225695665465848309095217964693916030466", + }, + { + "6840720762741964372185603768831031763412571244452731103935719626324813065968", + "21706573949504402596589372160652940106962129670251783730794239678073827564253", + }, + { + "1", + "0", + }}, + C: []string{ + "17548802242159422756497011319050257549779839182737330954154562317224853077096", + "16720285840459139191823107762843332365012723866736056448880671648502165007589", + "1", + }, + } + zkpProof.PubSignals = []string{ + "360506537017543098982364518145035624387547643177965411252793105868750389248", + "12345", + "12051733342209181702880711377819237050140862582923079913097401558944144010618", + } + message.Data.Scope = []interface{}{zkpProof} + + err := VerifyCredentialFetchRequest(&message) + assert.Nil(t, err) +} + +func TestExtractDataFromCredentialFetchRequest(t *testing.T) { + + var message types.CredentialFetchRequest + message.Type = CredentialFetchRequestMessageType + message.Data = types.CredentialFetchRequestMessageData{ClaimID: "992fc184-c902-4f9a-af62-b383cc5e1eb4", Schema: "KYCAgeCredential"} + + zkpProof := types.ZeroKnowledgeProof{ + Type: types.ZeroKnowledgeProofType, + CircuitID: circuits.AuthCircuitID, + } + + zkpProof.ProofData = &types.ProofData{ + A: []string{ + "18936271973117240691705559585769592974936923569213179030272017872877809039923", + "18422345941126925346404589344471685526481812474926428421192486541362664918772", + "1"}, + B: [][]string{ + { + "21330507917605771112737495332384182754017872671331663255035774134477307177657", + "11462448334617588029347704885403867272225695665465848309095217964693916030466", + }, + { + "6840720762741964372185603768831031763412571244452731103935719626324813065968", + "21706573949504402596589372160652940106962129670251783730794239678073827564253", + }, + { + "1", + "0", + }}, + C: []string{ + "17548802242159422756497011319050257549779839182737330954154562317224853077096", + "16720285840459139191823107762843332365012723866736056448880671648502165007589", + "1", + }, + } + zkpProof.PubSignals = []string{ + "360506537017543098982364518145035624387547643177965411252793105868750389248", + "12345", + "12051733342209181702880711377819237050140862582923079913097401558944144010618", + } + message.Data.Scope = []interface{}{zkpProof} + + token, err := ExtractMetadataFromCredentialFetchRequest(&message) + assert.Nil(t, err) + assert.Equal(t, "12345", token.Challenge) + assert.Equal(t, "992fc184-c902-4f9a-af62-b383cc5e1eb4", token.ClaimID) + assert.Equal(t, "KYCAgeCredential", token.ClaimSchema) + +} diff --git a/communication/packer/plain_test.go b/communication/packer/plain_test.go index 04a8785..b82c747 100644 --- a/communication/packer/plain_test.go +++ b/communication/packer/plain_test.go @@ -1,8 +1,9 @@ package packer import ( + "github.com/iden3/go-circuits" "github.com/iden3/go-iden3-auth/communication/auth" - types2 "github.com/iden3/go-iden3-auth/types" + "github.com/iden3/go-iden3-auth/types" "github.com/stretchr/testify/assert" "testing" ) @@ -10,20 +11,20 @@ import ( func TestPlainMessagePacker_Pack(t *testing.T) { packer := PlainMessagePacker{} - var message types2.AuthorizationMessageRequest + var message types.AuthorizationMessageRequest message.Type = auth.AuthorizationRequestMessageType - message.Data = types2.AuthorizationMessageRequestData{} + message.Data = types.AuthorizationMessageRequestData{} message.Data.Audience = "1125GJqgw6YEsKFwj63GY87MMxPL9kwDKxPUiwMLNZ" message.Data.CallbackURL = "https://test.com" - zkpProofRequest := types2.ZeroKnowledgeProofRequest{ - Type: types2.ZeroKnowledgeProofType, - CircuitID: types2.KycBySignaturesCircuitID, + zkpProofRequest := types.ZeroKnowledgeProofRequest{ + Type: types.ZeroKnowledgeProofType, + CircuitID: circuits.KycBySignaturesCircuitID, Rules: map[string]interface{}{ "challenge": "1234567", }, } - message.Data.Scope = []types2.TypedScope{zkpProofRequest} + message.Data.Scope = []types.TypedScope{zkpProofRequest} message.WithDefaultAuth(1234567) msgBytes, err := packer.Pack("application/json", &message) t.Log(string(msgBytes)) @@ -53,16 +54,16 @@ func TestPlainMessagePacker_Unpack(t *testing.T) { func TestPlainMessagePacker_PackAuthorizationResponse(t *testing.T) { packer := PlainMessagePacker{} - var message types2.AuthorizationMessageResponse + var message types.AuthorizationMessageResponse message.Type = auth.AuthorizationResponseMessageType - message.Data = types2.AuthorizationMessageResponseData{} + message.Data = types.AuthorizationMessageResponseData{} - zkpProof := types2.ZeroKnowledgeProof{ - Type: types2.ZeroKnowledgeProofType, - CircuitID: types2.AuthCircuitID, + zkpProof := types.ZeroKnowledgeProof{ + Type: types.ZeroKnowledgeProofType, + CircuitID: circuits.AuthCircuitID, } - zkpProof.ProofData = &types2.ProofData{ + zkpProof.ProofData = &types.ProofData{ A: []string{"14146277947056297753840642586002829867111675410988595047766001252156753371528", "14571022849315211248046007113544986624773029852663683182064313232057584750907", "1"}, B: [][]string{ {"16643510334478363316178974136322830670001098048711963846055396047727066595515", "10398230582752448515583571758866992012509398625081722188208617704185602394573"}, diff --git a/go.mod b/go.mod index 2e6dc58..f942cfd 100644 --- a/go.mod +++ b/go.mod @@ -15,10 +15,12 @@ require ( github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect github.com/btcsuite/btcd v0.20.1-beta // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dchest/blake512 v1.0.0 // indirect github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea // indirect github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-stack/stack v1.8.0 // indirect github.com/gorilla/websocket v1.4.2 // indirect + github.com/iden3/go-circuits v0.0.5 // indirect github.com/iden3/go-iden3-crypto v0.0.11 // indirect github.com/mitchellh/mapstructure v1.4.3 // indirect github.com/mr-tron/base58 v1.2.0 // indirect diff --git a/go.sum b/go.sum index 15523dd..e410d38 100644 --- a/go.sum +++ b/go.sum @@ -97,6 +97,7 @@ github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dchest/blake512 v1.0.0 h1:oDFEQFIqFSeuA34xLtXZ/rWxCXdSjirjzPhey5EUvmA= github.com/dchest/blake512 v1.0.0/go.mod h1:FV1x7xPPLWukZlpDpWQ88rF/SFwZ5qbskrzhLMB92JI= github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea h1:j4317fAZh7X6GqbFowYdYdI0L9bwxL07jyPZIdepyZ0= github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= @@ -225,6 +226,8 @@ github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3 github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/iden3/go-circom-prover-verifier v0.0.1 h1:gfmAwhvUB0Wya++dGfgvMYPsLzJf34Yw6x269CnhOP0= github.com/iden3/go-circom-prover-verifier v0.0.1/go.mod h1:1FkpX4nUXxYcY2fpzqd27wHHEnWeo1v1nwDnz2TgBRo= +github.com/iden3/go-circuits v0.0.5 h1:wOpVFQSyO9GfQRq2WoSIS2puinj8KrbIHy6baLGgdBQ= +github.com/iden3/go-circuits v0.0.5/go.mod h1:0bUcReAD+GPUIa1SfxiAJNNHp9hYp3dN8bfjtH2KLe8= github.com/iden3/go-iden3-core v0.0.11 h1:Msi8F6n5e755OMer+7ZV03z04GnQtoTNboKwfrDgB9A= github.com/iden3/go-iden3-core v0.0.11/go.mod h1:Ou51YR716WqeBJ3Z4BkGVAJROgSYgfnl4i8x3mfLOeY= github.com/iden3/go-iden3-crypto v0.0.5/go.mod h1:XKw1oDwYn2CIxKOtr7m/mL5jMn4mLOxAxtZBRxQBev8= diff --git a/proofs/zeroknowledge/handlers/circuit.go b/proofs/zeroknowledge/handlers/circuit.go index ced9d24..b7be293 100644 --- a/proofs/zeroknowledge/handlers/circuit.go +++ b/proofs/zeroknowledge/handlers/circuit.go @@ -2,17 +2,18 @@ package handlers import ( "fmt" - types2 "github.com/iden3/go-iden3-auth/types" + "github.com/iden3/go-circuits" + types "github.com/iden3/go-iden3-auth/types" ) // CircuitHandler is handler to verify circuit information of provided proof type CircuitHandler struct { - SupportedCircuits map[types2.CircuitID]types2.CircuitData + SupportedCircuits map[circuits.CircuitID]types.CircuitData next ProofHandler } // Process applies handler logic on provided message -func (h *CircuitHandler) Process(m *types2.ZeroKnowledgeProof) (err error) { +func (h *CircuitHandler) Process(m *types.ZeroKnowledgeProof) (err error) { circuitData, ok := h.SupportedCircuits[m.CircuitID] if !ok { diff --git a/proofs/zeroknowledge/proof.go b/proofs/zeroknowledge/proof.go index 8183745..8568fef 100644 --- a/proofs/zeroknowledge/proof.go +++ b/proofs/zeroknowledge/proof.go @@ -1,24 +1,30 @@ package zeroknowledge import ( - "github.com/iden3/go-iden3-auth/circuits" + "github.com/iden3/go-circuits" "github.com/iden3/go-iden3-auth/proofs/zeroknowledge/handlers" types "github.com/iden3/go-iden3-auth/types" ) -var supportedCircuits = map[types.CircuitID]types.CircuitData{ - types.KycBySignaturesCircuitID: { - ID: types.KycBySignaturesCircuitID, +var supportedCircuits = map[circuits.CircuitID]types.CircuitData{ + circuits.KycBySignaturesCircuitID: { + ID: circuits.KycBySignaturesCircuitID, Description: "circuit for kyc claims verification", - VerificationKey: circuits.KYCBySignatureVerificationKey, - Metadata: circuits.KYCBySignaturePublicSignalsSchema, + VerificationKey: circuits.KycBySignaturesVerificationKey, + Metadata: circuits.KycPublicSignalsSchema, }, - types.AuthCircuitID: { - ID: types.AuthCircuitID, + circuits.AuthCircuitID: { + ID: circuits.AuthCircuitID, Description: "circuit for verification of basic authentication", VerificationKey: circuits.AuthenticationVerificationKey, Metadata: circuits.AuthenticationPublicSignalsSchema, }, + circuits.AtomicQueryCircuitID: { + ID: circuits.AtomicQueryCircuitID, + Description: "circuit for atomic query on standard iden3 credential", + VerificationKey: circuits.AtomicQueryVerificationKey, + Metadata: circuits.AtomicQueryPublicSignalsSchema, + }, } // VerifyProof performs groth16 verification diff --git a/proofs/zeroknowledge/proof_test.go b/proofs/zeroknowledge/proof_test.go index 3747f0b..f157b8f 100644 --- a/proofs/zeroknowledge/proof_test.go +++ b/proofs/zeroknowledge/proof_test.go @@ -1,6 +1,7 @@ package zeroknowledge import ( + "github.com/iden3/go-circuits" "github.com/iden3/go-iden3-auth/types" "github.com/stretchr/testify/assert" "testing" @@ -10,7 +11,7 @@ func TestVerifyProof(t *testing.T) { var err error proofMessage := &types.ZeroKnowledgeProof{} - proofMessage.CircuitID = types.KycBySignaturesCircuitID + proofMessage.CircuitID = circuits.KycBySignaturesCircuitID proofMessage.ProofData = &types.ProofData{ A: []string{"15410252994758206156331933443865902387659457159831652500594192431349076893658", "20150829872771081060142254046116588090324284033366663360366174697329414878949", @@ -72,7 +73,7 @@ func TestVerifyAuthProof(t *testing.T) { var err error proofMessage := &types.ZeroKnowledgeProof{} - proofMessage.CircuitID = types.AuthCircuitID + proofMessage.CircuitID = circuits.AuthCircuitID proofMessage.ProofData = &types.ProofData{ A: []string{ diff --git a/types/circuits.go b/types/circuits.go index 923f3bb..c76cd94 100644 --- a/types/circuits.go +++ b/types/circuits.go @@ -1,21 +1,11 @@ package types -// CircuitID is a type that must be used for circuit id definition -type CircuitID string - -const ( - // AuthCircuitID is a type that must be used for auth circuit id definition - AuthCircuitID CircuitID = "auth" - // KycBySignaturesCircuitID is a type that must be used for kycBySignatures circuit id definition - KycBySignaturesCircuitID CircuitID = "kycBySignatures" - // KycCircuitCircuitID is a type that must be used for kyc circuit id definition - KycCircuitCircuitID CircuitID = "kyc" -) +import "github.com/iden3/go-circuits" // CircuitData represents data that describes circuit type CircuitData struct { - ID CircuitID + ID circuits.CircuitID Description string - VerificationKey VerificationKeyJSON - Metadata string + VerificationKey circuits.VerificationKeyJSON + Metadata circuits.PublicSchemaJSON } diff --git a/types/message.go b/types/message.go index dc73772..45ff2e3 100644 --- a/types/message.go +++ b/types/message.go @@ -2,6 +2,7 @@ package types import ( "encoding/json" + "github.com/iden3/go-circuits" ) // ProtocolMessage is type for protocol messages @@ -85,7 +86,7 @@ func (m *AuthorizationMessageRequest) WithDefaultAuth(challenge int64) error { authProofRequest := ZeroKnowledgeProofRequest{ Type: ZeroKnowledgeProofType, - CircuitID: AuthCircuitID, + CircuitID: circuits.AuthCircuitID, Rules: rules, } m.Data.Scope = append(m.Data.Scope, authProofRequest) @@ -108,3 +109,27 @@ func (m *AuthorizationMessageResponse) GetType() ProtocolMessage { func (m *AuthorizationMessageResponse) GetData() interface{} { return m.Data } + +// CredentialFetchRequest is struct the represents credential fetch request message format +type CredentialFetchRequest struct { + Type ProtocolMessage `json:"type"` + Data CredentialFetchRequestMessageData `json:"data"` + Message `json:"-"` +} + +// CredentialFetchRequestMessageData is struct the represents credential fetch request data +type CredentialFetchRequestMessageData struct { + ClaimID string `json:"claimID"` + Schema string `json:"schema"` + Scope []interface{} `json:"scope"` +} + +// GetType returns defined type of AuthorizationMessage +func (m *CredentialFetchRequest) GetType() ProtocolMessage { + return m.Type +} + +// GetData returns data of AuthorizationMessage +func (m *CredentialFetchRequest) GetData() interface{} { + return m.Data +} diff --git a/types/proof.go b/types/proof.go index bc9bf39..024eb6c 100644 --- a/types/proof.go +++ b/types/proof.go @@ -1,5 +1,7 @@ package types +import "github.com/iden3/go-circuits" + // ProofType is a type that must be used for proof definition type ProofType string @@ -22,11 +24,11 @@ type ProofMetadata struct { // ZeroKnowledgeProof represents structure of zkp object type ZeroKnowledgeProof struct { - Type ProofType `json:"type"` - CircuitID CircuitID `json:"circuit_id"` - PubSignals []string `json:"pub_signals"` - ProofData *ProofData `json:"proof_data"` - CircuitData *CircuitData `json:"circuit_data,omitempty"` + Type ProofType `json:"type"` + CircuitID circuits.CircuitID `json:"circuit_id"` + PubSignals []string `json:"pub_signals"` + ProofData *ProofData `json:"proof_data"` + CircuitData *CircuitData `json:"circuit_data,omitempty"` ProofMetadata TypedScope `json:"-"` } @@ -79,7 +81,7 @@ type AuthenticationRules struct { // ZeroKnowledgeProofRequest represents structure for request of zkp proof type ZeroKnowledgeProofRequest struct { - CircuitID CircuitID `json:"circuit_id,omitempty"` + CircuitID circuits.CircuitID `json:"circuit_id,omitempty"` Type ProofType `json:"type"` Rules map[string]interface{} `json:"rules,omitempty"` TypedScope `json:"-"` diff --git a/verification/proof_test.go b/verification/proof_test.go index 58e85ae..907c563 100644 --- a/verification/proof_test.go +++ b/verification/proof_test.go @@ -4,7 +4,7 @@ import ( "github.com/iden3/go-circom-prover-verifier/parsers" types2 "github.com/iden3/go-circom-prover-verifier/types" "github.com/iden3/go-circom-prover-verifier/verifier" - "github.com/iden3/go-iden3-auth/circuits" + "github.com/iden3/go-circuits" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "testing" @@ -12,7 +12,7 @@ import ( func TestVerify(t *testing.T) { // verifyGroth16 the proofs - vkJSON := []byte(circuits.KYCBySignatureVerificationKey) + vkJSON := []byte(circuits.KycBySignaturesCircuitID) publicJSON := []byte(`["411744492472830263284610159093112301866082562595864436469836164448155795456","12345","123776615674577205629582240968408410063074486679712932519574537196926599168","11688539338838797595201345228132404230382121068811390693927054959014251630145","840","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","123776615674577205629582240968408410063074486679712932519574537196926599168","11688539338838797595201345228132404230382121068811390693927054959014251630145","2021","4","25","18"]`) From d4ef5116fe90d48dd5dcd8be4b38da8ad0a1195a Mon Sep 17 00:00:00 2001 From: vmidyllic <74898029+vmidyllic@users.noreply.github.com> Date: Tue, 11 Jan 2022 17:59:04 +0200 Subject: [PATCH 2/2] fix tests with new proofs --- circuits/metadata.go | 0 circuits/verification_keys.go | 0 communication/auth/service_test.go | 50 ++++++------------------- communication/credentials/fetch_test.go | 48 ++++++++++++------------ go.mod | 2 +- go.sum | 5 +-- proofs/zeroknowledge/proof.go | 2 +- proofs/zeroknowledge/proof_test.go | 48 ++++++------------------ verification/proof_test.go | 15 +++----- 9 files changed, 57 insertions(+), 113 deletions(-) delete mode 100644 circuits/metadata.go delete mode 100644 circuits/verification_keys.go diff --git a/circuits/metadata.go b/circuits/metadata.go deleted file mode 100644 index e69de29..0000000 diff --git a/circuits/verification_keys.go b/circuits/verification_keys.go deleted file mode 100644 index e69de29..0000000 diff --git a/communication/auth/service_test.go b/communication/auth/service_test.go index 2743844..7fa6d3e 100644 --- a/communication/auth/service_test.go +++ b/communication/auth/service_test.go @@ -19,52 +19,26 @@ func TestVerify(t *testing.T) { Type: types.ZeroKnowledgeProofType, 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) @@ -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) } diff --git a/communication/credentials/fetch_test.go b/communication/credentials/fetch_test.go index 7efb7bd..f940a1d 100644 --- a/communication/credentials/fetch_test.go +++ b/communication/credentials/fetch_test.go @@ -11,7 +11,7 @@ func TestVerifyCredentialFetchRequest(t *testing.T) { var message types.CredentialFetchRequest message.Type = CredentialFetchRequestMessageType - message.Data = types.CredentialFetchRequestMessageData{} + message.Data = types.CredentialFetchRequestMessageData{ClaimID: "992fc184-c902-4f9a-af62-b383cc5e1eb4", Schema: "KYCAgeCredential"} zkpProof := types.ZeroKnowledgeProof{ Type: types.ZeroKnowledgeProofType, @@ -20,32 +20,32 @@ func TestVerifyCredentialFetchRequest(t *testing.T) { zkpProof.ProofData = &types.ProofData{ A: []string{ - "18936271973117240691705559585769592974936923569213179030272017872877809039923", - "18422345941126925346404589344471685526481812474926428421192486541362664918772", + "11130843150540789299458990586020000719280246153797882843214290541980522375072", + "1300841912943781723022032355836893831132920783788455531838254465784605762713", "1"}, B: [][]string{ { - "21330507917605771112737495332384182754017872671331663255035774134477307177657", - "11462448334617588029347704885403867272225695665465848309095217964693916030466", + "20615768536988438336537777909042352056392862251785722796637590212160561351656", + "10371144806107778890538857700855108667622042215096971747203105997454625814080", }, { - "6840720762741964372185603768831031763412571244452731103935719626324813065968", - "21706573949504402596589372160652940106962129670251783730794239678073827564253", + "19598541350804478549141207835028671111063915635580679694907635914279928677812", + "15264553045517065669171584943964322117397645147006909167427809837929458012913", }, { "1", "0", }}, C: []string{ - "17548802242159422756497011319050257549779839182737330954154562317224853077096", - "16720285840459139191823107762843332365012723866736056448880671648502165007589", + "16443309279825508893086251290003936935077348754097470818523558082502364822049", + "2984180227766048100510120407150752052334571876681304999595544138155611963273", "1", }, } zkpProof.PubSignals = []string{ - "360506537017543098982364518145035624387547643177965411252793105868750389248", - "12345", - "12051733342209181702880711377819237050140862582923079913097401558944144010618", + "1", + "18311560525383319719311394957064820091354976310599818797157189568621466950811", + "323416925264666217617288569742564703632850816035761084002720090377353297920", } message.Data.Scope = []interface{}{zkpProof} @@ -66,38 +66,38 @@ func TestExtractDataFromCredentialFetchRequest(t *testing.T) { zkpProof.ProofData = &types.ProofData{ A: []string{ - "18936271973117240691705559585769592974936923569213179030272017872877809039923", - "18422345941126925346404589344471685526481812474926428421192486541362664918772", + "11130843150540789299458990586020000719280246153797882843214290541980522375072", + "1300841912943781723022032355836893831132920783788455531838254465784605762713", "1"}, B: [][]string{ { - "21330507917605771112737495332384182754017872671331663255035774134477307177657", - "11462448334617588029347704885403867272225695665465848309095217964693916030466", + "20615768536988438336537777909042352056392862251785722796637590212160561351656", + "10371144806107778890538857700855108667622042215096971747203105997454625814080", }, { - "6840720762741964372185603768831031763412571244452731103935719626324813065968", - "21706573949504402596589372160652940106962129670251783730794239678073827564253", + "19598541350804478549141207835028671111063915635580679694907635914279928677812", + "15264553045517065669171584943964322117397645147006909167427809837929458012913", }, { "1", "0", }}, C: []string{ - "17548802242159422756497011319050257549779839182737330954154562317224853077096", - "16720285840459139191823107762843332365012723866736056448880671648502165007589", + "16443309279825508893086251290003936935077348754097470818523558082502364822049", + "2984180227766048100510120407150752052334571876681304999595544138155611963273", "1", }, } zkpProof.PubSignals = []string{ - "360506537017543098982364518145035624387547643177965411252793105868750389248", - "12345", - "12051733342209181702880711377819237050140862582923079913097401558944144010618", + "1", + "18311560525383319719311394957064820091354976310599818797157189568621466950811", + "323416925264666217617288569742564703632850816035761084002720090377353297920", } message.Data.Scope = []interface{}{zkpProof} token, err := ExtractMetadataFromCredentialFetchRequest(&message) assert.Nil(t, err) - assert.Equal(t, "12345", token.Challenge) + assert.Equal(t, "1", token.Challenge) assert.Equal(t, "992fc184-c902-4f9a-af62-b383cc5e1eb4", token.ClaimID) assert.Equal(t, "KYCAgeCredential", token.ClaimSchema) diff --git a/go.mod b/go.mod index f942cfd..3f5602f 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.17 require ( github.com/ethereum/go-ethereum v1.10.13 github.com/iden3/go-circom-prover-verifier v0.0.1 + github.com/iden3/go-circuits v0.0.9 github.com/iden3/go-iden3-core v0.0.11 github.com/iden3/go-merkletree-sql v1.0.0-pre8 github.com/pkg/errors v0.9.1 @@ -20,7 +21,6 @@ require ( github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-stack/stack v1.8.0 // indirect github.com/gorilla/websocket v1.4.2 // indirect - github.com/iden3/go-circuits v0.0.5 // indirect github.com/iden3/go-iden3-crypto v0.0.11 // indirect github.com/mitchellh/mapstructure v1.4.3 // indirect github.com/mr-tron/base58 v1.2.0 // indirect diff --git a/go.sum b/go.sum index e410d38..fd36b68 100644 --- a/go.sum +++ b/go.sum @@ -226,8 +226,8 @@ github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3 github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/iden3/go-circom-prover-verifier v0.0.1 h1:gfmAwhvUB0Wya++dGfgvMYPsLzJf34Yw6x269CnhOP0= github.com/iden3/go-circom-prover-verifier v0.0.1/go.mod h1:1FkpX4nUXxYcY2fpzqd27wHHEnWeo1v1nwDnz2TgBRo= -github.com/iden3/go-circuits v0.0.5 h1:wOpVFQSyO9GfQRq2WoSIS2puinj8KrbIHy6baLGgdBQ= -github.com/iden3/go-circuits v0.0.5/go.mod h1:0bUcReAD+GPUIa1SfxiAJNNHp9hYp3dN8bfjtH2KLe8= +github.com/iden3/go-circuits v0.0.9 h1:jCrrrM2Owa2PME1Ff0A9kL9vGv2ECR9RQDwcD+WbpOY= +github.com/iden3/go-circuits v0.0.9/go.mod h1:0bUcReAD+GPUIa1SfxiAJNNHp9hYp3dN8bfjtH2KLe8= github.com/iden3/go-iden3-core v0.0.11 h1:Msi8F6n5e755OMer+7ZV03z04GnQtoTNboKwfrDgB9A= github.com/iden3/go-iden3-core v0.0.11/go.mod h1:Ou51YR716WqeBJ3Z4BkGVAJROgSYgfnl4i8x3mfLOeY= github.com/iden3/go-iden3-crypto v0.0.5/go.mod h1:XKw1oDwYn2CIxKOtr7m/mL5jMn4mLOxAxtZBRxQBev8= @@ -312,7 +312,6 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs= github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= diff --git a/proofs/zeroknowledge/proof.go b/proofs/zeroknowledge/proof.go index 8568fef..24e43f3 100644 --- a/proofs/zeroknowledge/proof.go +++ b/proofs/zeroknowledge/proof.go @@ -11,7 +11,7 @@ var supportedCircuits = map[circuits.CircuitID]types.CircuitData{ ID: circuits.KycBySignaturesCircuitID, Description: "circuit for kyc claims verification", VerificationKey: circuits.KycBySignaturesVerificationKey, - Metadata: circuits.KycPublicSignalsSchema, + Metadata: circuits.KycBySignaturesPublicSignalsSchema, }, circuits.AuthCircuitID: { ID: circuits.AuthCircuitID, diff --git a/proofs/zeroknowledge/proof_test.go b/proofs/zeroknowledge/proof_test.go index 4a1b019..05027ac 100644 --- a/proofs/zeroknowledge/proof_test.go +++ b/proofs/zeroknowledge/proof_test.go @@ -13,51 +13,25 @@ func TestVerifyProof(t *testing.T) { proofMessage := &types.ZeroKnowledgeProof{} proofMessage.CircuitID = circuits.KycBySignaturesCircuitID proofMessage.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", }, } - proofMessage.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", - } + proofMessage.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"} + proofMessage.Type = "zeroknowledge" err = VerifyProof(proofMessage) diff --git a/verification/proof_test.go b/verification/proof_test.go index 907c563..c52c547 100644 --- a/verification/proof_test.go +++ b/verification/proof_test.go @@ -2,7 +2,6 @@ package verification import ( "github.com/iden3/go-circom-prover-verifier/parsers" - types2 "github.com/iden3/go-circom-prover-verifier/types" "github.com/iden3/go-circom-prover-verifier/verifier" "github.com/iden3/go-circuits" "github.com/stretchr/testify/assert" @@ -12,22 +11,20 @@ import ( func TestVerify(t *testing.T) { // verifyGroth16 the proofs - vkJSON := []byte(circuits.KycBySignaturesCircuitID) + vkJSON := []byte(circuits.KycBySignaturesVerificationKey) - publicJSON := []byte(`["411744492472830263284610159093112301866082562595864436469836164448155795456","12345","123776615674577205629582240968408410063074486679712932519574537196926599168","11688539338838797595201345228132404230382121068811390693927054959014251630145","840","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","123776615674577205629582240968408410063074486679712932519574537196926599168","11688539338838797595201345228132404230382121068811390693927054959014251630145","2021","4","25","18"]`) + publicJSON := []byte(`["12345","372902514040400364441393275265861152892555341750332828757240276565437644800","19443506635601976434000063402326775248489014592264899338419890539515181882284","840","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","372902514040400364441393275265861152892555341750332828757240276565437644800","19443506635601976434000063402326775248489014592264899338419890539515181882284","2021","4","25"]`) - proofJSON := []byte(`{"pi_a":"1d0d50f3df112a8d63fc899f900aa074f7eef2cd8efacf9d5cfee68734289f3a26de558d575bafd06ca5b6b5944d19877e5ea5f3c70c39f855e06069589c835c","pi_b":"2850c86effe287d308edbc711d0340dfae447cf1da1fcdcea93c0619ad73eeae02a0e91a72b7334da417160476ade6bb09d7631da7d76e991f49b59d3ccdd43e2cc4c23b8937a172ad9b3e825a979fce9239a7d5c3eaf3a44496005b6f3d59a6248dae2b3c124f025877062bbf90fbaff48634584c8065c6c14765bd97947e54","pi_c":"242cb3ab3c64530f69303a64eaf74ffa42511b7af16e29189070258d462346491fa67f85df1c16215540e932c85f626fa8a11fb21f14cb12b7b925041c8842a6"}`) - - public, err := parsers.ParsePublicSignals(publicJSON) + p := `{"pi_a":["10441536817202584897377823144827964642356918402871315490038163167310235469676","3188873104904010906845899057040012497857652125001996465924027367142766788060","1"],"pi_b":[["10259767950868305572343651918722890484304440255374794205464892311274784569874","18113532891970083775734522192028652126404157383671158241782353379080674688210"],["20011188305329655231409527762393912898857036946232895893305954758470171745705","19212224402431449690017436050830610655559646158634403540885275057516508525272"],["1","0"]],"pi_c":["17410066358263445906462947561105622363737416663317734129930901016400750644236","10889346016675221860511647187111664354773325795907973404602900127856769668544","1"],"protocol":"groth16"}` + proof, err := parsers.ParseProof([]byte(p)) require.Nil(t, err) - var proof types2.Proof - err = proof.UnmarshalJSON(proofJSON) + public, err := parsers.ParsePublicSignals(publicJSON) require.Nil(t, err) vk, err := parsers.ParseVk(vkJSON) require.Nil(t, err) - res := verifier.Verify(vk, &proof, public) + res := verifier.Verify(vk, proof, public) assert.True(t, res) }