Coder Social home page Coder Social logo

Comments (12)

dcousens avatar dcousens commented on June 4, 2024 2

@ezailWang go complain to Facebook that they are doing a terrible job at supporting Buffer.

from bip39.

dcousens avatar dcousens commented on June 4, 2024 1

@fanatid we didn't default it to enforce that developers know that a password can be provided. Many BIP39 compliant wallets don't support user-provided passwords, which is frustrating.

from bip39.

junderw avatar junderw commented on June 4, 2024 1
> var pbkdf2 = require('pbkdf2').pbkdf2Sync
> pbkdf2(undefined, undefined, 2048, 64, 'sha512')
TypeError: Password must be a buffer or string
    at checkBuffer (/home/ddd/node_modules/pbkdf2/lib/precondition.js:5:11)
    at module.exports (/home/ddd/node_modules/pbkdf2/lib/precondition.js:10:3)
    at nativePBKDF2Sync (/home/ddd/node_modules/pbkdf2/index.js:17:3)

looks like the reason is because Buffer.from is returning undefined.

This is a react-native problem. Please ask them how to fix safe-buffer package for react-native.

from bip39.

fanatid avatar fanatid commented on June 4, 2024

Because second argument (password) should be passed: https://github.com/bitcoinjs/bip39/blob/v2.5.0/index.js#L50-L59

@dcousens @junderw should we set password as zero buffer by default?

from bip39.

ezailWang avatar ezailWang commented on June 4, 2024
pbkdf2(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512')

function pbkdf2 (password, salt, iterations, keylen, digest) {
checkParameters(password, salt, iterations, keylen)
...
}
function checkBuffer (buf, name) {
if (typeof buf !== 'string' && !Buffer.isBuffer(buf)) {
throw new TypeError(name + ' must be a buffer or string')
}
}
module.exports = function (password, salt, iterations, keylen) {
checkBuffer(password, 'Password')
checkBuffer(salt, 'Salt')
...
}

But the"Password" of error doesn't mean the second argument here.
The first argument here is the wrong one. If I change the check order, the second argument will also go wrong.

from bip39.

dcousens avatar dcousens commented on June 4, 2024

That, is odd.

bip39/index.js

Line 51 in bafbcd3

var mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8')
should enforce that the password argument to PBKDF2 is a Buffer...

Can you show us what is in that variable?

from bip39.

ezailWang avatar ezailWang commented on June 4, 2024

I'm going to output the information for this variable like this.

var mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8')
var saltBuffer = Buffer.from(salt(unorm.nfkd(password)), 'utf8')
console.log(mnemonicBuffer);
if (typeof mnemonicBuffer !== 'string' && !Buffer.isBuffer(mnemonicBuffer)) {
    console.log('mnemonicBuffer is not a buffer or string')
  }

2018-05-17 11 15 08

And I added the judgment statement here, which can be passed at this time, but cannot be passed in PDKDF2.

from bip39.

junderw avatar junderw commented on June 4, 2024

works for me...

unless you give us the actual inputs that caused your problem OR the actual code that caused your problem, we can't really help much.

from bip39.

junderw avatar junderw commented on June 4, 2024

Also, @dcousens unorm when called with undefined returns empty string ''

> unorm.nfkd(undefined)
''

from bip39.

ezailWang avatar ezailWang commented on June 4, 2024

My running environment is react-native, and I found that buffer was imported into the bip39.
var Buffer = require('safe-buffer').Buffer
Unlike the buffer used in precondition.js, buffer is not referenced in precondition.js.
2018-05-18 2 33 34

from bip39.

ezailWang avatar ezailWang commented on June 4, 2024

Find a solution and add this code before referring to bip39.
global.Buffer = require('safe-buffer').Buffer;

from bip39.

ezailWang avatar ezailWang commented on June 4, 2024

I feel like I've been complaining enough to them that I'm not friendly to the new guy.

from bip39.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.