Skip to content

Commit 537d39f

Browse files
committed
fix: add utils file for keys and fix tx link
1 parent 8ac3e94 commit 537d39f

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

pkg/internal/common/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func GetTransactionLink(txHash string, chainId *big.Int) string {
379379
if !ok {
380380
return txHash
381381
} else {
382-
return fmt.Sprintf("%s/%s", chainMetadata.BlockExplorerUrl, txHash)
382+
return fmt.Sprintf("%s/tx/%s", chainMetadata.BlockExplorerUrl, txHash)
383383
}
384384
}
385385

pkg/internal/common/helper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ func TestGetTransactionLink(t *testing.T) {
2424
name: "valid mainnet tx hash",
2525
chainID: big.NewInt(1),
2626
txHash: "0x123",
27-
expectedTxLink: fmt.Sprintf("%s/%s", utils.MainnetBlockExplorerUrl, "0x123"),
27+
expectedTxLink: fmt.Sprintf("%s/tx/%s", utils.MainnetBlockExplorerUrl, "0x123"),
2828
},
2929
{
3030
name: "valid holesky tx hash",
3131
chainID: big.NewInt(17000),
3232
txHash: "0x123",
33-
expectedTxLink: fmt.Sprintf("%s/%s", utils.HoleskyBlockExplorerUrl, "0x123"),
33+
expectedTxLink: fmt.Sprintf("%s/tx/%s", utils.HoleskyBlockExplorerUrl, "0x123"),
3434
},
3535
{
3636
name: "valid custom chain tx hash",

pkg/keys/utils.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package keys
2+
3+
import (
4+
"fmt"
5+
"math/big"
6+
7+
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
8+
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
9+
)
10+
11+
// ParseBlsPrivateKey parses a BLS private key from a string either in hex or large integer format.
12+
func ParseBlsPrivateKey(privateKey string) (*bls.KeyPair, error) {
13+
privateKeyBigInt := new(big.Int)
14+
_, ok := privateKeyBigInt.SetString(privateKey, 10)
15+
var blsKeyPair *bls.KeyPair
16+
var err error
17+
if ok {
18+
fmt.Println("Importing from large integer")
19+
blsKeyPair, err = bls.NewKeyPairFromString(privateKey)
20+
if err != nil {
21+
return nil, err
22+
}
23+
} else {
24+
// Try to parse as hex
25+
fmt.Println("Importing from hex")
26+
z := new(big.Int)
27+
privateKey = common.Trim0x(privateKey)
28+
_, ok := z.SetString(privateKey, 16)
29+
if !ok {
30+
return nil, ErrInvalidHexPrivateKey
31+
}
32+
blsKeyPair, err = bls.NewKeyPairFromString(z.String())
33+
if err != nil {
34+
return nil, err
35+
}
36+
}
37+
return blsKeyPair, nil
38+
}

0 commit comments

Comments
 (0)