51

Regular Address EIP 55 added a "capitals-based checksum" which was implemented by Geth by May 2016. Here's Javascript code from Geth: /** * Checks if the given string is an address * * @method isAddress * @param {String} address the given HEX adress * @return {Boolean} */ var isAddress = function (address) { if (!/^(0x)?[0-9a-f]{40}$/i.test(...


38

You can if and only if a transaction has been sent from the account. When you send a tx, you sign the transaction and it includes these v r and s values. You parse these from the signed tx and then pass these v r and s values and the hash of the transaction back into a function and it'll spit out the public key. This is actually how you get the from address ...


34

There is an easier way now with web3: Naive: https://web3js.readthedocs.io/en/v1.2.0/web3-utils.html#isaddress web3.utils.isAddress('0xc1912fee45d61c87cc5ea59dae31190fffff232d'); > true OR Better version https://web3js.readthedocs.io/en/v1.2.0/web3-utils.html#tochecksumaddress try { const address = web3.utils.toChecksumAddress(rawInput) } catch(e) ...


33

thx @Edmunx Edgar, i tried to use ECIES, but it failed to install because of a subdepencency. I now used the bitcore-lib together with bitcore-ecies. This works like expected. EDIT: I created a npm-module which does exactly theses things and also has some performance optimisations and tutorials: github:eth-crypto. Here is my code for anyone with the same ...


20

Yes and no. No - a Bitcoin address cannot be directly used in Ethereum, and vice versa. Yes - underneath, a bitcoin private key is essentially a random 256-bit number (in a certain range, see bitcoin wiki). And the private key's corresponding public key is essentially the x and y coordinates of a point on an elliptic curve. Bitcoin and Ethereum both use ...


16

ethereumjs-wallet can be used to get public key from private key: > const hdkey = require('ethereumjs-wallet/hdkey') > const privateKey = hdkey.fromMasterSeed('random')._hdkey._privateKey > const Wallet = require('ethereumjs-wallet') > const wallet = Wallet.fromPrivateKey(privateKey) > wallet.getPublicKeyString() '...


11

No specific usecase of public key, As usually one can ask for public key(address) that means informally we sometimes say public key despite of address. An Ethereum address represents an account. For external owned accounts, the address is derived as the last 20 bytes of the public key controlling the account, e.g., ...


11

