Skip to content

Commit

Permalink
Sanitize Private Keys (#753)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalverra authored Oct 31, 2023
1 parent 28a04d4 commit 849b72b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions networks/known_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,19 +724,21 @@ func getValidNetworkKeys() []string {

// setKeys sets a network's private key(s) based on env vars
func setKeys(network *blockchain.EVMNetwork, walletKeys []string) {
for keyIndex, key := range walletKeys { // Sanitize keys of possible `0x` prefix
if strings.HasPrefix(key, "0x") {
walletKeys[keyIndex] = key[2:]
}
for keyIndex := range walletKeys { // Sanitize keys of possible `0x` prefix
// Trim some common addons
walletKeys[keyIndex] = strings.Trim(walletKeys[keyIndex], "\"'")
walletKeys[keyIndex] = strings.TrimSpace(walletKeys[keyIndex])
walletKeys[keyIndex] = strings.TrimPrefix(walletKeys[keyIndex], "0x")
}
network.PrivateKeys = walletKeys
fmt.Println("network.PrivateKeys", network.PrivateKeys)

// log public keys for debugging
publicKeys := []string{}
for _, key := range network.PrivateKeys {
publicKey, err := privateKeyToAddress(key)
if err != nil {
log.Fatal().Err(err).Msg("Error getting public key from private key")
log.Fatal().Err(err).Str("Key", key).Msg("Error reading private key")
}
publicKeys = append(publicKeys, publicKey)
}
Expand Down

0 comments on commit 849b72b

Please sign in to comment.