-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCosignAuthorityProvider.js
42 lines (34 loc) · 1.25 KB
/
CosignAuthorityProvider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 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.
const { convertLegacyPublicKeys } = require('eosjs/dist/eosjs-numeric');
module.exports = class CosignAuthorityProvider {
constructor(rpc) {
this.actor = 'energytester';
this.permission = 'active';
this.rpc = rpc;
}
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 === 'energytester'
&& auth.permission === 'active'
) {
delete transaction.actions[ti].authorization.splice(ai, 1)
}
})
});
// the rpc below should be an already configured JsonRPC client from eosjs
return convertLegacyPublicKeys((await this.rpc.fetch('/v1/chain/get_required_keys', {
transaction,
available_keys: args.availableKeys,
})).required_keys);
}
}