tomusdrw / rust-web3

Ethereum JSON-RPC multi-transport client. Rust implementation of web3 library. ENS address: rust-web3.eth
MIT License
1.45k stars 471 forks source link

Account creation #540

Closed io12 closed 3 years ago

io12 commented 3 years ago

There are some functions in the web3.eth.accounts namespace of web3.js that could be useful in rust-web3 for account creation. For example, create and privateKeyToAccount.

tomusdrw commented 3 years ago

@io12 PRs welcome! It's also possible to extend Web3 with custom Namespace implementations (see here).

io12 commented 3 years ago

Oh, apparently create is secp256k1::SecretKey::new and privateKeyToAccount is signing::secret_key_address.

songtianyi commented 2 years ago

@io12 Is there any way to recover an account from mnemonic words as the web3js does?

 const web3 = new Web3(provider);
  let prikey = utils.getUserWallet(sponsorMnemonic, provider).privateKey;
  const accountFrom = {
    privateKey: prikey,
  };
  let signer = web3.eth.accounts.privateKeyToAccount(prikey);
  web3.eth.accounts.wallet.add(signer);
io12 commented 2 years ago

Is there any way to recover an account from mnemonic words as the web3js does?

@songtianyi It looks like the bip32 crate can do this, but I haven't tried it.

songtianyi commented 2 years ago

Is there any way to recover an account from mnemonic words as the web3js does?

@songtianyi It looks like the bip32 crate can do this, but I haven't tried it.

the bip32 doc says

[Limitations and further work](https://docs.rs/bip32/latest/bip32/#limitations-and-further-work)
Only 24-word BIP39 mnemonics are supported
BIP43, BIP44, BIP49, BIP84 not yet properly supported