hashgraph / hedera-sdk-js

Hedera™ Hashgraph SDK for JavaScript/TypeScript
https://docs.hedera.com/guides/docs/sdks
Apache License 2.0
277 stars 145 forks source link

Error: invalid private key: <pkey> #32

Closed ilyakmet closed 5 years ago

ilyakmet commented 5 years ago

When I use string type pkey:

import {Client} from "@hashgraph/sdk";

const client = new Client({ 
    // this key defaults to this url, a public free proxy to the Hedera public testnet
    // generously hosted by MyHederaWallet.com
    url: "https://grpc-web.myhederawallet.com",
    operator: {
        // the account which signs transactions and query payments by default
        account: { shard: 0, realm: 0, account: ___ },
        // the private key used to sign the transactions, either encoded as a string
        // or as an `Ed25519PrivateKey` type 
        privateKey: "..."
    },
});

Error:

Error: invalid private key: <pkey>

How I can convert string type pkey to Ed25519 type ?

/** If `privateKey` is a string it will be parsed as an `Ed25519PrivateKey` */
export type PrivateKey = { privateKey: Ed25519PrivateKey | string };
export type PubKeyAndSigner = {
    publicKey: Ed25519PublicKey;
    signer: Signer;
};
mehcode commented 5 years ago

Ed25519PrivateKey.fromString("30....")

should work

abonander commented 5 years ago

@ilyakmet your private key string must be one of the following character lengths, which is how the SDK infers its encoding type:

It's possible that your private key string is actually a hex(DER) encoded structure containing both a private key and a public key. Can you measure and report its length and where you got it from?

5atoshin commented 2 years ago

Invalid private key encoding (code -5)