Skip to content

Commit

Permalink
Add README for register-signer
Browse files Browse the repository at this point in the history
  • Loading branch information
mdehoog committed Dec 12, 2024
1 parent 8ca2ee7 commit 4f247ba
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
29 changes: 29 additions & 0 deletions register-signer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Signer registration utility

This utility can be used to register an op-enclave signer key with the
[SystemConfigGlobal](../contracts/src/SystemConfigGlobal.sol) contract.

## Installation

```
go install github.com/base-org/op-enclave/register-signer
```

## Usage

Query an AWS Nitro attestation from op-enclave server:
```bash
curl -d '{"id":0,"jsonrpc":"2.0","method":"enclave_signerAttestation"}' -H "Content-Type: application/json" http://op-enclave:7333
```

```
Usage of register-signer:
-attestation string
attestation hex
-deployment string
deployment file (default "deployments/84532-deploy.json")
-private-key string
private key
-rpc string
rpc url (default "https://sepolia.base.org")
```
31 changes: 6 additions & 25 deletions register-signer/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package main

import (
"bytes"
"context"
"encoding/json"
"flag"
"fmt"
"os"
Expand All @@ -20,22 +18,18 @@ import (
"github.com/hf/nitrite"
)

type deployment struct {
SystemConfigGlobalProxy common.Address `json:"SystemConfigGlobalProxy"`
}

func main() {
var attestationHex string
var rpcUrl string
var privateKeyHex string
var deploymentFile string
var configAddress string
flag.StringVar(&attestationHex, "attestation", "", "attestation hex")
flag.StringVar(&rpcUrl, "rpc", "https://sepolia.base.org", "rpc url")
flag.StringVar(&privateKeyHex, "private-key", "", "private key")
flag.StringVar(&deploymentFile, "deployment", "deployments/84532-deploy.json", "deployment file")
flag.StringVar(&configAddress, "address", "", "address of the SystemConfigGlobal proxy contract")
flag.Parse()

if attestationHex == "" || privateKeyHex == "" {
if attestationHex == "" || privateKeyHex == "" || configAddress == "" {
flag.Usage()
os.Exit(1)
}
Expand All @@ -60,20 +54,6 @@ func main() {
panic(err)
}

deploy, err := os.ReadFile(deploymentFile)
if err != nil {
panic(err)
}
var d deployment
err = json.Unmarshal(deploy, &d)
if err != nil {
panic(err)
}

if bytes.Equal(common.Address{}.Bytes(), d.SystemConfigGlobalProxy.Bytes()) {
panic("SystemConfigGlobalProxy address not found in deployment file")
}

key, err := crypto.ToECDSA(privateKey)
if err != nil {
panic(err)
Expand All @@ -91,7 +71,7 @@ func main() {
},
}

systemConfigGlobal, err := bindings.NewSystemConfigGlobal(d.SystemConfigGlobalProxy, client)
systemConfigGlobal, err := bindings.NewSystemConfigGlobal(common.HexToAddress(configAddress), client)
if err != nil {
panic(err)
}
Expand All @@ -106,10 +86,11 @@ func main() {
panic(err)
}
fmt.Printf("Public key: %s\n", hexutil.Encode(res.Document.PublicKey))
fmt.Printf("Signer: %s\n", signerAddr.String())
if validSigner {
fmt.Printf("Signer already registered: %s\n", signerAddr.String())
return
} else {
fmt.Printf("Registering signer: %s\n", signerAddr.String())
}

certManagerAddr, err := systemConfigGlobal.CertManager(&bind.CallOpts{})
Expand Down

0 comments on commit 4f247ba

Please sign in to comment.