Skip to content

Commit

Permalink
feat: more vcs changes
Browse files Browse the repository at this point in the history
  • Loading branch information
skynet2 committed Oct 23, 2024
1 parent 5fbe5d8 commit 12866c2
Show file tree
Hide file tree
Showing 24 changed files with 256 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ALPINE_IMAGE ?=alpine
OPENSSL_IMAGE ?=frapsoft/openssl
GOPROXY ?= https://proxy.golang.org

VC_FRAMEWORK_VERSION = a58759112df5dec505bb1bd37c1baa1c8fcd823c
VC_FRAMEWORK_VERSION = 882ca910f0916f8da048532c0c9d0b9bc51f61eb
KMS_FRAMEWORK_VERSION = 8d9510c6bb88df0666fa45c55c0ace699a675b12
DID_GO_VERSION = 5721a3ff7396cfa3f5e5a64fd409c3edf82ddf94
SIDE_TREE_VERSION = f4260aff710479ba5fa3f0c61b51d451d9041225
Expand Down
3 changes: 2 additions & 1 deletion cmd/vc-rest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/trustbloc/did-go v1.3.1-0.20241021165331-5721a3ff7396
github.com/trustbloc/logutil-go v1.0.0
github.com/trustbloc/sidetree-go v1.0.1-0.20240219121130-f4260aff7104
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091
github.com/trustbloc/vcs v0.0.0
github.com/trustbloc/vcs/component/credentialstatus v0.0.0-00010101000000-000000000000
github.com/trustbloc/vcs/component/echo v0.0.0-00010101000000-000000000000
Expand Down Expand Up @@ -282,6 +282,7 @@ require (
)

replace (
github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f => github.com/skynet2/json-gold v0.6.0
github.com/trustbloc/vcs => ../..
github.com/trustbloc/vcs/component/credentialstatus => ../../component/credentialstatus
github.com/trustbloc/vcs/component/echo => ../../component/echo
Expand Down
8 changes: 4 additions & 4 deletions cmd/vc-rest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,6 @@ github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNH
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f h1:HlPa7RcxTCrva5izPfTEfvYecO7LTahgmMRD1Qp13xg=
github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f/go.mod h1:WZ501QQMbZZ+3pXFPhQKzNwS1+jls0oqov3uQ2WasLs=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -607,6 +605,8 @@ github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/skynet2/json-gold v0.6.0 h1:w64ixhVsG7eqJ/R69U1iyq8LtmBmz0gEzBF9os4DxA8=
github.com/skynet2/json-gold v0.6.0/go.mod h1:RVhE35veDX19r5gfUAR+IYHkAUuPwJO8Ie/qVeFaIzw=
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
Expand Down Expand Up @@ -676,8 +676,8 @@ github.com/trustbloc/logutil-go v1.0.0 h1:KzNs9TRbnmn+M3oYw9UkrtOjNd3ZGO8aLgfYtt
github.com/trustbloc/logutil-go v1.0.0/go.mod h1:JlxT0oZfNKgIlSNtgc001WEeDMxlnAvOM43gNm8DQVc=
github.com/trustbloc/sidetree-go v1.0.1-0.20240219121130-f4260aff7104 h1:0IW4muaGvhjJ4OkG6/PQG3DGf5POWxlA1wwEYsxWQ+4=
github.com/trustbloc/sidetree-go v1.0.1-0.20240219121130-f4260aff7104/go.mod h1:3yChjB5KOT7B9eZe0W1XaIx3MNUuC1Oe9nR/GCtI1W0=
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5 h1:k+C+8dfvi/0EOwr6Yjlei5yCYkg2jxPXYgWUYXE7hYU=
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5/go.mod h1:LJTZ+GIYr/HeklpmhzlNfz9zAd/t4mj4Kylr9+ubHnc=
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091 h1:xM6WbckFTPjeb2gGzCm2pJAOnVHRkrgz+wOXxukgQg4=
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091/go.mod h1:P8hpnwkdxWAlbqL8QiKiGjQImuLUPGscCoyGqz9RS/Q=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
Expand Down
21 changes: 11 additions & 10 deletions cmd/vc-rest/startcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,16 +992,17 @@ func buildEchoHandler(
}

verifierController := verifierv1.NewController(&verifierv1.Config{
VerifyCredentialSvc: verifyCredentialSvc,
ProfileSvc: verifierProfileSvc,
KMSRegistry: kmsRegistry,
DocumentLoader: documentLoader,
VDR: conf.VDR,
OIDCVPService: oidc4vpService,
Metrics: metrics,
Tracer: conf.Tracer,
EventSvc: eventSvc,
EventTopic: conf.StartupParameters.verifierEventTopic,
VerifyCredentialSvc: verifyCredentialSvc,
VerifyPresentationSvc: verifyPresentationSvc,
ProfileSvc: verifierProfileSvc,
KMSRegistry: kmsRegistry,
DocumentLoader: documentLoader,
VDR: conf.VDR,
OIDCVPService: oidc4vpService,
Metrics: metrics,
Tracer: conf.Tracer,
EventSvc: eventSvc,
EventTopic: conf.StartupParameters.verifierEventTopic,
})

verifierv1.RegisterHandlers(e, verifierController)
Expand Down
2 changes: 1 addition & 1 deletion component/credentialstatus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88
github.com/trustbloc/logutil-go v1.0.0
github.com/trustbloc/sidetree-go v1.0.1-0.20240219121130-f4260aff7104
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091
github.com/trustbloc/vcs v0.0.0-00010101000000-000000000000
)

