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

proto-signing serialize() error #1429

Closed
atmoner opened this issue May 24, 2023 · 9 comments · Fixed by #1430
Closed

proto-signing serialize() error #1429

atmoner opened this issue May 24, 2023 · 9 comments · Fixed by #1430
Labels
bug Something isn't working

Comments

@atmoner
Copy link

atmoner commented May 24, 2023

I have a small problem on the use of DirectSecp256k1HdWallet from the lib @cosmjs/proto-signing 0.30.1
When I want to encode a mnenomic with the serialize() function I have an error on the lib libsodium:

TypeError: libsodium_wrappers_1.default.crypto_pwhash is not a function

Here is a simple script to reproduce the error:

import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"

const password = '420420420'
const wallet = await DirectSecp256k1HdWallet.generate(12)
const original = await DirectSecp256k1HdWallet.fromMnemonic(wallet.mnemonic, { 
  prefix: 'bcna',
});     
const serialized = await original.serialize(password);

console.log(wallet.mnemonic)
console.log(serialized)

Result:
image

Tested on:

Node.js v18.16.0
Node.js v16.15.0

Reproduct:

git clone https://gist.github.com/atmoner/16d00040cef99f4f6b30392aa92e454c bug-serialize
cd  bug-serialize
npm i

Run:

node app
@atmoner
Copy link
Author

atmoner commented May 25, 2023

I found the problem and I know how to fix it!

The problem is that your @cosmjs/crypto lib uses the libsoduim-wrapper lib while it and as indicated in the documentation, crypto_pwhash_* is only used in the sumo version
See the explanation here: https://github.com/jedisct1/libsodium.js#standard-vs-sumo-version

So I installed the libsodium-wrappers-sumo package in your @cosmjs/crypto and I replaced the import of libsodium-wrappers in libsodium.ts

And it works! 👍

I don't make pull requests since I don't know your workflow, I let you do your tests!

@webmaster128 webmaster128 added the bug Something isn't working label May 25, 2023
@webmaster128
Copy link
Member

Thank you for debugging this! It seems like crypto_pwhash was removed between 0.7.10 and 0.7.11 of the non-sumo version. See jedisct1/libsodium.js#313. Since we pin an older version in the CosmJS repo, we don't see the problem here.

However, it was documented for a long time that the function is not available:
jedisct1/libsodium.js@57599d2
jedisct1/libsodium.js@d297e49

@atmoner
Copy link
Author

atmoner commented May 25, 2023

@webmaster128 you are welcome o/

Yes you have to use the libsodium-wrappers-sumo version!
It is possible to update the crypto lib of cosmJs?
because currently the serialize() function does not work on cosmJs

@webmaster128
Copy link
Member

Yeah, this should fix it: #1430

@webmaster128
Copy link
Member

The fix is shipped as part of the pre-release 0.31.0-alpha.1

@atmoner
Copy link
Author

atmoner commented May 25, 2023

Perfect! thank you very much for your speed

@atmoner
Copy link
Author

atmoner commented May 25, 2023

@webmaster128 0.31.0-alpha.1 tested and works perfectly!! Thanks again

@mihail727
Copy link

when release 0.31 version?

@atmoner
Copy link
Author

atmoner commented May 27, 2023

when release 0.31 version?

use 0.31.0-alpha.1 of @cosmjs/crypto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants