UNPKG

@citizenwallet/sdk

Version:

An sdk to easily work with citizen wallet.

41 lines 2.02 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.instanceOwner = exports.getCardAddress = void 0; const CardManagerModule_abi_json_1 = __importDefault(require("../abi/CardManagerModule.abi.json")); const ethers_1 = require("ethers"); const getCardAddress = async (config, hashedSerial, options) => { const { accountFactoryAddress, instanceId } = options ?? {}; const rpc = new ethers_1.JsonRpcProvider(config.getRPCUrl(accountFactoryAddress)); const cardConfig = config.primarySafeCardConfig; const contract = new ethers_1.Contract(cardConfig.address, CardManagerModule_abi_json_1.default, rpc); const hashedInstanceId = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(instanceId ?? cardConfig.instance_id)); try { const accountAddress = await contract.getFunction("getCardAddress")(hashedInstanceId, hashedSerial); return accountAddress; } catch (error) { console.error("Error fetching account address:", error); return null; } }; exports.getCardAddress = getCardAddress; const instanceOwner = async (config, options) => { const { accountFactoryAddress, instanceId } = options ?? {}; try { const cardConfig = config.primarySafeCardConfig; const hashedInstanceId = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(instanceId ?? cardConfig.instance_id)); const rpc = new ethers_1.JsonRpcProvider(config.getRPCUrl(accountFactoryAddress)); const contract = new ethers_1.Contract(cardConfig.address, CardManagerModule_abi_json_1.default, rpc); const owner = await contract.getFunction("instanceOwner")(hashedInstanceId); return owner; } catch (error) { console.error("Error fetching instance owner:", error); return null; } }; exports.instanceOwner = instanceOwner; //# sourceMappingURL=index.js.map