@@ -26,7 +26,6 @@ import (
26
26
"time"
27
27
28
28
"github.com/ethereum/go-ethereum/accounts"
29
- "github.com/ethereum/go-ethereum/accounts/abi/bind"
30
29
"github.com/ethereum/go-ethereum/cmd/utils"
31
30
"github.com/ethereum/go-ethereum/common"
32
31
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -46,10 +45,9 @@ var commandDeploy = cli.Command{
46
45
Flags : []cli.Flag {
47
46
nodeURLFlag ,
48
47
clefURLFlag ,
48
+ signerFlag ,
49
49
signersFlag ,
50
50
thresholdFlag ,
51
- keyFileFlag ,
52
- utils .PasswordFileFlag ,
53
51
},
54
52
Action : utils .MigrateFlags (deploy ),
55
53
}
@@ -60,12 +58,10 @@ var commandSign = cli.Command{
60
58
Flags : []cli.Flag {
61
59
nodeURLFlag ,
62
60
clefURLFlag ,
61
+ signerFlag ,
63
62
indexFlag ,
64
63
hashFlag ,
65
64
oracleFlag ,
66
- keyFileFlag ,
67
- signerFlag ,
68
- utils .PasswordFileFlag ,
69
65
},
70
66
Action : utils .MigrateFlags (sign ),
71
67
}
@@ -75,10 +71,10 @@ var commandPublish = cli.Command{
75
71
Usage : "Publish a checkpoint into the oracle" ,
76
72
Flags : []cli.Flag {
77
73
nodeURLFlag ,
74
+ clefURLFlag ,
75
+ signerFlag ,
78
76
indexFlag ,
79
77
signaturesFlag ,
80
- keyFileFlag ,
81
- utils .PasswordFileFlag ,
82
78
},
83
79
Action : utils .MigrateFlags (publish ),
84
80
}
@@ -108,11 +104,11 @@ func deploy(ctx *cli.Context) error {
108
104
}
109
105
fmt .Printf ("\n Signatures needed to publish: %d\n " , needed )
110
106
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 )
114
109
115
110
// Deploy the checkpoint oracle
111
+ fmt .Println ("Sending deploy request to Clef..." )
116
112
oracle , tx , _ , err := contract .DeployCheckpointOracle (transactor , client , addrs , big .NewInt (int64 (params .CheckpointFrequency )),
117
113
big .NewInt (int64 (params .CheckpointProcessConfirmations )), big .NewInt (int64 (needed )))
118
114
if err != nil {
@@ -158,9 +154,7 @@ func sign(ctx *cli.Context) error {
158
154
node = newRPCClient (ctx .GlobalString (nodeURLFlag .Name ))
159
155
160
156
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 )
164
158
165
159
// Check the validity of checkpoint
166
160
reqCtx , cancelFn := context .WithTimeout (context .Background (), 10 * time .Second )
@@ -207,43 +201,24 @@ func sign(ctx *cli.Context) error {
207
201
fmt .Printf ("Oracle => %s\n " , address .Hex ())
208
202
fmt .Printf ("Index %4d => %s\n " , cindex , chash .Hex ())
209
203
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 )
214
206
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
228
210
}
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 ()... ))
233
218
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 )
247
222
}
248
223
fmt .Printf ("Signer => %s\n " , signer )
249
224
fmt .Printf ("Signature => %s\n " , signature )
@@ -326,7 +301,8 @@ func publish(ctx *cli.Context) error {
326
301
fmt .Printf ("Sentry number => %d\n Sentry hash => %s\n " , recent .Number , recent .Hash ().Hex ())
327
302
328
303
// 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 )
330
306
if err != nil {
331
307
utils .Fatalf ("Register contract failed %v" , err )
332
308
}
0 commit comments