ssbc / ssb-keys

keyfile operations for ssb
36 stars 26 forks source link

generate() fails in electron #28

Closed uiur closed 7 years ago

uiur commented 8 years ago

electron: v1.2.8

ssbKeys.generate() throws an error in my electron environment.

Error: argument sd must be a buffer
    at Error (native)
    at Object.generate (/Users/zat/.ghq/github.com/uiureo/sonoba/node_modules/ssb-keys/sodium.js:13:30)
    at Object.exports.generate (/Users/zat/.ghq/github.com/uiureo/sonoba/node_modules/ssb-keys/index.js:78:37)
    at Object.<anonymous> (/Users/zat/.ghq/github.com/uiureo/sonoba/main.js:8:21)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at loadApplicationPackage (/Users/zat/.ghq/github.com/uiureo/sonoba/node_modules/electron-prebuilt/dist/Electron.app/Contents/Resources/default_app.asar/main.js:257:12)

The problem is that sodium.randombytes(buffer) returns true in the electron environment. This is weird because it returns null in node environment and works correctly.

seed = seed || sodium.randombytes(seed = new Buffer(32))
var keys = seed ? sodium.crypto_sign_seed_keypair(seed) : sodium.crypto_sign_keypair()

https://github.com/ssbc/ssb-keys/blob/c6ca6ea4a1433067774515ee3b8b5250962fb050/sodium.js#L9

I think that seed = seed || sodium.randombytes(seed = new Buffer(32)) is not necessary and removing this line resolves the issue. But I don't understand well how it behaves in other environments.

dominictarr commented 8 years ago

Thanks, fixed in ssb-keys@6.1.2 By the way, we are shifting development of ssb-* modules to use https://github.com/clehner/git-ssb we'll still take pull requests via github, of course, but git-ssb is preferred.

uiur commented 8 years ago

Thanks! git-ssb looks nice.