using Ethereum private key to encrypt string - ethereum

I need to encrypt a string using the private key of my ethereum account on an Ethereum private network.
How can I do this using web3js?
Note: The Ethereum client I use is Geth.

You may find your answer here: https://ethereum.stackexchange.com/questions/3092/how-to-encrypt-a-message-with-the-public-key-of-an-ethereum-address
With geth on its own I don't think that it is possible, however with bitcore-lib and bitcore-ecies it is.

Related

What is the difference between a Wallet and a JsonRpcSigner?

On the ethers documentation, it says that the two most commons signers are:
Wallet, which is a class which knows its private key and can execute any operations with it.
JsonRpcSigner, which is connected to a JsonRpcProvider (or sub-class) and is acquired using getSigner
What I'm having trouble understanding is how a JsonRpcSigner is created when the provider is a web3provider (i.e., MetaMask). Doesn't a web3provider know its private key and should therefore return a Wallet when provider.getSigner() is run?
The Wallet singer is used when your ethers.js instance knows the private key directly.
Since MetaMask doesn't share the key with other applications, ethers.js uses the JsonRpcSigner to be able to request the local MetaMask instance over its API to sign the transaction when needed, and then receive the signed transaction back, without ethers.js ever knowing the key.
I think the Wallet subclass of abstract signer has both the sign and signMessage methods, but JsonRpcSigner (what you get from provider.getSigner()) does not. The use case is I'm trying to sign a transaction using sign from metamask for instance and then submit it later.

how to actually make an auction functionality into my daap?

I've been trying to make an NFT marketplace with the functionality of auctioning an item. But I don't know how to achieve this via signing transaction.
I have tried to use almost every method of signing from web3.js, but it requires the private key of the user.
However there's the function web3.eth.signTransaction which doesn't require any private key to sign the transaction, but it gives an error on the console. saying : Error: The method 'eth_signTransaction' does not exist / is not available.
Can someone give me an overview of how this signing and sending transaction can be done implementing the functionality of auctioning an nft like nft marketplaces: opensea or foundation.
From the docs:
Signs a transaction. This account needs to be unlocked.
It doesn't require the private key, but it requires the account (that is used for signing the transaction) to be unlocked on the node. Which means the node needs to hold the private key to unlock the account.
It's usually allowed on local nodes such as Ganache or private nodes.
And public nodes such as Infura usually disable this functionality (hence the error message "eth_signTransaction is not available") since they don't store your private keys.
You can ask the user to sign the transaction using their wallet. For example using MetaMask (or any other wallet implementing the Ethereum provider API):
const transactionParameters = {
from: ethereum.selectedAddress, // must match user's active address
to: 'your address'
};
await ethereum.request({
method: 'eth_sendTransaction',
params: [transactionParameters],
});

Extracting a MetaMask seed phrase over to a private key?

Currently going over MCD Doc's 'Creating a Value' section.
It requires one to set the Infura api key as well as a private key. Currently, I have a MetaMask account with test ether (Kovan) inside it. Yet, MetaMask only seems to allow you to reveal the private key through a 12-keyword seed phrase. How could I convert this phrase into the proper private key that the MCD docs is looking for (which I assume in this case is just a 64 hexadecimal string)?
Metamask allows to export the private key.
Go to your account, select details. It will show your address and QR code. Below there is a "Export your private key" menu, after typing Metamask password it will reveal the private key.

eosio cleos, transfer commands with --url is unsecured?

Is this command unsecured?
./cleos --url https://eos.greymass.com transfer from to "3 EOS" "memo"
Is my private key still secure?
Your private key is used to sign transactions. The signed transaction is what is transferred over the internet. Your private key is secured as long as the host machine that's storing the private key is secured.
Your private key is used only during sign_transaction which is a wallet operation. You cannot perform a wallet operation using third party/block producer API. You have to run keosd locally in your system to perform wallet operations.
To perform ./cleos --url https://eos.greymass.com transfer from to "3 EOS" "memo" action, you have to make your wallet imported with keys and it should be unlocked. This should done locally in your system.
In short, your keys are secure while using ./cleos --url https://eos.greymass.com

What is the difference between web3.eth.accounts.create and web3.eth.personal.newAccount

As I understand when using web3.eth.accounts.create(), it doesn't add the account to chain (I'm using ganache-cli for testing), but web3.eth.personal.newAccount() does.
Is it the main purpose or is it a bug?
Is there other differences?
web3.js version: 1.0.0-beta.34
Both versions create a new account on the blockchain. The difference is how you interact with the node and having access to the private key. If you have a local node, you can use web3.eth.accounts.create which will create the account and provide you access to the private key generate so it can be stored locally. However, since returning the private key over a connection isn’t secure, you should never use this approach to create an account if you connect through a provider like Infura.
On the other hand, you can use web3.eth.personal to create a new account on a remote node. In this case, the private key will not be returned to you, so you lose some flexibility with accessing your account. When you don’t have the private key, you can’t sign transactions locally. In order to run transactions, you have to call unlockAccount on the remote node. Note that you have to send your password to create/unlock your account using web3.eth.personal, so you still need to make sure you using a secure connection.
Review this Medium blog post for additional info.