Skip to content

Commit 06e6606

Browse files
committed
feat(networks): add naga-test networks (attestation last checked failed, will need to test again)
1 parent 26d8eab commit 06e6606

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+14539
-8
lines changed

bun.lock

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "@lit-protocol/js-sdk",
66
"dependencies": {
77
"@dotenvx/dotenvx": "^1.6.4",
8-
"@lit-protocol/contracts": "^0.1.32",
8+
"@lit-protocol/contracts": "^0.1.33",
99
"@lit-protocol/nacl": "7.1.1",
1010
"@lit-protocol/uint8arrays": "7.1.1",
1111
"@metamask/eth-sig-util": "5.0.2",
@@ -203,7 +203,7 @@
203203
},
204204
"packages/lit-client": {
205205
"name": "@lit-protocol/lit-client",
206-
"version": "8.0.0-alpha.15",
206+
"version": "8.0.0-alpha.17",
207207
"dependencies": {
208208
"@lit-protocol/uint8arrays": "7.1.1",
209209
"bs58": "^6.0.0",
@@ -220,7 +220,7 @@
220220
},
221221
"packages/networks": {
222222
"name": "@lit-protocol/networks",
223-
"version": "8.0.0-alpha.19",
223+
"version": "8.0.0-alpha.21",
224224
"dependencies": {
225225
"@lit-protocol/contracts": "^0.1.32",
226226
"@lit-protocol/nacl": "7.1.1",
@@ -1078,7 +1078,7 @@
10781078

10791079
"@lit-protocol/constants": ["@lit-protocol/constants@workspace:packages/constants"],
10801080

1081-
"@lit-protocol/contracts": ["@lit-protocol/[email protected].32", "", { "peerDependencies": { "typescript": "^5.0.0" } }, "sha512-JiYZlN3ujJjTLBFaLU9HP7DOmPPSPMR1VkC9tJXtMGproPXgKncqSJB5Lvj0/aQF5bCIxKV8TQXPd+lPaDwm8A=="],
1081+
"@lit-protocol/contracts": ["@lit-protocol/[email protected].33", "", { "peerDependencies": { "typescript": "^5.0.0" } }, "sha512-L8jpgkCbrCW0l4fsGSd4YmsY8pbtqlDaTc6l9F9uwwSajTp0mjoT8AgwvPifnbLzB6TyHp56/ltKOgImXYZCMA=="],
10821082

10831083
"@lit-protocol/crypto": ["@lit-protocol/crypto@workspace:packages/crypto"],
10841084

@@ -5016,6 +5016,8 @@
50165016

50175017
"@lit-protocol/nacl/tslib": ["[email protected]", "", {}, "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="],
50185018

5019+
"@lit-protocol/networks/@lit-protocol/contracts": ["@lit-protocol/[email protected]", "", { "peerDependencies": { "typescript": "^5.0.0" } }, "sha512-JiYZlN3ujJjTLBFaLU9HP7DOmPPSPMR1VkC9tJXtMGproPXgKncqSJB5Lvj0/aQF5bCIxKV8TQXPd+lPaDwm8A=="],
5020+
50195021
"@lit-protocol/uint8arrays/@lit-protocol/constants": ["@lit-protocol/[email protected]", "", { "dependencies": { "@ethersproject/abstract-provider": "5.7.0", "@lit-protocol/accs-schemas": "^0.0.24", "@lit-protocol/contracts": "^0.0.74", "@lit-protocol/types": "7.1.1", "@openagenda/verror": "^3.1.4", "depd": "^2.0.0", "ethers": "^5.7.1", "siwe": "^2.3.2", "tslib": "1.14.1" } }, "sha512-wJY5r8D0FdvtkQtcjx5JfPC3Qeb5SZ1m72HTcvJdqaJaBgaPP4eg2JSUg9uNJ+knOCyfdiBPl47XlWTGqe1X4Q=="],
50205022

50215023
"@lit-protocol/uint8arrays/@lit-protocol/contracts": ["@lit-protocol/[email protected]", "", { "peerDependencies": { "typescript": "^5.0.0" } }, "sha512-8uV038gzBp7ew7a4884SVt9Zhu8CtiTb+A8dKNnByxVoT1kFt4O4DmsaniV8p9AGjNR13IWfpU1NFChmPHVIpQ=="],

e2e/src/init.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { fundAccount } from './helper/fundAccount';
1111

1212
const SupportedNetworkSchema = z.enum([
1313
'naga-dev',
14+
'naga-test',
1415
'naga-local',
1516
'naga-staging',
1617
]);
@@ -83,6 +84,13 @@ export const init = async (
8384
ifLessThan: '0.01',
8485
thenFundWith: '0.01',
8586
});
87+
} else if (_network === 'naga-test') {
88+
const { nagaTest } = await import('@lit-protocol/networks');
89+
_networkModule = nagaTest;
90+
await fundAccount(aliceViemAccount, liveMasterAccount, _networkModule, {
91+
ifLessThan: '0.01',
92+
thenFundWith: '0.01',
93+
});
8694
} else if (_network === 'naga-local') {
8795
const { nagaLocal } = await import('@lit-protocol/networks');
8896
_networkModule = nagaLocal;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"private": true,
3535
"dependencies": {
3636
"@dotenvx/dotenvx": "^1.6.4",
37-
"@lit-protocol/contracts": "^0.1.32",
37+
"@lit-protocol/contracts": "^0.1.33",
3838
"@lit-protocol/nacl": "7.1.1",
3939
"@lit-protocol/uint8arrays": "7.1.1",
4040
"@metamask/eth-sig-util": "5.0.2",

packages/networks/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
// import { NagaDevModule } from './networks/vNaga/envs/naga-rc-naga-2025-04-04/naga-dev.module';
22
import type { NagaLocalModule } from './networks/vNaga';
33
import type { NagaDevModule } from './networks/vNaga';
4+
import type { NagaTestModule } from './networks/vNaga';
45
import type { NagaStagingModule } from './networks/vNaga';
56

67
// Network modules
78
export {
89
// nagaDev,
9-
// nagaTest,
1010
// naga,
1111
nagaStaging,
1212
nagaLocal,
1313
nagaDev,
14+
nagaTest,
1415
} from './networks/vNaga';
1516

1617
// Network module types
1718
export type { NagaLocalModule } from './networks/vNaga';
1819
export type { NagaDevModule } from './networks/vNaga';
20+
export type { NagaTestModule } from './networks/vNaga';
1921
export type { NagaStagingModule } from './networks/vNaga';
2022

2123
// All Network modules
2224
export type LitNetworkModule =
2325
| NagaLocalModule
2426
| NagaDevModule
27+
| NagaTestModule
2528
| NagaStagingModule;
26-
// | NagaDevModule;
27-
// | NagaTestModule
2829
// | NagaProdModule
2930
// | NagaLocalModule
3031
// | DatilDevModule
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { ConnectionInfo } from '../../../../LitChainClient/types';
2+
import type { z } from 'zod';
3+
import type { PricingContextSchema } from '../../pricing-manager/PricingContextSchema';
4+
import { PKPAuthContextSchema, EoaAuthContextSchema } from '@lit-protocol/schemas';
5+
import type { NagaJitContext } from '@lit-protocol/types';
6+
7+
export type DecryptCreateRequestParams = {
8+
pricingContext: z.input<typeof PricingContextSchema>;
9+
authContext: z.input<typeof PKPAuthContextSchema | typeof EoaAuthContextSchema>;
10+
ciphertext: string;
11+
dataToEncryptHash: string;
12+
accessControlConditions?: any;
13+
evmContractConditions?: any;
14+
solRpcConditions?: any;
15+
unifiedAccessControlConditions?: any;
16+
connectionInfo: ConnectionInfo;
17+
version: string;
18+
chain: string;
19+
jitContext: NagaJitContext;
20+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { z } from 'zod';
2+
import { DecryptRequestSchema } from '@lit-protocol/schemas';
3+
4+
export const DecryptInputSchema = DecryptRequestSchema;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { z } from 'zod';
2+
import { MultipleAccessControlConditionsSchema } from '@lit-protocol/access-control-conditions-schemas';
3+
import { AuthSigSchema } from '@lit-protocol/schemas';
4+
5+
export const DecryptRequestDataSchema = MultipleAccessControlConditionsSchema.extend({
6+
ciphertext: z.string(),
7+
dataToEncryptHash: z.string(),
8+
authSig: AuthSigSchema,
9+
chain: z.string(),
10+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { z } from 'zod';
2+
3+
export const DecryptResponseDataSchema = z.object({
4+
signatureShare: z.object({
5+
ProofOfPossession: z.object({
6+
identifier: z.string(),
7+
value: z.string(),
8+
}),
9+
}),
10+
shareId: z.string(),
11+
// Keep backward compatibility fields
12+
share_id: z.string().optional(),
13+
signature_share: z.string().optional(),
14+
});
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
import { walletDecrypt, walletEncrypt } from '@lit-protocol/crypto';
2+
import { getChildLogger } from '@lit-protocol/logger';
3+
import { NagaJitContext } from '@lit-protocol/types';
4+
import { bytesToHex, stringToBytes } from 'viem';
5+
import { z } from 'zod';
6+
import {
7+
EncryptedVersion1Schema,
8+
GenericEncryptedPayloadSchema,
9+
} from '@lit-protocol/schemas';
10+
11+
const _logger = getChildLogger({
12+
module: 'E2EERequestManager',
13+
});
14+
15+
/**
16+
* Generic function to encrypt request data using JIT context
17+
* @param requestData The request data to encrypt
18+
* @param url The node URL to encrypt for
19+
* @param jitContext The JIT context containing key mappings
20+
* @returns Encrypted payload ready to send to the node
21+
*/
22+
const encryptRequestData = (
23+
requestData: any,
24+
url: string,
25+
jitContext: NagaJitContext
26+
): z.infer<typeof EncryptedVersion1Schema> => {
27+
if (!jitContext.keySet[url]) {
28+
throw new Error(`No encryption keys found for node URL: ${url}`);
29+
}
30+
31+
return walletEncrypt(
32+
jitContext.keySet[url].secretKey, // client secret key
33+
jitContext.keySet[url].publicKey, // node public key
34+
stringToBytes(JSON.stringify(requestData))
35+
);
36+
};
37+
38+
/**
39+
* Generic function to decrypt batch responses using JIT context
40+
* @param encryptedResult The encrypted batch result from nodes
41+
* @param jitContext The JIT context containing key mappings
42+
* @param extractResponseData Function to extract actual response data from decrypted content
43+
* @returns Array of decrypted response values
44+
*/
45+
const decryptBatchResponse = <T>(
46+
encryptedResult: z.infer<typeof GenericEncryptedPayloadSchema>,
47+
jitContext: NagaJitContext,
48+
extractResponseData: (decryptedJson: any) => T
49+
): T[] => {
50+
const parsedResult = GenericEncryptedPayloadSchema.parse(encryptedResult);
51+
52+
if (!parsedResult.success) {
53+
throw new Error(`Batch decryption failed: ${JSON.stringify(parsedResult)}`);
54+
}
55+
56+
const decryptedValues: T[] = [];
57+
58+
// Create a reverse mapping: nodePublicKey -> client secret key
59+
const verificationKeyToSecretKey: Record<
60+
string,
61+
{ url: string; secretKey: Uint8Array }
62+
> = {};
63+
64+
for (const url of Object.keys(jitContext.keySet)) {
65+
// Convert the stored node public key (Uint8Array) to hex string without 0x prefix
66+
const nodePublicKeyHex = bytesToHex(
67+
jitContext.keySet[url].publicKey
68+
).replace('0x', '');
69+
verificationKeyToSecretKey[nodePublicKeyHex] = {
70+
url,
71+
secretKey: jitContext.keySet[url].secretKey,
72+
};
73+
}
74+
75+
// Decrypt each encrypted payload
76+
for (let i = 0; i < parsedResult.values.length; i++) {
77+
const encryptedResponse = parsedResult.values[i];
78+
const verificationKey = encryptedResponse.payload.verification_key;
79+
80+
// Find the correct secret key for this response based on verification key
81+
const keyData = verificationKeyToSecretKey[verificationKey];
82+
83+
if (!keyData) {
84+
throw new Error(
85+
`No secret key found for verification key: ${verificationKey}`
86+
);
87+
}
88+
89+
try {
90+
const encryptedPayload: z.infer<typeof EncryptedVersion1Schema> = {
91+
version: encryptedResponse.version,
92+
payload: encryptedResponse.payload,
93+
};
94+
95+
const decrypted = walletDecrypt(keyData.secretKey, encryptedPayload);
96+
97+
// Parse the decrypted content
98+
const decryptedText = new TextDecoder().decode(decrypted);
99+
const parsedData = JSON.parse(decryptedText);
100+
101+
// Extract the actual response data using the provided function
102+
const responseData = extractResponseData(parsedData);
103+
decryptedValues.push(responseData);
104+
} catch (decryptError) {
105+
const errorMessage =
106+
decryptError instanceof Error ? decryptError.message : 'Unknown error';
107+
throw new Error(
108+
`Failed to decrypt response ${i} with key from ${keyData.url}: ${errorMessage}`
109+
);
110+
}
111+
}
112+
113+
if (decryptedValues.length === 0) {
114+
throw new Error('No responses were successfully decrypted');
115+
}
116+
117+
return decryptedValues;
118+
};
119+
120+
const handleEncryptedError = (
121+
errorResult: any,
122+
jitContext: NagaJitContext,
123+
operationName: string
124+
): never => {
125+
if (errorResult.error && errorResult.error.payload) {
126+
// Try to decrypt the error payload to get the actual error message
127+
try {
128+
_logger.info(
129+
`${operationName}: Attempting to decrypt error payload for detailed error information...`
130+
);
131+
132+
const errorAsEncryptedPayload = {
133+
success: true, // Fake success so the decryption can proceed
134+
values: [errorResult.error], // Wrap the error payload as if it's a successful response
135+
};
136+
137+
const decryptedErrorValues = decryptBatchResponse(
138+
errorAsEncryptedPayload as z.infer<
139+
typeof GenericEncryptedPayloadSchema
140+
>,
141+
jitContext,
142+
(decryptedJson) => {
143+
return decryptedJson.data || decryptedJson; // Return whatever we can get
144+
}
145+
);
146+
147+
_logger.error(
148+
`${operationName}: Decrypted error details from nodes:`,
149+
decryptedErrorValues
150+
);
151+
152+
// Use the actual error message from the nodes
153+
const firstError = decryptedErrorValues[0];
154+
if (firstError && firstError.error) {
155+
const errorMessage = firstError.error;
156+
const errorDetails = firstError.errorObject
157+
? `. Details: ${firstError.errorObject}`
158+
: '';
159+
throw new Error(
160+
`${operationName} failed. ${errorMessage}${errorDetails}`
161+
);
162+
}
163+
164+
// If no specific error field, show the full decrypted response
165+
throw new Error(
166+
`${operationName} failed. ${JSON.stringify(decryptedErrorValues)}`
167+
);
168+
} catch (decryptError) {
169+
_logger.error(
170+
`${operationName}: Failed to decrypt error payload:`,
171+
decryptError
172+
);
173+
174+
// If the decryptError is actually our thrown error with the node's message, re-throw it
175+
if (
176+
decryptError instanceof Error &&
177+
decryptError.message.includes(`${operationName} failed.`)
178+
) {
179+
throw decryptError;
180+
}
181+
182+
throw new Error(
183+
`${operationName} failed. The nodes returned an encrypted error response that could not be decrypted. ` +
184+
`This may indicate a configuration or network connectivity issue.`
185+
);
186+
}
187+
} else {
188+
throw new Error(`${operationName} failed with no error details provided`);
189+
}
190+
};
191+
192+
export const E2EERequestManager = {
193+
encryptRequestData,
194+
decryptBatchResponse,
195+
handleEncryptedError,
196+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {
2+
PKPAuthContextSchema,
3+
EoaAuthContextSchema,
4+
} from '@lit-protocol/schemas';
5+
import { LitActionResponseStrategy, NagaJitContext } from '@lit-protocol/types';
6+
import { z } from 'zod';
7+
import { PricingContextSchema } from '../../pricing-manager/PricingContextSchema';
8+
import { ConnectionInfo } from '../../../../LitChainClient/types';
9+
10+
export type ExecuteJsCreateRequestParams = {
11+
pricingContext: z.input<typeof PricingContextSchema>;
12+
authContext: z.input<
13+
typeof PKPAuthContextSchema | typeof EoaAuthContextSchema
14+
>;
15+
executionContext: {
16+
code?: string;
17+
ipfsId?: string;
18+
jsParams?: Record<string, any>;
19+
};
20+
connectionInfo: ConnectionInfo;
21+
version: string;
22+
useSingleNode?: boolean;
23+
responseStrategy?: LitActionResponseStrategy;
24+
jitContext: NagaJitContext;
25+
};

0 commit comments

Comments
 (0)