UNPKG

@aut-labs/sdk

Version:

The TS/JS SDK package aims to make it easy for frontends/backends to integrate with Aut Smart Contracts

89 lines 3.53 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const hubRegistry_service_1 = require("./services/hubRegistry.service"); const ipfs_service_1 = require("./services/ipfs.service"); const autID_service_1 = require("./services/autID.service"); const taskRegistry_service_1 = require("./services/taskRegistry.service"); const logger_1 = __importDefault(require("./utils/logger")); __exportStar(require("./contracts"), exports); __exportStar(require("./services"), exports); __exportStar(require("./utils"), exports); __exportStar(require("./models"), exports); class AutSDK { constructor(config) { this.config = config; this.services = {}; AutSDK._instance = this; if (this.config.ipfs) { this.client = new ipfs_service_1.IPFSClient(this.config.ipfs); } this._logger = new logger_1.default({ hideLogForProduction: !this.config.enableDebug }); } static async getInstance(wait = true) { if (AutSDK._initialized || !wait) { return AutSDK._instance; } return new Promise((resolve) => { AutSDK._resolve = resolve; AutSDK._timeout = setTimeout(() => { if (AutSDK._resolve) { AutSDK._resolve(AutSDK._instance); } }, 5000); }); } get signer() { return this._multiSigner?.signer; } async init(multiSigner, contracts, biconomy) { this._biconomy = biconomy; this._multiSigner = multiSigner; if (contracts.autIDAddress) { this.autID = this.initService(autID_service_1.AutID, contracts.autIDAddress); } if (contracts.hubRegistryAddress) { this.hubRegistry = this.initService(hubRegistry_service_1.HubRegistry, contracts.hubRegistryAddress); } if (contracts.taskRegistryAddress) { this.taskRegistry = this.initService(taskRegistry_service_1.TaskRegistry, contracts.taskRegistryAddress); } if (biconomy) { await biconomy.initializeBiconomy(multiSigner.signer); } if (AutSDK._timeout) { clearTimeout(AutSDK._timeout); if (AutSDK._resolve) { AutSDK._resolve(this); AutSDK._resolve = null; } AutSDK._timeout = null; } AutSDK._initialized = true; console.log("Aut SDK was initialized."); } initService(contract, address) { return new contract(address, this._multiSigner, this._biconomy, this.client); } } exports.default = AutSDK; AutSDK._initialized = false; //# sourceMappingURL=index.js.map