Skip to content

[Refactor] Create shared directory for all network environments #864

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

Open
wants to merge 19 commits into
base: naga
Choose a base branch
from

Conversation

Ansonhkg
Copy link
Collaborator

@Ansonhkg Ansonhkg commented Aug 19, 2025

WHAT

Currently, if we want to update the logic for different network environments (e.g., naga-dev and naga-staging), we have to modify two separate places with essentially the same code. This goes against the DRY principle.

This PR fixed this by creating a shared directory for all shared network APIs and utilities.

Please see the tree below to get the general sense how this is structured.

Here's the directory

Changes

  • Added default timeout --timeout 50000000 to the to the E2E tests.

Prereleases

🦋  New tag:  @lit-protocol/[email protected]
🦋  New tag:  @lit-protocol/[email protected]
🦋  New tag:  @lit-protocol/[email protected]
🦋  New tag:  @lit-protocol/[email protected]
🦋  New tag:  @lit-protocol/[email protected]
🦋  New tag:  @lit-protocol/[email protected]
🦋  New tag:  @lit-protocol/[email protected]
🦋  New tag:  @lit-protocol/[email protected]
🦋  New tag:  @lit-protocol/[email protected]
🦋  New tag:  @lit-protocol/[email protected]
🦋  New tag:  @lit-protocol/[email protected]
🦋  New tag:  @lit-protocol/[email protected]
🦋  New tag:  @lit-protocol/[email protected]

Tree

