diff --git a/packages/auth-helpers/src/lib/siwe/create-siwe-message.ts b/packages/auth-helpers/src/lib/siwe/create-siwe-message.ts index 5d3f82d67b..d1e55ff2a4 100644 --- a/packages/auth-helpers/src/lib/siwe/create-siwe-message.ts +++ b/packages/auth-helpers/src/lib/siwe/create-siwe-message.ts @@ -14,7 +14,7 @@ import { /** * Creates a SIWE - * @param params - The parameters for creating the SIWE message. + * @param { BaseSiweMessage } params - The parameters for creating the SIWE message. * @returns A promise that resolves to the created SIWE message as a string. * @throws An error if the walletAddress parameter is missing. */ @@ -80,7 +80,7 @@ export const createSiweMessage = async ( /** * Creates a SIWE message with recaps added to it. * - * @param params - The parameters for creating the SIWE message with recaps. + * @param { WithRecap } params - The parameters for creating the SIWE message with recaps. * @returns A Promise that resolves to a string representing the SIWE message. */ export const createSiweMessageWithRecaps = async ( @@ -93,7 +93,7 @@ export const createSiweMessageWithRecaps = async ( /** * Creates a SIWE message with capacity delegation. - * @param params - The parameters for creating the SIWE message. + * @param { WithCapacityDelegation } params - The parameters for creating the SIWE message. * @returns A Promise that resolves to the created SIWE message. * @throws An error if litNodeClient is not provided. */ diff --git a/packages/lit-node-client-nodejs/src/lib/helpers/handle-bls-response.spec.ts b/packages/lit-node-client-nodejs/src/lib/helpers/handle-bls-response.spec.ts new file mode 100644 index 0000000000..79a0a227ab --- /dev/null +++ b/packages/lit-node-client-nodejs/src/lib/helpers/handle-bls-response.spec.ts @@ -0,0 +1,61 @@ +import { handleBlsResponseData } from './handle-bls-response'; + +describe('handleBlsResponseData', () => { + it('should return an array of signed data', () => { + const responseData = [ + { + result: 'success', + signatureShare: { + ProofOfPossession: + '01b191b1d281857a95d2fd189683db366ab1088723338c1805daa4650459e9fcaebaa57b58108c284d233404dd5f2e58f208aafb87d981098aba3fe850980184a4b29643a21107b03f1d928646245b57af3745a81418989e0b6aad9bd1f192723c', + }, + shareIndex: 0, + curveType: 'BLS', + siweMessage: + "litprotocol.com wants you to sign in with your Ethereum account:\n0x7f2e96c99F9551915DA9e9F828F512330f130acB\n\nLit Protocol PKP session signature I further authorize the stated URI to perform the following actions on my behalf: I further authorize the stated URI to perform the following actions on my behalf: (1) 'Threshold': 'Execution' for 'lit-litaction://*'. (2) 'Threshold': 'Signing' for 'lit-pkp://*'. I further authorize the stated URI to perform the following actions on my behalf: (1) 'Threshold': 'Execution' for 'lit-litaction://*'. (2) 'Threshold': 'Signing' for 'lit-pkp://*'. (3) 'Auth': 'Auth' for 'lit-resolvedauthcontext://*'.\n\nURI: lit:session:73e09d1ad1faa329bef12ebaf9b982d2925746e3677cabd4b6b7196096a6ee02\nVersion: 1\nChain ID: 1\nNonce: 0xa5f18dbc0fa2080649042ab8cb6cef3b246c20c15b62482ba43fb4ca2a4642cb\nIssued At: 2024-04-25T02:09:35Z\nExpiration Time: 2024-04-26T02:09:50.822Z\nResources:\n- urn:recap:eyJhdHQiOnsibGl0LWxpdGFjdGlvbjovLyoiOnsiVGhyZXNob2xkL0V4ZWN1dGlvbiI6W3t9XX0sImxpdC1wa3A6Ly8qIjp7IlRocmVzaG9sZC9TaWduaW5nIjpbe31dfSwibGl0LXJlc29sdmVkYXV0aGNvbnRleHQ6Ly8qIjp7IkF1dGgvQXV0aCI6W3siYXV0aF9jb250ZXh0Ijp7ImFjdGlvbklwZnNJZHMiOlsiUW1ZM3F1bjlxWDNmVUJIVmZyQTlmM3Y5UnB5eVBvOFJIRXVFTjFYWVBxMVByQSJdLCJhdXRoTWV0aG9kQ29udGV4dHMiOlt7ImFwcElkIjoibGl0IiwiYXV0aE1ldGhvZFR5cGUiOjEsImV4cGlyYXRpb24iOjE3MTQwOTczODYsInVzZWRGb3JTaWduU2Vzc2lvbktleVJlcXVlc3QiOnRydWUsInVzZXJJZCI6IjB4NzA5OTc5NzBDNTE4MTJkYzNBMDEwQzdkMDFiNTBlMGQxN2RjNzlDOCJ9XSwiYXV0aFNpZ0FkZHJlc3MiOm51bGwsInJlc291cmNlcyI6W119fV19fSwicHJmIjpbXX0", + dataSigned: + 'b2efe867176b9212fd6acd39a33004a17e03d5a931250c700e31af95e2e7e4d5', + blsRootPubkey: + 'a6f7c284ac766db1b43f8c65d8ff15c7271a05b0863b5205d96459fd32aa353e9390ce0626560fb76720c1a5c8ca6902', + }, + { + result: 'success', + signatureShare: { + ProofOfPossession: + '038178034edcd5b48da4e2af6eb0891ece41389aa6119c80546d3fa00b5d2ba87eaec327b18d8013714b486246807498c8198e70cf8e917b1a5f1d8d0846787172521d41994de95bd641bdc1d9ccee9b459ceeb03f156cf357a4ff8faf5d2e167d', + }, + shareIndex: 2, + curveType: 'BLS', + siweMessage: + "litprotocol.com wants you to sign in with your Ethereum account:\n0x7f2e96c99F9551915DA9e9F828F512330f130acB\n\nLit Protocol PKP session signature I further authorize the stated URI to perform the following actions on my behalf: I further authorize the stated URI to perform the following actions on my behalf: (1) 'Threshold': 'Execution' for 'lit-litaction://*'. (2) 'Threshold': 'Signing' for 'lit-pkp://*'. I further authorize the stated URI to perform the following actions on my behalf: (1) 'Threshold': 'Execution' for 'lit-litaction://*'. (2) 'Threshold': 'Signing' for 'lit-pkp://*'. (3) 'Auth': 'Auth' for 'lit-resolvedauthcontext://*'.\n\nURI: lit:session:73e09d1ad1faa329bef12ebaf9b982d2925746e3677cabd4b6b7196096a6ee02\nVersion: 1\nChain ID: 1\nNonce: 0xa5f18dbc0fa2080649042ab8cb6cef3b246c20c15b62482ba43fb4ca2a4642cb\nIssued At: 2024-04-25T02:09:35Z\nExpiration Time: 2024-04-26T02:09:50.822Z\nResources:\n- urn:recap:eyJhdHQiOnsibGl0LWxpdGFjdGlvbjovLyoiOnsiVGhyZXNob2xkL0V4ZWN1dGlvbiI6W3t9XX0sImxpdC1wa3A6Ly8qIjp7IlRocmVzaG9sZC9TaWduaW5nIjpbe31dfSwibGl0LXJlc29sdmVkYXV0aGNvbnRleHQ6Ly8qIjp7IkF1dGgvQXV0aCI6W3siYXV0aF9jb250ZXh0Ijp7ImFjdGlvbklwZnNJZHMiOlsiUW1ZM3F1bjlxWDNmVUJIVmZyQTlmM3Y5UnB5eVBvOFJIRXVFTjFYWVBxMVByQSJdLCJhdXRoTWV0aG9kQ29udGV4dHMiOlt7ImFwcElkIjoibGl0IiwiYXV0aE1ldGhvZFR5cGUiOjEsImV4cGlyYXRpb24iOjE3MTQwOTczODYsInVzZWRGb3JTaWduU2Vzc2lvbktleVJlcXVlc3QiOnRydWUsInVzZXJJZCI6IjB4NzA5OTc5NzBDNTE4MTJkYzNBMDEwQzdkMDFiNTBlMGQxN2RjNzlDOCJ9XSwiYXV0aFNpZ0FkZHJlc3MiOm51bGwsInJlc291cmNlcyI6W119fV19fSwicHJmIjpbXX0", + dataSigned: + 'b2efe867176b9212fd6acd39a33004a17e03d5a931250c700e31af95e2e7e4d5', + blsRootPubkey: + 'a6f7c284ac766db1b43f8c65d8ff15c7271a05b0863b5205d96459fd32aa353e9390ce0626560fb76720c1a5c8ca6902', + }, + { + result: 'success', + signatureShare: { + ProofOfPossession: + '0292a026325a166398b85b53f3a7a34d147c5337e189d75c33c0f227f7926c839b408dfcc5d242a8685a81c68e0ccedc080c051219161dbc37f06627259b19d15120ab2f710075a44b1dcef18d511bb99b6625c8f575d2688c6b5b01ba6bf448c9', + }, + shareIndex: 1, + curveType: 'BLS', + siweMessage: + "litprotocol.com wants you to sign in with your Ethereum account:\n0x7f2e96c99F9551915DA9e9F828F512330f130acB\n\nLit Protocol PKP session signature I further authorize the stated URI to perform the following actions on my behalf: I further authorize the stated URI to perform the following actions on my behalf: (1) 'Threshold': 'Execution' for 'lit-litaction://*'. (2) 'Threshold': 'Signing' for 'lit-pkp://*'. I further authorize the stated URI to perform the following actions on my behalf: (1) 'Threshold': 'Execution' for 'lit-litaction://*'. (2) 'Threshold': 'Signing' for 'lit-pkp://*'. (3) 'Auth': 'Auth' for 'lit-resolvedauthcontext://*'.\n\nURI: lit:session:73e09d1ad1faa329bef12ebaf9b982d2925746e3677cabd4b6b7196096a6ee02\nVersion: 1\nChain ID: 1\nNonce: 0xa5f18dbc0fa2080649042ab8cb6cef3b246c20c15b62482ba43fb4ca2a4642cb\nIssued At: 2024-04-25T02:09:35Z\nExpiration Time: 2024-04-26T02:09:50.822Z\nResources:\n- urn:recap:eyJhdHQiOnsibGl0LWxpdGFjdGlvbjovLyoiOnsiVGhyZXNob2xkL0V4ZWN1dGlvbiI6W3t9XX0sImxpdC1wa3A6Ly8qIjp7IlRocmVzaG9sZC9TaWduaW5nIjpbe31dfSwibGl0LXJlc29sdmVkYXV0aGNvbnRleHQ6Ly8qIjp7IkF1dGgvQXV0aCI6W3siYXV0aF9jb250ZXh0Ijp7ImFjdGlvbklwZnNJZHMiOlsiUW1ZM3F1bjlxWDNmVUJIVmZyQTlmM3Y5UnB5eVBvOFJIRXVFTjFYWVBxMVByQSJdLCJhdXRoTWV0aG9kQ29udGV4dHMiOlt7ImFwcElkIjoibGl0IiwiYXV0aE1ldGhvZFR5cGUiOjEsImV4cGlyYXRpb24iOjE3MTQwOTczODYsInVzZWRGb3JTaWduU2Vzc2lvbktleVJlcXVlc3QiOnRydWUsInVzZXJJZCI6IjB4NzA5OTc5NzBDNTE4MTJkYzNBMDEwQzdkMDFiNTBlMGQxN2RjNzlDOCJ9XSwiYXV0aFNpZ0FkZHJlc3MiOm51bGwsInJlc291cmNlcyI6W119fV19fSwicHJmIjpbXX0", + dataSigned: + 'b2efe867176b9212fd6acd39a33004a17e03d5a931250c700e31af95e2e7e4d5', + blsRootPubkey: + 'a6f7c284ac766db1b43f8c65d8ff15c7271a05b0863b5205d96459fd32aa353e9390ce0626560fb76720c1a5c8ca6902', + }, + ] as any; + + const result = handleBlsResponseData(responseData); + + expect(result).toEqual([ + 'b2efe867176b9212fd6acd39a33004a17e03d5a931250c700e31af95e2e7e4d5', + 'b2efe867176b9212fd6acd39a33004a17e03d5a931250c700e31af95e2e7e4d5', + 'b2efe867176b9212fd6acd39a33004a17e03d5a931250c700e31af95e2e7e4d5', + ]); + }); +}); diff --git a/packages/lit-node-client-nodejs/src/lib/helpers/handle-bls-response.ts b/packages/lit-node-client-nodejs/src/lib/helpers/handle-bls-response.ts new file mode 100644 index 0000000000..5801f79fa8 --- /dev/null +++ b/packages/lit-node-client-nodejs/src/lib/helpers/handle-bls-response.ts @@ -0,0 +1,30 @@ +import { log } from '@lit-protocol/misc'; +import { BlsResponseData } from '@lit-protocol/types'; + +/** + * Handles the response data from BLS signature scheme. + * @param responseData - The response data from BLS signature scheme. + * @returns An array of signed data. + * @throws Error if no data is provided. + */ +export function handleBlsResponseData( + responseData: BlsResponseData[] +): string[] { + if (!responseData) { + throw new Error('[handleBlsResponseData] No data provided'); + } + + const signatureShares = responseData.map((s) => ({ + ProofOfPossession: s.signatureShare.ProofOfPossession, + })); + log(`[handleBlsResponseData] signatureShares:`, signatureShares); + + if (!signatureShares || signatureShares.length <= 0) { + throw new Error('[handleBlsResponseData] No signature shares provided'); + } + + const signedDataList = responseData.map((s) => s.dataSigned); + log(`[handleBlsResponseData] signedDataList:`, signedDataList); + + return signedDataList; +} 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 76cbd0ca2c..2c43a37145 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 @@ -110,7 +110,6 @@ import type { CapacityCreditsRes, JsonSignSessionKeyRequestV1, BlsResponseData, - SessionKeyCache, JsonPkpSignSdkParams, JsonExecutionSdkParams, ExecuteJsNoSigningResponse, @@ -119,20 +118,16 @@ import type { SigResponse, } from '@lit-protocol/types'; import * as blsSdk from '@lit-protocol/bls-sdk'; -import { normalizeArray } from './helpers/normalize-array'; import { normalizeJsParams } from './helpers/normalize-params'; import { encodeCode } from './helpers/encode-code'; +import { getFlattenShare, getSignatures } from './helpers/get-signatures'; import { removeDoubleQuotes } from './helpers/remove-double-quotes'; import { parseAsJsonOrString } from './helpers/parse-as-json-or-string'; -import { getFlattenShare, getSignatures } from './helpers/get-signatures'; import { getClaimsList } from './helpers/get-claims-list'; import { getClaims } from './helpers/get-claims'; +import { normalizeArray } from './helpers/normalize-array'; import { parsePkpSignResponse } from './helpers/parse-pkp-sign-response'; - -const TEMP_CACHE_PERIOD = 30000; // 30 seconds - -// Global cache variable -let sessionKeyCache: SessionKeyCache | null = null; +import { handleBlsResponseData } from './helpers/handle-bls-response'; export class LitNodeClientNodeJs extends LitCore @@ -155,10 +150,15 @@ 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( - `[createCapacityDelegationAuthSig] No delegatee addresses provided. It means that the capability will not restrict access based on delegatee list, but it may still enforce other restrictions such as usage limits (uses) and specific NFT IDs (nft_id).` + `[createCapacityDelegationAuthSig] 'delegateeAddresses' is an empty array. It means that no body can use it. However, if the 'delegateeAddresses' field is omitted, It means that the capability will not restrict access based on delegatee list, but it may still enforce other restrictions such as usage limits (uses) and specific NFT IDs (nft_id).` ); } @@ -173,11 +173,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({ @@ -185,17 +180,12 @@ export class LitNodeClientNodeJs litNodeClient: this, walletAddress: dAppOwnerWalletAddress, nonce: nonce, - - // -- default configuration for recap object capability - expiration: - params.expiration ?? new Date(Date.now() + 1000 * 60 * 7).toISOString(), - domain: params.domain ?? 'example.com', - statement: - params.statement ?? - 'This is a test statement. You can put anything you want here.', + expiration: params.expiration, + domain: params.domain, + statement: params.statement, // -- capacity delegation specific configuration - uses: params.uses ?? '1', + uses: params.uses, delegateeAddresses: params.delegateeAddresses, capacityTokenId: params.capacityTokenId, }); @@ -242,15 +232,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(); @@ -261,14 +242,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; @@ -2154,19 +2127,7 @@ export class LitNodeClientNodeJs let signedDataList: any[] = []; if (curveType === LIT_CURVE.BLS) { - let _responseData: BlsResponseData[] = responseData; - - const signatureShares = _responseData.map((s) => ({ - ProofOfPossession: s.signatureShare.ProofOfPossession, - })); - - log(`[signSessionKey] signatureShares:`, signatureShares); - - signedDataList = _responseData.map((s) => { - return s.dataSigned; - }); - - signedDataList = _responseData; + signedDataList = handleBlsResponseData(responseData); } else { signedDataList = responseData.map( (r: any) => (r as SignedData).signedData @@ -2272,9 +2233,7 @@ export class LitNodeClientNodeJs ); log(`[signSessionKey] sigType:`, sigType); - const signatureShares = blsSignedData.map((s) => ({ - ProofOfPossession: s.signatureShare.ProofOfPossession, - })); + const signatureShares = handleBlsResponseData(blsSignedData); log(`[signSessionKey] signatureShares:`, signatureShares); @@ -2548,6 +2507,7 @@ export class LitNodeClientNodeJs }; /** +<<<<<<<<< Temporary merge branch 1 * Retrieves the PKP sessionSigs. * * @param params - The parameters for retrieving the PKP sessionSigs. diff --git a/packages/misc/src/lib/misc.spec.ts b/packages/misc/src/lib/misc.spec.ts index 5f891f5e8b..9bd57b0981 100644 --- a/packages/misc/src/lib/misc.spec.ts +++ b/packages/misc/src/lib/misc.spec.ts @@ -239,251 +239,35 @@ describe('utils', () => { expect(res.requestId).toBeDefined(); }); }); -describe('find most common tings', () => { - it('should return the most common string in an array', () => { - const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 8]; - - const mostOccured = utilsModule.mostCommonString(arr); - expect(mostOccured).toBe(8); +describe('double escaped JSON string', () => { + test('A doubly escaped JSON string', () => { + const doublyEscapedJson = '{\\"key\\": \\"value\\"}'; + expect(utilsModule.normalizeAndStringify(doublyEscapedJson)).toBe( + '{"key":"value"}' + ); }); - it('should return the last element of the array if every element only appears once', () => { - const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; - - const mostOccured = utilsModule.mostCommonString(arr); - - expect(mostOccured).toBe(0); + test('A triply escaped JSON string', () => { + const triplyEscapedJson = '{\\\\\\"key\\\\\\": \\\\\\"value\\\\\\"}'; + expect(utilsModule.normalizeAndStringify(triplyEscapedJson)).toBe( + '{"key":"value"}' + ); }); - it('should test real world example of responseData', () => { - const responseData = [ - { - success: true, - signedData: { - sig: { - sigType: 'ECDSA_CAIT_SITH', - dataSigned: 'fail', - signatureShare: '', - shareIndex: 0, - bigR: '', - publicKey: '', - sigName: 'sig', - }, - }, - decryptedData: {}, - claimData: {}, - response: '', - logs: '', - }, - { - success: true, - signedData: { - sig: { - sigType: 'ECDSA_CAIT_SITH', - dataSigned: 'fail', - signatureShare: '', - shareIndex: 0, - bigR: '', - publicKey: '', - sigName: 'sig', - }, - }, - decryptedData: {}, - claimData: {}, - response: '', - logs: '', - }, - { - success: true, - signedData: { - sig: { - sigType: 'ECDSA_CAIT_SITH', - dataSigned: 'fail', - signatureShare: '', - shareIndex: 0, - bigR: '', - publicKey: '', - sigName: 'sig', - }, - }, - decryptedData: {}, - claimData: {}, - response: '', - logs: '', - }, - { - success: true, - signedData: { - sig: { - sigType: 'ECDSA_CAIT_SITH', - dataSigned: - '"7D87C5EA75F7378BB701E404C50639161AF3EFF66293E9F375B5F17EB50476F4"', - signatureShare: - '"A2022A52D6263F5AD61D1A4E29F2C2545FA6E711A30A35BF3456FD5297E4080A"', - shareIndex: 0, - bigR: '"035938946F745C3A6E8B8F0DF7849B0693AAB779695BA770F76906562F37DD005F"', - publicKey: - '"049C6E2DD71F553A29398FA0A93BBCB411EE442D97D253D9E82F41C8601B19BCD71F37F0A2A0A0F501593153C3FD2C9EC3A2BDFA8E43291B7B0E165A3E104BF0B2"', - sigName: 'sig', - }, - }, - decryptedData: {}, - claimData: {}, - response: '', - logs: '', - }, - { - success: true, - signedData: { - sig: { - sigType: 'ECDSA_CAIT_SITH', - dataSigned: - '"7D87C5EA75F7378BB701E404C50639161AF3EFF66293E9F375B5F17EB50476F4"', - signatureShare: - '"35790072188D520CDAA61394BB822C4F9D95CC2FC21CBAF54EBB91FA8734F5FE"', - shareIndex: 0, - bigR: '"035938946F745C3A6E8B8F0DF7849B0693AAB779695BA770F76906562F37DD005F"', - publicKey: - '"049C6E2DD71F553A29398FA0A93BBCB411EE442D97D253D9E82F41C8601B19BCD71F37F0A2A0A0F501593153C3FD2C9EC3A2BDFA8E43291B7B0E165A3E104BF0B2"', - sigName: 'sig', - }, - }, - decryptedData: {}, - claimData: {}, - response: '', - logs: '', - }, - { - success: true, - signedData: { - sig: { - sigType: 'ECDSA_CAIT_SITH', - dataSigned: - '"7D87C5EA75F7378BB701E404C50639161AF3EFF66293E9F375B5F17EB50476F4"', - signatureShare: - '"A1676E25812D6812BB24469943A15F68FAD4CC679E0376CE1EDD5E0D64236E7A"', - shareIndex: 0, - bigR: '"035938946F745C3A6E8B8F0DF7849B0693AAB779695BA770F76906562F37DD005F"', - publicKey: - '"049C6E2DD71F553A29398FA0A93BBCB411EE442D97D253D9E82F41C8601B19BCD71F37F0A2A0A0F501593153C3FD2C9EC3A2BDFA8E43291B7B0E165A3E104BF0B2"', - sigName: 'sig', - }, - }, - decryptedData: {}, - claimData: {}, - response: '', - logs: '', - }, - { - success: true, - signedData: { - sig: { - sigType: 'ECDSA_CAIT_SITH', - dataSigned: - '"7D87C5EA75F7378BB701E404C50639161AF3EFF66293E9F375B5F17EB50476F4"', - signatureShare: - '"3E8184B2E3DC4725A711D4DBF8D32288A8AC4F31FD04B8ACB302B9BB3D209122"', - shareIndex: 0, - bigR: '"035938946F745C3A6E8B8F0DF7849B0693AAB779695BA770F76906562F37DD005F"', - publicKey: - '"049C6E2DD71F553A29398FA0A93BBCB411EE442D97D253D9E82F41C8601B19BCD71F37F0A2A0A0F501593153C3FD2C9EC3A2BDFA8E43291B7B0E165A3E104BF0B2"', - sigName: 'sig', - }, - }, - decryptedData: {}, - claimData: {}, - response: '', - logs: '', - }, - ]; - - const mostCommonResponse = utilsModule.findMostCommonResponse(responseData); - - expect(mostCommonResponse).toEqual({ - success: true, - signedData: { - sig: { - sigType: 'ECDSA_CAIT_SITH', - dataSigned: - '"7D87C5EA75F7378BB701E404C50639161AF3EFF66293E9F375B5F17EB50476F4"', - signatureShare: - '"3E8184B2E3DC4725A711D4DBF8D32288A8AC4F31FD04B8ACB302B9BB3D209122"', - shareIndex: 0, - bigR: '"035938946F745C3A6E8B8F0DF7849B0693AAB779695BA770F76906562F37DD005F"', - publicKey: - '"049C6E2DD71F553A29398FA0A93BBCB411EE442D97D253D9E82F41C8601B19BCD71F37F0A2A0A0F501593153C3FD2C9EC3A2BDFA8E43291B7B0E165A3E104BF0B2"', - sigName: 'sig', - }, - }, - decryptedData: {}, - claimData: {}, - response: undefined, - logs: undefined, - }); + test('A correctly escaped JSON string (for comparison)', () => { + const correctlyEscapedJson = '{"key":"value"}'; + expect(utilsModule.normalizeAndStringify(correctlyEscapedJson)).toBe( + '{"key":"value"}' + ); }); - it('should return the most common response object', () => { - const responses = [ - { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - ]; - - const expectedResult = { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }; - const result = utilsModule.findMostCommonResponse(responses); + test('regular siwe message', () => { + const regularString = + 'litprotocol.com wants you to sign in with your Ethereum account:\\n0x3edB...'; - expect(result).toEqual(expectedResult); + expect(utilsModule.normalizeAndStringify(regularString)).toBe( + regularString + ); }); }); diff --git a/packages/types/src/lib/interfaces.ts b/packages/types/src/lib/interfaces.ts index 0904310625..550d248a36 100644 --- a/packages/types/src/lib/interfaces.ts +++ b/packages/types/src/lib/interfaces.ts @@ -283,8 +283,43 @@ export interface JsonSignSessionKeyRequestV1 { epoch?: number; } +// [ +// { +// "result": "success", +// "signatureShare": { +// "ProofOfPossession": "01b191b1d281857a95d2fd189683db366ab1088723338c1805daa4650459e9fcaebaa57b58108c284d233404dd5f2e58f208aafb87d981098aba3fe850980184a4b29643a21107b03f1d928646245b57af3745a81418989e0b6aad9bd1f192723c" +// }, +// "shareIndex": 0, +// "curveType": "BLS", +// "siweMessage": "litprotocol.com wants you to sign in with your Ethereum account:\n0x7f2e96c99F9551915DA9e9F828F512330f130acB\n\nLit Protocol PKP session signature I further authorize the stated URI to perform the following actions on my behalf: I further authorize the stated URI to perform the following actions on my behalf: (1) 'Threshold': 'Execution' for 'lit-litaction://*'. (2) 'Threshold': 'Signing' for 'lit-pkp://*'. I further authorize the stated URI to perform the following actions on my behalf: (1) 'Threshold': 'Execution' for 'lit-litaction://*'. (2) 'Threshold': 'Signing' for 'lit-pkp://*'. (3) 'Auth': 'Auth' for 'lit-resolvedauthcontext://*'.\n\nURI: lit:session:73e09d1ad1faa329bef12ebaf9b982d2925746e3677cabd4b6b7196096a6ee02\nVersion: 1\nChain ID: 1\nNonce: 0xa5f18dbc0fa2080649042ab8cb6cef3b246c20c15b62482ba43fb4ca2a4642cb\nIssued At: 2024-04-25T02:09:35Z\nExpiration Time: 2024-04-26T02:09:50.822Z\nResources:\n- urn:recap:eyJhdHQiOnsibGl0LWxpdGFjdGlvbjovLyoiOnsiVGhyZXNob2xkL0V4ZWN1dGlvbiI6W3t9XX0sImxpdC1wa3A6Ly8qIjp7IlRocmVzaG9sZC9TaWduaW5nIjpbe31dfSwibGl0LXJlc29sdmVkYXV0aGNvbnRleHQ6Ly8qIjp7IkF1dGgvQXV0aCI6W3siYXV0aF9jb250ZXh0Ijp7ImFjdGlvbklwZnNJZHMiOlsiUW1ZM3F1bjlxWDNmVUJIVmZyQTlmM3Y5UnB5eVBvOFJIRXVFTjFYWVBxMVByQSJdLCJhdXRoTWV0aG9kQ29udGV4dHMiOlt7ImFwcElkIjoibGl0IiwiYXV0aE1ldGhvZFR5cGUiOjEsImV4cGlyYXRpb24iOjE3MTQwOTczODYsInVzZWRGb3JTaWduU2Vzc2lvbktleVJlcXVlc3QiOnRydWUsInVzZXJJZCI6IjB4NzA5OTc5NzBDNTE4MTJkYzNBMDEwQzdkMDFiNTBlMGQxN2RjNzlDOCJ9XSwiYXV0aFNpZ0FkZHJlc3MiOm51bGwsInJlc291cmNlcyI6W119fV19fSwicHJmIjpbXX0", +// "dataSigned": "b2efe867176b9212fd6acd39a33004a17e03d5a931250c700e31af95e2e7e4d5", +// "blsRootPubkey": "a6f7c284ac766db1b43f8c65d8ff15c7271a05b0863b5205d96459fd32aa353e9390ce0626560fb76720c1a5c8ca6902" +// }, +// { +// "result": "success", +// "signatureShare": { +// "ProofOfPossession": "038178034edcd5b48da4e2af6eb0891ece41389aa6119c80546d3fa00b5d2ba87eaec327b18d8013714b486246807498c8198e70cf8e917b1a5f1d8d0846787172521d41994de95bd641bdc1d9ccee9b459ceeb03f156cf357a4ff8faf5d2e167d" +// }, +// "shareIndex": 2, +// "curveType": "BLS", +// "siweMessage": "litprotocol.com wants you to sign in with your Ethereum account:\n0x7f2e96c99F9551915DA9e9F828F512330f130acB\n\nLit Protocol PKP session signature I further authorize the stated URI to perform the following actions on my behalf: I further authorize the stated URI to perform the following actions on my behalf: (1) 'Threshold': 'Execution' for 'lit-litaction://*'. (2) 'Threshold': 'Signing' for 'lit-pkp://*'. I further authorize the stated URI to perform the following actions on my behalf: (1) 'Threshold': 'Execution' for 'lit-litaction://*'. (2) 'Threshold': 'Signing' for 'lit-pkp://*'. (3) 'Auth': 'Auth' for 'lit-resolvedauthcontext://*'.\n\nURI: lit:session:73e09d1ad1faa329bef12ebaf9b982d2925746e3677cabd4b6b7196096a6ee02\nVersion: 1\nChain ID: 1\nNonce: 0xa5f18dbc0fa2080649042ab8cb6cef3b246c20c15b62482ba43fb4ca2a4642cb\nIssued At: 2024-04-25T02:09:35Z\nExpiration Time: 2024-04-26T02:09:50.822Z\nResources:\n- urn:recap:eyJhdHQiOnsibGl0LWxpdGFjdGlvbjovLyoiOnsiVGhyZXNob2xkL0V4ZWN1dGlvbiI6W3t9XX0sImxpdC1wa3A6Ly8qIjp7IlRocmVzaG9sZC9TaWduaW5nIjpbe31dfSwibGl0LXJlc29sdmVkYXV0aGNvbnRleHQ6Ly8qIjp7IkF1dGgvQXV0aCI6W3siYXV0aF9jb250ZXh0Ijp7ImFjdGlvbklwZnNJZHMiOlsiUW1ZM3F1bjlxWDNmVUJIVmZyQTlmM3Y5UnB5eVBvOFJIRXVFTjFYWVBxMVByQSJdLCJhdXRoTWV0aG9kQ29udGV4dHMiOlt7ImFwcElkIjoibGl0IiwiYXV0aE1ldGhvZFR5cGUiOjEsImV4cGlyYXRpb24iOjE3MTQwOTczODYsInVzZWRGb3JTaWduU2Vzc2lvbktleVJlcXVlc3QiOnRydWUsInVzZXJJZCI6IjB4NzA5OTc5NzBDNTE4MTJkYzNBMDEwQzdkMDFiNTBlMGQxN2RjNzlDOCJ9XSwiYXV0aFNpZ0FkZHJlc3MiOm51bGwsInJlc291cmNlcyI6W119fV19fSwicHJmIjpbXX0", +// "dataSigned": "b2efe867176b9212fd6acd39a33004a17e03d5a931250c700e31af95e2e7e4d5", +// "blsRootPubkey": "a6f7c284ac766db1b43f8c65d8ff15c7271a05b0863b5205d96459fd32aa353e9390ce0626560fb76720c1a5c8ca6902" +// }, +// { +// "result": "success", +// "signatureShare": { +// "ProofOfPossession": "0292a026325a166398b85b53f3a7a34d147c5337e189d75c33c0f227f7926c839b408dfcc5d242a8685a81c68e0ccedc080c051219161dbc37f06627259b19d15120ab2f710075a44b1dcef18d511bb99b6625c8f575d2688c6b5b01ba6bf448c9" +// }, +// "shareIndex": 1, +// "curveType": "BLS", +// "siweMessage": "litprotocol.com wants you to sign in with your Ethereum account:\n0x7f2e96c99F9551915DA9e9F828F512330f130acB\n\nLit Protocol PKP session signature I further authorize the stated URI to perform the following actions on my behalf: I further authorize the stated URI to perform the following actions on my behalf: (1) 'Threshold': 'Execution' for 'lit-litaction://*'. (2) 'Threshold': 'Signing' for 'lit-pkp://*'. I further authorize the stated URI to perform the following actions on my behalf: (1) 'Threshold': 'Execution' for 'lit-litaction://*'. (2) 'Threshold': 'Signing' for 'lit-pkp://*'. (3) 'Auth': 'Auth' for 'lit-resolvedauthcontext://*'.\n\nURI: lit:session:73e09d1ad1faa329bef12ebaf9b982d2925746e3677cabd4b6b7196096a6ee02\nVersion: 1\nChain ID: 1\nNonce: 0xa5f18dbc0fa2080649042ab8cb6cef3b246c20c15b62482ba43fb4ca2a4642cb\nIssued At: 2024-04-25T02:09:35Z\nExpiration Time: 2024-04-26T02:09:50.822Z\nResources:\n- urn:recap:eyJhdHQiOnsibGl0LWxpdGFjdGlvbjovLyoiOnsiVGhyZXNob2xkL0V4ZWN1dGlvbiI6W3t9XX0sImxpdC1wa3A6Ly8qIjp7IlRocmVzaG9sZC9TaWduaW5nIjpbe31dfSwibGl0LXJlc29sdmVkYXV0aGNvbnRleHQ6Ly8qIjp7IkF1dGgvQXV0aCI6W3siYXV0aF9jb250ZXh0Ijp7ImFjdGlvbklwZnNJZHMiOlsiUW1ZM3F1bjlxWDNmVUJIVmZyQTlmM3Y5UnB5eVBvOFJIRXVFTjFYWVBxMVByQSJdLCJhdXRoTWV0aG9kQ29udGV4dHMiOlt7ImFwcElkIjoibGl0IiwiYXV0aE1ldGhvZFR5cGUiOjEsImV4cGlyYXRpb24iOjE3MTQwOTczODYsInVzZWRGb3JTaWduU2Vzc2lvbktleVJlcXVlc3QiOnRydWUsInVzZXJJZCI6IjB4NzA5OTc5NzBDNTE4MTJkYzNBMDEwQzdkMDFiNTBlMGQxN2RjNzlDOCJ9XSwiYXV0aFNpZ0FkZHJlc3MiOm51bGwsInJlc291cmNlcyI6W119fV19fSwicHJmIjpbXX0", +// "dataSigned": "b2efe867176b9212fd6acd39a33004a17e03d5a931250c700e31af95e2e7e4d5", +// "blsRootPubkey": "a6f7c284ac766db1b43f8c65d8ff15c7271a05b0863b5205d96459fd32aa353e9390ce0626560fb76720c1a5c8ca6902" +// } +// ] export interface BlsResponseData { - result: boolean; + result: boolean | 'success'; signatureShare: { ProofOfPossession: string; };