Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unknown public key type #1449

Open
godlovericea opened this issue Dec 10, 2024 · 3 comments
Open

unknown public key type #1449

godlovericea opened this issue Dec 10, 2024 · 3 comments

Comments

@godlovericea
Copy link

godlovericea commented Dec 10, 2024

when i write program below, it panic err:

panic: unknown public key type
privateKey, err := keypair.DeserializePrivateKey(privateKeyBytes)
if err != nil {
    fmt.Println(err)
    return "", "", "", err
}
pub := privateKey.Public()
aAddr := types.AddressFromPubKey(pub)

how to transform crypto.PublicKey to keypair.PublicKey

I have read the source code
Such as:
https://github.com/ontio/ontology/blob/master/cmd/account_cmd.go#L438

https://github.com/ontio/ontology/blob/master/cmd/sigsvr/store/wallet_store.go#L225

how to transform crypto.PublicKey to keypair.PublicKey
or
how to transform crypto.PublicKey to common.Address

@laizy
Copy link
Contributor

laizy commented Dec 12, 2024

Where is the privateKeyBytes come from?

@godlovericea
Copy link
Author

@laizy thank you very much

I have generated a keypair before , then cast to string , save it into my db
when I want to make tx, I get the prvString from my db, such as below

prv, _, _:= keypair.GenerateKeyPair(keypair.PK_ETHECDSA, nil)
prvString := hex.EncodeToString(keypair.SerializePrivateKey(prv))
privateKeyBytes , _:= hex.DecodeString(prvString )

@laizy
Copy link
Contributor

laizy commented Dec 13, 2024

If you want to send ontology transaction, you can use keypair.PK_ECDSA. keypair.PK_ETHECDSA is intend for ontology evm transaction.

The current workaround for your code is:

privateKey, err := keypair.DeserializePrivateKey(privateKeyBytes)
if err != nil {
    fmt.Println(err)
    return "", "", "", err
}
_, pub := keypair.FromEthereumPrivateKey(privateKey.(*ec.EthereumPrivateKey).PrivateKey)
aAddr := types.AddressFromPubKey(pub)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants