forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkey.go
More file actions
53 lines (43 loc) · 1.18 KB
/
key.go
File metadata and controls
53 lines (43 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package dsl
import (
"crypto/ecdsa"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum-optimism/optimism/op-devstack/devtest"
"github.com/ethereum-optimism/optimism/op-service/txplan"
)
// Key is an ethereum private key.
// This is a key with an address identity.
// The Key may be used on different chains: it is chain-agnostic.
type Key struct {
t devtest.T
priv *ecdsa.PrivateKey
addr common.Address
}
func NewKey(t devtest.T, priv *ecdsa.PrivateKey) *Key {
t.Require().NotNil(priv.PublicKey, "private key PublicKey attribute must be initialized")
addr := crypto.PubkeyToAddress(priv.PublicKey)
return &Key{
t: t,
priv: priv,
addr: addr,
}
}
func (a *Key) Priv() *ecdsa.PrivateKey {
return a.priv
}
func (a *Key) String() string {
return fmt.Sprintf("EOA(%s)", a.addr)
}
func (a *Key) Address() common.Address {
return a.addr
}
// Plan returns the tx-plan option to use this Key for signing of a transaction.
func (a *Key) Plan() txplan.Option {
return txplan.WithPrivateKey(a.priv)
}
// EOA combines this Key with an EL node into a single-chain EOA.
func (a *Key) User(el ELNode) *EOA {
return NewEOA(a, el)
}