.
├── shared
│   ├── README.md
│   ├── helpers
│   │   ├── handleAuthServerRequest.ts
│   │   ├── pollResponse.ts
│   │   └── processResources.ts
│   ├── logger.ts
│   └── utils
│       ├── NormaliseArraySchema.ts
│       ├── createRequestId.ts
│       ├── transformers
│       │   └── ipfsCidV0ToHex.ts
│       ├── transformers.ts
│       ├── z-transformers.ts
│       └── z-validate.ts
├── types.ts
└── vNaga
    ├── envs
    │   ├── base
    │   │   └── BaseNetworkEnvironment.ts
    │   ├── naga-dev
    │   │   ├── chain-manager
    │   │   │   └── createChainManager.ts
    │   │   ├── index.ts
    │   │   ├── naga-dev.env.ts
    │   │   └── naga-dev.module.ts
    │   ├── naga-local
    │   │   ├── chain-manager
    │   │   │   └── createChainManager.ts
    │   │   ├── generated
    │   │   │   ├── naga-develop.cjs
    │   │   │   ├── naga-develop.js
    │   │   │   └── naga-develop.ts
    │   │   ├── index.ts
    │   │   ├── naga-local.env.ts
    │   │   └── naga-local.module.ts
    │   ├── naga-staging
    │   │   ├── chain-manager
    │   │   │   └── createChainManager.ts
    │   │   ├── index.ts
    │   │   ├── naga-staging.env.ts
    │   │   └── naga-staging.module.ts
    │   └── naga-test
    │       ├── chain-manager
    │       │   └── createChainManager.ts
    │       ├── index.ts
    │       ├── naga-test.env.ts
    │       └── naga-test.module.ts
    ├── index.ts
    └── shared
        ├── factories
        │   ├── BaseChainManagerFactory.ts
        │   └── BaseModuleFactory.ts
        ├── helpers
        │   └── createRequestId.ts
        ├── index.ts
        ├── integration.test.ts
        ├── interfaces
        │   └── NetworkContext.ts
        ├── managers
        │   ├── LitChainClient
        │   │   ├── README.md
        │   │   ├── apis
        │   │   │   ├── highLevelApis
        │   │   │   │   ├── PKPPermissionsManager
        │   │   │   │   │   ├── PKPPermissionsManager.test.ts
        │   │   │   │   │   ├── PKPPermissionsManager.ts
        │   │   │   │   │   ├── README.md
        │   │   │   │   │   ├── handlers
        │   │   │   │   │   │   ├── addPermittedActionByIdentifier.ts
        │   │   │   │   │   │   ├── addPermittedAddressByIdentifier.ts
        │   │   │   │   │   │   ├── addPermittedAuthMethodByIdentifier.ts
        │   │   │   │   │   │   ├── addPermittedAuthMethodScopeByIdentifier.ts
        │   │   │   │   │   │   ├── getPKPsByAddress.ts
        │   │   │   │   │   │   ├── getPKPsByAuthMethod.ts
        │   │   │   │   │   │   ├── getPermissionsContext.ts
        │   │   │   │   │   │   ├── getPermittedActionsByIdentifier.ts
        │   │   │   │   │   │   ├── getPermittedAddressesByIdentifier.ts
        │   │   │   │   │   │   ├── getPermittedAuthMethodScopesByIdentifier.ts
        │   │   │   │   │   │   ├── getPermittedAuthMethodsByIdentifier.ts
        │   │   │   │   │   │   ├── isPermittedActionByIdentifier.ts
        │   │   │   │   │   │   ├── isPermittedAddressByIdentifier.ts
        │   │   │   │   │   │   ├── removePermittedActionByIdentifier.ts
        │   │   │   │   │   │   ├── removePermittedAddressByIdentifier.ts
        │   │   │   │   │   │   ├── removePermittedAuthMethodByIdentifier.ts
        │   │   │   │   │   │   └── removePermittedAuthMethodScopeByIdentifier.ts
        │   │   │   │   │   └── index.ts
        │   │   │   │   ├── PaymentManager
        │   │   │   │   │   └── PaymentManager.ts
        │   │   │   │   ├── README.md
        │   │   │   │   ├── connection
        │   │   │   │   │   └── getConnectionInfo.ts
        │   │   │   │   ├── index.ts
        │   │   │   │   ├── mintPKP
        │   │   │   │   │   ├── MintPKPSchema.ts
        │   │   │   │   │   ├── mintPKP.ts
        │   │   │   │   │   ├── mintWithEoa.ts
        │   │   │   │   │   └── mintWithMultiAuths.ts
        │   │   │   │   └── priceFeed
        │   │   │   │       ├── README.md
        │   │   │   │       ├── index.ts
        │   │   │   │       └── priceFeedApi.ts
        │   │   │   ├── index.ts
        │   │   │   ├── rawContractApis
        │   │   │   │   ├── README.md
        │   │   │   │   ├── ledger
        │   │   │   │   │   ├── read
        │   │   │   │   │   │   ├── getBalance.ts
        │   │   │   │   │   │   ├── getStableBalance.ts
        │   │   │   │   │   │   ├── getUserWithdrawDelay.ts
        │   │   │   │   │   │   └── getWithdrawRequest.ts
        │   │   │   │   │   └── write
        │   │   │   │   │       ├── deposit.ts
        │   │   │   │   │       ├── depositForUser.ts
        │   │   │   │   │       ├── requestWithdraw.ts
        │   │   │   │   │       └── withdraw.ts
        │   │   │   │   ├── paymentDelegation
        │   │   │   │   │   ├── read
        │   │   │   │   │   │   ├── getPayers.ts
        │   │   │   │   │   │   ├── getPayersAndRestrictions.ts
        │   │   │   │   │   │   ├── getRestriction.ts
        │   │   │   │   │   │   └── getUsers.ts
        │   │   │   │   │   └── write
        │   │   │   │   │       ├── delegatePayments.ts
        │   │   │   │   │       ├── delegatePaymentsBatch.ts
        │   │   │   │   │       ├── setRestriction.ts
        │   │   │   │   │       ├── undelegatePayments.ts
        │   │   │   │   │       └── undelegatePaymentsBatch.ts
        │   │   │   │   ├── permissions
        │   │   │   │   │   ├── read
        │   │   │   │   │   │   ├── getPermittedActions.ts
        │   │   │   │   │   │   ├── getPermittedAddresses.ts
        │   │   │   │   │   │   ├── getPermittedAuthMethodScopes.ts
        │   │   │   │   │   │   ├── getPermittedAuthMethods.ts
        │   │   │   │   │   │   ├── isPermittedAction.ts
        │   │   │   │   │   │   └── isPermittedAddress.ts
        │   │   │   │   │   ├── utils
        │   │   │   │   │   │   ├── pubkeyToTokenId.ts
        │   │   │   │   │   │   └── resolvePkpTokenId.ts
        │   │   │   │   │   └── write
        │   │   │   │   │       ├── addPermittedAction.ts
        │   │   │   │   │       ├── addPermittedAddress.ts
        │   │   │   │   │       ├── addPermittedAuthMethod.ts
        │   │   │   │   │       ├── addPermittedAuthMethodScope.ts
        │   │   │   │   │       ├── removePermittedAction.ts
        │   │   │   │   │       ├── removePermittedAddress.ts
        │   │   │   │   │       ├── removePermittedAuthMethod.ts
        │   │   │   │   │       └── removePermittedAuthMethodScope.ts
        │   │   │   │   ├── pkp
        │   │   │   │   │   ├── read
        │   │   │   │   │   │   ├── getPubkeyByTokenId.ts
        │   │   │   │   │   │   ├── getTokenIdsForAuthMethod.ts
        │   │   │   │   │   │   └── tokenOfOwnerByIndex.ts
        │   │   │   │   │   └── write
        │   │   │   │   │       ├── claimAndMint.ts
        │   │   │   │   │       ├── claimAndMintNextAndAddAuthMethodsWithTypes.ts
        │   │   │   │   │       ├── mintNext.ts
        │   │   │   │   │       ├── mintNextAndAddAuthMethods.ts
        │   │   │   │   │       └── safeTransfer.ts
        │   │   │   │   ├── pricing
        │   │   │   │   │   └── getNodesForRequest.ts
        │   │   │   │   └── staking
        │   │   │   │       └── getActiveUnkickedValidatorStructsAndCounts.ts
        │   │   │   ├── types.ts
        │   │   │   └── utils
        │   │   │       ├── callWithAdjustedOverrides.ts
        │   │   │       └── decodeLogs.ts
        │   │   ├── index.ts
        │   │   ├── schemas
        │   │   │   ├── ClaimAndMintSchema.ts
        │   │   │   ├── ClaimRequestSchema.ts
        │   │   │   ├── GetActiveUnkickedValidatorStructsAndCountsSchema.ts
        │   │   │   ├── MintRequestSchema.ts
        │   │   │   └── shared
        │   │   │       ├── AuthMethodSchema.ts
        │   │   │       ├── PKPDataSchema.ts
        │   │   │       ├── ScopeSchema.ts
        │   │   │       └── SignatureDataSchema.ts
        │   │   └── types.ts
        │   ├── api-manager
        │   │   ├── APIFactory.test.ts
        │   │   ├── APIFactory.ts
        │   │   ├── decrypt
        │   │   │   ├── decrypt.CreateRequestParams.ts
        │   │   │   ├── decrypt.InputSchema.ts
        │   │   │   ├── decrypt.RequestDataSchema.ts
        │   │   │   └── decrypt.ResponseDataSchema.ts
        │   │   ├── e2ee-request-manager
        │   │   │   └── E2EERequestManager.ts
        │   │   ├── executeJs
        │   │   │   ├── executeJs.CreateRequestParams.ts
        │   │   │   ├── executeJs.InputSchema.ts
        │   │   │   ├── executeJs.RequestDataSchema.ts
        │   │   │   ├── executeJs.ResponseDataSchema.ts
        │   │   │   ├── executeJs.ts
        │   │   │   └── index.ts
        │   │   ├── handshake
        │   │   │   └── handshake.schema.ts
        │   │   ├── helper
        │   │   │   ├── get-signatures.test.ts
        │   │   │   ├── get-signatures.ts
        │   │   │   ├── parse-pkp-sign-response.test.ts
        │   │   │   └── parse-pkp-sign-response.ts
        │   │   ├── pkpSign
        │   │   │   ├── pkpSign.CreateRequestParams.ts
        │   │   │   ├── pkpSign.InputSchema.ts
        │   │   │   ├── pkpSign.RequestDataSchema.ts
        │   │   │   └── pkpSign.ResponseDataSchema.ts
        │   │   ├── signSessionKey
        │   │   │   └── signSessionKey.ResponseDataSchema.ts
        │   │   └── types.ts
        │   ├── contract-manager
        │   │   ├── createContractsManager.ts
        │   │   └── index.ts
        │   ├── endpoints-manager
        │   │   ├── composeLitUrl.ts
        │   │   └── endpoints.ts
        │   ├── pricing-manager
        │   │   ├── constants.ts
        │   │   ├── getMaxPricesForNodeProduct.ts
        │   │   ├── getUserMaxPrice.ts
        │   │   └── schema.ts
        │   ├── session-manager
        │   │   ├── AuthContextSchema.ts
        │   │   ├── helper
        │   │   │   ├── session-sigs-reader.test.ts
        │   │   │   ├── session-sigs-reader.ts
        │   │   │   └── session-sigs-validator.ts
        │   │   └── issueSessionFromContext.ts
        │   └── state-manager
        │       ├── createStateManager.ts
        │       ├── helpers
        │       │   └── fetchBlockchainData.ts
        │       ├── state-types
        │       │   ├── createEvmEventState.ts
        │       │   └── createRefreshedValue.ts
        │       └── utils
        │           └── areStringArraysDifferent.ts
        ├── schemas
        │   ├── LitMessageSchema.ts
        │   └── index.ts
        ├── scripts
        │   └── generate-abi-signatures.ts
        └── types.ts

