CRYPTO NEWS

Getting public and private keys for an ethereum account keyfile and password

I was trying to generate the private and public key of an Ethereum account keyfile(one which gets generated at new account creation) and the password of account.

After I found 1st method, I tried to run keccak on public key to get hash and checked if its giving the account address or not. It printed some different address. So then I tried for another method, this time also I got same keypair.

Now I am confused about

  1. Is my code to get keypair is false(both the methods)?
  2. OR I am doing keccack part wrong?
  3. OR I am having completely wrong understanding of ethereum keypairs and address relation?
from web3.auto import w3 import binascii import ecdsa import codecs password = "Password string goes here"  #Getting privatekey with open(".//UTC--2022-06-16T17-01-58.671279300Z--af043ebbcc38ed68595ecd752040499afc4a69a0") as keyfile:     encrypted = keyfile.read()     pvt_key = w3.eth.account.decrypt(encrypted, password) print("Private key method 1: ") print(binascii.b2a_hex(pvt_key)) print()  #Getting public key private_key_bytes = bytearray.fromhex((binascii.b2a_hex(pvt_key)).decode("utf-8")) key = ecdsa.SigningKey.from_string(private_key_bytes, curve=ecdsa.SECP256k1).verifying_key key_bytes = key.to_string() key_hex = codecs.encode(key_bytes, 'hex') print("Public key method 1:") print(key_hex) print()  #Another method import eth_keys from eth_keys import keys from eth_utils import decode_hex from eth_account import account with open(".//UTC--2022-06-16T17-01-58.671279300Z--af043ebbcc38ed68595ecd752040499afc4a69a0") as keyfile:     encrypted = keyfile.read()     private_key = eth_keys.keys.PrivateKey(account.Account.decrypt(encrypted, password)) print("Private key method 2: ") print(private_key) print() priv_key_bytes = decode_hex(pvt_key.hex()) priv_key = keys.PrivateKey(priv_key_bytes) pub_key = priv_key.public_key print("Public key method 2: ") print(pub_key) print()  #Method to get adress after running keccak on public key #Not sure if its correct from Crypto.Hash import keccak public_key_bytes = bytearray.fromhex((binascii.b2a_hex(key_hex)).decode("utf-8")) keccak_hash = keccak.new(digest_bits=256) keccak_hash.update(public_key_bytes) keccak_digest = keccak_hash.hexdigest() wallet = "0x" +  keccak_digest[-40:] print(wallet) 

Transfer someone else’s NFT asset with an approve

I got this NFT marketplace smart contract. Still at the proof of concept stage, so I got 2 options to go with, I was just wondering if someone tried, or has knowledge about it: Here is the deal, I was thinking, when a user creates an item listing, instead of locking their listed item in::Listen

I got this NFT marketplace smart contract. Still at the proof of concept stage, so I got 2 options to go with, I was just wondering if someone tried, or has knowledge about it:

Here is the deal, I was thinking, when a user creates an item listing, instead of locking their listed item in my marketplace contract (user transfers it to the contract address), which is the mentioned option one, what if I cut down that process by letting them keep their NFT item, until someone purchases it, then transferring given NFT from sellers address to whoever bought it.

Now the question is (and it’s a tricky one) if it’s even possible to let the seller approve my marketplace contract on a given NFT item (when they create a listing) that I can use to process transferFrom function from seller address to buyer address when a buyer clicks on purchase function.

Will approval make that possible?

Getting public and private keys for an ethereum account keyfile and password

Shopping cart
There are no products in the cart!
Continue shopping
0