forked from lombard-finance/deposit-address
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweak_bytes.go
38 lines (31 loc) · 1011 Bytes
/
tweak_bytes.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
package deposit_address
import (
eth "github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
)
type BlockchainType string
const (
BlockchainTypeEvm BlockchainType = "evm"
)
// CalcTweakBytes Compute the tweakBytes for a given request, dispatching on `blockchainType`
func CalcTweakBytes(
blockchainType BlockchainType,
chainId [32]byte,
toAddress, lbtcAddress, auxData []byte,
) ([]byte, error) {
switch blockchainType {
case BlockchainTypeEvm:
// evm chain uses 20-byte address
if len(lbtcAddress) != 20 {
return nil, errors.Errorf("bad LbtcAddress (got %d bytes, expected 20)", len(lbtcAddress))
}
lbtcAddr := eth.BytesToAddress(lbtcAddress)
if len(toAddress) != 20 {
return nil, errors.Errorf("bad ToAddress (got %d bytes, expected 20)", len(toAddress))
}
depositAddr := eth.BytesToAddress(toAddress)
return EvmDepositTweak(lbtcAddr, depositAddr, chainId[:], auxData)
default:
return nil, errors.Errorf("unsupported blockchain type: %s", blockchainType)
}
}