Just to add to the very good accepted answer: Coin | Address size | Address encoding | Address creation ---------+---------------------+------------------+------------------ Bitcoin | 160 bits (20 bytes) | Base58Check | RIPEMD160(SHA256(<public_key>) Ethereum | 160 bits (20 bytes) | HEX* | KECCAK256(<public_key>)** ...


10

Some of the links in the comments helped me get the answers to my questions. I have collected all that information combined with my own (recently acquired) knowledge of cryptography from the Coursera Cryptography-I class (for the answer to question number 3). A1. The private key is never (or should never be) saved unencrypted on disk. It is generated from ...


10

Assuming you have the public key of the person you want to send a message to (if they've already signed a transaction you can recover it from the signature) it should be possible to encrypt and decrypt using ECIES. Apparently there's a JavaScript library for this, I assume you can use it in a browser: https://bitcointalk.org/index.php?topic=627927.0 I have ...


10

When you are creating a new wallet, what you are doing is creating an account. Every account has a private key and a public key, and are indexed by an address that is where you send the transaction. The address is the last 20 bytes of the hash of the public key. According to the documentation: Every account is defined by a pair of keys, a private key ...


9

The standard 40 character hex addresses now have a checksum in the form of capitalization. If the address has at least one capital letter then it is checksummed and, if inputted on a site that checks the sum, it will return false if it's not a valid address. The scheme is as follows: convert the address to hex, but if the ith digit is a letter (ie. it's ...


7

I don't think this is possible, since you lose information when going from public key to address: Start with the public key (64 bytes) Take the Keccak-256 hash of the public key. You should now have a string that is 32 bytes. (note: SHA3-256 eventually became the standard, but Ethereum uses Keccak) Take the last 20 bytes of this public key (Keccak-...


7

This works: return address(keccak256(publicKey) & (2**(8*21)-1)); 2**(8*21)-1 is just a trick to get 0xFFFFFF... (40 Fs) without typing it. :-) EDIT As pointed out by @schnorr, there's no need for the mask: return address(keccak256(publicKey));


6

Contracts cannot access the public key of the sender, since the raw transaction data is not visible to contracts. However, given the public key, you can verify that it does in fact match the address of the sender by re-deriving the address from the public key. In Solidity it would look something like this: function checkPubKey(bytes pubkey) constant ...


6

Ethereum security model relies on elliptic curve cryptography (ECC) to sign and validate transactions. In ECC public and private key are used to sign and verify. It has no concept of addresses. When signing and verifying transactions you do not need addresses. The original bitcoin paper do not mention addresses at all. They appear later in an effort to ...


6

An account address - either an externally owned account (what you're calling a wallet), or a contract account - isn't the same thing as a memory address. It's not possible to know what exists at "contract address + X", because account addresses aren't a mapping into a contiguous piece memory. As a primer, see the big picture (literally) here: https://...


5

The python package 'ethereum' has a function called 'check_checksum' in the utils module: from ethereum.utils import check_checksum check_checksum('0xc1912fee45d61c87cc5ea59dae31190fffff232d') > True I build a small project for this which i use programmatically in my apps. It has a 'micro' api: https://balidator.io/api/ethereum/...


4

function validateInputAddresses(address) { return (/^(0x){1}[0-9a-fA-F]{40}$/i.test(address)); }


4

I believe there is no practical use of the public key. Because of this, in most account creation tools, the public key is never even displayed to the user. (You could use the public key to encrypt a message such that only the private key holder can decrypt it, but this isn't typically done in Ethereum.)


4

Full public keys aren't really that useful in Ethereum*, as they don't serve any practical use. Taking the last 20 bytes is a: Heuristic aimed to simplify the management of the key; that is, copy and pasting, checksums or confirmations over the phone in large transfers. Pre-empting security mechanism. Hashing functions are broken every other decade or so, ...


4

If you want convert private key to public key and not address, then I would recommend using eth-keys library. It is in the dependencies of eth-account library, which is in the dependencies of web3py. Private key, used for account generation, consists of 64 hexadecimal characters (32 bytes total). So, if you have 32-bytes private key, then public key can be ...


3

By default, GPG generates a 2048-bit RSA key. This requires generating a very large random number that has structural requirements to make it a valid RSA private key. So not any random number will do. You might have to try several before you find one that meets the requirements. GPG also typically creates both a master key and a subkey. So you're creating ...


3

A Quorum node's keypair is generated using Constellation. Depending on which version you have, you run either of the following to generate tm.key (private key) and tm.pub (public key) files. You can just hit return when prompted to set a password unless you really want one. Old way: constellation-enclave-keygen tm New way: constellation-node --...


3

One possible setup: Store a private key inside the physical devices. It should be the same for all devices, and only known to you. You should make sure people can't get at it using whatever mechanism your hardware provides. Write the public key of this private key as a constant into your smart contract When creating a transaction, the device uses the ...


3

Both Ethereum and Bitcoin uses the same elliptic curve for private keys secp256k1. The difference is Ethereum formats addresses as hexadecimal and bitcoin as base58. It can be made such that ecrecover to work for both, it returns the raw 20 bytes without address formatting. One possible issue is that Ethereum uses keccak256 for signing, and bitcoin ...


3

ethereumjs-wallet does support HDWallet and let you calculate the address corresponding to an extended public key var hdkey = require('ethereumjs-wallet/hdkey'); var extPubKey = 'xpub6ERoQFMqiUoTXAL56JpQYLq5FyXaZypJiKdsAbHKzMUQsSiJTNSMnBtYYRXxda9C6fUx6mMMqatUDNFSKxxXcpBcpPkTqVwyethpWiQN8p5'; var hdwallet = hdkey.fromExtendedKey(extPubKey); var wallet = ...


3

Transforming a private key to a public key does not require the network. It's only cryptography. The network does not do any computation for you to give you the answer. An easier solution using Node.js: > const Wallet = require('ethereumjs-wallet'); undefined > Wallet.fromPrivateKey(Buffer.from('...


3

You need to hash the bytes of the public key (not the public key string). In Javascript https://runkit.com/embed/2w4f7dvkz2lg keccak256 = require('js-sha3').keccak256; keccak256(new Buffer('25b867253fe38ac7ed594f54b4f55fa18c49ced332fc352991e48a77ab7816c759d46cab51a59d9833cd6d958cc752ad95f10bbe469b364db2de5d3535417966', 'hex')).slice(24) "...


3

Without a signature, there's no way to get the public key (short of someone giving it to you). So for an address that has never made a transaction, this can't be done. (I'm not sure where getTransactionReceipt comes in. If you're calling that, then surely the account has made a transaction, so you can recover the public key.)


Only top voted, non community-wiki answers of a minimum length are eligible