From 0164e6622492105c6d9f84beb96e420d0a6fbc7e Mon Sep 17 00:00:00 2001 From: Anson Date: Fri, 3 May 2024 16:09:17 +0100 Subject: [PATCH 01/10] feat: cayenne remappings --- .../constants/src/lib/constants/constants.ts | 11 +++++-- packages/core/src/lib/lit-core.ts | 29 +++++++++++++++++-- .../src/lib/lit-node-client-nodejs.ts | 23 ++++++++++++--- packages/misc/src/lib/misc.spec.ts | 11 ++++++- packages/misc/src/lib/misc.ts | 23 +++++++++++++++ 5 files changed, 86 insertions(+), 11 deletions(-) diff --git a/packages/constants/src/lib/constants/constants.ts b/packages/constants/src/lib/constants/constants.ts index 042d6d8c8d..e16e1526e8 100644 --- a/packages/constants/src/lib/constants/constants.ts +++ b/packages/constants/src/lib/constants/constants.ts @@ -729,6 +729,11 @@ export const SYMM_KEY_ALGO_PARAMS = { length: 256, }; +/** + * Default node URL for Cayenne network + */ +export const CAYENNE_URL = 'https://cayenne.litgateway.com'; + /** * Default node URLs for each LIT network * Note: Dynamic networks such as Habanero have no default node URLS; they are always @@ -739,9 +744,9 @@ export const LIT_NETWORKS: { [key in LitNetwork]: string[] } & { internalDev: string[]; } = { [LitNetwork.Cayenne]: [ - 'https://cayenne.litgateway.com:7370', - 'https://cayenne.litgateway.com:7371', - 'https://cayenne.litgateway.com:7372', + `${CAYENNE_URL}:7370'`, + `${CAYENNE_URL}:7371'`, + `${CAYENNE_URL}:7372'`, ], [LitNetwork.Manzano]: [], [LitNetwork.Habanero]: [], diff --git a/packages/core/src/lib/lit-core.ts b/packages/core/src/lib/lit-core.ts index 4176bb87a5..f59e2cd970 100644 --- a/packages/core/src/lib/lit-core.ts +++ b/packages/core/src/lib/lit-core.ts @@ -23,12 +23,14 @@ import { StakingStates, version, LIT_ENDPOINT, + CAYENNE_URL, } from '@lit-protocol/constants'; import { LitContracts } from '@lit-protocol/contracts-sdk'; import { checkSevSnpAttestation, computeHDPubKey } from '@lit-protocol/crypto'; import { bootstrapLogManager, executeWithRetry, + getIpAddress, isBrowser, isNode, log, @@ -259,13 +261,34 @@ export class LitCore { this.config.litNetwork ); + const minNodeCount = ( + await LitContracts.getMinNodeCount(this.config.litNetwork) + ).toNumber(); + + const bootstrapUrls = await LitContracts.getValidators( + this.config.litNetwork + ); + + /** + * FIXME: We need this reformatting because the Cayenne network is not able to handle the node address as a URL. + * from: https://cayenne.litgateway.com + * to: http://207.244.70.36:7474 + */ + const remappedBootstrapUrls = await Promise.all( + bootstrapUrls.map(async (url) => { + const rootDomain = CAYENNE_URL.replace('https://', ''); + const ipAddress = await getIpAddress(rootDomain); + return `http://${ipAddress}:${new URL(url).port}`; + }) + ); + // If the network is cayenne it is a centralized testnet, so we use a static config // This is due to staking contracts holding local ip / port contexts which are innacurate to the ip / port exposed to the world - this.config.bootstrapUrls = LIT_NETWORKS.cayenne; + this.config.bootstrapUrls = remappedBootstrapUrls; this.config.minNodeCount = - LIT_NETWORKS.cayenne.length == 2 + remappedBootstrapUrls.length == 2 ? 2 - : (LIT_NETWORKS.cayenne.length * 2) / 3; + : (remappedBootstrapUrls.length * 2) / 3; /** * Here we are checking if a custom network defined with no node urls (bootstrap urls) defined diff --git a/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts b/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts index c743d1aa9f..0c01bad592 100644 --- a/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts +++ b/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts @@ -2418,10 +2418,25 @@ const resourceAbilityRequests = [ const signatures: SessionSigsMap = {}; this.connectedNodes.forEach((nodeAddress: string) => { - const toSign: SessionSigningTemplate = { - ...signingTemplate, - nodeAddress, - }; + let toSign: SessionSigningTemplate; + + // FIXME: We need this reformatting because the Cayenne network is not able to handle the node address as a URL. + // We are converting back + // from: http://207.244.70.36:7474 + // to: 127.0.0.1:7474 + if (this.config.litNetwork === LitNetwork.Cayenne) { + const url = new URL(nodeAddress); + const newNodeAddress = `127.0.0.1:${url.port}`; + toSign = { + ...signingTemplate, + nodeAddress: newNodeAddress, + }; + } else { + toSign = { + ...signingTemplate, + nodeAddress, + }; + } const signedMessage = JSON.stringify(toSign); diff --git a/packages/misc/src/lib/misc.spec.ts b/packages/misc/src/lib/misc.spec.ts index c4c0870c6d..5cf4edeb09 100644 --- a/packages/misc/src/lib/misc.spec.ts +++ b/packages/misc/src/lib/misc.spec.ts @@ -4,7 +4,7 @@ global.TextEncoder = TextEncoder; // @ts-ignore global.TextDecoder = TextDecoder; -import { LitErrorKind, LIT_ERROR } from '@lit-protocol/constants'; +import { LitErrorKind, LIT_ERROR, CAYENNE_URL } from '@lit-protocol/constants'; import * as utilsModule from './misc'; describe('utils', () => { @@ -288,3 +288,12 @@ it('should not remove hex prefix if it is not present', () => { expect(result).toBe(expectedOutput); }); + +it('should get ip address', async () => { + // polyfill fetch + const fetch = require('node-fetch'); + global.fetch = fetch; + + const ipAddres = await utilsModule.getIpAddress('cayenne.litgateway.com'); + expect(ipAddres).toBe('1'); +}); diff --git a/packages/misc/src/lib/misc.ts b/packages/misc/src/lib/misc.ts index 1456dd4c4b..223ae1df6d 100644 --- a/packages/misc/src/lib/misc.ts +++ b/packages/misc/src/lib/misc.ts @@ -915,3 +915,26 @@ export function normalizeAndStringify(input: string): string { return normalizeAndStringify(unescaped); } } + +/** + * Retrieves the IP address associated with a given domain. + * @param domain - The domain for which to retrieve the IP address. + * @returns A Promise that resolves to the IP address. + * @throws If no IP address is found or if the domain name is invalid. + */ +export async function getIpAddress(domain: string): Promise { + const apiURL = `https://dns.google/resolve?name=${domain}&type=A`; + + try { + const response = await fetch(apiURL); + const data = await response.json(); + + if (data.Answer && data.Answer.length > 0) { + return data.Answer[0].data; + } else { + throw new Error('No IP Address found or bad domain name'); + } + } catch (error: any) { + throw new Error(error); + } +} From d5925ad06dee013912c6206909baf09e6548945d Mon Sep 17 00:00:00 2001 From: Anson Date: Fri, 3 May 2024 18:24:58 +0100 Subject: [PATCH 02/10] chore: add comment --- packages/constants/src/lib/constants/constants.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/constants/src/lib/constants/constants.ts b/packages/constants/src/lib/constants/constants.ts index e16e1526e8..2a534af674 100644 --- a/packages/constants/src/lib/constants/constants.ts +++ b/packages/constants/src/lib/constants/constants.ts @@ -743,6 +743,8 @@ export const LIT_NETWORKS: { [key in LitNetwork]: string[] } & { localhost: string[]; internalDev: string[]; } = { + + // FIXME: Reviewers! These are not used in this branch, scroll down to see remapping logic [LitNetwork.Cayenne]: [ `${CAYENNE_URL}:7370'`, `${CAYENNE_URL}:7371'`, From 45276bd054c1419205b4501906bc28c27015453c Mon Sep 17 00:00:00 2001 From: Anson Date: Fri, 3 May 2024 22:38:36 +0100 Subject: [PATCH 03/10] feat: add litActionIpfsId to param --- .../get-lit-action-session-sigs.ts | 44 ++++++++++ local-tests/test.ts | 4 + ...eGeneratedSessionSigsToExecuteJsSigning.ts | 6 +- ...eGeneratedSessionSigsToExecuteJsSigning.ts | 81 +++++++++++++++++++ ...onIpfsCodeGeneratedSessionSigsToPkpSign.ts | 62 ++++++++++++++ .../src/lib/lit-node-client-nodejs.ts | 3 + packages/types/src/lib/interfaces.ts | 9 ++- 7 files changed, 205 insertions(+), 4 deletions(-) create mode 100644 local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning.ts create mode 100644 local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts diff --git a/local-tests/setup/session-sigs/get-lit-action-session-sigs.ts b/local-tests/setup/session-sigs/get-lit-action-session-sigs.ts index 1ccca73331..4036a5ed05 100644 --- a/local-tests/setup/session-sigs/get-lit-action-session-sigs.ts +++ b/local-tests/setup/session-sigs/get-lit-action-session-sigs.ts @@ -21,6 +21,8 @@ const INVALID_SESSION_SIG_LIT_ACTION_CODE = ` })(); `; +export const VALID_IPFS_ID = 'QmNZQXmY2VijUPfNrkC6zWykBnEniDouAeUpFi9r6aaqNz'; + export const getLitActionSessionSigs = async ( devEnv: TinnyEnvironment, alice: TinnyPerson, @@ -65,6 +67,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 diff --git a/local-tests/test.ts b/local-tests/test.ts index 24afa4b0f2..b709a40eca 100644 --- a/local-tests/test.ts +++ b/local-tests/test.ts @@ -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'; @@ -42,6 +43,7 @@ import { testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsJsonResponse } import { testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsConsoleLog } from './tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsConsoleLog'; import { testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile } from './tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile'; import { testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip } from './tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip'; +import { testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign } from './tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign'; (async () => { console.log('[𐬺πŸ§ͺ Tinny𐬺] Running tests...'); @@ -89,6 +91,8 @@ import { testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip } from }; const litActionSessionSigsTests = { + testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign, + testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning, testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning, testUseValidLitActionCodeGeneratedSessionSigsToPkpSign, testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel, diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning.ts index 345eebf948..f0f11326a4 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning.ts @@ -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.CAYENNE); + // devEnv.setUnavailable(LIT_TESTNET.MANZANO); const alice = await devEnv.createRandomPerson(); const litActionSessionSigs = await getLitActionSessionSigs(devEnv, alice, [ diff --git a/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning.ts b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning.ts new file mode 100644 index 0000000000..8afaf6eafe --- /dev/null +++ b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning.ts @@ -0,0 +1,81 @@ +import { LitActionResource, LitPKPResource } from '@lit-protocol/auth-helpers'; +import { log } from '@lit-protocol/misc'; +import { LitAbility } from '@lit-protocol/types'; +import { getLitActionSessionSigsUsingIpfsId } 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=testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning + * ❌ NOT AVAILABLE IN HABANERO + * βœ… NETWORK=localchain yarn test:local --filter=testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning + */ +export const testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning = + async (devEnv: TinnyEnvironment) => { + const alice = await devEnv.createRandomPerson(); + const litActionSessionSigs = await getLitActionSessionSigsUsingIpfsId( + devEnv, + alice, + [ + { + resource: new LitPKPResource('*'), + ability: LitAbility.PKPSigning, + }, + { + resource: new LitActionResource('*'), + ability: LitAbility.LitActionExecution, + }, + ] + ); + + const res = await devEnv.litNodeClient.executeJs({ + sessionSigs: litActionSessionSigs, + code: `(async () => { + const sigShare = await LitActions.signEcdsa({ + toSign: dataToSign, + publicKey, + sigName: "sig", + }); + })();`, + jsParams: { + dataToSign: alice.loveLetter, + publicKey: alice.authMethodOwnedPkp.publicKey, + }, + }); + + // -- Expected output: + // { + // claims: {}, + // signatures: { + // sig: { + // r: "6d5ce6f948ff763939c204fc0f1b750fa0267ed567ed59581082d0cbf283feef", + // s: "4957ece75c60388500c4b7aa38a5fbafb7c20427db181aff7806af54c16ee145", + // recid: 1, + // signature: "0x6d5ce6f948ff763939c204fc0f1b750fa0267ed567ed59581082d0cbf283feef4957ece75c60388500c4b7aa38a5fbafb7c20427db181aff7806af54c16ee1451c", + // publicKey: "04D10D941B04491FDC99B048E2252A69137333254C482511D6CCDD401C080AF4F51BF65D9AE2413FCE066E326D7F0CED9C139DD9BA2D1C6334FD8C14CA4DD7F3D0", + // dataSigned: "7D87C5EA75F7378BB701E404C50639161AF3EFF66293E9F375B5F17EB50476F4", + // }, + // }, + // decryptions: [], + // response: undefined, + // logs: "", + // } + + // -- assertions + if (!res.signatures.sig.r) { + throw new Error(`Expected "r" in res.signatures.sig`); + } + if (!res.signatures.sig.s) { + throw new Error(`Expected "s" in res.signatures.sig`); + } + + if (!res.signatures.sig.dataSigned) { + throw new Error(`Expected "dataSigned" in res.signatures.sig`); + } + + if (!res.signatures.sig.publicKey) { + throw new Error(`Expected "publicKey" in res.signatures.sig`); + } + + log('βœ… res:', res); + }; diff --git a/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts new file mode 100644 index 0000000000..89b57df1dc --- /dev/null +++ b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts @@ -0,0 +1,62 @@ +import { log } from '@lit-protocol/misc'; +import { getLitActionSessionSigsUsingIpfsId } 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=testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign + * ❌ NOT AVAILABLE IN HABANERO + * βœ… NETWORK=localchain yarn test:local --filter=testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign + * + **/ +export const testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign = + async (devEnv: TinnyEnvironment) => { + const alice = await devEnv.createRandomPerson(); + const litActionSessionSigs = await getLitActionSessionSigsUsingIpfsId( + devEnv, + alice + ); + + const res = await devEnv.litNodeClient.pkpSign({ + toSign: alice.loveLetter, + pubKey: alice.authMethodOwnedPkp.publicKey, + sessionSigs: litActionSessionSigs, + }); + + // -- Expected output: + // { + // r: "ab2cef959db920d56f001c3b05637ee49af4c4441f2867ea067c413594a4c87b", + // s: "4bf11e17b4bb618aa6ed75cbf0406e6babfd953c5b201da697077c5fbf5b542e", + // recid: 1, + // signature: "0xab2cef959db920d56f001c3b05637ee49af4c4441f2867ea067c413594a4c87b4bf11e17b4bb618aa6ed75cbf0406e6babfd953c5b201da697077c5fbf5b542e1c", + // publicKey: "04400AD53C2F8BA11EBC69F05D1076D5BEE4EAE668CD66BABADE2E0770F756FDEEFC2C1D20F9A698EA3FEC6E9C944FF9FAFC2DC339B8E9392AFB9CC8AE75C5E5EC", + // dataSigned: "7D87C5EA75F7378BB701E404C50639161AF3EFF66293E9F375B5F17EB50476F4", + // } + + // -- assertions + // r, s, dataSigned, and public key should be present + if (!res.r) { + throw new Error(`Expected "r" in res`); + } + if (!res.s) { + throw new Error(`Expected "s" in res`); + } + if (!res.dataSigned) { + throw new Error(`Expected "dataSigned" in res`); + } + if (!res.publicKey) { + throw new Error(`Expected "publicKey" in res`); + } + + // signature must start with 0x + if (!res.signature.startsWith('0x')) { + throw new Error(`Expected "signature" to start with 0x`); + } + + // recid must be parseable as a number + if (isNaN(res.recid)) { + throw new Error(`Expected "recid" to be parseable as a number`); + } + + log('βœ… res:', res); + }; diff --git a/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts b/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts index 0c01bad592..c4da901bfd 100644 --- a/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts +++ b/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts @@ -2035,6 +2035,9 @@ export class LitNodeClientNodeJs curveType: LIT_CURVE.BLS, // -- custom auths + ...(params?.litActionIpfsId && { + litActionIpfsId: params.litActionIpfsId, + }), ...(params?.litActionCode && { code: params.litActionCode }), ...(params?.jsParams && { jsParams: params.jsParams }), ...(this.currentEpochNumber && { epoch: this.currentEpochNumber }), diff --git a/packages/types/src/lib/interfaces.ts b/packages/types/src/lib/interfaces.ts index ec807425c1..7e7cc29856 100644 --- a/packages/types/src/lib/interfaces.ts +++ b/packages/types/src/lib/interfaces.ts @@ -292,10 +292,12 @@ export interface JsonSignSessionKeyRequestV1 { // authSig?: AuthSig; siweMessage: string; curveType: 'BLS'; + epoch?: number; + + // custom auth params code?: string; litActionIpfsId?: string; jsParams?: any; - epoch?: number; } // [ @@ -1009,6 +1011,10 @@ export interface SignSessionKeyProp { */ resourceAbilityRequests?: LitResourceAbilityRequest[]; + /** + * The js code on ipfs + */ + litActionIpfsId?: string; /** * The js code to run on the nodes */ @@ -1776,6 +1782,7 @@ export interface SignerLike { export interface GetPkpSessionSigs extends GetSessionSigsProps { pkpPublicKey: string; authMethods: AuthMethod[]; + litActionIpfsId?: string; litActionCode?: string; jsParams?: { publicKey?: string; From c2b6473b388b700c7f2e1896d9ce59e82be72134 Mon Sep 17 00:00:00 2001 From: Anson Date: Sat, 4 May 2024 00:06:43 +0100 Subject: [PATCH 04/10] feat: ipfs session sigs & test cases --- .../get-lit-action-session-sigs.ts | 33 ++++++++++++++++++- local-tests/test.ts | 14 ++++++-- ...validLitActionCodeToGenerateSessionSigs.ts | 2 +- ...dLitActionIpfsCodeToGenerateSessionSigs.ts | 33 +++++++++++++++++++ ...eGeneratedSessionSigsToExecuteJsSigning.ts | 1 + ...onIpfsCodeGeneratedSessionSigsToPkpSign.ts | 17 +++++++--- .../src/lib/lit-node-client-nodejs.ts | 16 +++++---- packages/types/src/lib/interfaces.ts | 6 ++-- 8 files changed, 104 insertions(+), 18 deletions(-) create mode 100644 local-tests/tests/testUseInvalidLitActionIpfsCodeToGenerateSessionSigs.ts diff --git a/local-tests/setup/session-sigs/get-lit-action-session-sigs.ts b/local-tests/setup/session-sigs/get-lit-action-session-sigs.ts index 4036a5ed05..1f7138a133 100644 --- a/local-tests/setup/session-sigs/get-lit-action-session-sigs.ts +++ b/local-tests/setup/session-sigs/get-lit-action-session-sigs.ts @@ -21,7 +21,15 @@ const INVALID_SESSION_SIG_LIT_ACTION_CODE = ` })(); `; -export const VALID_IPFS_ID = 'QmNZQXmY2VijUPfNrkC6zWykBnEniDouAeUpFi9r6aaqNz'; +/** + * https://cloudflare-ipfs.com/ipfs/QmRf5K7PVi5TWXiJdw7YYtcgpgRY6ufXGr9yYnxBLvLjDp + */ +export const VALID_IPFS_ID = 'QmRf5K7PVi5TWXiJdw7YYtcgpgRY6ufXGr9yYnxBLvLjDp'; + +/** + * https://cloudflare-ipfs.com/ipfs/QmR6WDLHvPf6yQwLcCzqJJGXEuXoJGTjdEaF5unXuPSxK9 + */ +export const INVALID_IPFS_ID = 'QmR6WDLHvPf6yQwLcCzqJJGXEuXoJGTjdEaF5unXuPSxK9'; export const getLitActionSessionSigs = async ( devEnv: TinnyEnvironment, @@ -133,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; +}; diff --git a/local-tests/test.ts b/local-tests/test.ts index b709a40eca..a589f46a85 100644 --- a/local-tests/test.ts +++ b/local-tests/test.ts @@ -44,6 +44,7 @@ import { testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsConsoleLog } fr 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...'); @@ -91,8 +92,6 @@ import { testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign } from './te }; const litActionSessionSigsTests = { - testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign, - testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning, testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning, testUseValidLitActionCodeGeneratedSessionSigsToPkpSign, testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel, @@ -103,6 +102,16 @@ import { testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign } from './te testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString, testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile, testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip, + + // -- invalid cases + testUseInvalidLitActionIpfsCodeToGenerateSessionSigs, + }; + + const litActionIpfsIdSessionSigsTests = { + testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign, + testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning, + + // -- invalid cases testUseInvalidLitActionCodeToGenerateSessionSigs, }; @@ -123,6 +132,7 @@ import { testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign } from './te ...eoaSessionSigsTests, ...pkpSessionSigsTests, ...litActionSessionSigsTests, + ...litActionIpfsIdSessionSigsTests, ...capacityDelegationTests, }, devEnv, diff --git a/local-tests/tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts b/local-tests/tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts index 791b64047e..9fa7098585 100644 --- a/local-tests/tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts +++ b/local-tests/tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts @@ -1,4 +1,3 @@ -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'; @@ -20,6 +19,7 @@ export const testUseInvalidLitActionCodeToGenerateSessionSigs = async ( 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' diff --git a/local-tests/tests/testUseInvalidLitActionIpfsCodeToGenerateSessionSigs.ts b/local-tests/tests/testUseInvalidLitActionIpfsCodeToGenerateSessionSigs.ts new file mode 100644 index 0000000000..174ca5f137 --- /dev/null +++ b/local-tests/tests/testUseInvalidLitActionIpfsCodeToGenerateSessionSigs.ts @@ -0,0 +1,33 @@ +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 === + 'There was an error getting the signing shares from the nodes.' + ) { + console.log( + 'βœ… testUseInvalidLitActionIpfsCodeToGenerateSessionSigs is expected to have an error' + ); + } else { + throw e; + } + } +}; diff --git a/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning.ts b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning.ts index 8afaf6eafe..ef8516f5ad 100644 --- a/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning.ts +++ b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning.ts @@ -42,6 +42,7 @@ export const testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning publicKey: alice.authMethodOwnedPkp.publicKey, }, }); + console.log('βœ… res:', res); // -- Expected output: // { diff --git a/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts index 89b57df1dc..2658da354d 100644 --- a/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts +++ b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts @@ -12,10 +12,17 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; export const testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign = async (devEnv: TinnyEnvironment) => { const alice = await devEnv.createRandomPerson(); - const litActionSessionSigs = await getLitActionSessionSigsUsingIpfsId( - devEnv, - alice - ); + let litActionSessionSigs; + + try { + litActionSessionSigs = await getLitActionSessionSigsUsingIpfsId( + devEnv, + alice + ); + } catch (e: any) { + console.log('❌ This error is NOT expected:', e); + throw new Error(e); + } const res = await devEnv.litNodeClient.pkpSign({ toSign: alice.loveLetter, @@ -23,6 +30,8 @@ export const testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign = sessionSigs: litActionSessionSigs, }); + console.log("βœ… res:", res); + // -- Expected output: // { // r: "ab2cef959db920d56f001c3b05637ee49af4c4441f2867ea067c413594a4c87b", diff --git a/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts b/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts index c4da901bfd..a68df33d7d 100644 --- a/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts +++ b/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts @@ -335,7 +335,7 @@ export class LitNodeClientNodeJs nonce, resourceAbilityRequests, litActionCode, - ipfsId, + litActionIpfsId, jsParams, sessionKey, }: GetWalletSigProps): Promise => { @@ -383,7 +383,7 @@ export class LitNodeClientNodeJs // for lit action custom auth ...(litActionCode && { litActionCode }), - ...(ipfsId && { ipfsId }), + ...(litActionIpfsId && { litActionIpfsId }), ...(jsParams && { jsParams }), }; @@ -2350,7 +2350,9 @@ const resourceAbilityRequests = [ // -- optional fields ...(params.litActionCode && { litActionCode: params.litActionCode }), - ...(params.ipfsId && { ipfsId: params.ipfsId }), + ...(params.litActionIpfsId && { + litActionIpfsId: params.litActionIpfsId, + }), ...(params.jsParams && { jsParams: params.jsParams }), }); @@ -2498,9 +2500,9 @@ const resourceAbilityRequests = [ } // lit action code and ipfs id cannot exist at the same time - if (props.litActionCode && props.ipfsId) { + if (props.litActionCode && props.litActionIpfsId) { throw new Error( - '[getPkpSessionSigs/callback]litActionCode and ipfsId cannot exist at the same time' + '[getPkpSessionSigs/callback]litActionCode and litActionIpfsId cannot exist at the same time' ); } @@ -2518,7 +2520,9 @@ const resourceAbilityRequests = [ // -- optional fields ...(props.litActionCode && { litActionCode: props.litActionCode }), - ...(props.ipfsId && { ipfsId: props.ipfsId }), + ...(props.litActionIpfsId && { + litActionIpfsId: props.litActionIpfsId, + }), ...(props.jsParams && { jsParams: props.jsParams }), }); diff --git a/packages/types/src/lib/interfaces.ts b/packages/types/src/lib/interfaces.ts index 7e7cc29856..ef8f605ca3 100644 --- a/packages/types/src/lib/interfaces.ts +++ b/packages/types/src/lib/interfaces.ts @@ -93,7 +93,7 @@ export interface AuthCallbackParams { resourceAbilityRequests?: LitResourceAbilityRequest[]; litActionCode?: string; - ipfsId?: string; + litActionIpfsId?: string; jsParams?: any; } @@ -1754,7 +1754,7 @@ export interface CapacityCreditsRes { export interface LitCustomAuth { litActionCode?: string; - ipfsId?: string; + litActionIpfsId?: string; jsParams?: { publicKey?: string; sigName?: string; @@ -1782,8 +1782,6 @@ export interface SignerLike { export interface GetPkpSessionSigs extends GetSessionSigsProps { pkpPublicKey: string; authMethods: AuthMethod[]; - litActionIpfsId?: string; - litActionCode?: string; jsParams?: { publicKey?: string; sigName?: string; From a90298ee9c2c7618f3157e35a22fddf8d06958d3 Mon Sep 17 00:00:00 2001 From: Anson Date: Sat, 4 May 2024 00:08:43 +0100 Subject: [PATCH 05/10] feat: turn on testings on cayenne! --- .../testDelegatingCapacityCreditsNFTToAnotherPkpToExecuteJs.ts | 2 -- ...estDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs.ts | 2 -- .../testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign.ts | 2 -- ...elegationAuthSigWithUnspecifiedCapacityTokenIdToExecuteJs.ts | 2 -- ...yDelegationAuthSigWithUnspecifiedCapacityTokenIdToPkpSign.ts | 2 -- ...cityDelegationAuthSigWithUnspecifiedDelegateesToExecuteJs.ts | 2 -- ...pacityDelegationAuthSigWithUnspecifiedDelegateesToPkpSign.ts | 1 - .../tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts | 1 - ...alidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile.ts | 1 - ...idLitActionCodeGeneratedSessionSigsToEncryptDecryptString.ts | 1 - ...ValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip.ts | 1 - ...alidLitActionCodeGeneratedSessionSigsToExecuteJsClaimKeys.ts | 1 - ...ctionCodeGeneratedSessionSigsToExecuteJsClaimMultipleKeys.ts | 1 - ...lidLitActionCodeGeneratedSessionSigsToExecuteJsConsoleLog.ts | 1 - ...dLitActionCodeGeneratedSessionSigsToExecuteJsJsonResponse.ts | 1 - ...eValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning.ts | 2 +- ...ctionCodeGeneratedSessionSigsToExecuteJsSigningInParallel.ts | 1 - .../testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts | 1 - ...estUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts | 2 +- 19 files changed, 2 insertions(+), 25 deletions(-) diff --git a/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherPkpToExecuteJs.ts b/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherPkpToExecuteJs.ts index f8de798aa5..d1fe134e45 100644 --- a/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherPkpToExecuteJs.ts +++ b/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherPkpToExecuteJs.ts @@ -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(); diff --git a/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs.ts b/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs.ts index b3b7bc0a15..46ba42a016 100644 --- a/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs.ts +++ b/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs.ts @@ -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(); diff --git a/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign.ts b/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign.ts index 00b0f4984b..ac5f308db0 100644 --- a/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign.ts +++ b/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign.ts @@ -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(); diff --git a/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToExecuteJs.ts b/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToExecuteJs.ts index 16c45d1590..1d85764098 100644 --- a/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToExecuteJs.ts +++ b/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToExecuteJs.ts @@ -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(); diff --git a/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToPkpSign.ts b/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToPkpSign.ts index 4abccce37e..fd7b22c0f7 100644 --- a/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToPkpSign.ts +++ b/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToPkpSign.ts @@ -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(); diff --git a/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToExecuteJs.ts b/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToExecuteJs.ts index f98f9e7592..d552915556 100644 --- a/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToExecuteJs.ts +++ b/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToExecuteJs.ts @@ -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(); diff --git a/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToPkpSign.ts b/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToPkpSign.ts index c319e809e5..11f0c05550 100644 --- a/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToPkpSign.ts +++ b/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToPkpSign.ts @@ -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(); diff --git a/local-tests/tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts b/local-tests/tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts index 9fa7098585..b188da7393 100644 --- a/local-tests/tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts +++ b/local-tests/tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts @@ -11,7 +11,6 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; export const testUseInvalidLitActionCodeToGenerateSessionSigs = async ( devEnv: TinnyEnvironment ) => { - devEnv.setUnavailable(LIT_TESTNET.CAYENNE); devEnv.setUnavailable(LIT_TESTNET.MANZANO); const alice = await devEnv.createRandomPerson(); diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile.ts index 30d4da72e8..e0ca8deb25 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile.ts @@ -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(); diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString.ts index fde1ce5e39..34c27fde7c 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString.ts @@ -16,7 +16,6 @@ import { log } from '@lit-protocol/misc'; */ export const testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString = async (devEnv: TinnyEnvironment) => { - devEnv.setUnavailable(LIT_TESTNET.CAYENNE); devEnv.setUnavailable(LIT_TESTNET.MANZANO); const alice = await devEnv.createRandomPerson(); diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip.ts index 1e2576865d..78aeb6c844 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptZip.ts @@ -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(); diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsClaimKeys.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsClaimKeys.ts index 0606cac29b..daa4d78d24 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsClaimKeys.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsClaimKeys.ts @@ -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(); diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsClaimMultipleKeys.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsClaimMultipleKeys.ts index 4244e3be5e..1c5c77916f 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsClaimMultipleKeys.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsClaimMultipleKeys.ts @@ -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(); diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsConsoleLog.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsConsoleLog.ts index c358f22d61..86d6f93371 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsConsoleLog.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsConsoleLog.ts @@ -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(); diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsJsonResponse.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsJsonResponse.ts index 5c968800f1..e61e3f78a7 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsJsonResponse.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsJsonResponse.ts @@ -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(); diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning.ts index f0f11326a4..b611e71804 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning.ts @@ -14,7 +14,7 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; */ export const testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning = async (devEnv: TinnyEnvironment) => { - // devEnv.setUnavailable(LIT_TESTNET.CAYENNE); + // // devEnv.setUnavailable(LIT_TESTNET.MANZANO); const alice = await devEnv.createRandomPerson(); diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel.ts index fbe8766817..47f23fe038 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel.ts @@ -12,7 +12,6 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; */ export const testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel = async (devEnv: TinnyEnvironment) => { - devEnv.setUnavailable(LIT_TESTNET.CAYENNE); devEnv.setUnavailable(LIT_TESTNET.MANZANO); const alice = await devEnv.createRandomPerson(); diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts index 9ec3c85bf9..042056f072 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts @@ -16,7 +16,6 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; export const testUseValidLitActionCodeGeneratedSessionSigsToPkpSign = async ( devEnv: TinnyEnvironment ) => { - devEnv.setUnavailable(LIT_TESTNET.CAYENNE); devEnv.setUnavailable(LIT_TESTNET.MANZANO); const alice = await devEnv.createRandomPerson(); diff --git a/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts index 2658da354d..93171186a8 100644 --- a/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts +++ b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts @@ -30,7 +30,7 @@ export const testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign = sessionSigs: litActionSessionSigs, }); - console.log("βœ… res:", res); + console.log('βœ… res:', res); // -- Expected output: // { From 6b27dc135deab5cfe0b3b7cc1e073e99ea146837 Mon Sep 17 00:00:00 2001 From: Anson Date: Sat, 4 May 2024 00:23:01 +0100 Subject: [PATCH 06/10] feat: update cayenne tests --- .../session-sigs/get-lit-action-session-sigs.ts | 4 ++-- local-tests/test.ts | 14 -------------- ...nvalidLitActionIpfsCodeToGenerateSessionSigs.ts | 5 +---- ...tActionIpfsCodeGeneratedSessionSigsToPkpSign.ts | 2 +- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/local-tests/setup/session-sigs/get-lit-action-session-sigs.ts b/local-tests/setup/session-sigs/get-lit-action-session-sigs.ts index 1f7138a133..baf05b96ce 100644 --- a/local-tests/setup/session-sigs/get-lit-action-session-sigs.ts +++ b/local-tests/setup/session-sigs/get-lit-action-session-sigs.ts @@ -27,9 +27,9 @@ const INVALID_SESSION_SIG_LIT_ACTION_CODE = ` export const VALID_IPFS_ID = 'QmRf5K7PVi5TWXiJdw7YYtcgpgRY6ufXGr9yYnxBLvLjDp'; /** - * https://cloudflare-ipfs.com/ipfs/QmR6WDLHvPf6yQwLcCzqJJGXEuXoJGTjdEaF5unXuPSxK9 + * https://cloudflare-ipfs.com/ipfs/QmeUByesskboEkLLcE9Hd3bWFZT5Xt53RSauMNTJSVhfqm */ -export const INVALID_IPFS_ID = 'QmR6WDLHvPf6yQwLcCzqJJGXEuXoJGTjdEaF5unXuPSxK9'; +export const INVALID_IPFS_ID = 'QmeUByesskboEkLLcE9Hd3bWFZT5Xt53RSauMNTJSVhfqm'; export const getLitActionSessionSigs = async ( devEnv: TinnyEnvironment, diff --git a/local-tests/test.ts b/local-tests/test.ts index a589f46a85..ed1277049e 100644 --- a/local-tests/test.ts +++ b/local-tests/test.ts @@ -51,20 +51,6 @@ import { testUseInvalidLitActionIpfsCodeToGenerateSessionSigs } from './tests/te 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, diff --git a/local-tests/tests/testUseInvalidLitActionIpfsCodeToGenerateSessionSigs.ts b/local-tests/tests/testUseInvalidLitActionIpfsCodeToGenerateSessionSigs.ts index 174ca5f137..4243a1cf90 100644 --- a/local-tests/tests/testUseInvalidLitActionIpfsCodeToGenerateSessionSigs.ts +++ b/local-tests/tests/testUseInvalidLitActionIpfsCodeToGenerateSessionSigs.ts @@ -19,10 +19,7 @@ export const testUseInvalidLitActionIpfsCodeToGenerateSessionSigs = async ( } catch (e: any) { console.log('❌ THIS IS EXPECTED: ', e); - if ( - e.message === - 'There was an error getting the signing shares from the nodes.' - ) { + if (e.message === 'An error related to validation has occured.') { console.log( 'βœ… testUseInvalidLitActionIpfsCodeToGenerateSessionSigs is expected to have an error' ); diff --git a/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts index 93171186a8..1ed4405d4f 100644 --- a/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts +++ b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts @@ -6,7 +6,7 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; * Test Commands: * βœ… NETWORK=cayenne yarn test:local --filter=testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign * ❌ NOT AVAILABLE IN HABANERO - * βœ… NETWORK=localchain yarn test:local --filter=testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign + * ❌ NETWORK=localchain yarn test:local --filter=testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign * **/ export const testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign = From 32c739879db09b697bfd061d1f3e323c3d680c5c Mon Sep 17 00:00:00 2001 From: Anson Date: Sat, 4 May 2024 00:26:25 +0100 Subject: [PATCH 07/10] feat: remove version override --- packages/core/src/lib/endpoint-version.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/core/src/lib/endpoint-version.ts b/packages/core/src/lib/endpoint-version.ts index f2d1381b79..41bbb31c07 100644 --- a/packages/core/src/lib/endpoint-version.ts +++ b/packages/core/src/lib/endpoint-version.ts @@ -21,16 +21,7 @@ export const composeLitUrl = (params: { throw new Error(`[composeLitUrl] Invalid URL: "${params.url}"`); } - let versionOverride: string | undefined = undefined; - - // Get the version override for a particular endpoint - // FIXME: We will remove this completly once v0.1 is deployed to all public networks - if (isNode()) { - versionOverride = process.env[`${params.endpoint.envName}`] || undefined; - } - - // Use the overridden version if it exists, otherwise use the default - const version = versionOverride || params.endpoint.version; + const version = params.endpoint.version; return `${params.url}${params.endpoint.path}${version}`; }; From a98760c89abe7f0515f0eafc26d63a8ca95f4def Mon Sep 17 00:00:00 2001 From: Anson Date: Sat, 4 May 2024 01:10:53 +0100 Subject: [PATCH 08/10] fix: jsdocs --- .../tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts | 2 +- ...idLitActionCodeGeneratedSessionSigsToEncryptDecryptString.ts | 2 +- ...ctionCodeGeneratedSessionSigsToExecuteJsSigningInParallel.ts | 2 +- .../testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/local-tests/tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts b/local-tests/tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts index b188da7393..537ad25408 100644 --- a/local-tests/tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts +++ b/local-tests/tests/testUseInvalidLitActionCodeToGenerateSessionSigs.ts @@ -4,7 +4,7 @@ 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 */ diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString.ts index 34c27fde7c..6828e8b596 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptString.ts @@ -9,7 +9,7 @@ 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 * diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel.ts index 47f23fe038..2249b5f01a 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigningInParallel.ts @@ -6,7 +6,7 @@ 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 */ diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts index 042056f072..2a46a2821e 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts @@ -8,7 +8,7 @@ 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 * From a4dd28ffc4386d64e2fbc6de19ab08e0ca7bc82d Mon Sep 17 00:00:00 2001 From: Anson Date: Sat, 4 May 2024 02:33:57 +0100 Subject: [PATCH 09/10] fix: browser global undefined see #416 #452 --- packages/auth-browser/src/lib/chains/eth.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/auth-browser/src/lib/chains/eth.ts b/packages/auth-browser/src/lib/chains/eth.ts index 3e66c6f79f..67946c7879 100644 --- a/packages/auth-browser/src/lib/chains/eth.ts +++ b/packages/auth-browser/src/lib/chains/eth.ts @@ -42,10 +42,6 @@ import { } from '@lit-protocol/misc'; import { getStorageItem } from '@lit-protocol/misc-browser'; -if (global && typeof global.Buffer === 'undefined') { - global.Buffer = BufferPolyfill; -} - if (globalThis && typeof globalThis.Buffer === 'undefined') { globalThis.Buffer = BufferPolyfill; } From 01274c2cb961e154b3b95719397492a814d001bd Mon Sep 17 00:00:00 2001 From: Anson Date: Sat, 4 May 2024 03:13:14 +0100 Subject: [PATCH 10/10] feat: add tslib as dependency --- packages/auth-helpers/package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/auth-helpers/package.json b/packages/auth-helpers/package.json index 300f3f80c2..0212f2312f 100644 --- a/packages/auth-helpers/package.json +++ b/packages/auth-helpers/package.json @@ -17,8 +17,8 @@ "access": "public", "directory": "../../dist/packages/auth-helpers" }, - "peerDependencies": { - "tslib": "^2.3.0" + "dependencies": { + "tslib": "2.6.0" }, "gitHead": "0d7334c2c55f448e91fe32f29edc5db8f5e09e4b", "tags": [ @@ -28,7 +28,7 @@ "crypto": false, "stream": false }, - "version": "6.0.0-alpha.1", + "version": "6.0.0-alpha.11", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +}