Skip to content

Commit

Permalink
Merge pull request #453 from LIT-Protocol/feature/lit-3100-auth-uni-c…
Browse files Browse the repository at this point in the history
…reate-a-mapping-for-cayenne-port-from-73xx-74xx

feat: cayenne remappings
  • Loading branch information
Ansonhkg authored May 4, 2024
2 parents a8d09d6 + 01274c2 commit cff71ba
Show file tree
Hide file tree
Showing 32 changed files with 395 additions and 84 deletions.
75 changes: 75 additions & 0 deletions local-tests/setup/session-sigs/get-lit-action-session-sigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ const INVALID_SESSION_SIG_LIT_ACTION_CODE = `
})();
`;

/**
* https://cloudflare-ipfs.com/ipfs/QmRf5K7PVi5TWXiJdw7YYtcgpgRY6ufXGr9yYnxBLvLjDp
*/
export const VALID_IPFS_ID = 'QmRf5K7PVi5TWXiJdw7YYtcgpgRY6ufXGr9yYnxBLvLjDp';

/**
* https://cloudflare-ipfs.com/ipfs/QmeUByesskboEkLLcE9Hd3bWFZT5Xt53RSauMNTJSVhfqm
*/
export const INVALID_IPFS_ID = 'QmeUByesskboEkLLcE9Hd3bWFZT5Xt53RSauMNTJSVhfqm';

export const getLitActionSessionSigs = async (
devEnv: TinnyEnvironment,
alice: TinnyPerson,
Expand Down Expand Up @@ -65,6 +75,48 @@ export const getLitActionSessionSigs = async (
return litActionSessionSigs;
};

export const getLitActionSessionSigsUsingIpfsId = async (
devEnv: TinnyEnvironment,
alice: TinnyPerson,
resourceAbilityRequests?: LitResourceAbilityRequest[]
) => {
if (devEnv.litNodeClient.config.litNetwork === LitNetwork.Manzano) {
console.warn(
'Manzano network detected. Adding capacityDelegationAuthSig to litActionSessionSigs'
);
}

// Use default resourceAbilityRequests if not provided
const _resourceAbilityRequests = resourceAbilityRequests || [
{
resource: new LitPKPResource('*'),
ability: LitAbility.PKPSigning,
},
{
resource: new LitActionResource('*'),
ability: LitAbility.LitActionExecution,
},
];

const litActionSessionSigs = await devEnv.litNodeClient.getPkpSessionSigs({
pkpPublicKey: alice.authMethodOwnedPkp.publicKey,
authMethods: [alice.authMethod],
resourceAbilityRequests: _resourceAbilityRequests,
litActionIpfsId: VALID_IPFS_ID,
jsParams: {
publicKey: alice.authMethodOwnedPkp.publicKey,
sigName: 'unified-auth-sig',
},

// -- only add this for manzano network
...(devEnv.litNodeClient.config.litNetwork === LitNetwork.Manzano
? { capacityDelegationAuthSig: devEnv.superCapacityDelegationAuthSig }
: {}),
});

return litActionSessionSigs;
};

export const getInvalidLitActionSessionSigs = async (
devEnv: TinnyEnvironment,
alice: TinnyPerson
Expand All @@ -89,3 +141,26 @@ export const getInvalidLitActionSessionSigs = async (

return litActionSessionSigs;
};

export const getInvalidLitActionIpfsSessionSigs = async (
devEnv: TinnyEnvironment,
alice: TinnyPerson
) => {
const litActionSessionSigs = await devEnv.litNodeClient.getPkpSessionSigs({
pkpPublicKey: alice.authMethodOwnedPkp.publicKey,
authMethods: [alice.authMethod],
resourceAbilityRequests: [
{
resource: new LitPKPResource('*'),
ability: LitAbility.PKPSigning,
},
],
litActionIpfsId: INVALID_IPFS_ID,
jsParams: {
publicKey: alice.authMethodOwnedPkp.publicKey,
sigName: 'unified-auth-sig',
},
});

return litActionSessionSigs;
};
28 changes: 14 additions & 14 deletions local-tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { testUsePkpSessionSigsToExecuteJsSigning } from './tests/testUsePkpSessi
import { testUsePkpSessionSigsToPkpSign } from './tests/testUsePkpSessionSigsToPkpSign';
import { testUseValidLitActionCodeGeneratedSessionSigsToPkpSign } from './tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign';
import { testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning } from './tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning';
import { testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning } from './tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning';
import { testUseEoaSessionSigsToExecuteJsSigningInParallel } from './tests/testUseEoaSessionSigsToExecuteJsSigningInParallel';
import { testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs } from './tests/testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs';
import { testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign } from './tests/testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign';
Expand Down Expand Up @@ -42,26 +43,14 @@ import { testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsJsonResponse }
import { testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsConsoleLog } from './tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsConsoleLog';
import { testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile } from './tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile';
import { testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip } from './tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip';
import { testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign } from './tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign';
import { testUseInvalidLitActionIpfsCodeToGenerateSessionSigs } from './tests/testUseInvalidLitActionIpfsCodeToGenerateSessionSigs';

(async () => {
console.log('[𐬺🧪 Tinny𐬺] Running tests...');
const devEnv = new TinnyEnvironment();
await devEnv.init();

if (LIT_TESTNET.LOCALCHAIN) {
// set global executeJs endpoint version for all tests.
devEnv.setGlobalExecuteJsVersion(
LIT_TESTNET.LOCALCHAIN,
LIT_ENDPOINT_VERSION.V1
);

// set global pkpSign endpoint version for all tests.
devEnv.setGlobalPkpSignVersion(
LIT_TESTNET.LOCALCHAIN,
LIT_ENDPOINT_VERSION.V1
);
}

const eoaSessionSigsTests = {
testUseEoaSessionSigsToExecuteJsSigning,
testUseEoaSessionSigsToPkpSign,
Expand Down Expand Up @@ -99,6 +88,16 @@ import { testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip } from
testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString,
testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile,
testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip,

// -- invalid cases
testUseInvalidLitActionIpfsCodeToGenerateSessionSigs,
};

const litActionIpfsIdSessionSigsTests = {
testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign,
testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning,

// -- invalid cases
testUseInvalidLitActionCodeToGenerateSessionSigs,
};

Expand All @@ -119,6 +118,7 @@ import { testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip } from
...eoaSessionSigsTests,
...pkpSessionSigsTests,
...litActionSessionSigsTests,
...litActionIpfsIdSessionSigsTests,
...capacityDelegationTests,
},
devEnv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import { LIT_TESTNET } from 'local-tests/setup/tinny-config';
export const testDelegatingCapacityCreditsNFTToAnotherPkpToExecuteJs = async (
devEnv: TinnyEnvironment
) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);

const alice = await devEnv.createRandomPerson();
const bob = await devEnv.createRandomPerson();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
*/
export const testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);

const alice = await devEnv.createRandomPerson();
const bob = await devEnv.createRandomPerson();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
export const testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign = async (
devEnv: TinnyEnvironment
) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);

