Skip to content

Commit

Permalink
Merge pull request #30 from iden3/feat/PID-2694
Browse files Browse the repository at this point in the history
feat/pid 2694
  • Loading branch information
vmidyllic authored Nov 25, 2024
2 parents 4943a44 + 8c7998e commit 28d9896
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.18.2
go-version: 1.19
- name: Checkout code
uses: actions/checkout@v2
- name: golangci-lint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
test:
strategy:
matrix:
containers: [ 1.18.3-bullseye ]
containers: [ 1.19-bullseye ]
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##
## Build did driver
##
FROM golang:1.18-alpine AS base
FROM golang:1.19-alpine AS base

WORKDIR /build

Expand Down
30 changes: 25 additions & 5 deletions cmd/driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/iden3/driver-did-iden3/pkg/app"
"github.com/iden3/driver-did-iden3/pkg/app/configs"
Expand All @@ -15,6 +16,8 @@ import (
"github.com/iden3/driver-did-iden3/pkg/services/blockchain/eth"
"github.com/iden3/driver-did-iden3/pkg/services/ens"
"github.com/iden3/driver-did-iden3/pkg/services/provers"
core "github.com/iden3/go-iden3-core/v2"
revocationReolver "github.com/iden3/merkletree-proof/resolvers"
)

func main() {
Expand Down Expand Up @@ -42,8 +45,9 @@ func main() {
}
}

resolvers, revocationResolvers := initResolvers()
mux := app.Handlers{DidDocumentHandler: &app.DidDocumentHandler{
DidDocumentService: services.NewDidDocumentServices(initResolvers(), r, services.WithProvers(proverRegistry))},
DidDocumentService: services.NewDidDocumentServices(resolvers, r, revocationResolvers, services.WithProvers(proverRegistry))},
}

server := http.Server{
Expand All @@ -58,7 +62,7 @@ func main() {
}
}

func initResolvers() *services.ResolverRegistry {
func initResolvers() (*services.ResolverRegistry, *revocationReolver.OnChainResolver) {
var path string
if len(os.Args) > 2 {
path = os.Args[1]
Expand All @@ -68,6 +72,12 @@ func initResolvers() *services.ResolverRegistry {
log.Fatal("can't read resolver settings:", err)
}
resolvers := services.NewChainResolvers()
var (
ethClients map[core.ChainID]*ethclient.Client
stateContractAddresses map[core.ChainID]common.Address
)
ethClients = make(map[core.ChainID]*ethclient.Client)
stateContractAddresses = make(map[core.ChainID]common.Address)
for chainName, chainSettings := range rs {
for networkName, networkSettings := range chainSettings {
prefix := fmt.Sprintf("%s:%s", chainName, networkName)
Expand All @@ -76,10 +86,20 @@ func initResolvers() *services.ResolverRegistry {
log.Fatalf("failed configure resolver for network '%s': %v", prefix, err)
}
resolvers.Add(prefix, resolver)

ethClient, err := ethclient.Dial(networkSettings.NetworkURL)
if err != nil {
log.Fatalf("failed configure resolver for network '%s': %v", prefix, err)
}
chainID, err := core.GetChainID(core.Blockchain(chainName), core.NetworkID(networkName))
if err != nil {
log.Fatalf("failed configure resolver for network '%s': %v", prefix, err)
}
ethClients[chainID] = ethClient
stateContractAddresses[chainID] = common.HexToAddress(networkSettings.ContractAddress)
}
}

return resolvers
return resolvers, revocationReolver.NewOnChainResolver(ethClients, stateContractAddresses)
}

func initDIDResolutionProverRegistry(cfg configs.Config) (*services.DIDResolutionProverRegistry, error) {
Expand All @@ -98,7 +118,7 @@ func initDIDResolutionProverRegistry(cfg configs.Config) (*services.DIDResolutio
func addCORSHeaders(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS, POST")

if r.Method == http.MethodOptions {
w.WriteHeader(http.StatusOK)
Expand Down
17 changes: 8 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module github.com/iden3/driver-did-iden3

go 1.18
go 1.19

require (
github.com/ethereum/go-ethereum v1.11.5
github.com/ethereum/go-ethereum v1.12.2
github.com/golang/mock v1.6.0
github.com/iden3/contracts-abi/state/go/abi v1.0.1
github.com/iden3/go-iden3-core/v2 v2.3.1
github.com/iden3/go-schema-processor/v2 v2.4.2
github.com/iden3/merkletree-proof v0.3.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
Expand All @@ -18,22 +18,23 @@ require (
)

require (
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/dchest/blake512 v1.0.0 // indirect
github.com/deckarep/golang-set/v2 v2.2.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/holiman/uint256 v1.2.0 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230911113809-c58b7e7a69b0 // indirect
github.com/iden3/go-schema-processor/v2 v2.5.1-0.20241118132742-9f041ef05b49 // indirect
github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f // indirect
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad // indirect
)

require (
github.com/btcsuite/btcd v0.22.0-beta // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cespare/cp v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.1 // indirect
Expand All @@ -57,8 +58,6 @@ require (
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/tyler-smith/go-bip32 v1.0.0
github.com/tyler-smith/go-bip39 v1.1.0
github.com/wealdtech/go-multicodec v1.4.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/sys v0.15.0 // indirect
Expand Down
Loading

0 comments on commit 28d9896

Please sign in to comment.