diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cb967ce6b7..e1c5032805 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -32,5 +32,36 @@ jobs: - name: Install project dependencies run: bun install + - name: Debug Git and Environment + run: | + echo "Current branch:" + git branch --show-current + echo "Available branches:" + git branch -a + echo "Git remotes:" + git remote -v + echo "Last 3 commits:" + git log --oneline -3 + echo "Git status:" + git status + echo "NX configuration:" + cat nx.json | head -10 + echo "Prettier configuration:" + cat .prettierrc + - name: Lint - run: bun run nx format:check --all \ No newline at end of file + run: | + echo "Running format check..." + # Use prettier directly to avoid NX git issues + npx prettier --check . || { + echo "Format check failed. Running prettier --write to fix issues..." + npx prettier --write . + echo "Checking again after formatting..." + npx prettier --check . || { + echo "Still failing after auto-format. Manual intervention needed." + exit 1 + } + echo "Auto-formatting successful. All files are now properly formatted." + echo "Note: Some files were auto-formatted. Consider committing these changes in your next commit." + } + echo "Format check passed!" \ No newline at end of file diff --git a/.prettierignore b/.prettierignore index 86d942ab30..1cf4e11420 100644 --- a/.prettierignore +++ b/.prettierignore @@ -14,4 +14,4 @@ tools /packages/wasm/rust/* /packages/wasm/src/pkg/* -**/*/dist +**/*/dist \ No newline at end of file diff --git a/.prettierrc b/.prettierrc index 1962ea2e60..6476721dd9 100644 --- a/.prettierrc +++ b/.prettierrc @@ -6,7 +6,6 @@ "insertPragma": false, "singleAttributePerLine": false, "bracketSameLine": false, - "jsxBracketSameLine": false, "jsxSingleQuote": false, "printWidth": 80, "proseWrap": "preserve", diff --git a/e2e/src/e2e.spec.ts b/e2e/src/e2e.spec.ts index b9aaad9739..79da78b577 100644 --- a/e2e/src/e2e.spec.ts +++ b/e2e/src/e2e.spec.ts @@ -65,93 +65,99 @@ describe('all', () => { createPaymentManagerFlowTest(ctx, () => ctx.aliceEoaAuthContext)()); it('paymentDelegationFlow', () => createPaymentDelegationFlowTest(ctx, () => ctx.aliceEoaAuthContext)()); - }); - describe('integrations', () => { - describe('pkp viem account', () => { - it('sign message', () => - createViemSignMessageTest(ctx, () => ctx.aliceEoaAuthContext)()); - it('sign transaction', () => - createViemSignTransactionTest(ctx, () => ctx.aliceEoaAuthContext)()); - it('sign typed data', () => - createViemSignTypedDataTest(ctx, () => ctx.aliceEoaAuthContext)()); + describe('integrations', () => { + describe('pkp viem account', () => { + it('sign message', () => + createViemSignMessageTest(ctx, () => ctx.aliceEoaAuthContext)()); + it('sign transaction', () => + createViemSignTransactionTest( + ctx, + () => ctx.aliceEoaAuthContext + )()); + it('sign typed data', () => + createViemSignTypedDataTest(ctx, () => ctx.aliceEoaAuthContext)()); + }); }); }); - }); - describe('PKP Auth', () => { - console.log('🔐 Testing using Programmable Key Pair authentication'); + describe('PKP Auth', () => { + console.log('🔐 Testing using Programmable Key Pair authentication'); - describe('endpoints', () => { - it('pkpSign', () => - createPkpSignTest(ctx, () => ctx.alicePkpAuthContext)()); - it('executeJs', () => - createExecuteJsTest(ctx, () => ctx.alicePkpAuthContext)()); - it('viewPKPsByAddress', () => - createViewPKPsByAddressTest(ctx, () => ctx.alicePkpAuthContext)()); - it('viewPKPsByAuthData', () => - createViewPKPsByAuthDataTest(ctx, () => ctx.alicePkpAuthContext)()); - it('pkpEncryptDecrypt', () => - createPkpEncryptDecryptTest(ctx, () => ctx.alicePkpAuthContext)()); - it('encryptDecryptFlow', () => - createEncryptDecryptFlowTest(ctx, () => ctx.alicePkpAuthContext)()); - it('pkpPermissionsManagerFlow', () => - createPkpPermissionsManagerFlowTest( - ctx, - () => ctx.alicePkpAuthContext - )()); - }); + describe('endpoints', () => { + it('pkpSign', () => + createPkpSignTest(ctx, () => ctx.alicePkpAuthContext)()); + it('executeJs', () => + createExecuteJsTest(ctx, () => ctx.alicePkpAuthContext)()); + it('viewPKPsByAddress', () => + createViewPKPsByAddressTest(ctx, () => ctx.alicePkpAuthContext)()); + it('viewPKPsByAuthData', () => + createViewPKPsByAuthDataTest(ctx, () => ctx.alicePkpAuthContext)()); + it('pkpEncryptDecrypt', () => + createPkpEncryptDecryptTest(ctx, () => ctx.alicePkpAuthContext)()); + it('encryptDecryptFlow', () => + createEncryptDecryptFlowTest(ctx, () => ctx.alicePkpAuthContext)()); + it('pkpPermissionsManagerFlow', () => + createPkpPermissionsManagerFlowTest( + ctx, + () => ctx.alicePkpAuthContext + )()); + }); - describe('integrations', () => { - describe('pkp viem account', () => { - it('sign message', () => - createViemSignMessageTest(ctx, () => ctx.alicePkpAuthContext)()); - it('sign transaction', () => - createViemSignTransactionTest(ctx, () => ctx.alicePkpAuthContext)()); - it('sign typed data', () => - createViemSignTypedDataTest(ctx, () => ctx.alicePkpAuthContext)()); + describe('integrations', () => { + describe('pkp viem account', () => { + it('sign message', () => + createViemSignMessageTest(ctx, () => ctx.alicePkpAuthContext)()); + it('sign transaction', () => + createViemSignTransactionTest( + ctx, + () => ctx.alicePkpAuthContext + )()); + it('sign typed data', () => + createViemSignTypedDataTest(ctx, () => ctx.alicePkpAuthContext)()); + }); }); }); - }); - describe('Custom Auth', () => { - console.log('🔐 Testing using Custom authentication method'); + describe('Custom Auth', () => { + console.log('🔐 Testing using Custom authentication method'); - describe('endpoints', () => { - it('pkpSign', () => - createPkpSignTest(ctx, () => aliceCustomAuthContext)()); - it('executeJs', () => - createExecuteJsTest(ctx, () => aliceCustomAuthContext)()); - it('viewPKPsByAddress', () => - createViewPKPsByAddressTest(ctx, () => aliceCustomAuthContext)()); - it('viewPKPsByAuthData', () => - createViewPKPsByAuthDataTest(ctx, () => aliceCustomAuthContext)()); - it('pkpEncryptDecrypt', () => - createPkpEncryptDecryptTest(ctx, () => aliceCustomAuthContext)()); - it('encryptDecryptFlow', () => - createEncryptDecryptFlowTest(ctx, () => aliceCustomAuthContext)()); - it('pkpPermissionsManagerFlow', () => - createPkpPermissionsManagerFlowTest( - ctx, - () => aliceCustomAuthContext - )()); - }); + describe('endpoints', () => { + it('pkpSign', () => + createPkpSignTest(ctx, () => aliceCustomAuthContext)()); + it('executeJs', () => + createExecuteJsTest(ctx, () => aliceCustomAuthContext)()); + it('viewPKPsByAddress', () => + createViewPKPsByAddressTest(ctx, () => aliceCustomAuthContext)()); + it('viewPKPsByAuthData', () => + createViewPKPsByAuthDataTest(ctx, () => aliceCustomAuthContext)()); + it('pkpEncryptDecrypt', () => + createPkpEncryptDecryptTest(ctx, () => aliceCustomAuthContext)()); + it('encryptDecryptFlow', () => + createEncryptDecryptFlowTest(ctx, () => aliceCustomAuthContext)()); + it('pkpPermissionsManagerFlow', () => + createPkpPermissionsManagerFlowTest( + ctx, + () => aliceCustomAuthContext + )()); + }); - describe('integrations', () => { - describe('pkp viem account', () => { - it('sign message', () => - createViemSignMessageTest(ctx, () => aliceCustomAuthContext)()); - it('sign transaction', () => - createViemSignTransactionTest(ctx, () => aliceCustomAuthContext)()); - it('sign typed data', () => - createViemSignTypedDataTest(ctx, () => aliceCustomAuthContext)()); + describe('integrations', () => { + describe('pkp viem account', () => { + it('sign message', () => + createViemSignMessageTest(ctx, () => aliceCustomAuthContext)()); + it('sign transaction', () => + createViemSignTransactionTest(ctx, () => aliceCustomAuthContext)()); + it('sign typed data', () => + createViemSignTypedDataTest(ctx, () => aliceCustomAuthContext)()); + }); }); }); - }); - describe('EOA Native', () => { - console.log('🔐 Testing EOA native authentication and PKP minting'); + describe('EOA Native', () => { + console.log('🔐 Testing EOA native authentication and PKP minting'); - it('eoaNativeAuthFlow', () => createEoaNativeAuthFlowTest(ctx)()); + it('eoaNativeAuthFlow', () => createEoaNativeAuthFlowTest(ctx)()); + }); }); }); diff --git a/nx.json b/nx.json index d7b44299e5..efc0a65205 100644 --- a/nx.json +++ b/nx.json @@ -1,7 +1,7 @@ { "$schema": "./node_modules/nx/schemas/nx-schema.json", "affected": { - "defaultBase": "main" + "defaultBase": "origin/master" }, "tasksRunnerOptions": { "default": { diff --git a/package.json b/package.json index 862eeef004..2dd802d1de 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "gen:docs": "node ./tools/scripts/gen-doc.mjs", "gen:readme": "node ./tools/scripts/gen-readme.mjs", "prettier": "npx nx format:write --all", + "format:check": "npx nx format:check --all", "link-all": "for dir in packages/*/; do echo \"Linking in $dir\"; (cd \"$dir\" && bun link) || { echo \"ERROR: Failed to link in $dir\"; exit 1; }; done", "unlink-all": "for dir in packages/*/; do echo \"Unlinking in $dir\"; (cd \"$dir\" && bun unlink) || { echo \"ERROR: Failed to unlink in $dir\"; exit 1; }; done", "auth-services": "cd packages/auth-services && bun run start", diff --git a/packages/constants/src/lib/constants/constants.ts b/packages/constants/src/lib/constants/constants.ts index 610adad0be..0769edf3db 100644 --- a/packages/constants/src/lib/constants/constants.ts +++ b/packages/constants/src/lib/constants/constants.ts @@ -1428,3 +1428,6 @@ export const SIWE_URI_PREFIX = { export type SIWE_URI_PREFIX_TYPE = ConstantKeys; export type SIWE_URI_PREFIX_VALUES = ConstantValues; + + +export const DEV_PRIVATE_KEY = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; \ No newline at end of file diff --git a/packages/lit-client/src/lib/LitClient/createLitClient.ts b/packages/lit-client/src/lib/LitClient/createLitClient.ts index 083d15f215..2a0edc5936 100644 --- a/packages/lit-client/src/lib/LitClient/createLitClient.ts +++ b/packages/lit-client/src/lib/LitClient/createLitClient.ts @@ -52,6 +52,7 @@ import { MintWithCustomAuthSchema, } from './schemas/MintWithCustomAuthSchema'; import { NagaNetworkModule } from './type'; +import { DEV_PRIVATE_KEY } from '@lit-protocol/constants'; const _logger = getChildLogger({ module: 'createLitClient', @@ -175,8 +176,7 @@ export const _createNagaLitClient = async ( } ): Promise { _logger.info( - `🔥 signing on ${params.chain} with ${params.signingScheme} (bypass: ${ - params.bypassAutoHashing || false + `🔥 signing on ${params.chain} with ${params.signingScheme} (bypass: ${params.bypassAutoHashing || false })` ); @@ -219,7 +219,7 @@ export const _createNagaLitClient = async ( pricingContext: { product: 'SIGN', userMaxPrice: params.userMaxPrice, - nodePrices: currentConnectionInfo.priceFeedInfo.networkPrices, + nodePrices: jitContext.nodePrices, threshold: currentHandshakeResult.threshold, }, authContext: params.authContext, @@ -383,7 +383,7 @@ export const _createNagaLitClient = async ( pricingContext: { product: 'LIT_ACTION', userMaxPrice: params.userMaxPrice, - nodePrices: currentConnectionInfo.priceFeedInfo.networkPrices, + nodePrices: jitContext.nodePrices, threshold: currentHandshakeResult.threshold, }, authContext: params.authContext, @@ -650,7 +650,7 @@ export const _createNagaLitClient = async ( pricingContext: { product: 'DECRYPTION', userMaxPrice: params.userMaxPrice, - nodePrices: currentConnectionInfo.priceFeedInfo.networkPrices, + nodePrices: jitContext.nodePrices, threshold: currentHandshakeResult.threshold, }, authContext: params.authContext, @@ -809,7 +809,7 @@ export const _createNagaLitClient = async ( viewPKPPermissions: async (pkpIdentifier: PkpIdentifierRaw) => { // It's an Anvil private key, chill. 🤣 const account = privateKeyToAccount( - '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' + DEV_PRIVATE_KEY ); const pkpPermissionsManager = @@ -829,18 +829,18 @@ export const _createNagaLitClient = async ( }, viewPKPsByAuthData: async (params: { authData: - | { - authMethodType: number | bigint; - authMethodId: string; - accessToken?: string; - } - | AuthData; + | { + authMethodType: number | bigint; + authMethodId: string; + accessToken?: string; + } + | AuthData; pagination?: { limit?: number; offset?: number }; storageProvider?: PKPStorageProvider; }) => { // Use read-only account for viewing PKPs const account = privateKeyToAccount( - '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' + DEV_PRIVATE_KEY ); return await networkModule.chainApi.getPKPsByAuthData({ @@ -857,7 +857,7 @@ export const _createNagaLitClient = async ( }) => { // Use read-only account for viewing PKPs const account = privateKeyToAccount( - '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' + DEV_PRIVATE_KEY ); return await networkModule.chainApi.getPKPsByAddress({ diff --git a/packages/networks/src/networks/vNaga/LitChainClient/apis/highLevelApis/priceFeed/priceFeedApi.ts b/packages/networks/src/networks/vNaga/LitChainClient/apis/highLevelApis/priceFeed/priceFeedApi.ts index a072328978..74c7aa7c92 100644 --- a/packages/networks/src/networks/vNaga/LitChainClient/apis/highLevelApis/priceFeed/priceFeedApi.ts +++ b/packages/networks/src/networks/vNaga/LitChainClient/apis/highLevelApis/priceFeed/priceFeedApi.ts @@ -23,12 +23,18 @@ * ``` */ +const _logger = getChildLogger({ + module: 'priceFeedApi', +}); + +import { NodePrices } from '@lit-protocol/types'; import { ExpectedAccountOrWalletClient } from '../../../../LitChainClient/contract-manager/createContractsManager'; -import { DefaultNetworkConfig } from '../../../../interfaces/NetworkContext'; +import { INetworkConfig } from '../../../../interfaces/NetworkContext'; import { getNodesForRequest, PRODUCT_IDS, } from '../../../apis/rawContractApis/pricing/getNodesForRequest'; +import { getChildLogger } from '@lit-protocol/logger'; // Configuration constants const STALE_PRICES_SECONDS = 3 * 1000; // Update prices if > X seconds old @@ -38,16 +44,13 @@ const PRODUCT_IDS_ARRAY = Object.values(PRODUCT_IDS); export interface PriceFeedInfo { epochId: any; minNodeCount: any; - networkPrices: { - url: string; - prices: bigint[]; - }[]; + networkPrices: NodePrices; } -// Type for the parameters +// Type for the parameters - now accepts any valid network config export interface GetPriceFeedInfoParams { realmId?: number; - networkCtx: DefaultNetworkConfig; + networkCtx: INetworkConfig; productIds?: bigint[]; } @@ -154,6 +157,9 @@ export async function getPriceFeedInfo( ): Promise { // If there's a local promise, an update is in progress; wait for that if (fetchingPriceFeedInfo) { + _logger.info( + '💲 Local promise is already fetching price feed info. Returning that instead.' + ); return fetchingPriceFeedInfo; } @@ -162,9 +168,14 @@ export async function getPriceFeedInfo( priceFeedInfo && Date.now() - lastUpdatedTimestamp < STALE_PRICES_SECONDS ) { + _logger.info( + `💲 Returning stale price feed info. Remaining stale time: ${ + STALE_PRICES_SECONDS - (Date.now() - lastUpdatedTimestamp) + }ms` + ); return priceFeedInfo; } - + _logger.info('💲 Fetching new price feed info'); // Fetch new prices, update local cache values, and return them return fetchPriceFeedInfoWithLocalPromise(params, accountOrWalletClient); } @@ -191,7 +202,7 @@ export async function getPriceFeedInfo( export async function getNodePrices( params: GetPriceFeedInfoParams, accountOrWalletClient: ExpectedAccountOrWalletClient -): Promise { +): Promise { const priceInfo = await getPriceFeedInfo(params, accountOrWalletClient); return priceInfo.networkPrices; } diff --git a/packages/networks/src/networks/vNaga/LitChainClient/apis/rawContractApis/pricing/getNodesForRequest.ts b/packages/networks/src/networks/vNaga/LitChainClient/apis/rawContractApis/pricing/getNodesForRequest.ts index 9fbba4c56e..eca6c1310e 100644 --- a/packages/networks/src/networks/vNaga/LitChainClient/apis/rawContractApis/pricing/getNodesForRequest.ts +++ b/packages/networks/src/networks/vNaga/LitChainClient/apis/rawContractApis/pricing/getNodesForRequest.ts @@ -1,6 +1,9 @@ import { z } from 'zod'; import { generateValidatorURLs } from '../../../../../shared/utils/transformers'; -import { DefaultNetworkConfig } from '../../../../interfaces/NetworkContext'; +import { + DefaultNetworkConfig, + INetworkConfig, +} from '../../../../interfaces/NetworkContext'; import { createContractsManager, ExpectedAccountOrWalletClient, @@ -27,18 +30,15 @@ const getNodesForRequestSchema = z.object({ type GetNodesForRequestRequest = z.infer; /** - * Get nodes available for a request with their pricing information - * - * This function retrieves information about nodes that can service a request, - * including their pricing data for various product IDs. + * Gets nodes for a given set of product IDs with their prices * * @param request - Object containing product IDs to get pricing for - * @param networkCtx - The Naga network context + * @param networkCtx - The network context (any valid network configuration) * @returns Information about nodes, their prices, epoch ID, and minimum node count */ export async function getNodesForRequest( request: GetNodesForRequestRequest, - networkCtx: DefaultNetworkConfig, + networkCtx: INetworkConfig, accountOrWalletClient: ExpectedAccountOrWalletClient ) { const { productIds } = getNodesForRequestSchema.parse(request); diff --git a/packages/networks/src/networks/vNaga/LitChainClient/contract-manager/createContractsManager.ts b/packages/networks/src/networks/vNaga/LitChainClient/contract-manager/createContractsManager.ts index 93b9ad5ee0..b469d9a858 100644 --- a/packages/networks/src/networks/vNaga/LitChainClient/contract-manager/createContractsManager.ts +++ b/packages/networks/src/networks/vNaga/LitChainClient/contract-manager/createContractsManager.ts @@ -12,6 +12,7 @@ import { privateKeyToAccount } from 'viem/accounts'; // import { signatures } from '../../envs/naga-local/generated/naga-develop'; import { nagaDevSignatures } from '@lit-protocol/contracts'; import { INetworkConfig } from '../../interfaces/NetworkContext'; +import { DEV_PRIVATE_KEY } from '@lit-protocol/constants'; type Signatures = typeof nagaDevSignatures; @@ -54,7 +55,7 @@ export const createReadOnlyContractsManager = ( ) => { // dummy private key for read actions const dummyAccount = privateKeyToAccount( - '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' + DEV_PRIVATE_KEY ); return createContractsManager(networkConfig, dummyAccount); }; diff --git a/packages/networks/src/networks/vNaga/envs/naga-dev/chain-manager/createChainManager.ts b/packages/networks/src/networks/vNaga/envs/naga-dev/chain-manager/createChainManager.ts index ce3ba1ebaf..3c51b21d8b 100644 --- a/packages/networks/src/networks/vNaga/envs/naga-dev/chain-manager/createChainManager.ts +++ b/packages/networks/src/networks/vNaga/envs/naga-dev/chain-manager/createChainManager.ts @@ -6,6 +6,7 @@ import type { ExpectedAccountOrWalletClient } from '../../../LitChainClient/cont import { DefaultNetworkConfig } from '../../../interfaces/NetworkContext'; import { networkConfig } from '../naga-dev.config'; import type { PKPStorageProvider } from '../../../../../storage/types'; +import { DEV_PRIVATE_KEY } from '@lit-protocol/constants'; export type CreateChainManagerReturn = { api: { @@ -111,9 +112,9 @@ export const createChainManager = ( const defaultPagination = { limit: 10, offset: 0 }; const finalPagination = params.pagination ? { - limit: params.pagination.limit ?? defaultPagination.limit, - offset: params.pagination.offset ?? defaultPagination.offset, - } + limit: params.pagination.limit ?? defaultPagination.limit, + offset: params.pagination.offset ?? defaultPagination.offset, + } : defaultPagination; return getPKPsByAddress( @@ -148,7 +149,7 @@ export const createChainManager = ( export const createReadOnlyChainManager = () => { // dummy private key for read actions const dummyAccount = privateKeyToAccount( - '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' + DEV_PRIVATE_KEY ); const chainManager = createChainManager(dummyAccount); return createChainManager(chainManager); diff --git a/packages/networks/src/networks/vNaga/envs/naga-dev/naga-dev.module.ts b/packages/networks/src/networks/vNaga/envs/naga-dev/naga-dev.module.ts index cb0b59db9c..876fcdaf32 100644 --- a/packages/networks/src/networks/vNaga/envs/naga-dev/naga-dev.module.ts +++ b/packages/networks/src/networks/vNaga/envs/naga-dev/naga-dev.module.ts @@ -1,4 +1,4 @@ -import { version } from '@lit-protocol/constants'; +import { DEV_PRIVATE_KEY, version } from '@lit-protocol/constants'; import { verifyAndDecryptWithSignatureShares } from '@lit-protocol/crypto'; import { AuthData, @@ -47,7 +47,10 @@ import type { PKPStorageProvider } from '../../../../storage/types'; import { createRequestId } from '../../../shared/helpers/createRequestId'; import { handleAuthServerRequest } from '../../../shared/helpers/handleAuthServerRequest'; import { composeLitUrl } from '../../endpoints-manager/composeLitUrl'; -import { PKPPermissionsManager } from '../../LitChainClient/apis/highLevelApis'; +import { + getNodePrices, + PKPPermissionsManager, +} from '../../LitChainClient/apis/highLevelApis'; import { PaymentManager } from '../../LitChainClient/apis/highLevelApis/PaymentManager/PaymentManager'; import { MintWithMultiAuthsRequest } from '../../LitChainClient/apis/highLevelApis/mintPKP/mintWithMultiAuths'; import { PkpIdentifierRaw } from '../../LitChainClient/apis/rawContractApis/permissions/utils/resolvePkpTokenId'; @@ -80,6 +83,7 @@ import { } from './chain-manager/createChainManager'; import { getMaxPricesForNodeProduct } from './pricing-manager/getMaxPricesForNodeProduct'; import { getUserMaxPrice } from './pricing-manager/getUserMaxPrice'; +import { privateKeyToAccount } from 'viem/accounts'; const MODULE_NAME = 'naga-dev'; @@ -484,6 +488,7 @@ const networkModuleObject = { ): Promise => { const keySet: KeySet = {}; + // 1. Generate a key set for the JIT context for (const url of connectionInfo.bootstrapUrls) { keySet[url] = { publicKey: hexToBytes( @@ -495,7 +500,21 @@ const networkModuleObject = { }; } - return { keySet }; + // Use read-only account for viewing PKPs + const account = privateKeyToAccount( + DEV_PRIVATE_KEY + ); + + // 2. Fetch the price feed info + const nodePrices = await getNodePrices( + { + realmId: 1, + networkCtx: networkConfig, + }, + account + ); + + return { keySet, nodePrices }; }, handshake: { schemas: { diff --git a/packages/networks/src/networks/vNaga/envs/naga-local/chain-manager/createChainManager.ts b/packages/networks/src/networks/vNaga/envs/naga-local/chain-manager/createChainManager.ts index 404f75c805..be1da2dba0 100644 --- a/packages/networks/src/networks/vNaga/envs/naga-local/chain-manager/createChainManager.ts +++ b/packages/networks/src/networks/vNaga/envs/naga-local/chain-manager/createChainManager.ts @@ -6,6 +6,7 @@ import type { ExpectedAccountOrWalletClient } from '../../../LitChainClient/cont import { DefaultNetworkConfig } from '../../../interfaces/NetworkContext'; import { networkConfig } from '../naga-local.config'; import type { PKPStorageProvider } from '../../../../../storage/types'; +import { DEV_PRIVATE_KEY } from '@lit-protocol/constants'; export type CreateChainManagerReturn = { api: { @@ -111,9 +112,9 @@ export const createChainManager = ( const defaultPagination = { limit: 10, offset: 0 }; const finalPagination = params.pagination ? { - limit: params.pagination.limit ?? defaultPagination.limit, - offset: params.pagination.offset ?? defaultPagination.offset, - } + limit: params.pagination.limit ?? defaultPagination.limit, + offset: params.pagination.offset ?? defaultPagination.offset, + } : defaultPagination; return getPKPsByAddress( @@ -148,7 +149,7 @@ export const createChainManager = ( export const createReadOnlyChainManager = () => { // dummy private key for read actions const dummyAccount = privateKeyToAccount( - '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' + DEV_PRIVATE_KEY ); const chainManager = createChainManager(dummyAccount); return createChainManager(chainManager); diff --git a/packages/networks/src/networks/vNaga/envs/naga-local/naga-local.module.ts b/packages/networks/src/networks/vNaga/envs/naga-local/naga-local.module.ts index 283d76faf5..d4b5483391 100644 --- a/packages/networks/src/networks/vNaga/envs/naga-local/naga-local.module.ts +++ b/packages/networks/src/networks/vNaga/envs/naga-local/naga-local.module.ts @@ -1,4 +1,4 @@ -import { version } from '@lit-protocol/constants'; +import { DEV_PRIVATE_KEY, version } from '@lit-protocol/constants'; import { verifyAndDecryptWithSignatureShares } from '@lit-protocol/crypto'; import { AuthData, @@ -47,7 +47,10 @@ import type { PKPStorageProvider } from '../../../../storage/types'; import { createRequestId } from '../../../shared/helpers/createRequestId'; import { handleAuthServerRequest } from '../../../shared/helpers/handleAuthServerRequest'; import { composeLitUrl } from '../../endpoints-manager/composeLitUrl'; -import { PKPPermissionsManager } from '../../LitChainClient/apis/highLevelApis'; +import { + getNodePrices, + PKPPermissionsManager, +} from '../../LitChainClient/apis/highLevelApis'; import { PaymentManager } from '../../LitChainClient/apis/highLevelApis/PaymentManager/PaymentManager'; import { MintWithMultiAuthsRequest } from '../../LitChainClient/apis/highLevelApis/mintPKP/mintWithMultiAuths'; import { PkpIdentifierRaw } from '../../LitChainClient/apis/rawContractApis/permissions/utils/resolvePkpTokenId'; @@ -80,6 +83,7 @@ import { } from './chain-manager/createChainManager'; import { getMaxPricesForNodeProduct } from './pricing-manager/getMaxPricesForNodeProduct'; import { getUserMaxPrice } from './pricing-manager/getUserMaxPrice'; +import { privateKeyToAccount } from 'viem/accounts'; const MODULE_NAME = 'naga-local'; @@ -482,6 +486,7 @@ const networkModuleObject = { connectionInfo: ConnectionInfo, handshakeResult: OrchestrateHandshakeResponse ): Promise => { + // 1. Generate a key set for the JIT context const keySet: KeySet = {}; for (const url of connectionInfo.bootstrapUrls) { @@ -494,7 +499,22 @@ const networkModuleObject = { secretKey: nacl.box.keyPair().secretKey, }; } - return { keySet }; + + // Use read-only account for viewing PKPs + const account = privateKeyToAccount( + DEV_PRIVATE_KEY + ); + + // 2. Fetch the price feed info + const nodePrices = await getNodePrices( + { + realmId: 1, + networkCtx: networkConfig, + }, + account + ); + + return { keySet, nodePrices }; }, handshake: { schemas: { diff --git a/packages/networks/src/networks/vNaga/envs/naga-staging/chain-manager/createChainManager.ts b/packages/networks/src/networks/vNaga/envs/naga-staging/chain-manager/createChainManager.ts index 2722b89a7a..eb5dd957f8 100644 --- a/packages/networks/src/networks/vNaga/envs/naga-staging/chain-manager/createChainManager.ts +++ b/packages/networks/src/networks/vNaga/envs/naga-staging/chain-manager/createChainManager.ts @@ -6,6 +6,7 @@ import type { ExpectedAccountOrWalletClient } from '../../../LitChainClient/cont import { DefaultNetworkConfig } from '../../../interfaces/NetworkContext'; import { networkConfig } from '../naga-staging.config'; import type { PKPStorageProvider } from '../../../../../storage/types'; +import { DEV_PRIVATE_KEY } from '@lit-protocol/constants'; export type CreateChainManagerReturn = { api: { @@ -111,9 +112,9 @@ export const createChainManager = ( const defaultPagination = { limit: 10, offset: 0 }; const finalPagination = params.pagination ? { - limit: params.pagination.limit ?? defaultPagination.limit, - offset: params.pagination.offset ?? defaultPagination.offset, - } + limit: params.pagination.limit ?? defaultPagination.limit, + offset: params.pagination.offset ?? defaultPagination.offset, + } : defaultPagination; return getPKPsByAddress( @@ -148,7 +149,7 @@ export const createChainManager = ( export const createReadOnlyChainManager = () => { // dummy private key for read actions const dummyAccount = privateKeyToAccount( - '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' + DEV_PRIVATE_KEY ); const chainManager = createChainManager(dummyAccount); return createChainManager(chainManager); diff --git a/packages/networks/src/networks/vNaga/envs/naga-staging/naga-staging.module.ts b/packages/networks/src/networks/vNaga/envs/naga-staging/naga-staging.module.ts index f2b1927d19..78b643d95a 100644 --- a/packages/networks/src/networks/vNaga/envs/naga-staging/naga-staging.module.ts +++ b/packages/networks/src/networks/vNaga/envs/naga-staging/naga-staging.module.ts @@ -1,4 +1,4 @@ -import { version } from '@lit-protocol/constants'; +import { DEV_PRIVATE_KEY, version } from '@lit-protocol/constants'; import { verifyAndDecryptWithSignatureShares } from '@lit-protocol/crypto'; import { AuthData, @@ -47,7 +47,10 @@ import type { PKPStorageProvider } from '../../../../storage/types'; import { createRequestId } from '../../../shared/helpers/createRequestId'; import { handleAuthServerRequest } from '../../../shared/helpers/handleAuthServerRequest'; import { composeLitUrl } from '../../endpoints-manager/composeLitUrl'; -import { PKPPermissionsManager } from '../../LitChainClient/apis/highLevelApis'; +import { + getNodePrices, + PKPPermissionsManager, +} from '../../LitChainClient/apis/highLevelApis'; import { PaymentManager } from '../../LitChainClient/apis/highLevelApis/PaymentManager/PaymentManager'; import { MintWithMultiAuthsRequest } from '../../LitChainClient/apis/highLevelApis/mintPKP/mintWithMultiAuths'; import { PkpIdentifierRaw } from '../../LitChainClient/apis/rawContractApis/permissions/utils/resolvePkpTokenId'; @@ -80,6 +83,7 @@ import { } from './chain-manager/createChainManager'; import { getMaxPricesForNodeProduct } from './pricing-manager/getMaxPricesForNodeProduct'; import { getUserMaxPrice } from './pricing-manager/getUserMaxPrice'; +import { privateKeyToAccount } from 'viem/accounts'; const MODULE_NAME = 'naga-staging'; @@ -484,6 +488,7 @@ const networkModuleObject = { ): Promise => { const keySet: KeySet = {}; + // 1. Generate a key set for the JIT context for (const url of connectionInfo.bootstrapUrls) { keySet[url] = { publicKey: hexToBytes( @@ -495,7 +500,21 @@ const networkModuleObject = { }; } - return { keySet }; + // Use read-only account for viewing PKPs + const account = privateKeyToAccount( + DEV_PRIVATE_KEY + ); + + // 2. Fetch the price feed info + const nodePrices = await getNodePrices( + { + realmId: 1, + networkCtx: networkConfig, + }, + account + ); + + return { keySet, nodePrices }; }, handshake: { schemas: { diff --git a/packages/networks/src/networks/vNaga/envs/naga-test/chain-manager/createChainManager.ts b/packages/networks/src/networks/vNaga/envs/naga-test/chain-manager/createChainManager.ts index eafcbc1c2d..434cb1c2b5 100644 --- a/packages/networks/src/networks/vNaga/envs/naga-test/chain-manager/createChainManager.ts +++ b/packages/networks/src/networks/vNaga/envs/naga-test/chain-manager/createChainManager.ts @@ -6,6 +6,7 @@ import type { ExpectedAccountOrWalletClient } from '../../../LitChainClient/cont import { DefaultNetworkConfig } from '../../../interfaces/NetworkContext'; import { networkConfig } from '../naga-test.config'; import type { PKPStorageProvider } from '../../../../../storage/types'; +import { DEV_PRIVATE_KEY } from '@lit-protocol/constants'; export type CreateChainManagerReturn = { api: { @@ -111,9 +112,9 @@ export const createChainManager = ( const defaultPagination = { limit: 10, offset: 0 }; const finalPagination = params.pagination ? { - limit: params.pagination.limit ?? defaultPagination.limit, - offset: params.pagination.offset ?? defaultPagination.offset, - } + limit: params.pagination.limit ?? defaultPagination.limit, + offset: params.pagination.offset ?? defaultPagination.offset, + } : defaultPagination; return getPKPsByAddress( @@ -148,7 +149,7 @@ export const createChainManager = ( export const createReadOnlyChainManager = () => { // dummy private key for read actions const dummyAccount = privateKeyToAccount( - '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' + DEV_PRIVATE_KEY ); const chainManager = createChainManager(dummyAccount); return createChainManager(chainManager); diff --git a/packages/networks/src/networks/vNaga/envs/naga-test/naga-test.module.ts b/packages/networks/src/networks/vNaga/envs/naga-test/naga-test.module.ts index cc3f950163..a4a1072c2e 100644 --- a/packages/networks/src/networks/vNaga/envs/naga-test/naga-test.module.ts +++ b/packages/networks/src/networks/vNaga/envs/naga-test/naga-test.module.ts @@ -1,4 +1,4 @@ -import { version } from '@lit-protocol/constants'; +import { DEV_PRIVATE_KEY, version } from '@lit-protocol/constants'; import { verifyAndDecryptWithSignatureShares } from '@lit-protocol/crypto'; import { AuthData, @@ -47,7 +47,10 @@ import type { PKPStorageProvider } from '../../../../storage/types'; import { createRequestId } from '../../../shared/helpers/createRequestId'; import { handleAuthServerRequest } from '../../../shared/helpers/handleAuthServerRequest'; import { composeLitUrl } from '../../endpoints-manager/composeLitUrl'; -import { PKPPermissionsManager } from '../../LitChainClient/apis/highLevelApis'; +import { + getNodePrices, + PKPPermissionsManager, +} from '../../LitChainClient/apis/highLevelApis'; import { PaymentManager } from '../../LitChainClient/apis/highLevelApis/PaymentManager/PaymentManager'; import { MintWithMultiAuthsRequest } from '../../LitChainClient/apis/highLevelApis/mintPKP/mintWithMultiAuths'; import { PkpIdentifierRaw } from '../../LitChainClient/apis/rawContractApis/permissions/utils/resolvePkpTokenId'; @@ -80,6 +83,7 @@ import { } from './chain-manager/createChainManager'; import { getMaxPricesForNodeProduct } from './pricing-manager/getMaxPricesForNodeProduct'; import { getUserMaxPrice } from './pricing-manager/getUserMaxPrice'; +import { privateKeyToAccount } from 'viem/accounts'; const MODULE_NAME = 'naga-test'; @@ -484,6 +488,7 @@ const networkModuleObject = { ): Promise => { const keySet: KeySet = {}; + // 1. Generate a key set for the JIT context for (const url of connectionInfo.bootstrapUrls) { keySet[url] = { publicKey: hexToBytes( @@ -495,7 +500,21 @@ const networkModuleObject = { }; } - return { keySet }; + // Use read-only account for viewing PKPs + const account = privateKeyToAccount( + DEV_PRIVATE_KEY + ); + + // 2. Fetch the price feed info + const nodePrices = await getNodePrices( + { + realmId: 1, + networkCtx: networkConfig, + }, + account + ); + + return { keySet, nodePrices }; }, handshake: { schemas: { diff --git a/packages/networks/src/networks/vNaga/interfaces/NetworkContext.ts b/packages/networks/src/networks/vNaga/interfaces/NetworkContext.ts index d7651e0f42..27c381b93d 100644 --- a/packages/networks/src/networks/vNaga/interfaces/NetworkContext.ts +++ b/packages/networks/src/networks/vNaga/interfaces/NetworkContext.ts @@ -22,6 +22,7 @@ export interface INetworkConfig { }; } +// TODO: we should use a stablised network config as the default network config export type DefaultNetworkConfig = INetworkConfig< typeof localDevSignatures, any diff --git a/packages/types/src/lib/v2types.ts b/packages/types/src/lib/v2types.ts index 064e5ea7e4..cb97d5638b 100644 --- a/packages/types/src/lib/v2types.ts +++ b/packages/types/src/lib/v2types.ts @@ -118,6 +118,13 @@ export type KeySet = Record< { publicKey: Uint8Array; secretKey: Uint8Array } >; +// aka. Network Prices +export type NodePrices = { + url: string; + prices: bigint[]; +}[]; + export type NagaJitContext = { keySet: KeySet; + nodePrices: NodePrices; };