Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/cosmos/ibc-…
Browse files Browse the repository at this point in the history
…go/v7-7.4.0

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
  • Loading branch information
eckelj committed Jun 26, 2024
2 parents 1fa39ee + c1663d3 commit 75351fd
Show file tree
Hide file tree
Showing 19 changed files with 832 additions and 182 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ go.work
/app.env
/ta
/tasmota*-rddl.bin
/data
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ linters:
- noctx
- nolintlint
- nosprintfhostport
- paralleltest
- perfsprint
- prealloc
- predeclared
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ A build service can be executed via ```./ta``` or be run via the following go co
go run cmd/ta/main.go
```

The following command will attest a given newline separated file of Trust Wallet machine IDs to the configured network:
```
./ta --attest-machine-ids-by-file keys.txt
```

## Configuration
The service needs to be configured via the ```./app.env``` file or environment variables.
A default configuration file is created at first run.
Expand Down
76 changes: 72 additions & 4 deletions cmd/ta/main.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
package main

import (
"bufio"
"bytes"
"flag"
"fmt"
"html/template"
"log"
"os"

"github.com/planetmint/planetmint-go/app"
"github.com/planetmint/planetmint-go/lib"
"github.com/rddl-network/ta_attest/config"
"github.com/rddl-network/ta_attest/service"

"github.com/spf13/viper"
"github.com/syndtr/goleveldb/leveldb"
)

var libConfig *lib.Config

func init() {
encodingConfig := app.MakeEncodingConfig()
libConfig = lib.GetConfig()
libConfig.SetEncodingConfig(encodingConfig)
}

func loadConfig(path string) (cfg *config.Config, err error) {
v := viper.New()
v.AddConfigPath(path)
Expand All @@ -30,6 +42,9 @@ func loadConfig(path string) (cfg *config.Config, err error) {
cfg.FirmwareESP32 = v.GetString("FIRMWARE_ESP32")
cfg.FirmwareESP32C3 = v.GetString("FIRMWARE_ESP32C3")
cfg.TestnetMode = v.GetBool("TESTNET_MODE")
cfg.DBPath = v.GetString("DB_PATH")
cfg.PlanetmintRPCHost = v.GetString("PLANETMINT_RPC_HOST")
cfg.LogLevel = v.GetString("LOG_LEVEL")
return
}
log.Println("no config file found")
Expand Down Expand Up @@ -57,15 +72,68 @@ func loadConfig(path string) (cfg *config.Config, err error) {
return
}

func attestFileContent(filename string, pmc service.PlanetmintClient) {
// Open the file for reading
file, err := os.Open(filename)
if err != nil {
log.Println("Error opening file:", err)
return
}
defer file.Close() // Ensure file gets closed even in case of errors

// Create a scanner to read the file line by line
scanner := bufio.NewScanner(file)
log.Println("Start processing the file ...")
// Iterate over each line in the scanner
for scanner.Scan() {
line := scanner.Text()
// Call your attestation function with the current line
log.Println("Attesting : " + line)
err := pmc.AttestTAPublicKeyHex(line)
if err != nil {
log.Println(err.Error())
} else {
log.Println("Successfully attested.")
}
}
log.Println("End of file")
// Handle any errors during scanning
if err := scanner.Err(); err != nil {
log.Println("Error reading file:", err)
}
}

func main() {
cfg, err := loadConfig("./")
if err != nil {
log.Fatalf("fatal error reading the configuration %s", err)
}

TAAttestationService := service.NewTrustAnchorAttestationService(cfg)
err = TAAttestationService.Run()
libConfig.SetChainID(cfg.PlanetmintChainID)
grpcConn, err := service.SetupGRPCConnection(cfg)
if err != nil {
fmt.Print(err.Error())
log.Fatalf("fatal error opening grpc connection %s", err)
}
pmc := service.NewPlanetmintClient(cfg.PlanetmintActor, grpcConn)

csvFile := flag.String("attest-machine-ids-by-file", "", "Path to a new line separated machine IDs")
flag.Parse()

if *csvFile != "" {
fmt.Println("Attestation mode enabled. Using CSV file:", *csvFile)

attestFileContent(*csvFile, *pmc)
} else {
fmt.Println("Web Service mode")
db, err := leveldb.OpenFile(cfg.DBPath, nil)
if err != nil {
log.Fatalf("fatal error opening db %s", err)
}

TAAttestationService := service.NewTrustAnchorAttestationService(cfg, db, pmc)
err = TAAttestationService.Run()
if err != nil {
fmt.Print(err.Error())
}
}
}
17 changes: 15 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package config

import "sync"
import (
"sync"

"github.com/rddl-network/go-utils/logger"
)

const DefaultConfigTemplate = `
FIRMWARE_ESP32="{{ .FirmwareESP32 }}"
FIRMWARE_ESP32C3="{{ .FirmwareESP32C3 }}"
PLANETMINT_ACTOR="{{ .PlanetmintActor }}"
PLANETMINT_CHAIN_ID="{{ .PlanetmintChainID }}"
SERVICE_BIND="{{ .ServiceBind }}"
SERVICE_PORT={{ .ServicePort }}"
SERVICE_PORT={{ .ServicePort }}
TESTNET_MODE={{ .TestnetMode }}
DB_PATH="{{ .DBPath }}"
PLANETMINT_RPC_HOST="{{ .PlanetmintRPCHost }}"
LOG_LEVEL="{{ .LogLevel }}"
`

// Config defines TA's top level configuration
Expand All @@ -21,6 +28,9 @@ type Config struct {
ServiceBind string `json:"service-bind" mapstructure:"service-bind"`
ServicePort int `json:"service-port" mapstructure:"service-port"`
TestnetMode bool `json:"testnet-mode" mapstructure:"testnet-mode"`
DBPath string `json:"db-path" mapstructure:"db-path"`
PlanetmintRPCHost string `json:"planetmint-rpc-host" mapstructure:"planetmint-rpc-host"`
LogLevel string `json:"log-level" mapstructure:"log-level"`
}

// global singleton
Expand All @@ -39,6 +49,9 @@ func DefaultConfig() *Config {
ServiceBind: "localhost",
ServicePort: 8080,
TestnetMode: false,
DBPath: "data",
PlanetmintRPCHost: "127.0.0.1:9090",
LogLevel: logger.DEBUG,
}
}

Expand Down
68 changes: 37 additions & 31 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
module github.com/rddl-network/ta_attest

go 1.20
go 1.21.5

require (
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/cosmos/cosmos-sdk v0.47.8
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0
github.com/gin-gonic/gin v1.9.1
github.com/golang/mock v1.6.0
github.com/planetmint/planetmint-go v0.6.5
github.com/planetmint/planetmint-go/lib v0.2.1
github.com/rddl-network/go-utils v0.1.1
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
gotest.tools v2.2.0+incompatible
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d
google.golang.org/grpc v1.63.2
)

require (
cloud.google.com/go v0.111.0 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.36.0 // indirect
cosmossdk.io/api v0.3.1 // indirect
cosmossdk.io/core v0.5.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
Expand All @@ -36,9 +39,10 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/btcsuite/btcd v0.23.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.2 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/btcsuite/btcd v0.24.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
Expand Down Expand Up @@ -72,15 +76,15 @@ require (
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
Expand All @@ -89,16 +93,15 @@ require (
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.2 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
Expand All @@ -110,7 +113,7 @@ require (
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.1 // indirect
github.com/hashicorp/go-getter v1.7.5 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
Expand Down Expand Up @@ -165,6 +168,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
Expand All @@ -174,25 +178,27 @@ require (
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.opentelemetry.io/otel/metric v1.22.0 // indirect
go.opentelemetry.io/otel/trace v1.22.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/api v0.149.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.162.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 75351fd

Please sign in to comment.