@lit-protocol/lit-node-client
Version:
This module is the main interface for interacting with the Lit Protocol network. It provides a robust client implementation that handles network communication, authentication, and node interactions in both browser and Node.js environments.
55 lines • 1.98 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.LitNodeClient = void 0;
const auth_browser_1 = require("@lit-protocol/auth-browser");
const constants_1 = require("@lit-protocol/constants");
const lit_node_client_nodejs_1 = require("@lit-protocol/lit-node-client-nodejs");
const misc_1 = require("@lit-protocol/misc");
const misc_browser_1 = require("@lit-protocol/misc-browser");
/**
* You can find all these available networks in the `constants` package
*
* @example
*
* ```
* import { LIT_NETWORK } from '@lit-protocol/constants';
*
* const litNodeClient = new LitNodeClient({
litNetwork: LIT_NETWORK.DatilTest,
});
* ```
*/
class LitNodeClient extends lit_node_client_nodejs_1.LitNodeClientNodeJs {
constructor(args) {
super({
...args,
defaultAuthCallback: auth_browser_1.checkAndSignAuthMessage,
});
/**
*
* (Browser Only) Get the config from browser local storage and override default config
*
* @returns { void }
*
*/
this._overrideConfigsFromLocalStorage = () => {
if ((0, misc_1.isNode)())
return;
const storageKey = 'LitNodeClientConfig';
const storageConfigOrError = (0, misc_browser_1.getStorageItem)(storageKey);
// -- validate
if (storageConfigOrError.type === constants_1.EITHER_TYPE.ERROR) {
(0, misc_1.log)(`Storage key "${storageKey}" is missing. `);
return;
}
// -- execute
const storageConfig = JSON.parse(storageConfigOrError.result);
// this.config = override(this.config, storageConfig);
this.config = { ...this.config, ...storageConfig };
};
// -- override configs
this._overrideConfigsFromLocalStorage();
}
}
exports.LitNodeClient = LitNodeClient;
//# sourceMappingURL=lit-node-client.js.map
;