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

Signing doesn't work in Node #13

Open
kincaidoneil opened this issue Jun 21, 2019 · 3 comments
Open

Signing doesn't work in Node #13

kincaidoneil opened this issue Jun 21, 2019 · 3 comments

Comments

@kincaidoneil
Copy link

This is building cosmos-keys from 81917a8.

I'm running the code below, adapted from this test:

const { signWithPrivateKey } = require("@lunie/cosmos-keys");

signWithPrivateKey(
  {
    account_number: "1",
    chain_id: "tendermint_test",
    fee: { amount: [{ amount: "0", denom: "" }], gas: "21906" },
    memo: "",
    msgs: [
      {
        type: "cosmos-sdk/Send",
        value: {
          inputs: [
            {
              address: "cosmos1qperwt9wrnkg5k9e5gzfgjppzpqhyav5j24d66",
              coins: [{ amount: "1", denom: "STAKE" }]
            }
          ],
          outputs: [
            {
              address: "cosmos1yeckxz7tapz34kjwnjxvmxzurerquhtrmxmuxt",
              coins: [{ amount: "1", denom: "STAKE" }]
            }
          ]
        }
      }
    ],
    sequence: "0"
  },
  Buffer.from(
    "2afc5a66b30e7521d553ec8e6f7244f906df97477248c30c103d7b3f2c671fef",
    "hex"
  )
);

Which errors with:
Error: Signing failed: private key should be a Buffer

I hypothesize this has to do with the way Webpack shims Buffers, which causes issues when using secp256k1 in Node, because the native version requires buffers, but is probably fine when used in a browser, since it falls back to using elliptic. (And since the test uses ts-jest rather than the Webpack bundle, the issue doesn't show up there.)

The native code in secp256k1 seems to complicate cross-platform compatibility. We've had a great experience using this WebAssembly alternative that's more portable (works seamlessly in Electron) and has decent performance, too. (One downside is the API might need to be async to ensure the WASM module is loaded). I'd be happy to PR that if you're interested!

@faboweb
Copy link
Contributor

faboweb commented Jun 22, 2019

If you could create a PR that would be amazing! Very interested in the approach.

@jnaviask
Copy link

I was also facing this problem and couldn't find a simple workaround.

@okwme
Copy link

okwme commented Jan 2, 2020

Running into this problem using lambda functions to sign transactions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants