wharfkit / signing-request

Library to assist in creating and digesting Signing Requests (ESR)
https://github.com/eosio-eps/EEPs/blob/master/EEPS/eep-7.md
Other
33 stars 20 forks source link

React Native "Unhandled promise rejection Error: Read past end of buffer" #8

Closed kylanhurt closed 3 years ago

kylanhurt commented 3 years ago

Attempting to get this implemented on React Native and am getting a Read past end of buffer error when trying to send a transaction. I was able to successfully send transactions through eosjs and am now trying to use that as the abiProvider. Any help would be appreciated!

import 'core-js';
import { SigningRequest } from 'eosio-signing-request';
import { TextDecoder, TextEncoder } from 'text-encoding';
import zlib from 'react-zlib-js';
const { Api, JsonRpc, RpcError } = require('eosjs');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig'); // development only

const Buffer = require('safe-buffer').Buffer;
const fetch = require('node-fetch'); // node only; not needed in browsers

global.Buffer = Buffer;

const eosRpc = new JsonRpc('https://mainnet.telosusa.io', { fetch });

const eosjsProvider = new JsSignatureProvider(['somekey']);

const eosApi = new Api({
  rpc: eosRpc,
  signatureProvider: eosjsProvider,
  textDecoder: new TextDecoder(),
  textEncoder: new TextEncoder(),
});

const options = {
  // string encoder
  textEncoder: new TextEncoder(),
  // string decoder
  textDecoder: new TextDecoder(),
  // zlib string compression (optional, recommended)
  zlib: {
    deflateRaw: (data) => new Uint8Array(zlib.InflateRaw(Buffer.from(data))),
    inflateRaw: (data) => new Uint8Array(zlib.DeflateRaw(Buffer.from(data))),
  },
  // Customizable ABI Provider used to retrieve contract data
  abiProvider: {
    getAbi: async (account) => await eosApi.getAbi(account),
  },
};

const App: () => React$Node = () => {
  const testSign = async () => {
    const req1 = await SigningRequest.create(
      {
        callback: {
          url: '',
          background: true,
        },
        action: {
          account: 'eosio.token',
          name: 'transfer',
          authorization: [{ actor: 'captaincrypt', permission: 'active' }],
          data: {
            from: 'captaincrypt',
            to: 'unmutediodap',
            quantity: '1.0001 TLOS',
            memo: 'Thanks for the Telos',
          },
        },
      },
      options,
    );
    console.log('req1 created: ', req1);
    const encoded = req1.encode();
    console.log('encoded: ', encoded);
    const req2 = SigningRequest.from(encoded, options);
    console.log('req2: ', req2);
  };

  useEffect(() => {
    testSign();
  }, []);
jnordberg commented 3 years ago

Is it when you decode the request again? A trace would be helpful to see where it goes wrong

You can also try to use the eosio-signing-request@next package, it uses our eosjs replacement eosio-core but the api is largely the same. We have been using that version successfully in react-native

jnordberg commented 3 years ago

Closing due to inactivity