@effectai/effect-js
Version:
Effect Network Javscript/Typescript SDK (for [https://effect.network](https://effect.network))
94 lines • 3.48 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Client = void 0;
const config_1 = require("./config");
const ipfs_1 = require("./services/ipfs");
const tasks_1 = require("./services/tasks");
const vaccount_1 = require("./services/vaccount");
const token_1 = require("./services/token");
const antelope_1 = require("@wharfkit/antelope");
const session_1 = require("@wharfkit/session");
const wallet_plugin_privatekey_1 = require("@wharfkit/wallet-plugin-privatekey");
const actions_1 = require("./services/actions");
const atomic_1 = require("./services/atomic");
const dao_1 = require("./services/dao");
class Client {
/**
* Create a new Effect Network Client instance
* @param {string} environment Which network you would like to connect to, defaults to 'jungle4'
*/
constructor(environment = 'jungle4', fetchProviderOptions) {
this.tasks = new tasks_1.TasksService(this);
this.ipfs = new ipfs_1.IpfsService(this);
this.vaccount = new vaccount_1.VAccountService(this);
this.efx = new token_1.TokenService(this);
this.action = new actions_1.ActionService(this);
this.atomic = new atomic_1.AtomicAssetsService(this);
this.dao = new dao_1.DaoService(this);
/**
* Retrieve the actor and permission from the session
* @returns [{ actor: Name; permission: Name }]
*/
this.sessionAuth = () => {
if (!this.session) {
throw new Error('Session is required for this method, please login.');
}
const { actor, permission } = this.session;
return [{ actor, permission }];
};
this.config = config_1.configPresets[environment];
this.fetchProvider = new antelope_1.FetchProvider(this.config.eosRpcUrl, {
fetch: fetchProviderOptions?.fetch ?? fetch ?? window?.fetch
});
this.eos = new antelope_1.APIClient({ provider: this.fetchProvider });
}
/**
* Login to the Effect Network with a session
* @param session Session object
*/
loginWithSession(session) {
this.session = session;
}
/**
* Login to the Effect Network with a private key
* @param actor EOS account name of the user
* @param permission EOS permission of the user
* @param privateKey EOS private key of the user
*/
login(actor, permission, privateKey) {
const walletPlugin = new wallet_plugin_privatekey_1.WalletPluginPrivateKey(privateKey);
this.loginWithSession(new session_1.Session({
actor,
permission,
walletPlugin,
chain: {
id: this.config.eosChainId,
url: this.config.eosRpcUrl,
},
}));
}
/**
* Logout from the Effect Network
*/
logout() {
// this.session = null;
}
/**
* Check if the user is logged in
* @returns {boolean} Whether or not the user is logged in
*/
isLoggedIn() {
return this.session === undefined && this.session === null;
}
/**
* Require a session to be set (make sure user is logged in), otherwise throw an error.
*/
requireSession() {
if (!this.session) {
throw new Error('Session is required for this method, please login.');
}
}
}
exports.Client = Client;
Client.__classname = 'Client';
//# sourceMappingURL=client.js.map