const alice = await devEnv.createRandomPerson();
const bob = await devEnv.createRandomPerson();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
*/
export const testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToExecuteJs =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);

const alice = await devEnv.createRandomPerson();
const bob = await devEnv.createRandomPerson();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
*/
export const testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToPkpSign =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);

const alice = await devEnv.createRandomPerson();
const bob = await devEnv.createRandomPerson();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';

export const testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToExecuteJs =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);

const alice = await devEnv.createRandomPerson();
const bob = await devEnv.createRandomPerson();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';

export const testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToPkpSign =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);
const alice = await devEnv.createRandomPerson();
const bob = await devEnv.createRandomPerson();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { LIT_ENDPOINT_VERSION } from '@lit-protocol/constants';
import { LIT_TESTNET } from 'local-tests/setup/tinny-config';
import { getInvalidLitActionSessionSigs } from 'local-tests/setup/session-sigs/get-lit-action-session-sigs';
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';

/**
* Test Commands:
* ❌ NOT AVAILABLE IN CAYENNE
* ✅ NETWORK=cayenne yarn test:local --filter=testUseInvalidLitActionCodeToGenerateSessionSigs
* ❌ NOT AVAILABLE IN MANZANO
* ✅ NETWORK=localchain yarn test:local --filter=testUseInvalidLitActionCodeToGenerateSessionSigs
*/
export const testUseInvalidLitActionCodeToGenerateSessionSigs = async (
devEnv: TinnyEnvironment
) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);
devEnv.setUnavailable(LIT_TESTNET.MANZANO);

const alice = await devEnv.createRandomPerson();

