@biconomy/sdk
Version:
SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.
71 lines • 3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toOwnableValidator = exports.getOwnablesInitData = exports.getOwnablesModuleInitData = void 0;
const viem_1 = require("viem");
const constants_1 = require("../../constants/index.js");
const toModule_1 = require("../utils/toModule.js");
const getOwnablesModuleInitData = (parameters) => ({
address: constants_1.OWNABLE_VALIDATOR_ADDRESS,
type: "validator",
initData: (0, viem_1.encodeAbiParameters)([
{ name: "threshold", type: "uint256" },
{ name: "owners", type: "address[]" }
], [parameters.threshold, parameters.owners])
});
exports.getOwnablesModuleInitData = getOwnablesModuleInitData;
const getOwnablesInitData = (_) => "0x";
exports.getOwnablesInitData = getOwnablesInitData;
const toOwnableValidator = (parameters) => {
const { account, signer, client = account.client, initData: initData_ = "0x", initArgs: initArgs_, moduleInitArgs: moduleInitArgs_ = {
threshold: 1,
owners: [signer.address]
}, deInitData = "0x" } = parameters;
const nexusAccount = (0, constants_1.getAccount)({
address: account.address,
type: "nexus"
});
const moduleInitData = (0, constants_1.getOwnableValidator)({
threshold: moduleInitArgs_.threshold,
owners: moduleInitArgs_.owners
});
const initData = initData_ ?? (0, exports.getOwnablesInitData)(initArgs_);
return (0, toModule_1.toModule)({
signer,
accountAddress: account.address,
address: constants_1.OWNABLE_VALIDATOR_ADDRESS,
initData: (0, exports.getOwnablesInitData)(),
deInitData,
moduleInitData,
getStubSignature: async () => {
const isInstalled = await (0, constants_1.isRhinestoneModuleInstalled)({
account: nexusAccount,
client: client,
module: {
address: constants_1.OWNABLE_VALIDATOR_ADDRESS,
type: "validator",
module: constants_1.OWNABLE_VALIDATOR_ADDRESS,
initData: "0x",
deInitData: "0x",
additionalContext: "0x"
}
});
let threshold;
if (isInstalled) {
threshold = await (0, constants_1.getOwnableValidatorThreshold)({
account: nexusAccount,
client: client
});
}
else {
const [_threshold, _owners] = (0, viem_1.decodeAbiParameters)([
{ name: "threshold", type: "uint256" },
{ name: "owners", type: "address[]" }
], initData);
threshold = Number(_threshold);
}
return (0, constants_1.getOwnableValidatorMockSignature)({ threshold });
}
});
};
exports.toOwnableValidator = toOwnableValidator;
//# sourceMappingURL=toOwnableValidator.js.map