Skip to content

Commit

Permalink
Merge pull request #1 from base-org/michael/script-sender
Browse files Browse the repository at this point in the history
Add the --sender flag to forge script automatically
  • Loading branch information
mdehoog committed Jul 28, 2023
2 parents 42194e5 + df95e99 commit 67e16e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/decred/dcrd/hdkeychain/v3 v3.1.1
github.com/ethereum/go-ethereum v1.12.0
github.com/tyler-smith/go-bip39 v1.1.0
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c h1:DZfsyhDK1hnSS5lH8l+JggqzEleHteTYfutAiVlSUM8=
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/karalabe/usb v0.0.3-0.20230711191512-61db3e06439c h1:AqsttAyEyIEsNz5WLRwuRwjiT5CMDUfLk6cFJDVPebs=
Expand Down Expand Up @@ -73,6 +73,7 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/exp v0.0.0-20230206171751-46f607a40771 h1:xP7rWLUr1e1n2xkK5YB4LI0hPEy3LJC6Wk+D4pGlOJg=
golang.org/x/exp v0.0.0-20230206171751-46f607a40771/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -81,7 +82,6 @@ golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df h1:5Pf6pFKu98ODmgnpvkJ3kFUOQGGLIzLIkbzUHp47618=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
Expand Down
21 changes: 14 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"flag"
"fmt"
"golang.org/x/exp/slices"
"io"
"log"
"os"
Expand All @@ -28,13 +29,15 @@ func main() {
var prefix string
var suffix string
var workdir string
var skipSender bool
flag.StringVar(&privateKey, "private-key", "", "Private key to use for signing")
flag.BoolVar(&ledger, "ledger", false, "Use ledger device for signing")
flag.StringVar(&mnemonic, "mnemonic", "", "Mnemonic to use for signing")
flag.StringVar(&hdPath, "hd-paths", "m/44'/60'/0'/0/0", "Hierarchical deterministic derivation path for mnemonic or ledger")
flag.StringVar(&prefix, "prefix", "vvvvvvvv", "String that prefixes the data to be signed")
flag.StringVar(&suffix, "suffix", "^^^^^^^^", "String that suffixes the data to be signed")
flag.StringVar(&workdir, "workdir", ".", "Directory in which to run the subprocess")
flag.BoolVar(&skipSender, "skip-sender", false, "Skip adding the --sender flag to forge script commands")
flag.Parse()

options := 0
Expand All @@ -51,15 +54,24 @@ func main() {
log.Fatalf("One (and only one) of --private-key, --ledger, --mnemonic must be set")
}

s, err := createSigner(privateKey, mnemonic, hdPath)
if err != nil {
log.Fatalf("Error creating signer: %v", err)
}

var input []byte
var err error
if flag.NArg() == 0 {
input, err = io.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("Error reading from stdin: %v", err)
}
} else {
input, err = run(workdir, flag.Arg(0), flag.Args()[1:]...)
args := flag.Args()
if !skipSender && args[0] == "forge" && args[1] == "script" && !slices.Contains(args, "--sender") {
args = append(args, "--sender", s.address().String())
}
fmt.Printf("Running '%s\n", strings.Join(args, " "))
input, err = run(workdir, args[0], args[1:]...)
if err != nil {
log.Fatalf("Error running process: %v", err)
}
Expand All @@ -79,11 +91,6 @@ func main() {
log.Fatalf("Expected EIP-712 hex string with 66 bytes, got %d bytes, value: %s", len(input), string(input))
}

s, err := createSigner(privateKey, mnemonic, hdPath)
if err != nil {
log.Fatalf("Error creating signer: %v", err)
}

domainHash := hash[2:34]
messageHash := hash[34:66]
fmt.Printf("Domain hash: 0x%s\n", hex.EncodeToString(domainHash))
Expand Down

0 comments on commit 67e16e4

Please sign in to comment.