GetScatter / ScatterWebExtension

Extension that allows you to sign transactions with your private keys securely from within the browser without ever exposing them.
MIT License
367 stars 127 forks source link

Error calling getArbitrarySignature (TypeError: t(...)[u] is not a function) #172

Open jurosh opened 5 years ago

jurosh commented 5 years ago

As per docs here https://get-scatter.com/docs/api-request-arbitrary-signature

Scatter should be able to get signature like:

// getScatterEosInstance is getting eos instance based on network...
const scatterInstance = getScatterEosInstance([
    { actor: makerAccount, permission: 'active' }
  ]);
const scattertSignature = await scatterInstance.getArbitrarySignature(
    makerPublicKey,
    'test', // orderBuffer.toString(),
    'Order signing',
    false
  );

Instead promise is rejected with reason:

"TypeError: t(...)[u] is not a function
    at Promise (chrome-extension://ammjpmhgckkpcamddpolhchgomcojkle/inject.js:40:270202)
    at new Promise (<anonymous>)
    at Proxy.n (chrome-extension://ammjpmhgckkpcamddpolhchgomcojkle/inject.js:40:270118)
    at _callee$ (webpack-internal:///./src/client/eos/trading.js:100:49)
    at tryCatch (webpack-internal:///./node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:65:40)
    at Generator.invoke [as _invoke] (webpack-internal:///./node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:303:22)
    at Generator.prototype.(anonymous function) [as next] (webpack-internal:///./node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:117:21)
    at step (webpack-internal:///./src/client/eos/trading.js:217:191)
    at eval (webpack-internal:///./src/client/eos/trading.js:217:437)
    at new Promise (<anonymous>)
    at eval (webpack-internal:///./src/client/eos/trading.js:217:99)
    at signOrderWithScatter (webpack-internal:///./src/client/eos/trading.js:137:18)
    at <anonymous>:1:1"

Using scatter extension 6.1.10 on Chrome (Linux)

nsjames commented 5 years ago

Need more code here to see what's going on ( like what getScatterEosInstance is doing ). Also, I see you're using extension, have to tried to check if this works from desktop? Lots of functionality is missing from the extension.

jurosh commented 5 years ago

Wanted to build and try desktop version but ran into https://github.com/GetScatter/ScatterDesktop/issues/156 :x:

Here are some details about getScatterEosInstance

// Tried also with latest scatter-js and same result...
import ScatterJS from 'scatter-js/dist/scatter.esm';
import Eos from 'eosjs';

...

export const getScatterEosInstance = (
  actors: Array<{ actor: string, permission: string }>,
  moreOptions: any = {}
) => {
  const options = {
    broadcast: true,
    chainId,
    authorization: actors,
    ...moreOptions
  };
  const scatterEos = ScatterJS.scatter.eos(eosNetwork, Eos, options, 'http');
  if (scatterEos === undefined || scatterEos === null) {
    // 'failed to obtain the Scatter eosjs instance.'
    // throw error....
  }
  return scatterEos;
};
nsjames commented 5 years ago

Looks like you aren't pulling in the ScatterEOS plugin: https://get-scatter.com/docs/examples-interaction-flow

jurosh commented 5 years ago

Forgot to paste it here, but I am doing eos initialization ScatterJS.plugins(new ScatterEOS()); in another file..

Cannot make this code to be functional:

scatterInstance.getArbitrarySignature(
    userPublicKey,
    'testToSign',
    'Order signing',
    false
);

@nsjames can you confirm it's working for you ? Already tried Scatter Desktop too and looks like it's same issue - so maybe error in scatter eos plugin or am I calling it wrong way ?

nsjames commented 5 years ago

Those imports, and the ScatterJS.plugins(new ScatterEOS()); instantiation should be done as early as possible in your app, and only in a single location and then fetched from a global store/state-handler.

By doing:

import ScatterJS from 'scatter-js/dist/scatter.esm';
import Eos from 'eosjs';

That instance of ScatterJS has no knowledge of any plugins in any other files as the scopes are different.

jurosh commented 5 years ago

So I am getting into the core of issue. Looks like I have to use ScatterJS.scatter for getting signatures but I was using ScatterJS.scatter.eos instead.