Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aadhaar circuit #88

Draft
wants to merge 12 commits into
base: generic_inputs
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.23.4
go-version: 1.23.5
- uses: golangci/golangci-lint-action@v6
with:
version: v1.63.4
4 changes: 2 additions & 2 deletions .github/workflows/tests-c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
containers:
- 1.22.5-bookworm
- 1.23.5-bookworm
runs-on: ubuntu-24.04
container: golang:${{matrix.containers}}
steps:
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22.5
go-version: 1.23.5
- uses: actions/cache@v4
with:
path: |
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ jobs:
strategy:
matrix:
go_version:
- "1.22.10"
- "1.23.4"
- "1.23.5"
runs-on: ubuntu-24.04
env:
IPFS_URL: http://localhost:5001
Expand Down
15 changes: 15 additions & 0 deletions aadhaar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package c_polygonid

import (
gocircuitexternal "github.com/0xPolygonID/go-circuit-external"

Check failure on line 4 in aadhaar.go

View workflow job for this annotation

GitHub Actions / test (1.23.5)

github.com/0xPolygonID/go-circuit-external@v0.0.0: replacement directory ../go-circuit-external does not exist
)

type anonAadhaarV1Inputs struct {
QRData *jsonNumber `json:"qrData"`
gocircuitexternal.AnonAadhaarV1Inputs
}

func (a *anonAadhaarV1Inputs) asAnonAadhaarV1Inputs() *gocircuitexternal.AnonAadhaarV1Inputs {
a.AnonAadhaarV1Inputs.QRData = a.QRData.toBitInt()
return &a.AnonAadhaarV1Inputs
}
49 changes: 49 additions & 0 deletions aadhaar_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package c_polygonid

import (
"encoding/json"
"math/big"
"os"
"testing"

gocircuitexternal "github.com/0xPolygonID/go-circuit-external"
"github.com/stretchr/testify/require"
)

func toBigInt(in string) *big.Int {
i, ok := new(big.Int).SetString(in, 10)
if !ok {
panic(in)
}
return i
}

func TestAnonAadhaarV1Inputs_UnmarshalJSON(t *testing.T) {
d, err := os.ReadFile("testdata/anon_aadhaar_v1_inputs.json")
require.NoError(t, err)

var inputs anonAadhaarV1Inputs
err = json.Unmarshal(d, &inputs)
require.NoError(t, err)

want := &gocircuitexternal.AnonAadhaarV1Inputs{
QRData: toBigInt("8259163575998395410294216884136380576185817320339145460288951755287582961380611852552428987321584902318624273479337130653734982789439199350807739714406680256506601030028361685736660257517232716829232450159251789263870750283214820475102793105777087762238893090228084052270739203426767272062178826235941508196284529472654271516164224874687419158221021213944829682919423174703783469927383220474654008065915029614141226522064062660593170425792840873655513538373377850112144063189928583588899889878172757870400281696669604010659786496608127700010264443115263361656744433002559396889060190428705316366290450741550935385486607346514118464415324976934593027192262025619948063647667007927187736245772179085671658409804311603784752615097922989017361163561315974008304022542448394278143245816470881130080719485003834016131185071765229491892891069788319670287394271744730364788949609836924781874523936880888005883165757273872375006288978183466996520618718348187182821516617721340861010989807614756396013627238651856164981477576514065364628430139194213240602981419233621531616776712580234318576148789862972873366521755587675635811636464535551028275057950562020714225333126426609311459495088802145911084644641596208432517247324679678535859879970296810837735288916946197174410518342751033634782712968162882714769666441813893046220965525694847349131353986974388432968669605721975441870936552792275255624723251162192468002453471184713983574359601113515796454264270501379717344206777921353459767049560942843350534472442799601294637063232419543855742825887931841338302499933012059977947394755335155868283405337181095220998277373266658634859632929226320059674299759100792654417315629048732480315019941928105082550091217622422743467170706956093632228513797781797454779203616427853022505097310749994766657051986303478622173767936568165644251615127773430128638507677775244195799780291921828512257290767451475181728141544788756907393883042588060697683541401090581157249784874529424005078918452607589129440476242749110421616270676359722523229311894327359615548588038186027827017569331332262329182564217789843145105509621002324556840213928256545454178891208004109769624959566302976213521762873815749009289995208912424872527724417047936432945498377307452190302923489092664437908497749093491199476080757200233878726847198496754472664256996743796092233459542884818717466621372105594672115988382565552756801323160697003960485232732393383241422077506009076922303757067128564302338914230360252223406874457414109774901980252709597099278192874164252010830754720603092419792069707099362278082792090307065378744856387301364608460967253691290230861162587170799141457093188189022390589265654613500974699477990974878105678883229707694455342266695530373994049224098435972125150350136428446936271698977517627416435999970351222450833295217051468307037908262231982382247410542334757724852032521780157518474618653527191342825230455100778913195115477763082159513429761573752871477695723697689470263993132596482716347199834315782099668846081963760553679915994617396376870314998926788197388410764535427795200340714967872713095483294486407886767431404892448155562283436571050452251042117926586451385682519188252281397"),
CredentialSubjectID: "did:iden3:privado:main:2Scn2RfosbkQDMQzQM5nCz3Nk5GnbzZCWzGCd3tc2G",
CredentialStatusRevocationNonce: 954548273,
CredentialStatusID: "https://issuer-node-core-api-demo.privado.id/v2/agent",
IssuerID: "did:iden3:privado:main:2Si3eZUE6XetYsmU5dyUK2Cvaxr1EEe65vdv2BML4L",
PubKey: `-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlegfdQZZXMJirdz93TXY
BAVbKt9G3HGcVrWO7hmZle+hoyVHEGIKx4Ael29E475FTbDxkOP31ONZiXIRc0Te
Uvz3gm+ElIipWaez0h623QNFFmLqiD7u796ImhSZuaR/lQTF8JbCYrltI9GXUDMt
npfrYUHSYd6XmU1MQWPKnL4+B3IhtEJT3PgWCUKLaDUe4+m2DSs1H9qm7owoqEUj
n5fefMD+XRROR0gT+0PsWD+BtO4yjCIWczSJjSELoBeibsaJQPBd8ivZzIa7w6Q1
Q5I3LVZhZ3abc1uhLKNYD5GcG9i6cMTCqwrPKwm8L66YHzwClabh6fJI9QBzCU/6
8QIDAQAB
-----END PUBLIC KEY-----`,
NullifierSeed: 12345678,
SignalHash: 1001,
}

require.Equal(t, want, inputs.asAnonAadhaarV1Inputs())
}
15 changes: 15 additions & 0 deletions cmd/polygonid/polygonid.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
char *error_msg;
} PLGNStatus;
*/
import "C"

Check failure on line 35 in cmd/polygonid/polygonid.go

View workflow job for this annotation

GitHub Actions / lint

could not import C (cgo preprocessing failed) (typecheck)

import (
"context"
Expand Down Expand Up @@ -288,6 +288,14 @@
status)
}

//export PLGNW3CCredentialToCoreClaim
func PLGNW3CCredentialToCoreClaim(jsonResponse **C.char, in *C.char, cfg *C.char,
status **C.PLGNStatus) bool {

return callGenericFn(c_polygonid.W3CCredentialToCoreClaim, jsonResponse, in,
cfg, status)
}

//export PLGNCreateClaim
func PLGNCreateClaim(jsonResponse **C.char, in *C.char,
status **C.PLGNStatus) (ok bool) {
Expand Down Expand Up @@ -926,6 +934,13 @@
return true
}

//export PLGNW3CCredentialFromAnonAadhaarInputs
func PLGNW3CCredentialFromAnonAadhaarInputs(jsonResponse **C.char, in *C.char,
cfg *C.char, status **C.PLGNStatus) bool {
return callGenericFn(c_polygonid.W3cCredentialsFromAnonAadhaarInputsJson,
jsonResponse, in, cfg, status)
}

// PLGNDescribeID parses ID and return it in different representations.
// Request example:
//
Expand Down
14 changes: 9 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
module github.com/0xPolygonID/c-polygonid

go 1.22
go 1.23.5

