@@ -26,7 +26,6 @@ import (
2626 "time"
2727
2828 "github.com/ethereum/go-ethereum/accounts"
29- "github.com/ethereum/go-ethereum/accounts/abi/bind"
3029 "github.com/ethereum/go-ethereum/cmd/utils"
3130 "github.com/ethereum/go-ethereum/common"
3231 "github.com/ethereum/go-ethereum/common/hexutil"
@@ -46,10 +45,9 @@ var commandDeploy = cli.Command{
4645 Flags : []cli.Flag {
4746 nodeURLFlag ,
4847 clefURLFlag ,
48+ signerFlag ,
4949 signersFlag ,
5050 thresholdFlag ,
51- keyFileFlag ,
52- utils .PasswordFileFlag ,
5351 },
5452 Action : utils .MigrateFlags (deploy ),
5553}
@@ -60,12 +58,10 @@ var commandSign = cli.Command{
6058 Flags : []cli.Flag {
6159 nodeURLFlag ,
6260 clefURLFlag ,
61+ signerFlag ,
6362 indexFlag ,
6463 hashFlag ,
6564 oracleFlag ,
66- keyFileFlag ,
67- signerFlag ,
68- utils .PasswordFileFlag ,
6965 },
7066 Action : utils .MigrateFlags (sign ),
7167}
@@ -75,10 +71,10 @@ var commandPublish = cli.Command{
7571 Usage : "Publish a checkpoint into the oracle" ,
7672 Flags : []cli.Flag {
7773 nodeURLFlag ,
74+ clefURLFlag ,
75+ signerFlag ,
7876 indexFlag ,
7977 signaturesFlag ,
80- keyFileFlag ,
81- utils .PasswordFileFlag ,
8278 },
8379 Action : utils .MigrateFlags (publish ),
8480}
@@ -108,11 +104,11 @@ func deploy(ctx *cli.Context) error {
108104 }
109105 fmt .Printf ("\n Signatures needed to publish: %d\n " , needed )
110106
111- // Retrieve the private key, create an abigen transactor and an RPC client
112- transactor := bind .NewKeyedTransactor (getKey (ctx ).PrivateKey )
113- client := newClient (ctx )
107+ // setup clef signer, create an abigen transactor and an RPC client
108+ transactor , client := newClefSigner (ctx ), newClient (ctx )
114109
115110 // Deploy the checkpoint oracle
111+ fmt .Println ("Sending deploy request to Clef..." )
116112 oracle , tx , _ , err := contract .DeployCheckpointOracle (transactor , client , addrs , big .NewInt (int64 (params .CheckpointFrequency )),
117113 big .NewInt (int64 (params .CheckpointProcessConfirmations )), big .NewInt (int64 (needed )))
118114 if err != nil {
@@ -158,9 +154,7 @@ func sign(ctx *cli.Context) error {
158154 node = newRPCClient (ctx .GlobalString (nodeURLFlag .Name ))
159155
160156 checkpoint := getCheckpoint (ctx , node )
161- chash = checkpoint .Hash ()
162- cindex = checkpoint .SectionIndex
163- address = getContractAddr (node )
157+ chash , cindex , address = checkpoint .Hash (), checkpoint .SectionIndex , getContractAddr (node )
164158
165159 // Check the validity of checkpoint
166160 reqCtx , cancelFn := context .WithTimeout (context .Background (), 10 * time .Second )
@@ -207,43 +201,24 @@ func sign(ctx *cli.Context) error {
207201 fmt .Printf ("Oracle => %s\n " , address .Hex ())
208202 fmt .Printf ("Index %4d => %s\n " , cindex , chash .Hex ())
209203
210- switch {
211- case ctx .GlobalIsSet (clefURLFlag .Name ):
212- // Sign checkpoint in clef mode.
213- signer = ctx .String (signerFlag .Name )
204+ // Sign checkpoint in clef mode.
205+ signer = ctx .String (signerFlag .Name )
214206
215- if ! offline {
216- if err := isAdmin (common .HexToAddress (signer )); err != nil {
217- return err
218- }
219- }
220- clef := newRPCClient (ctx .GlobalString (clefURLFlag .Name ))
221- p := make (map [string ]string )
222- buf := make ([]byte , 8 )
223- binary .BigEndian .PutUint64 (buf , cindex )
224- p ["address" ] = address .Hex ()
225- p ["message" ] = hexutil .Encode (append (buf , chash .Bytes ()... ))
226- if err := clef .Call (& signature , "account_signData" , accounts .MimetypeDataWithValidator , signer , p ); err != nil {
227- utils .Fatalf ("Failed to sign checkpoint, err %v" , err )
207+ if ! offline {
208+ if err := isAdmin (common .HexToAddress (signer )); err != nil {
209+ return err
228210 }
229- case ctx .GlobalIsSet (keyFileFlag .Name ):
230- // Sign checkpoint in raw private key file mode.
231- key := getKey (ctx )
232- signer = key .Address .Hex ()
211+ }
212+ clef := newRPCClient (ctx .String (clefURLFlag .Name ))
213+ p := make (map [string ]string )
214+ buf := make ([]byte , 8 )
215+ binary .BigEndian .PutUint64 (buf , cindex )
216+ p ["address" ] = address .Hex ()
217+ p ["message" ] = hexutil .Encode (append (buf , chash .Bytes ()... ))
233218
234- if ! offline {
235- if err := isAdmin (key .Address ); err != nil {
236- return err
237- }
238- }
239- sig , err := crypto .Sign (sighash (cindex , address , chash ), key .PrivateKey )
240- if err != nil {
241- utils .Fatalf ("Failed to sign checkpoint, err %v" , err )
242- }
243- sig [64 ] += 27 // Transform V from 0/1 to 27/28 according to the yellow paper
244- signature = common .Bytes2Hex (sig )
245- default :
246- utils .Fatalf ("Please specify clef URL or private key file path to sign checkpoint" )
219+ fmt .Println ("Sending signing request to Clef..." )
220+ if err := clef .Call (& signature , "account_signData" , accounts .MimetypeDataWithValidator , signer , p ); err != nil {
221+ utils .Fatalf ("Failed to sign checkpoint, err %v" , err )
247222 }
248223 fmt .Printf ("Signer => %s\n " , signer )
249224 fmt .Printf ("Signature => %s\n " , signature )
@@ -326,7 +301,8 @@ func publish(ctx *cli.Context) error {
326301 fmt .Printf ("Sentry number => %d\n Sentry hash => %s\n " , recent .Number , recent .Hash ().Hex ())
327302
328303 // Publish the checkpoint into the oracle
329- tx , err := oracle .RegisterCheckpoint (getKey (ctx ).PrivateKey , checkpoint .SectionIndex , checkpoint .Hash ().Bytes (), recent .Number , recent .Hash (), sigs )
304+ fmt .Println ("Sending publish request to Clef..." )
305+ tx , err := oracle .RegisterCheckpoint (newClefSigner (ctx ), checkpoint .SectionIndex , checkpoint .Hash ().Bytes (), recent .Number , recent .Hash (), sigs )
330306 if err != nil {
331307 utils .Fatalf ("Register contract failed %v" , err )
332308 }
0 commit comments