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

wallet.encry #3075

Closed
encrylife opened this issue Jun 13, 2022 · 7 comments
Closed

wallet.encry #3075

encrylife opened this issue Jun 13, 2022 · 7 comments
Assignees
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@encrylife
Copy link

Ethers Version

5.6.8

Search Terms

wallet.encrypt

Describe the Problem

when I create a keystore,I can't import the json file with metamask, but I can load ethers.Wallet.fromEncryptedJson

Code Snippet

async function createEncryWallet(privateKey, password, provider) {
    var data = ''
    var wallet = GetAccount(privateKey, provider)
    
    function callback(progress) {
        // console.log("Encrypting: " + parseInt(progress * 100) + "% complete");
    }
    let encryptPromise = wallet.encrypt(password, callback);

    encryptPromise.then(function(json) {
        return json
    })
    return await encryptPromise
}

Contract ABI

No response

Errors

key derivation failed - possibly wrong passphrase

Environment

node.js (v12 or newer)

Environment (Other)

"secp256k1": "^4.0.3" "keccak": "^3.0.2"

@encrylife encrylife added the investigate Under investigation and may be a bug. label Jun 13, 2022
@encrylife
Copy link
Author

var loadFromFile = function (pwd) { var filePath = "./wallet/0x818411ea51940CedfDE263b6a725a55E5f0F3d5d.json" var content = fs.readFileSync(filePath).toString() ethers.Wallet.fromEncryptedJson(content, pwd).then(function(wallet) { console.log("Address: " + wallet.address); console.log("private key" + wallet.privateKey) // "Address: 0x88a5C2d9919e46F883EB62F7b8Dd9d0CC45bc290" }).catch( (err) => { console.log(err) }) } loadFromFile(123456)

it works well,but can't import to metamask

@ricmoo ricmoo added the on-deck This Enhancement or Bug is currently being worked on. label Jun 17, 2022
@hbarcelos
Copy link

hbarcelos commented Jun 21, 2022

I have a theory about the root cause.

The generated encrypted JSON has a "Crypto" property (with a capital C), however all tools I've used out there expects it to be all lowercase.

Make sure to change "Crypto" to "crypto" and it will probably work.

@hbarcelos
Copy link

hbarcelos commented Jun 22, 2022

Found the culprit:

@ricmoo I can issue a PR to fix this, but it's literally a 1-char diff.

To corroborate the theory, if you go to the Web3 Secret Storage Definition section of the Ethereum wiki, you will notice that all "crypto" properties start with a lower c.

@ricmoo
Copy link
Member

ricmoo commented Jun 22, 2022

Thanks! Yeah, don’t worry about a PR. I’ll test and make the change. Thanks for the research though. :)

@zemse
Copy link
Collaborator

zemse commented Jun 26, 2022

Just to mention this was there since ethers v4. I remember from my first web3 job for a startup, when I looked into this issue that some investors weren't able to load their keystore on the application. Not sure if there is a consensus/standard on using Crypto or crypto, but afair I've seen parity keystores using lowercase.

@ricmoo
Copy link
Member

ricmoo commented Jul 14, 2022

Awesome! Thanks for the info by the way. This definitely didn't used to be the case; all the test vectors generated by Geth have a "C" but those generated by Parity have a lower-case "c").

It's also why the ethers parser allows any case to be used, because it was so chaotic. :)

It will be fixed in v5.7.0.

@ricmoo ricmoo added the fixed/complete This Bug is fixed or Enhancement is complete and published. label Jul 14, 2022
@ricmoo
Copy link
Member

ricmoo commented Aug 19, 2022

This has been updated in v5.7.0.

Try it out and let me know if you have any problems.

Thanks! :)

@ricmoo ricmoo closed this as completed Aug 19, 2022
@ricmoo ricmoo added enhancement New feature or improvement. and removed on-deck This Enhancement or Bug is currently being worked on. investigate Under investigation and may be a bug. labels Aug 19, 2022
janek26 added a commit to argentlabs/argent-x that referenced this issue Aug 29, 2022
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

4 participants