UNPKG

@1hive/connect-core

Version:

Access and interact with Aragon Organizations and their apps.

57 lines 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getACLForwardingPath = void 0; const getForwardingPath_1 = require("./getForwardingPath"); const abi_1 = require("../abi"); const app_1 = require("../app"); /** * Get the permission manager for an `app`'s and `role`. * * @param {string} appAddress * @param {string} roleHash * @return {Promise<string>} The permission manager */ async function getPermissionManager(appAddress, roleHash, installedApps) { var _a; const app = installedApps.find((app) => app.address === appAddress); const roles = await (app === null || app === void 0 ? void 0 : app.roles()); return (_a = roles === null || roles === void 0 ? void 0 : roles.find((role) => role.hash === roleHash)) === null || _a === void 0 ? void 0 : _a.manager; } /** * Calculates transaction path for performing a method on the ACL * * @param {string} methodSignature * @param {Array<*>} params * @return {Promise<Array<Object>>} An array of Ethereum transactions that describe each step in the path */ async function getACLForwardingPath(sender, acl, methodSignature, params, installedApps, provider) { const method = app_1.findAppMethodFromSignature(acl, methodSignature, { allowDeprecated: false, }); if (!method) { throw new Error(`No method named ${methodSignature} on ACL`); } if (method.roles && method.roles.length !== 0) { // This action can be done with regular transaction pathing (it's protected by an ACL role) return getForwardingPath_1.getForwardingPath(sender, acl, methodSignature, params, installedApps, provider); } else { // Some ACL functions don't have a role and are instead protected by a manager // Inspect the matched method's ABI to find the position of the 'app' and 'role' parameters // needed to get the permission manager const methodAbiFragment = abi_1.findMethodAbiFragment(acl.abi, methodSignature); if (!methodAbiFragment) { throw new Error(`Method ${method} not found on ACL ABI`); } const inputNames = methodAbiFragment.inputs.map((input) => input.name); const appIndex = inputNames.indexOf('_app'); const roleIndex = inputNames.indexOf('_role'); if (appIndex === -1 || roleIndex === -1) { throw new Error(`Method ${methodSignature} doesn't take _app and _role as input. Permission manager cannot be found.`); } const manager = await getPermissionManager(params[appIndex], params[roleIndex], installedApps); return getForwardingPath_1.getForwardingPath(sender, acl, methodSignature, params, installedApps, provider, manager); } } exports.getACLForwardingPath = getACLForwardingPath; //# sourceMappingURL=getACLForwardingPath.js.map