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: Private key does not satisfy the curve requirements (ie. it is invalid) #12

Open
strawberry-code opened this issue Mar 4, 2019 · 7 comments

Comments

@strawberry-code
Copy link

strawberry-code commented Mar 4, 2019

I followed step by step the instruction to import accounts private key using Metamask, but I get:

Error: Private key does not satisfy the curve requirements (ie. it is invalid)
    at new Wallet (/Users/sahelanthropus/IdeaProjects/deploy-contracts/test/node_modules/ethereumjs-wallet/index.js:29:11)
    at Function.Wallet.fromPrivateKey (/Users/sahelanthropus/IdeaProjects/deploy-contracts/test/node_modules/ethereumjs-wallet/index.js:204:10)
    at new HDWalletProvider (/Users/sahelanthropus/IdeaProjects/deploy-contracts/test/node_modules/truffle-hdwallet-provider-privkey/index.js:16:35)
    at Object.<anonymous> (/Users/sahelanthropus/IdeaProjects/deploy-contracts/test/deploy.js:11:18)
    at Module._compile (internal/modules/cjs/loader.js:734:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
    at Module.load (internal/modules/cjs/loader.js:626:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
    at Function.Module._load (internal/modules/cjs/loader.js:558:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:797:12)
    at executeUserCode (internal/bootstrap/node.js:526:15)
    at startMainThreadExecution (internal/bootstrap/node.js:439:3)

The strange thing is that in truffle framework I am able to use HDWalletProvider and string private key. Using it in my code doesn't work (nor truffle-hdwallet-provider nor truffle-hdwallet-provider-privkey).

Here is how I use it:

const MNEMONIC = 'PRIVATEKEYFROMMETAMASK';
const provider = new HDWalletProvider(MNEMONIC, "https://ropsten.infura.io/v3/INFURATOKEN");
const web3 = new Web3(provider);
@rhlsthrm
Copy link
Owner

rhlsthrm commented Mar 5, 2019

Are you using web3 1.0.0 or the old web3? You need to use this package, truffle-hdwallet-provider-privkey to make the private key work instead of the mnemonic.

You might need to make the private keys an array, like:

const MNEMONIC =[ 'PRIVATEKEYFROMMETAMASK'];
const provider = new HDWalletProvider(MNEMONIC, "https://ropsten.infura.io/v3/INFURATOKEN");
const web3 = new Web3(provider);

If that works for you, let me know and I'll update the docs.

@jordanmurkin
Copy link

Hi @Cristiano-c, I had this same issue and found your issue.

Someone else answered this in: ethereumjs/ethereumjs-wallet#20 suggesting to use Buffer.from('<PRIVATE_KEY>', 'hex') to convert your private key to a Buffer first.

This should work for you:

const privateKey = Buffer.from('PRIVATEKEYFROMMETAMASK', 'hex');
const provider = new HDWalletProvider(privateKey, "https://ropsten.infura.io/v3/INFURATOKEN");
const web3 = new Web3(provider);

@piotr-roslaniec
Copy link

piotr-roslaniec commented Jun 27, 2019

Notice that HDWalletProvider constructor takes in an array of private keys:

const HDWalletProvider = require("truffle-hdwallet-provider-privkey");
const privateKeys = ["myPrivateKey"]; 

module.exports = {
  networks: {
    rinkeby: {
      provider: function() {
        return new HDWalletProvider(
          privateKeys,
          "https://rinkeby.infura.io/v3/<myInfuraToken>"
        );
      },
      network_id: 4,
      gas: 4500000,
      gasPrice: 100000000
    }
  }
};

@vikramIde
Copy link

Guys having similar issue any help appreciated

ikrams-MacBook-Pro:dstorage vikrambhushan$ truffle migrate --reset --network testnet

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.

Error: Private key does not satisfy the curve requirements (ie. it is invalid)
    at new Wallet (/Users/vikrambhushan/Documents/Harmony/dstorage/node_modules/ethereumjs-wallet/index.js:29:11)
    at Function.Wallet.fromPrivateKey (/Users/vikrambhushan/Documents/Harmony/dstorage/node_modules/ethereumjs-wallet/index.js:204:10)
    at new HDWalletProvider (/Users/vikrambhushan/Documents/Harmony/dstorage/node_modules/truffle-hdwallet-provider-privkey/index.js:16:35)
    at Object.provider (/Users/vikrambhushan/Documents/Harmony/dstorage/truffle-config.js:18:23)
    at Object.getProvider (/usr/local/Cellar/node/13.13.0_1/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:20:1)
    at Object.create (/usr/local/Cellar/node/13.13.0_1/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:13:1)
    at TruffleConfig.get [as provider] (/usr/local/Cellar/node/13.13.0_1/lib/node_modules/truffle/build/webpack:/packages/config/dist/configDefaults.js:208:1)
    at Object.detect (/usr/local/Cellar/node/13.13.0_1/lib/node_modules/truffle/build/webpack:/packages/environment/environment.js:19:1)
    at Object.run (/usr/local/Cellar/node/13.13.0_1/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:201:1)
    at Command.run (/usr/local/Cellar/node/13.13.0_1/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:167:1)
Truffle v5.4.1 (core: 5.4.1)
Node v13.13.0```

@BarneyChambers
Copy link

Guys having similar issue any help appreciated

ikrams-MacBook-Pro:dstorage vikrambhushan$ truffle migrate --reset --network testnet

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.

Error: Private key does not satisfy the curve requirements (ie. it is invalid)
    at new Wallet (/Users/vikrambhushan/Documents/Harmony/dstorage/node_modules/ethereumjs-wallet/index.js:29:11)
    at Function.Wallet.fromPrivateKey (/Users/vikrambhushan/Documents/Harmony/dstorage/node_modules/ethereumjs-wallet/index.js:204:10)
    at new HDWalletProvider (/Users/vikrambhushan/Documents/Harmony/dstorage/node_modules/truffle-hdwallet-provider-privkey/index.js:16:35)
    at Object.provider (/Users/vikrambhushan/Documents/Harmony/dstorage/truffle-config.js:18:23)
    at Object.getProvider (/usr/local/Cellar/node/13.13.0_1/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:20:1)
    at Object.create (/usr/local/Cellar/node/13.13.0_1/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:13:1)
    at TruffleConfig.get [as provider] (/usr/local/Cellar/node/13.13.0_1/lib/node_modules/truffle/build/webpack:/packages/config/dist/configDefaults.js:208:1)
    at Object.detect (/usr/local/Cellar/node/13.13.0_1/lib/node_modules/truffle/build/webpack:/packages/environment/environment.js:19:1)
    at Object.run (/usr/local/Cellar/node/13.13.0_1/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:201:1)
    at Command.run (/usr/local/Cellar/node/13.13.0_1/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:167:1)
Truffle v5.4.1 (core: 5.4.1)
Node v13.13.0```

Are you wrapping the privateKey in an array? Make sure to do that let array = [privateKey]

@namelessperson0
Copy link

In this code base, the private key should not start with 0x. Remove 0x if present.

@Olayiwola-TD
Copy link

I have an old wallet inherited from family since 2016 which has been backup using keystore Json and password. i have been trying to recover the wallet using various wallet and they keep giving response "private key do not satisfy the curve requirements".

the only wallet that was able to import it is 'Math Wallet' on my android phone, but when i want to make transfer out, it request for password and when i input it i give a response "Privatekey error".

If i try to copy the private in order to export it .. it gives me back "Privatekey error".

please help

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

8 participants