Skip to content

Commit

Permalink
fix: #195 (#207)
Browse files Browse the repository at this point in the history
* fix: #195

* fix: remove ens provider private key

* fix: increase defaultRetrieveTimeout
  • Loading branch information
asabya authored May 9, 2022
1 parent f293e2f commit ea0554e
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 50 deletions.
5 changes: 5 additions & 0 deletions cmd/dfs-cli/cmd/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/fairdatasociety/fairOS-dfs/cmd/common"
"github.com/fairdatasociety/fairOS-dfs/pkg/api"
"github.com/fairdatasociety/fairOS-dfs/pkg/pod"
"github.com/fairdatasociety/fairOS-dfs/pkg/utils"
)

func podNew(podName string) {
Expand All @@ -43,6 +44,8 @@ func podNew(podName string) {
fmt.Println("could not create pod: ", err)
return
}
currentPod = podName
currentDirectory = utils.PathSeperator
message := strings.ReplaceAll(string(data), "\n", "")
fmt.Println(message)
}
Expand Down Expand Up @@ -111,6 +114,8 @@ func openPod(podName string) {
fmt.Println("pod open failed: ", err)
return
}
currentPod = podName
currentDirectory = utils.PathSeperator
message := strings.ReplaceAll(string(data), "\n", "")
fmt.Println(message)
}
Expand Down
5 changes: 0 additions & 5 deletions cmd/dfs-cli/cmd/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ func executor(in string) {
}
userName := blocks[2]
userLogin(userName, apiUserLoginV2)
currentUser = userName
currentPod = ""
currentDirectory = ""
currentPrompt = getCurrentPrompt()
Expand Down Expand Up @@ -426,8 +425,6 @@ func executor(in string) {
}
podName := blocks[2]
podNew(podName)
currentPod = podName
currentDirectory = utils.PathSeperator
currentPrompt = getCurrentPrompt()
case "del":
if len(blocks) < 3 {
Expand All @@ -446,8 +443,6 @@ func executor(in string) {
}
podName := blocks[2]
openPod(podName)
currentPod = podName
currentDirectory = utils.PathSeperator
currentPrompt = getCurrentPrompt()
case "close":
if !isPodOpened() {
Expand Down
1 change: 1 addition & 0 deletions cmd/dfs-cli/cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func userLogin(userName, apiEndpoint string) {
fmt.Println("login user: ", err)
return
}
currentUser = userName
message := strings.ReplaceAll(string(data), "\n", "")
fmt.Println(message)
}
Expand Down
1 change: 0 additions & 1 deletion cmd/dfs/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var (
optionSubdomainRegistrarAddress = "ens.subdomain-registrar-address"
optionENSRegistryAddress = "ens.ens-registry-address"
optionENSProviderBackend = "ens.ens-provider-backend"
optionENSProviderPrivateKey = "ens.ens-provider-private-key"

defaultCORSAllowedOrigins = []string{}
defaultDFSHttpPort = ":9090"
Expand Down
6 changes: 0 additions & 6 deletions cmd/dfs/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ can consume it.`,
subdomainRegistrarAddress := config.GetString(optionSubdomainRegistrarAddress)
ensRegistryAddress := config.GetString(optionENSRegistryAddress)
ensProviderBackend := config.GetString(optionENSProviderBackend)
ensProviderPrivateKey := config.GetString(optionENSProviderPrivateKey)

if providerDomain == "" {
fmt.Println("\nens provider domain is missing")
Expand All @@ -113,18 +112,13 @@ can consume it.`,
fmt.Println("\nensProvideBackend endpoint is missing")
return
}
if ensProviderPrivateKey == "" {
fmt.Println("\nens provider private key is missing")
return
}

ensConfig := &contracts.Config{
ENSRegistryAddress: ensRegistryAddress,
SubdomainRegistrarAddress: subdomainRegistrarAddress,
PublicResolverAddress: publicResolverAddress,
ProviderDomain: providerDomain,
ProviderBackend: ensProviderBackend,
ProviderPrivateKey: ensProviderPrivateKey,
}

var logger logging.Logger
Expand Down
20 changes: 10 additions & 10 deletions openapi/dfs.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.0.0

info:
version: 0.7.3
version: 0.8.0
title: FairOS-dfs API
description: 'A list of the currently provided Interfaces to interact with FairOS decentralised file system(dfs), implementing user, pod, file system, key value store and document store'

Expand All @@ -22,7 +22,7 @@ servers:
paths:
'/v1/user/signup':
post:
summary: 'Signup user'
summary: 'Signup user (v1)'
description: 'Signs up a user and subsequently logs in returning the authentication cookie `fairOS-dfs`.
The cookie needs to be sent n the request header in all subsequent requests.
Input is a form object containing the login, password and optionally mnemonic. [Will be deprecated soon, use /v2/user/signup]'
Expand Down Expand Up @@ -64,7 +64,7 @@ paths:

'/v2/user/signup':
post:
summary: 'Signup user'
summary: 'Signup user (v2)'
description: 'Signs up a user and subsequently logs in returning the authentication cookie `fairOS-dfs`.
The cookie needs to be sent n the request header in all subsequent requests.
Input is a form object containing the login, password and optionally mnemonic.'
Expand Down Expand Up @@ -104,7 +104,7 @@ paths:

'/v1/user/login':
post:
summary: 'Login user'
summary: 'Login user (v1)'
description: 'Logs in user and returns the authentication cookie `fairOS-dfs in the header.
The cookie needs to be sent n the request header in all subsequent requests.
Input is a form object containing the login and password.'
Expand Down Expand Up @@ -143,7 +143,7 @@ paths:

'/v2/user/login':
post:
summary: 'Login user'
summary: 'Login user (v2)'
description: 'Logs in user and returns the authentication cookie `fairOS-dfs in the header.
The cookie needs to be sent n the request header in all subsequent requests.
Input is a form object containing the login and password.'
Expand Down Expand Up @@ -181,7 +181,7 @@ paths:

'/v1/user/present':
get:
summary: 'User present'
summary: 'User present (v1)'
description: 'Check if an user is present in a given dfs-server.
Input contains form object containing the user name to check if it is present in the dfs server.'
tags:
Expand All @@ -208,7 +208,7 @@ paths:

'/v2/user/present':
get:
summary: 'User present'
summary: 'User present (v2)'
description: 'Check if an user is present in a given dfs-server.
Input contains form object containing the user name to check if it is present in the dfs server.'
tags:
Expand Down Expand Up @@ -343,7 +343,7 @@ paths:

'/v1/user/delete':
delete:
summary: 'Delete user'
summary: 'Delete user (v1)'
description: 'Delete a logged-in user from the dfs server.'
tags:
- User
Expand Down Expand Up @@ -377,7 +377,7 @@ paths:

'/v2/user/delete':
delete:
summary: 'Delete user'
summary: 'Delete user (v2)'
description: 'Delete a logged-in user from the dfs server.'
tags:
- User
Expand Down Expand Up @@ -2301,7 +2301,7 @@ components:
type: string
example: "user logged-in successfully"

UserSignupResponseWithMenonic:
UserSignupResponseWithMnemonic:
type: object
properties:
address:
Expand Down
1 change: 0 additions & 1 deletion pkg/contracts/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ type Config struct {
PublicResolverAddress string
ProviderDomain string
ProviderBackend string
ProviderPrivateKey string
}
3 changes: 0 additions & 3 deletions pkg/dfs/api.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !js
// +build !js

/*
Copyright © 2020 FairOS Authors
Expand Down
2 changes: 1 addition & 1 deletion pkg/ensm/ensm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

type ENSManager interface {
GetOwner(username string) (common.Address, error)
RegisterSubdomain(username string, owner common.Address) error
RegisterSubdomain(username string, owner common.Address, key *ecdsa.PrivateKey) error
SetResolver(username string, owner common.Address, key *ecdsa.PrivateKey) (string, error)
SetAll(username string, owner common.Address, key *ecdsa.PrivateKey) error
GetInfo(username string) (*ecdsa.PublicKey, string, error)
Expand Down
23 changes: 4 additions & 19 deletions pkg/ensm/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/fairdatasociety/fairOS-dfs/pkg/contracts"
"github.com/fairdatasociety/fairOS-dfs/pkg/contracts/ens"
Expand Down Expand Up @@ -42,9 +41,7 @@ type Client struct {
subdomainRegistrar *subdomainregistrar.Subdomainregistrar
publicResolver *publicresolver.Publicresolver

providerPrivateKey *ecdsa.PrivateKey
providerAddress common.Address
logger logging.Logger
logger logging.Logger
}

func New(ensConfig *contracts.Config, logger logging.Logger) (*Client, error) {
Expand All @@ -70,27 +67,15 @@ func New(ensConfig *contracts.Config, logger logging.Logger) (*Client, error) {
if err != nil {
return nil, err
}
privateKey, err := crypto.HexToECDSA(ensConfig.ProviderPrivateKey)
if err != nil {
return nil, err
}
publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
return nil, fmt.Errorf("error casting public key to ECDSA")
}
fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)

logger.Info("ensProviderBackend : ", ensConfig.ProviderBackend)
logger.Info("ensProviderAddress : ", fromAddress.Hex())
logger.Info("ensProviderDomain : ", ensConfig.ProviderDomain)
c := &Client{
eth: eth,
ensConfig: ensConfig,
ensRegistry: ensRegistry,
subdomainRegistrar: subdomainRegistrar,
publicResolver: publicResolver,
providerAddress: fromAddress,
providerPrivateKey: privateKey,
logger: logger,
}
return c, nil
Expand All @@ -105,7 +90,7 @@ func (c *Client) GetOwner(username string) (common.Address, error) {
return c.ensRegistry.Owner(opts, node)
}

func (c *Client) RegisterSubdomain(username string, owner common.Address) error {
func (c *Client) RegisterSubdomain(username string, owner common.Address, key *ecdsa.PrivateKey) error {
balance, err := c.eth.BalanceAt(context.Background(), owner, nil)
if err != nil {
return err
Expand All @@ -115,7 +100,7 @@ func (c *Client) RegisterSubdomain(username string, owner common.Address) error
return ErrInsufficientBalance
}

opts, err := c.newTransactor(c.providerPrivateKey, c.providerAddress)
opts, err := c.newTransactor(key, owner)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ensm/eth/mock/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *MockNamespaceManager) GetInfo(username string) (*ecdsa.PublicKey, strin
return pub, "", nil
}

func (c *MockNamespaceManager) RegisterSubdomain(username string, owner common.Address) error {
func (c *MockNamespaceManager) RegisterSubdomain(username string, owner common.Address, _ *ecdsa.PrivateKey) error {
c.storerMu.Lock()
defer c.storerMu.Unlock()
c.storer[username] = owner.Hex()
Expand Down
2 changes: 1 addition & 1 deletion pkg/feed/cacheentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
const (
hasherCount = 8

defaultRetrieveTimeout = 100 * time.Millisecond
defaultRetrieveTimeout = 400 * time.Millisecond
)

// CacheEntry caches the last known update of a specific Swarm feed.
Expand Down
2 changes: 1 addition & 1 deletion pkg/user/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func isUserNameValid(username string) bool {
}

func (u *Users) createENS(userName string, accountInfo *account.Info) (string, error) {
err := u.ens.RegisterSubdomain(userName, common.HexToAddress(accountInfo.GetAddress().Hex()))
err := u.ens.RegisterSubdomain(userName, common.HexToAddress(accountInfo.GetAddress().Hex()), accountInfo.GetPrivateKey())
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package dfs

var (
version = "0.8.0" // manually set semantic version number
version = "0.8.1" // manually set semantic version number
commit string // automatically set git commit hash

Version = func() string {
Expand Down

0 comments on commit ea0554e

Please sign in to comment.