Skip to content
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

feat: add custom nodeProtocol and enable https for port 443 #554

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
NETWORK: datil-dev
DEBUG: true
MAX_ATTEMPTS: 3
CHUNK_SIZE: 9
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand All @@ -55,4 +56,4 @@ jobs:
run: yarn build:dev
- name: Run End to End Tests
if: steps.build.outputs.exit_code == 0
run: yarn test:local --filter=testUseEoaSessionSigsToExecuteJsSigning,testUseEoaSessionSigsToPkpSign,testUsePkpSessionSigsToExecuteJsSigning,testUsePkpSessionSigsToPkpSign,testUseValidLitActionCodeGeneratedSessionSigsToPkpSign,testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning,testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs,testEthAuthSigToEncryptDecryptString,testExecuteJsSignAndCombineEcdsa,testExecutJsDecryptAndCombine,testExecuteJsBroadcastAndCollect --exclude=Parallel
run: yarn test:local --filter=testUseEoaSessionSigsToExecuteJsSigning,testUseEoaSessionSigsToPkpSign,testUsePkpSessionSigsToExecuteJsSigning,testUsePkpSessionSigsToPkpSign,testUseValidLitActionCodeGeneratedSessionSigsToPkpSign,testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning,testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs,testEthAuthSigToEncryptDecryptString,testExecuteJsSignAndCombineEcdsa,testExecutJsDecryptAndCombine,testExecuteJsBroadcastAndCollect --exclude=Parallel
9 changes: 5 additions & 4 deletions packages/constants/src/lib/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,8 @@ export const METAMASK_CHAIN_INFO_BY_NETWORK: Record<
localhost: metamaskChainInfo.yellowstone,
};

const HTTP = 'http://';
const HTTPS = 'https://';
export const HTTP = 'http://';
export const HTTPS = 'https://';

/**
* Mapping of network values to corresponding http protocol.
Expand All @@ -804,8 +804,9 @@ export const HTTP_BY_NETWORK: Record<
habanero: HTTPS,
'datil-dev': HTTPS,
'datil-test': HTTPS,
custom: HTTP,
localhost: HTTP,
internalDev: HTTPS,
custom: HTTP, // default, can be changed by config
localhost: HTTP, // default, can be changed by config
Ansonhkg marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand Down
24 changes: 19 additions & 5 deletions packages/contracts-sdk/src/lib/contracts-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import {
HTTP_BY_NETWORK,
CENTRALISATION_BY_NETWORK,
LIT_NETWORK,
HTTP,
HTTPS,
} from '@lit-protocol/constants';
import { LogManager, Logger } from '@lit-protocol/logger';
import { computeAddress } from 'ethers/lib/utils';
Expand Down Expand Up @@ -888,7 +890,8 @@ export class LitContracts {
public static getValidators = async (
network: LIT_NETWORKS_KEYS,
context?: LitContractContext | LitContractResolverContext,
rpcUrl?: string
rpcUrl?: string,
nodeProtocol?: typeof HTTP | typeof HTTPS | null
Ansonhkg marked this conversation as resolved.
Show resolved Hide resolved
): Promise<string[]> => {
const contract = await LitContracts.getStakingContract(
network,
Expand Down Expand Up @@ -941,13 +944,24 @@ export class LitContracts {
});

const networks = activeValidatorStructs.map((item: ValidatorStruct) => {
const protocol = HTTP_BY_NETWORK[network];
const centralisation = CENTRALISATION_BY_NETWORK[network];
const ip = intToIP(item.ip);
const port = item.port;

// Convert the integer IP to a string format
const ip = intToIP(item.ip);
let port = item.port;

// Determine the protocol to use based on various conditions
const protocol =
// If nodeProtocol is defined, use it
nodeProtocol ||
// If port is 443, use HTTPS, otherwise use network-specific HTTP
(port === 443 ? HTTPS : HTTP_BY_NETWORK[network]) ||
// Fallback to HTTP if no other conditions are met
HTTP;
Ansonhkg marked this conversation as resolved.
Show resolved Hide resolved

// Check for specific conditions in centralised networks
if (centralisation === 'centralised') {
// -- validate if it's cayenne AND port range is 8470 - 8479, if not, throw error
// Validate if it's cayenne AND port range is 8470 - 8479, if not, throw error
if (
network === LIT_NETWORK.Cayenne &&
!port.toString().startsWith('8')
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/lib/lit-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
LitNetwork,
StakingStates,
version,
HTTP,
HTTPS,
} from '@lit-protocol/constants';
import { LitContracts } from '@lit-protocol/contracts-sdk';
import {
Expand Down Expand Up @@ -99,6 +101,8 @@ export type LitNodeClientConfigWithDefaults = Required<
Pick<LitNodeClientConfig, 'storageProvider' | 'contractContext' | 'rpcUrl'>
> & {
bootstrapUrls: string[];
} & {
nodeProtocol?: typeof HTTP | typeof HTTPS | null;
};

// On epoch change, we wait this many seconds for the nodes to update to the new epoch before using the new epoch #
Expand Down Expand Up @@ -131,6 +135,7 @@ export class LitCore {
litNetwork: 'cayenne', // Default to cayenne network. will be replaced by custom config.
minNodeCount: 2, // Default value, should be replaced
bootstrapUrls: [], // Default value, should be replaced
nodeProtocol: null,
};
connectedNodes = new Set<string>();
serverKeys: Record<string, JsonHandshakeResponse> = {};
Expand Down Expand Up @@ -234,7 +239,8 @@ export class LitCore {
LitContracts.getValidators(
this.config.litNetwork,
this.config.contractContext,
this.config.rpcUrl
this.config.rpcUrl,
this.config.nodeProtocol
),
]);

Expand Down
Loading