Skip to content

Commit 29fa617

Browse files
Merge pull request #677 from LIT-Protocol/feature/lit-3945-js-sdk-add-sendtosinglenode-feature
Feature/lit 3945 js sdk add sendtosinglenode feature
2 parents 98e1796 + 22e291e commit 29fa617

File tree

5 files changed

+81
-5
lines changed

5 files changed

+81
-5
lines changed

local-tests/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ import { testSignTransactionWithSolanaEncryptedKey } from './tests/wrapped-keys/
107107
import { testBatchGeneratePrivateKeys } from './tests/wrapped-keys/testBatchGeneratePrivateKeys';
108108

109109
import { setLitActionsCodeToLocal } from './tests/wrapped-keys/util';
110+
import { testUseEoaSessionSigsToRequestSingleResponse } from './tests/testUseEoaSessionSigsToRequestSingleResponse';
110111

111112
// Use the current LIT action code to test against
112113
setLitActionsCodeToLocal();
@@ -170,6 +171,7 @@ setLitActionsCodeToLocal();
170171
testUseEoaSessionSigsToEncryptDecryptString,
171172
testUseEoaSessionSigsToEncryptDecryptFile,
172173
testUseEoaSessionSigsToEncryptDecryptZip,
174+
testUseEoaSessionSigsToRequestSingleResponse,
173175
};
174176

175177
const pkpSessionSigsTests = {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { getEoaSessionSigs } from 'local-tests/setup/session-sigs/get-eoa-session-sigs';
2+
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
3+
4+
/**
5+
* Test Commands:
6+
* ✅ NETWORK=datil-dev yarn test:local --filter=testUseEoaSessionSigsToRequestSingleResponse
7+
* ✅ NETWORK=datil-test yarn test:local --filter=testUseEoaSessionSigsToRequestSingleResponse
8+
* ✅ NETWORK=datil yarn test:local --filter=testUseEoaSessionSigsToRequestSingleResponse
9+
*/
10+
export const testUseEoaSessionSigsToRequestSingleResponse = async (
11+
devEnv: TinnyEnvironment
12+
) => {
13+
const alice = await devEnv.createRandomPerson();
14+
15+
try {
16+
const eoaSessionSigs = await getEoaSessionSigs(devEnv, alice);
17+
18+
const res = await devEnv.litNodeClient.executeJs({
19+
sessionSigs: eoaSessionSigs,
20+
code: `(async () => {
21+
console.log('hello world')
22+
})();`,
23+
numResponsesRequired: 1,
24+
});
25+
} finally {
26+
devEnv.releasePrivateKeyFromUser(alice);
27+
}
28+
console.log('res:', res);
29+
30+
// Expected output:
31+
// {
32+
// success: true,
33+
// signedData: {},
34+
// decryptedData: {},
35+
// claimData: {},
36+
// response: "",
37+
// logs: "hello world\n",
38+
// }
39+
40+
// -- assertions
41+
if (res.response) {
42+
throw new Error(`Expected "response" to be falsy`);
43+
}
44+
45+
if (!res.logs) {
46+
throw new Error(`Expected "logs" in res`);
47+
}
48+
49+
if (!res.logs.includes('hello world')) {
50+
throw new Error(`Expected "logs" to include 'hello world'`);
51+
}
52+
53+
if (!res.success) {
54+
throw new Error(`Expected "success" in res`);
55+
}
56+
};

packages/lit-node-client-nodejs/src/lib/helpers/get-signatures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export const getSignatures = <T>(params: {
146146

147147
if (allKeys.length !== initialKeys.length) {
148148
throwError({
149-
message: 'total number of valid signatures does not match requested',
149+
message: `Total number of valid signatures does not match requested. Valid signatures: ${allKeys.length}, Requested signatures: ${initialKeys.length}`,
150150
errorKind: LIT_ERROR.NO_VALID_SHARES.kind,
151151
errorCode: LIT_ERROR.NO_VALID_SHARES.code,
152152
});

packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ export class LitNodeClientNodeJs
10981098
const res = await this.handleNodePromises(
10991099
nodePromises,
11001100
requestId,
1101-
this.connectedNodes.size
1101+
params.numResponsesRequired || this.connectedNodes.size
11021102
);
11031103

11041104
// -- case: promises rejected
@@ -1162,7 +1162,7 @@ export class LitNodeClientNodeJs
11621162
const signatures = getSignatures({
11631163
requestId,
11641164
networkPubKeySet: this.networkPubKeySet,
1165-
minNodeCount: this.config.minNodeCount,
1165+
minNodeCount: params.numResponsesRequired || this.config.minNodeCount,
11661166
signedData: signedDataList,
11671167
});
11681168

packages/types/src/lib/interfaces.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ export interface JsonExecutionSdkParamsTargetNode
502502
}
503503

504504
export interface JsonExecutionSdkParams
505-
extends Pick<LitActionSdkParams, 'jsParams'> {
505+
extends Pick<LitActionSdkParams, 'jsParams'>,
506+
ExecuteJsAdvancedOptions {
506507
/**
507508
* JS code to run on the nodes
508509
*/
@@ -522,14 +523,29 @@ export interface JsonExecutionSdkParams
522523
* auth methods to resolve
523524
*/
524525
authMethods?: AuthMethod[];
526+
}
525527

528+
export interface ExecuteJsAdvancedOptions {
526529
/**
527530
* a strategy for proccessing `reponse` objects returned from the
528531
* Lit Action execution context
529532
*/
530533
responseStrategy?: LitActionResponseStrategy;
531534

535+
/**
536+
* Allow overriding the default `code` property in the `JsonExecutionSdkParams`
537+
*/
532538
ipfsOptions?: IpfsOptions;
539+
540+
/**
541+
* number of responses required to consider the execution successful
542+
*/
543+
numResponsesRequired?: number;
544+
545+
/**
546+
* idea: the number of nodes to pay for running executions
547+
*/
548+
// numNodesToRunOn?: number;
533549
}
534550

535551
export interface JsonExecutionRequestTargetNode extends JsonExecutionRequest {
@@ -687,7 +703,7 @@ export interface SigShare {
687703
bigr?: string; // backward compatibility
688704
bigR?: string;
689705
publicKey: string;
690-
dataSigned?: string;
706+
dataSigned?: string | 'fail';
691707
siweMessage?: string;
692708
sigName?: string;
693709
}
@@ -704,6 +720,8 @@ export interface PkpSignedData {
704720
export interface NodeShare {
705721
claimData: any;
706722
shareIndex: any;
723+
724+
// I think this is deprecated
707725
unsignedJwt: any;
708726
signedData: SigShare;
709727
decryptedData: any;

0 commit comments

Comments
 (0)