diff --git a/.env.ci b/.env.ci index a07d05981..322cb68e0 100644 --- a/.env.ci +++ b/.env.ci @@ -10,7 +10,7 @@ NO_SETUP=false USE_SHIVA=true NETWORK_CONFIG=./networkContext.json TEST_TIMEOUT=45000 - +USE_STORAGE=false #Shiva Client ENV Vars STOP_TESTNET=false TESTNET_MANAGER_URL=http://127.0.0.1:8000 diff --git a/local-tests/setup/tinny-config.ts b/local-tests/setup/tinny-config.ts index 8ebf01319..94e976314 100644 --- a/local-tests/setup/tinny-config.ts +++ b/local-tests/setup/tinny-config.ts @@ -123,6 +123,10 @@ export interface ProcessEnvs { * this value will be ignored */ NETWORK_CONFIG: string; + + STORAGE_CACHE: string; + + USE_STORAGE: boolean; } /** diff --git a/local-tests/setup/tinny-environment.ts b/local-tests/setup/tinny-environment.ts index 50c2c5552..0fdbe57b2 100644 --- a/local-tests/setup/tinny-environment.ts +++ b/local-tests/setup/tinny-environment.ts @@ -20,6 +20,7 @@ import { createSiweMessage, generateAuthSig } from '@lit-protocol/auth-helpers'; import { ShivaClient, TestnetClient } from './shiva-client'; import { toErrorWithMessage } from './tinny-utils'; import { CENTRALISATION_BY_NETWORK } from '@lit-protocol/constants'; +import { LocalStorage } from 'node-localstorage'; console.log('checking env', process.env['DEBUG']); export class TinnyEnvironment { @@ -76,6 +77,9 @@ export class TinnyEnvironment { NO_SETUP: process.env['NO_SETUP'] === 'true', USE_SHIVA: process.env['USE_SHIVA'] === 'true', NETWORK_CONFIG: process.env['NETWORK_CONFIG'] ?? './networkContext.json', + + STORAGE_CACHE: process.env['STORAGE_CACHE'] ?? './storage', + USE_STORAGE: process.env['USE_STORAGE'] === 'true', }; public litNodeClient: LitNodeClient; @@ -240,6 +244,11 @@ export class TinnyEnvironment { this?.testnet?.ContractContext ?? this._contractContext; this.litNodeClient = new LitNodeClient({ litNetwork: 'custom', + storageProvider: { + provider: this.processEnvs.USE_STORAGE + ? new LocalStorage(this.processEnvs.STORAGE_CACHE) + : undefined, + }, rpcUrl: this.rpc, debug: this.processEnvs.DEBUG, checkNodeAttestation: false, // disable node attestation check for local testing @@ -249,12 +258,22 @@ export class TinnyEnvironment { this.litNodeClient = new LitNodeClient({ litNetwork: this.network, checkNodeAttestation: true, + storageProvider: { + provider: this.processEnvs.USE_STORAGE + ? new LocalStorage(this.processEnvs.STORAGE_CACHE) + : undefined, + }, debug: this.processEnvs.DEBUG, }); } else if (centralisation === 'centralised') { this.litNodeClient = new LitNodeClient({ litNetwork: this.network, checkNodeAttestation: false, + storageProvider: { + provider: this.processEnvs.USE_STORAGE + ? new LocalStorage(this.processEnvs.STORAGE_CACHE) + : undefined, + }, debug: this.processEnvs.DEBUG, }); } else { diff --git a/local-tests/setup/tinny-operations.ts b/local-tests/setup/tinny-operations.ts index c0f70aceb..a5f843210 100644 --- a/local-tests/setup/tinny-operations.ts +++ b/local-tests/setup/tinny-operations.ts @@ -85,9 +85,11 @@ export const runInBand = async ({ console.error( `${testName} - Failed after ${maxAttempts} attempts (${timeTaken} ms)` ); - console.error(`Error: ${error}`); + console.error( + `Error: ${error.message}\nStack Trace: ${error.stackTrace}` + ); failedTests.push( - `${testName} (Failed in ${timeTaken} ms) - Error: ${error}` + `${testName} (Failed in ${timeTaken} ms) - Error: ${error.message}` ); } } diff --git a/local-tests/test.ts b/local-tests/test.ts index c66998d30..ce99337ae 100644 --- a/local-tests/test.ts +++ b/local-tests/test.ts @@ -113,6 +113,8 @@ import { testUseEoaSessionSigsToRequestSingleResponse } from './tests/testUseEoa // Use the current LIT action code to test against setLitActionsCodeToLocal(); +import { testPkpSessionSigsIsValidAfterEllapsedTime } from './tests/testPkpSessionSigsIsValidAfterEllapsedTime'; + (async () => { console.log('[𐬺🧪 Tinny𐬺] Running tests...'); const devEnv = new TinnyEnvironment(); @@ -187,6 +189,7 @@ setLitActionsCodeToLocal(); testUsePkpSessionSigsToEncryptDecryptString, testUsePkpSessionSigsToEncryptDecryptFile, testUsePkpSessionSigsToEncryptDecryptZip, + testPkpSessionSigsIsValidAfterEllapsedTime, }; const litActionSessionSigsTests = { diff --git a/local-tests/tests/testPkpSessionSigsIsValidAfterEllapsedTime.ts b/local-tests/tests/testPkpSessionSigsIsValidAfterEllapsedTime.ts new file mode 100644 index 000000000..b1a26f994 --- /dev/null +++ b/local-tests/tests/testPkpSessionSigsIsValidAfterEllapsedTime.ts @@ -0,0 +1,64 @@ +import { LIT_ENDPOINT_VERSION } from '@lit-protocol/constants'; +import { log, validateSessionSigs } from '@lit-protocol/misc'; +import { LIT_TESTNET } from 'local-tests/setup/tinny-config'; +import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; +import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; +import { + LitAbility, + LitActionResource, + LitPKPResource, +} from '@lit-protocol/auth-helpers'; + +/** + * Test Commands: + * ✅ NETWORK=cayenne yarn test:local --filter=testUsePkpSessionSigsToPkpSign + * ✅ NETWORK=manzano yarn test:local --filter=testUsePkpSessionSigsToPkpSign + * ✅ NETWORK=localchain yarn test:local --filter=testUsePkpSessionSigsToPkpSign + */ +export const testPkpSessionSigsIsValidAfterEllapsedTime = async ( + devEnv: TinnyEnvironment +) => { + const alice = await devEnv.createRandomPerson(); + + let pkpSessionSigs = await getPkpSessionSigs( + devEnv, + alice, + [ + { + resource: new LitPKPResource('*'), + ability: LitAbility.PKPSigning, + }, + { + resource: new LitActionResource('*'), + ability: LitAbility.LitActionExecution, + }, + ], + new Date(Date.now() + 1000).toISOString() + ); + await new Promise((res, rej) => { + setTimeout(res, 2000); + }); + + let res = validateSessionSigs(pkpSessionSigs); + + if (res.isValid) { + throw new Error( + 'Session signature validation should fail with expiration ellapsed' + ); + } + console.log(res); + try { + const res = await devEnv.litNodeClient.pkpSign({ + toSign: alice.loveLetter, + pubKey: alice.authMethodOwnedPkp.publicKey, + sessionSigs: pkpSessionSigs, + }); + } catch (e) { + console.log( + '✅ Session validation failed as expected: error is ', + e.message + ); + } + + devEnv.releasePrivateKeyFromUser(alice); +};