Skip to content
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

add local storage provider option and test for expired sesson signature #672

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.ci
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NO_SETUP=false
USE_SHIVA=true
NETWORK_CONFIG=./networkContext.json
TEST_TIMEOUT=45000

USE_STORAGE=true
#Shiva Client ENV Vars
STOP_TESTNET=false
TESTNET_MANAGER_URL=http://127.0.0.1:8000
Expand Down
4 changes: 4 additions & 0 deletions local-tests/setup/tinny-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export interface ProcessEnvs {
* this value will be ignored
*/
NETWORK_CONFIG: string;

STORAGE_CACHE: string;

USE_STORAGE: boolean;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions local-tests/setup/tinny-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -241,6 +245,9 @@ 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
Expand All @@ -250,12 +257,18 @@ 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 {
Expand Down
4 changes: 2 additions & 2 deletions local-tests/setup/tinny-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ 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}`
);
}
}
Expand Down
3 changes: 3 additions & 0 deletions local-tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ import { testExportWrappedKey } from './tests/wrapped-keys/testExportWrappedKey'
import { testSignMessageWithSolanaEncryptedKey } from './tests/wrapped-keys/testSignMessageWithSolanaEncryptedKey';
import { testSignTransactionWithSolanaEncryptedKey } from './tests/wrapped-keys/testSignTransactionWithSolanaEncryptedKey';

import {testPkpSessionSigsIsValidAfterEllapsedTime} from './tests/testPkpSessionSigsIsValidAfterEllapsedTime';

(async () => {
console.log('[𐬺🧪 Tinny𐬺] Running tests...');
const devEnv = new TinnyEnvironment();
Expand Down Expand Up @@ -176,6 +178,7 @@ import { testSignTransactionWithSolanaEncryptedKey } from './tests/wrapped-keys/
testUsePkpSessionSigsToEncryptDecryptString,
testUsePkpSessionSigsToEncryptDecryptFile,
testUsePkpSessionSigsToEncryptDecryptZip,
testPkpSessionSigsIsValidAfterEllapsedTime
};

const litActionSessionSigsTests = {
Expand Down
47 changes: 47 additions & 0 deletions local-tests/tests/testPkpSessionSigsIsValidAfterEllapsedTime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { LIT_ENDPOINT_VERSION } from '@lit-protocol/constants';
import { log } 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();

const 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);
});

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);
};
Loading