69 directories, 176 files

…natures script to be inside a shared directory
@Ansonhkg Ansonhkg added documentation Improvements or additions to documentation v8 | Naga ✨ Enhancement New feature or request and removed documentation Improvements or additions to documentation labels Aug 19, 2025
@Ansonhkg Ansonhkg self-assigned this Aug 19, 2025
@Ansonhkg Ansonhkg changed the title chore(package.json): update build scripts and update generate-abi-sig… [Refactor] Create shared directory for all network environments Aug 20, 2025
@Ansonhkg Ansonhkg marked this pull request as ready for review August 20, 2025 23:54
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a refactoring to create a shared directory structure for all network environments to eliminate code duplication and follow the DRY principle. The main change is removing environment-specific duplicate code from naga-staging and consolidating shared logic into a common directory structure.

Key changes:

  • Removal of duplicate API manager implementations from naga-staging environment
  • Deletion of environment-specific helper functions and utilities that are now shared
  • Cleanup of redundant state management, session management, and testing code

Reviewed Changes

Copilot reviewed 92 out of 335 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/networks/src/networks/vNaga/envs/naga-staging/api-manager/helper/get-signatures.ts Removed duplicate signature combination logic for executeJS and PKP sign operations
packages/networks/src/networks/vNaga/envs/naga-staging/api-manager/executeJs/*.ts Removed duplicate executeJs API implementation including schemas and handlers
packages/networks/src/networks/vNaga/envs/naga-staging/api-manager/decrypt/*.ts Removed duplicate decrypt API schemas and request/response handlers
packages/networks/src/networks/vNaga/envs/naga-staging/api-manager/e2ee-request-manager/E2EERequestManager.ts Removed duplicate end-to-end encryption request management logic
packages/networks/src/networks/vNaga/envs/naga-local/state-manager/*.ts Removed duplicate state management implementation and related test files
packages/networks/src/networks/vNaga/envs/naga-local/session-manager/*.ts Removed duplicate session management logic including validation and formatting utilities
packages/networks/src/networks/vNaga/envs/naga-prod/*.ts Removed placeholder/commented production environment files

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

…option-to-override' of github.com:LIT-Protocol/js-sdk into feature/jss-37-optimisation-unify-shared-logic-with-an-option-to-override
@Ansonhkg Ansonhkg closed this Aug 21, 2025
@Ansonhkg Ansonhkg deleted the feature/jss-37-optimisation-unify-shared-logic-with-an-option-to-override branch August 21, 2025 16:29
@Ansonhkg Ansonhkg restored the feature/jss-37-optimisation-unify-shared-logic-with-an-option-to-override branch August 21, 2025 16:30
@Ansonhkg Ansonhkg reopened this Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Enhancement New feature or request v8 | Naga
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant