Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion app/arbiter/crypto/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"os"

"github.com/btcsuite/btcd/btcutil"
"github.com/ethereum/go-ethereum/accounts/keystore"
)

Expand Down Expand Up @@ -104,7 +106,22 @@ func GetBtcKeyFromKeystore(path, password string) (string, error) {
if err != nil {
return "", err
}
return hex.EncodeToString(decryptedData), nil
hexPrivateKey, err := convertWIFToHex(string(decryptedData))
if err != nil {
return "", fmt.Errorf("failed to convert WIF to hex: %v", err)
}
return hexPrivateKey, nil
}

func convertWIFToHex(wif string) (string, error) {
decodedWIF, err := btcutil.DecodeWIF(wif)
if err != nil {
return "", err
}

privateKeyBytes := decodedWIF.PrivKey.Serialize()
hexPrivateKey := hex.EncodeToString(privateKeyBytes)
return hexPrivateKey, nil
}

// decryptBTCKeystore decrypts BTC keystore data using password
Expand Down
21 changes: 19 additions & 2 deletions app/keystore-generator/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@ import (
"crypto/cipher"
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"io"
"os"

"github.com/btcsuite/btcd/btcutil"
)

func convertWIFToHex(wif string) (string, error) {
decodedWIF, err := btcutil.DecodeWIF(wif)
if err != nil {
return "", err
}

privateKeyBytes := decodedWIF.PrivKey.Serialize()
hexPrivateKey := hex.EncodeToString(privateKeyBytes)
return hexPrivateKey, nil
}

func ParseKeystore(filePath string, password string) (string, error) {
data, err := os.ReadFile(filePath)
if err != nil {
Expand All @@ -23,8 +37,11 @@ func ParseKeystore(filePath string, password string) (string, error) {
if err != nil {
return "", fmt.Errorf("failed to decrypt keystore: %v", err)
}

return string(decrypted), nil
hexPrivateKey, err := convertWIFToHex(string(decrypted))
if err != nil {
return "", fmt.Errorf("failed to convert WIF to hex: %v", err)
}
return hexPrivateKey, nil
}

func Encrypt(data []byte, password string) ([]byte, error) {
Expand Down