@locker-labs/sdk
Version:
A utility library for enhancing your ERC-4337 experience
58 lines • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createLockerClient = createLockerClient;
const infra_1 = require("@account-kit/infra");
const smart_contracts_1 = require("@account-kit/smart-contracts");
const helpers_js_1 = require("./helpers.js");
function validateClientParams(params) {
if (!params.alchemyApiKey || params.alchemyApiKey.trim() === "") {
throw new Error("Invalid parameter: 'apiKey' is required and cannot be empty.");
}
if (!params.chain) {
throw new Error("Invalid parameter: 'chain' is required.");
}
if (!params.signer) {
throw new Error("Invalid configuration: No signer provided and no default PRIVATE KEY found in environment.");
}
}
async function createLockerClient(params) {
validateClientParams(params);
const { alchemyApiKey: apiKey, chain: lockerChain, signer, salt } = params;
const chain = (0, helpers_js_1.adaptLockerChain2AlchemyChain)(lockerChain);
const aaClient = await (0, smart_contracts_1.createModularAccountAlchemyClient)({
salt: salt ? salt : BigInt(0),
signer,
chain,
transport: (0, infra_1.alchemy)({ apiKey }),
});
const lockerClient = {
getAddress: () => aaClient.getAddress(),
isPluginInstalled: async (plugin) => {
const installedPlugins = await aaClient.getInstalledPlugins({});
if (!installedPlugins.includes(plugin)) {
return false;
}
return true;
},
extend: (pluginActions) => aaClient.extend(pluginActions),
installPlugin: async (plugin) => {
return await aaClient.installPlugin({
pluginAddress: plugin,
});
},
uninstallPlugin: async (plugin) => {
return await aaClient.uninstallPlugin({ pluginAddress: plugin });
},
sendUserOps: async (to, data, value) => {
return await aaClient.sendUserOperation({
uo: {
target: to,
data,
value,
},
});
},
};
return lockerClient;
}
//# sourceMappingURL=impl.js.map