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

Initial kyc-provider code base #1

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
.env
# Binaries for programs and plugins
*.exe
*.exe~
Expand Down
2 changes: 2 additions & 0 deletions .sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_PATH=config/dev.yaml
PRIVATE_KEY=key
24 changes: 16 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
FROM golang:1.22 AS builder

FROM golang:1.22.5-alpine3.19 AS builder
WORKDIR /app
COPY . .
RUN go mod download
RUN CGO_ENABLED=0 go build -o /entrypoint
RUN cat /etc/resolv.conf && apk add --no-cache git && \
git config --add --global url."git@github.com:".insteadOf https://github.com

FROM gcr.io/distroless/static-debian12
# Prepare dependencies
COPY go.mod go.sum ./
surzm marked this conversation as resolved.
Show resolved Hide resolved
RUN go mod download
# Build the binary
COPY ./cmd ./cmd
COPY ./internal ./internal
COPY ./config ./config
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o api ./cmd/api

COPY --from=builder /entrypoint /entrypoint

FROM alpine:3.19
WORKDIR /app
COPY --from=builder /app/api ./api
COPY --from=builder /app/config ./config
EXPOSE 8080
ENTRYPOINT ["/entrypoint"]
CMD ["./api"]
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
API_NAME := api
VERSION ?= dev
COMMIT=$(shell git rev-parse --short HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
TIME=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')

.PHONY: config
config: ## Creating the local config .env
@echo "Creating local config .env ..."
cp .sample.env .env

.PHONY: api
api: ## Run service http api
@echo "Running api..."
go run cmd/$(API_NAME)/*.go
77 changes: 0 additions & 77 deletions README.md

This file was deleted.

97 changes: 97 additions & 0 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package main

import (
"context"
"errors"
"gopkg.in/yaml.v3"
"io/fs"
"net/http"
"os"
"os/signal"
"syscall"

"github.com/dgraph-io/badger/v4"
"github.com/joho/godotenv"
log "github.com/sirupsen/logrus"

"github.com/swissborg/galactica-kyc-guardian/config"
"github.com/swissborg/galactica-kyc-guardian/internal/api"
"github.com/swissborg/galactica-kyc-guardian/internal/zkcert"
)

func main() {
log.SetFormatter(&log.JSONFormatter{})

log.Info("api service init...")
defer log.Info("api service stop")

ctx, cancelCancel := context.WithCancel(context.Background())

quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)

if err := godotenv.Load(".env"); err != nil {
var pathError *fs.PathError
if !errors.As(err, &pathError) {
log.Fatalf("parsing .env file: %v", err)
}
}

configPath := os.Getenv("CONFIG_PATH")
privKey := os.Getenv("PRIVATE_KEY")

yamlFile, err := os.ReadFile(configPath)
if err != nil {
log.Fatalf("yamlFile.Get err #%v .path: %s", err, configPath)
}

cfg := config.Config{}
err = yaml.Unmarshal(yamlFile, &cfg)
if err != nil {
log.Fatalf("unmarshal: %v", err)
}

certGenerator, err := zkcert.NewService(
privKey,
cfg.RegistryAddress,
cfg.Node,
cfg.MerkleProofService.URL,
cfg.MerkleProofService.TLS,
)
if err != nil {
log.Fatalf("failed to create cert generator %v", err)
}

opt := badger.DefaultOptions("").WithInMemory(true)
db, err := badger.Open(opt)
if err != nil {
log.Fatalf("failed to open badger %v", err)
}
defer db.Close()

server := api.NewServer(certGenerator, db)

go func() {
if err := server.Start(cfg.APIConf); err != nil && (!errors.Is(err, http.ErrServerClosed)) {
log.WithError(err).Fatal("shutting down the server")
}
}()

waiting := make(chan struct{})
go func() {
defer close(waiting)
select {
case <-quit:
log.Info("Gracefully stopping…")
cancelCancel()

if err := server.Stop(); err != nil {
log.WithError(err).Fatal()
}
case <-ctx.Done():
return
}
}()
<-waiting
log.Info("🏁 finished.")
}
20 changes: 20 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package config

import "github.com/ethereum/go-ethereum/common"

type Config struct {
APIConf APIConf `yaml:"APIConf"`
RegistryAddress common.Address `yaml:"RegistryAddress"`
Node string `yaml:"Node"`
MerkleProofService MerkleProofService `yaml:"MerkleProofService"`
}

type APIConf struct {
Port string `yaml:"Port" default:"8081"`
Host string `yaml:"Host" default:"0.0.0.0"`
}

type MerkleProofService struct {
URL string `yaml:"URL"`
TLS bool `yaml:"TLS"`
}
11 changes: 11 additions & 0 deletions config/dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
APIConf:
Host: "0.0.0.0"
Port: 8080

Node: https://evm-rpc-http-andromeda.galactica.com

RegistryAddress: 0x0415E990e55071F0d448F87CD170528C7783A484

MerkleProofService:
URL: merkle-proof-service.galactica.com:443/v1/galactica/41238
TLS: true
11 changes: 11 additions & 0 deletions config/prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
APIConf:
Host: "0.0.0.0"
Port: 8080

Node: https://evm-rpc-http-reticulum.galactica.com

RegistryAddress: 0x85032c035494324f62A5AfE2507d5427dFd72e76

MerkleProofService:
URL: merkle-proof-service.galactica.com:443/v1/galactica/9302
TLS: true
77 changes: 77 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
module github.com/swissborg/galactica-kyc-guardian

go 1.22.5

require (
github.com/Galactica-corp/merkle-proof-service v0.2.7
github.com/biter777/countries v1.7.5
github.com/dgraph-io/badger/v4 v4.2.0
github.com/ethereum/go-ethereum v1.14.8
github.com/galactica-corp/guardians-sdk v1.5.0
github.com/go-playground/validator/v10 v10.19.0
github.com/iden3/go-iden3-crypto v0.0.16
github.com/joho/godotenv v1.5.1
github.com/labstack/echo/v4 v4.12.0
github.com/sirupsen/logrus v1.9.3
github.com/stasundr/decimal v0.1.9
lomigmegard marked this conversation as resolved.
Show resolved Hide resolved
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // 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/dgraph-io/ristretto v0.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.13 // indirect
github.com/tklauser/numcpus v0.7.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.2 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Loading