try {
await getInvalidLitActionSessionSigs(devEnv, alice);
} catch (e: any) {
console.log('❌ This error is expected', e);
if (
e.message ===
'There was an error getting the signing shares from the nodes'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { LIT_ENDPOINT_VERSION } from '@lit-protocol/constants';
import { LIT_TESTNET } from 'local-tests/setup/tinny-config';
import { getInvalidLitActionIpfsSessionSigs } from 'local-tests/setup/session-sigs/get-lit-action-session-sigs';
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';

/**
* Test Commands:
* ✅ NETWORK=cayenne yarn test:local --filter=testUseInvalidLitActionIpfsCodeToGenerateSessionSigs
* ❌ NOT AVAILABLE IN MANZANO
* ✅ NETWORK=localchain yarn test:local --filter=testUseInvalidLitActionIpfsCodeToGenerateSessionSigs
*/
export const testUseInvalidLitActionIpfsCodeToGenerateSessionSigs = async (
devEnv: TinnyEnvironment
) => {
const alice = await devEnv.createRandomPerson();

try {
await getInvalidLitActionIpfsSessionSigs(devEnv, alice);
} catch (e: any) {
console.log('❌ THIS IS EXPECTED: ', e);

if (e.message === 'An error related to validation has occured.') {
console.log(
'✅ testUseInvalidLitActionIpfsCodeToGenerateSessionSigs is expected to have an error'
);
} else {
throw e;
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { getLitActionSessionSigs } from 'local-tests/setup/session-sigs/get-lit-
*/
export const testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);
devEnv.setUnavailable(LIT_TESTNET.MANZANO);
const alice = await devEnv.createRandomPerson();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import { log } from '@lit-protocol/misc';

/**
* Test Commands:
* ❌ NOT AVAILABLE IN CAYENNE
* ✅ NETWORK=cayenne yarn test:local --filter=testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString
* ❌ NOT AVAILABLE IN MANZANO
* ✅ NETWORK=localchain yarn test:local --filter=testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString
*
*/
export const testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);
devEnv.setUnavailable(LIT_TESTNET.MANZANO);

const alice = await devEnv.createRandomPerson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { log } from '@lit-protocol/misc';
*/
export const testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);
devEnv.setUnavailable(LIT_TESTNET.MANZANO);
const alice = await devEnv.createRandomPerson();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
*/
export const testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsClaimKeys =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);
devEnv.setUnavailable(LIT_TESTNET.MANZANO);

const alice = await devEnv.createRandomPerson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
*/
export const testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsClaimMultipleKeys =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);
devEnv.setUnavailable(LIT_TESTNET.MANZANO);

const alice = await devEnv.createRandomPerson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
*/
export const testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsConsoleLog =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);
devEnv.setUnavailable(LIT_TESTNET.MANZANO);

const alice = await devEnv.createRandomPerson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
*/
export const testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsJsonResponse =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);
devEnv.setUnavailable(LIT_TESTNET.MANZANO);

const alice = await devEnv.createRandomPerson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';

/**
* Test Commands:
* ❌ NOT AVAILABLE IN CAYENNE
* ✅ NETWORK=cayenne yarn test:local --filter=testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning
* ❌ NOT AVAILABLE IN HABANERO
* ✅ NETWORK=localchain yarn test:local --filter=testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning
*/
export const testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);
devEnv.setUnavailable(LIT_TESTNET.MANZANO);
//
// devEnv.setUnavailable(LIT_TESTNET.MANZANO);

const alice = await devEnv.createRandomPerson();
const litActionSessionSigs = await getLitActionSessionSigs(devEnv, alice, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';

/**
* Test Commands:
* ❌ Not available in Cayenne
* ✅ NETWORK=cayenne yarn test:local --filter=testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel
* ❌ Not available in Habanero
* ✅ NETWORK=localchain yarn test:local --filter=testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel
*/
export const testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel =
async (devEnv: TinnyEnvironment) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);
devEnv.setUnavailable(LIT_TESTNET.MANZANO);

const alice = await devEnv.createRandomPerson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';

/**
* Test Commands:
* ❌ NOT AVAILABLE IN CAYENNE
* ✅ NETWORK=cayenne yarn test:local --filter=testUseValidLitActionCodeGeneratedSessionSigsToPkpSign
* ❌ NOT AVAILABLE IN HABANERO
* ✅ NETWORK=localchain yarn test:local --filter=testUseValidLitActionCodeGeneratedSessionSigsToPkpSign
*
**/
export const testUseValidLitActionCodeGeneratedSessionSigsToPkpSign = async (
devEnv: TinnyEnvironment
) => {
devEnv.setUnavailable(LIT_TESTNET.CAYENNE);
devEnv.setUnavailable(LIT_TESTNET.MANZANO);

const alice = await devEnv.createRandomPerson();
Expand Down
Loading

0 comments on commit cff71ba

Please sign in to comment.