Skip to content

Commit

Permalink
if selective disclosure field name is a dot-separated path, create ne…
Browse files Browse the repository at this point in the history
…sted object from it
  • Loading branch information
olomix committed Jul 12, 2023
1 parent 27ea06c commit def6d97
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 13 deletions.
13 changes: 13 additions & 0 deletions inputs_sig.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,16 @@ func verifiablePresentationFromCred(ctx context.Context,
return
}

func mkVPObj(field string, value any) (string, any) {
idx := strings.Index(field, ".")
if idx == -1 {
return field, value
}

nestedField, value := mkVPObj(field[idx+1:], value)
return field[:idx], map[string]any{nestedField: value}
}

func fmtVerifiablePresentation(context string, tp string, field string,
value any) map[string]any {

Expand All @@ -510,6 +520,9 @@ func fmtVerifiablePresentation(context string, tp string, field string,
vcTypes = append(vcTypes, tp)
}

// if field name is a dot-separated path, create nested object from it.
field, value = mkVPObj(field, value)

return map[string]any{
"@context": baseContext,
"@type": "VerifiablePresentation",
Expand Down
44 changes: 44 additions & 0 deletions inputs_sig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,50 @@ func TestPrepareInputs(t *testing.T) {
"", AtomicQuerySigV2InputsFromJson, nil, cfg,
"credential is revoked")
})

t.Run("AtomicQuerySigV2InputsFromJson Nested Disclosure", func(t *testing.T) {

ipfsURL := os.Getenv("IPFS_URL")
if ipfsURL == "" {
t.Skip("IPFS_URL is not set")
}

cid := uploadIPFSFile(t, ipfsURL, "testdata/ipfs_QmcAJCriUKiU4WQogfhqpi6j8S8XTmZdmg7hpaVr4eGynW.json-ld")
// CID should correspond to the URL
require.Equal(t, "QmcAJCriUKiU4WQogfhqpi6j8S8XTmZdmg7hpaVr4eGynW", cid)

defer mockHttpClient(t, map[string]string{
"https://www.w3.org/2018/credentials/v1": "testdata/httpresp_credentials_v1.json",
"https://dev.polygonid.me/api/v1/identities/did%3Apolygonid%3Apolygon%3Amumbai%3A2qLPqvayNQz9TA2r5VPxUugoF18teGU583zJ859wfy/claims/revocation/status/214490175": "testdata/httpresp_rev_status_214490175.json",
"https://dev.polygonid.me/api/v1/identities/did%3Apolygonid%3Apolygon%3Amumbai%3A2qLPqvayNQz9TA2r5VPxUugoF18teGU583zJ859wfy/claims/revocation/status/2575161389": "testdata/httpresp_rev_status_2575161389.json",
"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld": "testdata/httpresp_iden3proofs.jsonld",
})()

wantVerifiablePresentation := map[string]any{
"@context": []any{"https://www.w3.org/2018/credentials/v1"},
"@type": "VerifiablePresentation",
"verifiableCredential": map[string]any{
"@context": []any{
"https://www.w3.org/2018/credentials/v1",
"ipfs://QmcAJCriUKiU4WQogfhqpi6j8S8XTmZdmg7hpaVr4eGynW",
},
"@type": []any{"VerifiableCredential", "DeliveryAddress"},
"credentialSubject": map[string]any{
"@type": "DeliveryAddress",
"postalProviderInformation": map[string]any{
"address1": map[string]any{
"name": "addressName",
},
},
},
},
}

doTest(t, "atomic_query_sig_v2_nested_selective_disclosure_inputs.json",
"atomic_query_sig_v2_nested_selective_disclosure_output.json",
AtomicQuerySigV2InputsFromJson, wantVerifiablePresentation,
EnvConfig{IPFSNodeURL: ipfsURL}, "")
})
}

