Skip to content

Instantly share code, notes, and snippets.

@aaroncox
Last active February 14, 2025 17:37
Show Gist options
  • Save aaroncox/102a70a9a6a37a9c2a90b6fabfbc86e7 to your computer and use it in GitHub Desktop.
Save aaroncox/102a70a9a6a37a9c2a90b6fabfbc86e7 to your computer and use it in GitHub Desktop.
Using a custom authority provider within eosjs for Greymass Fuel
// A custom cosigner AuthorityProvider for EOSJS v2
// This provider overrides the checks on all keys,
// allowing a partially signed transaction to be
// broadcast to the API node.
class CosignAuthorityProvider {
async getRequiredKeys(args) {
const { transaction } = args;
// Iterate over the actions and authorizations
transaction.actions.forEach((action, ti) => {
action.authorization.forEach((auth, ai) => {
// If the authorization matches the expected cosigner
// then remove it from the transaction while checking
// for what public keys are required
if (
auth.actor === 'greymassfuel'
&& auth.permission === 'cosign'
) {
delete transaction.actions[ti].authorization.splice(ai, 1)
}
})
});
return convertLegacyPublicKeys((await rpc.fetch('/v1/chain/get_required_keys', {
transaction,
available_keys: args.availableKeys,
})).required_keys);
}
}
// Pass in new authorityProvider
const api = new Api({
authorityProvider: new CosignAuthorityProvider(),
// the rest of your configuration
});
@nadiaalicante1
Copy link

I hope it worked

@najmahmd
Copy link

// A custom cosigner AuthorityProvider for EOSJS v2
// This provider overrides the checks on all keys,
// allowing a partially signed transaction to be
// broadcast to the API node.
class CosignAuthorityProvider {
async getRequiredKeys(args) {
const { transaction } = args;
// Iterate over the actions and authorizations
transaction.actions.forEach((action, ti) => {
action.authorization.forEach((auth, ai) => {
// If the authorization matches the expected cosigner
// then remove it from the transaction while checking
// for what public keys are required
if (
auth.actor === 'greymassfuel'
&& auth.permission === 'cosign'
) {
delete transaction.actions[ti].authorization.splice(ai, 1)
}
})
});
return convertLegacyPublicKeys((await rpc.fetch('/v1/chain/get_required_keys', {
transaction,
available_keys: args.availableKeys,
})).required_keys);
}
}

// Pass in new authorityProvider
const api = new Api({
authorityProvider: new CosignAuthorityProvider(),
// the rest of your configuration
});

@gurujustin
Copy link

gurujustin commented Jan 6, 2023

const { Api, JsonRpc } = require('eosjs');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig');
const { convertLegacyPublicKeys } = require('eosjs/dist/eosjs-numeric');

const privateKey = process.env.PRIVATE_KEY_EOS;
const signatureProvider = new JsSignatureProvider([privateKey]);

// Set up the API and JSON-RPC objects
const rpc = new JsonRpc('https://api.bitmars.one');

class CosignAuthorityProvider {
  async getRequiredKeys(args) {
    const { transaction } = args;
    // Iterate over the actions and authorizations
    transaction.actions.forEach((action, ti) => {
      action.authorization.forEach((auth, ai) => {
        // If the authorization matches the expected cosigner
        // then remove it from the transaction while checking
        // for what public keys are required
        if (
          auth.actor === "greymassfuel"
          && auth.permission === "cosign"
        ) {
          delete transaction.actions[ti].authorization.splice(ai, 1)
        }
      })
    });
    return convertLegacyPublicKeys((await rpc.fetch('/v1/chain/get_required_keys', {
      transaction,
      available_keys: args.availableKeys,
    })).required_keys);
  }
}
const api = new Api({ authorityProvider: new CosignAuthorityProvider(), rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });

const eosSwap = async () => {
  console.log('======EOS=======')
  
  // Call the contract
  try {
    const result = await api.transact({
      actions: [{
          account: "greymassnoop",
          name: "noop",
          authorization: [{
            actor: "greymassfuel",
            permission: "cosign"
          }],
          data: {}
        },
        {
          account: "eosio.token",
          name: "transfer",
          authorization: [{
            actor: "hubenokdevel",
            permission: "active"
          }],
          data: {
            from: "hubenokdevel",
            to: "fuel.gm",
            quantity: "0.0020 EOS",
            memo: "Fuel Transaction Fee | ref=teamg..."
          }
        },
        {
        account: "hubenokdevel",
        name: "buytoken",
        authorization: [{
          actor: 'hubenokdevel',
          permission: 'active',
        }],
        data: {
          user: "hubenokdevel",
          eos_amount: "0.1000 EOS",
          id_pool: 12,
          token_amount_per_native: "0.866 U",
          slippage_bips: 100,
          platform_fee_bips: 2000,
          gas_estimate: 20,
          recipient: "eosviralswap"
        },
      }]
    }, {
      blocksBehind: 3,
      expireSeconds: 30,
    });
    console.log(result);
  } catch (error) {
    console.error(error);
  }

}

module.exports = {
  eosSwap
}

this is my code and it's not working.
eosjs version is 22.1.0

RpcError: transaction declares authority '{"actor":"greymassfuel","permission":"cosign"}', but does not have signatures for it under a provided delay of 0 ms, provided permissions [], provided keys ["EOS54itY6cctjQP6pzNkuzdBfVKFjf7You8o1CbguhU66Ays4yBmp"], and a delay max limit of 3888000000 ms

@jmgayosso
Copy link

Hi @aaroncox I have exactly the same issue, Did you find the way to solve it??

@ttb-inc
Copy link

ttb-inc commented Feb 14, 2025

Hi,
I'm using the Anchor mobile app on UNICOVE.
Why am I getting this error?
What is the workaround?


Error: transaction declares authority
'{"actor":"greymassfuel","permission":"cosign"}',
but does not have signatures for it under a provided delay of 0 ms,
provided permissions [],
provided keys ["EOS8gGT...dkGL"],
and a delay max limit of 3888000000 ms

Thanks a lot.

@aaroncox
Copy link
Author

I'm not sure why that would be appearing without more details. If you could shoot an email over to [email protected] and let us know which page you were on and what action you were trying to perform when that error appeared, it'd help us track things down. Thanks!

@ttb-inc
Copy link

ttb-inc commented Feb 14, 2025

Thank you for your response.
I will reorganize and send you an email.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment