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

Error parsing ECDSA public key #1358

Closed
pathornteng opened this issue Dec 19, 2022 · 7 comments
Closed

Error parsing ECDSA public key #1358

pathornteng opened this issue Dec 19, 2022 · 7 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@pathornteng
Copy link

Description

Currently, Javascript SDK is throwing an error when it tries to parse ECDSA public.

const newAccountPrivateKey = PrivateKey.generateECDSA();
const newAccountPublicKey = newAccountPrivateKey.publicKey;
const publicKey2 = PublicKey.fromString(newAccountPublicKey.toStringDer());

This problem does not happen with ED25519.

Steps to reproduce

Run the following code

const newAccountPrivateKey = PrivateKey.generateECDSA();
const newAccountPublicKey = newAccountPrivateKey.publicKey;
const publicKey2 = PublicKey.fromString(newAccountPublicKey.toStringDer());

You will get

BadKeyError: invalid public key length: 47 bytes
    at Function.fromBytes (/Users/pathorn/Work/hedera/hedera-basic/node_modules/@hashgraph/cryptography/lib/PublicKey.cjs:74:11)
    at Function.fromString (/Users/pathorn/Work/hedera/hedera-basic/node_modules/@hashgraph/cryptography/lib/PublicKey.cjs:106:22)
    at Function.fromString (/Users/pathorn/Work/hedera/hedera-basic/node_modules/@hashgraph/sdk/lib/PublicKey.cjs:103:49)
    at main (/Users/pathorn/Work/hedera/hedera-basic/create-account.js:43:32)
    at Object.<anonymous> (/Users/pathorn/Work/hedera/hedera-basic/create-account.js:66:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)

Additional context

No response

Hedera network

mainnet, testnet, previewnet

Version

lastest

Operating system

macOS

@pathornteng pathornteng added the bug Something isn't working label Dec 19, 2022
@pathornteng
Copy link
Author

I suspect that we have the same problem with Java and Golang SDKs

@petreze
Copy link
Contributor

petreze commented Dec 19, 2022

@pathornteng
Tried to run the provided code example but the issue did not appear. I've tried also with the async version and it was again generated properly. Do you have a different setup or something that you might have missed on this one?

@pathornteng
Copy link
Author

I am using v2.19.0, the latest version, and I get the error every time. The following is the complete script on MacOS.

const { Client, PrivateKey, PublicKey } = require("@hashgraph/sdk");

async function main() {
  const newAccountPrivateKey = PrivateKey.generateECDSA();
  const newAccountPublicKey = newAccountPrivateKey.publicKey;
  const publicKey2 = PublicKey.fromString(newAccountPublicKey.toStringDer());
}
main();

@SimiHunjan SimiHunjan added this to the 2.20.0 milestone Dec 19, 2022
@petreze
Copy link
Contributor

petreze commented Dec 22, 2022

@pathornteng
Hello, try using newAccountPublicKey.toStringRaw() instead of newAccountPublicKey.toStringDer()

@pathornteng
Copy link
Author

Hi @petreze, yes newAccountPublicKey.toStringRaw() works but newAccountPublicKey.toStringDer() should also work since it works for ED25519.

@ochikov
Copy link
Contributor

ochikov commented Jan 10, 2023

@pathornteng We are going to fix it in the new release. Thank you for the opened issue.

@ochikov
Copy link
Contributor

ochikov commented Jan 16, 2023

Fixed with #1366

@ochikov ochikov closed this as completed Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants