@@ -25,6 +25,7 @@ import (
25
25
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc"
26
26
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc/types"
27
27
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin"
28
+ "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/eth"
28
29
keystorePkg "github.com/BitBoxSwiss/bitbox-wallet-app/backend/keystore"
29
30
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/signing"
30
31
"github.com/BitBoxSwiss/bitbox-wallet-app/util/errp"
@@ -109,7 +110,7 @@ func (keystore *Keystore) Configuration() *signing.Configuration {
109
110
// SupportsCoin implements keystore.Keystore.
110
111
func (keystore * Keystore ) SupportsCoin (coin coin.Coin ) bool {
111
112
switch coin .(type ) {
112
- case * btc.Coin :
113
+ case * btc.Coin , * eth. Coin :
113
114
return true
114
115
default :
115
116
return false
@@ -128,7 +129,8 @@ func (keystore *Keystore) SupportsAccount(coin coin.Coin, meta interface{}) bool
128
129
scriptType == signing .ScriptTypeP2WPKHP2SH ||
129
130
scriptType == signing .ScriptTypeP2WPKH ||
130
131
scriptType == signing .ScriptTypeP2TR
131
-
132
+ case * eth.Coin :
133
+ return true
132
134
default :
133
135
return false
134
136
}
@@ -180,14 +182,7 @@ func (keystore *Keystore) ExtendedPublicKey(
180
182
return extendedPrivateKey .Neuter ()
181
183
}
182
184
183
- // SignTransaction implements keystore.Keystore.
184
- func (keystore * Keystore ) SignTransaction (
185
- proposedTransaction interface {},
186
- ) error {
187
- btcProposedTx , ok := proposedTransaction .(* btc.ProposedTransaction )
188
- if ! ok {
189
- panic ("Only BTC supported for now." )
190
- }
185
+ func (keystore * Keystore ) signBTCTransaction (btcProposedTx * btc.ProposedTransaction ) error {
191
186
keystore .log .Info ("Sign transaction." )
192
187
transaction := btcProposedTx .TXProposal .Transaction
193
188
signatures := make ([]* types.Signature , len (transaction .TxIn ))
@@ -263,6 +258,33 @@ func (keystore *Keystore) SignTransaction(
263
258
return nil
264
259
}
265
260
261
+ func (keystore * Keystore ) signETHTransaction (tx * eth.TxProposal ) error {
262
+ xprv , err := tx .Keypath .Derive (keystore .master )
263
+ if err != nil {
264
+ return errp .Newf ("failed to derive key: %v" , err )
265
+ }
266
+ privKey , err := xprv .ECPrivKey ()
267
+ if err != nil {
268
+ return errp .Newf ("failed to get private key: %v" , err )
269
+ }
270
+ tx .Tx , err = ethTypes .SignTx (tx .Tx , tx .Signer , privKey .ToECDSA ())
271
+ return err
272
+ }
273
+
274
+ // SignTransaction implements keystore.Keystore.
275
+ func (keystore * Keystore ) SignTransaction (
276
+ proposedTransaction interface {},
277
+ ) error {
278
+ switch specificProposedTx := proposedTransaction .(type ) {
279
+ case * btc.ProposedTransaction :
280
+ return keystore .signBTCTransaction (specificProposedTx )
281
+ case * eth.TxProposal :
282
+ return keystore .signETHTransaction (specificProposedTx )
283
+ default :
284
+ panic ("unknown proposal type" )
285
+ }
286
+ }
287
+
266
288
// CanSignMessage implements keystore.Keystore.
267
289
func (keystore * Keystore ) CanSignMessage (coin.Code ) bool {
268
290
return false
0 commit comments