require (
github.com/0xPolygonID/go-circuit-external v0.0.0
github.com/dgraph-io/badger/v4 v4.5.0
github.com/ethereum/go-ethereum v1.14.12
github.com/iden3/go-circuits/v2 v2.4.1-0.20250116125441-51815c3526f8
github.com/iden3/go-iden3-core/v2 v2.3.1
github.com/iden3/go-iden3-crypto v0.0.17
github.com/iden3/go-merkletree-sql/v2 v2.0.6
github.com/iden3/go-onchain-credential-adapter v0.0.0-20240425110009-4004ac8da50c
github.com/iden3/go-schema-processor/v2 v2.6.0
github.com/iden3/go-schema-processor/v2 v2.6.1
github.com/iden3/iden3comm/v2 v2.7.0
github.com/iden3/merkletree-proof v0.3.0
github.com/piprate/json-gold v0.5.1-0.20241210232033-19254b3ec65b
Expand All @@ -29,15 +30,15 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dchest/blake512 v1.0.0 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/dgraph-io/ristretto/v2 v2.0.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564 // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/flatbuffers v24.3.25+incompatible // indirect
github.com/google/uuid v1.6.0 // indirect
Expand All @@ -53,11 +54,13 @@ require (
github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 // indirect
github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/lestrrat-go/blackmagic v1.0.1 // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/httprc v1.0.4 // indirect
github.com/lestrrat-go/httprc/v3 v3.0.0-beta1 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx/v2 v2.0.12 // indirect
github.com/lestrrat-go/jwx/v3 v3.0.0-alpha1 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand Down Expand Up @@ -89,3 +92,4 @@ require (

//replace github.com/iden3/go-circuits => ../go-circuits
//replace github.com/iden3/go-schema-processor/v2 => ../go-schema-processor
replace github.com/0xPolygonID/go-circuit-external => ../go-circuit-external
17 changes: 12 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80N
github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/dgraph-io/badger/v4 v4.5.0 h1:TeJE3I1pIWLBjYhIYCA1+uxrjWEoJXImFBMEBVSm16g=
github.com/dgraph-io/badger/v4 v4.5.0/go.mod h1:ysgYmIeG8dS/E8kwxT7xHyc7MkmwNYLRoYnFbr7387A=
github.com/dgraph-io/ristretto/v2 v2.0.0 h1:l0yiSOtlJvc0otkqyMaDNysg8E9/F/TYZwMbxscNOAQ=
Expand Down Expand Up @@ -77,8 +78,9 @@ github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
Expand Down Expand Up @@ -159,8 +161,8 @@ github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepi
github.com/iden3/go-rapidsnark/witness/v2 v2.0.0/go.mod h1:3JRjqUfW1hgI9hzLDO0v8z/DUkR0ZUehhYLlnIfRxnA=
github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e h1:WeiFCrpj5pLRtSA4Mg03yTrSZhHHqN/k5b6bwxd9/tY=
github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e/go.mod h1:UEBifEzw62T6VzIHJeHuUgeLg2U/J9ttf7hOwQEqnYk=
github.com/iden3/go-schema-processor/v2 v2.6.0 h1:5KWXtzwER/ftuTofuLJNEoQqRoX2UlnrmLvFmprgycs=
github.com/iden3/go-schema-processor/v2 v2.6.0/go.mod h1:MYrkk55aEx3ZBKz0d/0rfxa7lBH4x9TfKGI1T/WBlpw=
github.com/iden3/go-schema-processor/v2 v2.6.1 h1:KD33sTAu2xAyG94SmrUAMxI+MREFTmSsavYy70gkTW4=
github.com/iden3/go-schema-processor/v2 v2.6.1/go.mod h1:MYrkk55aEx3ZBKz0d/0rfxa7lBH4x9TfKGI1T/WBlpw=
github.com/iden3/iden3comm/v2 v2.7.0 h1:VTFCUQXywXepB+3ylamHFibmOEU1yplBx9Q9zC1MQbA=
github.com/iden3/iden3comm/v2 v2.7.0/go.mod h1:ZRnfFg4geX336Bp9+29ZQdSqchbsBoVcd7ARn6JXH5Y=
github.com/iden3/merkletree-proof v0.3.0 h1:NVlvtUBEgn4Etxxn+RsOmXP/qlI+85BdN8oUDTf3mxI=
Expand All @@ -179,16 +181,21 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/lestrrat-go/blackmagic v1.0.1 h1:lS5Zts+5HIC/8og6cGHb0uCcNCa3OUt1ygh3Qz2Fe80=
github.com/lestrrat-go/blackmagic v1.0.1/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU=
github.com/lestrrat-go/blackmagic v1.0.2 h1:Cg2gVSc9h7sz9NOByczrbUvLopQmXrfFx//N+AkAr5k=
github.com/lestrrat-go/blackmagic v1.0.2/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU=
github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE=
github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E=
github.com/lestrrat-go/httprc v1.0.4 h1:bAZymwoZQb+Oq8MEbyipag7iSq6YIga8Wj6GOiJGdI8=
github.com/lestrrat-go/httprc v1.0.4/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo=
github.com/lestrrat-go/httprc/v3 v3.0.0-beta1 h1:pzDjP9dSONCFQC/AE3mWUnHILGiYPiMKzQIS+weKJXA=
github.com/lestrrat-go/httprc/v3 v3.0.0-beta1/go.mod h1:wdsgouffPvWPEYh8t7PRH/PidR5sfVqt0na4Nhj60Ms=
github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI=
github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4=
github.com/lestrrat-go/jwx/v2 v2.0.12 h1:3d589+5w/b9b7S3DneICPW16AqTyYXB7VRjgluSDWeA=
github.com/lestrrat-go/jwx/v2 v2.0.12/go.mod h1:Mq4KN1mM7bp+5z/W5HS8aCNs5RKZ911G/0y2qUjAQuQ=
github.com/lestrrat-go/jwx/v3 v3.0.0-alpha1 h1:IKsSdax3m7zsi4ooThn7YR74PMsx8fqcLcEeA6164nI=
github.com/lestrrat-go/jwx/v3 v3.0.0-alpha1/go.mod h1:JLWHVwLtN56LfSrlpyjhvKEdG00MTYOrmzLIJkrCeDw=
github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU=
github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
Expand Down
93 changes: 93 additions & 0 deletions inputs_sig.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"sync"
"time"

gocircuitexternal "github.com/0xPolygonID/go-circuit-external"
"github.com/dgraph-io/badger/v4"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
Expand Down Expand Up @@ -1168,6 +1169,8 @@ func GenericInputsFromJson(ctx context.Context, cfg EnvConfig,
return LinkedMultiQueryInputsFromJson(ctx, cfg, in)
case circuits.AuthV2CircuitID:
return AuthV2InputsFromJson(ctx, cfg, in)
case gocircuitexternal.AnonAadhaarV1:
return AnonAadhaarInputsFromJson(ctx, cfg, in)
}

return AtomicQueryInputsResponse{}, errors.New("unknown circuit")
Expand Down Expand Up @@ -2657,3 +2660,93 @@ func AuthV2InputsFromJson(_ context.Context, _ EnvConfig,

return out, nil
}

func AnonAadhaarInputsFromJson(ctx context.Context, cfg EnvConfig,
in []byte) (AtomicQueryInputsResponse, error) {

var out AtomicQueryInputsResponse
var inputs anonAadhaarV1Inputs
err := json.Unmarshal(in, &inputs)
if err != nil {
return out, err
}

out.Inputs = inputs.asAnonAadhaarV1Inputs()
return out, nil
}

func W3cCredentialsFromAnonAadhaarInputsJson(ctx context.Context, cfg EnvConfig,
in []byte) (verifiable.W3CCredential, error) {

var inputs anonAadhaarV1Inputs
err := json.Unmarshal(in, &inputs)
if err != nil {
return verifiable.W3CCredential{}, err
}

w3cCred, err := inputs.asAnonAadhaarV1Inputs().W3CCredential()
if err != nil {
return verifiable.W3CCredential{}, err
}

return *w3cCred, nil
}

type CoreClaimResponse struct {
CoreClaim *core.Claim `json:"coreClaim"`
CoreClaimHex string `json:"coreClaimHex"`
CoreClaimIndexHash *JsonBigInt `json:"coreClaimHIndex"`
CoreClaimValueHash *JsonBigInt `json:"coreClaimHValue"`
}

func W3CCredentialToCoreClaim(ctx context.Context, cfg EnvConfig, in []byte) (CoreClaimResponse, error) {
var req struct {
W3CCredential *verifiable.W3CCredential `json:"w3cCredential"`
CoreClaimOptions *verifiable.CoreClaimOptions `json:"coreClaimOptions"`
}
err := json.Unmarshal(in, &req)
if err != nil {
return CoreClaimResponse{}, err
}
if req.W3CCredential == nil {
return CoreClaimResponse{},
errors.New("w3cCredential is not set in the request")
}

if req.CoreClaimOptions == nil {
req.CoreClaimOptions = &verifiable.CoreClaimOptions{
RevNonce: 0,
Version: 0,
SubjectPosition: verifiable.CredentialSubjectPositionIndex,
MerklizedRootPosition: verifiable.CredentialMerklizedRootPositionNone,
Updatable: false,
MerklizerOpts: nil,
}
}

req.CoreClaimOptions.MerklizerOpts = append(
req.CoreClaimOptions.MerklizerOpts,
merklize.WithDocumentLoader(cfg.documentLoader()))

var resp CoreClaimResponse

resp.CoreClaim, err = req.W3CCredential.ToCoreClaim(ctx,
req.CoreClaimOptions)
if err != nil {
return CoreClaimResponse{}, err
}

ih, vh, err := resp.CoreClaim.HiHv()
if err != nil {
return CoreClaimResponse{}, err
}
resp.CoreClaimIndexHash = NewJsonBigInt(ih)
resp.CoreClaimValueHash = NewJsonBigInt(vh)

resp.CoreClaimHex, err = resp.CoreClaim.Hex()
if err != nil {
return CoreClaimResponse{}, err
}

return resp, nil
}
Loading
Loading