func TestEnvConfig_UnmarshalJSON(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion testdata/atomic_query_mtp_v2_on_chain_status_output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"requestID":"1","userGenesisID":"21889130108254823615772876373128037217273062530127827364430428043065561602","profileNonce":"0","claimSubjectProfileNonce":"0","issuerID":"15581991792744269396064499510702144339217099104593719362405988930886308354","issuerClaim":["14559690932601973492667815902177586678096","21889130108254823615772876373128037217273062530127827364430428043065561602","15697636742427174942378579399424652827970443118166160513092687461470682485670","0","34928098246829792765314585820","0","0","0"],"issuerClaimMtp":["10660818590108639428871982872591489586183290725077275050593284687717172079964","19004583404027319386260877934866626052185781987882873664881072886791630045709","7688551737818240300462500951153481472047294955944044944287841608520632560800","17769487165855930261808351867030953601566316638365313132919095596635885953664","5161693871597286563237588861621057258574279578037312916501715191991470717054","0","0","13324322751273822110620689916704453645987815620794505188533106956429795192902","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerClaimClaimsTreeRoot":"15815313521304851418109067406329464655146418617011377781665616752769897127623","issuerClaimRevTreeRoot":"11962371738883302451524073240861657820349762867024192047397723064194456442418","issuerClaimRootsTreeRoot":"784112478200635040281186990104584409460466157583484839862858223721265258518","issuerClaimIdenState":"20792792603493945806129151122571708658758527512006564312672633241149756273094","issuerClaimNonRevClaimsTreeRoot":"5769420190957475207645102914228801838856588013032559096759080697894420395339","issuerClaimNonRevRevTreeRoot":"11962371738883302451524073240861657820349762867024192047397723064194456442418","issuerClaimNonRevRootsTreeRoot":"19366998096494315454647646959772577850327490978723945038065377546216608821866","issuerClaimNonRevState":"17965448550532712274287845555480752152272481042513305139308272327671568240820","issuerClaimNonRevMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerClaimNonRevMtpAuxHi":"2427988165","issuerClaimNonRevMtpAuxHv":"0","issuerClaimNonRevMtpNoAux":"0","isRevocationChecked":1,"claimSchema":"267831521922558027206082390043321796944","claimPathNotExists":0,"claimPathMtp":["16534428042297633750175000595232097716970128921344508808444542188109524671092","20136408412065421871169513346531928107929237932885840151844569675458908229318","16506659259489187604743512498132257380255841690580446590907927947486131590921","0","21618960417349819791327026112686919154102464675974390953288772823522767060833","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"claimPathMtpNoAux":"0","claimPathMtpAuxHi":"0","claimPathMtpAuxHv":"0","claimPathKey":"20376033832371109177683048456014525905119173674985843915445634726167450989630","claimPathValue":"19960424","operator":1,"slotIndex":0,"timestamp":1687645152,"value":["19960424","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]}
{"requestID":"1","userGenesisID":"21889130108254823615772876373128037217273062530127827364430428043065561602","profileNonce":"0","claimSubjectProfileNonce":"0","issuerID":"15581991792744269396064499510702144339217099104593719362405988930886308354","issuerClaim":["14559690932601973492667815902177586678096","21889130108254823615772876373128037217273062530127827364430428043065561602","15697636742427174942378579399424652827970443118166160513092687461470682485670","0","34928098246829792765314585820","0","0","0"],"issuerClaimMtp":["10660818590108639428871982872591489586183290725077275050593284687717172079964","19004583404027319386260877934866626052185781987882873664881072886791630045709","7688551737818240300462500951153481472047294955944044944287841608520632560800","17769487165855930261808351867030953601566316638365313132919095596635885953664","5161693871597286563237588861621057258574279578037312916501715191991470717054","0","0","13324322751273822110620689916704453645987815620794505188533106956429795192902","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerClaimClaimsTreeRoot":"15815313521304851418109067406329464655146418617011377781665616752769897127623","issuerClaimRevTreeRoot":"11962371738883302451524073240861657820349762867024192047397723064194456442418","issuerClaimRootsTreeRoot":"784112478200635040281186990104584409460466157583484839862858223721265258518","issuerClaimIdenState":"20792792603493945806129151122571708658758527512006564312672633241149756273094","issuerClaimNonRevClaimsTreeRoot":"5769420190957475207645102914228801838856588013032559096759080697894420395339","issuerClaimNonRevRevTreeRoot":"11962371738883302451524073240861657820349762867024192047397723064194456442418","issuerClaimNonRevRootsTreeRoot":"19366998096494315454647646959772577850327490978723945038065377546216608821866","issuerClaimNonRevState":"17965448550532712274287845555480752152272481042513305139308272327671568240820","issuerClaimNonRevMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerClaimNonRevMtpAuxHi":"2427988165","issuerClaimNonRevMtpAuxHv":"0","issuerClaimNonRevMtpNoAux":"0","isRevocationChecked":1,"claimSchema":"267831521922558027206082390043321796944","claimPathNotExists":0,"claimPathMtp":["16534428042297633750175000595232097716970128921344508808444542188109524671092","12073640998350984734151051363345371934379331094683260764481179727743582419200","4152566071195257884814206217928869294080907926700402283006563196412405035501","0","21618960417349819791327026112686919154102464675974390953288772823522767060833","0","0","0","598337659919446409842087827958890174831314627207995246981557068766765928775","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"claimPathMtpNoAux":"0","claimPathMtpAuxHi":"0","claimPathMtpAuxHv":"0","claimPathKey":"20376033832371109177683048456014525905119173674985843915445634726167450989630","claimPathValue":"19960424","operator":1,"slotIndex":0,"timestamp":1689169530,"value":["19960424","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"id": "2qMELfwwoRkhwjNh4qbZekm7rFddwWb2rTcHYkCh63",
"profileNonce": "123",
"claimSubjectProfileNonce": "234",
"verifiableCredentials": {
"id": "https://dev.polygonid.me/api/v1/identities/did:polygonid:polygon:mumbai:2qLPqvayNQz9TA2r5VPxUugoF18teGU583zJ859wfy/claims/9b401f13-20b1-11ee-9b72-0242ac1d0007",
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld",
"ipfs://QmcAJCriUKiU4WQogfhqpi6j8S8XTmZdmg7hpaVr4eGynW"
],
"type": [
"VerifiableCredential",
"DeliveryAddress"
],
"expirationDate": "2030-01-07T00:00:00Z",
"issuanceDate": "2023-07-12T12:42:48.103469079Z",
"credentialSubject": {
"deliveryTime": "2022-02-02T00:00:00Z",
"homeAddress": {
"line1": "l1",
"line2": "l2"
},
"id": "did:polygonid:polygon:mumbai:2qMELfwwoRkhwjNh4qbZekm7rFddwWb2rTcHYkCh63",
"isPostalProvider": true,
"postalProviderInformation": {
"address1": {
"name": "addressName"
},
"name": "n1",
"officeNo": 123
},
"price": 3.1,
"type": "DeliveryAddress"
},
"credentialStatus": {
"id": "https://dev.polygonid.me/api/v1/identities/did%3Apolygonid%3Apolygon%3Amumbai%3A2qLPqvayNQz9TA2r5VPxUugoF18teGU583zJ859wfy/claims/revocation/status/214490175",
"revocationNonce": 214490175,
"type": "SparseMerkleTreeProof"
},
"issuer": "did:polygonid:polygon:mumbai:2qLPqvayNQz9TA2r5VPxUugoF18teGU583zJ859wfy",
"credentialSchema": {
"id": "ipfs://QmX1aAdypawZoVXZ2YT8fHgapeRtDhnP96vPg2Btoe1Ujz",
"type": "JsonSchema2023"
},
"proof": [
{
"type": "BJJSignature2021",
"issuerData": {
"id": "did:polygonid:polygon:mumbai:2qLPqvayNQz9TA2r5VPxUugoF18teGU583zJ859wfy",
"state": {
"txId": "0xde8c8e234e9e4c159b9ce6361234c15eaaa123bddf15f395489a75e634e11182",
"blockTimestamp": 1683792462,
"blockNumber": 35452981,
"rootOfRoots": "03beaa14074a91698084d2dc077067babb8334584a7d73a047e6b238341b581d",
"claimsTreeRoot": "a5faef8b1fc67f65c55ad667919e51abfed008ca97475c41b26a5e70fd4c4a0a",
"revocationTreeRoot": "0000000000000000000000000000000000000000000000000000000000000000",
"value": "5ab768f8f2ec3f94e6830908fbf428ca3386ff87a5e704fcd1f11cae3420611f"
},
"authCoreClaim": "cca3371a6cb1b715004407e325bd993c080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e3b9e422feb1dcf83882b33bddf3c9a64d300e2280e9c286bb75839c824ace27c5560b8ca92be27698a14f6970c32731e73768d74fe83d0fd4f16f14b4402d242dd87d9900000000281cdcdf0200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"mtp": {
"existence": true,
"siblings": [
"16600125203338042323361216512603158366636445287571403125891881295088432028008",
"11315256355804790111057838658876672619892914293003422319088357823149445991751",
"5953630948937947438067785504646477838099205855387889079750411149043045455341",
"7144700925452824210038939338852356191428773494854012082867969138805603048585",
"3921545027306074721354497759643961758048633515411954472382458013486548057049",
"0",
"0",
"5436254548464410857916946211162171910597645182542037135954554779197265908702"
]
},
"credentialStatus": {
"id": "https://dev.polygonid.me/api/v1/identities/did%3Apolygonid%3Apolygon%3Amumbai%3A2qLPqvayNQz9TA2r5VPxUugoF18teGU583zJ859wfy/claims/revocation/status/2575161389",
"revocationNonce": 2575161389,
"type": "SparseMerkleTreeProof"
}
},
"coreClaim": "2feab48f30556e1d360007ba70de6c0b2a0000000000000000000000000000000212c10920c6b9e7785793a5476724d306bca0d820017ea61b5f6886534a0c002b5c94984280d3e02c5bc84e404894ac2fa978d36d6c5fbb8b169a4e754ef72b00000000000000000000000000000000000000000000000000000000000000003fdcc80c0000000080c1e3700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"signature": "f0bf038137d09c57fe214d74262320137bbb83c83ed827bb7f376d29ac7a441743ee46521e54735fc9e33ece2b1624f3c767a1567f84e011aa02b8c83ba37201"
}
]
},
"request": {
"id": 84239,
"circuitId": "credentialAtomicQuerySigV2",
"query": {
"allowedIssuers": "unused",
"context": "ipfs://QmcAJCriUKiU4WQogfhqpi6j8S8XTmZdmg7hpaVr4eGynW",
"type": "DeliveryAddress",
"credentialSubject": {
"postalProviderInformation.address1.name": {}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"requestID":"84239","userGenesisID":"21715145837359521933715514511895502047374845187585074005685783165315125762","profileNonce":"123","claimSubjectProfileNonce":"234","issuerID":"22942594156266665426613462771725327314382647426959044863446866613003751938","issuerClaim":["14307046198319830189021749001476556253743","21715145837359521933715514511895502047374845187585074005685783165315125762","19886405212887272255413097588107697207559546546321203245433309161608659098667","0","34937661038957603796397120575","0","0","0"],"issuerClaimNonRevClaimsTreeRoot":"2273017883386303214371303687972676397834901290161619866164194365200553743608","issuerClaimNonRevRevTreeRoot":"20886334301348796748779732232529938054780668195423799235723157520872439548281","issuerClaimNonRevRootsTreeRoot":"12831100563256723258095688566537173268640232986869077257277662735504334139048","issuerClaimNonRevState":"3156341134011552663235425055480181548208096702736185574734553897002545383321","issuerClaimNonRevMtp":["15068099395710279209116088766932267224585678575226717643047729221232916765468","2189070759111494123563493081161468940989812407956040534473128738739860911255","7477205790926779541080640660120305745755434522417143837504559066770052488949","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerClaimNonRevMtpAuxHi":"4136705639","issuerClaimNonRevMtpAuxHv":"0","issuerClaimNonRevMtpNoAux":"0","claimSchema":"15186787640414723560015489342291372591","issuerClaimSignatureR8x":"10450003244126866216196892273805496689430300141271848020719272730442755999530","issuerClaimSignatureR8y":"10524187772347925406661476818307564621153246709294367680347709611682442756080","issuerClaimSignatureS":"654860010397538250500859474929589702562454725713804235343310023326404374083","issuerAuthClaim":["2802810872911077472734549448614968009676","0","18004685840597262513177977764109198106190983513152532833229741162935913593315","16363217233621509147493247026329953659261800857040913370796979771313744467653","227737578863135127232172644397","0","0","0"],"issuerAuthClaimMtp":["16600125203338042323361216512603158366636445287571403125891881295088432028008","11315256355804790111057838658876672619892914293003422319088357823149445991751","5953630948937947438067785504646477838099205855387889079750411149043045455341","7144700925452824210038939338852356191428773494854012082867969138805603048585","3921545027306074721354497759643961758048633515411954472382458013486548057049","0","0","5436254548464410857916946211162171910597645182542037135954554779197265908702","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerAuthClaimNonRevMtp":["15068099395710279209116088766932267224585678575226717643047729221232916765468","12503617142493591559542830210106860642149788086756524276444903023773514357063","15494200977157294465144225269510752380944794946007603451617789527754422425328","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerAuthClaimNonRevMtpAuxHi":"0","issuerAuthClaimNonRevMtpAuxHv":"0","issuerAuthClaimNonRevMtpNoAux":"1","issuerAuthClaimsTreeRoot":"4654406534048944674417006311067465112472974884603602143521678033930482088613","issuerAuthRevTreeRoot":"0","issuerAuthRootsTreeRoot":"13272742905654896452483910063874611565255576170014837106221371541741479050755","isRevocationChecked":1,"claimPathNotExists":0,"claimPathMtp":["2756401501881287459939851604031584574585325012994135273806303908446485628253","21775361197413724229226684499705629957213261514539923323334069982893301189149","2495985945207058213195117170524008247208843076678549066181537608007515894141","0","0","0","20773690219808308743568139423198279465852083475933602111112569109080126125174","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"claimPathMtpNoAux":"0","claimPathMtpAuxHi":"0","claimPathMtpAuxHv":"0","claimPathKey":"2406798944181380033691194242784402730738613510248396192158687726626494205917","claimPathValue":"13526184782216181167557375564702157805009102812029373236610478212247032949768","operator":1,"slotIndex":0,"timestamp":1689169612,"value":["13526184782216181167557375564702157805009102812029373236610478212247032949768","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]}
Loading

0 comments on commit def6d97

Please sign in to comment.