Expand Down
4 changes: 2 additions & 2 deletions component/credentialstatus/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ github.com/trustbloc/logutil-go v1.0.0 h1:KzNs9TRbnmn+M3oYw9UkrtOjNd3ZGO8aLgfYtt
github.com/trustbloc/logutil-go v1.0.0/go.mod h1:JlxT0oZfNKgIlSNtgc001WEeDMxlnAvOM43gNm8DQVc=
github.com/trustbloc/sidetree-go v1.0.1-0.20240219121130-f4260aff7104 h1:0IW4muaGvhjJ4OkG6/PQG3DGf5POWxlA1wwEYsxWQ+4=
github.com/trustbloc/sidetree-go v1.0.1-0.20240219121130-f4260aff7104/go.mod h1:3yChjB5KOT7B9eZe0W1XaIx3MNUuC1Oe9nR/GCtI1W0=
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5 h1:k+C+8dfvi/0EOwr6Yjlei5yCYkg2jxPXYgWUYXE7hYU=
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5/go.mod h1:LJTZ+GIYr/HeklpmhzlNfz9zAd/t4mj4Kylr9+ubHnc=
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091 h1:xM6WbckFTPjeb2gGzCm2pJAOnVHRkrgz+wOXxukgQg4=
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091/go.mod h1:P8hpnwkdxWAlbqL8QiKiGjQImuLUPGscCoyGqz9RS/Q=
github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
Expand Down
2 changes: 1 addition & 1 deletion component/event/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/stretchr/testify v1.9.0
github.com/trustbloc/cmdutil-go v1.0.0
github.com/trustbloc/logutil-go v1.0.0
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091
github.com/trustbloc/vcs v0.0.0-00010101000000-000000000000
go.opentelemetry.io/otel/trace v1.29.0
)
Expand Down
4 changes: 2 additions & 2 deletions component/event/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88 h1:k3KNf9tE4TBV
github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88/go.mod h1:OKOtsLbE6W5s4mpjWkvk8XEqcmt9vTgVmDNkHELpWO0=
github.com/trustbloc/logutil-go v1.0.0 h1:KzNs9TRbnmn+M3oYw9UkrtOjNd3ZGO8aLgfYttMypcE=
github.com/trustbloc/logutil-go v1.0.0/go.mod h1:JlxT0oZfNKgIlSNtgc001WEeDMxlnAvOM43gNm8DQVc=
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5 h1:k+C+8dfvi/0EOwr6Yjlei5yCYkg2jxPXYgWUYXE7hYU=
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5/go.mod h1:LJTZ+GIYr/HeklpmhzlNfz9zAd/t4mj4Kylr9+ubHnc=
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091 h1:xM6WbckFTPjeb2gGzCm2pJAOnVHRkrgz+wOXxukgQg4=
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091/go.mod h1:P8hpnwkdxWAlbqL8QiKiGjQImuLUPGscCoyGqz9RS/Q=
github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
Expand Down
2 changes: 1 addition & 1 deletion component/profile/reader/file/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ require (
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/trustbloc/bbs-signature-go v1.0.2 // indirect
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5 // indirect
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/veraison/go-cose v1.3.0-rc.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions component/profile/reader/file/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ github.com/trustbloc/logutil-go v1.0.0 h1:KzNs9TRbnmn+M3oYw9UkrtOjNd3ZGO8aLgfYtt
github.com/trustbloc/logutil-go v1.0.0/go.mod h1:JlxT0oZfNKgIlSNtgc001WEeDMxlnAvOM43gNm8DQVc=
github.com/trustbloc/sidetree-go v1.0.1-0.20240219121130-f4260aff7104 h1:0IW4muaGvhjJ4OkG6/PQG3DGf5POWxlA1wwEYsxWQ+4=
github.com/trustbloc/sidetree-go v1.0.1-0.20240219121130-f4260aff7104/go.mod h1:3yChjB5KOT7B9eZe0W1XaIx3MNUuC1Oe9nR/GCtI1W0=
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5 h1:k+C+8dfvi/0EOwr6Yjlei5yCYkg2jxPXYgWUYXE7hYU=
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5/go.mod h1:LJTZ+GIYr/HeklpmhzlNfz9zAd/t4mj4Kylr9+ubHnc=
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091 h1:xM6WbckFTPjeb2gGzCm2pJAOnVHRkrgz+wOXxukgQg4=
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091/go.mod h1:P8hpnwkdxWAlbqL8QiKiGjQImuLUPGscCoyGqz9RS/Q=
github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
Expand Down
2 changes: 1 addition & 1 deletion component/wallet-cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88
github.com/trustbloc/logutil-go v1.0.0
github.com/trustbloc/sidetree-go v1.0.1-0.20240219121130-f4260aff7104
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091
github.com/trustbloc/vcs v0.0.0-00010101000000-000000000000
github.com/valyala/fastjson v1.6.4
github.com/veraison/go-cose v1.3.0-rc.1
Expand Down
4 changes: 2 additions & 2 deletions component/wallet-cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,8 @@ github.com/trustbloc/logutil-go v1.0.0 h1:KzNs9TRbnmn+M3oYw9UkrtOjNd3ZGO8aLgfYtt
github.com/trustbloc/logutil-go v1.0.0/go.mod h1:JlxT0oZfNKgIlSNtgc001WEeDMxlnAvOM43gNm8DQVc=
github.com/trustbloc/sidetree-go v1.0.1-0.20240219121130-f4260aff7104 h1:0IW4muaGvhjJ4OkG6/PQG3DGf5POWxlA1wwEYsxWQ+4=
github.com/trustbloc/sidetree-go v1.0.1-0.20240219121130-f4260aff7104/go.mod h1:3yChjB5KOT7B9eZe0W1XaIx3MNUuC1Oe9nR/GCtI1W0=
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5 h1:k+C+8dfvi/0EOwr6Yjlei5yCYkg2jxPXYgWUYXE7hYU=
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5/go.mod h1:LJTZ+GIYr/HeklpmhzlNfz9zAd/t4mj4Kylr9+ubHnc=
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091 h1:xM6WbckFTPjeb2gGzCm2pJAOnVHRkrgz+wOXxukgQg4=
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091/go.mod h1:P8hpnwkdxWAlbqL8QiKiGjQImuLUPGscCoyGqz9RS/Q=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
github.com/trustbloc/did-go v1.3.1-0.20241021165331-5721a3ff7396
github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88
github.com/trustbloc/logutil-go v1.0.0-rc1
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091
github.com/valyala/fastjson v1.6.4
github.com/veraison/go-cose v1.3.0-rc.1
github.com/xeipuuv/gojsonschema v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88 h1:k3KNf9tE4TBV
github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88/go.mod h1:OKOtsLbE6W5s4mpjWkvk8XEqcmt9vTgVmDNkHELpWO0=
github.com/trustbloc/logutil-go v1.0.0-rc1 h1:rRJbvgQfrlUfyej+mY0nuQJymGqjRW4oZEwKi544F4c=
github.com/trustbloc/logutil-go v1.0.0-rc1/go.mod h1:JlxT0oZfNKgIlSNtgc001WEeDMxlnAvOM43gNm8DQVc=
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5 h1:k+C+8dfvi/0EOwr6Yjlei5yCYkg2jxPXYgWUYXE7hYU=
github.com/trustbloc/vc-go v1.2.1-0.20240927095859-a58759112df5/go.mod h1:LJTZ+GIYr/HeklpmhzlNfz9zAd/t4mj4Kylr9+ubHnc=
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091 h1:xM6WbckFTPjeb2gGzCm2pJAOnVHRkrgz+wOXxukgQg4=
github.com/trustbloc/vc-go v1.2.1-0.20241021195658-882ca910f091/go.mod h1:P8hpnwkdxWAlbqL8QiKiGjQImuLUPGscCoyGqz9RS/Q=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

package main

import (
"encoding/gob"
"flag"
"fmt"
"os"
"path"
"reflect"

"github.com/golang/mock/mockgen/model"

pkg_ "github.com/trustbloc/vcs/pkg/observability/tracing/wrappers/oidc4vp"
)

var output = flag.String("output", "", "The output file name, or empty to use stdout.")

func main() {
flag.Parse()

its := []struct{
sym string
typ reflect.Type
}{

{ "Service", reflect.TypeOf((*pkg_.Service)(nil)).Elem()},

}
pkg := &model.Package{
// NOTE: This behaves contrary to documented behaviour if the
// package name is not the final component of the import path.
// The reflect package doesn't expose the package name, though.
Name: path.Base("github.com/trustbloc/vcs/pkg/observability/tracing/wrappers/oidc4vp"),
}

for _, it := range its {
intf, err := model.InterfaceFromInterfaceType(it.typ)
if err != nil {
fmt.Fprintf(os.Stderr, "Reflection: %v\n", err)
os.Exit(1)
}
intf.Name = it.sym
pkg.Interfaces = append(pkg.Interfaces, intf)
}

outfile := os.Stdout
if len(*output) != 0 {
var err error
outfile, err = os.Create(*output)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open output file %q", *output)
}
defer func() {
if err := outfile.Close(); err != nil {
fmt.Fprintf(os.Stderr, "failed to close output file %q", *output)
os.Exit(1)
}
}()
}

if err := gob.NewEncoder(outfile).Encode(pkg); err != nil {
fmt.Fprintf(os.Stderr, "gob encode: %v\n", err)
os.Exit(1)
}
}
123 changes: 123 additions & 0 deletions pkg/restapi/v1/issuer/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,32 @@ func (c *Controller) issueCredential(
finalCredentials = *body.Credential

enforceStrictValidation = true // todo for test passing, should we have it somewhere?

// for some reason should be allowed https://w3c.github.io/vc-data-model/#status test suite
if v, ok := finalCredentials.(map[string]interface{}); ok {
if status, statusOk := v["credentialStatus"].(map[string]interface{}); statusOk {
idObj, idObjOk := status["id"]

if !idObjOk {
delete(v, "credentialStatus")
finalCredentials = v
}

if idObjOk {
id, idOk := idObj.(string)

if !idOk || strings.Contains(id, " ") {
return nil, resterr.NewValidationError(resterr.InvalidValue, "credentialStatus.id",
errors.New("id must be a string"))
}

if id == "" {
delete(v, "credentialStatus")
finalCredentials = v
}
}
}
}
} else {
credentialTemplate, tmplErr := c.extractCredentialTemplate(profile, body)
if tmplErr != nil {
Expand All @@ -243,6 +269,35 @@ func (c *Controller) issueCredential(
return nil, err
}

issuer := credentialParsed.Contents().Issuer
if issuer != nil && !strings.HasPrefix(issuer.ID, "did:") {
return nil, resterr.NewValidationError(resterr.InvalidValue, "credential.issuer",
errors.New("issuer must be a DID"))
}

// todo some better handling https://www.w3.org/TR/vc-data-model-2.0/#dfn-url
if strings.Contains(credentialParsed.Contents().ID, " ") {
return nil, resterr.NewValidationError(resterr.InvalidValue, "credential.id",
errors.New("id must be a valid URL"))
}

if err = c.validateRelatedResources(credentialParsed); err != nil {
return nil, resterr.NewValidationError(resterr.InvalidValue, "credential", err)
}

if err = c.validateCredentialSchemas(credentialParsed); err != nil {
return nil, resterr.NewValidationError(resterr.InvalidValue, "credential", err)
}

content := credentialParsed.Contents()

if content.Issued != nil && content.Expired != nil {
if content.Issued.After(content.Expired.Time) || content.Issued.Equal(content.Expired.Time) {
return nil, resterr.NewValidationError(resterr.InvalidValue, "credential.issued",
errors.New("issued date must be before expiration date"))
}
}

credOpts, err := validateIssueCredOptions(body.Options, profile)
if err != nil {
return nil, fmt.Errorf("validate validateIssueCredOptions failed: %w", err)
Expand All @@ -251,6 +306,74 @@ func (c *Controller) issueCredential(
return c.signCredential(ctx, credentialParsed, profile, issuecredential.WithCryptoOpts(credOpts))
}

func (c *Controller) validateCredentialSchemas(cred *verifiable.Credential) error {
schemas := cred.CustomField("credentialSchema")
if schemas == nil {
return nil
}

if v, ok := schemas.(map[string]interface{}); ok {
schemas = []interface{}{v}
}

schemasArray, ok := schemas.([]interface{})
if !ok {
return errors.New("credentialSchema must be an array")
}

for _, schema := range schemasArray {
schemaMap, itemMapOk := schema.(map[string]interface{})
if !itemMapOk {
return errors.New("credentialSchema must be a map")
}

val, idOk := schemaMap["id"].(string)
if !idOk {
return errors.New("credentialSchema must have an id")
}

// todo some better handling https://www.w3.org/TR/vc-data-model-2.0/#dfn-url
if val == "" || strings.Contains(val, " ") {
return errors.New("credentialSchema id must be a valid URL")
}
}

return nil
}

func (c *Controller) validateRelatedResources(cred *verifiable.Credential) error {
relatedResources := cred.CustomField("relatedResource")
if relatedResources == nil {
return nil
}

relatedResourcesArray, ok := relatedResources.([]interface{})
if !ok {
return errors.New("relatedResource must be an array")
}

for _, relatedResource := range relatedResourcesArray {
relatedResourceMap, itemMapOk := relatedResource.(map[string]interface{})
if !itemMapOk {
return errors.New("relatedResource must be a map")
}

_, ok = relatedResourceMap["id"]
if !ok {
return errors.New("relatedResource must have an id")
}

_, hasDigest := relatedResourceMap["digestSRI"]
_, hasMultiBase := relatedResourceMap["digestMultibase"]

if !hasDigest && !hasMultiBase {
return errors.New("relatedResource must have a digestMultibase or digestSRI ")
}
}

return nil
}

func (c *Controller) extractCredentialTemplate(
profile *profileapi.Issuer,
body *IssueCredentialData) (*profileapi.CredentialTemplate, error) {
Expand Down
Loading

0 comments on commit 12866c2

Please sign in to comment.