From 9c4077b6facd91ebb78f2cec3a8a58ec84e44dc8 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 30 Apr 2024 15:48:40 +0100 Subject: [PATCH 01/16] fix: https://github.com/LIT-Protocol/js-sdk/pull/440#discussion_r1583772635 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit decriptedFile: Uint8Array(11) [ 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100 ] ✔ 1. testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile - Passed (5459.23 ms) --- ...dLitActionCodeGeneratedSessionSigsToEncryptDecryptFile.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile.ts index 2b3f765f8c..1ab330cabf 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile.ts @@ -6,6 +6,7 @@ import { LitAccessControlConditionResource } from '@lit-protocol/auth-helpers'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; import { log } from '@lit-protocol/misc'; +import { getLitActionSessionSigs } from 'local-tests/setup/session-sigs/get-lit-action-session-sigs'; /** * Test Commands: @@ -28,13 +29,13 @@ export const testUseValidLitActionCodeGeneratedSessionSigsToEncryptDecryptFile = userAddress: alice.authMethodOwnedPkp.ethAddress, }); - const pkpSessionSigs = await getPkpSessionSigs(devEnv, alice); + const litActionSessionSigs = await getLitActionSessionSigs(devEnv, alice); const encryptRes = await LitJsSdk.encryptString( { accessControlConditions: accs, chain: 'ethereum', - sessionSigs: pkpSessionSigs, + sessionSigs: litActionSessionSigs, dataToEncrypt: 'Hello world', }, devEnv.litNodeClient as unknown as ILitNodeClient From e01e07628aa5fc778fa6926d87431831688ec8fd Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 30 Apr 2024 15:55:39 +0100 Subject: [PATCH 02/16] fix: only BLS https://github.com/LIT-Protocol/js-sdk/pull/440#discussion_r1583793731 --- packages/types/src/lib/interfaces.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/types/src/lib/interfaces.ts b/packages/types/src/lib/interfaces.ts index 8ffafc8abd..8c98f5d542 100644 --- a/packages/types/src/lib/interfaces.ts +++ b/packages/types/src/lib/interfaces.ts @@ -315,7 +315,7 @@ export interface JsonSignSessionKeyRequestV1 { pkpPublicKey?: string; authSig?: AuthSig; siweMessage: string; - curveType: 'BLS' | 'ECDSA'; + curveType: 'BLS'; code?: string; litActionIpfsId?: string; jsParams?: any; From bcad173c3abf5a61e16517456a55c6995fd8363a Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 30 Apr 2024 16:21:53 +0100 Subject: [PATCH 03/16] fix: https://github.com/LIT-Protocol/js-sdk/pull/440#discussion_r1583794540 --- .../lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts | 1 - 1 file changed, 1 deletion(-) 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 54f77b9d0e..cb38ec80f5 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 @@ -2520,7 +2520,6 @@ export class LitNodeClientNodeJs sessionKey: sessionKeyUri, authMethods: params.authMethods, ...(params?.pkpPublicKey && { pkpPublicKey: params.pkpPublicKey }), - ...(params?.authSig && { authSig: params.authSig }), siweMessage: siweMessage, curveType: LIT_CURVE.BLS, From 451e0e77fcd23e96879b83cf5b55b773d20cb79e Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 30 Apr 2024 16:22:57 +0100 Subject: [PATCH 04/16] fix: https://github.com/LIT-Protocol/js-sdk/pull/440#discussion_r1583794866 --- .../lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cb38ec80f5..611750b753 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 @@ -702,7 +702,7 @@ export class LitNodeClientNodeJs throw new Error('authSig or sessionSig is required'); } const data: JsExecutionRequestBody = { - ...(authSig ? { authSig } : {}), + authSig, ...(code ? { code } : {}), ...(ipfsId ? { ipfsId } : {}), ...(authMethods ? { authMethods } : {}), From d428bad579f01511a106851bda5b6eb6f1dea589 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 30 Apr 2024 16:25:41 +0100 Subject: [PATCH 05/16] chore: added note https://github.com/LIT-Protocol/js-sdk/pull/440#discussion_r1583795896 --- packages/types/src/lib/interfaces.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/types/src/lib/interfaces.ts b/packages/types/src/lib/interfaces.ts index 8c98f5d542..46f1d72cec 100644 --- a/packages/types/src/lib/interfaces.ts +++ b/packages/types/src/lib/interfaces.ts @@ -244,6 +244,11 @@ export interface BaseJsonExecutionRequest { authMethods?: AuthMethod[]; } +/** + * FIXME: We should create a separate interface for JsExecutionRequestBody + * a body that the SDK accepts, and another one the node actually accepts. + * + */ export interface WithAuthSig extends BaseJsonExecutionRequest { authSig: AuthSig; sessionSigs?: any; @@ -257,7 +262,7 @@ export interface WithSessionSigs extends BaseJsonExecutionRequest { export type JsonExecutionRequest = WithAuthSig | WithSessionSigs; export interface JsExecutionRequestBody { - authSig?: AuthSig; + authSig: AuthSig; code?: string; ipfsId?: string; authMethods?: AuthMethod[]; @@ -313,7 +318,6 @@ export interface JsonSignSessionKeyRequestV1 { sessionKey: string; authMethods: AuthMethod[]; pkpPublicKey?: string; - authSig?: AuthSig; siweMessage: string; curveType: 'BLS'; code?: string; From eaf014b147458c8368ae6d1dcdefbee209fbda8b Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 29 Apr 2024 15:20:01 +0100 Subject: [PATCH 06/16] fix: improve readability --- .../src/lib/providers/BaseProvider.ts | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/packages/lit-auth-client/src/lib/providers/BaseProvider.ts b/packages/lit-auth-client/src/lib/providers/BaseProvider.ts index f4f2b84eef..d898c3d3b5 100644 --- a/packages/lit-auth-client/src/lib/providers/BaseProvider.ts +++ b/packages/lit-auth-client/src/lib/providers/BaseProvider.ts @@ -161,40 +161,43 @@ export abstract class BaseProvider { let response: SignSessionKeyResponse; + // common data for the signSessionKey function call + const commonData = { + sessionKey: params.sessionSigsParams.sessionKey, + statement: authCallbackParams.statement, + pkpPublicKey: params.pkpPublicKey, + expiration: authCallbackParams.expiration, + resources: authCallbackParams.resources, + chainId: chainId, + ...(params.resourceAbilityRequests && { + resourceAbilityRequests: params.resourceAbilityRequests, + }), + }; + + // prepare auth-specific data based on the authentication method + let authSpecificData = {}; + if (params.authMethod.authMethodType === AuthMethodType.EthWallet) { - const authSig = JSON.parse(params.authMethod.accessToken); - response = await nodeClient.signSessionKey({ - statement: authCallbackParams.statement, - sessionKey: params.sessionSigsParams.sessionKey, + authSpecificData = { + authSig: JSON.parse(params.authMethod.accessToken), authMethods: [], - authSig: authSig, - pkpPublicKey: params.pkpPublicKey, - expiration: authCallbackParams.expiration, - resources: authCallbackParams.resources, - chainId, - - // optional - ...(params.resourceAbilityRequests && { - resourceAbilityRequests: params.resourceAbilityRequests, - }), - }); + }; } else { - response = await nodeClient.signSessionKey({ - sessionKey: params.sessionSigsParams.sessionKey, - statement: authCallbackParams.statement, + authSpecificData = { authMethods: [params.authMethod], - pkpPublicKey: params.pkpPublicKey, - expiration: authCallbackParams.expiration, - resources: authCallbackParams.resources, - chainId, - - // optional - ...(params.resourceAbilityRequests && { - resourceAbilityRequests: params.resourceAbilityRequests, - }), - }); + }; } + // Merge the common and auth-specific data + response = await nodeClient.signSessionKey({ + // default + authMethods: [], + + // override + ...commonData, + ...authSpecificData, + }); + return response.authSig; }; } From 660759f5f001bc25767c9679d76df83d223ba707 Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 29 Apr 2024 15:49:30 +0100 Subject: [PATCH 07/16] fix: pass-in session key in base provider --- packages/lit-auth-client/src/lib/providers/BaseProvider.ts | 6 +++++- packages/types/src/lib/interfaces.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/lit-auth-client/src/lib/providers/BaseProvider.ts b/packages/lit-auth-client/src/lib/providers/BaseProvider.ts index d898c3d3b5..dc0e6a3a69 100644 --- a/packages/lit-auth-client/src/lib/providers/BaseProvider.ts +++ b/packages/lit-auth-client/src/lib/providers/BaseProvider.ts @@ -142,6 +142,10 @@ export abstract class BaseProvider { let authNeededCallback = params.sessionSigsParams.authNeededCallback; + // If no session key is provided, generate a new session key from the LitNodeClient + const sessionKey = + params.sessionSigsParams.sessionKey || this.litNodeClient.getSessionKey(); + // If no authNeededCallback is provided, create one that uses the provided PKP and auth method // to sign a session key and return an auth sig if (!authNeededCallback) { @@ -163,7 +167,7 @@ export abstract class BaseProvider { // common data for the signSessionKey function call const commonData = { - sessionKey: params.sessionSigsParams.sessionKey, + sessionKey: sessionKey, statement: authCallbackParams.statement, pkpPublicKey: params.pkpPublicKey, expiration: authCallbackParams.expiration, diff --git a/packages/types/src/lib/interfaces.ts b/packages/types/src/lib/interfaces.ts index 46f1d72cec..6592c62cd6 100644 --- a/packages/types/src/lib/interfaces.ts +++ b/packages/types/src/lib/interfaces.ts @@ -1471,7 +1471,7 @@ export interface BaseProviderSessionSigsParams { /** * Lit Node Client to use. If not provided, will use an existing Lit Node Client or create a new one */ - litNodeClient?: any; + litNodeClient?: ILitNodeClient; resourceAbilityRequests?: LitResourceAbilityRequest[]; } From f30a10a6a8ca12ac307052005d40a8e3ee0218eb Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 29 Apr 2024 15:20:01 +0100 Subject: [PATCH 08/16] feat: cherry-pick ee7011a --- packages/lit-auth-client/src/lib/providers/BaseProvider.ts | 2 +- packages/types/src/lib/interfaces.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/lit-auth-client/src/lib/providers/BaseProvider.ts b/packages/lit-auth-client/src/lib/providers/BaseProvider.ts index dc0e6a3a69..2e471462ad 100644 --- a/packages/lit-auth-client/src/lib/providers/BaseProvider.ts +++ b/packages/lit-auth-client/src/lib/providers/BaseProvider.ts @@ -167,7 +167,7 @@ export abstract class BaseProvider { // common data for the signSessionKey function call const commonData = { - sessionKey: sessionKey, + sessionKey: params.sessionSigsParams.sessionKey, statement: authCallbackParams.statement, pkpPublicKey: params.pkpPublicKey, expiration: authCallbackParams.expiration, diff --git a/packages/types/src/lib/interfaces.ts b/packages/types/src/lib/interfaces.ts index 6592c62cd6..7fa4a13cfa 100644 --- a/packages/types/src/lib/interfaces.ts +++ b/packages/types/src/lib/interfaces.ts @@ -247,7 +247,7 @@ export interface BaseJsonExecutionRequest { /** * FIXME: We should create a separate interface for JsExecutionRequestBody * a body that the SDK accepts, and another one the node actually accepts. - * + * */ export interface WithAuthSig extends BaseJsonExecutionRequest { authSig: AuthSig; From 8b92666a0a750f9e0959c030f22dcb7ffe66bafd Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 29 Apr 2024 15:49:30 +0100 Subject: [PATCH 09/16] fix: pass-in session key in base provider --- packages/lit-auth-client/src/lib/providers/BaseProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lit-auth-client/src/lib/providers/BaseProvider.ts b/packages/lit-auth-client/src/lib/providers/BaseProvider.ts index 2e471462ad..dc0e6a3a69 100644 --- a/packages/lit-auth-client/src/lib/providers/BaseProvider.ts +++ b/packages/lit-auth-client/src/lib/providers/BaseProvider.ts @@ -167,7 +167,7 @@ export abstract class BaseProvider { // common data for the signSessionKey function call const commonData = { - sessionKey: params.sessionSigsParams.sessionKey, + sessionKey: sessionKey, statement: authCallbackParams.statement, pkpPublicKey: params.pkpPublicKey, expiration: authCallbackParams.expiration, From b4a53dbb9d9bc0006701122249146dfd8c220ea5 Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 29 Apr 2024 17:34:44 +0100 Subject: [PATCH 10/16] fix: https://github.com/LIT-Protocol/js-sdk/pull/446#discussion_r1583307218 --- .../src/lib/providers/BaseProvider.ts | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/packages/lit-auth-client/src/lib/providers/BaseProvider.ts b/packages/lit-auth-client/src/lib/providers/BaseProvider.ts index dc0e6a3a69..43e2eaed0d 100644 --- a/packages/lit-auth-client/src/lib/providers/BaseProvider.ts +++ b/packages/lit-auth-client/src/lib/providers/BaseProvider.ts @@ -178,30 +178,21 @@ export abstract class BaseProvider { }), }; - // prepare auth-specific data based on the authentication method - let authSpecificData = {}; - if (params.authMethod.authMethodType === AuthMethodType.EthWallet) { - authSpecificData = { - authSig: JSON.parse(params.authMethod.accessToken), + const authSig = JSON.parse(params.authMethod.accessToken); + + response = await nodeClient.signSessionKey({ + ...commonData, + authSig: authSig, authMethods: [], - }; + }); } else { - authSpecificData = { + response = await nodeClient.signSessionKey({ + ...commonData, authMethods: [params.authMethod], - }; + }); } - // Merge the common and auth-specific data - response = await nodeClient.signSessionKey({ - // default - authMethods: [], - - // override - ...commonData, - ...authSpecificData, - }); - return response.authSig; }; } From 1c1727549c1ba2ff4cd23b6ada66b3f7731b3c0c Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 29 Apr 2024 19:06:43 +0100 Subject: [PATCH 11/16] feat: merge https://github.com/LIT-Protocol/js-sdk/pull/446 --- packages/lit-auth-client/src/lib/providers/BaseProvider.ts | 1 + packages/types/src/lib/interfaces.ts | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/lit-auth-client/src/lib/providers/BaseProvider.ts b/packages/lit-auth-client/src/lib/providers/BaseProvider.ts index 43e2eaed0d..62effb7c5a 100644 --- a/packages/lit-auth-client/src/lib/providers/BaseProvider.ts +++ b/packages/lit-auth-client/src/lib/providers/BaseProvider.ts @@ -200,6 +200,7 @@ export abstract class BaseProvider { // Generate session sigs with the given session params const sessionSigs = await this.litNodeClient.getSessionSigs({ ...params.sessionSigsParams, + sessionKey, authNeededCallback, }); diff --git a/packages/types/src/lib/interfaces.ts b/packages/types/src/lib/interfaces.ts index 7fa4a13cfa..183a59936a 100644 --- a/packages/types/src/lib/interfaces.ts +++ b/packages/types/src/lib/interfaces.ts @@ -987,8 +987,11 @@ export interface GetSessionSigsProps extends LitCustomAuth { */ authNeededCallback?: AuthCallback; - // The serialized session key pair to sign. If not provided, a session key pair will be fetched from localStorge or generated. - sessionKey?: any; + /** + * The serialized session key pair to sign. + * If not provided, a session key pair will be fetched from localStorge or generated. + */ + sessionKey?: SessionKeyPair; /** * @deprecated - use capabilityAuthSigs instead From 8a8694a166be4a86beb8bad3ee3aee83253301c9 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 30 Apr 2024 16:32:02 +0100 Subject: [PATCH 12/16] fix: remove TEMP_CACHE --- .../src/lib/lit-node-client-nodejs.ts | 23 ------------------- 1 file changed, 23 deletions(-) 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 611750b753..d0ec39193b 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 @@ -117,15 +117,9 @@ import type { JsExecutionRequestBody, JsonSignSessionKeyRequestV1, BlsResponseData, - SessionKeyCache, } from '@lit-protocol/types'; import * as blsSdk from '@lit-protocol/bls-sdk'; -const TEMP_CACHE_PERIOD = 30000; // 30 seconds - -// Global cache variable -let sessionKeyCache: SessionKeyCache | null = null; - export class LitNodeClientNodeJs extends LitCore implements LitClientSessionManager, ILitNodeClient @@ -327,15 +321,6 @@ export class LitNodeClientNodeJs `Storage key "${storageKey}" is missing. Not a problem. Contiune...` ); - // Check if a valid session key exists in cache - if ( - sessionKeyCache && - Date.now() - sessionKeyCache.timestamp < TEMP_CACHE_PERIOD - ) { - log(`[getSessionKey] Returning session key from cache.`); - return sessionKeyCache.value; - } - // Generate new one const newSessionKey = generateSessionKeyPair(); @@ -346,14 +331,6 @@ export class LitNodeClientNodeJs log( `[getSessionKey] Localstorage not available.Not a problem.Contiune...` ); - - // Store in cache - sessionKeyCache = { - value: newSessionKey, - timestamp: Date.now(), - }; - - log(`[getSessionKey] newSessionKey set to cache: `, sessionKeyCache); } return newSessionKey; From 3b7de4561cf00f2ec009ad49232a571b992a3d75 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 30 Apr 2024 16:33:35 +0100 Subject: [PATCH 13/16] fix: https://github.com/LIT-Protocol/js-sdk/pull/440#discussion_r1583803745 --- .../src/lib/lit-node-client-nodejs.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 d0ec39193b..1b46b6beb8 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 @@ -173,6 +173,11 @@ export class LitNodeClientNodeJs createCapacityDelegationAuthSig = async ( params: CapacityCreditsReq ): Promise => { + // -- validate + if (!params.dAppOwnerWallet) { + throw new Error('dAppOwnerWallet must exist'); + } + // Useful log for debugging if (!params.delegateeAddresses || params.delegateeAddresses.length === 0) { log( @@ -191,11 +196,6 @@ export class LitNodeClientNodeJs await this.connect(); } - // -- validate - if (!params.dAppOwnerWallet) { - throw new Error('dAppOwnerWallet must exist'); - } - const nonce = await this.getLatestBlockhash(); const siweMessage = await createSiweMessageWithCapacityDelegation({ From e424dafc8e174f4c7edee963e68a9393476fab21 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 30 Apr 2024 16:38:09 +0100 Subject: [PATCH 14/16] fix: https://github.com/LIT-Protocol/js-sdk/pull/440#discussion_r1583813538 --- .../src/lib/lit-node-client-nodejs.ts | 105 +++++++----------- 1 file changed, 39 insertions(+), 66 deletions(-) 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 1b46b6beb8..e5cb4c89f4 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 @@ -2622,26 +2622,15 @@ export class LitNodeClientNodeJs } // each of this field cannot be empty - let requiredFields = - curveType === LIT_CURVE.BLS - ? [ - 'signatureShare', - 'curveType', - 'shareIndex', - 'siweMessage', - 'dataSigned', - 'blsRootPubkey', - 'result', - ] - : [ - 'sigType', - 'dataSigned', - 'signatureShare', - 'bigr', - 'publicKey', - 'sigName', - 'siweMessage', - ]; + let requiredFields = [ + 'signatureShare', + 'curveType', + 'shareIndex', + 'siweMessage', + 'dataSigned', + 'blsRootPubkey', + 'result', + ]; // check if all required fields are present for (const field of requiredFields) { @@ -2688,59 +2677,43 @@ export class LitNodeClientNodeJs let signatures: any; - if (curveType === LIT_CURVE.BLS) { - const blsSignedData: BlsResponseData[] = - validatedSignedDataList as BlsResponseData[]; + const blsSignedData: BlsResponseData[] = + validatedSignedDataList as BlsResponseData[]; - const sigType = mostCommonString( - blsSignedData.map((s: any) => s.sigType) - ); - log(`[signSessionKey] sigType:`, sigType); + const sigType = mostCommonString(blsSignedData.map((s: any) => s.sigType)); + log(`[signSessionKey] sigType:`, sigType); - const signatureShares = blsSignedData.map((s) => ({ - ProofOfPossession: s.signatureShare.ProofOfPossession, - })); + const signatureShares = blsSignedData.map((s) => ({ + ProofOfPossession: s.signatureShare.ProofOfPossession, + })); - log(`[signSessionKey] signatureShares:`, signatureShares); + log(`[signSessionKey] signatureShares:`, signatureShares); - const blsCombinedSignature = blsSdk.combine_signature_shares( - signatureShares.map((s) => JSON.stringify(s)) - ); + const blsCombinedSignature = blsSdk.combine_signature_shares( + signatureShares.map((s) => JSON.stringify(s)) + ); - log(`[signSessionKey] blsCombinedSignature:`, blsCombinedSignature); + log(`[signSessionKey] blsCombinedSignature:`, blsCombinedSignature); - const publicKey = params.pkpPublicKey.startsWith('0x') - ? params.pkpPublicKey.slice(2) - : params.pkpPublicKey; + const publicKey = params.pkpPublicKey.startsWith('0x') + ? params.pkpPublicKey.slice(2) + : params.pkpPublicKey; - const dataSigned = mostCommonString( - blsSignedData.map((s: any) => s.dataSigned) - ); - const siweMessage = mostCommonString( - blsSignedData.map((s: any) => s.siweMessage) - ); - signatures = { - sessionSig: { - signature: blsCombinedSignature, - publicKey, - dataSigned, - siweMessage, - }, - }; - } else { - // Shape: [signSessionKey] signatures: { - // sessionSig: { - // r: "xx", - // s: "yy", - // recid: 1, - // signature: "0x...", - // publicKey: "04e...", - // dataSigned: "7c1...", - // siweMessage: "litprotocol.com wants you to sign in with your Ethereum account:\n0xd69969c6a2E56C928d63F12325fe1d9D47115C91\n\nLit Protocol PKP session signature Some custom statement. I further authorize the stated URI to perform the following actions on my behalf: (1) 'Threshold': 'Signing' for 'lit-pkp://*'.\n\nURI: lit:session:95ff87b5d2210c382ccfcba6bdb16ceb217da9726c91d0fdda5eb888f087488f\nVersion: 1\nChain ID: 1\nNonce: 0x337906a8c2a6da52d438495fc1b0145ed5632ec32ffa1dda1064f43775b3a802\nIssued At: 2024-04-09T17:58:47Z\nExpiration Time: 2024-04-10T17:59:13.420Z\nResources:\n- urn:recap:eyJhdHQiOnt9LCJwcmYiOltdfQ\n- urn:recap:eyJhdHQiOnsibGl0LXBrcDovLyoiOnsiVGhyZXNob2xkL1NpZ25pbmciOlt7fV19fSwicHJmIjpbXX0", - // }, - // } - signatures = this.getSessionSignatures(validatedSignedDataList); - } + const dataSigned = mostCommonString( + blsSignedData.map((s: any) => s.dataSigned) + ); + const mostCommonSiweMessage = mostCommonString( + blsSignedData.map((s: any) => s.siweMessage) + ); + + signatures = { + sessionSig: { + signature: blsCombinedSignature, + publicKey, + dataSigned, + siweMessage: mostCommonSiweMessage, + }, + }; log('[signSessionKey] signatures:', signatures); From 6e0e4ef5cb798930acffa7d1ebcc69d3aca65135 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 30 Apr 2024 16:43:20 +0100 Subject: [PATCH 15/16] fix: https://github.com/LIT-Protocol/js-sdk/pull/440#discussion_r1583811484 --- .../src/lib/lit-node-client-nodejs.ts | 24 +++++++------------ packages/types/src/lib/interfaces.ts | 3 --- 2 files changed, 8 insertions(+), 19 deletions(-) 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 e5cb4c89f4..a16009a720 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 @@ -2427,23 +2427,15 @@ export class LitNodeClientNodeJs params.expiration || new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(); - let sessionKeyUri: string; - - // This allow the user to provide a sessionKeyUri directly without using the session key pair - if (params?.sessionKeyUri) { - sessionKeyUri = params.sessionKeyUri; - log(`[signSessionKey] sessionKeyUri found in params:`, sessionKeyUri); - } else { - // Try to get it from local storage, if not generates one~ - let sessionKey: SessionKeyPair = - params.sessionKey ?? this.getSessionKey(); - sessionKeyUri = LIT_SESSION_KEY_URI + sessionKey.publicKey; + // Try to get it from local storage, if not generates one~ + const sessionKey: SessionKeyPair = + params.sessionKey ?? this.getSessionKey(); + const sessionKeyUri = LIT_SESSION_KEY_URI + sessionKey.publicKey; - log( - `[signSessionKey] sessionKeyUri is not found in params, generating a new one`, - sessionKeyUri - ); - } + log( + `[signSessionKey] sessionKeyUri is not found in params, generating a new one`, + sessionKeyUri + ); if (!sessionKeyUri) { throw new Error( diff --git a/packages/types/src/lib/interfaces.ts b/packages/types/src/lib/interfaces.ts index 183a59936a..af995db29c 100644 --- a/packages/types/src/lib/interfaces.ts +++ b/packages/types/src/lib/interfaces.ts @@ -929,9 +929,6 @@ export interface SignSessionKeyProp { resourceAbilityRequests?: LitResourceAbilityRequest[]; - // -- as part of auth unification - sessionKeyUri?: string; - litActionCode?: string; jsParams?: { From 7bc363dd3fb4aa76650cbe9a89fd5aa2a30552fb Mon Sep 17 00:00:00 2001 From: Anson Date: Wed, 1 May 2024 16:48:51 +0100 Subject: [PATCH 16/16] fix: remove authSig (need to fix `decryptToString` and `decryptToFile` return types --- packages/encryption/src/lib/encryption.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/encryption/src/lib/encryption.ts b/packages/encryption/src/lib/encryption.ts index 3e7e29bcd2..2fa80a33af 100644 --- a/packages/encryption/src/lib/encryption.ts +++ b/packages/encryption/src/lib/encryption.ts @@ -126,7 +126,7 @@ export async function decryptFromJson( ? ReturnType : never > { - const { authSig, sessionSigs, parsedJsonData, litNodeClient } = params; + const { sessionSigs, parsedJsonData, litNodeClient } = params; // -- validate const paramsIsSafe = safeParams({ @@ -153,7 +153,6 @@ export async function decryptFromJson( ciphertext: parsedJsonData.ciphertext, dataToEncryptHash: parsedJsonData.dataToEncryptHash, chain: parsedJsonData.chain, - authSig, sessionSigs, }, litNodeClient @@ -169,7 +168,6 @@ export async function decryptFromJson( ciphertext: parsedJsonData.ciphertext, dataToEncryptHash: parsedJsonData.dataToEncryptHash, chain: parsedJsonData.chain, - authSig, sessionSigs, }, litNodeClient @@ -444,7 +442,6 @@ export const encryptFileAndZipWithMetadata = async ( params: EncryptFileAndZipWithMetadataProps ): Promise => { const { - authSig, sessionSigs, accessControlConditions, evmContractConditions, @@ -460,7 +457,6 @@ export const encryptFileAndZipWithMetadata = async ( const paramsIsSafe = safeParams({ functionName: 'encryptFileAndZipWithMetadata', params: { - authSig, sessionSigs, accessControlConditions, evmContractConditions, @@ -545,13 +541,12 @@ export const encryptFileAndZipWithMetadata = async ( export const decryptZipFileWithMetadata = async ( params: DecryptZipFileWithMetadataProps ): Promise => { - const { authSig, sessionSigs, file, litNodeClient } = params; + const { sessionSigs, file, litNodeClient } = params; // -- validate const paramsIsSafe = safeParams({ functionName: 'decryptZipFileWithMetadata', params: { - authSig, sessionSigs, file, litNodeClient,