diff --git a/local-tests/test.ts b/local-tests/test.ts index 751782294a..431460344b 100644 --- a/local-tests/test.ts +++ b/local-tests/test.ts @@ -107,6 +107,7 @@ import { testSignTransactionWithSolanaEncryptedKey } from './tests/wrapped-keys/ import { testBatchGeneratePrivateKeys } from './tests/wrapped-keys/testBatchGeneratePrivateKeys'; import { setLitActionsCodeToLocal } from './tests/wrapped-keys/util'; +import { testUseEoaSessionSigsToRequestSingleResponse } from './tests/testUseEoaSessionSigsToRequestSingleResponse'; // Use the current LIT action code to test against setLitActionsCodeToLocal(); @@ -170,6 +171,7 @@ setLitActionsCodeToLocal(); testUseEoaSessionSigsToEncryptDecryptString, testUseEoaSessionSigsToEncryptDecryptFile, testUseEoaSessionSigsToEncryptDecryptZip, + testUseEoaSessionSigsToRequestSingleResponse, }; const pkpSessionSigsTests = { diff --git a/local-tests/tests/testUseEoaSessionSigsToRequestSingleResponse.ts b/local-tests/tests/testUseEoaSessionSigsToRequestSingleResponse.ts new file mode 100644 index 0000000000..c2b10f4ac7 --- /dev/null +++ b/local-tests/tests/testUseEoaSessionSigsToRequestSingleResponse.ts @@ -0,0 +1,56 @@ +import { getEoaSessionSigs } from 'local-tests/setup/session-sigs/get-eoa-session-sigs'; +import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; + +/** + * Test Commands: + * ✅ NETWORK=datil-dev yarn test:local --filter=testUseEoaSessionSigsToRequestSingleResponse + * ✅ NETWORK=datil-test yarn test:local --filter=testUseEoaSessionSigsToRequestSingleResponse + * ✅ NETWORK=datil yarn test:local --filter=testUseEoaSessionSigsToRequestSingleResponse + */ +export const testUseEoaSessionSigsToRequestSingleResponse = async ( + devEnv: TinnyEnvironment +) => { + const alice = await devEnv.createRandomPerson(); + + try { + const eoaSessionSigs = await getEoaSessionSigs(devEnv, alice); + + const res = await devEnv.litNodeClient.executeJs({ + sessionSigs: eoaSessionSigs, + code: `(async () => { + console.log('hello world') + })();`, + numResponsesRequired: 1, + }); + } finally { + devEnv.releasePrivateKeyFromUser(alice); + } + console.log('res:', res); + + // Expected output: + // { + // success: true, + // signedData: {}, + // decryptedData: {}, + // claimData: {}, + // response: "", + // logs: "hello world\n", + // } + + // -- assertions + if (res.response) { + throw new Error(`Expected "response" to be falsy`); + } + + if (!res.logs) { + throw new Error(`Expected "logs" in res`); + } + + if (!res.logs.includes('hello world')) { + throw new Error(`Expected "logs" to include 'hello world'`); + } + + if (!res.success) { + throw new Error(`Expected "success" in res`); + } +}; diff --git a/local-tests/tests/wrapped-keys/testBatchGeneratePrivateKeys.ts b/local-tests/tests/wrapped-keys/testBatchGeneratePrivateKeys.ts index ece325ef85..335698e7da 100644 --- a/local-tests/tests/wrapped-keys/testBatchGeneratePrivateKeys.ts +++ b/local-tests/tests/wrapped-keys/testBatchGeneratePrivateKeys.ts @@ -93,7 +93,6 @@ export const testBatchGeneratePrivateKeys = async ( const solanaMessageToSign = 'This is a test solana message'; const evmMessageToSign = 'This is a test evm message'; - const results = await batchGeneratePrivateKeys({ const { results } = await batchGeneratePrivateKeys({ pkpSessionSigs: pkpSessionSigsSigning, actions: [ diff --git a/packages/lit-node-client-nodejs/src/lib/helpers/get-signatures.ts b/packages/lit-node-client-nodejs/src/lib/helpers/get-signatures.ts index 4d25dc265f..0ecab7084e 100644 --- a/packages/lit-node-client-nodejs/src/lib/helpers/get-signatures.ts +++ b/packages/lit-node-client-nodejs/src/lib/helpers/get-signatures.ts @@ -146,7 +146,7 @@ export const getSignatures = (params: { if (allKeys.length !== initialKeys.length) { throwError({ - message: 'total number of valid signatures does not match requested', + message: `Total number of valid signatures does not match requested. Valid signatures: ${allKeys.length}, Requested signatures: ${initialKeys.length}`, errorKind: LIT_ERROR.NO_VALID_SHARES.kind, errorCode: LIT_ERROR.NO_VALID_SHARES.code, }); 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 e654174890..8733aed671 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 @@ -1098,7 +1098,7 @@ export class LitNodeClientNodeJs const res = await this.handleNodePromises( nodePromises, requestId, - this.connectedNodes.size + params.numResponsesRequired || this.connectedNodes.size ); // -- case: promises rejected @@ -1162,7 +1162,7 @@ export class LitNodeClientNodeJs const signatures = getSignatures({ requestId, networkPubKeySet: this.networkPubKeySet, - minNodeCount: this.config.minNodeCount, + minNodeCount: params.numResponsesRequired || this.config.minNodeCount, signedData: signedDataList, }); diff --git a/packages/types/src/lib/interfaces.ts b/packages/types/src/lib/interfaces.ts index d2a5f865ff..b626bd708f 100644 --- a/packages/types/src/lib/interfaces.ts +++ b/packages/types/src/lib/interfaces.ts @@ -502,7 +502,8 @@ export interface JsonExecutionSdkParamsTargetNode } export interface JsonExecutionSdkParams - extends Pick { + extends Pick, + ExecuteJsAdvancedOptions { /** * JS code to run on the nodes */ @@ -522,14 +523,29 @@ export interface JsonExecutionSdkParams * auth methods to resolve */ authMethods?: AuthMethod[]; +} +export interface ExecuteJsAdvancedOptions { /** * a strategy for proccessing `reponse` objects returned from the * Lit Action execution context */ responseStrategy?: LitActionResponseStrategy; + /** + * Allow overriding the default `code` property in the `JsonExecutionSdkParams` + */ ipfsOptions?: IpfsOptions; + + /** + * number of responses required to consider the execution successful + */ + numResponsesRequired?: number; + + /** + * idea: the number of nodes to pay for running executions + */ + // numNodesToRunOn?: number; } export interface JsonExecutionRequestTargetNode extends JsonExecutionRequest { @@ -687,7 +703,7 @@ export interface SigShare { bigr?: string; // backward compatibility bigR?: string; publicKey: string; - dataSigned?: string; + dataSigned?: string | 'fail'; siweMessage?: string; sigName?: string; } @@ -704,6 +720,8 @@ export interface PkpSignedData { export interface NodeShare { claimData: any; shareIndex: any; + + // I think this is deprecated unsignedJwt: any; signedData: SigShare; decryptedData: any;