From 3346f57ca427862863228bcad3c3b30ac249238c Mon Sep 17 00:00:00 2001 From: Bean Date: Tue, 5 Dec 2023 13:33:04 -0500 Subject: [PATCH] Ref/small fixes (#275) * update tests to gen pkps in setup for certain networks * logging and network config updates * add dynamic address and abi boostraping depedning on the network type. * move env loading out of setup * change to read from global * tweaks to test runners for jit pkps * fixes to network context resolve, and logging * add readme to e2e tests * changes to network resolving * remove unused imports * add custom to lit network types * fix staker contract resolving * add pkp with auth method to test env bootstrapping * fix failing tests from loader context * add response checks * fix test validation * fix: typo * fix to threshold resolve on chain * fixes to threshold parsing from chain * udpate readme * remove comment * fix up connection tests * up expiration time in generated siwe * change check from config assertion --------- Co-authored-by: Ansonhkg --- README.md | 61 ++--- e2e-nodejs/00-setup.mjs | 76 +----- e2e-nodejs/README.md | 32 +++ .../test-connection-internal-dev.mjs | 28 --- .../test-connection-threshold.mjs | 20 +- ...ection-cayenne.mjs => test-connection.mjs} | 13 +- .../test-lit-action-1-sig.mjs | 4 +- .../test-lit-action-2-sigs.mjs | 2 +- .../test-pkp-client-with-rpc.mjs | 11 +- ...st-pkp-client-without-rpc-sign-message.mjs | 6 +- .../test-pkp-client-without-rpc-sign-tx.mjs | 10 +- .../test-pkp-cosmos-send-tx.mjs | 4 +- .../test-pkp-cosmos-stargate-client.mjs | 4 +- .../group-pkp-cosmos/test-pkp-cosmos.mjs | 14 +- .../test-pkp-ethers-handler-eth-sign.mjs | 4 +- ...test-pkp-ethers-handler-personal-sign .mjs | 4 +- .../test-pkp-ethers-handler-send-tx.mjs | 4 +- .../test-pkp-ethers-handler-sign-tx.mjs | 8 +- ...-pkp-ethers-handler-sign-typed-data-v1.mjs | 4 +- ...-pkp-ethers-handler-sign-typed-data-v3.mjs | 4 +- ...-pkp-ethers-handler-sign-typed-data-v4.mjs | 4 +- ...est-pkp-ethers-handler-sign-typed-data.mjs | 4 +- .../test-pkp-ethers-sign-typed-data.mjs | 2 +- ...th-session-sigs-eth-wallet-auth-method.mjs | 218 +++++++----------- e2e-nodejs/group-pkp-sign/test-pkp-sign.mjs | 7 +- .../group-pkp-sui/test-pkp-sui-send-tx.mjs | 4 +- e2e-nodejs/group-pkp-sui/test-pkp-sui.mjs | 4 +- e2e-nodejs/index.mjs | 25 +- e2e-nodejs/loader.mjs | 98 ++++++++ packages/constants/src/lib/enums.ts | 1 + .../contracts-sdk/src/lib/contracts-sdk.ts | 113 ++++----- packages/core/src/lib/lit-core.ts | 26 ++- 32 files changed, 407 insertions(+), 412 deletions(-) create mode 100644 e2e-nodejs/README.md delete mode 100644 e2e-nodejs/group-connection/test-connection-internal-dev.mjs rename e2e-nodejs/group-connection/{test-connection-cayenne.mjs => test-connection.mjs} (66%) create mode 100644 e2e-nodejs/loader.mjs diff --git a/README.md b/README.md index 42958ee975..d9639c76b8 100644 --- a/README.md +++ b/README.md @@ -67,38 +67,41 @@ For usage directly in the browser with a script tag -| Package | Category | Version | Download | -| -------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [@lit-protocol/lit-node-client-nodejs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client-nodejs) | ![lit-node-client-nodejs](https://img.shields.io/badge/-nodejs-2E8B57 'lit-node-client-nodejs') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/lit-node-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client) | ![lit-node-client](https://img.shields.io/badge/-universal-8A6496 'lit-node-client') | 3.0.24 | npm
Vanilla JS (UMD) | +Package | Category | Version | Download +--- | --- | --- | --- +| [@lit-protocol/lit-node-client-nodejs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client-nodejs) | ![lit-node-client-nodejs](https://img.shields.io/badge/-nodejs-2E8B57 "lit-node-client-nodejs") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/lit-node-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client) | ![lit-node-client](https://img.shields.io/badge/-universal-8A6496 "lit-node-client") | 3.0.24 | npm
Vanilla JS (UMD) + If you're a tech-savvy user and wish to utilize only specific submodules that our main module relies upon, you can find individual packages listed below. This way, you can import only the necessary packages that cater to your specific use case:: -| Package | Category | Version | Download | -| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [@lit-protocol/access-control-conditions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions) | ![access-control-conditions](https://img.shields.io/badge/-universal-8A6496 'access-control-conditions') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/auth-helpers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-helpers) | ![auth-helpers](https://img.shields.io/badge/-universal-8A6496 'auth-helpers') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/bls-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/bls-sdk) | ![bls-sdk](https://img.shields.io/badge/-universal-8A6496 'bls-sdk') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/constants](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/constants) | ![constants](https://img.shields.io/badge/-universal-8A6496 'constants') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/contracts-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/contracts-sdk) | ![contracts-sdk](https://img.shields.io/badge/-universal-8A6496 'contracts-sdk') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/core](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/core) | ![core](https://img.shields.io/badge/-universal-8A6496 'core') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 'crypto') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/ecdsa-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/ecdsa-sdk) | ![ecdsa-sdk](https://img.shields.io/badge/-universal-8A6496 'ecdsa-sdk') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/encryption](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/encryption) | ![encryption](https://img.shields.io/badge/-universal-8A6496 'encryption') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/lit-third-party-libs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-third-party-libs) | ![lit-third-party-libs](https://img.shields.io/badge/-universal-8A6496 'lit-third-party-libs') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/misc](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc) | ![misc](https://img.shields.io/badge/-universal-8A6496 'misc') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/nacl](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/nacl) | ![nacl](https://img.shields.io/badge/-universal-8A6496 'nacl') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/pkp-base](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-base) | ![pkp-base](https://img.shields.io/badge/-universal-8A6496 'pkp-base') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/pkp-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-client) | ![pkp-client](https://img.shields.io/badge/-universal-8A6496 'pkp-client') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/pkp-cosmos](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-cosmos) | ![pkp-cosmos](https://img.shields.io/badge/-universal-8A6496 'pkp-cosmos') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/pkp-ethers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-ethers) | ![pkp-ethers](https://img.shields.io/badge/-universal-8A6496 'pkp-ethers') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/pkp-sui](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-sui) | ![pkp-sui](https://img.shields.io/badge/-universal-8A6496 'pkp-sui') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/pkp-walletconnect](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-walletconnect) | ![pkp-walletconnect](https://img.shields.io/badge/-universal-8A6496 'pkp-walletconnect') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/sev-snp-utils-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/sev-snp-utils-sdk) | ![sev-snp-utils-sdk](https://img.shields.io/badge/-universal-8A6496 'sev-snp-utils-sdk') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 'types') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/uint8arrays](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/uint8arrays) | ![uint8arrays](https://img.shields.io/badge/-universal-8A6496 'uint8arrays') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/auth-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-browser) | ![auth-browser](https://img.shields.io/badge/-browser-E98869 'auth-browser') | 3.0.24 | npm
Vanilla JS (UMD) | -| [@lit-protocol/misc-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc-browser) | ![misc-browser](https://img.shields.io/badge/-browser-E98869 'misc-browser') | 3.0.24 | npm
Vanilla JS (UMD) | + +Package | Category | Version | Download +--- | --- | --- | --- +| [@lit-protocol/access-control-conditions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions) | ![access-control-conditions](https://img.shields.io/badge/-universal-8A6496 "access-control-conditions") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/auth-helpers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-helpers) | ![auth-helpers](https://img.shields.io/badge/-universal-8A6496 "auth-helpers") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/bls-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/bls-sdk) | ![bls-sdk](https://img.shields.io/badge/-universal-8A6496 "bls-sdk") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/constants](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/constants) | ![constants](https://img.shields.io/badge/-universal-8A6496 "constants") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/contracts-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/contracts-sdk) | ![contracts-sdk](https://img.shields.io/badge/-universal-8A6496 "contracts-sdk") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/core](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/core) | ![core](https://img.shields.io/badge/-universal-8A6496 "core") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 "crypto") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/ecdsa-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/ecdsa-sdk) | ![ecdsa-sdk](https://img.shields.io/badge/-universal-8A6496 "ecdsa-sdk") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/encryption](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/encryption) | ![encryption](https://img.shields.io/badge/-universal-8A6496 "encryption") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/lit-third-party-libs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-third-party-libs) | ![lit-third-party-libs](https://img.shields.io/badge/-universal-8A6496 "lit-third-party-libs") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/logger](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/logger) | ![logger](https://img.shields.io/badge/-universal-8A6496 "logger") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/misc](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc) | ![misc](https://img.shields.io/badge/-universal-8A6496 "misc") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/nacl](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/nacl) | ![nacl](https://img.shields.io/badge/-universal-8A6496 "nacl") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/pkp-base](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-base) | ![pkp-base](https://img.shields.io/badge/-universal-8A6496 "pkp-base") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/pkp-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-client) | ![pkp-client](https://img.shields.io/badge/-universal-8A6496 "pkp-client") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/pkp-cosmos](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-cosmos) | ![pkp-cosmos](https://img.shields.io/badge/-universal-8A6496 "pkp-cosmos") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/pkp-ethers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-ethers) | ![pkp-ethers](https://img.shields.io/badge/-universal-8A6496 "pkp-ethers") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/pkp-sui](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-sui) | ![pkp-sui](https://img.shields.io/badge/-universal-8A6496 "pkp-sui") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/pkp-walletconnect](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-walletconnect) | ![pkp-walletconnect](https://img.shields.io/badge/-universal-8A6496 "pkp-walletconnect") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/sev-snp-utils-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/sev-snp-utils-sdk) | ![sev-snp-utils-sdk](https://img.shields.io/badge/-universal-8A6496 "sev-snp-utils-sdk") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 "types") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/uint8arrays](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/uint8arrays) | ![uint8arrays](https://img.shields.io/badge/-universal-8A6496 "uint8arrays") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/auth-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-browser) | ![auth-browser](https://img.shields.io/badge/-browser-E98869 "auth-browser") | 3.0.24 | npm
Vanilla JS (UMD) +| [@lit-protocol/misc-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc-browser) | ![misc-browser](https://img.shields.io/badge/-browser-E98869 "misc-browser") | 3.0.24 | npm
Vanilla JS (UMD) diff --git a/e2e-nodejs/00-setup.mjs b/e2e-nodejs/00-setup.mjs index f6b97a7b7a..f5d16d1e24 100644 --- a/e2e-nodejs/00-setup.mjs +++ b/e2e-nodejs/00-setup.mjs @@ -1,21 +1,13 @@ -import { LitNodeClient, uint8arrayFromString } from '@lit-protocol/lit-node-client'; +import { LitNodeClient } from '@lit-protocol/lit-node-client'; import LITCONFIG from '../lit.config.json' assert { type: 'json' }; import { fail } from '../tools/scripts/utils.mjs'; -import {LitContracts} from "@lit-protocol/contracts-sdk"; -import {ethers} from "ethers"; -import * as siwe from 'siwe'; -// ==================== ENV Loading ==================== -const network = process.env.NETWORK ?? LITCONFIG.TEST_ENV.litNetwork; -const debug = process.env.DEBUG === 'true' ?? LITCONFIG.TEST_ENV.debug; -const minNodeCount = LITCONFIG.TEST_ENV.minNodeCount; -const checkSevAttestation = process.env.CHECK_SEV ?? false; const client = new LitNodeClient({ - litNetwork: network, - debug: debug, - minNodeCount: minNodeCount, - checkNodeAttestation: checkSevAttestation + litNetwork: globalThis.LitCI.network, + debug: globalThis.LitCI.debug, + minNodeCount: globalThis.LitCI.minNodeCount, + checkNodeAttestation: globalThis.LitCI.sevAttestation }); await client.connect(); @@ -28,63 +20,5 @@ if (LITCONFIG.CONTROLLER_AUTHSIG === undefined) { fail('Controller authSig cannot be empty'); } -// ==================== SIWE Gen ==================== -const provider = new ethers.providers.JsonRpcProvider( - LITCONFIG.CHRONICLE_RPC -); - -const wallet = new ethers.Wallet(LITCONFIG.CONTROLLER_PRIVATE_KEY, provider); -const address = ethers.utils.getAddress(await wallet.getAddress()); - -// Craft the SIWE message -const domain = 'localhost'; -const origin = 'https://localhost/login'; -const statement = - 'This is a test statement. You can put anything you want here.'; -const siweMessage = new siwe.SiweMessage({ - domain, - address: address, - statement, - uri: origin, - version: '1', - chainId: 1, - expirationTime: new Date(Date.now() + 1000 * 60).toISOString() -}); -const messageToSign = siweMessage.prepareMessage(); - -// Sign the message and format the authSig -const signature = await wallet.signMessage(messageToSign); - -const authSig = { - sig: signature, - derivedVia: 'web3.eth.personal.sign', - signedMessage: messageToSign, - address: address, -}; -console.log("generated siwe for test run: ", authSig); - -// ==================== Global Vars ==================== -globalThis.LitCI = {}; -globalThis.LitCI.network = network; -globalThis.LitCI.debug = debug; -globalThis.LitCI.sevAttestation = checkSevAttestation; -globalThis.LitCI.CONTROLLER_AUTHSIG = authSig; -globalThis.LitCI.CONTROLLER_AUTHSIG_2 = LITCONFIG.CONTROLLER_AUTHSIG_2; - - -globalThis.LitCI.PKP_INFO = {}; -globalThis.LitCI.PKP_INFO.publicKey = LITCONFIG.PKP_PUBKEY; - -let contractClient = new LitContracts({ - signer: wallet, - debug: process.env.DEBUG === 'true' ?? LITCONFIG.TEST_ENV.debug, - network: process.env.NETWORK ?? LITCONFIG.TEST_ENV.litNetwork, -}); -await contractClient.connect(); - -let res = await contractClient.pkpNftContractUtils.write.mint(); -globalThis.LitCI.PKP_INFO = res.pkp; - - // ==================== Success ==================== export { client }; diff --git a/e2e-nodejs/README.md b/e2e-nodejs/README.md new file mode 100644 index 0000000000..99929e1d3b --- /dev/null +++ b/e2e-nodejs/README.md @@ -0,0 +1,32 @@ +# End to End NodeJS testing + +End to end testing environment for different operations on the Lit Network +- Message singing +- Transaction signing +- Session signature generation / signing +- Lit Action api testing +- LitContracts testing +- Concurrency operation tests + - 1 signature tests + - multi signature tests + + +## Usage +To run all tests in all groups you can use the command +`yarn test:e2e:node` + +Each test suite is contained in a single folder which is called a `group` groups can be filtered by the `filter` flag + +`yarn test:e2e:node --group=lit-actions` +In the above example, only tests in the `group-lit-actions` will run as group flags omit the `group` prefix + +`yarn test:e2e:node --group=lit-actions --filter=1-sig` +In the above example, we only run the `lit-actions` test group with a filter on the `test-lit-action-1-sig` which is reduced to `1-sig` from the `group` flag + +## environment Configuration +``` +NETWORK = cayenne | internalDev #Configures the network context for the test run +DEBUG = true | false # Turns on or off logging +CHECK_SEV = true | false # Configures checking of sev snp attestation reports +MINT_NEW = true | false # Enables provisioning of new keys for the test run +``` diff --git a/e2e-nodejs/group-connection/test-connection-internal-dev.mjs b/e2e-nodejs/group-connection/test-connection-internal-dev.mjs deleted file mode 100644 index 92cd1d0447..0000000000 --- a/e2e-nodejs/group-connection/test-connection-internal-dev.mjs +++ /dev/null @@ -1,28 +0,0 @@ -import path from 'path'; -import { success, fail, testThis } from '../../tools/scripts/utils.mjs'; - -import { LitNodeClient } from '@lit-protocol/lit-node-client'; - -const LIT_NETWORK = 'internalDev'; - -export async function main() { - // ==================== Test Logic ==================== - const client = new LitNodeClient({ - litNetwork: 'internalDev', - checkNodeAttestation: true - }); - await client.connect(); - - // ==================== Post-Validation ==================== - if (!client.ready) { - return fail('client not ready'); - } - if (client.config.litNetwork !== LIT_NETWORK) { - return fail(`client not connected to ${LIT_NETWORK}`); - } - - // ==================== Success ==================== - return success(`Connected to ${LIT_NETWORK}`); -} - -await testThis({ name: path.basename(import.meta.url), fn: main }); \ No newline at end of file diff --git a/e2e-nodejs/group-connection/test-connection-threshold.mjs b/e2e-nodejs/group-connection/test-connection-threshold.mjs index 75f08b287e..6a797f1b14 100644 --- a/e2e-nodejs/group-connection/test-connection-threshold.mjs +++ b/e2e-nodejs/group-connection/test-connection-threshold.mjs @@ -4,12 +4,14 @@ import LITCONFIG from '../../lit.config.json' assert { type: 'json' }; import { LitNodeClient } from '@lit-protocol/lit-node-client'; import {LitContracts} from '@lit-protocol/contracts-sdk'; -const LIT_NETWORK = 'cayenne'; + export async function main() { // ==================== Test Logic ==================== const client = new LitNodeClient({ - litNetwork: LIT_NETWORK + litNetwork: globalThis.LitCI.network, + debug: LITCONFIG.TEST_ENV.debug, + checkNodeAttestation: globalThis.LitCI.sevAttestation }); await client.connect(); @@ -17,21 +19,21 @@ export async function main() { if (!client.ready) { return fail('client not ready'); } - if (client.config.litNetwork !== LIT_NETWORK) { - return fail(`client not connected to ${LIT_NETWORK}`); + if (client.config.litNetwork !== globalThis.LitCI.network) { + return fail(`client not connected to ${globalThis.LitCI.network}`); } - let threshold = await LitContracts.getMinNodeCount(LIT_NETWORK); + let threshold = await LitContracts.getMinNodeCount(globalThis.LitCI.network); console.log(`threshold ${threshold}`); - console.log(`config threshold ${client.config.threshold}`) - client.config.threshold - if (client.config.minNodeCount !== threshold) { + console.log(`config threshold ${client.config.minNodeCount}`); + + if (parseInt(client.config.minNodeCount, 10) !== parseInt(threshold, 10)) { return fail(`threshold does not match config threshold, network state diverged`); } // ==================== Success ==================== - return success(`Connected to ${LIT_NETWORK}`); + return success(`Connected to ${globalThis.LitCI.network}`); } await testThis({ name: path.basename(import.meta.url), fn: main }); \ No newline at end of file diff --git a/e2e-nodejs/group-connection/test-connection-cayenne.mjs b/e2e-nodejs/group-connection/test-connection.mjs similarity index 66% rename from e2e-nodejs/group-connection/test-connection-cayenne.mjs rename to e2e-nodejs/group-connection/test-connection.mjs index d58b51f6f6..fd18fd2d69 100644 --- a/e2e-nodejs/group-connection/test-connection-cayenne.mjs +++ b/e2e-nodejs/group-connection/test-connection.mjs @@ -8,10 +8,9 @@ const LIT_NETWORK = 'cayenne'; export async function main() { // ==================== Test Logic ==================== const client = new LitNodeClient({ - litNetwork: LIT_NETWORK, - debug: process.env.DEBUG === 'true' ?? LITCONFIG.TEST_ENV.debug, - minNodeCount: LITCONFIG.TEST_ENV.minNodeCount, - checkNodeAttestation: false, + litNetwork: globalThis.LitCI.network, + debug: LITCONFIG.TEST_ENV.debug, + checkNodeAttestation: globalThis.LitCI.sevAttestation }); await client.connect(); @@ -19,12 +18,12 @@ export async function main() { if (!client.ready) { return fail('client not ready'); } - if (client.config.litNetwork !== LIT_NETWORK) { - return fail(`client not connected to ${LIT_NETWORK}`); + if (client.config.litNetwork !== globalThis.LitCI.network) { + return fail(`client not connected to ${globalThis.LitCI.network}`); } // ==================== Success ==================== - return success(`Connected to ${LIT_NETWORK}`); + return success(`Connected to ${globalThis.LitCI.network}`); } await testThis({ name: path.basename(import.meta.url), fn: main }); diff --git a/e2e-nodejs/group-lit-actions/test-lit-action-1-sig.mjs b/e2e-nodejs/group-lit-actions/test-lit-action-1-sig.mjs index 595c188b1d..341e071a04 100644 --- a/e2e-nodejs/group-lit-actions/test-lit-action-1-sig.mjs +++ b/e2e-nodejs/group-lit-actions/test-lit-action-1-sig.mjs @@ -27,7 +27,8 @@ export async function main() { }); // ==================== Post-Validation ==================== - if (Object.keys(res.signatures).length <= 0) { + + if (!res.signatures || Object.keys(res.signatures).length <= 0) { return fail( `should have at least 1 signature but received ${ Object.keys(res.signatures).length @@ -42,7 +43,6 @@ export async function main() { } } ); - // ==================== Success ==================== return success('Lit Action should log sign x1 sig'); } diff --git a/e2e-nodejs/group-lit-actions/test-lit-action-2-sigs.mjs b/e2e-nodejs/group-lit-actions/test-lit-action-2-sigs.mjs index fb5dc75e04..ff058d1262 100644 --- a/e2e-nodejs/group-lit-actions/test-lit-action-2-sigs.mjs +++ b/e2e-nodejs/group-lit-actions/test-lit-action-2-sigs.mjs @@ -41,7 +41,7 @@ export async function main() { }); // ==================== Post-Validation ==================== - if (Object.keys(res.signatures).length !== 2) { + if (!res.signatures || Object.keys(res.signatures).length !== 2) { return fail( `should have 2 signatures but received ${ Object.keys(res.signatures).length diff --git a/e2e-nodejs/group-pkp-client/test-pkp-client-with-rpc.mjs b/e2e-nodejs/group-pkp-client/test-pkp-client-with-rpc.mjs index 941da0a524..8f7fcbf03a 100644 --- a/e2e-nodejs/group-pkp-client/test-pkp-client-with-rpc.mjs +++ b/e2e-nodejs/group-pkp-client/test-pkp-client-with-rpc.mjs @@ -1,20 +1,19 @@ import path from 'path'; import { success, fail, testThis } from '../../tools/scripts/utils.mjs'; import LITCONFIG from '../../lit.config.json' assert { type: 'json' }; -import { client } from '../00-setup.mjs'; import { PKPClient } from '@lit-protocol/pkp-client'; import { ethers } from 'ethers'; export async function main() { // ==================== Setup ==================== const pkpClient = new PKPClient({ - controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG, - pkpPubKey: LITCONFIG.PKP_PUBKEY, + controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG, + pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey, rpcs: { eth: LITCONFIG.CHRONICLE_RPC, cosmos: LITCONFIG.COSMOS_RPC, }, - litNetwork: LITCONFIG.TEST_ENV.litNetwork, + litNetwork: globalThis.LitCI.network, cosmosAddressPrefix: 'cosmos', }); @@ -60,9 +59,9 @@ export async function main() { return fail('signature should be defined'); } - if (recoveredAddress !== LITCONFIG.PKP_ETH_ADDRESS) { + if (recoveredAddress !== globalThis.LitCI.PKP_INFO.ethAddress) { return fail( - `recoveredAddres should be ${LITCONFIG.PKP_ETH_ADDRESS}, got ${recoveredAddress}` + `recoveredAddres should be ${globalThis.LitCI.PKP_INFO.ethAddress}, got ${recoveredAddress}` ); } diff --git a/e2e-nodejs/group-pkp-client/test-pkp-client-without-rpc-sign-message.mjs b/e2e-nodejs/group-pkp-client/test-pkp-client-without-rpc-sign-message.mjs index 937f984d54..ab4b0b1cef 100644 --- a/e2e-nodejs/group-pkp-client/test-pkp-client-without-rpc-sign-message.mjs +++ b/e2e-nodejs/group-pkp-client/test-pkp-client-without-rpc-sign-message.mjs @@ -7,9 +7,9 @@ import { PKPClient } from '@lit-protocol/pkp-client'; export async function main() { // ==================== Setup ==================== const pkpClient = new PKPClient({ - controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG, - pkpPubKey: LITCONFIG.PKP_PUBKEY, - litNetwork: LITCONFIG.TEST_ENV.litNetwork, + controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG, + pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey, + litNetwork: globalThis.LitCI.network, cosmosAddressPrefix: 'cosmos', }); diff --git a/e2e-nodejs/group-pkp-client/test-pkp-client-without-rpc-sign-tx.mjs b/e2e-nodejs/group-pkp-client/test-pkp-client-without-rpc-sign-tx.mjs index 2ad0b8c0fa..a636dbd2fa 100644 --- a/e2e-nodejs/group-pkp-client/test-pkp-client-without-rpc-sign-tx.mjs +++ b/e2e-nodejs/group-pkp-client/test-pkp-client-without-rpc-sign-tx.mjs @@ -8,9 +8,9 @@ import { ethers } from 'ethers'; export async function main() { // ==================== Setup ==================== const pkpClient = new PKPClient({ - controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG, - pkpPubKey: LITCONFIG.PKP_PUBKEY, - litNetwork: LITCONFIG.TEST_ENV.litNetwork, + controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG, + pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey, + litNetwork: globalThis.LitCI.network, cosmosAddressPrefix: 'cosmos', }); @@ -56,9 +56,9 @@ export async function main() { return fail('signature should be defined'); } - if (recoveredAddress !== LITCONFIG.PKP_ETH_ADDRESS) { + if (recoveredAddress !== globalThis.LitCI.PKP_INFO.ethAddress) { return fail( - `recoveredAddres should be ${LITCONFIG.PKP_ETH_ADDRESS}, got ${recoveredAddress}` + `recoveredAddres should be ${globalThis.LitCI.PKP_INFO.ethAddress}, got ${recoveredAddress}` ); } // ==================== Success ==================== diff --git a/e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos-send-tx.mjs b/e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos-send-tx.mjs index 5f801a6792..4a7f3b639d 100644 --- a/e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos-send-tx.mjs +++ b/e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos-send-tx.mjs @@ -15,8 +15,8 @@ import { export async function main() { // ==================== Setup ==================== const cosmosWallet = new PKPCosmosWallet({ - controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG, - pkpPubKey: LITCONFIG.PKP_PUBKEY, + controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG, + pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey, rpc: LITCONFIG.COSMOS_RPC, // debug: true, addressPrefix: 'cosmos', diff --git a/e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos-stargate-client.mjs b/e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos-stargate-client.mjs index 3285ec6459..72689592dc 100644 --- a/e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos-stargate-client.mjs +++ b/e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos-stargate-client.mjs @@ -18,8 +18,8 @@ const TX_HASH = export async function main() { // ==================== Setup ==================== const cosmosWallet = new PKPCosmosWallet({ - controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG, - pkpPubKey: LITCONFIG.PKP_PUBKEY, + controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG, + pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey, rpc: LITCONFIG.COSMOS_RPC, // debug: true, addressPrefix: 'cosmos', diff --git a/e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos.mjs b/e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos.mjs index c55a2971da..c9c633a5a6 100644 --- a/e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos.mjs +++ b/e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos.mjs @@ -7,8 +7,8 @@ import { PKPCosmosWallet } from '@lit-protocol/pkp-cosmos'; export async function main() { // ==================== Setup ==================== const cosmosWallet = new PKPCosmosWallet({ - controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG, - pkpPubKey: LITCONFIG.PKP_PUBKEY, + controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG, + pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey, rpc: LITCONFIG.COSMOS_RPC, // debug: true, addressPrefix: 'cosmos', @@ -24,10 +24,16 @@ export async function main() { return fail('litNodeClient should be ready'); } - if (pkpAccount.address !== LITCONFIG.PKP_COSMOS_ADDRESS) { - return fail(`Expecting PKP address to be ${LITCONFIG.PKP_COSMOS_ADDRESS}`); + if (!pkpAccount.address.includes('cosmos')) { + return fail(`expecting account address to include "cosmos"`); + } + if (pkpAccount.algo != 'secp256k1') { + return fail('algo does not match: ', 'secp256k1'); } + if (pkpAccount.pubkey.length !== 33) { + return fail('pubkey buffer expected length is incorrect recieved: ', pkpAccount.pubkey.length, "expected", 33); + } // ==================== Success ==================== return success('PKPCosmosWallet should be able to getAccounts'); } diff --git a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-eth-sign.mjs b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-eth-sign.mjs index 8e8346d0d8..dcbcfaf03c 100644 --- a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-eth-sign.mjs +++ b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-eth-sign.mjs @@ -30,7 +30,7 @@ export async function main() { signer: pkpEthersWallet, payload: { method: 'eth_sign', - params: [LITCONFIG.PKP_ETH_ADDRESS, hexMsg], + params: [globalThis.LitCI.PKP_INFO.ethAddress, hexMsg], }, }); @@ -41,7 +41,7 @@ export async function main() { return fail('signature should be 132 characters long'); } - if (recoveredAddr !== LITCONFIG.PKP_ETH_ADDRESS) { + if (recoveredAddr !== globalThis.LitCI.PKP_INFO.ethAddress) { return fail( `recoveredAddr should be ${LITCONFIG.PKP_ETH_ADDRESS} but got ${recoveredAddr}` ); diff --git a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-personal-sign .mjs b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-personal-sign .mjs index 5c7b5d283f..79bd948b4d 100644 --- a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-personal-sign .mjs +++ b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-personal-sign .mjs @@ -29,7 +29,7 @@ export async function main() { signer: pkpEthersWallet, payload: { method: 'personal_sign', - params: [hexMsg, LITCONFIG.PKP_ETH_ADDRESS], + params: [hexMsg, globalThis.LitCI.PKP_INFO.ethAddress], }, }); @@ -40,7 +40,7 @@ export async function main() { return fail('signature should be 132 characters long'); } - if (recoveredAddr !== LITCONFIG.PKP_ETH_ADDRESS) { + if (recoveredAddr !== globalThis.LitCI.PKP_INFO.ethAddress) { return fail( `recoveredAddr should be ${LITCONFIG.PKP_ETH_ADDRESS} but got ${recoveredAddr}` ); diff --git a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-send-tx.mjs b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-send-tx.mjs index 988fffeb72..1aa7983bdd 100644 --- a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-send-tx.mjs +++ b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-send-tx.mjs @@ -20,8 +20,8 @@ export async function main() { // ==================== Test Logic ==================== // Transaction to sign and send - const from = LITCONFIG.PKP_ETH_ADDRESS; - const to = LITCONFIG.PKP_ETH_ADDRESS; + const from = globalThis.LitCI.PKP_INFO.ethAddress; + const to = globalThis.LitCI.PKP_INFO.ethAddress; const gasLimit = ethers.BigNumber.from('21000'); const value = ethers.BigNumber.from('0'); const data = '0x'; diff --git a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-tx.mjs b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-tx.mjs index 7e0e1b0555..cf845afbad 100644 --- a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-tx.mjs +++ b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-tx.mjs @@ -25,8 +25,8 @@ export async function main() { // ==================== Test Logic ==================== // Transaction to sign and send - const from = LITCONFIG.PKP_ETH_ADDRESS; - const to = LITCONFIG.PKP_ETH_ADDRESS; + const from = globalThis.LitCI.PKP_INFO.ethAddress; + const to = globalThis.LitCI.PKP_INFO.ethAddress; const gasLimit = ethers.BigNumber.from('21000'); const value = ethers.BigNumber.from('0'); const data = '0x'; @@ -89,9 +89,9 @@ export async function main() { ); } - if (recoveredAddress !== LITCONFIG.PKP_ETH_ADDRESS) { + if (recoveredAddress.toLowerCase() !== globalThis.LitCI.PKP_INFO.ethAddress.toLowerCase()) { return fail( - `recoveredAddres should be ${LITCONFIG.PKP_ETH_ADDRESS}, got ${recoveredAddress}` + `recoveredAddres should be ${globalThis.LitCI.PKP_INFO.ethAddress}, got ${recoveredAddress}` ); } diff --git a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data-v1.mjs b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data-v1.mjs index 4b74bfdfa2..ba3f85c598 100644 --- a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data-v1.mjs +++ b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data-v1.mjs @@ -39,7 +39,7 @@ export async function main() { signer: pkpEthersWallet, payload: { method: 'eth_signTypedData_v1', - params: [msgParams, LITCONFIG.PKP_ETH_ADDRESS], + params: [msgParams, globalThis.LitCI.PKP_INFO.ethAddress], }, }); @@ -56,7 +56,7 @@ export async function main() { return fail('signature should be 132 characters long'); } - if (recoveredAddr.toLowerCase() !== LITCONFIG.PKP_ETH_ADDRESS.toLowerCase()) { + if (recoveredAddr.toLowerCase() !== globalThis.LitCI.PKP_INFO.ethAddress.toLowerCase()) { return fail( `recoveredAddr ${recoveredAddr} should be ${LITCONFIG.PKP_ETH_ADDRESS}` ); diff --git a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data-v3.mjs b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data-v3.mjs index f7156acbc8..968d5735ac 100644 --- a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data-v3.mjs +++ b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data-v3.mjs @@ -64,7 +64,7 @@ export async function main() { signer: pkpEthersWallet, payload: { method: 'eth_signTypedData_v3', - params: [LITCONFIG.PKP_ETH_ADDRESS, JSON.stringify(msgParams)], + params: [globalThis.LitCI.PKP_INFO.ethAddress, JSON.stringify(msgParams)], }, }); @@ -86,7 +86,7 @@ export async function main() { return fail('signature should be 132 characters long'); } - if (recoveredAddr.toLowerCase() !== LITCONFIG.PKP_ETH_ADDRESS.toLowerCase()) { + if (recoveredAddr.toLowerCase() !== globalThis.LitCI.PKP_INFO.ethAddress.toLowerCase()) { return fail( `recoveredAddr ${recoveredAddr} should be ${LITCONFIG.PKP_ETH_ADDRESS}` ); diff --git a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data-v4.mjs b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data-v4.mjs index bb8815132a..75e06e552b 100644 --- a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data-v4.mjs +++ b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data-v4.mjs @@ -75,7 +75,7 @@ export async function main() { signer: pkpEthersWallet, payload: { method: 'eth_signTypedData_v4', - params: [LITCONFIG.PKP_ETH_ADDRESS, JSON.stringify(msgParams)], + params: [globalThis.LitCI.PKP_INFO.ethAddress, JSON.stringify(msgParams)], }, }); @@ -92,7 +92,7 @@ export async function main() { return fail('signature should be 132 characters long'); } - if (recoveredAddr.toLowerCase() !== LITCONFIG.PKP_ETH_ADDRESS.toLowerCase()) { + if (recoveredAddr.toLowerCase() !== globalThis.LitCI.PKP_INFO.ethAddress.toLowerCase()) { return fail( `recoveredAddr ${recoveredAddr} should be ${LITCONFIG.PKP_ETH_ADDRESS}` ); diff --git a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data.mjs b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data.mjs index fc45eb2d0d..3a8e87fff5 100644 --- a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data.mjs +++ b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-handler-sign-typed-data.mjs @@ -60,7 +60,7 @@ export async function main() { signer: pkpEthersWallet, payload: { method: 'eth_signTypedData', - params: [LITCONFIG.PKP_ETH_ADDRESS, msgParams], + params: [globalThis.LitCI.PKP_INFO.ethAddress, msgParams], }, }); @@ -77,7 +77,7 @@ export async function main() { return fail('signature should be 132 characters long'); } - if (recoveredAddr.toLowerCase() !== LITCONFIG.PKP_ETH_ADDRESS.toLowerCase()) { + if (recoveredAddr.toLowerCase() !== globalThis.LitCI.PKP_INFO.ethAddress.toLowerCase()) { return fail( `recoveredAddr ${recoveredAddr} should be ${LITCONFIG.PKP_ETH_ADDRESS}` ); diff --git a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-sign-typed-data.mjs b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-sign-typed-data.mjs index 745936e91f..e12960a5cf 100644 --- a/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-sign-typed-data.mjs +++ b/e2e-nodejs/group-pkp-ethers/test-pkp-ethers-sign-typed-data.mjs @@ -70,7 +70,7 @@ export async function main() { return fail('signature should be 132 characters long'); } - if (recoveredAddr.toLowerCase() !== LITCONFIG.PKP_ETH_ADDRESS.toLowerCase()) { + if (recoveredAddr.toLowerCase() !== globalThis.LitCI.PKP_INFO.ethAddress.toLowerCase()) { return fail( `recoveredAddr "${recoveredAddr}" should be ${LITCONFIG.PKP_ETH_ADDRESS}` ); diff --git a/e2e-nodejs/group-pkp-session-sigs/test-pkp-sign-with-session-sigs-eth-wallet-auth-method.mjs b/e2e-nodejs/group-pkp-session-sigs/test-pkp-sign-with-session-sigs-eth-wallet-auth-method.mjs index cccb44ed28..150e261824 100644 --- a/e2e-nodejs/group-pkp-session-sigs/test-pkp-sign-with-session-sigs-eth-wallet-auth-method.mjs +++ b/e2e-nodejs/group-pkp-session-sigs/test-pkp-sign-with-session-sigs-eth-wallet-auth-method.mjs @@ -1,12 +1,10 @@ import path from 'path'; import { success, fail, testThis } from '../../tools/scripts/utils.mjs'; -import LITCONFIG from '../../lit.config.json' assert { type: 'json' }; import { client } from '../00-setup.mjs'; import { LitAbility, LitActionResource } from '@lit-protocol/auth-helpers'; -import { LitAuthClient } from '@lit-protocol/lit-auth-client'; -import { AuthMethodType, ProviderType } from '@lit-protocol/constants'; import { ethers } from 'ethers'; import { PKPEthersWallet } from '@lit-protocol/pkp-ethers'; +import { uint8arrayFromString } from '@lit-protocol/uint8arrays'; // NOTE: you need to hash data before you send it in. // If you send something that isn't 32 bytes, the nodes will return an error. @@ -14,141 +12,93 @@ const TO_SIGN = ethers.utils.arrayify(ethers.utils.keccak256([1, 2, 3, 4, 5])); export async function main() { // ==================== Setup ==================== - if(globalThis.network === "cayenne") { - const litAuthClient = new LitAuthClient({ - litRelayConfig: { - relayApiKey: '67e55044-10b1-426f-9247-bb680e5fe0c8_relayer', - }, - version: 'V3', - litNodeClient: client, - }); - - // -- eth wallet - const authProvider = litAuthClient.initProvider(ProviderType.EthWallet); - const authMethod = { - authMethodType: AuthMethodType.EthWallet, - accessToken: JSON.stringify(LITCONFIG.CONTROLLER_AUTHSIG_2), - }; - - // -- setting scope for the auth method - // https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scopes - const options = { - permittedAuthMethodScopes: [[1]], - }; - - let pkps = await authProvider.fetchPKPsThroughRelayer(authMethod); - - if (pkps.length <= 0) { - try { - const auth = await authProvider.mintPKPThroughRelayer( - authMethod, - options - ); - console.log('auth', auth); - } catch (e) { - return fail('Failed to mint PKP'); - } - pkps = await authProvider.fetchPKPsThroughRelayer(authMethod); - } - - const pkp = pkps[pkps.length - 1]; - - // convert BigNumber to string - pkp.tokenId = ethers.BigNumber.from(pkp.tokenId).toString(); - - console.log('pkp', pkp); - - const pkpPubKey = pkp.publicKey; - - const sessionKeyPair = client.getSessionKey(); - - const authNeededCallback = async (params) => { - const response = await client.signSessionKey({ - sessionKey: sessionKeyPair, - statement: params.statement, - authSig: JSON.parse(authMethod.accessToken), // When this is empty or undefined, it will fail - authMethods: [authMethod], - pkpPublicKey: pkpPubKey, - expiration: params.expiration, - resources: params.resources, - chainId: 1, - }); - return response.authSig; - }; - - const resourceAbilities = [ - { - resource: new LitActionResource('*'), - ability: LitAbility.PKPSigning, - }, - ]; - - // ==================== Test Logic ==================== - - const sessionSigs = await client.getSessionSigs({ - chain: 'ethereum', - expiration: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7).toISOString(), - resourceAbilityRequests: resourceAbilities, + const sessionKeyPair = client.getSessionKey(); + const authNeededCallback = async (params) => { + const response = await client.signSessionKey({ sessionKey: sessionKeyPair, - authNeededCallback, - }); - - const pkpSignRes = await client?.pkpSign({ - toSign: TO_SIGN, - pubKey: pkpPubKey, - sessionSigs: sessionSigs, - // authMethods: [authMethod], // This is not working! - }); - - const pkpWallet = new PKPEthersWallet({ - pkpPubKey: pkpPubKey, - controllerSessionSigs: sessionSigs, - controllerAuthMethods: [], + statement: params.statement, + // authSig: globalThis.LitCI.CONTROLLER_AUTHSIG, // When this is empty or undefined, it will fail + authMethods: [{ + authMethodType: 1, + accessToken: JSON.stringify(globalThis.LitCI.CONTROLLER_AUTHSIG) + }], + pkpPublicKey: `0x${globalThis.LitCI.AUTH_METHOD_PKP_INFO.publicKey}`, + expiration: params.expiration, + resources: params.resources, + chainId: 1, }); - - await pkpWallet.init(); - - const signature = await pkpWallet.signMessage(TO_SIGN); - - // ==================== Post-Validation ==================== - - if (!pkpSignRes) { - return fail( - 'Failed to sign data with sessionSigs generated by eth wallet auth method' - ); - } - - let missingKeys = []; - - if (pkpSignRes) { - ['r', 's', 'recid', 'signature', 'publicKey', 'dataSigned'].forEach( - (key) => { - if (pkpSignRes[key] === undefined) { - missingKeys.push(key); - } + return response.authSig; + }; + + const resourceAbilities = [ + { + resource: new LitActionResource('*'), + ability: LitAbility.PKPSigning, + }, + ]; + + // ==================== Test Logic ==================== + + const sessionSigs = await client.getSessionSigs({ + chain: 'ethereum', + expiration: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7).toISOString(), + resourceAbilityRequests: resourceAbilities, + sessionKey: sessionKeyPair, + authNeededCallback, + }); + + const pkpSignRes = await client?.pkpSign({ + toSign: TO_SIGN, + pubKey: globalThis.LitCI.AUTH_METHOD_PKP_INFO.publicKey, + sessionSigs: sessionSigs, + // authMethods: [authMethod], // This is not working! + }); + + const pkpWallet = new PKPEthersWallet({ + pkpPubKey: globalThis.LitCI.AUTH_METHOD_PKP_INFO.publicKey, + controllerSessionSigs: sessionSigs, + controllerAuthMethods: [], + }); + + await pkpWallet.init(); + + const signature = await pkpWallet.signMessage(TO_SIGN); + + // ==================== Post-Validation ==================== + + if (!pkpSignRes) { + return fail( + 'Failed to sign data with sessionSigs generated by eth wallet auth method' + ); + } + + let missingKeys = []; + + if (pkpSignRes) { + ['r', 's', 'recid', 'signature', 'publicKey', 'dataSigned'].forEach( + (key) => { + if (pkpSignRes[key] === undefined) { + missingKeys.push(key); } - ); - } - - if (missingKeys.length > 0) { - return fail(`Missing keys: ${missingKeys.join(', ')}`); - } - - if (!signature) { - return fail( - 'Failed to sign data with sessionSigs generated by eth wallet auth method' - ); - } - - // ==================== Success ==================== - return success( - `it should use sessionSigs generated by eth wallet auth method to sign data. Signature is ${signature} and pkpSignRes is ${JSON.stringify( - pkpSignRes - )}` + } ); - } else { - return success('test skipped as network is not JIT compatible right now...'); } -} + if (missingKeys.length > 0) { + return fail(`Missing keys: ${missingKeys.join(', ')}`); + } + + if (!signature) { + return fail( + 'Failed to sign data with sessionSigs generated by eth wallet auth method' + ); + } + + // ==================== Success ==================== + return success( + `it should use sessionSigs generated by eth wallet auth method to sign data. Signature is ${signature} and pkpSignRes is ${JSON.stringify( + pkpSignRes + )}` + ); +} await testThis({ name: path.basename(import.meta.url), fn: main }); \ No newline at end of file diff --git a/e2e-nodejs/group-pkp-sign/test-pkp-sign.mjs b/e2e-nodejs/group-pkp-sign/test-pkp-sign.mjs index ed4189eed3..0666a5688a 100644 --- a/e2e-nodejs/group-pkp-sign/test-pkp-sign.mjs +++ b/e2e-nodejs/group-pkp-sign/test-pkp-sign.mjs @@ -4,16 +4,13 @@ import LITCONFIG from '../../lit.config.json' assert { type: 'json' }; import { client } from '../00-setup.mjs'; import { ethers } from 'ethers'; -const DATA_TO_SIGN = ethers.utils.arrayify( - ethers.utils.keccak256([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]) -); +const DATA_TO_SIGN = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode("Hello world"))); export async function main() { // ==================== Test Logic ==================== const sig = await client.pkpSign({ toSign: DATA_TO_SIGN, - pubKey: LITCONFIG.PKP_PUBKEY, authMethod: [], authSig: globalThis.LitCI.CONTROLLER_AUTHSIG, pubKey: globalThis.LitCI.PKP_INFO.publicKey, @@ -36,7 +33,7 @@ export async function main() { } }); - if (recoveredAddr !== LITCONFIG.PKP_ETH_ADDRESS) { + if (recoveredAddr !== globalThis.LitCI.PKP_INFO.ethAddress) { return fail( `recovered address ${recoveredAddr} should be ${LITCONFIG.PKP_ETH_ADDRESS}` ); diff --git a/e2e-nodejs/group-pkp-sui/test-pkp-sui-send-tx.mjs b/e2e-nodejs/group-pkp-sui/test-pkp-sui-send-tx.mjs index 5516c46249..03bf199dc9 100644 --- a/e2e-nodejs/group-pkp-sui/test-pkp-sui-send-tx.mjs +++ b/e2e-nodejs/group-pkp-sui/test-pkp-sui-send-tx.mjs @@ -16,8 +16,8 @@ export async function main() { const suiWallet = new PKPSuiWallet( { - controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG, - pkpPubKey: LITCONFIG.PKP_PUBKEY, + controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG, + pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey, }, provider ); diff --git a/e2e-nodejs/group-pkp-sui/test-pkp-sui.mjs b/e2e-nodejs/group-pkp-sui/test-pkp-sui.mjs index b372c5f70b..78c220e0ec 100644 --- a/e2e-nodejs/group-pkp-sui/test-pkp-sui.mjs +++ b/e2e-nodejs/group-pkp-sui/test-pkp-sui.mjs @@ -12,8 +12,8 @@ export async function main() { const suiWallet = new PKPSuiWallet( { - controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG, - pkpPubKey: LITCONFIG.PKP_PUBKEY, + controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG, + pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey, }, provider ); diff --git a/e2e-nodejs/index.mjs b/e2e-nodejs/index.mjs index 123d9f29d2..3957a2e7aa 100644 --- a/e2e-nodejs/index.mjs +++ b/e2e-nodejs/index.mjs @@ -9,8 +9,9 @@ const __dirname = path.dirname(__filename); const ROOT_DIR = path.resolve(__dirname, '../'); const DIR = ROOT_DIR + '/e2e-nodejs/'; +const ENV_LOADER_PATH = path.resolve(__dirname, 'loader.mjs'); -const IGNORE_LIST = ['index.mjs', 'template.mjs', '00-setup.mjs']; +const IGNORE_LIST = ['index.mjs', 'template.mjs', '00-setup.mjs', 'loader.mjs', 'README.md']; const IGNORE_DIRS = ['0_manual-tests']; /** * Function to get all files from the directory excluding 'index' @@ -42,13 +43,15 @@ const getFilesFromDir = (dir) => { }; async function main() { - console.log(` + greenLog(` 💡 Usage: yarn test:e2e:node 🌍 ENVs: - DEBUG=true yarn test:e2e:node (Enables debug mode) - NETOWRK= yarn test:e2e:node (Choose your network) - REAL_TX=true yarn test:e2e:node (Enables real tx that costs gas) + DEBUG=true (Enables debug mode) + NETOWRK= (Choose your network) + CHECK_SEV=true (enable sev attestation checks) + MINT_NEW=true (mint new pkp resources for test run) + REAL_TX=true yarn (Enables real tx that costs gas) 🚩 Flags: --filter= (Filters files by keyword) @@ -92,6 +95,18 @@ async function main() { let errorCounter = 0; let logs = []; + // load environment context and init global state + try { + await import('./loader.mjs'); + } catch(e) { + errorCounter += 1; + logs.push( + `------------------- +- [${errorCounter}] Error happened in environment loading, see below for details 👇 \n${e}` + ); + console.log(e); + } + // -- async mode if (mode === 'async') { for (const file of files) { diff --git a/e2e-nodejs/loader.mjs b/e2e-nodejs/loader.mjs new file mode 100644 index 0000000000..75a65520f3 --- /dev/null +++ b/e2e-nodejs/loader.mjs @@ -0,0 +1,98 @@ +import LITCONFIG from '../lit.config.json' assert { type: 'json' }; +import {LitContracts} from "@lit-protocol/contracts-sdk"; +import { uint8arrayFromString } from '@lit-protocol/uint8arrays'; +import {BigNumber, ethers} from "ethers"; +import * as siwe from 'siwe'; + +// ==================== ENV Loading ==================== +const network = process.env.NETWORK ?? LITCONFIG.TEST_ENV.litNetwork; +const debug = process.env.DEBUG === 'true' ?? LITCONFIG.TEST_ENV.debug; +const checkSevAttestation = process.env.CHECK_SEV ?? false; +const mintNew = process.env.MINT_NEW ?? true; + +// ==================== SIWE Gen ==================== +const provider = new ethers.providers.JsonRpcProvider( + LITCONFIG.CHRONICLE_RPC +); + +const wallet = new ethers.Wallet(LITCONFIG.CONTROLLER_PRIVATE_KEY, provider); +const address = ethers.utils.getAddress(await wallet.getAddress()); + +// Craft the SIWE message +const domain = 'localhost'; +const origin = 'https://localhost/login'; +const statement = + 'This is a test statement. You can put anything you want here.'; +const siweMessage = new siwe.SiweMessage({ + domain, + address: address, + statement, + uri: origin, + version: '1', + chainId: 1, + expirationTime: new Date(Date.now() + 1000 * 60 * 7).toISOString() +}); +const messageToSign = siweMessage.prepareMessage(); + +// Sign the message and format the authSig +const signature = await wallet.signMessage(messageToSign); + +const authSig = { + sig: signature, + derivedVia: 'web3.eth.personal.sign', + signedMessage: messageToSign, + address: address, +}; + +// ==================== Global Vars ==================== +globalThis.LitCI = {}; +globalThis.LitCI.network = network; +globalThis.LitCI.debug = debug; +globalThis.LitCI.sevAttestation = checkSevAttestation; +globalThis.LitCI.CONTROLLER_AUTHSIG = authSig; + + +globalThis.LitCI.PKP_INFO = {}; +globalThis.LitCI.PKP_INFO.publicKey = LITCONFIG.PKP_PUBKEY; +if (mintNew) { + let contractClient = new LitContracts({ + signer: wallet, + debug: process.env.DEBUG === 'true' ?? LITCONFIG.TEST_ENV.debug, + network: process.env.NETWORK ?? LITCONFIG.TEST_ENV.litNetwork, + }); + + await contractClient.connect(); + let res = await contractClient.pkpNftContractUtils.write.mint(); + + globalThis.LitCI.PKP_INFO = res.pkp; + const mintCost = await contractClient.pkpNftContract.read.mintCost(); + let authMethodId = ethers.utils.keccak256(uint8arrayFromString(`${authSig.address}:lit`)); + res = await contractClient.pkpHelperContract.write.mintNextAndAddAuthMethods( + 2, + [1], + [authMethodId], + [BigNumber.from(0)], + [[BigNumber.from(1)]], + true, + true, + { + value: mintCost + } + ); + + let tx = await res.wait(); + let tokenId = tx.events ? tx.events[0].topics[1] : tx.logs[0].topics[1]; + let pubkeyWithAuthMethod = await contractClient.pkpNftContract.read.getPubkey(tokenId); + let ethAddr = ethers.utils.computeAddress(pubkeyWithAuthMethod); + + globalThis.LitCI.AUTH_METHOD_PKP_INFO = {}; + globalThis.LitCI.AUTH_METHOD_PKP_INFO.publicKey = pubkeyWithAuthMethod.slice(2); + globalThis.LitCI.AUTH_METHOD_PKP_INFO.ethAddress = ethAddr; + globalThis.LitCI.AUTH_METHOD_PKP_INFO.authMethod = { + authMethodId, + authMethodType: 1 + }; +} + +console.log("environment Arguments"); +console.log(globalThis.LitCI); \ No newline at end of file diff --git a/packages/constants/src/lib/enums.ts b/packages/constants/src/lib/enums.ts index 966fe1e115..8be4b2450f 100644 --- a/packages/constants/src/lib/enums.ts +++ b/packages/constants/src/lib/enums.ts @@ -56,6 +56,7 @@ export enum AuthMethodScope { export enum LitNetwork { Cayenne = 'cayenne', InternalDev = 'internalDev', + Custom = 'custom' } /** diff --git a/packages/contracts-sdk/src/lib/contracts-sdk.ts b/packages/contracts-sdk/src/lib/contracts-sdk.ts index c8998c7792..fcb3f31438 100644 --- a/packages/contracts-sdk/src/lib/contracts-sdk.ts +++ b/packages/contracts-sdk/src/lib/contracts-sdk.ts @@ -45,6 +45,7 @@ import { TokenInfo, derivedAddresses } from './addresses'; import { IPubkeyRouter } from '../abis/PKPNFT.sol/PKPNFT'; import { computeAddress } from 'ethers/lib/utils'; import { getAuthIdByAuthMethod } from './auth-utils'; +import { Logger, LogManager } from "@lit-protocol/logger"; const DEFAULT_RPC = 'https://chain-rpc.litprotocol.com/http'; const BLOCK_EXPLORER = 'https://chain.litprotocol.com/'; @@ -101,8 +102,9 @@ export class LitContracts { connected: boolean = false; isPKP: boolean = false; debug: boolean = false; - network: "cayenne" | "internalDev" = "internalDev"; + network: "cayenne" | "internalDev"; + static logger: Logger = LogManager.Instance.get('contract-sdk'); // ----- autogen:declares:start ----- // Generated at 2023-11-07T01:50:52.460Z allowlistContract: { @@ -185,7 +187,7 @@ export class LitContracts { this.randomPrivateKey = args?.randomPrivatekey ?? false; this.options = args?.options; this.debug = args?.debug ?? false; - + this.network = args?.network || 'cayenne'; // if rpc is not specified, use the default rpc if (!this.rpc) { this.rpc = DEFAULT_RPC; @@ -214,12 +216,11 @@ export class LitContracts { /** * Logs a message to the console. * - * @param {string} str The message to log. - * @param {any} [opt] An optional value to log with the message. + * @param {any} [args] An optional value to log with the message. */ - log = (str: string, opt?: any) => { + log = (...args: any) => { if (this.debug) { - console.log(`[@lit-protocol/contracts-sdk] ${str}`, opt ?? ''); + LitContracts.logger.debug(...args); } }; @@ -377,7 +378,7 @@ export class LitContracts { } let addresses: any = await LitContracts.getContractAddresses(this.network); - this.log(addresses); + this.log("resolved contract addresses for: ", this.network, addresses); // ----- autogen:init:start ----- // Generated at 2023-11-07T01:50:52.460Z @@ -542,66 +543,28 @@ export class LitContracts { - public static async getStakingContract(network: "cayenne" | "internalDev") { + public static async getStakingContract(network: "cayenne" | "internalDev" | "custom" | "localhost") { + let manifest = await LitContracts._resolveContractContext(network); const rpcUrl = DEFAULT_RPC; const provider = new ethers.providers.JsonRpcProvider(rpcUrl); - if (network === 'cayenne') { - return new ethers.Contract(StakingData.address, StakingData.abi, provider); - } else if (network === 'internalDev') { - const INTERNAL_DEV_API = - 'https://lit-general-worker.getlit.dev/internal-dev-contract-addresses'; + const { config, data: contractData } = manifest; - let data; - try { - // Fetch and parse the JSON data in one step - data = await fetch(INTERNAL_DEV_API).then((res) => res.json()); - } catch (e: any) { - throw new Error(`Error fetching data from ${INTERNAL_DEV_API}: ${e.toString()}`); - } - // Destructure the data for easier access - const { config, data: contractData } = data; + const stakingContract = contractData.find((item: { name: string }) => item.name === 'Staking').contracts[0]; + const { address_hash, ABI } = stakingContract; - const stakingContract = contractData.find((item: { name: string }) => item.name === 'Staking') - .contracts[0]; - const { address_hash: address, ABI: abi } = stakingContract; - - // Validate the required data - if (!config || !address || !abi) { - throw new Error('❌ Required contract data is missing'); - } - - return new ethers.Contract(address, abi, provider); - } else { - throw new Error(`Invalid network. Only cayenne and internalDev are supported.`); + // Validate the required data + if (!address_hash || !ABI) { + throw new Error('❌ Required contract data is missing'); } + + return new ethers.Contract(address_hash, ABI, provider); } - public static async getContractAddresses(network: "cayenne" | "internalDev") { - let data; - const INTERNAL_DEV_API = - 'https://lit-general-worker.getlit.dev/internal-dev-contract-addresses'; - const CAYENNE_API = "https://lit-general-worker.getlit.dev/contract-addresses"; - if (network == "cayenne") { - try { - // Fetch and parse the JSON data in one step - data = await fetch(CAYENNE_API).then((res) => res.json()); - } catch (e: any) { - throw new Error(`Error fetching data from ${INTERNAL_DEV_API}: ${e.toString()}`); - } - } else if (network == "internalDev") { - try { - const INTERNAL_DEV_API = - 'https://lit-general-worker.getlit.dev/internal-dev-contract-addresses'; - // Fetch and parse the JSON data in one step - data = await fetch(INTERNAL_DEV_API).then((res) => res.json()); - } catch (e: any) { - throw new Error(`Error fetching data from ${INTERNAL_DEV_API}: ${e.toString()}`); - } - } - + public static async getContractAddresses(network: "cayenne" | "internalDev" | "custom" | "localhost") { + const data = await LitContracts._resolveContractContext(network); // Destructure the data for easier access const { config, data: contractData } = data; const addresses: any = {}; @@ -673,12 +636,11 @@ export class LitContracts { return addresses; } - public static getMinNodeCount = async (network: "cayenne" | "internalDev") => { + public static getMinNodeCount = async (network: "cayenne" | "internalDev" | "custom" | "localhost") => { const contract = await LitContracts.getStakingContract(network); - const configs = await contract['config'](); - const minNodeCount = configs.minimumValidatorCount.toString(); + const minNodeCount = await contract['currentValidatorCountForConsensus'](); if (!minNodeCount) { throw new Error('❌ Minimum validator count is not set'); @@ -686,7 +648,7 @@ export class LitContracts { return minNodeCount; } - public static getValidators = async (network: "cayenne" | "internalDev"): Promise => { + public static getValidators = async (network: "cayenne" | "internalDev" | "custom" | "localhost"): Promise => { const contract = await LitContracts.getStakingContract(network); @@ -699,8 +661,7 @@ export class LitContracts { ]); const validators = []; - console.log("active validators", activeValidators); - console.log("kicked validators", kickedValidators); + // Check if active validator set meets the threshold if ( activeValidators.length - kickedValidators.length >= @@ -711,7 +672,7 @@ export class LitContracts { validators.push(validator); } } else { - console.log('❌ Active validator set does not meet the threshold'); + LitContracts.logger.error('❌ Active validator set does not meet the threshold'); } // remove kicked validators in active validators @@ -730,6 +691,30 @@ export class LitContracts { return networks; }; + private static async _resolveContractContext(network: "cayenne" | "internalDev" | "custom" | "localhost") { + let data; + const INTERNAL_DEV_API = + 'https://lit-general-worker.getlit.dev/internal-dev-contract-addresses'; + const CAYENNE_API = "https://lit-general-worker.getlit.dev/contract-addresses"; + if (network === "cayenne") { + try { + // Fetch and parse the JSON data in one step + data = await fetch(CAYENNE_API).then((res) => res.json()); + } catch (e: any) { + throw new Error(`Error fetching data from ${CAYENNE_API}: ${e.toString()}`); + } + } else if (network === "internalDev") { + try { + // Fetch and parse the JSON data in one step + data = await fetch(INTERNAL_DEV_API).then((res) => res.json()); + } catch (e: any) { + throw new Error(`Error fetching data from ${INTERNAL_DEV_API}: ${e.toString()}`); + } + } + + return data; + } + mintWithAuth = async ({ authMethod, scopes, diff --git a/packages/core/src/lib/lit-core.ts b/packages/core/src/lib/lit-core.ts index 4e2f256956..58d1d917b2 100644 --- a/packages/core/src/lib/lit-core.ts +++ b/packages/core/src/lib/lit-core.ts @@ -164,7 +164,7 @@ export class LitCore { */ setNewConfig = async (): Promise => { - if(this.config.litNetwork !== LitNetwork.Cayenne) { + if(this.config.litNetwork === LitNetwork.InternalDev) { const minNodeCount = await LitContracts.getMinNodeCount(this.config.litNetwork as LitNetwork); const bootstrapUrls = await LitContracts.getValidators(this.config.litNetwork as LitNetwork); log("Bootstrap urls: ", bootstrapUrls); @@ -184,12 +184,12 @@ export class LitCore { }); } - this.config.minNodeCount = minNodeCount; - } else { + this.config.minNodeCount = parseInt(minNodeCount, 10); + } else if (this.config.litNetwork === LitNetwork.Cayenne){ // If the network is cayenne it is a centralized testnet so we use a static config // This is due to staking contracts holding local ip / port contexts which are innacurate to the ip / port exposed to the world this.config.bootstrapUrls = LIT_NETWORKS.cayenne; - this.config.minNodeCount = LIT_NETWORKS.cayenne.length == 2 ? 2 : LIT_NETWORKS.cayenne.length / 3; + this.config.minNodeCount = LIT_NETWORKS.cayenne.length == 2 ? 2 : (LIT_NETWORKS.cayenne.length * 2) / 3; } } @@ -204,14 +204,16 @@ export class LitCore { * @returns {Promise} A promise that resolves when the listener is successfully set up. */ listenForNewEpoch = async (): Promise => { - const stakingContract = await LitContracts.getStakingContract(this.config.litNetwork as LitNetwork); - - stakingContract.on("StateChanged", async (state: StakingStates) => { - log(`New state detected: "${state}"`); - if (state === StakingStates.NextValidatorSetLocked) { - await this.setNewConfig(); - } - }); + if (this.config.litNetwork === LitNetwork.InternalDev) { + const stakingContract = await LitContracts.getStakingContract(this.config.litNetwork as any); + log('listening for state change on staking contract: ', stakingContract.address); + stakingContract.on("StateChanged", async (state: StakingStates) => { + log(`New state detected: "${state}"`); + if (state === StakingStates.NextValidatorSetLocked) { + await this.setNewConfig(); + } + }); + } }; /**