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;