-
Notifications
You must be signed in to change notification settings - Fork 59
/
lit-node-client.ts
43 lines (37 loc) · 1.34 KB
/
lit-node-client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { LitNodeClientNodeJs } from '@lit-protocol/lit-node-client-nodejs';
import { checkAndSignAuthMessage } from '@lit-protocol/auth-browser';
import { CustomNetwork, LitNodeClientConfig } from '@lit-protocol/types';
import { isNode, log } from '@lit-protocol/misc';
import { getStorageItem } from '@lit-protocol/misc-browser';
import { EITHER_TYPE } from '@lit-protocol/constants';
export class LitNodeClient extends LitNodeClientNodeJs {
constructor(args: any[LitNodeClientConfig | CustomNetwork | any]) {
super({
...args,
defaultAuthCallback: checkAndSignAuthMessage,
});
// -- override configs
this.overrideConfigsFromLocalStorage();
}
/**
*
* (Browser Only) Get the config from browser local storage and override default config
*
* @returns { void }
*
*/
overrideConfigsFromLocalStorage = (): void => {
if (isNode()) return;
const storageKey = 'LitNodeClientConfig';
const storageConfigOrError = getStorageItem(storageKey);
// -- validate
if (storageConfigOrError.type === EITHER_TYPE.ERROR) {
log(`Storage key "${storageKey}" is missing. `);
return;
}
// -- execute
const storageConfig = JSON.parse(storageConfigOrError.result as string);
// this.config = override(this.config, storageConfig);
this.config = { ...this.config, ...storageConfig };
};
}