Skip to content

Feature/lit 3139 identify private methods in litnodeclient #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2308b16
refactor: make `checkNeedToResignSessionKey` private
Ansonhkg May 29, 2024
5e02115
chore: remove unused function
Ansonhkg May 29, 2024
1ccd46a
chore: reorganised methods placement
Ansonhkg May 29, 2024
7190ca1
chore: privateised methods
Ansonhkg May 29, 2024
fb9e047
Merge branch 'feature/lit-3138-consolidate-share-functions-and-use-ge…
Ansonhkg May 29, 2024
2ceba6f
refactor: privateise `getJWTParams`
Ansonhkg May 29, 2024
c248c58
chore: add jsDocs to private methods
Ansonhkg May 29, 2024
c93fbba
refactor: privatise `combineSharesAndGetJWT`
Ansonhkg May 29, 2024
2614b37
refactor: privatise `getSessionKeyUri`
Ansonhkg May 29, 2024
d209dad
Merge branch 'staging/v6' into feature/lit-3139-identify-private-meth…
Ansonhkg May 29, 2024
36f0e69
refactor: protect `sendCommandToNode`
Ansonhkg May 29, 2024
e0dd999
refactor: protect `getNodePromises`
Ansonhkg May 29, 2024
6793fb1
refactor: privatised `getRequestId`
Ansonhkg May 29, 2024
b199cee
refactor: privatised `handshakeWithNode`
Ansonhkg May 29, 2024
991e651
refactor: remove `getSessionSignatures`
Ansonhkg May 29, 2024
0725995
refactor: protected `getSessionSigByUrl`
Ansonhkg May 29, 2024
bf83f0c
refactor: privatised `getWalletSig`
Ansonhkg May 29, 2024
ca59ef0
refactor: protected `this.handleNodePromises`
Ansonhkg May 29, 2024
2a0328d
refactor: privateised `generatePromise` & remove unused imports
Ansonhkg May 29, 2024
e13ce83
chore: prettier
Ansonhkg May 29, 2024
1662e65
chore: reorganised code placement
Ansonhkg May 29, 2024
628fb8c
refactor: remove `getLitResourceForEncryption` as it's unused
Ansonhkg May 29, 2024
5d80a72
chore: improve jsDoc
Ansonhkg May 29, 2024
3d2a66b
chore: move `getExpiration` as helper
Ansonhkg May 29, 2024
5e5cfd3
doc: improve `getJWTParams` jsDoc
Ansonhkg May 29, 2024
ca5afdf
Merge pull request #483 from LIT-Protocol/feature/lit-3137-identify-h…
Ansonhkg May 29, 2024
47ced6f
Merge branch 'staging/v6' into feature/lit-3139-identify-private-meth…
Ansonhkg Jun 3, 2024
31ce5c7
chore: remove unused imports
Ansonhkg Jun 3, 2024
0b55cae
chore: remove unused imports
Ansonhkg Jun 3, 2024
fd358d9
Merge branch 'staging/v6' into feature/lit-3139-identify-private-meth…
Ansonhkg Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ describe('Lit Action', () => {
url: 'https://cayenne.litgateway.com:7371/web/execute',
data,
};
const res = await savedParams.litNodeClient.sendCommandToNode(reqBody);
const res = await savedParams.litNodeClient._sendCommandToNode(reqBody);
expect(res).to.have.property('success', true);
});

Expand Down
45 changes: 24 additions & 21 deletions packages/core/src/lib/lit-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
import {
bootstrapLogManager,
executeWithRetry,
getIpAddress,
isBrowser,
isNode,
log,
Expand Down Expand Up @@ -173,7 +172,7 @@ export class LitCore {
}

// -- set bootstrapUrls to match the network litNetwork unless it's set to custom
this.setCustomBootstrapUrls();
this.#setCustomBootstrapUrls();

// -- set global variables
globalThis.litConfig = this.config;
Expand Down Expand Up @@ -437,9 +436,9 @@ export class LitCore {
* that the client's configuration is always in sync with the current state of the
* staking contract.
*
* @returns {Promise<void>} A promise that resolves when the listener is successfully set up.
* @returns { void }
*/
private _listenForNewEpoch() {
#listenForNewEpoch(): void {
// Check if we've already set up the listener to avoid duplicates
if (this._stakingContractListener) {
// Already listening, do nothing
Expand Down Expand Up @@ -473,13 +472,14 @@ export class LitCore {
if (globalThis.litConfig) delete globalThis.litConfig;
}

_stopNetworkPolling() {
protected _stopNetworkPolling() {
if (this._networkSyncInterval) {
clearInterval(this._networkSyncInterval);
this._networkSyncInterval = null;
}
}
_stopListeningForNewEpoch() {

protected _stopListeningForNewEpoch() {
if (this._stakingContract && this._stakingContractListener) {
this._stakingContract.off('StateChanged', this._stakingContractListener);
this._stakingContractListener = null;
Expand All @@ -493,7 +493,7 @@ export class LitCore {
* @returns { void }
*
*/
setCustomBootstrapUrls = (): void => {
#setCustomBootstrapUrls = (): void => {
// -- validate
if (this.config.litNetwork === 'custom') return;

Expand Down Expand Up @@ -575,8 +575,8 @@ export class LitCore {
await this._runHandshakeWithBootstrapUrls();
Object.assign(this, { ...coreNodeConfig, connectedNodes, serverKeys });

this._scheduleNetworkSync();
this._listenForNewEpoch();
this.#scheduleNetworkSync();
this.#listenForNewEpoch();

// FIXME: don't create global singleton; multiple instances of `core` should not all write to global
// @ts-expect-error typeof globalThis is not defined. We're going to get rid of the global soon.
Expand Down Expand Up @@ -607,7 +607,7 @@ export class LitCore {
}): Promise<JsonHandshakeResponse> {
const challenge = this.getRandomHexString(64);

const handshakeResult = await this.handshakeWithNode(
const handshakeResult = await this.#handshakeWithNode(
{ url, challenge },
requestId
);
Expand Down Expand Up @@ -697,7 +697,7 @@ export class LitCore {
coreNodeConfig: CoreNodeConfig;
}> {
// -- handshake with each node
const requestId: string = this.getRequestId();
const requestId: string = this.#getRequestId();

// track connectedNodes for the new handshake operation
const connectedNodes = new Set<string>();
Expand Down Expand Up @@ -819,7 +819,7 @@ export class LitCore {
* We can remove this network sync code entirely if we refactor our code to fetch latest blockhash on-demand.
* @private
*/
private _scheduleNetworkSync() {
#scheduleNetworkSync() {
if (this._networkSyncInterval) {
clearInterval(this._networkSyncInterval);
}
Expand Down Expand Up @@ -862,7 +862,7 @@ export class LitCore {
* @returns { string }
*
*/
getRequestId() {
#getRequestId(): string {
return Math.random().toString(16).slice(2);
}

Expand All @@ -873,7 +873,7 @@ export class LitCore {
* @returns { string }
*/

getRandomHexString(size: number) {
getRandomHexString(size: number): string {
return [...Array(size)]
.map(() => Math.floor(Math.random() * 16).toString(16))
.join('');
Expand All @@ -887,7 +887,7 @@ export class LitCore {
* @returns { Promise<NodeCommandServerKeysResponse> }
*
*/
handshakeWithNode = async (
#handshakeWithNode = async (
params: HandshakeWithNode,
requestId: string
): Promise<NodeCommandServerKeysResponse> => {
Expand All @@ -909,7 +909,7 @@ export class LitCore {
challenge: params.challenge,
};

return await this.sendCommandToNode({
return await this._sendCommandToNode({
url: urlWithPath,
data,
requestId,
Expand Down Expand Up @@ -967,7 +967,7 @@ export class LitCore {
* @returns { Promise<any> }
*
*/
sendCommandToNode = async ({
protected _sendCommandToNode = async ({
url,
data,
requestId,
Expand Down Expand Up @@ -1005,7 +1005,7 @@ export class LitCore {
* @returns { Array<Promise<any>> }
*
*/
getNodePromises = (
protected _getNodePromises = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
callback: (url: string) => Promise<any>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -1030,7 +1030,7 @@ export class LitCore {
* @returns The session signature for the given URL.
* @throws An error if sessionSigs is not provided or if the session signature for the URL is not found.
*/
getSessionSigByUrl = ({
protected _getSessionSigByUrl = ({
sessionSigs,
url,
}: {
Expand Down Expand Up @@ -1136,7 +1136,7 @@ export class LitCore {
* @param { number } minNodeCount number of nodes we need valid results from in order to resolve
* @returns { Promise<SuccessNodePromises<T> | RejectedNodePromises> }
*/
handleNodePromises = async <T>(
protected _handleNodePromises = async <T>(
nodePromises: Promise<T>[],
requestId: string,
minNodeCount: number
Expand Down Expand Up @@ -1219,7 +1219,10 @@ export class LitCore {
* @returns { void }
*
*/
_throwNodeError = (res: RejectedNodePromises, requestId: string): void => {
protected _throwNodeError = (
res: RejectedNodePromises,
requestId: string
): void => {
if (res.error) {
if (
((res.error.errorCode &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getExpiration } from './get-expiration';

describe('getExpiration', () => {
it('should return the expiration date and time as an ISO string', () => {
// Arrange
const currentDate = new Date();
const expectedExpiration = new Date(
currentDate.getTime() + 1000 * 60 * 60 * 24
).toISOString();

// Act
const result = getExpiration();

// Assert
expect(result).toBe(expectedExpiration);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Returns the expiration date and time as an ISO string.
* The expiration is set to 24 hours from the current date and time.
*
* @returns {string} The expiration date and time as an ISO string.
*/
export const getExpiration = () => {
return new Date(Date.now() + 1000 * 60 * 60 * 24).toISOString();
};
Loading