-
Notifications
You must be signed in to change notification settings - Fork 39
/
l1_transaction.go
73 lines (59 loc) · 1.97 KB
/
l1_transaction.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package ethadapter
import (
"crypto/ecdsa"
"fmt"
"math/big"
"github.com/ten-protocol/go-ten/go/common"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
// L1Transaction is an abstraction that transforms an Ethereum transaction into a format that can be consumed more easily by Obscuro.
type L1Transaction interface{}
type L1RollupTx struct {
Rollup common.EncodedRollup
}
type L1DepositTx struct {
Amount *big.Int // Amount to be deposited
To *gethcommon.Address // Address the ERC20 Transfer was made to (always be the Management Contract Addr)
Sender *gethcommon.Address // Address that issued the ERC20, the token holder or tx.origin
TokenContract *gethcommon.Address // Address of the ERC20 Contract address that was executed
}
type L1RespondSecretTx struct {
Secret []byte
RequesterID gethcommon.Address
AttesterID gethcommon.Address
AttesterSig []byte
}
type L1SetImportantContractsTx struct {
Key string
NewAddress gethcommon.Address
}
// Sign signs the payload with a given private key
func (l *L1RespondSecretTx) Sign(privateKey *ecdsa.PrivateKey) *L1RespondSecretTx {
var data []byte
data = append(data, l.AttesterID.Bytes()...)
data = append(data, l.RequesterID.Bytes()...)
data = append(data, string(l.Secret)...)
ethereumMessageHash := func(data []byte) []byte {
prefix := fmt.Sprintf("\x19Ethereum Signed Message:\n%d", len(data))
return crypto.Keccak256([]byte(prefix), data)
}
hashedData := ethereumMessageHash(data)
// sign the hash
signedHash, err := crypto.Sign(hashedData, privateKey)
if err != nil {
return nil
}
// set recovery id to 27; prevent malleable signatures
signedHash[64] += 27
l.AttesterSig = signedHash
return l
}
type L1RequestSecretTx struct {
Attestation common.EncodedAttestationReport
}
type L1InitializeSecretTx struct {
EnclaveID *gethcommon.Address
InitialSecret []byte
Attestation common.EncodedAttestationReport
}