@1hive/connect-core
Version:
Access and interact with Aragon Organizations and their apps.
57 lines • 2.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isKernelSetAppIntent = exports.isKernelAppCodeNamespace = exports.decodeKernelSetAppParameters = exports.getKernelNamespace = void 0;
const abi_1 = require("@ethersproject/abi");
const solidity_1 = require("@ethersproject/solidity");
const address_1 = require("./address");
const app_1 = require("./app");
const CORE_NAMESPACE = solidity_1.keccak256(['string'], ['core']);
const APP_ADDR_NAMESPACE = solidity_1.keccak256(['string'], ['app']);
const APP_BASES_NAMESPACE = solidity_1.keccak256(['string'], ['base']);
const KERNEL_NAMESPACES_NAMES = new Map([
[CORE_NAMESPACE, 'Core'],
[APP_ADDR_NAMESPACE, 'Default apps'],
[APP_BASES_NAMESPACE, 'App code'],
]);
const SET_APP_ABI = [
{ name: 'namespace', type: 'bytes32' },
{ name: 'appId', type: 'bytes32' },
{ name: 'appAddress', type: 'address' },
].map((param) => abi_1.ParamType.from(param));
function getKernelNamespace(hash) {
return KERNEL_NAMESPACES_NAMES.has(hash)
? { name: KERNEL_NAMESPACES_NAMES.get(hash), hash }
: null;
}
exports.getKernelNamespace = getKernelNamespace;
/**
* Decode `Kernel.setApp()` parameters based on transaction data.
*
* @param {Object} data Transaction data
* @return {Object} Decoded parameters for `setApp()` (namespace, appId, appAddress)
*/
function decodeKernelSetAppParameters(data) {
// Strip 0x prefix + bytes4 sig to get parameter data
const paramData = data.substring(10);
return abi_1.defaultAbiCoder.decode(SET_APP_ABI, paramData);
}
exports.decodeKernelSetAppParameters = decodeKernelSetAppParameters;
function isKernelAppCodeNamespace(namespaceHash) {
return namespaceHash === APP_BASES_NAMESPACE;
}
exports.isKernelAppCodeNamespace = isKernelAppCodeNamespace;
/**
* Is the transaction intent for `Kernel.setApp()`?
*
* @param {Object} kernelApp App artifact for Kernel
* @param {Object} intent Transaction intent
* @return {Boolean} Whether the intent is `Kernel.setApp()`
*/
function isKernelSetAppIntent(kernelApp, intent) {
if (!address_1.addressesEqual(kernelApp.address, intent.to))
return false;
const method = app_1.findAppMethodFromData(kernelApp, intent.data);
return !!method && method.sig === 'setApp(bytes32,bytes32,address)';
}
exports.isKernelSetAppIntent = isKernelSetAppIntent;
//# sourceMappingURL=kernel.js.map